From 95c879b747d6a1facd2e55e0238bd02e734282fe Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Feb 2022 17:20:26 +0100 Subject: [PATCH 001/164] initial contract creation --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/protocol/contracts/stability/StableTokenRegistry.sol diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol new file mode 100644 index 00000000000..e69de29bb2d From 19a323c08c1ef2d4a3f7147c3e96e6ae85dc8470 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Feb 2022 17:58:37 +0100 Subject: [PATCH 002/164] added a contructor and a mapping --- .../stability/StableTokenRegistry.sol | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index e69de29bb2d..4e8e121dbd4 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -0,0 +1,18 @@ +pragma solidity ^0.5.13; + +import "./StableTokenEUR.sol"; +import "./StableToken.sol"; +import "./StableTokenBRL.sol"; + +/** + * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. + */ +contract StableTokenRegistry { + mapping(string => string) public stableTokenRegistry; + + /** + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ + constructor(bool test) public Initializable(test) {} +} From 0ce006e1c94bdb5a4d07301afdb6d2eff252de77 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 18:53:00 +0100 Subject: [PATCH 003/164] added function that add fiat tickers into the collection --- .../stability/StableTokenRegistry.sol | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 4e8e121dbd4..61b19175ded 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,18 +1,31 @@ pragma solidity ^0.5.13; -import "./StableTokenEUR.sol"; import "./StableToken.sol"; +import "./StableTokenEUR.sol"; import "./StableTokenBRL.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ contract StableTokenRegistry { - mapping(string => string) public stableTokenRegistry; + mapping(string => string) public stableTokens; + string[] public fiatTickers; /** - * @notice Sets initialized == true on implementation contracts - * @param test Set to true to skip implementation initialization - */ + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ constructor(bool test) public Initializable(test) {} + + /** + * @notice adds fiat currencies to fiatTickers collection + * @param currencyType the type of currency we're trying to push into the collection + */ + function addFiatTickers(string currencyType) external onlyOwner { + //also check if it already exists in the array, if it does then don't add + //so I can make sure there are no dublicates + require(!stableTokens[currencyType], "Stable token hasn't been issued"); + stableTokens[currencyType] = true; + fiatTickers.push(currencyType); + } } From ccef1d0046aafc3f56e586979abbea28633af5d1 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 18:57:07 +0100 Subject: [PATCH 004/164] function that returns all the fiat symbols thats been issued --- .../protocol/contracts/stability/StableTokenRegistry.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 61b19175ded..9d5c5c7bdff 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -28,4 +28,12 @@ contract StableTokenRegistry { stableTokens[currencyType] = true; fiatTickers.push(currencyType); } + + /** + * @notice Returns fiat currencies that have been issued. + * @return An array of currencies issued. + */ + function getFiatTickers() external view returns (string[] memory) { + return fiatTickers; + } } From 11829f53691e6720293441d37cd94ca5e2295c8f Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 19:17:06 +0100 Subject: [PATCH 005/164] quering a stable contract functionality --- .../contracts/stability/StableTokenRegistry.sol | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 9d5c5c7bdff..9954bb89fe2 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -21,7 +21,7 @@ contract StableTokenRegistry { * @notice adds fiat currencies to fiatTickers collection * @param currencyType the type of currency we're trying to push into the collection */ - function addFiatTickers(string currencyType) external onlyOwner { + function addFiatTickers(string _currencyType) external onlyOwner { //also check if it already exists in the array, if it does then don't add //so I can make sure there are no dublicates require(!stableTokens[currencyType], "Stable token hasn't been issued"); @@ -36,4 +36,12 @@ contract StableTokenRegistry { function getFiatTickers() external view returns (string[] memory) { return fiatTickers; } + + /** + * @notice Returns queried stable contract. + * @return stable contract. + */ + function queryContractByFiatType(string _fiatTicker) public view returns (string) { + return stableTokens[_fiatTicker]; + } } From 7dc32a77cc7f64999435ea15f24cda2bdd594b52 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 20:02:51 +0100 Subject: [PATCH 006/164] function to retrieve all the contract instances from a mapping --- .../contracts/stability/StableTokenRegistry.sol | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 9954bb89fe2..6dc0709a888 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -10,13 +10,13 @@ import "./StableTokenBRL.sol"; contract StableTokenRegistry { mapping(string => string) public stableTokens; string[] public fiatTickers; + string[] public contracts; /** * @notice Sets initialized == true on implementation contracts * @param test Set to true to skip implementation initialization */ constructor(bool test) public Initializable(test) {} - /** * @notice adds fiat currencies to fiatTickers collection * @param currencyType the type of currency we're trying to push into the collection @@ -31,12 +31,20 @@ contract StableTokenRegistry { /** * @notice Returns fiat currencies that have been issued. - * @return An array of currencies issued. + * @return A collection of currencies issued. */ function getFiatTickers() external view returns (string[] memory) { return fiatTickers; } + /** + * @notice Returns contracts that have been issued. + * @return A collection of contracts issued. + */ + function getContracts() external view returns (string[] memory) { + return contracts; + } + /** * @notice Returns queried stable contract. * @return stable contract. From 03887137af0385aa22083c46aebfeef6147ca676 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 20:06:27 +0100 Subject: [PATCH 007/164] removing unnecessary imports --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 6dc0709a888..a13d0ecd9e1 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,9 +1,5 @@ pragma solidity ^0.5.13; -import "./StableToken.sol"; -import "./StableTokenEUR.sol"; -import "./StableTokenBRL.sol"; - /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ From 07b2f794eb3f875061ae7bc1c6b75f89568d70a3 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 12:09:27 +0100 Subject: [PATCH 008/164] function that returns all the contracts --- .../protocol/contracts/stability/StableTokenRegistry.sol | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index a13d0ecd9e1..50e5be0aafa 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -13,6 +13,7 @@ contract StableTokenRegistry { * @param test Set to true to skip implementation initialization */ constructor(bool test) public Initializable(test) {} + /** * @notice adds fiat currencies to fiatTickers collection * @param currencyType the type of currency we're trying to push into the collection @@ -48,4 +49,12 @@ contract StableTokenRegistry { function queryContractByFiatType(string _fiatTicker) public view returns (string) { return stableTokens[_fiatTicker]; } + + function getContractInstances() external view returns (string[] memory) { + string[] memory contracts; + for (i = 0; i < fiatTickers.length; i++) { + contracts.push(stableTokens[fiatTickers[i]]); + } + return contracts; + } } From d94191664c33fce8875f338d1737506ee7260ba1 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 12:15:09 +0100 Subject: [PATCH 009/164] added comments --- .../protocol/contracts/stability/StableTokenRegistry.sol | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 50e5be0aafa..1fdccfb812c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -50,6 +50,11 @@ contract StableTokenRegistry { return stableTokens[_fiatTicker]; } + /** + * @notice Returns all the contract instances created. + * @return collection of stable token contracts. + */ + function getContractInstances() external view returns (string[] memory) { string[] memory contracts; for (i = 0; i < fiatTickers.length; i++) { From 5ae7ce28deb1f132dfdae3a8301c9e4a449d0a93 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 12:16:25 +0100 Subject: [PATCH 010/164] removed unnecessary function --- .../protocol/contracts/stability/StableTokenRegistry.sol | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 1fdccfb812c..ed38fd673e6 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -6,7 +6,6 @@ pragma solidity ^0.5.13; contract StableTokenRegistry { mapping(string => string) public stableTokens; string[] public fiatTickers; - string[] public contracts; /** * @notice Sets initialized == true on implementation contracts @@ -34,14 +33,6 @@ contract StableTokenRegistry { return fiatTickers; } - /** - * @notice Returns contracts that have been issued. - * @return A collection of contracts issued. - */ - function getContracts() external view returns (string[] memory) { - return contracts; - } - /** * @notice Returns queried stable contract. * @return stable contract. From 8e5e1cc3940e4248a279ea15c65ed14bddb93cbe Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 12:23:33 +0100 Subject: [PATCH 011/164] removed unnecessary function --- .../protocol/contracts/stability/StableTokenRegistry.sol | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index ed38fd673e6..63312f0628b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -33,14 +33,6 @@ contract StableTokenRegistry { return fiatTickers; } - /** - * @notice Returns queried stable contract. - * @return stable contract. - */ - function queryContractByFiatType(string _fiatTicker) public view returns (string) { - return stableTokens[_fiatTicker]; - } - /** * @notice Returns all the contract instances created. * @return collection of stable token contracts. From 5da3ce79ba5e272c43741f727f6087d7c797dcc6 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 13:33:51 +0100 Subject: [PATCH 012/164] functionality to remove unsupported tokens --- .../stability/StableTokenRegistry.sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 63312f0628b..14353bd6685 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -45,4 +45,23 @@ contract StableTokenRegistry { } return contracts; } + + /** + * @notice Removes unwamted token instances. + * @param fiatType The type of currency that is no longer supported. + * @param index The index in fiatTickers of fiatType. + */ + function removeRegistry(string fiatType, uint256 index) external onlyowner { + uint256 numFiats = fiatTickers.length; + require(index < numFiats, "Index is invalid"); + require(fiatType == fiatTickers[index], "Index does not match fiat type"); + uint256 newNumFiats = numFiats.sub(1); + + if (index != newNumFiats) { + fiatTickers[index] = fiatTickers[newNumFiats]; + } + fiatTickers[newNumFiats] = ""; + fiatTickers.length = newNumFiats; + } + } From 1da3a60f0673c7ac47a38b6e5982cbf279aac77d Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 13:47:55 +0100 Subject: [PATCH 013/164] function that adds new instances to the registry --- .../stability/StableTokenRegistry.sol | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 14353bd6685..d90770d5763 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -8,15 +8,15 @@ contract StableTokenRegistry { string[] public fiatTickers; /** - * @notice Sets initialized == true on implementation contracts - * @param test Set to true to skip implementation initialization - */ + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ constructor(bool test) public Initializable(test) {} /** - * @notice adds fiat currencies to fiatTickers collection - * @param currencyType the type of currency we're trying to push into the collection - */ + * @notice adds fiat currencies to fiatTickers collection + * @param currencyType the type of currency we're trying to push into the collection + */ function addFiatTickers(string _currencyType) external onlyOwner { //also check if it already exists in the array, if it does then don't add //so I can make sure there are no dublicates @@ -64,4 +64,17 @@ contract StableTokenRegistry { fiatTickers.length = newNumFiats; } + /** + * @notice Gives an address permission to spend Reserve without limit. + * @param spender The address that is allowed to spend Reserve funds. + */ + + function addNewRegistry(string fiatType, string contractType) external onlyOwner { + require("" != fiatType, "fiatType cant be an empty string"); + require("" != contractType, "contractType cant be an empty string"); + require(stableTokens[fiatType] != "", "This registry already exists"); + stableTokens[fiatType] = contractType; + fiatTickers.push(fiatType); + } + } From 46d365924f18b05e441e259a3eb48789f9db0581 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 13:50:42 +0100 Subject: [PATCH 014/164] poor indentation --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index d90770d5763..c690477a62b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -37,7 +37,6 @@ contract StableTokenRegistry { * @notice Returns all the contract instances created. * @return collection of stable token contracts. */ - function getContractInstances() external view returns (string[] memory) { string[] memory contracts; for (i = 0; i < fiatTickers.length; i++) { @@ -68,7 +67,6 @@ contract StableTokenRegistry { * @notice Gives an address permission to spend Reserve without limit. * @param spender The address that is allowed to spend Reserve funds. */ - function addNewRegistry(string fiatType, string contractType) external onlyOwner { require("" != fiatType, "fiatType cant be an empty string"); require("" != contractType, "contractType cant be an empty string"); From 2fa850d12f73773e463ae36601b2e4675d4115b6 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 15:06:07 +0100 Subject: [PATCH 015/164] resolving bugs --- .../protocol/contracts/stability/StableTokenRegistry.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index c690477a62b..4197ca34dc0 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -17,11 +17,10 @@ contract StableTokenRegistry { * @notice adds fiat currencies to fiatTickers collection * @param currencyType the type of currency we're trying to push into the collection */ - function addFiatTickers(string _currencyType) external onlyOwner { + function addFiatTickers(string currencyType) external onlyOwner { //also check if it already exists in the array, if it does then don't add //so I can make sure there are no dublicates - require(!stableTokens[currencyType], "Stable token hasn't been issued"); - stableTokens[currencyType] = true; + require(stableTokens[currencyType] != "", "Stable token hasn't been issued"); fiatTickers.push(currencyType); } From 6f67ac9fd4960f9720c30ed7ff55dcfdb308b3bc Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 15:59:29 +0100 Subject: [PATCH 016/164] suggested improvements --- .../stability/StableTokenRegistry.sol | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 4197ca34dc0..e39a745185c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -13,17 +13,6 @@ contract StableTokenRegistry { */ constructor(bool test) public Initializable(test) {} - /** - * @notice adds fiat currencies to fiatTickers collection - * @param currencyType the type of currency we're trying to push into the collection - */ - function addFiatTickers(string currencyType) external onlyOwner { - //also check if it already exists in the array, if it does then don't add - //so I can make sure there are no dublicates - require(stableTokens[currencyType] != "", "Stable token hasn't been issued"); - fiatTickers.push(currencyType); - } - /** * @notice Returns fiat currencies that have been issued. * @return A collection of currencies issued. @@ -46,13 +35,13 @@ contract StableTokenRegistry { /** * @notice Removes unwamted token instances. - * @param fiatType The type of currency that is no longer supported. - * @param index The index in fiatTickers of fiatType. + * @param fiatTicker The type of currency that is no longer supported. + * @param index The index in fiatTickers of fiatTicker. */ - function removeRegistry(string fiatType, uint256 index) external onlyowner { + function removeRegistry(string fiatTicker, uint256 index) external onlyowner { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); - require(fiatType == fiatTickers[index], "Index does not match fiat type"); + require(fiatTicker == fiatTickers[index], "Index does not match fiat type"); uint256 newNumFiats = numFiats.sub(1); if (index != newNumFiats) { @@ -66,12 +55,12 @@ contract StableTokenRegistry { * @notice Gives an address permission to spend Reserve without limit. * @param spender The address that is allowed to spend Reserve funds. */ - function addNewRegistry(string fiatType, string contractType) external onlyOwner { - require("" != fiatType, "fiatType cant be an empty string"); - require("" != contractType, "contractType cant be an empty string"); - require(stableTokens[fiatType] != "", "This registry already exists"); - stableTokens[fiatType] = contractType; - fiatTickers.push(fiatType); + function addNewRegistry(string fiatTicker, string stableTokenContractName) external onlyOwner { + require("" != fiatTicker, "fiatTicker cant be an empty string"); + require("" != stableTokenContractName, "stableTokenContractName cant be an empty string"); + require(stableTokens[fiatTicker] != "", "This registry already exists"); + stableTokens[fiatTicker] = stableTokenContractName; + fiatTickers.push(fiatTicker); } } From 6c4bac4431c40d287aa685aa9f05cc126982726e Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 17:10:06 +0100 Subject: [PATCH 017/164] writing initialize --- .../contracts/stability/StableTokenRegistry.sol | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index e39a745185c..1e2c01e5b8a 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,4 +1,5 @@ pragma solidity ^0.5.13; +import "../common/Initializable.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. @@ -13,6 +14,13 @@ contract StableTokenRegistry { */ constructor(bool test) public Initializable(test) {} + /** + * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. + * @param fiatTicker The fiat currency. + * @param stableTokenContractName The name of a stable token smart contract. + */ + function initialize() external initializer {} + /** * @notice Returns fiat currencies that have been issued. * @return A collection of currencies issued. @@ -38,7 +46,7 @@ contract StableTokenRegistry { * @param fiatTicker The type of currency that is no longer supported. * @param index The index in fiatTickers of fiatTicker. */ - function removeRegistry(string fiatTicker, uint256 index) external onlyowner { + function removeStableToken(string fiatTicker, uint256 index) external onlyowner { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require(fiatTicker == fiatTickers[index], "Index does not match fiat type"); @@ -55,7 +63,7 @@ contract StableTokenRegistry { * @notice Gives an address permission to spend Reserve without limit. * @param spender The address that is allowed to spend Reserve funds. */ - function addNewRegistry(string fiatTicker, string stableTokenContractName) external onlyOwner { + function addNewStableToken(string fiatTicker, string stableTokenContractName) external onlyOwner { require("" != fiatTicker, "fiatTicker cant be an empty string"); require("" != stableTokenContractName, "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker] != "", "This registry already exists"); From 788917048c734fe5b4dfcf607323164afdbaf38c Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 17:11:53 +0100 Subject: [PATCH 018/164] updated inconsistent syntax --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 1e2c01e5b8a..2db48da1cd1 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -64,8 +64,8 @@ contract StableTokenRegistry { * @param spender The address that is allowed to spend Reserve funds. */ function addNewStableToken(string fiatTicker, string stableTokenContractName) external onlyOwner { - require("" != fiatTicker, "fiatTicker cant be an empty string"); - require("" != stableTokenContractName, "stableTokenContractName cant be an empty string"); + require(fiatTicker != "", "fiatTicker cant be an empty string"); + require(stableTokenContractName != "", "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker] != "", "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); From a5e039aaf17ba42d7df7ae775356f222cbeaef8e Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 17:53:18 +0100 Subject: [PATCH 019/164] initialize function is implemented --- .../protocol/contracts/stability/StableTokenRegistry.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 2db48da1cd1..65022806c97 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,4 +1,5 @@ pragma solidity ^0.5.13; + import "../common/Initializable.sol"; /** @@ -19,7 +20,9 @@ contract StableTokenRegistry { * @param fiatTicker The fiat currency. * @param stableTokenContractName The name of a stable token smart contract. */ - function initialize() external initializer {} + function initialize(string fiatTicker, string stableTokenContractName) external initializer { + stableTokens[fiatTicker] = stableTokenContractName; + } /** * @notice Returns fiat currencies that have been issued. From a0c0cc95f706a8322b8d73a58d9c987f2fef787b Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 19:27:07 +0100 Subject: [PATCH 020/164] some of the resolved compile errors --- .../stability/StableTokenRegistry.sol | 21 ++++++++++++------- .../test/stability/stabletokenregistry.ts | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 packages/protocol/test/stability/stabletokenregistry.ts diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 65022806c97..2a26c0ceaff 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,13 +1,15 @@ pragma solidity ^0.5.13; import "../common/Initializable.sol"; +import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ -contract StableTokenRegistry { +contract StableTokenRegistry is Initializable, Ownable { mapping(string => string) public stableTokens; string[] public fiatTickers; + string[] public contracts; /** * @notice Sets initialized == true on implementation contracts @@ -20,7 +22,10 @@ contract StableTokenRegistry { * @param fiatTicker The fiat currency. * @param stableTokenContractName The name of a stable token smart contract. */ - function initialize(string fiatTicker, string stableTokenContractName) external initializer { + function initialize(string calldata fiatTicker, string calldata stableTokenContractName) + external + initializer + { stableTokens[fiatTicker] = stableTokenContractName; } @@ -37,8 +42,7 @@ contract StableTokenRegistry { * @return collection of stable token contracts. */ function getContractInstances() external view returns (string[] memory) { - string[] memory contracts; - for (i = 0; i < fiatTickers.length; i++) { + for (uint256 i = 0; i < fiatTickers.length; i++) { contracts.push(stableTokens[fiatTickers[i]]); } return contracts; @@ -49,7 +53,7 @@ contract StableTokenRegistry { * @param fiatTicker The type of currency that is no longer supported. * @param index The index in fiatTickers of fiatTicker. */ - function removeStableToken(string fiatTicker, uint256 index) external onlyowner { + function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require(fiatTicker == fiatTickers[index], "Index does not match fiat type"); @@ -64,9 +68,12 @@ contract StableTokenRegistry { /** * @notice Gives an address permission to spend Reserve without limit. - * @param spender The address that is allowed to spend Reserve funds. + * @param fiatTicker The address that is allowed to spend Reserve funds. */ - function addNewStableToken(string fiatTicker, string stableTokenContractName) external onlyOwner { + function addNewStableToken(string calldata fiatTicker, string calldata stableTokenContractName) + external + onlyOwner + { require(fiatTicker != "", "fiatTicker cant be an empty string"); require(stableTokenContractName != "", "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker] != "", "This registry already exists"); diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts new file mode 100644 index 00000000000..08e5f2601a8 --- /dev/null +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -0,0 +1,3 @@ +contract('StableTokenRegistry', () => { + console.log('hi') +}) From 3fe724feab6fea965da7f241517cb42b25ea1f8b Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 15:07:18 +0100 Subject: [PATCH 021/164] resolving compiler issues --- .../stability/StableTokenRegistry.sol | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 2a26c0ceaff..45a78ea0c2b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,5 +1,7 @@ pragma solidity ^0.5.13; +pragma experimental ABIEncoderV2; +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; @@ -7,9 +9,9 @@ import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ contract StableTokenRegistry is Initializable, Ownable { + using SafeMath for uint256; mapping(string => string) public stableTokens; string[] public fiatTickers; - string[] public contracts; /** * @notice Sets initialized == true on implementation contracts @@ -42,8 +44,9 @@ contract StableTokenRegistry is Initializable, Ownable { * @return collection of stable token contracts. */ function getContractInstances() external view returns (string[] memory) { + string[] memory contracts; for (uint256 i = 0; i < fiatTickers.length; i++) { - contracts.push(stableTokens[fiatTickers[i]]); + contracts[i] = stableTokens[fiatTickers[i]]; } return contracts; } @@ -56,7 +59,10 @@ contract StableTokenRegistry is Initializable, Ownable { function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); - require(fiatTicker == fiatTickers[index], "Index does not match fiat type"); + require( + keccak256(bytes(fiatTicker)) == keccak256(bytes(fiatTickers[index])), + "Index does not match fiat type" + ); uint256 newNumFiats = numFiats.sub(1); if (index != newNumFiats) { @@ -74,9 +80,9 @@ contract StableTokenRegistry is Initializable, Ownable { external onlyOwner { - require(fiatTicker != "", "fiatTicker cant be an empty string"); - require(stableTokenContractName != "", "stableTokenContractName cant be an empty string"); - require(stableTokens[fiatTicker] != "", "This registry already exists"); + require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); + require(bytes(stableTokenContractName) != 0, "stableTokenContractName cant be an empty string"); + require(bytes(stableTokens[fiatTicker]) != 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } From 484380f5449d2257979c6fc0d40265fd3df97aeb Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 15:12:01 +0100 Subject: [PATCH 022/164] last of compiler issues --- .../protocol/contracts/stability/StableTokenRegistry.sol | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 45a78ea0c2b..de0d896a32d 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -81,8 +81,11 @@ contract StableTokenRegistry is Initializable, Ownable { onlyOwner { require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); - require(bytes(stableTokenContractName) != 0, "stableTokenContractName cant be an empty string"); - require(bytes(stableTokens[fiatTicker]) != 0, "This registry already exists"); + require( + bytes(stableTokenContractName).length != 0, + "stableTokenContractName cant be an empty string" + ); + require(bytes(stableTokens[fiatTicker]).length != 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } From 7e6d02a2ab928caa428ae5a939661f6966c54e2d Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 15:53:25 +0100 Subject: [PATCH 023/164] upgrading removeStableToken funrction --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index de0d896a32d..b97ca9b756c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -57,11 +57,12 @@ contract StableTokenRegistry is Initializable, Ownable { * @param index The index in fiatTickers of fiatTicker. */ function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { + stableTokens[fiatTicker] = ""; uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require( keccak256(bytes(fiatTicker)) == keccak256(bytes(fiatTickers[index])), - "Index does not match fiat type" + "Index does not match fiatTicker" ); uint256 newNumFiats = numFiats.sub(1); From 8d87eafad7b9078d02a5a7b3c4125199f955d96e Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 17:41:14 +0100 Subject: [PATCH 024/164] updated registry --- .../stability/StableTokenRegistry.sol | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index b97ca9b756c..3794252da1a 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -21,14 +21,21 @@ contract StableTokenRegistry is Initializable, Ownable { /** * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. - * @param fiatTicker The fiat currency. - * @param stableTokenContractName The name of a stable token smart contract. + * @param existingFiatTickers Collection of fiat currencies issued already. + * @param existingStableTokenContractNames Collection of stable token smart contract names. */ - function initialize(string calldata fiatTicker, string calldata stableTokenContractName) - external - initializer - { - stableTokens[fiatTicker] = stableTokenContractName; + function initialize( + string[] calldata existingFiatTickers, + string[] calldata existingStableTokenContractNames + ) external initializer { + _transferOwnership(msg.sender); + require( + existingFiatTickers.length == existingStableTokenContractNames.length, + "Array length mismatch" + ); + for (uint256 i = 0; i < existingFiatTickers.length; i++) { + stableTokens[fiatTickers[i]] = existingFiatTickers[i]; + } } /** From 4e375935ab07eb110cb0579f464689f4b88553d1 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 19:33:33 +0100 Subject: [PATCH 025/164] updated initialize function --- packages/protocol/contracts/common/Registry.sol | 1 + .../protocol/contracts/stability/StableTokenRegistry.sol | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/packages/protocol/contracts/common/Registry.sol b/packages/protocol/contracts/common/Registry.sol index 9e89bd89523..d5045f3b806 100644 --- a/packages/protocol/contracts/common/Registry.sol +++ b/packages/protocol/contracts/common/Registry.sol @@ -3,6 +3,7 @@ pragma solidity ^0.5.13; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; +import "../../contracts/common/Registry.sol"; import "./interfaces/IRegistry.sol"; import "./Initializable.sol"; diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 3794252da1a..e26b79d4a95 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -4,6 +4,9 @@ pragma experimental ABIEncoderV2; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; +// import "../common/Registry.sol"; +// import "../common/UsingRegistry.sol"; +import "../common/interfaces/IRegistry.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. @@ -13,6 +16,8 @@ contract StableTokenRegistry is Initializable, Ownable { mapping(string => string) public stableTokens; string[] public fiatTickers; + IRegistry public registry; + /** * @notice Sets initialized == true on implementation contracts * @param test Set to true to skip implementation initialization @@ -88,6 +93,7 @@ contract StableTokenRegistry is Initializable, Ownable { external onlyOwner { + registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); require( bytes(stableTokenContractName).length != 0, From 82e1b0c833e521b0e869ee2bb47e1eecece7d0f1 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 19:35:10 +0100 Subject: [PATCH 026/164] removed commented out code --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index e26b79d4a95..fce950b2701 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -4,8 +4,6 @@ pragma experimental ABIEncoderV2; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; -// import "../common/Registry.sol"; -// import "../common/UsingRegistry.sol"; import "../common/interfaces/IRegistry.sol"; /** From 4d1451f51b6188b42bf18ae97e969a9dcb70de2b Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 1 Mar 2022 15:43:48 +0100 Subject: [PATCH 027/164] updated comments --- .../protocol/contracts/stability/StableTokenRegistry.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index fce950b2701..e579229555a 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -63,7 +63,7 @@ contract StableTokenRegistry is Initializable, Ownable { /** * @notice Removes unwamted token instances. - * @param fiatTicker The type of currency that is no longer supported. + * @param fiatTicker The currency that is no longer supported. * @param index The index in fiatTickers of fiatTicker. */ function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { @@ -84,8 +84,9 @@ contract StableTokenRegistry is Initializable, Ownable { } /** - * @notice Gives an address permission to spend Reserve without limit. - * @param fiatTicker The address that is allowed to spend Reserve funds. + * @notice Adds new Fiat Ticker and Stable Token contract to the registry. + * @param fiatTicker The currency we are trying to add in the registry. + * @param stableTokenContractName The contract we are trying to add in the registry. */ function addNewStableToken(string calldata fiatTicker, string calldata stableTokenContractName) external From 54d7d191229c6814be94787079ac343eb2177cac Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 09:46:27 +0100 Subject: [PATCH 028/164] created a proxy --- .../stability/proxies/StableTokenRegistryProxy.sol | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol diff --git a/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol b/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol new file mode 100644 index 00000000000..6e9656d991c --- /dev/null +++ b/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.5.13; + +import "../../common/Proxy.sol"; + +/* solhint-disable no-empty-blocks */ +contract StableTokenRegistryProxy is Proxy {} From 98f84c61a5feef5bc112ea583c5757f2f9992d86 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 09:51:23 +0100 Subject: [PATCH 029/164] updating build file --- packages/protocol/scripts/build.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts index 1f4f78240f7..7272ddeb65a 100644 --- a/packages/protocol/scripts/build.ts +++ b/packages/protocol/scripts/build.ts @@ -36,6 +36,7 @@ export const ProxyContracts = [ 'StableTokenEURProxy', 'StableTokenProxy', 'SortedOraclesProxy', + 'StableTokenRegistryProxy', ] export const CoreContracts = [ // common @@ -89,6 +90,7 @@ const OtherContracts = [ // abstract 'Initializable', 'UsingRegistry', + 'StableTokenRegistry', ] const Interfaces = ['ICeloToken', 'IERC20', 'ICeloVersionedContract'] From 55757be53f46970005ee989992c8cfdf5d9f39ca Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 11:56:43 +0100 Subject: [PATCH 030/164] updated build file --- packages/protocol/scripts/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts index 7272ddeb65a..7e4432d7ae8 100644 --- a/packages/protocol/scripts/build.ts +++ b/packages/protocol/scripts/build.ts @@ -79,6 +79,7 @@ export const CoreContracts = [ 'StableTokenEUR', 'StableTokenBRL', 'SortedOracles', + 'StableTokenRegistry', // liquidity 'GrandaMento', @@ -90,7 +91,6 @@ const OtherContracts = [ // abstract 'Initializable', 'UsingRegistry', - 'StableTokenRegistry', ] const Interfaces = ['ICeloToken', 'IERC20', 'ICeloVersionedContract'] From 3f445caceb2df0d76db611ff7efb6f32004efc32 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 14:40:02 +0100 Subject: [PATCH 031/164] initialize test suit --- .../test/stability/stabletokenregistry.ts | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 08e5f2601a8..60f998e60f9 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,3 +1,42 @@ -contract('StableTokenRegistry', () => { - console.log('hi') +import { assertRevert } from '@celo/protocol/lib/test-utils' +import { + // RegistryContract, + // RegistryInstance, + StableTokenRegistryContract, + StableTokenRegistryInstance, +} from 'types' + +const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') +// const Registry: RegistryContract = artifacts.require('Registry') + +contract('StableTokenRegistry', (accounts: string[]) => { + let strc: StableTokenRegistryInstance + + // @ts-ignore + let initializationTime + beforeEach(async () => { + strc = await STRC.new(true) + const response = await strc.initialize( + ['cUSD', 'cEUR', 'cBRL'], + ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] + ) + // @ts-ignore + initializationTime = (await web3.eth.getBlock(response.receipt.blockNumber)).timestamp + }) + + describe('#initialize()', async () => { + it('should have set the owner', async () => { + const owner: string = await strc.owner() + assert.equal(owner, accounts[0]) + }) + + it('should not be callable again', async () => { + await assertRevert( + strc.initialize( + ['cUSD', 'cEUR', 'cBRL'], + ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] + ) + ) + }) + }) }) From e5703ea7d29770c498e2f3b186cd2f58c855ae10 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 15:36:44 +0100 Subject: [PATCH 032/164] updating registry contract --- .../contracts/stability/StableTokenRegistry.sol | 8 ++++---- .../protocol/test/stability/stabletokenregistry.ts | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index e579229555a..3607ce9c905 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -31,13 +31,13 @@ contract StableTokenRegistry is Initializable, Ownable { string[] calldata existingFiatTickers, string[] calldata existingStableTokenContractNames ) external initializer { - _transferOwnership(msg.sender); require( existingFiatTickers.length == existingStableTokenContractNames.length, "Array length mismatch" ); + _transferOwnership(msg.sender); for (uint256 i = 0; i < existingFiatTickers.length; i++) { - stableTokens[fiatTickers[i]] = existingFiatTickers[i]; + addNewStableToken(fiatTickers[i], existingFiatTickers[i]); } } @@ -88,8 +88,8 @@ contract StableTokenRegistry is Initializable, Ownable { * @param fiatTicker The currency we are trying to add in the registry. * @param stableTokenContractName The contract we are trying to add in the registry. */ - function addNewStableToken(string calldata fiatTicker, string calldata stableTokenContractName) - external + function addNewStableToken(string memory fiatTicker, string memory stableTokenContractName) + public onlyOwner { registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 60f998e60f9..4873f54a72e 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,30 +1,30 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' -import { - // RegistryContract, - // RegistryInstance, - StableTokenRegistryContract, - StableTokenRegistryInstance, -} from 'types' +import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') -// const Registry: RegistryContract = artifacts.require('Registry') contract('StableTokenRegistry', (accounts: string[]) => { + console.log('hi') let strc: StableTokenRegistryInstance // @ts-ignore let initializationTime beforeEach(async () => { + console.log('1') strc = await STRC.new(true) + console.log('12') const response = await strc.initialize( ['cUSD', 'cEUR', 'cBRL'], ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] ) + console.log('123') // @ts-ignore initializationTime = (await web3.eth.getBlock(response.receipt.blockNumber)).timestamp + console.log('1234') }) describe('#initialize()', async () => { + console.log('12345') it('should have set the owner', async () => { const owner: string = await strc.owner() assert.equal(owner, accounts[0]) From f7f68de2cd1dd1671ef0d8e7e0e8ca138d2d8458 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 15:45:13 +0100 Subject: [PATCH 033/164] first few tests are passing --- .../test/stability/stabletokenregistry.ts | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 4873f54a72e..5647fda11cd 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -4,39 +4,21 @@ import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') contract('StableTokenRegistry', (accounts: string[]) => { - console.log('hi') let strc: StableTokenRegistryInstance - // @ts-ignore - let initializationTime beforeEach(async () => { - console.log('1') strc = await STRC.new(true) - console.log('12') - const response = await strc.initialize( - ['cUSD', 'cEUR', 'cBRL'], - ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] - ) - console.log('123') - // @ts-ignore - initializationTime = (await web3.eth.getBlock(response.receipt.blockNumber)).timestamp - console.log('1234') + await strc.initialize([], []) }) describe('#initialize()', async () => { - console.log('12345') it('should have set the owner', async () => { const owner: string = await strc.owner() assert.equal(owner, accounts[0]) }) it('should not be callable again', async () => { - await assertRevert( - strc.initialize( - ['cUSD', 'cEUR', 'cBRL'], - ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] - ) - ) + await assertRevert(strc.initialize([], [])) }) }) }) From 91cc2adb1cfe9a4ff9c56ef6d4e567002d5b5210 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 16:28:25 +0100 Subject: [PATCH 034/164] remove stableToken function --- .../test/stability/stabletokenregistry.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 5647fda11cd..4e5e14577d3 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -5,6 +5,9 @@ const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance + const nonOwner: string = accounts[1] + const fiatTicker: string = 'USD' + const stableTokenContractName = 'StableToken' beforeEach(async () => { strc = await STRC.new(true) @@ -21,4 +24,41 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.initialize([], [])) }) }) + + describe('#removeStableToken(fiatTicker)', () => { + beforeEach(async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + }) + + it('only allows owner', async () => { + await assertRevert(strc.removeStableToken(fiatTicker, 0, { from: nonOwner })) + }) + + it('has the right list of fiat tickers after removing one', async () => { + await strc.removeStableToken(fiatTicker, 0) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, []) + }) + + it("can't be removed twice", async () => { + await strc.removeStableToken(fiatTicker, 0) + await assertRevert(strc.removeStableToken(fiatTicker, 0)) + }) + + it("can't delete an index out of range", async () => { + await assertRevert(strc.removeStableToken(fiatTicker, 1)) + }) + + it('removes from a big array', async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + await strc.removeStableToken(fiatTicker, 0) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, [accounts[1]]) + }) + + it("doesn't remove an fiat ticker with the wrong index", async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + await assertRevert(strc.removeStableToken(fiatTicker, 1)) + }) + }) }) From cdeeaabfe9d805e0728b66f3d1c0d71f3ac68bf7 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 21 Mar 2022 12:58:46 +0100 Subject: [PATCH 035/164] resolving a mistake --- packages/protocol/contracts/common/Registry.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/protocol/contracts/common/Registry.sol b/packages/protocol/contracts/common/Registry.sol index d5045f3b806..9e89bd89523 100644 --- a/packages/protocol/contracts/common/Registry.sol +++ b/packages/protocol/contracts/common/Registry.sol @@ -3,7 +3,6 @@ pragma solidity ^0.5.13; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; -import "../../contracts/common/Registry.sol"; import "./interfaces/IRegistry.sol"; import "./Initializable.sol"; From 49f3b605af1f8821405588a9133f4f675d8e4349 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 21 Mar 2022 13:31:15 +0100 Subject: [PATCH 036/164] resolving based on corrections --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 3607ce9c905..343592852bf 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -79,7 +79,7 @@ contract StableTokenRegistry is Initializable, Ownable { if (index != newNumFiats) { fiatTickers[index] = fiatTickers[newNumFiats]; } - fiatTickers[newNumFiats] = ""; + delete fiatTickers[newNumFiats]; fiatTickers.length = newNumFiats; } From 882ad0071b2a6d58590ddf6bdb2954c4ab8fd505 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 22 Mar 2022 18:35:12 +0100 Subject: [PATCH 037/164] tests for remove function complete --- packages/protocol/test/stability/stabletokenregistry.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 4e5e14577d3..43995cc4f0a 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -50,14 +50,12 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('removes from a big array', async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) await strc.removeStableToken(fiatTicker, 0) const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, [accounts[1]]) + assert.deepEqual(fiatTickers, []) }) it("doesn't remove an fiat ticker with the wrong index", async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) await assertRevert(strc.removeStableToken(fiatTicker, 1)) }) }) From b0a32d1c795c5db5a60fecf7beedaae3ba631d20 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 22 Mar 2022 18:58:16 +0100 Subject: [PATCH 038/164] test suit for adding contracts --- .../test/stability/stabletokenregistry.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 43995cc4f0a..d20b503b6e7 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -59,4 +59,26 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.removeStableToken(fiatTicker, 1)) }) }) + + describe('#addNewStableToken(fiatTicker)', () => { + it('only allows owner', async () => { + await assertRevert( + strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) + ) + }) + + it('does not allow empty strings', async () => { + await assertRevert(strc.addNewStableToken(fiatTicker, '')) + await assertRevert(strc.addNewStableToken('', fiatTicker)) + await assertRevert(strc.addNewStableToken('', '')) + }) + + it('has the right list of fiat tickers after addition', async () => { + const spendersBeforeAdditions = await strc.getFiatTickers() + assert.deepEqual(spendersBeforeAdditions, []) + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, []) + }) + }) }) From 6ec5ee545d683621f21a800f837908dc4824e814 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 16:00:13 +0100 Subject: [PATCH 039/164] tests pass --- .../protocol/test/stability/stabletokenregistry.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index d20b503b6e7..97760e3ce92 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -6,7 +6,7 @@ const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] - const fiatTicker: string = 'USD' + const fiatTicker: string = 'cUSD' const stableTokenContractName = 'StableToken' beforeEach(async () => { @@ -49,7 +49,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.removeStableToken(fiatTicker, 1)) }) - it('removes from a big array', async () => { + it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) const fiatTickers = await strc.getFiatTickers() assert.deepEqual(fiatTickers, []) @@ -74,11 +74,11 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('has the right list of fiat tickers after addition', async () => { - const spendersBeforeAdditions = await strc.getFiatTickers() - assert.deepEqual(spendersBeforeAdditions, []) + const fiatTickersBefore = await strc.getFiatTickers() + assert.deepEqual(fiatTickersBefore, []) await strc.addNewStableToken(fiatTicker, stableTokenContractName) const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, []) + assert.deepEqual(fiatTickers, ['cUSD']) }) }) }) From 678fb5019f2f616ea85fd5dc6d709704ac0a7821 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 16:08:57 +0100 Subject: [PATCH 040/164] adding more arguments to compare --- packages/protocol/test/stability/stabletokenregistry.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 97760e3ce92..0b3f60a1e35 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -35,9 +35,11 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('has the right list of fiat tickers after removing one', async () => { + await strc.addNewStableToken('cEUR', 'StableTokenEUR') + await strc.addNewStableToken('cBRL', 'StableTokenBRL') await strc.removeStableToken(fiatTicker, 0) const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, []) + assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) }) it("can't be removed twice", async () => { From f96cf8f38f0a191440e05d03e7d6e65debff8101 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 18:38:45 +0100 Subject: [PATCH 041/164] adding registry contract to the registry --- packages/protocol/lib/registry-utils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index d6dae2db095..c056536b354 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -38,12 +38,14 @@ export enum CeloContractName { StableTokenBRL = 'StableTokenBRL', TransferWhitelist = 'TransferWhitelist', Validators = 'Validators', + StableTokenRegistry = 'StableTokenRegistry', } export const usesRegistry = [ CeloContractName.Escrow, CeloContractName.Reserve, CeloContractName.StableToken, + CeloContractName.StableTokenRegistry ] export const hasEntryInRegistry: string[] = [ @@ -65,4 +67,5 @@ export const hasEntryInRegistry: string[] = [ CeloContractName.Reserve, CeloContractName.SortedOracles, CeloContractName.StableToken, + CeloContractName.StableTokenRegistry ] From 2076806a04b3e65d1fab0ab4f8b5aa71600b599c Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 20:11:09 +0100 Subject: [PATCH 042/164] registry migrations --- packages/protocol/migrations/26_stableToken_registry.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/protocol/migrations/26_stableToken_registry.ts diff --git a/packages/protocol/migrations/26_stableToken_registry.ts b/packages/protocol/migrations/26_stableToken_registry.ts new file mode 100644 index 00000000000..e69de29bb2d From 415e07a95cb22d551782352e0b15a4c011c03880 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 20:11:45 +0100 Subject: [PATCH 043/164] unsaved changes --- .../migrations/26_stableToken_registry.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/protocol/migrations/26_stableToken_registry.ts b/packages/protocol/migrations/26_stableToken_registry.ts index e69de29bb2d..0fe9b38657a 100644 --- a/packages/protocol/migrations/26_stableToken_registry.ts +++ b/packages/protocol/migrations/26_stableToken_registry.ts @@ -0,0 +1,20 @@ +/* tslint:disable:no-console */ +import { CeloContractName } from '@celo/protocol/lib/registry-utils' +import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' +import { config } from '@celo/protocol/migrationsConfig' +import { StableTokenRegistryInstance } from 'types' + +const initializeArgs = async (): Promise => { + return [ + config.StableTokenRegistry.existingFiatTickers, + config.StableTokenRegistry.existingStableTokenContractNames, + ] +} + +module.exports = deploymentForCoreContract( + web3, + artifacts, + CeloContractName.StableTokenRegistry, + initializeArgs, + async (StableTokenRegistry: StableTokenRegistryInstance) => {} +) From 4637ceed5ac2a0051e36b26e3c835c3db13e1e09 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Mar 2022 10:49:44 +0100 Subject: [PATCH 044/164] bug fixed in initialized and two more found it addnewstabletoken --- .../protocol/contracts/stability/StableTokenRegistry.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 343592852bf..9e5757609bd 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -37,7 +37,7 @@ contract StableTokenRegistry is Initializable, Ownable { ); _transferOwnership(msg.sender); for (uint256 i = 0; i < existingFiatTickers.length; i++) { - addNewStableToken(fiatTickers[i], existingFiatTickers[i]); + addNewStableToken(existingFiatTickers[i], existingStableTokenContractNames[i]); } } @@ -92,13 +92,13 @@ contract StableTokenRegistry is Initializable, Ownable { public onlyOwner { - registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); + // registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); require( bytes(stableTokenContractName).length != 0, "stableTokenContractName cant be an empty string" ); - require(bytes(stableTokens[fiatTicker]).length != 0, "This registry already exists"); + // require(bytes(stableTokens[fiatTicker]).length != 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } From 482c7f551a60fea460c8aeca36de12bbcffa1ff0 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Mar 2022 11:45:07 +0100 Subject: [PATCH 045/164] refactoring get contracts function --- .../stability/StableTokenRegistry.sol | 44 +++++---- packages/protocol/migrationsConfig.js | 4 + .../test/stability/stabletokenregistry.ts | 90 ++++++++++--------- 3 files changed, 76 insertions(+), 62 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 9e5757609bd..d51fcbb5086 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,5 +1,4 @@ pragma solidity ^0.5.13; -pragma experimental ABIEncoderV2; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; @@ -11,8 +10,8 @@ import "../common/interfaces/IRegistry.sol"; */ contract StableTokenRegistry is Initializable, Ownable { using SafeMath for uint256; - mapping(string => string) public stableTokens; - string[] public fiatTickers; + mapping(bytes => bytes) public stableTokens; + bytes[] public fiatTickers; IRegistry public registry; @@ -28,8 +27,8 @@ contract StableTokenRegistry is Initializable, Ownable { * @param existingStableTokenContractNames Collection of stable token smart contract names. */ function initialize( - string[] calldata existingFiatTickers, - string[] calldata existingStableTokenContractNames + bytes32[] calldata existingFiatTickers, + bytes32[] calldata existingStableTokenContractNames ) external initializer { require( existingFiatTickers.length == existingStableTokenContractNames.length, @@ -37,28 +36,37 @@ contract StableTokenRegistry is Initializable, Ownable { ); _transferOwnership(msg.sender); for (uint256 i = 0; i < existingFiatTickers.length; i++) { - addNewStableToken(existingFiatTickers[i], existingStableTokenContractNames[i]); + addNewStableToken( + string(abi.encodePacked(existingFiatTickers[i])), + string(abi.encodePacked(existingStableTokenContractNames[i])) + ); } } - /** - * @notice Returns fiat currencies that have been issued. - * @return A collection of currencies issued. - */ - function getFiatTickers() external view returns (string[] memory) { - return fiatTickers; - } - /** * @notice Returns all the contract instances created. * @return collection of stable token contracts. */ - function getContractInstances() external view returns (string[] memory) { - string[] memory contracts; + function getContractInstances() external view returns (bytes memory, uint256[] memory) { + bytes[] memory contracts; + uint256 totalLength = 0; for (uint256 i = 0; i < fiatTickers.length; i++) { contracts[i] = stableTokens[fiatTickers[i]]; + totalLength += stableTokens[fiatTickers[i]].length; + } + uint256 numOfContracts = contracts.length; + bytes memory concatenated = new bytes(totalLength); + uint256 lastIndex = 0; + uint256[] memory lengths = new uint256[](numOfContracts); + for (uint256 i = 0; i < numOfContracts; i++) { + bytes storage contractName = stableTokens[fiatTickers[i]]; + lengths[i] = contractName.length; + for (uint256 j = 0; j < lengths[i]; j++) { + concatenated[lastIndex] = contractName[j]; + lastIndex++; + } } - return contracts; + return (concatenated, lengths); } /** @@ -71,7 +79,7 @@ contract StableTokenRegistry is Initializable, Ownable { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require( - keccak256(bytes(fiatTicker)) == keccak256(bytes(fiatTickers[index])), + keccak256(bytes(fiatTicker)) == keccak256(bytes(abi.encodePacked(fiatTickers[index]))), "Index does not match fiatTicker" ); uint256 newNumFiats = numFiats.sub(1); diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index 6df3ee5d3f2..41e8070fdf2 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -238,6 +238,10 @@ const DefaultConfig = { commission: 0.1, votesRatioOfLastVsFirstGroup: 2.0, }, + stableTokenRegistry: { + existingFiatTickers: ['cUSD', 'cEUR', 'cBRL'], + existingStableTokenContractNames: ['StableToken', 'StableTokenEUR', 'StableTokenBRL'], + }, } const NetworkConfigs = { diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 0b3f60a1e35..e54ee43cf87 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -26,61 +26,63 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) describe('#removeStableToken(fiatTicker)', () => { - beforeEach(async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) - }) + // beforeEach(async () => { + // await strc.addNewStableToken(fiatTicker, stableTokenContractName) + // }) it('only allows owner', async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) await assertRevert(strc.removeStableToken(fiatTicker, 0, { from: nonOwner })) }) - it('has the right list of fiat tickers after removing one', async () => { - await strc.addNewStableToken('cEUR', 'StableTokenEUR') - await strc.addNewStableToken('cBRL', 'StableTokenBRL') - await strc.removeStableToken(fiatTicker, 0) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) - }) + // it('has the right list of fiat tickers after removing one', async () => { + // await strc.addNewStableToken('cEUR', 'StableTokenEUR') + // await strc.addNewStableToken('cBRL', 'StableTokenBRL') + // await strc.removeStableToken(fiatTicker, 0) + // const fiatTickers = await strc.getFiatTickers() + // assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) + // }) - it("can't be removed twice", async () => { - await strc.removeStableToken(fiatTicker, 0) - await assertRevert(strc.removeStableToken(fiatTicker, 0)) - }) + // it("can't be removed twice", async () => { + // await strc.removeStableToken(fiatTicker, 0) + // await assertRevert(strc.removeStableToken(fiatTicker, 0)) + // }) - it("can't delete an index out of range", async () => { - await assertRevert(strc.removeStableToken(fiatTicker, 1)) - }) + // it("can't delete an index out of range", async () => { + // await assertRevert(strc.removeStableToken(fiatTicker, 1)) + // }) - it('removes from fiatTickers array', async () => { - await strc.removeStableToken(fiatTicker, 0) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, []) - }) + // it('removes from fiatTickers array', async () => { + // await strc.removeStableToken(fiatTicker, 0) + // const fiatTickers = await strc.getFiatTickers() + // assert.deepEqual(fiatTickers, []) + // }) - it("doesn't remove an fiat ticker with the wrong index", async () => { - await assertRevert(strc.removeStableToken(fiatTicker, 1)) - }) - }) + // it("doesn't remove an fiat ticker with the wrong index", async () => { + // await assertRevert(strc.removeStableToken(fiatTicker, 1)) + // }) + // }) - describe('#addNewStableToken(fiatTicker)', () => { - it('only allows owner', async () => { - await assertRevert( - strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) - ) - }) + // describe('#addNewStableToken(fiatTicker)', () => { + // it('only allows owner', async () => { + // await assertRevert( + // strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) + // ) + // }) - it('does not allow empty strings', async () => { - await assertRevert(strc.addNewStableToken(fiatTicker, '')) - await assertRevert(strc.addNewStableToken('', fiatTicker)) - await assertRevert(strc.addNewStableToken('', '')) - }) + // it('does not allow empty strings', async () => { + // await assertRevert(strc.addNewStableToken(fiatTicker, '')) + // await assertRevert(strc.addNewStableToken('', fiatTicker)) + // await assertRevert(strc.addNewStableToken('', '')) + // }) - it('has the right list of fiat tickers after addition', async () => { - const fiatTickersBefore = await strc.getFiatTickers() - assert.deepEqual(fiatTickersBefore, []) - await strc.addNewStableToken(fiatTicker, stableTokenContractName) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, ['cUSD']) - }) + // it('has the right list of fiat tickers after addition', async () => { + // const fiatTickersBefore = await strc.getFiatTickers() + // assert.deepEqual(fiatTickersBefore, []) + // await strc.addNewStableToken(fiatTicker, stableTokenContractName) + // await strc.addNewStableToken('cEUR', 'StableTokenEUR') + // const fiatTickers = await strc.getFiatTickers() + // assert.deepEqual(fiatTickers, ['cUSD', 'cEUR']) + // }) }) }) From f7d44ce218b7539531298fd0268b3be773b0afed Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Mar 2022 13:58:03 +0100 Subject: [PATCH 046/164] converted to bytes and contract compiles --- .../contracts/stability/StableTokenRegistry.sol | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index d51fcbb5086..edf12e06d7e 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -37,8 +37,8 @@ contract StableTokenRegistry is Initializable, Ownable { _transferOwnership(msg.sender); for (uint256 i = 0; i < existingFiatTickers.length; i++) { addNewStableToken( - string(abi.encodePacked(existingFiatTickers[i])), - string(abi.encodePacked(existingStableTokenContractNames[i])) + abi.encodePacked(existingFiatTickers[i]), + abi.encodePacked(existingStableTokenContractNames[i]) ); } } @@ -74,12 +74,12 @@ contract StableTokenRegistry is Initializable, Ownable { * @param fiatTicker The currency that is no longer supported. * @param index The index in fiatTickers of fiatTicker. */ - function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { - stableTokens[fiatTicker] = ""; + function removeStableToken(bytes calldata fiatTicker, uint256 index) external onlyOwner { + delete stableTokens[fiatTicker]; uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require( - keccak256(bytes(fiatTicker)) == keccak256(bytes(abi.encodePacked(fiatTickers[index]))), + keccak256(fiatTicker) == keccak256(fiatTickers[index]), "Index does not match fiatTicker" ); uint256 newNumFiats = numFiats.sub(1); @@ -96,7 +96,7 @@ contract StableTokenRegistry is Initializable, Ownable { * @param fiatTicker The currency we are trying to add in the registry. * @param stableTokenContractName The contract we are trying to add in the registry. */ - function addNewStableToken(string memory fiatTicker, string memory stableTokenContractName) + function addNewStableToken(bytes memory fiatTicker, bytes memory stableTokenContractName) public onlyOwner { @@ -110,5 +110,4 @@ contract StableTokenRegistry is Initializable, Ownable { stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } - } From f92baa9a3859b72c01d4d5b7fbec2e18bf36dcd6 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Mar 2022 14:35:46 +0100 Subject: [PATCH 047/164] initialize function added to tests --- .../test/stability/stabletokenregistry.ts | 119 +++++++++--------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index e54ee43cf87..f110b67462d 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,17 +1,24 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' +// import { keccak256 } from 'web3-utils' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') +const convertToHex = (input: string) => { + return web3.utils.utf8ToHex(input) +} + contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] - const fiatTicker: string = 'cUSD' - const stableTokenContractName = 'StableToken' + const fiatTicker: string = convertToHex('cBRL') + const stableTokenContractName = convertToHex('StableTokenBRL') + const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] + const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] beforeEach(async () => { strc = await STRC.new(true) - await strc.initialize([], []) + await strc.initialize(fiatTickers, stableTokenContractNames) }) describe('#initialize()', async () => { @@ -21,68 +28,68 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('should not be callable again', async () => { - await assertRevert(strc.initialize([], [])) + await assertRevert(strc.initialize(fiatTickers, stableTokenContractNames)) }) }) describe('#removeStableToken(fiatTicker)', () => { - // beforeEach(async () => { - // await strc.addNewStableToken(fiatTicker, stableTokenContractName) - // }) + beforeEach(async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + }) it('only allows owner', async () => { await strc.addNewStableToken(fiatTicker, stableTokenContractName) await assertRevert(strc.removeStableToken(fiatTicker, 0, { from: nonOwner })) }) - // it('has the right list of fiat tickers after removing one', async () => { - // await strc.addNewStableToken('cEUR', 'StableTokenEUR') - // await strc.addNewStableToken('cBRL', 'StableTokenBRL') - // await strc.removeStableToken(fiatTicker, 0) - // const fiatTickers = await strc.getFiatTickers() - // assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) - // }) - - // it("can't be removed twice", async () => { - // await strc.removeStableToken(fiatTicker, 0) - // await assertRevert(strc.removeStableToken(fiatTicker, 0)) - // }) - - // it("can't delete an index out of range", async () => { - // await assertRevert(strc.removeStableToken(fiatTicker, 1)) - // }) - - // it('removes from fiatTickers array', async () => { - // await strc.removeStableToken(fiatTicker, 0) - // const fiatTickers = await strc.getFiatTickers() - // assert.deepEqual(fiatTickers, []) - // }) - - // it("doesn't remove an fiat ticker with the wrong index", async () => { - // await assertRevert(strc.removeStableToken(fiatTicker, 1)) - // }) - // }) - - // describe('#addNewStableToken(fiatTicker)', () => { - // it('only allows owner', async () => { - // await assertRevert( - // strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) - // ) - // }) - - // it('does not allow empty strings', async () => { - // await assertRevert(strc.addNewStableToken(fiatTicker, '')) - // await assertRevert(strc.addNewStableToken('', fiatTicker)) - // await assertRevert(strc.addNewStableToken('', '')) - // }) - - // it('has the right list of fiat tickers after addition', async () => { - // const fiatTickersBefore = await strc.getFiatTickers() - // assert.deepEqual(fiatTickersBefore, []) - // await strc.addNewStableToken(fiatTicker, stableTokenContractName) - // await strc.addNewStableToken('cEUR', 'StableTokenEUR') - // const fiatTickers = await strc.getFiatTickers() - // assert.deepEqual(fiatTickers, ['cUSD', 'cEUR']) - // }) + it('has the right list of fiat tickers after removing one', async () => { + await strc.addNewStableToken('cEUR', 'StableTokenEUR') + await strc.addNewStableToken('cBRL', 'StableTokenBRL') + await strc.removeStableToken(fiatTicker, 0) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) + }) + + it("can't be removed twice", async () => { + await strc.removeStableToken(fiatTicker, 0) + await assertRevert(strc.removeStableToken(fiatTicker, 0)) + }) + + it("can't delete an index out of range", async () => { + await assertRevert(strc.removeStableToken(fiatTicker, 1)) + }) + + it('removes from fiatTickers array', async () => { + await strc.removeStableToken(fiatTicker, 0) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, []) + }) + + it("doesn't remove an fiat ticker with the wrong index", async () => { + await assertRevert(strc.removeStableToken(fiatTicker, 1)) + }) + }) + + describe('#addNewStableToken(fiatTicker)', () => { + it('only allows owner', async () => { + await assertRevert( + strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) + ) + }) + + it('does not allow empty strings', async () => { + await assertRevert(strc.addNewStableToken(fiatTicker, '')) + await assertRevert(strc.addNewStableToken('', fiatTicker)) + await assertRevert(strc.addNewStableToken('', '')) + }) + + it('has the right list of fiat tickers after addition', async () => { + const fiatTickersBefore = await strc.getFiatTickers() + assert.deepEqual(fiatTickersBefore, []) + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + await strc.addNewStableToken('cEUR', 'StableTokenEUR') + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, ['cUSD', 'cEUR']) + }) }) }) From 9597488b8d0ac6a3da514e39b148c78fe8fdb6a2 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 29 Mar 2022 12:07:03 +0200 Subject: [PATCH 048/164] 8 tests pass, refactoring the contract --- .../stability/StableTokenRegistry.sol | 4 +- .../test/stability/stabletokenregistry.ts | 69 ++++++++++++------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index edf12e06d7e..827f684c40b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -80,7 +80,7 @@ contract StableTokenRegistry is Initializable, Ownable { require(index < numFiats, "Index is invalid"); require( keccak256(fiatTicker) == keccak256(fiatTickers[index]), - "Index does not match fiatTicker" + "Source fiatTicker does not match the one in the storage on given index" ); uint256 newNumFiats = numFiats.sub(1); @@ -106,7 +106,7 @@ contract StableTokenRegistry is Initializable, Ownable { bytes(stableTokenContractName).length != 0, "stableTokenContractName cant be an empty string" ); - // require(bytes(stableTokens[fiatTicker]).length != 0, "This registry already exists"); + require(stableTokens[fiatTicker].length == 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index f110b67462d..ce2850af765 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,6 +1,5 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' -// import { keccak256 } from 'web3-utils' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') @@ -12,10 +11,24 @@ contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] - const fiatTicker: string = convertToHex('cBRL') - const stableTokenContractName = convertToHex('StableTokenBRL') + const fiatTicker: string = convertToHex('cUSD') + const stableTokenContractName = convertToHex('StableToken') const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] + + const getFiatTickers = async () => { + const updatedFiatTickers = [] + for (let i = 0; i < 180; i++) { + try { + updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(i))) + } catch (error) { + console.log(error) + break + } + } + return updatedFiatTickers + } + beforeEach(async () => { strc = await STRC.new(true) await strc.initialize(fiatTickers, stableTokenContractNames) @@ -34,7 +47,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { describe('#removeStableToken(fiatTicker)', () => { beforeEach(async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) + await strc.addNewStableToken(convertToHex('cBRL'), convertToHex('StableTokenBRL')) }) it('only allows owner', async () => { @@ -43,30 +56,35 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('has the right list of fiat tickers after removing one', async () => { - await strc.addNewStableToken('cEUR', 'StableTokenEUR') - await strc.addNewStableToken('cBRL', 'StableTokenBRL') + await strc.addNewStableToken(fiatTicker, stableTokenContractName) await strc.removeStableToken(fiatTicker, 0) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) + const updatedFiatTickers = await getFiatTickers() + assert.deepEqual(updatedFiatTickers, ['cEUR', 'cBRL']) }) + // it('has the right list of contract names after removing one', async () => { + // await strc.addNewStableToken(fiatTicker, stableTokenContractName) + // await strc.removeStableToken(fiatTicker, 0) + // const updatedContractNames = strc.getContractInstances(); + // }) + it("can't be removed twice", async () => { - await strc.removeStableToken(fiatTicker, 0) - await assertRevert(strc.removeStableToken(fiatTicker, 0)) + await strc.removeStableToken(convertToHex('cUSD'), 0) + await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 0)) }) it("can't delete an index out of range", async () => { - await assertRevert(strc.removeStableToken(fiatTicker, 1)) + await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) }) it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, []) + const updatedFiatTickers = await getFiatTickers() + assert.deepEqual(updatedFiatTickers, []) }) it("doesn't remove an fiat ticker with the wrong index", async () => { - await assertRevert(strc.removeStableToken(fiatTicker, 1)) + await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) }) }) @@ -78,18 +96,23 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('does not allow empty strings', async () => { - await assertRevert(strc.addNewStableToken(fiatTicker, '')) - await assertRevert(strc.addNewStableToken('', fiatTicker)) - await assertRevert(strc.addNewStableToken('', '')) + await assertRevert(strc.addNewStableToken(fiatTicker, convertToHex(''))) + await assertRevert(strc.addNewStableToken(convertToHex(''), fiatTicker)) + await assertRevert(strc.addNewStableToken(convertToHex(''), convertToHex(''))) }) it('has the right list of fiat tickers after addition', async () => { - const fiatTickersBefore = await strc.getFiatTickers() - assert.deepEqual(fiatTickersBefore, []) - await strc.addNewStableToken(fiatTicker, stableTokenContractName) - await strc.addNewStableToken('cEUR', 'StableTokenEUR') - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, ['cUSD', 'cEUR']) + const fiatTickersBefore = await getFiatTickers() + assert.deepEqual(fiatTickersBefore, ['cUSD', 'cEUR']) + await strc.addNewStableToken(convertToHex('cBRL'), convertToHex('StableTokenEUR')) + const updatedFiatTickers = await getFiatTickers() + assert.deepEqual(updatedFiatTickers, ['cUSD', 'cEUR', 'cBRL']) }) }) + + // it('has no duplicates', async () => { + // console.log('yay') + // console.log(await getFiatTickers); + // await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) + // }) }) From 86608d50c574f331b9a3228779b591ba1574f89e Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 29 Mar 2022 16:09:55 +0200 Subject: [PATCH 049/164] latest --- .../stability/StableTokenRegistry.sol | 21 +++++++++++-------- .../test/stability/stabletokenregistry.ts | 15 ++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 827f684c40b..85bf2439d3c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -78,10 +78,16 @@ contract StableTokenRegistry is Initializable, Ownable { delete stableTokens[fiatTicker]; uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); - require( - keccak256(fiatTicker) == keccak256(fiatTickers[index]), - "Source fiatTicker does not match the one in the storage on given index" - ); + // require(fiatTicker.length == fiatTickers[index].length, "mismatch in length"); + for (uint256 i = 0; i < fiatTicker.length; i++) { + for (uint256 j = 0; j < fiatTickers[index].length; j++) { + require(fiatTicker[i] == fiatTickers[index][i]); + } + } + // require( + // keccak256(abi.encodePacked(fiatTicker)) == keccak256(abi.encodePacked(fiatTickers[index])), + // "Source fiatTicker does not match the one in the storage on given index" + // ); uint256 newNumFiats = numFiats.sub(1); if (index != newNumFiats) { @@ -101,11 +107,8 @@ contract StableTokenRegistry is Initializable, Ownable { onlyOwner { // registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); - require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); - require( - bytes(stableTokenContractName).length != 0, - "stableTokenContractName cant be an empty string" - ); + require(fiatTicker.length != 0, "fiatTicker cant be an empty string"); + require(stableTokenContractName.length != 0, "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker].length == 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index ce2850af765..2ff9305b6f5 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -56,10 +56,9 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('has the right list of fiat tickers after removing one', async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, ['cEUR', 'cBRL']) + assert.deepEqual(updatedFiatTickers, ['cBRL', 'cEUR']) }) // it('has the right list of contract names after removing one', async () => { @@ -80,7 +79,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, []) + assert.deepEqual(updatedFiatTickers, ['cBRL', 'cEUR']) }) it("doesn't remove an fiat ticker with the wrong index", async () => { @@ -101,6 +100,10 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.addNewStableToken(convertToHex(''), convertToHex(''))) }) + it('does not allow duplicate values', async () => { + await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) + }) + it('has the right list of fiat tickers after addition', async () => { const fiatTickersBefore = await getFiatTickers() assert.deepEqual(fiatTickersBefore, ['cUSD', 'cEUR']) @@ -109,10 +112,4 @@ contract('StableTokenRegistry', (accounts: string[]) => { assert.deepEqual(updatedFiatTickers, ['cUSD', 'cEUR', 'cBRL']) }) }) - - // it('has no duplicates', async () => { - // console.log('yay') - // console.log(await getFiatTickers); - // await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) - // }) }) From 985860fa176889260d8d9e803cb07b607c0fb499 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 29 Mar 2022 19:07:37 +0200 Subject: [PATCH 050/164] fixing bugs --- .../contracts/stability/StableTokenRegistry.sol | 12 +++++------- .../protocol/test/stability/stabletokenregistry.ts | 8 +++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 85bf2439d3c..8346aeddfcc 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -78,16 +78,14 @@ contract StableTokenRegistry is Initializable, Ownable { delete stableTokens[fiatTicker]; uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); - // require(fiatTicker.length == fiatTickers[index].length, "mismatch in length"); for (uint256 i = 0; i < fiatTicker.length; i++) { - for (uint256 j = 0; j < fiatTickers[index].length; j++) { - require(fiatTicker[i] == fiatTickers[index][i]); + if (fiatTicker[i] != 0) { + require( + fiatTicker[i] == fiatTickers[index][i], + "source doesn't match the existing fiatTicker" + ); } } - // require( - // keccak256(abi.encodePacked(fiatTicker)) == keccak256(abi.encodePacked(fiatTickers[index])), - // "Source fiatTicker does not match the one in the storage on given index" - // ); uint256 newNumFiats = numFiats.sub(1); if (index != newNumFiats) { diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 2ff9305b6f5..a868feef1c9 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -22,11 +22,9 @@ contract('StableTokenRegistry', (accounts: string[]) => { try { updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(i))) } catch (error) { - console.log(error) - break + return updatedFiatTickers } } - return updatedFiatTickers } beforeEach(async () => { @@ -85,6 +83,10 @@ contract('StableTokenRegistry', (accounts: string[]) => { it("doesn't remove an fiat ticker with the wrong index", async () => { await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) }) + + it('reverts if a wrong values is passed as a fiatTicker', async () => { + await assertRevert(strc.removeStableToken(convertToHex('cEUR'), 0)) + }) }) describe('#addNewStableToken(fiatTicker)', () => { From 7345da38752d40623b67f209e70ccce0ccd2cb06 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 31 Mar 2022 19:44:58 +0200 Subject: [PATCH 051/164] =?UTF-8?q?everything=20works=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stability/StableTokenRegistry.sol | 47 +++++++----- .../test/stability/stabletokenregistry.ts | 71 ++++++++++++------- 2 files changed, 77 insertions(+), 41 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 8346aeddfcc..f700452fc84 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -4,6 +4,7 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; import "../common/interfaces/IRegistry.sol"; +import "../common/UsingRegistry.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. @@ -23,24 +24,28 @@ contract StableTokenRegistry is Initializable, Ownable { /** * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. - * @param existingFiatTickers Collection of fiat currencies issued already. - * @param existingStableTokenContractNames Collection of stable token smart contract names. + * @param fiatTicker Collection of fiat currencies issued already. + * @param stableTokenContractName Collection of stable token smart contract names. */ - function initialize( - bytes32[] calldata existingFiatTickers, - bytes32[] calldata existingStableTokenContractNames - ) external initializer { - require( - existingFiatTickers.length == existingStableTokenContractNames.length, - "Array length mismatch" - ); + function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) + external + initializer + { + // require( + // existingFiatTickers.length == existingStableTokenContractNames.length, + // "Array length mismatch" + // ); _transferOwnership(msg.sender); - for (uint256 i = 0; i < existingFiatTickers.length; i++) { - addNewStableToken( - abi.encodePacked(existingFiatTickers[i]), - abi.encodePacked(existingStableTokenContractNames[i]) - ); - } + bytes memory USD = bytes("USD"); + bytes memory StableToken = "537461626c65546f6b656e"; + bytes memory EUR = "455552"; + bytes memory StableTokenEUR = "537461626c65546f6b656e455552"; + bytes memory BRL = "42524c"; + bytes memory StableTokenBRL = "537461626c65546f6b656e42524c"; + addNewStableToken(bytes("USD"), bytes("StableToken")); + addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); + addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); + addNewStableToken(fiatTicker, stableTokenContractName); } /** @@ -111,4 +116,14 @@ contract StableTokenRegistry is Initializable, Ownable { stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } + + // TODO make function that inputs fiatTicker and returns a StableTokenContract + + /** + * @notice Adds new Fiat Ticker and Stable Token contract to the registry. + * @param fiatTicker The currency we are trying to add in the registry. + */ + function getFiatTickerLength(bytes memory fiatTicker) public returns (bytes memory) { + return stableTokens[fiatTicker]; + } } diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index a868feef1c9..439e38593f8 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,35 +1,57 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' + + const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') +// const Registry: RegistryContract = artifacts.require('Registry') + const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) } +// const assertSTContractNames = (contractsHex: string, lengths: BigNumber[], expectedContracts: string[]) => { +// assert.equal(lengths.length, expectedContracts.length) +// const contracts = web3.utils.hexToUtf8(contractsHex) +// let currentIndex = 0 +// expectedContracts.forEach((expectedContract: string, i: number) => { +// const contract = contracts.slice(currentIndex, currentIndex + lengths[i].toNumber()) +// currentIndex += lengths[i].toNumber() +// assert.equal(contract, expectedContract) +// }) +// assert.equal(contracts.length, currentIndex) +// } + + contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] - const fiatTicker: string = convertToHex('cUSD') + const fiatTicker: string = convertToHex('USD') const stableTokenContractName = convertToHex('StableToken') - const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] - const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] + // const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] + // const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] const getFiatTickers = async () => { const updatedFiatTickers = [] - for (let i = 0; i < 180; i++) { - try { - updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(i))) + try + { + let index = 0 + while (await strc.fiatTickers(index)) { + updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(index))) + index++ + } } catch (error) { return updatedFiatTickers - } } } beforeEach(async () => { strc = await STRC.new(true) - await strc.initialize(fiatTickers, stableTokenContractNames) + // const registry = await Registry.new(true) + // await registry.setAddressFor(CeloContractName.StableTokenRegistry, strc.address) + await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL')) }) describe('#initialize()', async () => { @@ -39,53 +61,52 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('should not be callable again', async () => { - await assertRevert(strc.initialize(fiatTickers, stableTokenContractNames)) + await assertRevert(strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'))) }) }) describe('#removeStableToken(fiatTicker)', () => { beforeEach(async () => { - await strc.addNewStableToken(convertToHex('cBRL'), convertToHex('StableTokenBRL')) + await strc.addNewStableToken(convertToHex('GBP'), convertToHex('StableTokenGBP')) }) it('only allows owner', async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) await assertRevert(strc.removeStableToken(fiatTicker, 0, { from: nonOwner })) }) it('has the right list of fiat tickers after removing one', async () => { await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, ['cBRL', 'cEUR']) + assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) // it('has the right list of contract names after removing one', async () => { - // await strc.addNewStableToken(fiatTicker, stableTokenContractName) - // await strc.removeStableToken(fiatTicker, 0) - // const updatedContractNames = strc.getContractInstances(); + // await strc.removeStableToken(fiatTicker, 0) + // const [contractsHex, lengths] = await strc.getContractInstances() + // assertSTContractNames(contractsHex, lengths, []) // }) it("can't be removed twice", async () => { - await strc.removeStableToken(convertToHex('cUSD'), 0) - await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 0)) + await strc.removeStableToken(convertToHex('USD'), 0) + await assertRevert(strc.removeStableToken(convertToHex('USD'), 0)) }) it("can't delete an index out of range", async () => { - await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) + await assertRevert(strc.removeStableToken(convertToHex('USD'), 1)) }) it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, ['cBRL', 'cEUR']) + assert.deepEqual(updatedFiatTickers, [ 'GBP', 'EUR', 'BRL', 'GEL' ]) }) it("doesn't remove an fiat ticker with the wrong index", async () => { - await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) + await assertRevert(strc.removeStableToken(convertToHex('USD'), 1)) }) it('reverts if a wrong values is passed as a fiatTicker', async () => { - await assertRevert(strc.removeStableToken(convertToHex('cEUR'), 0)) + await assertRevert(strc.removeStableToken(convertToHex('EUR'), 0)) }) }) @@ -101,17 +122,17 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.addNewStableToken(convertToHex(''), fiatTicker)) await assertRevert(strc.addNewStableToken(convertToHex(''), convertToHex(''))) }) - + it('does not allow duplicate values', async () => { await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) }) it('has the right list of fiat tickers after addition', async () => { const fiatTickersBefore = await getFiatTickers() - assert.deepEqual(fiatTickersBefore, ['cUSD', 'cEUR']) - await strc.addNewStableToken(convertToHex('cBRL'), convertToHex('StableTokenEUR')) + assert.deepEqual(fiatTickersBefore, ['USD', 'EUR', 'BRL', 'GEL']) + await strc.addNewStableToken(convertToHex('MXN'), convertToHex('StableTokenMXN')) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, ['cUSD', 'cEUR', 'cBRL']) + assert.deepEqual(updatedFiatTickers, ['USD', 'EUR', 'BRL', 'GEL', 'MXN']) }) }) }) From 94e9d0b200b5559b0e7a1eed69606f57cc27a8ff Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Sat, 2 Apr 2022 17:20:21 +0200 Subject: [PATCH 052/164] added a contraxt query function + tests --- .../stability/StableTokenRegistry.sol | 8 +-- .../test/stability/stabletokenregistry.ts | 61 +++++++++++-------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index f700452fc84..aed705fb763 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -117,13 +117,11 @@ contract StableTokenRegistry is Initializable, Ownable { fiatTickers.push(fiatTicker); } - // TODO make function that inputs fiatTicker and returns a StableTokenContract - /** - * @notice Adds new Fiat Ticker and Stable Token contract to the registry. - * @param fiatTicker The currency we are trying to add in the registry. + * @notice Queries a corresponding StableToken contract name based on fiat ticker. + * @param fiatTicker Type of currency to query corresponding contract. */ - function getFiatTickerLength(bytes memory fiatTicker) public returns (bytes memory) { + function queryStableTokenContractNames(bytes memory fiatTicker) public returns (bytes memory) { return stableTokens[fiatTicker]; } } diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 439e38593f8..9e273cd9822 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,28 +1,30 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' +import BigNumber from 'bignumber.js' import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' - - const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') -// const Registry: RegistryContract = artifacts.require('Registry') +// const Registry: RegistryContract = artifacts.require('Registry') const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) } -// const assertSTContractNames = (contractsHex: string, lengths: BigNumber[], expectedContracts: string[]) => { -// assert.equal(lengths.length, expectedContracts.length) -// const contracts = web3.utils.hexToUtf8(contractsHex) -// let currentIndex = 0 -// expectedContracts.forEach((expectedContract: string, i: number) => { -// const contract = contracts.slice(currentIndex, currentIndex + lengths[i].toNumber()) -// currentIndex += lengths[i].toNumber() -// assert.equal(contract, expectedContract) -// }) -// assert.equal(contracts.length, currentIndex) -// } - +const assertSTContractNames = ( + contractsHex: string, + lengths: BigNumber[], + expectedContracts: string[] +) => { + assert.equal(lengths.length, expectedContracts.length) + const contracts = web3.utils.hexToUtf8(contractsHex) + let currentIndex = 0 + expectedContracts.forEach((expectedContract: string, i: number) => { + const contract = contracts.slice(currentIndex, currentIndex + lengths[i].toNumber()) + currentIndex += lengths[i].toNumber() + assert.equal(contract, expectedContract) + }) + assert.equal(contracts.length, currentIndex) +} contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance @@ -35,15 +37,14 @@ contract('StableTokenRegistry', (accounts: string[]) => { const getFiatTickers = async () => { const updatedFiatTickers = [] - try - { + try { let index = 0 - while (await strc.fiatTickers(index)) { + while (await strc.fiatTickers(index)) { updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(index))) index++ - } - } catch (error) { - return updatedFiatTickers + } + } catch (error) { + return updatedFiatTickers } } @@ -81,9 +82,12 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) // it('has the right list of contract names after removing one', async () => { - // await strc.removeStableToken(fiatTicker, 0) + // console.log('yes') + // await strc.removeStableToken(fiatTicker, 0) + // console.log('works'); // const [contractsHex, lengths] = await strc.getContractInstances() - // assertSTContractNames(contractsHex, lengths, []) + // console.log(contractsHex, lengths); + // assertSTContractNames(contractsHex, lengths, ['StableTokenEUR', 'StableTokenBRL']) // }) it("can't be removed twice", async () => { @@ -98,7 +102,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, [ 'GBP', 'EUR', 'BRL', 'GEL' ]) + assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) it("doesn't remove an fiat ticker with the wrong index", async () => { @@ -122,7 +126,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.addNewStableToken(convertToHex(''), fiatTicker)) await assertRevert(strc.addNewStableToken(convertToHex(''), convertToHex(''))) }) - + it('does not allow duplicate values', async () => { await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) }) @@ -135,4 +139,11 @@ contract('StableTokenRegistry', (accounts: string[]) => { assert.deepEqual(updatedFiatTickers, ['USD', 'EUR', 'BRL', 'GEL', 'MXN']) }) }) + + describe('#queryStableTokenContractNames(fiatTicker)', () => { + it('returns the corresponfing contract name', async () => { + const queriedContract = await strc.queryStableTokenContractNames.call(fiatTicker) + assert.deepEqual(queriedContract, stableTokenContractName) + }) + }) }) From 864eb311ede89c7d70e547f8ed2d6cdfdb243d0b Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Sat, 2 Apr 2022 17:52:26 +0200 Subject: [PATCH 053/164] =?UTF-8?q?lists=20all=20the=20correct=20contract?= =?UTF-8?q?=20namea=20after=20adding=20and=20removing=20one=20=E2=9C=A8?= =?UTF-8?q?=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stability/StableTokenRegistry.sol | 15 ++-------- .../test/stability/stabletokenregistry.ts | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index aed705fb763..a12450b4036 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -31,17 +31,7 @@ contract StableTokenRegistry is Initializable, Ownable { external initializer { - // require( - // existingFiatTickers.length == existingStableTokenContractNames.length, - // "Array length mismatch" - // ); _transferOwnership(msg.sender); - bytes memory USD = bytes("USD"); - bytes memory StableToken = "537461626c65546f6b656e"; - bytes memory EUR = "455552"; - bytes memory StableTokenEUR = "537461626c65546f6b656e455552"; - bytes memory BRL = "42524c"; - bytes memory StableTokenBRL = "537461626c65546f6b656e42524c"; addNewStableToken(bytes("USD"), bytes("StableToken")); addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); @@ -53,13 +43,12 @@ contract StableTokenRegistry is Initializable, Ownable { * @return collection of stable token contracts. */ function getContractInstances() external view returns (bytes memory, uint256[] memory) { - bytes[] memory contracts; + // bytes[] memory contracts; uint256 totalLength = 0; for (uint256 i = 0; i < fiatTickers.length; i++) { - contracts[i] = stableTokens[fiatTickers[i]]; totalLength += stableTokens[fiatTickers[i]].length; } - uint256 numOfContracts = contracts.length; + uint256 numOfContracts = fiatTickers.length; bytes memory concatenated = new bytes(totalLength); uint256 lastIndex = 0; uint256[] memory lengths = new uint256[](numOfContracts); diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 9e273cd9822..99cf62dfc9c 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -81,14 +81,16 @@ contract('StableTokenRegistry', (accounts: string[]) => { assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) - // it('has the right list of contract names after removing one', async () => { - // console.log('yes') - // await strc.removeStableToken(fiatTicker, 0) - // console.log('works'); - // const [contractsHex, lengths] = await strc.getContractInstances() - // console.log(contractsHex, lengths); - // assertSTContractNames(contractsHex, lengths, ['StableTokenEUR', 'StableTokenBRL']) - // }) + it('has the right list of contract names after removing one', async () => { + await strc.removeStableToken(fiatTicker, 0) + const [contractsHex, lengths] = await strc.getContractInstances() + assertSTContractNames(contractsHex, lengths, [ + 'StableTokenGBP', + 'StableTokenEUR', + 'StableTokenBRL', + 'StableTokenGEL', + ]) + }) it("can't be removed twice", async () => { await strc.removeStableToken(convertToHex('USD'), 0) @@ -138,6 +140,18 @@ contract('StableTokenRegistry', (accounts: string[]) => { const updatedFiatTickers = await getFiatTickers() assert.deepEqual(updatedFiatTickers, ['USD', 'EUR', 'BRL', 'GEL', 'MXN']) }) + + it('has the right list of contract names after adding one', async () => { + await strc.addNewStableToken(convertToHex('MXN'), convertToHex('StableTokenMXN')) + const [contractsHex, lengths] = await strc.getContractInstances() + assertSTContractNames(contractsHex, lengths, [ + 'StableToken', + 'StableTokenEUR', + 'StableTokenBRL', + 'StableTokenGEL', + 'StableTokenMXN', + ]) + }) }) describe('#queryStableTokenContractNames(fiatTicker)', () => { From 5146180d1f3351936e9660f3e9c0e21e7cb87b05 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Sat, 2 Apr 2022 18:32:02 +0200 Subject: [PATCH 054/164] all functions are fully tested and work --- .../protocol/contracts/stability/StableTokenRegistry.sol | 1 - packages/protocol/test/stability/stabletokenregistry.ts | 6 ------ 2 files changed, 7 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index a12450b4036..1bc10a45a6d 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -43,7 +43,6 @@ contract StableTokenRegistry is Initializable, Ownable { * @return collection of stable token contracts. */ function getContractInstances() external view returns (bytes memory, uint256[] memory) { - // bytes[] memory contracts; uint256 totalLength = 0; for (uint256 i = 0; i < fiatTickers.length; i++) { totalLength += stableTokens[fiatTickers[i]].length; diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 99cf62dfc9c..78593715daf 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -4,8 +4,6 @@ import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') -// const Registry: RegistryContract = artifacts.require('Registry') - const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) } @@ -32,8 +30,6 @@ contract('StableTokenRegistry', (accounts: string[]) => { const fiatTicker: string = convertToHex('USD') const stableTokenContractName = convertToHex('StableToken') - // const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] - // const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] const getFiatTickers = async () => { const updatedFiatTickers = [] @@ -50,8 +46,6 @@ contract('StableTokenRegistry', (accounts: string[]) => { beforeEach(async () => { strc = await STRC.new(true) - // const registry = await Registry.new(true) - // await registry.setAddressFor(CeloContractName.StableTokenRegistry, strc.address) await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL')) }) From 2bbb87376244d019fd47ed1c0f363f6bcca75607 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 12:25:24 +0200 Subject: [PATCH 055/164] adding it to the registry --- .../contracts/stability/StableTokenRegistry.sol | 13 ++++++++----- .../protocol/test/stability/stabletokenregistry.ts | 13 ++++++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 1bc10a45a6d..2de7612197b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -9,7 +9,7 @@ import "../common/UsingRegistry.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ -contract StableTokenRegistry is Initializable, Ownable { +contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { using SafeMath for uint256; mapping(bytes => bytes) public stableTokens; bytes[] public fiatTickers; @@ -26,16 +26,19 @@ contract StableTokenRegistry is Initializable, Ownable { * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. * @param fiatTicker Collection of fiat currencies issued already. * @param stableTokenContractName Collection of stable token smart contract names. + * @param registryAddress The address of the registry core smart contract. */ - function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) - external - initializer - { + function initialize( + bytes calldata fiatTicker, + bytes calldata stableTokenContractName, + address registryAddress + ) external initializer { _transferOwnership(msg.sender); addNewStableToken(bytes("USD"), bytes("StableToken")); addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); addNewStableToken(fiatTicker, stableTokenContractName); + setRegistry(registryAddress); } /** diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 78593715daf..df83a19b7ad 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,8 +1,10 @@ +import { CeloContractName } from '@celo/protocol/lib/registry-utils' import { assertRevert } from '@celo/protocol/lib/test-utils' import BigNumber from 'bignumber.js' -import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' +import { RegistryContract, StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') +const Registry: RegistryContract = artifacts.require('Registry') const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) @@ -46,17 +48,22 @@ contract('StableTokenRegistry', (accounts: string[]) => { beforeEach(async () => { strc = await STRC.new(true) - await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL')) + const registry = await Registry.new(true) + await registry.setAddressFor(CeloContractName.Accounts, strc.address) + await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) }) describe('#initialize()', async () => { + const registry = await Registry.new(true) it('should have set the owner', async () => { const owner: string = await strc.owner() assert.equal(owner, accounts[0]) }) it('should not be callable again', async () => { - await assertRevert(strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'))) + await assertRevert( + strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) + ) }) }) From f4e083febea09526b74bf83fd4f75fdb0c957966 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 14:34:26 +0200 Subject: [PATCH 056/164] finished --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 1 - packages/protocol/migrations/26_stableToken_registry.ts | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 2de7612197b..cb5ea00c1ae 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -100,7 +100,6 @@ contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { public onlyOwner { - // registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); require(fiatTicker.length != 0, "fiatTicker cant be an empty string"); require(stableTokenContractName.length != 0, "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker].length == 0, "This registry already exists"); diff --git a/packages/protocol/migrations/26_stableToken_registry.ts b/packages/protocol/migrations/26_stableToken_registry.ts index 0fe9b38657a..0e95af2dae1 100644 --- a/packages/protocol/migrations/26_stableToken_registry.ts +++ b/packages/protocol/migrations/26_stableToken_registry.ts @@ -16,5 +16,6 @@ module.exports = deploymentForCoreContract( artifacts, CeloContractName.StableTokenRegistry, initializeArgs, - async (StableTokenRegistry: StableTokenRegistryInstance) => {} + // tslint:disable-next-line: no-empty + async (_StableTokenRegistry: StableTokenRegistryInstance) => {} ) From 25aeeb26fa08d247a3cf35ca8a10af53537ec675 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 15:38:12 +0200 Subject: [PATCH 057/164] fixed migrations --- ...26_stableToken_registry.ts => 27_stableToken_registry.ts} | 5 +---- packages/protocol/migrationsConfig.js | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) rename packages/protocol/migrations/{26_stableToken_registry.ts => 27_stableToken_registry.ts} (81%) diff --git a/packages/protocol/migrations/26_stableToken_registry.ts b/packages/protocol/migrations/27_stableToken_registry.ts similarity index 81% rename from packages/protocol/migrations/26_stableToken_registry.ts rename to packages/protocol/migrations/27_stableToken_registry.ts index 0e95af2dae1..a56431d7b2c 100644 --- a/packages/protocol/migrations/26_stableToken_registry.ts +++ b/packages/protocol/migrations/27_stableToken_registry.ts @@ -5,10 +5,7 @@ import { config } from '@celo/protocol/migrationsConfig' import { StableTokenRegistryInstance } from 'types' const initializeArgs = async (): Promise => { - return [ - config.StableTokenRegistry.existingFiatTickers, - config.StableTokenRegistry.existingStableTokenContractNames, - ] + return [config.stableTokenRegistry.fiatTicker, config.stableTokenRegistry.stableTokenContractName] } module.exports = deploymentForCoreContract( diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index 41e8070fdf2..f118131a758 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -239,8 +239,8 @@ const DefaultConfig = { votesRatioOfLastVsFirstGroup: 2.0, }, stableTokenRegistry: { - existingFiatTickers: ['cUSD', 'cEUR', 'cBRL'], - existingStableTokenContractNames: ['StableToken', 'StableTokenEUR', 'StableTokenBRL'], + fiatTicker: '0x474250', + stableTokenContractName: '0x537473626c65546f6b656e474250', }, } From e861d261f4547d573c75cea203036a7c6e4e31ee Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 16:11:31 +0200 Subject: [PATCH 058/164] amount of arguments in initialize error fixed --- packages/protocol/migrations/08_reserve.ts | 2 +- .../migrations/27_stableToken_registry.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/protocol/migrations/08_reserve.ts b/packages/protocol/migrations/08_reserve.ts index 686eab930f0..fd8b9d8fa00 100644 --- a/packages/protocol/migrations/08_reserve.ts +++ b/packages/protocol/migrations/08_reserve.ts @@ -21,7 +21,7 @@ const initializeArgs = async (): Promise< ) return [ registry.address, - config.reserve.tobinTaxStalenessThreshold, + config.reserve.tobinTaxStalenessThareshold, config.reserve.dailySpendingRatio, 0, // frozenGold cannot be set until the reserve us funded 0, // frozenGold cannot be set until the reserve us funded diff --git a/packages/protocol/migrations/27_stableToken_registry.ts b/packages/protocol/migrations/27_stableToken_registry.ts index a56431d7b2c..8a100ca5175 100644 --- a/packages/protocol/migrations/27_stableToken_registry.ts +++ b/packages/protocol/migrations/27_stableToken_registry.ts @@ -1,11 +1,22 @@ /* tslint:disable:no-console */ import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' +import { + deploymentForCoreContract, + getDeployedProxiedContract, +} from '@celo/protocol/lib/web3-utils' import { config } from '@celo/protocol/migrationsConfig' -import { StableTokenRegistryInstance } from 'types' +import { RegistryInstance, StableTokenRegistryInstance } from 'types' const initializeArgs = async (): Promise => { - return [config.stableTokenRegistry.fiatTicker, config.stableTokenRegistry.stableTokenContractName] + const registry: RegistryInstance = await getDeployedProxiedContract( + 'Registry', + artifacts + ) + return [ + config.stableTokenRegistry.fiatTicker, + config.stableTokenRegistry.stableTokenContractName, + registry.address, + ] } module.exports = deploymentForCoreContract( From 900617ad46bf78c6f0d0b9cae971bed58cf5f142 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 17:04:53 +0200 Subject: [PATCH 059/164] bug --- packages/protocol/test/stability/stabletokenregistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index df83a19b7ad..91438934c11 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -49,7 +49,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { beforeEach(async () => { strc = await STRC.new(true) const registry = await Registry.new(true) - await registry.setAddressFor(CeloContractName.Accounts, strc.address) + await registry.setAddressFor(CeloContractName.StableTokenRegistry, strc.address) await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) }) From d1995c85622c80de2e0e57d02e1f97de193f5cae Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 18:46:35 +0200 Subject: [PATCH 060/164] had an accidental type in reserve --- packages/protocol/migrations/08_reserve.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/migrations/08_reserve.ts b/packages/protocol/migrations/08_reserve.ts index fd8b9d8fa00..686eab930f0 100644 --- a/packages/protocol/migrations/08_reserve.ts +++ b/packages/protocol/migrations/08_reserve.ts @@ -21,7 +21,7 @@ const initializeArgs = async (): Promise< ) return [ registry.address, - config.reserve.tobinTaxStalenessThareshold, + config.reserve.tobinTaxStalenessThreshold, config.reserve.dailySpendingRatio, 0, // frozenGold cannot be set until the reserve us funded 0, // frozenGold cannot be set until the reserve us funded From 347e5316b00746cc91f328d3c44ce6a3990202f5 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 12 Apr 2022 16:19:16 +0200 Subject: [PATCH 061/164] migration tests pass --- .../protocol/contracts/stability/StableTokenRegistry.sol | 6 +++++- ...7_stableToken_registry.ts => 25_stableToken_registry.ts} | 4 +--- .../migrations/{25_governance.ts => 26_governance.ts} | 0 .../{26_elect_validators.ts => 27_elect_validators.ts} | 0 packages/protocol/migrationsConfig.js | 4 ++-- packages/protocol/test/common/accounts.ts | 3 +-- 6 files changed, 9 insertions(+), 8 deletions(-) rename packages/protocol/migrations/{27_stableToken_registry.ts => 25_stableToken_registry.ts} (86%) rename packages/protocol/migrations/{25_governance.ts => 26_governance.ts} (100%) rename packages/protocol/migrations/{26_elect_validators.ts => 27_elect_validators.ts} (100%) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index cb5ea00c1ae..778be0ba76f 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -111,7 +111,11 @@ contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { * @notice Queries a corresponding StableToken contract name based on fiat ticker. * @param fiatTicker Type of currency to query corresponding contract. */ - function queryStableTokenContractNames(bytes memory fiatTicker) public returns (bytes memory) { + function queryStableTokenContractNames(bytes memory fiatTicker) + public + view + returns (bytes memory) + { return stableTokens[fiatTicker]; } } diff --git a/packages/protocol/migrations/27_stableToken_registry.ts b/packages/protocol/migrations/25_stableToken_registry.ts similarity index 86% rename from packages/protocol/migrations/27_stableToken_registry.ts rename to packages/protocol/migrations/25_stableToken_registry.ts index 8a100ca5175..e366fd6e171 100644 --- a/packages/protocol/migrations/27_stableToken_registry.ts +++ b/packages/protocol/migrations/25_stableToken_registry.ts @@ -23,7 +23,5 @@ module.exports = deploymentForCoreContract( web3, artifacts, CeloContractName.StableTokenRegistry, - initializeArgs, - // tslint:disable-next-line: no-empty - async (_StableTokenRegistry: StableTokenRegistryInstance) => {} + initializeArgs ) diff --git a/packages/protocol/migrations/25_governance.ts b/packages/protocol/migrations/26_governance.ts similarity index 100% rename from packages/protocol/migrations/25_governance.ts rename to packages/protocol/migrations/26_governance.ts diff --git a/packages/protocol/migrations/26_elect_validators.ts b/packages/protocol/migrations/27_elect_validators.ts similarity index 100% rename from packages/protocol/migrations/26_elect_validators.ts rename to packages/protocol/migrations/27_elect_validators.ts diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index f118131a758..43f89d19a8c 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -239,8 +239,8 @@ const DefaultConfig = { votesRatioOfLastVsFirstGroup: 2.0, }, stableTokenRegistry: { - fiatTicker: '0x474250', - stableTokenContractName: '0x537473626c65546f6b656e474250', + fiatTicker: '0x494e52', // fiat ticker + stableTokenContractName: '0x537461626c65546f6b656e494e52', // stable token contract name }, } diff --git a/packages/protocol/test/common/accounts.ts b/packages/protocol/test/common/accounts.ts index 2ea8848a728..9c7f8577129 100644 --- a/packages/protocol/test/common/accounts.ts +++ b/packages/protocol/test/common/accounts.ts @@ -13,6 +13,7 @@ import { parseSolidityStringArray } from '@celo/utils/lib/parsing' import { authorizeSigner as buildAuthorizeSignerTypedData } from '@celo/utils/lib/typed-data-constructors' import { generateTypedDataHash } from '@celo/utils/src/sign-typed-data-utils' import { parseSignatureWithoutPrefix } from '@celo/utils/src/signatureUtils' +import BigNumber from 'bignumber.js' import { AccountsContract, AccountsInstance, @@ -22,8 +23,6 @@ import { } from 'types' import { keccak256 } from 'web3-utils' -import BigNumber from 'bignumber.js' - const Accounts: AccountsContract = artifacts.require('Accounts') const Registry: RegistryContract = artifacts.require('Registry') const MockValidators: MockValidatorsContract = artifacts.require('MockValidators') From 281708b1e8512a94576ffe39abad8aa81d4ee329 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 3 May 2022 21:36:27 +0200 Subject: [PATCH 062/164] one minor fix needed --- packages/protocol/lib/web3-utils.ts | 1 - packages/protocol/releaseData/initializationData/release9.json | 0 2 files changed, 1 deletion(-) create mode 100644 packages/protocol/releaseData/initializationData/release9.json diff --git a/packages/protocol/lib/web3-utils.ts b/packages/protocol/lib/web3-utils.ts index e082d6b300e..e77a6e300c0 100644 --- a/packages/protocol/lib/web3-utils.ts +++ b/packages/protocol/lib/web3-utils.ts @@ -132,7 +132,6 @@ export function randomUint256() { return BigNumber.random() .times(maxUint256) .integerValue() - .valueOf() } export function checkFunctionArgsLength(args: any[], abi: any) { diff --git a/packages/protocol/releaseData/initializationData/release9.json b/packages/protocol/releaseData/initializationData/release9.json new file mode 100644 index 00000000000..e69de29bb2d From 9a838813324cda7ae1efa7636e3f3107877c8a84 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 4 May 2022 14:35:57 +0200 Subject: [PATCH 063/164] removed from registry --- .../contracts/stability/StableTokenRegistry.sol | 11 ++++------- packages/protocol/lib/registry-utils.ts | 3 --- .../migrations/25_stableToken_registry.ts | 17 +++-------------- .../test/stability/stabletokenregistry.ts | 13 +++---------- 4 files changed, 10 insertions(+), 34 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 778be0ba76f..fc9c6d4909f 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -26,19 +26,16 @@ contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. * @param fiatTicker Collection of fiat currencies issued already. * @param stableTokenContractName Collection of stable token smart contract names. - * @param registryAddress The address of the registry core smart contract. */ - function initialize( - bytes calldata fiatTicker, - bytes calldata stableTokenContractName, - address registryAddress - ) external initializer { + function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) + external + initializer + { _transferOwnership(msg.sender); addNewStableToken(bytes("USD"), bytes("StableToken")); addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); addNewStableToken(fiatTicker, stableTokenContractName); - setRegistry(registryAddress); } /** diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index c056536b354..d6dae2db095 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -38,14 +38,12 @@ export enum CeloContractName { StableTokenBRL = 'StableTokenBRL', TransferWhitelist = 'TransferWhitelist', Validators = 'Validators', - StableTokenRegistry = 'StableTokenRegistry', } export const usesRegistry = [ CeloContractName.Escrow, CeloContractName.Reserve, CeloContractName.StableToken, - CeloContractName.StableTokenRegistry ] export const hasEntryInRegistry: string[] = [ @@ -67,5 +65,4 @@ export const hasEntryInRegistry: string[] = [ CeloContractName.Reserve, CeloContractName.SortedOracles, CeloContractName.StableToken, - CeloContractName.StableTokenRegistry ] diff --git a/packages/protocol/migrations/25_stableToken_registry.ts b/packages/protocol/migrations/25_stableToken_registry.ts index e366fd6e171..65c81e57561 100644 --- a/packages/protocol/migrations/25_stableToken_registry.ts +++ b/packages/protocol/migrations/25_stableToken_registry.ts @@ -1,22 +1,11 @@ /* tslint:disable:no-console */ import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { - deploymentForCoreContract, - getDeployedProxiedContract, -} from '@celo/protocol/lib/web3-utils' +import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' import { config } from '@celo/protocol/migrationsConfig' -import { RegistryInstance, StableTokenRegistryInstance } from 'types' +import { StableTokenRegistryInstance } from 'types' const initializeArgs = async (): Promise => { - const registry: RegistryInstance = await getDeployedProxiedContract( - 'Registry', - artifacts - ) - return [ - config.stableTokenRegistry.fiatTicker, - config.stableTokenRegistry.stableTokenContractName, - registry.address, - ] + return [config.stableTokenRegistry.fiatTicker, config.stableTokenRegistry.stableTokenContractName] } module.exports = deploymentForCoreContract( diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 91438934c11..78593715daf 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,10 +1,8 @@ -import { CeloContractName } from '@celo/protocol/lib/registry-utils' import { assertRevert } from '@celo/protocol/lib/test-utils' import BigNumber from 'bignumber.js' -import { RegistryContract, StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' +import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') -const Registry: RegistryContract = artifacts.require('Registry') const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) @@ -48,22 +46,17 @@ contract('StableTokenRegistry', (accounts: string[]) => { beforeEach(async () => { strc = await STRC.new(true) - const registry = await Registry.new(true) - await registry.setAddressFor(CeloContractName.StableTokenRegistry, strc.address) - await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) + await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL')) }) describe('#initialize()', async () => { - const registry = await Registry.new(true) it('should have set the owner', async () => { const owner: string = await strc.owner() assert.equal(owner, accounts[0]) }) it('should not be callable again', async () => { - await assertRevert( - strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) - ) + await assertRevert(strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'))) }) }) From b0133ee559faa65898d700625687e81ddd1bc484 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 4 May 2022 15:56:32 +0200 Subject: [PATCH 064/164] readded in registry-utils --- packages/protocol/lib/registry-utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index d6dae2db095..ef839dc2ca4 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -38,6 +38,7 @@ export enum CeloContractName { StableTokenBRL = 'StableTokenBRL', TransferWhitelist = 'TransferWhitelist', Validators = 'Validators', + StableTokenRegistry = 'StableTokenRegistry', } export const usesRegistry = [ From f4096207781378bf534c1bca4f7adfefc193d06e Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 6 May 2022 12:43:33 +0200 Subject: [PATCH 065/164] upgraded the number of migration file the tests should run to --- packages/cli/package.json | 2 +- packages/sdk/contractkit/package.json | 2 +- packages/sdk/identity/package.json | 2 +- packages/sdk/transactions-uri/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 26be227461e..f3bfe057037 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -28,7 +28,7 @@ "generate:shrinkwrap": "npm install --production && npm shrinkwrap", "check:shrinkwrap": "npm install --production && npm shrinkwrap && ./scripts/check_shrinkwrap_dirty.sh", "prepack": "yarn run build && oclif-dev manifest && oclif-dev readme && yarn run check:shrinkwrap", - "test:reset": "yarn --cwd ../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../dev-utils/src/migration-override.json --upto 25 --release_gold_contracts scripts/truffle/releaseGoldExampleConfigs.json", + "test:reset": "yarn --cwd ../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../dev-utils/src/migration-override.json --upto 26 --release_gold_contracts scripts/truffle/releaseGoldExampleConfigs.json", "test:livechain": "yarn --cwd ../protocol devchain run-tar .tmp/devchain.tar.gz", "test": "TZ=UTC jest --runInBand" }, diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index 0c6935288ab..fd6d7777522 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -22,7 +22,7 @@ "clean:all": "yarn clean && rm -rf src/generated", "prepublishOnly": "yarn build", "docs": "typedoc", - "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 25", + "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 26", "test:livechain": "yarn --cwd ../../protocol devchain run-tar .tmp/devchain.tar.gz", "test": "jest --runInBand", "lint": "tslint -c tslint.json --project ." diff --git a/packages/sdk/identity/package.json b/packages/sdk/identity/package.json index 965a6b7d34c..51a6c8bec66 100644 --- a/packages/sdk/identity/package.json +++ b/packages/sdk/identity/package.json @@ -18,7 +18,7 @@ "build": "tsc -b .", "clean": "tsc -b . --clean", "docs": "typedoc", - "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 25", + "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 26", "test:livechain": "yarn --cwd ../../protocol devchain run-tar .tmp/devchain.tar.gz", "test": "jest --runInBand", "lint": "tslint -c tslint.json --project .", diff --git a/packages/sdk/transactions-uri/package.json b/packages/sdk/transactions-uri/package.json index 2a2874cd6d5..8a847936de7 100644 --- a/packages/sdk/transactions-uri/package.json +++ b/packages/sdk/transactions-uri/package.json @@ -17,7 +17,7 @@ "build": "tsc -b .", "clean": "tsc -b . --clean", "docs": "typedoc", - "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 25", + "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 26", "test:livechain": "yarn --cwd ../../protocol devchain run-tar .tmp/devchain.tar.gz", "test": "jest --runInBand", "lint": "tslint -c tslint.json --project .", From d70cd4406d6003f4fea374e4dfaa121a965efb96 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 9 May 2022 10:56:43 +0200 Subject: [PATCH 066/164] cleaning up --- .../protocol/contracts/stability/StableTokenRegistry.sol | 5 +---- packages/protocol/migrations/26_governance.ts | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index fc9c6d4909f..31387213a0c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -4,18 +4,15 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; import "../common/interfaces/IRegistry.sol"; -import "../common/UsingRegistry.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ -contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { +contract StableTokenRegistry is Initializable, Ownable { using SafeMath for uint256; mapping(bytes => bytes) public stableTokens; bytes[] public fiatTickers; - IRegistry public registry; - /** * @notice Sets initialized == true on implementation contracts * @param test Set to true to skip implementation initialization diff --git a/packages/protocol/migrations/26_governance.ts b/packages/protocol/migrations/26_governance.ts index 78a731eb053..ed993fb87bc 100644 --- a/packages/protocol/migrations/26_governance.ts +++ b/packages/protocol/migrations/26_governance.ts @@ -98,6 +98,7 @@ module.exports = deploymentForCoreContract( 'StableToken', 'StableTokenEUR', 'Validators', + 'StableTokenRegistry', ] if (!config.governance.skipTransferOwnership) { From 122de4aef880013d45a01b99396005c216d81131 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 20 May 2022 13:40:59 +0200 Subject: [PATCH 067/164] applying suggestions --- .../protocol/contracts/stability/StableTokenRegistry.sol | 4 +++- packages/protocol/lib/web3-utils.ts | 1 + packages/protocol/migrations/25_stableToken_registry.ts | 8 ++------ packages/protocol/migrationsConfig.js | 4 ++-- packages/protocol/test/stability/stabletokenregistry.ts | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 31387213a0c..ee2b8c47d32 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -32,7 +32,9 @@ contract StableTokenRegistry is Initializable, Ownable { addNewStableToken(bytes("USD"), bytes("StableToken")); addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); - addNewStableToken(fiatTicker, stableTokenContractName); + if (fiatTicker.length != 0 && stableTokenContractName.length != 0) { + addNewStableToken(fiatTicker, stableTokenContractName); + } } /** diff --git a/packages/protocol/lib/web3-utils.ts b/packages/protocol/lib/web3-utils.ts index e77a6e300c0..e082d6b300e 100644 --- a/packages/protocol/lib/web3-utils.ts +++ b/packages/protocol/lib/web3-utils.ts @@ -132,6 +132,7 @@ export function randomUint256() { return BigNumber.random() .times(maxUint256) .integerValue() + .valueOf() } export function checkFunctionArgsLength(args: any[], abi: any) { diff --git a/packages/protocol/migrations/25_stableToken_registry.ts b/packages/protocol/migrations/25_stableToken_registry.ts index 65c81e57561..45622f3a476 100644 --- a/packages/protocol/migrations/25_stableToken_registry.ts +++ b/packages/protocol/migrations/25_stableToken_registry.ts @@ -1,16 +1,12 @@ /* tslint:disable:no-console */ import { CeloContractName } from '@celo/protocol/lib/registry-utils' import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' -import { config } from '@celo/protocol/migrationsConfig' import { StableTokenRegistryInstance } from 'types' -const initializeArgs = async (): Promise => { - return [config.stableTokenRegistry.fiatTicker, config.stableTokenRegistry.stableTokenContractName] -} +// Add initializeArgs when trying to deploy a the registry with a new stable asset on the test net module.exports = deploymentForCoreContract( web3, artifacts, - CeloContractName.StableTokenRegistry, - initializeArgs + CeloContractName.StableTokenRegistry ) diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index 43f89d19a8c..7a6e36124d2 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -239,8 +239,8 @@ const DefaultConfig = { votesRatioOfLastVsFirstGroup: 2.0, }, stableTokenRegistry: { - fiatTicker: '0x494e52', // fiat ticker - stableTokenContractName: '0x537461626c65546f6b656e494e52', // stable token contract name + fiatTicker: [], // empty array resambles empty bytes + stableTokenContractName: [], // empty array resambles empty bytes }, } diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 78593715daf..96e9fd5ffa1 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -23,7 +23,6 @@ const assertSTContractNames = ( }) assert.equal(contracts.length, currentIndex) } - contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] @@ -31,6 +30,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { const fiatTicker: string = convertToHex('USD') const stableTokenContractName = convertToHex('StableToken') + // Add this to contractkit once we have it const getFiatTickers = async () => { const updatedFiatTickers = [] try { @@ -71,7 +71,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { it('has the right list of fiat tickers after removing one', async () => { await strc.removeStableToken(fiatTicker, 0) - const updatedFiatTickers = await getFiatTickers() + const updatedFiatTickers = await strc.getFiatTickers() assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) From e275ecace7a3c4cc45a21be51b4467619a83ffcc Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 15 Jun 2022 11:19:37 +0200 Subject: [PATCH 068/164] error in ts wrapper --- packages/protocol/test/stability/stabletokenregistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 96e9fd5ffa1..6f63d683720 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -71,7 +71,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { it('has the right list of fiat tickers after removing one', async () => { await strc.removeStableToken(fiatTicker, 0) - const updatedFiatTickers = await strc.getFiatTickers() + const updatedFiatTickers = await getFiatTickers() assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) From 5ead536d5421da1c5c931c3d298dd558549752b8 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 15 Jun 2022 11:51:38 +0200 Subject: [PATCH 069/164] fixed migration error --- packages/protocol/migrations/25_stableToken_registry.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/protocol/migrations/25_stableToken_registry.ts b/packages/protocol/migrations/25_stableToken_registry.ts index 45622f3a476..f6031cecadf 100644 --- a/packages/protocol/migrations/25_stableToken_registry.ts +++ b/packages/protocol/migrations/25_stableToken_registry.ts @@ -1,12 +1,14 @@ -/* tslint:disable:no-console */ import { CeloContractName } from '@celo/protocol/lib/registry-utils' import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' import { StableTokenRegistryInstance } from 'types' -// Add initializeArgs when trying to deploy a the registry with a new stable asset on the test net +const initializeArgs = async (): Promise => { + return [[], []] +} module.exports = deploymentForCoreContract( web3, artifacts, - CeloContractName.StableTokenRegistry + CeloContractName.StableTokenRegistry, + initializeArgs ) From cf913e382f0898d0571cdc233beedc1475110769 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Feb 2022 17:20:26 +0100 Subject: [PATCH 070/164] initial contract creation --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/protocol/contracts/stability/StableTokenRegistry.sol diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol new file mode 100644 index 00000000000..e69de29bb2d From 21514b3de8ce8140991aefef6f7095d3e51bd811 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Feb 2022 17:58:37 +0100 Subject: [PATCH 071/164] added a contructor and a mapping --- .../stability/StableTokenRegistry.sol | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index e69de29bb2d..4e8e121dbd4 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -0,0 +1,18 @@ +pragma solidity ^0.5.13; + +import "./StableTokenEUR.sol"; +import "./StableToken.sol"; +import "./StableTokenBRL.sol"; + +/** + * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. + */ +contract StableTokenRegistry { + mapping(string => string) public stableTokenRegistry; + + /** + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ + constructor(bool test) public Initializable(test) {} +} From f68518170f1aeb3b596a90781aec9e55031adfea Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 18:53:00 +0100 Subject: [PATCH 072/164] added function that add fiat tickers into the collection --- .../stability/StableTokenRegistry.sol | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 4e8e121dbd4..61b19175ded 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,18 +1,31 @@ pragma solidity ^0.5.13; -import "./StableTokenEUR.sol"; import "./StableToken.sol"; +import "./StableTokenEUR.sol"; import "./StableTokenBRL.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ contract StableTokenRegistry { - mapping(string => string) public stableTokenRegistry; + mapping(string => string) public stableTokens; + string[] public fiatTickers; /** - * @notice Sets initialized == true on implementation contracts - * @param test Set to true to skip implementation initialization - */ + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ constructor(bool test) public Initializable(test) {} + + /** + * @notice adds fiat currencies to fiatTickers collection + * @param currencyType the type of currency we're trying to push into the collection + */ + function addFiatTickers(string currencyType) external onlyOwner { + //also check if it already exists in the array, if it does then don't add + //so I can make sure there are no dublicates + require(!stableTokens[currencyType], "Stable token hasn't been issued"); + stableTokens[currencyType] = true; + fiatTickers.push(currencyType); + } } From 874e9ac9c907daa31e49e7b25df3e29d524ef002 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 18:57:07 +0100 Subject: [PATCH 073/164] function that returns all the fiat symbols thats been issued --- .../protocol/contracts/stability/StableTokenRegistry.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 61b19175ded..9d5c5c7bdff 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -28,4 +28,12 @@ contract StableTokenRegistry { stableTokens[currencyType] = true; fiatTickers.push(currencyType); } + + /** + * @notice Returns fiat currencies that have been issued. + * @return An array of currencies issued. + */ + function getFiatTickers() external view returns (string[] memory) { + return fiatTickers; + } } From 9e38e400f6ca64dced7aeaf5d5de70852044b803 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 19:17:06 +0100 Subject: [PATCH 074/164] quering a stable contract functionality --- .../contracts/stability/StableTokenRegistry.sol | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 9d5c5c7bdff..9954bb89fe2 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -21,7 +21,7 @@ contract StableTokenRegistry { * @notice adds fiat currencies to fiatTickers collection * @param currencyType the type of currency we're trying to push into the collection */ - function addFiatTickers(string currencyType) external onlyOwner { + function addFiatTickers(string _currencyType) external onlyOwner { //also check if it already exists in the array, if it does then don't add //so I can make sure there are no dublicates require(!stableTokens[currencyType], "Stable token hasn't been issued"); @@ -36,4 +36,12 @@ contract StableTokenRegistry { function getFiatTickers() external view returns (string[] memory) { return fiatTickers; } + + /** + * @notice Returns queried stable contract. + * @return stable contract. + */ + function queryContractByFiatType(string _fiatTicker) public view returns (string) { + return stableTokens[_fiatTicker]; + } } From 5796867d04095aaa88cec5b58d870a4cdc0812bf Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 20:02:51 +0100 Subject: [PATCH 075/164] function to retrieve all the contract instances from a mapping --- .../contracts/stability/StableTokenRegistry.sol | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 9954bb89fe2..6dc0709a888 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -10,13 +10,13 @@ import "./StableTokenBRL.sol"; contract StableTokenRegistry { mapping(string => string) public stableTokens; string[] public fiatTickers; + string[] public contracts; /** * @notice Sets initialized == true on implementation contracts * @param test Set to true to skip implementation initialization */ constructor(bool test) public Initializable(test) {} - /** * @notice adds fiat currencies to fiatTickers collection * @param currencyType the type of currency we're trying to push into the collection @@ -31,12 +31,20 @@ contract StableTokenRegistry { /** * @notice Returns fiat currencies that have been issued. - * @return An array of currencies issued. + * @return A collection of currencies issued. */ function getFiatTickers() external view returns (string[] memory) { return fiatTickers; } + /** + * @notice Returns contracts that have been issued. + * @return A collection of contracts issued. + */ + function getContracts() external view returns (string[] memory) { + return contracts; + } + /** * @notice Returns queried stable contract. * @return stable contract. From 16426f69fb8bc84dd15fcaf1a615e5637dbb69ab Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Feb 2022 20:06:27 +0100 Subject: [PATCH 076/164] removing unnecessary imports --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 6dc0709a888..a13d0ecd9e1 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,9 +1,5 @@ pragma solidity ^0.5.13; -import "./StableToken.sol"; -import "./StableTokenEUR.sol"; -import "./StableTokenBRL.sol"; - /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ From 140cc1ebb338dc75f6d22ceb699a06481d1792f1 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 12:09:27 +0100 Subject: [PATCH 077/164] function that returns all the contracts --- .../protocol/contracts/stability/StableTokenRegistry.sol | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index a13d0ecd9e1..50e5be0aafa 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -13,6 +13,7 @@ contract StableTokenRegistry { * @param test Set to true to skip implementation initialization */ constructor(bool test) public Initializable(test) {} + /** * @notice adds fiat currencies to fiatTickers collection * @param currencyType the type of currency we're trying to push into the collection @@ -48,4 +49,12 @@ contract StableTokenRegistry { function queryContractByFiatType(string _fiatTicker) public view returns (string) { return stableTokens[_fiatTicker]; } + + function getContractInstances() external view returns (string[] memory) { + string[] memory contracts; + for (i = 0; i < fiatTickers.length; i++) { + contracts.push(stableTokens[fiatTickers[i]]); + } + return contracts; + } } From 4bc1b28e133ee488ac3da5a4f7efbae3ddbcad5f Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 12:15:09 +0100 Subject: [PATCH 078/164] added comments --- .../protocol/contracts/stability/StableTokenRegistry.sol | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 50e5be0aafa..1fdccfb812c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -50,6 +50,11 @@ contract StableTokenRegistry { return stableTokens[_fiatTicker]; } + /** + * @notice Returns all the contract instances created. + * @return collection of stable token contracts. + */ + function getContractInstances() external view returns (string[] memory) { string[] memory contracts; for (i = 0; i < fiatTickers.length; i++) { From afe6259105869589eab916ed842a634d0bd6844d Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 12:16:25 +0100 Subject: [PATCH 079/164] removed unnecessary function --- .../protocol/contracts/stability/StableTokenRegistry.sol | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 1fdccfb812c..ed38fd673e6 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -6,7 +6,6 @@ pragma solidity ^0.5.13; contract StableTokenRegistry { mapping(string => string) public stableTokens; string[] public fiatTickers; - string[] public contracts; /** * @notice Sets initialized == true on implementation contracts @@ -34,14 +33,6 @@ contract StableTokenRegistry { return fiatTickers; } - /** - * @notice Returns contracts that have been issued. - * @return A collection of contracts issued. - */ - function getContracts() external view returns (string[] memory) { - return contracts; - } - /** * @notice Returns queried stable contract. * @return stable contract. From afe8652f7003138bf25ee85b4e45372382cbeda4 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 12:23:33 +0100 Subject: [PATCH 080/164] removed unnecessary function --- .../protocol/contracts/stability/StableTokenRegistry.sol | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index ed38fd673e6..63312f0628b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -33,14 +33,6 @@ contract StableTokenRegistry { return fiatTickers; } - /** - * @notice Returns queried stable contract. - * @return stable contract. - */ - function queryContractByFiatType(string _fiatTicker) public view returns (string) { - return stableTokens[_fiatTicker]; - } - /** * @notice Returns all the contract instances created. * @return collection of stable token contracts. From b34a14bb1ad2f9849cfa9e2c39f81a3378d92de3 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 13:33:51 +0100 Subject: [PATCH 081/164] functionality to remove unsupported tokens --- .../stability/StableTokenRegistry.sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 63312f0628b..14353bd6685 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -45,4 +45,23 @@ contract StableTokenRegistry { } return contracts; } + + /** + * @notice Removes unwamted token instances. + * @param fiatType The type of currency that is no longer supported. + * @param index The index in fiatTickers of fiatType. + */ + function removeRegistry(string fiatType, uint256 index) external onlyowner { + uint256 numFiats = fiatTickers.length; + require(index < numFiats, "Index is invalid"); + require(fiatType == fiatTickers[index], "Index does not match fiat type"); + uint256 newNumFiats = numFiats.sub(1); + + if (index != newNumFiats) { + fiatTickers[index] = fiatTickers[newNumFiats]; + } + fiatTickers[newNumFiats] = ""; + fiatTickers.length = newNumFiats; + } + } From ea494a80c3342e47ec17762f9c8acc4131b03788 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 13:47:55 +0100 Subject: [PATCH 082/164] function that adds new instances to the registry --- .../stability/StableTokenRegistry.sol | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 14353bd6685..d90770d5763 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -8,15 +8,15 @@ contract StableTokenRegistry { string[] public fiatTickers; /** - * @notice Sets initialized == true on implementation contracts - * @param test Set to true to skip implementation initialization - */ + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ constructor(bool test) public Initializable(test) {} /** - * @notice adds fiat currencies to fiatTickers collection - * @param currencyType the type of currency we're trying to push into the collection - */ + * @notice adds fiat currencies to fiatTickers collection + * @param currencyType the type of currency we're trying to push into the collection + */ function addFiatTickers(string _currencyType) external onlyOwner { //also check if it already exists in the array, if it does then don't add //so I can make sure there are no dublicates @@ -64,4 +64,17 @@ contract StableTokenRegistry { fiatTickers.length = newNumFiats; } + /** + * @notice Gives an address permission to spend Reserve without limit. + * @param spender The address that is allowed to spend Reserve funds. + */ + + function addNewRegistry(string fiatType, string contractType) external onlyOwner { + require("" != fiatType, "fiatType cant be an empty string"); + require("" != contractType, "contractType cant be an empty string"); + require(stableTokens[fiatType] != "", "This registry already exists"); + stableTokens[fiatType] = contractType; + fiatTickers.push(fiatType); + } + } From 798f233144361dbe3d16cfa82b903f1ff35ba7a9 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 13:50:42 +0100 Subject: [PATCH 083/164] poor indentation --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index d90770d5763..c690477a62b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -37,7 +37,6 @@ contract StableTokenRegistry { * @notice Returns all the contract instances created. * @return collection of stable token contracts. */ - function getContractInstances() external view returns (string[] memory) { string[] memory contracts; for (i = 0; i < fiatTickers.length; i++) { @@ -68,7 +67,6 @@ contract StableTokenRegistry { * @notice Gives an address permission to spend Reserve without limit. * @param spender The address that is allowed to spend Reserve funds. */ - function addNewRegistry(string fiatType, string contractType) external onlyOwner { require("" != fiatType, "fiatType cant be an empty string"); require("" != contractType, "contractType cant be an empty string"); From b6b7b61b1754ce20759a12821575871509831c93 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 15:06:07 +0100 Subject: [PATCH 084/164] resolving bugs --- .../protocol/contracts/stability/StableTokenRegistry.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index c690477a62b..4197ca34dc0 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -17,11 +17,10 @@ contract StableTokenRegistry { * @notice adds fiat currencies to fiatTickers collection * @param currencyType the type of currency we're trying to push into the collection */ - function addFiatTickers(string _currencyType) external onlyOwner { + function addFiatTickers(string currencyType) external onlyOwner { //also check if it already exists in the array, if it does then don't add //so I can make sure there are no dublicates - require(!stableTokens[currencyType], "Stable token hasn't been issued"); - stableTokens[currencyType] = true; + require(stableTokens[currencyType] != "", "Stable token hasn't been issued"); fiatTickers.push(currencyType); } From 9135dd747dcac1072b1de4f821df87a4762a57dd Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 15:59:29 +0100 Subject: [PATCH 085/164] suggested improvements --- .../stability/StableTokenRegistry.sol | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 4197ca34dc0..e39a745185c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -13,17 +13,6 @@ contract StableTokenRegistry { */ constructor(bool test) public Initializable(test) {} - /** - * @notice adds fiat currencies to fiatTickers collection - * @param currencyType the type of currency we're trying to push into the collection - */ - function addFiatTickers(string currencyType) external onlyOwner { - //also check if it already exists in the array, if it does then don't add - //so I can make sure there are no dublicates - require(stableTokens[currencyType] != "", "Stable token hasn't been issued"); - fiatTickers.push(currencyType); - } - /** * @notice Returns fiat currencies that have been issued. * @return A collection of currencies issued. @@ -46,13 +35,13 @@ contract StableTokenRegistry { /** * @notice Removes unwamted token instances. - * @param fiatType The type of currency that is no longer supported. - * @param index The index in fiatTickers of fiatType. + * @param fiatTicker The type of currency that is no longer supported. + * @param index The index in fiatTickers of fiatTicker. */ - function removeRegistry(string fiatType, uint256 index) external onlyowner { + function removeRegistry(string fiatTicker, uint256 index) external onlyowner { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); - require(fiatType == fiatTickers[index], "Index does not match fiat type"); + require(fiatTicker == fiatTickers[index], "Index does not match fiat type"); uint256 newNumFiats = numFiats.sub(1); if (index != newNumFiats) { @@ -66,12 +55,12 @@ contract StableTokenRegistry { * @notice Gives an address permission to spend Reserve without limit. * @param spender The address that is allowed to spend Reserve funds. */ - function addNewRegistry(string fiatType, string contractType) external onlyOwner { - require("" != fiatType, "fiatType cant be an empty string"); - require("" != contractType, "contractType cant be an empty string"); - require(stableTokens[fiatType] != "", "This registry already exists"); - stableTokens[fiatType] = contractType; - fiatTickers.push(fiatType); + function addNewRegistry(string fiatTicker, string stableTokenContractName) external onlyOwner { + require("" != fiatTicker, "fiatTicker cant be an empty string"); + require("" != stableTokenContractName, "stableTokenContractName cant be an empty string"); + require(stableTokens[fiatTicker] != "", "This registry already exists"); + stableTokens[fiatTicker] = stableTokenContractName; + fiatTickers.push(fiatTicker); } } From f925ed132f6342a9d5d0a2663b34cc98f77eec22 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 17:10:06 +0100 Subject: [PATCH 086/164] writing initialize --- .../contracts/stability/StableTokenRegistry.sol | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index e39a745185c..1e2c01e5b8a 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,4 +1,5 @@ pragma solidity ^0.5.13; +import "../common/Initializable.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. @@ -13,6 +14,13 @@ contract StableTokenRegistry { */ constructor(bool test) public Initializable(test) {} + /** + * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. + * @param fiatTicker The fiat currency. + * @param stableTokenContractName The name of a stable token smart contract. + */ + function initialize() external initializer {} + /** * @notice Returns fiat currencies that have been issued. * @return A collection of currencies issued. @@ -38,7 +46,7 @@ contract StableTokenRegistry { * @param fiatTicker The type of currency that is no longer supported. * @param index The index in fiatTickers of fiatTicker. */ - function removeRegistry(string fiatTicker, uint256 index) external onlyowner { + function removeStableToken(string fiatTicker, uint256 index) external onlyowner { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require(fiatTicker == fiatTickers[index], "Index does not match fiat type"); @@ -55,7 +63,7 @@ contract StableTokenRegistry { * @notice Gives an address permission to spend Reserve without limit. * @param spender The address that is allowed to spend Reserve funds. */ - function addNewRegistry(string fiatTicker, string stableTokenContractName) external onlyOwner { + function addNewStableToken(string fiatTicker, string stableTokenContractName) external onlyOwner { require("" != fiatTicker, "fiatTicker cant be an empty string"); require("" != stableTokenContractName, "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker] != "", "This registry already exists"); From 939fe3b2fcbb016d9a2baf92c042aec6e64995c2 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 17:11:53 +0100 Subject: [PATCH 087/164] updated inconsistent syntax --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 1e2c01e5b8a..2db48da1cd1 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -64,8 +64,8 @@ contract StableTokenRegistry { * @param spender The address that is allowed to spend Reserve funds. */ function addNewStableToken(string fiatTicker, string stableTokenContractName) external onlyOwner { - require("" != fiatTicker, "fiatTicker cant be an empty string"); - require("" != stableTokenContractName, "stableTokenContractName cant be an empty string"); + require(fiatTicker != "", "fiatTicker cant be an empty string"); + require(stableTokenContractName != "", "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker] != "", "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); From 97db82896e663dc411513fa76473c0cda6ffbe69 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 17:53:18 +0100 Subject: [PATCH 088/164] initialize function is implemented --- .../protocol/contracts/stability/StableTokenRegistry.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 2db48da1cd1..65022806c97 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,4 +1,5 @@ pragma solidity ^0.5.13; + import "../common/Initializable.sol"; /** @@ -19,7 +20,9 @@ contract StableTokenRegistry { * @param fiatTicker The fiat currency. * @param stableTokenContractName The name of a stable token smart contract. */ - function initialize() external initializer {} + function initialize(string fiatTicker, string stableTokenContractName) external initializer { + stableTokens[fiatTicker] = stableTokenContractName; + } /** * @notice Returns fiat currencies that have been issued. From 702e439d0aa204af20a64f72924198848f68f225 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Feb 2022 19:27:07 +0100 Subject: [PATCH 089/164] some of the resolved compile errors --- .../stability/StableTokenRegistry.sol | 21 ++++++++++++------- .../test/stability/stabletokenregistry.ts | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 packages/protocol/test/stability/stabletokenregistry.ts diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 65022806c97..2a26c0ceaff 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,13 +1,15 @@ pragma solidity ^0.5.13; import "../common/Initializable.sol"; +import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ -contract StableTokenRegistry { +contract StableTokenRegistry is Initializable, Ownable { mapping(string => string) public stableTokens; string[] public fiatTickers; + string[] public contracts; /** * @notice Sets initialized == true on implementation contracts @@ -20,7 +22,10 @@ contract StableTokenRegistry { * @param fiatTicker The fiat currency. * @param stableTokenContractName The name of a stable token smart contract. */ - function initialize(string fiatTicker, string stableTokenContractName) external initializer { + function initialize(string calldata fiatTicker, string calldata stableTokenContractName) + external + initializer + { stableTokens[fiatTicker] = stableTokenContractName; } @@ -37,8 +42,7 @@ contract StableTokenRegistry { * @return collection of stable token contracts. */ function getContractInstances() external view returns (string[] memory) { - string[] memory contracts; - for (i = 0; i < fiatTickers.length; i++) { + for (uint256 i = 0; i < fiatTickers.length; i++) { contracts.push(stableTokens[fiatTickers[i]]); } return contracts; @@ -49,7 +53,7 @@ contract StableTokenRegistry { * @param fiatTicker The type of currency that is no longer supported. * @param index The index in fiatTickers of fiatTicker. */ - function removeStableToken(string fiatTicker, uint256 index) external onlyowner { + function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require(fiatTicker == fiatTickers[index], "Index does not match fiat type"); @@ -64,9 +68,12 @@ contract StableTokenRegistry { /** * @notice Gives an address permission to spend Reserve without limit. - * @param spender The address that is allowed to spend Reserve funds. + * @param fiatTicker The address that is allowed to spend Reserve funds. */ - function addNewStableToken(string fiatTicker, string stableTokenContractName) external onlyOwner { + function addNewStableToken(string calldata fiatTicker, string calldata stableTokenContractName) + external + onlyOwner + { require(fiatTicker != "", "fiatTicker cant be an empty string"); require(stableTokenContractName != "", "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker] != "", "This registry already exists"); diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts new file mode 100644 index 00000000000..08e5f2601a8 --- /dev/null +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -0,0 +1,3 @@ +contract('StableTokenRegistry', () => { + console.log('hi') +}) From 8c7a4b9dfb0d344a520ab1a4b0969bfc56caf9b5 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 15:07:18 +0100 Subject: [PATCH 090/164] resolving compiler issues --- .../stability/StableTokenRegistry.sol | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 2a26c0ceaff..45a78ea0c2b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,5 +1,7 @@ pragma solidity ^0.5.13; +pragma experimental ABIEncoderV2; +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; @@ -7,9 +9,9 @@ import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ contract StableTokenRegistry is Initializable, Ownable { + using SafeMath for uint256; mapping(string => string) public stableTokens; string[] public fiatTickers; - string[] public contracts; /** * @notice Sets initialized == true on implementation contracts @@ -42,8 +44,9 @@ contract StableTokenRegistry is Initializable, Ownable { * @return collection of stable token contracts. */ function getContractInstances() external view returns (string[] memory) { + string[] memory contracts; for (uint256 i = 0; i < fiatTickers.length; i++) { - contracts.push(stableTokens[fiatTickers[i]]); + contracts[i] = stableTokens[fiatTickers[i]]; } return contracts; } @@ -56,7 +59,10 @@ contract StableTokenRegistry is Initializable, Ownable { function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); - require(fiatTicker == fiatTickers[index], "Index does not match fiat type"); + require( + keccak256(bytes(fiatTicker)) == keccak256(bytes(fiatTickers[index])), + "Index does not match fiat type" + ); uint256 newNumFiats = numFiats.sub(1); if (index != newNumFiats) { @@ -74,9 +80,9 @@ contract StableTokenRegistry is Initializable, Ownable { external onlyOwner { - require(fiatTicker != "", "fiatTicker cant be an empty string"); - require(stableTokenContractName != "", "stableTokenContractName cant be an empty string"); - require(stableTokens[fiatTicker] != "", "This registry already exists"); + require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); + require(bytes(stableTokenContractName) != 0, "stableTokenContractName cant be an empty string"); + require(bytes(stableTokens[fiatTicker]) != 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } From 987f53e3273901695c2ebd3a7d693c7a67439277 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 15:12:01 +0100 Subject: [PATCH 091/164] last of compiler issues --- .../protocol/contracts/stability/StableTokenRegistry.sol | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 45a78ea0c2b..de0d896a32d 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -81,8 +81,11 @@ contract StableTokenRegistry is Initializable, Ownable { onlyOwner { require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); - require(bytes(stableTokenContractName) != 0, "stableTokenContractName cant be an empty string"); - require(bytes(stableTokens[fiatTicker]) != 0, "This registry already exists"); + require( + bytes(stableTokenContractName).length != 0, + "stableTokenContractName cant be an empty string" + ); + require(bytes(stableTokens[fiatTicker]).length != 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } From 510ff8779176c68c8c3b76270cf5d4e2d4dd94c3 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 15:53:25 +0100 Subject: [PATCH 092/164] upgrading removeStableToken funrction --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index de0d896a32d..b97ca9b756c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -57,11 +57,12 @@ contract StableTokenRegistry is Initializable, Ownable { * @param index The index in fiatTickers of fiatTicker. */ function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { + stableTokens[fiatTicker] = ""; uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require( keccak256(bytes(fiatTicker)) == keccak256(bytes(fiatTickers[index])), - "Index does not match fiat type" + "Index does not match fiatTicker" ); uint256 newNumFiats = numFiats.sub(1); From 5add546162a435f7791763877c092c0331719b7e Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 17:41:14 +0100 Subject: [PATCH 093/164] updated registry --- .../stability/StableTokenRegistry.sol | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index b97ca9b756c..3794252da1a 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -21,14 +21,21 @@ contract StableTokenRegistry is Initializable, Ownable { /** * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. - * @param fiatTicker The fiat currency. - * @param stableTokenContractName The name of a stable token smart contract. + * @param existingFiatTickers Collection of fiat currencies issued already. + * @param existingStableTokenContractNames Collection of stable token smart contract names. */ - function initialize(string calldata fiatTicker, string calldata stableTokenContractName) - external - initializer - { - stableTokens[fiatTicker] = stableTokenContractName; + function initialize( + string[] calldata existingFiatTickers, + string[] calldata existingStableTokenContractNames + ) external initializer { + _transferOwnership(msg.sender); + require( + existingFiatTickers.length == existingStableTokenContractNames.length, + "Array length mismatch" + ); + for (uint256 i = 0; i < existingFiatTickers.length; i++) { + stableTokens[fiatTickers[i]] = existingFiatTickers[i]; + } } /** From 868a59ea0b46e1f6767310e53368a75805bea511 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 19:33:33 +0100 Subject: [PATCH 094/164] updated initialize function --- packages/protocol/contracts/common/Registry.sol | 1 + .../protocol/contracts/stability/StableTokenRegistry.sol | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/packages/protocol/contracts/common/Registry.sol b/packages/protocol/contracts/common/Registry.sol index 9e89bd89523..d5045f3b806 100644 --- a/packages/protocol/contracts/common/Registry.sol +++ b/packages/protocol/contracts/common/Registry.sol @@ -3,6 +3,7 @@ pragma solidity ^0.5.13; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; +import "../../contracts/common/Registry.sol"; import "./interfaces/IRegistry.sol"; import "./Initializable.sol"; diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 3794252da1a..e26b79d4a95 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -4,6 +4,9 @@ pragma experimental ABIEncoderV2; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; +// import "../common/Registry.sol"; +// import "../common/UsingRegistry.sol"; +import "../common/interfaces/IRegistry.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. @@ -13,6 +16,8 @@ contract StableTokenRegistry is Initializable, Ownable { mapping(string => string) public stableTokens; string[] public fiatTickers; + IRegistry public registry; + /** * @notice Sets initialized == true on implementation contracts * @param test Set to true to skip implementation initialization @@ -88,6 +93,7 @@ contract StableTokenRegistry is Initializable, Ownable { external onlyOwner { + registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); require( bytes(stableTokenContractName).length != 0, From 4f1ec1a4b6503f9a7d47431ef6b6f28e1de89004 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 28 Feb 2022 19:35:10 +0100 Subject: [PATCH 095/164] removed commented out code --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index e26b79d4a95..fce950b2701 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -4,8 +4,6 @@ pragma experimental ABIEncoderV2; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; -// import "../common/Registry.sol"; -// import "../common/UsingRegistry.sol"; import "../common/interfaces/IRegistry.sol"; /** From f9576d95bb5002d4625d0c4a4536246d040029f8 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 1 Mar 2022 15:43:48 +0100 Subject: [PATCH 096/164] updated comments --- .../protocol/contracts/stability/StableTokenRegistry.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index fce950b2701..e579229555a 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -63,7 +63,7 @@ contract StableTokenRegistry is Initializable, Ownable { /** * @notice Removes unwamted token instances. - * @param fiatTicker The type of currency that is no longer supported. + * @param fiatTicker The currency that is no longer supported. * @param index The index in fiatTickers of fiatTicker. */ function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { @@ -84,8 +84,9 @@ contract StableTokenRegistry is Initializable, Ownable { } /** - * @notice Gives an address permission to spend Reserve without limit. - * @param fiatTicker The address that is allowed to spend Reserve funds. + * @notice Adds new Fiat Ticker and Stable Token contract to the registry. + * @param fiatTicker The currency we are trying to add in the registry. + * @param stableTokenContractName The contract we are trying to add in the registry. */ function addNewStableToken(string calldata fiatTicker, string calldata stableTokenContractName) external From eaf5cc72eb73bef748117f3e780a16258d1f4c2f Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 09:46:27 +0100 Subject: [PATCH 097/164] created a proxy --- .../stability/proxies/StableTokenRegistryProxy.sol | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol diff --git a/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol b/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol new file mode 100644 index 00000000000..6e9656d991c --- /dev/null +++ b/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.5.13; + +import "../../common/Proxy.sol"; + +/* solhint-disable no-empty-blocks */ +contract StableTokenRegistryProxy is Proxy {} From 029db306194f97cd8e0741b37b40edc59b8bebf4 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 09:51:23 +0100 Subject: [PATCH 098/164] updating build file --- packages/protocol/scripts/build.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts index 1f4f78240f7..7272ddeb65a 100644 --- a/packages/protocol/scripts/build.ts +++ b/packages/protocol/scripts/build.ts @@ -36,6 +36,7 @@ export const ProxyContracts = [ 'StableTokenEURProxy', 'StableTokenProxy', 'SortedOraclesProxy', + 'StableTokenRegistryProxy', ] export const CoreContracts = [ // common @@ -89,6 +90,7 @@ const OtherContracts = [ // abstract 'Initializable', 'UsingRegistry', + 'StableTokenRegistry', ] const Interfaces = ['ICeloToken', 'IERC20', 'ICeloVersionedContract'] From b9fa18765393fad6d4c7dfa65e60030626968bc6 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 11:56:43 +0100 Subject: [PATCH 099/164] updated build file --- packages/protocol/scripts/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts index 7272ddeb65a..7e4432d7ae8 100644 --- a/packages/protocol/scripts/build.ts +++ b/packages/protocol/scripts/build.ts @@ -79,6 +79,7 @@ export const CoreContracts = [ 'StableTokenEUR', 'StableTokenBRL', 'SortedOracles', + 'StableTokenRegistry', // liquidity 'GrandaMento', @@ -90,7 +91,6 @@ const OtherContracts = [ // abstract 'Initializable', 'UsingRegistry', - 'StableTokenRegistry', ] const Interfaces = ['ICeloToken', 'IERC20', 'ICeloVersionedContract'] From 2ac9cfc94b585ec5b7fe82105b5516fb71c77ca1 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 14:40:02 +0100 Subject: [PATCH 100/164] initialize test suit --- .../test/stability/stabletokenregistry.ts | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 08e5f2601a8..60f998e60f9 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,3 +1,42 @@ -contract('StableTokenRegistry', () => { - console.log('hi') +import { assertRevert } from '@celo/protocol/lib/test-utils' +import { + // RegistryContract, + // RegistryInstance, + StableTokenRegistryContract, + StableTokenRegistryInstance, +} from 'types' + +const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') +// const Registry: RegistryContract = artifacts.require('Registry') + +contract('StableTokenRegistry', (accounts: string[]) => { + let strc: StableTokenRegistryInstance + + // @ts-ignore + let initializationTime + beforeEach(async () => { + strc = await STRC.new(true) + const response = await strc.initialize( + ['cUSD', 'cEUR', 'cBRL'], + ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] + ) + // @ts-ignore + initializationTime = (await web3.eth.getBlock(response.receipt.blockNumber)).timestamp + }) + + describe('#initialize()', async () => { + it('should have set the owner', async () => { + const owner: string = await strc.owner() + assert.equal(owner, accounts[0]) + }) + + it('should not be callable again', async () => { + await assertRevert( + strc.initialize( + ['cUSD', 'cEUR', 'cBRL'], + ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] + ) + ) + }) + }) }) From ca804fb6cd2a7cb95ba5894060135c19400ca9d9 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 15:36:44 +0100 Subject: [PATCH 101/164] updating registry contract --- .../contracts/stability/StableTokenRegistry.sol | 8 ++++---- .../protocol/test/stability/stabletokenregistry.ts | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index e579229555a..3607ce9c905 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -31,13 +31,13 @@ contract StableTokenRegistry is Initializable, Ownable { string[] calldata existingFiatTickers, string[] calldata existingStableTokenContractNames ) external initializer { - _transferOwnership(msg.sender); require( existingFiatTickers.length == existingStableTokenContractNames.length, "Array length mismatch" ); + _transferOwnership(msg.sender); for (uint256 i = 0; i < existingFiatTickers.length; i++) { - stableTokens[fiatTickers[i]] = existingFiatTickers[i]; + addNewStableToken(fiatTickers[i], existingFiatTickers[i]); } } @@ -88,8 +88,8 @@ contract StableTokenRegistry is Initializable, Ownable { * @param fiatTicker The currency we are trying to add in the registry. * @param stableTokenContractName The contract we are trying to add in the registry. */ - function addNewStableToken(string calldata fiatTicker, string calldata stableTokenContractName) - external + function addNewStableToken(string memory fiatTicker, string memory stableTokenContractName) + public onlyOwner { registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 60f998e60f9..4873f54a72e 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,30 +1,30 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' -import { - // RegistryContract, - // RegistryInstance, - StableTokenRegistryContract, - StableTokenRegistryInstance, -} from 'types' +import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') -// const Registry: RegistryContract = artifacts.require('Registry') contract('StableTokenRegistry', (accounts: string[]) => { + console.log('hi') let strc: StableTokenRegistryInstance // @ts-ignore let initializationTime beforeEach(async () => { + console.log('1') strc = await STRC.new(true) + console.log('12') const response = await strc.initialize( ['cUSD', 'cEUR', 'cBRL'], ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] ) + console.log('123') // @ts-ignore initializationTime = (await web3.eth.getBlock(response.receipt.blockNumber)).timestamp + console.log('1234') }) describe('#initialize()', async () => { + console.log('12345') it('should have set the owner', async () => { const owner: string = await strc.owner() assert.equal(owner, accounts[0]) From d53303cec1ae7ae631e4e61a9301bebc3046cce4 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 15:45:13 +0100 Subject: [PATCH 102/164] first few tests are passing --- .../test/stability/stabletokenregistry.ts | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 4873f54a72e..5647fda11cd 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -4,39 +4,21 @@ import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') contract('StableTokenRegistry', (accounts: string[]) => { - console.log('hi') let strc: StableTokenRegistryInstance - // @ts-ignore - let initializationTime beforeEach(async () => { - console.log('1') strc = await STRC.new(true) - console.log('12') - const response = await strc.initialize( - ['cUSD', 'cEUR', 'cBRL'], - ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] - ) - console.log('123') - // @ts-ignore - initializationTime = (await web3.eth.getBlock(response.receipt.blockNumber)).timestamp - console.log('1234') + await strc.initialize([], []) }) describe('#initialize()', async () => { - console.log('12345') it('should have set the owner', async () => { const owner: string = await strc.owner() assert.equal(owner, accounts[0]) }) it('should not be callable again', async () => { - await assertRevert( - strc.initialize( - ['cUSD', 'cEUR', 'cBRL'], - ['StableToken', 'StableTokenEUR', 'StableTokenBRL'] - ) - ) + await assertRevert(strc.initialize([], [])) }) }) }) From c4ea2589b1052fac83f44ea3ba63c90aa17d6129 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 2 Mar 2022 16:28:25 +0100 Subject: [PATCH 103/164] remove stableToken function --- .../test/stability/stabletokenregistry.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 5647fda11cd..4e5e14577d3 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -5,6 +5,9 @@ const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance + const nonOwner: string = accounts[1] + const fiatTicker: string = 'USD' + const stableTokenContractName = 'StableToken' beforeEach(async () => { strc = await STRC.new(true) @@ -21,4 +24,41 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.initialize([], [])) }) }) + + describe('#removeStableToken(fiatTicker)', () => { + beforeEach(async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + }) + + it('only allows owner', async () => { + await assertRevert(strc.removeStableToken(fiatTicker, 0, { from: nonOwner })) + }) + + it('has the right list of fiat tickers after removing one', async () => { + await strc.removeStableToken(fiatTicker, 0) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, []) + }) + + it("can't be removed twice", async () => { + await strc.removeStableToken(fiatTicker, 0) + await assertRevert(strc.removeStableToken(fiatTicker, 0)) + }) + + it("can't delete an index out of range", async () => { + await assertRevert(strc.removeStableToken(fiatTicker, 1)) + }) + + it('removes from a big array', async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + await strc.removeStableToken(fiatTicker, 0) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, [accounts[1]]) + }) + + it("doesn't remove an fiat ticker with the wrong index", async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + await assertRevert(strc.removeStableToken(fiatTicker, 1)) + }) + }) }) From 7b1688baa6b5737288d09fc5d993fc525618030c Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 21 Mar 2022 12:58:46 +0100 Subject: [PATCH 104/164] resolving a mistake --- packages/protocol/contracts/common/Registry.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/protocol/contracts/common/Registry.sol b/packages/protocol/contracts/common/Registry.sol index d5045f3b806..9e89bd89523 100644 --- a/packages/protocol/contracts/common/Registry.sol +++ b/packages/protocol/contracts/common/Registry.sol @@ -3,7 +3,6 @@ pragma solidity ^0.5.13; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; -import "../../contracts/common/Registry.sol"; import "./interfaces/IRegistry.sol"; import "./Initializable.sol"; From de2d14030b13180df180a3d35968af51ddcbde7c Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 21 Mar 2022 13:31:15 +0100 Subject: [PATCH 105/164] resolving based on corrections --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 3607ce9c905..343592852bf 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -79,7 +79,7 @@ contract StableTokenRegistry is Initializable, Ownable { if (index != newNumFiats) { fiatTickers[index] = fiatTickers[newNumFiats]; } - fiatTickers[newNumFiats] = ""; + delete fiatTickers[newNumFiats]; fiatTickers.length = newNumFiats; } From 1bb5f47ce02ec9f3ff85716fc859522788564b78 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 22 Mar 2022 18:35:12 +0100 Subject: [PATCH 106/164] tests for remove function complete --- packages/protocol/test/stability/stabletokenregistry.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 4e5e14577d3..43995cc4f0a 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -50,14 +50,12 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('removes from a big array', async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) await strc.removeStableToken(fiatTicker, 0) const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, [accounts[1]]) + assert.deepEqual(fiatTickers, []) }) it("doesn't remove an fiat ticker with the wrong index", async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) await assertRevert(strc.removeStableToken(fiatTicker, 1)) }) }) From b0050efab2ac493f88aafd75a1edab05edccc918 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 22 Mar 2022 18:58:16 +0100 Subject: [PATCH 107/164] test suit for adding contracts --- .../test/stability/stabletokenregistry.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 43995cc4f0a..d20b503b6e7 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -59,4 +59,26 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.removeStableToken(fiatTicker, 1)) }) }) + + describe('#addNewStableToken(fiatTicker)', () => { + it('only allows owner', async () => { + await assertRevert( + strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) + ) + }) + + it('does not allow empty strings', async () => { + await assertRevert(strc.addNewStableToken(fiatTicker, '')) + await assertRevert(strc.addNewStableToken('', fiatTicker)) + await assertRevert(strc.addNewStableToken('', '')) + }) + + it('has the right list of fiat tickers after addition', async () => { + const spendersBeforeAdditions = await strc.getFiatTickers() + assert.deepEqual(spendersBeforeAdditions, []) + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, []) + }) + }) }) From c3c92cb0a68754f61cf007d4ac5d2f79ce8ae39a Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 16:00:13 +0100 Subject: [PATCH 108/164] tests pass --- .../protocol/test/stability/stabletokenregistry.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index d20b503b6e7..97760e3ce92 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -6,7 +6,7 @@ const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] - const fiatTicker: string = 'USD' + const fiatTicker: string = 'cUSD' const stableTokenContractName = 'StableToken' beforeEach(async () => { @@ -49,7 +49,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.removeStableToken(fiatTicker, 1)) }) - it('removes from a big array', async () => { + it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) const fiatTickers = await strc.getFiatTickers() assert.deepEqual(fiatTickers, []) @@ -74,11 +74,11 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('has the right list of fiat tickers after addition', async () => { - const spendersBeforeAdditions = await strc.getFiatTickers() - assert.deepEqual(spendersBeforeAdditions, []) + const fiatTickersBefore = await strc.getFiatTickers() + assert.deepEqual(fiatTickersBefore, []) await strc.addNewStableToken(fiatTicker, stableTokenContractName) const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, []) + assert.deepEqual(fiatTickers, ['cUSD']) }) }) }) From d9df8209e4dcdee59534227729c79ec4d64c8e4b Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 16:08:57 +0100 Subject: [PATCH 109/164] adding more arguments to compare --- packages/protocol/test/stability/stabletokenregistry.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 97760e3ce92..0b3f60a1e35 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -35,9 +35,11 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('has the right list of fiat tickers after removing one', async () => { + await strc.addNewStableToken('cEUR', 'StableTokenEUR') + await strc.addNewStableToken('cBRL', 'StableTokenBRL') await strc.removeStableToken(fiatTicker, 0) const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, []) + assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) }) it("can't be removed twice", async () => { From da23d3d0cd10ee9d2249dc5c7138d612384b69bb Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 18:38:45 +0100 Subject: [PATCH 110/164] adding registry contract to the registry --- packages/protocol/lib/registry-utils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index d6dae2db095..c056536b354 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -38,12 +38,14 @@ export enum CeloContractName { StableTokenBRL = 'StableTokenBRL', TransferWhitelist = 'TransferWhitelist', Validators = 'Validators', + StableTokenRegistry = 'StableTokenRegistry', } export const usesRegistry = [ CeloContractName.Escrow, CeloContractName.Reserve, CeloContractName.StableToken, + CeloContractName.StableTokenRegistry ] export const hasEntryInRegistry: string[] = [ @@ -65,4 +67,5 @@ export const hasEntryInRegistry: string[] = [ CeloContractName.Reserve, CeloContractName.SortedOracles, CeloContractName.StableToken, + CeloContractName.StableTokenRegistry ] From 4762799ccd4b7b96a340607b74b201930bd44b63 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 20:11:09 +0100 Subject: [PATCH 111/164] registry migrations --- packages/protocol/migrations/26_stableToken_registry.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/protocol/migrations/26_stableToken_registry.ts diff --git a/packages/protocol/migrations/26_stableToken_registry.ts b/packages/protocol/migrations/26_stableToken_registry.ts new file mode 100644 index 00000000000..e69de29bb2d From 933e125961d01657966658a844735df39a1c6737 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 23 Mar 2022 20:11:45 +0100 Subject: [PATCH 112/164] unsaved changes --- .../migrations/26_stableToken_registry.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/protocol/migrations/26_stableToken_registry.ts b/packages/protocol/migrations/26_stableToken_registry.ts index e69de29bb2d..0fe9b38657a 100644 --- a/packages/protocol/migrations/26_stableToken_registry.ts +++ b/packages/protocol/migrations/26_stableToken_registry.ts @@ -0,0 +1,20 @@ +/* tslint:disable:no-console */ +import { CeloContractName } from '@celo/protocol/lib/registry-utils' +import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' +import { config } from '@celo/protocol/migrationsConfig' +import { StableTokenRegistryInstance } from 'types' + +const initializeArgs = async (): Promise => { + return [ + config.StableTokenRegistry.existingFiatTickers, + config.StableTokenRegistry.existingStableTokenContractNames, + ] +} + +module.exports = deploymentForCoreContract( + web3, + artifacts, + CeloContractName.StableTokenRegistry, + initializeArgs, + async (StableTokenRegistry: StableTokenRegistryInstance) => {} +) From dfb85d43b05397b65abfa83048cb4e0a2a589271 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 24 Mar 2022 10:49:44 +0100 Subject: [PATCH 113/164] bug fixed in initialized and two more found it addnewstabletoken --- .../protocol/contracts/stability/StableTokenRegistry.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 343592852bf..9e5757609bd 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -37,7 +37,7 @@ contract StableTokenRegistry is Initializable, Ownable { ); _transferOwnership(msg.sender); for (uint256 i = 0; i < existingFiatTickers.length; i++) { - addNewStableToken(fiatTickers[i], existingFiatTickers[i]); + addNewStableToken(existingFiatTickers[i], existingStableTokenContractNames[i]); } } @@ -92,13 +92,13 @@ contract StableTokenRegistry is Initializable, Ownable { public onlyOwner { - registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); + // registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); require( bytes(stableTokenContractName).length != 0, "stableTokenContractName cant be an empty string" ); - require(bytes(stableTokens[fiatTicker]).length != 0, "This registry already exists"); + // require(bytes(stableTokens[fiatTicker]).length != 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } From c64b05e9183f58820816e7fa5b0c0b766dedc472 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Mar 2022 11:45:07 +0100 Subject: [PATCH 114/164] refactoring get contracts function --- .../stability/StableTokenRegistry.sol | 44 +++++---- packages/protocol/migrationsConfig.js | 4 + .../test/stability/stabletokenregistry.ts | 90 ++++++++++--------- 3 files changed, 76 insertions(+), 62 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 9e5757609bd..d51fcbb5086 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -1,5 +1,4 @@ pragma solidity ^0.5.13; -pragma experimental ABIEncoderV2; import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; @@ -11,8 +10,8 @@ import "../common/interfaces/IRegistry.sol"; */ contract StableTokenRegistry is Initializable, Ownable { using SafeMath for uint256; - mapping(string => string) public stableTokens; - string[] public fiatTickers; + mapping(bytes => bytes) public stableTokens; + bytes[] public fiatTickers; IRegistry public registry; @@ -28,8 +27,8 @@ contract StableTokenRegistry is Initializable, Ownable { * @param existingStableTokenContractNames Collection of stable token smart contract names. */ function initialize( - string[] calldata existingFiatTickers, - string[] calldata existingStableTokenContractNames + bytes32[] calldata existingFiatTickers, + bytes32[] calldata existingStableTokenContractNames ) external initializer { require( existingFiatTickers.length == existingStableTokenContractNames.length, @@ -37,28 +36,37 @@ contract StableTokenRegistry is Initializable, Ownable { ); _transferOwnership(msg.sender); for (uint256 i = 0; i < existingFiatTickers.length; i++) { - addNewStableToken(existingFiatTickers[i], existingStableTokenContractNames[i]); + addNewStableToken( + string(abi.encodePacked(existingFiatTickers[i])), + string(abi.encodePacked(existingStableTokenContractNames[i])) + ); } } - /** - * @notice Returns fiat currencies that have been issued. - * @return A collection of currencies issued. - */ - function getFiatTickers() external view returns (string[] memory) { - return fiatTickers; - } - /** * @notice Returns all the contract instances created. * @return collection of stable token contracts. */ - function getContractInstances() external view returns (string[] memory) { - string[] memory contracts; + function getContractInstances() external view returns (bytes memory, uint256[] memory) { + bytes[] memory contracts; + uint256 totalLength = 0; for (uint256 i = 0; i < fiatTickers.length; i++) { contracts[i] = stableTokens[fiatTickers[i]]; + totalLength += stableTokens[fiatTickers[i]].length; + } + uint256 numOfContracts = contracts.length; + bytes memory concatenated = new bytes(totalLength); + uint256 lastIndex = 0; + uint256[] memory lengths = new uint256[](numOfContracts); + for (uint256 i = 0; i < numOfContracts; i++) { + bytes storage contractName = stableTokens[fiatTickers[i]]; + lengths[i] = contractName.length; + for (uint256 j = 0; j < lengths[i]; j++) { + concatenated[lastIndex] = contractName[j]; + lastIndex++; + } } - return contracts; + return (concatenated, lengths); } /** @@ -71,7 +79,7 @@ contract StableTokenRegistry is Initializable, Ownable { uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require( - keccak256(bytes(fiatTicker)) == keccak256(bytes(fiatTickers[index])), + keccak256(bytes(fiatTicker)) == keccak256(bytes(abi.encodePacked(fiatTickers[index]))), "Index does not match fiatTicker" ); uint256 newNumFiats = numFiats.sub(1); diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index 6df3ee5d3f2..41e8070fdf2 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -238,6 +238,10 @@ const DefaultConfig = { commission: 0.1, votesRatioOfLastVsFirstGroup: 2.0, }, + stableTokenRegistry: { + existingFiatTickers: ['cUSD', 'cEUR', 'cBRL'], + existingStableTokenContractNames: ['StableToken', 'StableTokenEUR', 'StableTokenBRL'], + }, } const NetworkConfigs = { diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 0b3f60a1e35..e54ee43cf87 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -26,61 +26,63 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) describe('#removeStableToken(fiatTicker)', () => { - beforeEach(async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) - }) + // beforeEach(async () => { + // await strc.addNewStableToken(fiatTicker, stableTokenContractName) + // }) it('only allows owner', async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) await assertRevert(strc.removeStableToken(fiatTicker, 0, { from: nonOwner })) }) - it('has the right list of fiat tickers after removing one', async () => { - await strc.addNewStableToken('cEUR', 'StableTokenEUR') - await strc.addNewStableToken('cBRL', 'StableTokenBRL') - await strc.removeStableToken(fiatTicker, 0) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) - }) + // it('has the right list of fiat tickers after removing one', async () => { + // await strc.addNewStableToken('cEUR', 'StableTokenEUR') + // await strc.addNewStableToken('cBRL', 'StableTokenBRL') + // await strc.removeStableToken(fiatTicker, 0) + // const fiatTickers = await strc.getFiatTickers() + // assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) + // }) - it("can't be removed twice", async () => { - await strc.removeStableToken(fiatTicker, 0) - await assertRevert(strc.removeStableToken(fiatTicker, 0)) - }) + // it("can't be removed twice", async () => { + // await strc.removeStableToken(fiatTicker, 0) + // await assertRevert(strc.removeStableToken(fiatTicker, 0)) + // }) - it("can't delete an index out of range", async () => { - await assertRevert(strc.removeStableToken(fiatTicker, 1)) - }) + // it("can't delete an index out of range", async () => { + // await assertRevert(strc.removeStableToken(fiatTicker, 1)) + // }) - it('removes from fiatTickers array', async () => { - await strc.removeStableToken(fiatTicker, 0) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, []) - }) + // it('removes from fiatTickers array', async () => { + // await strc.removeStableToken(fiatTicker, 0) + // const fiatTickers = await strc.getFiatTickers() + // assert.deepEqual(fiatTickers, []) + // }) - it("doesn't remove an fiat ticker with the wrong index", async () => { - await assertRevert(strc.removeStableToken(fiatTicker, 1)) - }) - }) + // it("doesn't remove an fiat ticker with the wrong index", async () => { + // await assertRevert(strc.removeStableToken(fiatTicker, 1)) + // }) + // }) - describe('#addNewStableToken(fiatTicker)', () => { - it('only allows owner', async () => { - await assertRevert( - strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) - ) - }) + // describe('#addNewStableToken(fiatTicker)', () => { + // it('only allows owner', async () => { + // await assertRevert( + // strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) + // ) + // }) - it('does not allow empty strings', async () => { - await assertRevert(strc.addNewStableToken(fiatTicker, '')) - await assertRevert(strc.addNewStableToken('', fiatTicker)) - await assertRevert(strc.addNewStableToken('', '')) - }) + // it('does not allow empty strings', async () => { + // await assertRevert(strc.addNewStableToken(fiatTicker, '')) + // await assertRevert(strc.addNewStableToken('', fiatTicker)) + // await assertRevert(strc.addNewStableToken('', '')) + // }) - it('has the right list of fiat tickers after addition', async () => { - const fiatTickersBefore = await strc.getFiatTickers() - assert.deepEqual(fiatTickersBefore, []) - await strc.addNewStableToken(fiatTicker, stableTokenContractName) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, ['cUSD']) - }) + // it('has the right list of fiat tickers after addition', async () => { + // const fiatTickersBefore = await strc.getFiatTickers() + // assert.deepEqual(fiatTickersBefore, []) + // await strc.addNewStableToken(fiatTicker, stableTokenContractName) + // await strc.addNewStableToken('cEUR', 'StableTokenEUR') + // const fiatTickers = await strc.getFiatTickers() + // assert.deepEqual(fiatTickers, ['cUSD', 'cEUR']) + // }) }) }) From 5a17c8f0f7752628d4479edd3d2bc4c3d79928c9 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Mar 2022 13:58:03 +0100 Subject: [PATCH 115/164] converted to bytes and contract compiles --- .../contracts/stability/StableTokenRegistry.sol | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index d51fcbb5086..edf12e06d7e 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -37,8 +37,8 @@ contract StableTokenRegistry is Initializable, Ownable { _transferOwnership(msg.sender); for (uint256 i = 0; i < existingFiatTickers.length; i++) { addNewStableToken( - string(abi.encodePacked(existingFiatTickers[i])), - string(abi.encodePacked(existingStableTokenContractNames[i])) + abi.encodePacked(existingFiatTickers[i]), + abi.encodePacked(existingStableTokenContractNames[i]) ); } } @@ -74,12 +74,12 @@ contract StableTokenRegistry is Initializable, Ownable { * @param fiatTicker The currency that is no longer supported. * @param index The index in fiatTickers of fiatTicker. */ - function removeStableToken(string calldata fiatTicker, uint256 index) external onlyOwner { - stableTokens[fiatTicker] = ""; + function removeStableToken(bytes calldata fiatTicker, uint256 index) external onlyOwner { + delete stableTokens[fiatTicker]; uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); require( - keccak256(bytes(fiatTicker)) == keccak256(bytes(abi.encodePacked(fiatTickers[index]))), + keccak256(fiatTicker) == keccak256(fiatTickers[index]), "Index does not match fiatTicker" ); uint256 newNumFiats = numFiats.sub(1); @@ -96,7 +96,7 @@ contract StableTokenRegistry is Initializable, Ownable { * @param fiatTicker The currency we are trying to add in the registry. * @param stableTokenContractName The contract we are trying to add in the registry. */ - function addNewStableToken(string memory fiatTicker, string memory stableTokenContractName) + function addNewStableToken(bytes memory fiatTicker, bytes memory stableTokenContractName) public onlyOwner { @@ -110,5 +110,4 @@ contract StableTokenRegistry is Initializable, Ownable { stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } - } From c7b400062c35cb51a83cc6dfa41deaa616fb73e6 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 25 Mar 2022 14:35:46 +0100 Subject: [PATCH 116/164] initialize function added to tests --- .../test/stability/stabletokenregistry.ts | 119 +++++++++--------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index e54ee43cf87..f110b67462d 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,17 +1,24 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' +// import { keccak256 } from 'web3-utils' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') +const convertToHex = (input: string) => { + return web3.utils.utf8ToHex(input) +} + contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] - const fiatTicker: string = 'cUSD' - const stableTokenContractName = 'StableToken' + const fiatTicker: string = convertToHex('cBRL') + const stableTokenContractName = convertToHex('StableTokenBRL') + const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] + const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] beforeEach(async () => { strc = await STRC.new(true) - await strc.initialize([], []) + await strc.initialize(fiatTickers, stableTokenContractNames) }) describe('#initialize()', async () => { @@ -21,68 +28,68 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('should not be callable again', async () => { - await assertRevert(strc.initialize([], [])) + await assertRevert(strc.initialize(fiatTickers, stableTokenContractNames)) }) }) describe('#removeStableToken(fiatTicker)', () => { - // beforeEach(async () => { - // await strc.addNewStableToken(fiatTicker, stableTokenContractName) - // }) + beforeEach(async () => { + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + }) it('only allows owner', async () => { await strc.addNewStableToken(fiatTicker, stableTokenContractName) await assertRevert(strc.removeStableToken(fiatTicker, 0, { from: nonOwner })) }) - // it('has the right list of fiat tickers after removing one', async () => { - // await strc.addNewStableToken('cEUR', 'StableTokenEUR') - // await strc.addNewStableToken('cBRL', 'StableTokenBRL') - // await strc.removeStableToken(fiatTicker, 0) - // const fiatTickers = await strc.getFiatTickers() - // assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) - // }) - - // it("can't be removed twice", async () => { - // await strc.removeStableToken(fiatTicker, 0) - // await assertRevert(strc.removeStableToken(fiatTicker, 0)) - // }) - - // it("can't delete an index out of range", async () => { - // await assertRevert(strc.removeStableToken(fiatTicker, 1)) - // }) - - // it('removes from fiatTickers array', async () => { - // await strc.removeStableToken(fiatTicker, 0) - // const fiatTickers = await strc.getFiatTickers() - // assert.deepEqual(fiatTickers, []) - // }) - - // it("doesn't remove an fiat ticker with the wrong index", async () => { - // await assertRevert(strc.removeStableToken(fiatTicker, 1)) - // }) - // }) - - // describe('#addNewStableToken(fiatTicker)', () => { - // it('only allows owner', async () => { - // await assertRevert( - // strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) - // ) - // }) - - // it('does not allow empty strings', async () => { - // await assertRevert(strc.addNewStableToken(fiatTicker, '')) - // await assertRevert(strc.addNewStableToken('', fiatTicker)) - // await assertRevert(strc.addNewStableToken('', '')) - // }) - - // it('has the right list of fiat tickers after addition', async () => { - // const fiatTickersBefore = await strc.getFiatTickers() - // assert.deepEqual(fiatTickersBefore, []) - // await strc.addNewStableToken(fiatTicker, stableTokenContractName) - // await strc.addNewStableToken('cEUR', 'StableTokenEUR') - // const fiatTickers = await strc.getFiatTickers() - // assert.deepEqual(fiatTickers, ['cUSD', 'cEUR']) - // }) + it('has the right list of fiat tickers after removing one', async () => { + await strc.addNewStableToken('cEUR', 'StableTokenEUR') + await strc.addNewStableToken('cBRL', 'StableTokenBRL') + await strc.removeStableToken(fiatTicker, 0) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) + }) + + it("can't be removed twice", async () => { + await strc.removeStableToken(fiatTicker, 0) + await assertRevert(strc.removeStableToken(fiatTicker, 0)) + }) + + it("can't delete an index out of range", async () => { + await assertRevert(strc.removeStableToken(fiatTicker, 1)) + }) + + it('removes from fiatTickers array', async () => { + await strc.removeStableToken(fiatTicker, 0) + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, []) + }) + + it("doesn't remove an fiat ticker with the wrong index", async () => { + await assertRevert(strc.removeStableToken(fiatTicker, 1)) + }) + }) + + describe('#addNewStableToken(fiatTicker)', () => { + it('only allows owner', async () => { + await assertRevert( + strc.addNewStableToken(fiatTicker, stableTokenContractName, { from: nonOwner }) + ) + }) + + it('does not allow empty strings', async () => { + await assertRevert(strc.addNewStableToken(fiatTicker, '')) + await assertRevert(strc.addNewStableToken('', fiatTicker)) + await assertRevert(strc.addNewStableToken('', '')) + }) + + it('has the right list of fiat tickers after addition', async () => { + const fiatTickersBefore = await strc.getFiatTickers() + assert.deepEqual(fiatTickersBefore, []) + await strc.addNewStableToken(fiatTicker, stableTokenContractName) + await strc.addNewStableToken('cEUR', 'StableTokenEUR') + const fiatTickers = await strc.getFiatTickers() + assert.deepEqual(fiatTickers, ['cUSD', 'cEUR']) + }) }) }) From 40d08a54007f61b2dcedbe28c45b3dc29929dabf Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 29 Mar 2022 12:07:03 +0200 Subject: [PATCH 117/164] 8 tests pass, refactoring the contract --- .../stability/StableTokenRegistry.sol | 4 +- .../test/stability/stabletokenregistry.ts | 69 ++++++++++++------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index edf12e06d7e..827f684c40b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -80,7 +80,7 @@ contract StableTokenRegistry is Initializable, Ownable { require(index < numFiats, "Index is invalid"); require( keccak256(fiatTicker) == keccak256(fiatTickers[index]), - "Index does not match fiatTicker" + "Source fiatTicker does not match the one in the storage on given index" ); uint256 newNumFiats = numFiats.sub(1); @@ -106,7 +106,7 @@ contract StableTokenRegistry is Initializable, Ownable { bytes(stableTokenContractName).length != 0, "stableTokenContractName cant be an empty string" ); - // require(bytes(stableTokens[fiatTicker]).length != 0, "This registry already exists"); + require(stableTokens[fiatTicker].length == 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index f110b67462d..ce2850af765 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,6 +1,5 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' -// import { keccak256 } from 'web3-utils' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') @@ -12,10 +11,24 @@ contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] - const fiatTicker: string = convertToHex('cBRL') - const stableTokenContractName = convertToHex('StableTokenBRL') + const fiatTicker: string = convertToHex('cUSD') + const stableTokenContractName = convertToHex('StableToken') const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] + + const getFiatTickers = async () => { + const updatedFiatTickers = [] + for (let i = 0; i < 180; i++) { + try { + updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(i))) + } catch (error) { + console.log(error) + break + } + } + return updatedFiatTickers + } + beforeEach(async () => { strc = await STRC.new(true) await strc.initialize(fiatTickers, stableTokenContractNames) @@ -34,7 +47,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { describe('#removeStableToken(fiatTicker)', () => { beforeEach(async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) + await strc.addNewStableToken(convertToHex('cBRL'), convertToHex('StableTokenBRL')) }) it('only allows owner', async () => { @@ -43,30 +56,35 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('has the right list of fiat tickers after removing one', async () => { - await strc.addNewStableToken('cEUR', 'StableTokenEUR') - await strc.addNewStableToken('cBRL', 'StableTokenBRL') + await strc.addNewStableToken(fiatTicker, stableTokenContractName) await strc.removeStableToken(fiatTicker, 0) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, ['cBRL', 'cEUR']) + const updatedFiatTickers = await getFiatTickers() + assert.deepEqual(updatedFiatTickers, ['cEUR', 'cBRL']) }) + // it('has the right list of contract names after removing one', async () => { + // await strc.addNewStableToken(fiatTicker, stableTokenContractName) + // await strc.removeStableToken(fiatTicker, 0) + // const updatedContractNames = strc.getContractInstances(); + // }) + it("can't be removed twice", async () => { - await strc.removeStableToken(fiatTicker, 0) - await assertRevert(strc.removeStableToken(fiatTicker, 0)) + await strc.removeStableToken(convertToHex('cUSD'), 0) + await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 0)) }) it("can't delete an index out of range", async () => { - await assertRevert(strc.removeStableToken(fiatTicker, 1)) + await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) }) it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, []) + const updatedFiatTickers = await getFiatTickers() + assert.deepEqual(updatedFiatTickers, []) }) it("doesn't remove an fiat ticker with the wrong index", async () => { - await assertRevert(strc.removeStableToken(fiatTicker, 1)) + await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) }) }) @@ -78,18 +96,23 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('does not allow empty strings', async () => { - await assertRevert(strc.addNewStableToken(fiatTicker, '')) - await assertRevert(strc.addNewStableToken('', fiatTicker)) - await assertRevert(strc.addNewStableToken('', '')) + await assertRevert(strc.addNewStableToken(fiatTicker, convertToHex(''))) + await assertRevert(strc.addNewStableToken(convertToHex(''), fiatTicker)) + await assertRevert(strc.addNewStableToken(convertToHex(''), convertToHex(''))) }) it('has the right list of fiat tickers after addition', async () => { - const fiatTickersBefore = await strc.getFiatTickers() - assert.deepEqual(fiatTickersBefore, []) - await strc.addNewStableToken(fiatTicker, stableTokenContractName) - await strc.addNewStableToken('cEUR', 'StableTokenEUR') - const fiatTickers = await strc.getFiatTickers() - assert.deepEqual(fiatTickers, ['cUSD', 'cEUR']) + const fiatTickersBefore = await getFiatTickers() + assert.deepEqual(fiatTickersBefore, ['cUSD', 'cEUR']) + await strc.addNewStableToken(convertToHex('cBRL'), convertToHex('StableTokenEUR')) + const updatedFiatTickers = await getFiatTickers() + assert.deepEqual(updatedFiatTickers, ['cUSD', 'cEUR', 'cBRL']) }) }) + + // it('has no duplicates', async () => { + // console.log('yay') + // console.log(await getFiatTickers); + // await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) + // }) }) From 377f508e4201fee6799d8d2b4f38cd2b2540c21c Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 29 Mar 2022 16:09:55 +0200 Subject: [PATCH 118/164] latest --- .../stability/StableTokenRegistry.sol | 21 +++++++++++-------- .../test/stability/stabletokenregistry.ts | 15 ++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 827f684c40b..85bf2439d3c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -78,10 +78,16 @@ contract StableTokenRegistry is Initializable, Ownable { delete stableTokens[fiatTicker]; uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); - require( - keccak256(fiatTicker) == keccak256(fiatTickers[index]), - "Source fiatTicker does not match the one in the storage on given index" - ); + // require(fiatTicker.length == fiatTickers[index].length, "mismatch in length"); + for (uint256 i = 0; i < fiatTicker.length; i++) { + for (uint256 j = 0; j < fiatTickers[index].length; j++) { + require(fiatTicker[i] == fiatTickers[index][i]); + } + } + // require( + // keccak256(abi.encodePacked(fiatTicker)) == keccak256(abi.encodePacked(fiatTickers[index])), + // "Source fiatTicker does not match the one in the storage on given index" + // ); uint256 newNumFiats = numFiats.sub(1); if (index != newNumFiats) { @@ -101,11 +107,8 @@ contract StableTokenRegistry is Initializable, Ownable { onlyOwner { // registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); - require(bytes(fiatTicker).length != 0, "fiatTicker cant be an empty string"); - require( - bytes(stableTokenContractName).length != 0, - "stableTokenContractName cant be an empty string" - ); + require(fiatTicker.length != 0, "fiatTicker cant be an empty string"); + require(stableTokenContractName.length != 0, "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker].length == 0, "This registry already exists"); stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index ce2850af765..2ff9305b6f5 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -56,10 +56,9 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('has the right list of fiat tickers after removing one', async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, ['cEUR', 'cBRL']) + assert.deepEqual(updatedFiatTickers, ['cBRL', 'cEUR']) }) // it('has the right list of contract names after removing one', async () => { @@ -80,7 +79,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, []) + assert.deepEqual(updatedFiatTickers, ['cBRL', 'cEUR']) }) it("doesn't remove an fiat ticker with the wrong index", async () => { @@ -101,6 +100,10 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.addNewStableToken(convertToHex(''), convertToHex(''))) }) + it('does not allow duplicate values', async () => { + await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) + }) + it('has the right list of fiat tickers after addition', async () => { const fiatTickersBefore = await getFiatTickers() assert.deepEqual(fiatTickersBefore, ['cUSD', 'cEUR']) @@ -109,10 +112,4 @@ contract('StableTokenRegistry', (accounts: string[]) => { assert.deepEqual(updatedFiatTickers, ['cUSD', 'cEUR', 'cBRL']) }) }) - - // it('has no duplicates', async () => { - // console.log('yay') - // console.log(await getFiatTickers); - // await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) - // }) }) From 36e149d3d50bb7ccec8e89a1eab9ff1660115061 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 29 Mar 2022 19:07:37 +0200 Subject: [PATCH 119/164] fixing bugs --- .../contracts/stability/StableTokenRegistry.sol | 12 +++++------- .../protocol/test/stability/stabletokenregistry.ts | 8 +++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 85bf2439d3c..8346aeddfcc 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -78,16 +78,14 @@ contract StableTokenRegistry is Initializable, Ownable { delete stableTokens[fiatTicker]; uint256 numFiats = fiatTickers.length; require(index < numFiats, "Index is invalid"); - // require(fiatTicker.length == fiatTickers[index].length, "mismatch in length"); for (uint256 i = 0; i < fiatTicker.length; i++) { - for (uint256 j = 0; j < fiatTickers[index].length; j++) { - require(fiatTicker[i] == fiatTickers[index][i]); + if (fiatTicker[i] != 0) { + require( + fiatTicker[i] == fiatTickers[index][i], + "source doesn't match the existing fiatTicker" + ); } } - // require( - // keccak256(abi.encodePacked(fiatTicker)) == keccak256(abi.encodePacked(fiatTickers[index])), - // "Source fiatTicker does not match the one in the storage on given index" - // ); uint256 newNumFiats = numFiats.sub(1); if (index != newNumFiats) { diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 2ff9305b6f5..a868feef1c9 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -22,11 +22,9 @@ contract('StableTokenRegistry', (accounts: string[]) => { try { updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(i))) } catch (error) { - console.log(error) - break + return updatedFiatTickers } } - return updatedFiatTickers } beforeEach(async () => { @@ -85,6 +83,10 @@ contract('StableTokenRegistry', (accounts: string[]) => { it("doesn't remove an fiat ticker with the wrong index", async () => { await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) }) + + it('reverts if a wrong values is passed as a fiatTicker', async () => { + await assertRevert(strc.removeStableToken(convertToHex('cEUR'), 0)) + }) }) describe('#addNewStableToken(fiatTicker)', () => { From ac8e49310f5af50c8dfe17013eda744cbbe69dbc Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 31 Mar 2022 19:44:58 +0200 Subject: [PATCH 120/164] =?UTF-8?q?everything=20works=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stability/StableTokenRegistry.sol | 47 +++++++----- .../test/stability/stabletokenregistry.ts | 71 ++++++++++++------- 2 files changed, 77 insertions(+), 41 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 8346aeddfcc..f700452fc84 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -4,6 +4,7 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; import "../common/interfaces/IRegistry.sol"; +import "../common/UsingRegistry.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. @@ -23,24 +24,28 @@ contract StableTokenRegistry is Initializable, Ownable { /** * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. - * @param existingFiatTickers Collection of fiat currencies issued already. - * @param existingStableTokenContractNames Collection of stable token smart contract names. + * @param fiatTicker Collection of fiat currencies issued already. + * @param stableTokenContractName Collection of stable token smart contract names. */ - function initialize( - bytes32[] calldata existingFiatTickers, - bytes32[] calldata existingStableTokenContractNames - ) external initializer { - require( - existingFiatTickers.length == existingStableTokenContractNames.length, - "Array length mismatch" - ); + function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) + external + initializer + { + // require( + // existingFiatTickers.length == existingStableTokenContractNames.length, + // "Array length mismatch" + // ); _transferOwnership(msg.sender); - for (uint256 i = 0; i < existingFiatTickers.length; i++) { - addNewStableToken( - abi.encodePacked(existingFiatTickers[i]), - abi.encodePacked(existingStableTokenContractNames[i]) - ); - } + bytes memory USD = bytes("USD"); + bytes memory StableToken = "537461626c65546f6b656e"; + bytes memory EUR = "455552"; + bytes memory StableTokenEUR = "537461626c65546f6b656e455552"; + bytes memory BRL = "42524c"; + bytes memory StableTokenBRL = "537461626c65546f6b656e42524c"; + addNewStableToken(bytes("USD"), bytes("StableToken")); + addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); + addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); + addNewStableToken(fiatTicker, stableTokenContractName); } /** @@ -111,4 +116,14 @@ contract StableTokenRegistry is Initializable, Ownable { stableTokens[fiatTicker] = stableTokenContractName; fiatTickers.push(fiatTicker); } + + // TODO make function that inputs fiatTicker and returns a StableTokenContract + + /** + * @notice Adds new Fiat Ticker and Stable Token contract to the registry. + * @param fiatTicker The currency we are trying to add in the registry. + */ + function getFiatTickerLength(bytes memory fiatTicker) public returns (bytes memory) { + return stableTokens[fiatTicker]; + } } diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index a868feef1c9..439e38593f8 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,35 +1,57 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' + + const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') +// const Registry: RegistryContract = artifacts.require('Registry') + const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) } +// const assertSTContractNames = (contractsHex: string, lengths: BigNumber[], expectedContracts: string[]) => { +// assert.equal(lengths.length, expectedContracts.length) +// const contracts = web3.utils.hexToUtf8(contractsHex) +// let currentIndex = 0 +// expectedContracts.forEach((expectedContract: string, i: number) => { +// const contract = contracts.slice(currentIndex, currentIndex + lengths[i].toNumber()) +// currentIndex += lengths[i].toNumber() +// assert.equal(contract, expectedContract) +// }) +// assert.equal(contracts.length, currentIndex) +// } + + contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] - const fiatTicker: string = convertToHex('cUSD') + const fiatTicker: string = convertToHex('USD') const stableTokenContractName = convertToHex('StableToken') - const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] - const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] + // const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] + // const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] const getFiatTickers = async () => { const updatedFiatTickers = [] - for (let i = 0; i < 180; i++) { - try { - updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(i))) + try + { + let index = 0 + while (await strc.fiatTickers(index)) { + updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(index))) + index++ + } } catch (error) { return updatedFiatTickers - } } } beforeEach(async () => { strc = await STRC.new(true) - await strc.initialize(fiatTickers, stableTokenContractNames) + // const registry = await Registry.new(true) + // await registry.setAddressFor(CeloContractName.StableTokenRegistry, strc.address) + await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL')) }) describe('#initialize()', async () => { @@ -39,53 +61,52 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) it('should not be callable again', async () => { - await assertRevert(strc.initialize(fiatTickers, stableTokenContractNames)) + await assertRevert(strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'))) }) }) describe('#removeStableToken(fiatTicker)', () => { beforeEach(async () => { - await strc.addNewStableToken(convertToHex('cBRL'), convertToHex('StableTokenBRL')) + await strc.addNewStableToken(convertToHex('GBP'), convertToHex('StableTokenGBP')) }) it('only allows owner', async () => { - await strc.addNewStableToken(fiatTicker, stableTokenContractName) await assertRevert(strc.removeStableToken(fiatTicker, 0, { from: nonOwner })) }) it('has the right list of fiat tickers after removing one', async () => { await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, ['cBRL', 'cEUR']) + assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) // it('has the right list of contract names after removing one', async () => { - // await strc.addNewStableToken(fiatTicker, stableTokenContractName) - // await strc.removeStableToken(fiatTicker, 0) - // const updatedContractNames = strc.getContractInstances(); + // await strc.removeStableToken(fiatTicker, 0) + // const [contractsHex, lengths] = await strc.getContractInstances() + // assertSTContractNames(contractsHex, lengths, []) // }) it("can't be removed twice", async () => { - await strc.removeStableToken(convertToHex('cUSD'), 0) - await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 0)) + await strc.removeStableToken(convertToHex('USD'), 0) + await assertRevert(strc.removeStableToken(convertToHex('USD'), 0)) }) it("can't delete an index out of range", async () => { - await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) + await assertRevert(strc.removeStableToken(convertToHex('USD'), 1)) }) it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, ['cBRL', 'cEUR']) + assert.deepEqual(updatedFiatTickers, [ 'GBP', 'EUR', 'BRL', 'GEL' ]) }) it("doesn't remove an fiat ticker with the wrong index", async () => { - await assertRevert(strc.removeStableToken(convertToHex('cUSD'), 1)) + await assertRevert(strc.removeStableToken(convertToHex('USD'), 1)) }) it('reverts if a wrong values is passed as a fiatTicker', async () => { - await assertRevert(strc.removeStableToken(convertToHex('cEUR'), 0)) + await assertRevert(strc.removeStableToken(convertToHex('EUR'), 0)) }) }) @@ -101,17 +122,17 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.addNewStableToken(convertToHex(''), fiatTicker)) await assertRevert(strc.addNewStableToken(convertToHex(''), convertToHex(''))) }) - + it('does not allow duplicate values', async () => { await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) }) it('has the right list of fiat tickers after addition', async () => { const fiatTickersBefore = await getFiatTickers() - assert.deepEqual(fiatTickersBefore, ['cUSD', 'cEUR']) - await strc.addNewStableToken(convertToHex('cBRL'), convertToHex('StableTokenEUR')) + assert.deepEqual(fiatTickersBefore, ['USD', 'EUR', 'BRL', 'GEL']) + await strc.addNewStableToken(convertToHex('MXN'), convertToHex('StableTokenMXN')) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, ['cUSD', 'cEUR', 'cBRL']) + assert.deepEqual(updatedFiatTickers, ['USD', 'EUR', 'BRL', 'GEL', 'MXN']) }) }) }) From 6eef5b9710cc1b52926475f2cbf5710009713a74 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Sat, 2 Apr 2022 17:20:21 +0200 Subject: [PATCH 121/164] added a contraxt query function + tests --- .../stability/StableTokenRegistry.sol | 8 +-- .../test/stability/stabletokenregistry.ts | 61 +++++++++++-------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index f700452fc84..aed705fb763 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -117,13 +117,11 @@ contract StableTokenRegistry is Initializable, Ownable { fiatTickers.push(fiatTicker); } - // TODO make function that inputs fiatTicker and returns a StableTokenContract - /** - * @notice Adds new Fiat Ticker and Stable Token contract to the registry. - * @param fiatTicker The currency we are trying to add in the registry. + * @notice Queries a corresponding StableToken contract name based on fiat ticker. + * @param fiatTicker Type of currency to query corresponding contract. */ - function getFiatTickerLength(bytes memory fiatTicker) public returns (bytes memory) { + function queryStableTokenContractNames(bytes memory fiatTicker) public returns (bytes memory) { return stableTokens[fiatTicker]; } } diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 439e38593f8..9e273cd9822 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,28 +1,30 @@ import { assertRevert } from '@celo/protocol/lib/test-utils' +import BigNumber from 'bignumber.js' import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' - - const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') -// const Registry: RegistryContract = artifacts.require('Registry') +// const Registry: RegistryContract = artifacts.require('Registry') const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) } -// const assertSTContractNames = (contractsHex: string, lengths: BigNumber[], expectedContracts: string[]) => { -// assert.equal(lengths.length, expectedContracts.length) -// const contracts = web3.utils.hexToUtf8(contractsHex) -// let currentIndex = 0 -// expectedContracts.forEach((expectedContract: string, i: number) => { -// const contract = contracts.slice(currentIndex, currentIndex + lengths[i].toNumber()) -// currentIndex += lengths[i].toNumber() -// assert.equal(contract, expectedContract) -// }) -// assert.equal(contracts.length, currentIndex) -// } - +const assertSTContractNames = ( + contractsHex: string, + lengths: BigNumber[], + expectedContracts: string[] +) => { + assert.equal(lengths.length, expectedContracts.length) + const contracts = web3.utils.hexToUtf8(contractsHex) + let currentIndex = 0 + expectedContracts.forEach((expectedContract: string, i: number) => { + const contract = contracts.slice(currentIndex, currentIndex + lengths[i].toNumber()) + currentIndex += lengths[i].toNumber() + assert.equal(contract, expectedContract) + }) + assert.equal(contracts.length, currentIndex) +} contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance @@ -35,15 +37,14 @@ contract('StableTokenRegistry', (accounts: string[]) => { const getFiatTickers = async () => { const updatedFiatTickers = [] - try - { + try { let index = 0 - while (await strc.fiatTickers(index)) { + while (await strc.fiatTickers(index)) { updatedFiatTickers.push(web3.utils.hexToUtf8(await strc.fiatTickers(index))) index++ - } - } catch (error) { - return updatedFiatTickers + } + } catch (error) { + return updatedFiatTickers } } @@ -81,9 +82,12 @@ contract('StableTokenRegistry', (accounts: string[]) => { }) // it('has the right list of contract names after removing one', async () => { - // await strc.removeStableToken(fiatTicker, 0) + // console.log('yes') + // await strc.removeStableToken(fiatTicker, 0) + // console.log('works'); // const [contractsHex, lengths] = await strc.getContractInstances() - // assertSTContractNames(contractsHex, lengths, []) + // console.log(contractsHex, lengths); + // assertSTContractNames(contractsHex, lengths, ['StableTokenEUR', 'StableTokenBRL']) // }) it("can't be removed twice", async () => { @@ -98,7 +102,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { it('removes from fiatTickers array', async () => { await strc.removeStableToken(fiatTicker, 0) const updatedFiatTickers = await getFiatTickers() - assert.deepEqual(updatedFiatTickers, [ 'GBP', 'EUR', 'BRL', 'GEL' ]) + assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) it("doesn't remove an fiat ticker with the wrong index", async () => { @@ -122,7 +126,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { await assertRevert(strc.addNewStableToken(convertToHex(''), fiatTicker)) await assertRevert(strc.addNewStableToken(convertToHex(''), convertToHex(''))) }) - + it('does not allow duplicate values', async () => { await assertRevert(strc.addNewStableToken(fiatTicker, stableTokenContractName)) }) @@ -135,4 +139,11 @@ contract('StableTokenRegistry', (accounts: string[]) => { assert.deepEqual(updatedFiatTickers, ['USD', 'EUR', 'BRL', 'GEL', 'MXN']) }) }) + + describe('#queryStableTokenContractNames(fiatTicker)', () => { + it('returns the corresponfing contract name', async () => { + const queriedContract = await strc.queryStableTokenContractNames.call(fiatTicker) + assert.deepEqual(queriedContract, stableTokenContractName) + }) + }) }) From e5c45749f32e216f4cdd565b8f380160f6d9bc13 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Sat, 2 Apr 2022 17:52:26 +0200 Subject: [PATCH 122/164] =?UTF-8?q?lists=20all=20the=20correct=20contract?= =?UTF-8?q?=20namea=20after=20adding=20and=20removing=20one=20=E2=9C=A8?= =?UTF-8?q?=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stability/StableTokenRegistry.sol | 15 ++-------- .../test/stability/stabletokenregistry.ts | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index aed705fb763..a12450b4036 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -31,17 +31,7 @@ contract StableTokenRegistry is Initializable, Ownable { external initializer { - // require( - // existingFiatTickers.length == existingStableTokenContractNames.length, - // "Array length mismatch" - // ); _transferOwnership(msg.sender); - bytes memory USD = bytes("USD"); - bytes memory StableToken = "537461626c65546f6b656e"; - bytes memory EUR = "455552"; - bytes memory StableTokenEUR = "537461626c65546f6b656e455552"; - bytes memory BRL = "42524c"; - bytes memory StableTokenBRL = "537461626c65546f6b656e42524c"; addNewStableToken(bytes("USD"), bytes("StableToken")); addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); @@ -53,13 +43,12 @@ contract StableTokenRegistry is Initializable, Ownable { * @return collection of stable token contracts. */ function getContractInstances() external view returns (bytes memory, uint256[] memory) { - bytes[] memory contracts; + // bytes[] memory contracts; uint256 totalLength = 0; for (uint256 i = 0; i < fiatTickers.length; i++) { - contracts[i] = stableTokens[fiatTickers[i]]; totalLength += stableTokens[fiatTickers[i]].length; } - uint256 numOfContracts = contracts.length; + uint256 numOfContracts = fiatTickers.length; bytes memory concatenated = new bytes(totalLength); uint256 lastIndex = 0; uint256[] memory lengths = new uint256[](numOfContracts); diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 9e273cd9822..99cf62dfc9c 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -81,14 +81,16 @@ contract('StableTokenRegistry', (accounts: string[]) => { assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) - // it('has the right list of contract names after removing one', async () => { - // console.log('yes') - // await strc.removeStableToken(fiatTicker, 0) - // console.log('works'); - // const [contractsHex, lengths] = await strc.getContractInstances() - // console.log(contractsHex, lengths); - // assertSTContractNames(contractsHex, lengths, ['StableTokenEUR', 'StableTokenBRL']) - // }) + it('has the right list of contract names after removing one', async () => { + await strc.removeStableToken(fiatTicker, 0) + const [contractsHex, lengths] = await strc.getContractInstances() + assertSTContractNames(contractsHex, lengths, [ + 'StableTokenGBP', + 'StableTokenEUR', + 'StableTokenBRL', + 'StableTokenGEL', + ]) + }) it("can't be removed twice", async () => { await strc.removeStableToken(convertToHex('USD'), 0) @@ -138,6 +140,18 @@ contract('StableTokenRegistry', (accounts: string[]) => { const updatedFiatTickers = await getFiatTickers() assert.deepEqual(updatedFiatTickers, ['USD', 'EUR', 'BRL', 'GEL', 'MXN']) }) + + it('has the right list of contract names after adding one', async () => { + await strc.addNewStableToken(convertToHex('MXN'), convertToHex('StableTokenMXN')) + const [contractsHex, lengths] = await strc.getContractInstances() + assertSTContractNames(contractsHex, lengths, [ + 'StableToken', + 'StableTokenEUR', + 'StableTokenBRL', + 'StableTokenGEL', + 'StableTokenMXN', + ]) + }) }) describe('#queryStableTokenContractNames(fiatTicker)', () => { From 31c5f0968a153f94138669fdc0f99367d083e9b9 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Sat, 2 Apr 2022 18:32:02 +0200 Subject: [PATCH 123/164] all functions are fully tested and work --- .../protocol/contracts/stability/StableTokenRegistry.sol | 1 - packages/protocol/test/stability/stabletokenregistry.ts | 6 ------ 2 files changed, 7 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index a12450b4036..1bc10a45a6d 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -43,7 +43,6 @@ contract StableTokenRegistry is Initializable, Ownable { * @return collection of stable token contracts. */ function getContractInstances() external view returns (bytes memory, uint256[] memory) { - // bytes[] memory contracts; uint256 totalLength = 0; for (uint256 i = 0; i < fiatTickers.length; i++) { totalLength += stableTokens[fiatTickers[i]].length; diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 99cf62dfc9c..78593715daf 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -4,8 +4,6 @@ import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') -// const Registry: RegistryContract = artifacts.require('Registry') - const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) } @@ -32,8 +30,6 @@ contract('StableTokenRegistry', (accounts: string[]) => { const fiatTicker: string = convertToHex('USD') const stableTokenContractName = convertToHex('StableToken') - // const fiatTickers: string[] = [convertToHex('cUSD'), convertToHex('cEUR')] - // const stableTokenContractNames = [convertToHex('StableToken'), convertToHex('StableTokenEUR')] const getFiatTickers = async () => { const updatedFiatTickers = [] @@ -50,8 +46,6 @@ contract('StableTokenRegistry', (accounts: string[]) => { beforeEach(async () => { strc = await STRC.new(true) - // const registry = await Registry.new(true) - // await registry.setAddressFor(CeloContractName.StableTokenRegistry, strc.address) await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL')) }) From e37f27223e2790dbb15e349de5e36d8f325e67b7 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 12:25:24 +0200 Subject: [PATCH 124/164] adding it to the registry --- .../contracts/stability/StableTokenRegistry.sol | 13 ++++++++----- .../protocol/test/stability/stabletokenregistry.ts | 13 ++++++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 1bc10a45a6d..2de7612197b 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -9,7 +9,7 @@ import "../common/UsingRegistry.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ -contract StableTokenRegistry is Initializable, Ownable { +contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { using SafeMath for uint256; mapping(bytes => bytes) public stableTokens; bytes[] public fiatTickers; @@ -26,16 +26,19 @@ contract StableTokenRegistry is Initializable, Ownable { * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. * @param fiatTicker Collection of fiat currencies issued already. * @param stableTokenContractName Collection of stable token smart contract names. + * @param registryAddress The address of the registry core smart contract. */ - function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) - external - initializer - { + function initialize( + bytes calldata fiatTicker, + bytes calldata stableTokenContractName, + address registryAddress + ) external initializer { _transferOwnership(msg.sender); addNewStableToken(bytes("USD"), bytes("StableToken")); addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); addNewStableToken(fiatTicker, stableTokenContractName); + setRegistry(registryAddress); } /** diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 78593715daf..df83a19b7ad 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,8 +1,10 @@ +import { CeloContractName } from '@celo/protocol/lib/registry-utils' import { assertRevert } from '@celo/protocol/lib/test-utils' import BigNumber from 'bignumber.js' -import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' +import { RegistryContract, StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') +const Registry: RegistryContract = artifacts.require('Registry') const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) @@ -46,17 +48,22 @@ contract('StableTokenRegistry', (accounts: string[]) => { beforeEach(async () => { strc = await STRC.new(true) - await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL')) + const registry = await Registry.new(true) + await registry.setAddressFor(CeloContractName.Accounts, strc.address) + await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) }) describe('#initialize()', async () => { + const registry = await Registry.new(true) it('should have set the owner', async () => { const owner: string = await strc.owner() assert.equal(owner, accounts[0]) }) it('should not be callable again', async () => { - await assertRevert(strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'))) + await assertRevert( + strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) + ) }) }) From b75d70d5ac0c07df0ae2693bd95e827c16993b40 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 14:34:26 +0200 Subject: [PATCH 125/164] finished --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 1 - packages/protocol/migrations/26_stableToken_registry.ts | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 2de7612197b..cb5ea00c1ae 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -100,7 +100,6 @@ contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { public onlyOwner { - // registry.getAddressForOrDie(keccak256(abi.encodePacked(stableTokenContractName))); require(fiatTicker.length != 0, "fiatTicker cant be an empty string"); require(stableTokenContractName.length != 0, "stableTokenContractName cant be an empty string"); require(stableTokens[fiatTicker].length == 0, "This registry already exists"); diff --git a/packages/protocol/migrations/26_stableToken_registry.ts b/packages/protocol/migrations/26_stableToken_registry.ts index 0fe9b38657a..0e95af2dae1 100644 --- a/packages/protocol/migrations/26_stableToken_registry.ts +++ b/packages/protocol/migrations/26_stableToken_registry.ts @@ -16,5 +16,6 @@ module.exports = deploymentForCoreContract( artifacts, CeloContractName.StableTokenRegistry, initializeArgs, - async (StableTokenRegistry: StableTokenRegistryInstance) => {} + // tslint:disable-next-line: no-empty + async (_StableTokenRegistry: StableTokenRegistryInstance) => {} ) From ac340c77ef10ef21d85fe10a89df850ec7ecf6dd Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 15:38:12 +0200 Subject: [PATCH 126/164] fixed migrations --- ...26_stableToken_registry.ts => 27_stableToken_registry.ts} | 5 +---- packages/protocol/migrationsConfig.js | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) rename packages/protocol/migrations/{26_stableToken_registry.ts => 27_stableToken_registry.ts} (81%) diff --git a/packages/protocol/migrations/26_stableToken_registry.ts b/packages/protocol/migrations/27_stableToken_registry.ts similarity index 81% rename from packages/protocol/migrations/26_stableToken_registry.ts rename to packages/protocol/migrations/27_stableToken_registry.ts index 0e95af2dae1..a56431d7b2c 100644 --- a/packages/protocol/migrations/26_stableToken_registry.ts +++ b/packages/protocol/migrations/27_stableToken_registry.ts @@ -5,10 +5,7 @@ import { config } from '@celo/protocol/migrationsConfig' import { StableTokenRegistryInstance } from 'types' const initializeArgs = async (): Promise => { - return [ - config.StableTokenRegistry.existingFiatTickers, - config.StableTokenRegistry.existingStableTokenContractNames, - ] + return [config.stableTokenRegistry.fiatTicker, config.stableTokenRegistry.stableTokenContractName] } module.exports = deploymentForCoreContract( diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index 41e8070fdf2..f118131a758 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -239,8 +239,8 @@ const DefaultConfig = { votesRatioOfLastVsFirstGroup: 2.0, }, stableTokenRegistry: { - existingFiatTickers: ['cUSD', 'cEUR', 'cBRL'], - existingStableTokenContractNames: ['StableToken', 'StableTokenEUR', 'StableTokenBRL'], + fiatTicker: '0x474250', + stableTokenContractName: '0x537473626c65546f6b656e474250', }, } From a94305ed3306cc395d27addb089edffd6c626893 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 16:11:31 +0200 Subject: [PATCH 127/164] amount of arguments in initialize error fixed --- packages/protocol/migrations/08_reserve.ts | 2 +- .../migrations/27_stableToken_registry.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/protocol/migrations/08_reserve.ts b/packages/protocol/migrations/08_reserve.ts index 686eab930f0..fd8b9d8fa00 100644 --- a/packages/protocol/migrations/08_reserve.ts +++ b/packages/protocol/migrations/08_reserve.ts @@ -21,7 +21,7 @@ const initializeArgs = async (): Promise< ) return [ registry.address, - config.reserve.tobinTaxStalenessThreshold, + config.reserve.tobinTaxStalenessThareshold, config.reserve.dailySpendingRatio, 0, // frozenGold cannot be set until the reserve us funded 0, // frozenGold cannot be set until the reserve us funded diff --git a/packages/protocol/migrations/27_stableToken_registry.ts b/packages/protocol/migrations/27_stableToken_registry.ts index a56431d7b2c..8a100ca5175 100644 --- a/packages/protocol/migrations/27_stableToken_registry.ts +++ b/packages/protocol/migrations/27_stableToken_registry.ts @@ -1,11 +1,22 @@ /* tslint:disable:no-console */ import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' +import { + deploymentForCoreContract, + getDeployedProxiedContract, +} from '@celo/protocol/lib/web3-utils' import { config } from '@celo/protocol/migrationsConfig' -import { StableTokenRegistryInstance } from 'types' +import { RegistryInstance, StableTokenRegistryInstance } from 'types' const initializeArgs = async (): Promise => { - return [config.stableTokenRegistry.fiatTicker, config.stableTokenRegistry.stableTokenContractName] + const registry: RegistryInstance = await getDeployedProxiedContract( + 'Registry', + artifacts + ) + return [ + config.stableTokenRegistry.fiatTicker, + config.stableTokenRegistry.stableTokenContractName, + registry.address, + ] } module.exports = deploymentForCoreContract( From 5e0f95676e2ff439d3ab4bf5ba4f8a91a6d968f8 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 17:04:53 +0200 Subject: [PATCH 128/164] bug --- packages/protocol/test/stability/stabletokenregistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index df83a19b7ad..91438934c11 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -49,7 +49,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { beforeEach(async () => { strc = await STRC.new(true) const registry = await Registry.new(true) - await registry.setAddressFor(CeloContractName.Accounts, strc.address) + await registry.setAddressFor(CeloContractName.StableTokenRegistry, strc.address) await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) }) From c3f18098a32bda0765121a1e1befe22fe845df9f Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 11 Apr 2022 18:46:35 +0200 Subject: [PATCH 129/164] had an accidental type in reserve --- packages/protocol/migrations/08_reserve.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/migrations/08_reserve.ts b/packages/protocol/migrations/08_reserve.ts index fd8b9d8fa00..686eab930f0 100644 --- a/packages/protocol/migrations/08_reserve.ts +++ b/packages/protocol/migrations/08_reserve.ts @@ -21,7 +21,7 @@ const initializeArgs = async (): Promise< ) return [ registry.address, - config.reserve.tobinTaxStalenessThareshold, + config.reserve.tobinTaxStalenessThreshold, config.reserve.dailySpendingRatio, 0, // frozenGold cannot be set until the reserve us funded 0, // frozenGold cannot be set until the reserve us funded From ed366b1ba789d2147242799e9dd9d19c0f0f22da Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 12 Apr 2022 16:19:16 +0200 Subject: [PATCH 130/164] migration tests pass --- .../protocol/contracts/stability/StableTokenRegistry.sol | 6 +++++- ...7_stableToken_registry.ts => 25_stableToken_registry.ts} | 4 +--- .../migrations/{25_governance.ts => 26_governance.ts} | 0 .../{26_elect_validators.ts => 27_elect_validators.ts} | 0 packages/protocol/migrationsConfig.js | 4 ++-- packages/protocol/test/common/accounts.ts | 3 +-- 6 files changed, 9 insertions(+), 8 deletions(-) rename packages/protocol/migrations/{27_stableToken_registry.ts => 25_stableToken_registry.ts} (86%) rename packages/protocol/migrations/{25_governance.ts => 26_governance.ts} (100%) rename packages/protocol/migrations/{26_elect_validators.ts => 27_elect_validators.ts} (100%) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index cb5ea00c1ae..778be0ba76f 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -111,7 +111,11 @@ contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { * @notice Queries a corresponding StableToken contract name based on fiat ticker. * @param fiatTicker Type of currency to query corresponding contract. */ - function queryStableTokenContractNames(bytes memory fiatTicker) public returns (bytes memory) { + function queryStableTokenContractNames(bytes memory fiatTicker) + public + view + returns (bytes memory) + { return stableTokens[fiatTicker]; } } diff --git a/packages/protocol/migrations/27_stableToken_registry.ts b/packages/protocol/migrations/25_stableToken_registry.ts similarity index 86% rename from packages/protocol/migrations/27_stableToken_registry.ts rename to packages/protocol/migrations/25_stableToken_registry.ts index 8a100ca5175..e366fd6e171 100644 --- a/packages/protocol/migrations/27_stableToken_registry.ts +++ b/packages/protocol/migrations/25_stableToken_registry.ts @@ -23,7 +23,5 @@ module.exports = deploymentForCoreContract( web3, artifacts, CeloContractName.StableTokenRegistry, - initializeArgs, - // tslint:disable-next-line: no-empty - async (_StableTokenRegistry: StableTokenRegistryInstance) => {} + initializeArgs ) diff --git a/packages/protocol/migrations/25_governance.ts b/packages/protocol/migrations/26_governance.ts similarity index 100% rename from packages/protocol/migrations/25_governance.ts rename to packages/protocol/migrations/26_governance.ts diff --git a/packages/protocol/migrations/26_elect_validators.ts b/packages/protocol/migrations/27_elect_validators.ts similarity index 100% rename from packages/protocol/migrations/26_elect_validators.ts rename to packages/protocol/migrations/27_elect_validators.ts diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index f118131a758..43f89d19a8c 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -239,8 +239,8 @@ const DefaultConfig = { votesRatioOfLastVsFirstGroup: 2.0, }, stableTokenRegistry: { - fiatTicker: '0x474250', - stableTokenContractName: '0x537473626c65546f6b656e474250', + fiatTicker: '0x494e52', // fiat ticker + stableTokenContractName: '0x537461626c65546f6b656e494e52', // stable token contract name }, } diff --git a/packages/protocol/test/common/accounts.ts b/packages/protocol/test/common/accounts.ts index 2ea8848a728..9c7f8577129 100644 --- a/packages/protocol/test/common/accounts.ts +++ b/packages/protocol/test/common/accounts.ts @@ -13,6 +13,7 @@ import { parseSolidityStringArray } from '@celo/utils/lib/parsing' import { authorizeSigner as buildAuthorizeSignerTypedData } from '@celo/utils/lib/typed-data-constructors' import { generateTypedDataHash } from '@celo/utils/src/sign-typed-data-utils' import { parseSignatureWithoutPrefix } from '@celo/utils/src/signatureUtils' +import BigNumber from 'bignumber.js' import { AccountsContract, AccountsInstance, @@ -22,8 +23,6 @@ import { } from 'types' import { keccak256 } from 'web3-utils' -import BigNumber from 'bignumber.js' - const Accounts: AccountsContract = artifacts.require('Accounts') const Registry: RegistryContract = artifacts.require('Registry') const MockValidators: MockValidatorsContract = artifacts.require('MockValidators') From 6fc872db087bef60698d963ae4568f58c6b25e33 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 3 May 2022 21:36:27 +0200 Subject: [PATCH 131/164] one minor fix needed --- packages/protocol/lib/web3-utils.ts | 1 - packages/protocol/releaseData/initializationData/release9.json | 0 2 files changed, 1 deletion(-) create mode 100644 packages/protocol/releaseData/initializationData/release9.json diff --git a/packages/protocol/lib/web3-utils.ts b/packages/protocol/lib/web3-utils.ts index e082d6b300e..e77a6e300c0 100644 --- a/packages/protocol/lib/web3-utils.ts +++ b/packages/protocol/lib/web3-utils.ts @@ -132,7 +132,6 @@ export function randomUint256() { return BigNumber.random() .times(maxUint256) .integerValue() - .valueOf() } export function checkFunctionArgsLength(args: any[], abi: any) { diff --git a/packages/protocol/releaseData/initializationData/release9.json b/packages/protocol/releaseData/initializationData/release9.json new file mode 100644 index 00000000000..e69de29bb2d From 883851ad661d6fd01fe038a1bbbfb7a298ec2f19 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 4 May 2022 14:35:57 +0200 Subject: [PATCH 132/164] removed from registry --- .../contracts/stability/StableTokenRegistry.sol | 11 ++++------- packages/protocol/lib/registry-utils.ts | 3 --- .../migrations/25_stableToken_registry.ts | 17 +++-------------- .../test/stability/stabletokenregistry.ts | 13 +++---------- 4 files changed, 10 insertions(+), 34 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 778be0ba76f..fc9c6d4909f 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -26,19 +26,16 @@ contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. * @param fiatTicker Collection of fiat currencies issued already. * @param stableTokenContractName Collection of stable token smart contract names. - * @param registryAddress The address of the registry core smart contract. */ - function initialize( - bytes calldata fiatTicker, - bytes calldata stableTokenContractName, - address registryAddress - ) external initializer { + function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) + external + initializer + { _transferOwnership(msg.sender); addNewStableToken(bytes("USD"), bytes("StableToken")); addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); addNewStableToken(fiatTicker, stableTokenContractName); - setRegistry(registryAddress); } /** diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index c056536b354..d6dae2db095 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -38,14 +38,12 @@ export enum CeloContractName { StableTokenBRL = 'StableTokenBRL', TransferWhitelist = 'TransferWhitelist', Validators = 'Validators', - StableTokenRegistry = 'StableTokenRegistry', } export const usesRegistry = [ CeloContractName.Escrow, CeloContractName.Reserve, CeloContractName.StableToken, - CeloContractName.StableTokenRegistry ] export const hasEntryInRegistry: string[] = [ @@ -67,5 +65,4 @@ export const hasEntryInRegistry: string[] = [ CeloContractName.Reserve, CeloContractName.SortedOracles, CeloContractName.StableToken, - CeloContractName.StableTokenRegistry ] diff --git a/packages/protocol/migrations/25_stableToken_registry.ts b/packages/protocol/migrations/25_stableToken_registry.ts index e366fd6e171..65c81e57561 100644 --- a/packages/protocol/migrations/25_stableToken_registry.ts +++ b/packages/protocol/migrations/25_stableToken_registry.ts @@ -1,22 +1,11 @@ /* tslint:disable:no-console */ import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { - deploymentForCoreContract, - getDeployedProxiedContract, -} from '@celo/protocol/lib/web3-utils' +import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' import { config } from '@celo/protocol/migrationsConfig' -import { RegistryInstance, StableTokenRegistryInstance } from 'types' +import { StableTokenRegistryInstance } from 'types' const initializeArgs = async (): Promise => { - const registry: RegistryInstance = await getDeployedProxiedContract( - 'Registry', - artifacts - ) - return [ - config.stableTokenRegistry.fiatTicker, - config.stableTokenRegistry.stableTokenContractName, - registry.address, - ] + return [config.stableTokenRegistry.fiatTicker, config.stableTokenRegistry.stableTokenContractName] } module.exports = deploymentForCoreContract( diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 91438934c11..78593715daf 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -1,10 +1,8 @@ -import { CeloContractName } from '@celo/protocol/lib/registry-utils' import { assertRevert } from '@celo/protocol/lib/test-utils' import BigNumber from 'bignumber.js' -import { RegistryContract, StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' +import { StableTokenRegistryContract, StableTokenRegistryInstance } from 'types' const STRC: StableTokenRegistryContract = artifacts.require('StableTokenRegistry') -const Registry: RegistryContract = artifacts.require('Registry') const convertToHex = (input: string) => { return web3.utils.utf8ToHex(input) @@ -48,22 +46,17 @@ contract('StableTokenRegistry', (accounts: string[]) => { beforeEach(async () => { strc = await STRC.new(true) - const registry = await Registry.new(true) - await registry.setAddressFor(CeloContractName.StableTokenRegistry, strc.address) - await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) + await strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL')) }) describe('#initialize()', async () => { - const registry = await Registry.new(true) it('should have set the owner', async () => { const owner: string = await strc.owner() assert.equal(owner, accounts[0]) }) it('should not be callable again', async () => { - await assertRevert( - strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'), registry.address) - ) + await assertRevert(strc.initialize(convertToHex('GEL'), convertToHex('StableTokenGEL'))) }) }) From fa167a5a2c909f94151627e5aabbdcb5910649f3 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 4 May 2022 15:56:32 +0200 Subject: [PATCH 133/164] readded in registry-utils --- packages/protocol/lib/registry-utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index d6dae2db095..ef839dc2ca4 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -38,6 +38,7 @@ export enum CeloContractName { StableTokenBRL = 'StableTokenBRL', TransferWhitelist = 'TransferWhitelist', Validators = 'Validators', + StableTokenRegistry = 'StableTokenRegistry', } export const usesRegistry = [ From 931c551a0094041bceb0129b15c1fbf9d2ccdb43 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 6 May 2022 12:43:33 +0200 Subject: [PATCH 134/164] upgraded the number of migration file the tests should run to --- packages/cli/package.json | 2 +- packages/sdk/contractkit/package.json | 2 +- packages/sdk/identity/package.json | 2 +- packages/sdk/transactions-uri/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 26be227461e..f3bfe057037 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -28,7 +28,7 @@ "generate:shrinkwrap": "npm install --production && npm shrinkwrap", "check:shrinkwrap": "npm install --production && npm shrinkwrap && ./scripts/check_shrinkwrap_dirty.sh", "prepack": "yarn run build && oclif-dev manifest && oclif-dev readme && yarn run check:shrinkwrap", - "test:reset": "yarn --cwd ../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../dev-utils/src/migration-override.json --upto 25 --release_gold_contracts scripts/truffle/releaseGoldExampleConfigs.json", + "test:reset": "yarn --cwd ../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../dev-utils/src/migration-override.json --upto 26 --release_gold_contracts scripts/truffle/releaseGoldExampleConfigs.json", "test:livechain": "yarn --cwd ../protocol devchain run-tar .tmp/devchain.tar.gz", "test": "TZ=UTC jest --runInBand" }, diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index 0c6935288ab..fd6d7777522 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -22,7 +22,7 @@ "clean:all": "yarn clean && rm -rf src/generated", "prepublishOnly": "yarn build", "docs": "typedoc", - "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 25", + "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 26", "test:livechain": "yarn --cwd ../../protocol devchain run-tar .tmp/devchain.tar.gz", "test": "jest --runInBand", "lint": "tslint -c tslint.json --project ." diff --git a/packages/sdk/identity/package.json b/packages/sdk/identity/package.json index 965a6b7d34c..51a6c8bec66 100644 --- a/packages/sdk/identity/package.json +++ b/packages/sdk/identity/package.json @@ -18,7 +18,7 @@ "build": "tsc -b .", "clean": "tsc -b . --clean", "docs": "typedoc", - "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 25", + "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 26", "test:livechain": "yarn --cwd ../../protocol devchain run-tar .tmp/devchain.tar.gz", "test": "jest --runInBand", "lint": "tslint -c tslint.json --project .", diff --git a/packages/sdk/transactions-uri/package.json b/packages/sdk/transactions-uri/package.json index 2a2874cd6d5..8a847936de7 100644 --- a/packages/sdk/transactions-uri/package.json +++ b/packages/sdk/transactions-uri/package.json @@ -17,7 +17,7 @@ "build": "tsc -b .", "clean": "tsc -b . --clean", "docs": "typedoc", - "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 25", + "test:reset": "yarn --cwd ../../protocol devchain generate-tar .tmp/devchain.tar.gz --migration_override ../../dev-utils/src/migration-override.json --upto 26", "test:livechain": "yarn --cwd ../../protocol devchain run-tar .tmp/devchain.tar.gz", "test": "jest --runInBand", "lint": "tslint -c tslint.json --project .", From fc7a3970d49461c9d77e005a129784e603831b72 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Mon, 9 May 2022 10:56:43 +0200 Subject: [PATCH 135/164] cleaning up --- .../protocol/contracts/stability/StableTokenRegistry.sol | 5 +---- packages/protocol/migrations/26_governance.ts | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index fc9c6d4909f..31387213a0c 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -4,18 +4,15 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol"; import "../common/Initializable.sol"; import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; import "../common/interfaces/IRegistry.sol"; -import "../common/UsingRegistry.sol"; /** * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. */ -contract StableTokenRegistry is Initializable, Ownable, UsingRegistry { +contract StableTokenRegistry is Initializable, Ownable { using SafeMath for uint256; mapping(bytes => bytes) public stableTokens; bytes[] public fiatTickers; - IRegistry public registry; - /** * @notice Sets initialized == true on implementation contracts * @param test Set to true to skip implementation initialization diff --git a/packages/protocol/migrations/26_governance.ts b/packages/protocol/migrations/26_governance.ts index 78a731eb053..ed993fb87bc 100644 --- a/packages/protocol/migrations/26_governance.ts +++ b/packages/protocol/migrations/26_governance.ts @@ -98,6 +98,7 @@ module.exports = deploymentForCoreContract( 'StableToken', 'StableTokenEUR', 'Validators', + 'StableTokenRegistry', ] if (!config.governance.skipTransferOwnership) { From 04628b6eee500f9986321a44e9e01fd50564dd8c Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Fri, 20 May 2022 13:40:59 +0200 Subject: [PATCH 136/164] applying suggestions --- .../protocol/contracts/stability/StableTokenRegistry.sol | 4 +++- packages/protocol/lib/web3-utils.ts | 1 + packages/protocol/migrations/25_stableToken_registry.ts | 8 ++------ packages/protocol/migrationsConfig.js | 4 ++-- packages/protocol/test/stability/stabletokenregistry.ts | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 31387213a0c..ee2b8c47d32 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -32,7 +32,9 @@ contract StableTokenRegistry is Initializable, Ownable { addNewStableToken(bytes("USD"), bytes("StableToken")); addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); - addNewStableToken(fiatTicker, stableTokenContractName); + if (fiatTicker.length != 0 && stableTokenContractName.length != 0) { + addNewStableToken(fiatTicker, stableTokenContractName); + } } /** diff --git a/packages/protocol/lib/web3-utils.ts b/packages/protocol/lib/web3-utils.ts index e77a6e300c0..e082d6b300e 100644 --- a/packages/protocol/lib/web3-utils.ts +++ b/packages/protocol/lib/web3-utils.ts @@ -132,6 +132,7 @@ export function randomUint256() { return BigNumber.random() .times(maxUint256) .integerValue() + .valueOf() } export function checkFunctionArgsLength(args: any[], abi: any) { diff --git a/packages/protocol/migrations/25_stableToken_registry.ts b/packages/protocol/migrations/25_stableToken_registry.ts index 65c81e57561..45622f3a476 100644 --- a/packages/protocol/migrations/25_stableToken_registry.ts +++ b/packages/protocol/migrations/25_stableToken_registry.ts @@ -1,16 +1,12 @@ /* tslint:disable:no-console */ import { CeloContractName } from '@celo/protocol/lib/registry-utils' import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' -import { config } from '@celo/protocol/migrationsConfig' import { StableTokenRegistryInstance } from 'types' -const initializeArgs = async (): Promise => { - return [config.stableTokenRegistry.fiatTicker, config.stableTokenRegistry.stableTokenContractName] -} +// Add initializeArgs when trying to deploy a the registry with a new stable asset on the test net module.exports = deploymentForCoreContract( web3, artifacts, - CeloContractName.StableTokenRegistry, - initializeArgs + CeloContractName.StableTokenRegistry ) diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index 43f89d19a8c..7a6e36124d2 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -239,8 +239,8 @@ const DefaultConfig = { votesRatioOfLastVsFirstGroup: 2.0, }, stableTokenRegistry: { - fiatTicker: '0x494e52', // fiat ticker - stableTokenContractName: '0x537461626c65546f6b656e494e52', // stable token contract name + fiatTicker: [], // empty array resambles empty bytes + stableTokenContractName: [], // empty array resambles empty bytes }, } diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 78593715daf..96e9fd5ffa1 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -23,7 +23,6 @@ const assertSTContractNames = ( }) assert.equal(contracts.length, currentIndex) } - contract('StableTokenRegistry', (accounts: string[]) => { let strc: StableTokenRegistryInstance const nonOwner: string = accounts[1] @@ -31,6 +30,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { const fiatTicker: string = convertToHex('USD') const stableTokenContractName = convertToHex('StableToken') + // Add this to contractkit once we have it const getFiatTickers = async () => { const updatedFiatTickers = [] try { @@ -71,7 +71,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { it('has the right list of fiat tickers after removing one', async () => { await strc.removeStableToken(fiatTicker, 0) - const updatedFiatTickers = await getFiatTickers() + const updatedFiatTickers = await strc.getFiatTickers() assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) From 7d4a86dd432341288c670752efa32229204d1dd1 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 15 Jun 2022 11:19:37 +0200 Subject: [PATCH 137/164] error in ts wrapper --- packages/protocol/test/stability/stabletokenregistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/test/stability/stabletokenregistry.ts b/packages/protocol/test/stability/stabletokenregistry.ts index 96e9fd5ffa1..6f63d683720 100644 --- a/packages/protocol/test/stability/stabletokenregistry.ts +++ b/packages/protocol/test/stability/stabletokenregistry.ts @@ -71,7 +71,7 @@ contract('StableTokenRegistry', (accounts: string[]) => { it('has the right list of fiat tickers after removing one', async () => { await strc.removeStableToken(fiatTicker, 0) - const updatedFiatTickers = await strc.getFiatTickers() + const updatedFiatTickers = await getFiatTickers() assert.deepEqual(updatedFiatTickers, ['GBP', 'EUR', 'BRL', 'GEL']) }) From 5a461c771f9c8c9d70126ed17c6d3277c4adc074 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 15 Jun 2022 11:51:38 +0200 Subject: [PATCH 138/164] fixed migration error --- packages/protocol/migrations/25_stableToken_registry.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/protocol/migrations/25_stableToken_registry.ts b/packages/protocol/migrations/25_stableToken_registry.ts index 45622f3a476..f6031cecadf 100644 --- a/packages/protocol/migrations/25_stableToken_registry.ts +++ b/packages/protocol/migrations/25_stableToken_registry.ts @@ -1,12 +1,14 @@ -/* tslint:disable:no-console */ import { CeloContractName } from '@celo/protocol/lib/registry-utils' import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' import { StableTokenRegistryInstance } from 'types' -// Add initializeArgs when trying to deploy a the registry with a new stable asset on the test net +const initializeArgs = async (): Promise => { + return [[], []] +} module.exports = deploymentForCoreContract( web3, artifacts, - CeloContractName.StableTokenRegistry + CeloContractName.StableTokenRegistry, + initializeArgs ) From d3f288db6723abd39a91481d5ebea2ae38e5fc24 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 21 Jun 2022 09:35:43 +0200 Subject: [PATCH 139/164] added an empty object in release9 --- packages/protocol/releaseData/initializationData/release9.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/protocol/releaseData/initializationData/release9.json b/packages/protocol/releaseData/initializationData/release9.json index e69de29bb2d..9e26dfeeb6e 100644 --- a/packages/protocol/releaseData/initializationData/release9.json +++ b/packages/protocol/releaseData/initializationData/release9.json @@ -0,0 +1 @@ +{} \ No newline at end of file From fc2484ea45de09858757313ca2962b585c2a09b1 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 21 Jun 2022 10:17:57 +0200 Subject: [PATCH 140/164] release tag update --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 956d3bfc63d..db9ea3728c0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,7 +34,7 @@ defaults: &defaults contract-defaults: &contract-defaults <<: *defaults environment: - RELEASE_TAG: core-contracts.v6 + RELEASE_TAG: core-contracts.v7 e2e-defaults: &e2e-defaults <<: *defaults From e900c8ac580e96cb2a3ec0d698661053a11b8ab5 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 21 Jun 2022 10:37:55 +0200 Subject: [PATCH 141/164] updating correct release tag --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index db9ea3728c0..dae708d6ccc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,7 +34,7 @@ defaults: &defaults contract-defaults: &contract-defaults <<: *defaults environment: - RELEASE_TAG: core-contracts.v7 + RELEASE_TAG: core-contracts.v7.post-audit e2e-defaults: &e2e-defaults <<: *defaults From 14ff9105215404a41c48a885427a28fbaeeb07aa Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 22 Jun 2022 10:12:48 +0200 Subject: [PATCH 142/164] removed unnecessary release9 json file --- packages/protocol/releaseData/initializationData/release9.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 packages/protocol/releaseData/initializationData/release9.json diff --git a/packages/protocol/releaseData/initializationData/release9.json b/packages/protocol/releaseData/initializationData/release9.json deleted file mode 100644 index 9e26dfeeb6e..00000000000 --- a/packages/protocol/releaseData/initializationData/release9.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file From c76a63ff9e64384e95aec1af77dfd72c63181e2f Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Sat, 25 Jun 2022 19:07:36 +0200 Subject: [PATCH 143/164] updating the release tag --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dae708d6ccc..db9ea3728c0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,7 +34,7 @@ defaults: &defaults contract-defaults: &contract-defaults <<: *defaults environment: - RELEASE_TAG: core-contracts.v7.post-audit + RELEASE_TAG: core-contracts.v7 e2e-defaults: &e2e-defaults <<: *defaults From 91541146b0a7c677dc6b7538a93b300abe21c16f Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 28 Jun 2022 16:38:43 +0200 Subject: [PATCH 144/164] add release report --- .../versionReports/release7-report.json | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 packages/protocol/releaseData/versionReports/release7-report.json diff --git a/packages/protocol/releaseData/versionReports/release7-report.json b/packages/protocol/releaseData/versionReports/release7-report.json new file mode 100644 index 00000000000..f631e637c14 --- /dev/null +++ b/packages/protocol/releaseData/versionReports/release7-report.json @@ -0,0 +1,235 @@ +{ + "oldArtifactsFolder": "/Users/ninabarbakadze_1/Desktop/celo2/celo-monorepo/packages/protocol/build/core-contracts.v6/contracts", + "newArtifactsFolder": "/Users/ninabarbakadze_1/Desktop/celo2/celo-monorepo/packages/protocol/build/core-contracts.v7/contracts", + "exclude": "/.*Test|Mock.*|I[A-Z].*|.*Proxy|MultiSig.*|ReleaseGold|SlasherUtil|UsingPrecompiles/", + "report": { + "contracts": { + "Exchange": { + "changes": { + "storage": [], + "major": [ + { + "contract": "Exchange", + "signature": "initialize(address,address,uint256,uint256,uint256,uint256)", + "type": "MethodRemoved" + } + ], + "minor": [ + { + "contract": "Exchange", + "signature": "initialize(address,string,uint256,uint256,uint256,uint256)", + "type": "MethodAdded" + }, + { + "contract": "Exchange", + "signature": "activateStable()", + "type": "MethodAdded" + } + ], + "patch": [ + { + "contract": "Exchange", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "+1", + "minor": "0", + "patch": "0" + } + }, + "ExchangeBRL": { + "changes": { + "storage": [], + "major": [ + { + "contract": "ExchangeBRL", + "signature": "initialize(address,address,uint256,uint256,uint256,uint256)", + "type": "MethodRemoved" + } + ], + "minor": [ + { + "contract": "ExchangeBRL", + "signature": "initialize(address,string,uint256,uint256,uint256,uint256)", + "type": "MethodAdded" + }, + { + "contract": "ExchangeBRL", + "signature": "activateStable()", + "type": "MethodAdded" + } + ], + "patch": [ + { + "contract": "ExchangeBRL", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "+1", + "minor": "0", + "patch": "0" + } + }, + "ExchangeEUR": { + "changes": { + "storage": [], + "major": [ + { + "contract": "ExchangeEUR", + "signature": "initialize(address,address,uint256,uint256,uint256,uint256)", + "type": "MethodRemoved" + } + ], + "minor": [ + { + "contract": "ExchangeEUR", + "signature": "initialize(address,string,uint256,uint256,uint256,uint256)", + "type": "MethodAdded" + }, + { + "contract": "ExchangeEUR", + "signature": "activateStable()", + "type": "MethodAdded" + } + ], + "patch": [ + { + "contract": "ExchangeEUR", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "+1", + "minor": "0", + "patch": "0" + } + }, + "Accounts": { + "changes": { + "storage": [], + "major": [], + "minor": [ + { + "contract": "Accounts", + "signature": "setPaymentDelegation(address,uint256)", + "type": "MethodAdded" + }, + { + "contract": "Accounts", + "signature": "getPaymentDelegation(address)", + "type": "MethodAdded" + }, + { + "contract": "Accounts", + "signature": "deletePaymentDelegation()", + "type": "MethodAdded" + } + ], + "patch": [ + { + "contract": "Accounts", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "=", + "minor": "+1", + "patch": "0" + } + }, + "LockedGold": { + "changes": { + "storage": [], + "major": [], + "minor": [ + { + "contract": "LockedGold", + "signature": "getPendingWithdrawal(address,uint256)", + "type": "MethodAdded" + } + ], + "patch": [ + { + "contract": "LockedGold", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "=", + "minor": "+1", + "patch": "0" + } + }, + "GrandaMento": { + "changes": { + "storage": [], + "major": [], + "minor": [], + "patch": [ + { + "contract": "GrandaMento", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "=", + "minor": "=", + "patch": "+1" + } + }, + "Reserve": { + "changes": { + "storage": [], + "major": [], + "minor": [], + "patch": [ + { + "contract": "Reserve", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "=", + "minor": "=", + "patch": "+1" + } + }, + "Validators": { + "changes": { + "storage": [], + "major": [], + "minor": [], + "patch": [ + { + "contract": "Validators", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "=", + "minor": "=", + "patch": "+1" + } + } + }, + "libraries": {} + } +} From 408d239c405f2780787b6ac487b1f0b7ba2aa851 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 28 Jun 2022 17:12:49 +0200 Subject: [PATCH 145/164] update the path for ci --- .../protocol/releaseData/versionReports/release7-report.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/releaseData/versionReports/release7-report.json b/packages/protocol/releaseData/versionReports/release7-report.json index f631e637c14..8bb19ae5cc5 100644 --- a/packages/protocol/releaseData/versionReports/release7-report.json +++ b/packages/protocol/releaseData/versionReports/release7-report.json @@ -1,6 +1,6 @@ { - "oldArtifactsFolder": "/Users/ninabarbakadze_1/Desktop/celo2/celo-monorepo/packages/protocol/build/core-contracts.v6/contracts", - "newArtifactsFolder": "/Users/ninabarbakadze_1/Desktop/celo2/celo-monorepo/packages/protocol/build/core-contracts.v7/contracts", + "oldArtifactsFolder": "/home/circleci/app/packages/protocol/build/core-contracts.v5/contracts", + "newArtifactsFolder": "/home/circleci/app/packages/protocol/build/core-contracts.v6/contracts", "exclude": "/.*Test|Mock.*|I[A-Z].*|.*Proxy|MultiSig.*|ReleaseGold|SlasherUtil|UsingPrecompiles/", "report": { "contracts": { From 314f8f0f7878b22b3c227b53a326ff40b7a873b8 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 29 Jun 2022 16:51:21 +0200 Subject: [PATCH 146/164] correct ci path --- initial-accounts.json | 6 ++++++ packages/dev-utils/src/migration-override.json | 11 ++++++++--- .../releaseData/versionReports/release7-report.json | 4 ++-- packages/protocol/truffle-config.js | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 initial-accounts.json diff --git a/initial-accounts.json b/initial-accounts.json new file mode 100644 index 00000000000..390e9fb6407 --- /dev/null +++ b/initial-accounts.json @@ -0,0 +1,6 @@ +[ + { + "address": "0xE4c563e272B30CB263A9A1B1B03F5999D2948D3D", + "balance": "120000000000000000000000000" + } + ] \ No newline at end of file diff --git a/packages/dev-utils/src/migration-override.json b/packages/dev-utils/src/migration-override.json index 213756a69f0..f35b4f90b23 100644 --- a/packages/dev-utils/src/migration-override.json +++ b/packages/dev-utils/src/migration-override.json @@ -56,7 +56,8 @@ "0x5409ED021D9299bf6814279A6A1411A7e866A631", "0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb", "0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84", - "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63" + "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63", + "0xE4c563e272B30CB263A9A1B1B03F5999D2948D3D" ], "values": [ "50000000000000000000000", @@ -80,12 +81,14 @@ "0x5409ED021D9299bf6814279A6A1411A7e866A631", "0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb", "0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84", - "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63" + "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63", + "0xE4c563e272B30CB263A9A1B1B03F5999D2948D3D" ], "values": [ "50000000000000000000000", "50000000000000000000000", "50000000000000000000000", + "50000000000000000000000", "50000000000000000000000" ] }, @@ -104,12 +107,14 @@ "0x5409ED021D9299bf6814279A6A1411A7e866A631", "0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb", "0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84", - "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63" + "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63", + "0xE4c563e272B30CB263A9A1B1B03F5999D2948D3D" ], "values": [ "50000000000000000000000", "50000000000000000000000", "50000000000000000000000", + "50000000000000000000000", "50000000000000000000000" ] }, diff --git a/packages/protocol/releaseData/versionReports/release7-report.json b/packages/protocol/releaseData/versionReports/release7-report.json index 8bb19ae5cc5..1d961b99f6d 100644 --- a/packages/protocol/releaseData/versionReports/release7-report.json +++ b/packages/protocol/releaseData/versionReports/release7-report.json @@ -1,6 +1,6 @@ { - "oldArtifactsFolder": "/home/circleci/app/packages/protocol/build/core-contracts.v5/contracts", - "newArtifactsFolder": "/home/circleci/app/packages/protocol/build/core-contracts.v6/contracts", + "oldArtifactsFolder": "/home/circleci/app/packages/protocol/build/core-contracts.v6/contracts", + "newArtifactsFolder": "/home/circleci/app/packages/protocol/build/core-contracts.v7/contracts", "exclude": "/.*Test|Mock.*|I[A-Z].*|.*Proxy|MultiSig.*|ReleaseGold|SlasherUtil|UsingPrecompiles/", "report": { "contracts": { diff --git a/packages/protocol/truffle-config.js b/packages/protocol/truffle-config.js index 98db1afe31c..138b4d730e6 100644 --- a/packages/protocol/truffle-config.js +++ b/packages/protocol/truffle-config.js @@ -44,7 +44,7 @@ const hostPort = parseInt(process.env.CELO_NODE_PORT || '8545') const defaultConfig = { host: hostAddress, port: hostPort, - network_id: 1101, + network_id: 42220, from: OG_FROM, gas: gasLimit, gasPrice: 100000000000, From ff792a743da06078a8a03228889a9dfc681338b4 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 29 Jun 2022 17:20:49 +0200 Subject: [PATCH 147/164] removed incorrect configs --- initial-accounts.json | 6 ------ packages/dev-utils/src/migration-override.json | 11 +++-------- packages/protocol/truffle-config.js | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) delete mode 100644 initial-accounts.json diff --git a/initial-accounts.json b/initial-accounts.json deleted file mode 100644 index 390e9fb6407..00000000000 --- a/initial-accounts.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "address": "0xE4c563e272B30CB263A9A1B1B03F5999D2948D3D", - "balance": "120000000000000000000000000" - } - ] \ No newline at end of file diff --git a/packages/dev-utils/src/migration-override.json b/packages/dev-utils/src/migration-override.json index f35b4f90b23..213756a69f0 100644 --- a/packages/dev-utils/src/migration-override.json +++ b/packages/dev-utils/src/migration-override.json @@ -56,8 +56,7 @@ "0x5409ED021D9299bf6814279A6A1411A7e866A631", "0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb", "0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84", - "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63", - "0xE4c563e272B30CB263A9A1B1B03F5999D2948D3D" + "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63" ], "values": [ "50000000000000000000000", @@ -81,14 +80,12 @@ "0x5409ED021D9299bf6814279A6A1411A7e866A631", "0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb", "0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84", - "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63", - "0xE4c563e272B30CB263A9A1B1B03F5999D2948D3D" + "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63" ], "values": [ "50000000000000000000000", "50000000000000000000000", "50000000000000000000000", - "50000000000000000000000", "50000000000000000000000" ] }, @@ -107,14 +104,12 @@ "0x5409ED021D9299bf6814279A6A1411A7e866A631", "0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb", "0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84", - "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63", - "0xE4c563e272B30CB263A9A1B1B03F5999D2948D3D" + "0xE834EC434DABA538cd1b9Fe1582052B880BD7e63" ], "values": [ "50000000000000000000000", "50000000000000000000000", "50000000000000000000000", - "50000000000000000000000", "50000000000000000000000" ] }, diff --git a/packages/protocol/truffle-config.js b/packages/protocol/truffle-config.js index 138b4d730e6..98db1afe31c 100644 --- a/packages/protocol/truffle-config.js +++ b/packages/protocol/truffle-config.js @@ -44,7 +44,7 @@ const hostPort = parseInt(process.env.CELO_NODE_PORT || '8545') const defaultConfig = { host: hostAddress, port: hostPort, - network_id: 42220, + network_id: 1101, from: OG_FROM, gas: gasLimit, gasPrice: 100000000000, From be3207124ba32f9da00e7eea50c9dc7d56322e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Fri, 1 Jul 2022 12:47:22 +0200 Subject: [PATCH 148/164] Trying to get all the tags from git --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index db9ea3728c0..a4bbf0c3680 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -151,6 +151,7 @@ jobs: # Verify that following commands work, they are later called in the incremental testing script # There output does not matter here, the fact that they finish successfully does. git rev-parse --abbrev-ref HEAD + git fetch --all --tags - attach_workspace: at: ~/app From e1a190acbf4aefbadda5829a7b208876da0e0396 Mon Sep 17 00:00:00 2001 From: Martin Volpe Date: Fri, 1 Jul 2022 16:56:10 +0200 Subject: [PATCH 149/164] try to add on devchain --- packages/protocol/scripts/bash/release-on-devchain.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/protocol/scripts/bash/release-on-devchain.sh b/packages/protocol/scripts/bash/release-on-devchain.sh index 0c0f7fb44b5..d85d84630b4 100755 --- a/packages/protocol/scripts/bash/release-on-devchain.sh +++ b/packages/protocol/scripts/bash/release-on-devchain.sh @@ -47,9 +47,14 @@ yarn run truffle exec ./scripts/truffle/verify-bytecode.js --network development echo "- Check versions of current branch" # From check-versions.sh +echo " - Checkout migrationsConfig.js at $NEW_BRANCH" +git checkout $NEW_BRANCH -- migrationsConfig.js + CONTRACT_EXCLUSION_REGEX=".*Test|Mock.*|I[A-Z].*|.*Proxy|MultiSig.*|ReleaseGold|SlasherUtil|UsingPrecompiles" yarn ts-node scripts/check-backward.ts sem_check --old_contracts $BUILD_DIR/contracts --new_contracts build/contracts --exclude $CONTRACT_EXCLUSION_REGEX --output_file report.json +git checkout - -- migrationsConfig.js + # From make-release.sh echo "- Deploy release of current branch" INITIALIZATION_FILE=`ls -1 releaseData/initializationData/* | tail -n 1 | xargs realpath` From 1262cfad25b706be262e4841860a26bf8cd1e970 Mon Sep 17 00:00:00 2001 From: Martin Volpe Date: Fri, 1 Jul 2022 17:18:09 +0200 Subject: [PATCH 150/164] Fixed branch name --- packages/protocol/scripts/bash/release-on-devchain.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/scripts/bash/release-on-devchain.sh b/packages/protocol/scripts/bash/release-on-devchain.sh index d85d84630b4..3daa215ed93 100755 --- a/packages/protocol/scripts/bash/release-on-devchain.sh +++ b/packages/protocol/scripts/bash/release-on-devchain.sh @@ -47,8 +47,8 @@ yarn run truffle exec ./scripts/truffle/verify-bytecode.js --network development echo "- Check versions of current branch" # From check-versions.sh -echo " - Checkout migrationsConfig.js at $NEW_BRANCH" -git checkout $NEW_BRANCH -- migrationsConfig.js +echo " - Checkout migrationsConfig.js at $BRANCH" +git checkout $BRANCH -- migrationsConfig.js CONTRACT_EXCLUSION_REGEX=".*Test|Mock.*|I[A-Z].*|.*Proxy|MultiSig.*|ReleaseGold|SlasherUtil|UsingPrecompiles" yarn ts-node scripts/check-backward.ts sem_check --old_contracts $BUILD_DIR/contracts --new_contracts build/contracts --exclude $CONTRACT_EXCLUSION_REGEX --output_file report.json From 2a7b3d42202feaf593f08a777aa761836e4700c4 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Thu, 28 Apr 2022 15:45:35 +0200 Subject: [PATCH 151/164] Restored a missing test (#9460) Authored-by: Nina Barbakadze --- packages/protocol/test/governance/voting/lockedgold.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/protocol/test/governance/voting/lockedgold.ts b/packages/protocol/test/governance/voting/lockedgold.ts index fa0431bf171..21265141d41 100644 --- a/packages/protocol/test/governance/voting/lockedgold.ts +++ b/packages/protocol/test/governance/voting/lockedgold.ts @@ -202,13 +202,21 @@ contract('LockedGold', (accounts: string[]) => { ) }) - it('should add a pending withdrawal', async () => { + it('should add a pending withdrawal #getPendingWithdrawal()', async () => { const [val, timestamp] = await lockedGold.getPendingWithdrawal(account, 0) assertEqualBN(val, value) assertEqualBN(timestamp, availabilityTime) await assertRevert(lockedGold.getPendingWithdrawal(account, 1)) }) + it('should add a pending withdrawal #getPendingWithdrawals()', async () => { + const [values, timestamps] = await lockedGold.getPendingWithdrawals(account) + assert.equal(values.length, 1) + assert.equal(timestamps.length, 1) + assertEqualBN(values[0], value) + assertEqualBN(timestamps[0], availabilityTime) + }) + it("should decrease the account's nonvoting locked gold balance", async () => { assertEqualBN(await lockedGold.getAccountNonvotingLockedGold(account), 0) }) From d9a50e251ed7f96b89fdb33371180ef3115d5d2d Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 4 May 2022 14:36:53 +0200 Subject: [PATCH 152/164] Consistent code across GrandaMento and Exchange in setSpread (#9459) --- packages/protocol/contracts/stability/Exchange.sol | 2 +- packages/protocol/contracts/stability/GrandaMento.sol | 7 +++++-- packages/protocol/test/stability/grandamento.ts | 9 +++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/protocol/contracts/stability/Exchange.sol b/packages/protocol/contracts/stability/Exchange.sol index caf6f7fcb63..55183c52aae 100644 --- a/packages/protocol/contracts/stability/Exchange.sol +++ b/packages/protocol/contracts/stability/Exchange.sol @@ -298,7 +298,7 @@ contract Exchange is spread = FixidityLib.wrap(newSpread); require( FixidityLib.lte(spread, FixidityLib.fixed1()), - "the value of spread must be less than or equal to 1" + "Spread must be less than or equal to 1" ); emit SpreadSet(newSpread); } diff --git a/packages/protocol/contracts/stability/GrandaMento.sol b/packages/protocol/contracts/stability/GrandaMento.sol index 631d37be971..6c29c529773 100644 --- a/packages/protocol/contracts/stability/GrandaMento.sol +++ b/packages/protocol/contracts/stability/GrandaMento.sol @@ -167,7 +167,7 @@ contract GrandaMento is * @return The storage, major, minor, and patch version of the contract. */ function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 1, 0, 0); + return (1, 1, 0, 1); } /** @@ -582,8 +582,11 @@ contract GrandaMento is * @param newSpread The new value for the spread to be wrapped. Must be <= fixed 1. */ function setSpread(uint256 newSpread) public onlyOwner { - require(newSpread <= FixidityLib.fixed1().unwrap(), "Spread must be smaller than 1"); spread = FixidityLib.wrap(newSpread); + require( + FixidityLib.lte(spread, FixidityLib.fixed1()), + "Spread must be less than or equal to 1" + ); emit SpreadSet(newSpread); } diff --git a/packages/protocol/test/stability/grandamento.ts b/packages/protocol/test/stability/grandamento.ts index 957574e0788..c87a97e7a72 100644 --- a/packages/protocol/test/stability/grandamento.ts +++ b/packages/protocol/test/stability/grandamento.ts @@ -3,6 +3,7 @@ import { assertEqualBN, assertEqualBNArray, assertLogMatches2, + assertRevert, assertRevertWithReason, timeTravel, } from '@celo/protocol/lib/test-utils' @@ -1085,10 +1086,10 @@ contract('GrandaMento', (accounts: string[]) => { }) }) - it('reverts when the spread is greater than 1', async () => { - await assertRevertWithReason( - grandaMento.setSpread(toFixed(1.0001)), - 'Spread must be smaller than 1' + it('reverts when the spread is more than 1', async () => { + await assertRevert( + grandaMento.setSpread(toFixed(1001 / 1000)), + 'Spread must be less than or equal to 1' ) }) From 8bc292eeca7f3efd40c4ea9812514ca136aef8b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Mon, 9 May 2022 22:24:24 +0200 Subject: [PATCH 153/164] Fix Oracle check (#9527) --- .../protocol/contracts/stability/Reserve.sol | 10 +- .../stability/StableTokenRegistry.sol | 117 ++++++++++++++++++ .../proxies/StableTokenRegistryProxy.sol | 6 + 3 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 packages/protocol/contracts/stability/StableTokenRegistry.sol create mode 100644 packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol diff --git a/packages/protocol/contracts/stability/Reserve.sol b/packages/protocol/contracts/stability/Reserve.sol index c31e91ac924..61e378555af 100644 --- a/packages/protocol/contracts/stability/Reserve.sol +++ b/packages/protocol/contracts/stability/Reserve.sol @@ -538,9 +538,13 @@ contract Reserve is uint256 stableAmount; uint256 goldAmount; (stableAmount, goldAmount) = sortedOracles.medianRate(_tokens[i]); - uint256 stableTokenSupply = IERC20(_tokens[i]).totalSupply(); - uint256 aStableTokenValueInGold = stableTokenSupply.mul(goldAmount).div(stableAmount); - stableTokensValueInGold = stableTokensValueInGold.add(aStableTokenValueInGold); + + if (goldAmount != 0) { + // tokens with no oracle reports don't count towards collateralization ratio + uint256 stableTokenSupply = IERC20(_tokens[i]).totalSupply(); + uint256 aStableTokenValueInGold = stableTokenSupply.mul(goldAmount).div(stableAmount); + stableTokensValueInGold = stableTokensValueInGold.add(aStableTokenValueInGold); + } } return FixidityLib diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol new file mode 100644 index 00000000000..ee2b8c47d32 --- /dev/null +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -0,0 +1,117 @@ +pragma solidity ^0.5.13; + +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import "../common/Initializable.sol"; +import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; +import "../common/interfaces/IRegistry.sol"; + +/** + * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. + */ +contract StableTokenRegistry is Initializable, Ownable { + using SafeMath for uint256; + mapping(bytes => bytes) public stableTokens; + bytes[] public fiatTickers; + + /** + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ + constructor(bool test) public Initializable(test) {} + + /** + * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. + * @param fiatTicker Collection of fiat currencies issued already. + * @param stableTokenContractName Collection of stable token smart contract names. + */ + function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) + external + initializer + { + _transferOwnership(msg.sender); + addNewStableToken(bytes("USD"), bytes("StableToken")); + addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); + addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); + if (fiatTicker.length != 0 && stableTokenContractName.length != 0) { + addNewStableToken(fiatTicker, stableTokenContractName); + } + } + + /** + * @notice Returns all the contract instances created. + * @return collection of stable token contracts. + */ + function getContractInstances() external view returns (bytes memory, uint256[] memory) { + uint256 totalLength = 0; + for (uint256 i = 0; i < fiatTickers.length; i++) { + totalLength += stableTokens[fiatTickers[i]].length; + } + uint256 numOfContracts = fiatTickers.length; + bytes memory concatenated = new bytes(totalLength); + uint256 lastIndex = 0; + uint256[] memory lengths = new uint256[](numOfContracts); + for (uint256 i = 0; i < numOfContracts; i++) { + bytes storage contractName = stableTokens[fiatTickers[i]]; + lengths[i] = contractName.length; + for (uint256 j = 0; j < lengths[i]; j++) { + concatenated[lastIndex] = contractName[j]; + lastIndex++; + } + } + return (concatenated, lengths); + } + + /** + * @notice Removes unwamted token instances. + * @param fiatTicker The currency that is no longer supported. + * @param index The index in fiatTickers of fiatTicker. + */ + function removeStableToken(bytes calldata fiatTicker, uint256 index) external onlyOwner { + delete stableTokens[fiatTicker]; + uint256 numFiats = fiatTickers.length; + require(index < numFiats, "Index is invalid"); + for (uint256 i = 0; i < fiatTicker.length; i++) { + if (fiatTicker[i] != 0) { + require( + fiatTicker[i] == fiatTickers[index][i], + "source doesn't match the existing fiatTicker" + ); + } + } + uint256 newNumFiats = numFiats.sub(1); + + if (index != newNumFiats) { + fiatTickers[index] = fiatTickers[newNumFiats]; + } + delete fiatTickers[newNumFiats]; + fiatTickers.length = newNumFiats; + } + + /** + * @notice Adds new Fiat Ticker and Stable Token contract to the registry. + * @param fiatTicker The currency we are trying to add in the registry. + * @param stableTokenContractName The contract we are trying to add in the registry. + */ + function addNewStableToken(bytes memory fiatTicker, bytes memory stableTokenContractName) + public + onlyOwner + { + require(fiatTicker.length != 0, "fiatTicker cant be an empty string"); + require(stableTokenContractName.length != 0, "stableTokenContractName cant be an empty string"); + require(stableTokens[fiatTicker].length == 0, "This registry already exists"); + stableTokens[fiatTicker] = stableTokenContractName; + fiatTickers.push(fiatTicker); + } + + /** + * @notice Queries a corresponding StableToken contract name based on fiat ticker. + * @param fiatTicker Type of currency to query corresponding contract. + */ + function queryStableTokenContractNames(bytes memory fiatTicker) + public + view + returns (bytes memory) + { + return stableTokens[fiatTicker]; + } +} diff --git a/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol b/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol new file mode 100644 index 00000000000..6e9656d991c --- /dev/null +++ b/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.5.13; + +import "../../common/Proxy.sol"; + +/* solhint-disable no-empty-blocks */ +contract StableTokenRegistryProxy is Proxy {} From 3d2aa8c96d4aa14bc140337e1886a47689b8918e Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Tue, 22 Feb 2022 10:18:55 -0500 Subject: [PATCH 154/164] Add version report --- .../protocol/releaseData/versionReports/release6-report.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/versionReports/release6-report.json b/packages/protocol/releaseData/versionReports/release6-report.json index d633c114262..154259f9652 100644 --- a/packages/protocol/releaseData/versionReports/release6-report.json +++ b/packages/protocol/releaseData/versionReports/release6-report.json @@ -385,4 +385,4 @@ } } } -} +} \ No newline at end of file From b2b8d3cc41a02890e8f30824bea56ecd80989f6d Mon Sep 17 00:00:00 2001 From: Martin Volpe Date: Fri, 13 May 2022 15:09:06 +0200 Subject: [PATCH 155/164] Added newline at the end --- .../protocol/releaseData/versionReports/release6-report.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/versionReports/release6-report.json b/packages/protocol/releaseData/versionReports/release6-report.json index 154259f9652..d633c114262 100644 --- a/packages/protocol/releaseData/versionReports/release6-report.json +++ b/packages/protocol/releaseData/versionReports/release6-report.json @@ -385,4 +385,4 @@ } } } -} \ No newline at end of file +} From 28b2fd7ab3de49d2e0bab573657739c6c9f9ad87 Mon Sep 17 00:00:00 2001 From: Martin Volpe Date: Fri, 13 May 2022 15:10:45 +0200 Subject: [PATCH 156/164] Fixed release versions --- .../protocol/releaseData/initializationData/release6.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/initializationData/release6.json b/packages/protocol/releaseData/initializationData/release6.json index 0967ef424bc..b3e85ae1f65 100644 --- a/packages/protocol/releaseData/initializationData/release6.json +++ b/packages/protocol/releaseData/initializationData/release6.json @@ -1 +1,4 @@ -{} +{ + "StableTokenBRL": ["Celo Brazilian Real", "cREAL", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", [], [], "ExchangeBRL"], + "ExchangeBRL": ["0x000000000000000000000000000000000000ce10", "0x0000000000000000000000000000000000000000", "5000000000000000000000", "250000000000000000000", "300", "5"] +} \ No newline at end of file From 6cdececd8dba48cf9289edde51d5d8bca357f24f Mon Sep 17 00:00:00 2001 From: Martin Volpe Date: Tue, 5 Jul 2022 13:16:29 +0200 Subject: [PATCH 157/164] Deleted wrong files --- .../stability/StableTokenRegistry.sol | 117 ------------------ .../proxies/StableTokenRegistryProxy.sol | 6 - 2 files changed, 123 deletions(-) delete mode 100644 packages/protocol/contracts/stability/StableTokenRegistry.sol delete mode 100644 packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol deleted file mode 100644 index ee2b8c47d32..00000000000 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ /dev/null @@ -1,117 +0,0 @@ -pragma solidity ^0.5.13; - -import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -import "../common/Initializable.sol"; -import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; -import "../common/interfaces/IRegistry.sol"; - -/** - * @title contract that lists what stable coins are deployed as part of Celo's Stability protocol. - */ -contract StableTokenRegistry is Initializable, Ownable { - using SafeMath for uint256; - mapping(bytes => bytes) public stableTokens; - bytes[] public fiatTickers; - - /** - * @notice Sets initialized == true on implementation contracts - * @param test Set to true to skip implementation initialization - */ - constructor(bool test) public Initializable(test) {} - - /** - * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. - * @param fiatTicker Collection of fiat currencies issued already. - * @param stableTokenContractName Collection of stable token smart contract names. - */ - function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) - external - initializer - { - _transferOwnership(msg.sender); - addNewStableToken(bytes("USD"), bytes("StableToken")); - addNewStableToken(bytes("EUR"), bytes("StableTokenEUR")); - addNewStableToken(bytes("BRL"), bytes("StableTokenBRL")); - if (fiatTicker.length != 0 && stableTokenContractName.length != 0) { - addNewStableToken(fiatTicker, stableTokenContractName); - } - } - - /** - * @notice Returns all the contract instances created. - * @return collection of stable token contracts. - */ - function getContractInstances() external view returns (bytes memory, uint256[] memory) { - uint256 totalLength = 0; - for (uint256 i = 0; i < fiatTickers.length; i++) { - totalLength += stableTokens[fiatTickers[i]].length; - } - uint256 numOfContracts = fiatTickers.length; - bytes memory concatenated = new bytes(totalLength); - uint256 lastIndex = 0; - uint256[] memory lengths = new uint256[](numOfContracts); - for (uint256 i = 0; i < numOfContracts; i++) { - bytes storage contractName = stableTokens[fiatTickers[i]]; - lengths[i] = contractName.length; - for (uint256 j = 0; j < lengths[i]; j++) { - concatenated[lastIndex] = contractName[j]; - lastIndex++; - } - } - return (concatenated, lengths); - } - - /** - * @notice Removes unwamted token instances. - * @param fiatTicker The currency that is no longer supported. - * @param index The index in fiatTickers of fiatTicker. - */ - function removeStableToken(bytes calldata fiatTicker, uint256 index) external onlyOwner { - delete stableTokens[fiatTicker]; - uint256 numFiats = fiatTickers.length; - require(index < numFiats, "Index is invalid"); - for (uint256 i = 0; i < fiatTicker.length; i++) { - if (fiatTicker[i] != 0) { - require( - fiatTicker[i] == fiatTickers[index][i], - "source doesn't match the existing fiatTicker" - ); - } - } - uint256 newNumFiats = numFiats.sub(1); - - if (index != newNumFiats) { - fiatTickers[index] = fiatTickers[newNumFiats]; - } - delete fiatTickers[newNumFiats]; - fiatTickers.length = newNumFiats; - } - - /** - * @notice Adds new Fiat Ticker and Stable Token contract to the registry. - * @param fiatTicker The currency we are trying to add in the registry. - * @param stableTokenContractName The contract we are trying to add in the registry. - */ - function addNewStableToken(bytes memory fiatTicker, bytes memory stableTokenContractName) - public - onlyOwner - { - require(fiatTicker.length != 0, "fiatTicker cant be an empty string"); - require(stableTokenContractName.length != 0, "stableTokenContractName cant be an empty string"); - require(stableTokens[fiatTicker].length == 0, "This registry already exists"); - stableTokens[fiatTicker] = stableTokenContractName; - fiatTickers.push(fiatTicker); - } - - /** - * @notice Queries a corresponding StableToken contract name based on fiat ticker. - * @param fiatTicker Type of currency to query corresponding contract. - */ - function queryStableTokenContractNames(bytes memory fiatTicker) - public - view - returns (bytes memory) - { - return stableTokens[fiatTicker]; - } -} diff --git a/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol b/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol deleted file mode 100644 index 6e9656d991c..00000000000 --- a/packages/protocol/contracts/stability/proxies/StableTokenRegistryProxy.sol +++ /dev/null @@ -1,6 +0,0 @@ -pragma solidity ^0.5.13; - -import "../../common/Proxy.sol"; - -/* solhint-disable no-empty-blocks */ -contract StableTokenRegistryProxy is Proxy {} From ec24021d88781209047b6be3ed97a6e7e185cc70 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 5 Jul 2022 13:53:44 +0200 Subject: [PATCH 158/164] adding a version number --- .../protocol/contracts/stability/StableTokenRegistry.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index ee2b8c47d32..30a9b43984f 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -13,6 +13,14 @@ contract StableTokenRegistry is Initializable, Ownable { mapping(bytes => bytes) public stableTokens; bytes[] public fiatTickers; + /** + * @notice Returns the storage, major, minor, and patch version of the contract. + * @return The storage, major, minor, and patch version of the contract. + */ + function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { + return (1, 0, 0, 0); + } + /** * @notice Sets initialized == true on implementation contracts * @param test Set to true to skip implementation initialization From f0d9c180a77da1986b5fdc86fc78f1d5c53a9f98 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 5 Jul 2022 13:56:13 +0200 Subject: [PATCH 159/164] updated the major version number to 1 --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 30a9b43984f..1ebe6bd0510 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -18,7 +18,7 @@ contract StableTokenRegistry is Initializable, Ownable { * @return The storage, major, minor, and patch version of the contract. */ function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 0, 0, 0); + return (1, 1, 0, 0); } /** From 3e9f7a804d4c2ba981670787df3e374b40ecf027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 5 Jul 2022 15:29:40 +0200 Subject: [PATCH 160/164] Create release8.json --- packages/protocol/releaseData/initializationData/release8.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/protocol/releaseData/initializationData/release8.json diff --git a/packages/protocol/releaseData/initializationData/release8.json b/packages/protocol/releaseData/initializationData/release8.json new file mode 100644 index 00000000000..0967ef424bc --- /dev/null +++ b/packages/protocol/releaseData/initializationData/release8.json @@ -0,0 +1 @@ +{} From 9f515075ecb97bf5839beb5cf160b1293fc9edf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 5 Jul 2022 17:02:44 +0200 Subject: [PATCH 161/164] Update release8.json --- .../protocol/releaseData/initializationData/release8.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/initializationData/release8.json b/packages/protocol/releaseData/initializationData/release8.json index 0967ef424bc..fdbed832033 100644 --- a/packages/protocol/releaseData/initializationData/release8.json +++ b/packages/protocol/releaseData/initializationData/release8.json @@ -1 +1,3 @@ -{} +{ + 'StableTokenRegistry': [[], []] +} From bed934292c770e2f0404906d5148cfaa4d4098d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 5 Jul 2022 17:03:03 +0200 Subject: [PATCH 162/164] Update release8.json --- packages/protocol/releaseData/initializationData/release8.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/initializationData/release8.json b/packages/protocol/releaseData/initializationData/release8.json index fdbed832033..7bcb6122ae0 100644 --- a/packages/protocol/releaseData/initializationData/release8.json +++ b/packages/protocol/releaseData/initializationData/release8.json @@ -1,3 +1,3 @@ { - 'StableTokenRegistry': [[], []] + StableTokenRegistry: [[], []] } From 19b71421beab10873ac01b1f46b70b342fe3e550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 5 Jul 2022 17:03:24 +0200 Subject: [PATCH 163/164] Update release8.json --- packages/protocol/releaseData/initializationData/release8.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/initializationData/release8.json b/packages/protocol/releaseData/initializationData/release8.json index 7bcb6122ae0..cde66d6c75e 100644 --- a/packages/protocol/releaseData/initializationData/release8.json +++ b/packages/protocol/releaseData/initializationData/release8.json @@ -1,3 +1,3 @@ { - StableTokenRegistry: [[], []] + "StableTokenRegistry": [[], []] } From c724e68d88db66901d657dba35a470eb5485daac Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Tue, 5 Jul 2022 17:33:27 +0200 Subject: [PATCH 164/164] Update StableTokenRegistry.sol --- packages/protocol/contracts/stability/StableTokenRegistry.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/stability/StableTokenRegistry.sol b/packages/protocol/contracts/stability/StableTokenRegistry.sol index 1ebe6bd0510..00cf4f8ecaf 100644 --- a/packages/protocol/contracts/stability/StableTokenRegistry.sol +++ b/packages/protocol/contracts/stability/StableTokenRegistry.sol @@ -29,8 +29,8 @@ contract StableTokenRegistry is Initializable, Ownable { /** * @notice Used in place of the constructor to allow the contract to be upgradable via proxy. - * @param fiatTicker Collection of fiat currencies issued already. - * @param stableTokenContractName Collection of stable token smart contract names. + * @param fiatTicker fiat currency issued. + * @param stableTokenContractName stable token smart contract name. */ function initialize(bytes calldata fiatTicker, bytes calldata stableTokenContractName) external