@pioneer-platform/zapper-client 8.3.9 → 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.
Files changed (2) hide show
  1. package/lib/index.js +117 -36
  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,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, e_1;
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:
@@ -123,7 +195,12 @@ var get_portfolio = function (address) {
123
195
  balance.balance = token === null || token === void 0 ? void 0 : token.balance.toString();
124
196
  balance.chain = app.network;
125
197
  balance.networkId = pioneer_caip_1.evmCaips[app.network].split('/')[0];
126
- balance.caip = balance.networkId + "/erc20:" + token.address;
198
+ if (token.type !== 'base-token' && token.address !== '0x0000000000000000000000000000000000000000') {
199
+ balance.caip = balance.networkId + "/erc20:" + token.address;
200
+ }
201
+ else {
202
+ balance.caip = balance.networkId + '/slip44:60';
203
+ }
127
204
  balance.metaType = token.metaType || product.metaType;
128
205
  balance.name = asset.displayProps.label;
129
206
  balance.appId = app.appId;
@@ -158,33 +235,36 @@ var get_portfolio = function (address) {
158
235
  tokens.forEach(function (token) {
159
236
  log.debug(tag, "token: ", token);
160
237
  var network = token.network;
161
- log.debug(tag, "network: ", token);
238
+ log.debug(tag, "network: ", network);
162
239
  var caip = pioneer_caip_1.evmCaips[network];
163
- if (!caip)
164
- throw Error("no caip for network: " + network);
165
- token.networkId = caip.split('/')[0];
166
- if (token.token.address !== '0x0000000000000000000000000000000000000000') {
167
- token.assetCaip = token.networkId + "/erc20:" + token.token.address;
240
+ if (caip) {
241
+ token.networkId = caip.split('/')[0];
242
+ if (token.token.address !== '0x0000000000000000000000000000000000000000') {
243
+ token.assetCaip = token.networkId + "/erc20:" + token.token.address;
244
+ }
245
+ else {
246
+ token.assetCaip = caip;
247
+ }
248
+ var balance = {
249
+ balance: token.token.balance.toString(),
250
+ networkId: token.networkId,
251
+ chain: token.network,
252
+ caip: token.assetCaip,
253
+ type: 'erc20',
254
+ name: token.token.name,
255
+ symbol: token.token.symbol,
256
+ ticker: token.token.symbol,
257
+ decimals: token.token.decimals,
258
+ priceUsd: token.token.price,
259
+ valueUsd: token.token.balanceUSD.toString(),
260
+ };
261
+ output_1.balances.push(balance);
262
+ log.debug(tag, "token.balanceUSD: ", token.token.balanceUSD);
263
+ totalBalanceUsdTokens_1 += token.token.balanceUSD;
168
264
  }
169
265
  else {
170
- token.assetCaip = caip;
266
+ log.error(tag, "No caip found for network: ", network);
171
267
  }
172
- var balance = {
173
- balance: token.token.balance.toString(),
174
- networkId: token.networkId,
175
- chain: token.network,
176
- caip: token.assetCaip,
177
- type: 'erc20',
178
- name: token.token.name,
179
- symbol: token.token.symbol,
180
- ticker: token.token.symbol,
181
- decimals: token.token.decimals,
182
- priceUsd: token.token.price,
183
- valueUsd: token.token.balanceUSD.toString(),
184
- };
185
- output_1.balances.push(balance);
186
- log.debug(tag, "token.balanceUSD: ", token.token.balanceUSD);
187
- totalBalanceUsdTokens_1 += token.token.balanceUSD;
188
268
  });
189
269
  }
190
270
  }
@@ -244,8 +324,8 @@ var get_portfolio = function (address) {
244
324
  output_1.totalNetWorth = totalNetWorth;
245
325
  return [2 /*return*/, output_1];
246
326
  case 11:
247
- e_1 = _c.sent();
248
- console.error(tag, "e: ", e_1);
327
+ e_2 = _c.sent();
328
+ console.error(tag, "e: ", e_2);
249
329
  return [3 /*break*/, 12];
250
330
  case 12: return [2 /*return*/];
251
331
  }
@@ -254,7 +334,7 @@ var get_portfolio = function (address) {
254
334
  };
255
335
  var get_total_networth = function (address) {
256
336
  return __awaiter(this, void 0, void 0, function () {
257
- var tag, appsResponse, apps, totalBalanceUSDApp_2, tokensResponse, tokens, totalBalanceUsdTokens_2, nftResponse, nftUsdNetWorth, totalNetWorth, e_2;
337
+ var tag, appsResponse, apps, totalBalanceUSDApp_2, tokensResponse, tokens, totalBalanceUsdTokens_2, nftResponse, nftUsdNetWorth, totalNetWorth, e_3;
258
338
  return __generator(this, function (_a) {
259
339
  switch (_a.label) {
260
340
  case 0:
@@ -313,8 +393,8 @@ var get_total_networth = function (address) {
313
393
  log.debug("totalNetWorth: ", totalNetWorth);
314
394
  return [2 /*return*/, totalNetWorth];
315
395
  case 5:
316
- e_2 = _a.sent();
317
- console.error(tag, "e: ", e_2);
396
+ e_3 = _a.sent();
397
+ console.error(tag, "e: ", e_3);
318
398
  return [3 /*break*/, 6];
319
399
  case 6: return [2 /*return*/];
320
400
  }
@@ -323,7 +403,7 @@ var get_total_networth = function (address) {
323
403
  };
324
404
  var get_tokens = function (address) {
325
405
  return __awaiter(this, void 0, void 0, function () {
326
- var tag, apiKey, appsResponse, e_3;
406
+ var tag, apiKey, appsResponse, e_4;
327
407
  return __generator(this, function (_a) {
328
408
  switch (_a.label) {
329
409
  case 0:
@@ -363,8 +443,8 @@ var get_tokens = function (address) {
363
443
  // },headers)
364
444
  return [2 /*return*/, appsResponse.data];
365
445
  case 3:
366
- e_3 = _a.sent();
367
- console.error(tag, "e: ", e_3);
446
+ e_4 = _a.sent();
447
+ console.error(tag, "e: ", e_4);
368
448
  return [3 /*break*/, 4];
369
449
  case 4: return [2 /*return*/];
370
450
  }
@@ -373,7 +453,7 @@ var get_tokens = function (address) {
373
453
  };
374
454
  var get_nfts = function (address) {
375
455
  return __awaiter(this, void 0, void 0, function () {
376
- var tag, url, result, e_4;
456
+ var tag, url, result, e_5;
377
457
  return __generator(this, function (_a) {
378
458
  switch (_a.label) {
379
459
  case 0:
@@ -390,11 +470,12 @@ var get_nfts = function (address) {
390
470
  result = _a.sent();
391
471
  return [2 /*return*/, result.data];
392
472
  case 3:
393
- e_4 = _a.sent();
394
- console.error(tag, "e: ", e_4);
473
+ e_5 = _a.sent();
474
+ console.error(tag, "e: ", e_5);
395
475
  return [3 /*break*/, 4];
396
476
  case 4: return [2 /*return*/];
397
477
  }
398
478
  });
399
479
  });
400
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.9",
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",