Skip to content

feat(pool): add deadline guard to swap entrypoint (#107) - #110

Merged
0takuc0mrade merged 1 commit into
Nodus-protocol:mainfrom
fadesany:deadline_guard
Jul 23, 2026
Merged

feat(pool): add deadline guard to swap entrypoint (#107)#110
0takuc0mrade merged 1 commit into
Nodus-protocol:mainfrom
fadesany:deadline_guard

Conversation

@fadesany

Copy link
Copy Markdown
Contributor

Problem

Every other state-changing entrypoint in the pool contract accepts a deadline: u64 and rejects stale transactions with Error::Expired:

  • add_liquidity
  • remove_liquidity
  • swap_exact_tokens_for_tokens
  • swap_tokens_for_exact_tokens

But the raw swap entrypoint had no deadline parameter, leaving it vulnerable to stale/front-runnable transactions.

Changes

  1. contracts/pool/src/lib.rs — Added deadline: u64 parameter to swap and the 3-line timestamp guard (if env.ledger().timestamp() > deadline { return Err(Error::Expired); }) before lock(), matching the existing pattern in the other four entrypoints.

  2. contracts/pool/tests/integration_tests.rs — Added expired_swap_rejected test (timestamp 5_000, deadline 1_000, asserts .is_err()), mirroring expired_remove_liquidity_rejected. Updated all existing try_swap callers to pass &u64::MAX.

  3. contracts/pool/tests/unit_tests.rs — Updated the one try_swap caller to pass &u64::MAX.

Closes #107

- 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
@0takuc0mrade
0takuc0mrade merged commit ab98725 into Nodus-protocol:main Jul 23, 2026
3 checks passed
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.

safety: low-level swap() has no deadline guard, unlike every other mutating entrypoint

2 participants