Skip to content

feat(pegged-swap): raise linearWidth (A) cap to 5000#75

Merged
rharutyunyan merged 2 commits into
1inch:masterfrom
Kolesnikim:feat/peggedswap-a-cap-5000
Jun 15, 2026
Merged

feat(pegged-swap): raise linearWidth (A) cap to 5000#75
rharutyunyan merged 2 commits into
1inch:masterfrom
Kolesnikim:feat/peggedswap-a-cap-5000

Conversation

@Kolesnikim

Copy link
Copy Markdown
Contributor

Change Summary

Raise the PeggedSwap linearWidth (amplification A) cap in @1inch/swap-vm-sdk from A <= 2 to A <= 5000, mirroring the swap-vm contract changes in release/1.0:

The SDK was the last piece still capping at A <= 2, which made any pegged band tighter than ±20% throw. With A <= 5000, the representable symmetric half-width X = 1 / (2A + 1) drops to ~±0.01%, unlocking tight pegs (stablecoin / wrapped-asset pairs).

What changed

  • pegged-swap-math.ts: MAX_LINEAR_WIDTH 2n -> 5000n * PEGGED_SWAP_ONE (the A = (1 - X) / (2X) / X = 1 / (2A + 1) formulas are unchanged - only the representable range widens).
  • pegged-swap-args.ts: the PeggedSwapArgs constructor now reuses the shared MAX_LINEAR_WIDTH instead of a hardcoded 2n * 10n ** 27n.
  • Tests retargeted to the new cap/floor (20% -> A=2; 0.01% floor -> 4999.5e27; reject sub-floor widths; MAX -> ~0.009999%; args throw at 5000e27).
  • Bump @1inch/swap-vm-sdk 0.1.5 -> 0.1.6.

Testing & Verification

  • Unit tests (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 (5000 on release/1.0).

Made with Cursor

Kolesnikim and others added 2 commits June 15, 2026 14:44
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>
@sonarqubecloud

Copy link
Copy Markdown

@rharutyunyan rharutyunyan merged commit 5f676cd into 1inch:master Jun 15, 2026
2 checks passed
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.

2 participants