Add service provider auctions #59

Merged
nabarun merged 29 commits from deep-stack/laconicd:iv-service-provider-auction into main 2024-09-25 12:38:50 +00:00
5 changed files with 32 additions and 21 deletions
Showing only changes of commit 9e3b2cc0dc - Show all commits

View File

@ -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)

View File

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

View File

@ -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,

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.")
}
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,13 +899,14 @@ 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)))
extraAmountCoin := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid))
sdkErr = k.bankKeeper.SendCoinsFromModuleToAccount(
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx,
auctiontypes.ModuleName,
sdk.AccAddress(auction.OwnerAddress),
@ -911,7 +916,6 @@ func (k Keeper) pickServiceProviderAuctionWinners(ctx sdk.Context, auction *auct
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))))

View File

@ -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,
)