sigil.system.dex system contract. All AMM math is integer-only; no floats appear in consensus settlement.
Pool model
A pool is identified by a canonical id derived from(asset_a, asset_b, fee_bps):
5, 30, 100, or 1000 (0.05%, 0.30%, 1.0%, 10.0%).
Transactions
| Variant | Purpose |
|---|---|
DexCreatePool | Create a new pool with initial liquidity. |
DexAddLiquidity | Add proportional liquidity, mint LP shares. |
DexRemoveLiquidity | Burn LP shares, return proportional assets. |
DexSwapExactIn | Swap a known input amount for at least min_out. |
DexSwapExactOut | Swap up to max_in for an exact output amount. |
Pool creation
floor(sqrt(amount_a * amount_b)). Subsequent adds are proportional.
Swap
- Debits the input asset from the swapper.
- Computes the output:
out = amount_in × reserve_b × (10000 − fee_bps) / (reserve_a × 10000 + amount_in × (10000 − fee_bps)). - Asserts
out >= min_out. - Credits the output asset to the swapper.
- Updates the reserves.
- Verifies the constant-product invariant did not decrease.
Quotes
Read-only quotes are available without sending a transaction:Determinism
- All math is integer-only. No floats.
- Pool ids are deterministic BLAKE3-derived ids over the canonical asset pair and fee tier.
expiration_heightis a deterministic block-height guard.0in the system-contract ABI means no deadline; native transaction data usesNone.- MINT debits and credits reuse the native account-balance ledger. Non-MINT DEX asset balances are stored in the DEX state partition.
dex/: pools, LP positions, non-native asset balances, and events survive replay and restart.
RPC surface
| Method | Returns |
|---|---|
sigil_getDexPool | Pool record by id. |
sigil_listDexPools | Paginated pool list. |
sigil_quoteDexSwapExactIn | Exact-in quote. |
sigil_quoteDexSwapExactOut | Exact-out quote. |
sigil_getDexPosition | LP position for a DID and pool. |
sigil_listDexEvents | Pool events filtered by id or DID. |
Subscriptions
dextopic emits per-pool events (create, swap, add, remove) with optionalpool_idfilter.
Implementation
- Types:
node/sigil-core/src/dex.rs. - Executor:
node/sigil-node/src/executor_dex.rs. - System contract: pinned at genesis as
sigil.system.dex.
See also
- Swap on the DEX — recipe.
- Custom tokens — what trades against MINT.