Skip to content
This repository was archived by the owner on Aug 21, 2023. It is now read-only.

Commit d6e089d

Browse files
authored
Merge pull request #45 from uchami-lg/set-erc20-metadata-on-initialize
Removing setERC20Metadata function and adding it to Initializer
2 parents f13d8d6 + 44793f8 commit d6e089d

5 files changed

Lines changed: 13 additions & 37 deletions

File tree

contracts/moonstream/ERC20Initializer.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import "../diamond/libraries/LibDiamond.sol";
1515
import "./LibERC20.sol";
1616

1717
contract ERC20Initializer {
18-
function init() external {
18+
function init(string memory name, string memory symbol) external {
1919
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
2020
ds.supportedInterfaces[type(IERC20).interfaceId] = true;
2121

2222
LibERC20.ERC20Storage storage es = LibERC20.erc20Storage();
2323
es.controller = msg.sender;
24-
es.name = "Moonstream DAO";
25-
es.symbol = "MNSTR";
24+
es.name = name;
25+
es.symbol = symbol;
2626
}
2727
}

contracts/moonstream/ERC20WithCommonStorage.sol

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,6 @@ import "@openzeppelin-contracts/contracts/utils/Context.sol";
2323
import "./LibERC20.sol";
2424

2525
contract ERC20WithCommonStorage is Context, IERC20, IERC20Metadata {
26-
/**
27-
* @dev Sets the values for {name} and {symbol}.
28-
*
29-
* The default value of {decimals} is 18. To select a different value for
30-
* {decimals} you should overload it.
31-
*
32-
* All two of these values are immutable: they can only be set once during
33-
* construction.
34-
*/
35-
function setERC20Metadata(string memory name_, string memory symbol_)
36-
external
37-
{
38-
LibERC20.enforceIsController();
39-
LibERC20.ERC20Storage storage es = LibERC20.erc20Storage();
40-
es.name = name_;
41-
es.symbol = symbol_;
42-
}
43-
4426
/**
4527
* @dev Returns the name of the token.
4628
*/

dao/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def facet_cut(
5454
ignore_selectors: Optional[List[str]] = None,
5555
methods: Optional[List[str]] = None,
5656
selectors: Optional[List[str]] = None,
57+
initializer_params: Optional[List[Any]] = None,
5758
) -> Any:
5859
"""
5960
Cuts the given facet onto the given Diamond contract.
@@ -127,7 +128,9 @@ def facet_cut(
127128
if facet_name == "ERC20Facet":
128129
if initializer_address != ZERO_ADDRESS and action != "remove":
129130
erc20_initializer = ERC20Initializer.ERC20Initializer(initializer_address)
130-
calldata = erc20_initializer.contract.init.encode_input()
131+
calldata = erc20_initializer.contract.init.encode_input(
132+
initializer_params[0], initializer_params[1]
133+
)
131134
elif facet_name == "TerminusFacet":
132135
if initializer_address != ZERO_ADDRESS and action != "remove":
133136
terminus_initializer = TerminusInitializer.TerminusInitializer(

dao/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def setUpClass(cls) -> None:
3939
"add",
4040
{"from": accounts[0]},
4141
initializer.address,
42+
initializer_params=["Moonstream DAO", "MNSTR"],
4243
)
4344

4445
cls.erc20_initializer = initializer.address

dao/test_moonstream.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def test_add_and_replace(self):
2424
"add",
2525
{"from": accounts[0]},
2626
initializer.address,
27+
initializer_params=["Moonstream DAO", "MNSTR"],
2728
)
2829

2930
diamond_erc20 = ERC20Facet.ERC20Facet(diamond_address)
@@ -39,19 +40,6 @@ def test_add_and_replace(self):
3940
expected_decimals = 18
4041
self.assertEqual(decimals, expected_decimals)
4142

42-
with self.assertRaises(Exception):
43-
diamond_erc20.set_erc20_metadata("LOL", "ROFL", {"from": accounts[1]})
44-
45-
diamond_erc20.set_erc20_metadata("LOL", "ROFL", {"from": accounts[0]})
46-
47-
name = diamond_erc20.name()
48-
expected_name = "LOL"
49-
self.assertEqual(name, expected_name)
50-
51-
symbol = diamond_erc20.symbol()
52-
expected_symbol = "ROFL"
53-
self.assertEqual(symbol, expected_symbol)
54-
5543
new_erc20_facet = ERC20Facet.ERC20Facet(None)
5644
new_erc20_facet.deploy({"from": accounts[0]})
5745
facet_cut(
@@ -61,14 +49,15 @@ def test_add_and_replace(self):
6149
"replace",
6250
{"from": accounts[0]},
6351
initializer.address,
52+
initializer_params=["ROFL", "LOL"],
6453
)
6554

6655
name = diamond_erc20.name()
67-
expected_name = "Moonstream DAO"
56+
expected_name = "ROFL"
6857
self.assertEqual(name, expected_name)
6958

7059
symbol = diamond_erc20.symbol()
71-
expected_symbol = "MNSTR"
60+
expected_symbol = "LOL"
7261
self.assertEqual(symbol, expected_symbol)
7362

7463

@@ -88,6 +77,7 @@ def test_remove_facet(self):
8877
"add",
8978
{"from": accounts[0]},
9079
initializer.address,
80+
initializer_params=["Moonstream DAO", "MNSTR"],
9181
)
9282

9383
diamond_erc20 = ERC20Facet.ERC20Facet(diamond_address)

0 commit comments

Comments
 (0)