Repository navigation
[DeFi][FIN-04][M2] Complete constant-product AMM/LP lifecycle with generated builders #54
Description
Implementation ownership — protocol-first, no finance-specific compiler feature
Primary implementation layers: DeFi application/protocol package + generated SDK/CKB adapter. swap_a_for_b, add_liquidity and remove_liquidity remain ordinary author-written actions, never grammar productions or compiler-recognised builtins.
Implementation shape: implement Pool/LP state transitions, reserve accounting and constant-product fee/price invariants in the application scripts; enforce them against authentic input/output Cells. Use #52's custody authority and #53's checked maths. Reuse compiler-generated builders and ProtocolBundle to discover exact deployed assets, construct witnesses, reserve fee/capacity and execute all required Script groups on the same candidate transaction. Keep the transaction serializer and signing flow in existing general tooling.
Acceptance interpretation: the complete lifecycle must work without edits that hard-code AMM behaviour into parser, type checker, IR or codegen. A missing general transaction feature requires a separately scoped, business-neutral prerequisite with an executable failing case.
Compiler-change gate (all FIN work): This issue does not authorise finance-specific grammar, IR, opcodes, codegen branches or hidden protocol semantics. First try existing general CellScript constructs. Any genuinely missing general capability needs a minimal failing application, a non-financial use case, its own narrow issue and independent checker/ABI/resource/gate acceptance as required by #43 §2.2. Application correctness and builder convenience are distinct from language support.
Parent: #43 FIN-04/M2. Status: proposed; no release or production acceptance.
Owner roles: pool protocol and generated-builder/adapter engineers; reviewer unassigned.
Hard dependencies
- [DeFi][FIN-02][M1] Enforce authentic pool custody, asset identity and LP supply #52 FIN-02: enforced reserve custody, pool/LP identity and supply controls.
- FIN-03: admitted financial width, invariant and rounding contract.
- Use closed [Candidate][Consensus runtime] Implement executable bounded Cell-group consumption #7/[Candidate][Consensus runtime] Implement executable bounded output-plan correspondence #8 bounded lifecycle, [Architecture][Builder] Add an artifact-only multi-Script ProtocolBundle #9/[Language design] Model typed cross-Script transaction roles without runtime linkage #10/[Language/ABI] Bind runtime Script values to verified package interfaces #11 ProtocolBundle/exact roles/handles and [0.30][Acceptance] Build the canonical Rust-comparable CKB business corpus #26 corpus. [0.32][Language/ABI] Stabilize generic compatible-open Script and verifier handles #28/[0.32][ProtocolBundle] Stabilize runtime-selected open cross-Script roles #29 are not required for exact-deployment pool.
- First runnable implementation unblocks FIN-05 independent DX trial and early FIN-09 retry prototype; full acceptance unblocks FIN-07 order/pool settlement.
Scope
- Freeze [DeFi][Application/Protocol] EVM-class finance on CKB with CellScript #43 D08 (deposit residuals, used proportional amounts, explicit refunds, zero-share rejection) and applicable D10 clock policy. Retain chosen D01–D07 asset/custody/fee/locked-share invariants.
- Implement a uniquely initialised two-asset constant-product pool: deposit, second provider, LP transfer/split/merge as admitted, swap both directions, liquidity withdrawal, final redemption of all circulating LP whilst preserving non-redeemable minimum shares.
- Verify authentic reserve, fee and LP token transitions; ensure actual transaction inputs/outputs enforce invariant, fees stay in reserves, rounding and user limits/slippage are correct, and capacity is owned and refunded under explicit rules.
- Extend existing generated builders/CKB adapter, rather than inventing a second transaction serializer, for live Cell discovery, quote, fee/change funding, canonical witness encoding, signing integration and all-Script-group preflight.
- Publish a reproducible pool package and developer guide; expose a stable first runnable path early enough for FIN-05 to instantiate a second independent pool.
Acceptance
- An uninterrupted authentic lifecycle executes as a series of real CKB transactions, consuming prior outputs: create → second-provider deposit → both swap directions → withdraw → redeem all circulating shares subject to locked minimum.
- Builder/model/on-chain outputs agree at minimum, representative, maximum and fee/rounding boundaries; document unusable domains and explicit rejection.
- Wrong asset, missing pool/reserve, forged LP, standalone LP burn, pool desynchronisation, incorrect fee/rounding, bad recipient, invalid slippage, expired/stale input where admitted, capacity mismatch, and zero-share deposits reject by the intended Script.
- Every implicated Script group is included and verified against the same serialized transaction; raw builder checks do not stand in for on-chain obligations; generated byte identities agree.
- Retain frozen resource budgets, full valid/reject execution, source/ELF/deps/transaction/node hashes, checker mutations and relevant dev/CI/backend gates; reviewer disposition recorded.
- Documentation and package interfaces enable FIN-05 external deployment of a different exact asset pair without manual verifier replacement.
No concentrated liquidity, Oracle feeds, admin fee extraction, native CKB pair without its own capacity contract, production live stablecoins or public deployment. Ref: #43 §§5–7, 10–12.
Dependency cross-links (confirmed GitHub issues)
Hard dependencies: #52 FIN-02 and #53 FIN-03. Early runnable SDK hand-off: #55 FIN-05 and #59 FIN-09 recovery prototype. Full implementation acceptance required by: #57 FIN-07; indirectly #58 FIN-08 and #60 FIN-10. Do not require #28/#29 unless an exact-deployment case proves otherwise.
Umbrella dependency graph and authoritative financial acceptance: #43.
Activity