-
Notifications
You must be signed in to change notification settings - Fork 58
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
feat: depositNow #712
Changes from 9 commits
62a2bcd
f0e97d2
0d08332
544b7cd
d53b4fb
27e5cd3
bbf077e
5c3b2c1
3c083d1
5b8aaf8
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 |
---|---|---|
|
@@ -74,17 +74,14 @@ pub fn deposit_v3( | |
exclusive_relayer: Pubkey, | ||
quote_timestamp: u32, | ||
fill_deadline: u32, | ||
exclusivity_deadline: u32, | ||
exclusivity_period: u32, | ||
message: Vec<u8>, | ||
) -> Result<()> { | ||
let state = &mut ctx.accounts.state; | ||
|
||
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 | ||
// 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 { | ||
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. if 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. note that EVM implementation has the same underflow issue, so we might fix it there too 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. 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? 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. as per this comment, it would underflow in EVM 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. right but my question was would it throw the error 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. |
||
return err!(CommonError::InvalidQuoteTimestamp); | ||
} | ||
|
||
|
@@ -112,7 +109,7 @@ pub fn deposit_v3( | |
deposit_id: state.number_of_deposits, | ||
quote_timestamp, | ||
fill_deadline, | ||
exclusivity_deadline, | ||
exclusivity_deadline: current_time + exclusivity_period, | ||
depositor, | ||
recipient, | ||
exclusive_relayer, | ||
|
@@ -121,3 +118,37 @@ pub fn deposit_v3( | |
|
||
Ok(()) | ||
} | ||
|
||
pub fn deposit_v3_now( | ||
ctx: Context<DepositV3>, | ||
depositor: Pubkey, | ||
recipient: Pubkey, | ||
input_token: Pubkey, | ||
output_token: Pubkey, | ||
input_amount: u64, | ||
output_amount: u64, | ||
destination_chain_id: u64, | ||
exclusive_relayer: Pubkey, | ||
fill_deadline_offset: u32, | ||
exclusivity_period: u32, | ||
message: Vec<u8>, | ||
) -> Result<()> { | ||
let current_time = get_current_time(ctx.accounts.state)?; | ||
deposit_v3( | ||
ctx, | ||
depositor, | ||
recipient, | ||
input_token, | ||
output_token, | ||
input_amount, | ||
output_amount, | ||
destination_chain_id, | ||
exclusive_relayer, | ||
current_time, | ||
current_time + fill_deadline_offset, | ||
exclusivity_period, | ||
message, | ||
)?; | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,9 @@ const exclusiveRelayer = Keypair.generate().publicKey; | |
const outputToken = new PublicKey("1111111111113EsMD5n1VA94D2fALdb1SAKLam8j"); // TODO: this is lazy. this is cast USDC from Eth mainnet. | ||
const inputAmount = new BN(500000); | ||
const outputAmount = inputAmount; | ||
const quoteTimestamp = new BN(Math.floor(Date.now() / 1000) - 10); // 10 seconds ago. | ||
const quoteTimestamp = new BN(Math.floor(Date.now() / 1000) - 60); // 60 seconds ago. | ||
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. | ||
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 update applies to match the EVM changes and the correct input prop and how it's meant to be used. |
||
const message = Buffer.from("Test message"); | ||
const depositQuoteTimeBuffer = new BN(3600); // 1 hour. | ||
const fillDeadlineBuffer = new BN(3600 * 4); // 4 hours. | ||
|
@@ -90,7 +90,11 @@ async function getCurrentTime(program: Program<SvmSpoke>, state: any) { | |
} | ||
|
||
function assertSE(a: any, b: any, errorMessage: string) { | ||
assert.strictEqual(a.toString(), b.toString(), errorMessage); | ||
if (a === undefined || b === undefined) { | ||
throw new Error("Undefined value" + errorMessage); | ||
} else { | ||
assert.strictEqual(a.toString(), b.toString(), errorMessage); | ||
} | ||
} | ||
|
||
interface DepositData { | ||
|
@@ -104,7 +108,7 @@ interface DepositData { | |
exclusiveRelayer: PublicKey; | ||
quoteTimestamp: BN; | ||
fillDeadline: BN; | ||
exclusivityDeadline: BN; | ||
exclusivityPeriod: BN; | ||
message: Buffer; | ||
} | ||
|
||
|
@@ -141,7 +145,7 @@ export const common = { | |
outputAmount, | ||
quoteTimestamp, | ||
fillDeadline, | ||
exclusivityDeadline, | ||
exclusivityPeriod, | ||
message, | ||
depositQuoteTimeBuffer, | ||
fillDeadlineBuffer, | ||
|
@@ -163,7 +167,7 @@ export const common = { | |
exclusiveRelayer, | ||
quoteTimestamp, | ||
fillDeadline, | ||
exclusivityDeadline, | ||
exclusivityPeriod, | ||
message, | ||
} as DepositData, | ||
}; |
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.
we had miss-named this prop! the implementation was correct but the variable name was wrong. see
contracts/contracts/SpokePool.sol
Line 489 in 31693cd
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.
I think we had it correct initially, but EVM implementation had changed since here
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.
on master EVM implementation it's still called exclusivityPeriod
so I think as it is now we are consistent?