2022-02-23 17:27:44 +01:00
|
|
|
const { ethers } = require('hardhat')
|
|
|
|
const defaultConfig = require('../config')
|
|
|
|
|
|
|
|
async function generate(config = defaultConfig) {
|
2022-03-31 21:40:12 +02:00
|
|
|
const FactoryFactory = await ethers.getContractFactory('MultipleInstanceFactory')
|
2022-02-23 17:27:44 +01:00
|
|
|
const deploymentBytecodeFactory =
|
|
|
|
FactoryFactory.bytecode +
|
|
|
|
FactoryFactory.interface
|
2022-03-09 22:43:57 +01:00
|
|
|
.encodeDeploy([config.verifier, config.hasher, config.merkleTreeHeight, config.owner])
|
|
|
|
.slice(2)
|
|
|
|
|
|
|
|
const factoryAddress = ethers.utils.getCreate2Address(
|
|
|
|
config.singletonFactory,
|
|
|
|
config.salt,
|
|
|
|
ethers.utils.keccak256(deploymentBytecodeFactory),
|
|
|
|
)
|
|
|
|
|
|
|
|
const FactoryWithRegistryFactory = await ethers.getContractFactory('InstanceFactoryWithRegistry')
|
|
|
|
const deploymentBytecodeFactoryWithRegistry =
|
|
|
|
FactoryWithRegistryFactory.bytecode +
|
|
|
|
FactoryWithRegistryFactory.interface
|
2022-02-23 17:27:44 +01:00
|
|
|
.encodeDeploy([
|
|
|
|
config.verifier,
|
|
|
|
config.hasher,
|
|
|
|
config.merkleTreeHeight,
|
|
|
|
config.governance,
|
|
|
|
config.instanceRegistry,
|
|
|
|
config.TORN,
|
2022-03-15 18:55:01 +01:00
|
|
|
config.UniswapV3Factory,
|
|
|
|
config.WETH,
|
|
|
|
config.TWAPSlotsMin,
|
2022-02-23 17:27:44 +01:00
|
|
|
config.creationFee,
|
|
|
|
])
|
|
|
|
.slice(2)
|
|
|
|
|
2022-03-09 22:43:57 +01:00
|
|
|
const factoryWithRegistryAddress = ethers.utils.getCreate2Address(
|
2022-02-23 17:27:44 +01:00
|
|
|
config.singletonFactory,
|
|
|
|
config.salt,
|
2022-03-09 22:43:57 +01:00
|
|
|
ethers.utils.keccak256(deploymentBytecodeFactoryWithRegistry),
|
2022-02-23 17:27:44 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const result = {
|
|
|
|
factoryContract: {
|
|
|
|
address: factoryAddress,
|
|
|
|
bytecode: deploymentBytecodeFactory,
|
|
|
|
isProxy: false,
|
|
|
|
},
|
2022-03-09 22:43:57 +01:00
|
|
|
factoryWithRegistryContract: {
|
|
|
|
address: factoryWithRegistryAddress,
|
|
|
|
bytecode: deploymentBytecodeFactoryWithRegistry,
|
|
|
|
isProxy: false,
|
|
|
|
},
|
2022-02-23 17:27:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
async function generateWithLog() {
|
|
|
|
const contracts = await generate()
|
2022-03-31 21:40:12 +02:00
|
|
|
console.log('MultipleInstanceFactory contract: ', contracts.factoryContract.address)
|
2022-03-09 22:43:57 +01:00
|
|
|
console.log('Instance factory with registry contract: ', contracts.factoryWithRegistryContract.address)
|
2022-02-23 17:27:44 +01:00
|
|
|
return contracts
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
generate,
|
|
|
|
generateWithLog,
|
|
|
|
}
|