-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhardhat.config.ts
115 lines (102 loc) · 4.07 KB
/
hardhat.config.ts
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
import "@nomiclabs/hardhat-web3";
import "hardhat-typechain";
import "hardhat-gas-reporter";
import { HardhatUserConfig } from "hardhat/types";
import { task } from "hardhat/config";
import {
binanceHotWallet,
coinmarketcapKey,
CONTRACT_ADDRESS,
ethAlchemyRpcUrl,
ethChainId,
ethInfuraRpcUrl,
OWNER,
USDCAddress,
} from "./src/consts";
import { compoundLoop, printClaimableComp, printCurrentLiquidity, printHistoricalLiquidity } from "./src/balance";
import { erc20, fmt, fmt1e6, fmt1e8, impersonate, to1e6 } from "./src/utils";
task("status", "check status").setAction(async () => {
await printClaimableComp();
await printCurrentLiquidity();
await printHistoricalLiquidity(12);
});
task("addFunds", "fork and add funds").setAction(async () => {
await impersonate(OWNER);
await impersonate(binanceHotWallet);
await erc20(USDCAddress).methods.transfer(CONTRACT_ADDRESS, to1e6(4_000_000)).send({ from: binanceHotWallet });
const instance = compoundLoop();
const startBalance = await instance.methods.underlyingBalance().call({ from: OWNER });
const startCTokenBalance = await instance.methods.cTokenBalance().call({ from: OWNER });
const startLiquidity = await instance.methods.getAccountLiquidityWithInterest().call({ from: OWNER });
console.log("startBalance", fmt1e6(startBalance));
console.log("startCTokenBalance", fmt1e8(startCTokenBalance));
console.log("startLiquidity", fmt(startLiquidity.accountLiquidity));
await instance.methods.enterPosition(to1e6(250_000), 94, 100).send({ from: OWNER });
const endBalance = await instance.methods.underlyingBalance().call({ from: OWNER });
const endCTokenBalance = await instance.methods.cTokenBalance().call({ from: OWNER });
const endLiquidity = await instance.methods.getAccountLiquidityWithInterest().call({ from: OWNER });
console.log("endBalance", fmt1e6(endBalance));
console.log("endCTokenBalance", fmt1e8(endCTokenBalance));
console.log("endLiquidity", fmt(endLiquidity.accountLiquidity));
await instance.methods.exitPosition(100, 1, 1).send({ from: OWNER });
console.log("exit");
const endBalance2 = await instance.methods.underlyingBalance().call({ from: OWNER });
const endCTokenBalance2 = await instance.methods.cTokenBalance().call({ from: OWNER });
const endLiquidity2 = await instance.methods.getAccountLiquidityWithInterest().call({ from: OWNER });
console.log("endBalance2", fmt1e6(endBalance2));
console.log("endCTokenBalance2", fmt1e8(endCTokenBalance2));
console.log("endLiquidity2", fmt(endLiquidity2.accountLiquidity));
});
task("futureSim").setAction(async () => {
await impersonate(OWNER);
const instance = compoundLoop();
console.log("USDC", fmt1e6(await instance.methods.underlyingBalance().call({ from: OWNER })));
console.log("CToken", fmt1e8(await instance.methods.cTokenBalance().call({ from: OWNER })));
console.log("Liquidity", fmt((await instance.methods.getAccountLiquidityWithInterest().call({ from: OWNER })).accountLiquidity));
require("ethereumjs-hooks").jumpBlocks(1_000_000);
console.log("a million blocks later... (150 days) ");
console.log("USDC", fmt1e6(await instance.methods.underlyingBalance().call({ from: OWNER })));
console.log("CToken", fmt1e8(await instance.methods.cTokenBalance().call({ from: OWNER })));
console.log("Liquidity", fmt((await instance.methods.getAccountLiquidityWithInterest().call({ from: OWNER })).accountLiquidity));
});
const config: HardhatUserConfig = {
solidity: {
version: "0.7.4",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
defaultNetwork: "hardhat",
networks: {
hardhat: {
blockGasLimit: 12e6,
forking: {
url: ethAlchemyRpcUrl,
},
},
eth: {
chainId: ethChainId,
url: ethInfuraRpcUrl,
timeout: 60000,
httpHeaders: {
keepAlive: "true",
},
},
},
typechain: {
outDir: "typechain-hardhat",
target: "web3-v1",
},
mocha: {
timeout: 500_000,
},
gasReporter: {
currency: "USD",
coinmarketcap: coinmarketcapKey,
showTimeSpent: true,
},
};
export default config;