-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathharvester.mainnet.fork.js
More file actions
313 lines (267 loc) · 10.5 KB
/
Copy pathharvester.mainnet.fork.js
File metadata and controls
313 lines (267 loc) · 10.5 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
const { expect } = require("chai");
const { utils, BigNumber } = require("ethers");
const { createFixtureLoader, harvesterFixture } = require("./../_fixture");
const { isCI, oethUnits } = require("./../helpers");
const { hotDeployOption } = require("../_hot-deploy");
const addresses = require("../../utils/addresses");
const { setERC20TokenBalance } = require("../_fund");
const { parseUnits } = require("ethers").utils;
const loadFixture = createFixtureLoader(harvesterFixture);
describe("ForkTest: Harvester", function () {
this.timeout(0);
// Retry up to 3 times on CI
this.retries(isCI ? 3 : 0);
let fixture;
beforeEach(async () => {
fixture = await loadFixture();
await hotDeployOption(fixture, null, {
isOethFixture: true,
});
await hotDeployOption(fixture, null, {
isOethFixture: false,
});
});
describe("with Curve", () => {
it("Should swap CRV for WETH", async () => {
const {
oethHarvester,
strategist,
convexEthMetaStrategy,
oethDripper,
crv,
weth,
} = fixture;
const wethBefore = await weth.balanceOf(oethDripper.address);
// Send some rewards to the strategy
await setERC20TokenBalance(convexEthMetaStrategy.address, crv, "1000");
// prettier-ignore
const tx = await oethHarvester
.connect(strategist)["harvestAndSwap(address)"](convexEthMetaStrategy.address);
await expect(tx).to.emit(convexEthMetaStrategy, "RewardTokenCollected");
await expect(tx).to.emit(oethHarvester, "RewardTokenSwapped");
await expect(tx).to.emit(oethHarvester, "RewardProceedsTransferred");
// Should've transferred swapped WETH to Dripper
expect(await weth.balanceOf(oethDripper.address)).to.be.gt(
wethBefore.add(oethUnits("0.1"))
);
});
});
// Commenting this out since none of the strategies have anything
// that we want to harvest on Uniswap V2 or V3 right now.
// describe("with Uniswap V3", () => {
// it("Should swap CRV for USDT", async () => {
// const { harvester, timelock, crv } = fixture;
// const crvBefore = await crv.balanceOf(harvester.address);
// await harvester.connect(timelock).swapRewardToken(crv.address);
// expect(await crv.balanceOf(harvester.address)).to.equal(
// crvBefore.sub(oethUnits("4000"))
// );
// });
// });
describe("with Balancer", () => {
it("Should swap BAL and AURA for WETH", async () => {
const {
oethHarvester,
strategist,
bal,
aura,
weth,
oethDripper,
balancerREthStrategy,
} = fixture;
const wethBefore = await weth.balanceOf(oethDripper.address);
// Send some rewards to the strategy
await setERC20TokenBalance(balancerREthStrategy.address, bal, "1000");
await setERC20TokenBalance(balancerREthStrategy.address, aura, "1000");
// prettier-ignore
const tx = await oethHarvester
.connect(strategist)["harvestAndSwap(address)"](balancerREthStrategy.address);
await expect(tx).to.emit(balancerREthStrategy, "RewardTokenCollected");
await expect(tx).to.emit(oethHarvester, "RewardTokenSwapped");
await expect(tx).to.emit(oethHarvester, "RewardProceedsTransferred");
// Should've transferred everything to Harvester
expect(await bal.balanceOf(balancerREthStrategy.address)).to.equal("0");
expect(await aura.balanceOf(balancerREthStrategy.address)).to.equal("0");
// Should've transferred swapped WETH to Dripper
expect(await weth.balanceOf(oethDripper.address)).to.be.gt(
wethBefore.add(oethUnits("0.1"))
);
});
});
describe("OUSD Rewards Config", () => {
it("Should have correct reward token config for CRV", async () => {
const { harvester, crv } = fixture;
const config = await harvester.rewardTokenConfigs(crv.address);
expect(config.allowedSlippageBps).to.equal(300);
expect(config.harvestRewardBps).to.equal(200);
expect(config.swapPlatform).to.equal(
1 // Uniswap V3
);
expect(config.swapPlatformAddr).to.equal(
"0xE592427A0AEce92De3Edee1F18E0157C05861564"
);
expect(config.doSwapRewardToken).to.be.true;
expect(config.liquidationLimit).to.equal(parseUnits("4000", 18));
expect(await harvester.uniswapV3Path(crv.address)).to.eq(
utils.solidityPack(
["address", "uint24", "address", "uint24", "address"],
[
addresses.mainnet.CRV,
3000,
addresses.mainnet.WETH,
500,
addresses.mainnet.USDT,
]
)
);
});
it("Should have correct reward token config for CVX", async () => {
const { harvester, cvx } = fixture;
const config = await harvester.rewardTokenConfigs(cvx.address);
expect(config.allowedSlippageBps).to.equal(300);
expect(config.harvestRewardBps).to.equal(100);
expect(config.swapPlatform).to.equal(
1 // Uniswap V3
);
expect(config.swapPlatformAddr).to.equal(
"0xE592427A0AEce92De3Edee1F18E0157C05861564"
);
expect(config.doSwapRewardToken).to.be.true;
expect(config.liquidationLimit).to.equal(utils.parseEther("2500"));
expect(await harvester.uniswapV3Path(cvx.address)).to.eq(
utils.solidityPack(
["address", "uint24", "address", "uint24", "address"],
[
addresses.mainnet.CVX,
10000,
addresses.mainnet.WETH,
500,
addresses.mainnet.USDT,
]
)
);
});
it("Should have correct reward token config for COMP", async () => {
const { harvester, comp } = fixture;
const config = await harvester.rewardTokenConfigs(comp.address);
expect(config.allowedSlippageBps).to.equal(300);
expect(config.harvestRewardBps).to.equal(100);
expect(config.swapPlatform).to.equal(
1 // Uniswap V3
);
expect(config.swapPlatformAddr).to.equal(
"0xE592427A0AEce92De3Edee1F18E0157C05861564"
);
expect(config.doSwapRewardToken).to.be.true;
expect(config.liquidationLimit).to.equal(0);
expect((await harvester.uniswapV3Path(comp.address)).toLowerCase()).to.eq(
utils.solidityPack(
["address", "uint24", "address", "uint24", "address"],
[
addresses.mainnet.COMP,
3000,
addresses.mainnet.WETH,
500,
addresses.mainnet.USDT,
]
)
);
});
it("Should have correct reward token config for AAVE", async () => {
const { harvester, aave } = fixture;
const config = await harvester.rewardTokenConfigs(aave.address);
expect(config.allowedSlippageBps).to.equal(300);
expect(config.harvestRewardBps).to.equal(100);
expect(config.swapPlatform).to.equal(
1 // Uniswap V3
);
expect(config.swapPlatformAddr).to.equal(
"0xE592427A0AEce92De3Edee1F18E0157C05861564"
);
expect(config.doSwapRewardToken).to.be.true;
expect(config.liquidationLimit).to.equal(0);
expect((await harvester.uniswapV3Path(aave.address)).toLowerCase()).to.eq(
utils.solidityPack(
["address", "uint24", "address", "uint24", "address"],
[
addresses.mainnet.Aave,
10000,
addresses.mainnet.WETH,
500,
addresses.mainnet.USDT,
]
)
);
});
});
describe("OETH Rewards Config", () => {
it("Should have correct reward token config for CRV", async () => {
const { oethHarvester, crv } = fixture;
const config = await oethHarvester.rewardTokenConfigs(crv.address);
expect(config.allowedSlippageBps).to.equal(300);
expect(config.harvestRewardBps).to.equal(200);
expect(config.swapPlatform).to.equal(
3 // Curve
);
expect(config.swapPlatformAddr).to.equal(
"0x4eBdF703948ddCEA3B11f675B4D1Fba9d2414A14"
);
expect(config.doSwapRewardToken).to.be.true;
expect(config.liquidationLimit).to.equal(parseUnits("4000", 18));
const indices = await oethHarvester.curvePoolIndices(crv.address);
expect(indices[0]).to.eq(BigNumber.from("2"));
expect(indices[1]).to.eq(BigNumber.from("1"));
});
it("Should have correct reward token config for CVX", async () => {
const { oethHarvester, cvx } = fixture;
const config = await oethHarvester.rewardTokenConfigs(cvx.address);
expect(config.allowedSlippageBps).to.equal(300);
expect(config.harvestRewardBps).to.equal(200);
expect(config.swapPlatform).to.equal(
3 // Curve
);
expect(config.swapPlatformAddr).to.equal(
"0xB576491F1E6e5E62f1d8F26062Ee822B40B0E0d4"
);
expect(config.doSwapRewardToken).to.be.true;
expect(config.liquidationLimit).to.equal(parseUnits("2500", 18));
const indices = await oethHarvester.curvePoolIndices(cvx.address);
expect(indices[0]).to.eq(BigNumber.from("1"));
expect(indices[1]).to.eq(BigNumber.from("0"));
});
it("Should have correct reward token config for BAL", async () => {
const { oethHarvester, bal } = fixture;
const config = await oethHarvester.rewardTokenConfigs(bal.address);
expect(config.allowedSlippageBps).to.equal(300);
expect(config.harvestRewardBps).to.equal(200);
expect(config.swapPlatform).to.equal(
2 // Balancer
);
expect(config.swapPlatformAddr).to.equal(
"0xBA12222222228d8Ba445958a75a0704d566BF2C8"
);
expect(config.doSwapRewardToken).to.be.true;
expect(config.liquidationLimit).to.equal(parseUnits("1000", 18));
expect(await oethHarvester.balancerPoolId(bal.address)).to.equal(
"0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014"
);
});
it("Should have correct reward token config for AURA", async () => {
const { oethHarvester, aura } = fixture;
const config = await oethHarvester.rewardTokenConfigs(aura.address);
expect(config.allowedSlippageBps).to.equal(300);
expect(config.harvestRewardBps).to.equal(200);
expect(config.swapPlatform).to.equal(
2 // Balancer
);
expect(config.swapPlatformAddr).to.equal(
"0xBA12222222228d8Ba445958a75a0704d566BF2C8"
);
expect(config.doSwapRewardToken).to.be.true;
expect(config.liquidationLimit).to.equal(parseUnits("4000", 18));
expect(await oethHarvester.balancerPoolId(aura.address)).to.equal(
"0xcfca23ca9ca720b6e98e3eb9b6aa0ffc4a5c08b9000200000000000000000274"
);
});
});
});