Skip to content

Commit 0fee026

Browse files
authored
fix(svm): deposit scripts (#1010)
* fix(svm): deposit scripts Signed-off-by: Pablo Maldonado <[email protected]> * fix: simpleFill Signed-off-by: Pablo Maldonado <[email protected]> --------- Signed-off-by: Pablo Maldonado <[email protected]>
1 parent 8355870 commit 0fee026

File tree

3 files changed

+86
-36
lines changed

3 files changed

+86
-36
lines changed

scripts/svm/nativeDeposit.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ import * as anchor from "@coral-xyz/anchor";
44
import { AnchorProvider, BN } from "@coral-xyz/anchor";
55
import {
66
ASSOCIATED_TOKEN_PROGRAM_ID,
7-
NATIVE_MINT,
8-
TOKEN_PROGRAM_ID,
97
createApproveCheckedInstruction,
108
createAssociatedTokenAccountIdempotentInstruction,
119
createCloseAccountInstruction,
1210
createSyncNativeInstruction,
1311
getAssociatedTokenAddressSync,
1412
getMinimumBalanceForRentExemptAccount,
1513
getMint,
14+
NATIVE_MINT,
15+
TOKEN_PROGRAM_ID,
1616
} from "@solana/spl-token";
1717
import {
1818
PublicKey,
19-
Transaction,
2019
sendAndConfirmTransaction,
21-
TransactionInstruction,
2220
SystemProgram,
21+
Transaction,
22+
TransactionInstruction,
2323
} from "@solana/web3.js";
2424
import yargs from "yargs";
2525
import { hideBin } from "yargs/helpers";
26-
import { getSpokePoolProgram, SOLANA_SPOKE_STATE_SEED } from "../../src/svm/web3-v1";
26+
import { getDepositPda, getDepositSeedHash, getSpokePoolProgram, SOLANA_SPOKE_STATE_SEED } from "../../src/svm/web3-v1";
2727

2828
// Set up the provider
2929
const provider = AnchorProvider.env();
@@ -125,20 +125,49 @@ async function nativeDeposit(): Promise<void> {
125125
? []
126126
: [createCloseAccountInstruction(userTokenAccount, signer.publicKey, signer.publicKey)];
127127

128+
const depositData: Parameters<typeof getDepositSeedHash>[0] = {
129+
depositor: signer.publicKey,
130+
recipient,
131+
inputToken,
132+
outputToken,
133+
inputAmount,
134+
outputAmount,
135+
destinationChainId,
136+
exclusiveRelayer,
137+
quoteTimestamp: new BN(quoteTimestamp),
138+
fillDeadline: new BN(fillDeadline),
139+
exclusivityParameter: new BN(exclusivityDeadline),
140+
message,
141+
};
142+
const delegatePda = getDepositPda(depositData, program.programId);
143+
128144
// Delegate state PDA to pull depositor tokens.
129145
const approveIx = await createApproveCheckedInstruction(
130146
userTokenAccount,
131147
inputToken,
132-
statePda,
148+
delegatePda,
133149
signer.publicKey,
134150
BigInt(inputAmount.toString()),
135151
tokenDecimals,
136152
undefined,
137153
TOKEN_PROGRAM_ID
138154
);
139155

140-
const depositIx = await (
141-
program.methods.deposit(
156+
const depositAccounts = {
157+
state: statePda,
158+
delegate: delegatePda,
159+
signer: signer.publicKey,
160+
depositorTokenAccount: userTokenAccount,
161+
vault: vault,
162+
mint: inputToken,
163+
tokenProgram: TOKEN_PROGRAM_ID,
164+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
165+
systemProgram: SystemProgram.programId,
166+
program: programId,
167+
};
168+
169+
const depositIx = await program.methods
170+
.deposit(
142171
signer.publicKey,
143172
recipient,
144173
inputToken,
@@ -151,16 +180,8 @@ async function nativeDeposit(): Promise<void> {
151180
fillDeadline,
152181
exclusivityDeadline,
153182
message
154-
) as any
155-
)
156-
.accounts({
157-
state: statePda,
158-
signer: signer.publicKey,
159-
userTokenAccount,
160-
vault: vault,
161-
tokenProgram: TOKEN_PROGRAM_ID,
162-
mint: inputToken,
163-
})
183+
)
184+
.accounts(depositAccounts)
164185
.instruction();
165186

166187
// Create the deposit transaction

scripts/svm/simpleDeposit.ts

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ import {
99
getAssociatedTokenAddressSync,
1010
getMint,
1111
} from "@solana/spl-token";
12-
import { PublicKey, Transaction, sendAndConfirmTransaction, TransactionInstruction } from "@solana/web3.js";
12+
import {
13+
PublicKey,
14+
SystemProgram,
15+
Transaction,
16+
TransactionInstruction,
17+
sendAndConfirmTransaction,
18+
} from "@solana/web3.js";
1319
import yargs from "yargs";
1420
import { hideBin } from "yargs/helpers";
15-
import { getSpokePoolProgram } from "../../src/svm/web3-v1";
21+
import { getDepositPda, getDepositSeedHash, getSpokePoolProgram } from "../../src/svm/web3-v1";
1622

1723
// Set up the provider
1824
const provider = AnchorProvider.env();
@@ -90,20 +96,49 @@ async function deposit(): Promise<void> {
9096

9197
const tokenDecimals = (await getMint(provider.connection, inputToken, undefined, TOKEN_PROGRAM_ID)).decimals;
9298

99+
const depositData: Parameters<typeof getDepositSeedHash>[0] = {
100+
depositor: signer.publicKey,
101+
recipient,
102+
inputToken,
103+
outputToken,
104+
inputAmount,
105+
outputAmount,
106+
destinationChainId,
107+
exclusiveRelayer,
108+
quoteTimestamp: new BN(quoteTimestamp),
109+
fillDeadline: new BN(fillDeadline),
110+
exclusivityParameter: new BN(exclusivityDeadline),
111+
message,
112+
};
113+
const delegatePda = getDepositPda(depositData, program.programId);
114+
93115
// Delegate state PDA to pull depositor tokens.
94116
const approveIx = await createApproveCheckedInstruction(
95117
userTokenAccount,
96118
inputToken,
97-
statePda,
119+
delegatePda,
98120
signer.publicKey,
99121
BigInt(inputAmount.toString()),
100122
tokenDecimals,
101123
undefined,
102124
TOKEN_PROGRAM_ID
103125
);
104126

105-
const depositIx = await (
106-
program.methods.deposit(
127+
const depositAccounts = {
128+
state: statePda,
129+
delegate: delegatePda,
130+
signer: signer.publicKey,
131+
depositorTokenAccount: userTokenAccount,
132+
vault: vault,
133+
mint: inputToken,
134+
tokenProgram: TOKEN_PROGRAM_ID,
135+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
136+
systemProgram: SystemProgram.programId,
137+
program: programId,
138+
};
139+
140+
const depositIx = await program.methods
141+
.deposit(
107142
signer.publicKey,
108143
recipient,
109144
inputToken,
@@ -116,16 +151,8 @@ async function deposit(): Promise<void> {
116151
fillDeadline,
117152
exclusivityDeadline,
118153
message
119-
) as any
120-
)
121-
.accounts({
122-
state: statePda,
123-
signer: signer.publicKey,
124-
userTokenAccount,
125-
vault: vault,
126-
tokenProgram: TOKEN_PROGRAM_ID,
127-
mint: inputToken,
128-
})
154+
)
155+
.accounts(depositAccounts)
129156
.instruction();
130157
// Create a custom instruction with arbitrary data
131158

scripts/svm/simpleFill.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,13 @@ async function fillRelay(): Promise<void> {
149149
])
150150
.instruction();
151151

152-
// Delegate state PDA to pull relayer tokens.
152+
const delegate = getFillRelayDelegatePda(relayHashUint8Array, chainId, signer.publicKey, program.programId).pda;
153+
154+
// Delegate fill delegate PDA to pull relayer tokens.
153155
const approveIx = await createApproveCheckedInstruction(
154156
relayerTokenAccount,
155157
outputToken,
156-
statePda,
158+
delegate,
157159
signer.publicKey,
158160
BigInt(relayData.outputAmount.toString()),
159161
tokenDecimals,
@@ -166,7 +168,7 @@ async function fillRelay(): Promise<void> {
166168
const fillAccounts = {
167169
state: statePda,
168170
signer: signer.publicKey,
169-
delegate: getFillRelayDelegatePda(relayHashUint8Array, chainId, signer.publicKey, program.programId).pda,
171+
delegate,
170172
instructionParams: program.programId,
171173
mint: outputToken,
172174
relayerTokenAccount: relayerTokenAccount,

0 commit comments

Comments
 (0)