@pioneer-platform/zapper-client 8.3.10 → 8.3.12

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.
Files changed (2) hide show
  1. package/lib/index.js +111 -13
  2. 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,86 @@ 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, cleanResponse, 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 hash\n fromUser {\n address\n displayName {\n value\n }\n }\n toUser {\n address\n displayName {\n value\n }\n }\n input\n value\n gasPrice\n gas\n }\n interpretation {\n processedDescription\n }\n app {\n name\n imgUrl\n }\n network\n timestamp\n similarEventCount\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 hash\n fromUser {\n address\n displayName {\n value\n }\n }\n toUser {\n address\n displayName {\n value\n }\n }\n input\n value\n gasPrice\n gas\n }\n interpretation {\n processedDescription\n }\n app {\n name\n imgUrl\n }\n network\n timestamp\n similarEventCount\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
+ cleanResponse = response.data.accountsTimeline.edges.map(function (edge) {
144
+ var _a = edge.node, _b = _a.transaction, hash = _b.hash, fromUser = _b.fromUser, toUser = _b.toUser, input = _b.input, value = _b.value, gasPrice = _b.gasPrice, gas = _b.gas, processedDescription = _a.interpretation.processedDescription, app = _a.app, network = _a.network, timestamp = _a.timestamp, similarEventCount = _a.similarEventCount;
145
+ return {
146
+ txid: hash,
147
+ from: {
148
+ address: fromUser.address,
149
+ displayName: fromUser.displayName.value,
150
+ },
151
+ to: toUser ? {
152
+ address: toUser.address,
153
+ displayName: toUser.displayName.value,
154
+ } : null,
155
+ description: processedDescription,
156
+ app: app ? {
157
+ name: app.name,
158
+ imgUrl: app.imgUrl,
159
+ } : null,
160
+ network: network,
161
+ timestamp: new Date(timestamp).toISOString(),
162
+ input: input,
163
+ value: value,
164
+ gasPrice: gasPrice,
165
+ gas: gas,
166
+ similarEventCount: similarEventCount
167
+ };
168
+ });
169
+ console.log("Cleaned response:", cleanResponse);
170
+ return [2 /*return*/, cleanResponse];
171
+ case 3:
172
+ e_1 = _a.sent();
173
+ console.error(tag, "Error: ", e_1);
174
+ return [2 /*return*/, null];
175
+ case 4: return [2 /*return*/];
176
+ }
177
+ });
178
+ });
82
179
  };
83
180
  var get_portfolio = function (address) {
84
181
  var _a, _b;
85
182
  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, e_1;
183
+ 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
184
  return __generator(this, function (_c) {
88
185
  switch (_c.label) {
89
186
  case 0:
@@ -127,7 +224,7 @@ var get_portfolio = function (address) {
127
224
  balance.caip = balance.networkId + "/erc20:" + token.address;
128
225
  }
129
226
  else {
130
- balance.caip = balance.networkId + 'slip44:60';
227
+ balance.caip = balance.networkId + '/slip44:60';
131
228
  }
132
229
  balance.metaType = token.metaType || product.metaType;
133
230
  balance.name = asset.displayProps.label;
@@ -252,8 +349,8 @@ var get_portfolio = function (address) {
252
349
  output_1.totalNetWorth = totalNetWorth;
253
350
  return [2 /*return*/, output_1];
254
351
  case 11:
255
- e_1 = _c.sent();
256
- console.error(tag, "e: ", e_1);
352
+ e_2 = _c.sent();
353
+ console.error(tag, "e: ", e_2);
257
354
  return [3 /*break*/, 12];
258
355
  case 12: return [2 /*return*/];
259
356
  }
@@ -262,7 +359,7 @@ var get_portfolio = function (address) {
262
359
  };
263
360
  var get_total_networth = function (address) {
264
361
  return __awaiter(this, void 0, void 0, function () {
265
- var tag, appsResponse, apps, totalBalanceUSDApp_2, tokensResponse, tokens, totalBalanceUsdTokens_2, nftResponse, nftUsdNetWorth, totalNetWorth, e_2;
362
+ var tag, appsResponse, apps, totalBalanceUSDApp_2, tokensResponse, tokens, totalBalanceUsdTokens_2, nftResponse, nftUsdNetWorth, totalNetWorth, e_3;
266
363
  return __generator(this, function (_a) {
267
364
  switch (_a.label) {
268
365
  case 0:
@@ -321,8 +418,8 @@ var get_total_networth = function (address) {
321
418
  log.debug("totalNetWorth: ", totalNetWorth);
322
419
  return [2 /*return*/, totalNetWorth];
323
420
  case 5:
324
- e_2 = _a.sent();
325
- console.error(tag, "e: ", e_2);
421
+ e_3 = _a.sent();
422
+ console.error(tag, "e: ", e_3);
326
423
  return [3 /*break*/, 6];
327
424
  case 6: return [2 /*return*/];
328
425
  }
@@ -331,7 +428,7 @@ var get_total_networth = function (address) {
331
428
  };
332
429
  var get_tokens = function (address) {
333
430
  return __awaiter(this, void 0, void 0, function () {
334
- var tag, apiKey, appsResponse, e_3;
431
+ var tag, apiKey, appsResponse, e_4;
335
432
  return __generator(this, function (_a) {
336
433
  switch (_a.label) {
337
434
  case 0:
@@ -371,8 +468,8 @@ var get_tokens = function (address) {
371
468
  // },headers)
372
469
  return [2 /*return*/, appsResponse.data];
373
470
  case 3:
374
- e_3 = _a.sent();
375
- console.error(tag, "e: ", e_3);
471
+ e_4 = _a.sent();
472
+ console.error(tag, "e: ", e_4);
376
473
  return [3 /*break*/, 4];
377
474
  case 4: return [2 /*return*/];
378
475
  }
@@ -381,7 +478,7 @@ var get_tokens = function (address) {
381
478
  };
382
479
  var get_nfts = function (address) {
383
480
  return __awaiter(this, void 0, void 0, function () {
384
- var tag, url, result, e_4;
481
+ var tag, url, result, e_5;
385
482
  return __generator(this, function (_a) {
386
483
  switch (_a.label) {
387
484
  case 0:
@@ -398,11 +495,12 @@ var get_nfts = function (address) {
398
495
  result = _a.sent();
399
496
  return [2 /*return*/, result.data];
400
497
  case 3:
401
- e_4 = _a.sent();
402
- console.error(tag, "e: ", e_4);
498
+ e_5 = _a.sent();
499
+ console.error(tag, "e: ", e_5);
403
500
  return [3 /*break*/, 4];
404
501
  case 4: return [2 /*return*/];
405
502
  }
406
503
  });
407
504
  });
408
505
  };
506
+ var templateObject_1;
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@pioneer-platform/zapper-client",
3
- "version": "8.3.10",
3
+ "version": "8.3.12",
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",