From 573b2f9098129b7f22fbfedee1c5712c6408682e Mon Sep 17 00:00:00 2001 From: Uriel Chami Date: Fri, 13 May 2022 11:26:24 -0300 Subject: [PATCH 1/2] Removing setERC20Metadata function and adding parameters to ERC20Initializer to be compliant --- contracts/moonstream/ERC20Initializer.sol | 6 +++--- .../moonstream/ERC20WithCommonStorage.sol | 18 ----------------- dao/core.py | 3 ++- dao/test_core.py | 1 + dao/test_moonstream.py | 20 +++++-------------- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/contracts/moonstream/ERC20Initializer.sol b/contracts/moonstream/ERC20Initializer.sol index 3c5a185..9536202 100644 --- a/contracts/moonstream/ERC20Initializer.sol +++ b/contracts/moonstream/ERC20Initializer.sol @@ -15,13 +15,13 @@ import "../diamond/libraries/LibDiamond.sol"; import "./LibERC20.sol"; contract ERC20Initializer { - function init() external { + function init(string memory name, string memory symbol) external { LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); ds.supportedInterfaces[type(IERC20).interfaceId] = true; LibERC20.ERC20Storage storage es = LibERC20.erc20Storage(); es.controller = msg.sender; - es.name = "Moonstream DAO"; - es.symbol = "MNSTR"; + es.name = name; + es.symbol = symbol; } } diff --git a/contracts/moonstream/ERC20WithCommonStorage.sol b/contracts/moonstream/ERC20WithCommonStorage.sol index ffd8a2e..f931d61 100644 --- a/contracts/moonstream/ERC20WithCommonStorage.sol +++ b/contracts/moonstream/ERC20WithCommonStorage.sol @@ -23,24 +23,6 @@ import "@openzeppelin-contracts/contracts/utils/Context.sol"; import "./LibERC20.sol"; contract ERC20WithCommonStorage is Context, IERC20, IERC20Metadata { - /** - * @dev Sets the values for {name} and {symbol}. - * - * The default value of {decimals} is 18. To select a different value for - * {decimals} you should overload it. - * - * All two of these values are immutable: they can only be set once during - * construction. - */ - function setERC20Metadata(string memory name_, string memory symbol_) - external - { - LibERC20.enforceIsController(); - LibERC20.ERC20Storage storage es = LibERC20.erc20Storage(); - es.name = name_; - es.symbol = symbol_; - } - /** * @dev Returns the name of the token. */ diff --git a/dao/core.py b/dao/core.py index 0c8ddc8..825a3ac 100644 --- a/dao/core.py +++ b/dao/core.py @@ -54,6 +54,7 @@ def facet_cut( ignore_selectors: Optional[List[str]] = None, methods: Optional[List[str]] = None, selectors: Optional[List[str]] = None, + initializer_params: Optional[List[Any]] = None, ) -> Any: """ Cuts the given facet onto the given Diamond contract. @@ -127,7 +128,7 @@ def facet_cut( if facet_name == "ERC20Facet": if initializer_address != ZERO_ADDRESS and action != "remove": erc20_initializer = ERC20Initializer.ERC20Initializer(initializer_address) - calldata = erc20_initializer.contract.init.encode_input() + calldata = erc20_initializer.contract.init.encode_input(initializer_params[0], initializer_params[1]) elif facet_name == "TerminusFacet": if initializer_address != ZERO_ADDRESS and action != "remove": terminus_initializer = TerminusInitializer.TerminusInitializer( diff --git a/dao/test_core.py b/dao/test_core.py index 0c95231..461be4a 100644 --- a/dao/test_core.py +++ b/dao/test_core.py @@ -39,6 +39,7 @@ def setUpClass(cls) -> None: "add", {"from": accounts[0]}, initializer.address, + initializer_params = ["Moonstream DAO", "MNSTR"] ) cls.erc20_initializer = initializer.address diff --git a/dao/test_moonstream.py b/dao/test_moonstream.py index fb0d6f4..ba76505 100644 --- a/dao/test_moonstream.py +++ b/dao/test_moonstream.py @@ -24,6 +24,7 @@ def test_add_and_replace(self): "add", {"from": accounts[0]}, initializer.address, + initializer_params = ["Moonstream DAO", "MNSTR"] ) diamond_erc20 = ERC20Facet.ERC20Facet(diamond_address) @@ -39,19 +40,6 @@ def test_add_and_replace(self): expected_decimals = 18 self.assertEqual(decimals, expected_decimals) - with self.assertRaises(Exception): - diamond_erc20.set_erc20_metadata("LOL", "ROFL", {"from": accounts[1]}) - - diamond_erc20.set_erc20_metadata("LOL", "ROFL", {"from": accounts[0]}) - - name = diamond_erc20.name() - expected_name = "LOL" - self.assertEqual(name, expected_name) - - symbol = diamond_erc20.symbol() - expected_symbol = "ROFL" - self.assertEqual(symbol, expected_symbol) - new_erc20_facet = ERC20Facet.ERC20Facet(None) new_erc20_facet.deploy({"from": accounts[0]}) facet_cut( @@ -61,14 +49,15 @@ def test_add_and_replace(self): "replace", {"from": accounts[0]}, initializer.address, + initializer_params = ["ROFL", "LOL"] ) name = diamond_erc20.name() - expected_name = "Moonstream DAO" + expected_name = "ROFL" self.assertEqual(name, expected_name) symbol = diamond_erc20.symbol() - expected_symbol = "MNSTR" + expected_symbol = "LOL" self.assertEqual(symbol, expected_symbol) @@ -88,6 +77,7 @@ def test_remove_facet(self): "add", {"from": accounts[0]}, initializer.address, + initializer_params = ["Moonstream DAO", "MNSTR"] ) diamond_erc20 = ERC20Facet.ERC20Facet(diamond_address) From 44793f8fc29a8631689d38efb205d35b94e58c93 Mon Sep 17 00:00:00 2001 From: Uriel Chami Date: Mon, 16 May 2022 13:52:26 -0300 Subject: [PATCH 2/2] Black formatting --- dao/core.py | 4 +++- dao/test_core.py | 2 +- dao/test_moonstream.py | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dao/core.py b/dao/core.py index 825a3ac..8c35273 100644 --- a/dao/core.py +++ b/dao/core.py @@ -128,7 +128,9 @@ def facet_cut( if facet_name == "ERC20Facet": if initializer_address != ZERO_ADDRESS and action != "remove": erc20_initializer = ERC20Initializer.ERC20Initializer(initializer_address) - calldata = erc20_initializer.contract.init.encode_input(initializer_params[0], initializer_params[1]) + calldata = erc20_initializer.contract.init.encode_input( + initializer_params[0], initializer_params[1] + ) elif facet_name == "TerminusFacet": if initializer_address != ZERO_ADDRESS and action != "remove": terminus_initializer = TerminusInitializer.TerminusInitializer( diff --git a/dao/test_core.py b/dao/test_core.py index 461be4a..7cb486c 100644 --- a/dao/test_core.py +++ b/dao/test_core.py @@ -39,7 +39,7 @@ def setUpClass(cls) -> None: "add", {"from": accounts[0]}, initializer.address, - initializer_params = ["Moonstream DAO", "MNSTR"] + initializer_params=["Moonstream DAO", "MNSTR"], ) cls.erc20_initializer = initializer.address diff --git a/dao/test_moonstream.py b/dao/test_moonstream.py index ba76505..3fa1adb 100644 --- a/dao/test_moonstream.py +++ b/dao/test_moonstream.py @@ -24,7 +24,7 @@ def test_add_and_replace(self): "add", {"from": accounts[0]}, initializer.address, - initializer_params = ["Moonstream DAO", "MNSTR"] + initializer_params=["Moonstream DAO", "MNSTR"], ) diamond_erc20 = ERC20Facet.ERC20Facet(diamond_address) @@ -49,7 +49,7 @@ def test_add_and_replace(self): "replace", {"from": accounts[0]}, initializer.address, - initializer_params = ["ROFL", "LOL"] + initializer_params=["ROFL", "LOL"], ) name = diamond_erc20.name() @@ -77,7 +77,7 @@ def test_remove_facet(self): "add", {"from": accounts[0]}, initializer.address, - initializer_params = ["Moonstream DAO", "MNSTR"] + initializer_params=["Moonstream DAO", "MNSTR"], ) diamond_erc20 = ERC20Facet.ERC20Facet(diamond_address)