Documentation ¶
Index ¶
- func NewMsgServerImpl(keeper Keeper) types.MsgServer
- func NewQuerier(k Keeper) queryServer
- type Keeper
- func (k Keeper) CheckEnoughBalances(ctx sdk.Context, coinsToSpend sdk.Coins, account sdk.AccAddress) error
- func (k Keeper) ExitPool(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, poolSharesOut sdk.Coin) (tokensOut sdk.Coins, err error)
- func (k Keeper) FetchAllPools(ctx sdk.Context) (pools []types.Pool)
- func (k Keeper) FetchPool(ctx sdk.Context, poolId uint64) (pool types.Pool, err error)
- func (k Keeper) FetchPoolFromPair(ctx sdk.Context, denomA string, denomB string) (pool types.Pool, err error)
- func (k Keeper) GetDenomLiquidity(ctx sdk.Context, denom string) (amount sdkmath.Int, err error)
- func (k Keeper) GetNextPoolNumber(ctx sdk.Context) (poolNumber uint64, err error)
- func (k Keeper) GetNextPoolNumberAndIncrement(ctx sdk.Context) (uint64, error)
- func (k Keeper) GetParams(ctx sdk.Context) (p types.Params)
- func (k Keeper) GetTotalLiquidity(ctx sdk.Context) (coins sdk.Coins)
- func (k Keeper) JoinPool(ctx sdk.Context, joinerAddr sdk.AccAddress, poolId uint64, tokensIn sdk.Coins, ...) (pool types.Pool, numSharesOut sdk.Coin, remCoins sdk.Coins, err error)
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) NewPool(ctx sdk.Context, sender sdk.AccAddress, poolParams types.PoolParams, ...) (poolId uint64, err error)
- func (k Keeper) RecordTotalLiquidityDecrease(ctx sdk.Context, coins sdk.Coins) error
- func (k Keeper) RecordTotalLiquidityIncrease(ctx sdk.Context, coins sdk.Coins) error
- func (k Keeper) SetDenomLiquidity(ctx sdk.Context, denom string, amount sdkmath.Int) error
- 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.Pool)
- func (k Keeper) SetPoolIdByDenom(ctx sdk.Context, pool types.Pool)
- func (k Keeper) SetTotalLiquidity(ctx sdk.Context, coins sdk.Coins) error
- func (k Keeper) SwapExactAmountIn(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, tokenIn sdk.Coin, ...) (tokenOut sdk.Coin, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMsgServerImpl ¶
NewMsgServerImpl returns an implementation of the MsgServer interface for the provided Keeper.
func NewQuerier ¶
func NewQuerier(k Keeper) queryServer
Types ¶
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
func NewKeeper ¶
func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ps paramtypes.Subspace, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, distrKeeper types.DistrKeeper, ) Keeper
NewKeeper Creates a new keeper for the spot module.
args
cdc: a codec storeKey: the key-value store key that this keeper uses ps: the param subspace for this keeper accountKeeper: the auth module\'s keeper for accounts bankKeeper: the bank module\'s keeper for bank transfers
ret
Keeper: a keeper for the spot module
func (Keeper) CheckEnoughBalances ¶
func (k Keeper) CheckEnoughBalances( ctx sdk.Context, coinsToSpend sdk.Coins, account sdk.AccAddress, ) error
Checks if account has enough balance to spend coins.
args:
- ctx: cosmos-sdk context
- coinsToSpend: the coins that the account wishes to spend
- account: the address of the account spending the coins
ret:
- error: an error if insufficient balance
func (Keeper) ExitPool ¶
func (k Keeper) ExitPool( ctx sdk.Context, sender sdk.AccAddress, poolId uint64, poolSharesOut sdk.Coin, ) (tokensOut sdk.Coins, err error)
ExitPool Exits a pool by taking out tokens relative to the amount of pool shares in proportion to the total amount of pool shares.
For example, if a pool has 100 pool shares and ExitPool is called with 50 pool shares, half of the tokens (minus exit fees) are returned to the user.
Inverse of JoinPool.
Throws an error if the provided pool shares doesn't match up with the pool's actual pool share.
args:
- ctx: the cosmos-sdk context
- sender: the user who wishes to withdraw tokens
- poolId: the pool's numeric id
- poolSharesOut: the amount of pool shares to burn
ret:
- tokensOut: the amount of liquidity withdrawn from the pool
- err: error if any
func (Keeper) FetchAllPools ¶
FetchAllPools fetch all pools from the store and returns them.
func (Keeper) FetchPool ¶
FetchPool Fetches a pool by id number. Does not modify state. Panics if the bytes could not be unmarshalled to a Pool proto object.
args
ctx: the cosmos-sdk context poolId: the pool id number
ret
pool: a Pool proto object
func (Keeper) FetchPoolFromPair ¶
func (k Keeper) FetchPoolFromPair(ctx sdk.Context, denomA string, denomB string) ( pool types.Pool, err error, )
FetchPoolFromPair Given a pair of denom, find the corresponding pool id if it exists.
args:
- denomA: One denom
- denomB: A second denom
ret:
- poolId: the pool id
- err: error if any
func (Keeper) GetDenomLiquidity ¶
Fetches the liquidity for a specific coin denom.
args:
ctx: the cosmos-sdk context denom: the coin denom
ret:
amount: the amount of liquidity for the provided coin. Returns 0 if not found.
func (Keeper) GetNextPoolNumber ¶
GetNextPoolNumber Retrieves the next pool id number to use when creating a new pool. This function is idempotent (does not change state).
args
ctx: the cosmos-sdk context
ret
uint64: a pool id number
func (Keeper) GetNextPoolNumberAndIncrement ¶
GetNextPoolNumberAndIncrement Returns the next pool id number, and increments the state's next pool id number by one so that the next pool creation uses an autoincremented id number.
args
ctx: the cosmos-sdk context
ret
uint64: a pool id number
func (Keeper) GetTotalLiquidity ¶
Fetches the liquidity for all tokens in the spot.
args:
ctx: the cosmos-sdk context
ret:
coins: an array of liquidities in the spot
func (Keeper) JoinPool ¶
func (k Keeper) JoinPool( ctx sdk.Context, joinerAddr sdk.AccAddress, poolId uint64, tokensIn sdk.Coins, shouldSwap bool, ) (pool types.Pool, numSharesOut sdk.Coin, remCoins sdk.Coins, err error)
JoinPool Joins a pool without swapping leftover assets if the ratios don't exactly match the pool's asset ratios.
For example, if a pool has 100 pool shares, 100foo, 100bar, and JoinPool is called with 75foo and bar, only 50foo and 50bar would be deposited. 25foo in remCoins would be returned to the user, along with 50 pool shares would be minted and given to the user.
Inverse of ExitPool.
args:
- ctx: the cosmos-sdk context
- joinerAddr: the user who wishes to withdraw tokens
- poolId: the pool's numeric id
- tokensIn: the amount of liquidity to provide
ret:
- pool: the updated pool after joining
- numSharesOut: the pool shares minted and returned to the user
- remCoins: the number of remaining coins from the user's initial deposit attempt
- err: error if any
func (Keeper) NewPool ¶
func (k Keeper) NewPool( ctx sdk.Context, sender sdk.AccAddress, poolParams types.PoolParams, poolAssets []types.PoolAsset, ) (poolId uint64, err error)
NewPool Creates a brand new pool and writes it to the state.
args
ctx: the cosmos-sdk context sender: the pool creator's address poolParams: parameters of the pool, represented by a PoolParams proto object poolAssets: initial assets in the pool, represented by a PoolAssets proto object array
ret
poolId: the pool id number err: an error if any occurred
func (Keeper) RecordTotalLiquidityDecrease ¶
Increases the total liquidity of the provided coins by the coin amount.
args:
ctx: the cosmos-sdk context coins: the coins removed from the spot
func (Keeper) RecordTotalLiquidityIncrease ¶
Increases the total liquidity of the provided coins by the coin amount.
args:
ctx: the cosmos-sdk context coins: the coins added to the spot
func (Keeper) SetDenomLiquidity ¶
Sets the liquidity for a specific coin denom.
args:
ctx: the cosmos-sdk context denom: the coin denom amount: the amount of liquidity for the coin
func (Keeper) SetNextPoolNumber ¶
Sets the next pool id that should be chosen when a new pool is created. This function changes the state.
args
ctx: the cosmos-sdk context poolNumber: the numeric id of the next pool number to use
func (Keeper) SetPool ¶
SetPool Writes a pool to the state. Panics if the pool proto could not be marshaled.
args:
- ctx: the cosmos-sdk context
- pool: the Pool proto object
func (Keeper) SetPoolIdByDenom ¶
SetPoolIdByDenom Writes a pool to the state accessible with the PoolId. Panics if the pool proto could not be marshaled.
args:
- ctx: the cosmos-sdk context
- pool: the Pool proto object
func (Keeper) SetTotalLiquidity ¶
Sets the total liquidity for each coin.
args:
ctx: the cosmos-sdk context coins: the array of liquidities to update with
func (Keeper) SwapExactAmountIn ¶
func (k Keeper) SwapExactAmountIn( ctx sdk.Context, sender sdk.AccAddress, poolId uint64, tokenIn sdk.Coin, tokenOutDenom string, ) (tokenOut sdk.Coin, err error)
SwapExactAmountIn Given a poolId and the amount of tokens to swap in, returns the number of tokens out received, specified by the tokenOutDenom.
For example, if pool 1 has 100foo and 100bar, this function can be called with tokenIn=10foo and tokenOutDenom=bar.
args:
- ctx: the cosmos-sdk context
- sender: the address wishing to perform the swap
- poolId: the pool id number
- tokenIn: the amount of tokens to given to the pool
- tokenOutDenom: the denom of the token taken out of the pool
ret:
- tokenOut: the amount of tokens taken out of the pool
- err: error if any