Documentation ¶
Overview ¶
Package pricefeed allows a group of white-listed oracles to post price information of specific assets that are tracked by the system. For each asset, the module computes the median of all posted prices by white-listed oracles and takes that as the current price value.
Index ¶
- Constants
- Variables
- func EndBlocker(ctx sdk.Context, k Keeper) sdk.Tags
- func ErrEmptyInput(codespace sdk.CodespaceType) sdk.Error
- func ErrExpired(codespace sdk.CodespaceType) sdk.Error
- func ErrInvalidAsset(codespace sdk.CodespaceType) sdk.Error
- func ErrInvalidOracle(codespace sdk.CodespaceType) sdk.Error
- func ErrNoValidPrice(codespace sdk.CodespaceType) sdk.Error
- func HandleMsgPostPrice(ctx sdk.Context, k Keeper, msg MsgPostPrice) sdk.Result
- func InitGenesis(ctx sdk.Context, keeper Keeper, genState GenesisState)
- func NewHandler(k Keeper) sdk.Handler
- func NewQuerier(keeper Keeper) sdk.Querier
- func ParamKeyTable() params.KeyTable
- func RegisterCodec(cdc *codec.Codec)
- func ValidateGenesis(data GenesisState) error
- type AppModule
- func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) sdk.Tags
- func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) ([]abci.ValidatorUpdate, sdk.Tags)
- func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage
- func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate
- func (AppModule) Name() string
- func (am AppModule) NewHandler() sdk.Handler
- func (am AppModule) NewQuerierHandler() sdk.Querier
- func (AppModule) QuerierRoute() string
- func (AppModule) RegisterInvariants(_ sdk.InvariantRouter)
- func (AppModule) Route() string
- type AppModuleBasic
- type Asset
- type CurrentPrice
- type GenesisState
- type Keeper
- func (k Keeper) AddAsset(ctx sdk.Context, assetCode string, desc string)
- func (k Keeper) AddOracle(ctx sdk.Context, address string)
- func (k Keeper) GetAsset(ctx sdk.Context, assetCode string) (Asset, bool)
- func (k Keeper) GetAssets(ctx sdk.Context) []Asset
- func (k Keeper) GetCurrentPrice(ctx sdk.Context, assetCode string) CurrentPrice
- func (k Keeper) GetOracle(ctx sdk.Context, oracle string) (Oracle, bool)
- func (k Keeper) GetOracles(ctx sdk.Context) []Oracle
- func (k Keeper) GetRawPrices(ctx sdk.Context, assetCode string) []PostedPrice
- func (k Keeper) SetCurrentPrices(ctx sdk.Context) sdk.Error
- func (k Keeper) SetPrice(ctx sdk.Context, oracle sdk.AccAddress, assetCode string, price sdk.Dec, ...) (PostedPrice, sdk.Error)
- func (k Keeper) ValidatePostPrice(ctx sdk.Context, msg MsgPostPrice) sdk.Error
- type MsgPostPrice
- type Oracle
- type PostedPrice
- type QueryAssetsResp
- type QueryRawPricesResp
- type SortDecs
Constants ¶
const ( // DefaultCodespace codespace for the module DefaultCodespace sdk.CodespaceType = ModuleName // CodeEmptyInput error code for empty input errors CodeEmptyInput sdk.CodeType = 1 // CodeExpired error code for expired prices CodeExpired sdk.CodeType = 2 // CodeInvalidPrice error code for all input prices expired CodeInvalidPrice sdk.CodeType = 3 // CodeInvalidAsset error code for invalid asset CodeInvalidAsset sdk.CodeType = 4 // CodeInvalidOracle error code for invalid oracle CodeInvalidOracle sdk.CodeType = 5 )
const ( // ModuleKey is the name of the module ModuleName = "pricefeed" // StoreKey is the store key string for gov StoreKey = ModuleName // RouterKey is the message route for gov RouterKey = ModuleName // QuerierRoute is the querier route for gov QuerierRoute = ModuleName // Parameter store default namestore DefaultParamspace = ModuleName // Store prefix for the raw pricefeed of an asset RawPriceFeedPrefix = StoreKey + ":raw:" // Store prefix for the current price of an asset CurrentPricePrefix = StoreKey + ":currentprice:" // Store Prefix for the assets in the pricefeed system AssetPrefix = StoreKey + ":assets" // OraclePrefix store prefix for the oracle accounts OraclePrefix = StoreKey + ":oracles" )
TODO refactor constants to app.go
const ( // QueryCurrentPrice command for current price queries QueryCurrentPrice = "price" // QueryRawPrices command for raw price queries QueryRawPrices = "rawprices" // QueryAssets command for assets query QueryAssets = "assets" )
const (
// TypeMsgPostPrice type of PostPrice msg
TypeMsgPostPrice = "post_price"
)
Variables ¶
var ParamStoreKeyOracleList = []byte("oraclelist")
ParamStoreKeyOracleList key to get the list of oracle
Functions ¶
func EndBlocker ¶
EndBlocker updates the current pricefeed
func ErrEmptyInput ¶
func ErrEmptyInput(codespace sdk.CodespaceType) sdk.Error
ErrEmptyInput Error constructor
func ErrExpired ¶
func ErrExpired(codespace sdk.CodespaceType) sdk.Error
ErrExpired Error constructor for posted price messages with expired price
func ErrInvalidAsset ¶
func ErrInvalidAsset(codespace sdk.CodespaceType) sdk.Error
ErrInvalidAsset Error constructor for posted price messages for invalid assets
func ErrInvalidOracle ¶
func ErrInvalidOracle(codespace sdk.CodespaceType) sdk.Error
ErrInvalidOracle Error constructor for posted price messages for invalid oracles
func ErrNoValidPrice ¶
func ErrNoValidPrice(codespace sdk.CodespaceType) sdk.Error
ErrNoValidPrice Error constructor for posted price messages with expired price
func HandleMsgPostPrice ¶
HandleMsgPostPrice handles prices posted by oracles
func InitGenesis ¶
func InitGenesis(ctx sdk.Context, keeper Keeper, genState GenesisState)
InitGenesis sets distribution information for genesis.
func NewHandler ¶
NewHandler handles all pricefeed type messages
func NewQuerier ¶
NewQuerier is the module level router for state queries
func RegisterCodec ¶
RegisterCodec registers concrete types on the Amino codec
func ValidateGenesis ¶
func ValidateGenesis(data GenesisState) error
ValidateGenesis performs basic validation of genesis data returning an error for any failed validation criteria.
Types ¶
type AppModule ¶
type AppModule struct { AppModuleBasic // contains filtered or unexported fields }
AppModule app module type
func NewAppModule ¶
NewAppModule creates a new AppModule object
func (AppModule) BeginBlock ¶
BeginBlock module begin-block
func (AppModule) EndBlock ¶
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) ([]abci.ValidatorUpdate, sdk.Tags)
EndBlock module end-block
func (AppModule) ExportGenesis ¶
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage
ExportGenesis module export genesis
func (AppModule) InitGenesis ¶
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate
InitGenesis module init-genesis
func (AppModule) NewHandler ¶
NewHandler module handler
func (AppModule) NewQuerierHandler ¶
NewQuerierHandler module querier
func (AppModule) QuerierRoute ¶
QuerierRoute module querier route name
func (AppModule) RegisterInvariants ¶
func (AppModule) RegisterInvariants(_ sdk.InvariantRouter)
RegisterInvariants register module invariants
type AppModuleBasic ¶
type AppModuleBasic struct{}
AppModuleBasic app module basics object
func (AppModuleBasic) DefaultGenesis ¶
func (AppModuleBasic) DefaultGenesis() json.RawMessage
DefaultGenesis default genesis state
func (AppModuleBasic) RegisterCodec ¶
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec)
RegisterCodec register module codec
func (AppModuleBasic) ValidateGenesis ¶
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error
ValidateGenesis module validate genesis
type CurrentPrice ¶
type CurrentPrice struct { AssetCode string `json:"asset_code"` Price sdk.Dec `json:"price"` Expiry sdk.Int `json:"expiry"` }
CurrentPrice struct that contains the metadata of a current price for a particular asset in the pricefeed module.
type GenesisState ¶
GenesisState state at gensis
func DefaultGenesisState ¶
func DefaultGenesisState() GenesisState
DefaultGenesisState returns a default genesis state
func ExportGenesis ¶
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState
ExportGenesis returns a GenesisState for a given context and keeper.
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
Keeper struct for pricefeed module
func (Keeper) GetCurrentPrice ¶
func (k Keeper) GetCurrentPrice(ctx sdk.Context, assetCode string) CurrentPrice
GetCurrentPrice fetches the current median price of all oracles for a specific asset
func (Keeper) GetOracle ¶
GetOracle returns the oracle address as a string if it is in the pricefeed store
func (Keeper) GetOracles ¶
GetOracles returns the oracles in the pricefeed store
func (Keeper) GetRawPrices ¶
func (k Keeper) GetRawPrices(ctx sdk.Context, assetCode string) []PostedPrice
GetRawPrices fetches the set of all prices posted by oracles for an asset
func (Keeper) SetCurrentPrices ¶
SetCurrentPrices updates the price of an asset to the meadian of all valid oracle inputs
func (Keeper) SetPrice ¶
func (k Keeper) SetPrice( ctx sdk.Context, oracle sdk.AccAddress, assetCode string, price sdk.Dec, expiry sdk.Int) (PostedPrice, sdk.Error)
SetPrice updates the posted price for a specific oracle
func (Keeper) ValidatePostPrice ¶
ValidatePostPrice makes sure the person posting the price is an oracle
type MsgPostPrice ¶
type MsgPostPrice struct { From sdk.AccAddress // client that sent in this address AssetCode string // asset code used by exchanges/api Price sdk.Dec // price in decimal (max precision 18) Expiry sdk.Int // block height }
MsgPostPrice struct representing a posted price message. Used by oracles to input prices to the pricefeed
func NewMsgPostPrice ¶
func NewMsgPostPrice( from sdk.AccAddress, assetCode string, price sdk.Dec, expiry sdk.Int) MsgPostPrice
NewMsgPostPrice creates a new post price msg
func (MsgPostPrice) GetSignBytes ¶
func (msg MsgPostPrice) GetSignBytes() []byte
GetSignBytes Implements Msg.
func (MsgPostPrice) GetSigners ¶
func (msg MsgPostPrice) GetSigners() []sdk.AccAddress
GetSigners Implements Msg.
func (MsgPostPrice) ValidateBasic ¶
func (msg MsgPostPrice) ValidateBasic() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type Oracle ¶
type Oracle struct {
OracleAddress string `json:"oracle_address"`
}
Oracle struct that documents which address an oracle is using
type PostedPrice ¶
type PostedPrice struct { AssetCode string `json:"asset_code"` OracleAddress string `json:"oracle_address"` Price sdk.Dec `json:"price"` Expiry sdk.Int `json:"expiry"` }
PostedPrice struct represented a price for an asset posted by a specific oracle
type QueryRawPricesResp ¶
type QueryRawPricesResp []string
QueryRawPricesResp response to a rawprice query
func (QueryRawPricesResp) String ¶
func (n QueryRawPricesResp) String() string
implement fmt.Stringer