pay lowest-bid remainder to auction creator
parent
5c41dc7fef
commit
5d71effb7f
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue