From a60475c331a93cd531841d18bb5898eecdab26e5 Mon Sep 17 00:00:00 2001 From: A5 Pickle Date: Thu, 31 Oct 2024 14:57:14 -0500 Subject: [PATCH 1/3] update submodule --- .gitmodules | 2 +- lib/example-liquidity-layer | 2 +- package-lock.json | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 974255c..e4ede52 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "lib/example-liquidity-layer"] path = lib/example-liquidity-layer url = https://github.com/wormhole-foundation/example-liquidity-layer.git - branch = v0.3.2 + branch = v0.3.3 diff --git a/lib/example-liquidity-layer b/lib/example-liquidity-layer index b505422..fd73007 160000 --- a/lib/example-liquidity-layer +++ b/lib/example-liquidity-layer @@ -1 +1 @@ -Subproject commit b505422d4e92558cc2759f1373974d27b4ee43a7 +Subproject commit fd730076aa14952d5ce4d7e44bde18c12705267d diff --git a/package-lock.json b/package-lock.json index 8dbf898..15e0367 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4421,6 +4421,7 @@ "version": "0.0.1", "resolved": "file:lib/example-liquidity-layer/wormhole-foundation-example-liquidity-layer-definitions-0.0.1.tgz", "integrity": "sha512-hGwQm8a1YfbvcqJOubvzduzYfl59GkTkI9dKaeI0YdqPoExFHghSmzkghzJvwAhOyT0hjGa+37ayDRygXipoSA==", + "license": "Apache-2.0", "dependencies": { "@wormhole-foundation/sdk-base": "^0.10.9", "@wormhole-foundation/sdk-definitions": "^0.10.9" @@ -4448,6 +4449,7 @@ "version": "0.0.1", "resolved": "file:lib/example-liquidity-layer/wormhole-foundation-example-liquidity-layer-evm-0.0.1.tgz", "integrity": "sha512-fc6k10EFHZ1OQa5Qw3lkLZAuRXHqZeAy3s+xcJ2krJmLlXiqd7pAkkm9F0Io3E9i6mTxab+YehwdqUHZoSZ91A==", + "license": "Apache-2.0", "dependencies": { "@wormhole-foundation/example-liquidity-layer-definitions": "0.0.1", "@wormhole-foundation/sdk-base": "^0.10.9", From 48fd3b867917b5809754d73283ac6dc8c04561b4 Mon Sep 17 00:00:00 2001 From: A5 Pickle Date: Fri, 1 Nov 2024 09:30:48 -0500 Subject: [PATCH 2/3] solana: disable direct data mapping fix stack access violation with complete swap payload remove init_if_needed for swap ATAs --- solana/Anchor.toml | 2 + .../programs/swap-layer/src/composite/mod.rs | 13 +- .../src/processor/complete/swap/payload.rs | 13 +- .../src/processor/initiate/swap/exact_in.rs | 13 +- solana/ts/src/swapLayer/index.ts | 165 ++++++++++++------ solana/ts/tests/10__swap.ts | 50 +++--- 6 files changed, 163 insertions(+), 93 deletions(-) diff --git a/solana/Anchor.toml b/solana/Anchor.toml index edf12bd..74eb0e5 100644 --- a/solana/Anchor.toml +++ b/solana/Anchor.toml @@ -34,6 +34,8 @@ url = "https://api.mainnet-beta.solana.com" ### every 400 ms. A fast voting cadence ensures faster finality and convergence ticks_per_slot = 16 +deactivate_feature = ["EenyoWx9UMXYKpR8mW5Jmfmy2fRjzUtM7NduYMY8bx33"] + ### Wormhole Core Bridge Program [[test.genesis]] address = "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth" diff --git a/solana/programs/swap-layer/src/composite/mod.rs b/solana/programs/swap-layer/src/composite/mod.rs index b876cac..c6e61de 100644 --- a/solana/programs/swap-layer/src/composite/mod.rs +++ b/solana/programs/swap-layer/src/composite/mod.rs @@ -10,7 +10,7 @@ use crate::{ }, }; use anchor_lang::{prelude::*, system_program}; -use anchor_spl::{associated_token, token, token_interface}; +use anchor_spl::{token, token_interface}; use common::{ admin::utils::{ assistant::{self, only_authorized}, @@ -328,9 +328,10 @@ pub struct CompleteSwap<'info> { /// Temporary swap token account to receive USDC from the prepared fill. This account will be /// closed at the end of this instruction. + /// + /// NOTE: This ATA must already be created. #[account( - init_if_needed, - payer = payer, + mut, associated_token::mint = usdc, associated_token::authority = authority, associated_token::token_program = token_program @@ -339,9 +340,10 @@ pub struct CompleteSwap<'info> { /// Temporary swap token account to receive destination mint after the swap. This account will /// be closed at the end of this instruction. + /// + /// NOTE: This ATA must already be created. #[account( - init_if_needed, - payer = payer, + mut, associated_token::mint = dst_mint, associated_token::authority = authority, associated_token::token_program = dst_token_program @@ -365,7 +367,6 @@ pub struct CompleteSwap<'info> { pub token_program: Program<'info, token::Token>, pub dst_token_program: Interface<'info, token_interface::TokenInterface>, - associated_token_program: Program<'info, associated_token::AssociatedToken>, pub system_program: Program<'info, System>, } diff --git a/solana/programs/swap-layer/src/processor/complete/swap/payload.rs b/solana/programs/swap-layer/src/processor/complete/swap/payload.rs index f3fad41..d0d484d 100644 --- a/solana/programs/swap-layer/src/processor/complete/swap/payload.rs +++ b/solana/programs/swap-layer/src/processor/complete/swap/payload.rs @@ -4,7 +4,7 @@ use crate::{ state::{StagedInbound, StagedInboundInfo, StagedInboundSeeds}, }; use anchor_lang::prelude::*; -use anchor_spl::{associated_token, token, token_interface}; +use anchor_spl::{token, token_interface}; use swap_layer_messages::{ messages::SwapMessageV1, types::{OutputToken, RedeemMode}, @@ -35,9 +35,10 @@ pub struct CompleteSwapPayload<'info> { /// Temporary swap token account to receive USDC from the prepared fill. This account will be /// closed at the end of this instruction. + /// + /// NOTE: This ATA must already be created. #[account( - init_if_needed, - payer = payer, + mut, associated_token::mint = usdc, associated_token::authority = staged_inbound, associated_token::token_program = token_program @@ -46,9 +47,10 @@ pub struct CompleteSwapPayload<'info> { /// Temporary swap token account to receive destination mint after the swap. This account will /// be closed at the end of this instruction. + /// + /// NOTE: This ATA must already be created. #[account( - init_if_needed, - payer = payer, + mut, associated_token::mint = dst_mint, associated_token::authority = staged_inbound, associated_token::token_program = dst_token_program @@ -72,7 +74,6 @@ pub struct CompleteSwapPayload<'info> { token_program: Program<'info, token::Token>, dst_token_program: Interface<'info, token_interface::TokenInterface>, - associated_token_program: Program<'info, associated_token::AssociatedToken>, system_program: Program<'info, System>, } diff --git a/solana/programs/swap-layer/src/processor/initiate/swap/exact_in.rs b/solana/programs/swap-layer/src/processor/initiate/swap/exact_in.rs index 6f8a58a..81099cc 100644 --- a/solana/programs/swap-layer/src/processor/initiate/swap/exact_in.rs +++ b/solana/programs/swap-layer/src/processor/initiate/swap/exact_in.rs @@ -5,7 +5,7 @@ use crate::{ PREPARED_ORDER_SEED_PREFIX, }; use anchor_lang::prelude::*; -use anchor_spl::{associated_token, token, token_interface}; +use anchor_spl::{token, token_interface}; use common::wormhole_io::TypePrefixedPayload; #[derive(Accounts)] @@ -89,9 +89,10 @@ pub struct InitiateSwapExactIn<'info> { /// Temporary swap token account to receive source mint from the staged custody token. This /// account will be closed at the end of this instruction. + /// + /// NOTE: This ATA must already be created. #[account( - init_if_needed, - payer = payer, + mut, associated_token::mint = src_mint, associated_token::authority = swap_authority, associated_token::token_program = src_token_program @@ -100,9 +101,10 @@ pub struct InitiateSwapExactIn<'info> { /// Temporary swap token account to receive destination mint after the swap. This account will /// be closed at the end of this instruction. + /// + /// NOTE: This ATA must already be created. #[account( - init_if_needed, - payer = payer, + mut, associated_token::mint = usdc, associated_token::authority = swap_authority )] @@ -126,7 +128,6 @@ pub struct InitiateSwapExactIn<'info> { prepared_custody_token: UncheckedAccount<'info>, token_router_program: Program<'info, token_router::program::TokenRouter>, - associated_token_program: Program<'info, associated_token::AssociatedToken>, src_token_program: Interface<'info, token_interface::TokenInterface>, token_program: Program<'info, token::Token>, system_program: Program<'info, System>, diff --git a/solana/ts/src/swapLayer/index.ts b/solana/ts/src/swapLayer/index.ts index 008cc30..94aec1b 100644 --- a/solana/ts/src/swapLayer/index.ts +++ b/solana/ts/src/swapLayer/index.ts @@ -198,10 +198,11 @@ export class SwapLayerProgram { )[0]; } - async swapAccounts(accounts: { + async prepareSwapAccounts(accounts: { + payer: PublicKey; authority: PublicKey; - sourceMint: PublicKey; - destinationMint: PublicKey; + srcMint: PublicKey; + dstMint: PublicKey; srcTokenProgram?: PublicKey; dstTokenProgram?: PublicKey; }): Promise<{ @@ -209,34 +210,58 @@ export class SwapLayerProgram { dstSwapToken: PublicKey; srcTokenProgram: PublicKey; dstTokenProgram: PublicKey; + srcCreateAtaIx: TransactionInstruction; + dstCreateAtaIx: TransactionInstruction; }> { - const { authority, sourceMint, destinationMint } = accounts; + const { payer, authority, srcMint, dstMint } = accounts; let { srcTokenProgram, dstTokenProgram } = accounts; if (srcTokenProgram === undefined) { - const accInfo = await this.connection().getAccountInfo(sourceMint); + const accInfo = await this.connection().getAccountInfo(srcMint); srcTokenProgram = accInfo.owner; } if (dstTokenProgram === undefined) { - const accInfo = await this.connection().getAccountInfo(destinationMint); + const accInfo = await this.connection().getAccountInfo(dstMint); dstTokenProgram = accInfo.owner; } + const srcSwapToken = splToken.getAssociatedTokenAddressSync( + srcMint, + authority, + true, + srcTokenProgram, + ); + + const dstSwapToken = splToken.getAssociatedTokenAddressSync( + dstMint, + authority, + true, + dstTokenProgram, + ); + + const srcCreateAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction( + payer, + srcSwapToken, + authority, + srcMint, + srcTokenProgram, + ); + + const dstCreateAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction( + payer, + dstSwapToken, + authority, + dstMint, + dstTokenProgram, + ); + return { - srcSwapToken: splToken.getAssociatedTokenAddressSync( - sourceMint, - authority, - true, - srcTokenProgram, - ), - dstSwapToken: splToken.getAssociatedTokenAddressSync( - destinationMint, - authority, - true, - dstTokenProgram, - ), + srcSwapToken, + dstSwapToken, srcTokenProgram, dstTokenProgram, + srcCreateAtaIx, + dstCreateAtaIx, }; } @@ -719,7 +744,7 @@ export class SwapLayerProgram { .instruction(); } - async initiateSwapExactInIx( + async initiateSwapExactInIxes( accounts: { payer: PublicKey; stagedOutbound: PublicKey; @@ -734,7 +759,13 @@ export class SwapLayerProgram { cpiInstruction: TransactionInstruction; targetChain?: ChainId; }, - ): Promise { + ): Promise< + [ + TransactionInstruction, // srcCreateAtaIx + TransactionInstruction, // dstCreateAtaIx + TransactionInstruction, // swapIx + ] + > { const { payer, stagedOutbound } = accounts; const { cpiInstruction } = args; @@ -764,19 +795,20 @@ export class SwapLayerProgram { stagedCustodyToken ??= this.stagedCustodyTokenAddress(stagedOutbound); const swapAuthority = this.swapAuthorityAddress(preparedOrder); - const swapAccounts = await this.swapAccounts({ + const preparedSwap = await this.prepareSwapAccounts({ + payer, authority: swapAuthority, - sourceMint: srcMint, - destinationMint: this.usdcMint, + srcMint, + dstMint: this.usdcMint, srcTokenProgram, dstTokenProgram: splToken.TOKEN_PROGRAM_ID, }); - const { srcSwapToken, dstSwapToken } = swapAccounts; - srcTokenProgram ??= swapAccounts.srcTokenProgram; + const { srcSwapToken, dstSwapToken, srcCreateAtaIx, dstCreateAtaIx } = preparedSwap; + srcTokenProgram ??= preparedSwap.srcTokenProgram; const tokenRouter = this.tokenRouterProgram(); - return this.program.methods + const swapIx = await this.program.methods .initiateSwapExactIn(cpiInstruction.data) .accounts({ payer, @@ -798,13 +830,14 @@ export class SwapLayerProgram { .routerEndpointAddress(targetChain), preparedCustodyToken: tokenRouter.preparedCustodyTokenAddress(preparedOrder), tokenRouterProgram: tokenRouter.ID, - associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID, srcTokenProgram, tokenProgram: splToken.TOKEN_PROGRAM_ID, systemProgram: SystemProgram.programId, }) .remainingAccounts(cpiInstruction.keys) .instruction(); + + return [srcCreateAtaIx, dstCreateAtaIx, swapIx]; } async completeTransferRelayIx( @@ -971,7 +1004,7 @@ export class SwapLayerProgram { .instruction(); } - async completeSwapDirectIx( + async completeSwapDirectIxes( accounts: { payer: PublicKey; preparedFill: PublicKey; @@ -985,7 +1018,13 @@ export class SwapLayerProgram { args: { cpiInstruction: TransactionInstruction; }, - ): Promise { + ): Promise< + [ + TransactionInstruction, // srcCreateAtaIx + TransactionInstruction, // dstCreateAtaIx + TransactionInstruction, // swapIx + ] + > { const { payer, preparedFill, recipient } = accounts; const { cpiInstruction } = args; @@ -995,15 +1034,16 @@ export class SwapLayerProgram { feeRecipientToken ??= await this.fetchCustodian().then((c) => c.feeRecipientToken); const swapAuthority = this.swapAuthorityAddress(preparedFill); - const swapAccounts = await this.swapAccounts({ + const preparedSwap = await this.prepareSwapAccounts({ + payer, authority: swapAuthority, - sourceMint: this.usdcMint, - destinationMint: dstMint, + srcMint: this.usdcMint, + dstMint, srcTokenProgram: splToken.TOKEN_PROGRAM_ID, dstTokenProgram, }); - const { srcSwapToken, dstSwapToken } = swapAccounts; - dstTokenProgram ??= swapAccounts.dstTokenProgram; + const { srcSwapToken, dstSwapToken, srcCreateAtaIx, dstCreateAtaIx } = preparedSwap; + dstTokenProgram ??= preparedSwap.dstTokenProgram; recipientToken ??= splToken.getAssociatedTokenAddressSync( dstMint, recipient, @@ -1011,7 +1051,7 @@ export class SwapLayerProgram { dstTokenProgram, ); - return this.program.methods + const swapIx = await this.program.methods .completeSwapDirect(cpiInstruction.data) .accounts({ completeSwap: { @@ -1026,7 +1066,6 @@ export class SwapLayerProgram { feeRecipientToken, usdc: this.usdcComposite(), dstMint, - associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID, tokenProgram: splToken.TOKEN_PROGRAM_ID, dstTokenProgram, systemProgram: SystemProgram.programId, @@ -1036,9 +1075,11 @@ export class SwapLayerProgram { }) .remainingAccounts(cpiInstruction.keys) .instruction(); + + return [srcCreateAtaIx, dstCreateAtaIx, swapIx]; } - async completeSwapRelayIx( + async completeSwapRelayIxes( accounts: { payer: PublicKey; preparedFill: PublicKey; @@ -1052,7 +1093,13 @@ export class SwapLayerProgram { args: { cpiInstruction: TransactionInstruction; }, - ): Promise { + ): Promise< + [ + TransactionInstruction, // srcCreateAtaIx + TransactionInstruction, // dstCreateAtaIx + TransactionInstruction, // swapIx + ] + > { const { payer, preparedFill, recipient } = accounts; const { cpiInstruction } = args; @@ -1062,15 +1109,16 @@ export class SwapLayerProgram { feeRecipientToken ??= await this.fetchCustodian().then((c) => c.feeRecipientToken); const swapAuthority = this.swapAuthorityAddress(preparedFill); - const swapAccounts = await this.swapAccounts({ + const preparedSwap = await this.prepareSwapAccounts({ + payer, authority: swapAuthority, - sourceMint: this.usdcMint, - destinationMint: dstMint, + srcMint: this.usdcMint, + dstMint, srcTokenProgram: splToken.TOKEN_PROGRAM_ID, dstTokenProgram, }); - const { srcSwapToken, dstSwapToken } = swapAccounts; - dstTokenProgram ??= swapAccounts.dstTokenProgram; + const { srcSwapToken, dstSwapToken, srcCreateAtaIx, dstCreateAtaIx } = preparedSwap; + dstTokenProgram ??= preparedSwap.dstTokenProgram; recipientToken ??= splToken.getAssociatedTokenAddressSync( dstMint, recipient, @@ -1078,7 +1126,7 @@ export class SwapLayerProgram { dstTokenProgram, ); - return this.program.methods + const swapIx = await this.program.methods .completeSwapRelay(cpiInstruction.data) .accounts({ completeSwap: { @@ -1093,7 +1141,6 @@ export class SwapLayerProgram { feeRecipientToken, usdc: this.usdcComposite(), dstMint, - associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID, tokenProgram: splToken.TOKEN_PROGRAM_ID, dstTokenProgram, systemProgram: SystemProgram.programId, @@ -1103,9 +1150,11 @@ export class SwapLayerProgram { }) .remainingAccounts(cpiInstruction.keys) .instruction(); + + return [srcCreateAtaIx, dstCreateAtaIx, swapIx]; } - async completeSwapPayloadIx( + async completeSwapPayloadIxes( accounts: { payer: PublicKey; preparedFill: PublicKey; @@ -1117,7 +1166,13 @@ export class SwapLayerProgram { args: { cpiInstruction: TransactionInstruction; }, - ): Promise { + ): Promise< + [ + TransactionInstruction, // srcCreateAtaIx + TransactionInstruction, // dstCreateAtaIx + TransactionInstruction, // swapIx + ] + > { const { payer, preparedFill } = accounts; const { cpiInstruction } = args; @@ -1126,18 +1181,19 @@ export class SwapLayerProgram { dstMint ??= splToken.NATIVE_MINT; const stagedInbound = this.stagedInboundAddress(preparedFill); - const swapAccounts = await this.swapAccounts({ + const preparedSwap = await this.prepareSwapAccounts({ + payer, authority: stagedInbound, - sourceMint: this.usdcMint, - destinationMint: dstMint, + srcMint: this.usdcMint, + dstMint, srcTokenProgram: splToken.TOKEN_PROGRAM_ID, dstTokenProgram, }); - const { srcSwapToken, dstSwapToken } = swapAccounts; - dstTokenProgram ??= swapAccounts.dstTokenProgram; + const { srcSwapToken, dstSwapToken, srcCreateAtaIx, dstCreateAtaIx } = preparedSwap; + dstTokenProgram ??= preparedSwap.dstTokenProgram; feeRecipientToken ??= await this.fetchCustodian().then((c) => c.feeRecipientToken); - return this.program.methods + const swapIx = await this.program.methods .completeSwapPayload(cpiInstruction.data) .accounts({ payer, @@ -1151,13 +1207,14 @@ export class SwapLayerProgram { feeRecipientToken, usdc: this.usdcComposite(), dstMint, - associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID, tokenProgram: splToken.TOKEN_PROGRAM_ID, dstTokenProgram, systemProgram: SystemProgram.programId, }) .remainingAccounts(cpiInstruction.keys) .instruction(); + + return [srcCreateAtaIx, dstCreateAtaIx, swapIx]; } tokenRouterProgram(): tokenRouterSdk.TokenRouterProgram { diff --git a/solana/ts/tests/10__swap.ts b/solana/ts/tests/10__swap.ts index d860fe6..dcafe62 100644 --- a/solana/ts/tests/10__swap.ts +++ b/solana/ts/tests/10__swap.ts @@ -2004,7 +2004,7 @@ describe("Swap Layer -- Jupiter V6", () => { assert.deepEqual(sourceMint, srcMint); assert.deepEqual(destinationMint, swapLayer.usdcMint); - const ix = await swapLayer.initiateSwapExactInIx( + const swapIxes = await swapLayer.initiateSwapExactInIxes( { payer: payer.publicKey, stagedOutbound, @@ -2026,9 +2026,15 @@ describe("Swap Layer -- Jupiter V6", () => { }), ); - await expectIxErr(connection, [computeIx, ix], [payer], "InsufficientAmountOut", { - addressLookupTableAccounts, - }); + await expectIxErr( + connection, + [computeIx, ...swapIxes], + [payer], + "InsufficientAmountOut", + { + addressLookupTableAccounts, + }, + ); }); it("USDT via Whirlpool", async function () { @@ -2081,7 +2087,7 @@ describe("Swap Layer -- Jupiter V6", () => { assert.isTrue(accInfos.every((info) => info === null)); } - const ix = await swapLayer.initiateSwapExactInIx( + const swapIxes = await swapLayer.initiateSwapExactInIxes( { payer: payer.publicKey, stagedOutbound, @@ -2103,7 +2109,7 @@ describe("Swap Layer -- Jupiter V6", () => { }), ); - await expectIxOk(connection, [computeIx, ix], [payer], { + await expectIxOk(connection, [computeIx, ...swapIxes], [payer], { addressLookupTableAccounts, }); @@ -2632,7 +2638,7 @@ describe("Swap Layer -- Jupiter V6", () => { assert.isTrue(accInfos.every((info) => info === null)); } - const ix = await swapLayer.initiateSwapExactInIx( + const swapIxes = await swapLayer.initiateSwapExactInIxes( { payer: payer.publicKey, stagedOutbound, @@ -2654,7 +2660,7 @@ describe("Swap Layer -- Jupiter V6", () => { }), ); - await expectIxOk(connection, [computeIx, ix], [payer], { + await expectIxOk(connection, [computeIx, ...swapIxes], [payer], { addressLookupTableAccounts, }); @@ -2794,7 +2800,7 @@ describe("Swap Layer -- Jupiter V6", () => { "Ethereum", "0x000000000000000000000000000000000000d00d", ), - buf: Uint8Array.from(Buffer.from("All your base are belong to us."),) + buf: Uint8Array.from(Buffer.from("All your base are belong to us.")), }, outputToken, amountIn, @@ -2832,7 +2838,7 @@ describe("Swap Layer -- Jupiter V6", () => { "Ethereum", "0x000000000000000000000000000000000000d00d", ), - buf: Uint8Array.from(Buffer.from("All your base are belong to us."),) + buf: Uint8Array.from(Buffer.from("All your base are belong to us.")), }, amountIn, }, @@ -2870,7 +2876,7 @@ describe("Swap Layer -- Jupiter V6", () => { "Ethereum", "0x000000000000000000000000000000000000d00d", ), - buf: Uint8Array.from(Buffer.from("All your base are belong to us."),) + buf: Uint8Array.from(Buffer.from("All your base are belong to us.")), }, outputToken, amountIn, @@ -2972,13 +2978,13 @@ describe("Swap Layer -- Jupiter V6", () => { const expectedDstMint = accounts.dstMint ?? splToken.NATIVE_MINT; assert.deepEqual(destinationMint, expectedDstMint); - const ix = await swapLayer.completeSwapDirectIx(accounts, { cpiInstruction }); + const swapIxes = await swapLayer.completeSwapDirectIxes(accounts, { cpiInstruction }); const ixs = [ ComputeBudgetProgram.setComputeUnitLimit({ units: 750_000, }), - ix, + ...swapIxes, ]; const addressLookupTableAccounts = await Promise.all( @@ -3073,13 +3079,13 @@ describe("Swap Layer -- Jupiter V6", () => { ); const expectedDstMint = accounts.dstMint ?? splToken.NATIVE_MINT; - const ix = await swapLayer.completeSwapRelayIx(accounts, { cpiInstruction }); + const swapIxes = await swapLayer.completeSwapRelayIxes(accounts, { cpiInstruction }); const ixs = [ ComputeBudgetProgram.setComputeUnitLimit({ units: 750_000, }), - ix, + ...swapIxes, ]; const addressLookupTableAccounts = await Promise.all( @@ -3209,13 +3215,13 @@ describe("Swap Layer -- Jupiter V6", () => { ), ); - const ix = await swapLayer.completeSwapPayloadIx(accounts, { cpiInstruction }); + const swapIxs = await swapLayer.completeSwapPayloadIxes(accounts, { cpiInstruction }); const ixs = [ ComputeBudgetProgram.setComputeUnitLimit({ units: 750_000, }), - ix, + ...swapIxs, ]; const addressLookupTableAccounts = await Promise.all( @@ -3240,7 +3246,9 @@ describe("Swap Layer -- Jupiter V6", () => { addressLookupTableAccounts, }); - const { recipient, redeemMode, outputToken } = decodeSwapLayerMessage(Uint8Array.from(redeemerMessage)); + const { recipient, redeemMode, outputToken } = decodeSwapLayerMessage( + Uint8Array.from(redeemerMessage), + ); if (redeemMode.mode !== "Payload") { assert.fail("Not in payload mode"); } @@ -4047,7 +4055,7 @@ describe("Swap Layer -- Jupiter V6", () => { let { additionalLuts } = otherOpts; additionalLuts ??= []; - const ix = await swapLayer.initiateSwapExactInIx(accounts, args); + const swapIxes = await swapLayer.initiateSwapExactInIxes(accounts, args); const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 750_000, @@ -4061,13 +4069,13 @@ describe("Swap Layer -- Jupiter V6", () => { ); if (errorMsg !== null) { - await expectIxErr(connection, [computeIx, ix], signers, errorMsg, { + await expectIxErr(connection, [computeIx, ...swapIxes], signers, errorMsg, { addressLookupTableAccounts, }); return; } - await expectIxOk(connection, [computeIx, ix], signers, { + await expectIxOk(connection, [computeIx, ...swapIxes], signers, { addressLookupTableAccounts, }); } From 531597cb0d1980c9c7a48c46e62e56353b3954a0 Mon Sep 17 00:00:00 2001 From: A5 Pickle Date: Fri, 1 Nov 2024 09:46:09 -0500 Subject: [PATCH 3/3] e2e: fix instruction handling --- e2e/tests/helpers/utils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e/tests/helpers/utils.ts b/e2e/tests/helpers/utils.ts index 049eb06..c8659d2 100644 --- a/e2e/tests/helpers/utils.ts +++ b/e2e/tests/helpers/utils.ts @@ -189,18 +189,18 @@ export async function completeSwapForTest( }, ); - let ix; + let swapIxes; if (opts.redeemMode === "direct") { - ix = await swapLayer.completeSwapDirectIx(accounts, { cpiInstruction }); + swapIxes = await swapLayer.completeSwapDirectIxes(accounts, { cpiInstruction }); } else if (opts.redeemMode === "relay") { - ix = await swapLayer.completeSwapRelayIx(accounts, { cpiInstruction }); + swapIxes = await swapLayer.completeSwapRelayIxes(accounts, { cpiInstruction }); } const ixs = [ ComputeBudgetProgram.setComputeUnitLimit({ units: 700_000, }), - ix, + ...swapIxes, ]; const addressLookupTableAccounts = await Promise.all( @@ -239,7 +239,7 @@ export async function swapExactInForTest( let { additionalLuts, signers } = opts; additionalLuts ??= []; - const ix = await swapLayer.initiateSwapExactInIx(accounts, args); + const swapIxes = await swapLayer.initiateSwapExactInIxes(accounts, args); const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 700_000, @@ -252,7 +252,7 @@ export async function swapExactInForTest( }), ); - await expectIxOk(swapLayer.connection(), [computeIx, ix], signers, { + await expectIxOk(swapLayer.connection(), [computeIx, ...swapIxes], signers, { addressLookupTableAccounts, }); }