Skip to content

Commit

Permalink
Fixes bid price comparison logic in auction handler
Browse files Browse the repository at this point in the history
Corrects the mathematical comparison for bid price validation to properly compare payment amount against selling amount multiplied by floor price.

Adds clarifying comments explaining the price conversion between tokens and the purpose of MinPriceMultiplier to improve code readability.
  • Loading branch information
assafmo committed Dec 24, 2024
1 parent 2bbebeb commit 8995864
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions x/auction/keeper/auction_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ func fcfsBidHandler(ctx sdk.Context, k Keeper, auction *types.Auction, bid *type
)
}

// Note: price converts SellingToken to PaymentToken
// Any calculation down the road makes sense only if price is multiplied by a derivative of SellingToken
price, err := k.icqoracleKeeper.GetTokenPriceForQuoteDenom(ctx, auction.SellingDenom, auction.PaymentDenom)
if err != nil {
return err
}

// Apply MinPriceMultiplier
bidsFloorPrice := price.Mul(auction.MinPriceMultiplier)

if bid.SellingTokenAmount.ToLegacyDec().
Mul(bidsFloorPrice).
LT(bid.PaymentTokenAmount.ToLegacyDec()) {
// if paymentAmount < sellingAmount * bidsFloorPrice
if bid.PaymentTokenAmount.ToLegacyDec().LT(bid.SellingTokenAmount.ToLegacyDec().
Mul(bidsFloorPrice)) {
return fmt.Errorf("bid price too low: offered %s%s for %s%s, bids floor price is %s%s (price=%s %s/%s)",
bid.PaymentTokenAmount.String(),
auction.PaymentDenom,
Expand Down

0 comments on commit 8995864

Please sign in to comment.