Documentation ¶
Index ¶
- Constants
- Variables
- func AmountXFromAmountY(lowSqrtPrice, currentSqrtPrice, highSqrtPrice *apd.Decimal, amountY string) (amountX string, err error)
- func AmountYFromAmountX(lowSqrtPrice, currentSqrtPrice, highSqrtPrice *apd.Decimal, amountX string) (amountY string, err error)
- func BigDotIntToDecimal(b *big.Int) (*apd.Decimal, error)
- func DecimalToBigDotInt(d *apd.Decimal, isRoundUp bool) (*big.Int, error)
- func GetLpID(poolID, address string, lowSqrtPrice, highSqrtPrice *apd.Decimal, ...) string
- func GetPoolCurrentPrice(pool *schema.Pool, priceDirection string) (string, error)
- func GetPoolCurrentPrice2(pool *schema.Pool, priceDirection string) (string, error)
- func GetPoolID(tokenXTag, tokenYTag string, feeRatio *apd.Decimal) string
- func GetPoolLp(pool *schema.Pool, lpID string) (*schema.Lp, bool)
- func GetPoolLps(pool *schema.Pool, excludedLpIDs []string) []*schema.Lp
- func GetPoolLps2(pool *schema.Pool) []schema.Lp
- func LiquidityFromAmount(amountX, amountY string) (string, error)
- func LiquidityFromAmountX(lowSqrtPrice, currentSqrtPrice, highSqrtPrice *apd.Decimal, amountX string) (liquidity string, err error)
- func LiquidityFromAmountY(lowSqrtPrice, currentSqrtPrice, highSqrtPrice *apd.Decimal, amountY string) (liquidity string, err error)
- func LiquidityToAmount(liquidity string, lowSqrtPrice, currentSqrtPrice, highSqrtPrice *apd.Decimal, ...) (amountX, amountY string, err error)
- func LiquidityToAmount2(liquidity string, lowSqrtPrice, currentSqrtPrice, highSqrtPrice *apd.Decimal) (amountX, amountY string, err error)
- func LpCurrentPrice(lp schema.Lp) string
- func LpHighPrice(lp schema.Lp) string
- func LpLowPrice(lp schema.Lp) string
- func LpSwap(lp *schema.Lp, tokenIn, tokenOut string, amountIn *big.Int, isDryRun bool) (*schema.SwapOutput, error)
- func LpVerifySwap(lp *schema.Lp, tokenIn, tokenOut string, amountIn, amountOut *big.Int) (bool, error)
- func NewLp(poolID, tokenXTag, tokenYTag, address string, ...) (*schema.Lp, error)
- func NewPool(tokenXTag, tokenYTag, feeRatio string) (*schema.Pool, error)
- func PathsToSwapInputs(user string, paths []schema.Path) (map[string]*schema.SwapInput, error)
- func PoolAddLiquidity(pool *schema.Pool, lp *schema.Lp) error
- func PoolRemoveLiquidity(pool *schema.Pool, lpID string)
- func PoolSwap(pool *schema.Pool, tokenIn, tokenOut string, amountIn *big.Int, ...) ([]schema.SwapOutput, error)
- func PoolsSwap(poolPaths []*schema.Pool, tokenIn, tokenOut string, amountIn *big.Int, ...) ([]schema.SwapOutput, *big.Int, error)
- func QuotientGreaterThan(dividend, divisor *apd.Decimal, minimum string) bool
- func SqrtPrice(price string) (*apd.Decimal, error)
- func SqrtPriceToPrice(sqrtPrice apd.Decimal) (string, error)
- func SqrtPriceToPriceWithFee(sqrtPrice, feeRatio apd.Decimal, priceDirection string) (string, error)
- func StringToDecimal(s string) (*apd.Decimal, error)
- func SwapAmount(startSqrtPrice, endSqrtPrice *apd.Decimal, liquidity *big.Int) (amountIn, amountOut *big.Int, amountInDecimal, amountOutDecimal *apd.Decimal, ...)
- func SwapOut(startSqrtPrice *apd.Decimal, liquidity, amountIn *big.Int, tokenInIsX bool) (amountOut *big.Int, endSqrtPrice *apd.Decimal, err error)
- func SwapOutputsToPaths(user string, core *Core, swapOutputs []schema.SwapOutput) ([]schema.Path, error)
- func TokenXYForPool(tokenA, tokenB string) (string, string)
- type Core
- func (c *Core) AddLiquidity(address string, msg routerSchema.LpMsgAdd) error
- func (c *Core) AddLiquidityByLp(lp *schema.Lp) error
- func (c *Core) FindPool(tokenX, tokenY string, feeRatio *apd.Decimal) (*schema.Pool, error)
- func (c *Core) FindPoolPaths(tokenIn, tokenOut string) ([][]*schema.Pool, error)
- func (c *Core) GetAllLps() (lps []schema.Lp)
- func (c *Core) GetLps(address string) (lps []schema.Lp)
- func (c *Core) GetPoolCurrentPrice(poolID, priceDirection string) (string, error)
- func (c *Core) GetPoolCurrentPrice2(poolID, priceDirection string) (string, error)
- func (c *Core) Query(msg routerSchema.UserMsgQuery) ([]schema.Path, error)
- func (c *Core) RemoveLiquidity(address string, msg routerSchema.LpMsgRemove) error
- func (c *Core) RemoveLiquidityByAddress(lpAddr string) (err error)
- func (c *Core) RemoveLiquidityByID(lpID string) (lp *schema.Lp, err error)
- func (c *Core) Update(userAddr string, paths []schema.Path) error
- func (c *Core) Verify(userAddr string, paths []schema.Path) error
- type DecimalSlice
- type Tick
Constants ¶
View Source
const (
MaxPoolPathLength = 3
)
View Source
const (
PRECISION uint32 = 32
)
Variables ¶
View Source
var ( ERR_INVALID_POOL = errors.New("err_invalid_pool") ERR_NO_POOL = errors.New("err_no_pool") ERR_NO_LP = errors.New("err_no_lp") ERR_NO_PATH = errors.New("err_no_path") ERR_INVALID_AMOUNT = errors.New("err_invalid_amount") ERR_OUT_OF_RANGE = errors.New("err_out_of_range") ERR_INVALID_TOKEN = errors.New("err_invalid_token") ERR_INVALID_NUMBER = errors.New("err_invalid_number") ERR_NO_IMPLEMENT = errors.New("err_no_implement") ERR_INVALID_PATH = errors.New("err_invalid_path") ERR_INVALID_SWAPOUTS = errors.New("err_invalid_swapouts") ERR_INVALID_POOL_PATHS = errors.New("err_invalid_pool_paths") ERR_INVALID_SWAP_USER = errors.New("err_invalid_swap_user") ERR_INVALID_PATH_FEE = errors.New("err_invalid_path_fee") ERR_FEE_TOO_SMALL = errors.New("err_fee_too_small") // error for lp ERR_INVALID_PRICE = errors.New("err_invalid_price") ERR_INVALID_LIQUIDITY = errors.New("err_invalid_liquidity") ERR_INVALID_PRICE_DIRECTION = errors.New("err_invalid_price_direction") ERR_INVALID_FEE = errors.New("err_invalid_fee") )
Functions ¶
func AmountXFromAmountY ¶
func AmountYFromAmountX ¶
func GetPoolCurrentPrice ¶
func GetPoolCurrentPrice2 ¶
func LiquidityFromAmount ¶
func LiquidityFromAmountX ¶
func LiquidityFromAmountY ¶
func LiquidityToAmount ¶
func LiquidityToAmount2 ¶
func LiquidityToAmount2(liquidity string, lowSqrtPrice, currentSqrtPrice, highSqrtPrice *apd.Decimal) (amountX, amountY string, err error)
deprecated
func LpCurrentPrice ¶
func LpHighPrice ¶
func LpLowPrice ¶
func LpVerifySwap ¶
func PathsToSwapInputs ¶
func PoolRemoveLiquidity ¶
func PoolsSwap ¶
func PoolsSwap(poolPaths []*schema.Pool, tokenIn, tokenOut string, amountIn *big.Int, excludedLpIDs []string) ([]schema.SwapOutput, *big.Int, error)
PoolsSwap is not for update, use it for query
func QuotientGreaterThan ¶
func SqrtPriceToPriceWithFee ¶
func SwapAmount ¶
func SwapOutputsToPaths ¶
func TokenXYForPool ¶
Types ¶
type Core ¶
type Core struct { FeeRecepient string // router fee recepient address FeeRatio *apd.Decimal // router fee ratio Pools map[string]*schema.Pool // pool id -> Pool Lps map[string]*schema.Lp // lp id -> Lp AddressToLpIDs map[string][]string // address -> []lpID MaxPoolPathLength int TokenTagToPoolIDs map[string][]string // tokentag -> []lpID }
func (*Core) AddLiquidity ¶
func (c *Core) AddLiquidity(address string, msg routerSchema.LpMsgAdd) error
func (*Core) FindPoolPaths ¶
func (*Core) GetPoolCurrentPrice ¶
func (*Core) GetPoolCurrentPrice2 ¶
func (*Core) Query ¶
func (c *Core) Query(msg routerSchema.UserMsgQuery) ([]schema.Path, error)
func (*Core) RemoveLiquidity ¶
func (c *Core) RemoveLiquidity(address string, msg routerSchema.LpMsgRemove) error
func (*Core) RemoveLiquidityByAddress ¶
func (*Core) RemoveLiquidityByID ¶
type DecimalSlice ¶
func (DecimalSlice) Len ¶
func (p DecimalSlice) Len() int
func (DecimalSlice) Less ¶
func (p DecimalSlice) Less(i, j int) bool
func (DecimalSlice) Swap ¶
func (p DecimalSlice) Swap(i, j int)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.