@pioneer-platform/zapper-client 8.19.0 → 8.24.0
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 +30 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +104 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @pioneer-platform/zapper-client
|
|
2
2
|
|
|
3
|
+
## 8.24.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- chore: feat(pioneer-server): Migrate from Bun to Node.js for Blockbook WebSocket compatibility
|
|
8
|
+
|
|
9
|
+
## 8.23.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- feat(pioneer-server): Migrate from Bun to Node.js for Blockbook WebSocket compatibility
|
|
14
|
+
|
|
15
|
+
## 8.22.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- feat(pioneer-server): Migrate from Bun to Node.js for Blockbook WebSocket compatibility
|
|
20
|
+
|
|
21
|
+
## 8.21.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- feat(pioneer-server): Migrate from Bun to Node.js for Blockbook WebSocket compatibility
|
|
26
|
+
|
|
27
|
+
## 8.20.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- feat(pioneer-server): Migrate from Bun to Node.js for Blockbook WebSocket compatibility
|
|
32
|
+
|
|
3
33
|
## 8.19.0
|
|
4
34
|
|
|
5
35
|
### Minor Changes
|
package/lib/index.d.ts
CHANGED
|
@@ -37,6 +37,23 @@ declare const assignCorrectCaip: (networkId: string, token: any, networkName: st
|
|
|
37
37
|
* Logs CAIP assignment for debugging
|
|
38
38
|
*/
|
|
39
39
|
declare const logCaipAssignment: (balance: any, originalCaip?: string) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Determine if an asset is native or a token based on CAIP pattern
|
|
42
|
+
*
|
|
43
|
+
* Native assets use /slip44: pattern (e.g., eip155:1/slip44:60 for ETH)
|
|
44
|
+
* This includes L2 native assets like ETH on Base, Arbitrum, Optimism, etc.
|
|
45
|
+
*
|
|
46
|
+
* Tokens use contract-based patterns:
|
|
47
|
+
* - /erc20: for Ethereum and EVM chains
|
|
48
|
+
* - /bep20: for Binance Smart Chain
|
|
49
|
+
* - /spl: for Solana
|
|
50
|
+
* - /denom: for Cosmos ecosystem
|
|
51
|
+
* - /ibc: for IBC tokens
|
|
52
|
+
*
|
|
53
|
+
* @param caip - The CAIP identifier to check
|
|
54
|
+
* @returns true if native asset, false if token
|
|
55
|
+
*/
|
|
56
|
+
declare const isNativeAsset: (caip: string) => boolean;
|
|
40
57
|
declare const get_portfolio: (address: string) => Promise<any>;
|
|
41
58
|
declare const get_total_networth: (address: string) => Promise<any>;
|
|
42
59
|
declare const get_tokens: (address: string) => Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -300,6 +300,46 @@ var logCaipAssignment = function (balance, originalCaip) {
|
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
302
|
};
|
|
303
|
+
/**
|
|
304
|
+
* Determine if an asset is native or a token based on CAIP pattern
|
|
305
|
+
*
|
|
306
|
+
* Native assets use /slip44: pattern (e.g., eip155:1/slip44:60 for ETH)
|
|
307
|
+
* This includes L2 native assets like ETH on Base, Arbitrum, Optimism, etc.
|
|
308
|
+
*
|
|
309
|
+
* Tokens use contract-based patterns:
|
|
310
|
+
* - /erc20: for Ethereum and EVM chains
|
|
311
|
+
* - /bep20: for Binance Smart Chain
|
|
312
|
+
* - /spl: for Solana
|
|
313
|
+
* - /denom: for Cosmos ecosystem
|
|
314
|
+
* - /ibc: for IBC tokens
|
|
315
|
+
*
|
|
316
|
+
* @param caip - The CAIP identifier to check
|
|
317
|
+
* @returns true if native asset, false if token
|
|
318
|
+
*/
|
|
319
|
+
var isNativeAsset = function (caip) {
|
|
320
|
+
var tag = TAG + " | isNativeAsset | ";
|
|
321
|
+
if (!caip || !caip.includes('/')) {
|
|
322
|
+
log.warn(tag, "Invalid CAIP format:", caip);
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
// Native assets have /slip44: pattern
|
|
326
|
+
if (caip.includes('/slip44:')) {
|
|
327
|
+
log.debug(tag, "Native asset detected: ".concat(caip));
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
// Tokens have contract-based patterns
|
|
331
|
+
if (caip.includes('/erc20:') ||
|
|
332
|
+
caip.includes('/bep20:') ||
|
|
333
|
+
caip.includes('/spl:') ||
|
|
334
|
+
caip.includes('/denom:') ||
|
|
335
|
+
caip.includes('/ibc:')) {
|
|
336
|
+
log.debug(tag, "Token detected: ".concat(caip));
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
// Default to token for unknown patterns (safer)
|
|
340
|
+
log.warn(tag, "Unknown CAIP pattern, defaulting to token: ".concat(caip));
|
|
341
|
+
return false;
|
|
342
|
+
};
|
|
303
343
|
module.exports = {
|
|
304
344
|
getTokens: function (address) {
|
|
305
345
|
return get_tokens(address);
|
|
@@ -316,7 +356,7 @@ module.exports = {
|
|
|
316
356
|
};
|
|
317
357
|
var get_portfolio = function (address) {
|
|
318
358
|
return __awaiter(this, void 0, void 0, function () {
|
|
319
|
-
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_2;
|
|
359
|
+
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, totalNetWorthFormatted, e_2;
|
|
320
360
|
var _c;
|
|
321
361
|
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, _10, _11;
|
|
322
362
|
return __generator(this, function (_12) {
|
|
@@ -327,7 +367,8 @@ var get_portfolio = function (address) {
|
|
|
327
367
|
case 1:
|
|
328
368
|
_12.trys.push([1, 11, , 13]);
|
|
329
369
|
output_1 = {
|
|
330
|
-
balances: []
|
|
370
|
+
balances: [], // Native assets only (ETH, BTC, etc. with /slip44:)
|
|
371
|
+
tokens: [] // ERC20/BEP20/SPL tokens with contract addresses
|
|
331
372
|
};
|
|
332
373
|
appsGraphqlQuery = {
|
|
333
374
|
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 ",
|
|
@@ -389,7 +430,15 @@ var get_portfolio = function (address) {
|
|
|
389
430
|
type: 'app-token'
|
|
390
431
|
};
|
|
391
432
|
balance.caip = assignCorrectCaip(networkId, tokenForCaip, networkName);
|
|
392
|
-
|
|
433
|
+
// Categorize based on CAIP pattern
|
|
434
|
+
if (isNativeAsset(balance.caip)) {
|
|
435
|
+
output_1.balances.push(balance);
|
|
436
|
+
log.debug(tag, "App-token ".concat(balance.symbol, " (").concat(balance.caip, ") \u2192 balances (native)"));
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
output_1.tokens.push(balance);
|
|
440
|
+
log.debug(tag, "App-token ".concat(balance.symbol, " (").concat(balance.caip, ") \u2192 tokens"));
|
|
441
|
+
}
|
|
393
442
|
}
|
|
394
443
|
else if (position.type === 'contract-position') {
|
|
395
444
|
tokens = position.tokens || [];
|
|
@@ -419,7 +468,15 @@ var get_portfolio = function (address) {
|
|
|
419
468
|
symbol: token.symbol
|
|
420
469
|
};
|
|
421
470
|
balance.caip = assignCorrectCaip(networkId, tokenForCaip, networkName);
|
|
422
|
-
|
|
471
|
+
// Categorize based on CAIP pattern
|
|
472
|
+
if (isNativeAsset(balance.caip)) {
|
|
473
|
+
output_1.balances.push(balance);
|
|
474
|
+
log.debug(tag, "Contract-position ".concat(balance.symbol, " (").concat(balance.caip, ") \u2192 balances (native)"));
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
output_1.tokens.push(balance);
|
|
478
|
+
log.debug(tag, "Contract-position ".concat(balance.symbol, " (").concat(balance.caip, ") \u2192 tokens"));
|
|
479
|
+
}
|
|
423
480
|
}
|
|
424
481
|
}
|
|
425
482
|
}
|
|
@@ -450,8 +507,9 @@ var get_portfolio = function (address) {
|
|
|
450
507
|
if ((_4 = (_3 = (_2 = tokensResponse.data) === null || _2 === void 0 ? void 0 : _2.data) === null || _3 === void 0 ? void 0 : _3.portfolioV2) === null || _4 === void 0 ? void 0 : _4.tokenBalances) {
|
|
451
508
|
tokenData = tokensResponse.data.data.portfolioV2.tokenBalances;
|
|
452
509
|
tokens = ((_5 = tokenData.byToken) === null || _5 === void 0 ? void 0 : _5.edges) || [];
|
|
453
|
-
|
|
454
|
-
|
|
510
|
+
// DO NOT set output.tokens here - let categorization logic handle it
|
|
511
|
+
// output.tokens will be populated by the CAIP categorization logic below
|
|
512
|
+
log.info(tag, "tokens from GraphQL: ", tokens.length);
|
|
455
513
|
if (tokens.length > 0) {
|
|
456
514
|
tokens.forEach(function (edge) {
|
|
457
515
|
var tokenNode = edge.node;
|
|
@@ -494,7 +552,15 @@ var get_portfolio = function (address) {
|
|
|
494
552
|
address: tokenNode.tokenAddress,
|
|
495
553
|
network: networkName
|
|
496
554
|
});
|
|
497
|
-
|
|
555
|
+
// Categorize based on CAIP pattern
|
|
556
|
+
if (isNativeAsset(assetCaip)) {
|
|
557
|
+
output_1.balances.push(balance);
|
|
558
|
+
log.debug(tag, "Portfolio token ".concat(tokenNode.symbol, " (").concat(assetCaip, ") \u2192 balances (native)"));
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
output_1.tokens.push(balance);
|
|
562
|
+
log.debug(tag, "Portfolio token ".concat(tokenNode.symbol, " (").concat(assetCaip, ") \u2192 tokens"));
|
|
563
|
+
}
|
|
498
564
|
log.debug(tag, "token.balanceUSD: ", tokenNode.balanceUSD);
|
|
499
565
|
totalBalanceUsdTokens_1 += tokenNode.balanceUSD || 0;
|
|
500
566
|
}
|
|
@@ -537,6 +603,37 @@ var get_portfolio = function (address) {
|
|
|
537
603
|
totalNetWorth = totalBalanceUSDApp + totalBalanceUsdTokens_1 + nftUsdNetWorth;
|
|
538
604
|
//console.log("totalNetWorth: ",totalNetWorth);
|
|
539
605
|
output_1.totalNetWorth = totalNetWorth;
|
|
606
|
+
// 🔍 DEBUG: Log categorization summary for diagnostics
|
|
607
|
+
log.info(tag, "\uD83D\uDD0D [ZAPPER FINAL] Portfolio categorization complete:");
|
|
608
|
+
log.info(tag, " \uD83D\uDCCA Native balances: ".concat(output_1.balances.length, " (should have /slip44:)"));
|
|
609
|
+
log.info(tag, " \uD83E\uDE99 Tokens: ".concat(output_1.tokens.length, " (should have /erc20:)"));
|
|
610
|
+
totalNetWorthFormatted = (typeof totalNetWorth === 'number' && !isNaN(totalNetWorth))
|
|
611
|
+
? "$".concat(totalNetWorth.toFixed(2))
|
|
612
|
+
: "$0.00 (NaN)";
|
|
613
|
+
log.info(tag, " \uD83D\uDCB0 Total value: ".concat(totalNetWorthFormatted));
|
|
614
|
+
// Sample native balances
|
|
615
|
+
if (output_1.balances.length > 0) {
|
|
616
|
+
log.info(tag, " \uD83D\uDCCA Sample native balances (first 3):");
|
|
617
|
+
output_1.balances.slice(0, 3).forEach(function (b) {
|
|
618
|
+
var valueFormatted = (typeof b.valueUsd === 'number')
|
|
619
|
+
? "$".concat(b.valueUsd.toFixed(2))
|
|
620
|
+
: '$0';
|
|
621
|
+
log.info(tag, " - ".concat(b.symbol, ": ").concat(b.caip, " (").concat(valueFormatted, ")"));
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
// Sample tokens
|
|
625
|
+
if (output_1.tokens.length > 0) {
|
|
626
|
+
log.info(tag, " \uD83E\uDE99 Sample tokens (first 3):");
|
|
627
|
+
output_1.tokens.slice(0, 3).forEach(function (t) {
|
|
628
|
+
var valueFormatted = (typeof t.valueUsd === 'number')
|
|
629
|
+
? "$".concat(t.valueUsd.toFixed(2))
|
|
630
|
+
: '$0';
|
|
631
|
+
log.info(tag, " - ".concat(t.symbol, ": ").concat(t.caip, " (").concat(valueFormatted, ", balance: ").concat(t.balance, ")"));
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
log.warn(tag, " \u26A0\uFE0F [CRITICAL] Zapper categorized 0 tokens! Expected 60-70 tokens including $1300 USDT!");
|
|
636
|
+
}
|
|
540
637
|
return [2 /*return*/, output_1];
|
|
541
638
|
case 11:
|
|
542
639
|
e_2 = _12.sent();
|