Skip to content

Commit 42de6dc

Browse files
authored
Deterministic Contract Deployments (#8)
Changes to the deployment script using create2. These should enable us to deploy the contracts to the same address on all networks.
1 parent 8245efe commit 42de6dc

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

script/DeployBatchCaller.s.sol

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@ import "forge-std/Vm.sol";
66
import "src/BatchCallAndSponsor.sol";
77
import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
88
import "lib/openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol";
9+
import "lib/openzeppelin-contracts/contracts/utils/Create2.sol";
910

1011
contract DeployBatchCaller is Script {
1112
BatchCallAndSponsor public batchCaller;
13+
// This salt will be used for CREATE2 deployment
14+
bytes32 public constant SALT = keccak256("BatchCallAndSponsor-v1");
1215

1316
function run() external {
1417
uint256 deployerPk = vm.envUint("DEPLOYER_KEY");
15-
address deployer = vm.addr(deployerPk);
16-
console.log("Deployer:", deployer);
18+
// Get the bytecode of the contract
19+
bytes memory bytecode = type(BatchCallAndSponsor).creationCode;
1720

1821
// Start broadcasting transactions with Alice's private key.
1922
vm.startBroadcast(deployerPk);
2023

21-
// Deploy the delegation contract (Alice will delegate calls to this contract).
22-
batchCaller = new BatchCallAndSponsor();
24+
// Deploy using CREATE2
25+
address payable deployedAddress = payable(Create2.deploy(0, SALT, bytecode));
26+
27+
// Cast the deployed address to BatchCallAndSponsor
28+
batchCaller = BatchCallAndSponsor(deployedAddress);
2329

2430
vm.stopBroadcast();
31+
// Log the deployed address
32+
console2.log("BatchCallAndSponsor deployed to:", deployedAddress);
2533
}
2634
}

script/DeployMultisend.s.sol

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,32 @@ import "forge-std/Vm.sol";
66
import "src/EOAMultisend.sol";
77
import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
88
import "lib/openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol";
9+
import "lib/openzeppelin-contracts/contracts/utils/Create2.sol";
910

1011
contract DeployMultisend is Script {
1112
EOAMultisend public multisend;
1213

14+
// This salt will be used for CREATE2 deployment
15+
// Using a constant salt ensures the same address across all networks
16+
bytes32 public constant SALT = keccak256("EOAMultisend-v1");
17+
1318
function run() external {
1419
uint256 deployerPk = vm.envUint("DEPLOYER_KEY");
1520

1621
vm.startBroadcast(deployerPk);
1722

18-
multisend = new EOAMultisend();
23+
// Get the bytecode of the contract
24+
bytes memory bytecode = type(EOAMultisend).creationCode;
25+
26+
// Deploy using CREATE2
27+
address payable deployedAddress = payable(Create2.deploy(0, SALT, bytecode));
28+
29+
// Cast the deployed address to EOAMultisend
30+
multisend = EOAMultisend(deployedAddress);
1931

2032
vm.stopBroadcast();
33+
34+
// Log the deployed address
35+
console2.log("EOAMultisend deployed to:", deployedAddress);
2136
}
2237
}

0 commit comments

Comments
 (0)