-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(x/gov): limit deposited coins to accepted proposal denom #18189
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
edffa7c
feat(x/gov): limit deposited coins to accepted proposal denom
julienrbrt 39a4d9c
changelog
julienrbrt 9239dd5
error msg consistency
julienrbrt c210001
fix test
julienrbrt 601a1f2
Merge branch 'main' into julien/gov-limit-deposit
julienrbrt 11f1eaf
do not enforce non initial deposit to contain each time all coins
julienrbrt 585e0d8
Merge branch 'main' into julien/gov-limit-deposit
julienrbrt fd6ef30
add (go) doc
julienrbrt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,16 @@ func (keeper Keeper) AddDeposit(ctx context.Context, proposalID uint64, deposito | |
| return false, errors.Wrapf(types.ErrInactiveProposal, "%d", proposalID) | ||
| } | ||
|
|
||
| // Check coins to be deposited match the proposal's deposit params | ||
| params, err := keeper.Params.Get(ctx) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| if err := keeper.validateDepositDenom(ctx, params, depositAmount); err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| // update the governance module's account coins pool | ||
| err = keeper.bankKeeper.SendCoinsFromAccountToModule(ctx, depositorAddr, types.ModuleName, depositAmount) | ||
| if err != nil { | ||
|
|
@@ -84,13 +94,9 @@ func (keeper Keeper) AddDeposit(ctx context.Context, proposalID uint64, deposito | |
| } | ||
|
|
||
| // Check if deposit has provided sufficient total funds to transition the proposal into the voting period | ||
| activatedVotingPeriod := false | ||
| params, err := keeper.Params.Get(ctx) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| minDepositAmount := proposal.GetMinDepositFromParams(params) | ||
|
|
||
| activatedVotingPeriod := false | ||
| if proposal.Status == v1.StatusDepositPeriod && sdk.NewCoins(proposal.TotalDeposit...).IsAllGTE(minDepositAmount) { | ||
| err = keeper.ActivateVotingPeriod(ctx, proposal) | ||
| if err != nil { | ||
|
|
@@ -237,12 +243,7 @@ func (keeper Keeper) RefundAndDeleteDeposits(ctx context.Context, proposalID uin | |
| // validateInitialDeposit validates if initial deposit is greater than or equal to the minimum | ||
| // required at the time of proposal submission. This threshold amount is determined by | ||
| // the deposit parameters. Returns nil on success, error otherwise. | ||
| func (keeper Keeper) validateInitialDeposit(ctx context.Context, initialDeposit sdk.Coins, expedited bool) error { | ||
| params, err := keeper.Params.Get(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| func (keeper Keeper) validateInitialDeposit(ctx context.Context, params v1.Params, initialDeposit sdk.Coins, expedited bool) error { | ||
| minInitialDepositRatio, err := sdkmath.LegacyNewDecFromStr(params.MinInitialDepositRatio) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -266,3 +267,21 @@ func (keeper Keeper) validateInitialDeposit(ctx context.Context, initialDeposit | |
| } | ||
| return nil | ||
| } | ||
|
|
||
| // validateDepositDenom validates if the deposit denom is accepted by the governance module. | ||
| func (keeper Keeper) validateDepositDenom(ctx context.Context, params v1.Params, depositAmount sdk.Coins) error { | ||
| denoms := []string{} | ||
| acceptedDenoms := make(map[string]bool, len(params.MinDeposit)) | ||
| for _, coin := range params.MinDeposit { | ||
| acceptedDenoms[coin.Denom] = true | ||
| denoms = append(denoms, coin.Denom) | ||
| } | ||
|
|
||
| for _, coin := range depositAmount { | ||
|
Contributor
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. can we add a godoc and a mention in the readme about this feature. If a user sends a valid token and invalid token the tx will be rejected, etc
Contributor
Author
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. Added 👍🏾 |
||
| if _, ok := acceptedDenoms[coin.Denom]; !ok { | ||
| return errors.Wrapf(types.ErrInvalidDepositDenom, "deposited %s, but gov accepts only the following denom(s): %v", coin, denoms) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.