@@ -5,6 +5,7 @@ const { unwrapUniswapLPs, unwrapCrv } = require("../helper/unwrapLPs");
5
5
const { getChainTransform } = require ( "../helper/portedTokens" ) ;
6
6
const { toUSDT, usdtAddress } = require ( "../helper/balances" ) ;
7
7
const { staking } = require ( "../helper/staking" ) ;
8
+ const { GraphQLClient, gql } = require ( "graphql-request" ) ;
8
9
9
10
const excluded = [ "pbamm" , "pickle-eth" , "sushi-pickle-eth" ] ;
10
11
const jars_url =
@@ -14,6 +15,59 @@ const jars_url =
14
15
const dillAddress = "0xbBCf169eE191A1Ba7371F30A1C344bFC498b29Cf" ;
15
16
const pickleAddress = "0x429881672B9AE42b8EbA0E26cD9C73711b891Ca5" ;
16
17
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
+
17
71
function chainTvl ( chain ) {
18
72
return async ( _timestamp , _ethBlock , chainBlocks ) => {
19
73
const block = chainBlocks [ chain ] ;
@@ -100,13 +154,68 @@ function chainTvl(chain) {
100
154
} ;
101
155
}
102
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
+ } ) ;
205
+ }
206
+ return balances ;
207
+ } ;
208
+ }
209
+
103
210
module . exports = {
104
211
arbitrum : {
105
212
tvl : chainTvl ( "arbitrum" ) ,
213
+ pool2 : chainPool2 ( "arbitrum" ) ,
106
214
} ,
107
215
ethereum : {
108
216
tvl : chainTvl ( "ethereum" ) ,
109
217
staking : staking ( dillAddress , pickleAddress ) ,
218
+ pool2 : chainPool2 ( "ethereum" ) ,
110
219
} ,
111
220
polygon : {
112
221
tvl : chainTvl ( "polygon" ) ,
0 commit comments