From 051289b016d02ddcc8d44bf0f81fa9a48053177b Mon Sep 17 00:00:00 2001 From: bry Date: Wed, 25 Sep 2024 13:40:44 -0700 Subject: [PATCH 1/2] do a pass on agave 2.0 changes --- packages/helium-admin-cli/src/utils.ts | 27 ++++------ packages/migration-service/package.json | 1 + packages/migration-service/src/test-submit.ts | 50 ++++++++++++------- packages/migration-service/yarn.deploy.lock | 1 + packages/spl-utils/src/transaction.ts | 40 ++++++++++++++- tests/helium-entity-manager.ts | 6 ++- yarn.lock | 1 + 7 files changed, 87 insertions(+), 39 deletions(-) diff --git a/packages/helium-admin-cli/src/utils.ts b/packages/helium-admin-cli/src/utils.ts index ad143f1f3..3b4d92d43 100644 --- a/packages/helium-admin-cli/src/utils.ts +++ b/packages/helium-admin-cli/src/utils.ts @@ -7,6 +7,7 @@ import { toBN, withPriorityFees, } from "@helium/spl-utils"; +import { confirmTransaction } from "@helium/spl-utils/src"; import { createCreateMetadataAccountV3Instruction, PROGRAM_ID as METADATA_PROGRAM_ID, @@ -489,7 +490,7 @@ export async function sendInstructionsOrCreateProposal({ console.log("Created lookup table since ix too big", lut.toBase58()); await tx.sign([walletSigner!]); const sent = await provider.connection.sendTransaction(tx); - await provider.connection.confirmTransaction(sent, "confirmed"); + await confirmTransaction(provider, sent, "confirmed"); console.log(`Added tx ${idx}`, sent); await AddressLookupTableProgram.closeLookupTable({ @@ -785,12 +786,7 @@ export async function sendInstructionsOrSquads({ await withPriorityFees({ connection: provider.connection, instructions: [ - await squads.buildAddInstruction( - multisig, - txKey, - ix, - index - ), + await squads.buildAddInstruction(multisig, txKey, ix, index), ], computeUnits: 200000, }) @@ -798,15 +794,14 @@ export async function sendInstructionsOrSquads({ index++; } - const ixs: TransactionInstruction[] = [] - ixs.push(await squads.buildActivateTransaction(multisig, txKey)) - ixs.push(await squads.buildApproveTransaction(multisig, txKey)) + const ixs: TransactionInstruction[] = []; + ixs.push(await squads.buildActivateTransaction(multisig, txKey)); + ixs.push(await squads.buildApproveTransaction(multisig, txKey)); if (executeTransaction) { - ixs.push(await squads.buildExecuteTransaction( - txKey, - provider.wallet.publicKey - )); + ixs.push( + await squads.buildExecuteTransaction(txKey, provider.wallet.publicKey) + ); } await sendInstructions( @@ -814,10 +809,10 @@ export async function sendInstructionsOrSquads({ await withPriorityFees({ connection: provider.connection, computeUnits: 1000000, - instructions: ixs + instructions: ixs, }), signers - ) + ); } export async function parseEmissionsSchedule(filepath: string) { diff --git a/packages/migration-service/package.json b/packages/migration-service/package.json index b014d4df0..408ca204a 100644 --- a/packages/migration-service/package.json +++ b/packages/migration-service/package.json @@ -45,6 +45,7 @@ "@helium/helium-sub-daos-sdk": "^0.9.6", "@helium/lazy-distributor-sdk": "^0.9.6", "@helium/lazy-transactions-sdk": "^0.9.6", + "@helium/spl-utils": "^0.9.6", "@helium/treasury-management-sdk": "^0.9.6", "@helium/voter-stake-registry-sdk": "^0.9.6", "@metaplex-foundation/mpl-token-metadata": "^2.10.0", diff --git a/packages/migration-service/src/test-submit.ts b/packages/migration-service/src/test-submit.ts index d6582b982..552325c7e 100644 --- a/packages/migration-service/src/test-submit.ts +++ b/packages/migration-service/src/test-submit.ts @@ -1,4 +1,5 @@ import * as anchor from "@coral-xyz/anchor"; +import { confirmTransaction } from "@helium/spl-utils"; import axios from "axios"; import os from "os"; import yargs from "yargs/yargs"; @@ -22,8 +23,8 @@ const yarg = yargs(hideBin(process.argv)).options({ }, targetWallet: { alias: "t", - type: "string" - } + type: "string", + }, }); async function run() { @@ -33,25 +34,36 @@ async function run() { anchor.setProvider(anchor.AnchorProvider.local(argv.url)); const provider = anchor.getProvider() as anchor.AnchorProvider; - const txs = (await axios.get(`${argv.migrateUrl}/migrate/${argv.targetWallet}`)).data.transactions; - const txids = await Promise.all(txs.map(async tx => await provider.connection.sendRawTransaction( - Buffer.from(tx), - { - skipPreflight: true - } - ))); + const txs = ( + await axios.get(`${argv.migrateUrl}/migrate/${argv.targetWallet}`) + ).data.transactions; + const txids = await Promise.all( + txs.map( + async (tx) => + await provider.connection.sendRawTransaction(Buffer.from(tx), { + skipPreflight: true, + }) + ) + ); console.log("Sending", txids); - const success = await Promise.all(txids.map(async txid => { - const tx = await provider.connection.confirmTransaction(txid, "processed"); - if(tx.value.err) { - const tx = await provider.connection.getTransaction(txid); - console.error(txid, tx!.meta!.logMessages?.join("\n")); - } - return !tx.value.err - })); - + const success = await Promise.all( + txids.map(async (txid) => { + const tx = await confirmTransaction(provider, txid, "processed"); + if (tx.value.err) { + const tx = await provider.connection.getTransaction(txid); + console.error(txid, tx!.meta!.logMessages?.join("\n")); + } + return !tx.value.err; + }) + ); - console.log("done", success.filter(s => !s).length, "failed", success.filter(s => s).length, "succeeded"); + console.log( + "done", + success.filter((s) => !s).length, + "failed", + success.filter((s) => s).length, + "succeeded" + ); } run() diff --git a/packages/migration-service/yarn.deploy.lock b/packages/migration-service/yarn.deploy.lock index 328b6cdff..523ff7499 100644 --- a/packages/migration-service/yarn.deploy.lock +++ b/packages/migration-service/yarn.deploy.lock @@ -423,6 +423,7 @@ __metadata: "@helium/helium-sub-daos-sdk": ^0.9.6 "@helium/lazy-distributor-sdk": ^0.9.6 "@helium/lazy-transactions-sdk": ^0.9.6 + "@helium/spl-utils": ^0.9.6 "@helium/treasury-management-sdk": ^0.9.6 "@helium/voter-stake-registry-sdk": ^0.9.6 "@metaplex-foundation/mpl-token-metadata": ^2.10.0 diff --git a/packages/spl-utils/src/transaction.ts b/packages/spl-utils/src/transaction.ts index b37a7ca10..3019531e1 100644 --- a/packages/spl-utils/src/transaction.ts +++ b/packages/spl-utils/src/transaction.ts @@ -1,4 +1,4 @@ -import { AnchorProvider, Program, Provider } from "@coral-xyz/anchor"; +import anchor, { AnchorProvider, Program, Provider } from "@coral-xyz/anchor"; import { AddressLookupTableAccount, Commitment, @@ -6,7 +6,6 @@ import { Connection, Finality, Keypair, - Message, PublicKey, RpcResponseAndContext, SendOptions, @@ -14,6 +13,7 @@ import { Signer, SimulatedTransactionResponse, Transaction, + TransactionConfirmationStatus, TransactionInstruction, TransactionMessage, TransactionSignature, @@ -942,3 +942,39 @@ export async function batchParallelInstructionsWithPriorityFee( maxSignatureBatch ); } + +export async function confirmTransaction( + provider: AnchorProvider, + signature: string, + confirmationStatus: TransactionConfirmationStatus = "finalized", + timeout: number = 15000, + pollingInterval: number = 500 +): Promise> { + const startTime = Date.now(); + + while (Date.now() - startTime < timeout) { + const statuses = await provider.connection.getSignatureStatuses([ + signature, + ]); + + const status = statuses.value?.[0]; + + if (status?.confirmationStatus === confirmationStatus) { + return { + context: { + slot: status.slot || 0, + }, + value: status, + }; + } + + if (status?.err) { + throw new Error("Transaction failed"); + } + + // Wait for the polling interval before checking again + await new Promise((resolve) => setTimeout(resolve, pollingInterval)); + } + + throw new Error("Transaction confirmation timed out"); +} diff --git a/tests/helium-entity-manager.ts b/tests/helium-entity-manager.ts index b13aff16d..6eed24491 100644 --- a/tests/helium-entity-manager.ts +++ b/tests/helium-entity-manager.ts @@ -12,6 +12,7 @@ import { createMintInstructions, proofArgsAndAccounts, sendInstructions, + confirmTransaction, toBN, } from "@helium/spl-utils"; import { AddGatewayV1 } from "@helium/transactions"; @@ -783,7 +784,7 @@ describe("helium-entity-manager", () => { .signers([makerKeypair]) .transaction(); tx.recentBlockhash = ( - await provider.connection.getRecentBlockhash() + await provider.connection.getLatestBlockhash() ).blockhash; tx.feePayer = provider.wallet.publicKey; tx.partialSign(makerKeypair); @@ -803,7 +804,8 @@ describe("helium-entity-manager", () => { const sig = await provider.connection.sendRawTransaction( Buffer.from(transaction, "hex") ); - await provider.connection.confirmTransaction(sig); + + await confirmTransaction(provider, sig); }); it("issues a mobile hotspot", async () => { diff --git a/yarn.lock b/yarn.lock index 3da2ce9fc..3feb2db1c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1194,6 +1194,7 @@ __metadata: "@helium/helium-sub-daos-sdk": ^0.9.6 "@helium/lazy-distributor-sdk": ^0.9.6 "@helium/lazy-transactions-sdk": ^0.9.6 + "@helium/spl-utils": ^0.9.6 "@helium/treasury-management-sdk": ^0.9.6 "@helium/voter-stake-registry-sdk": ^0.9.6 "@metaplex-foundation/mpl-token-metadata": ^2.10.0 From 9fa3bda0984cf91d52caee3191a1574053d3cfaa Mon Sep 17 00:00:00 2001 From: bry Date: Wed, 25 Sep 2024 13:42:42 -0700 Subject: [PATCH 2/2] fix import --- packages/helium-admin-cli/src/utils.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/helium-admin-cli/src/utils.ts b/packages/helium-admin-cli/src/utils.ts index 3b4d92d43..214ddb129 100644 --- a/packages/helium-admin-cli/src/utils.ts +++ b/packages/helium-admin-cli/src/utils.ts @@ -1,23 +1,20 @@ import * as anchor from "@coral-xyz/anchor"; import { idlAddress } from "@coral-xyz/anchor/dist/cjs/idl"; import { + confirmTransaction, createAtaAndMintInstructions, createMintInstructions, sendInstructions, toBN, withPriorityFees, } from "@helium/spl-utils"; -import { confirmTransaction } from "@helium/spl-utils/src"; import { - createCreateMetadataAccountV3Instruction, PROGRAM_ID as METADATA_PROGRAM_ID, + createCreateMetadataAccountV3Instruction, } from "@metaplex-foundation/mpl-token-metadata"; import { AccountMetaData, BPF_UPGRADE_LOADER_ID, - getGovernanceProgramVersion, - getProposalTransactionAddress, - getTokenOwnerRecordAddress, Governance, GovernanceAccountParser, InstructionData, @@ -25,6 +22,10 @@ import { Realm, Vote, VoteType, + YesNoVote, + getGovernanceProgramVersion, + getProposalTransactionAddress, + getTokenOwnerRecordAddress, withAddSignatory, withCastVote, withCreateProposal, @@ -35,7 +36,6 @@ import { withRelinquishVote, withSignOffProposal, withWithdrawGoverningTokens, - YesNoVote, } from "@solana/spl-governance"; import { AuthorityType, @@ -50,9 +50,9 @@ import { Connection, Keypair, PublicKey, - Signer, SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY, + Signer, TransactionInstruction, TransactionMessage, VersionedTransaction,