-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/permissioned mtoken #194
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
Changes from 3 commits
ad83b33
b1a33f8
c83008b
ff4d994
de62546
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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.9; | ||
|
|
||
| import "./mToken.sol"; | ||
|
|
||
| /** | ||
| * @title mTokenPermissioned | ||
| * @notice mToken with fully permissioned transfers | ||
| * @author RedDuck Software | ||
| */ | ||
| //solhint-disable contract-name-camelcase | ||
| abstract contract mTokenPermissioned is mToken { | ||
| /** | ||
| * @dev leaving a storage gap for futures updates | ||
| */ | ||
| uint256[50] private __gap; | ||
|
|
||
| /** | ||
| * @dev overrides _beforeTokenTransfer function to allow | ||
| * greenlisted users to use the token transfers functions | ||
| */ | ||
| function _beforeTokenTransfer( | ||
| address from, | ||
| address to, | ||
| uint256 amount | ||
| ) internal virtual override(mToken) { | ||
| if (to != address(0)) { | ||
| if (from != address(0)) { | ||
| _onlyGreenlisted(from); | ||
| } | ||
| _onlyGreenlisted(to); | ||
| } | ||
|
|
||
| mToken._beforeTokenTransfer(from, to, amount); | ||
| } | ||
|
|
||
| /** | ||
| * @notice AC role of a greenlist | ||
| * @return role bytes32 role | ||
| */ | ||
| function _greenlistedRole() internal pure virtual returns (bytes32); | ||
|
|
||
| /** | ||
| * @dev checks that a given `account` | ||
| * have `greenlistedRole()` | ||
| */ | ||
| function _onlyGreenlisted(address account) | ||
| private | ||
| view | ||
| onlyRole(_greenlistedRole(), account) | ||
| {} | ||
kostyamospan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.9; | ||
|
|
||
| import "../mTokenPermissioned.sol"; | ||
|
|
||
| //solhint-disable contract-name-camelcase | ||
| contract mTokenPermissionedTest is mTokenPermissioned { | ||
| bytes32 public constant M_TOKEN_TEST_MINT_OPERATOR_ROLE = | ||
| keccak256("M_TOKEN_TEST_MINT_OPERATOR_ROLE"); | ||
|
|
||
| bytes32 public constant M_TOKEN_TEST_BURN_OPERATOR_ROLE = | ||
| keccak256("M_TOKEN_TEST_BURN_OPERATOR_ROLE"); | ||
|
|
||
| bytes32 public constant M_TOKEN_TEST_PAUSE_OPERATOR_ROLE = | ||
| keccak256("M_TOKEN_TEST_PAUSE_OPERATOR_ROLE"); | ||
|
|
||
| bytes32 public constant M_TOKEN_TEST_GREENLISTED_ROLE = | ||
| keccak256("M_TOKEN_TEST_GREENLISTED_ROLE"); | ||
|
|
||
| function _disableInitializers() internal override {} | ||
|
|
||
| function _getNameSymbol() | ||
| internal | ||
| pure | ||
| override | ||
| returns (string memory, string memory) | ||
| { | ||
| return ("mTokenPermissionedTest", "mTokenPermissionedTest"); | ||
| } | ||
|
|
||
| function _minterRole() internal pure override returns (bytes32) { | ||
| return M_TOKEN_TEST_MINT_OPERATOR_ROLE; | ||
| } | ||
|
|
||
| function _burnerRole() internal pure override returns (bytes32) { | ||
| return M_TOKEN_TEST_BURN_OPERATOR_ROLE; | ||
| } | ||
|
|
||
| function _pauserRole() internal pure override returns (bytes32) { | ||
| return M_TOKEN_TEST_PAUSE_OPERATOR_ROLE; | ||
| } | ||
|
|
||
| function _greenlistedRole() internal pure override returns (bytes32) { | ||
| return M_TOKEN_TEST_GREENLISTED_ROLE; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,11 @@ | ||||||||||||
| import { MTokenName } from '../../../../../config'; | ||||||||||||
| import { importWithoutCache } from '../../../../../helpers/utils'; | ||||||||||||
|
|
||||||||||||
| export const getTokenContractFromTemplate = async (mToken: MTokenName) => { | ||||||||||||
| export const getTokenContractFromTemplate = async ( | ||||||||||||
| mToken: MTokenName, | ||||||||||||
| optionalParams?: Record<string, unknown>, | ||||||||||||
| ) => { | ||||||||||||
| const { isPermissionedMToken = false } = optionalParams || {}; | ||||||||||||
| const { getTokenContractNames } = await importWithoutCache( | ||||||||||||
| require.resolve('../../../../../helpers/contracts'), | ||||||||||||
| ); | ||||||||||||
|
|
@@ -25,14 +29,17 @@ export const getTokenContractFromTemplate = async (mToken: MTokenName) => { | |||||||||||
| // SPDX-License-Identifier: MIT | ||||||||||||
| pragma solidity 0.8.9; | ||||||||||||
|
|
||||||||||||
| import "../../mToken.sol"; | ||||||||||||
| import "../../mToken${isPermissionedMToken ? 'Permissioned' : ''}.sol"; | ||||||||||||
| ${isPermissionedMToken ? `import "./${contractNames.roles}.sol";` : ''} | ||||||||||||
|
Comment on lines
+32
to
+33
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. When
Suggested change
|
||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @title ${contractNames.token} | ||||||||||||
| * @author RedDuck Software | ||||||||||||
| */ | ||||||||||||
| //solhint-disable contract-name-camelcase | ||||||||||||
| contract ${contractNames.token} is mToken { | ||||||||||||
| contract ${contractNames.token} is mToken${ | ||||||||||||
| isPermissionedMToken ? `Permissioned, ${contractNames.roles}` : '' | ||||||||||||
| } { | ||||||||||||
|
Comment on lines
+40
to
+42
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. The template uses a ternary operator to conditionally extend the contract with
Suggested change
|
||||||||||||
| /** | ||||||||||||
| * @notice actor that can mint ${contractNames.token} | ||||||||||||
| */ | ||||||||||||
|
|
@@ -88,6 +95,18 @@ export const getTokenContractFromTemplate = async (mToken: MTokenName) => { | |||||||||||
| function _pauserRole() internal pure override returns (bytes32) { | ||||||||||||
| return ${roles.pauser}; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| ${ | ||||||||||||
| isPermissionedMToken | ||||||||||||
| ? ` | ||||||||||||
| /** | ||||||||||||
| * @inheritdoc mTokenPermissioned | ||||||||||||
| */ | ||||||||||||
| function _greenlistedRole() internal pure override returns (bytes32) { | ||||||||||||
| return ${roles.greenlisted}; | ||||||||||||
| }` | ||||||||||||
| : '' | ||||||||||||
| } | ||||||||||||
| }`, | ||||||||||||
| }; | ||||||||||||
| }; | ||||||||||||
Uh oh!
There was an error while loading. Please reload this page.