From 571f0d02857137c55207f0e593c2b787c57a34dd Mon Sep 17 00:00:00 2001 From: MrDeadCe11 Date: Thu, 5 Sep 2024 21:45:11 -0500 Subject: [PATCH] slight refactor --- foundry.toml | 2 +- script/BaseData.sol | 10 +++--- script/BaseScript.s.sol | 39 +++++++++++++++++++---- script/DeployMainnetImplementations.s.sol | 14 ++++++-- script/inputs/L2ERC20DeploymentInput.json | 2 +- script/inputs/L2OFTAdapterInput.json | 2 +- 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/foundry.toml b/foundry.toml index fd5d210..36d60dc 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,7 +5,7 @@ libs = ["lib"] test = 'test' cache_path = 'cache' fs_permissions = [ - { access = "read-write", path = "./script/output" }, + { access = "read-write", path = "./deployments" }, { access = "read", path = "./" }, ] optimizer = true diff --git a/script/BaseData.sol b/script/BaseData.sol index fae9185..c252210 100644 --- a/script/BaseData.sol +++ b/script/BaseData.sol @@ -20,7 +20,7 @@ contract BaseData is Script { uint256 optimism; uint256 arbitrum; uint256 fraxtal; - uint256 holeksy; + uint256 holesky; uint256 fraxtalTestnet; } @@ -33,7 +33,7 @@ contract BaseData is Script { optimism: 10, arbitrum: 42161, fraxtal: 252, - holeksy: 17000, + holesky: 17000, fraxtalTestnet: 2522 }); @@ -57,8 +57,8 @@ contract BaseData is Script { addresses[chainIds.base] = ChainAddresses({lzEndpoint: 0x1a44076050125825900e736c501f859c50fE728c}); actors[chainIds.base] = Actors({OFT_DELEGATE: address(0), TOKEN_ADMIN: address(0), PROXY_ADMIN: address(0)}); - addresses[chainIds.holeksy] = ChainAddresses({lzEndpoint: 0x6EDCE65403992e310A62460808c4b910D972f10f}); - actors[chainIds.holeksy] = Actors({ + addresses[chainIds.holesky] = ChainAddresses({lzEndpoint: 0x6EDCE65403992e310A62460808c4b910D972f10f}); + actors[chainIds.holesky] = Actors({ OFT_DELEGATE: 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913, // yn security council TOKEN_ADMIN: 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913, PROXY_ADMIN: 0x743b91CDB1C694D4F51bCDA3a4A59DcC0d02b913 @@ -79,7 +79,7 @@ contract BaseData is Script { function isSupportedChainId(uint256 chainId) public view returns (bool) { return chainId == chainIds.mainnet || chainId == chainIds.base || chainId == chainIds.fraxtal - || chainId == chainIds.optimism || chainId == chainIds.arbitrum || chainId == chainIds.holeksy + || chainId == chainIds.optimism || chainId == chainIds.arbitrum || chainId == chainIds.holesky || chainId == chainIds.fraxtalTestnet; } } diff --git a/script/BaseScript.s.sol b/script/BaseScript.s.sol index 91a59cf..d8fbde7 100644 --- a/script/BaseScript.s.sol +++ b/script/BaseScript.s.sol @@ -5,14 +5,21 @@ import {BaseData} from "./BaseData.sol"; import {ImmutableMultiChainDeployer} from "@factory/ImmutableMultiChainDeployer.sol"; import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol"; import {EndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/EndpointV2.sol"; +import "forge-std/console.sol"; -struct YnOFTAdapterInput { +struct L2YnOFTAdapterInput { address adapterImplementation; uint256 chainId; address erc20Address; RateLimitConfig[] rateLimitConfigs; } +struct L1YnOFTAdapterInput { + uint256 chainId; + address erc20Address; + RateLimitConfig[] rateLimitConfigs; +} + struct RateLimitConfig { uint256 limit; uint256 window; @@ -32,7 +39,8 @@ contract BaseScript is BaseData { // TODO: setup saving of deployment data in deployments json file uint256 _chainId; bytes public data; - YnOFTAdapterInput public _ynOFTAdapterInputs; + L2YnOFTAdapterInput public _ynOFTAdapterInputs; + L1YnOFTAdapterInput public _ynOFTImplementationInputs; YnERC20Input public _ynERC20Inputs; RateLimiter.RateLimitConfig[] public _rateLimitConfigs; @@ -45,8 +53,21 @@ contract BaseScript is BaseData { function _loadOFTAdapterData(string memory _inputPath) internal { _loadJson(_inputPath); _loadYnOFTAdapterInputs(); + _verifyChain(); _getRateLimiterConfigs(); + } + + function _loadOFTImplementationData(string memory _inputPath) internal { + _loadJson(_inputPath); + _loadYnOFTImplementationInputs(); _verifyChain(); + _getRateLimiterConfigs(); + } + + function _loadYnOFTImplementationInputs() internal { + L1YnOFTAdapterInput memory implementationInputs = abi.decode(data, (L1YnOFTAdapterInput)); + this.loadImplementationInputs(implementationInputs); + _chainId = _ynOFTImplementationInputs.chainId; } function _loadJson(string memory _path) internal { @@ -56,15 +77,19 @@ contract BaseScript is BaseData { } function _loadYnOFTAdapterInputs() internal { - YnOFTAdapterInput memory ynOFTAdapterInputs = abi.decode(data, (YnOFTAdapterInput)); - _chainId = _ynOFTAdapterInputs.chainId; + L2YnOFTAdapterInput memory ynOFTAdapterInputs = abi.decode(data, (L2YnOFTAdapterInput)); this.loadAdapterInputs(ynOFTAdapterInputs); + _chainId = _ynOFTAdapterInputs.chainId; } - function loadAdapterInputs(YnOFTAdapterInput calldata _ynInput) external { + function loadAdapterInputs(L2YnOFTAdapterInput calldata _ynInput) external { _ynOFTAdapterInputs = _ynInput; } + function loadImplementationInputs(L1YnOFTAdapterInput calldata _ynImpInput) external { + _ynOFTImplementationInputs = _ynImpInput; + } + function _loadYnERC20Inputs() internal { _ynERC20Inputs = abi.decode(data, (YnERC20Input)); _chainId = _ynERC20Inputs.chainId; @@ -92,11 +117,11 @@ contract BaseScript is BaseData { function _getOutputPath(string memory _deploymentType) internal view returns (string memory) { string memory root = vm.projectRoot(); - return string.concat(root, "/script/output/", _deploymentType, "-", vm.toString(block.chainid), ".json"); + return string.concat(root, "/deployments/", _deploymentType, "-", vm.toString(block.chainid), ".json"); } function _writeOutput(string memory deploymentType, string memory json) internal { - string memory path = _getOutputPath("ImmutableMultiChainDeployer"); + string memory path = _getOutputPath(deploymentType); vm.writeFile(path, json); } } diff --git a/script/DeployMainnetImplementations.s.sol b/script/DeployMainnetImplementations.s.sol index dfe5b7c..7657283 100644 --- a/script/DeployMainnetImplementations.s.sol +++ b/script/DeployMainnetImplementations.s.sol @@ -7,13 +7,13 @@ import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/Ra import {L1YnOFTAdapterUpgradeable} from "@/L1YnOFTAdapterUpgradeable.sol"; import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -//forge script script/DeployMainnetImplementations.s.sol:DeployMainnetImplementations --rpc-url ${rpc} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify +// forge script script/DeployMainnetImplementations.s.sol:DeployMainnetImplementations --rpc-url ${rpc} --sig "run(string memory)" ${path} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify contract DeployMainnetImplementations is BaseScript { address public mainnetOFTAdapterImpl; L1YnOFTAdapterUpgradeable public mainnetOFTAdapter; function run(string memory __path) public { - _loadOFTAdapterData(__path); + _loadYnOFTImplementationInputs(__path); vm.broadcast(); @@ -23,5 +23,15 @@ contract DeployMainnetImplementations is BaseScript { L1YnOFTAdapterUpgradeable(address(new TransparentUpgradeableProxy(mainnetOFTAdapterImpl, msg.sender, ""))); mainnetOFTAdapter.initialize(msg.sender, _rateLimitConfigs); + + _serializeOutputs("MainnetImplementations"); + } + + function _serializeOutputs(string memory objectKey) internal override { + vm.serializeAddress(objectKey, "erc20", _ynOftAdapterInputs.erc20Address); + vm.serializeString(objectKey, "chainid", vm.toString(block.chainid)); + vm.serializeAddress(objectKey, "OFTAdapterImplementation", address(mainnetOFTAdapterImpl)); + string memory finalJson = vm.serializeAddress(objectKey, "OFTAdapter", address(mainnetOFTAdapter)); + _writeOutput("MainnetImplementations", finalJson); } } diff --git a/script/inputs/L2ERC20DeploymentInput.json b/script/inputs/L2ERC20DeploymentInput.json index 8521592..db6108a 100644 --- a/script/inputs/L2ERC20DeploymentInput.json +++ b/script/inputs/L2ERC20DeploymentInput.json @@ -1,5 +1,5 @@ { - "chainId": 1, + "chainId": 17000, "erc20Address": "0x0000000000000000000000000000000000000000", "lzEndpoint": "0x0000000000000000000000000000000000000000", "name": "name", diff --git a/script/inputs/L2OFTAdapterInput.json b/script/inputs/L2OFTAdapterInput.json index 76bfd18..5c9b16b 100644 --- a/script/inputs/L2OFTAdapterInput.json +++ b/script/inputs/L2OFTAdapterInput.json @@ -1,5 +1,5 @@ { - "chainId": 1, + "chainId": 17000, "erc20Address": "0x0000000000000000000000000000000000000000", "adapterImplementation": "0x0000000000000000000000000000000000000000", "rateLimiterConfigs": [