pricefeed

package
v0.0.0-...-55fa119 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

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

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

View Source
const (
	// QueryCurrentPrice command for current price queries
	QueryCurrentPrice = "price"
	// QueryRawPrices command for raw price queries
	QueryRawPrices = "rawprices"
	// QueryAssets command for assets query
	QueryAssets = "assets"
)
View Source
const (
	// TypeMsgPostPrice type of PostPrice msg
	TypeMsgPostPrice = "post_price"
)

Variables

View Source
var ParamStoreKeyOracleList = []byte("oraclelist")

ParamStoreKeyOracleList key to get the list of oracle

Functions

func EndBlocker

func EndBlocker(ctx sdk.Context, k Keeper) sdk.Tags

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

func HandleMsgPostPrice(
	ctx sdk.Context,
	k Keeper,
	msg MsgPostPrice) sdk.Result

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

func NewHandler(k Keeper) sdk.Handler

NewHandler handles all pricefeed type messages

func NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

NewQuerier is the module level router for state queries

func ParamKeyTable

func ParamKeyTable() params.KeyTable

ParamKeyTable keytable

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

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

func NewAppModule(keeper Keeper) AppModule

NewAppModule creates a new AppModule object

func (AppModule) BeginBlock

func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) sdk.Tags

BeginBlock module begin-block

func (AppModule) EndBlock

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

func (AppModule) Name() string

Name module name

func (AppModule) NewHandler

func (am AppModule) NewHandler() sdk.Handler

NewHandler module handler

func (AppModule) NewQuerierHandler

func (am AppModule) NewQuerierHandler() sdk.Querier

NewQuerierHandler module querier

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute module querier route name

func (AppModule) RegisterInvariants

func (AppModule) RegisterInvariants(_ sdk.InvariantRouter)

RegisterInvariants register module invariants

func (AppModule) Route

func (AppModule) Route() string

Route module message route name

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic app module basics object

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis() json.RawMessage

DefaultGenesis default genesis state

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name get module name

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 Asset

type Asset struct {
	AssetCode   string `json:"asset_code"`
	Description string `json:"description"`
}

Asset struct that represents an asset in the pricefeed

func (Asset) String

func (a Asset) String() string

implement fmt.Stringer

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.

func (CurrentPrice) String

func (cp CurrentPrice) String() string

implement fmt.Stringer

type GenesisState

type GenesisState struct {
	Assets  []Asset
	Oracles []Oracle
}

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 NewKeeper

func NewKeeper(storeKey sdk.StoreKey, cdc *codec.Codec, codespace sdk.CodespaceType) Keeper

NewKeeper returns a new keeper for the pricefeed modle

func (Keeper) AddAsset

func (k Keeper) AddAsset(
	ctx sdk.Context,
	assetCode string,
	desc string,
)

AddAsset adds an asset to the store

func (Keeper) AddOracle

func (k Keeper) AddOracle(ctx sdk.Context, address string)

AddOracle adds an Oracle to the store

func (Keeper) GetAsset

func (k Keeper) GetAsset(ctx sdk.Context, assetCode string) (Asset, bool)

GetAsset returns the asset if it is in the pricefeed system

func (Keeper) GetAssets

func (k Keeper) GetAssets(ctx sdk.Context) []Asset

GetAssets returns the assets in the pricefeed store

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

func (k Keeper) GetOracle(ctx sdk.Context, oracle string) (Oracle, bool)

GetOracle returns the oracle address as a string if it is in the pricefeed store

func (Keeper) GetOracles

func (k Keeper) GetOracles(ctx sdk.Context) []Oracle

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

func (k Keeper) SetCurrentPrices(ctx sdk.Context) sdk.Error

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

func (k Keeper) ValidatePostPrice(ctx sdk.Context, msg MsgPostPrice) sdk.Error

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

func (msg MsgPostPrice) Route() string

Route Implements Msg.

func (MsgPostPrice) Type

func (msg MsgPostPrice) Type() string

Type 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

func (PostedPrice) String

func (pp PostedPrice) String() string

implement fmt.Stringer

type QueryAssetsResp

type QueryAssetsResp []string

QueryAssetsResp response to a assets query

func (QueryAssetsResp) String

func (n QueryAssetsResp) String() string

implement fmt.Stringer

type QueryRawPricesResp

type QueryRawPricesResp []string

QueryRawPricesResp response to a rawprice query

func (QueryRawPricesResp) String

func (n QueryRawPricesResp) String() string

implement fmt.Stringer

type SortDecs

type SortDecs []sdk.Dec

SortDecs provides the interface needed to sort sdk.Dec slices

func (SortDecs) Len

func (a SortDecs) Len() int

func (SortDecs) Less

func (a SortDecs) Less(i, j int) bool

func (SortDecs) Swap

func (a SortDecs) Swap(i, j int)

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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