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

feat: depositNow #712

merged 10 commits into from
Nov 4, 2024

Conversation

chrismaree
Copy link
Member

@chrismaree chrismaree commented Oct 31, 2024

Adds Deposit Now, fixes 2 todos and addresses one small bug found.

Signed-off-by: chrismaree <[email protected]>
Signed-off-by: chrismaree <[email protected]>
Signed-off-by: chrismaree <[email protected]>
@@ -79,7 +74,7 @@ pub fn deposit_v3(
exclusive_relayer: Pubkey,
quote_timestamp: u32,
fill_deadline: u32,
exclusivity_deadline: u32,
exclusivity_period: u32,
Copy link
Member Author

Choose a reason for hiding this comment

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

we had miss-named this prop! the implementation was correct but the variable name was wrong. see

uint32 exclusivityPeriod,

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we had it correct initially, but EVM implementation had changed since here

Copy link
Member Author

Choose a reason for hiding this comment

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

on master EVM implementation it's still called exclusivityPeriod

so I think as it is now we are consistent?

// overflow (from devnet testing). add a test to re-create this and fix it such that the error is thrown,
// not caught via overflow.
if current_time - quote_timestamp > state.deposit_quote_time_buffer {
if current_time.checked_sub(quote_timestamp).unwrap_or(u32::MAX) > state.deposit_quote_time_buffer {
Copy link
Member Author

Choose a reason for hiding this comment

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

if checked_sub underflows then it defaults to the unwrap_or value, of u32::MAX, forcing the if to return true, and throwing the error. This fixes the TODO above that I saw on testnet (and validated in unit tests).

Copy link
Contributor

Choose a reason for hiding this comment

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

note that EVM implementation has the same underflow issue, so we might fix it there too

Copy link
Member Author

Choose a reason for hiding this comment

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

in the evm implementation if it fails at that point does it revert with an underflow error or does it throw the associated revert message that we are expecting?

Copy link
Contributor

Choose a reason for hiding this comment

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

as per this comment, it would underflow in EVM

Copy link
Member Author

@chrismaree chrismaree Nov 4, 2024

Choose a reason for hiding this comment

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

right but my question was would it throw the error InvalidQuoteTimestamp or underflow. it seems it will throw with underflow (see here).

my original point is that this is actually a bit confusing for a caller. there are situations where multiple invalid input values return the same error. equally, there are situations where some invalid input values, depending on the input, return inconsistent errors.

I agree with your original reply that we should fix this consistently, changing the evm implementation such that all invalid errors return the same error.

@@ -17,12 +17,7 @@ use crate::{
output_token: Pubkey,
input_amount: u64,
output_amount: u64,
destination_chain_id: u64, // TODO: we can remove some of these instructions props
Copy link
Member Author

Choose a reason for hiding this comment

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

we dont need the extra fields here in the instructions. also, be removing them, we could re-use this DepositV3 context for the depositNow method.

Copy link
Contributor

@Reinis-FRP Reinis-FRP Nov 4, 2024

Choose a reason for hiding this comment

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

We def better call deposit_v3 from deposit_v3_now, same as its done in EVM

Copy link
Member Author

Choose a reason for hiding this comment

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

Originally before removing the extra instructions, I was not able to re-call deposit_v3. I've now tried again and with the removed extra instructions (in particular, the ones missing when calling deposit_v3_now) I was able to re-use the original deposit_v3 method. take a look again.

const fillDeadline = new BN(Math.floor(Date.now() / 1000) + 600); // 600 seconds from now.
const exclusivityDeadline = new BN(Math.floor(Date.now() / 1000) + 300); // 300 seconds from now.
const exclusivityPeriod = new BN(300); // 300 seconds.
Copy link
Member Author

Choose a reason for hiding this comment

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

this update applies to match the EVM changes and the correct input prop and how it's meant to be used.

Signed-off-by: chrismaree <[email protected]>
Signed-off-by: chrismaree <[email protected]>
@chrismaree chrismaree marked this pull request as ready for review November 1, 2024 10:57
Signed-off-by: chrismaree <[email protected]>
Signed-off-by: chrismaree <[email protected]>
Comment on lines 138 to 140
if !ctx.accounts.route.enabled {
return err!(CommonError::DisabledRoute);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is redundant as this uses DepositV3 context that already checked the route.

Copy link
Contributor

Choose a reason for hiding this comment

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

and we better not reimplement the deposit_v3 logic here, but call it internally

@@ -15,7 +15,7 @@ const { provider, connection, program, owner, seedBalance, initializeState, depo
const { createRoutePda, getVaultAta, assertSE, assert, getCurrentTime, depositQuoteTimeBuffer, fillDeadlineBuffer } =
common;

describe("svm_spoke.deposit", () => {
describe.only("svm_spoke.deposit", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove only

Signed-off-by: chrismaree <[email protected]>
@@ -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)?;

Signed-off-by: chrismaree <[email protected]>
Copy link
Contributor

@Reinis-FRP Reinis-FRP left a comment

Choose a reason for hiding this comment

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

cool!

Signed-off-by: chrismaree <[email protected]>
@chrismaree chrismaree merged commit 2e468e5 into master Nov 4, 2024
9 checks passed
@chrismaree chrismaree deleted the chrismaree/deposit-now branch November 4, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants