[ENG-685]: Reordering the bid checking so that it is more logical (#45)

This commit is contained in:
David Terpay 2023-04-05 17:55:00 -04:00 committed by GitHub
parent dbf280be65
commit 5d1e08d5aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,17 +41,6 @@ func (k Keeper) ValidateAuctionMsg(ctx sdk.Context, bidder sdk.AccAddress, bid,
// ValidateAuctionBid validates that the bidder has sufficient funds to participate in the auction and that the bid amount
// is sufficiently high enough.
func (k Keeper) ValidateAuctionBid(ctx sdk.Context, bidder sdk.AccAddress, bid, highestBid sdk.Coins) error {
// Ensure the bid is greater than the highest bid + min bid increment.
minBidIncrement, err := k.GetMinBidIncrement(ctx)
if err != nil {
return err
}
minBid := highestBid.Add(minBidIncrement...)
if !bid.IsAllGTE(minBid) {
return fmt.Errorf("bid amount (%s) is less than the highest bid (%s) + min bid increment (%s)", bid, highestBid, minBidIncrement)
}
// Get the bid floor.
reserveFee, err := k.GetReserveFee(ctx)
if err != nil {
@ -62,6 +51,19 @@ func (k Keeper) ValidateAuctionBid(ctx sdk.Context, bidder sdk.AccAddress, bid,
return fmt.Errorf("bid amount (%s) is less than the reserve fee (%s)", bid, reserveFee)
}
if !highestBid.Empty() {
// Ensure the bid is greater than the highest bid + min bid increment.
minBidIncrement, err := k.GetMinBidIncrement(ctx)
if err != nil {
return err
}
minBid := highestBid.Add(minBidIncrement...)
if !bid.IsAllGTE(minBid) {
return fmt.Errorf("bid amount (%s) is less than the highest bid (%s) + min bid increment (%s)", bid, highestBid, minBidIncrement)
}
}
// Get the pay-to-play fee.
minBuyInFee, err := k.GetMinBuyInFee(ctx)
if err != nil {