-
Notifications
You must be signed in to change notification settings - Fork 115
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-816] Update Revshare logic for affiliates #2298
Changes from all commits
809a0ce
b8d0f0d
5c2fa13
2060d21
3f21cf6
f162535
71e434a
ab729a3
5fcdffa
e69bbb7
962942e
75b30fc
53b26b2
e98790b
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 | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,6 @@ package keeper | |||||
import ( | ||||||
"math/big" | ||||||
|
||||||
errorsmod "cosmossdk.io/errors" | ||||||
"cosmossdk.io/store/prefix" | ||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||
"github.com/dydxprotocol/v4-chain/protocol/lib" | ||||||
|
@@ -163,25 +162,28 @@ func (k Keeper) GetAllRevShares( | |||||
feeSourceToRevSharePpm := make(map[types.RevShareFeeSource]uint32) | ||||||
feeSourceToQuoteQuantums[types.REV_SHARE_FEE_SOURCE_TAKER_FEE] = big.NewInt(0) | ||||||
feeSourceToRevSharePpm[types.REV_SHARE_FEE_SOURCE_TAKER_FEE] = 0 | ||||||
feeSourceToQuoteQuantums[types.REV_SHARE_FEE_SOURCE_NET_FEE] = big.NewInt(0) | ||||||
feeSourceToRevSharePpm[types.REV_SHARE_FEE_SOURCE_NET_FEE] = 0 | ||||||
feeSourceToQuoteQuantums[types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE] = big.NewInt(0) | ||||||
feeSourceToRevSharePpm[types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE] = 0 | ||||||
|
||||||
totalFeesShared := big.NewInt(0) | ||||||
takerFees := fill.TakerFeeQuoteQuantums | ||||||
makerFees := fill.MakerFeeQuoteQuantums | ||||||
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. Let's also change
|
||||||
netFees := big.NewInt(0).Add(takerFees, makerFees) | ||||||
|
||||||
affiliateRevShares, err := k.getAffiliateRevShares(ctx, fill, affiliatesWhitelistMap) | ||||||
affiliateRevShares, affiliateFeesShared, err := k.getAffiliateRevShares(ctx, fill, affiliatesWhitelistMap) | ||||||
if err != nil { | ||||||
return types.RevSharesForFill{}, err | ||||||
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. Comment on caller function Instead propagating error returned from Order matching + rev share both working > Only order matching working > Order matching not working 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. sounds good. I'll add some error logs to catch in case it fails 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. Did we do this in this PR? Or plan to do in another one? 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 is done in the PR . Check here. Also updated tests in revshare_test.go 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. Oh, the original comment was suggesting that we keep Changing We should either:
The first seems slightly cleaner to me since we just need one error log instead of multiple |
||||||
} | ||||||
netFeesSubAffiliateFeesShared := new(big.Int).Sub(netFees, affiliateFeesShared) | ||||||
if netFeesSubAffiliateFeesShared.Sign() <= 0 { | ||||||
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. Nit: move to immediately below line 129 |
||||||
return types.RevSharesForFill{}, types.ErrAffiliateFeesSharedExceedsNetFees | ||||||
} | ||||||
|
||||||
unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFees) | ||||||
unconditionalRevShares, err := k.getUnconditionalRevShares(ctx, netFeesSubAffiliateFeesShared) | ||||||
teddyding marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if err != nil { | ||||||
return types.RevSharesForFill{}, err | ||||||
} | ||||||
|
||||||
marketMapperRevShares, err := k.getMarketMapperRevShare(ctx, fill.MarketId, netFees) | ||||||
marketMapperRevShares, err := k.getMarketMapperRevShare(ctx, fill.MarketId, netFeesSubAffiliateFeesShared) | ||||||
if err != nil { | ||||||
return types.RevSharesForFill{}, err | ||||||
} | ||||||
|
@@ -208,8 +210,7 @@ func (k Keeper) GetAllRevShares( | |||||
} | ||||||
//check total fees shared is less than or equal to net fees | ||||||
if totalFeesShared.Cmp(netFees) > 0 { | ||||||
return types.RevSharesForFill{}, errorsmod.Wrap( | ||||||
types.ErrTotalFeesSharedExceedsNetFees, "total fees shared exceeds net fees") | ||||||
return types.RevSharesForFill{}, types.ErrTotalFeesSharedExceedsNetFees | ||||||
} | ||||||
|
||||||
return types.RevSharesForFill{ | ||||||
|
@@ -224,20 +225,20 @@ func (k Keeper) getAffiliateRevShares( | |||||
ctx sdk.Context, | ||||||
fill clobtypes.FillForProcess, | ||||||
affiliatesWhitelistMap map[string]uint32, | ||||||
) ([]types.RevShare, error) { | ||||||
) ([]types.RevShare, *big.Int, error) { | ||||||
takerAddr := fill.TakerAddr | ||||||
takerFee := fill.TakerFeeQuoteQuantums | ||||||
if fill.MonthlyRollingTakerVolumeQuantums >= types.MaxReferee30dVolumeForAffiliateShareQuantums { | ||||||
return nil, nil | ||||||
return nil, big.NewInt(0), nil | ||||||
} | ||||||
|
||||||
takerAffiliateAddr, feeSharePpm, exists, err := k.affiliatesKeeper.GetTakerFeeShare( | ||||||
ctx, takerAddr, affiliatesWhitelistMap) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
return nil, big.NewInt(0), err | ||||||
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. Return In the error case at line 237, consider returning Apply this diff to adjust the return value: -return nil, big.NewInt(0), err
+return nil, nil, err Committable suggestion
Suggested change
|
||||||
} | ||||||
if !exists { | ||||||
return nil, nil | ||||||
return nil, big.NewInt(0), nil | ||||||
} | ||||||
feesShared := lib.BigMulPpm(takerFee, lib.BigU(feeSharePpm), false) | ||||||
return []types.RevShare{ | ||||||
|
@@ -248,23 +249,23 @@ func (k Keeper) getAffiliateRevShares( | |||||
QuoteQuantums: feesShared, | ||||||
RevSharePpm: feeSharePpm, | ||||||
}, | ||||||
}, nil | ||||||
}, feesShared, nil | ||||||
} | ||||||
|
||||||
func (k Keeper) getUnconditionalRevShares( | ||||||
ctx sdk.Context, | ||||||
netFees *big.Int, | ||||||
netFeesSubAffiliateFeesShared *big.Int, | ||||||
) ([]types.RevShare, error) { | ||||||
revShares := []types.RevShare{} | ||||||
unconditionalRevShareConfig, err := k.GetUnconditionalRevShareConfigParams(ctx) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
for _, revShare := range unconditionalRevShareConfig.Configs { | ||||||
feeShared := lib.BigMulPpm(netFees, lib.BigU(revShare.SharePpm), false) | ||||||
feeShared := lib.BigMulPpm(netFeesSubAffiliateFeesShared, lib.BigU(revShare.SharePpm), false) | ||||||
revShare := types.RevShare{ | ||||||
Recipient: revShare.Address, | ||||||
RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, | ||||||
RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, | ||||||
RevShareType: types.REV_SHARE_TYPE_UNCONDITIONAL, | ||||||
QuoteQuantums: feeShared, | ||||||
RevSharePpm: revShare.SharePpm, | ||||||
|
@@ -277,7 +278,7 @@ func (k Keeper) getUnconditionalRevShares( | |||||
func (k Keeper) getMarketMapperRevShare( | ||||||
ctx sdk.Context, | ||||||
marketId uint32, | ||||||
netFees *big.Int, | ||||||
netFeesSubAffiliateFeesShared *big.Int, | ||||||
) ([]types.RevShare, error) { | ||||||
revShares := []types.RevShare{} | ||||||
marketMapperRevshareAddress, revenueSharePpm, err := k.GetMarketMapperRevenueShareForMarket(ctx, marketId) | ||||||
|
@@ -288,10 +289,10 @@ func (k Keeper) getMarketMapperRevShare( | |||||
return nil, nil | ||||||
} | ||||||
|
||||||
marketMapperRevshareAmount := lib.BigMulPpm(netFees, lib.BigU(revenueSharePpm), false) | ||||||
marketMapperRevshareAmount := lib.BigMulPpm(netFeesSubAffiliateFeesShared, lib.BigU(revenueSharePpm), false) | ||||||
revShares = append(revShares, types.RevShare{ | ||||||
Recipient: marketMapperRevshareAddress.String(), | ||||||
RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_FEE, | ||||||
RevShareFeeSource: types.REV_SHARE_FEE_SOURCE_NET_PROTOCOL_REVENUE, | ||||||
RevShareType: types.REV_SHARE_TYPE_MARKET_MAPPER, | ||||||
QuoteQuantums: marketMapperRevshareAmount, | ||||||
RevSharePpm: revenueSharePpm, | ||||||
|
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.
Consider revising the error handling strategy for
GetAllRevShares
The addition of error handling for
GetAllRevShares
is a good practice. However, the current implementation might mask potential issues:revSharesForFill
struct when an error occurs.Consider the following suggestions:
revSharesForFill
is appropriate in all scenarios.Here's a potential alternative implementation:
This approach would propagate the error, allowing the caller to decide how to handle it.