Skip to content

test(swap-vm): concentrated liquidity single-sided position tests at 1800 USDC/WETH market price#77

Draft
krboktv wants to merge 1 commit into
masterfrom
cursor/concentrated-liquidity-single-side-test-f6ff
Draft

test(swap-vm): concentrated liquidity single-sided position tests at 1800 USDC/WETH market price#77
krboktv wants to merge 1 commit into
masterfrom
cursor/concentrated-liquidity-single-side-test-f6ff

Conversation

@krboktv

@krboktv krboktv commented Jul 10, 2026

Copy link
Copy Markdown
Member

Summary

Adds test coverage for concentrated liquidity single-sided positions with the market price at 1800 USDC per WETH — positions where the whole price range sits on one side of the market, so the LP deposits only one token (Uniswap V3-style limit-order liquidity).

Unit tests

price-range.test.ts — new single-sided positions (1800 USDC per WETH market price) block:

  • computeMaxAllocation for a 1800–2200 range above the market allocates WETH only (USDC reserve is exactly 0)
  • computeMaxAllocation for a 1500–1800 range below the market allocates USDC only (WETH reserve is exactly 0)
  • computeFixedAllocation single-sided equivalents for both ranges
  • spot price recovery via fromPriceBounds from a USDC-only allocation returns exactly 1800

concentrate-liquidity-math.test.ts — new single-sided position at 1800 USDC per WETH market price block:

  • computeLiquidityFromAmounts with spot at the sqrt max bound (range above market) yields actualLt = 0 (WETH-only)
  • computeLiquidityFromAmounts with spot at the sqrt min bound (range below market) yields actualGt = 0 (USDC-only)
  • computeLiquidityAndPrice recovers the spot at the range bound from single-sided (one-token) balances for both cases

E2E tests (tests/swap-vm.spec.ts)

Two fork-based tests over AquaXYCAmmStrategy.newConcentrate:

  1. WETH-only position, 1800–2200 range, market 1800 (USDC → WETH) — ships the strategy with 0 USDC / ~400 WETH, verifies the wrong-direction swap (WETH → USDC) reverts on-chain since the position holds no USDC, then swaps 1800 USDC and gets ~1 WETH at an effective price of 1800.4296 (right at the bound plus slippage).
  2. USDC-only position, 1500–1800 range, market 1800 (WETH → USDC) — mirror case: ships ~1M USDC / 0 WETH, verifies USDC → WETH reverts, then sells 1 WETH for 1799.717746 USDC.

Both tests also assert that both tokens must still be registered in the Aqua strategy (the empty side is shipped with amount 0), because Aqua.safeBalances reverts with SafeBalancesForTokenNotInActiveStrategy otherwise.

Note: at the range boundary the price bounds must be passed in sqrt(P) order (higher human USDC-per-WETH quote = lower sqrt) — PriceRange.new cannot normalize human-ordered bounds when spot coincides with a bound; the tests document this with comments.

Verification

  • Unit: 601 passed (592 baseline + 9 new) — pnpm vitest run in typescript/swap-vm
  • Lint + type-check: pass
  • E2E: both new tests pass against an anvil mainnet fork
Open in Web Open in Cursor 

… at 1800 USDC/WETH market price

Co-authored-by: Kirill <krboktv@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

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