Documentation ¶
Index ¶
- func NewMsgServerImpl(keeper Keeper) types.MsgServer
- func NewQuerier(k Keeper) types.QueryServer
- type ActivePairsState
- func (state ActivePairsState) AddActivePairs(ctx sdk.Context, pairs []common.AssetPair)
- func (state ActivePairsState) Get(ctx sdk.Context, pair common.AssetPair) (active bool)
- func (state ActivePairsState) Iterate(ctx sdk.Context, do func(*types.ActivePairMarshaler) (stop bool))
- func (state ActivePairsState) Set(ctx sdk.Context, pair common.AssetPair, active bool)
- func (state ActivePairsState) SetMany(ctx sdk.Context, pairs common.AssetPairs, active bool)
- type Keeper
- func (k Keeper) ActivePairsStore() ActivePairsState
- func (k Keeper) CalculateMedianPrice(prices []types.CurrentPrice) sdk.Dec
- func (k Keeper) GatherRawPrices(ctx sdk.Context, token0 string, token1 string) error
- func (k Keeper) GetCurrentPrice(ctx sdk.Context, token0 string, token1 string) (currPrice types.CurrentPrice, err error)
- func (k Keeper) GetCurrentPrices(ctx sdk.Context) types.CurrentPrices
- func (k Keeper) GetCurrentTWAP(ctx sdk.Context, token0 string, token1 string) (twap sdk.Dec, err error)
- func (k Keeper) GetOraclesForPair(ctx sdk.Context, pairID string) (oracles []sdk.AccAddress)
- func (k Keeper) GetOraclesForPairs(ctx sdk.Context, pairs common.AssetPairs) map[common.AssetPair][]sdk.AccAddress
- func (k Keeper) GetPairs(ctx sdk.Context) common.AssetPairs
- func (k Keeper) GetParams(ctx sdk.Context) types.Params
- func (k Keeper) GetRawPrices(ctx sdk.Context, pairStr string) types.PostedPrices
- func (k Keeper) GetTwapLookbackWindow(ctx sdk.Context) time.Duration
- func (k Keeper) IsActivePair(ctx sdk.Context, pairID string) bool
- func (k Keeper) IsWhitelistedOracle(ctx sdk.Context, pairID string, address sdk.AccAddress) bool
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) OraclesStore() OraclesState
- func (k Keeper) PostRawPrice(ctx sdk.Context, oracle sdk.AccAddress, pairStr string, price sdk.Dec, ...) (err error)
- func (k Keeper) SetParams(ctx sdk.Context, params types.Params)
- func (k Keeper) WhitelistOracles(ctx sdk.Context, oracles []sdk.AccAddress)
- func (k Keeper) WhitelistOraclesForPairs(ctx sdk.Context, oracles []sdk.AccAddress, proposedPairs []common.AssetPair)
- type OraclesState
- func (state OraclesState) AddOracles(ctx sdk.Context, pair common.AssetPair, oracles []sdk.AccAddress)
- func (state OraclesState) Get(ctx sdk.Context, pair common.AssetPair) (oracles []sdk.AccAddress)
- func (state OraclesState) Iterate(ctx sdk.Context, do func(*types.OraclesMarshaler) (stop bool))
- func (state OraclesState) Set(ctx sdk.Context, pair common.AssetPair, oracles []sdk.AccAddress)
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 ¶ added in v0.15.0
func NewQuerier(k Keeper) types.QueryServer
Types ¶
type ActivePairsState ¶ added in v0.5.2
type ActivePairsState Keeper
----------------------------------------------------------------------------- ActivePairsState implements methods for updating the "active pairs" sdk.KVStore
func (ActivePairsState) AddActivePairs ¶ added in v0.5.2
func (state ActivePairsState) AddActivePairs( ctx sdk.Context, pairs []common.AssetPair, )
func (ActivePairsState) Iterate ¶ added in v0.5.2
func (state ActivePairsState) Iterate( ctx sdk.Context, do func(*types.ActivePairMarshaler) (stop bool), )
func (ActivePairsState) Set ¶ added in v0.5.2
ActivePairsState.Set either sets a pair to active or deletes it from the
key-value store (i.e., pairs default to inactive if they don't exist).
func (ActivePairsState) SetMany ¶ added in v0.5.2
func (state ActivePairsState) SetMany( ctx sdk.Context, pairs common.AssetPairs, active bool, )
type Keeper ¶
type Keeper struct { RawPrices collections.Map[collections.Pair[common.AssetPair, sdk.AccAddress], types.PostedPrice] CurrentPrices collections.Map[common.AssetPair, types.CurrentPrice] // PriceSnapshots maps types.PriceSnapshot to the common.AssetPair of the snapshot and the creation timestamp as keys.Uint64Key. PriceSnapshots collections.Map[collections.Pair[common.AssetPair, time.Time], types.PriceSnapshot] // contains filtered or unexported fields }
func NewKeeper ¶
func NewKeeper( cdc codec.BinaryCodec, storeKey, memKey storetypes.StoreKey, ps paramtypes.Subspace, ) Keeper
func (Keeper) ActivePairsStore ¶ added in v0.5.2
func (k Keeper) ActivePairsStore() ActivePairsState
ActivePairsStore maintains the "active pairs" KVStore: maps pair name → isActive. If a pair doesn't have a key in the store, the pair is inactive.
func (Keeper) CalculateMedianPrice ¶
func (k Keeper) CalculateMedianPrice(prices []types.CurrentPrice) sdk.Dec
CalculateMedianPrice calculates the median prices for the input prices.
func (Keeper) GatherRawPrices ¶ added in v0.9.2
GatherRawPrices updates the current price of an asset to the median of all valid posted oracle prices.
args:
- ctx: cosmos-sdk context
- token0: the base asset
- token1: the quote asset
ret:
- err: error if any
func (Keeper) GetCurrentPrice ¶
func (k Keeper) GetCurrentPrice(ctx sdk.Context, token0 string, token1 string, ) (currPrice types.CurrentPrice, err error)
GetCurrentPrice fetches the current median price of all oracles for a specific market.
args:
- ctx: cosmos-sdk context
- token0: the base asset
- token1: the quote asset
ret:
- currPrice: the current price
- err: error if any
func (Keeper) GetCurrentPrices ¶
func (k Keeper) GetCurrentPrices(ctx sdk.Context) types.CurrentPrices
GetCurrentPrices returns all current price objects from the store
func (Keeper) GetCurrentTWAP ¶ added in v0.9.2
func (k Keeper) GetCurrentTWAP(ctx sdk.Context, token0 string, token1 string, ) (twap sdk.Dec, err error)
Gets the time-weighted average price from [ ctx.BlockTime() - interval, ctx.BlockTime() ) Note the open-ended right bracket.
If there's only one snapshot, then this function returns the price from that single snapshot.
Returns -1 if there's no price.
Args: - ctx: cosmos-sdk context - pair: the token pair
Returns: - twap: TWAP as sdk.Dec - err: error
func (Keeper) GetOraclesForPair ¶ added in v0.5.2
GetOraclesForPair returns the oracles for a valid asset pair
func (Keeper) GetOraclesForPairs ¶ added in v0.5.2
func (k Keeper) GetOraclesForPairs(ctx sdk.Context, pairs common.AssetPairs, ) map[common.AssetPair][]sdk.AccAddress
GetOraclesForPairs returns the 'oraclesMatrix' corresponding to 'pairs'. 'oraclesMap' is a map from pair → list of oracles. This function effectively gives a subset of the OraclesState KVStore.
func (Keeper) GetPairs ¶
func (k Keeper) GetPairs(ctx sdk.Context) common.AssetPairs
GetPairs returns the pairs from params
func (Keeper) GetRawPrices ¶
GetRawPrices fetches the set of all prices posted by oracles for an asset
func (Keeper) GetTwapLookbackWindow ¶ added in v0.12.0
func (Keeper) IsActivePair ¶ added in v0.5.2
GetPair returns the market if it is in the pricefeed system
func (Keeper) IsWhitelistedOracle ¶ added in v0.5.2
IsWhitelistedOracle returns true if the address is whitelisted, false if not.
func (Keeper) OraclesStore ¶ added in v0.5.2
func (k Keeper) OraclesStore() OraclesState
OraclesStore maintains the "oracles" KVStore: maps pair name → oracles.
func (Keeper) PostRawPrice ¶ added in v0.9.2
func (k Keeper) PostRawPrice( ctx sdk.Context, oracle sdk.AccAddress, pairStr string, price sdk.Dec, expiry time.Time, ) (err error)
PostRawPrice updates the posted price for a specific oracle
args:
- ctx: the sdk context
- oracle: the address of the oracle posting the raw price
- pairStr: the string of the asset pair
- price: the price
- expiry: when the raw price should expire
ret:
- err: error if any
func (Keeper) WhitelistOracles ¶ added in v0.1.0
func (k Keeper) WhitelistOracles(ctx sdk.Context, oracles []sdk.AccAddress)
Whitelists given 'oracles' for all of the current pairs in the module params.
func (Keeper) WhitelistOraclesForPairs ¶ added in v0.5.2
func (k Keeper) WhitelistOraclesForPairs( ctx sdk.Context, oracles []sdk.AccAddress, proposedPairs []common.AssetPair, )
WhitelistOraclesForPairs whitelists 'oracles' for the given 'pairs'.
type OraclesState ¶ added in v0.5.2
type OraclesState Keeper
----------------------------------------------------------------------------- OraclesState implements methods for updating the "oracles" sdk.KVStore
func (OraclesState) AddOracles ¶ added in v0.5.2
func (state OraclesState) AddOracles( ctx sdk.Context, pair common.AssetPair, oracles []sdk.AccAddress, )
func (OraclesState) Get ¶ added in v0.5.2
func (state OraclesState) Get( ctx sdk.Context, pair common.AssetPair, ) (oracles []sdk.AccAddress)
func (OraclesState) Iterate ¶ added in v0.5.2
func (state OraclesState) Iterate( ctx sdk.Context, do func(*types.OraclesMarshaler) (stop bool), )
func (OraclesState) Set ¶ added in v0.5.2
func (state OraclesState) Set( ctx sdk.Context, pair common.AssetPair, oracles []sdk.AccAddress, )