-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OTE-788] Update revshare safety #2284
Changes from 4 commits
ad7a78d
193df7c
af30e36
d29f906
12d634e
4c842a6
d1a58d0
ed5be06
5b50b2f
21bb82b
11f651d
6111a9e
f8e2a77
caa4017
434c965
059bd8d
7e9ef41
6a0051d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package keeper | ||
|
||
import ( | ||
"math" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types" | ||
) | ||
|
@@ -27,6 +30,40 @@ func (k Keeper) SetPerpetualFeeParams( | |
return err | ||
} | ||
|
||
lowestMakerFee := int32(math.MaxInt32) | ||
lowestTakerFee := int32(math.MaxInt32) | ||
for _, tier := range params.Tiers { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of duplicating logic let's create |
||
if tier.MakerFeePpm < lowestMakerFee { | ||
lowestMakerFee = tier.MakerFeePpm | ||
} | ||
if tier.TakerFeePpm < lowestTakerFee { | ||
lowestTakerFee = tier.TakerFeePpm | ||
} | ||
} | ||
affiliateTiers, err := k.affiliatesKeeper.GetAllAffiliateTiers(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
unconditionalRevShareConfig, err := k.revShareKeeper.GetUnconditionalRevShareConfigParams(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
marketMapperRevShareParams := k.revShareKeeper.GetMarketMapperRevenueShareParams(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
valid := k.revShareKeeper.ValidateRevShareSafety(ctx, affiliateTiers, unconditionalRevShareConfig, | ||
marketMapperRevShareParams, lowestTakerFee, lowestMakerFee) | ||
if !valid { | ||
return errorsmod.Wrapf( | ||
types.ErrRevShareSafetyViolation, | ||
"rev share safety violation", | ||
) | ||
} | ||
|
||
store := ctx.KVStore(k.storeKey) | ||
b := k.cdc.MustMarshal(¶ms) | ||
store.Set([]byte(types.PerpetualFeeParamsKey), b) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,18 +124,18 @@ func (k Keeper) SetUnconditionalRevShareConfigParams(ctx sdk.Context, config typ | |
store.Set([]byte(types.UnconditionalRevShareConfigKey), unconditionalRevShareConfigBytes) | ||
} | ||
|
||
// ValidateRevShareSafety roughly checks if the total rev share is valid using the formula below | ||
// highest_affiliate_taker_share * (highest_taker_fee_share_ppm / | ||
// (lowest_maker_fee_share_ppm + highest_taker_fee_share_ppm)) | ||
// ValidateRevShareSafety roughly checks if the total rev share is valid using the formula below: | ||
// highest_affiliate_taker_share * (lowest_taker_fee_ppm / | ||
// (lowest_maker_ppm + lowest_taker_fee_ppm)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document that we always expect |
||
// + sum(unconditional_rev_shares) + market_mapper_rev_share < 100% | ||
func (k Keeper) ValidateRevShareSafety( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since both
Which is actually a lot simpler 😓 Lmk if this makes sense There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense to me. Made the change! |
||
ctx sdk.Context, | ||
affiliateTiers affiliatetypes.AffiliateTiers, | ||
unconditionalRevShareConfig types.UnconditionalRevShareConfig, | ||
marketMapperRevShareParams types.MarketMapperRevenueShareParams, | ||
lowestTakerFeePpm int32, | ||
lowestMakerFeePpm int32, | ||
) bool { | ||
highestTakerFeeSharePpm := k.feetiersKeeper.GetHighestTakerFee(ctx) | ||
lowestMakerFeeSharePpm := k.feetiersKeeper.GetLowestMakerFee(ctx) | ||
highestTierRevSharePpm := uint32(0) | ||
if len(affiliateTiers.Tiers) > 0 { | ||
highestTierRevSharePpm = affiliateTiers.Tiers[len(affiliateTiers.Tiers)-1].TakerFeeSharePpm | ||
|
@@ -148,7 +148,7 @@ func (k Keeper) ValidateRevShareSafety( | |
|
||
totalRevSharePpm := totalUnconditionalRevSharePpm + totalMarketMapperRevSharePpm + | ||
uint32(math.Ceil(float64(highestTierRevSharePpm)*(float64( | ||
highestTakerFeeSharePpm)/float64(lowestMakerFeeSharePpm+highestTakerFeeSharePpm)))) | ||
lowestTakerFeePpm)/float64(lowestMakerFeePpm+lowestTakerFeePpm)))) | ||
return totalRevSharePpm < lib.OneMillion | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
Incomplete Removal of
RevShareKeeper
DetectedThe search results indicate that
RevShareKeeper
is still present in multiple areas of the codebase, including interfaces, keeper implementations, and test files. This suggests that the replacement withFeetiersKeeper
is not fully implemented.Action Items:
RevShareKeeper
are replaced withFeetiersKeeper
across the entire codebase.FeetiersKeeper
instead ofRevShareKeeper
.RevShareKeeper
are appropriately managed by the newFeetiersKeeper
.Analysis chain
New
FeetiersKeeper
interface introducedThe new
FeetiersKeeper
interface has been added, replacing the previousRevShareKeeper
. This change aligns with the PR objective of updating revenue share safety.A few points to consider:
RevShareKeeper
was used have been updated to useFeetiersKeeper
instead.RevShareKeeper
methods likeValidateRevShareSafety
suggests that the safety checks might have been moved elsewhere or implemented differently.To ensure that all usages of the old
RevShareKeeper
have been properly updated, please run the following script:This script will help identify any places where the old
RevShareKeeper
might still be in use and confirm thatFeetiersKeeper
is being used appropriately.Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 8519