Documentation
¶
Overview ¶
Package pool manages pool configuration and on-chain state queries.
Index ¶
- Constants
- func IntSqrt(n uint64) uint64
- func LPMintedForDeposit(deposit0, _, reserve0, _, totalSupply uint64) uint64
- func RemovePayouts(lpBurned, reserve0, reserve1, totalSupply uint64) (payout0, payout1 uint64)
- func SwapOutput(amountIn, reserveIn, reserveOut, feeNum, feeDen uint64) uint64
- type Config
- type ContractInfo
- type PoolVariant
- type State
Constants ¶
const LPPremint uint64 = 2_000_000_000_000_000
LPPremint is the total pre-minted LP token supply per pool. Elements consensus sums ALL explicit output values (cross-asset) and rejects transactions where the total exceeds MAX_MONEY (2.1e15). We reserve 1e14 (~$10M headroom) for pool deposits, change, and fees in the create-pool transaction where the full premint appears.
Variables ¶
This section is empty.
Functions ¶
func LPMintedForDeposit ¶
LPMintedForDeposit computes LP tokens to mint for add-liquidity. The lp_reserve_add contract validates: lp_minted == floor(deposit0 * supply / reserve0). deposit1 is validated separately by the contract's proportionality check.
func RemovePayouts ¶
RemovePayouts computes proportional payouts for remove-liquidity.
func SwapOutput ¶
SwapOutput computes the maximum output amount for a fee-adjusted swap. Formula: out = reserveOut * amountIn * feeNum / (reserveIn * feeDen + amountIn * feeNum) This is the fee-adjusted constant-product invariant used by the Simplicity contracts. If feeNum or feeDen is zero (e.g. legacy pool.json without fee fields), falls back to the no-fee formula (feeNum = feeDen = 1), which is the standard constant-product k formula. Uses big.Int to avoid overflow for mainnet-scale reserves.
Types ¶
type Config ¶
type Config struct {
PoolCreation ContractInfo `json:"pool_creation"`
// Pool A: dual-leaf taproot (swap + remove leaves share one address)
PoolA ContractInfo `json:"pool_a"`
PoolASwap PoolVariant `json:"pool_a_swap"`
PoolARemove PoolVariant `json:"pool_a_remove"`
// Pool B: dual-leaf taproot
PoolB ContractInfo `json:"pool_b"`
PoolBSwap PoolVariant `json:"pool_b_swap"`
PoolBRemove PoolVariant `json:"pool_b_remove"`
// LP Reserve: dual-leaf taproot (add + remove leaves share one address)
LpReserve ContractInfo `json:"lp_reserve"`
LpReserveAdd PoolVariant `json:"lp_reserve_add"`
LpReserveRemove PoolVariant `json:"lp_reserve_remove"`
// Asset IDs and fee parameters stored after compile/create-pool.
// FeeNum/FeeDen are baked into the compiled contracts (.args at compile time)
// and must be stored here so swap/add/remove operations use the correct formula.
Asset0 string `json:"asset0,omitempty"`
Asset1 string `json:"asset1,omitempty"`
LPAssetID string `json:"lp_asset_id,omitempty"`
FeeNum uint64 `json:"fee_num,omitempty"`
FeeDen uint64 `json:"fee_den,omitempty"`
}
Config holds all pool contract addresses, binaries, and asset IDs.
type ContractInfo ¶
type ContractInfo struct {
Address string `json:"address"`
CMR string `json:"cmr"` // 32-byte Simplicity CMR hex (taproot leaf content)
BinaryHex string `json:"binary_hex"` // hex-encoded Simplicity program
}
ContractInfo holds compiled contract data for one pool script.
type PoolVariant ¶
type PoolVariant struct {
CMR string `json:"cmr"`
BinaryHex string `json:"binary_hex"`
ControlBlock string `json:"control_block"` // hex-encoded taproot control block
}
PoolVariant holds the CMR, binary, and control block for one mode-specific pool script (e.g., swap-only or remove-only). The address is shared with the parent ContractInfo (dual-leaf taproot).
type State ¶
type State struct {
Reserve0 uint64 // pool_a asset0 satoshis
Reserve1 uint64 // pool_b asset1 satoshis
LPReserve uint64 // lp_reserve LP token amount
PoolATxID string
PoolAVout uint32
PoolBTxID string
PoolBVout uint32
LpReserveTxID string
LpReserveVout uint32
}
State holds live on-chain pool reserves.
func (*State) TotalSupply ¶
TotalSupply derives the circulating LP token supply from the reserve.