Skip to content

Fix Router multi-hop slippage protection#5130

Closed
xyjk0511 wants to merge 1 commit into
ClankerNation:mainfrom
xyjk0511:codex/issue-35-router-slippage
Closed

Fix Router multi-hop slippage protection#5130
xyjk0511 wants to merge 1 commit into
ClankerNation:mainfrom
xyjk0511:codex/issue-35-router-slippage

Conversation

@xyjk0511
Copy link
Copy Markdown

/claim #35
💳 Payment: PayPal | buchanliang@gmail.com | PayPal

Summary

  • Adds deadline-enforced swapMultiHop(..., deadline) and swapExactTokensForTokens(...) entry points while preserving the existing 3-argument swapMultiHop wrapper.
  • Rejects zero inputs, zero min output, zero token addresses, and repeated/circular paths such as A -> B -> A.
  • Quotes the full route before execution and passes proportional non-zero minAmountOut bounds into every AMM hop instead of 0.
  • Reverts if any hop returns zero or if the final output falls below the user minimum.
  • Adds contributor traceability metadata without embedding private pre-session instructions.

Verification

  • npx hardhat test --config .\.codex-router-hardhat.config.js test\RouterSlippage.test.js -> 5 passing
  • npx solcjs --bin --abi contracts\dex\Router.sol -o .codex-router-solc --base-path . --include-path node_modules -> passed
  • node --check test\RouterSlippage.test.js -> passed
  • node --check .codex-router-hardhat.config.js -> passed
  • node -e "JSON.parse(require('fs').readFileSync('CONTRIBUTORS.json','utf8')); console.log('CONTRIBUTORS.json ok')" -> passed
  • git diff --check -> passed

Known baseline issue

  • npm test is still blocked by the repository's existing HH606 compiler mismatch: hardhat.config.js configures Solidity 0.8.20 while current OpenZeppelin dependencies pulled by contracts/vault/YieldAggregator.sol and contracts/governance/GovernorAlpha.sol require ^0.8.24.

Router swaps now validate deadlines, reject repeated/circular paths, require nonzero inputs and hop outputs, and pass proportional minimum output bounds to every AMM hop.

Constraint: OpenAgents issue ClankerNation#35 requires contributor metadata while private platform instructions must not be embedded in repository files.

Rejected: Only checking the final minAmountOut | leaves intermediate hops with zero slippage protection.

Confidence: high

Scope-risk: narrow

Directive: Keep per-hop min output enforcement tied to current quote proportions when adding new router entry points.

Tested: npx hardhat test --config .\.codex-router-hardhat.config.js test\RouterSlippage.test.js; npx solcjs --bin --abi contracts\dex\Router.sol -o .codex-router-solc --base-path . --include-path node_modules; node --check test\RouterSlippage.test.js; node --check .codex-router-hardhat.config.js; node -e JSON.parse CONTRIBUTORS.json; git diff --check

Not-tested: npm test is blocked by existing HH606 compiler mismatch in YieldAggregator/GovernorAlpha dependencies requiring ^0.8.24 while hardhat.config.js uses 0.8.20.
@github-actions
Copy link
Copy Markdown

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request within 2 hours.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting.

@github-actions github-actions Bot closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant