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
6 changed files with 44 additions and 49 deletions
Showing only changes of commit 552db03227 - Show all commits

View File

@ -5668,7 +5668,8 @@ func (x *MsgReleaseFunds) GetSigner() string {
return "" return ""
} }
// MsgReleaseFundsResponse returns the state of the auction after releasing the funds // MsgReleaseFundsResponse returns the state of the auction after releasing the
// funds
type MsgReleaseFundsResponse struct { type MsgReleaseFundsResponse struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache

View File

@ -95,8 +95,8 @@ message Auction {
// Only applicable in provider auctions // Only applicable in provider auctions
int32 num_providers = 15; int32 num_providers = 15;
bool funds_released = 16 [ bool funds_released = 16
(gogoproto.moretags) = [ (gogoproto.moretags) =
"json:\"funds_released\" yaml:\"funds_released\"" ]; "json:\"funds_released\" yaml:\"funds_released\"" ];
} }

View File

@ -192,7 +192,8 @@ message MsgReleaseFunds {
[ (gogoproto.moretags) = "json:\"signer\" yaml:\"signer\"" ]; [ (gogoproto.moretags) = "json:\"signer\" yaml:\"signer\"" ];
} }
// MsgReleaseFundsResponse returns the state of the auction after releasing the funds // MsgReleaseFundsResponse returns the state of the auction after releasing the
// funds
message MsgReleaseFundsResponse { message MsgReleaseFundsResponse {
option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_getters) = false;

View File

@ -892,16 +892,16 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(len(auction.WinnerAddresses)))) totalAmountPaid := auction.WinningPrice.Amount.Mul(math.NewInt(int64(len(auction.WinnerAddresses))))
creatorLeftOverAmount := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid)) creatorLeftOverAmount := sdk.NewCoin(auction.MaxPrice.Denom, totalLockedAmount.Sub(totalAmountPaid))
creatorAddress, err := sdk.AccAddressFromBech32(auction.OwnerAddress) ownerAccAddress, err := sdk.AccAddressFromBech32(auction.OwnerAddress)
if err != nil { if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Invalid creatorAddress address. %v", err)) k.Logger(ctx).Error(fmt.Sprintf("Invalid auction owner address. %v", err))
panic("Invalid creator address.") panic("Invalid auction owner address.")
} }
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount( sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, ctx,
auctiontypes.ModuleName, auctiontypes.ModuleName,
creatorAddress, ownerAccAddress,
sdk.NewCoins(creatorLeftOverAmount), sdk.NewCoins(creatorLeftOverAmount),
) )
if sdkErr != nil { if sdkErr != nil {
@ -920,13 +920,6 @@ func (k Keeper) pickProviderAuctionWinners(ctx sdk.Context, auction *auctiontype
} }
func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds) (*auctiontypes.Auction, error) { func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds) (*auctiontypes.Auction, error) {
if has, err := k.HasAuction(ctx, msg.AuctionId); !has {
if err != nil {
return nil, err
}
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
}
auction, err := k.GetAuctionById(ctx, msg.AuctionId) auction, err := k.GetAuctionById(ctx, msg.AuctionId)
if err != nil { if err != nil {
return nil, err return nil, err
@ -936,21 +929,26 @@ func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds)
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction kind must be provider.") return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction kind must be provider.")
} }
if auction.Status != auctiontypes.AuctionStatusCompleted {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not completed.")
}
if auction.Status == auctiontypes.AuctionStatusFundsReleased {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Funds have already been released.")
}
// Only the auction owner can release funds. // Only the auction owner can release funds.
if msg.Signer != auction.OwnerAddress { if msg.Signer != auction.OwnerAddress {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Auction owner mismatch.") return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Auction owner mismatch.")
} }
// Process winner accounts (if nobody bids, there won't be a winner). if auction.Status != auctiontypes.AuctionStatusCompleted {
if len(auction.WinnerAddresses) > 0 { return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not completed.")
}
if auction.Status == auctiontypes.AuctionStatusFundsReleased {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction funds already released.")
}
// Mark funds as released in the stored auction
auction.FundsReleased = true
if err = k.SaveAuction(ctx, &auction); err != nil {
return nil, err
}
// Process winner accounts.
for _, winnerAddress := range auction.WinnerAddresses { for _, winnerAddress := range auction.WinnerAddresses {
winnerAccAddress, err := sdk.AccAddressFromBech32(winnerAddress) winnerAccAddress, err := sdk.AccAddressFromBech32(winnerAddress)
if err != nil { if err != nil {
@ -958,7 +956,7 @@ func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds)
panic("Invalid winner address.") panic("Invalid winner address.")
} }
// Send winning price to bidders // Send winning price to winning bidders
sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount( sdkErr := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, ctx,
auctiontypes.ModuleName, auctiontypes.ModuleName,
@ -970,9 +968,6 @@ func (k Keeper) ReleaseFunds(ctx sdk.Context, msg auctiontypes.MsgReleaseFunds)
panic(sdkErr) panic(sdkErr)
} }
} }
}
auction.FundsReleased = true
return &auction, err return &auction, err
} }

View File

@ -56,7 +56,6 @@ func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreate
} }
// CommitBid is the command for committing a bid // CommitBid is the command for committing a bid
// nolint: all
func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) { func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
@ -94,7 +93,6 @@ func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid)
} }
// RevealBid is the command for revealing a bid // RevealBid is the command for revealing a bid
// nolint: all
func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) { func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err
@ -151,7 +149,6 @@ func (ms msgServer) UpdateParams(c context.Context, msg *auctiontypes.MsgUpdateP
} }
// ReleaseFunds is the command to pay the winning amounts to provider auction winners // ReleaseFunds is the command to pay the winning amounts to provider auction winners
// nolint: all
func (ms msgServer) ReleaseFunds(c context.Context, msg *auctiontypes.MsgReleaseFunds) (*auctiontypes.MsgReleaseFundsResponse, error) { func (ms msgServer) ReleaseFunds(c context.Context, msg *auctiontypes.MsgReleaseFunds) (*auctiontypes.MsgReleaseFundsResponse, error) {
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
return nil, err return nil, err

View File

@ -434,7 +434,8 @@ func (m *MsgReleaseFunds) XXX_DiscardUnknown() {
var xxx_messageInfo_MsgReleaseFunds proto.InternalMessageInfo var xxx_messageInfo_MsgReleaseFunds proto.InternalMessageInfo
// MsgReleaseFundsResponse returns the state of the auction after releasing the funds // MsgReleaseFundsResponse returns the state of the auction after releasing the
// funds
type MsgReleaseFundsResponse struct { type MsgReleaseFundsResponse struct {
// Auction details // Auction details
Auction *Auction `protobuf:"bytes,1,opt,name=auction,proto3" json:"auction,omitempty" json:"auction" yaml:"auction"` Auction *Auction `protobuf:"bytes,1,opt,name=auction,proto3" json:"auction,omitempty" json:"auction" yaml:"auction"`