Add service provider auctions #59
@ -825,7 +825,7 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return -1
|
||||
} 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).
|
||||
totalLockedAmount := auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders)))
|
||||
if len(winnerBids) > 0 {
|
||||
for _, bid := range winnerBids {
|
||||
winnerAddress, err := sdk.AccAddressFromBech32(bid.BidderAddress)
|
||||
@ -903,32 +902,23 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
|
||||
panic(sdkErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send back extra amount to auction creator
|
||||
totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(len(winnerBids))))
|
||||
extraAmount := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid))
|
||||
// Send back any leftover locked amount to auction creator
|
||||
// All of it in case of no winners
|
||||
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(
|
||||
ctx,
|
||||
auctiontypes.ModuleName,
|
||||
sdk.AccAddress(auction.OwnerAddress),
|
||||
sdk.NewCoins(extraAmount),
|
||||
)
|
||||
if sdkErr != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error returning extra locked amount: %v", 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)
|
||||
}
|
||||
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
|
||||
ctx,
|
||||
auctiontypes.ModuleName,
|
||||
sdk.AccAddress(auction.OwnerAddress),
|
||||
sdk.NewCoins(creatorLeftOverAmount),
|
||||
)
|
||||
if sdkErr != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error returning leftover locked amount: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
|
||||
// Notify other modules (hook).
|
||||
|
Loading…
Reference in New Issue
Block a user