Skip to content

feat: migrate shield-swap-sdk to the new shield_swap.aleo stack - #62

Open
iamalwaysuncomfortable wants to merge 22 commits into
masterfrom
feat/shield-swap-update
Open

feat: migrate shield-swap-sdk to the new shield_swap.aleo stack#62
iamalwaysuncomfortable wants to merge 22 commits into
masterfrom
feat/shield-swap-update

Conversation

@iamalwaysuncomfortable

Copy link
Copy Markdown
Member

Migrates shield-swap-sdk from the retired shield_swap_v3.aleo to the freshly deployed shield_swap.aleo stack, per the migration guide (amm-v3#62 target). Hard cutover — no state carries over.

Contract cutover

  • Wire layer regenerated from deployed testnet bytecode: PROGRAM_ID = shield_swap.aleo; U256 {hi, lo} prices, MerkleProof struct, PositionNFT.withdrawal, reshaped PoolState/Slot/Tick/Position/SwapOutput, new compliance records; claim_multi_hop_output and set_token_decimals gone.
  • Q128.128 math: new _MAGIC_X128 tick table + MIN/MAX_SQRT_RATIO_X128 pinned from the contract and verified against the reference implementation (f(±400000) matches exactly); u256_to_int / int_to_u256_plaintext helpers.
  • Raw native amounts end to end: no dust rule, no 9-decimal normalization; SlotView.price re-derived; collect_all requests exactly the chain-reported owed amounts.
  • Freezelist proofs: mint / claim_swap_output / collect carry [MerkleProof; 2] arrays — empty-tree defaults while the lists are empty, wrapper_proofs= override for later.
  • Immutable withdrawal: mint(withdrawal=…) (defaults to recipient) is stored on the NFT; collect always pays it — the recipient kwarg is removed.
  • Blinding: CLAIM_OR_SWAP_DOMAIN unchanged in the new bytecode; only DEFAULT_PROGRAM flips (v3 vectors kept as algorithm tests, new-program vectors pinned).

Automatic router dispatch

Every verb detects each token's wrapped/plain shape (from_wrapper_token_id chain probe, cached; transport errors propagate rather than misclassifying) and dispatches per the guide's §6 matrix:

  • swap → shield_swap_router.swap_from_wrapped when the input is wrapped (funded with underlying records; deposit + burn happen in-transaction; amount_out_min > 0 enforced at prepare time)
  • claim → 4-way dispatch on the finalized SwapOutput shapes (covers the plain-start/wrapped-claim asymmetry)
  • mint/increase/collect → the 11 LP-router transitions, wrapper proofs interleaved per the deployed input orders
  • decrease/burn → always direct

Record selection understands credits.aleo (microcredits) and skips recipient-bound wrapper records. Mirrored in AsyncShieldSwap.

Supporting changes

  • aleo.codegen (main SDK): fixed-length Array ABI type support (fmt_array, toposort/ref-check recursion into array elements).
  • API layer → staging: DEFAULT_API_URL and regen default now https://amm-api-staging.dev.provable.com (SHIELD_SWAP_API_URL override); models regenerated (wrapper_programamm_token_program, new underlying_program/underlying_token_id drive record-program resolution); redeem no longer rotates the session credential.
  • Devnode harness: deploys the new 5-program stack (core + multisig + freezelist + 2 test tokens), initializes the freezelist, registers plain tokens via the two-arg allow_token with idempotent bootstrap.

Verification

  • shield-swap-sdk unit suite: 171 passed
  • main SDK suite: 905 passed (includes codegen Array coverage)
  • live read + drift tier (real testnet + staging API): 11 passed — pinned ABI matches deployed bytecode, X128 invariants on live slots, local pool/tick key derivation parity, registry↔chain wrapped-detection agreement
  • devnode lifecycle (hermetic, full stack): 11 passed — pools → mint → increase → decrease → both-direction swaps + claims → owner≠withdrawal collect payout → burn
  • live write tiers (plain + wrapped swap roundtrips) are wired and skip cleanly pending DPS e2e credentials

- /auth/verify: send challenge_id from the challenge payload
- sessions are httpOnly cookies + X-CSRF-Token (legacy body-JWT kept)
- is_authenticated covers both credential kinds
- salted retry on DPS consumer-username collisions
- lifecycle live test: invite codes are pasted, never generated; shed
  SHIELD_SWAP_PRIVATE_KEY so the fresh-profile premise holds
…nt under cookie auth

- _headers: prefer the live session (csrf + cookies) over Authorization;
  ss_ tokens don't cover the /access tier and the server reads the header first
- 401 while both credentials are loaded drops the expired session and
  retries as bearer (15-min sessions)
- _auth_done recognizes cookie sessions; CSRF never persisted as jwt;
  from_profile prefers the durable ss_ token over stale session creds
Slot-derived insert hints only validate for a pool's FIRST position —
finalize asserts the true linked-list predecessors, so every later mint
was rejected on populated pools. find_tick_predecessor walks the ticks
mapping from the MIN sentinel (fresh pools anchor at the sentinel;
initialized ticks return themselves since validation is skipped).
… 0.3.0

shield-swap-sdk now floors aleo-sdk at 0.3 (Array codegen runtime).
Docs updated: staging auth/session + referral-vs-access invites, live-
verified LP behaviors (tick-list hints, wrapped-side exact amounts,
slippage headroom), sdk-abi example re-pointed at the new stack.
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.

1 participant