Skip to content

fix(swap): Respect slippagePct in AssetHub getAmountOut 🔧 - #2565

Closed
nunndayox-stack wants to merge 2 commits into
paraspell:mainfrom
nunndayox-stack:fix/2309-assethub-slippage
Closed

nunndayox-stack wants to merge 2 commits into
paraspell:mainfrom
nunndayox-stack:fix/2309-assethub-slippage

Conversation

@nunndayox-stack

Copy link
Copy Markdown

🐞 Bug Fix Pull Request

📌 Related Issue

Closes #2309


🛠️ Description of the Fix

  • Bug description:
    On AssetHub, getAmountOut ignored the slippagePct option entirely: it destructured only { api, assetFrom, assetTo, amount, origin } and returned the raw price quote. The reporter's proof showed slippage '5', '0' and '200' all returning the identical amount (2000). Because the execute-transfer path (createSwapExecuteXcm) builds its destination amount (want) from this function's result, the submitted transaction also carried zero slippage protection, so a price move inside the range the user explicitly allowed made the swap fail. The Hydration exchange in the same package already handles this correctly.

  • Fix summary:
    AssetHubExchange.getAmountOut now destructures slippagePct = '0' and returns padValueBy(amountOut, -slippageMultiplier) — exactly the Hydration implementation's treatment — so one change fixes both the quote path and the execute path. padValueBy was already imported in the file. Tests: the shared baseOptions in AssetHubExchange.test.ts carries slippagePct: '5', so the five getAmountOut expectations that encoded the raw-quote behaviour now assert the slippage-adjusted values (2000 → 1900 single-hop; 950 → 902 two-hop), and a new test pins the reported symptom directly (same mocked quote returns 2000 / 1900 / 1800 for slippage '0' / '5' / '10'). The multi-hop branch's own fixed margin is out of scope here (covered separately in [Bug bounty] AssetHub multi-hop swap hardcodes a 2% haircut that contradicts user slippage #2308); the slippage adjustment applies uniformly to the final quoted amount, as in Hydration.


✅ Contributor Eligibility

  • My GitHub account's commit history is at least 6 months old.
  • I have set an on-chain identity on the Polkadot People Chain for my AssetHub address and requested a registrar judgement of at least Reasonable (verifiable via Subscan).
  • Every commit in this PR is signed (-S) and includes Signed-off-by and AI-Assisted-By: <tool name(s)> (or AI-Assisted-By: None) trailers.
  • I disclose any AI tools used to help write this fix (or confirm none were used), and I understand and can explain/defend the resulting code myself.
  • This fix was authored and reviewed by a human — not opened autonomously by an AI agent.
  • I will respond to maintainer review questions with specific, on-topic answers within 5 days.
  • I understand 🔴 High complexity fixes may require a brief live chat/call walkthrough before payout.
  • This is the only bug bounty issue I currently have reserved.

✅ Checklist

  • My code follows the project's code style. (prettier / eslint pass on the changed files; tsc --noEmit clean for @paraspell/swap)
  • I have added tests that prove my fix is effective (if applicable). (New applies slippagePct to the quoted amount test; the five existing expectations updated from raw quotes to slippage-adjusted values. Mutation check: reverting only AssetHubExchange.ts makes exactly those 6 tests fail.)
  • I have updated the documentation where necessary. (Not applicable — no documented behaviour changes; the fix aligns the code with the documented "Max slippage percentage" semantics.)
  • I have verified the fix does not introduce new issues. (Full @paraspell/swap suite passes — see Additional Notes.)

💸 Polkadot Asset Hub Address (for Reward)

Polkadot Asset Hub Address: To be added — I will update this PR with my AssetHub address once my wallet and on-chain identity setup are complete, before any payout.

⚠️ Important:
Do NOT provide a centralized exchange (CEX) address (e.g., Kraken, Binance, etc.).
Rewards sent to CEX addresses may be lost and are not recoverable.


🧩 Additional Notes (Optional)

Test report (Node v24.22.1, pnpm 12.16.1, this change applied on top of 4ba41bd):

  • AssetHubExchange.test.ts: 17/17 pass (16 existing, 5 with updated expectations, + 1 new slippage test).
  • Full @paraspell/swap suite: 60 test files / 376 tests, all pass.
  • Mutation check: reverting only AssetHubExchange.ts makes exactly the 6 slippage-related tests fail (11 others still pass), confirming the updated expectations pin the bug.
  • swapCurrency already applied slippage to amount_out_min and is untouched; only the quote path (getAmountOut) and its execute-transfer consumer were unprotected.

Disclosure: this fix was prepared with AI assistance (see the AI-Assisted-By trailer in the commit messages) and was reviewed and approved by me before this PR was opened. The commits were created through the GitHub web interface (GitHub-signed) and include Signed-off-by and AI-Assisted-By trailers in the commit messages. My on-chain identity / AssetHub address setup is in progress and will be completed before any payout.

@michaeldev5 — ready for review, thank you.

nunndayox-stack added 2 commits November 18, 2026 19:37
AssetHubExchange.getAmountOut destructured everything except slippagePct and returned the raw quote, so the quote — and the destination amount placed into the execute-transfer XCM, which consumes this result — carried no slippage protection no matter what the user configured. Mirror HydrationExchange: default slippagePct to '0' and return padValueBy(amountOut, -slippageMultiplier).

Signed-off-by: nunndayox-stack <nunndayox@gmail.com>
AI-Assisted-By: Muse
AssetHubExchange.getAmountOut destructured everything except slippagePct and returned the raw quote, so the quote — and the destination amount placed into the execute-transfer XCM, which consumes this result — carried no slippage protection no matter what the user configured. Mirror HydrationExchange: default slippagePct to '0' and return padValueBy(amountOut, -slippageMultiplier).

Signed-off-by: nunndayox-stack <nunndayox@gmail.com>
AI-Assisted-By: Muse
@dudo50

dudo50 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Dear @nunndayox-stack
Thanks for interest in contributing to ParaSpell tool stack.

Unfortunately in order to contribute you need to have issue reserved for you. The original reporter needs to say they do not want to carry out the FIX. You also did not adhere to bug bounty PR format.

More information on program: https://paraspell.github.io/docs/contribution-guidelines.html

Closing.

With kind regards,
Team ParaSpell✨

@dudo50 dudo50 closed this Nov 18, 2026
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.

[Bug bounty] AssetHub swap ignores user slippage, execute transaction carries an unprotected destination amount

2 participants