-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
94 lines (77 loc) · 2.46 KB
/
run.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
import * as dotenv from "dotenv";
import axios from "axios";
import { ethers } from "ethers";
import poolABI from "./abi/Pool.json" assert { type: "json" };
import dnftABI from "./abi/dNFT.json" assert { type: "json" };
dotenv.config();
const { TENDERLY_USER, TENDERLY_PROJECT, TENDERLY_ACCESS_KEY, INFURA } =
process.env;
const TENDERLY_FORK_API = `https://api.tenderly.co/api/v1/account/${TENDERLY_USER}/project/${TENDERLY_PROJECT}/fork`;
const opts = {
headers: {
"X-Access-Key": TENDERLY_ACCESS_KEY,
},
};
async function run() {
const gp = new ethers.providers.JsonRpcProvider(INFURA);
const blockNumber = await gp.getBlockNumber();
console.log(blockNumber);
const body = {
network_id: "5",
block_number: blockNumber,
};
let forkId;
await axios
.post(TENDERLY_FORK_API, body, opts)
.then((res) => {
console.log(
`Forked with fork ID ${res.data.simulation_fork.id}. Check the Dashboard!`
);
forkId = res.data.simulation_fork.id;
})
.catch((err) => console.error(err));
const forkRPC = `https://rpc.tenderly.co/fork/${forkId}`;
const provider = new ethers.providers.JsonRpcProvider(forkRPC);
const signer = provider.getSigner();
const params = [
["0xEd6715D2172BFd50C2DBF608615c2AB497904803"],
ethers.utils.hexValue(100), // hex encoded wei amount
];
await provider.send("tenderly_addBalance", params);
const pool = new ethers.Contract(
"0x67488Df72673d85c42a83e5ECAdBBEeA16C01A22",
poolABI["abi"],
signer
);
const dnft = new ethers.Contract(
"0x93c23f661F11E5cF62791294E03ee353AD1009a3",
dnftABI["abi"],
signer
);
const unsignedTx = await pool.populateTransaction.sync();
const transactionParameters = [
{
to: pool.address,
from: "0xEd6715D2172BFd50C2DBF608615c2AB497904803",
data: unsignedTx.data,
gas: ethers.utils.hexValue(3000000),
gasPrice: ethers.utils.hexValue(1),
value: ethers.utils.hexValue(0),
},
];
const id = 8;
let res = await dnft.idToNft(id);
console.log(res);
const txHash = await provider.send(
"eth_sendTransaction",
transactionParameters
);
console.log(txHash);
res = await pool.lastEthPrice();
console.log(parseInt(res._hex));
res = await dnft.idToNft(id);
console.log(res);
const TENDERLY_FORK_ACCESS_URL = `https://api.tenderly.co/api/v1/account/${TENDERLY_USER}/project/${TENDERLY_PROJECT}/fork/${forkId}`;
await axios.delete(TENDERLY_FORK_ACCESS_URL, opts);
}
run();