@pioneer-platform/zapper-client 8.3.10 → 8.3.11
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/lib/index.js +86 -13
- package/package.json +5 -2
package/lib/index.js
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
https://docs.blocknative.com/webhook-api
|
|
4
4
|
|
|
5
5
|
*/
|
|
6
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
7
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
8
|
+
return cooked;
|
|
9
|
+
};
|
|
10
|
+
var __assign = (this && this.__assign) || function () {
|
|
11
|
+
__assign = Object.assign || function(t) {
|
|
12
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
13
|
+
s = arguments[i];
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
};
|
|
19
|
+
return __assign.apply(this, arguments);
|
|
20
|
+
};
|
|
6
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -47,12 +62,19 @@ var pioneer_caip_1 = require("@pioneer-platform/pioneer-caip");
|
|
|
47
62
|
var Axios = require('axios');
|
|
48
63
|
var https = require('https');
|
|
49
64
|
var API_KEY = process.env['ZAPPER_API_KEY'];
|
|
65
|
+
var API_KEY_NEW = process.env['ZAPPER_API_KEY_TIMELINE'];
|
|
50
66
|
if (!API_KEY)
|
|
51
67
|
throw Error("api key required! set env ZAPPER_API_KEY");
|
|
68
|
+
if (!API_KEY_NEW)
|
|
69
|
+
throw Error("api key required! set env ZAPPER_API_KEY_TIMELINE");
|
|
52
70
|
var axios = Axios.create();
|
|
53
71
|
var Authorization = "Basic ".concat(Buffer.from("".concat(API_KEY, ":"), "binary").toString("base64"));
|
|
54
72
|
console.log(Authorization);
|
|
55
73
|
var URL_SERVICE = "https://api.zapper.xyz";
|
|
74
|
+
// const { ApolloClient, InMemoryCache, createHttpLink, gql, HttpLink } = require('@apollo/client/core');
|
|
75
|
+
var _a = require('@apollo/client/core'), ApolloClient = _a.ApolloClient, InMemoryCache = _a.InMemoryCache, HttpLink = _a.HttpLink, gql = _a.gql;
|
|
76
|
+
var setContext = require('@apollo/client/link/context').setContext;
|
|
77
|
+
var fetch = require('node-fetch'); // Ensure node-fetch is installed
|
|
56
78
|
var axiosRetry = require('axios-retry');
|
|
57
79
|
axiosRetry(axios, {
|
|
58
80
|
retries: 3, // number of retries
|
|
@@ -79,11 +101,61 @@ module.exports = {
|
|
|
79
101
|
getTotalNetworth: function (address) {
|
|
80
102
|
return get_total_networth(address);
|
|
81
103
|
},
|
|
104
|
+
getAccountHistory: function (address) {
|
|
105
|
+
return get_account_history(address);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
var get_account_history = function (address) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
var tag, endpoint, encodedKey_1, httpLink, authLink, client, query, variables, response, e_1;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
switch (_a.label) {
|
|
113
|
+
case 0:
|
|
114
|
+
tag = "get_account_history | ";
|
|
115
|
+
_a.label = 1;
|
|
116
|
+
case 1:
|
|
117
|
+
_a.trys.push([1, 3, , 4]);
|
|
118
|
+
endpoint = "https://public.zapper.xyz/graphql";
|
|
119
|
+
encodedKey_1 = Buffer.from(API_KEY_NEW).toString('base64');
|
|
120
|
+
httpLink = new HttpLink({
|
|
121
|
+
uri: endpoint,
|
|
122
|
+
fetch: fetch,
|
|
123
|
+
});
|
|
124
|
+
authLink = setContext(function (_, _a) {
|
|
125
|
+
var headers = _a.headers;
|
|
126
|
+
return ({
|
|
127
|
+
headers: __assign(__assign({}, headers), { 'Content-Type': 'application/json', 'Authorization': "Basic ".concat(encodedKey_1) }),
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
client = new ApolloClient({
|
|
131
|
+
link: authLink.concat(httpLink),
|
|
132
|
+
cache: new InMemoryCache(),
|
|
133
|
+
});
|
|
134
|
+
query = gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n query ($addresses: [Address!], $realtimeInterpretation: Boolean, $isSigner: Boolean) {\n accountsTimeline(addresses: $addresses, realtimeInterpretation: $realtimeInterpretation, isSigner: $isSigner) {\n edges {\n node {\n transaction {\n fromUser {\n address\n displayName {\n value\n }\n }\n toUser {\n displayName {\n value\n }\n }\n }\n interpretation {\n processedDescription\n }\n app {\n name\n imgUrl\n }\n network\n timestamp\n }\n }\n }\n }\n "], ["\n query ($addresses: [Address!], $realtimeInterpretation: Boolean, $isSigner: Boolean) {\n accountsTimeline(addresses: $addresses, realtimeInterpretation: $realtimeInterpretation, isSigner: $isSigner) {\n edges {\n node {\n transaction {\n fromUser {\n address\n displayName {\n value\n }\n }\n toUser {\n displayName {\n value\n }\n }\n }\n interpretation {\n processedDescription\n }\n app {\n name\n imgUrl\n }\n network\n timestamp\n }\n }\n }\n }\n "])));
|
|
135
|
+
variables = {
|
|
136
|
+
addresses: [address],
|
|
137
|
+
realtimeInterpretation: true,
|
|
138
|
+
isSigner: true,
|
|
139
|
+
};
|
|
140
|
+
return [4 /*yield*/, client.query({ query: query, variables: variables })];
|
|
141
|
+
case 2:
|
|
142
|
+
response = _a.sent();
|
|
143
|
+
console.log("response:", response.data);
|
|
144
|
+
console.log("response:", response.data.accountsTimeline.edges);
|
|
145
|
+
return [2 /*return*/, response.data.accountsTimeline.edges];
|
|
146
|
+
case 3:
|
|
147
|
+
e_1 = _a.sent();
|
|
148
|
+
console.error(tag, "Error: ", e_1);
|
|
149
|
+
return [2 /*return*/, null];
|
|
150
|
+
case 4: return [2 /*return*/];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
82
154
|
};
|
|
83
155
|
var get_portfolio = function (address) {
|
|
84
156
|
var _a, _b;
|
|
85
157
|
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
var tag, output_1, appsResponse, apps, totalBalanceUSDApp_1, i, app, j, product, k, asset, l, token, balance, tokensResponse, totalBalanceUsdTokens_1, tokens, limit, allTokens, cursor, url, response, tokens, error_1, nftResponse, nftUsdNetWorth, totalNetWorth,
|
|
158
|
+
var tag, output_1, appsResponse, apps, totalBalanceUSDApp_1, i, app, j, product, k, asset, l, token, balance, tokensResponse, totalBalanceUsdTokens_1, tokens, limit, allTokens, cursor, url, response, tokens, error_1, nftResponse, nftUsdNetWorth, totalNetWorth, e_2;
|
|
87
159
|
return __generator(this, function (_c) {
|
|
88
160
|
switch (_c.label) {
|
|
89
161
|
case 0:
|
|
@@ -127,7 +199,7 @@ var get_portfolio = function (address) {
|
|
|
127
199
|
balance.caip = balance.networkId + "/erc20:" + token.address;
|
|
128
200
|
}
|
|
129
201
|
else {
|
|
130
|
-
balance.caip = balance.networkId + 'slip44:60';
|
|
202
|
+
balance.caip = balance.networkId + '/slip44:60';
|
|
131
203
|
}
|
|
132
204
|
balance.metaType = token.metaType || product.metaType;
|
|
133
205
|
balance.name = asset.displayProps.label;
|
|
@@ -252,8 +324,8 @@ var get_portfolio = function (address) {
|
|
|
252
324
|
output_1.totalNetWorth = totalNetWorth;
|
|
253
325
|
return [2 /*return*/, output_1];
|
|
254
326
|
case 11:
|
|
255
|
-
|
|
256
|
-
console.error(tag, "e: ",
|
|
327
|
+
e_2 = _c.sent();
|
|
328
|
+
console.error(tag, "e: ", e_2);
|
|
257
329
|
return [3 /*break*/, 12];
|
|
258
330
|
case 12: return [2 /*return*/];
|
|
259
331
|
}
|
|
@@ -262,7 +334,7 @@ var get_portfolio = function (address) {
|
|
|
262
334
|
};
|
|
263
335
|
var get_total_networth = function (address) {
|
|
264
336
|
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
-
var tag, appsResponse, apps, totalBalanceUSDApp_2, tokensResponse, tokens, totalBalanceUsdTokens_2, nftResponse, nftUsdNetWorth, totalNetWorth,
|
|
337
|
+
var tag, appsResponse, apps, totalBalanceUSDApp_2, tokensResponse, tokens, totalBalanceUsdTokens_2, nftResponse, nftUsdNetWorth, totalNetWorth, e_3;
|
|
266
338
|
return __generator(this, function (_a) {
|
|
267
339
|
switch (_a.label) {
|
|
268
340
|
case 0:
|
|
@@ -321,8 +393,8 @@ var get_total_networth = function (address) {
|
|
|
321
393
|
log.debug("totalNetWorth: ", totalNetWorth);
|
|
322
394
|
return [2 /*return*/, totalNetWorth];
|
|
323
395
|
case 5:
|
|
324
|
-
|
|
325
|
-
console.error(tag, "e: ",
|
|
396
|
+
e_3 = _a.sent();
|
|
397
|
+
console.error(tag, "e: ", e_3);
|
|
326
398
|
return [3 /*break*/, 6];
|
|
327
399
|
case 6: return [2 /*return*/];
|
|
328
400
|
}
|
|
@@ -331,7 +403,7 @@ var get_total_networth = function (address) {
|
|
|
331
403
|
};
|
|
332
404
|
var get_tokens = function (address) {
|
|
333
405
|
return __awaiter(this, void 0, void 0, function () {
|
|
334
|
-
var tag, apiKey, appsResponse,
|
|
406
|
+
var tag, apiKey, appsResponse, e_4;
|
|
335
407
|
return __generator(this, function (_a) {
|
|
336
408
|
switch (_a.label) {
|
|
337
409
|
case 0:
|
|
@@ -371,8 +443,8 @@ var get_tokens = function (address) {
|
|
|
371
443
|
// },headers)
|
|
372
444
|
return [2 /*return*/, appsResponse.data];
|
|
373
445
|
case 3:
|
|
374
|
-
|
|
375
|
-
console.error(tag, "e: ",
|
|
446
|
+
e_4 = _a.sent();
|
|
447
|
+
console.error(tag, "e: ", e_4);
|
|
376
448
|
return [3 /*break*/, 4];
|
|
377
449
|
case 4: return [2 /*return*/];
|
|
378
450
|
}
|
|
@@ -381,7 +453,7 @@ var get_tokens = function (address) {
|
|
|
381
453
|
};
|
|
382
454
|
var get_nfts = function (address) {
|
|
383
455
|
return __awaiter(this, void 0, void 0, function () {
|
|
384
|
-
var tag, url, result,
|
|
456
|
+
var tag, url, result, e_5;
|
|
385
457
|
return __generator(this, function (_a) {
|
|
386
458
|
switch (_a.label) {
|
|
387
459
|
case 0:
|
|
@@ -398,11 +470,12 @@ var get_nfts = function (address) {
|
|
|
398
470
|
result = _a.sent();
|
|
399
471
|
return [2 /*return*/, result.data];
|
|
400
472
|
case 3:
|
|
401
|
-
|
|
402
|
-
console.error(tag, "e: ",
|
|
473
|
+
e_5 = _a.sent();
|
|
474
|
+
console.error(tag, "e: ", e_5);
|
|
403
475
|
return [3 /*break*/, 4];
|
|
404
476
|
case 4: return [2 /*return*/];
|
|
405
477
|
}
|
|
406
478
|
});
|
|
407
479
|
});
|
|
408
480
|
};
|
|
481
|
+
var templateObject_1;
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/zapper-client",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.11",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"@apollo/client": "^3.12.4",
|
|
7
8
|
"@pioneer-platform/loggerdog": "^8.3.1",
|
|
8
9
|
"@pioneer-platform/pioneer-caip": "^9.2.36",
|
|
9
10
|
"axios": "^1.3.4",
|
|
10
|
-
"dotenv": "^8.2.0"
|
|
11
|
+
"dotenv": "^8.2.0",
|
|
12
|
+
"graphql": "^16.10.0",
|
|
13
|
+
"node-fetch": "2"
|
|
11
14
|
},
|
|
12
15
|
"scripts": {
|
|
13
16
|
"npm": "npm i",
|