|
1 |
| -const sdk = require("@defillama/sdk"); |
2 |
| -const abi = require("./abi.json"); |
3 |
| -const utils = require("../helper/utils"); |
4 |
| -const { unwrapUniswapLPs, unwrapCrv } = require("../helper/unwrapLPs"); |
5 |
| -const { getChainTransform } = require("../helper/portedTokens"); |
6 | 1 | const { toUSDT, usdtAddress } = require("../helper/balances");
|
7 |
| -const { staking } = require("../helper/staking"); |
8 |
| -const { GraphQLClient, gql } = require("graphql-request"); |
| 2 | +const axios = require("axios"); |
9 | 3 |
|
10 |
| -const excluded = ["pbamm", "pickle-eth", "sushi-pickle-eth"]; |
11 |
| -const jars_url = |
12 |
| - "https://stkpowy01i.execute-api.us-west-1.amazonaws.com/prod/protocol/pools"; |
13 |
| - |
14 |
| -// Contracts |
15 |
| -const dillAddress = "0xbBCf169eE191A1Ba7371F30A1C344bFC498b29Cf"; |
| 4 | +const pfcore = "https://api.pickle.finance/prod/protocol/pfcore/"; |
16 | 5 | const pickleAddress = "0x429881672B9AE42b8EbA0E26cD9C73711b891Ca5";
|
17 | 6 |
|
18 |
| -const pool2s = [ |
19 |
| - { |
20 |
| - contract: "0xfAA267C3Bb25a82CFDB604136a29895D30fd3fd8", // Gauge |
21 |
| - lpToken: "0xdc98556Ce24f007A5eF6dC1CE96322d65832A819", // Uni Pickle-Eth |
22 |
| - chain: "ethereum", |
23 |
| - }, |
24 |
| - { |
25 |
| - contract: "0xbD17B1ce622d73bD438b9E658acA5996dc394b0d", // Masterchef |
26 |
| - lpToken: "0xdc98556Ce24f007A5eF6dC1CE96322d65832A819", // Uni Pickle-Eth |
27 |
| - chain: "ethereum", |
28 |
| - }, |
29 |
| - { |
30 |
| - contract: "0xEF0881eC094552b2e128Cf945EF17a6752B4Ec5d", // Sushi MC2 |
31 |
| - lpToken: "0x269Db91Fc3c7fCC275C2E6f22e5552504512811c", // Sushi Pickle-Eth |
32 |
| - chain: "ethereum", |
33 |
| - }, |
34 |
| - { |
35 |
| - contract: "0xBA12222222228d8Ba445958a75a0704d566BF2C8", // Balancer Vault |
36 |
| - lpToken: "0xc2f082d33b5b8ef3a7e3de30da54efd3114512ac", // Balancer Pickle-Eth |
37 |
| - chain: "arbitrum", |
38 |
| - }, |
39 |
| -]; |
40 |
| - |
41 |
| -async function getBalancerPoolLiquidity(poolAddress, block) { |
42 |
| - // delayed by around 5 mins to allow subgraph to update |
43 |
| - block -= 25; |
44 |
| - var endpoint = `https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-arbitrum-v2`; |
45 |
| - var graphQLClient = new GraphQLClient(endpoint); |
46 |
| - var query = gql`{ |
47 |
| - pools( |
48 |
| - first: 1, |
49 |
| - skip: 0, |
50 |
| - block: {number: ${block}}, |
51 |
| - where: {address_in: ["${poolAddress}"]} |
52 |
| - ) { |
53 |
| - address, |
54 |
| - totalLiquidity |
55 |
| - } |
56 |
| - } |
57 |
| - `; |
58 |
| - |
59 |
| - const results = await graphQLClient.request(query, { |
60 |
| - block, |
61 |
| - }); |
62 |
| - |
63 |
| - const result = results.pools[0]; |
64 |
| - const filtered = { |
65 |
| - address: result.address, |
66 |
| - totalLiquidity: result.totalLiquidity, |
67 |
| - }; |
68 |
| - return filtered; |
69 |
| -} |
70 |
| - |
71 |
| -function chainTvl(chain) { |
| 7 | +function fetch(chain, type) { |
72 | 8 | return async (_timestamp, _ethBlock, chainBlocks) => {
|
73 |
| - const block = chainBlocks[chain]; |
74 |
| - const transformAddress = await getChainTransform(chain); |
75 |
| - const balances = {}; |
76 |
| - |
77 |
| - let jars = (await utils.fetchURL(jars_url)).data |
78 |
| - .map((jar) => { |
79 |
| - if (jar.network === (chain === "ethereum" ? "eth" : chain)) |
80 |
| - return { |
81 |
| - ...jar, |
82 |
| - name: jar.identifier, |
83 |
| - }; |
84 |
| - }) |
85 |
| - .filter((x) => x && !excluded.includes(x.name)); |
| 9 | + const response = (await axios.get(pfcore))?.data; |
86 | 10 |
|
87 |
| - const jar_balances = ( |
88 |
| - await sdk.api.abi.multiCall({ |
89 |
| - block, |
90 |
| - calls: jars.map((jar) => ({ |
91 |
| - target: jar.jarAddress, |
92 |
| - })), |
93 |
| - abi: abi.balance, |
94 |
| - chain, |
95 |
| - }) |
96 |
| - ).output.map((val) => val.output); |
| 11 | + chain = chain === "ethereum" ? "eth" : chain; |
97 | 12 |
|
98 |
| - const lpPositions = []; |
| 13 | + let tvl = 0; |
| 14 | + let pool2 = 0; |
99 | 15 |
|
100 |
| - await Promise.all( |
101 |
| - jars.map(async (jar, idx) => { |
102 |
| - if ( |
103 |
| - ((jar.name.includes("crv") || jar.name === "dodohndeth") && |
104 |
| - chain === "arbitrum") || |
105 |
| - jar.name === "rbn-eth" |
106 |
| - ) { |
107 |
| - sdk.util.sumSingleBalance( |
108 |
| - balances, |
109 |
| - usdtAddress, |
110 |
| - toUSDT(jar.liquidity_locked) |
111 |
| - ); |
112 |
| - } else if ( |
113 |
| - jar.name.toLowerCase().includes("crv") && |
114 |
| - jar.name != "yvecrv-eth" |
115 |
| - ) { |
116 |
| - await unwrapCrv( |
117 |
| - balances, |
118 |
| - jar.tokenAddress, |
119 |
| - jar_balances[idx], |
120 |
| - block, |
121 |
| - chain, |
122 |
| - transformAddress |
123 |
| - ); |
124 |
| - } else if (jar.name.includes("-") || jar.name.includes("lp")) { |
125 |
| - lpPositions.push({ |
126 |
| - balance: jar_balances[idx], |
127 |
| - token: jar.tokenAddress, |
128 |
| - }); |
129 |
| - } else if (jar.name === "aleth") { |
130 |
| - sdk.util.sumSingleBalance( |
131 |
| - // sum as weth |
132 |
| - balances, |
133 |
| - "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", |
134 |
| - jar_balances[idx] |
135 |
| - ); |
136 |
| - } else { |
137 |
| - sdk.util.sumSingleBalance( |
138 |
| - balances, |
139 |
| - transformAddress(jar.tokenAddress), |
140 |
| - jar_balances[idx] |
141 |
| - ); |
| 16 | + Object.keys(response.assets).forEach((assetsType) => { |
| 17 | + response.assets[assetsType].forEach((asset) => { |
| 18 | + if (asset.chain === chain) { |
| 19 | + if (asset.tags && asset.tags.includes("pool2")) { |
| 20 | + pool2 += asset.details.harvestStats.balanceUSD; |
| 21 | + } else { |
| 22 | + tvl += asset.details.harvestStats?.balanceUSD ?? 0; |
| 23 | + } |
142 | 24 | }
|
143 |
| - }) |
144 |
| - ); |
145 |
| - await unwrapUniswapLPs( |
146 |
| - balances, |
147 |
| - lpPositions, |
148 |
| - block, |
149 |
| - chain, |
150 |
| - transformAddress |
151 |
| - ); |
152 |
| - |
153 |
| - return balances; |
154 |
| - }; |
155 |
| -} |
156 |
| - |
157 |
| -function chainPool2(chain) { |
158 |
| - return async (_timestamp, _ethBlock, chainBlocks) => { |
159 |
| - const block = chainBlocks[chain]; |
160 |
| - const transformAddress = await getChainTransform(chain); |
161 |
| - const balances = {}; |
162 |
| - |
163 |
| - const chainPool2s = pool2s.filter((pool) => pool.chain === chain); |
164 |
| - |
165 |
| - if (chain === "ethereum") { |
166 |
| - const pool2Balances = await Promise.all( |
167 |
| - chainPool2s.map(async (pool) => { |
168 |
| - return ( |
169 |
| - await sdk.api.erc20.balanceOf({ |
170 |
| - target: pool.lpToken, |
171 |
| - owner: pool.contract, |
172 |
| - }) |
173 |
| - ).output; |
174 |
| - }) |
175 |
| - ); |
176 |
| - |
177 |
| - const lpPositions = chainPool2s.map((pool, idx) => { |
178 |
| - return { |
179 |
| - balance: pool2Balances[idx], |
180 |
| - token: pool.lpToken, |
181 |
| - }; |
182 |
| - }); |
183 |
| - |
184 |
| - await unwrapUniswapLPs( |
185 |
| - balances, |
186 |
| - lpPositions, |
187 |
| - block, |
188 |
| - chain, |
189 |
| - transformAddress |
190 |
| - ); |
191 |
| - } else if (chain === "arbitrum") { |
192 |
| - const pool2Balances = await Promise.all( |
193 |
| - chainPool2s.map(async (pool) => { |
194 |
| - return await getBalancerPoolLiquidity(pool.lpToken, block); |
195 |
| - }) |
196 |
| - ); |
197 |
| - |
198 |
| - pool2Balances.forEach((pool) => { |
199 |
| - sdk.util.sumSingleBalance( |
200 |
| - balances, |
201 |
| - usdtAddress, |
202 |
| - toUSDT(pool.totalLiquidity) |
203 |
| - ); |
204 | 25 | });
|
| 26 | + }); |
| 27 | + |
| 28 | + let result = {}; |
| 29 | + |
| 30 | + switch (type) { |
| 31 | + case "tvl": |
| 32 | + result = { [usdtAddress]: toUSDT(tvl) }; |
| 33 | + break; |
| 34 | + case "pool2": |
| 35 | + result = { [usdtAddress]: toUSDT(pool2) }; |
| 36 | + break; |
| 37 | + case "staking": |
| 38 | + const picklesLocked = response.dill.pickleLocked; |
| 39 | + result = { [pickleAddress]: picklesLocked * 1e18 }; |
| 40 | + break; |
205 | 41 | }
|
206 |
| - return balances; |
| 42 | + |
| 43 | + return result; |
207 | 44 | };
|
208 | 45 | }
|
209 | 46 |
|
210 | 47 | module.exports = {
|
211 |
| - arbitrum: { |
212 |
| - tvl: chainTvl("arbitrum"), |
213 |
| - pool2: chainPool2("arbitrum"), |
214 |
| - }, |
215 | 48 | ethereum: {
|
216 |
| - tvl: chainTvl("ethereum"), |
217 |
| - staking: staking(dillAddress, pickleAddress), |
218 |
| - pool2: chainPool2("ethereum"), |
| 49 | + tvl: fetch("ethereum", "tvl"), |
| 50 | + pool2: fetch("ethereum", "pool2"), |
| 51 | + staking: fetch("ethereum", "staking"), |
219 | 52 | },
|
220 | 53 | polygon: {
|
221 |
| - tvl: chainTvl("polygon"), |
| 54 | + tvl: fetch("polygon", "tvl"), |
| 55 | + pool2: fetch("polygon", "pool2"), |
| 56 | + }, |
| 57 | + arbitrum: { |
| 58 | + tvl: fetch("arbitrum", "tvl"), |
| 59 | + pool2: fetch("arbitrum", "pool2"), |
| 60 | + }, |
| 61 | + moonriver: { |
| 62 | + tvl: fetch("moonriver", "tvl"), |
| 63 | + }, |
| 64 | + harmony: { |
| 65 | + tvl: fetch("harmony", "tvl"), |
| 66 | + }, |
| 67 | + okexchain: { |
| 68 | + tvl: fetch("okex", "tvl"), |
| 69 | + }, |
| 70 | + cronos: { |
| 71 | + tvl: fetch("cronos", "tvl"), |
| 72 | + }, |
| 73 | + aurora: { |
| 74 | + tvl: fetch("aurora", "tvl"), |
222 | 75 | },
|
223 | 76 | };
|
0 commit comments