Documentation
¶
Overview ¶
Package liquidity implements AMM liquidity pools for the DEX VM.
Index ¶
- Variables
- type LPPosition
- type Manager
- func (m *Manager) AddLiquidity(poolID ids.ID, amount0 *big.Int, amount1 *big.Int, minLiquidity *big.Int) (*big.Int, error)
- func (m *Manager) CreatePool(token0, token1 ids.ID, initialAmount0, initialAmount1 *big.Int, ...) (*Pool, error)
- func (m *Manager) GetAllPools() []*Pool
- func (m *Manager) GetPool(poolID ids.ID) (*Pool, error)
- func (m *Manager) GetPoolByPair(token0, token1 ids.ID) (*Pool, error)
- func (m *Manager) GetPoolsByTokenPair(token0, token1 ids.ID) []*Pool
- func (m *Manager) GetQuote(poolID ids.ID, tokenIn ids.ID, amountIn *big.Int) (*big.Int, error)
- func (m *Manager) RemoveLiquidity(poolID ids.ID, liquidity *big.Int, minAmount0 *big.Int, minAmount1 *big.Int) (*big.Int, *big.Int, error)
- func (m *Manager) Swap(poolID ids.ID, tokenIn ids.ID, amountIn *big.Int, minAmountOut *big.Int) (*SwapResult, error)
- type Pool
- type PoolType
- type SwapResult
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInsufficientLiquidity = errors.New("insufficient liquidity") ErrPoolNotFound = errors.New("pool not found") ErrInvalidAmount = errors.New("invalid amount") ErrSlippageExceeded = errors.New("slippage exceeded") ErrZeroLiquidity = errors.New("zero liquidity not allowed") ErrPoolExists = errors.New("pool already exists") ErrSameToken = errors.New("cannot create pool with same token") )
Functions ¶
This section is empty.
Types ¶
type LPPosition ¶
type LPPosition struct {
Owner ids.ShortID `json:"owner"`
PoolID ids.ID `json:"poolId"`
Liquidity *big.Int `json:"liquidity"` // LP tokens held
Token0Owed *big.Int `json:"token0Owed"` // Unclaimed token0 fees
Token1Owed *big.Int `json:"token1Owed"` // Unclaimed token1 fees
TickLower int32 `json:"tickLower,omitempty"` // For concentrated
TickUpper int32 `json:"tickUpper,omitempty"` // For concentrated
CreatedAt int64 `json:"createdAt"`
}
LPPosition represents a liquidity provider's position in a pool.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages all liquidity pools.
func (*Manager) AddLiquidity ¶
func (m *Manager) AddLiquidity( poolID ids.ID, amount0 *big.Int, amount1 *big.Int, minLiquidity *big.Int, ) (*big.Int, error)
AddLiquidity adds liquidity to a pool.
func (*Manager) CreatePool ¶
func (m *Manager) CreatePool( token0, token1 ids.ID, initialAmount0, initialAmount1 *big.Int, poolType PoolType, feeBps uint16, ) (*Pool, error)
CreatePool creates a new liquidity pool.
func (*Manager) GetAllPools ¶
GetAllPools returns all pools.
func (*Manager) GetPoolByPair ¶
GetPoolByPair returns a pool by token pair.
func (*Manager) GetPoolsByTokenPair ¶
GetPoolsByTokenPair returns all pools for a given token pair.
type Pool ¶
type Pool struct {
ID ids.ID `json:"id"`
Token0 ids.ID `json:"token0"` // First token in the pair
Token1 ids.ID `json:"token1"` // Second token in the pair
Reserve0 *big.Int `json:"reserve0"` // Reserve of token0
Reserve1 *big.Int `json:"reserve1"` // Reserve of token1
Type PoolType `json:"type"`
FeeBps uint16 `json:"feeBps"` // Trading fee in basis points
TotalSupply *big.Int `json:"totalSupply"` // Total LP tokens
// Concentrated liquidity parameters (for Concentrated type)
TickLower int32 `json:"tickLower,omitempty"`
TickUpper int32 `json:"tickUpper,omitempty"`
SqrtPriceX96 *big.Int `json:"sqrtPriceX96,omitempty"`
// Statistics
Volume0 *big.Int `json:"volume0"` // Cumulative volume in token0
Volume1 *big.Int `json:"volume1"` // Cumulative volume in token1
Fees0 *big.Int `json:"fees0"` // Cumulative fees in token0
Fees1 *big.Int `json:"fees1"` // Cumulative fees in token1
TxCount uint64 `json:"txCount"` // Total transaction count
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
}
Pool represents an AMM liquidity pool.
type SwapResult ¶
type SwapResult struct {
AmountIn *big.Int `json:"amountIn"`
AmountOut *big.Int `json:"amountOut"`
Fee *big.Int `json:"fee"`
PriceImpact uint64 `json:"priceImpact"` // In basis points
NewReserve0 *big.Int `json:"newReserve0"`
NewReserve1 *big.Int `json:"newReserve1"`
}
SwapResult contains the result of a swap operation.
Click to show internal directories.
Click to hide internal directories.