From 43bf272007c7c7c816d93b542c952d9fd70845f3 Mon Sep 17 00:00:00 2001 From: MrDeadCe11 Date: Fri, 6 Sep 2024 20:03:08 -0500 Subject: [PATCH] added script for l2 adapter deployment --- script/BaseScript.s.sol | 37 +++++++++++++++++++-- script/DeployMainnetImplementations.s.sol | 9 +++-- script/inputs/L2OFTAdapterInput.json | 12 +++---- src/factory/ImmutableMultiChainDeployer.sol | 2 ++ 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/script/BaseScript.s.sol b/script/BaseScript.s.sol index e29a214..9a8dd56 100644 --- a/script/BaseScript.s.sol +++ b/script/BaseScript.s.sol @@ -11,6 +11,9 @@ struct L2YnOFTAdapterInput { address adapterImplementation; uint256 chainId; address erc20Address; + bytes32 implementationSalt; + address proxyController; + bytes32 proxySalt; RateLimitConfig[] rateLimitConfigs; } @@ -39,6 +42,9 @@ contract BaseScript is BaseData { // TODO: setup saving of deployment data in deployments json file uint256 _chainId; bytes public data; + string public json; + address public immutableDeployer; + address public adapterImplementation; L2YnOFTAdapterInput public _ynOFTAdapterInputs; L1YnOFTAdapterInput public _ynOFTImplementationInputs; YnERC20Input public _ynERC20Inputs; @@ -54,6 +60,7 @@ contract BaseScript is BaseData { _loadJson(_inputPath); _loadYnOFTAdapterInputs(); _verifyChain(); + _loadDeployerForChain(block.chainid); _getRateLimiterConfigs(); } @@ -70,9 +77,29 @@ contract BaseScript is BaseData { _chainId = _ynOFTImplementationInputs.chainId; } + function _loadDeployerForChain(uint256 chainId) internal { + string memory path = string( + abi.encodePacked( + vm.projectRoot(), "/deployments/ImmutableMultiChainDeployer-", vm.toString(chainId), ".json" + ) + ); + string memory _json = vm.readFile(path); + immutableDeployer = vm.parseJsonAddress(_json, ".ImmutableMultiChainDeployerAddress"); + require(immutableDeployer != address(0), "invalid deployer"); + } + + function _loadAdapterImplementationForChain(uint32 chainId) internal { + string memory path = string( + abi.encodePacked(vm.projectRoot(), "/deployments/MainnetImplementations-", vm.toString(chainId), ".json") + ); + string memory _json = vm.readFile(path); + adapterImplementation = vm.parseJsonAddress(_json, ".OFTAdapterImplementation"); + require(adapterImplementation != address(0), "invalid adapter Implementation"); + } + function _loadJson(string memory _path) internal { string memory path = string(abi.encodePacked(vm.projectRoot(), "/", _path)); - string memory json = vm.readFile(path); + json = vm.readFile(path); data = vm.parseJson(json); } @@ -120,8 +147,12 @@ contract BaseScript is BaseData { return string.concat(root, "/deployments/", _deploymentType, "-", vm.toString(block.chainid), ".json"); } - function _writeOutput(string memory deploymentType, string memory json) internal { + function _writeOutput(string memory deploymentType, string memory _json) internal { string memory path = _getOutputPath(deploymentType); - vm.writeFile(path, json); + vm.writeFile(path, _json); + } + + function createSalt(address deployerAddress, string memory label) public pure returns (bytes32 _salt) { + _salt = bytes32(abi.encodePacked(bytes20(deployerAddress), bytes12(bytes32(keccak256(abi.encode(label)))))); } } diff --git a/script/DeployMainnetImplementations.s.sol b/script/DeployMainnetImplementations.s.sol index 5c8e941..0b6cd40 100644 --- a/script/DeployMainnetImplementations.s.sol +++ b/script/DeployMainnetImplementations.s.sol @@ -15,10 +15,13 @@ contract DeployMainnetImplementations is BaseScript { function run(string memory __path) public { _loadOFTImplementationData(__path); + _loadDeployerForChain(block.chainid); + vm.broadcast(); - mainnetOFTAdapterImpl = - address(new L1YnOFTAdapterUpgradeable(_ynOFTAdapterInputs.erc20Address, addresses[_chainId].lzEndpoint)); + mainnetOFTAdapterImpl = address( + new L1YnOFTAdapterUpgradeable(_ynOFTImplementationInputs.erc20Address, addresses[_chainId].lzEndpoint) + ); mainnetOFTAdapter = L1YnOFTAdapterUpgradeable(address(new TransparentUpgradeableProxy(mainnetOFTAdapterImpl, msg.sender, ""))); @@ -28,7 +31,7 @@ contract DeployMainnetImplementations is BaseScript { } function _serializeOutputs(string memory objectKey) internal override { - vm.serializeAddress(objectKey, "erc20", _ynOFTAdapterInputs.erc20Address); + vm.serializeAddress(objectKey, "erc20", _ynOFTImplementationInputs.erc20Address); vm.serializeString(objectKey, "chainid", vm.toString(block.chainid)); vm.serializeAddress(objectKey, "OFTAdapterImplementation", address(mainnetOFTAdapterImpl)); string memory finalJson = vm.serializeAddress(objectKey, "OFTAdapter", address(mainnetOFTAdapter)); diff --git a/script/inputs/L2OFTAdapterInput.json b/script/inputs/L2OFTAdapterInput.json index 5c9b16b..8c63498 100644 --- a/script/inputs/L2OFTAdapterInput.json +++ b/script/inputs/L2OFTAdapterInput.json @@ -1,14 +1,14 @@ { "chainId": 17000, - "erc20Address": "0x0000000000000000000000000000000000000000", - "adapterImplementation": "0x0000000000000000000000000000000000000000", + "erc20Address": "0xd9029669BC74878BCB5BE58c259ed0A277C5c16E", + "adapterImplementation": "0x1D5B39612a354C2Ff1f50cfd8D9FDEdB4d4F9e62", + "implementationSalt": "0x000000000000000000000000000000000000000093329e122e1b1b30629b7a7b", + "proxyController": "0x941E92c9Eff78a2b7217057752cf938040a59aE9", + "proxySalt": "0x000000000000000000000000000000000000000093329e122e1b1b30629f7a7b", "rateLimiterConfigs": [ { "limit": "100000000000000000000", "window": "86400" } - ], - "TOKEN_ADMIN": "0x0000000000000000000000000000000000000000", - "PROXY_ADMIN": "0x0000000000000000000000000000000000000000", - "OFT_DELEGATE": "0x0000000000000000000000000000000000000000" + ] } \ No newline at end of file diff --git a/src/factory/ImmutableMultiChainDeployer.sol b/src/factory/ImmutableMultiChainDeployer.sol index 43ed748..59fddf2 100644 --- a/src/factory/ImmutableMultiChainDeployer.sol +++ b/src/factory/ImmutableMultiChainDeployer.sol @@ -8,6 +8,7 @@ import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/Ra import {IImmutableMultiChainDeployer} from "@interfaces/IImmutableMultiChainDeployer.sol"; import {L2YnOFTAdapterUpgradeable} from "@/L2YnOFTAdapterUpgradeable.sol"; import {L2YnERC20Upgradeable} from "@/L2YnERC20Upgradeable.sol"; +import "forge-std/console.sol"; contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer { /// @notice Emitted when a new contract is deployed @@ -67,6 +68,7 @@ contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer { address _proxyController, bytes memory _l2YnOFTAdapterBytecode ) public override returns (address deployedContract) { + console.log(msg.sender); bytes memory _constructorParams = abi.encode(_token, _lzEndpoint); bytes memory _contractCode = abi.encodePacked(_l2YnOFTAdapterBytecode, _constructorParams); bytes memory _initializeArgs =