keeper

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetsValue added in v0.12.0

func AssetsValue(ctx sdk.Context, oracleKeeper types.OracleKeeper, amountDepthInfo []types.AssetAmountDepth) (sdk.Dec, sdk.Dec, error)

func LiquidityRatioFromPriceDepth added in v0.12.0

func LiquidityRatioFromPriceDepth(depth sdk.Dec) sdk.Dec

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

NewMsgServerImpl returns an implementation of the MsgServer interface for the provided Keeper.

func PortionCoins

func PortionCoins(coins sdk.Coins, portion sdk.Dec) sdk.Coins

Types

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey,
	transientStoreKey storetypes.StoreKey,
	ps paramtypes.Subspace,
	authority string,

	parameterKeeper *pkeeper.Keeper,
	bankKeeper types.BankKeeper,
	accountKeeper types.AccountKeeper,
	oracleKeeper types.OracleKeeper,
	commitmentKeeper *commitmentkeeper.Keeper,
	assetProfileKeeper types.AssetProfileKeeper,
	accountedPoolKeeper types.AccountedPoolKeeper,
) *Keeper

func (Keeper) AllSlippageTracks added in v0.13.0

func (k Keeper) AllSlippageTracks(ctx sdk.Context) []types.OraclePoolSlippageTrack

func (Keeper) ApplyExitPoolStateChange added in v0.14.0

func (k Keeper) ApplyExitPoolStateChange(ctx sdk.Context, pool types.Pool, exiter sdk.AccAddress, numShares sdk.Int, exitCoins sdk.Coins) error

func (Keeper) ApplySwapRequest added in v0.11.0

func (k Keeper) ApplySwapRequest(ctx sdk.Context, msg sdk.Msg) error

func (Keeper) Balance added in v0.14.0

func (Keeper) BurnPoolShareFromAccount

func (k Keeper) BurnPoolShareFromAccount(ctx sdk.Context, pool types.Pool, addr sdk.AccAddress, amount sdk.Int) error

BurnPoolShareFromAccount burns `amount` of the given pool's shares held by `addr`.

func (Keeper) CalcInAmtGivenOut added in v0.11.0

func (k Keeper) CalcInAmtGivenOut(
	ctx sdk.Context,
	poolId uint64,
	oracle types.OracleKeeper,
	snapshot *types.Pool,
	tokensOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) (
	tokenIn sdk.Coin, err error,
)

CalcInAmtGivenOut calculates token to be provided, fee added, given the swapped out amount, using solveConstantFunctionInvariant.

func (Keeper) CalcInRouteByDenom added in v0.16.0

func (k Keeper) CalcInRouteByDenom(ctx sdk.Context, denomIn string, denomOut string, baseCurrency string) ([]*types.SwapAmountInRoute, error)

CalcInRouteByDenom calculates the in route by denom

func (Keeper) CalcInRouteSpotPrice added in v0.16.0

func (k Keeper) CalcInRouteSpotPrice(ctx sdk.Context, tokenIn sdk.Coin, routes []*types.SwapAmountInRoute, discount sdk.Dec, overrideSwapFee sdk.Dec) (sdk.Dec, sdk.Coin, sdk.Dec, sdk.Dec, sdk.Coin, sdk.Dec, error)

CalcInRouteSpotPrice calculates the spot price of the given token and in route

func (Keeper) CalcOutAmtGivenIn added in v0.11.0

func (k Keeper) CalcOutAmtGivenIn(
	ctx sdk.Context,
	poolId uint64,
	oracle types.OracleKeeper,
	snapshot *types.Pool,
	tokensIn sdk.Coins,
	tokenOutDenom string,
	swapFee sdk.Dec,
) (sdk.Coin, error)

CalcOutAmtGivenIn calculates tokens to be swapped out given the provided amount and fee deducted, using solveConstantFunctionInvariant.

func (Keeper) CalcOutRouteByDenom added in v0.16.0

func (k Keeper) CalcOutRouteByDenom(ctx sdk.Context, denomOut string, denomIn string, baseCurrency string) ([]*types.SwapAmountOutRoute, error)

CalcOutRouteByDenom calculates the out route by denom

func (Keeper) CalcOutRouteSpotPrice added in v0.16.0

func (k Keeper) CalcOutRouteSpotPrice(ctx sdk.Context, tokenOut sdk.Coin, routes []*types.SwapAmountOutRoute, discount sdk.Dec, overrideSwapFee sdk.Dec) (sdk.Dec, sdk.Coin, sdk.Dec, sdk.Dec, sdk.Coin, sdk.Dec, error)

CalcOutRouteSpotPrice calculates the spot price of the given token and out route

func (Keeper) CalcSwapEstimationByDenom added in v0.16.0

func (k Keeper) CalcSwapEstimationByDenom(
	ctx sdk.Context,
	amount sdk.Coin,
	denomIn string,
	denomOut string,
	baseCurrency string,
	discount sdk.Dec,
	overrideSwapFee sdk.Dec,
	decimals uint64,
) (
	inRoute []*types.SwapAmountInRoute,
	outRoute []*types.SwapAmountOutRoute,
	outAmount sdk.Coin,
	spotPrice sdk.Dec,
	swapFeeOut sdk.Dec,
	discountOut sdk.Dec,
	availableLiquidity sdk.Coin,
	weightBonus sdk.Dec,
	priceImpact sdk.Dec,
	err error,
)

CalcSwapEstimationByDenom calculates the swap estimation by denom

func (Keeper) ClearOutdatedSlippageTrack added in v0.13.0

func (k Keeper) ClearOutdatedSlippageTrack(ctx sdk.Context)

func (Keeper) CreatePool

func (k Keeper) CreatePool(ctx sdk.Context, msg *types.MsgCreatePool) (uint64, error)

CreatePool attempts to create a pool returning the newly created pool ID or an error upon failure. The pool creation fee is used to fund the community pool. It will create a dedicated module account for the pool and sends the initial liquidity to the created module account.

After the initial liquidity is sent to the pool's account, this function calls an InitializePool function from the source module. That module is responsible for: - saving the pool into its own state - Minting LP shares to pool creator - Setting metadata for the shares

func (Keeper) DecreaseDenomLiquidity

func (k Keeper) DecreaseDenomLiquidity(ctx sdk.Context, denom string, amount math.Int) error

DecreaseDenomLiquidity decreases the liquidity of a denom by a certain amount

func (Keeper) DeleteSlippageTrack added in v0.13.0

func (k Keeper) DeleteSlippageTrack(ctx sdk.Context, track types.OraclePoolSlippageTrack)

func (Keeper) DeleteSwapExactAmountInRequest added in v0.11.0

func (k Keeper) DeleteSwapExactAmountInRequest(ctx sdk.Context, msg *types.MsgSwapExactAmountIn, index uint64)

DeleteSwapExactAmountInRequest removes a swap exact amount in request

func (Keeper) DeleteSwapExactAmountOutRequest added in v0.11.0

func (k Keeper) DeleteSwapExactAmountOutRequest(ctx sdk.Context, msg *types.MsgSwapExactAmountOut, index uint64)

DeleteSwapExactAmountOutRequest deletes a swap exact amount out request

func (Keeper) DeleteSwapRequest added in v0.11.0

func (k Keeper) DeleteSwapRequest(ctx sdk.Context, msg sdk.Msg, index uint64)

func (Keeper) EndBlocker added in v0.11.0

func (k Keeper) EndBlocker(ctx sdk.Context)

EndBlocker of amm module

func (Keeper) ExecuteSwapRequests added in v0.11.0

func (k Keeper) ExecuteSwapRequests(ctx sdk.Context) []sdk.Msg

func (Keeper) ExitPool

func (k Keeper) ExitPool(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolId uint64,
	shareInAmount sdk.Int,
	tokenOutMins sdk.Coins,
	tokenOutDenom string,
) (exitCoins sdk.Coins, err error)

func (Keeper) FirstPoolId added in v0.11.0

func (k Keeper) FirstPoolId(msg sdk.Msg) uint64

func (Keeper) GetAllDenomLiquidity

func (k Keeper) GetAllDenomLiquidity(ctx sdk.Context) (list []types.DenomLiquidity)

GetAllDenomLiquidity returns all denomLiquidity

func (Keeper) GetAllPool

func (k Keeper) GetAllPool(ctx sdk.Context) (list []types.Pool)

GetAllPool returns all pool

func (Keeper) GetAllPoolIdsWithDenom

func (k Keeper) GetAllPoolIdsWithDenom(ctx sdk.Context, denom string) (list []uint64)

Get pool Ids that contains the denom in pool assets

func (Keeper) GetAllSwapExactAmountInRequests added in v0.11.0

func (k Keeper) GetAllSwapExactAmountInRequests(ctx sdk.Context) (list []types.MsgSwapExactAmountIn)

GetAllSwapExactAmountInRequests returns all SwapExactAmountIn requests

func (Keeper) GetAllSwapExactAmountOutRequests added in v0.11.0

func (k Keeper) GetAllSwapExactAmountOutRequests(ctx sdk.Context) (list []types.MsgSwapExactAmountOut)

GetAllSwapExactAmountOutRequests returns all SwapExactAmountOut requests

func (Keeper) GetDenomLiquidity

func (k Keeper) GetDenomLiquidity(ctx sdk.Context, denom string) (val types.DenomLiquidity, found bool)

GetDenomLiquidity returns a denomLiquidity from its index

func (Keeper) GetFirstSlippageTrack added in v0.13.0

func (k Keeper) GetFirstSlippageTrack(ctx sdk.Context, poolId uint64) types.OraclePoolSlippageTrack

func (Keeper) GetFirstSwapExactAmountInRequest added in v0.11.0

func (k Keeper) GetFirstSwapExactAmountInRequest(ctx sdk.Context, sprefix []byte) (*types.MsgSwapExactAmountIn, uint64)

func (Keeper) GetFirstSwapExactAmountOutRequest added in v0.11.0

func (k Keeper) GetFirstSwapExactAmountOutRequest(ctx sdk.Context, sprefix []byte) (*types.MsgSwapExactAmountOut, uint64)

func (Keeper) GetLastSlippageTrack added in v0.13.0

func (k Keeper) GetLastSlippageTrack(ctx sdk.Context, poolId uint64) types.OraclePoolSlippageTrack

func (Keeper) GetLastSwapRequestIndex added in v0.11.0

func (k Keeper) GetLastSwapRequestIndex(ctx sdk.Context) uint64

func (Keeper) GetLatestPool

func (k Keeper) GetLatestPool(ctx sdk.Context) (val types.Pool, found bool)

GetLatestPool retrieves the latest pool item from the list of pools

func (Keeper) GetNextPoolId

func (k Keeper) GetNextPoolId(ctx sdk.Context) uint64

GetNextPoolId returns the next pool id.

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) types.Params

GetParams get all parameters as types.Params

func (Keeper) GetPool

func (k Keeper) GetPool(ctx sdk.Context, poolId uint64) (val types.Pool, found bool)

GetPool returns a pool from its index

func (Keeper) GetPoolIdWithAllDenoms added in v0.16.0

func (k Keeper) GetPoolIdWithAllDenoms(ctx sdk.Context, denoms []string) (poolId uint64, found bool)

GetPoolIdWithAllDenoms returns the first pool id that contains all specified denominations

func (Keeper) GetPoolSnapshotOrSet added in v0.11.0

func (k Keeper) GetPoolSnapshotOrSet(ctx sdk.Context, pool types.Pool) (val types.Pool)

GetPoolSnapshotOrSet returns a pool snapshot or set the snapshot

func (Keeper) GetSlippageTrack added in v0.13.0

func (k Keeper) GetSlippageTrack(ctx sdk.Context, poolId uint64, timestamp uint64) types.OraclePoolSlippageTrack

func (Keeper) GetStackedSlippage added in v0.11.0

func (k Keeper) GetStackedSlippage(ctx sdk.Context, poolId uint64) sdk.Dec

func (Keeper) GetTrackedSlippageDiff added in v0.13.0

func (k Keeper) GetTrackedSlippageDiff(ctx sdk.Context, poolId uint64) sdk.Coins

func (Keeper) InRouteByDenom added in v0.16.0

func (Keeper) IncreaseDenomLiquidity

func (k Keeper) IncreaseDenomLiquidity(ctx sdk.Context, denom string, amount math.Int) error

IncreaseDenomLiquidity increases the liquidity of a denom by a certain amount

func (Keeper) InitializePool

func (k Keeper) InitializePool(ctx sdk.Context, pool *types.Pool, sender sdk.AccAddress) (err error)

This function: - saves the pool to state - Mints LP shares to the pool creator - Sets bank metadata for the LP denom - Records total liquidity increase - Calls the AfterPoolCreated hook

func (Keeper) IterateLiquidityPools

func (k Keeper) IterateLiquidityPools(ctx sdk.Context, handlerFn func(pool types.Pool) (stop bool))

IterateLiquidty iterates over all LiquidityPools and performs a callback.

func (Keeper) JoinPoolNoSwap

func (k Keeper) JoinPoolNoSwap(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolId uint64,
	shareOutAmount sdk.Int,
	tokenInMaxs sdk.Coins,
) (tokenIn sdk.Coins, sharesOut sdk.Int, err error)

JoinPoolNoSwap aims to LP exactly enough to pool #{poolId} to get shareOutAmount number of LP shares. If the required tokens is greater than tokenInMaxs, returns an error & the message reverts. Leftover tokens that weren't LP'd (due to being at inexact ratios) remain in the sender account.

JoinPoolNoSwap determines the maximum amount that can be LP'd without any swap, by looking at the ratio of the total LP'd assets. (e.g. 2 osmo : 1 atom) It then finds the maximal amount that can be LP'd.

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

func (Keeper) MintPoolShareToAccount

func (k Keeper) MintPoolShareToAccount(ctx sdk.Context, pool types.Pool, addr sdk.AccAddress, amount math.Int) error

MintPoolShareToAccount attempts to mint shares of a AMM denomination to the specified address returning an error upon failure. Shares are minted using the x/amm module account.

func (Keeper) OnCollectFee

func (k Keeper) OnCollectFee(ctx sdk.Context, pool types.Pool, fee sdk.Coins) error

func (Keeper) OutRouteByDenom added in v0.16.0

func (Keeper) Params

func (Keeper) Pool

func (Keeper) PoolAll

func (Keeper) PoolCreationFee

func (k Keeper) PoolCreationFee(ctx sdk.Context) (res uint64)

PoolCreationFee returns the PoolCreationFee param

func (Keeper) PoolExists

func (k Keeper) PoolExists(ctx sdk.Context, poolId uint64) bool

PoolExists checks if a pool with the given poolId exists in the list of pools

func (Keeper) RecordTotalLiquidityDecrease

func (k Keeper) RecordTotalLiquidityDecrease(ctx sdk.Context, coins sdk.Coins)

func (Keeper) RecordTotalLiquidityIncrease

func (k Keeper) RecordTotalLiquidityIncrease(ctx sdk.Context, coins sdk.Coins)

func (Keeper) RemoveDenomLiquidity

func (k Keeper) RemoveDenomLiquidity(ctx sdk.Context, denom string)

RemoveDenomLiquidity removes a denomLiquidity from the store

func (Keeper) RemovePool

func (k Keeper) RemovePool(ctx sdk.Context, poolId uint64)

RemovePool removes a pool from the store

func (Keeper) RouteExactAmountIn

func (k Keeper) RouteExactAmountIn(
	ctx sdk.Context,
	sender sdk.AccAddress,
	recipient sdk.AccAddress,
	routes []types.SwapAmountInRoute,
	tokenIn sdk.Coin,
	tokenOutMinAmount math.Int,
	discount sdk.Dec,
) (tokenOutAmount math.Int, totalDiscountedSwapFee sdk.Dec, discountOut sdk.Dec, err error)

RouteExactAmountIn defines the input denom and input amount for the first pool, the output of the first pool is chained as the input for the next routed pool transaction succeeds when final amount out is greater than tokenOutMinAmount defined.

func (Keeper) RouteExactAmountOut

func (k Keeper) RouteExactAmountOut(ctx sdk.Context,
	sender sdk.AccAddress,
	recipient sdk.AccAddress,
	routes []types.SwapAmountOutRoute,
	tokenInMaxAmount math.Int,
	tokenOut sdk.Coin,
	discount sdk.Dec,
) (tokenInAmount math.Int, totalDiscountedSwapFee sdk.Dec, discountOut sdk.Dec, err error)

MultihopSwapExactAmountOut defines the output denom and output amount for the last pool. Calculation starts by providing the tokenOutAmount of the final pool to calculate the required tokenInAmount the calculated tokenInAmount is used as defined tokenOutAmount of the previous pool, calculating in reverse order of the swap Transaction succeeds if the calculated tokenInAmount of the first pool is less than the defined tokenInMaxAmount defined.

func (Keeper) SelectOneSwapRequest added in v0.11.0

func (k Keeper) SelectOneSwapRequest(ctx sdk.Context, sprefix []byte) (sdk.Msg, uint64)

func (Keeper) SelectReverseSwapRequest added in v0.11.0

func (k Keeper) SelectReverseSwapRequest(ctx sdk.Context, msg sdk.Msg) (sdk.Msg, uint64)

func (Keeper) SetDenomLiquidity

func (k Keeper) SetDenomLiquidity(ctx sdk.Context, denomLiquidity types.DenomLiquidity)

SetDenomLiquidity sets a specific denomLiquidity in the store from its index

func (*Keeper) SetHooks

func (k *Keeper) SetHooks(gh types.AmmHooks) *Keeper

Set the amm hooks.

func (Keeper) SetLastSwapRequestIndex added in v0.11.0

func (k Keeper) SetLastSwapRequestIndex(ctx sdk.Context, index uint64)

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams set the params

func (Keeper) SetPool

func (k Keeper) SetPool(ctx sdk.Context, pool types.Pool) error

SetPool set a specific pool in the store from its index

func (Keeper) SetSlippageTrack added in v0.13.0

func (k Keeper) SetSlippageTrack(ctx sdk.Context, track types.OraclePoolSlippageTrack)

func (Keeper) SetSwapExactAmountInRequests added in v0.11.0

func (k Keeper) SetSwapExactAmountInRequests(ctx sdk.Context, msg *types.MsgSwapExactAmountIn, index uint64)

SetSwapExactAmountInRequests stores swap exact amount in request

func (Keeper) SetSwapExactAmountOutRequests added in v0.11.0

func (k Keeper) SetSwapExactAmountOutRequests(ctx sdk.Context, msg *types.MsgSwapExactAmountOut, index uint64)

SetSwapExactAmountInRequests stores swap exact amount out request

func (Keeper) SlippageTrack added in v0.13.0

func (Keeper) SlippageTrackAll added in v0.13.0

func (Keeper) SwapEstimation added in v0.13.0

func (Keeper) SwapEstimationByDenom added in v0.16.0

func (Keeper) SwapExactAmountIn

func (k Keeper) SwapExactAmountIn(
	ctx sdk.Context,
	sender sdk.AccAddress,
	recipient sdk.AccAddress,
	pool types.Pool,
	tokenIn sdk.Coin,
	tokenOutDenom string,
	tokenOutMinAmount math.Int,
	swapFee sdk.Dec,
) (tokenOutAmount math.Int, err error)

SwapExactAmountIn is an internal method for swapping an exact amount of tokens as input to a pool, using the provided swapFee. This is intended to allow different swap fees as determined by multi-hops, or when recovering from chain liveness failures. TODO: investigate if swapFee can be unexported https://github.com/osmosis-labs/osmosis/issues/3130

func (Keeper) SwapExactAmountOut

func (k Keeper) SwapExactAmountOut(
	ctx sdk.Context,
	sender sdk.AccAddress,
	recipient sdk.AccAddress,
	pool types.Pool,
	tokenInDenom string,
	tokenInMaxAmount math.Int,
	tokenOut sdk.Coin,
	swapFee sdk.Dec,
) (tokenInAmount math.Int, err error)

SwapExactAmountOut is a method for swapping to get an exact number of tokens out of a pool, using the provided swapFee. This is intended to allow different swap fees as determined by multi-hops, or when recovering from chain liveness failures.

func (Keeper) SwapFeesToRevenueToken

func (k Keeper) SwapFeesToRevenueToken(ctx sdk.Context, pool types.Pool, fee sdk.Coins) error

No fee management required when doing swap from fees to revenue token

func (Keeper) SwapInAmtGivenOut added in v0.11.0

func (k Keeper) SwapInAmtGivenOut(
	ctx sdk.Context, poolId uint64, oracleKeeper types.OracleKeeper, snapshot *types.Pool,
	tokensOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) (
	tokenIn sdk.Coin, slippageAmount sdk.Dec, weightBalanceBonus sdk.Dec, err error,
)

SwapInAmtGivenOut is a mutative method for CalcOutAmtGivenIn, which includes the actual swap.

func (Keeper) SwapOutAmtGivenIn added in v0.11.0

func (k Keeper) SwapOutAmtGivenIn(
	ctx sdk.Context, poolId uint64,
	oracleKeeper types.OracleKeeper,
	snapshot *types.Pool,
	tokensIn sdk.Coins,
	tokenOutDenom string,
	swapFee sdk.Dec,
) (tokenOut sdk.Coin, slippageAmount sdk.Dec, weightBalanceBonus sdk.Dec, err error)

SwapOutAmtGivenIn is a mutative method for CalcOutAmtGivenIn, which includes the actual swap.

func (Keeper) TrackSlippage added in v0.13.0

func (k Keeper) TrackSlippage(ctx sdk.Context, poolId uint64, amount sdk.Coin)

func (Keeper) UpdatePoolForSwap

func (k Keeper) UpdatePoolForSwap(
	ctx sdk.Context,
	pool types.Pool,
	sender sdk.AccAddress,
	recipient sdk.AccAddress,
	tokenIn sdk.Coin,
	tokenOut sdk.Coin,
	swapFeeIn sdk.Dec,
	swapFeeOut sdk.Dec,
	weightBalanceBonus sdk.Dec,
) (sdk.Int, error)

UpdatePoolForSwap takes a pool, sender, and tokenIn, tokenOut amounts It then updates the pool's balances to the new reserve amounts, and sends the in tokens from the sender to the pool, and the out tokens from the pool to the sender.

func (Keeper) UpdatePoolParams added in v0.18.0

func (k Keeper) UpdatePoolParams(ctx sdk.Context, poolId uint64, poolParams types.PoolParams) (uint64, types.PoolParams, error)

UpdatePoolParams updates the pool params

Jump to

Keyboard shortcuts

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