-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: improve how depositor ATA interactions work #710
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -17,15 +17,13 @@ use crate::{ | |||
output_token: Pubkey, | ||||
input_amount: u64, | ||||
output_amount: u64, | ||||
destination_chain_id: u64, // TODO: we can remove some of these instructions props | ||||
exclusive_relayer: Pubkey, | ||||
quote_timestamp: u32, | ||||
fill_deadline: u32, | ||||
exclusivity_deadline: u32, | ||||
message: Vec<u8> | ||||
destination_chain_id: u64, | ||||
)] | ||||
pub struct DepositV3<'info> { | ||||
#[account(mut)] | ||||
#[account( | ||||
mut, | ||||
constraint = signer.key() == depositor @ SvmError::DepositorMustBeSigner | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have this restriction in EVM where sender can provide any depositor address There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, we dont really care about this as long as the authority is the depositor. previously we checked the authority is the signer, but now we check it is the depositor, which is functionally different. the goal I was trying to achieve is that deposit will work for a multi-sig & correct ATA support, where the depositor is the owner of the ATA. I think how it's structured, without this constraint, will support multisigs where the authority is not the signer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we don't really care that depositor is signer. and in case of multisig the authority account will be owned by the token program. we don't need to replicate any authorsation checks here as they will be performed in CPI transfer |
||||
)] | ||||
pub signer: Signer<'info>, | ||||
#[account( | ||||
mut, | ||||
|
@@ -37,17 +35,18 @@ pub struct DepositV3<'info> { | |||
|
||||
#[account( | ||||
seeds = [b"route", input_token.as_ref(), state.key().as_ref(), destination_chain_id.to_le_bytes().as_ref()], | ||||
bump | ||||
bump, | ||||
constraint = route.enabled @ CommonError::DisabledRoute | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was explicit check in EVM implementation. why move it here in constraints? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved it to match how we apply similar constraints on
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For fills EVM implementation has There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ye, I recall this. that still feels funny to me though. Would we not rather be consistent between rust implementation? the EVM logic feels inconsistent between the modifier use vs inline checks anyways. |
||||
)] | ||||
pub route: Account<'info, Route>, | ||||
|
||||
#[account( | ||||
mut, | ||||
token::mint = mint, | ||||
token::authority = signer, | ||||
associated_token::mint = mint, | ||||
associated_token::authority = depositor, | ||||
token::token_program = token_program | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change also token_program constraint to use associated_token |
||||
)] | ||||
pub user_token_account: InterfaceAccount<'info, TokenAccount>, | ||||
pub depositor_token_account: InterfaceAccount<'info, TokenAccount>, | ||||
|
||||
#[account( | ||||
mut, | ||||
|
@@ -59,7 +58,6 @@ pub struct DepositV3<'info> { | |||
|
||||
#[account( | ||||
mint::token_program = token_program, | ||||
// IDL build fails when requiring `address = input_token` for mint, thus using a custom constraint. | ||||
constraint = mint.key() == input_token @ SvmError::InvalidMint | ||||
)] | ||||
pub mint: InterfaceAccount<'info, Mint>, | ||||
|
@@ -84,10 +82,6 @@ pub fn deposit_v3( | |||
) -> Result<()> { | ||||
let state = &mut ctx.accounts.state; | ||||
|
||||
if !ctx.accounts.route.enabled { | ||||
return err!(CommonError::DisabledRoute); | ||||
} | ||||
|
||||
let current_time = get_current_time(state)?; | ||||
|
||||
// TODO: if the deposit quote timestamp is bad it is possible to make this error with a subtraction | ||||
|
@@ -102,7 +96,7 @@ pub fn deposit_v3( | |||
} | ||||
|
||||
let transfer_accounts = TransferChecked { | ||||
from: ctx.accounts.user_token_account.to_account_info(), | ||||
from: ctx.accounts.depositor_token_account.to_account_info(), | ||||
mint: ctx.accounts.mint.to_account_info(), | ||||
to: ctx.accounts.vault.to_account_info(), | ||||
authority: ctx.accounts.signer.to_account_info(), | ||||
|
@@ -130,5 +124,3 @@ pub fn deposit_v3( | |||
|
||||
Ok(()) | ||||
} | ||||
|
||||
// TODO: do we need other flavours of deposit? like speed up deposit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is now redundant