-
Notifications
You must be signed in to change notification settings - Fork 0
/
idleCreamDai.js
213 lines (175 loc) · 10.4 KB
/
idleCreamDai.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
const { expect } = require("chai");
const { BigNumber, Wallet } = require("ethers");
const { formatEther, parseEther } =require('@ethersproject/units')
const daiAbi = require('../abis/daiAbi.json');
const crDaiAbi = require('../abis/crDaiAbi.json');
const { ethers } = require("hardhat");
// Mainnet Fork and test case for mainnet with hardhat network by impersonate account from mainnet
describe("deployed Contract on Mainnet fork", function() {
it("hardhat_impersonateAccount and transfer balance to our account", async function() {
const accounts = await ethers.getSigners();
// Mainnet addresses
const accountToImpersonate = '0x1759f4f92af1100105e405fca66abba49d5f924e'
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
const creamDAIContractAddress = '0x92B767185fB3B04F881e3aC8e5B0662a027A1D9f'
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [accountToImpersonate]}
)
let signer = await ethers.provider.getSigner(accountToImpersonate)
let daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
await daiContract.transfer(accounts[0].address, daiContract.balanceOf(accountToImpersonate))
signer = await ethers.provider.getSigner(accounts[0].address)
daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
});
it("Initialize IDle and CreamDAI startergy", async function() {
const accounts = await ethers.getSigners();
const accountToImpersonate = '0x1759f4f92af1100105e405fca66abba49d5f924e'
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
const creamDAIContractAddress = '0x92B767185fB3B04F881e3aC8e5B0662a027A1D9f'
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [accountToImpersonate]}
)
let signer = await ethers.provider.getSigner(accountToImpersonate)
let daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
await daiContract.transfer(accounts[0].address, daiContract.balanceOf(accountToImpersonate))
signer = await ethers.provider.getSigner(accounts[0].address)
daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
const IdleCreamDAI = await ethers.getContractFactory('IdleCreamDAI', signer);
const IdleCreamDAI_Instance = await IdleCreamDAI.deploy();
let creamDaiContract = new ethers.Contract(creamDAIContractAddress, crDaiAbi, signer)
await IdleCreamDAI_Instance.initialize(
creamDaiContract.address,
accounts[0].address
)
});
it("Mint from CreamDAI through idle startergy", async function() {
const accounts = await ethers.getSigners();
const accountToImpersonate = '0x1759f4f92af1100105e405fca66abba49d5f924e'
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
const creamDAIContractAddress = '0x92B767185fB3B04F881e3aC8e5B0662a027A1D9f'
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [accountToImpersonate]}
)
let signer = await ethers.provider.getSigner(accountToImpersonate)
let daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
await daiContract.transfer(accounts[0].address, daiContract.balanceOf(accountToImpersonate))
signer = await ethers.provider.getSigner(accounts[0].address)
daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
const IdleCreamDAI = await ethers.getContractFactory('IdleCreamDAI', signer);
const IdleCreamDAI_Instance = await IdleCreamDAI.deploy();
let creamDaiContract = new ethers.Contract(creamDAIContractAddress, crDaiAbi, signer)
await IdleCreamDAI_Instance.initialize(
creamDaiContract.address,
accounts[0].address
)
await daiContract.approve(creamDaiContract.address, '1000000000000000000000000000000000')
await daiContract.transfer(IdleCreamDAI_Instance.address, '1000000000000000000')
const bal0 = await creamDaiContract.balanceOf(accounts[0].address);
console.log('balanceOf0 crDai before mint: ', bal0.toString());
await IdleCreamDAI_Instance.mint() //// Mint Tokens or BuyTokens
const bal1 = await creamDaiContract.balanceOf(accounts[0].address);
console.log('balanceOf1 crDai after mint: ', bal1.toString());
});
it("Mint and Redeem from CreamDAI through idle startergy", async function() {
const accounts = await ethers.getSigners();
const accountToImpersonate = '0x1759f4f92af1100105e405fca66abba49d5f924e'
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
const creamDAIContractAddress = '0x92B767185fB3B04F881e3aC8e5B0662a027A1D9f'
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [accountToImpersonate]}
)
let signer = await ethers.provider.getSigner(accountToImpersonate)
let daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
await daiContract.transfer(accounts[0].address, daiContract.balanceOf(accountToImpersonate))
signer = await ethers.provider.getSigner(accounts[0].address)
daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
const IdleCreamDAI = await ethers.getContractFactory('IdleCreamDAI', signer);
const IdleCreamDAI_Instance = await IdleCreamDAI.deploy();
let creamDaiContract = new ethers.Contract(creamDAIContractAddress, crDaiAbi, signer)
await IdleCreamDAI_Instance.initialize(
creamDaiContract.address,
accounts[0].address
)
await daiContract.approve(creamDaiContract.address, '1000000000000000000000000000000000')
await daiContract.transfer(IdleCreamDAI_Instance.address, '10000000')
await IdleCreamDAI_Instance.mint() //// Mint Tokens or BuyTokens from CreamDAI
const balance = await creamDaiContract.balanceOf(accounts[0].address)
await creamDaiContract.transfer(IdleCreamDAI_Instance.address, balance)
await IdleCreamDAI_Instance.redeem(IdleCreamDAI_Instance.address) //// Idle Redeem or SellTokens from BarnBeidge
});
it("Get NextSupplyRate", async function() {
const accounts = await ethers.getSigners();
const accountToImpersonate = '0x1759f4f92af1100105e405fca66abba49d5f924e'
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
const creamDAIContractAddress = '0x92B767185fB3B04F881e3aC8e5B0662a027A1D9f'
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [accountToImpersonate]}
)
let signer = await ethers.provider.getSigner(accountToImpersonate)
let daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
await daiContract.transfer(accounts[0].address, daiContract.balanceOf(accountToImpersonate))
signer = await ethers.provider.getSigner(accounts[0].address)
daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
const IdleCreamDAI = await ethers.getContractFactory('IdleCreamDAI', signer);
const IdleCreamDAI_Instance = await IdleCreamDAI.deploy();
let creamDaiContract = new ethers.Contract(creamDAIContractAddress, crDaiAbi, signer)
await IdleCreamDAI_Instance.initialize(
creamDaiContract.address,
accounts[0].address
)
const rate = await IdleCreamDAI_Instance.nextSupplyRate('0') //// Idle Redeem or SellTokens from BarnBeidge
console.log('rate: ', rate.toString());
});
// it("This test case will print all state", async function() {
// const accounts = await ethers.getSigners();
// const accountToImpersonate = '0x1759f4f92af1100105e405fca66abba49d5f924e'
// const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
// const creamDAIContractAddress = '0x92B767185fB3B04F881e3aC8e5B0662a027A1D9f'
// await hre.network.provider.request({
// method: "hardhat_impersonateAccount",
// params: [accountToImpersonate]}
// )
// let signer = await ethers.provider.getSigner(accountToImpersonate)
// let daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
// await daiContract.transfer(accounts[0].address, daiContract.balanceOf(accountToImpersonate))
// signer = await ethers.provider.getSigner(accounts[0].address)
// daiContract = new ethers.Contract(daiAddress, daiAbi, signer)
// const IdleCreamDAI = await ethers.getContractFactory('IdleCreamDAI', signer);
// const IdleCreamDAI_Instance = await IdleCreamDAI.deploy();
// console.log('IdleCreamDAI_Instance: ', IdleCreamDAI_Instance.address);
// const rate = await IdleCreamDAI_Instance.nextSupplyRate('0') //// Idle Redeem or SellTokens from BarnBeidge
// console.log('rate: ', rate.toString());
// let creamDaiContract = new ethers.Contract(creamDAIContractAddress, crDaiAbi, signer)
// console.log('creamDaiContract.address: ', creamDaiContract.address)
// const maxBondDailyRate = await creamDaiContract.callStatic.maxBondDailyRate()
// console.log('maxBondDailyRate: ', maxBondDailyRate.toString())
// await IdleCreamDAI_Instance.initialize(
// creamDaiContract.address,
// accounts[0].address
// )
// await daiContract.approve(creamDaiContract.address, '1000000000000000000000000000000000')
// await daiContract.transfer(IdleCreamDAI_Instance.address, '10000000')
// const bal4 = await daiContract.balanceOf(IdleCreamDAI_Instance.address)
// console.log('IdleCreamDAI_Instance.address-bal4: ', bal4.toString())
// const bal5 = await creamDaiContract.balanceOf(IdleCreamDAI_Instance.address)
// console.log('creamDaiContract.address-bal5: ', bal5.toString())
// await IdleCreamDAI_Instance.mint() //// Mint Tokens or BuyTokens from CreamDAI
// const bal6 = await daiContract.balanceOf(IdleCreamDAI_Instance.address)
// console.log('IdleCreamDAI_Instance.address-bal6: ', bal6.toString())
// const bal61 = await creamDaiContract.balanceOf(accounts[0].address)
// console.log('creamDaiContract.address-bal61: ', bal61.toString())
// await creamDaiContract.transfer(IdleCreamDAI_Instance.address, bal61)
// const bal7 = await creamDaiContract.balanceOf(IdleCreamDAI_Instance.address)
// console.log('creamDaiContract.address-bal7: ', bal7.toString())
// await IdleCreamDAI_Instance.redeem(IdleCreamDAI_Instance.address) //// Idle Redeem or SellTokens from BarnBeidge
// const bal8 = await daiContract.balanceOf(IdleCreamDAI_Instance.address)
// console.log('IdleCreamDAI_Instance.address-bal8: ', bal8.toString())
// const bal9 = await creamDaiContract.balanceOf(IdleCreamDAI_Instance.address)
// console.log('creamDaiContract.address-bal9: ', bal9.toString())
// });
})