From 25a7c0d59a56c780763944a75af26e2b5e11f54d Mon Sep 17 00:00:00 2001 From: pahor167 Date: Tue, 14 May 2024 11:08:42 +0200 Subject: [PATCH 1/9] FeeCurrencyDirectory to devchain --- packages/protocol/contractPackages.ts | 4 ++-- .../proxies/FeeCurrencyDirectoryProxy.sol | 6 ++++++ packages/protocol/lib/registry-utils.ts | 7 ++++--- .../26_100_fee_currency_directory.ts | 20 +++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 packages/protocol/contracts/common/proxies/FeeCurrencyDirectoryProxy.sol create mode 100644 packages/protocol/migrations_ts/26_100_fee_currency_directory.ts diff --git a/packages/protocol/contractPackages.ts b/packages/protocol/contractPackages.ts index 936064aa317..1242a52e5be 100644 --- a/packages/protocol/contractPackages.ts +++ b/packages/protocol/contractPackages.ts @@ -48,7 +48,7 @@ export const SOLIDITY_08_PACKAGE = { proxiesPath: '/', // Proxies are still with 0.5 contracts // Proxies shouldn't have to be added to a list manually // https://github.com/celo-org/celo-monorepo/issues/10555 - contracts: ['GasPriceMinimum'], - proxyContracts: ['GasPriceMinimumProxy'], + contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory'], + proxyContracts: ['GasPriceMinimumProxy', 'FeeCurrencyDirectoryProxy'], truffleConfig: 'truffle-config0.8.js', } satisfies ContractPackage diff --git a/packages/protocol/contracts/common/proxies/FeeCurrencyDirectoryProxy.sol b/packages/protocol/contracts/common/proxies/FeeCurrencyDirectoryProxy.sol new file mode 100644 index 00000000000..b8aacbcb4bd --- /dev/null +++ b/packages/protocol/contracts/common/proxies/FeeCurrencyDirectoryProxy.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.5.13; + +import "../Proxy.sol"; + +/* solhint-disable-next-line no-empty-blocks */ +contract FeeCurrencyDirectoryProxy is Proxy {} diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index ddec08171b2..67c7371784e 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -28,6 +28,7 @@ export enum CeloContractName { FeeCurrencyWhitelist = 'FeeCurrencyWhitelist', Freezer = 'Freezer', GasPriceMinimum = 'GasPriceMinimum', + FeeCurrencyDirectory = 'FeeCurrencyDirectory', GoldToken = 'GoldToken', Governance = 'Governance', GovernanceSlasher = 'GovernanceSlasher', @@ -52,10 +53,10 @@ export const usesRegistry = [ CeloContractName.StableToken, ] -export const hasEntryInRegistry: ContractPackage[]= [ +export const hasEntryInRegistry: ContractPackage[] = [ { name: "default", - contracts:[ + contracts: [ CeloContractName.Accounts, CeloContractName.Attestations, CeloContractName.BlockchainParameters, @@ -78,7 +79,7 @@ export const hasEntryInRegistry: ContractPackage[]= [ { ...MENTO_PACKAGE, // not all Mentro contracts are supposed to be in the Registry - contracts:[ + contracts: [ CeloContractName.Exchange, CeloContractName.GrandaMento, CeloContractName.Reserve, diff --git a/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts b/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts new file mode 100644 index 00000000000..ed04f0cb090 --- /dev/null +++ b/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts @@ -0,0 +1,20 @@ +import { CeloContractName } from '@celo/protocol/lib/registry-utils' +import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' +import { FeeCurrencyDirectoryInstance } from 'types/08' +import { SOLIDITY_08_PACKAGE } from '../contractPackages' + +const initializeArgs = async (): Promise => { + return [ + ] +} + +module.exports = deploymentForCoreContract( + web3, + artifacts, + CeloContractName.FeeCurrencyDirectory, + initializeArgs, + async (feeCurrencyDirectory: FeeCurrencyDirectoryInstance, _web3: Web3, networkName: string) => { + console.log("Fee currency directory deployed and registered!!!", feeCurrencyDirectory.address, networkName); + }, + SOLIDITY_08_PACKAGE +) From b396c6ea690957a9ea54172cd2d158bff91f3a09 Mon Sep 17 00:00:00 2001 From: pahor167 Date: Tue, 14 May 2024 12:06:18 +0200 Subject: [PATCH 2/9] Mento Fee Currency adapter --- packages/protocol/contractPackages.ts | 4 +- .../common/MentoFeeCurrencyAdapterV1.sol | 41 +++++++++++++++++++ .../MentoFeeCurrencyAdapterV1Proxy.sol | 6 +++ packages/protocol/lib/registry-utils.ts | 1 + .../26_100_mento_fee_currency_adapterV1.ts | 24 +++++++++++ .../26_101_fee_currency_directory.ts | 38 +++++++++++++++++ 6 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol create mode 100644 packages/protocol/contracts/common/proxies/MentoFeeCurrencyAdapterV1Proxy.sol create mode 100644 packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts create mode 100644 packages/protocol/migrations_ts/26_101_fee_currency_directory.ts diff --git a/packages/protocol/contractPackages.ts b/packages/protocol/contractPackages.ts index 1242a52e5be..33f891c943e 100644 --- a/packages/protocol/contractPackages.ts +++ b/packages/protocol/contractPackages.ts @@ -48,7 +48,7 @@ export const SOLIDITY_08_PACKAGE = { proxiesPath: '/', // Proxies are still with 0.5 contracts // Proxies shouldn't have to be added to a list manually // https://github.com/celo-org/celo-monorepo/issues/10555 - contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory'], - proxyContracts: ['GasPriceMinimumProxy', 'FeeCurrencyDirectoryProxy'], + contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory', 'MentoFeeCurrencyAdapterV1'], + proxyContracts: ['GasPriceMinimumProxy', 'FeeCurrencyDirectoryProxy', 'MentoFeeCurrencyAdapterV1'], truffleConfig: 'truffle-config0.8.js', } satisfies ContractPackage diff --git a/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol b/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol new file mode 100644 index 00000000000..9a54a192e85 --- /dev/null +++ b/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol @@ -0,0 +1,41 @@ +import "../../contracts/common/Initializable.sol"; +import "../../contracts/stability/interfaces/ISortedOracles.sol"; +import "./interfaces/IOracle.sol"; +import "@openzeppelin/contracts8/access/Ownable.sol"; + +contract MentoFeeCurrencyAdapterV1 is IOracle, Initializable, Ownable { + ISortedOracles public sortedOracles; + + constructor(bool test) public Initializable(test) {} + + /** + * @notice Initializes the contract with the owner set. + */ + function initialize(address _sortedOracles) public initializer { + _transferOwnership(msg.sender); + sortedOracles = ISortedOracles(_sortedOracles); + } + + /** + * @notice Retrieves exchange rate between token and CELO. + * @param token The token address whose price is to be fetched. + * @return numerator The exchange rate numerator. + * @return denominator The exchange rate denominator. + */ + function getExchangeRate( + address token + ) public view returns (uint256 numerator, uint256 denominator) { + (numerator, denominator) = sortedOracles.medianRate(token); + } + + /** + * @notice Returns the storage, major, minor, and patch version of the contract. + * @return Storage version of the contract. + * @return Major version of the contract. + * @return Minor version of the contract. + * @return Patch version of the contract. + */ + function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { + return (1, 1, 0, 0); + } +} diff --git a/packages/protocol/contracts/common/proxies/MentoFeeCurrencyAdapterV1Proxy.sol b/packages/protocol/contracts/common/proxies/MentoFeeCurrencyAdapterV1Proxy.sol new file mode 100644 index 00000000000..9e676e83b43 --- /dev/null +++ b/packages/protocol/contracts/common/proxies/MentoFeeCurrencyAdapterV1Proxy.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.5.13; + +import "../Proxy.sol"; + +/* solhint-disable-next-line no-empty-blocks */ +contract MentoFeeCurrencyAdapterV1Proxy is Proxy {} diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index 67c7371784e..cd00a78109c 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -29,6 +29,7 @@ export enum CeloContractName { Freezer = 'Freezer', GasPriceMinimum = 'GasPriceMinimum', FeeCurrencyDirectory = 'FeeCurrencyDirectory', + MentoFeeCurrencyAdapterV1 = 'MentoFeeCurrencyAdapterV1', GoldToken = 'GoldToken', Governance = 'Governance', GovernanceSlasher = 'GovernanceSlasher', diff --git a/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts b/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts new file mode 100644 index 00000000000..c9b151a086e --- /dev/null +++ b/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts @@ -0,0 +1,24 @@ +import { CeloContractName } from '@celo/protocol/lib/registry-utils' +import { deploymentForCoreContract, getDeployedProxiedContract } from '@celo/protocol/lib/web3-utils' +import { SortedOraclesInstance } from '@celo/protocol/types' +import { MentoFeeCurrencyAdapterV1Instance } from 'types/08' +import { SOLIDITY_08_PACKAGE } from '../contractPackages' + +const initializeArgs = async (): Promise => { + const sortedOraclesAddress = await getDeployedProxiedContract('SortedOracles', artifacts) + return [ + sortedOraclesAddress.address + ] +} + +module.exports = deploymentForCoreContract( + web3, + artifacts, + CeloContractName.MentoFeeCurrencyAdapterV1, + initializeArgs, + async (feeCurrencyDirectory: MentoFeeCurrencyAdapterV1Instance, _web3: Web3, networkName: string) => { + + console.log("MentoFeeCurrencyAdapterV1Instance deployed and registered!!!", feeCurrencyDirectory.address, networkName); + }, + SOLIDITY_08_PACKAGE +) diff --git a/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts b/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts new file mode 100644 index 00000000000..c0eaebba70a --- /dev/null +++ b/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts @@ -0,0 +1,38 @@ +import { ArtifactsSingleton } from '@celo/protocol/lib/artifactsSingleton' +import { CeloContractName } from '@celo/protocol/lib/registry-utils' +import { deploymentForCoreContract, getDeployedProxiedContract } from '@celo/protocol/lib/web3-utils' +import { StableTokenInstance } from '@celo/protocol/types/typechain-mento' +import { FeeCurrencyDirectoryInstance, MentoFeeCurrencyAdapterV1Instance } from 'types/08' +import { MENTO_PACKAGE, SOLIDITY_08_PACKAGE } from '../contractPackages' + +const initializeArgs = async (): Promise => { + return [ + ] +} + +module.exports = deploymentForCoreContract( + web3, + artifacts, + CeloContractName.FeeCurrencyDirectory, + initializeArgs, + async (feeCurrencyDirectory: FeeCurrencyDirectoryInstance, _web3: Web3, networkName: string) => { + + const artifacts08 = ArtifactsSingleton.getInstance(SOLIDITY_08_PACKAGE, artifacts) + const feeCurrencyDirectoryInstance = await getDeployedProxiedContract('FeeCurrencyDirectory', artifacts08) + const nentoFeeCurrencyAdapterV1Instance = await getDeployedProxiedContract('MentoFeeCurrencyAdapterV1', artifacts08) + + for (const token of ['StableToken', 'StableTokenEUR', 'StableTokenBRL']) { + const stableToken: StableTokenInstance = + await getDeployedProxiedContract( + token, + ArtifactsSingleton.getInstance(MENTO_PACKAGE) + ) + console.log("setting currency config for", token, "with address", stableToken.address, "and adapter address", nentoFeeCurrencyAdapterV1Instance.address, "on network", networkName); + await feeCurrencyDirectoryInstance.setCurrencyConfig(stableToken.address, nentoFeeCurrencyAdapterV1Instance.address, 1) + } + + + console.log("Fee currency directory deployed and registered!!!", feeCurrencyDirectory.address, networkName); + }, + SOLIDITY_08_PACKAGE +) From 0aa876e5d4f2138d3b9ec91c780ecebd7d9b4a26 Mon Sep 17 00:00:00 2001 From: pahor167 Date: Tue, 14 May 2024 12:14:16 +0200 Subject: [PATCH 3/9] MentoFeeCurrencyAdapter test --- .../26_100_fee_currency_directory.ts | 20 ------- .../common/MentoFeeCurrencyAdapterV1.t.sol | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 20 deletions(-) delete mode 100644 packages/protocol/migrations_ts/26_100_fee_currency_directory.ts create mode 100644 packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol diff --git a/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts b/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts deleted file mode 100644 index ed04f0cb090..00000000000 --- a/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { deploymentForCoreContract } from '@celo/protocol/lib/web3-utils' -import { FeeCurrencyDirectoryInstance } from 'types/08' -import { SOLIDITY_08_PACKAGE } from '../contractPackages' - -const initializeArgs = async (): Promise => { - return [ - ] -} - -module.exports = deploymentForCoreContract( - web3, - artifacts, - CeloContractName.FeeCurrencyDirectory, - initializeArgs, - async (feeCurrencyDirectory: FeeCurrencyDirectoryInstance, _web3: Web3, networkName: string) => { - console.log("Fee currency directory deployed and registered!!!", feeCurrencyDirectory.address, networkName); - }, - SOLIDITY_08_PACKAGE -) diff --git a/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol b/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol new file mode 100644 index 00000000000..853fd6b84a0 --- /dev/null +++ b/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity >=0.8.7 <0.8.20; + +import "celo-foundry-8/Test.sol"; +import "../../contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol"; + +contract MockOracleV1 { + uint256 numerator; + uint256 denominator; + uint256 lastUpdateTimestamp; + address token; + + function setExchangeRate(address _token, uint256 _numerator, uint256 _denominator) public { + numerator = _numerator; + denominator = _denominator; + lastUpdateTimestamp = block.timestamp; + token = _token; + } + + function medianRate(address token) external view returns (uint256, uint256) { + return (numerator, denominator); + } +} + + +contract MentoFeeCurrencyAdapterBase is Test { + MentoFeeCurrencyAdapterV1 mentoAdapter; + MockOracleV1 oracle; + address nonOwner; + address owner; + + function setUp() public virtual { + owner = address(this); + nonOwner = actor("nonOwner"); + oracle = new MockOracleV1(); + + mentoAdapter = new MentoFeeCurrencyAdapterV1(true); + mentoAdapter.initialize(address(oracle)); + } +} + +contract GetExchangeRate is MentoFeeCurrencyAdapterBase { + function test_ShouldReturnExchangeRateFromOracle() public { + address token = address(1); + uint256 numerator = 1; + uint256 denominator = 2; + oracle.setExchangeRate(token, numerator, denominator); + (uint256 rateNumerator, uint256 rateDenominator) = mentoAdapter.getExchangeRate(token); + + assertEq(rateNumerator, numerator); + assertEq(rateDenominator, denominator); + } +} From 4b40cd44220c15455e6b8685cb8097a2097fef19 Mon Sep 17 00:00:00 2001 From: pahor167 Date: Tue, 14 May 2024 13:15:08 +0200 Subject: [PATCH 4/9] lint --- packages/protocol/contractPackages.ts | 6 ++- .../common/MentoFeeCurrencyAdapterV1.sol | 2 +- .../26_100_mento_fee_currency_adapterV1.ts | 27 +++++++---- .../26_101_fee_currency_directory.ts | 45 ++++++++++++++----- .../common/MentoFeeCurrencyAdapterV1.t.sol | 3 +- 5 files changed, 61 insertions(+), 22 deletions(-) diff --git a/packages/protocol/contractPackages.ts b/packages/protocol/contractPackages.ts index 33f891c943e..ddc1de316bc 100644 --- a/packages/protocol/contractPackages.ts +++ b/packages/protocol/contractPackages.ts @@ -49,6 +49,10 @@ export const SOLIDITY_08_PACKAGE = { // Proxies shouldn't have to be added to a list manually // https://github.com/celo-org/celo-monorepo/issues/10555 contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory', 'MentoFeeCurrencyAdapterV1'], - proxyContracts: ['GasPriceMinimumProxy', 'FeeCurrencyDirectoryProxy', 'MentoFeeCurrencyAdapterV1'], + proxyContracts: [ + 'GasPriceMinimumProxy', + 'FeeCurrencyDirectoryProxy', + 'MentoFeeCurrencyAdapterV1', + ], truffleConfig: 'truffle-config0.8.js', } satisfies ContractPackage diff --git a/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol b/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol index 9a54a192e85..bbbb55451f6 100644 --- a/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol +++ b/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol @@ -5,7 +5,7 @@ import "@openzeppelin/contracts8/access/Ownable.sol"; contract MentoFeeCurrencyAdapterV1 is IOracle, Initializable, Ownable { ISortedOracles public sortedOracles; - + constructor(bool test) public Initializable(test) {} /** diff --git a/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts b/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts index c9b151a086e..69a991ee5f5 100644 --- a/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts +++ b/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts @@ -1,14 +1,18 @@ import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { deploymentForCoreContract, getDeployedProxiedContract } from '@celo/protocol/lib/web3-utils' +import { + deploymentForCoreContract, + getDeployedProxiedContract, +} from '@celo/protocol/lib/web3-utils' import { SortedOraclesInstance } from '@celo/protocol/types' import { MentoFeeCurrencyAdapterV1Instance } from 'types/08' import { SOLIDITY_08_PACKAGE } from '../contractPackages' const initializeArgs = async (): Promise => { - const sortedOraclesAddress = await getDeployedProxiedContract('SortedOracles', artifacts) - return [ - sortedOraclesAddress.address - ] + const sortedOraclesAddress = await getDeployedProxiedContract( + 'SortedOracles', + artifacts + ) + return [sortedOraclesAddress.address] } module.exports = deploymentForCoreContract( @@ -16,9 +20,16 @@ module.exports = deploymentForCoreContract( artifacts, CeloContractName.MentoFeeCurrencyAdapterV1, initializeArgs, - async (feeCurrencyDirectory: MentoFeeCurrencyAdapterV1Instance, _web3: Web3, networkName: string) => { - - console.log("MentoFeeCurrencyAdapterV1Instance deployed and registered!!!", feeCurrencyDirectory.address, networkName); + async ( + feeCurrencyDirectory: MentoFeeCurrencyAdapterV1Instance, + _web3: Web3, + networkName: string + ) => { + console.log( + 'MentoFeeCurrencyAdapterV1Instance deployed and registered!!!', + feeCurrencyDirectory.address, + networkName + ) }, SOLIDITY_08_PACKAGE ) diff --git a/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts b/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts index c0eaebba70a..82d86a465d9 100644 --- a/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts +++ b/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts @@ -1,13 +1,15 @@ import { ArtifactsSingleton } from '@celo/protocol/lib/artifactsSingleton' import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { deploymentForCoreContract, getDeployedProxiedContract } from '@celo/protocol/lib/web3-utils' +import { + deploymentForCoreContract, + getDeployedProxiedContract, +} from '@celo/protocol/lib/web3-utils' import { StableTokenInstance } from '@celo/protocol/types/typechain-mento' import { FeeCurrencyDirectoryInstance, MentoFeeCurrencyAdapterV1Instance } from 'types/08' import { MENTO_PACKAGE, SOLIDITY_08_PACKAGE } from '../contractPackages' const initializeArgs = async (): Promise => { - return [ - ] + return [] } module.exports = deploymentForCoreContract( @@ -16,10 +18,17 @@ module.exports = deploymentForCoreContract( CeloContractName.FeeCurrencyDirectory, initializeArgs, async (feeCurrencyDirectory: FeeCurrencyDirectoryInstance, _web3: Web3, networkName: string) => { - const artifacts08 = ArtifactsSingleton.getInstance(SOLIDITY_08_PACKAGE, artifacts) - const feeCurrencyDirectoryInstance = await getDeployedProxiedContract('FeeCurrencyDirectory', artifacts08) - const nentoFeeCurrencyAdapterV1Instance = await getDeployedProxiedContract('MentoFeeCurrencyAdapterV1', artifacts08) + const feeCurrencyDirectoryInstance = + await getDeployedProxiedContract( + 'FeeCurrencyDirectory', + artifacts08 + ) + const nentoFeeCurrencyAdapterV1Instance = + await getDeployedProxiedContract( + 'MentoFeeCurrencyAdapterV1', + artifacts08 + ) for (const token of ['StableToken', 'StableTokenEUR', 'StableTokenBRL']) { const stableToken: StableTokenInstance = @@ -27,12 +36,28 @@ module.exports = deploymentForCoreContract( token, ArtifactsSingleton.getInstance(MENTO_PACKAGE) ) - console.log("setting currency config for", token, "with address", stableToken.address, "and adapter address", nentoFeeCurrencyAdapterV1Instance.address, "on network", networkName); - await feeCurrencyDirectoryInstance.setCurrencyConfig(stableToken.address, nentoFeeCurrencyAdapterV1Instance.address, 1) + console.log( + 'setting currency config for', + token, + 'with address', + stableToken.address, + 'and adapter address', + nentoFeeCurrencyAdapterV1Instance.address, + 'on network', + networkName + ) + await feeCurrencyDirectoryInstance.setCurrencyConfig( + stableToken.address, + nentoFeeCurrencyAdapterV1Instance.address, + 1 + ) } - - console.log("Fee currency directory deployed and registered!!!", feeCurrencyDirectory.address, networkName); + console.log( + 'Fee currency directory deployed and registered!!!', + feeCurrencyDirectory.address, + networkName + ) }, SOLIDITY_08_PACKAGE ) diff --git a/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol b/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol index 853fd6b84a0..8df9a62080c 100644 --- a/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol +++ b/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol @@ -18,11 +18,10 @@ contract MockOracleV1 { } function medianRate(address token) external view returns (uint256, uint256) { - return (numerator, denominator); + return (numerator, denominator); } } - contract MentoFeeCurrencyAdapterBase is Test { MentoFeeCurrencyAdapterV1 mentoAdapter; MockOracleV1 oracle; From a7163171051280a1b8a423fe9fcf5db509cad922 Mon Sep 17 00:00:00 2001 From: pahor167 Date: Tue, 14 May 2024 15:55:47 +0200 Subject: [PATCH 5/9] Update of SortedOracles --- .../common/MentoFeeCurrencyAdapterV1.sol | 41 ------------- .../common/interfaces/IOracle.sol | 2 +- .../MentoFeeCurrencyAdapterV1Proxy.sol | 6 -- .../contracts/stability/SortedOracles.sol | 37 ++++++++---- packages/protocol/lib/registry-utils.ts | 1 - .../26_100_fee_currency_directory.ts | 57 +++++++++++++++++++ .../common/MentoFeeCurrencyAdapterV1.t.sol | 52 ----------------- 7 files changed, 83 insertions(+), 113 deletions(-) delete mode 100644 packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol delete mode 100644 packages/protocol/contracts/common/proxies/MentoFeeCurrencyAdapterV1Proxy.sol create mode 100644 packages/protocol/migrations_ts/26_100_fee_currency_directory.ts delete mode 100644 packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol diff --git a/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol b/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol deleted file mode 100644 index bbbb55451f6..00000000000 --- a/packages/protocol/contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol +++ /dev/null @@ -1,41 +0,0 @@ -import "../../contracts/common/Initializable.sol"; -import "../../contracts/stability/interfaces/ISortedOracles.sol"; -import "./interfaces/IOracle.sol"; -import "@openzeppelin/contracts8/access/Ownable.sol"; - -contract MentoFeeCurrencyAdapterV1 is IOracle, Initializable, Ownable { - ISortedOracles public sortedOracles; - - constructor(bool test) public Initializable(test) {} - - /** - * @notice Initializes the contract with the owner set. - */ - function initialize(address _sortedOracles) public initializer { - _transferOwnership(msg.sender); - sortedOracles = ISortedOracles(_sortedOracles); - } - - /** - * @notice Retrieves exchange rate between token and CELO. - * @param token The token address whose price is to be fetched. - * @return numerator The exchange rate numerator. - * @return denominator The exchange rate denominator. - */ - function getExchangeRate( - address token - ) public view returns (uint256 numerator, uint256 denominator) { - (numerator, denominator) = sortedOracles.medianRate(token); - } - - /** - * @notice Returns the storage, major, minor, and patch version of the contract. - * @return Storage version of the contract. - * @return Major version of the contract. - * @return Minor version of the contract. - * @return Patch version of the contract. - */ - function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 1, 0, 0); - } -} diff --git a/packages/protocol/contracts-0.8/common/interfaces/IOracle.sol b/packages/protocol/contracts-0.8/common/interfaces/IOracle.sol index cea44909aa8..87d0a3d8980 100644 --- a/packages/protocol/contracts-0.8/common/interfaces/IOracle.sol +++ b/packages/protocol/contracts-0.8/common/interfaces/IOracle.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; +pragma solidity >=0.5.13 <0.9.0; /// Possibly not final version interface IOracle { diff --git a/packages/protocol/contracts/common/proxies/MentoFeeCurrencyAdapterV1Proxy.sol b/packages/protocol/contracts/common/proxies/MentoFeeCurrencyAdapterV1Proxy.sol deleted file mode 100644 index 9e676e83b43..00000000000 --- a/packages/protocol/contracts/common/proxies/MentoFeeCurrencyAdapterV1Proxy.sol +++ /dev/null @@ -1,6 +0,0 @@ -pragma solidity ^0.5.13; - -import "../Proxy.sol"; - -/* solhint-disable-next-line no-empty-blocks */ -contract MentoFeeCurrencyAdapterV1Proxy is Proxy {} diff --git a/packages/protocol/contracts/stability/SortedOracles.sol b/packages/protocol/contracts/stability/SortedOracles.sol index 39c2540e2d3..df26a79b143 100644 --- a/packages/protocol/contracts/stability/SortedOracles.sol +++ b/packages/protocol/contracts/stability/SortedOracles.sol @@ -12,6 +12,7 @@ import "../common/FixidityLib.sol"; import "../common/Initializable.sol"; import "../common/linkedlists/AddressSortedLinkedListWithMedian.sol"; import "../common/linkedlists/SortedLinkedListWithMedian.sol"; +import "../../contracts-0.8/common/interfaces/IOracle.sol"; /** * @title SortedOracles @@ -319,6 +320,29 @@ contract SortedOracles is ISortedOracles, ICeloVersionedContract, Ownable, Initi return rates[token].getElements(); } + /** + * @notice Returns the exchange rate for a specified token. + * @param token The token for which the exchange rate is being retrieved. + * @return uint256 The exchange rate for the specified token. + * @return uint256 The denominator for the exchange rate. + */ + function getExchangeRate( + address token + ) external view returns (uint256 numerator, uint256 denominator) { + (numerator, denominator) = medianRate(token); + } + + /** + * @notice Returns the storage, major, minor, and patch version of the contract. + * @return Storage version of the contract. + * @return Major version of the contract. + * @return Minor version of the contract. + * @return Patch version of the contract. + */ + function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { + return (1, 1, 4, 0); + } + /** * @notice Returns the median of the currently stored rates for a specified rateFeedId. * @dev Please note that this function respects the equivalentToken mapping, and so may @@ -327,7 +351,7 @@ contract SortedOracles is ISortedOracles, ICeloVersionedContract, Ownable, Initi * @return uint256 The median exchange rate for rateFeedId (fixidity). * @return uint256 denominator */ - function medianRate(address token) external view returns (uint256, uint256) { + function medianRate(address token) public view returns (uint256, uint256) { EquivalentToken storage equivalentToken = equivalentTokens[token]; if (equivalentToken.token != address(0)) { (uint256 equivalentMedianRate, uint256 denominator) = medianRateWithoutEquivalentMapping( @@ -339,17 +363,6 @@ contract SortedOracles is ISortedOracles, ICeloVersionedContract, Ownable, Initi return medianRateWithoutEquivalentMapping(token); } - /** - * @notice Returns the storage, major, minor, and patch version of the contract. - * @return Storage version of the contract. - * @return Major version of the contract. - * @return Minor version of the contract. - * @return Patch version of the contract. - */ - function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { - return (1, 1, 3, 0); - } - /** * @notice Sets the report expiry parameter. * @param _reportExpirySeconds The number of seconds before a report is considered expired. diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index cd00a78109c..67c7371784e 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -29,7 +29,6 @@ export enum CeloContractName { Freezer = 'Freezer', GasPriceMinimum = 'GasPriceMinimum', FeeCurrencyDirectory = 'FeeCurrencyDirectory', - MentoFeeCurrencyAdapterV1 = 'MentoFeeCurrencyAdapterV1', GoldToken = 'GoldToken', Governance = 'Governance', GovernanceSlasher = 'GovernanceSlasher', diff --git a/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts b/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts new file mode 100644 index 00000000000..92f0b60539a --- /dev/null +++ b/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts @@ -0,0 +1,57 @@ +import { ArtifactsSingleton } from '@celo/protocol/lib/artifactsSingleton' +import { CeloContractName } from '@celo/protocol/lib/registry-utils' +import { + deploymentForCoreContract, + getDeployedProxiedContract, +} from '@celo/protocol/lib/web3-utils' +import { SortedOraclesInstance, StableTokenInstance } from '@celo/protocol/types/typechain-mento' +import { FeeCurrencyDirectoryInstance } from 'types/08' +import { MENTO_PACKAGE, SOLIDITY_08_PACKAGE } from '../contractPackages' + +const initializeArgs = async (): Promise => { + return [] +} + +module.exports = deploymentForCoreContract( + web3, + artifacts, + CeloContractName.FeeCurrencyDirectory, + initializeArgs, + async (feeCurrencyDirectory: FeeCurrencyDirectoryInstance, _web3: Web3, networkName: string) => { + console.log("in after"); + const sortedOracles = await getDeployedProxiedContract( + 'SortedOracles', + artifacts + ) + + for (const token of ['StableToken', 'StableTokenEUR', 'StableTokenBRL']) { + const stableToken: StableTokenInstance = + await getDeployedProxiedContract( + token, + ArtifactsSingleton.getInstance(MENTO_PACKAGE) + ) + console.log( + 'setting currency config for', + token, + 'with address', + stableToken.address, + 'and adapter address', + sortedOracles.address, + 'on network', + networkName + ) + await feeCurrencyDirectory.setCurrencyConfig( + stableToken.address, + sortedOracles.address, + 1 + ) + } + + console.log( + 'Fee currency directory deployed and registered!!!', + feeCurrencyDirectory.address, + networkName + ) + }, + SOLIDITY_08_PACKAGE +) diff --git a/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol b/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol deleted file mode 100644 index 8df9a62080c..00000000000 --- a/packages/protocol/test-sol/common/MentoFeeCurrencyAdapterV1.t.sol +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity >=0.8.7 <0.8.20; - -import "celo-foundry-8/Test.sol"; -import "../../contracts-0.8/common/MentoFeeCurrencyAdapterV1.sol"; - -contract MockOracleV1 { - uint256 numerator; - uint256 denominator; - uint256 lastUpdateTimestamp; - address token; - - function setExchangeRate(address _token, uint256 _numerator, uint256 _denominator) public { - numerator = _numerator; - denominator = _denominator; - lastUpdateTimestamp = block.timestamp; - token = _token; - } - - function medianRate(address token) external view returns (uint256, uint256) { - return (numerator, denominator); - } -} - -contract MentoFeeCurrencyAdapterBase is Test { - MentoFeeCurrencyAdapterV1 mentoAdapter; - MockOracleV1 oracle; - address nonOwner; - address owner; - - function setUp() public virtual { - owner = address(this); - nonOwner = actor("nonOwner"); - oracle = new MockOracleV1(); - - mentoAdapter = new MentoFeeCurrencyAdapterV1(true); - mentoAdapter.initialize(address(oracle)); - } -} - -contract GetExchangeRate is MentoFeeCurrencyAdapterBase { - function test_ShouldReturnExchangeRateFromOracle() public { - address token = address(1); - uint256 numerator = 1; - uint256 denominator = 2; - oracle.setExchangeRate(token, numerator, denominator); - (uint256 rateNumerator, uint256 rateDenominator) = mentoAdapter.getExchangeRate(token); - - assertEq(rateNumerator, numerator); - assertEq(rateDenominator, denominator); - } -} From c817c913017dfe53d78b1a23f7da9f5044ab8d00 Mon Sep 17 00:00:00 2001 From: pahor167 Date: Tue, 14 May 2024 16:01:12 +0200 Subject: [PATCH 6/9] tests added --- .../26_100_fee_currency_directory.ts | 7 +-- .../26_100_mento_fee_currency_adapterV1.ts | 35 ----------- .../26_101_fee_currency_directory.ts | 63 ------------------- .../test-sol/stability/SortedOracles.t.sol | 3 + 4 files changed, 4 insertions(+), 104 deletions(-) delete mode 100644 packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts delete mode 100644 packages/protocol/migrations_ts/26_101_fee_currency_directory.ts diff --git a/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts b/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts index 92f0b60539a..604d4276a89 100644 --- a/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts +++ b/packages/protocol/migrations_ts/26_100_fee_currency_directory.ts @@ -18,7 +18,6 @@ module.exports = deploymentForCoreContract( CeloContractName.FeeCurrencyDirectory, initializeArgs, async (feeCurrencyDirectory: FeeCurrencyDirectoryInstance, _web3: Web3, networkName: string) => { - console.log("in after"); const sortedOracles = await getDeployedProxiedContract( 'SortedOracles', artifacts @@ -40,11 +39,7 @@ module.exports = deploymentForCoreContract( 'on network', networkName ) - await feeCurrencyDirectory.setCurrencyConfig( - stableToken.address, - sortedOracles.address, - 1 - ) + await feeCurrencyDirectory.setCurrencyConfig(stableToken.address, sortedOracles.address, 1) } console.log( diff --git a/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts b/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts deleted file mode 100644 index 69a991ee5f5..00000000000 --- a/packages/protocol/migrations_ts/26_100_mento_fee_currency_adapterV1.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { - deploymentForCoreContract, - getDeployedProxiedContract, -} from '@celo/protocol/lib/web3-utils' -import { SortedOraclesInstance } from '@celo/protocol/types' -import { MentoFeeCurrencyAdapterV1Instance } from 'types/08' -import { SOLIDITY_08_PACKAGE } from '../contractPackages' - -const initializeArgs = async (): Promise => { - const sortedOraclesAddress = await getDeployedProxiedContract( - 'SortedOracles', - artifacts - ) - return [sortedOraclesAddress.address] -} - -module.exports = deploymentForCoreContract( - web3, - artifacts, - CeloContractName.MentoFeeCurrencyAdapterV1, - initializeArgs, - async ( - feeCurrencyDirectory: MentoFeeCurrencyAdapterV1Instance, - _web3: Web3, - networkName: string - ) => { - console.log( - 'MentoFeeCurrencyAdapterV1Instance deployed and registered!!!', - feeCurrencyDirectory.address, - networkName - ) - }, - SOLIDITY_08_PACKAGE -) diff --git a/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts b/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts deleted file mode 100644 index 82d86a465d9..00000000000 --- a/packages/protocol/migrations_ts/26_101_fee_currency_directory.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { ArtifactsSingleton } from '@celo/protocol/lib/artifactsSingleton' -import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { - deploymentForCoreContract, - getDeployedProxiedContract, -} from '@celo/protocol/lib/web3-utils' -import { StableTokenInstance } from '@celo/protocol/types/typechain-mento' -import { FeeCurrencyDirectoryInstance, MentoFeeCurrencyAdapterV1Instance } from 'types/08' -import { MENTO_PACKAGE, SOLIDITY_08_PACKAGE } from '../contractPackages' - -const initializeArgs = async (): Promise => { - return [] -} - -module.exports = deploymentForCoreContract( - web3, - artifacts, - CeloContractName.FeeCurrencyDirectory, - initializeArgs, - async (feeCurrencyDirectory: FeeCurrencyDirectoryInstance, _web3: Web3, networkName: string) => { - const artifacts08 = ArtifactsSingleton.getInstance(SOLIDITY_08_PACKAGE, artifacts) - const feeCurrencyDirectoryInstance = - await getDeployedProxiedContract( - 'FeeCurrencyDirectory', - artifacts08 - ) - const nentoFeeCurrencyAdapterV1Instance = - await getDeployedProxiedContract( - 'MentoFeeCurrencyAdapterV1', - artifacts08 - ) - - for (const token of ['StableToken', 'StableTokenEUR', 'StableTokenBRL']) { - const stableToken: StableTokenInstance = - await getDeployedProxiedContract( - token, - ArtifactsSingleton.getInstance(MENTO_PACKAGE) - ) - console.log( - 'setting currency config for', - token, - 'with address', - stableToken.address, - 'and adapter address', - nentoFeeCurrencyAdapterV1Instance.address, - 'on network', - networkName - ) - await feeCurrencyDirectoryInstance.setCurrencyConfig( - stableToken.address, - nentoFeeCurrencyAdapterV1Instance.address, - 1 - ) - } - - console.log( - 'Fee currency directory deployed and registered!!!', - feeCurrencyDirectory.address, - networkName - ) - }, - SOLIDITY_08_PACKAGE -) diff --git a/packages/protocol/test-sol/stability/SortedOracles.t.sol b/packages/protocol/test-sol/stability/SortedOracles.t.sol index 4d89e5445fa..003cb5e3b30 100644 --- a/packages/protocol/test-sol/stability/SortedOracles.t.sol +++ b/packages/protocol/test-sol/stability/SortedOracles.t.sol @@ -476,8 +476,11 @@ contract RemoveOracle is SortedOraclesTest { sortedOracle.removeOracle(aToken, oracleAccount, 0); (uint256 newMedianRate, uint256 newNumOfRates) = sortedOracle.medianRate(aToken); + (uint256 exchangeRate, uint256 exchangeRateDenominator) = sortedOracle.getExchangeRate(aToken); assertEq(originalMedianRate, newMedianRate); assertEq(originalNumOfRates, newNumOfRates); + assertEq(exchangeRate, newMedianRate); + assertEq(exchangeRateDenominator, FIXED1); } function test_ShouldNotDecreaseTheNumberOfTimestamps_WhenThereIsASingleReportLeft() public { From 6376a214660f46b7c968b347607f142ff2ae8b05 Mon Sep 17 00:00:00 2001 From: pahor167 Date: Thu, 16 May 2024 12:40:27 +0200 Subject: [PATCH 7/9] fix test release --- .../lib/compatibility/verify-bytecode.ts | 20 +++++++------ .../initializationData/release12.json | 3 ++ .../scripts/truffle/verify-bytecode.ts | 4 ++- .../test/compatibility/verify-bytecode.ts | 28 +++++++++---------- 4 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 packages/protocol/releaseData/initializationData/release12.json diff --git a/packages/protocol/lib/compatibility/verify-bytecode.ts b/packages/protocol/lib/compatibility/verify-bytecode.ts index a7b1f5af13b..b5dfdb59f26 100644 --- a/packages/protocol/lib/compatibility/verify-bytecode.ts +++ b/packages/protocol/lib/compatibility/verify-bytecode.ts @@ -9,6 +9,7 @@ import { } from '@celo/protocol/lib/bytecode' import { verifyProxyStorageProof } from '@celo/protocol/lib/proxy-utils' import { ProposalTx } from '@celo/protocol/scripts/truffle/make-release' +import { ZERO_ADDRESS } from '@celo/protocol/test/constants' import { BuildArtifacts } from '@openzeppelin/upgrades' import { ProxyInstance, RegistryInstance } from 'types' import Web3 from 'web3' @@ -24,7 +25,7 @@ let ignoredContracts = [ ] interface VerificationContext { - artifacts: BuildArtifacts + artifacts: BuildArtifacts[] libraryAddresses: LibraryAddresses registry: RegistryInstance governanceAddress: string @@ -76,8 +77,8 @@ export const getProposedProxyAddress = (contract: string, proposal: ProposalTx[] return relevantTx.args[1] } -const getSourceBytecodeFromArtifacts = (contract: string, artifacts: BuildArtifacts): string => - stripMetadata(artifacts.getArtifactByName(contract).deployedBytecode) +const getSourceBytecodeFromArtifacts = (contract: string, artifacts: BuildArtifacts[]): string => + stripMetadata(artifacts.map(a => a.getArtifactByName(contract)).find(a => a).deployedBytecode) const getSourceBytecode = (contract: string, context: VerificationContext): string => getSourceBytecodeFromArtifacts(contract, context.artifacts) @@ -110,7 +111,6 @@ const dfsStep = async (queue: string[], visited: Set, context: Verificat throw new Error(`Proposed ${contract}Proxy does not match compiled proxy bytecode`) } - console.log(`Proxy deployed at ${proxyAddress} matches ${contract}Proxy (bytecode and storage)`) } // check implementation deployment @@ -124,6 +124,10 @@ const dfsStep = async (queue: string[], visited: Set, context: Verificat implementationAddress = ensureLeading0x(context.libraryAddresses.addresses[contract]) } else { const proxyAddress = await context.registry.getAddressForString(contract) + if (proxyAddress === ZERO_ADDRESS) { + console.log(`Contract ${contract} is not in registry - skipping bytecode verification`) + return; + } const proxy = await context.Proxy.at(proxyAddress) // necessary await implementationAddress = await proxy._getImplementation() } @@ -166,7 +170,7 @@ const assertValidProposalTransactions = (proposal: ProposalTx[]) => { } const assertValidInitializationData = ( - artifacts: BuildArtifacts, + artifacts: BuildArtifacts[], proposal: ProposalTx[], web3: Web3, initializationData: InitializationData @@ -182,7 +186,7 @@ const assertValidInitializationData = ( ) } - const contract = artifacts.getArtifactByName(contractName) + const contract = artifacts.map(a => a.getArtifactByName(contractName)).find(a => a) const initializeAbi = contract.abi.find( (abi: any) => abi.type === 'function' && abi.name === 'initialize' ) @@ -216,7 +220,7 @@ const assertValidInitializationData = ( */ export const verifyBytecodes = async ( contracts: string[], - artifacts: BuildArtifacts, + artifacts: BuildArtifacts[], registry: RegistryInstance, proposal: ProposalTx[], Proxy: Truffle.Contract, @@ -228,7 +232,7 @@ export const verifyBytecodes = async ( assertValidProposalTransactions(proposal) assertValidInitializationData(artifacts, proposal, _web3, initializationData) - const compiledContracts = artifacts.listArtifacts().map((a) => a.contractName) + const compiledContracts = Array.prototype.concat.apply([], artifacts.map(a => a.listArtifacts())).map((a) => a.contractName) if (version > 9) { ignoredContracts = [...ignoredContracts, ...ignoredContractsV9] diff --git a/packages/protocol/releaseData/initializationData/release12.json b/packages/protocol/releaseData/initializationData/release12.json new file mode 100644 index 00000000000..1d122a10b5d --- /dev/null +++ b/packages/protocol/releaseData/initializationData/release12.json @@ -0,0 +1,3 @@ +{ + "FeeCurrencyDirectory": [] +} diff --git a/packages/protocol/scripts/truffle/verify-bytecode.ts b/packages/protocol/scripts/truffle/verify-bytecode.ts index a5123e7166c..1890869d0cf 100644 --- a/packages/protocol/scripts/truffle/verify-bytecode.ts +++ b/packages/protocol/scripts/truffle/verify-bytecode.ts @@ -36,6 +36,7 @@ const argv = require('minimist')(process.argv.slice(2), { }) const artifactsDirectory = argv.build_artifacts ? argv.build_artifacts : './build/contracts' +const artifacts08Directory = argv.build_artifacts08 ? argv.build_artifacts08 : './build/contracts-0.8' const branch = (argv.branch ? argv.branch : '') as string const network = argv.network ?? 'development' const proposal = argv.proposal ? readJsonSync(argv.proposal) : [] @@ -48,9 +49,10 @@ module.exports = async (callback: (error?: any) => number) => { const registry = await Registry.at(celoRegistryAddress) const buildArtifacts = getBuildArtifacts(artifactsDirectory) + const artifacts08 = getBuildArtifacts(artifacts08Directory) const libraryAddresses = await verifyBytecodes( Object.keys(CeloContractName), - buildArtifacts, + [buildArtifacts, artifacts08], registry, proposal, Proxy, diff --git a/packages/protocol/test/compatibility/verify-bytecode.ts b/packages/protocol/test/compatibility/verify-bytecode.ts index e69c64755b5..942a612f303 100644 --- a/packages/protocol/test/compatibility/verify-bytecode.ts +++ b/packages/protocol/test/compatibility/verify-bytecode.ts @@ -123,7 +123,7 @@ contract('', (accounts) => { describe('verifyBytecodes', () => { it(`doesn't throw on matching contracts`, async () => { - await verifyBytecodes(['TestContract'], buildArtifacts, registry, [], Proxy, web3) + await verifyBytecodes(['TestContract'], [buildArtifacts], registry, [], Proxy, web3) assert(true) }) @@ -131,7 +131,7 @@ contract('', (accounts) => { const oldBytecode = artifact.deployedBytecode artifact.deployedBytecode = '0x0' + oldBytecode.slice(3, artifact.deployedBytecode.length) await assertThrowsAsync( - verifyBytecodes(['TestContract'], buildArtifacts, registry, [], Proxy, web3) + verifyBytecodes(['TestContract'], [buildArtifacts], registry, [], Proxy, web3) ) artifact.deployedBytecode = oldBytecode }) @@ -142,7 +142,7 @@ contract('', (accounts) => { libraryArtifact.deployedBytecode = oldBytecode.slice(0, 44) + '00' + oldBytecode.slice(46, oldBytecode.length) await assertThrowsAsync( - verifyBytecodes(['TestContract'], buildArtifacts, registry, [], Proxy, web3) + verifyBytecodes(['TestContract'], [buildArtifacts], registry, [], Proxy, web3) ) libraryArtifact.deployedBytecode = oldBytecode }) @@ -171,7 +171,7 @@ contract('', (accounts) => { await verifyBytecodes( ['TestContract'], - upgradedLibBuildArtifacts, + [upgradedLibBuildArtifacts], registry, proposal, Proxy, @@ -191,7 +191,7 @@ contract('', (accounts) => { ] await assertThrowsAsync( - verifyBytecodes(['TestContract'], buildArtifacts, registry, proposal, Proxy, web3) + verifyBytecodes(['TestContract'], [buildArtifacts], registry, proposal, Proxy, web3) ) }) @@ -206,7 +206,7 @@ contract('', (accounts) => { ] await assertThrowsAsync( - verifyBytecodes(['TestContract'], buildArtifacts, registry, proposal, Proxy, web3) + verifyBytecodes(['TestContract'], [buildArtifacts], registry, proposal, Proxy, web3) ) }) }) @@ -233,7 +233,7 @@ contract('', (accounts) => { await verifyBytecodes( ['TestContract'], - upgradedContractBuildArtifacts, + [upgradedContractBuildArtifacts], registry, proposal, Proxy, @@ -253,7 +253,7 @@ contract('', (accounts) => { ] await assertThrowsAsync( - verifyBytecodes(['TestContract'], buildArtifacts, registry, proposal, Proxy, web3) + verifyBytecodes(['TestContract'], [buildArtifacts], registry, proposal, Proxy, web3) ) }) @@ -268,7 +268,7 @@ contract('', (accounts) => { ] await assertThrowsAsync( - verifyBytecodes(['TestContract'], buildArtifacts, registry, proposal, Proxy, web3) + verifyBytecodes(['TestContract'], [buildArtifacts], registry, proposal, Proxy, web3) ) }) @@ -278,7 +278,7 @@ contract('', (accounts) => { await assertThrowsAsync( verifyBytecodes( ['TestContract'], - upgradedContractBuildArtifacts, + [upgradedContractBuildArtifacts], registry, proposal, Proxy, @@ -311,7 +311,7 @@ contract('', (accounts) => { await verifyBytecodes( ['TestContract'], - upgradedContractBuildArtifacts, + [upgradedContractBuildArtifacts], registry, proposal, Proxy, @@ -331,7 +331,7 @@ contract('', (accounts) => { ] await assertThrowsAsync( - verifyBytecodes(['TestContract'], buildArtifacts, registry, proposal, Proxy, web3) + verifyBytecodes(['TestContract'], [buildArtifacts], registry, proposal, Proxy, web3) ) }) @@ -346,7 +346,7 @@ contract('', (accounts) => { ] await assertThrowsAsync( - verifyBytecodes(['TestContract'], buildArtifacts, registry, proposal, Proxy, web3) + verifyBytecodes(['TestContract'], [buildArtifacts], registry, proposal, Proxy, web3) ) }) }) @@ -364,7 +364,7 @@ contract('', (accounts) => { await assertThrowsAsync( verifyBytecodes( ['TestContract'], - upgradedContractBuildArtifacts, + [upgradedContractBuildArtifacts], registry, proposal, Proxy, From 302ba15f1dd9218c89dd8afe32d0aae9439b610a Mon Sep 17 00:00:00 2001 From: pahor167 Date: Thu, 16 May 2024 14:08:26 +0200 Subject: [PATCH 8/9] lint --- packages/protocol/scripts/truffle/verify-bytecode.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/protocol/scripts/truffle/verify-bytecode.ts b/packages/protocol/scripts/truffle/verify-bytecode.ts index 1890869d0cf..9ca918b3029 100644 --- a/packages/protocol/scripts/truffle/verify-bytecode.ts +++ b/packages/protocol/scripts/truffle/verify-bytecode.ts @@ -36,7 +36,9 @@ const argv = require('minimist')(process.argv.slice(2), { }) const artifactsDirectory = argv.build_artifacts ? argv.build_artifacts : './build/contracts' -const artifacts08Directory = argv.build_artifacts08 ? argv.build_artifacts08 : './build/contracts-0.8' +const artifacts08Directory = argv.build_artifacts08 + ? argv.build_artifacts08 + : './build/contracts-0.8' const branch = (argv.branch ? argv.branch : '') as string const network = argv.network ?? 'development' const proposal = argv.proposal ? readJsonSync(argv.proposal) : [] From c42946b97e406ccaa321efc2d49bf7296fce8ee6 Mon Sep 17 00:00:00 2001 From: pahor167 Date: Thu, 16 May 2024 15:10:35 +0200 Subject: [PATCH 9/9] removal of MentoFeeCurrencyAdapterV1 --- packages/protocol/contractPackages.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contractPackages.ts b/packages/protocol/contractPackages.ts index ddc1de316bc..09ff7ce536d 100644 --- a/packages/protocol/contractPackages.ts +++ b/packages/protocol/contractPackages.ts @@ -48,7 +48,7 @@ export const SOLIDITY_08_PACKAGE = { proxiesPath: '/', // Proxies are still with 0.5 contracts // Proxies shouldn't have to be added to a list manually // https://github.com/celo-org/celo-monorepo/issues/10555 - contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory', 'MentoFeeCurrencyAdapterV1'], + contracts: ['GasPriceMinimum', 'FeeCurrencyDirectory'], proxyContracts: [ 'GasPriceMinimumProxy', 'FeeCurrencyDirectoryProxy',