keeper

package
v0.9.0-test-purpose-3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WeightRecoveryPortion = sdk.NewDecWithPrec(10, 2) // 10%

Functions

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,
	memKey storetypes.StoreKey,
	ps paramtypes.Subspace,

	bankKeeper types.BankKeeper,
	accountKeeper types.AccountKeeper,
	oracleKeeper types.OracleKeeper,
	commitmentKeeper *commitmentkeeper.Keeper,
	apKeeper types.AssetProfileKeeper,
) *Keeper

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) 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) 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) 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) GetDenomLiquidity

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

GetDenomLiquidity returns a denomLiquidity from its index

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) 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) 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,
	routes []types.SwapAmountInRoute,
	tokenIn sdk.Coin,
	tokenOutMinAmount math.Int,
) (tokenOutAmount math.Int, 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,
	routes []types.SwapAmountOutRoute,
	tokenInMaxAmount math.Int,
	tokenOut sdk.Coin,
) (tokenInAmount math.Int, 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) 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) 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) SwapExactAmountIn

func (k Keeper) SwapExactAmountIn(
	ctx sdk.Context,
	sender 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,
	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) UpdatePoolForSwap

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

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.

Jump to

Keyboard shortcuts

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