Repository navigation
fix(swap): Respect slippagePct in AssetHub getAmountOut 🔧 - #2565
Closed
nunndayox-stack wants to merge 2 commits into
Closed
nunndayox-stack wants to merge 2 commits into
nunndayox-stack wants to merge 2 commits into
Conversation
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
Contributor
|
Dear @nunndayox-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, |
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.
🐞 Bug Fix Pull Request
📌 Related Issue
Closes #2309
🛠️ Description of the Fix
Bug description:
On AssetHub,
getAmountOutignored theslippagePctoption 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.getAmountOutnow destructuresslippagePct = '0'and returnspadValueBy(amountOut, -slippageMultiplier)— exactly the Hydration implementation's treatment — so one change fixes both the quote path and the execute path.padValueBywas already imported in the file. Tests: the sharedbaseOptionsinAssetHubExchange.test.tscarriesslippagePct: '5', so the fivegetAmountOutexpectations 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
Reasonable(verifiable via Subscan).-S) and includesSigned-off-byandAI-Assisted-By: <tool name(s)>(orAI-Assisted-By: None) trailers.✅ Checklist
tsc --noEmitclean for@paraspell/swap)applies slippagePct to the quoted amounttest; the five existing expectations updated from raw quotes to slippage-adjusted values. Mutation check: reverting onlyAssetHubExchange.tsmakes exactly those 6 tests fail.)@paraspell/swapsuite 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.
🧩 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).@paraspell/swapsuite: 60 test files / 376 tests, all pass.AssetHubExchange.tsmakes exactly the 6 slippage-related tests fail (11 others still pass), confirming the updated expectations pin the bug.swapCurrencyalready applied slippage toamount_out_minand 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-Bytrailer 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 includeSigned-off-byandAI-Assisted-Bytrailers 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.