Skip to content

Commit

Permalink
Add singleton deployer deployment to deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk committed Jul 7, 2023
1 parent 7716ab1 commit c8fcb7e
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions utils/deploy-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +37,9 @@ const singletonFactoryFactory = {
"type": "function"
}]
}
const singletonFactoryDeployTx =
'0xf9016c8085174876e8008303c4d88080b90154608060405234801561001057600080fd5b50610134806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634af63f0214602d575b600080fd5b60cf60048036036040811015604157600080fd5b810190602081018135640100000000811115605b57600080fd5b820183602082011115606c57600080fd5b80359060200191846001830284011164010000000083111715608d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550509135925060eb915050565b604080516001600160a01b039092168252519081900360200190f35b6000818351602085016000f5939250505056fea26469706673582212206b44f8a82cb6b156bfcc3dc6aadd6df4eefd204bc928a4397fd15dacf6d5320564736f6c634300060200331b83247000822470'
const singletonFactoryDeployer = '0xBb6e024b9cFFACB947A71991E386681B1Cd1477D'

const prompt = ora()
const attempVerify = async <T extends ContractFactory>(name: string, _: new () => T, address: string, ...args: Parameters<T["deploy"]>) => {
Expand Down Expand Up @@ -67,8 +70,30 @@ type simpleContractFactory<Y extends Array<any>> = {
attach: (address: string) => ethers.Contract
}

const deploy = async <T extends simpleContractFactory<Y>, Y extends Array<any>>(name: string, contract: new (...args: [signer: ethers.Signer]) => T, ...args: Y): Promise<ethers.Contract> => {
const singletonFactory = new ethers.Contract(singletonFactoryFactory.address, singletonFactoryFactory.abi, signer)
const deploy = async <T extends simpleContractFactory<Y>, Y extends Array<any>>(
name: string,
contract: new (...args: [signer: ethers.Signer]) => T,
...args: Y
): Promise<ethers.Contract> => {
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)
Expand Down

0 comments on commit c8fcb7e

Please sign in to comment.