Skip to content

Commit

Permalink
add script to compute create2 address for contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Jan 21, 2025
1 parent 95545f9 commit 806e66d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
16 changes: 15 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,21 @@ const config: HardhatUserConfig = {
ignition: {
strategyConfig: {
create2: {
salt: "0x000000000000000000000000000000000000000000f4179bc3e4988a1a06f8d1", // 20 bytes: zero address; 1 byte: 00 - no cross chain protection, 11 bytes - random salt.
salt: "0x000000000000000000000000000000000000000000f4179bc3e4988a1a06f8d1",
// 20 bytes: zero address; 1 byte: 00 - no cross chain protection, 11 bytes - random salt.
//
// CreateX implements different safeguarding mechanisms depending on the encoded values in the salt
// * (`||` stands for byte-wise concatenation):
// => salt (32 bytes) = 0xbebebebebebebebebebebebebebebebebebebebe||ff||1212121212121212121212
// * - The first 20 bytes (i.e. `bebebebebebebebebebebebebebebebebebebebe`) may be used to
// * implement a permissioned deploy protection by setting them equal to `msg.sender`,
// -> In our case we set it to zero address to disable this protection
// * - The 21st byte (i.e. `ff`) may be used to implement a cross-chain redeploy protection by
// * setting it equal to `0x01`,
// -> In our case we set it to `0x00` to disable this protection
// * - The last random 11 bytes (i.e. `1212121212121212121212`) allow for 2**88 bits of entropy
// * for mining a salt.
// -> In our case f4179bc3e4988a1a06f8d1
},
},
requiredConfirmations: 5,
Expand Down
22 changes: 22 additions & 0 deletions scripts/maintenance/computeCreate2Address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ethers } from "hardhat";

async function main() {
const byteCode = "<your contract byte code here>";
const salt = "0x000000000000000000000000000000000000000000f4179bc3e4988a1a06f8d1"; // Replace your salt here;
const create2Deployer = "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed"; // This is deployer address for CreateX in every network

const create2ContractAddress = ethers.getCreate2Address(
create2Deployer,
ethers.keccak256(salt),
ethers.keccak256(byteCode),
);

console.log("Create2 computed address:", create2ContractAddress);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit 806e66d

Please sign in to comment.