|
1 | | -// // SPDX-License-Identifier: MIT |
2 | | -// pragma solidity 0.8.28; |
3 | | - |
4 | | -// import {Script} from "forge-std/Script.sol"; |
5 | | -// import {console} from "forge-std/console.sol"; |
6 | | - |
7 | | -// import {ERC1967Factory} from "solady/utils/ERC1967Factory.sol"; |
8 | | -// import {ERC1967FactoryConstants} from "solady/utils/ERC1967FactoryConstants.sol"; |
9 | | - |
10 | | -// import {CrossChainERC20Factory} from "../src/CrossChainERC20Factory.sol"; |
11 | | -// import {CrossChainMessenger} from "../src/CrossChainMessenger.sol"; |
12 | | -// import {MessagePasser} from "../src/MessagePasser.sol"; |
13 | | -// import {TokenBridge} from "../src/TokenBridge.sol"; |
14 | | - |
15 | | -// contract DeployScript is Script { |
16 | | -// address public constant PROXY_ADMIN = 0x0fe884546476dDd290eC46318785046ef68a0BA9; |
17 | | - |
18 | | -// bytes32 public constant ORACLE = 0x0000000000000000000000000e9a877906EBc3b7098DA2404412BF0Ed1A5EFb4; |
19 | | -// bytes32 public constant REMOTE_MESSENGER = 0x7e273983f136714ba93a740a050279b541d6f25ebc6bbc6fc67616d0d5529cea; |
20 | | -// bytes32 public constant OTHER_BRIDGE = 0x7a25452c36304317d6fe970091c383b0d45e9b0b06485d2561156f025c6936af; |
21 | | - |
22 | | -// function setUp() public { |
23 | | -// vm.label(PROXY_ADMIN, "PROXY_ADMIN"); |
24 | | -// vm.label(ERC1967FactoryConstants.ADDRESS, "ERC1967_FACTORY"); |
25 | | -// } |
26 | | - |
27 | | -// function run() public { |
28 | | -// Chain memory chain = getChain(block.chainid); |
29 | | -// console.log("Deploying on chain: %s", chain.name); |
30 | | - |
31 | | -// vm.startBroadcast(); |
32 | | -// address messagePasser = _deployMessagePasser(); |
33 | | -// address messenger = _deployMessenger(messagePasser); |
34 | | -// address bridge = _deployBridge(messenger); |
35 | | -// address factory = _deployFactory(bridge); |
36 | | -// vm.stopBroadcast(); |
37 | | - |
38 | | -// console.log("Deployed MessagePasser at: %s", messagePasser); |
39 | | -// console.log("Deployed CrossChainMessenger at: %s", messenger); |
40 | | -// console.log("Deployed TokenBridge at: %s", bridge); |
41 | | -// console.log("Deployed CrossChainERC20Factory at: %s", factory); |
42 | | - |
43 | | -// string memory out = "{"; |
44 | | -// out = _record(out, "MessagePasser", messagePasser, false); |
45 | | -// out = _record(out, "CrossChainMessenger", messenger, false); |
46 | | -// out = _record(out, "TokenBridge", bridge, false); |
47 | | -// out = _record(out, "CrossChainERC20Factory", factory, true); |
48 | | -// out = string.concat(out, "}"); |
49 | | - |
50 | | -// vm.createDir("deployments", true); |
51 | | -// vm.writeFile(string.concat("deployments/", chain.chainAlias, ".json"), out); |
52 | | -// } |
53 | | - |
54 | | -// function _deployMessagePasser() private returns (address) { |
55 | | -// MessagePasser messagePasser = new MessagePasser(); |
56 | | -// return address(messagePasser); |
57 | | -// } |
58 | | - |
59 | | -// function _deployMessenger(address messagePasser) private returns (address) { |
60 | | -// CrossChainMessenger messengerImpl = new CrossChainMessenger(messagePasser, REMOTE_MESSENGER); |
61 | | -// CrossChainMessenger messengerProxy = CrossChainMessenger( |
62 | | -// ERC1967Factory(ERC1967FactoryConstants.ADDRESS).deployAndCall({ |
63 | | -// implementation: address(messengerImpl), |
64 | | -// admin: PROXY_ADMIN, |
65 | | -// data: abi.encodeCall(CrossChainMessenger.initialize, (ORACLE)) |
66 | | -// }) |
67 | | -// ); |
68 | | - |
69 | | -// return address(messengerProxy); |
70 | | -// } |
71 | | - |
72 | | -// function _deployBridge(address messenger) private returns (address) { |
73 | | -// TokenBridge bridgeImpl = new TokenBridge(); |
74 | | -// TokenBridge bridgeProxy = TokenBridge( |
75 | | -// ERC1967Factory(ERC1967FactoryConstants.ADDRESS).deployAndCall({ |
76 | | -// implementation: address(bridgeImpl), |
77 | | -// admin: PROXY_ADMIN, |
78 | | -// data: abi.encodeCall(TokenBridge.initialize, (messenger, OTHER_BRIDGE)) |
79 | | -// }) |
80 | | -// ); |
81 | | - |
82 | | -// return address(bridgeProxy); |
83 | | -// } |
84 | | - |
85 | | -// function _deployFactory(address bridge) private returns (address) { |
86 | | -// CrossChainERC20Factory xChainERC20FactoryImpl = new CrossChainERC20Factory(); |
87 | | -// CrossChainERC20Factory xChainERC20Factory = CrossChainERC20Factory( |
88 | | -// ERC1967Factory(ERC1967FactoryConstants.ADDRESS).deployAndCall({ |
89 | | -// implementation: address(xChainERC20FactoryImpl), |
90 | | -// admin: PROXY_ADMIN, |
91 | | -// data: abi.encodeCall(CrossChainERC20Factory.initialize, (bridge)) |
92 | | -// }) |
93 | | -// ); |
94 | | - |
95 | | -// return address(xChainERC20Factory); |
96 | | -// } |
97 | | - |
98 | | -// function _record(string memory out, string memory key, address addr, bool isLast) |
99 | | -// private |
100 | | -// pure |
101 | | -// returns (string memory) |
102 | | -// { |
103 | | -// return string.concat(out, "\"", key, "\": \"", vm.toString(addr), isLast ? "\"" : "\","); |
104 | | -// } |
105 | | - |
106 | | -// function _addressToBytes32(address value) private pure returns (bytes32) { |
107 | | -// return bytes32(uint256(uint160(value))); |
108 | | -// } |
109 | | -// } |
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity 0.8.28; |
| 3 | + |
| 4 | +import {Script} from "forge-std/Script.sol"; |
| 5 | +import {console} from "forge-std/console.sol"; |
| 6 | +import {UpgradeableBeacon} from "solady/utils/UpgradeableBeacon.sol"; |
| 7 | + |
| 8 | +import {ERC1967Factory} from "solady/utils/ERC1967Factory.sol"; |
| 9 | +import {ERC1967FactoryConstants} from "solady/utils/ERC1967FactoryConstants.sol"; |
| 10 | + |
| 11 | +import {Bridge} from "../src/Bridge.sol"; |
| 12 | +import {CrossChainERC20} from "../src/CrossChainERC20.sol"; |
| 13 | +import {CrossChainERC20Factory} from "../src/CrossChainERC20Factory.sol"; |
| 14 | + |
| 15 | +import {Pubkey} from "../src/libraries/SVMLib.sol"; |
| 16 | + |
| 17 | +contract DeployScript is Script { |
| 18 | + address public constant PROXY_ADMIN = 0x0fe884546476dDd290eC46318785046ef68a0BA9; |
| 19 | + |
| 20 | + // EF3xsxZGWWJX9T7vCPb7hEgyJQKEj1mgSNLMNvF8a7cj |
| 21 | + Pubkey public constant REMOTE_BRIDGE = |
| 22 | + Pubkey.wrap(0xc4c16980efe2a570c1a7599fd2ebb40ca7f85daf897482b9c85d4b8933a61608); |
| 23 | + address public constant ORACLE = 0x0e9a877906EBc3b7098DA2404412BF0Ed1A5EFb4; |
| 24 | + |
| 25 | + function setUp() public { |
| 26 | + vm.label(PROXY_ADMIN, "PROXY_ADMIN"); |
| 27 | + vm.label(ERC1967FactoryConstants.ADDRESS, "ERC1967_FACTORY"); |
| 28 | + } |
| 29 | + |
| 30 | + function run() public { |
| 31 | + Chain memory chain = getChain(block.chainid); |
| 32 | + console.log("Deploying on chain: %s", chain.name); |
| 33 | + |
| 34 | + vm.startBroadcast(); |
| 35 | + address bridge = _deployBridge(); |
| 36 | + address factory = _deployFactory(bridge); |
| 37 | + vm.stopBroadcast(); |
| 38 | + |
| 39 | + console.log("Deployed Bridge at: %s", bridge); |
| 40 | + console.log("Deployed CrossChainERC20Factory at: %s", factory); |
| 41 | + |
| 42 | + string memory out = "{"; |
| 43 | + out = _record(out, "Bridge", bridge, false); |
| 44 | + out = _record(out, "CrossChainERC20Factory", factory, true); |
| 45 | + out = string.concat(out, "}"); |
| 46 | + |
| 47 | + vm.createDir("deployments", true); |
| 48 | + vm.writeFile(string.concat("deployments/", chain.chainAlias, ".json"), out); |
| 49 | + } |
| 50 | + |
| 51 | + function _deployBridge() private returns (address) { |
| 52 | + Bridge bridgeImpl = new Bridge(REMOTE_BRIDGE, ORACLE, PROXY_ADMIN); |
| 53 | + Bridge bridgeProxy = Bridge( |
| 54 | + ERC1967Factory(ERC1967FactoryConstants.ADDRESS).deploy({ |
| 55 | + implementation: address(bridgeImpl), |
| 56 | + admin: PROXY_ADMIN |
| 57 | + }) |
| 58 | + ); |
| 59 | + |
| 60 | + return address(bridgeProxy); |
| 61 | + } |
| 62 | + |
| 63 | + function _deployFactory(address bridge) private returns (address) { |
| 64 | + address erc20 = address(new CrossChainERC20(bridge)); |
| 65 | + address erc20Beacon = address(new UpgradeableBeacon(PROXY_ADMIN, erc20)); |
| 66 | + |
| 67 | + CrossChainERC20Factory xChainERC20FactoryImpl = new CrossChainERC20Factory(erc20Beacon); |
| 68 | + CrossChainERC20Factory xChainERC20Factory = CrossChainERC20Factory( |
| 69 | + ERC1967Factory(ERC1967FactoryConstants.ADDRESS).deploy({ |
| 70 | + implementation: address(xChainERC20FactoryImpl), |
| 71 | + admin: PROXY_ADMIN |
| 72 | + }) |
| 73 | + ); |
| 74 | + |
| 75 | + return address(xChainERC20Factory); |
| 76 | + } |
| 77 | + |
| 78 | + function _record(string memory out, string memory key, address addr, bool isLast) |
| 79 | + private |
| 80 | + pure |
| 81 | + returns (string memory) |
| 82 | + { |
| 83 | + return string.concat(out, "\"", key, "\": \"", vm.toString(addr), isLast ? "\"" : "\","); |
| 84 | + } |
| 85 | + |
| 86 | + function _addressToBytes32(address value) private pure returns (bytes32) { |
| 87 | + return bytes32(uint256(uint160(value))); |
| 88 | + } |
| 89 | +} |
0 commit comments