diff --git a/script/BaseConfig.sol b/script/BaseConfig.sol index 563132b..fbd7526 100644 --- a/script/BaseConfig.sol +++ b/script/BaseConfig.sol @@ -37,13 +37,12 @@ contract BaseDeploymentConfig is Script { _compareStrings(chainName, "arbitrum-goerli") || _compareStrings(chainName, "scroll-testnet-goerli") || _compareStrings(chainName, "staging-goerli") || - _compareStrings(chainName, "staging-mumbai") + _compareStrings(chainName, "staging-mumbai") || + _compareStrings(chainName, "test") ) { config = _readDeploymentConfig( - string.concat(vm.projectRoot(), "/deployments/", chainName, ".json") + string.concat(vm.projectRoot(), "/deployments/", chainName, "/run-latest.json") ); - } else if (_compareStrings(chainName, "test")) { - config = DeploymentConfig(address(0), address(0), address(0), address(0)); } else { revert ChainNameNotFound(chainName); } @@ -100,15 +99,7 @@ contract BaseDeploymentConfig is Script { vm.writeJson( finalJson, - string.concat( - vm.projectRoot(), - "/deployments/tmp/", - chainName, - "/logs", - "-", - Strings.toString(block.timestamp), - ".json" - ) + string.concat(vm.projectRoot(), "/deployments/tmp/", chainName, "/run-latest.json") ); } diff --git a/script/DeployLibraries.s.sol b/script/DeployLibraries.s.sol index 364f8e5..fd341d8 100644 --- a/script/DeployLibraries.s.sol +++ b/script/DeployLibraries.s.sol @@ -14,11 +14,11 @@ import {RequestBuilder} from "src/utils/RequestBuilder.sol"; /** * @title DeployLibraries Script * @notice To test this script locally, run: - * in a first terminal: `anvil fork-url https://rpc.ankr.com/polygon_mumbai` - * in a second terminal: `cast rpc anvil_impersonateAccount` + * in a first terminal: `anvil --fork-url https://rpc.ankr.com/polygon_mumbai` + * in a second terminal: `cast rpc anvil_impersonateAccount 0xbb8fca8f2381cfeede5d7541d7bf76343ef6c67b` * and finally: `CHAIN_NAME=test forge script DeployLibraries --rpc-url localhost --sender 0xbb8fca8f2381cfeede5d7541d7bf76343ef6c67b --unlocked -vvvv` * You should see that the libraries are being deployed and successfully set in the AddressesProvider contract. - * You can then run the `yarn save-deployments` command to save the deployment addresses in the `deployments` folder. You will see the libraries addresses in the `deployments/test/logs-*.json` file. + * You can then run the `yarn save-deployments` command to save the deployment addresses in the `deployments` folder. You will see the libraries addresses in the `deployments/test/run-latest.json` file. */ contract DeployLibraries is Script, BaseDeploymentConfig { @@ -29,15 +29,6 @@ contract DeployLibraries is Script, BaseDeploymentConfig { RequestBuilder requestBuilder; } - struct DeployedLibrary { - address addr; - string name; - } - - // useful variables to set libraries addresses in AddressesProvider in batch - address[] public contractAddresses; - string[] public contractNames; - function run() public { runFor(vm.envString("CHAIN_NAME")); } @@ -57,28 +48,6 @@ contract DeployLibraries is Script, BaseDeploymentConfig { deployedLibraries.signatureBuilder = _deploySignatureBuilder(); deployedLibraries.requestBuilder = _deployRequestBuilder(); - // associate libraries addresses to names - DeployedLibrary[] memory deployedLibrariesArray = new DeployedLibrary[](4); - deployedLibrariesArray[0] = DeployedLibrary({ - addr: address(deployedLibraries.authRequestBuilder), - name: "authRequestBuilder-v1.1" - }); - deployedLibrariesArray[1] = DeployedLibrary({ - addr: address(deployedLibraries.claimRequestBuilder), - name: "claimRequestBuilder-v1.1" - }); - deployedLibrariesArray[2] = DeployedLibrary({ - addr: address(deployedLibraries.signatureBuilder), - name: "signatureBuilder-v1.1" - }); - deployedLibrariesArray[3] = DeployedLibrary({ - addr: address(deployedLibraries.requestBuilder), - name: "requestBuilder-v1.1" - }); - - // update addresses provider with deployed libraries addresses - _setLibrariesAddresses(deployedLibrariesArray); - // update deployment config with deployed libraries addresses // and save it in `deployments` folder // only for a successful broadcast @@ -137,37 +106,4 @@ contract DeployLibraries is Script, BaseDeploymentConfig { console.log("requestBuilder Deployed:", address(requestBuilder)); return requestBuilder; } - - function _setLibrariesAddresses(DeployedLibrary[] memory deployedLibrariesArray) private { - console.log("== Updating Addresses Provider =="); - IAddressesProvider sismoAddressProvider = IAddressesProvider(SISMO_ADDRESSES_PROVIDER_V2); - - for (uint256 i = 0; i < deployedLibrariesArray.length; i++) { - DeployedLibrary memory deployedLibrary = deployedLibrariesArray[i]; - address currentContractAddress = sismoAddressProvider.get(deployedLibrary.name); - - if (currentContractAddress != deployedLibrary.addr) { - console.log( - "current contract address for", - deployedLibrary.name, - "is different. Updating address to", - deployedLibrary.addr - ); - // save address to update in batch after - contractAddresses.push(deployedLibrary.addr); - contractNames.push(deployedLibrary.name); - } else { - console.log( - "current contract address for", - deployedLibrary.name, - "is already the expected one. skipping update" - ); - } - } - - if (contractAddresses.length > 0) { - console.log("Updating Addresses Provider in batch..."); - sismoAddressProvider.setBatch(contractAddresses, contractNames); - } - } } diff --git a/script/utils/SetAddressesProvider.s.sol b/script/utils/SetAddressesProvider.s.sol new file mode 100644 index 0000000..1d2737b --- /dev/null +++ b/script/utils/SetAddressesProvider.s.sol @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; + +import "forge-std/Script.sol"; +import "forge-std/console.sol"; + +import {IAddressesProvider} from "src/interfaces/IAddressesProvider.sol"; +import {BaseDeploymentConfig, DeploymentConfig} from "script/BaseConfig.sol"; + +contract SetAddressesProvider is Script, BaseDeploymentConfig { + struct DeployedLibrary { + address addr; + string name; + } + + // useful variables to set libraries addresses in AddressesProvider in batch + address[] public contractAddresses; + string[] public contractNames; + + function run() external { + runFor(vm.envString("CHAIN_NAME")); + } + + function runFor(string memory _chainName) public { + console.log("Run for CHAIN_NAME:", _chainName); + console.log("Sender:", msg.sender); + + vm.startBroadcast(); + _setConfig({chainName: _chainName}); + + // associate libraries addresses to names + DeployedLibrary[] memory deployedLibrariesArray = new DeployedLibrary[](4); + deployedLibrariesArray[0] = DeployedLibrary({ + addr: address(config.authRequestBuilder), + name: "authRequestBuilder-v1.1" + }); + deployedLibrariesArray[1] = DeployedLibrary({ + addr: address(config.claimRequestBuilder), + name: "claimRequestBuilder-v1.1" + }); + deployedLibrariesArray[2] = DeployedLibrary({ + addr: address(config.signatureBuilder), + name: "signatureBuilder-v1.1" + }); + deployedLibrariesArray[3] = DeployedLibrary({ + addr: address(config.requestBuilder), + name: "requestBuilder-v1.1" + }); + + // update addresses provider with deployed libraries addresses + _setLibrariesAddresses(deployedLibrariesArray); + + vm.stopBroadcast(); + } + + function _setLibrariesAddresses(DeployedLibrary[] memory deployedLibrariesArray) private { + console.log("== Updating Addresses Provider =="); + IAddressesProvider sismoAddressProvider = IAddressesProvider(SISMO_ADDRESSES_PROVIDER_V2); + + for (uint256 i = 0; i < deployedLibrariesArray.length; i++) { + DeployedLibrary memory deployedLibrary = deployedLibrariesArray[i]; + address currentContractAddress = sismoAddressProvider.get(deployedLibrary.name); + + if (currentContractAddress != deployedLibrary.addr) { + console.log( + "current contract address for", + deployedLibrary.name, + "is different. Updating address to", + deployedLibrary.addr + ); + // save address to update in batch after + contractAddresses.push(deployedLibrary.addr); + contractNames.push(deployedLibrary.name); + } else { + console.log( + "current contract address for", + deployedLibrary.name, + "is already the expected one. skipping update" + ); + } + } + + if (contractAddresses.length > 0) { + console.log("Updating Addresses Provider in batch..."); + sismoAddressProvider.setBatch(contractAddresses, contractNames); + } + } +} diff --git a/test/script/DeployLibraries.t.sol b/test/script/DeployLibraries.t.sol index 3b03fcc..b0f6eaf 100644 --- a/test/script/DeployLibraries.t.sol +++ b/test/script/DeployLibraries.t.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.17; import "forge-std/Test.sol"; import "forge-std/console.sol"; import {DeployLibraries, DeploymentConfig} from "script/DeployLibraries.s.sol"; +import {SetAddressesProvider} from "script/utils/SetAddressesProvider.s.sol"; import {AddressesProviderMock} from "test/mocks/AddressesProviderMock.sol"; import {BaseTest} from "test/BaseTest.t.sol"; import {IAddressesProvider} from "src/interfaces/IAddressesProvider.sol"; @@ -11,17 +12,39 @@ import {IAddressesProvider} from "src/interfaces/IAddressesProvider.sol"; contract DeployLibrariesTest is BaseTest { DeployLibraries deploy; DeploymentConfig contracts; + SetAddressesProvider setAddressesProvider; function setUp() public virtual override { super.setUp(); + // clean the deployments/test folder + string[] memory removeFolderInputs = new string[](3); + removeFolderInputs[0] = "rm"; + removeFolderInputs[1] = "-rf"; + removeFolderInputs[2] = string.concat(vm.projectRoot(), "/deployments/test"); + vm.ffi(removeFolderInputs); + deploy = new DeployLibraries(); // deploy all libraries by calling the `runFor` function of the DeployLibraries script contract (bool success, bytes memory result) = address(deploy).delegatecall( abi.encodeWithSelector(DeployLibraries.runFor.selector, "test") ); - require(success, "Deploy script did not run successfully!"); + require(success, "DeployLibraries script did not run successfully!"); contracts = abi.decode(result, (DeploymentConfig)); + + // save the test config in the `deployments` folder + // so that the libraries addresses are available for the other scripts + string[] memory inputs = new string[](2); + inputs[0] = "yarn"; + inputs[1] = "save-deployments"; + vm.ffi(inputs); + + // set the addresses in the AddressesProvider contract + setAddressesProvider = new SetAddressesProvider(); + (bool success2, ) = address(setAddressesProvider).delegatecall( + abi.encodeWithSelector(SetAddressesProvider.runFor.selector, "test") + ); + require(success2, "SetAddressesProvider script did not run successfully!"); } function testDeployLibraries() public { diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..c942a1e --- /dev/null +++ b/yarn.lock @@ -0,0 +1,53 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@solidity-parser/parser@^0.16.0": + version "0.16.1" + resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.16.1.tgz#f7c8a686974e1536da0105466c4db6727311253c" + integrity sha512-PdhRFNhbTtu3x8Axm0uYpqOy/lODYQK+MlYSgqIsq2L8SFYEHJPHNUiOTAJbDGzNjjr1/n9AcIayxafR/fWmYw== + dependencies: + antlr4ts "^0.5.0-alpha.4" + +antlr4ts@^0.5.0-alpha.4: + version "0.5.0-alpha.4" + resolved "https://registry.yarnpkg.com/antlr4ts/-/antlr4ts-0.5.0-alpha.4.tgz#71702865a87478ed0b40c0709f422cf14d51652a" + integrity sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ== + +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== + dependencies: + yallist "^4.0.0" + +prettier-plugin-solidity@^1.0.0-beta.13: + version "1.1.3" + resolved "https://registry.yarnpkg.com/prettier-plugin-solidity/-/prettier-plugin-solidity-1.1.3.tgz#9a35124f578404caf617634a8cab80862d726cba" + integrity sha512-fQ9yucPi2sBbA2U2Xjh6m4isUTJ7S7QLc/XDDsktqqxYfTwdYKJ0EnnywXHwCGAaYbQNK+HIYPL1OemxuMsgeg== + dependencies: + "@solidity-parser/parser" "^0.16.0" + semver "^7.3.8" + solidity-comments-extractor "^0.0.7" + +prettier@^2.3.1: + version "2.8.8" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da" + integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q== + +semver@^7.3.8: + version "7.5.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" + integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== + dependencies: + lru-cache "^6.0.0" + +solidity-comments-extractor@^0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/solidity-comments-extractor/-/solidity-comments-extractor-0.0.7.tgz#99d8f1361438f84019795d928b931f4e5c39ca19" + integrity sha512-wciNMLg/Irp8OKGrh3S2tfvZiZ0NEyILfcRCXCD4mp7SgK/i9gzLfhY2hY7VMCQJ3kH9UB9BzNdibIVMchzyYw== + +yallist@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" + integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==