diff --git a/utils/deploy-contracts.ts b/utils/deploy-contracts.ts index a9ca23db..975ed71e 100644 --- a/utils/deploy-contracts.ts +++ b/utils/deploy-contracts.ts @@ -10,7 +10,7 @@ import { Factory__factory } from '../gen/typechain' -import { ContractFactory, ethers } from 'ethers' +import { BigNumber, ContractFactory, ethers } from 'ethers' import fs from 'fs' const provider = hethers.provider @@ -37,6 +37,9 @@ const singletonFactoryFactory = { "type": "function" }] } +const singletonFactoryDeployTx = + '0xf9016c8085174876e8008303c4d88080b90154608060405234801561001057600080fd5b50610134806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634af63f0214602d575b600080fd5b60cf60048036036040811015604157600080fd5b810190602081018135640100000000811115605b57600080fd5b820183602082011115606c57600080fd5b80359060200191846001830284011164010000000083111715608d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550509135925060eb915050565b604080516001600160a01b039092168252519081900360200190f35b6000818351602085016000f5939250505056fea26469706673582212206b44f8a82cb6b156bfcc3dc6aadd6df4eefd204bc928a4397fd15dacf6d5320564736f6c634300060200331b83247000822470' +const singletonFactoryDeployer = '0xBb6e024b9cFFACB947A71991E386681B1Cd1477D' const prompt = ora() const attempVerify = async (name: string, _: new () => T, address: string, ...args: Parameters) => { @@ -67,8 +70,30 @@ type simpleContractFactory> = { attach: (address: string) => ethers.Contract } -const deploy = async , Y extends Array>(name: string, contract: new (...args: [signer: ethers.Signer]) => T, ...args: Y): Promise => { - const singletonFactory = new ethers.Contract(singletonFactoryFactory.address, singletonFactoryFactory.abi, signer) +const deploy = async , Y extends Array>( + name: string, + contract: new (...args: [signer: ethers.Signer]) => T, + ...args: Y +): Promise => { + const singletonFactory = new ethers.Contract(singletonFactoryFactory.address, singletonFactoryFactory.abi, signer) + + if (ethers.utils.arrayify(await provider.getCode(singletonFactory.address)).length <= 2) { + // Deploy singleton deployer + const o = ora().start(`Deploying singleton factory`) + const deployerBal = BigNumber.from('24700000000000000') + if ((await provider.getBalance(singletonFactoryDeployer)).lt(deployerBal)) { + o.info('Funding singleton factory deployer') + const tx = await signer.sendTransaction({ + to: singletonFactoryDeployer, + value: deployerBal, + }) + await tx.wait() + o.info('Funded. Deploying singleton factory') + } + const tx = await provider.sendTransaction(singletonFactoryDeployTx) + await tx.wait() + o.succeed(`Deployed singleton factory`) + } const o = ora().start(`Deploying ${name}`) const c = new contract(signer)