feat(pool): add deadline guard to swap entrypoint (#107) - #110
Merged
Conversation
- Added parameter to to reject stale transactions - Added guard before , consistent with other entrypoints - Added integration test mirroring - Updated all existing test callers of to pass Closes Nodus-protocol#107
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every other state-changing entrypoint in the pool contract accepts a
deadline: u64and rejects stale transactions withError::Expired:add_liquidityremove_liquidityswap_exact_tokens_for_tokensswap_tokens_for_exact_tokensBut the raw
swapentrypoint had no deadline parameter, leaving it vulnerable to stale/front-runnable transactions.Changes
contracts/pool/src/lib.rs— Addeddeadline: u64parameter toswapand the 3-line timestamp guard (if env.ledger().timestamp() > deadline { return Err(Error::Expired); }) beforelock(), matching the existing pattern in the other four entrypoints.contracts/pool/tests/integration_tests.rs— Addedexpired_swap_rejectedtest (timestamp5_000, deadline1_000, asserts.is_err()), mirroringexpired_remove_liquidity_rejected. Updated all existingtry_swapcallers to pass&u64::MAX.contracts/pool/tests/unit_tests.rs— Updated the onetry_swapcaller to pass&u64::MAX.Closes #107