Use stable sort for sorting bids
Some checks failed
Protobuf / lint (pull_request) Successful in 18s
Build / build (pull_request) Successful in 2m11s
E2E Tests / test-e2e (pull_request) Successful in 3m8s
Integration Tests / test-integration (pull_request) Successful in 1m41s
SDK Tests / sdk_tests_nameservice_expiry (pull_request) Successful in 7m19s
SDK Tests / sdk_tests_auctions (pull_request) Failing after 11m52s
Unit Tests / test-unit (pull_request) Successful in 1m49s
SDK Tests / sdk_tests (pull_request) Failing after 9m8s
Some checks failed
Protobuf / lint (pull_request) Successful in 18s
Build / build (pull_request) Successful in 2m11s
E2E Tests / test-e2e (pull_request) Successful in 3m8s
Integration Tests / test-integration (pull_request) Successful in 1m41s
SDK Tests / sdk_tests_nameservice_expiry (pull_request) Successful in 7m19s
SDK Tests / sdk_tests_auctions (pull_request) Failing after 11m52s
Unit Tests / test-unit (pull_request) Successful in 1m49s
SDK Tests / sdk_tests (pull_request) Failing after 9m8s
This commit is contained in:
parent
3f9b494480
commit
93f7f17cc0
@ -825,7 +825,7 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort the valid bids
|
// Sort the valid bids
|
||||||
slices.SortFunc(revealedBids, func(a, b *auctiontypes.Bid) int {
|
slices.SortStableFunc(revealedBids, func(a, b *auctiontypes.Bid) int {
|
||||||
if a.BidAmount.Amount.LT(b.BidAmount.Amount) {
|
if a.BidAmount.Amount.LT(b.BidAmount.Amount) {
|
||||||
return -1
|
return -1
|
||||||
} else if a.BidAmount.Amount.GT(b.BidAmount.Amount) {
|
} else if a.BidAmount.Amount.GT(b.BidAmount.Amount) {
|
||||||
@ -887,7 +887,6 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process winner accounts (if nobody bids, there won't be a winner).
|
// Process winner accounts (if nobody bids, there won't be a winner).
|
||||||
totalLockedAmount := auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders)))
|
|
||||||
if len(winnerBids) > 0 {
|
if len(winnerBids) > 0 {
|
||||||
for _, bid := range winnerBids {
|
for _, bid := range winnerBids {
|
||||||
winnerAddress, err := sdk.AccAddressFromBech32(bid.BidderAddress)
|
winnerAddress, err := sdk.AccAddressFromBech32(bid.BidderAddress)
|
||||||
@ -903,33 +902,24 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
|
|||||||
panic(sdkErr)
|
panic(sdkErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Send back extra amount to auction creator
|
// Send back any leftover locked amount to auction creator
|
||||||
totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(len(winnerBids))))
|
// All of it in case of no winners
|
||||||
extraAmount := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid))
|
totalLockedAmount := auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders)))
|
||||||
|
totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(len(auction.WinnerAddresses))))
|
||||||
|
creatorLeftOverAmount := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid))
|
||||||
|
|
||||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
||||||
ctx,
|
ctx,
|
||||||
auctiontypes.ModuleName,
|
auctiontypes.ModuleName,
|
||||||
sdk.AccAddress(auction.OwnerAddress),
|
sdk.AccAddress(auction.OwnerAddress),
|
||||||
sdk.NewCoins(extraAmount),
|
sdk.NewCoins(creatorLeftOverAmount),
|
||||||
)
|
)
|
||||||
if sdkErr != nil {
|
if sdkErr != nil {
|
||||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error returning extra locked amount: %v", sdkErr))
|
k.Logger(ctx).Error(fmt.Sprintf("Auction error returning leftover locked amount: %v", sdkErr))
|
||||||
panic(sdkErr)
|
panic(sdkErr)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Return all locked amount in case of no winners
|
|
||||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
|
||||||
ctx,
|
|
||||||
auctiontypes.ModuleName,
|
|
||||||
sdk.AccAddress(auction.OwnerAddress),
|
|
||||||
sdk.NewCoins(sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount)))
|
|
||||||
if sdkErr != nil {
|
|
||||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error returning bid amount: %v", sdkErr))
|
|
||||||
panic(sdkErr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify other modules (hook).
|
// Notify other modules (hook).
|
||||||
k.Logger(ctx).Info(fmt.Sprintf("Auction %s notifying %d modules.", auction.Id, len(k.usageKeepers)))
|
k.Logger(ctx).Info(fmt.Sprintf("Auction %s notifying %d modules.", auction.Id, len(k.usageKeepers)))
|
||||||
|
Loading…
Reference in New Issue
Block a user