Skip to content

Commit

Permalink
feat(svm): fix simple fill script (#898)
Browse files Browse the repository at this point in the history
* feat(svm): fix simple fill script

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: simplify

Signed-off-by: Pablo Maldonado <[email protected]>

* feat: bump version

Signed-off-by: Pablo Maldonado <[email protected]>

---------

Signed-off-by: Pablo Maldonado <[email protected]>
  • Loading branch information
md0x authored Feb 26, 2025
1 parent 8ef0a3a commit 70d82df
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
18 changes: 18 additions & 0 deletions deployments/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,23 @@
"1301": {
"SpokePool": { "address": "0x6999526e507Cc3b03b180BbE05E1Ff938259A874", "blockNumber": 12593713 },
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 12594561 }
},
"133268194659241": {
"SvmSpoke": {
"address": "JAZWcGrpSWNPTBj8QtJ9UyQqhJCDhG9GJkDeMf5NQBiq",
"blockNumber": 356313770
},
"MulticallHandler": {
"address": "Fk1RpqsfeWt8KnFCTW9NQVdVxYvxuqjGn6iPB9wrmM8h",
"blockNumber": 356321050
},
"MessageTransmitter": {
"address": "CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd",
"blockNumber": 339604856
},
"TokenMessengerMinter": {
"address": "CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3",
"blockNumber": 277864039
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@across-protocol/contracts",
"version": "4.0.2",
"version": "4.0.3",
"author": "UMA Team",
"license": "AGPL-3.0-only",
"repository": {
Expand Down
50 changes: 33 additions & 17 deletions scripts/svm/simpleFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PublicKey, SystemProgram, Transaction, sendAndConfirmTransaction } from
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { calculateRelayHashUint8Array, getSpokePoolProgram, intToU8Array32 } from "../../src/svm/web3-v1";
import { FillDataValues } from "../../src/types/svm";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down Expand Up @@ -133,6 +134,16 @@ async function fillRelay(): Promise<void> {

const tokenDecimals = (await getMint(provider.connection, outputToken, undefined, TOKEN_PROGRAM_ID)).decimals;

// Create the ATA using the create_token_accounts method
const createTokenAccountsIx = await program.methods
.createTokenAccounts()
.accounts({ signer: signer.publicKey, mint: outputToken, tokenProgram: TOKEN_PROGRAM_ID })
.remainingAccounts([
{ pubkey: recipient, isWritable: false, isSigner: false },
{ pubkey: recipientTokenAccount, isWritable: true, isSigner: false },
])
.instruction();

// Delegate state PDA to pull relayer tokens.
const approveIx = await createApproveCheckedInstruction(
relayerTokenAccount,
Expand All @@ -145,24 +156,29 @@ async function fillRelay(): Promise<void> {
TOKEN_PROGRAM_ID
);

const fillIx = await (
program.methods.fillRelay(Array.from(relayHashUint8Array), relayData, chainId, signer.publicKey) as any
)
.accounts({
state: statePda,
signer: signer.publicKey,
instructionParams: program.programId,
mint: outputToken,
relayerTokenAccount: relayerTokenAccount,
recipientTokenAccount: recipientTokenAccount,
fillStatus: fillStatusPda,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
systemProgram: SystemProgram.programId,
programId: programId,
})
const fillDataValues: FillDataValues = [Array.from(relayHashUint8Array), relayData, chainId, signer.publicKey];

const fillAccounts = {
state: statePda,
signer: signer.publicKey,
instructionParams: program.programId,
mint: outputToken,
relayerTokenAccount: relayerTokenAccount,
recipientTokenAccount: recipientTokenAccount,
fillStatus: fillStatusPda,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
systemProgram: SystemProgram.programId,
programId: programId,
program: program.programId,
};

const fillIx = await program.methods
.fillRelay(...fillDataValues)
.accounts(fillAccounts)
.instruction();
const fillTx = new Transaction().add(approveIx, fillIx);

const fillTx = new Transaction().add(createTokenAccountsIx, approveIx, fillIx);
const tx = await sendAndConfirmTransaction(provider.connection, fillTx, [signer]);

console.log("Transaction signature:", tx);
Expand Down

0 comments on commit 70d82df

Please sign in to comment.