Add service provider auctions #59
@ -3915,7 +3915,7 @@ type Auction struct {
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// Auction's kind (vickrey | service_provider)
|
||||
// Auction's kind (vickrey | provider)
|
||||
Kind string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty"`
|
||||
Status string `protobuf:"bytes,3,opt,name=status,proto3" json:"status,omitempty"`
|
||||
// Address of the creator of the auction
|
||||
@ -3932,7 +3932,7 @@ type Auction struct {
|
||||
RevealFee *v1beta1.Coin `protobuf:"bytes,9,opt,name=reveal_fee,json=revealFee,proto3" json:"reveal_fee,omitempty"`
|
||||
// Minimum acceptable bid amount for a valid commit
|
||||
MinimumBid *v1beta1.Coin `protobuf:"bytes,10,opt,name=minimum_bid,json=minimumBid,proto3" json:"minimum_bid,omitempty"`
|
||||
// Addresses of the winners (one for vickrey and can be multiple for service_provider)
|
||||
// Addresses of the winners (one for vickrey auctions and can be multiple for provider auctions)
|
||||
WinnerAddresses []string `protobuf:"bytes,11,rep,name=winner_addresses,json=winnerAddresses,proto3" json:"winner_addresses,omitempty"`
|
||||
// Winning bids, i.e., the best bids
|
||||
WinningBids []*v1beta1.Coin `protobuf:"bytes,12,rep,name=winning_bids,json=winningBids,proto3" json:"winning_bids,omitempty"`
|
||||
|
@ -4311,7 +4311,7 @@ type MsgCreateAuction struct {
|
||||
MinimumBid *v1beta1.Coin `protobuf:"bytes,5,opt,name=minimum_bid,json=minimumBid,proto3" json:"minimum_bid,omitempty"`
|
||||
// Address of the signer
|
||||
Signer string `protobuf:"bytes,6,opt,name=signer,proto3" json:"signer,omitempty"`
|
||||
// Auction's kind (vickrey | service_provider)
|
||||
// Auction's kind (vickrey | provider)
|
||||
Kind string `protobuf:"bytes,7,opt,name=kind,proto3" json:"kind,omitempty"`
|
||||
// Maximum acceptable bid amount (for service provider auctions)
|
||||
MaxPrice *v1beta1.Coin `protobuf:"bytes,8,opt,name=max_price,json=maxPrice,proto3" json:"max_price,omitempty"`
|
||||
|
@ -53,7 +53,7 @@ message Auction {
|
||||
|
||||
string id = 1;
|
||||
|
||||
// Auction's kind (vickrey | service_provider)
|
||||
// Auction's kind (vickrey | provider)
|
||||
string kind = 2 [
|
||||
(gogoproto.moretags) = "json:\"kind\" yaml:\"kind\""
|
||||
];
|
||||
@ -101,7 +101,7 @@ message Auction {
|
||||
(gogoproto.moretags) = "json:\"minimum_bid\" yaml:\"minimum_bid\""
|
||||
];
|
||||
|
||||
// Addresses of the winners (one for vickrey and can be multiple for service_provider)
|
||||
// Addresses of the winners (one for vickrey auctions and can be multiple for provider auctions)
|
||||
repeated string winner_addresses = 11;
|
||||
|
||||
// Winning bids, i.e., the best bids
|
||||
@ -110,7 +110,7 @@ message Auction {
|
||||
(gogoproto.moretags) = "json:\"winning_bids\" yaml:\"winning_bids\""
|
||||
];
|
||||
|
||||
// Amount the winner pays, i.e. the second best bid
|
||||
// Amount the winner pays (vickrey auction) or gets paid (provider auction), i.e. the second best bid
|
||||
cosmos.base.v1beta1.Coin winning_price = 13 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.moretags) = "json:\"winning_price\" yaml:\"winning_price\""
|
||||
|
@ -77,7 +77,7 @@ message MsgCreateAuction {
|
||||
string signer = 6
|
||||
[ (gogoproto.moretags) = "json:\"signer\" yaml:\"signer\"" ];
|
||||
|
||||
// Auction's kind (vickrey | service_provider)
|
||||
// Auction's kind (vickrey | provider)
|
||||
string kind = 7 [
|
||||
(gogoproto.moretags) = "json:\"kind\" yaml:\"kind\""
|
||||
];
|
||||
|
@ -113,7 +113,7 @@ func (m *Params) GetMinimumBid() types.Coin {
|
||||
// Auction represents a sealed-bid on-chain auction
|
||||
type Auction struct {
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// Auction's kind (vickrey | service_provider)
|
||||
// Auction's kind (vickrey | provider)
|
||||
Kind string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty" json:"kind" yaml:"kind"`
|
||||
Status string `protobuf:"bytes,3,opt,name=status,proto3" json:"status,omitempty"`
|
||||
// Address of the creator of the auction
|
||||
@ -130,7 +130,7 @@ type Auction struct {
|
||||
RevealFee types.Coin `protobuf:"bytes,9,opt,name=reveal_fee,json=revealFee,proto3" json:"reveal_fee" json:"reveal_fee" yaml:"reveal_fee"`
|
||||
// Minimum acceptable bid amount for a valid commit
|
||||
MinimumBid types.Coin `protobuf:"bytes,10,opt,name=minimum_bid,json=minimumBid,proto3" json:"minimum_bid" json:"minimum_bid" yaml:"minimum_bid"`
|
||||
// Addresses of the winners (one for vickrey and can be multiple for service_provider)
|
||||
// Addresses of the winners (one for vickrey auctions and can be multiple for provider auctions)
|
||||
WinnerAddresses []string `protobuf:"bytes,11,rep,name=winner_addresses,json=winnerAddresses,proto3" json:"winner_addresses,omitempty"`
|
||||
// Winning bids, i.e., the best bids
|
||||
WinningBids []types.Coin `protobuf:"bytes,12,rep,name=winning_bids,json=winningBids,proto3" json:"winning_bids" json:"winning_bids" yaml:"winning_bids"`
|
||||
|
@ -341,12 +341,12 @@ func (k Keeper) CreateAuction(ctx sdk.Context, msg auctiontypes.MsgCreateAuction
|
||||
commitsEndTime := now.Add(msg.CommitsDuration)
|
||||
revealsEndTime := now.Add(msg.CommitsDuration + msg.RevealsDuration)
|
||||
|
||||
if msg.Kind == auctiontypes.AuctionKindServiceProvider {
|
||||
if msg.Kind == auctiontypes.AuctionKindProvider {
|
||||
totalLockedAmount := sdk.NewCoin(msg.MaxPrice.Denom, msg.MaxPrice.Amount.MulRaw(int64(msg.NumProviders)))
|
||||
|
||||
sdkErr := k.bankKeeper.SendCoinsFromAccountToModule(ctx, signerAddress, auctiontypes.ModuleName, sdk.NewCoins(totalLockedAmount))
|
||||
if sdkErr != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error transferring maximum_bid amount: %v", sdkErr))
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Auction error transferring maximum price amount: %v", sdkErr))
|
||||
panic(sdkErr)
|
||||
}
|
||||
}
|
||||
@ -531,12 +531,12 @@ func (k Keeper) RevealBid(ctx sdk.Context, msg auctiontypes.MsgRevealBid) (*auct
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.")
|
||||
}
|
||||
|
||||
if auction.Kind == "vickrey" && bidAmount.IsLT(auction.MinimumBid) {
|
||||
if auction.Kind == auctiontypes.AuctionKindVickrey && 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.")
|
||||
if auction.Kind == auctiontypes.AuctionKindProvider && bidAmount.IsGTE(auction.MaxPrice) {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid is higher than maximum price.")
|
||||
}
|
||||
|
||||
// Lock bid amount.
|
||||
@ -630,7 +630,7 @@ func (k Keeper) processAuctionPhases(ctx sdk.Context) error {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err = k.pickServiceProviderAuctionWinners(ctx, auction); err != nil {
|
||||
if err = k.pickProviderAuctionWinners(ctx, auction); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -754,8 +754,8 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
}
|
||||
}
|
||||
|
||||
// Process winner accounts (if nobody bids, there won't be a winner).
|
||||
if len(auction.WinnerAddresses) == 0 {
|
||||
// Process winner account (if nobody bids, there won't be a winner).
|
||||
if len(auction.WinnerAddresses) == 1 {
|
||||
winnerAddress, err := sdk.AccAddressFromBech32(auction.WinnerAddresses[0])
|
||||
if err != nil {
|
||||
k.Logger(ctx).Error(fmt.Sprintf("Invalid winner address. %v", err))
|
||||
@ -799,8 +799,8 @@ func (k Keeper) pickAuctionWinner(ctx sdk.Context, auction *auctiontypes.Auction
|
||||
return nil
|
||||
}
|
||||
|
||||
// Pick winner for service_provider auction
|
||||
func (k Keeper) pickServiceProviderAuctionWinners(ctx sdk.Context, auction *auctiontypes.Auction) error {
|
||||
// Pick winner for provider auction
|
||||
func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontypes.Auction) error {
|
||||
k.Logger(ctx).Info(fmt.Sprintf("Picking auction %s winners.", auction.Id))
|
||||
|
||||
bids, err := k.GetBids(ctx, auction.Id)
|
||||
@ -848,7 +848,6 @@ func (k Keeper) pickServiceProviderAuctionWinners(ctx sdk.Context, auction *auct
|
||||
}
|
||||
auction.WinnerAddresses = winnerAddresses
|
||||
auction.WinningBids = winningBids
|
||||
auction.WinningPrice = winnerBids[0].BidAmount
|
||||
|
||||
if len(winnerBids) > 0 {
|
||||
// The last best bid is the winning price
|
||||
|
@ -68,7 +68,7 @@ func (msg MsgCreateAuction) ValidateBasic() error {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "minimum bid should be greater than zero.")
|
||||
}
|
||||
|
||||
if msg.Kind == AuctionKindServiceProvider && !msg.MaxPrice.IsPositive() {
|
||||
if msg.Kind == AuctionKindProvider && !msg.MaxPrice.IsPositive() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "maximum price should be greater than zero.")
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ type MsgCreateAuction struct {
|
||||
MinimumBid types.Coin `protobuf:"bytes,5,opt,name=minimum_bid,json=minimumBid,proto3" json:"minimum_bid" json:"minimum_bid" yaml:"minimum_bid"`
|
||||
// Address of the signer
|
||||
Signer string `protobuf:"bytes,6,opt,name=signer,proto3" json:"signer,omitempty" json:"signer" yaml:"signer"`
|
||||
// Auction's kind (vickrey | service_provider)
|
||||
// Auction's kind (vickrey | provider)
|
||||
Kind string `protobuf:"bytes,7,opt,name=kind,proto3" json:"kind,omitempty" json:"kind" yaml:"kind"`
|
||||
// Maximum acceptable bid amount (for service provider auctions)
|
||||
MaxPrice types.Coin `protobuf:"bytes,8,opt,name=max_price,json=maxPrice,proto3" json:"max_price" json:"max_price" yaml:"max_price"`
|
||||
|
@ -31,8 +31,8 @@ const (
|
||||
|
||||
// Auction kinds
|
||||
const (
|
||||
AuctionKindVickrey = "vickrey"
|
||||
AuctionKindServiceProvider = "service_provider"
|
||||
AuctionKindVickrey = "vickrey"
|
||||
AuctionKindProvider = "provider"
|
||||
)
|
||||
|
||||
// AuctionId simplifies generation of auction ids.
|
||||
|
Loading…
Reference in New Issue
Block a user