Documentation ¶
Overview ¶
Package auction is a module for creating generic auctions and allowing users to place bids until a timeout is reached.
TODO
- investigate when exactly auctions close and verify queue/endblocker logic is ok
- add more test cases, add stronger validation to user inputs
- add minimum bid increment
- decided whether to put auction params like default timeouts into the auctions themselves
- add docs
- Add constants for the module and route names
- user facing things like cli, rest, querier, tags
- custom error types, codespace
Index ¶
- Constants
- func EndBlocker(ctx sdk.Context, k Keeper) sdk.Tags
- func NewHandler(keeper Keeper) sdk.Handler
- func NewQuerier(keeper Keeper) sdk.Querier
- 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 Auction
- type BaseAuction
- type ForwardAuction
- type ForwardReverseAuction
- type GenesisState
- type ID
- type Keeper
- func (k Keeper) CloseAuction(ctx sdk.Context, auctionID ID) sdk.Error
- func (k Keeper) GetAuction(ctx sdk.Context, auctionID ID) (Auction, bool)
- func (k Keeper) GetAuctionIterator(ctx sdk.Context) sdk.Iterator
- func (k Keeper) PlaceBid(ctx sdk.Context, auctionID ID, bidder sdk.AccAddress, bid sdk.Coin, ...) sdk.Error
- func (k Keeper) StartForwardAuction(ctx sdk.Context, seller sdk.AccAddress, lot sdk.Coin, initialBid sdk.Coin) (ID, sdk.Error)
- func (k Keeper) StartForwardReverseAuction(ctx sdk.Context, seller sdk.AccAddress, lot sdk.Coin, maxBid sdk.Coin, ...) (ID, sdk.Error)
- func (k Keeper) StartReverseAuction(ctx sdk.Context, buyer sdk.AccAddress, bid sdk.Coin, initialLot sdk.Coin) (ID, sdk.Error)
- type MsgPlaceBid
- type QueryResAuctions
- type ReverseAuction
Constants ¶
const ( // MaxAuctionDuration max length of auction, in blocks MaxAuctionDuration endTime = 2 * 24 * 3600 / 5 // roughly 2 days, at 5s block time // 34560 // BidDuration how long an auction gets extended when someone bids, in blocks BidDuration endTime = 3 * 3600 / 5 // roughly 3 hours, at 5s block time TODO better name // 2160 )
const ModuleName = "auction"
ModuleName name of module
const (
// QueryGetAuction command for getting the information about a particular auction
QueryGetAuction = "getauctions"
)
Variables ¶
This section is empty.
Functions ¶
func EndBlocker ¶
EndBlocker runs at the end of every block.
func NewHandler ¶
NewHandler returns a function to handle all "auction" type messages.
func NewQuerier ¶
NewQuerier is the module level router for state queries
func RegisterCodec ¶
RegisterCodec registers concrete types on the codec.
func ValidateGenesis ¶
func ValidateGenesis(data GenesisState) error
ValidateGenesis validates genesis state
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 Auction ¶
type Auction interface { GetID() ID SetID(ID) PlaceBid(currentBlockHeight endTime, bidder sdk.AccAddress, lot sdk.Coin, bid sdk.Coin) ([]bankOutput, []bankInput, sdk.Error) GetEndTime() endTime // auctions close at the end of the block with blockheight EndTime (ie bids placed in that block are valid) GetPayout() bankInput String() string }
Auction is an interface to several types of auction.
type BaseAuction ¶
type BaseAuction struct { ID ID Initiator sdk.AccAddress // Person who starts the auction. Giving away Lot (aka seller in a forward auction) Lot sdk.Coin // Amount of coins up being given by initiator (FA - amount for sale by seller, RA - cost of good by buyer (bid)) Bidder sdk.AccAddress // Person who bids in the auction. Receiver of Lot. (aka buyer in forward auction, seller in RA) Bid sdk.Coin // Amount of coins being given by the bidder (FA - bid, RA - amount being sold) EndTime endTime // Block height at which the auction closes. It closes at the end of this block MaxEndTime endTime // Maximum closing time. Auctions can close before this but never after. }
BaseAuction type shared by all Auctions
func (BaseAuction) GetEndTime ¶
func (a BaseAuction) GetEndTime() endTime
GetEndTime getter for auction end time
func (BaseAuction) GetPayout ¶
func (a BaseAuction) GetPayout() bankInput
GetPayout implements Auction
func (BaseAuction) String ¶
func (a BaseAuction) String() string
type ForwardAuction ¶
type ForwardAuction struct {
BaseAuction
}
ForwardAuction type for forward auctions
func NewForwardAuction ¶
func NewForwardAuction(seller sdk.AccAddress, lot sdk.Coin, initialBid sdk.Coin, endTime endTime) (ForwardAuction, bankOutput)
NewForwardAuction creates a new forward auction
type ForwardReverseAuction ¶
type ForwardReverseAuction struct { BaseAuction MaxBid sdk.Coin OtherPerson sdk.AccAddress // TODO rename, this is normally the original CDP owner }
ForwardReverseAuction type for forward reverse auction
func NewForwardReverseAuction ¶
func NewForwardReverseAuction(seller sdk.AccAddress, lot sdk.Coin, initialBid sdk.Coin, endTime endTime, maxBid sdk.Coin, otherPerson sdk.AccAddress) (ForwardReverseAuction, bankOutput)
NewForwardReverseAuction creates a new forward reverse auction
func (*ForwardReverseAuction) PlaceBid ¶
func (a *ForwardReverseAuction) PlaceBid(currentBlockHeight endTime, bidder sdk.AccAddress, lot sdk.Coin, bid sdk.Coin) (outputs []bankOutput, inputs []bankInput, err sdk.Error)
PlaceBid implements auction
func (ForwardReverseAuction) String ¶
func (a ForwardReverseAuction) String() string
type GenesisState ¶
type GenesisState struct { }
GenesisState - crisis genesis state
func DefaultGenesisState ¶
func DefaultGenesisState() GenesisState
DefaultGenesisState creates a default GenesisState object
func ExportGenesis ¶
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState
ExportGenesis returns a GenesisState for a given context and keeper.
func NewGenesisState ¶
func NewGenesisState() GenesisState
NewGenesisState creates a new GenesisState object
type ID ¶
type ID uint64
ID type for auction IDs
func NewIDFromString ¶
NewIDFromString generate new auction ID from a string
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
func (Keeper) CloseAuction ¶
CloseAuction closes an auction and distributes funds to the seller and highest bidder. TODO because this is called by the end blocker, it has to be valid for the duration of the EndTime block. Should maybe move this to a begin blocker?
func (Keeper) GetAuction ¶
getAuction gets an auction from the store by auctionID
func (Keeper) GetAuctionIterator ¶
GetAuctionIterator returns an iterator over all auctions in the store
func (Keeper) PlaceBid ¶
func (k Keeper) PlaceBid(ctx sdk.Context, auctionID ID, bidder sdk.AccAddress, bid sdk.Coin, lot sdk.Coin) sdk.Error
PlaceBid places a bid on any auction.
func (Keeper) StartForwardAuction ¶
func (k Keeper) StartForwardAuction(ctx sdk.Context, seller sdk.AccAddress, lot sdk.Coin, initialBid sdk.Coin) (ID, sdk.Error)
StartForwardAuction starts a normal auction. Known as flap in maker.
func (Keeper) StartForwardReverseAuction ¶
func (k Keeper) StartForwardReverseAuction(ctx sdk.Context, seller sdk.AccAddress, lot sdk.Coin, maxBid sdk.Coin, otherPerson sdk.AccAddress) (ID, sdk.Error)
StartForwardReverseAuction starts an auction where bidders bid up to a maxBid, then switch to bidding down on price. Known as flip in maker.
type MsgPlaceBid ¶
type MsgPlaceBid struct { AuctionID ID Bidder sdk.AccAddress // This can be a buyer (who increments bid), or a seller (who decrements lot) TODO rename to be clearer? Bid sdk.Coin Lot sdk.Coin }
MsgPlaceBid is the message type used to place a bid on any type of auction.
func NewMsgPlaceBid ¶
func NewMsgPlaceBid(auctionID ID, bidder sdk.AccAddress, bid sdk.Coin, lot 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) 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() sdk.Error
ValidateBasic does a simple validation check that doesn't require access to any other information.
type QueryResAuctions ¶
type QueryResAuctions []string
QueryResAuctions Result Payload for an auctions query
type ReverseAuction ¶
type ReverseAuction struct {
BaseAuction
}
ReverseAuction type for reverse auctions
func NewReverseAuction ¶
func NewReverseAuction(buyer sdk.AccAddress, bid sdk.Coin, initialLot sdk.Coin, endTime endTime) (ReverseAuction, bankOutput)
NewReverseAuction creates a new reverse auction