Update create auction CLI

This commit is contained in:
IshaVenikar 2024-09-13 16:12:52 +05:30
parent 70f0d050fa
commit 9e3b2cc0dc
5 changed files with 32 additions and 21 deletions

View File

@ -233,9 +233,9 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au
} }
winnerAddresses := make([]*string, len(auction.WinnerAddresses)) winnerAddresses := make([]*string, len(auction.WinnerAddresses))
for i := range auction.WinnerAddresses { for i, winnerAddress := range auction.WinnerAddresses {
addr := auction.WinnerAddresses[i] address := winnerAddress
winnerAddresses[i] = &addr winnerAddresses[i] = &address
} }
numProviders := int(auction.NumProviders) numProviders := int(auction.NumProviders)

View File

@ -341,6 +341,7 @@ func (kts *KeeperTestSuite) createAuctionAndCommitBid(commitBid bool) (*types.Au
params.RevealFee, params.RevealFee,
params.MinimumBid, params.MinimumBid,
sdk.Coin{}, sdk.Coin{},
int32(1),
types.AuctionKindVickrey, types.AuctionKindVickrey,
accounts[0], accounts[0],
), ),

View File

@ -4,6 +4,7 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"os" "os"
"strconv"
"time" "time"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
@ -173,7 +174,11 @@ func GetCmdCreateAuction() *cobra.Command {
kind := args[6] 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( msg := auctiontypes.NewMsgCreateAuction(
commitsDuration, commitsDuration,

View File

@ -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.") 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.") 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 auction.Status = auctiontypes.AuctionStatusCompleted
if highestBid != nil { if highestBid != nil {
winnerAddresses := make([]string, 1) auction.WinningBids = []sdk.Coin{highestBid.BidAmount}
auction.WinnerAddresses = winnerAddresses auction.WinnerAddresses = []string{highestBid.BidderAddress}
// Winner pays 2nd price, if a 2nd price exists. // Winner pays 2nd price, if a 2nd price exists.
auction.WinningPrice = highestBid.BidAmount auction.WinningPrice = highestBid.BidAmount
if secondHighestBid != nil { if secondHighestBid != nil {
@ -895,22 +899,22 @@ func (k Keeper) pickServiceProviderAuctionWinners(ctx sdk.Context, auction *auct
panic(sdkErr) panic(sdkErr)
} }
// Send back extra amount to auction creator }
totalLockedAmount := auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders))) // Send back extra amount to auction creator
totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders))) 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( sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, ctx,
auctiontypes.ModuleName, auctiontypes.ModuleName,
sdk.AccAddress(auction.OwnerAddress), sdk.AccAddress(auction.OwnerAddress),
sdk.NewCoins(extraAmountCoin), sdk.NewCoins(extraAmountCoin),
) )
if sdkErr != nil { if sdkErr != nil {
k.Logger(ctx).Error(fmt.Sprintf("Auction error returning extra locked amount: %v", sdkErr)) k.Logger(ctx).Error(fmt.Sprintf("Auction error returning extra locked amount: %v", sdkErr))
panic(sdkErr) panic(sdkErr)
}
} }
} else { } else {
totalLockedAmount := sdk.NewCoin(auction.MaxPrice.Denom, auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders)))) totalLockedAmount := sdk.NewCoin(auction.MaxPrice.Denom, auction.MaxPrice.Amount.Mul(math.NewInt(int64(auction.NumProviders))))

View File

@ -295,6 +295,7 @@ func (k Keeper) createAuthority(ctx sdk.Context, name string, owner string, isRo
moduleParams.AuthorityAuctionRevealFee, moduleParams.AuthorityAuctionRevealFee,
moduleParams.AuthorityAuctionMinimumBid, moduleParams.AuthorityAuctionMinimumBid,
sdk.NewCoin("alnt", math.NewInt(0)), sdk.NewCoin("alnt", math.NewInt(0)),
int32(1),
auctiontypes.AuctionKindVickrey, auctiontypes.AuctionKindVickrey,
ownerAddress, ownerAddress,
) )