cfmm_common

package
v9.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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 LP's the maximal amount of tokens in possible, and returns the number of shares that'd be and how many coins would be left over.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL