auction

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: 8 Imported by: 0

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

View Source
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
)
View Source
const ModuleName = "auction"

ModuleName name of module

View Source
const (
	// QueryGetAuction command for getting the information about a particular auction
	QueryGetAuction = "getauctions"
)

Variables

This section is empty.

Functions

func EndBlocker

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

EndBlocker runs at the end of every block.

func NewHandler

func NewHandler(keeper Keeper) sdk.Handler

NewHandler returns a function to handle all "auction" type messages.

func NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

NewQuerier is the module level router for state queries

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

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

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

func (a BaseAuction) GetID() ID

GetID getter for auction ID

func (BaseAuction) GetPayout

func (a BaseAuction) GetPayout() bankInput

GetPayout implements Auction

func (*BaseAuction) SetID

func (a *BaseAuction) SetID(id ID)

SetID setter for auction ID

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

func (*ForwardAuction) PlaceBid

func (a *ForwardAuction) PlaceBid(currentBlockHeight endTime, bidder sdk.AccAddress, lot sdk.Coin, bid sdk.Coin) ([]bankOutput, []bankInput, sdk.Error)

PlaceBid implements 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

func NewIDFromString(s string) (ID, error)

NewIDFromString generate new auction ID from a string

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

func NewKeeper

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

NewKeeper returns a new auction keeper.

func (Keeper) CloseAuction

func (k Keeper) CloseAuction(ctx sdk.Context, auctionID ID) sdk.Error

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

func (k Keeper) GetAuction(ctx sdk.Context, auctionID ID) (Auction, bool)

getAuction gets an auction from the store by auctionID

func (Keeper) GetAuctionIterator

func (k Keeper) GetAuctionIterator(ctx sdk.Context) sdk.Iterator

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.

func (Keeper) StartReverseAuction

func (k Keeper) StartReverseAuction(ctx sdk.Context, buyer sdk.AccAddress, bid sdk.Coin, initialLot sdk.Coin) (ID, sdk.Error)

StartReverseAuction starts an auction where sellers compete by offering decreasing prices. Known as flop 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

func (QueryResAuctions) String

func (n QueryResAuctions) String() string

implement fmt.Stringer

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

func (*ReverseAuction) PlaceBid

func (a *ReverseAuction) PlaceBid(currentBlockHeight endTime, bidder sdk.AccAddress, lot sdk.Coin, bid sdk.Coin) ([]bankOutput, []bankInput, sdk.Error)

PlaceBid implements Auction

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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