Skip to content

Commit

Permalink
feat: change authorized eibc lp fee acceptance criteria (#1471)
Browse files Browse the repository at this point in the history
(cherry picked from commit 80a53c7)
  • Loading branch information
zale144 authored and omritoptix committed Nov 14, 2024
1 parent db31822 commit 26c485f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 68 deletions.
4 changes: 2 additions & 2 deletions proto/dymensionxyz/dymension/eibc/authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ message RollappCriteria {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

// min_lp_fee_percentage is the minimum fee earning percentage the LP is willing to get from a demand order
cosmos.base.v1beta1.DecProto min_lp_fee_percentage = 4 [
// min_fee_percentage is the minimum gross fee earning percentage the LP is willing to get from a demand order
cosmos.base.v1beta1.DecProto min_fee_percentage = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecProto"
];
Expand Down
12 changes: 6 additions & 6 deletions x/eibc/client/cli/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
FlagExpiration = "expiration"
FlagRollapp = "rollapp"
FlagDenoms = "denoms"
FlagMinLPFeePercentage = "min-lp-fee-percentage"
FlagMinFeePercentage = "min-fee-percentage"
FlagMaxPrice = "max-price"
FlagOperatorFeeShare = "operator-fee-share"
FlagSettlementValidated = "settlement-validated"
Expand Down Expand Up @@ -59,16 +59,16 @@ Examples:
return fmt.Errorf("failed to get denoms: %w", err)
}

minFeeStr, err := cmd.Flags().GetString(FlagMinLPFeePercentage)
minFeeStr, err := cmd.Flags().GetString(FlagMinFeePercentage)
if err != nil {
return fmt.Errorf("failed to get min fee: %w", err)
}

minFeePercDec, err := sdk.NewDecFromStr(minFeeStr)
if err != nil {
return fmt.Errorf("invalid min lp fee percentage: %w", err)
return fmt.Errorf("invalid min fee percentage: %w", err)
}
minLPFeePercent := sdk.DecProto{Dec: minFeePercDec}
minFeePercent := sdk.DecProto{Dec: minFeePercDec}

maxPriceStr, err := cmd.Flags().GetString(FlagMaxPrice)
if err != nil {
Expand Down Expand Up @@ -120,7 +120,7 @@ Examples:
rollappCriteria := types.NewRollappCriteria(
rollappID,
denoms,
minLPFeePercent,
minFeePercent,
maxPrice,
spendLimit,
fulfillerFeePart,
Expand Down Expand Up @@ -150,7 +150,7 @@ Examples:
cmd.Flags().StringSlice(FlagDenoms, []string{}, "An array of denoms allowed to use")
cmd.Flags().String(FlagSpendLimit, "", "An array of Coins allowed to spend")
cmd.Flags().Bool(FlagSettlementValidated, false, "Settlement validated flag")
cmd.Flags().String(FlagMinLPFeePercentage, "", "Minimum fee")
cmd.Flags().String(FlagMinFeePercentage, "", "Minimum fee")
cmd.Flags().String(FlagMaxPrice, "", "Maximum price")
cmd.Flags().String(FlagOperatorFeeShare, "", "Fulfiller fee part")
cmd.Flags().Int64(FlagExpiration, 0, "Expire time as Unix timestamp. Set zero (0) for no expiry. Default is 0.")
Expand Down
83 changes: 41 additions & 42 deletions x/eibc/types/authz.pb.go

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

20 changes: 9 additions & 11 deletions x/eibc/types/fulfill_order_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewFulfillOrderAuthorization(rollapps []*RollappCriteria) *FulfillOrderAuth
func NewRollappCriteria(
rollappID string,
denoms []string,
minLPFeePercentage sdk.DecProto,
minFeePercentage sdk.DecProto,
maxPrice sdk.Coins,
spendLimit sdk.Coins,
fulfillerFeePart sdk.DecProto,
Expand All @@ -28,7 +28,7 @@ func NewRollappCriteria(
return &RollappCriteria{
RollappId: rollappID,
Denoms: denoms,
MinLpFeePercentage: minLPFeePercentage,
MinFeePercentage: minFeePercentage,
MaxPrice: maxPrice,
SpendLimit: spendLimit,
OperatorFeeShare: fulfillerFeePart,
Expand Down Expand Up @@ -97,16 +97,14 @@ func (a FulfillOrderAuthorization) Accept(
errorsmod.Wrapf(errors.ErrInvalidCoins, "invalid fee amount: %s", err)
}

operatorFee := orderFeeDec.Mul(matchedCriteria.OperatorFeeShare.Dec)
amountDec := mFulfill.Price[0].Amount.Add(orderFeeDec.RoundInt()).ToLegacyDec()
minLPFee := amountDec.Mul(matchedCriteria.MinLpFeePercentage.Dec)
lpFee := orderFeeDec.Sub(operatorFee)
minFee := amountDec.Mul(matchedCriteria.MinFeePercentage.Dec)

if lpFee.LT(minLPFee) {
if orderFeeDec.LT(minFee) {
return authz.AcceptResponse{},
errorsmod.Wrapf(errors.ErrUnauthorized,
"order LP fee %s is less than minimum LP fee %s",
lpFee.String(), minLPFee.String())
"order fee %s is less than minimum fee %s",
orderFeeDec.String(), minFee.String())
}

// Check if the order price does not exceed the max price
Expand Down Expand Up @@ -186,9 +184,9 @@ func (a FulfillOrderAuthorization) ValidateBasic() error {
}
rollappIDSet[criteria.RollappId] = struct{}{}

// Validate MinLpFeePercentage
if !criteria.MinLpFeePercentage.Dec.IsNil() && criteria.MinLpFeePercentage.Dec.IsNegative() {
return errorsmod.Wrapf(errors.ErrInvalidRequest, "min_lp_fee_percentage cannot be negative for rollapp_id %s", criteria.RollappId)
// Validate MinFeePercentage
if !criteria.MinFeePercentage.Dec.IsNil() && criteria.MinFeePercentage.Dec.IsNegative() {
return errorsmod.Wrapf(errors.ErrInvalidRequest, "min_fee_percentage cannot be negative for rollapp_id %s", criteria.RollappId)
}

// Validate OperatorFeeShare
Expand Down
14 changes: 7 additions & 7 deletions x/eibc/types/fulfill_order_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestFulfillOrderAuthorization_Accept(t *testing.T) {
Denoms: []string{"atom"},
MaxPrice: sdk.NewCoins(sdk.NewInt64Coin("atom", 500)),
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 1000)),
MinLpFeePercentage: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.05")},
MinFeePercentage: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.05")},
OperatorFeeShare: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.02")},
SettlementValidated: true,
},
Expand All @@ -49,7 +49,7 @@ func TestFulfillOrderAuthorization_Accept(t *testing.T) {
Denoms: []string{"atom"},
MaxPrice: sdk.NewCoins(sdk.NewInt64Coin("atom", 500)),
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 600)),
MinLpFeePercentage: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.05")},
MinFeePercentage: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.05")},
OperatorFeeShare: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.02")},
SettlementValidated: true,
},
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestFulfillOrderAuthorization_ValidateBasic(t *testing.T) {
Denoms: []string{"atom", "btc"},
MaxPrice: sdk.NewCoins(sdk.NewInt64Coin("atom", 500)),
SpendLimit: sdk.NewCoins(sdk.NewInt64Coin("atom", 1000)),
MinLpFeePercentage: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.05")},
MinFeePercentage: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.05")},
OperatorFeeShare: sdk.DecProto{Dec: sdk.MustNewDecFromStr("0.02")},
SettlementValidated: true,
},
Expand All @@ -137,16 +137,16 @@ func TestFulfillOrderAuthorization_ValidateBasic(t *testing.T) {
expectedError: "",
},
{
name: "Negative MinLpFeePercentage",
name: "Negative MinFeePercentage",
authorization: FulfillOrderAuthorization{
Rollapps: []*RollappCriteria{
{
RollappId: "rollapp1",
MinLpFeePercentage: sdk.DecProto{Dec: sdk.MustNewDecFromStr("-0.01")},
RollappId: "rollapp1",
MinFeePercentage: sdk.DecProto{Dec: sdk.MustNewDecFromStr("-0.01")},
},
},
},
expectedError: "min_lp_fee_percentage cannot be negative for rollapp_id rollapp1",
expectedError: "min_fee_percentage cannot be negative for rollapp_id rollapp1",
},
{
name: "OperatorFeeShare Greater Than One",
Expand Down

0 comments on commit 26c485f

Please sign in to comment.