-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardhat.config.js
90 lines (72 loc) · 2.58 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
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-ethers");
require("dotenv").config();
const TBTCToken = require("@keep-network/tbtc/artifacts/TBTCToken.json");
// This task it for use with a forked version of *mainnet*
// It impersonates a wallet with a large TBTC stack on mainnet and uses that
// wallet to transfer TBTC to the local ETH Wallet to test the redemption
// process using tbtc.js
//
// this task should be run when there is a forked version of mainnet already
// running locally
//
// npx hardhat accounts --network localhost
task("accounts", "Get TBTC to test with", async () => {
// 1. SETUP
const sender = process.env.HARDHAT_IMPERSONATE_WALLET;
const receiver = process.env.ETH_WALLET_PUBLIC_KEY;
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [sender]
});
const signer = await ethers.provider.getSigner(sender);
const contract = new ethers.Contract(
TBTCToken.networks[1].address,
TBTCToken.abi,
signer
);
console.log(`Sender: ${sender}`);
console.log(`Receiver: ${receiver}`);
// 2. Transfer TBTC
const amount = ethers.utils.parseUnits("100", 18);
await contract.transfer(receiver, amount);
let finalBalance = await contract.balanceOf(receiver);
console.log(`\tReceived ${ethers.utils.formatUnits(amount, 18)} TBTC `);
console.log(`\tFinal balance: ${finalBalance} TBTC`);
// 3. Transfer ETH
let provider = new ethers.getDefaultProvider();
let senderEthBalance = await provider.getBalance(sender);
// balance is a BigNumber (in wei); format is as a sting (in ether)
console.log("Sender ETH Balance: " + ethers.utils.formatEther(senderEthBalance));
let transaction = {
to: receiver,
value: ethers.utils.parseEther("10")
};
// Send the transaction
await signer.sendTransaction(transaction);
let receiverEthBalance = await provider.getBalance(receiver);
// balance is a BigNumber (in wei); format is as a sting (in ether)
console.log("Receiver ETH Balance: " + ethers.utils.formatEther(receiverEthBalance));
// 4. Cleanup
await hre.network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [sender]
});
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.7.3",
networks: {
hardhat: {
chainId: parseInt(process.env.HARDHAT_CHAIN_ID),
forking: {
url: process.env.HARDHAT_URL,
blockNumber: parseInt(process.env.HARDHAT_BLOCK)
}
}
}
};