Skip to content

Commit 8bb8ea9

Browse files
committed
build: port truffle migrations to hardhat deployment script, update npm deployment scripts
1 parent 9580124 commit 8bb8ea9

6 files changed

Lines changed: 90 additions & 98 deletions

File tree

migrations/1_initial_migration.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

migrations/2_deploy_contracts.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

migrations/3_setup_ownership.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
],
2424
"scripts": {
2525
"ganache": "ganache-cli -d --port 8545 --defaultBalanceEther 500",
26-
"migrate": "truffle migrate",
2726
"build": "npm run compile:contracts && npm run compile:types",
2827
"calculate-contract-bytecode": "node scripts/calculateContractBytecode.js --contract",
2928
"compile": "hardhat compile",
3029
"compile:contracts": "truffle compile",
3130
"compile:types": "typechain --target=truffle --outDir build/types/truffle-types \"build/contracts/*.json\"",
32-
"deploy:development": "npm run build && npm run migrate -- --network development",
33-
"deploy:mainnet": "npm run build && npm run migrate -- --network mainnet",
34-
"deploy:ropsten": "npm run build && npm run migrate -- --network ropsten",
35-
"deploy:kovan": "npm run build && npm run migrate -- --network kovan",
31+
"deploy": "hardhat run scripts/deploy.ts",
32+
"deploy:development": "npm run deploy",
33+
"deploy:mainnet": "npm run deploy -- --network mainnet",
34+
"deploy:ropsten": "npm run deploy -- --network ropsten",
35+
"deploy:kovan": "npm run deploy -- --network kovan",
3636
"lint:tests": "eslint 'test/**/*.ts'",
3737
"lint:tests:fix": "npm run lint:tests -- --fix",
3838
"lint:sol": "solhint -f table contracts/**/*.sol",

scripts/deploy.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {Contract, ContractFactory} from '@ethersproject/contracts'
2+
import {ethers} from 'hardhat'
3+
4+
const {MULTISIG} = require('./deployment-config.json')
5+
6+
async function deployContracts() {
7+
// deploy AddressBook
8+
const AddressBook: ContractFactory = await ethers.getContractFactory('AddressBook')
9+
const addressBook = await AddressBook.deploy()
10+
11+
// deploy OtokenFactory & set address
12+
const OtokenFactory: ContractFactory = await ethers.getContractFactory('OtokenFactory')
13+
const oTokenFactory = await OtokenFactory.deploy(addressBook.address)
14+
await addressBook.setOtokenFactory(oTokenFactory.address)
15+
16+
// deploy Otoken implementation & set address
17+
const Otoken: ContractFactory = await ethers.getContractFactory('Otoken')
18+
const oTokenImplementation = await Otoken.deploy()
19+
await addressBook.setOtokenImpl(oTokenImplementation.address)
20+
21+
// deploy Whitelist module & set address
22+
const Whitelist: ContractFactory = await ethers.getContractFactory('Whitelist')
23+
const whitelist = await Whitelist.deploy(addressBook.address)
24+
await addressBook.setWhitelist(whitelist.address)
25+
26+
// deploy Oracle module & set address
27+
const Oracle: ContractFactory = await ethers.getContractFactory('Oracle')
28+
const oracle = await Oracle.deploy()
29+
await addressBook.setOracle(oracle.address)
30+
31+
// deploy MarginPool module & set address
32+
const MarginPool: ContractFactory = await ethers.getContractFactory('MarginPool')
33+
const marginPool = await MarginPool.deploy(addressBook.address)
34+
await addressBook.setMarginPool(marginPool.address)
35+
36+
// deploy MarginCalculator module & set address
37+
const MarginCalculator: ContractFactory = await ethers.getContractFactory('MarginCalculator')
38+
const marginCalculator = await MarginCalculator.deploy(addressBook.address)
39+
await addressBook.setMarginCalculator(marginCalculator.address)
40+
41+
// deploy MarginVault library
42+
const MarginVault: ContractFactory = await ethers.getContractFactory('MarginVault')
43+
const marginVault = await MarginVault.deploy()
44+
45+
// deploy Controller & set address
46+
const Controller: ContractFactory = await ethers.getContractFactory('Controller', {
47+
libraries: {
48+
MarginVault: marginVault.address,
49+
},
50+
})
51+
const controller = await Controller.deploy()
52+
await addressBook.setController(controller.address)
53+
54+
return {addressBook, controller, marginPool, oracle, whitelist}
55+
}
56+
57+
async function setupOwnership({
58+
addressBook,
59+
controller,
60+
marginPool,
61+
oracle,
62+
whitelist,
63+
}: {
64+
[contractName: string]: Contract
65+
}) {
66+
// new protocol owner
67+
const newOwner = MULTISIG
68+
69+
controller = await controller.attach(await addressBook.getController())
70+
71+
// transfer ownership
72+
await addressBook.transferOwnership(newOwner)
73+
await whitelist.transferOwnership(newOwner)
74+
await oracle.transferOwnership(newOwner)
75+
await marginPool.transferOwnership(newOwner)
76+
await controller.transferOwnership(newOwner)
77+
}
78+
79+
deployContracts()
80+
.then(setupOwnership)
81+
.then(() => process.exit(0))
82+
.catch((error: Error) => {
83+
console.error(error)
84+
process.exit(1)
85+
})

0 commit comments

Comments
 (0)