Skip to content

Commit

Permalink
call initialization function
Browse files Browse the repository at this point in the history
  • Loading branch information
Aodhgan committed Apr 21, 2021
1 parent 43cbd59 commit 6ebad29
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -19,3 +19,5 @@ types
# Solidity Coverage
coverage
coverage.json

dist
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -2,7 +2,8 @@
"name": "@pooltogether/pooltogether-proxy-factory",
"version": "1.0.0-beta.3",
"description": "PoolTogether ProxyFactory Deployer",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "GPL-3.0",
"scripts": {
"clean": "rm -rf cache/ artifacts/",
Expand Down
25 changes: 19 additions & 6 deletions src/deploy.ts
Expand Up @@ -4,6 +4,7 @@ import { getChainByChainId } from "evm-chains"
import { Signer } from "ethers"
import { existsSync, writeFileSync } from 'fs';
import { deployments, ethers, getChainId } from "hardhat"
import { info } from 'console';


const displayLogs = !process.env.HIDE_DEPLOY_LOG;
Expand Down Expand Up @@ -48,19 +49,23 @@ interface DeploySettings {
overWrite?: boolean
signer: any // replace with Signer type from ethers
initializeData?: any // string?
abi: any
}

export async function factoryDeploy(deploySettings: DeploySettings){
// get address of minimal proxy factory
const allDeployments = await deployments.all()
const genericProxyFactory = allDeployments.GenericProxyFactory

//get network name
const networkName = await getChainByChainId(parseInt(await getChainId())).name

if(!genericProxyFactory){
throw new Error(`No GenericProxyFactory deployed for this network ()`)
}

//get network name
const networkName = await getChainByChainId(parseInt(await getChainId())).name
if(deploySettings.initializeData && !deploySettings.abi){
throw new Error(`Initialize data provided but no ABI`)
}

if(deploySettings.overWrite && existsSync(`./deployments/${networkName}/${deploySettings.contractName}.json`)){
cyan(`Using existing implementation for ${deploySettings.contractName}`)
Expand All @@ -79,7 +84,7 @@ export async function factoryDeploy(deploySettings: DeploySettings){
const receipt = await ethers.provider.getTransactionReceipt(createProxyResult.hash);

const createdEvent = genericProxyFactoryContract.interface.parseLog(receipt.logs[0]);
// green(`aToken proxy for ${aTokenEntry.aTokenSymbol} created at ${createdEvent.args.created}`)
green(`Proxy for ${deploySettings.contractName} created at ${createdEvent.args.created}`)

const jsonObj: ProxyDeployment = {
address: createdEvent.args.created,
Expand All @@ -88,7 +93,15 @@ export async function factoryDeploy(deploySettings: DeploySettings){
args: deploySettings?.initializeData,
bytecode: `${await ethers.provider.getCode(createdEvent.args.created)}`
}

writeFileSync(`./deployments/${networkName}/${deploySettings.contractName}.json`, JSON.stringify(jsonObj), {encoding:'utf8',flag:'w'})
const pathFile = `./deployments/${networkName}/${deploySettings.contractName}.json`
info(`Deployments file saved at ${pathFile}`)
writeFileSync(pathFile, JSON.stringify(jsonObj), {encoding:'utf8',flag:'w'})

// now call intializer if applicable
if(deploySettings.initializeData){
dim(`calling passed function`)
const instanceContract = await ethers.getContractAt(deploySettings.abi, createdEvent.args.created, deploySettings.signer)
await instanceContract.initialize(deploySettings.initializeData) // will this always be intialize?
}

}
7 changes: 5 additions & 2 deletions tsconfig.json
Expand Up @@ -7,7 +7,8 @@
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"outDir": "./dist"
"outDir": "./dist",
"declaration": true
},
"include": [
"hardhat.config.ts",
Expand All @@ -19,5 +20,7 @@
"Constant.ts",
"./src/*"
],
"exclude":["node_modules"]
"exclude":[
"node_modules"
]
}

0 comments on commit 6ebad29

Please sign in to comment.