@@ -15,6 +15,7 @@ import { PublicKey, SystemProgram, Transaction, sendAndConfirmTransaction } from
1515import yargs from "yargs" ;
1616import { hideBin } from "yargs/helpers" ;
1717import { calculateRelayHashUint8Array , getSpokePoolProgram , intToU8Array32 } from "../../src/svm/web3-v1" ;
18+ import { FillDataValues } from "../../src/types/svm" ;
1819
1920// Set up the provider
2021const provider = AnchorProvider . env ( ) ;
@@ -133,6 +134,16 @@ async function fillRelay(): Promise<void> {
133134
134135 const tokenDecimals = ( await getMint ( provider . connection , outputToken , undefined , TOKEN_PROGRAM_ID ) ) . decimals ;
135136
137+ // Create the ATA using the create_token_accounts method
138+ const createTokenAccountsIx = await program . methods
139+ . createTokenAccounts ( )
140+ . accounts ( { signer : signer . publicKey , mint : outputToken , tokenProgram : TOKEN_PROGRAM_ID } )
141+ . remainingAccounts ( [
142+ { pubkey : recipient , isWritable : false , isSigner : false } ,
143+ { pubkey : recipientTokenAccount , isWritable : true , isSigner : false } ,
144+ ] )
145+ . instruction ( ) ;
146+
136147 // Delegate state PDA to pull relayer tokens.
137148 const approveIx = await createApproveCheckedInstruction (
138149 relayerTokenAccount ,
@@ -145,24 +156,29 @@ async function fillRelay(): Promise<void> {
145156 TOKEN_PROGRAM_ID
146157 ) ;
147158
148- const fillIx = await (
149- program . methods . fillRelay ( Array . from ( relayHashUint8Array ) , relayData , chainId , signer . publicKey ) as any
150- )
151- . accounts ( {
152- state : statePda ,
153- signer : signer . publicKey ,
154- instructionParams : program . programId ,
155- mint : outputToken ,
156- relayerTokenAccount : relayerTokenAccount ,
157- recipientTokenAccount : recipientTokenAccount ,
158- fillStatus : fillStatusPda ,
159- tokenProgram : TOKEN_PROGRAM_ID ,
160- associatedTokenProgram : ASSOCIATED_TOKEN_PROGRAM_ID ,
161- systemProgram : SystemProgram . programId ,
162- programId : programId ,
163- } )
159+ const fillDataValues : FillDataValues = [ Array . from ( relayHashUint8Array ) , relayData , chainId , signer . publicKey ] ;
160+
161+ const fillAccounts = {
162+ state : statePda ,
163+ signer : signer . publicKey ,
164+ instructionParams : program . programId ,
165+ mint : outputToken ,
166+ relayerTokenAccount : relayerTokenAccount ,
167+ recipientTokenAccount : recipientTokenAccount ,
168+ fillStatus : fillStatusPda ,
169+ tokenProgram : TOKEN_PROGRAM_ID ,
170+ associatedTokenProgram : ASSOCIATED_TOKEN_PROGRAM_ID ,
171+ systemProgram : SystemProgram . programId ,
172+ programId : programId ,
173+ program : program . programId ,
174+ } ;
175+
176+ const fillIx = await program . methods
177+ . fillRelay ( ...fillDataValues )
178+ . accounts ( fillAccounts )
164179 . instruction ( ) ;
165- const fillTx = new Transaction ( ) . add ( approveIx , fillIx ) ;
180+
181+ const fillTx = new Transaction ( ) . add ( createTokenAccountsIx , approveIx , fillIx ) ;
166182 const tx = await sendAndConfirmTransaction ( provider . connection , fillTx , [ signer ] ) ;
167183
168184 console . log ( "Transaction signature:" , tx ) ;
0 commit comments