mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
give auction types more accurate names
This commit is contained in:
parent
08689305cc
commit
c239932297
@ -37,7 +37,7 @@ func TestKeeper_EndBlocker(t *testing.T) {
|
||||
ctx := tApp.NewContext(true, abci.Header{})
|
||||
keeper := tApp.GetAuctionKeeper()
|
||||
|
||||
auctionID, err := keeper.StartForwardReverseAuction(ctx, sellerModName, c("token1", 20), c("token2", 50), returnAddrs, returnWeights)
|
||||
auctionID, err := keeper.StartCollateralAuction(ctx, sellerModName, c("token1", 20), c("token2", 50), returnAddrs, returnWeights)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, keeper.PlaceBid(ctx, auctionID, buyer, c("token2", 30)))
|
||||
|
||||
|
@ -22,24 +22,24 @@ const (
|
||||
|
||||
var (
|
||||
// functions aliases
|
||||
NewForwardAuction = types.NewForwardAuction
|
||||
NewReverseAuction = types.NewReverseAuction
|
||||
NewForwardReverseAuction = types.NewForwardReverseAuction
|
||||
NewWeightedAddresses = types.NewWeightedAddresses
|
||||
RegisterCodec = types.RegisterCodec
|
||||
NewGenesisState = types.NewGenesisState
|
||||
DefaultGenesisState = types.DefaultGenesisState
|
||||
ValidateGenesis = types.ValidateGenesis
|
||||
GetAuctionKey = types.GetAuctionKey
|
||||
GetAuctionByTimeKey = types.GetAuctionByTimeKey
|
||||
Uint64FromBytes = types.Uint64FromBytes
|
||||
Uint64ToBytes = types.Uint64ToBytes
|
||||
NewMsgPlaceBid = types.NewMsgPlaceBid
|
||||
NewParams = types.NewParams
|
||||
DefaultParams = types.DefaultParams
|
||||
ParamKeyTable = types.ParamKeyTable
|
||||
NewKeeper = keeper.NewKeeper
|
||||
NewQuerier = keeper.NewQuerier
|
||||
NewSurplusAuction = types.NewSurplusAuction
|
||||
NewDebtAuction = types.NewDebtAuction
|
||||
NewCollateralAuction = types.NewCollateralAuction
|
||||
NewWeightedAddresses = types.NewWeightedAddresses
|
||||
RegisterCodec = types.RegisterCodec
|
||||
NewGenesisState = types.NewGenesisState
|
||||
DefaultGenesisState = types.DefaultGenesisState
|
||||
ValidateGenesis = types.ValidateGenesis
|
||||
GetAuctionKey = types.GetAuctionKey
|
||||
GetAuctionByTimeKey = types.GetAuctionByTimeKey
|
||||
Uint64FromBytes = types.Uint64FromBytes
|
||||
Uint64ToBytes = types.Uint64ToBytes
|
||||
NewMsgPlaceBid = types.NewMsgPlaceBid
|
||||
NewParams = types.NewParams
|
||||
DefaultParams = types.DefaultParams
|
||||
ParamKeyTable = types.ParamKeyTable
|
||||
NewKeeper = keeper.NewKeeper
|
||||
NewQuerier = keeper.NewQuerier
|
||||
|
||||
// variable aliases
|
||||
ModuleCdc = types.ModuleCdc
|
||||
@ -51,17 +51,17 @@ var (
|
||||
)
|
||||
|
||||
type (
|
||||
Auction = types.Auction
|
||||
BaseAuction = types.BaseAuction
|
||||
ForwardAuction = types.ForwardAuction
|
||||
ReverseAuction = types.ReverseAuction
|
||||
ForwardReverseAuction = types.ForwardReverseAuction
|
||||
WeightedAddresses = types.WeightedAddresses
|
||||
SupplyKeeper = types.SupplyKeeper
|
||||
Auctions = types.Auctions
|
||||
GenesisState = types.GenesisState
|
||||
MsgPlaceBid = types.MsgPlaceBid
|
||||
Params = types.Params
|
||||
QueryResAuctions = types.QueryResAuctions
|
||||
Keeper = keeper.Keeper
|
||||
Auction = types.Auction
|
||||
BaseAuction = types.BaseAuction
|
||||
SurplusAuction = types.SurplusAuction
|
||||
DebtAuction = types.DebtAuction
|
||||
CollateralAuction = types.CollateralAuction
|
||||
WeightedAddresses = types.WeightedAddresses
|
||||
SupplyKeeper = types.SupplyKeeper
|
||||
Auctions = types.Auctions
|
||||
GenesisState = types.GenesisState
|
||||
MsgPlaceBid = types.MsgPlaceBid
|
||||
Params = types.Params
|
||||
QueryResAuctions = types.QueryResAuctions
|
||||
Keeper = keeper.Keeper
|
||||
)
|
||||
|
@ -9,10 +9,10 @@ import (
|
||||
"github.com/kava-labs/kava/x/auction/types"
|
||||
)
|
||||
|
||||
// StartForwardAuction starts a normal auction that mints the sold coins.
|
||||
func (k Keeper) StartForwardAuction(ctx sdk.Context, seller string, lot sdk.Coin, bidDenom string) (uint64, sdk.Error) {
|
||||
// StartSurplusAuction starts a normal auction that mints the sold coins.
|
||||
func (k Keeper) StartSurplusAuction(ctx sdk.Context, seller string, lot sdk.Coin, bidDenom string) (uint64, sdk.Error) {
|
||||
// create auction
|
||||
auction := types.NewForwardAuction(seller, lot, bidDenom, ctx.BlockTime().Add(types.DefaultMaxAuctionDuration))
|
||||
auction := types.NewSurplusAuction(seller, lot, bidDenom, ctx.BlockTime().Add(types.DefaultMaxAuctionDuration))
|
||||
|
||||
// take coins from module account
|
||||
err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, seller, types.ModuleName, sdk.NewCoins(lot))
|
||||
@ -27,10 +27,10 @@ func (k Keeper) StartForwardAuction(ctx sdk.Context, seller string, lot sdk.Coin
|
||||
return auctionID, nil
|
||||
}
|
||||
|
||||
// StartReverseAuction starts an auction where sellers compete by offering decreasing prices.
|
||||
func (k Keeper) StartReverseAuction(ctx sdk.Context, buyer string, bid sdk.Coin, initialLot sdk.Coin) (uint64, sdk.Error) {
|
||||
// StartDebtAuction starts an auction where sellers compete by offering decreasing prices.
|
||||
func (k Keeper) StartDebtAuction(ctx sdk.Context, buyer string, bid sdk.Coin, initialLot sdk.Coin) (uint64, sdk.Error) {
|
||||
// create auction
|
||||
auction := types.NewReverseAuction(buyer, bid, initialLot, ctx.BlockTime().Add(types.DefaultMaxAuctionDuration))
|
||||
auction := types.NewDebtAuction(buyer, bid, initialLot, ctx.BlockTime().Add(types.DefaultMaxAuctionDuration))
|
||||
|
||||
// This auction type mints coins at close. Need to check module account has minting privileges to avoid potential err in endblocker.
|
||||
macc := k.supplyKeeper.GetModuleAccount(ctx, buyer)
|
||||
@ -45,14 +45,14 @@ func (k Keeper) StartReverseAuction(ctx sdk.Context, buyer string, bid sdk.Coin,
|
||||
return auctionID, nil
|
||||
}
|
||||
|
||||
// StartForwardReverseAuction starts an auction where bidders bid up to a maxBid, then switch to bidding down on price.
|
||||
func (k Keeper) StartForwardReverseAuction(ctx sdk.Context, seller string, lot sdk.Coin, maxBid sdk.Coin, lotReturnAddrs []sdk.AccAddress, lotReturnWeights []sdk.Int) (uint64, sdk.Error) {
|
||||
// StartCollateralAuction starts an auction where bidders bid up to a maxBid, then switch to bidding down on price.
|
||||
func (k Keeper) StartCollateralAuction(ctx sdk.Context, seller string, lot sdk.Coin, maxBid sdk.Coin, lotReturnAddrs []sdk.AccAddress, lotReturnWeights []sdk.Int) (uint64, sdk.Error) {
|
||||
// create auction
|
||||
weightedAddresses, err := types.NewWeightedAddresses(lotReturnAddrs, lotReturnWeights)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
auction := types.NewForwardReverseAuction(seller, lot, ctx.BlockTime().Add(types.DefaultMaxAuctionDuration), maxBid, weightedAddresses)
|
||||
auction := types.NewCollateralAuction(seller, lot, ctx.BlockTime().Add(types.DefaultMaxAuctionDuration), maxBid, weightedAddresses)
|
||||
|
||||
// take coins from module account
|
||||
err = k.supplyKeeper.SendCoinsFromModuleToModule(ctx, seller, types.ModuleName, sdk.NewCoins(lot))
|
||||
@ -85,19 +85,19 @@ func (k Keeper) PlaceBid(ctx sdk.Context, auctionID uint64, bidder sdk.AccAddres
|
||||
var err sdk.Error
|
||||
var updatedAuction types.Auction
|
||||
switch a := auction.(type) {
|
||||
case types.ForwardAuction:
|
||||
if updatedAuction, err = k.PlaceBidForward(ctx, a, bidder, newAmount); err != nil {
|
||||
case types.SurplusAuction:
|
||||
if updatedAuction, err = k.PlaceBidSurplus(ctx, a, bidder, newAmount); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.ReverseAuction:
|
||||
if updatedAuction, err = k.PlaceBidReverse(ctx, a, bidder, newAmount); err != nil {
|
||||
case types.DebtAuction:
|
||||
if updatedAuction, err = k.PlaceBidDebt(ctx, a, bidder, newAmount); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.ForwardReverseAuction:
|
||||
case types.CollateralAuction:
|
||||
if !a.IsReversePhase() {
|
||||
updatedAuction, err = k.PlaceBidForwardReverseForward(ctx, a, bidder, newAmount)
|
||||
updatedAuction, err = k.PlaceForwardBidCollateral(ctx, a, bidder, newAmount)
|
||||
} else {
|
||||
updatedAuction, err = k.PlaceBidForwardReverseReverse(ctx, a, bidder, newAmount)
|
||||
updatedAuction, err = k.PlaceReverseBidCollateral(ctx, a, bidder, newAmount)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@ -111,7 +111,7 @@ func (k Keeper) PlaceBid(ctx sdk.Context, auctionID uint64, bidder sdk.AccAddres
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k Keeper) PlaceBidForward(ctx sdk.Context, a types.ForwardAuction, bidder sdk.AccAddress, bid sdk.Coin) (types.ForwardAuction, sdk.Error) {
|
||||
func (k Keeper) PlaceBidSurplus(ctx sdk.Context, a types.SurplusAuction, bidder sdk.AccAddress, bid sdk.Coin) (types.SurplusAuction, sdk.Error) {
|
||||
// Validate New Bid
|
||||
if bid.Denom != a.Bid.Denom {
|
||||
return a, sdk.ErrInternal("bid denom doesn't match auction")
|
||||
@ -151,8 +151,7 @@ func (k Keeper) PlaceBidForward(ctx sdk.Context, a types.ForwardAuction, bidder
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// TODO naming
|
||||
func (k Keeper) PlaceBidForwardReverseForward(ctx sdk.Context, a types.ForwardReverseAuction, bidder sdk.AccAddress, bid sdk.Coin) (types.ForwardReverseAuction, sdk.Error) {
|
||||
func (k Keeper) PlaceForwardBidCollateral(ctx sdk.Context, a types.CollateralAuction, bidder sdk.AccAddress, bid sdk.Coin) (types.CollateralAuction, sdk.Error) {
|
||||
// Validate new bid
|
||||
if bid.Denom != a.Bid.Denom {
|
||||
return a, sdk.ErrInternal("bid denom doesn't match auction")
|
||||
@ -193,7 +192,7 @@ func (k Keeper) PlaceBidForwardReverseForward(ctx sdk.Context, a types.ForwardRe
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func (k Keeper) PlaceBidForwardReverseReverse(ctx sdk.Context, a types.ForwardReverseAuction, bidder sdk.AccAddress, lot sdk.Coin) (types.ForwardReverseAuction, sdk.Error) {
|
||||
func (k Keeper) PlaceReverseBidCollateral(ctx sdk.Context, a types.CollateralAuction, bidder sdk.AccAddress, lot sdk.Coin) (types.CollateralAuction, sdk.Error) {
|
||||
// Validate bid
|
||||
if lot.Denom != a.Lot.Denom {
|
||||
return a, sdk.ErrInternal("lot denom doesn't match auction")
|
||||
@ -240,7 +239,7 @@ func (k Keeper) PlaceBidForwardReverseReverse(ctx sdk.Context, a types.ForwardRe
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func (k Keeper) PlaceBidReverse(ctx sdk.Context, a types.ReverseAuction, bidder sdk.AccAddress, lot sdk.Coin) (types.ReverseAuction, sdk.Error) {
|
||||
func (k Keeper) PlaceBidDebt(ctx sdk.Context, a types.DebtAuction, bidder sdk.AccAddress, lot sdk.Coin) (types.DebtAuction, sdk.Error) {
|
||||
// Validate New Bid
|
||||
if lot.Denom != a.Lot.Denom {
|
||||
return a, sdk.ErrInternal("lot denom doesn't match auction")
|
||||
@ -288,16 +287,16 @@ func (k Keeper) CloseAuction(ctx sdk.Context, auctionID uint64) sdk.Error {
|
||||
|
||||
// payout to the last bidder
|
||||
switch auc := auction.(type) {
|
||||
case types.ForwardAuction:
|
||||
if err := k.PayoutForwardAuction(ctx, auc); err != nil {
|
||||
case types.SurplusAuction:
|
||||
if err := k.PayoutSurplusAuction(ctx, auc); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.ReverseAuction:
|
||||
if err := k.PayoutReverseAuction(ctx, auc); err != nil {
|
||||
case types.DebtAuction:
|
||||
if err := k.PayoutDebtAuction(ctx, auc); err != nil {
|
||||
return err
|
||||
}
|
||||
case types.ForwardReverseAuction:
|
||||
if err := k.PayoutForwardReverseAuction(ctx, auc); err != nil {
|
||||
case types.CollateralAuction:
|
||||
if err := k.PayoutCollateralAuction(ctx, auc); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
@ -308,7 +307,7 @@ func (k Keeper) CloseAuction(ctx sdk.Context, auctionID uint64) sdk.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k Keeper) PayoutReverseAuction(ctx sdk.Context, a types.ReverseAuction) sdk.Error {
|
||||
func (k Keeper) PayoutDebtAuction(ctx sdk.Context, a types.DebtAuction) sdk.Error {
|
||||
err := k.supplyKeeper.MintCoins(ctx, a.Initiator, sdk.NewCoins(a.Lot))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -320,7 +319,7 @@ func (k Keeper) PayoutReverseAuction(ctx sdk.Context, a types.ReverseAuction) sd
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k Keeper) PayoutForwardAuction(ctx sdk.Context, a types.ForwardAuction) sdk.Error {
|
||||
func (k Keeper) PayoutSurplusAuction(ctx sdk.Context, a types.SurplusAuction) sdk.Error {
|
||||
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, a.Bidder, sdk.NewCoins(a.Lot))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -328,7 +327,7 @@ func (k Keeper) PayoutForwardAuction(ctx sdk.Context, a types.ForwardAuction) sd
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k Keeper) PayoutForwardReverseAuction(ctx sdk.Context, a types.ForwardReverseAuction) sdk.Error {
|
||||
func (k Keeper) PayoutCollateralAuction(ctx sdk.Context, a types.CollateralAuction) sdk.Error {
|
||||
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, a.Bidder, sdk.NewCoins(a.Lot))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
"github.com/kava-labs/kava/x/liquidator"
|
||||
)
|
||||
|
||||
func TestForwardAuctionBasic(t *testing.T) {
|
||||
func TestSurplusAuctionBasic(t *testing.T) {
|
||||
// Setup
|
||||
_, addrs := app.GeneratePrivKeyAddressPairs(1)
|
||||
buyer := addrs[0]
|
||||
@ -37,7 +37,7 @@ func TestForwardAuctionBasic(t *testing.T) {
|
||||
keeper := tApp.GetAuctionKeeper()
|
||||
|
||||
// Create an auction (lot: 20 token1, initialBid: 0 token2)
|
||||
auctionID, err := keeper.StartForwardAuction(ctx, sellerModName, c("token1", 20), "token2") // lot, bid denom
|
||||
auctionID, err := keeper.StartSurplusAuction(ctx, sellerModName, c("token1", 20), "token2") // lot, bid denom
|
||||
require.NoError(t, err)
|
||||
// Check seller's coins have decreased
|
||||
tApp.CheckBalance(t, ctx, sellerAddr, cs(c("token1", 80), c("token2", 100)))
|
||||
@ -60,7 +60,7 @@ func TestForwardAuctionBasic(t *testing.T) {
|
||||
tApp.CheckBalance(t, ctx, buyer, cs(c("token1", 120), c("token2", 80)))
|
||||
}
|
||||
|
||||
func TestReverseAuctionBasic(t *testing.T) {
|
||||
func TestDebtAuctionBasic(t *testing.T) {
|
||||
// Setup
|
||||
_, addrs := app.GeneratePrivKeyAddressPairs(1)
|
||||
seller := addrs[0]
|
||||
@ -79,7 +79,7 @@ func TestReverseAuctionBasic(t *testing.T) {
|
||||
keeper := tApp.GetAuctionKeeper()
|
||||
|
||||
// Start auction
|
||||
auctionID, err := keeper.StartReverseAuction(ctx, buyerModName, c("token1", 20), c("token2", 99999)) // buyer, bid, initialLot
|
||||
auctionID, err := keeper.StartDebtAuction(ctx, buyerModName, c("token1", 20), c("token2", 99999)) // buyer, bid, initialLot
|
||||
require.NoError(t, err)
|
||||
// Check buyer's coins have not decreased, as lot is minted at the end
|
||||
tApp.CheckBalance(t, ctx, buyerAddr, nil) // zero coins
|
||||
@ -98,7 +98,7 @@ func TestReverseAuctionBasic(t *testing.T) {
|
||||
tApp.CheckBalance(t, ctx, seller, cs(c("token1", 80), c("token2", 110)))
|
||||
}
|
||||
|
||||
func TestForwardReverseAuctionBasic(t *testing.T) {
|
||||
func TestCollateralAuctionBasic(t *testing.T) {
|
||||
// Setup
|
||||
_, addrs := app.GeneratePrivKeyAddressPairs(4)
|
||||
buyer := addrs[0]
|
||||
@ -123,7 +123,7 @@ func TestForwardReverseAuctionBasic(t *testing.T) {
|
||||
keeper := tApp.GetAuctionKeeper()
|
||||
|
||||
// Start auction
|
||||
auctionID, err := keeper.StartForwardReverseAuction(ctx, sellerModName, c("token1", 20), c("token2", 50), returnAddrs, returnWeights) // seller, lot, maxBid, otherPerson
|
||||
auctionID, err := keeper.StartCollateralAuction(ctx, sellerModName, c("token1", 20), c("token2", 50), returnAddrs, returnWeights) // seller, lot, maxBid, otherPerson
|
||||
require.NoError(t, err)
|
||||
// Check seller's coins have decreased
|
||||
tApp.CheckBalance(t, ctx, sellerAddr, cs(c("token1", 80), c("token2", 100)))
|
||||
@ -158,7 +158,7 @@ func TestForwardReverseAuctionBasic(t *testing.T) {
|
||||
tApp.CheckBalance(t, ctx, buyer, cs(c("token1", 115), c("token2", 50)))
|
||||
}
|
||||
|
||||
func TestStartForwardAuction(t *testing.T) {
|
||||
func TestStartSurplusAuction(t *testing.T) {
|
||||
someTime := time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||
type args struct {
|
||||
seller string
|
||||
@ -211,7 +211,7 @@ func TestStartForwardAuction(t *testing.T) {
|
||||
keeper := tApp.GetAuctionKeeper()
|
||||
|
||||
// run function under test
|
||||
id, err := keeper.StartForwardAuction(ctx, tc.args.seller, tc.args.lot, tc.args.bidDenom)
|
||||
id, err := keeper.StartSurplusAuction(ctx, tc.args.seller, tc.args.lot, tc.args.bidDenom)
|
||||
|
||||
// check
|
||||
sk := tApp.GetSupplyKeeper()
|
||||
@ -224,7 +224,7 @@ func TestStartForwardAuction(t *testing.T) {
|
||||
require.Equal(t, initialLiquidatorCoins.Sub(cs(tc.args.lot)), liquidatorCoins)
|
||||
// check auction in store and is correct
|
||||
require.True(t, found)
|
||||
expectedAuction := types.Auction(types.ForwardAuction{BaseAuction: types.BaseAuction{
|
||||
expectedAuction := types.Auction(types.SurplusAuction{BaseAuction: types.BaseAuction{
|
||||
ID: 0,
|
||||
Initiator: tc.args.seller,
|
||||
Lot: tc.args.lot,
|
||||
|
@ -18,7 +18,7 @@ func SetGetDeleteAuction(t *testing.T) {
|
||||
ctx := tApp.NewContext(true, abci.Header{})
|
||||
someTime := time.Date(43, time.January, 1, 0, 0, 0, 0, time.UTC) // need to specify UTC as tz info is lost on unmarshal
|
||||
var id uint64 = 5
|
||||
auction := types.NewForwardAuction("some_module", c("usdx", 100), "kava", someTime).WithID(id)
|
||||
auction := types.NewSurplusAuction("some_module", c("usdx", 100), "kava", someTime).WithID(id)
|
||||
|
||||
// write and read from store
|
||||
keeper.SetAuction(ctx, auction)
|
||||
@ -73,9 +73,9 @@ func TestIterateAuctions(t *testing.T) {
|
||||
ctx := tApp.NewContext(true, abci.Header{})
|
||||
|
||||
auctions := []types.Auction{
|
||||
types.NewForwardAuction("sellerMod", c("denom", 12345678), "anotherdenom", time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)).WithID(0),
|
||||
types.NewReverseAuction("buyerMod", c("denom", 12345678), c("anotherdenom", 12345678), time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)).WithID(1),
|
||||
types.NewForwardReverseAuction("sellerMod", c("denom", 12345678), time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC), c("anotherdenom", 12345678), types.WeightedAddresses{}).WithID(2),
|
||||
types.NewSurplusAuction("sellerMod", c("denom", 12345678), "anotherdenom", time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)).WithID(0),
|
||||
types.NewDebtAuction("buyerMod", c("denom", 12345678), c("anotherdenom", 12345678), time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)).WithID(1),
|
||||
types.NewCollateralAuction("sellerMod", c("denom", 12345678), time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC), c("anotherdenom", 12345678), types.WeightedAddresses{}).WithID(2),
|
||||
}
|
||||
for _, a := range auctions {
|
||||
keeper.SetAuction(ctx, a)
|
||||
|
@ -6,8 +6,8 @@ order: 1
|
||||
|
||||
Auctions are broken down into three distinct types, which correspond to three specific functionalities within the CDP system.
|
||||
|
||||
* **Forward Auction:** An auction in which a fixed lot of coins (c1) is sold for increasing amounts of other coins (c2). Bidders increment the amount of c2 they are willing to pay for the lot of c1. After the completion of a forward auction, the winning bid of c2 is burned, and the bidder receives the lot of c1. As a concrete example, forward auction are used to sell a fixed amount of USDX stable coins in exchange for increasing bids of KAVA governance tokens. The governance tokens are then burned and the winner receives USDX.
|
||||
* **Reverse Auction:** An auction in which a fixed amount of coins (c1) is bid for a decreasing lot of other coins (c2). Bidders decrement the lot of c2 they are willing to receive for the fixed amount of c1. As a concrete example, reverse auctions are used to raise a certain amount of USDX stable coins in exchange for decreasing lots of KAVA governance tokens. The USDX tokens are used to recapitalize the cdp system and the winner receives KAVA.
|
||||
* **Forward Reverse Auction:** An two phase auction is which a fixed lot of coins (c1) is sold for increasing amounts of other coins (c2). Bidders increment the amount of c2 until a specific `maxBid` is reached. Once `maxBid` is reached, a fixed amount of c2 is bid for a decreasing lot of c1. In the second phase, bidders decrement the lot of c1 they are willing to receive for a fixed amount of c2. As a concrete example. forward reverse auctions are used to sell collateral (ATOM, for example) for up to a `maxBid` amount of USDX. The USDX tokens are used to recapitalize the cdp system and the winner receives the specified lot of ATOM. In the event that the winning lot is smaller than the total lot, the excess ATOM is ratably returned to the original owners of the liquidated CDPs that were collateralized with that ATOM.
|
||||
* **Surplus Auction:** An auction in which a fixed lot of coins (c1) is sold for increasing amounts of other coins (c2). Bidders increment the amount of c2 they are willing to pay for the lot of c1. After the completion of a forward auction, the winning bid of c2 is burned, and the bidder receives the lot of c1. As a concrete example, forward auction are used to sell a fixed amount of USDX stable coins in exchange for increasing bids of KAVA governance tokens. The governance tokens are then burned and the winner receives USDX.
|
||||
* **Debt Auction:** An auction in which a fixed amount of coins (c1) is bid for a decreasing lot of other coins (c2). Bidders decrement the lot of c2 they are willing to receive for the fixed amount of c1. As a concrete example, reverse auctions are used to raise a certain amount of USDX stable coins in exchange for decreasing lots of KAVA governance tokens. The USDX tokens are used to recapitalize the cdp system and the winner receives KAVA.
|
||||
* **Surplus Reverse Auction:** An two phase auction is which a fixed lot of coins (c1) is sold for increasing amounts of other coins (c2). Bidders increment the amount of c2 until a specific `maxBid` is reached. Once `maxBid` is reached, a fixed amount of c2 is bid for a decreasing lot of c1. In the second phase, bidders decrement the lot of c1 they are willing to receive for a fixed amount of c2. As a concrete example. forward reverse auctions are used to sell collateral (ATOM, for example) for up to a `maxBid` amount of USDX. The USDX tokens are used to recapitalize the cdp system and the winner receives the specified lot of ATOM. In the event that the winning lot is smaller than the total lot, the excess ATOM is ratably returned to the original owners of the liquidated CDPs that were collateralized with that ATOM.
|
||||
|
||||
Auctions are always initiated by another module, and not directly by users. Auctions start with an expiry, the time at which the auction is guaranteed to end, even if there have been no bidders. After each bid, the auction is extended by a specific amount of time, `BidDuration`. In the case that increasing the auction time by `BidDuration` would cause the auction to go past its expiry, the expiry is chosen as the ending time.
|
||||
|
@ -51,13 +51,13 @@ type BaseAuction struct {
|
||||
MaxEndTime time.Time // Maximum closing time. Auctions can close before this but never after.
|
||||
}
|
||||
|
||||
// ForwardAuction type for forward auctions
|
||||
type ForwardAuction struct {
|
||||
//SurplusAuction type for forward auctions
|
||||
typeSurplusAuction struct {
|
||||
BaseAuction
|
||||
}
|
||||
|
||||
// ReverseAuction type for reverse auctions
|
||||
type ReverseAuction struct {
|
||||
// DebtAuction type for reverse auctions
|
||||
type DebtAuction struct {
|
||||
BaseAuction
|
||||
}
|
||||
|
||||
@ -67,8 +67,8 @@ type WeightedAddresses struct {
|
||||
Weights []sdk.Int
|
||||
}
|
||||
|
||||
// ForwardReverseAuction type for forward reverse auction
|
||||
type ForwardReverseAuction struct {
|
||||
// CollateralAuction type for forward reverse auction
|
||||
type CollateralAuction struct {
|
||||
BaseAuction
|
||||
MaxBid sdk.Coin
|
||||
LotReturns WeightedAddresses // return addresses to pay out reductions in the lot amount to. Lot is bid down during reverse phase.
|
||||
|
@ -21,14 +21,14 @@ type MsgPlaceBid struct {
|
||||
**State Modifications:**
|
||||
|
||||
* Update bidder if different than previous bidder
|
||||
* For forward auctions:
|
||||
* For Surplus auctions:
|
||||
* Update Bid Amount
|
||||
* Return bid coins to previous bidder
|
||||
* Burn coins equal to the increment in the bid (CurrentBid - PreviousBid)
|
||||
* For Reverse auctions:
|
||||
* For Debt auctions:
|
||||
* Update lot amount
|
||||
* Return bid coins to previous bidder
|
||||
* For Forward Reverse auctions:
|
||||
* For Collateral auctions:
|
||||
* Return bid coins to previous bidder
|
||||
* If in forward phase:
|
||||
* Update bid amount
|
||||
|
@ -46,17 +46,17 @@ func (a BaseAuction) String() string {
|
||||
)
|
||||
}
|
||||
|
||||
// ForwardAuction type for forward auctions
|
||||
type ForwardAuction struct {
|
||||
// SurplusAuction type for forward auctions
|
||||
type SurplusAuction struct {
|
||||
BaseAuction
|
||||
}
|
||||
|
||||
// WithID returns an auction with the ID set
|
||||
func (a ForwardAuction) WithID(id uint64) Auction { a.ID = id; return a }
|
||||
func (a SurplusAuction) WithID(id uint64) Auction { a.ID = id; return a }
|
||||
|
||||
// NewForwardAuction creates a new forward auction
|
||||
func NewForwardAuction(seller string, lot sdk.Coin, bidDenom string, endTime time.Time) ForwardAuction {
|
||||
auction := ForwardAuction{BaseAuction{
|
||||
// NewSurplusAuction creates a new forward auction
|
||||
func NewSurplusAuction(seller string, lot sdk.Coin, bidDenom string, endTime time.Time) SurplusAuction {
|
||||
auction := SurplusAuction{BaseAuction{
|
||||
// no ID
|
||||
Initiator: seller,
|
||||
Lot: lot,
|
||||
@ -68,20 +68,20 @@ func NewForwardAuction(seller string, lot sdk.Coin, bidDenom string, endTime tim
|
||||
return auction
|
||||
}
|
||||
|
||||
// ReverseAuction type for reverse auctions
|
||||
type ReverseAuction struct {
|
||||
// DebtAuction type for reverse auctions
|
||||
type DebtAuction struct {
|
||||
BaseAuction
|
||||
}
|
||||
|
||||
// WithID returns an auction with the ID set
|
||||
func (a ReverseAuction) WithID(id uint64) Auction { a.ID = id; return a }
|
||||
func (a DebtAuction) WithID(id uint64) Auction { a.ID = id; return a }
|
||||
|
||||
// NewReverseAuction creates a new reverse auction
|
||||
func NewReverseAuction(buyerModAccName string, bid sdk.Coin, initialLot sdk.Coin, EndTime time.Time) ReverseAuction {
|
||||
// NewDebtAuction creates a new reverse auction
|
||||
func NewDebtAuction(buyerModAccName string, bid sdk.Coin, initialLot sdk.Coin, EndTime time.Time) DebtAuction {
|
||||
// Note: Bidder is set to the initiator's module account address instead of module name. (when the first bid is placed, it is paid out to the initiator)
|
||||
// Setting to the module account address bypasses calling supply.SendCoinsFromModuleToModule, instead calls SendCoinsFromModuleToAccount.
|
||||
// This isn't a problem currently, but if additional logic/validation was added for sending to coins to Module Accounts, it would be bypassed.
|
||||
auction := ReverseAuction{BaseAuction{
|
||||
auction := DebtAuction{BaseAuction{
|
||||
// no ID
|
||||
Initiator: buyerModAccName,
|
||||
Lot: initialLot,
|
||||
@ -93,21 +93,21 @@ func NewReverseAuction(buyerModAccName string, bid sdk.Coin, initialLot sdk.Coin
|
||||
return auction
|
||||
}
|
||||
|
||||
// ForwardReverseAuction type for forward reverse auction
|
||||
type ForwardReverseAuction struct {
|
||||
// CollateralAuction type for forward reverse auction
|
||||
type CollateralAuction struct {
|
||||
BaseAuction
|
||||
MaxBid sdk.Coin
|
||||
LotReturns WeightedAddresses // return addresses to pay out reductions in the lot amount to. Lot is bid down during reverse phase.
|
||||
}
|
||||
|
||||
// WithID returns an auction with the ID set
|
||||
func (a ForwardReverseAuction) WithID(id uint64) Auction { a.ID = id; return a }
|
||||
func (a CollateralAuction) WithID(id uint64) Auction { a.ID = id; return a }
|
||||
|
||||
func (a ForwardReverseAuction) IsReversePhase() bool {
|
||||
func (a CollateralAuction) IsReversePhase() bool {
|
||||
return a.Bid.IsEqual(a.MaxBid)
|
||||
}
|
||||
|
||||
func (a ForwardReverseAuction) String() string {
|
||||
func (a CollateralAuction) String() string {
|
||||
return fmt.Sprintf(`Auction %d:
|
||||
Initiator: %s
|
||||
Lot: %s
|
||||
@ -123,9 +123,9 @@ func (a ForwardReverseAuction) String() string {
|
||||
)
|
||||
}
|
||||
|
||||
// NewForwardReverseAuction creates a new forward reverse auction
|
||||
func NewForwardReverseAuction(seller string, lot sdk.Coin, EndTime time.Time, maxBid sdk.Coin, lotReturns WeightedAddresses) ForwardReverseAuction {
|
||||
auction := ForwardReverseAuction{
|
||||
// NewCollateralAuction creates a new forward reverse auction
|
||||
func NewCollateralAuction(seller string, lot sdk.Coin, EndTime time.Time, maxBid sdk.Coin, lotReturns WeightedAddresses) CollateralAuction {
|
||||
auction := CollateralAuction{
|
||||
BaseAuction: BaseAuction{
|
||||
// no ID
|
||||
Initiator: seller,
|
||||
|
@ -2,7 +2,7 @@ package types
|
||||
|
||||
// // TODO can this be less verbose? Should PlaceBid() be split into smaller functions?
|
||||
// // It would be possible to combine all auction tests into one test runner.
|
||||
// func TestForwardAuction_PlaceBid(t *testing.T) {
|
||||
// func TesSurplusAuction_PlaceBid(t *testing.T) {
|
||||
// seller := sdk.AccAddress([]byte("a_seller"))
|
||||
// buyer1 := sdk.AccAddress([]byte("buyer1"))
|
||||
// buyer2 := sdk.AccAddress([]byte("buyer2"))
|
||||
@ -17,7 +17,7 @@ package types
|
||||
// }
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// auction ForwardAuction
|
||||
// auction SurplusAuction
|
||||
// args args
|
||||
// expectedOutputs []BankOutput
|
||||
// expectedInputs []BankInput
|
||||
@ -28,7 +28,7 @@ package types
|
||||
// }{
|
||||
// {
|
||||
// "normal",
|
||||
// ForwardAuction{BaseAuction{
|
||||
// SurplusAuction{BaseAuction{
|
||||
// Initiator: seller,
|
||||
// Lot: c("usdx", 100),
|
||||
// Bidder: buyer1,
|
||||
@ -46,7 +46,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "lowBid",
|
||||
// ForwardAuction{BaseAuction{
|
||||
// SurplusAuction{BaseAuction{
|
||||
// Initiator: seller,
|
||||
// Lot: c("usdx", 100),
|
||||
// Bidder: buyer1,
|
||||
@ -64,7 +64,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "equalBid",
|
||||
// ForwardAuction{BaseAuction{
|
||||
// SurplusAuction{BaseAuction{
|
||||
// Initiator: seller,
|
||||
// Lot: c("usdx", 100),
|
||||
// Bidder: buyer1,
|
||||
@ -82,7 +82,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "timeout",
|
||||
// ForwardAuction{BaseAuction{
|
||||
// SurplusAuction{BaseAuction{
|
||||
// Initiator: seller,
|
||||
// Lot: c("usdx", 100),
|
||||
// Bidder: buyer1,
|
||||
@ -100,7 +100,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "hitMaxEndTime",
|
||||
// ForwardAuction{BaseAuction{
|
||||
// SurplusAuction{BaseAuction{
|
||||
// Initiator: seller,
|
||||
// Lot: c("usdx", 100),
|
||||
// Bidder: buyer1,
|
||||
@ -139,7 +139,7 @@ package types
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestReverseAuction_PlaceBid(t *testing.T) {
|
||||
// func TestDebtAuction_PlaceBid(t *testing.T) {
|
||||
// buyer := sdk.AccAddress([]byte("a_buyer"))
|
||||
// seller1 := sdk.AccAddress([]byte("seller1"))
|
||||
// seller2 := sdk.AccAddress([]byte("seller2"))
|
||||
@ -154,7 +154,7 @@ package types
|
||||
// }
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// auction ReverseAuction
|
||||
// auction DebtAuction
|
||||
// args args
|
||||
// expectedOutputs []BankOutput
|
||||
// expectedInputs []BankInput
|
||||
@ -165,7 +165,7 @@ package types
|
||||
// }{
|
||||
// {
|
||||
// "normal",
|
||||
// ReverseAuction{BaseAuction{
|
||||
// DebtAuction{BaseAuction{
|
||||
// Initiator: buyer,
|
||||
// Lot: c("kava", 10),
|
||||
// Bidder: seller1,
|
||||
@ -183,7 +183,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "highBid",
|
||||
// ReverseAuction{BaseAuction{
|
||||
// DebtAuction{BaseAuction{
|
||||
// Initiator: buyer,
|
||||
// Lot: c("kava", 10),
|
||||
// Bidder: seller1,
|
||||
@ -201,7 +201,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "equalBid",
|
||||
// ReverseAuction{BaseAuction{
|
||||
// DebtAuction{BaseAuction{
|
||||
// Initiator: buyer,
|
||||
// Lot: c("kava", 10),
|
||||
// Bidder: seller1,
|
||||
@ -219,7 +219,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "timeout",
|
||||
// ReverseAuction{BaseAuction{
|
||||
// DebtAuction{BaseAuction{
|
||||
// Initiator: buyer,
|
||||
// Lot: c("kava", 10),
|
||||
// Bidder: seller1,
|
||||
@ -237,7 +237,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "hitMaxEndTime",
|
||||
// ReverseAuction{BaseAuction{
|
||||
// DebtAuction{BaseAuction{
|
||||
// Initiator: buyer,
|
||||
// Lot: c("kava", 10),
|
||||
// Bidder: seller1,
|
||||
@ -276,7 +276,7 @@ package types
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestForwardReverseAuction_PlaceBid(t *testing.T) {
|
||||
// func TestCollateralAuction_PlaceBid(t *testing.T) {
|
||||
// cdpOwner := sdk.AccAddress([]byte("a_cdp_owner"))
|
||||
// seller := sdk.AccAddress([]byte("a_seller"))
|
||||
// buyer1 := sdk.AccAddress([]byte("buyer1"))
|
||||
@ -292,7 +292,7 @@ package types
|
||||
// }
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// auction ForwardReverseAuction
|
||||
// auction CollateralAuction
|
||||
// args args
|
||||
// expectedOutputs []BankOutput
|
||||
// expectedInputs []BankInput
|
||||
@ -304,7 +304,7 @@ package types
|
||||
// }{
|
||||
// {
|
||||
// "normalForwardBid",
|
||||
// ForwardReverseAuction{BaseAuction: BaseAuction{
|
||||
// CollateralAuction{BaseAuction: BaseAuction{
|
||||
// Initiator: seller,
|
||||
// Lot: c("xrp", 100),
|
||||
// Bidder: buyer1,
|
||||
@ -325,7 +325,7 @@ package types
|
||||
// },
|
||||
// {
|
||||
// "normalSwitchOverBid",
|
||||
// ForwardReverseAuction{BaseAuction: BaseAuction{
|
||||
// CollateralAuction{BaseAuction: BaseAuction{
|
||||
// Initiator: seller,
|
||||
// Lot: c("xrp", 100),
|
||||
// Bidder: buyer1,
|
||||
@ -345,8 +345,8 @@ package types
|
||||
// true,
|
||||
// },
|
||||
// {
|
||||
// "normalReverseBid",
|
||||
// ForwardReverseAuction{BaseAuction: BaseAuction{
|
||||
// "normalDebtBid",
|
||||
// CollateralAuction{BaseAuction: BaseAuction{
|
||||
// Initiator: seller,
|
||||
// Lot: c("xrp", 99),
|
||||
// Bidder: buyer1,
|
||||
|
@ -17,7 +17,7 @@ func RegisterCodec(cdc *codec.Codec) {
|
||||
|
||||
// Register the Auction interface and concrete types
|
||||
cdc.RegisterInterface((*Auction)(nil), nil)
|
||||
cdc.RegisterConcrete(ForwardAuction{}, "auction/ForwardAuction", nil)
|
||||
cdc.RegisterConcrete(ReverseAuction{}, "auction/ReverseAuction", nil)
|
||||
cdc.RegisterConcrete(ForwardReverseAuction{}, "auction/ForwardReverseAuction", nil)
|
||||
cdc.RegisterConcrete(SurplusAuction{}, "auction/SurplusAuction", nil)
|
||||
cdc.RegisterConcrete(DebtAuction{}, "auction/DebtAuction", nil)
|
||||
cdc.RegisterConcrete(CollateralAuction{}, "auction/CollateralAuction", nil)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user