Skip to content

Commit 31693cd

Browse files
authored
feat: improve how depositor ATA interactions work (#710)
1 parent 299c9d1 commit 31693cd

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

programs/svm-spoke/src/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub enum CommonError {
3131
DepositsArePaused,
3232
#[msg("Fills are currently paused!")]
3333
FillsArePaused,
34-
// Add any additional errors here if needed
3534
}
3635

3736
// SVM specific errors.

programs/svm-spoke/src/instructions/deposit.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ use crate::{
1717
output_token: Pubkey,
1818
input_amount: u64,
1919
output_amount: u64,
20-
destination_chain_id: u64, // TODO: we can remove some of these instructions props
21-
exclusive_relayer: Pubkey,
22-
quote_timestamp: u32,
23-
fill_deadline: u32,
24-
exclusivity_deadline: u32,
25-
message: Vec<u8>
20+
destination_chain_id: u64,
2621
)]
2722
pub struct DepositV3<'info> {
2823
#[account(mut)]
@@ -37,17 +32,18 @@ pub struct DepositV3<'info> {
3732

3833
#[account(
3934
seeds = [b"route", input_token.as_ref(), state.key().as_ref(), destination_chain_id.to_le_bytes().as_ref()],
40-
bump
35+
bump,
36+
constraint = route.enabled @ CommonError::DisabledRoute
4137
)]
4238
pub route: Account<'info, Route>,
4339

4440
#[account(
4541
mut,
46-
token::mint = mint,
47-
token::authority = signer,
48-
token::token_program = token_program
42+
associated_token::mint = mint,
43+
associated_token::authority = depositor,
44+
associated_token::token_program = token_program
4945
)]
50-
pub user_token_account: InterfaceAccount<'info, TokenAccount>,
46+
pub depositor_token_account: InterfaceAccount<'info, TokenAccount>,
5147

5248
#[account(
5349
mut,
@@ -59,7 +55,6 @@ pub struct DepositV3<'info> {
5955

6056
#[account(
6157
mint::token_program = token_program,
62-
// IDL build fails when requiring `address = input_token` for mint, thus using a custom constraint.
6358
constraint = mint.key() == input_token @ SvmError::InvalidMint
6459
)]
6560
pub mint: InterfaceAccount<'info, Mint>,
@@ -84,10 +79,6 @@ pub fn deposit_v3(
8479
) -> Result<()> {
8580
let state = &mut ctx.accounts.state;
8681

87-
if !ctx.accounts.route.enabled {
88-
return err!(CommonError::DisabledRoute);
89-
}
90-
9182
let current_time = get_current_time(state)?;
9283

9384
// TODO: if the deposit quote timestamp is bad it is possible to make this error with a subtraction
@@ -102,7 +93,7 @@ pub fn deposit_v3(
10293
}
10394

10495
let transfer_accounts = TransferChecked {
105-
from: ctx.accounts.user_token_account.to_account_info(),
96+
from: ctx.accounts.depositor_token_account.to_account_info(),
10697
mint: ctx.accounts.mint.to_account_info(),
10798
to: ctx.accounts.vault.to_account_info(),
10899
authority: ctx.accounts.signer.to_account_info(),
@@ -130,5 +121,3 @@ pub fn deposit_v3(
130121

131122
Ok(())
132123
}
133-
134-
// TODO: do we need other flavours of deposit? like speed up deposit

test/svm/SvmSpoke.Deposit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("svm_spoke.deposit", () => {
5858
state,
5959
route,
6060
signer: depositor.publicKey,
61-
userTokenAccount: depositorTA,
61+
depositorTokenAccount: depositorTA,
6262
vault,
6363
mint: inputToken,
6464
tokenProgram: TOKEN_PROGRAM_ID,
@@ -368,7 +368,7 @@ describe("svm_spoke.deposit", () => {
368368
state: fakeState,
369369
route: fakeRoutePda,
370370
signer: depositor.publicKey,
371-
userTokenAccount: depositorTA,
371+
depositorTokenAccount: depositorTA,
372372
vault: fakeVault,
373373
mint: inputToken,
374374
tokenProgram: TOKEN_PROGRAM_ID,

0 commit comments

Comments
 (0)