@@ -10,12 +10,16 @@ import {
1010 AddressLookupTableProgram ,
1111 VersionedTransaction ,
1212 TransactionMessage ,
13+ sendAndConfirmTransaction ,
14+ Transaction ,
1315} from "@solana/web3.js" ;
1416import {
1517 ASSOCIATED_TOKEN_PROGRAM_ID ,
1618 TOKEN_PROGRAM_ID ,
1719 getAssociatedTokenAddressSync ,
1820 createAssociatedTokenAccount ,
21+ getMint ,
22+ createApproveCheckedInstruction ,
1923} from "@solana/spl-token" ;
2024import { SvmSpoke } from "../../target/types/svm_spoke" ;
2125import yargs from "yargs" ;
@@ -49,8 +53,8 @@ async function testBundleLogic(): Promise<void> {
4953 const amounts = Array . from ( { length : numberOfRelayersToRepay } , ( _ , i ) => new BN ( i + 1 ) ) ;
5054 const inputToken = new PublicKey ( resolvedArgv . inputToken ) ;
5155
52- const signer = provider . wallet . publicKey ;
53- console . log ( "Running from signer: " , signer . toString ( ) ) ;
56+ const signer = ( provider . wallet as anchor . Wallet ) . payer ;
57+ console . log ( "Running from signer: " , signer . publicKey . toString ( ) ) ;
5458
5559 const [ statePda , _ ] = PublicKey . findProgramAddressSync (
5660 [ Buffer . from ( "state" ) , seed . toArrayLike ( Buffer , "le" , 8 ) ] ,
@@ -76,21 +80,38 @@ async function testBundleLogic(): Promise<void> {
7680 { property : "seed" , value : seed . toString ( ) } ,
7781 { property : "numberOfRelayersToRepay" , value : numberOfRelayersToRepay } ,
7882 { property : "inputToken" , value : inputToken . toString ( ) } ,
79- { property : "signer" , value : signer . toString ( ) } ,
83+ { property : "signer" , value : signer . publicKey . toString ( ) } ,
8084 { property : "statePda" , value : statePda . toString ( ) } ,
8185 { property : "routePda" , value : routePda . toString ( ) } ,
8286 { property : "vault" , value : vault . toString ( ) } ,
8387 ] ) ;
8488
89+ const userTokenAccount = getAssociatedTokenAddressSync ( inputToken , signer . publicKey ) ;
90+
91+ const tokenDecimals = ( await getMint ( provider . connection , inputToken , undefined , TOKEN_PROGRAM_ID ) ) . decimals ;
92+
8593 // Use program.methods.depositV3 to send tokens to the spoke. note this is NOT a valid deposit, we just want to
8694 // seed tokens into the spoke to test repayment.
87- const depositTx = await (
95+
96+ // Delegate state PDA to pull depositor tokens.
97+ const inputAmount = amounts . reduce ( ( acc , amount ) => acc . add ( amount ) , new BN ( 0 ) ) ;
98+ const approveIx = await createApproveCheckedInstruction (
99+ userTokenAccount ,
100+ inputToken ,
101+ statePda ,
102+ signer . publicKey ,
103+ BigInt ( inputAmount . toString ( ) ) ,
104+ tokenDecimals ,
105+ undefined ,
106+ TOKEN_PROGRAM_ID
107+ ) ;
108+ const depositIx = await (
88109 program . methods . depositV3 (
89- signer ,
90- signer , // recipient is the signer for this example
110+ signer . publicKey ,
111+ signer . publicKey , // recipient is the signer for this example
91112 inputToken ,
92113 inputToken , // Re-use inputToken as outputToken. does not matter for this deposit.
93- amounts . reduce ( ( acc , amount ) => acc . add ( amount ) , new BN ( 0 ) ) ,
114+ inputAmount ,
94115 new BN ( 0 ) ,
95116 new BN ( 11155111 ) , // destinationChainId. assumed to be enabled, as with routePDA
96117 PublicKey . default , // exclusiveRelayer
@@ -103,13 +124,17 @@ async function testBundleLogic(): Promise<void> {
103124 . accounts ( {
104125 state : statePda ,
105126 route : routePda ,
106- signer : signer ,
107- userTokenAccount : getAssociatedTokenAddressSync ( inputToken , signer ) ,
127+ signer : signer . publicKey ,
128+ userTokenAccount : getAssociatedTokenAddressSync ( inputToken , signer . publicKey ) ,
108129 vault : vault ,
109130 tokenProgram : TOKEN_PROGRAM_ID ,
110131 mint : inputToken ,
111132 } )
112- . rpc ( ) ;
133+ . instruction ( ) ;
134+ const depositTx = await sendAndConfirmTransaction ( provider . connection , new Transaction ( ) . add ( approveIx , depositIx ) , [
135+ signer ,
136+ ] ) ;
137+
113138 console . log ( `Deposit transaction sent: ${ depositTx } ` ) ;
114139
115140 // Create a single repayment leaf with the array of amounts and corresponding refund addresses
@@ -161,15 +186,15 @@ async function testBundleLogic(): Promise<void> {
161186 { property : "State PDA" , value : statePda . toString ( ) } ,
162187 { property : "Route PDA" , value : routePda . toString ( ) } ,
163188 { property : "Root Bundle PDA" , value : rootBundle . toString ( ) } ,
164- { property : "Signer" , value : signer . toString ( ) } ,
189+ { property : "Signer" , value : signer . publicKey . toString ( ) } ,
165190 ] ) ;
166191
167192 const relayRootBundleTx = await ( program . methods . relayRootBundle ( Array . from ( root ) , Array . from ( root ) ) as any )
168193 . accounts ( {
169194 state : statePda ,
170195 rootBundle : rootBundle ,
171- signer : signer ,
172- payer : signer ,
196+ signer : signer . publicKey ,
197+ payer : signer . publicKey ,
173198 systemProgram : SystemProgram . programId ,
174199 } )
175200 . rpc ( ) ;
@@ -190,15 +215,15 @@ async function testBundleLogic(): Promise<void> {
190215 console . log ( "loading execute relayer refund leaf params..." ) ;
191216
192217 const [ instructionParams ] = PublicKey . findProgramAddressSync (
193- [ Buffer . from ( "instruction_params" ) , signer . toBuffer ( ) ] ,
218+ [ Buffer . from ( "instruction_params" ) , signer . publicKey . toBuffer ( ) ] ,
194219 program . programId
195220 ) ;
196221
197222 const staticAccounts = {
198223 instructionParams,
199224 state : statePda ,
200225 rootBundle : rootBundle ,
201- signer : signer ,
226+ signer : signer . publicKey ,
202227 vault : vault ,
203228 tokenProgram : TOKEN_PROGRAM_ID ,
204229 mint : inputToken ,
@@ -213,8 +238,8 @@ async function testBundleLogic(): Promise<void> {
213238
214239 // Consolidate all above addresses into a single array for the Address Lookup Table (ALT).
215240 const [ lookupTableInstruction , lookupTableAddress ] = await AddressLookupTableProgram . createLookupTable ( {
216- authority : signer ,
217- payer : signer ,
241+ authority : signer . publicKey ,
242+ payer : signer . publicKey ,
218243 recentSlot : await provider . connection . getSlot ( ) ,
219244 } ) ;
220245
@@ -235,8 +260,8 @@ async function testBundleLogic(): Promise<void> {
235260 for ( let i = 0 ; i < lookupAddresses . length ; i += maxExtendedAccounts ) {
236261 const extendInstruction = AddressLookupTableProgram . extendLookupTable ( {
237262 lookupTable : lookupTableAddress ,
238- authority : signer ,
239- payer : signer ,
263+ authority : signer . publicKey ,
264+ payer : signer . publicKey ,
240265 addresses : lookupAddresses . slice ( i , i + maxExtendedAccounts ) ,
241266 } ) ;
242267
@@ -253,7 +278,7 @@ async function testBundleLogic(): Promise<void> {
253278 throw new Error ( "AddressLookupTableAccount not fetched" ) ;
254279 }
255280
256- await loadExecuteRelayerRefundLeafParams ( program , signer , rootBundleId , leaf , proofAsNumbers ) ;
281+ await loadExecuteRelayerRefundLeafParams ( program , signer . publicKey , rootBundleId , leaf , proofAsNumbers ) ;
257282
258283 console . log ( `loaded execute relayer refund leaf params ${ instructionParams } . \nExecuting relayer refund leaf...` ) ;
259284
@@ -267,7 +292,7 @@ async function testBundleLogic(): Promise<void> {
267292 const computeBudgetInstruction = ComputeBudgetProgram . setComputeUnitLimit ( { units : 500_000 } ) ;
268293 const versionedTx = new VersionedTransaction (
269294 new TransactionMessage ( {
270- payerKey : signer ,
295+ payerKey : signer . publicKey ,
271296 recentBlockhash : ( await provider . connection . getLatestBlockhash ( ) ) . blockhash ,
272297 instructions : [ computeBudgetInstruction , executeInstruction ] ,
273298 } ) . compileToV0Message ( [ lookupTableAccount ] )
@@ -280,8 +305,9 @@ async function testBundleLogic(): Promise<void> {
280305
281306 // Close the instruction parameters account
282307 console . log ( "Closing instruction params..." ) ;
308+ await new Promise ( ( resolve ) => setTimeout ( resolve , 15000 ) ) ; // Wait for the previous transaction to be processed.
283309 const closeInstructionParamsTx = await ( program . methods . closeInstructionParams ( ) as any )
284- . accounts ( { signer : signer , instructionParams : instructionParams } )
310+ . accounts ( { signer : signer . publicKey , instructionParams : instructionParams } )
285311 . rpc ( ) ;
286312 console . log ( `Close instruction params transaction sent: ${ closeInstructionParamsTx } ` ) ;
287313 // Note we cant close the lookup table account as it needs to be both deactivated and expired at to do this.
0 commit comments