@pioneer-platform/zapper-client 8.3.14 → 8.4.1
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 +22 -0
- package/package.json +3 -3
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -533
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @pioneer-platform/zapper-client
|
|
2
|
+
|
|
3
|
+
## 8.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Automated patch version bump for all packages
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @pioneer-platform/loggerdog@8.4.1
|
|
10
|
+
- @pioneer-platform/pioneer-caip@9.3.1
|
|
11
|
+
|
|
12
|
+
## 8.4.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- Release: minor version bump for all packages
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @pioneer-platform/loggerdog@8.4.0
|
|
22
|
+
- @pioneer-platform/pioneer-caip@9.3.0
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/zapper-client",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.1",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@pioneer-platform/loggerdog": "^8.
|
|
8
|
-
"@pioneer-platform/pioneer-caip": "^9.
|
|
7
|
+
"@pioneer-platform/loggerdog": "^8.4.1",
|
|
8
|
+
"@pioneer-platform/pioneer-caip": "^9.3.1",
|
|
9
9
|
"axios": "^1.6.0",
|
|
10
10
|
"dotenv": "^8.2.0"
|
|
11
11
|
},
|
package/lib/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/index.js
DELETED
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
https://docs.blocknative.com/webhook-api
|
|
4
|
-
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
var TAG = " | zapper | ";
|
|
55
|
-
var log = require('@pioneer-platform/loggerdog')();
|
|
56
|
-
//@ts-ignore
|
|
57
|
-
var pioneer_caip_1 = require("@pioneer-platform/pioneer-caip");
|
|
58
|
-
var Axios = require('axios');
|
|
59
|
-
var https = require('https');
|
|
60
|
-
var API_KEY = process.env['ZAPPER_API_KEY'];
|
|
61
|
-
if (!API_KEY)
|
|
62
|
-
throw Error("api key required! set env ZAPPER_API_KEY");
|
|
63
|
-
var axios = Axios.create();
|
|
64
|
-
var Authorization = "Basic ".concat(Buffer.from("".concat(API_KEY, ":"), "binary").toString("base64"));
|
|
65
|
-
console.log(Authorization);
|
|
66
|
-
var URL_SERVICE = "https://api.zapper.xyz";
|
|
67
|
-
// Removed axios-retry - using basic axios
|
|
68
|
-
/**
|
|
69
|
-
* Validates if a CAIP is correctly formatted for the given token
|
|
70
|
-
*/
|
|
71
|
-
var validateCaip = function (caip, token, networkName) {
|
|
72
|
-
var _a;
|
|
73
|
-
var tag = TAG + " | validateCaip | ";
|
|
74
|
-
try {
|
|
75
|
-
if (!caip || !caip.includes('/')) {
|
|
76
|
-
log.error(tag, "Invalid CAIP format:", caip);
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
var _b = caip.split('/'), network = _b[0], assetType = _b[1];
|
|
80
|
-
// Check if token has contract address
|
|
81
|
-
var hasContractAddress = token.address &&
|
|
82
|
-
token.address !== '0x0000000000000000000000000000000000000000' &&
|
|
83
|
-
token.address.toLowerCase() !== '0x0';
|
|
84
|
-
// Special handling for eETH (Ether.fi staked ETH)
|
|
85
|
-
var isEETH = token.symbol === 'eETH' ||
|
|
86
|
-
(token.address && token.address.toLowerCase() === '0x35fa164735182de50811e8e2e824cfb9b6118ac2');
|
|
87
|
-
if (hasContractAddress || isEETH) {
|
|
88
|
-
// This should be an ERC-20 token
|
|
89
|
-
if (!(assetType === null || assetType === void 0 ? void 0 : assetType.includes('erc20'))) {
|
|
90
|
-
log.error(tag, "Token ".concat(token.symbol, " with address ").concat(token.address, " should have ERC-20 CAIP but got: ").concat(caip));
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
// Verify contract address is in CAIP
|
|
94
|
-
if (!(assetType === null || assetType === void 0 ? void 0 : assetType.includes((_a = token.address) === null || _a === void 0 ? void 0 : _a.toLowerCase()))) {
|
|
95
|
-
log.error(tag, "Token ".concat(token.symbol, " CAIP missing contract address: ").concat(caip));
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
// This should be a native asset
|
|
101
|
-
if (!(assetType === null || assetType === void 0 ? void 0 : assetType.includes('slip44'))) {
|
|
102
|
-
log.error(tag, "Native asset ".concat(token.symbol, " should have slip44 CAIP but got: ").concat(caip));
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
log.error(tag, "CAIP validation error:", e);
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Assigns the correct CAIP for a token based on its properties
|
|
115
|
-
*/
|
|
116
|
-
var assignCorrectCaip = function (networkId, token, networkName) {
|
|
117
|
-
var tag = TAG + " | assignCorrectCaip | ";
|
|
118
|
-
try {
|
|
119
|
-
// Check if token has a valid contract address
|
|
120
|
-
var hasContractAddress = token.address &&
|
|
121
|
-
token.address !== '0x0000000000000000000000000000000000000000' &&
|
|
122
|
-
token.address.toLowerCase() !== '0x0' &&
|
|
123
|
-
token.address.toLowerCase() !== '0x';
|
|
124
|
-
// Known token addresses for special handling
|
|
125
|
-
var knownTokens = {
|
|
126
|
-
'eETH': '0x35fa164735182de50811e8e2e824cfb9b6118ac2',
|
|
127
|
-
'weETH': '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee',
|
|
128
|
-
'stETH': '0xae7ab96520de3a18e5e111b5eaab095312d7fe84',
|
|
129
|
-
'wstETH': '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0'
|
|
130
|
-
};
|
|
131
|
-
// Check if this is a known token that should be ERC-20
|
|
132
|
-
var knownAddress = knownTokens[token.symbol];
|
|
133
|
-
if (knownAddress) {
|
|
134
|
-
var caip_1 = "".concat(networkId, "/erc20:").concat(knownAddress.toLowerCase());
|
|
135
|
-
log.debug(tag, "Assigned known token CAIP for ".concat(token.symbol, ": ").concat(caip_1));
|
|
136
|
-
return caip_1;
|
|
137
|
-
}
|
|
138
|
-
// For tokens with valid contract addresses (ERC-20/ERC-721)
|
|
139
|
-
if (hasContractAddress) {
|
|
140
|
-
var caip_2 = "".concat(networkId, "/erc20:").concat(token.address.toLowerCase());
|
|
141
|
-
log.debug(tag, "Assigned ERC-20 CAIP for ".concat(token.symbol, ": ").concat(caip_2));
|
|
142
|
-
return caip_2;
|
|
143
|
-
}
|
|
144
|
-
// For native tokens (ETH, BNB, MATIC, etc) - only when explicitly base-token or no address
|
|
145
|
-
if (token.type === 'base-token' || token.symbol === 'ETH' || token.symbol === 'BNB' || token.symbol === 'MATIC') {
|
|
146
|
-
var caip_3 = "".concat(networkId, "/slip44:60");
|
|
147
|
-
log.debug(tag, "Assigned native CAIP for ".concat(token.symbol, ": ").concat(caip_3));
|
|
148
|
-
return caip_3;
|
|
149
|
-
}
|
|
150
|
-
// Default to slip44:60 for native assets without addresses
|
|
151
|
-
var caip = "".concat(networkId, "/slip44:60");
|
|
152
|
-
log.warn(tag, "Default CAIP assignment for ".concat(token.symbol, ": ").concat(caip));
|
|
153
|
-
return caip;
|
|
154
|
-
}
|
|
155
|
-
catch (e) {
|
|
156
|
-
log.error(tag, "Error assigning CAIP:", e);
|
|
157
|
-
// Fallback to native token CAIP
|
|
158
|
-
return "".concat(networkId, "/slip44:60");
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Logs CAIP assignment for debugging
|
|
163
|
-
*/
|
|
164
|
-
var logCaipAssignment = function (balance, originalCaip) {
|
|
165
|
-
var tag = TAG + " | logCaipAssignment | ";
|
|
166
|
-
if (originalCaip && originalCaip !== balance.caip) {
|
|
167
|
-
log.info(tag, "CAIP corrected for ".concat(balance.symbol, ":"));
|
|
168
|
-
log.info(tag, " Original: ".concat(originalCaip));
|
|
169
|
-
log.info(tag, " Corrected: ".concat(balance.caip));
|
|
170
|
-
log.info(tag, " Token details:", {
|
|
171
|
-
symbol: balance.symbol,
|
|
172
|
-
name: balance.name,
|
|
173
|
-
address: balance.tokenAddress,
|
|
174
|
-
type: balance.tokenType,
|
|
175
|
-
metaType: balance.metaType
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
module.exports = {
|
|
180
|
-
getTokens: function (address) {
|
|
181
|
-
return get_tokens(address);
|
|
182
|
-
},
|
|
183
|
-
getNFTs: function (address) {
|
|
184
|
-
return get_nfts(address);
|
|
185
|
-
},
|
|
186
|
-
getPortfolio: function (address) {
|
|
187
|
-
return get_portfolio(address);
|
|
188
|
-
},
|
|
189
|
-
getTotalNetworth: function (address) {
|
|
190
|
-
return get_total_networth(address);
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
var get_portfolio = function (address) {
|
|
194
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
-
var tag, output_1, appsResponse, apps, totalBalanceUSDApp_1, i, app, j, product, k, asset, l, token, balance, tokenForCaip, tokensResponse, totalBalanceUsdTokens_1, tokens, limit, allTokens, cursor, url, response, tokens, error_1, nftResponse, nftUsdNetWorth, totalNetWorth, e_1;
|
|
196
|
-
var _a, _b, _c, _d;
|
|
197
|
-
return __generator(this, function (_e) {
|
|
198
|
-
switch (_e.label) {
|
|
199
|
-
case 0:
|
|
200
|
-
tag = TAG + " | get_portfolio | ";
|
|
201
|
-
_e.label = 1;
|
|
202
|
-
case 1:
|
|
203
|
-
_e.trys.push([1, 11, , 12]);
|
|
204
|
-
output_1 = {
|
|
205
|
-
balances: []
|
|
206
|
-
};
|
|
207
|
-
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=".concat(address), {
|
|
208
|
-
headers: {
|
|
209
|
-
accept: "*/*",
|
|
210
|
-
Authorization: Authorization,
|
|
211
|
-
},
|
|
212
|
-
})];
|
|
213
|
-
case 2:
|
|
214
|
-
appsResponse = _e.sent();
|
|
215
|
-
log.info(tag, "appsResponse: ", appsResponse.data);
|
|
216
|
-
apps = appsResponse.data;
|
|
217
|
-
totalBalanceUSDApp_1 = 0;
|
|
218
|
-
apps.forEach(function (app) {
|
|
219
|
-
totalBalanceUSDApp_1 += app.balanceUSD;
|
|
220
|
-
});
|
|
221
|
-
for (i = 0; i < apps.length; i++) {
|
|
222
|
-
app = apps[i];
|
|
223
|
-
for (j = 0; j < app.products.length; j++) {
|
|
224
|
-
product = app.products[j];
|
|
225
|
-
log.info(tag, "product: ", product);
|
|
226
|
-
for (k = 0; k < product.assets.length; k++) {
|
|
227
|
-
asset = product.assets[k];
|
|
228
|
-
log.info(tag, "asset: ", asset);
|
|
229
|
-
for (l = 0; l < asset.tokens.length; l++) {
|
|
230
|
-
token = asset.tokens[l];
|
|
231
|
-
balance = {};
|
|
232
|
-
balance.pubkey = app.address;
|
|
233
|
-
balance.balance = token === null || token === void 0 ? void 0 : token.balance.toString();
|
|
234
|
-
balance.chain = app.network;
|
|
235
|
-
balance.networkId = pioneer_caip_1.evmCaips[app.network].split('/')[0];
|
|
236
|
-
tokenForCaip = token;
|
|
237
|
-
if (asset.type === 'app-token' && asset.address &&
|
|
238
|
-
asset.address !== '0x0000000000000000000000000000000000000000') {
|
|
239
|
-
// Use the asset-level address for app tokens
|
|
240
|
-
tokenForCaip = __assign(__assign({}, token), { address: asset.address, symbol: asset.symbol || token.symbol });
|
|
241
|
-
}
|
|
242
|
-
// Assign correct CAIP based on token properties
|
|
243
|
-
balance.caip = assignCorrectCaip(balance.networkId, tokenForCaip, app.network);
|
|
244
|
-
// Log CAIP assignment for debugging
|
|
245
|
-
log.debug(tag, "CAIP assigned for ".concat(asset.symbol || token.symbol, ": ").concat(balance.caip), {
|
|
246
|
-
assetAddress: asset.address,
|
|
247
|
-
tokenAddress: token.address,
|
|
248
|
-
assetType: asset.type,
|
|
249
|
-
tokenType: token.type,
|
|
250
|
-
network: app.network
|
|
251
|
-
});
|
|
252
|
-
balance.metaType = token.metaType || product.metaType;
|
|
253
|
-
balance.name = asset.displayProps.label;
|
|
254
|
-
balance.appId = app.appId;
|
|
255
|
-
balance.icon = asset.displayProps.images[0];
|
|
256
|
-
balance.display = asset.displayProps.images;
|
|
257
|
-
balance.groupId = asset.groupId;
|
|
258
|
-
balance.symbol = asset.symbol || token.symbol; // Use asset symbol if available
|
|
259
|
-
balance.ticker = asset.symbol || token.symbol; // Use asset symbol if available
|
|
260
|
-
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
|
|
261
|
-
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
|
|
262
|
-
// Add additional fields for debugging
|
|
263
|
-
balance.tokenAddress = asset.address || token.address;
|
|
264
|
-
balance.tokenType = asset.type || token.type;
|
|
265
|
-
output_1.balances.push(balance);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/tokens?addresses%5B%5D=".concat(address), {
|
|
271
|
-
headers: {
|
|
272
|
-
accept: "*/*",
|
|
273
|
-
Authorization: Authorization,
|
|
274
|
-
},
|
|
275
|
-
})];
|
|
276
|
-
case 3:
|
|
277
|
-
tokensResponse = _e.sent();
|
|
278
|
-
console.log("tokensResponse: ", tokensResponse.data);
|
|
279
|
-
if (tokensResponse.data && tokensResponse.data[address.toLowerCase()]) {
|
|
280
|
-
tokens = tokensResponse.data;
|
|
281
|
-
totalBalanceUsdTokens_1 = 0;
|
|
282
|
-
tokens = tokens[address.toLowerCase()];
|
|
283
|
-
output_1.tokens = tokens;
|
|
284
|
-
log.info(tag, "tokens: ", tokens.length);
|
|
285
|
-
if (tokens) {
|
|
286
|
-
tokens.forEach(function (token) {
|
|
287
|
-
log.debug(tag, "token: ", token);
|
|
288
|
-
var network = token.network;
|
|
289
|
-
log.debug(tag, "network: ", network);
|
|
290
|
-
var caip = pioneer_caip_1.evmCaips[network];
|
|
291
|
-
if (caip) {
|
|
292
|
-
token.networkId = caip.split('/')[0];
|
|
293
|
-
// Assign correct CAIP based on token properties
|
|
294
|
-
token.assetCaip = assignCorrectCaip(token.networkId, token.token, network);
|
|
295
|
-
var balance = {
|
|
296
|
-
balance: token.token.balance.toString(),
|
|
297
|
-
networkId: token.networkId,
|
|
298
|
-
chain: token.network,
|
|
299
|
-
caip: token.assetCaip,
|
|
300
|
-
type: 'erc20',
|
|
301
|
-
name: token.token.name,
|
|
302
|
-
symbol: token.token.symbol,
|
|
303
|
-
ticker: token.token.symbol,
|
|
304
|
-
decimals: token.token.decimals,
|
|
305
|
-
priceUsd: token.token.price,
|
|
306
|
-
valueUsd: token.token.balanceUSD.toString(),
|
|
307
|
-
tokenAddress: token.token.address,
|
|
308
|
-
};
|
|
309
|
-
// Log CAIP assignment for debugging
|
|
310
|
-
log.debug(tag, "CAIP assigned for ".concat(token.token.symbol, ": ").concat(token.assetCaip), {
|
|
311
|
-
address: token.token.address,
|
|
312
|
-
network: network
|
|
313
|
-
});
|
|
314
|
-
output_1.balances.push(balance);
|
|
315
|
-
log.debug(tag, "token.balanceUSD: ", token.token.balanceUSD);
|
|
316
|
-
totalBalanceUsdTokens_1 += token.token.balanceUSD;
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
log.error(tag, "No caip found for network: ", network);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
totalBalanceUsdTokens_1 = 0;
|
|
326
|
-
}
|
|
327
|
-
limit = 100;
|
|
328
|
-
allTokens = [];
|
|
329
|
-
cursor = null;
|
|
330
|
-
_e.label = 4;
|
|
331
|
-
case 4:
|
|
332
|
-
if (!true) return [3 /*break*/, 9];
|
|
333
|
-
_e.label = 5;
|
|
334
|
-
case 5:
|
|
335
|
-
_e.trys.push([5, 7, , 8]);
|
|
336
|
-
url = "https://api.zapper.xyz/v2/nft/user/tokens?userAddress=".concat(address, "&limit=").concat(limit);
|
|
337
|
-
if (cursor) {
|
|
338
|
-
url += "&cursor=".concat(cursor);
|
|
339
|
-
}
|
|
340
|
-
return [4 /*yield*/, Axios.get(url, {
|
|
341
|
-
headers: {
|
|
342
|
-
accept: "*/*",
|
|
343
|
-
Authorization: Authorization,
|
|
344
|
-
},
|
|
345
|
-
})];
|
|
346
|
-
case 6:
|
|
347
|
-
response = _e.sent();
|
|
348
|
-
tokens = response.data;
|
|
349
|
-
//console.log("tokens: ",tokens)
|
|
350
|
-
allTokens = allTokens.concat(tokens.items);
|
|
351
|
-
cursor = response.data.cursor;
|
|
352
|
-
if (!cursor) {
|
|
353
|
-
return [3 /*break*/, 9];
|
|
354
|
-
}
|
|
355
|
-
return [3 /*break*/, 8];
|
|
356
|
-
case 7:
|
|
357
|
-
error_1 = _e.sent();
|
|
358
|
-
console.error(error_1);
|
|
359
|
-
return [3 /*break*/, 8];
|
|
360
|
-
case 8: return [3 /*break*/, 4];
|
|
361
|
-
case 9:
|
|
362
|
-
output_1.nfts = allTokens;
|
|
363
|
-
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/nft/balances/net-worth?addresses%5B%5D=".concat(address), {
|
|
364
|
-
headers: {
|
|
365
|
-
accept: "*/*",
|
|
366
|
-
Authorization: Authorization,
|
|
367
|
-
},
|
|
368
|
-
})];
|
|
369
|
-
case 10:
|
|
370
|
-
nftResponse = _e.sent();
|
|
371
|
-
nftUsdNetWorth = nftResponse.data;
|
|
372
|
-
output_1.nftUsdNetWorth = nftUsdNetWorth;
|
|
373
|
-
output_1.totalBalanceUsdTokens = totalBalanceUsdTokens_1;
|
|
374
|
-
output_1.totalBalanceUSDApp = totalBalanceUSDApp_1;
|
|
375
|
-
totalNetWorth = totalBalanceUSDApp_1 + totalBalanceUsdTokens_1 + parseFloat(nftUsdNetWorth[address.toLowerCase()]);
|
|
376
|
-
//console.log("totalNetWorth: ",totalNetWorth);
|
|
377
|
-
output_1.totalNetWorth = totalNetWorth;
|
|
378
|
-
return [2 /*return*/, output_1];
|
|
379
|
-
case 11:
|
|
380
|
-
e_1 = _e.sent();
|
|
381
|
-
console.error(tag, "e: ", e_1);
|
|
382
|
-
return [3 /*break*/, 12];
|
|
383
|
-
case 12: return [2 /*return*/];
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
};
|
|
388
|
-
var get_total_networth = function (address) {
|
|
389
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
390
|
-
var tag, appsResponse, apps, totalBalanceUSDApp_2, tokensResponse, tokens, totalBalanceUsdTokens_2, nftResponse, nftUsdNetWorth, totalNetWorth, e_2;
|
|
391
|
-
return __generator(this, function (_a) {
|
|
392
|
-
switch (_a.label) {
|
|
393
|
-
case 0:
|
|
394
|
-
tag = TAG + " | get_tokens | ";
|
|
395
|
-
_a.label = 1;
|
|
396
|
-
case 1:
|
|
397
|
-
_a.trys.push([1, 5, , 6]);
|
|
398
|
-
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=".concat(address), {
|
|
399
|
-
headers: {
|
|
400
|
-
accept: "*/*",
|
|
401
|
-
Authorization: Authorization,
|
|
402
|
-
},
|
|
403
|
-
})];
|
|
404
|
-
case 2:
|
|
405
|
-
appsResponse = _a.sent();
|
|
406
|
-
apps = appsResponse.data;
|
|
407
|
-
totalBalanceUSDApp_2 = 0;
|
|
408
|
-
apps.forEach(function (app) {
|
|
409
|
-
totalBalanceUSDApp_2 += app.balanceUSD;
|
|
410
|
-
});
|
|
411
|
-
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/tokens?addresses%5B%5D=".concat(address), {
|
|
412
|
-
headers: {
|
|
413
|
-
accept: "*/*",
|
|
414
|
-
Authorization: Authorization,
|
|
415
|
-
},
|
|
416
|
-
})];
|
|
417
|
-
case 3:
|
|
418
|
-
tokensResponse = _a.sent();
|
|
419
|
-
log.debug("tokensResponse: ", tokensResponse.data);
|
|
420
|
-
tokens = tokensResponse.data;
|
|
421
|
-
totalBalanceUsdTokens_2 = 0;
|
|
422
|
-
tokens = tokens[address.toLowerCase()];
|
|
423
|
-
// log.debug("tokens: ",tokens)
|
|
424
|
-
tokens.forEach(function (token) {
|
|
425
|
-
log.debug("token: ", token);
|
|
426
|
-
var network = token.network;
|
|
427
|
-
log.debug("network: ", token);
|
|
428
|
-
var caip = pioneer_caip_1.evmCaips[network];
|
|
429
|
-
token.caip = caip;
|
|
430
|
-
log.debug("token.balanceUSD: ", token.token.balanceUSD);
|
|
431
|
-
totalBalanceUsdTokens_2 += token.token.balanceUSD;
|
|
432
|
-
});
|
|
433
|
-
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/nft/balances/net-worth?addresses%5B%5D=".concat(address), {
|
|
434
|
-
headers: {
|
|
435
|
-
accept: "*/*",
|
|
436
|
-
Authorization: Authorization,
|
|
437
|
-
},
|
|
438
|
-
})];
|
|
439
|
-
case 4:
|
|
440
|
-
nftResponse = _a.sent();
|
|
441
|
-
nftUsdNetWorth = nftResponse.data;
|
|
442
|
-
log.debug("nftUsdNetWorth: ", nftUsdNetWorth);
|
|
443
|
-
log.debug("totalBalanceUsdTokens: ", totalBalanceUsdTokens_2);
|
|
444
|
-
log.debug("totalBalanceUSDApp: ", totalBalanceUSDApp_2);
|
|
445
|
-
totalNetWorth = totalBalanceUSDApp_2 + totalBalanceUsdTokens_2 + parseFloat(nftUsdNetWorth[address.toLowerCase()]);
|
|
446
|
-
log.debug("totalNetWorth: ", totalNetWorth);
|
|
447
|
-
return [2 /*return*/, totalNetWorth];
|
|
448
|
-
case 5:
|
|
449
|
-
e_2 = _a.sent();
|
|
450
|
-
console.error(tag, "e: ", e_2);
|
|
451
|
-
return [3 /*break*/, 6];
|
|
452
|
-
case 6: return [2 /*return*/];
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
};
|
|
457
|
-
var get_tokens = function (address) {
|
|
458
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
459
|
-
var tag, apiKey, appsResponse, e_3;
|
|
460
|
-
return __generator(this, function (_a) {
|
|
461
|
-
switch (_a.label) {
|
|
462
|
-
case 0:
|
|
463
|
-
tag = TAG + " | get_tokens | ";
|
|
464
|
-
_a.label = 1;
|
|
465
|
-
case 1:
|
|
466
|
-
_a.trys.push([1, 3, , 4]);
|
|
467
|
-
apiKey = API_KEY;
|
|
468
|
-
log.debug(Authorization);
|
|
469
|
-
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=".concat(address), {
|
|
470
|
-
headers: {
|
|
471
|
-
accept: "*/*",
|
|
472
|
-
Authorization: Authorization,
|
|
473
|
-
},
|
|
474
|
-
})];
|
|
475
|
-
case 2:
|
|
476
|
-
appsResponse = _a.sent();
|
|
477
|
-
// @ts-ignore
|
|
478
|
-
// const appsResponse = await Axios.get(
|
|
479
|
-
// `https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=${address}`,
|
|
480
|
-
// {
|
|
481
|
-
// headers: {
|
|
482
|
-
// accept: "*/*",
|
|
483
|
-
// Authorization,
|
|
484
|
-
// },
|
|
485
|
-
// }
|
|
486
|
-
// );
|
|
487
|
-
// let url = URL_SERVICE + "/v2/balances/apps?addresses=" + address+",api_key="+API_KEY
|
|
488
|
-
// const headers = {
|
|
489
|
-
// headers: {
|
|
490
|
-
// "Authorization": "Bearer "+process.env['ZAPPER_API_KEY'],
|
|
491
|
-
// }
|
|
492
|
-
// }
|
|
493
|
-
// let result = await axios({
|
|
494
|
-
// url,
|
|
495
|
-
// method: 'GET'
|
|
496
|
-
// },headers)
|
|
497
|
-
return [2 /*return*/, appsResponse.data];
|
|
498
|
-
case 3:
|
|
499
|
-
e_3 = _a.sent();
|
|
500
|
-
console.error(tag, "e: ", e_3);
|
|
501
|
-
return [3 /*break*/, 4];
|
|
502
|
-
case 4: return [2 /*return*/];
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
};
|
|
507
|
-
var get_nfts = function (address) {
|
|
508
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
509
|
-
var tag, url, result, e_4;
|
|
510
|
-
return __generator(this, function (_a) {
|
|
511
|
-
switch (_a.label) {
|
|
512
|
-
case 0:
|
|
513
|
-
tag = TAG + " | get_tokens | ";
|
|
514
|
-
_a.label = 1;
|
|
515
|
-
case 1:
|
|
516
|
-
_a.trys.push([1, 3, , 4]);
|
|
517
|
-
url = URL_SERVICE + "/v2/nft/user/tokens?userAddress=" + address;
|
|
518
|
-
return [4 /*yield*/, axios({
|
|
519
|
-
url: url,
|
|
520
|
-
method: 'GET',
|
|
521
|
-
})];
|
|
522
|
-
case 2:
|
|
523
|
-
result = _a.sent();
|
|
524
|
-
return [2 /*return*/, result.data];
|
|
525
|
-
case 3:
|
|
526
|
-
e_4 = _a.sent();
|
|
527
|
-
console.error(tag, "e: ", e_4);
|
|
528
|
-
return [3 /*break*/, 4];
|
|
529
|
-
case 4: return [2 /*return*/];
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
};
|