forked from izyak/HOOD-Protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
145 lines (116 loc) · 4.96 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const path = require("path");
const ORACLE_ADDRESS = "0x8c064bcf7c0da3b3b090babfe8f3323534d84d68"
function BigN(n) {
return ethers.BigNumber.from(n.toString())
}
async function main() {
// get deployer account
const [deployer] = await ethers.getSigners();
contracts = {}
const AddressProvider = await ethers.getContractFactory("AddressProvider")
const Config = await ethers.getContractFactory("Config")
config = await Config.deploy()
contracts['config'] = config.address
const Core = await ethers.getContractFactory("LendingPoolCore", {
libraries: {
Config: contracts['config']
}
})
const Asset = await ethers.getContractFactory("Asset")
const Oracle = await ethers.getContractFactory("Oracle")
const Pool = await ethers.getContractFactory("LendingPool")
const DataProvider = await ethers.getContractFactory("LendingPoolDataProvider")
const ReserveInitializer = await ethers.getContractFactory("ReserveInitializer")
addressProvider = await AddressProvider.deploy()
ap = addressProvider.address
contracts['addressProvider'] = ap
core = await Core.deploy(ap)
contracts['lendingPoolCore'] = core.address
pool = await Pool.deploy(ap)
contracts['lendingPool'] = pool.address
data = await DataProvider.deploy(ap)
contracts['dataProvider'] = data.address
initializer = await ReserveInitializer.deploy(ap)
contracts['initializer'] = initializer.address
oracle = await Oracle.deploy(ORACLE_ADDRESS)
contracts['oracle'] = oracle.address
await addressProvider.setLendingPool(pool.address)
await addressProvider.setLendingPoolCore(core.address)
await addressProvider.setLendingPoolDataProvider(data.address)
await addressProvider.setETHAddress('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE')
await addressProvider.setReserveInitializer(initializer.address)
await addressProvider.setConfigLibrary(config.address)
await addressProvider.setPriceOracle(oracle.address)
await core.initialize()
await data.initialize()
await pool.initialize()
await initializer.initialize()
asset1 = await Asset.deploy("Bitcoin", "BTC", 18);
asset1Addr = asset1.address;
contracts['btc'] = asset1Addr
asset2 = await Asset.deploy("Ethereum", "ETH", 18);
asset2Addr = asset2.address;
contracts['eth'] = asset2Addr
asset3 = await Asset.deploy("United States Dollar", "USD", 18);
asset3Addr = asset3.address;
contracts['usd'] = asset3Addr
console.table(contracts)
let deployerAddr = deployer.address;
console.log(deployerAddr)
await asset1.mint(deployerAddr, BigN(999 * 10 ** 18))
await asset2.mint(deployerAddr, BigN(999 * 10 ** 18))
await asset3.mint(deployerAddr, BigN(999 * 10 ** 18))
console.log('minting done!')
await initializer.initializeReserve(contracts['btc']);
await initializer.initializeReserve(contracts['eth']);
await initializer.initializeReserve(contracts['usd']);
console.log("reserve initialized")
// // // set prices of assets
// const newtPrice = ethers.BigNumber.from(`${parseInt(5 * 10 ** 18)}`);
// const usdPrice = ethers.BigNumber.from(`${parseInt(1 * 10 ** 18)}`);
// const balnPrice = ethers.BigNumber.from(`${parseInt((10 ** 18)/120)}`);
// await oracle.set_reference_data(contracts['usd'], usdPrice); // [usd][usd] = 1
// await oracle.set_reference_data(contracts['baln'], balnPrice); // [baln][usd] = 1/120
// await oracle.set_reference_data(contracts['omm'], newtPrice); // [newt][usd] = 5
tx = await asset1.approve(contracts['lendingPoolCore'], BigN(200 * 10 ** 18))
await tx.wait()
tx = await asset2.approve(contracts['lendingPoolCore'], BigN(200 * 10 ** 18))
await tx.wait()
tx = await asset3.approve(contracts['lendingPoolCore'], BigN(200 * 10 ** 18))
await tx.wait()
console.log('approvals done!')
tx = await pool.deposit(contracts['btc'], BigN(200 * 10 ** 18))
await tx.wait()
tx = await pool.deposit(contracts['eth'], BigN(200 * 10 ** 18))
await tx.wait()
tx = await pool.deposit(contracts['usd'], BigN(200 * 10 ** 18))
await tx.wait()
console.log('Deposits done')
saveContractAdresses(contracts)
console.log("setup complete")
}
function saveContractAdresses(contractAddresses) {
const fs = require("fs");
const contractsDir = path.join(__dirname, "..", "frontend", "src", "consts");
if (!fs.existsSync(contractsDir)) {
fs.mkdirSync(contractsDir);
}
fs.writeFileSync(
path.join(contractsDir, "contractAddresses.json"),
JSON.stringify(contractAddresses, undefined, 2)
);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});