-
Notifications
You must be signed in to change notification settings - Fork 5
Feat/mtoken min balance #242
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
Open
kostyamospan
wants to merge
21
commits into
main
Choose a base branch
from
feat/mtoken-min-balance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2ee695e
feat: mtoken min balance contract
kostyamospan 8b90792
chore: generator scripts min balance
kostyamospan 4257ca4
fix: skills, refactor min balance contract
kostyamospan bbfe232
fix: migrated to roles based exempt list from mapping
kostyamospan 2125ba8
refactor: removed flag from _validateMinBalance
kostyamospan a54a98f
fix: upgrade tests added
kostyamospan 5bbf996
fix: removed extra gaps for upgrade safety
kostyamospan e1488bb
fix: typo
kostya-midas 98bb0ce
fix: mwin metadata and contract
kostya-midas 3af60a5
Merge remote-tracking branch 'origin/main' into feat/mtoken-min-balance
kostya-midas 4b3c772
chore: new impl deployed
kostya-midas 2a5fb21
chore: mwin aggregator upgrade propose
kostya-midas 4e52c6a
fix: propose reinitializer values
kostya-midas 198375c
fix: execute script
kostya-midas 8bd6800
fix: collect redemption fees before burning mTokens
dmytroh-dev 0452797
fix: reuse redemption helpers for min-balance flows
dmytroh-dev 0fb1ecb
fix: cover min-balance redemptions across all vaults
dmytroh-dev 8b18fc3
Merge pull request #248 from midas-apps/fix/redemption-fee-before-burn
kostya-midas d97b00a
chore: mwin mtoken rv upgrade
kostya-midas 885bc08
feat: mGLOeuro on Ethereum
dmytroh-dev 9ed3453
feat: mGLO on Optimism
dmytroh-dev 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.9; | ||
|
|
||
| import "./mToken.sol"; | ||
|
|
||
| /** | ||
| * @title mTokenMinBalance | ||
| * @notice mToken with minimum balance checks | ||
| * @author RedDuck Software | ||
| */ | ||
| //solhint-disable contract-name-camelcase | ||
| abstract contract mTokenMinBalance is mToken { | ||
| /** | ||
| * @dev leaving a storage gap for futures updates | ||
| */ | ||
| uint256[50] private __gap; | ||
|
|
||
| /** | ||
| * @dev overrides _afterTokenTransfer function to check if the recipient has a minimum balance | ||
| */ | ||
| function _afterTokenTransfer( | ||
| address from, | ||
| address to, | ||
| uint256 amount | ||
| ) internal virtual override { | ||
| if (from != address(0) && !_isMinBalanceExempt(from)) { | ||
| _validateMinBalance(from); | ||
| } | ||
|
|
||
| if (to != address(0) && !_isMinBalanceExempt(to)) { | ||
| _validateMinBalance(to); | ||
| } | ||
|
|
||
| super._afterTokenTransfer(from, to, amount); | ||
| } | ||
|
|
||
| /** | ||
| * @dev returns the role holder of which is exempt from min balance checks | ||
| */ | ||
| function _minBalanceExemptRole() internal view virtual returns (bytes32); | ||
|
|
||
| /** | ||
| * @dev checks if a user is exempt from min balance checks | ||
| * @param user address of the user | ||
| * @return bool true if the user is exempt from min balance checks | ||
| */ | ||
| function _isMinBalanceExempt(address user) private view returns (bool) { | ||
| return accessControl.hasRole(_minBalanceExemptRole(), user); | ||
| } | ||
|
|
||
| /** | ||
| * @dev validates the minimum balance of a user | ||
| * @param user address of the user | ||
| */ | ||
| function _validateMinBalance(address user) private view { | ||
| uint256 balance = balanceOf(user); | ||
| require( | ||
| balance == 0 || balance >= 1 ether, | ||
| "MTMB: min balance not met" | ||
| ); | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.9; | ||
|
|
||
| import "./mTokenPermissioned.sol"; | ||
| import "./mTokenMinBalance.sol"; | ||
|
|
||
| /** | ||
| * @title mTokenPermissionedMinBalance | ||
| * @notice mToken with permissioned transfers and minimum balance checks | ||
| * @author RedDuck Software | ||
| */ | ||
| //solhint-disable contract-name-camelcase | ||
| abstract contract mTokenPermissionedMinBalance is | ||
| mTokenMinBalance, | ||
| mTokenPermissioned | ||
| { | ||
| // no gap as we would upgrade some of the deployments | ||
| // to mTokenMinBalance | ||
|
|
||
| /** | ||
| * @dev overrides _beforeTokenTransfer function to call the parent hooks | ||
| */ | ||
| function _beforeTokenTransfer( | ||
| address from, | ||
| address to, | ||
| uint256 amount | ||
| ) internal virtual override(mTokenPermissioned, mToken) { | ||
| mTokenPermissioned._beforeTokenTransfer(from, to, amount); | ||
| } | ||
|
|
||
| /** | ||
| * @dev overrides _afterTokenTransfer function to call the parent hooks | ||
| */ | ||
| function _afterTokenTransfer( | ||
|
Comment on lines
+31
to
+34
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. |
||
| address from, | ||
| address to, | ||
| uint256 amount | ||
| ) internal virtual override(mTokenMinBalance, ERC20Upgradeable) { | ||
| mTokenMinBalance._afterTokenTransfer(from, to, amount); | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
contracts/products/mGLOeuro/MGloEuroCustomAggregatorFeed.sol
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.9; | ||
|
|
||
| import "../../feeds/CustomAggregatorV3CompatibleFeed.sol"; | ||
| import "./MGloEuroMidasAccessControlRoles.sol"; | ||
|
|
||
| /** | ||
| * @title MGloEuroCustomAggregatorFeed | ||
| * @notice AggregatorV3 compatible feed for mGLOeuro, | ||
| * where price is submitted manually by feed admins | ||
| * @author RedDuck Software | ||
| */ | ||
| contract MGloEuroCustomAggregatorFeed is | ||
| CustomAggregatorV3CompatibleFeed, | ||
| MGloEuroMidasAccessControlRoles | ||
| { | ||
| /** | ||
| * @dev leaving a storage gap for futures updates | ||
| */ | ||
| uint256[50] private __gap; | ||
|
|
||
| /** | ||
| * @inheritdoc CustomAggregatorV3CompatibleFeed | ||
| */ | ||
| function feedAdminRole() public pure override returns (bytes32) { | ||
| return M_GLO_EURO_CUSTOM_AGGREGATOR_FEED_ADMIN_ROLE; | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.9; | ||
|
|
||
| import "../../feeds/DataFeed.sol"; | ||
| import "./MGloEuroMidasAccessControlRoles.sol"; | ||
|
|
||
| /** | ||
| * @title MGloEuroDataFeed | ||
| * @notice DataFeed for mGLOeuro product | ||
| * @author RedDuck Software | ||
| */ | ||
| contract MGloEuroDataFeed is DataFeed, MGloEuroMidasAccessControlRoles { | ||
| /** | ||
| * @dev leaving a storage gap for futures updates | ||
| */ | ||
| uint256[50] private __gap; | ||
|
|
||
| /** | ||
| * @inheritdoc DataFeed | ||
| */ | ||
| function feedAdminRole() public pure override returns (bytes32) { | ||
| return M_GLO_EURO_CUSTOM_AGGREGATOR_FEED_ADMIN_ROLE; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Hardcoding "1 ether" (which is "10**18") as the minimum balance assumes that all tokens using this contract will have 18 decimals and require exactly a 1-token minimum balance. If a token has fewer decimals (e.g., 6 decimals for USDC-pegged tokens or 8 decimals for BTC-pegged tokens), "1 ether" translates to an extremely large minimum balance (e.g., "10^12" or "10^10" tokens), making the token practically unusable.
To support tokens with different decimals and allow customization of the minimum balance, consider defining a virtual function "_minBalance()" that defaults to "10 ** decimals()" (or a customizable value) and can be overridden by specific token implementations.