@pioneer-platform/zapper-client 8.11.0 → 8.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/LINK_INVESTIGATION_REPORT.md +164 -0
- package/ZAPPER_API_FINDINGS.md +246 -0
- package/docs/zapper-graql.md +5512 -0
- package/docs/zapper_api.md +1514 -0
- package/lib/index.d.ts +30 -1
- package/lib/index.js +259 -266
- package/package.json +2 -2
- package/lib/index.js.map +0 -75
package/lib/index.js
CHANGED
|
@@ -3,17 +3,6 @@
|
|
|
3
3
|
https://docs.blocknative.com/webhook-api
|
|
4
4
|
|
|
5
5
|
*/
|
|
6
|
-
var __assign = (this && this.__assign) || function () {
|
|
7
|
-
__assign = Object.assign || function(t) {
|
|
8
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
-
s = arguments[i];
|
|
10
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
-
t[p] = s[p];
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
};
|
|
15
|
-
return __assign.apply(this, arguments);
|
|
16
|
-
};
|
|
17
6
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
7
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
8
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -50,11 +39,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
50
39
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
40
|
}
|
|
52
41
|
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
42
|
var TAG = " | zapper | ";
|
|
55
43
|
var log = require('@pioneer-platform/loggerdog')();
|
|
56
44
|
//@ts-ignore
|
|
57
|
-
var
|
|
45
|
+
var evmCaips = require('@pioneer-platform/pioneer-caip').evmCaips;
|
|
58
46
|
var axiosLib = require('axios');
|
|
59
47
|
var Axios = axiosLib.default || axiosLib;
|
|
60
48
|
var https = require('https');
|
|
@@ -62,9 +50,9 @@ var API_KEY = process.env['ZAPPER_API_KEY'];
|
|
|
62
50
|
if (!API_KEY)
|
|
63
51
|
throw Error("api key required! set env ZAPPER_API_KEY");
|
|
64
52
|
var axios = Axios.create();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var
|
|
53
|
+
// IMPORTANT: Zapper GraphQL API uses x-zapper-api-key header, not Authorization
|
|
54
|
+
var GRAPHQL_URL = "https://public.zapper.xyz/graphql";
|
|
55
|
+
var REST_URL = "https://api.zapper.xyz";
|
|
68
56
|
// Removed axios-retry - using basic axios
|
|
69
57
|
/**
|
|
70
58
|
* Validates if a CAIP is correctly formatted for the given token
|
|
@@ -193,131 +181,178 @@ module.exports = {
|
|
|
193
181
|
};
|
|
194
182
|
var get_portfolio = function (address) {
|
|
195
183
|
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
-
var tag, output_1, appsResponse, apps,
|
|
197
|
-
var
|
|
198
|
-
|
|
199
|
-
|
|
184
|
+
var tag, output_1, appsGraphqlQuery, appsResponse, appsData, totalBalanceUSDApp, apps, _i, apps_1, appEdge, appNode, networkName, networkId, positions, _a, positions_1, posEdge, position, balance, tokenForCaip, tokens, _b, tokens_1, tokenWithMeta, token, balance, tokenForCaip, graphqlQuery, tokensResponse, totalBalanceUsdTokens_1, tokenData, tokens, nftGraphqlQuery, nftResponse, nftData, nftUsdNetWorth, allTokens, totalNetWorth, e_1;
|
|
185
|
+
var _c;
|
|
186
|
+
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
|
|
187
|
+
return __generator(this, function (_10) {
|
|
188
|
+
switch (_10.label) {
|
|
200
189
|
case 0:
|
|
201
190
|
tag = TAG + " | get_portfolio | ";
|
|
202
|
-
|
|
191
|
+
_10.label = 1;
|
|
203
192
|
case 1:
|
|
204
|
-
|
|
193
|
+
_10.trys.push([1, 5, , 6]);
|
|
205
194
|
output_1 = {
|
|
206
195
|
balances: []
|
|
207
196
|
};
|
|
208
|
-
|
|
197
|
+
appsGraphqlQuery = {
|
|
198
|
+
query: "\n query AppBalances($addresses: [Address!]!) {\n portfolioV2(addresses: $addresses) {\n appBalances {\n totalBalanceUSD\n byApp(first: 100) {\n edges {\n node {\n balanceUSD\n app {\n id\n slug\n displayName\n }\n network {\n name\n chainId\n }\n positionBalances(first: 100) {\n edges {\n node {\n ... on AppTokenPositionBalance {\n type\n address\n symbol\n balance\n balanceUSD\n price\n appId\n groupId\n displayProps {\n label\n images\n }\n tokens {\n ... on BaseTokenPositionBalance {\n address\n balance\n balanceUSD\n price\n symbol\n }\n }\n }\n ... on ContractPositionBalance {\n type\n address\n balanceUSD\n appId\n groupId\n displayProps {\n label\n images\n }\n tokens {\n metaType\n token {\n ... on BaseTokenPositionBalance {\n address\n balance\n balanceUSD\n price\n symbol\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n ",
|
|
199
|
+
variables: {
|
|
200
|
+
addresses: [address]
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
return [4 /*yield*/, Axios.post(GRAPHQL_URL, appsGraphqlQuery, {
|
|
209
204
|
headers: {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
205
|
+
'Content-Type': 'application/json',
|
|
206
|
+
'x-zapper-api-key': API_KEY,
|
|
207
|
+
}
|
|
213
208
|
})];
|
|
214
209
|
case 2:
|
|
215
|
-
appsResponse =
|
|
216
|
-
log.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
apps
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
log.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
210
|
+
appsResponse = _10.sent();
|
|
211
|
+
log.debug(tag, "GraphQL apps response:", appsResponse.data);
|
|
212
|
+
appsData = (_f = (_e = (_d = appsResponse.data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.portfolioV2) === null || _f === void 0 ? void 0 : _f.appBalances;
|
|
213
|
+
totalBalanceUSDApp = (appsData === null || appsData === void 0 ? void 0 : appsData.totalBalanceUSD) || 0;
|
|
214
|
+
apps = ((_g = appsData === null || appsData === void 0 ? void 0 : appsData.byApp) === null || _g === void 0 ? void 0 : _g.edges) || [];
|
|
215
|
+
for (_i = 0, apps_1 = apps; _i < apps_1.length; _i++) {
|
|
216
|
+
appEdge = apps_1[_i];
|
|
217
|
+
appNode = appEdge.node;
|
|
218
|
+
networkName = appNode.network.name.toLowerCase().replace(' ', '-');
|
|
219
|
+
networkId = ((_h = evmCaips[networkName]) === null || _h === void 0 ? void 0 : _h.split('/')[0]) || ((_j = evmCaips[appNode.network.name.toLowerCase()]) === null || _j === void 0 ? void 0 : _j.split('/')[0]);
|
|
220
|
+
if (!networkId) {
|
|
221
|
+
log.warn(tag, "No CAIP found for network: ".concat(networkName));
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
positions = ((_k = appNode.positionBalances) === null || _k === void 0 ? void 0 : _k.edges) || [];
|
|
225
|
+
for (_a = 0, positions_1 = positions; _a < positions_1.length; _a++) {
|
|
226
|
+
posEdge = positions_1[_a];
|
|
227
|
+
position = posEdge.node;
|
|
228
|
+
if (position.type === 'app-token') {
|
|
229
|
+
balance = {};
|
|
230
|
+
balance.pubkey = address;
|
|
231
|
+
balance.balance = ((_l = position.balance) === null || _l === void 0 ? void 0 : _l.toString()) || '0';
|
|
232
|
+
balance.chain = networkName;
|
|
233
|
+
balance.networkId = networkId;
|
|
234
|
+
balance.symbol = position.symbol;
|
|
235
|
+
balance.ticker = position.symbol;
|
|
236
|
+
balance.name = ((_m = position.displayProps) === null || _m === void 0 ? void 0 : _m.label) || position.symbol;
|
|
237
|
+
balance.appId = position.appId;
|
|
238
|
+
balance.groupId = position.groupId;
|
|
239
|
+
balance.icon = ((_p = (_o = position.displayProps) === null || _o === void 0 ? void 0 : _o.images) === null || _p === void 0 ? void 0 : _p[0]) || '';
|
|
240
|
+
balance.display = ((_q = position.displayProps) === null || _q === void 0 ? void 0 : _q.images) || [];
|
|
241
|
+
balance.priceUsd = ((_r = position.price) === null || _r === void 0 ? void 0 : _r.toString()) || '0';
|
|
242
|
+
balance.valueUsd = ((_s = position.balanceUSD) === null || _s === void 0 ? void 0 : _s.toString()) || '0';
|
|
243
|
+
balance.tokenAddress = position.address;
|
|
244
|
+
balance.tokenType = 'app-token';
|
|
245
|
+
tokenForCaip = {
|
|
246
|
+
address: position.address,
|
|
247
|
+
symbol: position.symbol,
|
|
248
|
+
type: 'app-token'
|
|
249
|
+
};
|
|
250
|
+
balance.caip = assignCorrectCaip(networkId, tokenForCaip, networkName);
|
|
251
|
+
output_1.balances.push(balance);
|
|
252
|
+
}
|
|
253
|
+
else if (position.type === 'contract-position') {
|
|
254
|
+
tokens = position.tokens || [];
|
|
255
|
+
for (_b = 0, tokens_1 = tokens; _b < tokens_1.length; _b++) {
|
|
256
|
+
tokenWithMeta = tokens_1[_b];
|
|
257
|
+
token = tokenWithMeta.token;
|
|
258
|
+
if (token && token.balanceUSD > 0) {
|
|
259
|
+
balance = {};
|
|
260
|
+
balance.pubkey = address;
|
|
261
|
+
balance.balance = ((_t = token.balance) === null || _t === void 0 ? void 0 : _t.toString()) || '0';
|
|
262
|
+
balance.chain = networkName;
|
|
263
|
+
balance.networkId = networkId;
|
|
264
|
+
balance.symbol = token.symbol;
|
|
265
|
+
balance.ticker = token.symbol;
|
|
266
|
+
balance.name = ((_u = position.displayProps) === null || _u === void 0 ? void 0 : _u.label) || token.symbol;
|
|
267
|
+
balance.appId = position.appId;
|
|
268
|
+
balance.groupId = position.groupId;
|
|
269
|
+
balance.icon = ((_w = (_v = position.displayProps) === null || _v === void 0 ? void 0 : _v.images) === null || _w === void 0 ? void 0 : _w[0]) || '';
|
|
270
|
+
balance.display = ((_x = position.displayProps) === null || _x === void 0 ? void 0 : _x.images) || [];
|
|
271
|
+
balance.priceUsd = ((_y = token.price) === null || _y === void 0 ? void 0 : _y.toString()) || '0';
|
|
272
|
+
balance.valueUsd = ((_z = token.balanceUSD) === null || _z === void 0 ? void 0 : _z.toString()) || '0';
|
|
273
|
+
balance.tokenAddress = token.address;
|
|
274
|
+
balance.tokenType = 'contract-position';
|
|
275
|
+
balance.metaType = tokenWithMeta.metaType;
|
|
276
|
+
tokenForCaip = {
|
|
277
|
+
address: token.address,
|
|
278
|
+
symbol: token.symbol
|
|
279
|
+
};
|
|
280
|
+
balance.caip = assignCorrectCaip(networkId, tokenForCaip, networkName);
|
|
281
|
+
output_1.balances.push(balance);
|
|
242
282
|
}
|
|
243
|
-
// Assign correct CAIP based on token properties
|
|
244
|
-
balance.caip = assignCorrectCaip(balance.networkId, tokenForCaip, app.network);
|
|
245
|
-
// Log CAIP assignment for debugging
|
|
246
|
-
log.debug(tag, "CAIP assigned for ".concat(asset.symbol || token.symbol, ": ").concat(balance.caip), {
|
|
247
|
-
assetAddress: asset.address,
|
|
248
|
-
tokenAddress: token.address,
|
|
249
|
-
assetType: asset.type,
|
|
250
|
-
tokenType: token.type,
|
|
251
|
-
network: app.network
|
|
252
|
-
});
|
|
253
|
-
balance.metaType = token.metaType || product.metaType;
|
|
254
|
-
balance.name = asset.displayProps.label;
|
|
255
|
-
balance.appId = app.appId;
|
|
256
|
-
balance.icon = asset.displayProps.images[0];
|
|
257
|
-
balance.display = asset.displayProps.images;
|
|
258
|
-
balance.groupId = asset.groupId;
|
|
259
|
-
balance.symbol = asset.symbol || token.symbol; // Use asset symbol if available
|
|
260
|
-
balance.ticker = asset.symbol || token.symbol; // Use asset symbol if available
|
|
261
|
-
balance.priceUsd = ((_a = asset.price) === null || _a === void 0 ? void 0 : _a.toString()) || ((_b = token === null || token === void 0 ? void 0 : token.price) === null || _b === void 0 ? void 0 : _b.toString()) || '0'; // Use asset price if available
|
|
262
|
-
balance.valueUsd = ((_c = asset.balanceUSD) === null || _c === void 0 ? void 0 : _c.toString()) || ((_d = token === null || token === void 0 ? void 0 : token.balanceUSD) === null || _d === void 0 ? void 0 : _d.toString()) || '0'; // Use asset value if available
|
|
263
|
-
// Add additional fields for debugging
|
|
264
|
-
balance.tokenAddress = asset.address || token.address;
|
|
265
|
-
balance.tokenType = asset.type || token.type;
|
|
266
|
-
output_1.balances.push(balance);
|
|
267
283
|
}
|
|
268
284
|
}
|
|
269
285
|
}
|
|
270
286
|
}
|
|
271
|
-
|
|
287
|
+
graphqlQuery = {
|
|
288
|
+
query: "\n query TokenBalances($addresses: [Address!]!) {\n portfolioV2(addresses: $addresses) {\n tokenBalances {\n totalBalanceUSD\n byToken(first: 100, filters: { includeTokensWithMissingPrices: true }) {\n edges {\n node {\n symbol\n tokenAddress\n balance\n balanceUSD\n price\n name\n decimals\n network {\n name\n chainId\n }\n }\n }\n }\n }\n }\n }\n ",
|
|
289
|
+
variables: {
|
|
290
|
+
addresses: [address]
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
return [4 /*yield*/, Axios.post(GRAPHQL_URL, graphqlQuery, {
|
|
272
294
|
headers: {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
295
|
+
'Content-Type': 'application/json',
|
|
296
|
+
'x-zapper-api-key': API_KEY,
|
|
297
|
+
}
|
|
276
298
|
})];
|
|
277
299
|
case 3:
|
|
278
|
-
tokensResponse =
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
tokens =
|
|
284
|
-
output_1.tokens = tokens;
|
|
300
|
+
tokensResponse = _10.sent();
|
|
301
|
+
log.debug(tag, "GraphQL tokens response:", tokensResponse.data);
|
|
302
|
+
totalBalanceUsdTokens_1 = 0;
|
|
303
|
+
if ((_2 = (_1 = (_0 = tokensResponse.data) === null || _0 === void 0 ? void 0 : _0.data) === null || _1 === void 0 ? void 0 : _1.portfolioV2) === null || _2 === void 0 ? void 0 : _2.tokenBalances) {
|
|
304
|
+
tokenData = tokensResponse.data.data.portfolioV2.tokenBalances;
|
|
305
|
+
tokens = ((_3 = tokenData.byToken) === null || _3 === void 0 ? void 0 : _3.edges) || [];
|
|
306
|
+
output_1.tokens = tokens.map(function (edge) { return edge.node; });
|
|
285
307
|
log.info(tag, "tokens: ", tokens.length);
|
|
286
|
-
if (tokens) {
|
|
287
|
-
tokens.forEach(function (
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
var
|
|
308
|
+
if (tokens.length > 0) {
|
|
309
|
+
tokens.forEach(function (edge) {
|
|
310
|
+
var tokenNode = edge.node;
|
|
311
|
+
log.debug(tag, "token: ", tokenNode);
|
|
312
|
+
// Map Zapper network name to our network format
|
|
313
|
+
var networkName = tokenNode.network.name.toLowerCase().replace(' ', '-');
|
|
314
|
+
log.debug(tag, "network: ", networkName);
|
|
315
|
+
// Try to find matching CAIP for this network
|
|
316
|
+
var caip = evmCaips[networkName] || evmCaips[tokenNode.network.name.toLowerCase()];
|
|
292
317
|
if (caip) {
|
|
293
|
-
|
|
318
|
+
var networkId = caip.split('/')[0];
|
|
319
|
+
// Create token object in expected format for CAIP assignment
|
|
320
|
+
var tokenForCaip = {
|
|
321
|
+
address: tokenNode.tokenAddress,
|
|
322
|
+
symbol: tokenNode.symbol,
|
|
323
|
+
name: tokenNode.name,
|
|
324
|
+
decimals: tokenNode.decimals,
|
|
325
|
+
balance: tokenNode.balance,
|
|
326
|
+
balanceUSD: tokenNode.balanceUSD,
|
|
327
|
+
price: tokenNode.price
|
|
328
|
+
};
|
|
294
329
|
// Assign correct CAIP based on token properties
|
|
295
|
-
|
|
330
|
+
var assetCaip = assignCorrectCaip(networkId, tokenForCaip, networkName);
|
|
296
331
|
var balance = {
|
|
297
|
-
balance:
|
|
298
|
-
networkId:
|
|
299
|
-
chain:
|
|
300
|
-
caip:
|
|
332
|
+
balance: tokenNode.balance.toString(),
|
|
333
|
+
networkId: networkId,
|
|
334
|
+
chain: networkName,
|
|
335
|
+
caip: assetCaip,
|
|
301
336
|
type: 'erc20',
|
|
302
|
-
name:
|
|
303
|
-
symbol:
|
|
304
|
-
ticker:
|
|
305
|
-
decimals:
|
|
306
|
-
priceUsd:
|
|
307
|
-
valueUsd:
|
|
308
|
-
tokenAddress:
|
|
337
|
+
name: tokenNode.name,
|
|
338
|
+
symbol: tokenNode.symbol,
|
|
339
|
+
ticker: tokenNode.symbol,
|
|
340
|
+
decimals: tokenNode.decimals,
|
|
341
|
+
priceUsd: tokenNode.price,
|
|
342
|
+
valueUsd: tokenNode.balanceUSD.toString(),
|
|
343
|
+
tokenAddress: tokenNode.tokenAddress,
|
|
309
344
|
};
|
|
310
345
|
// Log CAIP assignment for debugging
|
|
311
|
-
log.debug(tag, "CAIP assigned for ".concat(
|
|
312
|
-
address:
|
|
313
|
-
network:
|
|
346
|
+
log.debug(tag, "CAIP assigned for ".concat(tokenNode.symbol, ": ").concat(assetCaip), {
|
|
347
|
+
address: tokenNode.tokenAddress,
|
|
348
|
+
network: networkName
|
|
314
349
|
});
|
|
315
350
|
output_1.balances.push(balance);
|
|
316
|
-
log.debug(tag, "token.balanceUSD: ",
|
|
317
|
-
totalBalanceUsdTokens_1 +=
|
|
351
|
+
log.debug(tag, "token.balanceUSD: ", tokenNode.balanceUSD);
|
|
352
|
+
totalBalanceUsdTokens_1 += tokenNode.balanceUSD || 0;
|
|
318
353
|
}
|
|
319
354
|
else {
|
|
320
|
-
log.error(tag, "No caip found for network: ", network);
|
|
355
|
+
log.error(tag, "No caip found for network: ", networkName, tokenNode.network);
|
|
321
356
|
}
|
|
322
357
|
});
|
|
323
358
|
}
|
|
@@ -325,179 +360,123 @@ var get_portfolio = function (address) {
|
|
|
325
360
|
else {
|
|
326
361
|
totalBalanceUsdTokens_1 = 0;
|
|
327
362
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
case 5:
|
|
336
|
-
_e.trys.push([5, 7, , 8]);
|
|
337
|
-
url = "https://api.zapper.xyz/v2/nft/user/tokens?userAddress=".concat(address, "&limit=").concat(limit);
|
|
338
|
-
if (cursor) {
|
|
339
|
-
url += "&cursor=".concat(cursor);
|
|
340
|
-
}
|
|
341
|
-
return [4 /*yield*/, Axios.get(url, {
|
|
363
|
+
nftGraphqlQuery = {
|
|
364
|
+
query: "\n query NFTBalances($addresses: [Address!]!) {\n portfolioV2(addresses: $addresses) {\n nftBalances {\n totalBalanceUSD\n totalTokensOwned\n byToken(first: 100) {\n edges {\n node {\n token {\n tokenId\n name\n collection {\n address\n name\n network\n }\n estimatedValue {\n valueUsd\n }\n }\n }\n }\n }\n }\n }\n }\n ",
|
|
365
|
+
variables: {
|
|
366
|
+
addresses: [address]
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
return [4 /*yield*/, Axios.post(GRAPHQL_URL, nftGraphqlQuery, {
|
|
342
370
|
headers: {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
371
|
+
'Content-Type': 'application/json',
|
|
372
|
+
'x-zapper-api-key': API_KEY,
|
|
373
|
+
}
|
|
346
374
|
})];
|
|
347
|
-
case
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
allTokens =
|
|
352
|
-
cursor = response.data.cursor;
|
|
353
|
-
if (!cursor) {
|
|
354
|
-
return [3 /*break*/, 9];
|
|
355
|
-
}
|
|
356
|
-
return [3 /*break*/, 8];
|
|
357
|
-
case 7:
|
|
358
|
-
error_1 = _e.sent();
|
|
359
|
-
console.error(error_1);
|
|
360
|
-
return [3 /*break*/, 8];
|
|
361
|
-
case 8: return [3 /*break*/, 4];
|
|
362
|
-
case 9:
|
|
375
|
+
case 4:
|
|
376
|
+
nftResponse = _10.sent();
|
|
377
|
+
nftData = (_6 = (_5 = (_4 = nftResponse.data) === null || _4 === void 0 ? void 0 : _4.data) === null || _5 === void 0 ? void 0 : _5.portfolioV2) === null || _6 === void 0 ? void 0 : _6.nftBalances;
|
|
378
|
+
nftUsdNetWorth = (nftData === null || nftData === void 0 ? void 0 : nftData.totalBalanceUSD) || 0;
|
|
379
|
+
allTokens = ((_8 = (_7 = nftData === null || nftData === void 0 ? void 0 : nftData.byToken) === null || _7 === void 0 ? void 0 : _7.edges) === null || _8 === void 0 ? void 0 : _8.map(function (edge) { return edge.node.token; })) || [];
|
|
363
380
|
output_1.nfts = allTokens;
|
|
364
|
-
|
|
365
|
-
headers: {
|
|
366
|
-
accept: "*/*",
|
|
367
|
-
Authorization: Authorization,
|
|
368
|
-
},
|
|
369
|
-
})];
|
|
370
|
-
case 10:
|
|
371
|
-
nftResponse = _e.sent();
|
|
372
|
-
nftUsdNetWorth = nftResponse.data;
|
|
373
|
-
output_1.nftUsdNetWorth = nftUsdNetWorth;
|
|
381
|
+
output_1.nftUsdNetWorth = (_c = {}, _c[address.toLowerCase()] = nftUsdNetWorth.toString(), _c);
|
|
374
382
|
output_1.totalBalanceUsdTokens = totalBalanceUsdTokens_1;
|
|
375
|
-
output_1.totalBalanceUSDApp =
|
|
376
|
-
totalNetWorth =
|
|
383
|
+
output_1.totalBalanceUSDApp = totalBalanceUSDApp;
|
|
384
|
+
totalNetWorth = totalBalanceUSDApp + totalBalanceUsdTokens_1 + parseFloat(nftUsdNetWorth[address.toLowerCase()]);
|
|
377
385
|
//console.log("totalNetWorth: ",totalNetWorth);
|
|
378
386
|
output_1.totalNetWorth = totalNetWorth;
|
|
379
387
|
return [2 /*return*/, output_1];
|
|
380
|
-
case
|
|
381
|
-
e_1 =
|
|
382
|
-
console.error(tag, "
|
|
383
|
-
|
|
384
|
-
|
|
388
|
+
case 5:
|
|
389
|
+
e_1 = _10.sent();
|
|
390
|
+
console.error(tag, "CRITICAL: Zapper API call failed:", e_1);
|
|
391
|
+
console.error(tag, "Error details:", (_9 = e_1 === null || e_1 === void 0 ? void 0 : e_1.response) === null || _9 === void 0 ? void 0 : _9.status, e_1 === null || e_1 === void 0 ? void 0 : e_1.message);
|
|
392
|
+
// Return empty result instead of undefined/null
|
|
393
|
+
return [2 /*return*/, {
|
|
394
|
+
balances: [],
|
|
395
|
+
tokens: [],
|
|
396
|
+
nfts: [],
|
|
397
|
+
totalNetWorth: 0,
|
|
398
|
+
totalBalanceUsdTokens: 0,
|
|
399
|
+
totalBalanceUSDApp: 0,
|
|
400
|
+
nftUsdNetWorth: {}
|
|
401
|
+
}];
|
|
402
|
+
case 6: return [2 /*return*/];
|
|
385
403
|
}
|
|
386
404
|
});
|
|
387
405
|
});
|
|
388
406
|
};
|
|
389
407
|
var get_total_networth = function (address) {
|
|
390
408
|
return __awaiter(this, void 0, void 0, function () {
|
|
391
|
-
var tag,
|
|
392
|
-
|
|
393
|
-
|
|
409
|
+
var tag, graphqlQuery, portfolioResponse, portfolioData, totalBalanceUsdTokens, totalBalanceUSDApp, nftUsdNetWorth, totalNetWorth, e_2;
|
|
410
|
+
var _a, _b, _c, _d, _e;
|
|
411
|
+
return __generator(this, function (_f) {
|
|
412
|
+
switch (_f.label) {
|
|
394
413
|
case 0:
|
|
395
|
-
tag = TAG + " |
|
|
396
|
-
|
|
414
|
+
tag = TAG + " | get_total_networth | ";
|
|
415
|
+
_f.label = 1;
|
|
397
416
|
case 1:
|
|
398
|
-
|
|
399
|
-
|
|
417
|
+
_f.trys.push([1, 3, , 4]);
|
|
418
|
+
graphqlQuery = {
|
|
419
|
+
query: "\n query PortfolioTotals($addresses: [Address!]!) {\n portfolioV2(addresses: $addresses) {\n tokenBalances {\n totalBalanceUSD\n }\n appBalances {\n totalBalanceUSD\n }\n nftBalances {\n totalBalanceUSD\n }\n }\n }\n ",
|
|
420
|
+
variables: {
|
|
421
|
+
addresses: [address]
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
return [4 /*yield*/, Axios.post(GRAPHQL_URL, graphqlQuery, {
|
|
400
425
|
headers: {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
426
|
+
'Content-Type': 'application/json',
|
|
427
|
+
'x-zapper-api-key': API_KEY,
|
|
428
|
+
}
|
|
404
429
|
})];
|
|
405
430
|
case 2:
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
},
|
|
417
|
-
})];
|
|
418
|
-
case 3:
|
|
419
|
-
tokensResponse = _a.sent();
|
|
420
|
-
log.debug("tokensResponse: ", tokensResponse.data);
|
|
421
|
-
tokens = tokensResponse.data;
|
|
422
|
-
totalBalanceUsdTokens_2 = 0;
|
|
423
|
-
tokens = tokens[address.toLowerCase()];
|
|
424
|
-
// log.debug("tokens: ",tokens)
|
|
425
|
-
tokens.forEach(function (token) {
|
|
426
|
-
log.debug("token: ", token);
|
|
427
|
-
var network = token.network;
|
|
428
|
-
log.debug("network: ", token);
|
|
429
|
-
var caip = pioneer_caip_1.evmCaips[network];
|
|
430
|
-
token.caip = caip;
|
|
431
|
-
log.debug("token.balanceUSD: ", token.token.balanceUSD);
|
|
432
|
-
totalBalanceUsdTokens_2 += token.token.balanceUSD;
|
|
433
|
-
});
|
|
434
|
-
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/nft/balances/net-worth?addresses%5B%5D=".concat(address), {
|
|
435
|
-
headers: {
|
|
436
|
-
accept: "*/*",
|
|
437
|
-
Authorization: Authorization,
|
|
438
|
-
},
|
|
439
|
-
})];
|
|
440
|
-
case 4:
|
|
441
|
-
nftResponse = _a.sent();
|
|
442
|
-
nftUsdNetWorth = nftResponse.data;
|
|
443
|
-
log.debug("nftUsdNetWorth: ", nftUsdNetWorth);
|
|
444
|
-
log.debug("totalBalanceUsdTokens: ", totalBalanceUsdTokens_2);
|
|
445
|
-
log.debug("totalBalanceUSDApp: ", totalBalanceUSDApp_2);
|
|
446
|
-
totalNetWorth = totalBalanceUSDApp_2 + totalBalanceUsdTokens_2 + parseFloat(nftUsdNetWorth[address.toLowerCase()]);
|
|
447
|
-
log.debug("totalNetWorth: ", totalNetWorth);
|
|
431
|
+
portfolioResponse = _f.sent();
|
|
432
|
+
portfolioData = (_b = (_a = portfolioResponse.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.portfolioV2;
|
|
433
|
+
totalBalanceUsdTokens = ((_c = portfolioData === null || portfolioData === void 0 ? void 0 : portfolioData.tokenBalances) === null || _c === void 0 ? void 0 : _c.totalBalanceUSD) || 0;
|
|
434
|
+
totalBalanceUSDApp = ((_d = portfolioData === null || portfolioData === void 0 ? void 0 : portfolioData.appBalances) === null || _d === void 0 ? void 0 : _d.totalBalanceUSD) || 0;
|
|
435
|
+
nftUsdNetWorth = ((_e = portfolioData === null || portfolioData === void 0 ? void 0 : portfolioData.nftBalances) === null || _e === void 0 ? void 0 : _e.totalBalanceUSD) || 0;
|
|
436
|
+
log.debug(tag, "totalBalanceUsdTokens: ", totalBalanceUsdTokens);
|
|
437
|
+
log.debug(tag, "totalBalanceUSDApp: ", totalBalanceUSDApp);
|
|
438
|
+
log.debug(tag, "nftUsdNetWorth: ", nftUsdNetWorth);
|
|
439
|
+
totalNetWorth = totalBalanceUSDApp + totalBalanceUsdTokens + nftUsdNetWorth;
|
|
440
|
+
log.debug(tag, "totalNetWorth: ", totalNetWorth);
|
|
448
441
|
return [2 /*return*/, totalNetWorth];
|
|
449
|
-
case
|
|
450
|
-
e_2 =
|
|
442
|
+
case 3:
|
|
443
|
+
e_2 = _f.sent();
|
|
451
444
|
console.error(tag, "e: ", e_2);
|
|
452
|
-
return [3 /*break*/,
|
|
453
|
-
case
|
|
445
|
+
return [3 /*break*/, 4];
|
|
446
|
+
case 4: return [2 /*return*/];
|
|
454
447
|
}
|
|
455
448
|
});
|
|
456
449
|
});
|
|
457
450
|
};
|
|
458
451
|
var get_tokens = function (address) {
|
|
459
452
|
return __awaiter(this, void 0, void 0, function () {
|
|
460
|
-
var tag,
|
|
461
|
-
|
|
462
|
-
|
|
453
|
+
var tag, graphqlQuery, appsResponse, e_3;
|
|
454
|
+
var _a, _b, _c, _d, _e;
|
|
455
|
+
return __generator(this, function (_f) {
|
|
456
|
+
switch (_f.label) {
|
|
463
457
|
case 0:
|
|
464
458
|
tag = TAG + " | get_tokens | ";
|
|
465
|
-
|
|
459
|
+
_f.label = 1;
|
|
466
460
|
case 1:
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
461
|
+
_f.trys.push([1, 3, , 4]);
|
|
462
|
+
log.debug(tag, "Using API key:", (API_KEY === null || API_KEY === void 0 ? void 0 : API_KEY.substring(0, 10)) + "...");
|
|
463
|
+
graphqlQuery = {
|
|
464
|
+
query: "\n query AppBalances($addresses: [Address!]!) {\n portfolioV2(addresses: $addresses) {\n appBalances {\n byApp(first: 100) {\n edges {\n node {\n balanceUSD\n app {\n slug\n displayName\n }\n network {\n name\n }\n }\n }\n }\n }\n }\n }\n ",
|
|
465
|
+
variables: {
|
|
466
|
+
addresses: [address]
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
return [4 /*yield*/, Axios.post(GRAPHQL_URL, graphqlQuery, {
|
|
471
470
|
headers: {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
471
|
+
'Content-Type': 'application/json',
|
|
472
|
+
'x-zapper-api-key': API_KEY,
|
|
473
|
+
}
|
|
475
474
|
})];
|
|
476
475
|
case 2:
|
|
477
|
-
appsResponse =
|
|
478
|
-
|
|
479
|
-
// const appsResponse = await Axios.get(
|
|
480
|
-
// `https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=${address}`,
|
|
481
|
-
// {
|
|
482
|
-
// headers: {
|
|
483
|
-
// accept: "*/*",
|
|
484
|
-
// Authorization,
|
|
485
|
-
// },
|
|
486
|
-
// }
|
|
487
|
-
// );
|
|
488
|
-
// let url = URL_SERVICE + "/v2/balances/apps?addresses=" + address+",api_key="+API_KEY
|
|
489
|
-
// const headers = {
|
|
490
|
-
// headers: {
|
|
491
|
-
// "Authorization": "Bearer "+process.env['ZAPPER_API_KEY'],
|
|
492
|
-
// }
|
|
493
|
-
// }
|
|
494
|
-
// let result = await axios({
|
|
495
|
-
// url,
|
|
496
|
-
// method: 'GET'
|
|
497
|
-
// },headers)
|
|
498
|
-
return [2 /*return*/, appsResponse.data];
|
|
476
|
+
appsResponse = _f.sent();
|
|
477
|
+
return [2 /*return*/, ((_e = (_d = (_c = (_b = (_a = appsResponse.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.portfolioV2) === null || _c === void 0 ? void 0 : _c.appBalances) === null || _d === void 0 ? void 0 : _d.byApp) === null || _e === void 0 ? void 0 : _e.edges) || []];
|
|
499
478
|
case 3:
|
|
500
|
-
e_3 =
|
|
479
|
+
e_3 = _f.sent();
|
|
501
480
|
console.error(tag, "e: ", e_3);
|
|
502
481
|
return [3 /*break*/, 4];
|
|
503
482
|
case 4: return [2 /*return*/];
|
|
@@ -507,24 +486,38 @@ var get_tokens = function (address) {
|
|
|
507
486
|
};
|
|
508
487
|
var get_nfts = function (address) {
|
|
509
488
|
return __awaiter(this, void 0, void 0, function () {
|
|
510
|
-
var tag,
|
|
511
|
-
|
|
512
|
-
|
|
489
|
+
var tag, graphqlQuery, result, nftData, tokens, e_4;
|
|
490
|
+
var _a, _b, _c, _d, _e;
|
|
491
|
+
return __generator(this, function (_f) {
|
|
492
|
+
switch (_f.label) {
|
|
513
493
|
case 0:
|
|
514
|
-
tag = TAG + " |
|
|
515
|
-
|
|
494
|
+
tag = TAG + " | get_nfts | ";
|
|
495
|
+
_f.label = 1;
|
|
516
496
|
case 1:
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
497
|
+
_f.trys.push([1, 3, , 4]);
|
|
498
|
+
graphqlQuery = {
|
|
499
|
+
query: "\n query NFTBalances($addresses: [Address!]!) {\n portfolioV2(addresses: $addresses) {\n nftBalances {\n totalBalanceUSD\n totalTokensOwned\n byToken(first: 100) {\n edges {\n node {\n token {\n tokenId\n name\n description\n collection {\n address\n name\n network\n type\n }\n estimatedValue {\n valueUsd\n }\n mediasV3 {\n images {\n edges {\n node {\n originalUri\n thumbnail\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n ",
|
|
500
|
+
variables: {
|
|
501
|
+
addresses: [address]
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
return [4 /*yield*/, axios.post(GRAPHQL_URL, graphqlQuery, {
|
|
505
|
+
headers: {
|
|
506
|
+
'Content-Type': 'application/json',
|
|
507
|
+
'x-zapper-api-key': API_KEY,
|
|
508
|
+
}
|
|
522
509
|
})];
|
|
523
510
|
case 2:
|
|
524
|
-
result =
|
|
525
|
-
|
|
511
|
+
result = _f.sent();
|
|
512
|
+
nftData = (_c = (_b = (_a = result.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.portfolioV2) === null || _c === void 0 ? void 0 : _c.nftBalances;
|
|
513
|
+
tokens = ((_e = (_d = nftData === null || nftData === void 0 ? void 0 : nftData.byToken) === null || _d === void 0 ? void 0 : _d.edges) === null || _e === void 0 ? void 0 : _e.map(function (edge) { return edge.node.token; })) || [];
|
|
514
|
+
return [2 /*return*/, {
|
|
515
|
+
items: tokens,
|
|
516
|
+
totalCount: (nftData === null || nftData === void 0 ? void 0 : nftData.totalTokensOwned) || 0,
|
|
517
|
+
totalBalanceUSD: (nftData === null || nftData === void 0 ? void 0 : nftData.totalBalanceUSD) || 0
|
|
518
|
+
}];
|
|
526
519
|
case 3:
|
|
527
|
-
e_4 =
|
|
520
|
+
e_4 = _f.sent();
|
|
528
521
|
console.error(tag, "e: ", e_4);
|
|
529
522
|
return [3 /*break*/, 4];
|
|
530
523
|
case 4: return [2 /*return*/];
|