types

package
v0.9.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: Apache-2.0 Imports: 13 Imported by: 13

Documentation

Index

Constants

View Source
const (
	CollateralAuctionType = "collateral"
	SurplusAuctionType    = "surplus"
	DebtAuctionType       = "debt"
	ForwardAuctionPhase   = "forward"
	ReverseAuctionPhase   = "reverse"
)
View Source
const (
	EventTypeAuctionStart = "auction_start"
	EventTypeAuctionBid   = "auction_bid"
	EventTypeAuctionClose = "auction_close"

	AttributeValueCategory  = ModuleName
	AttributeKeyAuctionID   = "auction_id"
	AttributeKeyAuctionType = "auction_type"
	AttributeKeyBidder      = "bidder"
	AttributeKeyLot         = "lot"
	AttributeKeyMaxBid      = "max_bid"
	AttributeKeyBid         = "bid"
	AttributeKeyEndTime     = "end_time"
	AttributeKeyCloseBlock  = "close_block"
)

Events for the module

View Source
const (
	// ModuleName The name that will be used throughout the module
	ModuleName = "auction"

	// StoreKey Top level store key where all module items will be stored
	StoreKey = ModuleName

	// RouterKey Top level router key
	RouterKey = ModuleName

	// DefaultParamspace default name for parameter store
	DefaultParamspace = ModuleName

	// QuerierRoute route used for abci queries
	QuerierRoute = ModuleName
)
View Source
const (
	// DefaultMaxAuctionDuration max length of auction
	DefaultMaxAuctionDuration time.Duration = 2 * 24 * time.Hour
	// DefaultBidDuration how long an auction gets extended when someone bids
	DefaultBidDuration time.Duration = 1 * time.Hour
)

Defaults for auction params

View Source
const (
	// QueryGetAuction is the query path for querying one auction
	QueryGetAuction = "auction"
	// QueryGetAuctions is the query path for querying all auctions
	QueryGetAuctions = "auctions"
	// QueryGetParams is the query path for querying the global auction params
	QueryGetParams = "params"
)
View Source
const DefaultNextAuctionID uint64 = 1

DefaultNextAuctionID is the starting poiint for auction IDs.

Variables

View Source
var (
	// ErrInvalidInitialAuctionID error for when the initial auction ID hasn't been set
	ErrInvalidInitialAuctionID = sdkerrors.Register(ModuleName, 2, "initial auction ID hasn't been set")
	// ErrUnrecognizedAuctionType error for unrecognized auction type
	ErrUnrecognizedAuctionType = sdkerrors.Register(ModuleName, 3, "unrecognized auction type")
	// ErrAuctionNotFound error for when an auction is not found
	ErrAuctionNotFound = sdkerrors.Register(ModuleName, 4, "auction not found")
	// ErrAuctionHasNotExpired error for attempting to close an auction that has not passed its end time
	ErrAuctionHasNotExpired = sdkerrors.Register(ModuleName, 5, "auction can't be closed as curent block time has not passed auction end time")
	// ErrAuctionHasExpired error for when an auction is closed and unavailable for bidding
	ErrAuctionHasExpired = sdkerrors.Register(ModuleName, 6, "auction has closed")
	// ErrInvalidBidDenom error for when bid denom doesn't match auction bid denom
	ErrInvalidBidDenom = sdkerrors.Register(ModuleName, 7, "bid denom doesn't match auction bid denom")
	// ErrInvalidLotDenom error for when lot denom doesn't match auction lot denom
	ErrInvalidLotDenom = sdkerrors.Register(ModuleName, 8, "lot denom doesn't match auction lot denom")
	// ErrBidTooSmall error for when bid is not greater than auction's min bid amount
	ErrBidTooSmall = sdkerrors.Register(ModuleName, 9, "bid is not greater than auction's min new bid amount")
	// ErrBidTooLarge error for when bid is larger than auction's maximum allowed bid
	ErrBidTooLarge = sdkerrors.Register(ModuleName, 10, "bid is greater than auction's max bid")
	// ErrLotTooSmall error for when lot is less than zero
	ErrLotTooSmall = sdkerrors.Register(ModuleName, 11, "lot is not greater than auction's min new lot amount")
	// ErrLotTooLarge error for when lot is not smaller than auction's max new lot amount
	ErrLotTooLarge = sdkerrors.Register(ModuleName, 12, "lot is greater than auction's max new lot amount")
)
View Source
var (
	AuctionKeyPrefix       = []byte{0x00} // prefix for keys that store auctions
	AuctionByTimeKeyPrefix = []byte{0x01} // prefix for keys that are part of the auctionsByTime index

	NextAuctionIDKey = []byte{0x02} // key for the next auction id
)

Key prefixes

View Source
var (
	// DefaultIncrement is the smallest percent change a new bid must have from the old one
	DefaultIncrement sdk.Dec = sdk.MustNewDecFromStr("0.05")
	// ParamStoreKeyParams Param store key for auction params
	KeyBidDuration         = []byte("BidDuration")
	KeyMaxAuctionDuration  = []byte("MaxAuctionDuration")
	KeyIncrementSurplus    = []byte("IncrementSurplus")
	KeyIncrementDebt       = []byte("IncrementDebt")
	KeyIncrementCollateral = []byte("IncrementCollateral")
)
View Source
var DistantFuture = time.Date(9000, 1, 1, 0, 0, 0, 0, time.UTC)

DistantFuture is a very large time value to use as initial the ending time for auctions. It is not set to the max time supported. This can cause problems with time comparisons, see https://stackoverflow.com/a/32620397. Also amino panics when encoding times ≥ the start of year 10000.

View Source
var ModuleCdc = codec.New()

ModuleCdc module level codec

Functions

func GetAuctionByTimeKey

func GetAuctionByTimeKey(endTime time.Time, auctionID uint64) []byte

GetAuctionByTimeKey returns the key for iterating auctions by time

func GetAuctionKey

func GetAuctionKey(auctionID uint64) []byte

GetAuctionKey returns the bytes of an auction key

func ParamKeyTable

func ParamKeyTable() subspace.KeyTable

ParamKeyTable Key declaration for parameters

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on the codec.

func Uint64FromBytes

func Uint64FromBytes(bz []byte) uint64

Uint64FromBytes converts some fixed length bytes back into a uint64.

func Uint64ToBytes

func Uint64ToBytes(id uint64) []byte

Uint64ToBytes converts a uint64 into fixed length bytes for use in store keys.

Types

type Auction

type Auction interface {
	GetID() uint64
	WithID(uint64) Auction

	GetInitiator() string
	GetLot() sdk.Coin
	GetBidder() sdk.AccAddress
	GetBid() sdk.Coin
	GetEndTime() time.Time

	GetType() string
	GetPhase() string
}

Auction is an interface for handling common actions on auctions.

type AuctionWithPhase

type AuctionWithPhase struct {
	Auction Auction `json:"auction" yaml:"auction"`

	Type  string `json:"type" yaml:"type"`
	Phase string `json:"phase" yaml:"phase"`
}

AuctionWithPhase augmented type for collateral auctions which includes auction phase for querying

func NewAuctionWithPhase

func NewAuctionWithPhase(a Auction) AuctionWithPhase

NewAuctionWithPhase returns new AuctionWithPhase

type Auctions

type Auctions []Auction

Auctions is a slice of auctions.

type BaseAuction

type BaseAuction struct {
	ID              uint64         `json:"id" yaml:"id"`
	Initiator       string         `json:"initiator" yaml:"initiator"`                 // Module name that starts the auction. Pays out Lot.
	Lot             sdk.Coin       `json:"lot" yaml:"lot"`                             // Coins that will paid out by Initiator to the winning bidder.
	Bidder          sdk.AccAddress `json:"bidder" yaml:"bidder"`                       // Latest bidder. Receiver of Lot.
	Bid             sdk.Coin       `json:"bid" yaml:"bid"`                             // Coins paid into the auction the bidder.
	HasReceivedBids bool           `json:"has_received_bids" yaml:"has_received_bids"` // Whether the auction has received any bids or not.
	EndTime         time.Time      `json:"end_time" yaml:"end_time"`                   // Current auction closing time. Triggers at the end of the block with time ≥ EndTime.
	MaxEndTime      time.Time      `json:"max_end_time" yaml:"max_end_time"`           // Maximum closing time. Auctions can close before this but never after.
}

BaseAuction is a common type shared by all Auctions.

func (BaseAuction) GetBid

func (a BaseAuction) GetBid() sdk.Coin

GetBid is a getter for auction Bid.

func (BaseAuction) GetBidder

func (a BaseAuction) GetBidder() sdk.AccAddress

GetBidder is a getter for auction Bidder.

func (BaseAuction) GetEndTime

func (a BaseAuction) GetEndTime() time.Time

GetEndTime is a getter for auction end time.

func (BaseAuction) GetID

func (a BaseAuction) GetID() uint64

GetID is a getter for auction ID.

func (BaseAuction) GetInitiator

func (a BaseAuction) GetInitiator() string

GetInitiator is a getter for auction Initiator.

func (BaseAuction) GetLot

func (a BaseAuction) GetLot() sdk.Coin

GetLot is a getter for auction Lot.

func (BaseAuction) GetType

func (a BaseAuction) GetType() string

GetType returns the auction type. Used to identify auctions in event attributes.

func (BaseAuction) String

func (a BaseAuction) String() string

func (BaseAuction) Validate

func (a BaseAuction) Validate() error

Validate verifies that the auction end time is before max end time

type CollateralAuction

type CollateralAuction struct {
	BaseAuction `json:"base_auction" yaml:"base_auction"`

	CorrespondingDebt sdk.Coin          `json:"corresponding_debt" yaml:"corresponding_debt"`
	MaxBid            sdk.Coin          `json:"max_bid" yaml:"max_bid"`
	LotReturns        WeightedAddresses `json:"lot_returns" yaml:"lot_returns"`
}

CollateralAuction is a two phase auction. Initially, in forward auction phase, bids can be placed up to a max bid. Then it switches to a reverse auction phase, where the initial amount up for auction is bid down. Unsold Lot is sent to LotReturns, being divided among the addresses by weight. Collateral auctions are normally used to sell off collateral seized from CDPs.

func NewCollateralAuction

func NewCollateralAuction(seller string, lot sdk.Coin, endTime time.Time, maxBid sdk.Coin, lotReturns WeightedAddresses, debt sdk.Coin) CollateralAuction

NewCollateralAuction returns a new collateral auction.

func (CollateralAuction) GetModuleAccountCoins

func (a CollateralAuction) GetModuleAccountCoins() sdk.Coins

GetModuleAccountCoins returns the total number of coins held in the module account for this auction. It is used in genesis initialize the module account correctly.

func (CollateralAuction) GetPhase

func (a CollateralAuction) GetPhase() string

GetPhase returns the direction of a collateral auction.

func (CollateralAuction) GetType

func (a CollateralAuction) GetType() string

GetType returns the auction type. Used to identify auctions in event attributes.

func (CollateralAuction) IsReversePhase

func (a CollateralAuction) IsReversePhase() bool

IsReversePhase returns whether the auction has switched over to reverse phase or not. CollateralAuctions initially start in forward phase.

func (CollateralAuction) String

func (a CollateralAuction) String() string

func (CollateralAuction) Validate added in v0.8.0

func (a CollateralAuction) Validate() error

Validate validates the CollateralAuction fields values.

func (CollateralAuction) WithID

func (a CollateralAuction) WithID(id uint64) Auction

WithID returns an auction with the ID set.

type DebtAuction

type DebtAuction struct {
	BaseAuction `json:"base_auction" yaml:"base_auction"`

	CorrespondingDebt sdk.Coin `json:"corresponding_debt" yaml:"corresponding_debt"`
}

DebtAuction is a reverse auction that mints what it pays out. It is normally used to acquire pegged asset to cover the CDP system's debts that were not covered by selling collateral.

func NewDebtAuction

func NewDebtAuction(buyerModAccName string, bid sdk.Coin, initialLot sdk.Coin, endTime time.Time, debt sdk.Coin) DebtAuction

NewDebtAuction returns a new debt auction.

func (DebtAuction) GetModuleAccountCoins

func (a DebtAuction) GetModuleAccountCoins() sdk.Coins

GetModuleAccountCoins returns the total number of coins held in the module account for this auction. It is used in genesis initialize the module account correctly.

func (DebtAuction) GetPhase

func (a DebtAuction) GetPhase() string

GetPhase returns the direction of a debt auction, which never changes.

func (DebtAuction) GetType

func (a DebtAuction) GetType() string

GetType returns the auction type. Used to identify auctions in event attributes.

func (DebtAuction) Validate added in v0.8.0

func (a DebtAuction) Validate() error

Validate validates the DebtAuction fields values.

func (DebtAuction) WithID

func (a DebtAuction) WithID(id uint64) Auction

WithID returns an auction with the ID set.

type GenesisAuction

type GenesisAuction interface {
	Auction
	GetModuleAccountCoins() sdk.Coins
	Validate() error
}

GenesisAuction is an interface that extends the auction interface to add functionality needed for initializing auctions from genesis.

type GenesisAuctions

type GenesisAuctions []GenesisAuction

GenesisAuctions is a slice of genesis auctions.

type GenesisState

type GenesisState struct {
	NextAuctionID uint64          `json:"next_auction_id" yaml:"next_auction_id"`
	Params        Params          `json:"params" yaml:"params"`
	Auctions      GenesisAuctions `json:"auctions" yaml:"auctions"`
}

GenesisState is auction state that must be provided at chain genesis.

func DefaultGenesisState

func DefaultGenesisState() GenesisState

DefaultGenesisState returns the default genesis state for auction module.

func NewGenesisState

func NewGenesisState(nextID uint64, ap Params, ga GenesisAuctions) GenesisState

NewGenesisState returns a new genesis state object for auctions module.

func (GenesisState) Equal

func (gs GenesisState) Equal(gs2 GenesisState) bool

Equal checks whether two GenesisState structs are equivalent.

func (GenesisState) IsEmpty

func (gs GenesisState) IsEmpty() bool

IsEmpty returns true if a GenesisState is empty.

func (GenesisState) Validate

func (gs GenesisState) Validate() error

Validate validates genesis inputs. It returns error if validation of any input fails.

type MsgPlaceBid

type MsgPlaceBid struct {
	AuctionID uint64         `json:"auction_id" yaml:"auction_id"`
	Bidder    sdk.AccAddress `json:"bidder" yaml:"bidder"`
	Amount    sdk.Coin       `json:"amount" yaml:"amount"` // The new bid or lot to be set on the auction.
}

MsgPlaceBid is the message type used to place a bid on any type of auction.

func NewMsgPlaceBid

func NewMsgPlaceBid(auctionID uint64, bidder sdk.AccAddress, amt sdk.Coin) MsgPlaceBid

NewMsgPlaceBid returns a new MsgPlaceBid.

func (MsgPlaceBid) GetSignBytes

func (msg MsgPlaceBid) GetSignBytes() []byte

GetSignBytes gets the canonical byte representation of the Msg.

func (MsgPlaceBid) GetSigners

func (msg MsgPlaceBid) GetSigners() []sdk.AccAddress

GetSigners returns the addresses of signers that must sign.

func (MsgPlaceBid) Route

func (msg MsgPlaceBid) Route() string

Route return the message type used for routing the message.

func (MsgPlaceBid) String added in v0.8.0

func (msg MsgPlaceBid) String() string

func (MsgPlaceBid) Type

func (msg MsgPlaceBid) Type() string

Type returns a human-readable string for the message, intended for utilization within tags.

func (MsgPlaceBid) ValidateBasic

func (msg MsgPlaceBid) ValidateBasic() error

ValidateBasic does a simple validation check that doesn't require access to state.

type Params

type Params struct {
	MaxAuctionDuration  time.Duration `json:"max_auction_duration" yaml:"max_auction_duration"` // max length of auction
	BidDuration         time.Duration `json:"bid_duration" yaml:"bid_duration"`                 // additional time added to the auction end time after each bid, capped by the expiry.
	IncrementSurplus    sdk.Dec       `json:"increment_surplus" yaml:"increment_surplus"`       // percentage change (of auc.Bid) required for a new bid on a surplus auction
	IncrementDebt       sdk.Dec       `json:"increment_debt" yaml:"increment_debt"`             // percentage change (of auc.Lot) required for a new bid on a debt auction
	IncrementCollateral sdk.Dec       `json:"increment_collateral" yaml:"increment_collateral"` // percentage change (of auc.Bid or auc.Lot) required for a new bid on a collateral auction
}

Params is the governance parameters for the auction module.

func DefaultParams

func DefaultParams() Params

DefaultParams returns the default parameters for auctions.

func NewParams

func NewParams(maxAuctionDuration, bidDuration time.Duration, incrementSurplus, incrementDebt, incrementCollateral sdk.Dec) Params

NewParams returns a new Params object.

func (Params) Equal

func (p Params) Equal(p2 Params) bool

Equal returns a boolean determining if two Params types are identical.

func (*Params) ParamSetPairs

func (p *Params) ParamSetPairs() subspace.ParamSetPairs

ParamSetPairs implements the ParamSet interface and returns all the key/value pairs.

func (Params) String

func (p Params) String() string

String implements stringer interface

func (Params) Validate

func (p Params) Validate() error

Validate checks that the parameters have valid values.

type QueryAllAuctionParams

type QueryAllAuctionParams struct {
	Page  int    `json:"page" yaml:"page"`
	Limit int    `json:"limit" yaml:"limit"`
	Type  string `json:"type" yaml:"type"`
	Denom string `json:"denom" yaml:"denom"`
	Phase string `json:"phase" yaml:"phase"`
}

QueryAllAuctionParams is the params for an auctions query

func NewQueryAllAuctionParams

func NewQueryAllAuctionParams(page, limit int, aucType, aucDenom, aucPhase string) QueryAllAuctionParams

NewQueryAllAuctionParams creates a new QueryAllAuctionParams

type QueryAuctionParams

type QueryAuctionParams struct {
	AuctionID uint64
}

QueryAuctionParams params for query /auction/auction

type SupplyKeeper

type SupplyKeeper interface {
	GetModuleAddress(name string) sdk.AccAddress
	GetModuleAccount(ctx sdk.Context, moduleName string) supplyexported.ModuleAccountI

	SendCoinsFromModuleToModule(ctx sdk.Context, sender, recipient string, amt sdk.Coins) error
	SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error

	BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
	MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error
}

SupplyKeeper defines the expected supply Keeper

type SurplusAuction

type SurplusAuction struct {
	BaseAuction `json:"base_auction" yaml:"base_auction"`
}

SurplusAuction is a forward auction that burns what it receives from bids. It is normally used to sell off excess pegged asset acquired by the CDP system.

func NewSurplusAuction

func NewSurplusAuction(seller string, lot sdk.Coin, bidDenom string, endTime time.Time) SurplusAuction

NewSurplusAuction returns a new surplus auction.

func (SurplusAuction) GetModuleAccountCoins

func (a SurplusAuction) GetModuleAccountCoins() sdk.Coins

GetModuleAccountCoins returns the total number of coins held in the module account for this auction. It is used in genesis initialize the module account correctly.

func (SurplusAuction) GetPhase

func (a SurplusAuction) GetPhase() string

GetPhase returns the direction of a surplus auction, which never changes.

func (SurplusAuction) GetType

func (a SurplusAuction) GetType() string

GetType returns the auction type. Used to identify auctions in event attributes.

func (SurplusAuction) WithID

func (a SurplusAuction) WithID(id uint64) Auction

WithID returns an auction with the ID set.

type WeightedAddresses

type WeightedAddresses struct {
	Addresses []sdk.AccAddress `json:"addresses" yaml:"addresses"`
	Weights   []sdk.Int        `json:"weights" yaml:"weights"`
}

WeightedAddresses is a type for storing some addresses and associated weights.

func NewWeightedAddresses

func NewWeightedAddresses(addrs []sdk.AccAddress, weights []sdk.Int) (WeightedAddresses, error)

NewWeightedAddresses returns a new list addresses with weights.

func (WeightedAddresses) Validate added in v0.8.0

func (wa WeightedAddresses) Validate() error

Validate checks for that the weights are not negative, not all zero, and the lengths match.

Jump to

Keyboard shortcuts

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