diff --git a/packages/protocol/test/genesis/generate_genesis.test.ts b/packages/protocol/test/genesis/generate_genesis.test.ts index 94e12d186df..f92955c6bfd 100644 --- a/packages/protocol/test/genesis/generate_genesis.test.ts +++ b/packages/protocol/test/genesis/generate_genesis.test.ts @@ -59,6 +59,12 @@ action("Generate Genesis", function () { const expectCode: string = alloc[address].code expect(code.toLowerCase()).to.be.equal(expectCode.toLowerCase()) + + if (testConfig.contractAddresses[alloc[address].contractName]) { + expect(address).to.be.equal( + testConfig.contractAddresses[alloc[address].contractName] + ) + } } }) diff --git a/packages/protocol/test/genesis/test_config.json b/packages/protocol/test/genesis/test_config.json index 9400a4cc31a..441fc75e84e 100644 --- a/packages/protocol/test/genesis/test_config.json +++ b/packages/protocol/test/genesis/test_config.json @@ -20,6 +20,9 @@ { "0xdD2FD4581271e230360230F9337D5c0430Bf44C0": 1024 }, + { + "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E": 1024 + }, { "0x2546BcD3c84621e976D8185a91A922aE77ECEc30": 1024 }, @@ -40,7 +43,44 @@ }, { "0xBcd4042DE499D14e55001CcbB24a551F3b954096": 1024 + }, + { + "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720": 1024 + }, + { + "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f": 1024 + }, + { + "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955": 1024 + }, + { + "0x976EA74026E726554dB657fA54763abd0C3a0aa9": 1024 + }, + { + "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc": 1024 + }, + { + "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65": 1024 + }, + { + "0x90F79bf6EB2c4f870365E785982E1f101E93b906": 1024 + }, + { + "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC": 1024 + }, + { + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8": 1024 + }, + { + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266": 1024 } ], + "contractAddresses": { + "V1TaikoL2": "0x0000777700000000000000000000000000000001", + "TokenVault": "0x0000777700000000000000000000000000000002", + "EtherVault": "0x0000777700000000000000000000000000000003", + "Bridge": "0x0000777700000000000000000000000000000004", + "TestERC20": "0x0000777700000000000000000000000000000005" + }, "predeployERC20": true -} +} \ No newline at end of file diff --git a/packages/protocol/utils/generate_genesis/erc20.ts b/packages/protocol/utils/generate_genesis/erc20.ts index 9389de1cdf4..27e0d02b9db 100644 --- a/packages/protocol/utils/generate_genesis/erc20.ts +++ b/packages/protocol/utils/generate_genesis/erc20.ts @@ -27,13 +27,21 @@ export async function deployERC20( "./test/thirdparty/TestERC20.sol/TestERC20.json" )) - const address = ethers.utils.getCreate2Address( - contractOwner, - ethers.utils.keccak256( - ethers.utils.toUtf8Bytes(`${chainId}${artifact.contractName}`) - ), - ethers.utils.keccak256(ethers.utils.toUtf8Bytes(artifact.bytecode)) - ) + let address: string + if ( + config.contractAddresses && + ethers.utils.isAddress(config.contractAddresses[artifact.contractName]) + ) { + address = config.contractAddresses[artifact.contractName] + } else { + address = ethers.utils.getCreate2Address( + contractOwner, + ethers.utils.keccak256( + ethers.utils.toUtf8Bytes(`${chainId}${artifact.contractName}`) + ), + ethers.utils.keccak256(ethers.utils.toUtf8Bytes(artifact.bytecode)) + ) + } const variables = { _name: TOKEN_NAME, diff --git a/packages/protocol/utils/generate_genesis/interface.ts b/packages/protocol/utils/generate_genesis/interface.ts index 9bb5df8cf28..234a917d0dc 100644 --- a/packages/protocol/utils/generate_genesis/interface.ts +++ b/packages/protocol/utils/generate_genesis/interface.ts @@ -5,6 +5,7 @@ export interface Config { [key: string]: number }> predeployERC20: boolean + contractAddresses: Object } export interface Result { diff --git a/packages/protocol/utils/generate_genesis/v1TaikoL2.ts b/packages/protocol/utils/generate_genesis/v1TaikoL2.ts index 18105799f8f..716ed0e2bd5 100644 --- a/packages/protocol/utils/generate_genesis/v1TaikoL2.ts +++ b/packages/protocol/utils/generate_genesis/v1TaikoL2.ts @@ -39,7 +39,8 @@ export async function deployV1TaikoL2( const contractConfigs: any = await generateContractConfigs( contractOwner, - chainId + chainId, + config.contractAddresses ) const storageLayouts: any = {} @@ -88,7 +89,8 @@ export async function deployV1TaikoL2( // and initialized variables. async function generateContractConfigs( contractOwner: string, - chainId: number + chainId: number, + hardCodedAddresses: any ): Promise { const contractArtifacts: any = { // Libraries @@ -165,13 +167,20 @@ async function generateContractConfigs( bytecode = linkContractLibs(contractArtifacts.Bridge, addressMap) } - addressMap[contractName] = ethers.utils.getCreate2Address( - contractOwner, - ethers.utils.keccak256( - ethers.utils.toUtf8Bytes(`${chainId}${contractName}`) - ), - ethers.utils.keccak256(ethers.utils.toUtf8Bytes(bytecode)) - ) + if ( + hardCodedAddresses && + ethers.utils.isAddress(hardCodedAddresses[contractName]) + ) { + addressMap[contractName] = hardCodedAddresses[contractName] + } else { + addressMap[contractName] = ethers.utils.getCreate2Address( + contractOwner, + ethers.utils.keccak256( + ethers.utils.toUtf8Bytes(`${chainId}${contractName}`) + ), + ethers.utils.keccak256(ethers.utils.toUtf8Bytes(bytecode)) + ) + } } console.log("pre-computed addresses:")