From 5158b96c963ba54a40a0ff3dabfeb8354f0b79e4 Mon Sep 17 00:00:00 2001 From: turtlebasket Date: Wed, 7 Sep 2022 23:49:51 +0000 Subject: [PATCH] implement locking requirement to bid --- x/colinearcore/keeper/msg_server_lock_funds.go | 2 ++ x/colinearcore/keeper/msg_server_new_bid.go | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/x/colinearcore/keeper/msg_server_lock_funds.go b/x/colinearcore/keeper/msg_server_lock_funds.go index f16c1c6..9f9731f 100644 --- a/x/colinearcore/keeper/msg_server_lock_funds.go +++ b/x/colinearcore/keeper/msg_server_lock_funds.go @@ -59,5 +59,7 @@ func (k msgServer) LockFunds(goCtx context.Context, msg *types.MsgLockFunds) (*t lockedUsers.Users[msg.Creator] = totalAfterPay.String() + k.Keeper.SetLockedUsers(ctx, lockedUsers) + return &types.MsgLockFundsResponse{}, nil } diff --git a/x/colinearcore/keeper/msg_server_new_bid.go b/x/colinearcore/keeper/msg_server_new_bid.go index dfe4f32..8b77130 100644 --- a/x/colinearcore/keeper/msg_server_new_bid.go +++ b/x/colinearcore/keeper/msg_server_new_bid.go @@ -2,10 +2,12 @@ package keeper import ( "context" + "errors" "fmt" "math/big" "reflect" + "colinear/x/colinearcore/auctionconfig" "colinear/x/colinearcore/memdb" "colinear/x/colinearcore/types" @@ -15,6 +17,21 @@ import ( func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.MsgNewBidResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + lockedUsers, ok := k.Keeper.GetLockedUsers(ctx) + if !ok { + return nil, errors.New("unable to read locked providers (uninitialized)") + } + if lockedAmtStr, ok := lockedUsers.Users[msg.Creator]; !ok { + return nil, fmt.Errorf("provider has not locked CLR tokens (min: %d uCLR)", auctionconfig.ProviderMinLockedUClr) + } else { + lockedAmt := new(big.Int) + lockedAmt.SetString(lockedAmtStr, 10) + required := big.NewInt(auctionconfig.ProviderMinLockedUClr) + if lockedAmt.Cmp(required) == -1 { + return nil, fmt.Errorf("provider has not locked enough CLR tokens (min: %d uCLR, locked: %s)", auctionconfig.ProviderMinLockedUClr, lockedAmt.String()) + } + } + auction, found := k.Keeper.GetAuction(ctx, msg.AuctionIndex) if !found { return nil, fmt.Errorf("didn't find auction of index %s", msg.AuctionIndex) @@ -28,7 +45,6 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M return nil, fmt.Errorf("auction %s is expired", msg.AuctionIndex) } - ok := false amt := new(big.Int) amt, ok = amt.SetString(msg.Amount, 10) if !ok {