Skip to content

Commit

Permalink
rename price_multiplier to min_price_multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Dec 19, 2024
1 parent 3390b83 commit 59a9e78
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 144 deletions.
5 changes: 3 additions & 2 deletions proto/stride/auction/auction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ message Auction {
// Whether auction is active
bool enabled = 5;

// Price multiplier (e.g. 0.95 for 5% discount)
string price_multiplier = 6 [
// Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle price)
// bids_floor_price = oracle_price * min_price_multiplier
string min_price_multiplier = 6 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
Expand Down
10 changes: 6 additions & 4 deletions proto/stride/auction/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ message MsgCreateAuction {
// Whether auction is active
bool enabled = 6;

// Price multiplier (e.g. 0.95 for 5% discount)
string price_multiplier = 7 [
// Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle price)
// bids_floor_price = oracle_price * min_price_multiplier
string min_price_multiplier = 7 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
Expand Down Expand Up @@ -109,8 +110,9 @@ message MsgUpdateAuction {
// Whether auction is active
bool enabled = 4;

// Price multiplier (e.g. 0.95 for 5% discount)
string price_multiplier = 5 [
// Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle price)
// bids_floor_price = oracle_price * min_price_multiplier
string min_price_multiplier = 5 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
Expand Down
4 changes: 2 additions & 2 deletions x/auction/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Example:

func CmdCreateAuction() *cobra.Command {
cmd := &cobra.Command{
Use: "create-auction [name] [selling-denom] [payment-denom] [enabled] [price-multiplier] [min-bid-amount] [beneficiary]",
Use: "create-auction [name] [selling-denom] [payment-denom] [enabled] [min-price-multiplier] [min-bid-amount] [beneficiary]",
Short: "Create a new auction",
Long: strings.TrimSpace(
fmt.Sprintf(`Create a new auction for a specific token.
Expand Down Expand Up @@ -133,7 +133,7 @@ Example:

func CmdUpdateAuction() *cobra.Command {
cmd := &cobra.Command{
Use: "update-auction [name] [enabled] [price-multiplier] [min-bid-amount] [beneficiary]",
Use: "update-auction [name] [enabled] [min-price-multiplier] [min-bid-amount] [beneficiary]",
Short: "Update an existing auction",
Long: strings.TrimSpace(
fmt.Sprintf(`Update an existing auction's parameters.
Expand Down
12 changes: 6 additions & 6 deletions x/auction/keeper/auction_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ func fcfsBidHandler(ctx sdk.Context, k Keeper, auction *types.Auction, bid *type
return err
}

discountedPrice := price.Mul(auction.PriceMultiplier)
bidsFloorPrice := price.Mul(auction.MinPriceMultiplier)

if bid.SellingTokenAmount.ToLegacyDec().
Mul(discountedPrice).
Mul(bidsFloorPrice).
LT(bid.PaymentTokenAmount.ToLegacyDec()) {
return fmt.Errorf("bid price too low: offered %s%s for %s%s, minimum required is %s%s (price=%s %s/%s)",
return fmt.Errorf("bid price too low: offered %s%s for %s%s, bids floor price is %s%s (price=%s %s/%s)",
bid.PaymentTokenAmount.String(),
auction.PaymentDenom,
bid.SellingTokenAmount.String(),
auction.SellingDenom,
bid.SellingTokenAmount.ToLegacyDec().Mul(discountedPrice).String(),
bid.SellingTokenAmount.ToLegacyDec().Mul(bidsFloorPrice).String(),
auction.PaymentDenom,
discountedPrice.String(),
bidsFloorPrice.String(),
auction.PaymentDenom,
auction.SellingDenom,
)
Expand Down Expand Up @@ -106,7 +106,7 @@ func fcfsBidHandler(ctx sdk.Context, k Keeper, auction *types.Auction, bid *type
sdk.NewAttribute(types.AttributeKeyPaymentDenom, auction.PaymentDenom),
sdk.NewAttribute(types.AttributeKeySellingAmount, bid.SellingTokenAmount.String()),
sdk.NewAttribute(types.AttributeKeySellingDenom, auction.SellingDenom),
sdk.NewAttribute(types.AttributeKeyPrice, discountedPrice.String()),
sdk.NewAttribute(types.AttributeKeyPrice, bidsFloorPrice.String()),
),
)

Expand Down
4 changes: 2 additions & 2 deletions x/auction/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (ms msgServer) CreateAuction(goCtx context.Context, msg *types.MsgCreateAuc
SellingDenom: msg.SellingDenom,
PaymentDenom: msg.PaymentDenom,
Enabled: msg.Enabled,
PriceMultiplier: msg.PriceMultiplier,
MinPriceMultiplier: msg.MinPriceMultiplier,
MinBidAmount: msg.MinBidAmount,
Beneficiary: msg.Beneficiary,
TotalPaymentTokenReceived: math.ZeroInt(),
Expand All @@ -75,7 +75,7 @@ func (ms msgServer) UpdateAuction(goCtx context.Context, msg *types.MsgUpdateAuc
auction.Type = msg.AuctionType
auction.Enabled = msg.Enabled
auction.MinBidAmount = msg.MinBidAmount
auction.PriceMultiplier = msg.PriceMultiplier
auction.MinPriceMultiplier = msg.MinPriceMultiplier
auction.Beneficiary = msg.Beneficiary

err = ms.Keeper.SetAuction(ctx, auction)
Expand Down
83 changes: 42 additions & 41 deletions x/auction/types/auction.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/auction/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (gs GenesisState) Validate() error {
auction.Type,
auction.SellingDenom,
auction.PaymentDenom,
auction.PriceMultiplier,
auction.MinPriceMultiplier,
auction.MinBidAmount,
auction.Beneficiary,
)
Expand Down
50 changes: 25 additions & 25 deletions x/auction/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,25 @@ func NewMsgCreateAuction(
sellingDenom string,
paymentDenom string,
enabled bool,
priceMultiplier string,
minPriceMultiplier string,
minBidAmount uint64,
beneficiary string,
) *MsgCreateAuction {
priceMultiplierDec, err := math.LegacyNewDecFromStr(priceMultiplier)
minPriceMultiplierDec, err := math.LegacyNewDecFromStr(minPriceMultiplier)
if err != nil {
panic(fmt.Sprintf("cannot parse LegacyDecimal from priceMultiplier '%s'", priceMultiplier))
panic(fmt.Sprintf("cannot parse LegacyDecimal from minPriceMultiplier '%s'", minPriceMultiplier))
}

return &MsgCreateAuction{
Admin: admin,
AuctionName: auctionName,
AuctionType: auctionType,
SellingDenom: sellingDenom,
PaymentDenom: paymentDenom,
Enabled: enabled,
PriceMultiplier: priceMultiplierDec,
MinBidAmount: math.NewIntFromUint64(minBidAmount),
Beneficiary: beneficiary,
Admin: admin,
AuctionName: auctionName,
AuctionType: auctionType,
SellingDenom: sellingDenom,
PaymentDenom: paymentDenom,
Enabled: enabled,
MinPriceMultiplier: minPriceMultiplierDec,
MinBidAmount: math.NewIntFromUint64(minBidAmount),
Beneficiary: beneficiary,
}
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func (msg *MsgCreateAuction) ValidateBasic() error {
msg.AuctionType,
msg.SellingDenom,
msg.PaymentDenom,
msg.PriceMultiplier,
msg.MinPriceMultiplier,
msg.MinBidAmount,
msg.Beneficiary,
)
Expand All @@ -165,23 +165,23 @@ func NewMsgUpdateAuction(
auctionName string,
auctionType AuctionType,
enabled bool,
priceMultiplier string,
minPriceMultiplier string,
minBidAmount uint64,
beneficiary string,
) *MsgUpdateAuction {
priceMultiplierDec, err := math.LegacyNewDecFromStr(priceMultiplier)
minPriceMultiplierDec, err := math.LegacyNewDecFromStr(minPriceMultiplier)
if err != nil {
panic(fmt.Sprintf("cannot parse LegacyDecimal from priceMultiplier '%s'", priceMultiplier))
panic(fmt.Sprintf("cannot parse LegacyDecimal from minPriceMultiplier '%s'", minPriceMultiplier))
}

return &MsgUpdateAuction{
Admin: admin,
AuctionName: auctionName,
AuctionType: auctionType,
Enabled: enabled,
PriceMultiplier: priceMultiplierDec,
MinBidAmount: math.NewIntFromUint64(minBidAmount),
Beneficiary: beneficiary,
Admin: admin,
AuctionName: auctionName,
AuctionType: auctionType,
Enabled: enabled,
MinPriceMultiplier: minPriceMultiplierDec,
MinBidAmount: math.NewIntFromUint64(minBidAmount),
Beneficiary: beneficiary,
}
}

Expand Down Expand Up @@ -216,8 +216,8 @@ func (msg *MsgUpdateAuction) ValidateBasic() error {
if _, ok := AuctionType_name[int32(msg.AuctionType)]; !ok {
return errors.New("auction-type is invalid")
}
if msg.PriceMultiplier.IsZero() {
return errors.New("price-multiplier cannot be 0")
if msg.MinPriceMultiplier.IsZero() {
return errors.New("min-price-multiplier cannot be 0")
}
if msg.MinBidAmount.LT(math.ZeroInt()) {
return errors.New("min-bid-amount must be at least 0")
Expand Down
Loading

0 comments on commit 59a9e78

Please sign in to comment.