diff --git a/x/cosmostest/keeper/auction_expiry.go b/x/cosmostest/keeper/auction_expiry.go index bb352ff..d369ad9 100644 --- a/x/cosmostest/keeper/auction_expiry.go +++ b/x/cosmostest/keeper/auction_expiry.go @@ -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)