keeper

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

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 sdk.StoreKey,
	ps paramtypes.Subspace,
	accountKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper,
	distrKeeper types.DistrKeeper,
) Keeper

Creates a new keeper for the dex 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 dex module

func (Keeper) CheckEnoughBalances added in v0.1.0

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)

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 added in v0.1.0

func (k Keeper) FetchAllPools(ctx sdk.Context) (pools []types.Pool)

FeatchAllPools fetch all pools from the store and returns them.

func (Keeper) FetchPool

func (k Keeper) FetchPool(ctx sdk.Context, poolId uint64) (pool types.Pool, err error)

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

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

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

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

func (k Keeper) GetNextPoolNumber(ctx sdk.Context) (poolNumber uint64, err error)

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

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

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

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

GetParams get all parameters as types.Params

func (Keeper) GetTotalLiquidity

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

Fetches the liquidity for all tokens in the dex.

args:

ctx: the cosmos-sdk context

ret:

coins: an array of liquidities in the dex

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)

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

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

func (Keeper) NewPool

func (k Keeper) NewPool(
	ctx sdk.Context,
	sender sdk.AccAddress,
	poolParams types.PoolParams,
	poolAssets []types.PoolAsset,
) (poolId uint64, err error)

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

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

Increases the total liquidity of the provided coins by the coin amount.

args:

ctx: the cosmos-sdk context
coins: the coins removed from the dex

func (Keeper) RecordTotalLiquidityIncrease

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

Increases the total liquidity of the provided coins by the coin amount.

args:

ctx: the cosmos-sdk context
coins: the coins added to the dex

func (Keeper) SetDenomLiquidity

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

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

func (k Keeper) SetNextPoolNumber(ctx sdk.Context, poolNumber uint64)

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

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

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

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

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

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)

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

Jump to

Keyboard shortcuts

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