From 4c391cf26789537fa249ad25e976330cecc6935f Mon Sep 17 00:00:00 2001 From: Kevin Peters Date: Wed, 13 Mar 2024 20:01:06 -0500 Subject: [PATCH 1/8] solana: add priority fee to redeem transactions --- sdk/src/contexts/solana/context.ts | 42 +++++++++++-------- .../solana/utils/sendAndConfirmPostVaa.ts | 5 +++ wormhole-connect/src/utils/wallet/index.ts | 12 +++--- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/sdk/src/contexts/solana/context.ts b/sdk/src/contexts/solana/context.ts index c2c4eb653..bc3296e72 100644 --- a/sdk/src/contexts/solana/context.ts +++ b/sdk/src/contexts/solana/context.ts @@ -901,26 +901,34 @@ export class SolanaContext< } const parsed = parseTokenTransferVaa(signedVAA); + const tokenKey = new PublicKey(parsed.tokenAddress); const isNativeSol = parsed.tokenChain === MAINNET_CHAINS.solana && - new PublicKey(parsed.tokenAddress).equals(NATIVE_MINT); + tokenKey.equals(NATIVE_MINT); + const transaction = new Transaction(); + transaction.add(...(await this.determineComputeBudget([tokenKey]))); if (isNativeSol) { - return await redeemAndUnwrapOnSolana( - this.connection, - contracts.core, - contracts.token_bridge, - payerAddr, - signedVAA, + transaction.add( + await redeemAndUnwrapOnSolana( + this.connection, + contracts.core, + contracts.token_bridge, + payerAddr, + signedVAA, + ), ); } else { - return await redeemOnSolana( - this.connection, - contracts.core, - contracts.token_bridge, - payerAddr, - signedVAA, + transaction.add( + await redeemOnSolana( + this.connection, + contracts.core, + contracts.token_bridge, + payerAddr, + signedVAA, + ), ); } + return transaction; } async redeemRelay( @@ -1230,7 +1238,10 @@ export class SolanaContext< const recentFees = recentFeesResponse .map((dp) => dp.prioritizationFee) .sort((a, b) => a - b); - fee = recentFees[Math.floor(recentFees.length * SOLANA_FEE_PERCENTILE)]; + fee = Math.max( + recentFees[Math.floor(recentFees.length * SOLANA_FEE_PERCENTILE)], + fee, + ); } } catch (e) { console.error('Error fetching Solana recent fees', e); @@ -1239,9 +1250,6 @@ export class SolanaContext< console.info(`Setting Solana compute unit price to ${fee} microLamports`); return [ - ComputeBudgetProgram.setComputeUnitLimit({ - units: 250_000, - }), ComputeBudgetProgram.setComputeUnitPrice({ microLamports: fee, }), diff --git a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts index 84ad83077..e4c02f3d3 100644 --- a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts +++ b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts @@ -5,6 +5,7 @@ import { Keypair, PublicKeyInitData, Transaction, + TransactionInstruction, } from '@solana/web3.js'; import { signSendAndConfirmTransaction, @@ -31,6 +32,7 @@ export async function postVaaWithRetry( vaa: Buffer, maxRetries?: number, commitment?: Commitment, + computeBudgetInstructions?: TransactionInstruction[], ): Promise { const { unsignedTransactions, signers } = await createPostSignedVaaTransactions( @@ -40,6 +42,9 @@ export async function postVaaWithRetry( vaa, commitment, ); + for (const unsignedTransaction of unsignedTransactions) { + unsignedTransaction.add(...(computeBudgetInstructions || [])); + } const postVaaTransaction = unsignedTransactions.pop()!; diff --git a/wormhole-connect/src/utils/wallet/index.ts b/wormhole-connect/src/utils/wallet/index.ts index de3a39e29..c25708c22 100644 --- a/wormhole-connect/src/utils/wallet/index.ts +++ b/wormhole-connect/src/utils/wallet/index.ts @@ -4,12 +4,9 @@ import { Context, SendResult, ChainConfig, -} from '@wormhole-foundation/wormhole-connect-sdk'; -import { postVaaSolanaWithRetry, - CHAIN_ID_EVMOS, - CHAIN_ID_INJECTIVE, -} from '@certusone/wormhole-sdk'; +} from '@wormhole-foundation/wormhole-connect-sdk'; +import { CHAIN_ID_EVMOS, CHAIN_ID_INJECTIVE } from '@certusone/wormhole-sdk'; import { ContractReceipt } from 'ethers'; import { NotSupported, @@ -18,6 +15,7 @@ import { } from '@xlabs-libs/wallet-aggregator-core'; import config from 'config'; +import { solanaContext } from 'utils/sdk'; import { getChainByChainId } from 'utils'; import { AssetInfo } from './evm'; @@ -161,6 +159,8 @@ export const postVaa = async ( if (!wallet) throw new Error('not connected'); const pk = (wallet as any).adapter.publicKey; const MAX_VAA_UPLOAD_RETRIES_SOLANA = 5; + const computeBudgetInstructions = + await solanaContext().determineComputeBudget([]); await postVaaSolanaWithRetry( connection, @@ -169,6 +169,8 @@ export const postVaa = async ( pk.toString(), Buffer.from(signedVAA), MAX_VAA_UPLOAD_RETRIES_SOLANA, + undefined, + computeBudgetInstructions, ); }; From d9bf75c342863ce3aed4b8fb804a92ca25b59d2a Mon Sep 17 00:00:00 2001 From: Kevin Peters Date: Thu, 14 Mar 2024 12:35:32 -0500 Subject: [PATCH 2/8] make compute budget ixs first --- sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts index e4c02f3d3..539e9d793 100644 --- a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts +++ b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts @@ -43,7 +43,9 @@ export async function postVaaWithRetry( commitment, ); for (const unsignedTransaction of unsignedTransactions) { - unsignedTransaction.add(...(computeBudgetInstructions || [])); + unsignedTransaction.instructions.unshift( + ...(computeBudgetInstructions || []), + ); } const postVaaTransaction = unsignedTransactions.pop()!; From 4754cb9fb737eaaaae090e881c9eee081052c094 Mon Sep 17 00:00:00 2001 From: Kevin Peters Date: Thu, 14 Mar 2024 12:56:38 -0500 Subject: [PATCH 3/8] Revert "make compute budget ixs first" This reverts commit d376a79b66d167f47f3b19d3b6c5ba70bd8c2de3. --- sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts index 539e9d793..e4c02f3d3 100644 --- a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts +++ b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts @@ -43,9 +43,7 @@ export async function postVaaWithRetry( commitment, ); for (const unsignedTransaction of unsignedTransactions) { - unsignedTransaction.instructions.unshift( - ...(computeBudgetInstructions || []), - ); + unsignedTransaction.add(...(computeBudgetInstructions || [])); } const postVaaTransaction = unsignedTransactions.pop()!; From 8007fbe223bd923c022ffd39e8fcca4e653766ff Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Fri, 15 Mar 2024 12:27:37 -0400 Subject: [PATCH 4/8] filter out 0s, take median --- sdk/src/contexts/solana/context.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sdk/src/contexts/solana/context.ts b/sdk/src/contexts/solana/context.ts index bc3296e72..1742f9be5 100644 --- a/sdk/src/contexts/solana/context.ts +++ b/sdk/src/contexts/solana/context.ts @@ -79,7 +79,7 @@ const SOLANA_SEQ_LOG = 'Program log: Sequence: '; const SOLANA_CHAIN_NAME = MAINNET_CONFIG.chains.solana!.key; // Add priority fee according to 75th percentile of recent fees paid -const SOLANA_FEE_PERCENTILE = 0.75; +const SOLANA_FEE_PERCENTILE = 0.5; const SOLANA_MAINNET_EMMITER_ID = 'ec7372995d5cc8732397fb0ad35c0121e0eaa90d26f828a534cab54391b3a4f5'; @@ -1225,7 +1225,9 @@ export class SolanaContext< async determineComputeBudget( lockedWritableAccounts: PublicKey[] = [], ): Promise { - let fee = 100_000; // Set fee to 100,000 microlamport by default + // https://twitter.com/0xMert_/status/1768669928825962706 + + let fee = 1; // Set fee to 100,000 microlamport by default try { const recentFeesResponse = @@ -1237,11 +1239,14 @@ export class SolanaContext< // Get 75th percentile fee paid in recent slots const recentFees = recentFeesResponse .map((dp) => dp.prioritizationFee) + .filter((dp) => dp > 0) .sort((a, b) => a - b); - fee = Math.max( - recentFees[Math.floor(recentFees.length * SOLANA_FEE_PERCENTILE)], - fee, - ); + + if (recentFees.length > 0) { + const medianFee = + recentFees[Math.floor(recentFees.length * SOLANA_FEE_PERCENTILE)]; + fee = Math.max(fee, medianFee); + } } } catch (e) { console.error('Error fetching Solana recent fees', e); From 2bac879e80796ff79027983fc107080b63252bc1 Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Mon, 18 Mar 2024 15:17:23 -0400 Subject: [PATCH 5/8] move compute budget logic into util --- sdk/src/contexts/solana/context.ts | 138 ++++++------------ .../solana/utils/computeBudget/index.ts | 98 +++++++++++++ .../solana/utils/sendAndConfirmPostVaa.ts | 5 +- wormhole-connect/src/utils/wallet/index.ts | 4 - 4 files changed, 144 insertions(+), 101 deletions(-) create mode 100644 sdk/src/contexts/solana/utils/computeBudget/index.ts diff --git a/sdk/src/contexts/solana/context.ts b/sdk/src/contexts/solana/context.ts index 1742f9be5..fd2134263 100644 --- a/sdk/src/contexts/solana/context.ts +++ b/sdk/src/contexts/solana/context.ts @@ -23,7 +23,6 @@ import { import { clusterApiUrl, Commitment, - ComputeBudgetProgram, Connection, Keypair, PublicKey, @@ -66,6 +65,7 @@ import { getClaim, getPostedMessage, } from './utils/wormhole'; +import { addComputeBudget } from './utils/computeBudget'; import { ForeignAssetCache } from '../../utils'; import { RelayerAbstract } from '../abstracts/relayer'; import { @@ -78,9 +78,6 @@ import { const SOLANA_SEQ_LOG = 'Program log: Sequence: '; const SOLANA_CHAIN_NAME = MAINNET_CONFIG.chains.solana!.key; -// Add priority fee according to 75th percentile of recent fees paid -const SOLANA_FEE_PERCENTILE = 0.5; - const SOLANA_MAINNET_EMMITER_ID = 'ec7372995d5cc8732397fb0ad35c0121e0eaa90d26f828a534cab54391b3a4f5'; const SOLANA_TESTNET_EMITTER_ID = @@ -277,18 +274,15 @@ export class SolanaContext< payerPublicKey, tokenPublicKey, ); - const transaction = new Transaction(); - transaction.add( - ...(await this.determineComputeBudget([ - tokenPublicKey, - associatedPublicKey, - ])), + const transaction = new Transaction( + await this.connection?.getLatestBlockhash(commitment), ); transaction.add(createAccountInst); - - const { blockhash } = await this.connection.getLatestBlockhash(commitment); - transaction.recentBlockhash = blockhash; transaction.feePayer = payerPublicKey; + await addComputeBudget(this.connection!, transaction, [ + tokenPublicKey, + associatedPublicKey, + ]); return transaction; } @@ -397,12 +391,9 @@ export class SolanaContext< payerPublicKey, //authority ); - const { blockhash } = await this.connection.getLatestBlockhash(commitment); - const transaction = new Transaction(); - transaction.add(...(await this.determineComputeBudget([NATIVE_MINT]))); - - transaction.recentBlockhash = blockhash; - transaction.feePayer = payerPublicKey; + const transaction = new Transaction( + await this.connection?.getLatestBlockhash(commitment), + ); transaction.add( createAncillaryAccountIx, initialBalanceTransferIx, @@ -411,6 +402,9 @@ export class SolanaContext< tokenBridgeTransferIx, closeAccountIx, ); + + transaction.feePayer = payerPublicKey; + await addComputeBudget(this.connection!, transaction, [NATIVE_MINT]); transaction.partialSign(message, ancillaryKeypair); return transaction; } @@ -531,17 +525,16 @@ export class SolanaContext< recipientAddress, recipientChainId, ); - const transaction = new Transaction(); - transaction.add( - ...(await this.determineComputeBudget([ - new PublicKey(fromAddress), - new PublicKey(mintAddress), - ])), + + const transaction = new Transaction( + await this.connection?.getLatestBlockhash(commitment), ); transaction.add(approvalIx, tokenBridgeTransferIx); - const { blockhash } = await this.connection.getLatestBlockhash(commitment); - transaction.recentBlockhash = blockhash; transaction.feePayer = new PublicKey(senderAddress); + await addComputeBudget(this.connection!, transaction, [ + new PublicKey(fromAddress), + new PublicKey(mintAddress), + ]); transaction.partialSign(message); return transaction; } @@ -905,29 +898,25 @@ export class SolanaContext< const isNativeSol = parsed.tokenChain === MAINNET_CHAINS.solana && tokenKey.equals(NATIVE_MINT); - const transaction = new Transaction(); - transaction.add(...(await this.determineComputeBudget([tokenKey]))); - if (isNativeSol) { - transaction.add( - await redeemAndUnwrapOnSolana( + + const transaction = isNativeSol + ? await redeemAndUnwrapOnSolana( this.connection, contracts.core, contracts.token_bridge, payerAddr, signedVAA, - ), - ); - } else { - transaction.add( - await redeemOnSolana( + ) + : await redeemOnSolana( this.connection, contracts.core, contracts.token_bridge, payerAddr, signedVAA, - ), - ); - } + ); + + await addComputeBudget(this.connection!, transaction, [tokenKey]); + return transaction; } @@ -961,8 +950,10 @@ export class SolanaContext< parsed.tokenChain, parsed.tokenAddress, ); - const transaction = new Transaction(); - transaction.add(...(await this.determineComputeBudget([mint]))); + + const transaction = new Transaction( + await this.connection?.getLatestBlockhash('finalized'), + ); const recipientTokenAccount = getAssociatedTokenAddressSync( mint, recipient, @@ -1004,9 +995,8 @@ export class SolanaContext< ); } transaction.add(redeemIx); - const { blockhash } = await this.connection.getLatestBlockhash('finalized'); - transaction.recentBlockhash = blockhash; transaction.feePayer = new PublicKey(recipient); + await addComputeBudget(this.connection!, transaction, [mint]); return transaction; } @@ -1073,7 +1063,10 @@ export class SolanaContext< ); const recipientChainId = this.context.toChainId(recipientChain); const nonce = createNonce().readUint32LE(); - const transaction = new Transaction(); + const transaction = new Transaction( + await this.connection?.getLatestBlockhash('finalized'), + ); + transaction.feePayer = new PublicKey(senderAddress); if (token === NATIVE || token.chain === SOLANA_CHAIN_NAME) { const mint = token === NATIVE ? NATIVE_MINT : token.address; @@ -1107,9 +1100,6 @@ export class SolanaContext< } } - transaction.add( - ...(await this.determineComputeBudget(writableAddresses)), - ); transaction.add( await createTransferNativeTokensWithRelayInstruction( this.connection, @@ -1126,12 +1116,11 @@ export class SolanaContext< wrapToken, ), ); + + await addComputeBudget(this.connection!, transaction, writableAddresses); } else { const mint = await this.mustGetForeignAsset(token, sendingChain); - transaction.add( - ...(await this.determineComputeBudget([new PublicKey(mint)])), - ); transaction.add( await createTransferWrappedTokensWithRelayInstruction( this.connection, @@ -1147,11 +1136,11 @@ export class SolanaContext< nonce, ), ); - } - const { blockhash } = await this.connection.getLatestBlockhash('finalized'); - transaction.recentBlockhash = blockhash; - transaction.feePayer = new PublicKey(senderAddress); + await addComputeBudget(this.connection!, transaction, [ + new PublicKey(mint), + ]); + } return transaction; } @@ -1221,43 +1210,4 @@ export class SolanaContext< chain: 'solana', }; } - - async determineComputeBudget( - lockedWritableAccounts: PublicKey[] = [], - ): Promise { - // https://twitter.com/0xMert_/status/1768669928825962706 - - let fee = 1; // Set fee to 100,000 microlamport by default - - try { - const recentFeesResponse = - await this.connection?.getRecentPrioritizationFees({ - lockedWritableAccounts, - }); - - if (recentFeesResponse) { - // Get 75th percentile fee paid in recent slots - const recentFees = recentFeesResponse - .map((dp) => dp.prioritizationFee) - .filter((dp) => dp > 0) - .sort((a, b) => a - b); - - if (recentFees.length > 0) { - const medianFee = - recentFees[Math.floor(recentFees.length * SOLANA_FEE_PERCENTILE)]; - fee = Math.max(fee, medianFee); - } - } - } catch (e) { - console.error('Error fetching Solana recent fees', e); - } - - console.info(`Setting Solana compute unit price to ${fee} microLamports`); - - return [ - ComputeBudgetProgram.setComputeUnitPrice({ - microLamports: fee, - }), - ]; - } } diff --git a/sdk/src/contexts/solana/utils/computeBudget/index.ts b/sdk/src/contexts/solana/utils/computeBudget/index.ts new file mode 100644 index 000000000..9404f1437 --- /dev/null +++ b/sdk/src/contexts/solana/utils/computeBudget/index.ts @@ -0,0 +1,98 @@ +import { + Connection, + Transaction, + TransactionInstruction, + PublicKey, + ComputeBudgetProgram, +} from '@solana/web3.js'; + +// Add priority fee according to 50th percentile of recent fees paid +const DEFAULT_FEE_PERCENTILE = 0.5; + +export async function addComputeBudget( + connection: Connection, + transaction: Transaction, + lockedWritableAccounts: PublicKey[] = [], +): Promise { + const ixs = await determineComputeBudget( + connection, + transaction, + lockedWritableAccounts, + ); + transaction.add(...ixs); +} + +export async function determineComputeBudget( + connection: Connection, + transaction: Transaction, + lockedWritableAccounts: PublicKey[] = [], + feePercentile: number = DEFAULT_FEE_PERCENTILE, +): Promise { + let computeBudget = 250_000; + let priorityFee = 1; + + try { + const simulateResponse = await connection.simulateTransaction(transaction); + + if (simulateResponse?.value?.unitsConsumed) { + // Set compute budget to 120% of the units used in the simulated transaction + computeBudget = Math.round(simulateResponse.value.unitsConsumed * 1.2); + } + + priorityFee = await determinePriorityFee( + connection, + lockedWritableAccounts, + feePercentile, + ); + } catch (e) { + console.error(`Failed to get compute budget for Solana transaction: ${e}`); + } + + console.info(`Setting Solana compute unit budget to ${computeBudget} units`); + console.info( + `Setting Solana compute unit price to ${priorityFee} microLamports`, + ); + + return [ + ComputeBudgetProgram.setComputeUnitLimit({ + units: computeBudget, + }), + ComputeBudgetProgram.setComputeUnitPrice({ + microLamports: priorityFee, + }), + ]; +} + +async function determinePriorityFee( + connection: Connection, + lockedWritableAccounts: PublicKey[] = [], + percentile: number, +): Promise { + // https://twitter.com/0xMert_/status/1768669928825962706 + + let fee = 1; // Set fee to 100,000 microlamport by default + + try { + const recentFeesResponse = await connection.getRecentPrioritizationFees({ + lockedWritableAccounts, + }); + + if (recentFeesResponse) { + // Get 75th percentile fee paid in recent slots + const recentFees = recentFeesResponse + .map((dp) => dp.prioritizationFee) + .filter((dp) => dp > 0) + .sort((a, b) => a - b); + + if (recentFees.length > 0) { + const medianFee = + recentFees[Math.floor(recentFees.length * percentile)]; + fee = Math.max(fee, medianFee); + } + } + } catch (e) { + console.error('Error fetching Solana recent fees', e); + } + + return fee; +} diff --git a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts index e4c02f3d3..02eccacfe 100644 --- a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts +++ b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts @@ -5,7 +5,6 @@ import { Keypair, PublicKeyInitData, Transaction, - TransactionInstruction, } from '@solana/web3.js'; import { signSendAndConfirmTransaction, @@ -15,6 +14,7 @@ import { TransactionSignatureAndResponse, PreparedTransactions, } from './utils'; +import { addComputeBudget } from './computeBudget'; import { createPostVaaInstruction, createVerifySignaturesInstructions, @@ -32,7 +32,6 @@ export async function postVaaWithRetry( vaa: Buffer, maxRetries?: number, commitment?: Commitment, - computeBudgetInstructions?: TransactionInstruction[], ): Promise { const { unsignedTransactions, signers } = await createPostSignedVaaTransactions( @@ -43,7 +42,7 @@ export async function postVaaWithRetry( commitment, ); for (const unsignedTransaction of unsignedTransactions) { - unsignedTransaction.add(...(computeBudgetInstructions || [])); + addComputeBudget(connection, unsignedTransaction, []); } const postVaaTransaction = unsignedTransactions.pop()!; diff --git a/wormhole-connect/src/utils/wallet/index.ts b/wormhole-connect/src/utils/wallet/index.ts index c25708c22..efc89564d 100644 --- a/wormhole-connect/src/utils/wallet/index.ts +++ b/wormhole-connect/src/utils/wallet/index.ts @@ -15,7 +15,6 @@ import { } from '@xlabs-libs/wallet-aggregator-core'; import config from 'config'; -import { solanaContext } from 'utils/sdk'; import { getChainByChainId } from 'utils'; import { AssetInfo } from './evm'; @@ -159,8 +158,6 @@ export const postVaa = async ( if (!wallet) throw new Error('not connected'); const pk = (wallet as any).adapter.publicKey; const MAX_VAA_UPLOAD_RETRIES_SOLANA = 5; - const computeBudgetInstructions = - await solanaContext().determineComputeBudget([]); await postVaaSolanaWithRetry( connection, @@ -170,7 +167,6 @@ export const postVaa = async ( Buffer.from(signedVAA), MAX_VAA_UPLOAD_RETRIES_SOLANA, undefined, - computeBudgetInstructions, ); }; From 74c390ad953796808089fccff3ba974b733a77b7 Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Mon, 18 Mar 2024 15:29:06 -0400 Subject: [PATCH 6/8] log errors --- sdk/src/contexts/solana/utils/computeBudget/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdk/src/contexts/solana/utils/computeBudget/index.ts b/sdk/src/contexts/solana/utils/computeBudget/index.ts index 9404f1437..6f52fbebd 100644 --- a/sdk/src/contexts/solana/utils/computeBudget/index.ts +++ b/sdk/src/contexts/solana/utils/computeBudget/index.ts @@ -34,6 +34,12 @@ export async function determineComputeBudget( try { const simulateResponse = await connection.simulateTransaction(transaction); + if (simulateResponse.value.err) { + console.error( + `Error simulating Solana transaction: ${simulateResponse.value.err}`, + ); + } + if (simulateResponse?.value?.unitsConsumed) { // Set compute budget to 120% of the units used in the simulated transaction computeBudget = Math.round(simulateResponse.value.unitsConsumed * 1.2); From 371d77bf04b96e2a101ef48209dba80389942d51 Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Mon, 18 Mar 2024 15:52:32 -0400 Subject: [PATCH 7/8] await promise --- sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts index 02eccacfe..2f177cf95 100644 --- a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts +++ b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts @@ -42,7 +42,7 @@ export async function postVaaWithRetry( commitment, ); for (const unsignedTransaction of unsignedTransactions) { - addComputeBudget(connection, unsignedTransaction, []); + await addComputeBudget(connection, unsignedTransaction, []); } const postVaaTransaction = unsignedTransactions.pop()!; From 132f206773fdc7c260c616b22f4640ba2100aea7 Mon Sep 17 00:00:00 2001 From: Kevin Peters Date: Tue, 19 Mar 2024 12:42:43 -0500 Subject: [PATCH 8/8] add compute budget for last redeem tx separately it depends on the first txs and simulation will fail otherwise --- sdk/src/contexts/solana/utils/computeBudget/index.ts | 2 +- sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts | 8 ++++---- wormhole-connect/src/utils/wallet/index.ts | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sdk/src/contexts/solana/utils/computeBudget/index.ts b/sdk/src/contexts/solana/utils/computeBudget/index.ts index 6f52fbebd..a342ee3e6 100644 --- a/sdk/src/contexts/solana/utils/computeBudget/index.ts +++ b/sdk/src/contexts/solana/utils/computeBudget/index.ts @@ -76,7 +76,7 @@ async function determinePriorityFee( ): Promise { // https://twitter.com/0xMert_/status/1768669928825962706 - let fee = 1; // Set fee to 100,000 microlamport by default + let fee = 1; // Set fee to 1 microlamport by default try { const recentFeesResponse = await connection.getRecentPrioritizationFees({ diff --git a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts index 2f177cf95..83520c8c4 100644 --- a/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts +++ b/sdk/src/contexts/solana/utils/sendAndConfirmPostVaa.ts @@ -41,12 +41,11 @@ export async function postVaaWithRetry( vaa, commitment, ); - for (const unsignedTransaction of unsignedTransactions) { - await addComputeBudget(connection, unsignedTransaction, []); - } - const postVaaTransaction = unsignedTransactions.pop()!; + for (const unsignedTransaction of unsignedTransactions) { + await addComputeBudget(connection, unsignedTransaction); + } const responses = await sendAndConfirmTransactionsWithRetry( connection, modifySignTransaction(signTransaction, ...signers), @@ -55,6 +54,7 @@ export async function postVaaWithRetry( maxRetries, ); //While the signature_set is used to create the final instruction, it doesn't need to sign it. + await addComputeBudget(connection, postVaaTransaction); responses.push( ...(await sendAndConfirmTransactionsWithRetry( connection, diff --git a/wormhole-connect/src/utils/wallet/index.ts b/wormhole-connect/src/utils/wallet/index.ts index efc89564d..9f635772f 100644 --- a/wormhole-connect/src/utils/wallet/index.ts +++ b/wormhole-connect/src/utils/wallet/index.ts @@ -166,7 +166,6 @@ export const postVaa = async ( pk.toString(), Buffer.from(signedVAA), MAX_VAA_UPLOAD_RETRIES_SOLANA, - undefined, ); };