From 9e3b2cc0dc21eae7bec90c51a7692c525ecfd267 Mon Sep 17 00:00:00 2001 From: IshaVenikar Date: Fri, 13 Sep 2024 16:12:52 +0530 Subject: [PATCH] Update create auction CLI --- gql/util.go | 6 +-- .../auction/keeper/query_server_test.go | 1 + x/auction/client/cli/tx.go | 7 +++- x/auction/keeper/keeper.go | 38 ++++++++++--------- x/registry/keeper/naming_keeper.go | 1 + 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/gql/util.go b/gql/util.go index f230f18e..3aa3d08b 100644 --- a/gql/util.go +++ b/gql/util.go @@ -233,9 +233,9 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au } winnerAddresses := make([]*string, len(auction.WinnerAddresses)) - for i := range auction.WinnerAddresses { - addr := auction.WinnerAddresses[i] - winnerAddresses[i] = &addr + for i, winnerAddress := range auction.WinnerAddresses { + address := winnerAddress + winnerAddresses[i] = &address } numProviders := int(auction.NumProviders) diff --git a/tests/integration/auction/keeper/query_server_test.go b/tests/integration/auction/keeper/query_server_test.go index 2980722d..1a8c8b53 100644 --- a/tests/integration/auction/keeper/query_server_test.go +++ b/tests/integration/auction/keeper/query_server_test.go @@ -341,6 +341,7 @@ func (kts *KeeperTestSuite) createAuctionAndCommitBid(commitBid bool) (*types.Au params.RevealFee, params.MinimumBid, sdk.Coin{}, + int32(1), types.AuctionKindVickrey, accounts[0], ), diff --git a/x/auction/client/cli/tx.go b/x/auction/client/cli/tx.go index a170b287..30423244 100644 --- a/x/auction/client/cli/tx.go +++ b/x/auction/client/cli/tx.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "fmt" "os" + "strconv" "time" "github.com/cosmos/cosmos-sdk/client" @@ -173,7 +174,11 @@ func GetCmdCreateAuction() *cobra.Command { kind := args[6] - numProviders := args[7] + numProvidersInt, err := strconv.Atoi(args[7]) + if err != nil { + return fmt.Errorf("invalid num-providers value: %w", err) + } + numProviders := int32(numProvidersInt) msg := auctiontypes.NewMsgCreateAuction( commitsDuration, diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go index 13498505..a884bfbe 100644 --- a/x/auction/keeper/keeper.go +++ b/x/auction/keeper/keeper.go @@ -531,7 +531,11 @@ func (k Keeper) RevealBid(ctx sdk.Context, msg auctiontypes.MsgRevealBid) (*auct return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.") } - if bidAmount.IsLT(auction.MinimumBid) { + if auction.Kind == "vickrey" && bidAmount.IsLT(auction.MinimumBid) { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid is lower than minimum bid.") + } + + if auction.Kind == "service_provider" && bidAmount.IsGTE(auction.MaxPrice) { return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid is lower than minimum bid.") } @@ -708,8 +712,8 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction auction.Status = auctiontypes.AuctionStatusCompleted if highestBid != nil { - winnerAddresses := make([]string, 1) - auction.WinnerAddresses = winnerAddresses + auction.WinningBids = []sdk.Coin{highestBid.BidAmount} + auction.WinnerAddresses = []string{highestBid.BidderAddress} // Winner pays 2nd price, if a 2nd price exists. auction.WinningPrice = highestBid.BidAmount if secondHighestBid != nil { @@ -895,22 +899,22 @@ func (k Keeper) pickServiceProviderAuctionWinners(ctx sdk.Context, auction *auct panic(sdkErr) } - // Send back extra amount to auction creator - totalLockedAmount := auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders))) - totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders))) + } + // Send back extra amount to auction creator + totalLockedAmount := auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders))) + totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders))) - extraAmountCoin := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid)) + extraAmountCoin := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid)) - sdkErr = k.bankKeeper.SendCoinsFromModuleToAccount( - ctx, - auctiontypes.ModuleName, - sdk.AccAddress(auction.OwnerAddress), - sdk.NewCoins(extraAmountCoin), - ) - if sdkErr != nil { - k.Logger(ctx).Error(fmt.Sprintf("Auction error returning extra locked amount: %v", sdkErr)) - panic(sdkErr) - } + sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount( + ctx, + auctiontypes.ModuleName, + sdk.AccAddress(auction.OwnerAddress), + sdk.NewCoins(extraAmountCoin), + ) + if sdkErr != nil { + k.Logger(ctx).Error(fmt.Sprintf("Auction error returning extra locked amount: %v", sdkErr)) + panic(sdkErr) } } else { totalLockedAmount := sdk.NewCoin(auction.MaxPrice.Denom, auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders)))) diff --git a/x/registry/keeper/naming_keeper.go b/x/registry/keeper/naming_keeper.go index d0c9c7ca..4358d5ec 100644 --- a/x/registry/keeper/naming_keeper.go +++ b/x/registry/keeper/naming_keeper.go @@ -295,6 +295,7 @@ func (k Keeper) createAuthority(ctx sdk.Context, name string, owner string, isRo moduleParams.AuthorityAuctionRevealFee, moduleParams.AuthorityAuctionMinimumBid, sdk.NewCoin("alnt", math.NewInt(0)), + int32(1), auctiontypes.AuctionKindVickrey, ownerAddress, )