WIP type updates

This commit is contained in:
2022-09-02 21:03:03 +00:00
parent e8e7680ae2
commit 75c051af04
7 changed files with 234 additions and 26 deletions

View File

@@ -1,8 +1,10 @@
package keeper
import (
"cosmos-test/x/cosmostest/math"
"cosmos-test/x/cosmostest/memdb"
"math/big"
"time"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -25,7 +27,7 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
auction, found := k.GetAuction(ctx, auctionId)
// make sure the auction exists on-chain
if !found {
return errors.Errorf("auction %s not found on-chain", auctionId)
return errors.Errorf("auction %s not found", auctionId)
}
if uint64(ctx.BlockHeight()) >= auction.Deadline {
@@ -35,6 +37,9 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err)
}
// Remainig Unpaid: Full bid amount
auction.Remaining = auction.Best.Amount
// clear auction
memdb.BidDB.ClearAuction(auctionId)
@@ -62,6 +67,34 @@ func (k *Keeper) FinalizeExpiredAuctions(ctx types.Context) {
})
}
func (k *Keeper) VestAuctionPayments(ctx types.Context) {
func (k *Keeper) PayAuctionAmountDue(ctx types.Context, auctionId string) error {
auction, found := k.GetAuction(ctx, auctionId)
if !found {
return errors.Errorf("auction %s not found", auctionId)
}
blockTime := ctx.BlockTime()
deadline := time.Unix(int64(auction.Deadline), 0)
if blockTime.After(deadline) {
return nil
} else {
amtTotal := new(big.Int)
amtTotal.SetString(auction.Best.Amount, 10)
amtRemaining := new(big.Int)
amtTotal.SetString(auction.Remaining, 10)
amt, err := math.CalcAmountVestableLinear(
amtTotal,
amtRemaining,
ctx.BlockTime(),
time.Unix(int64(auction.LeaseStart), 0),
time.Unix(int64(auction.LeaseEnd), 0),
)
if err != nil {
return err
}
coins := sdk.NewCoins(sdk.NewCoin(auction.Denom, sdk.NewIntFromBigInt(amt)))
err = k.bank.SendCoinsFromModuleToAccount(ctx, "cosmostest", sdk.AccAddress(auction.Best.Owner), coins)
return err
}
}

View File

@@ -27,10 +27,14 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
Name: msg.Name,
Description: msg.Description,
// Best: new(types.Bid),
Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime,
Denom: msg.Denom,
Owner: msg.Creator,
Ceiling: msg.Ceiling,
Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime,
Denom: msg.Denom,
Owner: msg.Creator,
Ceiling: msg.Ceiling,
LeaseStart: uint64(ctx.BlockTime().Unix()),
LeaseEnd: msg.LeaseEnd,
Closed: false,
Remaining: "0",
}
senderAddr, err := sdk.AccAddressFromBech32(msg.Creator)