keeper

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewQuerier added in v0.3.0

func NewQuerier(k Keeper) types.QueryServer

Types

type Keeper

type Keeper struct {
	Pools            collections.Map[asset.Pair, types.Vpool]
	ReserveSnapshots collections.Map[collections.Pair[asset.Pair, time.Time], types.ReserveSnapshot]
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	codec codec.BinaryCodec,
	storeKey sdk.StoreKey,
	oracleKeeper types.OracleKeeper,
) Keeper

func (Keeper) CreatePool

func (k Keeper) CreatePool(
	ctx sdk.Context,
	pair asset.Pair,
	quoteAssetReserve sdk.Dec,
	baseAssetReserve sdk.Dec,
	config types.VpoolConfig,
) error

CreatePool creates a pool for a specific pair.

func (Keeper) EditPoolConfig added in v0.16.1

func (k Keeper) EditPoolConfig(
	ctx sdk.Context,
	pair asset.Pair,
	config types.VpoolConfig,
) error

func (Keeper) EditSwapInvariant added in v0.16.1

func (k Keeper) EditSwapInvariant(
	ctx sdk.Context,
	swapInvariantMap types.EditSwapInvariantsProposal_SwapInvariantMultiple,
) error

func (Keeper) ExistsPool

func (k Keeper) ExistsPool(ctx sdk.Context, pair asset.Pair) bool

ExistsPool returns true if pool exists, false if not.

func (Keeper) GetAllPools added in v0.2.10

func (k Keeper) GetAllPools(ctx sdk.Context) []types.Vpool

GetAllPools returns an array of all the pools

args:

  • ctx: the cosmos-sdk context

ret:

  • []types.Vpool: All defined vpool

func (Keeper) GetBaseAssetPrice

func (k Keeper) GetBaseAssetPrice(
	ctx sdk.Context,
	pair asset.Pair,
	dir types.Direction,
	baseAssetAmount sdk.Dec,
) (quoteAmount sdk.Dec, err error)

GetBaseAssetPrice So how much stablecoin you would get if you sold baseAssetAmount amount of perpetual contracts.

Returns the amount of quote assets required to achieve a move of baseAssetAmount in a direction. e.g. if removing <baseAssetAmount> base assets from the pool, returns the amount of quote assets do so.

args:

  • ctx: cosmos-sdk context
  • pair: the trading token pair
  • dir: add or remove
  • baseAssetAmount: the amount of base asset

ret:

  • quoteAmount: the amount of quote assets required to make the desired swap
  • err: error

func (Keeper) GetBaseAssetTWAP

func (k Keeper) GetBaseAssetTWAP(
	ctx sdk.Context,
	pair asset.Pair,
	direction types.Direction,
	baseAssetAmount sdk.Dec,
	lookbackInterval time.Duration,
) (quoteAssetAmount sdk.Dec, err error)

GetBaseAssetTWAP Returns the amount of quote assets required to achieve a move of baseAssetAmount in a direction, based on historical snapshots. e.g. if removing <baseAssetAmount> base assets from the pool, returns the amount of quote assets do so.

args:

  • ctx: cosmos-sdk context
  • pair: the token pair
  • direction: add or remove
  • baseAssetAmount: amount of base asset to add or remove
  • lookbackInterval: how far back to calculate TWAP

ret:

  • quoteAssetAmount: the amount of quote asset to make the desired move, as sdk.Dec
  • err: error

func (Keeper) GetLastSnapshot added in v0.16.1

func (k Keeper) GetLastSnapshot(ctx sdk.Context, pool types.Vpool) (types.ReserveSnapshot, error)

GetLastSnapshot retrieve the last snapshot for a particular vpool

args:

  • ctx: the cosmos-sdk context
  • pool: the vpool to check

func (Keeper) GetMaintenanceMarginRatio added in v0.11.0

func (k Keeper) GetMaintenanceMarginRatio(ctx sdk.Context, pair asset.Pair) (sdk.Dec, error)

GetMaintenanceMarginRatio returns the maintenance margin ratio for the pool from the asset pair.

args:

  • ctx: the cosmos-sdk context
  • pair: the asset pair

ret:

  • sdk.Dec: The maintenance margin ratio for the pool
  • error

func (Keeper) GetMarkPrice added in v0.15.0

func (k Keeper) GetMarkPrice(ctx sdk.Context, pair asset.Pair) (sdk.Dec, error)

GetMarkPrice retrieves the price of the base asset denominated in quote asset.

The convention is the amount of quote assets required to buy one base asset.

e.g. If the tokenPair is BTC:NUSD, the method would return sdk.Dec(40,000.00) because the instantaneous tangent slope on the vpool curve is 40,000.00, so it would cost ~40,000.00 to buy one BTC:NUSD perp.

args:

  • ctx: cosmos-sdk context
  • pair: the token pair to get price for

ret:

  • price: the price of the token pair as sdk.dec
  • err: error

func (Keeper) GetMarkPriceTWAP added in v0.15.0

func (k Keeper) GetMarkPriceTWAP(
	ctx sdk.Context,
	pair asset.Pair,
	lookbackInterval time.Duration,
) (quoteAssetAmount sdk.Dec, err error)

GetMarkPriceTWAP Returns the twap of the spot price (y/x).

args:

  • ctx: cosmos-sdk context
  • pair: the token pair
  • direction: add or remove
  • baseAssetAmount: amount of base asset to add or remove
  • lookbackInterval: how far back to calculate TWAP

ret:

  • quoteAssetAmount: the amount of quote asset to make the desired move, as sdk.Dec
  • err: error

func (Keeper) GetMaxLeverage added in v0.13.0

func (k Keeper) GetMaxLeverage(ctx sdk.Context, pair asset.Pair) (sdk.Dec, error)

GetMaxLeverage returns the maximum leverage required to open a position in the pool.

args:

  • ctx: the cosmos-sdk context
  • pair: the asset pair

ret:

  • sdk.Dec: The maintenance margin ratio for the pool
  • error

func (Keeper) GetPoolPrices added in v0.13.0

func (k Keeper) GetPoolPrices(
	ctx sdk.Context, pool types.Vpool,
) (types.PoolPrices, error)

GetPoolPrices returns the mark price, twap (mark) price, and index price for a vpool. An error is returned if the pool does not exist. No error is returned if the prices don't exist, however.

func (Keeper) GetQuoteAssetPrice

func (k Keeper) GetQuoteAssetPrice(
	ctx sdk.Context,
	pair asset.Pair,
	dir types.Direction,
	quoteAmountAbs sdk.Dec,
) (baseAssetAmount sdk.Dec, err error)

GetQuoteAssetPrice Returns the amount of base assets required to achieve a move of quoteAmount in a direction. e.g. if removing <quoteAmount> quote assets from the pool, returns the amount of base assets do so.

args:

  • ctx: cosmos-sdk context
  • pair: the trading token pair
  • dir: add or remove
  • quoteAmountAbs: the amount of quote asset

ret:

  • baseAssetAmount: the amount of base assets required to make the desired swap
  • err: error

func (Keeper) GetSettlementPrice

func (k Keeper) GetSettlementPrice(ctx sdk.Context, pair asset.Pair) (sdk.Dec, error)

TODO(mercilex): implement

func (Keeper) IsOverSpreadLimit

func (k Keeper) IsOverSpreadLimit(ctx sdk.Context, pair asset.Pair) (bool, error)

IsOverSpreadLimit compares the current spot price of the vpool (given by pair) to the underlying's index price (given by an oracle). It panics if you provide it with a pair that doesn't exist in the state.

args:

  • ctx: the cosmos-sdk context
  • pair: the asset pair

ret:

  • bool: whether the price has deviated from the oracle price beyond a spread ratio

func (Keeper) Logger added in v0.13.0

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

func (Keeper) SwapBaseForQuote

func (k Keeper) SwapBaseForQuote(
	ctx sdk.Context,
	pair asset.Pair,
	dir types.Direction,
	baseAmt sdk.Dec,
	quoteLimit sdk.Dec,
	skipFluctuationLimitCheck bool,
) (quoteAmtAbs sdk.Dec, err error)

SwapBaseForQuote Trades baseAssets in exchange for quoteAssets. The base asset is a crypto asset like BTC. The quote asset is a stablecoin like NUSD.

args:

  • ctx: cosmos-sdk context
  • pair: a token pair like BTC:NUSD
  • dir: either add or remove from pool
  • baseAmt: the amount of base asset being traded
  • quoteAmountLimit: a limiter to ensure the trader doesn't get screwed by slippage
  • skipFluctuationLimitCheck: whether or not to skip the fluctuation limit check

ret:

  • quoteAmtAbs: the absolute value of the amount swapped in quote assets
  • err: error

func (Keeper) SwapQuoteForBase

func (k Keeper) SwapQuoteForBase(
	ctx sdk.Context,
	pair asset.Pair,
	dir types.Direction,
	quoteAmt sdk.Dec,
	baseLimit sdk.Dec,
	skipFluctuationLimitCheck bool,
) (baseAmtAbs sdk.Dec, err error)

SwapQuoteForBase Trades quoteAssets in exchange for baseAssets. The quote asset is a stablecoin like NUSD. The base asset is a crypto asset like BTC or ETH.

args:

  • ctx: cosmos-sdk context
  • pair: a token pair like BTC:NUSD
  • dir: either add or remove from pool
  • quoteAssetAmount: the amount of quote asset being traded
  • baseAmountLimit: a limiter to ensure the trader doesn't get screwed by slippage
  • skipFluctuationLimitCheck: whether or not to skip the fluctuation limit check

ret:

  • baseAssetAmount: the amount of base asset swapped
  • err: error

Jump to

Keyboard shortcuts

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