Skip to content

Fix/swap hardening - #672

Merged
Topmatrixmor2014 merged 13 commits into
FinChippay:mainfrom
sebas11042:fix/swap-hardening
Aug 19, 2026
Merged

Fix/swap hardening#672
Topmatrixmor2014 merged 13 commits into
FinChippay:mainfrom
sebas11042:fix/swap-hardening

Conversation

@sebas11042

Copy link
Copy Markdown
Contributor

Summary

Hardens the in-contract swap path against fee-on-transfer inputs, stale/malformed paths, slippage edge cases, and protocol-fee accounting. Adds a dedicated swap hardening test suite and updates contract/shared error docs.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / chore
  • Smart contract change

Related issue

Closes #626

Changes

  • Measure the actual amount received by the contract for swaps and compute output/protocol fee from that delta, protecting fee-on-transfer inputs.
  • Reject malformed/stale swap paths, including repeated tokens, zero-liquidity hops, and insufficient output reserves.
  • Refine exact-output swaps to respect max_amount_in under rounding and fee-on-transfer top-ups.
  • Emit richer swap events with requested input, actual input, output, fee, and path length.
  • Add tests/swap_hardening.rs with 19 tests covering fee-on-transfer, slippage, rounding, stale paths, rollback behavior, fee collector accounting, dust, and large values.
  • Map swap-related ContractError codes in the shared error catalog and regenerate error-code docs.
  • Update swap/contract documentation for measured inputs and hardened path behavior.

Testing

  • Tested locally on Testnet
  • Added/updated unit tests
  • Manually tested UI flow

Local checks run:

cargo +stable fmt --check
cargo +stable clippy -- -D warnings
cargo +stable test
cargo +stable check --target wasm32v1-none
cargo +stable build --target wasm32v1-none --release
cargo audit
node scripts/generate-error-codes-doc.js --check
node smoke check for swap ContractError mappings

## Screenshots (if UI change)

<!-- Add before/after screenshots -->

## Checklist

- [x] My code follows the project style
- [x] I've updated docs if needed
- [x] No console errors or warnings
- [x] I've rebased on latest `main`

@github-actions github-actions Bot added the needs-review PR ready for Greptile AI code review label Aug 18, 2026
@github-actions

Copy link
Copy Markdown

🤖 Greptile AI Code Review

Greptile will automatically review this PR (18 file(s) changed).

Review gates:

  • ✅ CodeQL Security Scan
  • ✅ Custom rules (.greptile/config.json)
  • ✅ Architecture guidelines (.greptile/rules.md)

To manually trigger a re-review, comment @greptileai on this PR.
To skip review, add the skip-review label.

@Topmatrixmor2014
Topmatrixmor2014 merged commit 5577ae9 into FinChippay:main Aug 19, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review PR ready for Greptile AI code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue #57 — Swap/DEX Hardening: Fee-on-Transfer Tokens, Stale Path Prices & Slippage Tests

2 participants