mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-05 02:24:26 -08:00
pay lowest-bid remainder to auction creator
This commit is contained in:
@@ -2,8 +2,10 @@ package keeper
|
||||
|
||||
import (
|
||||
"cosmos-test/x/cosmostest/memdb"
|
||||
"math/big"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -36,7 +38,21 @@ func (k *Keeper) EndExpiredAuctions(ctx types.Context) {
|
||||
// clear auction
|
||||
memdb.BidDB.ClearAuction(auctionId)
|
||||
|
||||
// pay out user
|
||||
// pay out remainder to auction creator
|
||||
ceiling := new(big.Int)
|
||||
ceiling.SetString(auction.Ceiling, 10)
|
||||
lowestBidAmt := new(big.Int)
|
||||
lowestBidAmt.SetString(auction.Best.Amount, 10)
|
||||
// only pay out if there is a difference
|
||||
if ceiling.Cmp(lowestBidAmt) == 1 {
|
||||
amtRemaining := new(big.Int)
|
||||
amtRemaining.Sub(ceiling, lowestBidAmt)
|
||||
coins := sdk.NewCoins(sdk.Coin{
|
||||
Amount: sdk.NewIntFromBigInt(amtRemaining),
|
||||
Denom: auction.Denom,
|
||||
})
|
||||
k.bank.SendCoinsFromModuleToAccount(ctx, "cosmostest", sdk.AccAddress(auction.Owner), coins)
|
||||
}
|
||||
|
||||
// end auction
|
||||
k.SetAuction(ctx, auction)
|
||||
|
||||
Reference in New Issue
Block a user