Documentation ¶
Index ¶
- func NewQuerier(k Keeper) queryServer
- type Keeper
- func (k Keeper) CreatePool(ctx sdk.Context, pair common.AssetPair, tradeLimitRatio sdk.Dec, ...)
- func (k Keeper) ExistsPool(ctx sdk.Context, pair common.AssetPair) bool
- func (k Keeper) GetAllPools(ctx sdk.Context) []*types.Pool
- func (k Keeper) GetBaseAssetPrice(ctx sdk.Context, pair common.AssetPair, dir types.Direction, ...) (quoteAmount sdk.Dec, err error)
- func (k Keeper) GetBaseAssetTWAP(ctx sdk.Context, pair common.AssetPair, direction types.Direction, ...) (quoteAssetAmount sdk.Dec, err error)
- func (k Keeper) GetCurrentTWAP(ctx sdk.Context, pair common.AssetPair) (types.CurrentTWAP, error)
- func (k Keeper) GetMaintenanceMarginRatio(ctx sdk.Context, pair common.AssetPair) sdk.Dec
- func (k Keeper) GetQuoteAssetPrice(ctx sdk.Context, pair common.AssetPair, dir types.Direction, ...) (baseAssetAmount sdk.Dec, err error)
- func (k Keeper) GetQuoteAssetTWAP(ctx sdk.Context, pair common.AssetPair, direction types.Direction, ...) (baseAssetAmount sdk.Dec, err error)
- func (k Keeper) GetSettlementPrice(ctx sdk.Context, pair common.AssetPair) (sdk.Dec, error)
- func (k Keeper) GetSpotPrice(ctx sdk.Context, pair common.AssetPair) (sdk.Dec, error)
- func (k Keeper) GetUnderlyingPrice(ctx sdk.Context, pair common.AssetPair) (sdk.Dec, error)
- func (k Keeper) IsOverSpreadLimit(ctx sdk.Context, pair common.AssetPair) bool
- func (k Keeper) SwapBaseForQuote(ctx sdk.Context, pair common.AssetPair, dir types.Direction, ...) (quoteAssetAmount sdk.Dec, err error)
- func (k Keeper) SwapQuoteForBase(ctx sdk.Context, pair common.AssetPair, dir types.Direction, ...) (baseAssetAmount sdk.Dec, err error)
- func (k Keeper) UpdateTWAP(ctx sdk.Context, pairID string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewQuerier ¶ added in v0.3.0
func NewQuerier(k Keeper) queryServer
Types ¶
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
func NewKeeper ¶
func NewKeeper( codec codec.BinaryCodec, storeKey sdk.StoreKey, pricefeedKeeper types.PricefeedKeeper, ) Keeper
func (Keeper) CreatePool ¶
func (k Keeper) CreatePool( ctx sdk.Context, pair common.AssetPair, tradeLimitRatio sdk.Dec, quoteAssetReserve sdk.Dec, baseAssetReserve sdk.Dec, fluctuationLimitRatio sdk.Dec, maxOracleSpreadRatio sdk.Dec, maintenanceMarginRatio sdk.Dec, )
CreatePool creates a pool for a specific pair.
func (Keeper) ExistsPool ¶
ExistsPool returns true if pool exists, false if not.
func (Keeper) GetAllPools ¶ added in v0.2.10
GetAllPools returns all pools that exist.
func (Keeper) GetBaseAssetPrice ¶
func (k Keeper) GetBaseAssetPrice( ctx sdk.Context, pair common.AssetPair, dir types.Direction, baseAssetAmount sdk.Dec, ) (quoteAmount sdk.Dec, err error)
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 common.AssetPair, direction types.Direction, baseAssetAmount sdk.Dec, lookbackInterval time.Duration, ) (quoteAssetAmount sdk.Dec, err error)
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) GetCurrentTWAP ¶ added in v0.9.2
GetCurrentTWAP fetches the current median price of all oracles for a specific market
func (Keeper) GetMaintenanceMarginRatio ¶ added in v0.11.0
* 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
func (Keeper) GetQuoteAssetPrice ¶
func (k Keeper) GetQuoteAssetPrice( ctx sdk.Context, pair common.AssetPair, dir types.Direction, quoteAmount sdk.Dec, ) (baseAssetAmount sdk.Dec, err error)
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
- quoteAmount: the amount of quote asset
ret:
- baseAssetAmount: the amount of base assets required to make the desired swap
- err: error
func (Keeper) GetQuoteAssetTWAP ¶
func (k Keeper) GetQuoteAssetTWAP( ctx sdk.Context, pair common.AssetPair, direction types.Direction, quoteAssetAmount sdk.Dec, lookbackInterval time.Duration, ) (baseAssetAmount sdk.Dec, err error)
Returns the amount of base assets required to achieve a move of quoteAssetAmount in a direction, based on historical snapshots. e.g. if removing <quoteAssetAmount> quote assets from the pool, returns the amount of base assets do so.
args:
- ctx: cosmos-sdk context
- pair: the token pair
- direction: add or remove
- quoteAssetAmount: amount of base asset to add or remove
- lookbackInterval: how far back to calculate TWAP
ret:
- baseAssetAmount: the amount of quote asset to make the desired move, as sdk.Dec
- err: error
func (Keeper) GetSettlementPrice ¶
TODO(mercilex): implement
func (Keeper) GetSpotPrice ¶
GetSpotPrice 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) GetUnderlyingPrice ¶
Retrieves the base asset's price from PricefeedKeeper (oracle). The price is denominated in quote asset, so # of quote asset to buy one base asset.
args:
- ctx: cosmos-sdk context
- pair: token pair
ret:
- price: price as sdk.Dec
- err: error
func (Keeper) IsOverSpreadLimit ¶
* 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 or not the price has deviated from the oracle price beyond a spread ratio
func (Keeper) SwapBaseForQuote ¶
func (k Keeper) SwapBaseForQuote( ctx sdk.Context, pair common.AssetPair, dir types.Direction, baseAssetAmount sdk.Dec, quoteAmountLimit sdk.Dec, skipFluctuationLimitCheck bool, ) (quoteAssetAmount sdk.Dec, err error)
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
- baseAssetAmount: the amount of quote 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:
- quoteAssetAmount: the amount of quote asset swapped
- err: error
func (Keeper) SwapQuoteForBase ¶
func (k Keeper) SwapQuoteForBase( ctx sdk.Context, pair common.AssetPair, dir types.Direction, quoteAssetAmount sdk.Dec, baseAmountLimit sdk.Dec, skipFluctuationLimitCheck bool, ) (baseAssetAmount sdk.Dec, err error)
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