keeper

package
v11.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllInvariants

func AllInvariants(keeper Keeper, bk types.BankKeeper) sdk.Invariant

AllInvariants runs all invariants of the gamm module

func NewBalancerMsgServerImpl

func NewBalancerMsgServerImpl(keeper *Keeper) balancer.MsgServer

func NewMsgServerImpl

func NewMsgServerImpl(keeper *Keeper) types.MsgServer

func PoolAccountInvariant

func PoolAccountInvariant(keeper Keeper, bk types.BankKeeper) sdk.Invariant

PoolAccountInvariant checks that the pool account balance reflects the sum of pool assets

func RegisterInvariants

func RegisterInvariants(ir sdk.InvariantRegistry, keeper Keeper, bk types.BankKeeper)

RegisterInvariants registers all governance invariants.

Types

type Keeper

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

func NewKeeper

func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, communityPoolKeeper types.CommunityPoolKeeper) Keeper

func (Keeper) BurnPoolShareFromAccount

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

BurnPoolShareFromAccount burns `amount` of the given pools shares held by `addr`.

func (Keeper) CalculateSpotPrice

func (k Keeper) CalculateSpotPrice(
	ctx sdk.Context,
	poolID uint64,
	baseAssetDenom string,
	quoteAssetDenom string,
) (sdk.Dec, error)

CalculateSpotPrice returns the spot price of the quote asset in terms of the base asset, using the specified pool. E.g. if pool 1 traded 2 atom for 3 osmo, the quote asset was atom, and the base asset was osmo, this would return 1.5. (Meaning that 1 atom costs 1.5 osmo)

func (Keeper) CreatePool

func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (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, shares are minted and sent to the pool creator. The shares are created using a denomination in the form of gamm/pool/{poolID}. In addition, the x/bank metadata is updated to reflect the newly created GAMM share denomination.

func (Keeper) DeletePool

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

func (Keeper) ExitPool

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

func (Keeper) ExitSwapExactAmountOut

func (k Keeper) ExitSwapExactAmountOut(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolId uint64,
	tokenOut sdk.Coin,
	shareInMaxAmount sdk.Int,
) (shareInAmount sdk.Int, err error)

func (Keeper) ExitSwapShareAmountIn

func (k Keeper) ExitSwapShareAmountIn(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolId uint64,
	tokenOutDenom string,
	shareInAmount sdk.Int,
	tokenOutMinAmount sdk.Int,
) (tokenOutAmount sdk.Int, err error)

ExitSwapShareAmountIn is an Exit Pool transaction, that will exit all of the provided LP shares, and then swap it all against the pool into tokenOutDenom. If the amount of tokens gotten out after the swap is less than tokenOutMinAmount, return an error.

func (Keeper) ExportGenesis

func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState

ExportGenesis returns the capability module's exported genesis.

func (Keeper) GetDenomLiquidity

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

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) (params types.Params)

GetParams returns the total set params.

func (Keeper) GetPoolAndPoke

func (k Keeper) GetPoolAndPoke(ctx sdk.Context, poolId uint64) (types.PoolI, error)

GetPoolAndPoke returns a PoolI based on it's identifier if one exists. Prior to returning the pool, the weights of the pool are updated via PokePool. TODO: Consider rename to GetPool due to downstream API confusion.

func (Keeper) GetPoolDenoms

func (k Keeper) GetPoolDenoms(ctx sdk.Context, poolId uint64) ([]string, error)

GetPoolDenom retrieves the pool based on PoolId and returns the coin denoms that it holds.

func (Keeper) GetPoolsAndPoke

func (k Keeper) GetPoolsAndPoke(ctx sdk.Context) (res []types.PoolI, err error)

func (Keeper) GetTotalLiquidity

func (k Keeper) GetTotalLiquidity(ctx sdk.Context) sdk.Coins

func (Keeper) InitGenesis

func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState, unpacker codectypes.AnyUnpacker)

InitGenesis initializes the x/gamm module's state from a provided genesis state, which includes the current live pools, global pool parameters (e.g. pool creation fee), next pool id etc.

func (Keeper) IterateDenomLiquidity

func (k Keeper) IterateDenomLiquidity(ctx sdk.Context, cb func(sdk.Coin) bool)

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

func (k Keeper) JoinSwapExactAmountIn(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolId uint64,
	tokensIn sdk.Coins,
	shareOutMinAmount sdk.Int,
) (sdk.Int, error)

JoinSwapExactAmountIn is an LP transaction, that will LP all of the provided tokensIn coins. The underlying pool is responsible for swapping any non-even LP proportions to the correct ratios. An error is returned if the amount of LP shares obtained at the end is less than shareOutMinAmount. Otherwise, we return the total amount of shares outgoing from joining the pool.

func (Keeper) JoinSwapShareAmountOut

func (k Keeper) JoinSwapShareAmountOut(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolId uint64,
	tokenInDenom string,
	shareOutAmount sdk.Int,
	tokenInMaxAmount sdk.Int,
) (tokenInAmount sdk.Int, err error)

func (Keeper) MarshalPool

func (k Keeper) MarshalPool(pool types.PoolI) ([]byte, error)

func (Keeper) MintPoolShareToAccount

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

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

func (Keeper) MultihopSwapExactAmountIn

func (k Keeper) MultihopSwapExactAmountIn(
	ctx sdk.Context,
	sender sdk.AccAddress,
	routes []types.SwapAmountInRoute,
	tokenIn sdk.Coin,
	tokenOutMinAmount sdk.Int,
) (tokenOutAmount sdk.Int, err error)

MultihopSwapExactAmountIn 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) MultihopSwapExactAmountOut

func (k Keeper) MultihopSwapExactAmountOut(
	ctx sdk.Context,
	sender sdk.AccAddress,
	routes []types.SwapAmountOutRoute,
	tokenInMaxAmount sdk.Int,
	tokenOut sdk.Coin,
) (tokenInAmount sdk.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) 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) SetHooks

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

Set the gamm hooks.

func (Keeper) SwapExactAmountIn

func (k Keeper) SwapExactAmountIn(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolId uint64,
	tokenIn sdk.Coin,
	tokenOutDenom string,
	tokenOutMinAmount sdk.Int,
) (sdk.Int, error)

SwapExactAmountIn attempts to swap one asset, tokenIn, for another asset denominated via tokenOutDenom through a pool denoted by poolId specifying that tokenOutMinAmount must be returned in the resulting asset returning an error upon failure. Upon success, the resulting tokens swapped for are returned. A swap fee is applied determined by the pool's parameters.

func (Keeper) SwapExactAmountOut

func (k Keeper) SwapExactAmountOut(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolId uint64,
	tokenInDenom string,
	tokenInMaxAmount sdk.Int,
	tokenOut sdk.Coin,
) (tokenInAmount sdk.Int, err error)

func (Keeper) UnmarshalPool

func (k Keeper) UnmarshalPool(bz []byte) (types.PoolI, error)

type Querier

type Querier struct {
	Keeper
}

Querier defines a wrapper around the x/gamm keeper providing gRPC method handlers.

func NewQuerier

func NewQuerier(k Keeper) Querier

func (Querier) EstimateSwapExactAmountIn

EstimateSwapExactAmountIn estimates input token amount for a swap.

func (Querier) EstimateSwapExactAmountOut

EstimateSwapExactAmountOut estimates token output amount for a swap.

func (Querier) NumPools

NumPools returns total number of pools.

func (Querier) Pool

Pool checks if a pool exists and their respective poolWeights.

func (Querier) PoolParams

PoolParams queries a specified pool for its params.

func (Querier) Pools

Pools checks existence of multiple pools and their poolWeights

func (Querier) SpotPrice

SpotPrice returns target pool asset prices on base and quote assets.

func (Querier) TotalLiquidity

TotalLiquidity returns total liquidity across all pools.

func (Querier) TotalPoolLiquidity

TotalPoolLiquidity returns total liquidity in pool.

func (Querier) TotalShares

TotalShares returns total pool shares.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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