diff --git a/contracts/CMTAT.sol b/contracts/CMTAT.sol index f0f3da57..e77d0857 100644 --- a/contracts/CMTAT.sol +++ b/contracts/CMTAT.sol @@ -34,14 +34,8 @@ contract CMTAT is string constant TEXT_TRANSFER_OK = "No restriction"; constructor( - address owner, - address forwarder, - string memory name, - string memory symbol, - string memory tokenId, - string memory terms + address forwarder ) MetaTxModule(forwarder) { - __CMTAT_init(owner, name, symbol, tokenId, terms); } function initialize( @@ -66,7 +60,7 @@ contract CMTAT is string memory symbol, string memory tokenId, string memory terms - ) internal initializer { + ) internal onlyInitializing { __Context_init_unchained(); __Base_init_unchained(0, tokenId, terms); __AccessControl_init_unchained(); @@ -77,7 +71,7 @@ contract CMTAT is __CMTAT_init_unchained(owner); } - function __CMTAT_init_unchained(address owner) internal initializer { + function __CMTAT_init_unchained(address owner) internal onlyInitializing { _setupRole(DEFAULT_ADMIN_ROLE, owner); _setupRole(ENFORCER_ROLE, owner); _setupRole(MINTER_ROLE, owner); diff --git a/contracts/modules/BaseModule.sol b/contracts/modules/BaseModule.sol index 007e2a02..ae449ba9 100644 --- a/contracts/modules/BaseModule.sol +++ b/contracts/modules/BaseModule.sol @@ -28,7 +28,7 @@ abstract contract BaseModule is Initializable, ERC20Upgradeable { uint8 decimals_, string memory tokenId_, string memory terms_ - ) internal initializer { + ) internal onlyInitializing { __ERC20_init(name_, symbol_); _decimals = decimals_; tokenId = tokenId_; @@ -39,7 +39,7 @@ abstract contract BaseModule is Initializable, ERC20Upgradeable { uint8 decimals_, string memory tokenId_, string memory terms_ - ) internal initializer { + ) internal onlyInitializing { _decimals = decimals_; tokenId = tokenId_; terms = terms_; diff --git a/contracts/modules/EnforcementModule.sol b/contracts/modules/EnforcementModule.sol index 0d317130..004cbbfc 100644 --- a/contracts/modules/EnforcementModule.sol +++ b/contracts/modules/EnforcementModule.sol @@ -36,12 +36,12 @@ abstract contract EnforcementModule is /** * @dev Initializes the contract in unpaused state. */ - function __Enforcement_init() internal initializer { + function __Enforcement_init() internal onlyInitializing { __Context_init_unchained(); __Enforcement_init_unchained(); } - function __Enforcement_init_unchained() internal initializer {} + function __Enforcement_init_unchained() internal onlyInitializing {} /** * @dev Returns true if the contract is paused, and false otherwise. diff --git a/contracts/modules/SnapshotModule.sol b/contracts/modules/SnapshotModule.sol index 9849d671..5e6ec54d 100644 --- a/contracts/modules/SnapshotModule.sol +++ b/contracts/modules/SnapshotModule.sol @@ -36,12 +36,12 @@ abstract contract SnapshotModule is uint256[] private _scheduledSnapshots; - function __Snapshot_init() internal initializer { + function __Snapshot_init() internal onlyInitializing { __Context_init_unchained(); __Snapshot_init_unchained(); } - function __Snapshot_init_unchained() internal initializer {} + function __Snapshot_init_unchained() internal onlyInitializing{} function _scheduleSnapshot(uint256 time) internal returns (uint256) { require(block.timestamp < time, "Snapshot scheduled in the past"); diff --git a/contracts/modules/ValidationModule.sol b/contracts/modules/ValidationModule.sol index 3e3d3b2e..b0f87ad9 100644 --- a/contracts/modules/ValidationModule.sol +++ b/contracts/modules/ValidationModule.sol @@ -22,14 +22,14 @@ abstract contract ValidationModule is Initializable, ContextUpgradeable { /** * @dev Initializes the contract with rule engine. */ - function __Validation_init(IRuleEngine ruleEngine_) internal initializer { + function __Validation_init(IRuleEngine ruleEngine_) internal onlyInitializing { __Context_init_unchained(); __Validation_init_unchained(ruleEngine_); } function __Validation_init_unchained(IRuleEngine ruleEngine_) internal - initializer + onlyInitializing { if (address(ruleEngine_) != address(0)) { ruleEngine = ruleEngine_; diff --git a/package-lock.json b/package-lock.json index cb6df918..19676202 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5613,7 +5613,8 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/@types/lru-cache/-/lru-cache-5.1.1.tgz", "integrity": "sha512-ssE3Vlrys7sdIzs5LOxCzTVMsU7i9oa/IaW92wF32JFb3CVczqOkru2xspuKczHEbG3nvmPY7IFqVmGGHdNbYw==", - "dev": true + "dev": true, + "peer": true }, "node_modules/@types/mime": { "version": "3.0.1", @@ -8531,6 +8532,7 @@ "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.4.1.tgz", "integrity": "sha512-r4eRSeStEGf6M5SKdrQhhLK5bOwOBxQhIE3YSTnZE3GpKiLfnnhE+tPtrJE79+eDJgm39BM6LSoI8SCx4HbwlQ==", "dev": true, + "optional": true, "engines": { "node": ">=6" } @@ -12442,7 +12444,8 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.3.0.tgz", "integrity": "sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==", - "dev": true + "dev": true, + "optional": true }, "node_modules/immutable": { "version": "4.1.0", @@ -13553,6 +13556,7 @@ "integrity": "sha512-iB8O/7Db9lPaITU1aA2txU/cBEXAt4vWwKQRrrWuS6XDgbP4QZGj9BL2aNbwb002atoQ/lIotJkfyzz+ygQnUQ==", "dev": true, "hasInstallScript": true, + "optional": true, "dependencies": { "abstract-leveldown": "~6.2.1", "napi-macros": "~2.0.0", @@ -13567,6 +13571,7 @@ "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.3.tgz", "integrity": "sha512-BsLm5vFMRUrrLeCcRc+G0t2qOaTzpoJQLOubq2XM72eNpjF5UdU5o/5NvlNhx95XHcAvcl8OMXr4mlg/fRgUXQ==", "dev": true, + "optional": true, "dependencies": { "buffer": "^5.5.0", "immediate": "^3.2.3", @@ -13583,6 +13588,7 @@ "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-2.0.1.tgz", "integrity": "sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw==", "dev": true, + "optional": true, "engines": { "node": ">=6" } @@ -13592,6 +13598,7 @@ "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-1.0.1.tgz", "integrity": "sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==", "dev": true, + "optional": true, "dependencies": { "xtend": "^4.0.2" }, @@ -13604,6 +13611,7 @@ "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz", "integrity": "sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ==", "dev": true, + "optional": true, "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", @@ -26863,7 +26871,8 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/@types/lru-cache/-/lru-cache-5.1.1.tgz", "integrity": "sha512-ssE3Vlrys7sdIzs5LOxCzTVMsU7i9oa/IaW92wF32JFb3CVczqOkru2xspuKczHEbG3nvmPY7IFqVmGGHdNbYw==", - "dev": true + "dev": true, + "peer": true }, "@types/mime": { "version": "3.0.1", @@ -29209,7 +29218,8 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.4.1.tgz", "integrity": "sha512-r4eRSeStEGf6M5SKdrQhhLK5bOwOBxQhIE3YSTnZE3GpKiLfnnhE+tPtrJE79+eDJgm39BM6LSoI8SCx4HbwlQ==", - "dev": true + "dev": true, + "optional": true }, "emoji-regex": { "version": "10.2.1", @@ -32232,7 +32242,8 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.3.0.tgz", "integrity": "sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==", - "dev": true + "dev": true, + "optional": true }, "immutable": { "version": "4.1.0", @@ -33074,6 +33085,7 @@ "resolved": "https://registry.npmjs.org/leveldown/-/leveldown-5.6.0.tgz", "integrity": "sha512-iB8O/7Db9lPaITU1aA2txU/cBEXAt4vWwKQRrrWuS6XDgbP4QZGj9BL2aNbwb002atoQ/lIotJkfyzz+ygQnUQ==", "dev": true, + "optional": true, "requires": { "abstract-leveldown": "~6.2.1", "napi-macros": "~2.0.0", @@ -33085,6 +33097,7 @@ "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.3.tgz", "integrity": "sha512-BsLm5vFMRUrrLeCcRc+G0t2qOaTzpoJQLOubq2XM72eNpjF5UdU5o/5NvlNhx95XHcAvcl8OMXr4mlg/fRgUXQ==", "dev": true, + "optional": true, "requires": { "buffer": "^5.5.0", "immediate": "^3.2.3", @@ -33097,13 +33110,15 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-2.0.1.tgz", "integrity": "sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw==", - "dev": true + "dev": true, + "optional": true }, "level-supports": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-1.0.1.tgz", "integrity": "sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==", "dev": true, + "optional": true, "requires": { "xtend": "^4.0.2" } @@ -33112,7 +33127,8 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz", "integrity": "sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ==", - "dev": true + "dev": true, + "optional": true } } }, diff --git a/test/modules/AuthorizationModule.test.js b/test/modules/AuthorizationModule.test.js index 2e0b7d2a..fcb93369 100644 --- a/test/modules/AuthorizationModule.test.js +++ b/test/modules/AuthorizationModule.test.js @@ -9,7 +9,8 @@ contract( 'AuthorizationModule', function ([_, owner, address1, address2, address3, fakeRuleEngine]) { beforeEach(async function () { - this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + this.cmtat = await CMTAT.new(_, { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Authorization', function () { diff --git a/test/modules/BaseModule.test.js b/test/modules/BaseModule.test.js index ebe7bddd..b4b2dd7c 100644 --- a/test/modules/BaseModule.test.js +++ b/test/modules/BaseModule.test.js @@ -8,7 +8,8 @@ contract( 'BaseModule', function ([_, owner, address1, address2, address3, fakeRuleEngine]) { beforeEach(async function () { - this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + this.cmtat = await CMTAT.new(_, { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Token structure', function () { diff --git a/test/modules/BurnModule.test.js b/test/modules/BurnModule.test.js index 0ac44a72..ba68f3f8 100644 --- a/test/modules/BurnModule.test.js +++ b/test/modules/BurnModule.test.js @@ -8,7 +8,8 @@ contract( 'BurnModule', function ([_, owner, address1, address2, address3, fakeRuleEngine]) { beforeEach(async function () { - this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + this.cmtat = await CMTAT.new(_, { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Burn', function () { diff --git a/test/modules/EnforcementModule.test.js b/test/modules/EnforcementModule.test.js index 0ea1ee72..a05e4d2d 100644 --- a/test/modules/EnforcementModule.test.js +++ b/test/modules/EnforcementModule.test.js @@ -8,7 +8,8 @@ contract( 'EnforcementModule', function ([_, owner, address1, address2, address3, fakeRuleEngine]) { beforeEach(async function () { - this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + this.cmtat = await CMTAT.new(_, { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Freeze', function () { diff --git a/test/modules/MetaTxModule.test.js b/test/modules/MetaTxModule.test.js index a4064b3b..c24a5b85 100644 --- a/test/modules/MetaTxModule.test.js +++ b/test/modules/MetaTxModule.test.js @@ -28,8 +28,9 @@ contract( ]) { beforeEach(async function () { this.trustedForwarder = await MinimalForwarderMock.new() + this.cmtat = await CMTAT.new(this.trustedForwarder.address, { from: owner }) this.trustedForwarder.initialize() - this.cmtat = await CMTAT.new(owner, this.trustedForwarder.address, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Transferring without paying gas', function () { diff --git a/test/modules/MintModule.test.js b/test/modules/MintModule.test.js index a6fa75df..271eb3f1 100644 --- a/test/modules/MintModule.test.js +++ b/test/modules/MintModule.test.js @@ -8,7 +8,8 @@ contract( 'MintModule', function ([_, owner, address1, address2, address3, fakeRuleEngine]) { beforeEach(async function () { - this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + this.cmtat = await CMTAT.new(_, { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Minting', function () { diff --git a/test/modules/PauseModule.test.js b/test/modules/PauseModule.test.js index 3e188926..c02e5b12 100644 --- a/test/modules/PauseModule.test.js +++ b/test/modules/PauseModule.test.js @@ -6,7 +6,8 @@ const CMTAT = artifacts.require('CMTAT') contract('PauseModule', function ([_, owner, address1, address2, address3]) { beforeEach(async function () { - this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + this.cmtat = await CMTAT.new(_, { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Pause', function () { diff --git a/test/modules/SnapshotModule.test.js b/test/modules/SnapshotModule.test.js index 06c589bd..bf98ce87 100644 --- a/test/modules/SnapshotModule.test.js +++ b/test/modules/SnapshotModule.test.js @@ -15,7 +15,8 @@ contract( 'SnapshotModule', function ([_, owner, address1, address2, address3, fakeRuleEngine]) { beforeEach(async function () { - this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + this.cmtat = await CMTAT.new(_, { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Snapshot scheduling', function () { diff --git a/test/modules/ValidationModule.test.js b/test/modules/ValidationModule.test.js index f9595cff..c87cd3c4 100644 --- a/test/modules/ValidationModule.test.js +++ b/test/modules/ValidationModule.test.js @@ -9,7 +9,8 @@ contract( 'ValidationModule', function ([_, owner, address1, address2, address3, fakeRuleEngine]) { beforeEach(async function () { - this.cmtat = await CMTAT.new(owner, _, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) + this.cmtat = await CMTAT.new(_, { from: owner }) + await this.cmtat.initialize(owner, 'CMTA Token', 'CMTAT', 'CMTAT_ISIN', 'https://cmta.ch', { from: owner }) }) context('Rule Engine', function () {