-
Notifications
You must be signed in to change notification settings - Fork 343
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
feat(incentives): added fees for adding to gauge and gauge creation #1188
Changes from all commits
9c7d045
87d702c
0eb38a6
21117b4
6b03791
c28e8f1
9c43bec
380559f
0ac2b4c
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,13 +3,12 @@ package keeper | |
import ( | ||
"context" | ||
|
||
"github.com/dymensionxyz/dymension/v3/x/incentives/types" | ||
"github.com/osmosis-labs/osmosis/v15/osmoutils" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/osmosis-labs/osmosis/v15/osmoutils" | ||
|
||
"github.com/dymensionxyz/dymension/v3/x/incentives/types" | ||
) | ||
|
||
// msgServer provides a way to reference keeper pointer in the message server interface. | ||
|
@@ -35,7 +34,11 @@ func (server msgServer) CreateGauge(goCtx context.Context, msg *types.MsgCreateG | |
return nil, err | ||
} | ||
|
||
if err := server.keeper.chargeFeeIfSufficientFeeDenomBalance(ctx, owner, types.CreateGaugeFee, msg.Coins); err != nil { | ||
// Charge fess based on the number of coins to add | ||
// Fee = CreateGaugeBaseFee + AddDenomFee * NumDenoms | ||
params := server.keeper.GetParams(ctx) | ||
fee := params.CreateGaugeBaseFee.Add(params.AddDenomFee.MulRaw(int64(len(msg.Coins)))) | ||
if err = server.keeper.chargeFeeIfSufficientFeeDenomBalance(ctx, owner, fee, msg.Coins); err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -63,10 +66,20 @@ func (server msgServer) AddToGauge(goCtx context.Context, msg *types.MsgAddToGau | |
return nil, err | ||
} | ||
|
||
if err := server.keeper.chargeFeeIfSufficientFeeDenomBalance(ctx, owner, types.AddToGaugeFee, msg.Rewards); err != nil { | ||
gauge, err := server.keeper.GetGaugeByID(ctx, msg.GaugeId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Charge fess based on the number of coins to add | ||
// Fee = AddToGaugeBaseFee + AddDenomFee * (NumAddedDenoms + NumGaugeDenoms) | ||
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. Why do we need to pay for existing denoms as well? Isn't it already paid for when added initially? 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. to prevent spam where somebody keeps excessively adding funds to some already overloaded gauge 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. so this fee makes it pricey to add more and more new denoms to the gauge |
||
params := server.keeper.GetParams(ctx) | ||
fee := params.AddToGaugeBaseFee.Add(params.AddDenomFee.MulRaw(int64(len(msg.Rewards) + len(gauge.Coins)))) | ||
if err = server.keeper.chargeFeeIfSufficientFeeDenomBalance(ctx, owner, fee, msg.Rewards); err != nil { | ||
return nil, err | ||
} | ||
err = server.keeper.AddToGaugeRewards(ctx, owner, msg.Rewards, msg.GaugeId) | ||
|
||
err = server.keeper.AddToGaugeRewards(ctx, owner, msg.Rewards, gauge) | ||
if err != nil { | ||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) | ||
} | ||
|
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.
not a fan of commented code! :D
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.
it's an old state migration (v3 while current is v4), and i didn't want to modify old migration scripts, so i intentionally left this code commented here to have a historical reference. added an explanation comment for that.