-
Notifications
You must be signed in to change notification settings - Fork 26
/
hardhat.config.js
120 lines (90 loc) · 3.54 KB
/
hardhat.config.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
/**
* @type import('hardhat/config').HardhatUserConfig
*/
require("@nomiclabs/hardhat-ethers");
const ERC20ABI = [
'function balanceOf(address) external view returns (uint)',
'function transfer(address, uint) external returns (bool)',
]
// Run this task with mainnet fork,
// so that you can see play around your flashloan example contract
task("flashloanV1", async (_, hre) => {
// The address that has USDC on mainnet
const walletAddr = '0xf977814e90da44bfa03b6295a0616a897441acec'
const USDCAddr = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
// below flashLender and comptroller addresses are for C.R.E.A.M. V1
const flashloanLenderAddr = '0xa8682Cfd2B6c714d2190fA38863d545c7a0b73D5'
const comptrollerAddr = '0x3d5BC3c8d13dcB8bF317092d84783c2697AE9258'
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [walletAddr]
});
const wallet = await hre.ethers.provider.getSigner(walletAddr);
const factory = await hre.ethers.getContractFactory('FlashloanBorrower');
// deploy flashloan Borrower contract
const flashloanBorrowerContract = await factory.deploy(comptrollerAddr);
// Send 100 USDC to flash loan Borrower contract,
// so that you have enough fund to pay the fee.
const USDC = new ethers.Contract(USDCAddr, ERC20ABI, wallet);
let tx = await USDC.transfer(flashloanBorrowerContract.address, 100 * 1e6)
await tx.wait()
console.log('contract:', flashloanBorrowerContract.address);
// call the doFlashloan
tx = await flashloanBorrowerContract.doFlashloan(flashloanLenderAddr, USDCAddr, 10000 * 1e6);
const receipt = await tx.wait()
// see the result
console.log(receipt.events)
await hre.network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [walletAddr]
});
})
task("flashloanIronBank", async (_, hre) => {
// The address that has SNX on mainnet
const walletAddr = '0xf977814e90da44bfa03b6295a0616a897441acec'
const SNXAddr = '0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F'
const flashloanLenderAddr = '0x1a21Ab52d1Ca1312232a72f4cf4389361A479829'
const comptrollerAddr = '0xAB1c342C7bf5Ec5F02ADEA1c2270670bCa144CbB'
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [walletAddr]
});
const wallet = await hre.ethers.provider.getSigner(walletAddr);
const factory = await hre.ethers.getContractFactory('FlashloanBorrower');
// deploy flashloan Borrower contract
const flashloanBorrowerContract = await factory.deploy(comptrollerAddr);
// Send SNX to flash loan Borrower contract,
// so that you have enough fund to pay the fee.
const SNX = new ethers.Contract(SNXAddr, ERC20ABI, wallet);
let tx = await SNX.transfer(flashloanBorrowerContract.address, 100 * 1e6)
await tx.wait()
console.log('contract:', flashloanBorrowerContract.address);
// call the doFlashloan
tx = await flashloanBorrowerContract.doFlashloan(flashloanLenderAddr, SNXAddr, 10000 * 1e6);
const receipt = await tx.wait()
// see the result
console.log(receipt.events)
await hre.network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [walletAddr]
});
})
module.exports = {
defaultNetwork: "hardhat",
solidity: {
version: "0.8.0" ,
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
networks: {
hardhat: {
forking: {
url: "https://mainnet.infura.io/v3/<PROJECT_ID>"
}
}
},
};