|
| 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