Documentation ¶
Index ¶
- func AllInvariants(keeper Keeper, bk types.BankKeeper) sdk.Invariant
- func NewBalancerMsgServerImpl(keeper *Keeper) balancer.MsgServer
- func NewMsgServerImpl(keeper *Keeper) types.MsgServer
- func PoolAccountInvariant(keeper Keeper, bk types.BankKeeper) sdk.Invariant
- func RegisterInvariants(ir sdk.InvariantRegistry, keeper Keeper, bk types.BankKeeper)
- type Keeper
- func (k Keeper) BurnPoolShareFromAccount(ctx sdk.Context, pool types.PoolI, addr sdk.AccAddress, amount sdk.Int) error
- func (k Keeper) CalculateSpotPrice(ctx sdk.Context, poolID uint64, baseAssetDenom string, quoteAssetDenom string) (sdk.Dec, error)
- func (k Keeper) CreatePool(ctx sdk.Context, msg types.CreatePoolMsg) (uint64, error)
- func (k Keeper) DeletePool(ctx sdk.Context, poolId uint64) error
- func (k Keeper) ExitPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, shareInAmount sdk.Int, ...) (exitCoins sdk.Coins, err error)
- func (k Keeper) ExitSwapExactAmountOut(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, tokenOut sdk.Coin, ...) (shareInAmount sdk.Int, err error)
- func (k Keeper) ExitSwapShareAmountIn(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, tokenOutDenom string, ...) (tokenOutAmount sdk.Int, err error)
- func (k Keeper) GetDenomLiquidity(ctx sdk.Context, denom string) sdk.Int
- func (k Keeper) GetNextPoolNumberAndIncrement(ctx sdk.Context) uint64
- func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)
- func (k Keeper) GetPoolAndPoke(ctx sdk.Context, poolId uint64) (types.PoolI, error)
- func (k Keeper) GetPoolsAndPoke(ctx sdk.Context) (res []types.PoolI, err error)
- func (k Keeper) GetTotalLiquidity(ctx sdk.Context) sdk.Coins
- func (k Keeper) IterateDenomLiquidity(ctx sdk.Context, cb func(sdk.Coin) bool)
- func (k Keeper) JoinPoolNoSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, shareOutAmount sdk.Int, ...) (err error)
- func (k Keeper) JoinSwapExactAmountIn(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, tokensIn sdk.Coins, ...) (sdk.Int, error)
- func (k Keeper) JoinSwapShareAmountOut(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, tokenInDenom string, ...) (tokenInAmount sdk.Int, err error)
- func (k Keeper) MarshalPool(pool types.PoolI) ([]byte, error)
- func (k Keeper) MintPoolShareToAccount(ctx sdk.Context, pool types.PoolI, addr sdk.AccAddress, amount sdk.Int) error
- func (k Keeper) MultihopSwapExactAmountIn(ctx sdk.Context, sender sdk.AccAddress, routes []types.SwapAmountInRoute, ...) (tokenOutAmount sdk.Int, err error)
- func (k Keeper) MultihopSwapExactAmountOut(ctx sdk.Context, sender sdk.AccAddress, routes []types.SwapAmountOutRoute, ...) (tokenInAmount sdk.Int, err error)
- func (k Keeper) RecordTotalLiquidityDecrease(ctx sdk.Context, coins sdk.Coins)
- func (k Keeper) RecordTotalLiquidityIncrease(ctx sdk.Context, coins sdk.Coins)
- func (k Keeper) SetDenomLiquidity(ctx sdk.Context, denom string, amount sdk.Int)
- func (k *Keeper) SetHooks(gh types.SwapHooks) *Keeper
- func (k Keeper) SetNextPoolNumber(ctx sdk.Context, poolNumber uint64)
- func (k Keeper) SetParams(ctx sdk.Context, params types.Params)
- func (k Keeper) SetPool(ctx sdk.Context, pool types.PoolI) error
- func (k *Keeper) SetStableSwapScalingFactors(ctx sdk.Context, scalingFactors []uint64, poolId uint64, ...) error
- func (k Keeper) SetTotalLiquidity(ctx sdk.Context, coins sdk.Coins)
- func (k Keeper) SwapExactAmountIn(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, tokenIn sdk.Coin, ...) (sdk.Int, error)
- func (k Keeper) SwapExactAmountOut(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, tokenInDenom string, ...) (tokenInAmount sdk.Int, err error)
- func (k Keeper) UnmarshalPool(bz []byte) (types.PoolI, error)
- type Querier
- func (q Querier) EstimateSwapExactAmountIn(ctx context.Context, req *types.QuerySwapExactAmountInRequest) (*types.QuerySwapExactAmountInResponse, error)
- func (q Querier) EstimateSwapExactAmountOut(ctx context.Context, req *types.QuerySwapExactAmountOutRequest) (*types.QuerySwapExactAmountOutResponse, error)
- func (q Querier) NumPools(ctx context.Context, _ *types.QueryNumPoolsRequest) (*types.QueryNumPoolsResponse, error)
- func (q Querier) Pool(ctx context.Context, req *types.QueryPoolRequest) (*types.QueryPoolResponse, error)
- func (q Querier) PoolParams(ctx context.Context, req *types.QueryPoolParamsRequest) (*types.QueryPoolParamsResponse, error)
- func (q Querier) Pools(ctx context.Context, req *types.QueryPoolsRequest) (*types.QueryPoolsResponse, error)
- func (q Querier) SpotPrice(ctx context.Context, req *types.QuerySpotPriceRequest) (*types.QuerySpotPriceResponse, error)
- func (q Querier) TotalLiquidity(ctx context.Context, _ *types.QueryTotalLiquidityRequest) (*types.QueryTotalLiquidityResponse, error)
- func (q Querier) TotalPoolLiquidity(ctx context.Context, req *types.QueryTotalPoolLiquidityRequest) (*types.QueryTotalPoolLiquidityResponse, error)
- func (q Querier) TotalShares(ctx context.Context, req *types.QueryTotalSharesRequest) (*types.QueryTotalSharesResponse, error)
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 swap module
func NewMsgServerImpl ¶
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, distrKeeper types.DistrKeeper) 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 ¶ added in v1.1.0
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 swap/pool/{poolID}. In addition, the x/bank metadata is updated to reflect the newly created swap share denomination.
func (Keeper) ExitSwapExactAmountOut ¶ added in v1.1.0
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) GetDenomLiquidity ¶
func (Keeper) GetNextPoolNumberAndIncrement ¶
GetNextPoolNumberAndIncrement returns the next pool number, and increments the corresponding state entry.
func (Keeper) GetPoolAndPoke ¶ added in v1.1.0
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.
func (Keeper) GetPoolsAndPoke ¶ added in v1.1.0
func (Keeper) IterateDenomLiquidity ¶
func (Keeper) JoinPoolNoSwap ¶ added in v1.1.0
func (k Keeper) JoinPoolNoSwap( ctx sdk.Context, sender sdk.AccAddress, poolId uint64, shareOutAmount sdk.Int, tokenInMaxs sdk.Coins, ) (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 ¶ added in v1.1.0
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 (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 swap denomination to the specified address returning an error upon failure. Shares are minted using the x/swap 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 (Keeper) RecordTotalLiquidityIncrease ¶
func (Keeper) SetDenomLiquidity ¶
func (Keeper) SetNextPoolNumber ¶
SetNextPoolNumber sets next pool number.
func (*Keeper) SetStableSwapScalingFactors ¶ added in v1.1.0
func (k *Keeper) SetStableSwapScalingFactors(ctx sdk.Context, scalingFactors []uint64, poolId uint64, scalingFactorGovernor string) error
set ScalingFactors in stable stableswap pools
func (Keeper) SetTotalLiquidity ¶
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 ¶
type Querier ¶ added in v1.1.0
type Querier struct {
Keeper
}
Querier defines a wrapper around the x/swap keeper providing gRPC method handlers.
func NewQuerier ¶ added in v1.1.0
func (Querier) EstimateSwapExactAmountIn ¶ added in v1.1.0
func (q Querier) EstimateSwapExactAmountIn(ctx context.Context, req *types.QuerySwapExactAmountInRequest) (*types.QuerySwapExactAmountInResponse, error)
func (Querier) EstimateSwapExactAmountOut ¶ added in v1.1.0
func (q Querier) EstimateSwapExactAmountOut(ctx context.Context, req *types.QuerySwapExactAmountOutRequest) (*types.QuerySwapExactAmountOutResponse, error)
func (Querier) NumPools ¶ added in v1.1.0
func (q Querier) NumPools(ctx context.Context, _ *types.QueryNumPoolsRequest) (*types.QueryNumPoolsResponse, error)
func (Querier) Pool ¶ added in v1.1.0
func (q Querier) Pool( ctx context.Context, req *types.QueryPoolRequest, ) (*types.QueryPoolResponse, error)
func (Querier) PoolParams ¶ added in v1.1.0
func (q Querier) PoolParams(ctx context.Context, req *types.QueryPoolParamsRequest) (*types.QueryPoolParamsResponse, error)
func (Querier) Pools ¶ added in v1.1.0
func (q Querier) Pools( ctx context.Context, req *types.QueryPoolsRequest, ) (*types.QueryPoolsResponse, error)
func (Querier) SpotPrice ¶ added in v1.1.0
func (q Querier) SpotPrice(ctx context.Context, req *types.QuerySpotPriceRequest) (*types.QuerySpotPriceResponse, error)
func (Querier) TotalLiquidity ¶ added in v1.1.0
func (q Querier) TotalLiquidity(ctx context.Context, _ *types.QueryTotalLiquidityRequest) (*types.QueryTotalLiquidityResponse, error)
func (Querier) TotalPoolLiquidity ¶ added in v1.1.0
func (q Querier) TotalPoolLiquidity(ctx context.Context, req *types.QueryTotalPoolLiquidityRequest) (*types.QueryTotalPoolLiquidityResponse, error)
func (Querier) TotalShares ¶ added in v1.1.0
func (q Querier) TotalShares(ctx context.Context, req *types.QueryTotalSharesRequest) (*types.QueryTotalSharesResponse, error)