feat(pegged-swap): raise linearWidth (A) cap to 5000#75
Merged
rharutyunyan merged 2 commits intoJun 15, 2026
Conversation
Mirror swap-vm contract PRs #123/#127 (release/1.0) which raised the PeggedSwap amplification cap from A<=2 to A<=5000. This unlocks tight pegged bands down to ~+/-0.01% half-width (X = 1/(2A+1)). - MAX_LINEAR_WIDTH: 2 -> 5000 * PEGGED_SWAP_ONE - PeggedSwapArgs reuses the shared MAX_LINEAR_WIDTH (was hardcoded 2e27) - tests updated to the new cap / floor - bump @1inch/swap-vm-sdk 0.1.5 -> 0.1.6 Co-authored-by: Cursor <cursoragent@cursor.com>
|
rharutyunyan
approved these changes
Jun 15, 2026
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.



Change Summary
Raise the PeggedSwap
linearWidth(amplificationA) cap in@1inch/swap-vm-sdkfromA <= 2toA <= 5000, mirroring the swap-vm contract changes inrelease/1.0:2 -> 500500 -> 5000The SDK was the last piece still capping at
A <= 2, which made any pegged band tighter than±20%throw. WithA <= 5000, the representable symmetric half-widthX = 1 / (2A + 1)drops to~±0.01%, unlocking tight pegs (stablecoin / wrapped-asset pairs).What changed
pegged-swap-math.ts:MAX_LINEAR_WIDTH2n -> 5000n * PEGGED_SWAP_ONE(theA = (1 - X) / (2X)/X = 1 / (2A + 1)formulas are unchanged - only the representable range widens).pegged-swap-args.ts: thePeggedSwapArgsconstructor now reuses the sharedMAX_LINEAR_WIDTHinstead of a hardcoded2n * 10n ** 27n.20% -> A=2;0.01% floor -> 4999.5e27; reject sub-floor widths;MAX -> ~0.009999%; args throw at5000e27).@1inch/swap-vm-sdk0.1.5 -> 0.1.6.Testing & Verification
vitest) updated for the new cap/floor and the percent <-> linearWidth round-trips.Risk
Low-to-medium: widens an input bound; no change to the invariant/solver or the 160-byte args encoding. Curvature stays
p = 0.5. The cap must match the deployed contract bound (5000onrelease/1.0).Made with Cursor