generated from 0xDaksh/solidity-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
fixtures.ts
68 lines (60 loc) · 2.1 KB
/
fixtures.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
import { parseEther } from "@ethersproject/units";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { ethers } from "hardhat";
import {
ComptrollerInterface,
ComptrollerInterface__factory,
CTokenInterface,
CTokenInterface__factory,
ERC20,
ERC20__factory,
} from "../../../typechain";
import { DAIAddr, USDCAddr, USDCWhaleAddr } from "../../consts";
import { impersonate } from "../../utils";
import { cUSDCAddr, cDAIAddr, comptrollerAddr } from "./consts";
interface CompoundFixtureResult {
wallet: SignerWithAddress;
cUSDC: CTokenInterface;
cDAI: CTokenInterface;
USDC: ERC20;
DAI: ERC20;
comptroller: ComptrollerInterface;
}
export const compoundFixture = async (): Promise<CompoundFixtureResult> => {
// ethers gives us 10 wallets, let's use the second one
// since we already used the first one in aave
// get a wallet with 1000 ETH
const [_, wallet] = await ethers.getSigners();
// get the compound controller -> comptroller!
const comptroller = ComptrollerInterface__factory.connect(comptrollerAddr, wallet);
// get the cerc20 token for USDC
const cUSDC = CTokenInterface__factory.connect(cUSDCAddr, wallet);
// get the cerc20 token for DAI
const cDAI = CTokenInterface__factory.connect(cDAIAddr, wallet);
// get the erc20 token for USDC
const USDC = ERC20__factory.connect(USDCAddr, wallet);
// get the erc20 token for DAI
const DAI = ERC20__factory.connect(DAIAddr, wallet);
// a whale is an account with a ton of tokens/ether
// we impersonate a whale on a local network to acquire those tokens
// we're sending some ether to cover the transfer fees
await wallet.sendTransaction({
value: parseEther("1"),
to: USDCWhaleAddr,
});
// impersonate the whale
await impersonate([USDCWhaleAddr]);
const USDCWhale = await ethers.getSigner(USDCWhaleAddr);
// originally we should have 0 USDC in our wallet
// after transfering it from whale to us
// we should have 10,000 USDC
await USDC.connect(USDCWhale).transfer(wallet.address, 10000);
return {
wallet,
cUSDC,
cDAI,
USDC,
DAI,
comptroller,
};
};