Skip to content
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: depositNow #712

Merged
merged 10 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions programs/svm-spoke/src/instructions/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,45 +134,22 @@ pub fn deposit_v3_now(
message: Vec<u8>,
) -> Result<()> {
let state = &mut ctx.accounts.state;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state does not need to be mut here anymore as we only use it for getting current time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub fn get_current_time(_state: &State) expects mutable state for this function. we might want to remove this requirement for this as it does not need to mutate it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think get_current_time needs mut state, but we would need to pass the borrowed reference, e.g.:

let current_time = get_current_time(&ctx.accounts.state)?;


if !ctx.accounts.route.enabled {
return err!(CommonError::DisabledRoute);
}

let current_time = get_current_time(state)?;

let fill_deadline = current_time + fill_deadline_offset;

if fill_deadline < current_time || fill_deadline > current_time + state.fill_deadline_buffer {
return err!(CommonError::InvalidFillDeadline);
}

let transfer_accounts = TransferChecked {
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(),
};
let cpi_context = CpiContext::new(ctx.accounts.token_program.to_account_info(), transfer_accounts);
transfer_checked(cpi_context, input_amount, ctx.accounts.mint.decimals)?;

state.number_of_deposits += 1; // Increment number of deposits

emit_cpi!(V3FundsDeposited {
deposit_v3(
ctx,
depositor,
recipient,
input_token,
output_token,
input_amount,
output_amount,
destination_chain_id,
deposit_id: state.number_of_deposits,
quote_timestamp: current_time,
fill_deadline,
exclusivity_deadline: current_time + exclusivity_period,
depositor,
recipient,
exclusive_relayer,
current_time,
current_time + fill_deadline_offset,
exclusivity_period,
message,
});
)?;

Ok(())
}
2 changes: 1 addition & 1 deletion test/svm/SvmSpoke.Deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { provider, connection, program, owner, seedBalance, initializeState, depo
const { createRoutePda, getVaultAta, assertSE, assert, getCurrentTime, depositQuoteTimeBuffer, fillDeadlineBuffer } =
common;

describe.only("svm_spoke.deposit", () => {
describe("svm_spoke.deposit", () => {
anchor.setProvider(provider);

const depositor = Keypair.generate();
Expand Down
Loading