From 7a4b92ca6db910bb0c6294b9d028556333a80ea5 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 27 Jul 2023 03:01:29 -0700 Subject: [PATCH 1/3] add setFeeCollector --- contracts/templates/ERC20Template3.sol | 41 ++++++++++----------- test/unit/datatokens/ERC20Template3.test.js | 27 +++----------- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/contracts/templates/ERC20Template3.sol b/contracts/templates/ERC20Template3.sol index cb4545e3..affbcc17 100644 --- a/contracts/templates/ERC20Template3.sol +++ b/contracts/templates/ERC20Template3.sol @@ -197,8 +197,7 @@ contract ERC20Template3 is address exchangeContract, address indexed baseToken ); - event NewDispenser(address dispenserContract); - + event NewPaymentCollector( address indexed caller, address indexed _newPaymentCollector, @@ -206,7 +205,6 @@ contract ERC20Template3 is uint256 blockNumber ); - modifier onlyNotInitialized() { require( !initialized, @@ -338,12 +336,6 @@ contract ERC20Template3 is initialized = true; // set payment collector to this contract, so we can get the $$$ _setPaymentCollector(address(this)); - emit NewPaymentCollector( - msg.sender, - address(this), - block.timestamp, - block.number - ); publishMarketFeeAddress = addresses_[2]; publishMarketFeeToken = addresses_[3]; publishMarketFeeAmount = uints_[1]; @@ -521,18 +513,6 @@ contract ERC20Template3 is _removeMinter(_minter); } - /** - * @dev setData - * Only ERC20Deployer (at 721 level) can call it. - * This function allows to store data with a preset key (keccak256(ERC20Address)) into NFT 725 Store - * @param _value data to be set with this key - */ - - function setData(bytes calldata _value) external onlyERC20Deployer { - bytes32 key = keccak256(abi.encodePacked(address(this))); - IERC721Template(_erc721Address).setDataERC20(key, _value); - } - /** * @dev cleanPermissions() * Only NFT Owner (at 721 level) can call it. @@ -627,8 +607,27 @@ contract ERC20Template3 is function _setPaymentCollector(address _newPaymentCollector) internal { paymentCollector = _newPaymentCollector; + emit NewPaymentCollector( + msg.sender, + paymentCollector, + block.timestamp, + block.number + ); } + /** + * @dev setFeeCollector + * Only feeManager can call it + * This function allows to set a newFeeCollector (who will get FRE fees, slashes stakes, revenue per epoch if no predictoors) + * @param _newFeeCollector new fee collector + */ + + function setFeeCollector(address _newFeeCollector) external onlyERC20Deployer{ + feeCollector = _newFeeCollector; + } + + + /** * @dev getPublishingMarketFee * Get publishingMarket Fee diff --git a/test/unit/datatokens/ERC20Template3.test.js b/test/unit/datatokens/ERC20Template3.test.js index b60bebd7..e7b6fb13 100644 --- a/test/unit/datatokens/ERC20Template3.test.js +++ b/test/unit/datatokens/ERC20Template3.test.js @@ -353,27 +353,6 @@ describe("ERC20Template3", () => { assert(address, "Not able to get the parent ERC721 address") }); - it("#setData - should fail to setData if NOT erc20Deployer", async () => { - const key = web3.utils.keccak256(erc20Token.address); - const value = web3.utils.asciiToHex("SomeData"); - - await expectRevert( - erc20Token.connect(user2).setData(value), - "ERC20Template: NOT DEPLOYER ROLE" - ); - - assert((await tokenERC721.getData(key)) == "0x"); - }); - - it("#setData - should succeed to setData if erc20Deployer", async () => { - const key = web3.utils.keccak256(erc20Token.address); - const value = web3.utils.asciiToHex("SomeData"); - - await erc20Token.connect(user3).setData(value); - - assert((await tokenERC721.getData(key)) == value); - }); - it("#cleanPermissions - should fail to call cleanPermissions if NOT NFTOwner", async () => { await expectRevert( erc20Token.connect(user2).cleanPermissions(), @@ -749,6 +728,12 @@ describe("ERC20Template3", () => { assert(publishFee[1] = erc20Token.address) assert(publishFee[2] = web3.utils.toWei('10')) }); + it("#setFeeCollector - user should not be able to set new fee collector", async () => { + await expectRevert( + erc20TokenWithPublishFee.connect(user2).setFeeCollector(user2.address), + "ERC20Template: NOT DEPLOYER ROLE" + ); + }); it("#getId - should return templateId", async () => { const templateId = 3; assert((await erc20Token.getId()) == templateId); From beb6d1a8a5431f5dae5a6c058b26420435daeaf9 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 27 Jul 2023 03:04:54 -0700 Subject: [PATCH 2/3] fix lint --- contracts/templates/ERC20Template3.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/templates/ERC20Template3.sol b/contracts/templates/ERC20Template3.sol index affbcc17..a9ac6623 100644 --- a/contracts/templates/ERC20Template3.sol +++ b/contracts/templates/ERC20Template3.sol @@ -618,7 +618,8 @@ contract ERC20Template3 is /** * @dev setFeeCollector * Only feeManager can call it - * This function allows to set a newFeeCollector (who will get FRE fees, slashes stakes, revenue per epoch if no predictoors) + * This function allows to set a newFeeCollector + * (will get FRE fees, slashes stakes, revenue per epoch if no predictoors) * @param _newFeeCollector new fee collector */ From a0ccf2b33d58d11ddcaf1d329971610a2782ca5f Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 27 Jul 2023 03:21:07 -0700 Subject: [PATCH 3/3] add zero address check --- contracts/templates/ERC20Template3.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/templates/ERC20Template3.sol b/contracts/templates/ERC20Template3.sol index a9ac6623..1aa47b8c 100644 --- a/contracts/templates/ERC20Template3.sol +++ b/contracts/templates/ERC20Template3.sol @@ -624,7 +624,9 @@ contract ERC20Template3 is */ function setFeeCollector(address _newFeeCollector) external onlyERC20Deployer{ + require(_newFeeCollector!=address(0)); feeCollector = _newFeeCollector; + }