Skip to content

Commit

Permalink
build: port truffle migrations to hardhat deployment script, update npm
Browse files Browse the repository at this point in the history
deployment scripts
  • Loading branch information
CruzMolina committed Jun 4, 2021
1 parent 20ab7f2 commit 873e800
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 101 deletions.
7 changes: 0 additions & 7 deletions migrations/1_initial_migration.js

This file was deleted.

57 changes: 0 additions & 57 deletions migrations/2_deploy_contracts.js

This file was deleted.

29 changes: 0 additions & 29 deletions migrations/3_setup_ownership.js

This file was deleted.

3 changes: 0 additions & 3 deletions migrations/deployment-config.json

This file was deleted.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
],
"scripts": {
"ganache": "ganache-cli -d --port 8545 --defaultBalanceEther 500",
"migrate": "truffle migrate",
"build": "npm run compile:contracts && npm run compile:types",
"calculate-contract-bytecode": "node scripts/calculateContractBytecode.js --contract",
"compile": "hardhat compile",
"compile:contracts": "truffle compile",
"compile:types": "typechain --target=truffle --outDir build/types/truffle-types \"build/contracts/*.json\"",
"deploy:development": "npm run build && npm run migrate -- --network development",
"deploy:mainnet": "npm run build && npm run migrate -- --network mainnet",
"deploy:ropsten": "npm run build && npm run migrate -- --network ropsten",
"deploy:kovan": "npm run build && npm run migrate -- --network kovan",
"deploy": "hardhat run scripts/deploy.ts",
"deploy:development": "npm run deploy",
"deploy:mainnet": "npm run deploy -- --network mainnet",
"deploy:ropsten": "npm run deploy -- --network ropsten",
"deploy:kovan": "npm run deploy -- --network kovan",
"lint:tests": "eslint 'test/**/*.ts'",
"lint:tests:fix": "npm run lint:tests -- --fix",
"lint:sol": "solhint -f table contracts/**/*.sol",
Expand Down
85 changes: 85 additions & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {Contract, ContractFactory} from '@ethersproject/contracts'
import {ethers} from 'hardhat'

const {MULTISIG} = require('../migrations/deployment-config.json')

async function deployContracts() {
// deploy AddressBook
const AddressBook: ContractFactory = await ethers.getContractFactory('AddressBook')
const addressBook = await AddressBook.deploy()

// deploy OtokenFactory & set address
const OtokenFactory: ContractFactory = await ethers.getContractFactory('OtokenFactory')
const oTokenFactory = await OtokenFactory.deploy(addressBook.address)
await addressBook.setOtokenFactory(oTokenFactory.address)

// deploy Otoken implementation & set address
const Otoken: ContractFactory = await ethers.getContractFactory('Otoken')
const oTokenImplementation = await Otoken.deploy()
await addressBook.setOtokenImpl(oTokenImplementation.address)

// deploy Whitelist module & set address
const Whitelist: ContractFactory = await ethers.getContractFactory('Whitelist')
const whitelist = await Whitelist.deploy(addressBook.address)
await addressBook.setWhitelist(whitelist.address)

// deploy Oracle module & set address
const Oracle: ContractFactory = await ethers.getContractFactory('Oracle')
const oracle = await Oracle.deploy()
await addressBook.setOracle(oracle.address)

// deploy MarginPool module & set address
const MarginPool: ContractFactory = await ethers.getContractFactory('MarginPool')
const marginPool = await MarginPool.deploy(addressBook.address)
await addressBook.setMarginPool(marginPool.address)

// deploy MarginCalculator module & set address
const MarginCalculator: ContractFactory = await ethers.getContractFactory('MarginCalculator')
const marginCalculator = await MarginCalculator.deploy(addressBook.address)
await addressBook.setMarginCalculator(marginCalculator.address)

// deploy MarginVault library
const MarginVault: ContractFactory = await ethers.getContractFactory('MarginVault')
const marginVault = await MarginVault.deploy()

// deploy Controller & set address
const Controller: ContractFactory = await ethers.getContractFactory('Controller', {
libraries: {
MarginVault: marginVault.address,
},
})
const controller = await Controller.deploy()
await addressBook.setController(controller.address)

return {addressBook, controller, marginPool, oracle, whitelist}
}

async function setupOwnership({
addressBook,
controller,
marginPool,
oracle,
whitelist,
}: {
[contractName: string]: Contract
}) {
// new protocol owner
const newOwner = MULTISIG

controller = await controller.attach(await addressBook.getController())

// transfer ownership
await addressBook.transferOwnership(newOwner)
await whitelist.transferOwnership(newOwner)
await oracle.transferOwnership(newOwner)
await marginPool.transferOwnership(newOwner)
await controller.transferOwnership(newOwner)
}

deployContracts()
.then(setupOwnership)
.then(() => process.exit(0))
.catch((error: Error) => {
console.error(error)
process.exit(1)
})

0 comments on commit 873e800

Please sign in to comment.