-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
152 lines (146 loc) · 4.15 KB
/
index.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const { ethers } = require("ethers");
// Set contract address ABI
const contractABI_myContract = [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "getReservesFromPools",
"outputs": [
{
"internalType": "uint256",
"name": "reserve0_pool1",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "reserve1_pool1",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "reserve0_pool2",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "reserve1_pool2",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "reserve0_pool3",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "reserve1_pool3",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "reserve0_pool4",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "reserve1_pool4",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "pool1",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "pool2",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "pool3",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "pool4",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
];
async function get() {
// Connect to zkSync network using ethers.js
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.era.zksync.io');
// Set contract addresses
const contractAddress_myContract = "0x0A3697050A8030db921b402A09d8aE64e22316b0"; // That my contract address
// Create contract instances
const myContractInstance = new ethers.Contract(contractAddress_myContract, contractABI_myContract, provider);
// Interacting with the getReservesFromPools() function
const reserves_Pools = await myContractInstance.getReservesFromPools();
console.log("---------------Pool Info---------------------");
console.log("Pool_1 total USDC reserves :",reserves_Pools.reserve0_pool1.toString() / 1e6);
console.log("Pool_1 total ETH reserves :",reserves_Pools.reserve1_pool1.toString() / 1e18);
console.log("Pool_1 total USDC reserves :",reserves_Pools.reserve0_pool2.toString() / 1e6);
console.log("Pool_2 total ETH reserves :",reserves_Pools.reserve1_pool2.toString() / 1e18);
console.log("Pool_1 total USDC reserves :",reserves_Pools.reserve0_pool3.toString() / 1e6);
console.log("Pool_3 total ETH reserves :",reserves_Pools.reserve1_pool3.toString() / 1e18);
console.log("Pool_1 total USDC reserves :",reserves_Pools.reserve0_pool4.toString() / 1e6);
console.log("Pool_4 total ETH reserves :",reserves_Pools.reserve1_pool4.toString() / 1e18);
const pool1_reserve0 = reserves_Pools.reserve0_pool1 / 1e6;
const pool1_reserve1 = reserves_Pools.reserve1_pool1 / 1e18;
const pool2_reserve0 = reserves_Pools.reserve0_pool2 / 1e6;
const pool2_reserve1 = reserves_Pools.reserve1_pool2 / 1e18;
const pool3_reserve0 = reserves_Pools.reserve0_pool3 / 1e6;
const pool3_reserve1 = reserves_Pools.reserve1_pool3 / 1e18;
const pool4_reserve0 = reserves_Pools.reserve0_pool4 / 1e6;
const pool4_reserve1 = reserves_Pools.reserve1_pool4 / 1e18;
const pool1_calculate = pool1_reserve0 / pool1_reserve1 ;
const pool2_calculate = pool2_reserve0 / pool2_reserve1 ;
const pool3_calculate = pool3_reserve0 / pool3_reserve1 ;
const pool4_calculate = pool4_reserve0 / pool4_reserve1 ;
console.log("---------------Pricies---------------------");
console.log("Pool_1 WETH price :",pool1_calculate);
console.log("Pool_2 WETH price :",pool2_calculate);
console.log("Pool_3 WETH price :",pool3_calculate);
console.log("Pool_4 WETH price :",pool4_calculate);
}
get()