forked from yuichiroaoki/poly-flash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.ts
50 lines (42 loc) · 1.2 KB
/
token.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
import { network, ethers } from "hardhat";
import { Contract } from "ethers";
export const getErc20Balance = async (
contract: Contract,
address: string,
name: string,
decimals: number
) => {
const [balance] = await Promise.all([contract.balanceOf(address)]);
console.log(name, ethers.utils.formatUnits(balance, decimals));
};
export const fundErc20 = async (
contract: Contract,
sender: string,
recepient: string,
amount: string,
decimals: number
) => {
const FUND_AMOUNT = ethers.utils.parseUnits(amount, decimals);
// fund erc20 token to the contract
const MrWhale = await ethers.getSigner(sender);
const contractSigner = contract.connect(MrWhale);
await contractSigner.transfer(recepient, FUND_AMOUNT);
};
export const impersonateFundErc20 = async (
contract: Contract,
sender: string,
recepient: string,
amount: string,
decimals: number = 18
) => {
await network.provider.request({
method: "hardhat_impersonateAccount",
params: [sender],
});
// fund baseToken to the contract
await fundErc20(contract, sender, recepient, amount, decimals);
await network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [sender],
});
};