forked from cerc-io/laconicd
Add TODO comments for reverse auction changes
This commit is contained in:
parent
df43322ef3
commit
aad2eb979b
@ -109,6 +109,13 @@ message Auction {
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.moretags) = "json:\"winning_price\" yaml:\"winning_price\""
|
||||
];
|
||||
|
||||
// cosmos.base.v1beta1.Coin maximum_bid
|
||||
// for reverse auctions
|
||||
|
||||
// bool reverse
|
||||
// if true, lowest bidder wins the auction (reverse auction) (supplier / service provider / etc. auctions)
|
||||
// if false, highest bidder wins the auction (forward auction)
|
||||
}
|
||||
|
||||
// Auctions represent all the auctions in the module
|
||||
|
||||
@ -339,6 +339,8 @@ func (k Keeper) CreateAuction(ctx sdk.Context, msg auctiontypes.MsgCreateAuction
|
||||
commitsEndTime := now.Add(msg.CommitsDuration)
|
||||
revealsEndTime := now.Add(msg.CommitsDuration + msg.RevealsDuration)
|
||||
|
||||
// if it's a reverse auction, take msg.MaximumBid from signerAddress to module account
|
||||
|
||||
auction := auctiontypes.Auction{
|
||||
Id: auctionId,
|
||||
Status: auctiontypes.AuctionStatusCommitPhase,
|
||||
@ -638,6 +640,10 @@ func (k Keeper) deleteCompletedAuctions(ctx sdk.Context) error {
|
||||
func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction) error {
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Picking auction %s winner.", auction.Id))
|
||||
|
||||
// Rename variables
|
||||
// bestBid
|
||||
// secondBestBid
|
||||
|
||||
var highestBid *auctiontypes.Bid
|
||||
var secondHighestBid *auctiontypes.Bid
|
||||
|
||||
@ -662,6 +668,10 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
continue
|
||||
}
|
||||
|
||||
// implement a comparison function to get a better bid amont two
|
||||
// higher is better for forward auctions
|
||||
// lower is better for reverse auctions
|
||||
|
||||
//nolint: all
|
||||
if highestBid.BidAmount.IsLT(bid.BidAmount) {
|
||||
k.Logger(ctx).Info(fmt.Sprintf("New highest bid %s %s", bid.BidderAddress, bid.BidAmount.String()))
|
||||
@ -682,6 +692,8 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
}
|
||||
}
|
||||
|
||||
// in case of reverse auctions, WinningPrice is second lowest bid (secondBestBid)
|
||||
|
||||
// Highest bid is the winner, but pays second highest bid price.
|
||||
auction.Status = auctiontypes.AuctionStatusCompleted
|
||||
|
||||
@ -721,6 +733,10 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
}
|
||||
}
|
||||
|
||||
// do this only in forward auctions
|
||||
// in reverse auctions, return the extra amount back to the auction creator (auction.OwnerAddress)
|
||||
// extra amount = maximumBid - secondBestBid
|
||||
|
||||
// Send back locked bid amount to all bidders.
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctiontypes.ModuleName, bidderAddress, sdk.NewCoins(bid.BidAmount))
|
||||
if sdkErr != nil {
|
||||
@ -762,6 +778,9 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error burning coins: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
} else {
|
||||
// if no winner
|
||||
// return all funds back to the auction creator
|
||||
}
|
||||
|
||||
// Notify other modules (hook).
|
||||
|
||||
Loading…
Reference in New Issue
Block a user