Documentation ¶
Index ¶
- func BinarySearchSingleAssetJoin(pool types.PoolI, tokenIn sdk.Coin, ...) (numLPShares sdk.Int, err error)
- func CalcExitPool(ctx sdk.Context, pool types.PoolI, exitingShares sdk.Int, exitFee sdk.Dec) (sdk.Coins, error)
- func MaximalExactRatioJoin(p types.PoolI, ctx sdk.Context, tokensIn sdk.Coins) (numShares sdk.Int, remCoins sdk.Coins, err error)
- func SwapAllCoinsToSingleAsset(pool types.PoolI, ctx sdk.Context, inTokens sdk.Coins, swapToDenom string, ...) (sdk.Int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearchSingleAssetJoin ¶
func BinarySearchSingleAssetJoin( pool types.PoolI, tokenIn sdk.Coin, poolWithAddedLiquidityAndShares func(newLiquidity sdk.Coin, newShares sdk.Int) types.PoolI, ) (numLPShares sdk.Int, err error)
We binary search a number of LP shares, s.t. if we exited the pool with the updated liquidity, and swapped all the tokens back to the input denom, we'd get the same amount. (under 0 swap fee) Thanks to CFMM path-independence, we can estimate slippage with these swaps to be sure to get the right numbers here. (by path-independence, swap all of B -> A, and then swap all of C -> A will yield same amount of A, regardless of order and interleaving)
This implementation requires each of pool.GetTotalPoolLiquidity, pool.ExitPool, and pool.SwapExactAmountIn to not update or read from state, and instead only do updates based upon the pool struct.
func CalcExitPool ¶
func CalcExitPool(ctx sdk.Context, pool types.PoolI, exitingShares sdk.Int, exitFee sdk.Dec) (sdk.Coins, error)
CalcExitPool returns how many tokens should come out, when exiting k LP shares against a "standard" CFMM
func MaximalExactRatioJoin ¶
func MaximalExactRatioJoin(p types.PoolI, ctx sdk.Context, tokensIn sdk.Coins) (numShares sdk.Int, remCoins sdk.Coins, err error)
MaximalExactRatioJoin calculates the maximal amount of tokens that can be joined whilst maintaining pool asset's ratio returning the number of shares that'd be and how many coins would be left over.
e.g) suppose we have a pool of 10 foo tokens and 10 bar tokens, with the total amount of 100 shares. if `tokensIn` provided is 1 foo token and 2 bar tokens, `MaximalExactRatioJoin` would be returning (10 shares, 1 bar token, nil)
This can be used when `tokensIn` are not guaranteed the same ratio as assets in the pool. Calculation for this is done in the following steps.
- iterate through all the tokens provided as an argument, calculate how much ratio it accounts for the asset in the pool
- get the minimal share ratio that would work as the benchmark for all tokens.
- calculate the number of shares that could be joined (total share * min share ratio), return the remaining coins
Types ¶
This section is empty.