@pioneer-platform/zapper-client 8.1.18
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.d.ts +11 -0
- package/lib/index.js +311 -0
- package/package.json +30 -0
- package/tsconfig.json +13 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const TAG = " | blocknative | ";
|
|
2
|
+
declare const Axios: any;
|
|
3
|
+
declare const https: any;
|
|
4
|
+
declare let API_KEY: string | undefined;
|
|
5
|
+
declare const axios: any;
|
|
6
|
+
declare const Authorization: string;
|
|
7
|
+
declare let URL_SERVICE: string;
|
|
8
|
+
declare const get_portfolio: (address: string) => Promise<any>;
|
|
9
|
+
declare const get_total_networth: (address: string) => Promise<number | undefined>;
|
|
10
|
+
declare const get_tokens: (address: string) => Promise<any>;
|
|
11
|
+
declare const get_nfts: (address: string) => Promise<any>;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
https://docs.blocknative.com/webhook-api
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
17
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
+
function step(op) {
|
|
20
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
+
while (_) try {
|
|
22
|
+
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;
|
|
23
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
+
switch (op[0]) {
|
|
25
|
+
case 0: case 1: t = op; break;
|
|
26
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
+
default:
|
|
30
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
+
if (t[2]) _.ops.pop();
|
|
35
|
+
_.trys.pop(); continue;
|
|
36
|
+
}
|
|
37
|
+
op = body.call(thisArg, _);
|
|
38
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var TAG = " | blocknative | ";
|
|
43
|
+
var Axios = require('axios');
|
|
44
|
+
var https = require('https');
|
|
45
|
+
var API_KEY = process.env['ZAPPER_API_KEY'];
|
|
46
|
+
if (!API_KEY)
|
|
47
|
+
throw Error("api key required! set env ZAPPER_API_KEY");
|
|
48
|
+
var axios = Axios.create();
|
|
49
|
+
var Authorization = "Basic " + Buffer.from(API_KEY + ":", "binary").toString("base64");
|
|
50
|
+
var URL_SERVICE = "https://api.zapper.xyz";
|
|
51
|
+
module.exports = {
|
|
52
|
+
getTokens: function (address) {
|
|
53
|
+
return get_tokens(address);
|
|
54
|
+
},
|
|
55
|
+
getNFTs: function (address) {
|
|
56
|
+
return get_nfts(address);
|
|
57
|
+
},
|
|
58
|
+
getPortfolio: function (address) {
|
|
59
|
+
return get_portfolio(address);
|
|
60
|
+
},
|
|
61
|
+
getTotalNetworth: function (address) {
|
|
62
|
+
return get_total_networth(address);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
var get_portfolio = function (address) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
var tag, output, appsResponse, apps, totalBalanceUSDApp_1, tokensResponse, tokens, totalBalanceUsdTokens_1, limit, allTokens, cursor, url, response, tokens_1, error_1, nftResponse, nftUsdNetWorth, totalNetWorth, e_1;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
tag = TAG + " | get_portfolio | ";
|
|
72
|
+
_a.label = 1;
|
|
73
|
+
case 1:
|
|
74
|
+
_a.trys.push([1, 11, , 12]);
|
|
75
|
+
output = {};
|
|
76
|
+
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=" + address, {
|
|
77
|
+
headers: {
|
|
78
|
+
accept: "*/*",
|
|
79
|
+
Authorization: Authorization,
|
|
80
|
+
},
|
|
81
|
+
})];
|
|
82
|
+
case 2:
|
|
83
|
+
appsResponse = _a.sent();
|
|
84
|
+
apps = appsResponse.data;
|
|
85
|
+
totalBalanceUSDApp_1 = 0;
|
|
86
|
+
apps.forEach(function (app) {
|
|
87
|
+
totalBalanceUSDApp_1 += app.balanceUSD;
|
|
88
|
+
});
|
|
89
|
+
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/tokens?addresses%5B%5D=" + address, {
|
|
90
|
+
headers: {
|
|
91
|
+
accept: "*/*",
|
|
92
|
+
Authorization: Authorization,
|
|
93
|
+
},
|
|
94
|
+
})];
|
|
95
|
+
case 3:
|
|
96
|
+
tokensResponse = _a.sent();
|
|
97
|
+
tokens = tokensResponse.data;
|
|
98
|
+
totalBalanceUsdTokens_1 = 0;
|
|
99
|
+
tokens = tokens[address.toLowerCase()];
|
|
100
|
+
output.tokens = tokens;
|
|
101
|
+
console.log("tokens: ", tokens);
|
|
102
|
+
if (tokens) {
|
|
103
|
+
tokens.forEach(function (token) {
|
|
104
|
+
console.log("token: ", token);
|
|
105
|
+
console.log("token.balanceUSD: ", token.token.balanceUSD);
|
|
106
|
+
totalBalanceUsdTokens_1 += token.token.balanceUSD;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
limit = 100;
|
|
110
|
+
allTokens = [];
|
|
111
|
+
cursor = null;
|
|
112
|
+
_a.label = 4;
|
|
113
|
+
case 4:
|
|
114
|
+
if (!true) return [3 /*break*/, 9];
|
|
115
|
+
_a.label = 5;
|
|
116
|
+
case 5:
|
|
117
|
+
_a.trys.push([5, 7, , 8]);
|
|
118
|
+
url = "https://api.zapper.xyz/v2/nft/user/tokens?userAddress=" + address + "&limit=" + limit;
|
|
119
|
+
if (cursor) {
|
|
120
|
+
url += "&cursor=" + cursor;
|
|
121
|
+
}
|
|
122
|
+
return [4 /*yield*/, Axios.get(url, {
|
|
123
|
+
headers: {
|
|
124
|
+
accept: "*/*",
|
|
125
|
+
Authorization: Authorization,
|
|
126
|
+
},
|
|
127
|
+
})];
|
|
128
|
+
case 6:
|
|
129
|
+
response = _a.sent();
|
|
130
|
+
tokens_1 = response.data;
|
|
131
|
+
console.log("tokens: ", tokens_1);
|
|
132
|
+
allTokens = allTokens.concat(tokens_1.items);
|
|
133
|
+
cursor = response.data.cursor;
|
|
134
|
+
if (!cursor) {
|
|
135
|
+
return [3 /*break*/, 9];
|
|
136
|
+
}
|
|
137
|
+
return [3 /*break*/, 8];
|
|
138
|
+
case 7:
|
|
139
|
+
error_1 = _a.sent();
|
|
140
|
+
console.error(error_1);
|
|
141
|
+
return [3 /*break*/, 8];
|
|
142
|
+
case 8: return [3 /*break*/, 4];
|
|
143
|
+
case 9:
|
|
144
|
+
output.nfts = allTokens;
|
|
145
|
+
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/nft/balances/net-worth?addresses%5B%5D=" + address, {
|
|
146
|
+
headers: {
|
|
147
|
+
accept: "*/*",
|
|
148
|
+
Authorization: Authorization,
|
|
149
|
+
},
|
|
150
|
+
})];
|
|
151
|
+
case 10:
|
|
152
|
+
nftResponse = _a.sent();
|
|
153
|
+
nftUsdNetWorth = nftResponse.data;
|
|
154
|
+
output.nftUsdNetWorth = nftUsdNetWorth;
|
|
155
|
+
output.totalBalanceUsdTokens = totalBalanceUsdTokens_1;
|
|
156
|
+
output.totalBalanceUSDApp = totalBalanceUSDApp_1;
|
|
157
|
+
totalNetWorth = totalBalanceUSDApp_1 + totalBalanceUsdTokens_1 + parseFloat(nftUsdNetWorth[address.toLowerCase()]);
|
|
158
|
+
// console.log("totalNetWorth: ",totalNetWorth);
|
|
159
|
+
output.totalNetWorth = totalNetWorth;
|
|
160
|
+
return [2 /*return*/, output];
|
|
161
|
+
case 11:
|
|
162
|
+
e_1 = _a.sent();
|
|
163
|
+
console.error(tag, "e: ", e_1);
|
|
164
|
+
return [3 /*break*/, 12];
|
|
165
|
+
case 12: return [2 /*return*/];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
var get_total_networth = function (address) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
+
var tag, appsResponse, apps, totalBalanceUSDApp_2, tokensResponse, tokens, totalBalanceUsdTokens_2, nftResponse, nftUsdNetWorth, totalNetWorth, e_2;
|
|
173
|
+
return __generator(this, function (_a) {
|
|
174
|
+
switch (_a.label) {
|
|
175
|
+
case 0:
|
|
176
|
+
tag = TAG + " | get_tokens | ";
|
|
177
|
+
_a.label = 1;
|
|
178
|
+
case 1:
|
|
179
|
+
_a.trys.push([1, 5, , 6]);
|
|
180
|
+
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=" + address, {
|
|
181
|
+
headers: {
|
|
182
|
+
accept: "*/*",
|
|
183
|
+
Authorization: Authorization,
|
|
184
|
+
},
|
|
185
|
+
})];
|
|
186
|
+
case 2:
|
|
187
|
+
appsResponse = _a.sent();
|
|
188
|
+
apps = appsResponse.data;
|
|
189
|
+
totalBalanceUSDApp_2 = 0;
|
|
190
|
+
apps.forEach(function (app) {
|
|
191
|
+
totalBalanceUSDApp_2 += app.balanceUSD;
|
|
192
|
+
});
|
|
193
|
+
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/tokens?addresses%5B%5D=" + address, {
|
|
194
|
+
headers: {
|
|
195
|
+
accept: "*/*",
|
|
196
|
+
Authorization: Authorization,
|
|
197
|
+
},
|
|
198
|
+
})];
|
|
199
|
+
case 3:
|
|
200
|
+
tokensResponse = _a.sent();
|
|
201
|
+
console.log("tokensResponse: ", tokensResponse.data);
|
|
202
|
+
tokens = tokensResponse.data;
|
|
203
|
+
totalBalanceUsdTokens_2 = 0;
|
|
204
|
+
tokens = tokens[address.toLowerCase()];
|
|
205
|
+
// console.log("tokens: ",tokens)
|
|
206
|
+
tokens.forEach(function (token) {
|
|
207
|
+
console.log("token: ", token);
|
|
208
|
+
console.log("token.balanceUSD: ", token.token.balanceUSD);
|
|
209
|
+
totalBalanceUsdTokens_2 += token.token.balanceUSD;
|
|
210
|
+
});
|
|
211
|
+
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/nft/balances/net-worth?addresses%5B%5D=" + address, {
|
|
212
|
+
headers: {
|
|
213
|
+
accept: "*/*",
|
|
214
|
+
Authorization: Authorization,
|
|
215
|
+
},
|
|
216
|
+
})];
|
|
217
|
+
case 4:
|
|
218
|
+
nftResponse = _a.sent();
|
|
219
|
+
nftUsdNetWorth = nftResponse.data;
|
|
220
|
+
console.log("nftUsdNetWorth: ", nftUsdNetWorth);
|
|
221
|
+
console.log("totalBalanceUsdTokens: ", totalBalanceUsdTokens_2);
|
|
222
|
+
console.log("totalBalanceUSDApp: ", totalBalanceUSDApp_2);
|
|
223
|
+
totalNetWorth = totalBalanceUSDApp_2 + totalBalanceUsdTokens_2 + parseFloat(nftUsdNetWorth[address.toLowerCase()]);
|
|
224
|
+
console.log("totalNetWorth: ", totalNetWorth);
|
|
225
|
+
return [2 /*return*/, totalNetWorth];
|
|
226
|
+
case 5:
|
|
227
|
+
e_2 = _a.sent();
|
|
228
|
+
console.error(tag, "e: ", e_2);
|
|
229
|
+
return [3 /*break*/, 6];
|
|
230
|
+
case 6: return [2 /*return*/];
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
var get_tokens = function (address) {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
237
|
+
var tag, apiKey, appsResponse, e_3;
|
|
238
|
+
return __generator(this, function (_a) {
|
|
239
|
+
switch (_a.label) {
|
|
240
|
+
case 0:
|
|
241
|
+
tag = TAG + " | get_tokens | ";
|
|
242
|
+
_a.label = 1;
|
|
243
|
+
case 1:
|
|
244
|
+
_a.trys.push([1, 3, , 4]);
|
|
245
|
+
apiKey = API_KEY;
|
|
246
|
+
console.log(Authorization);
|
|
247
|
+
return [4 /*yield*/, Axios.get("https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=" + address, {
|
|
248
|
+
headers: {
|
|
249
|
+
accept: "*/*",
|
|
250
|
+
Authorization: Authorization,
|
|
251
|
+
},
|
|
252
|
+
})];
|
|
253
|
+
case 2:
|
|
254
|
+
appsResponse = _a.sent();
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
// const appsResponse = await Axios.get(
|
|
257
|
+
// `https://api.zapper.xyz/v2/balances/apps?addresses%5B%5D=${address}`,
|
|
258
|
+
// {
|
|
259
|
+
// headers: {
|
|
260
|
+
// accept: "*/*",
|
|
261
|
+
// Authorization,
|
|
262
|
+
// },
|
|
263
|
+
// }
|
|
264
|
+
// );
|
|
265
|
+
// let url = URL_SERVICE + "/v2/balances/apps?addresses=" + address+",api_key="+API_KEY
|
|
266
|
+
// const headers = {
|
|
267
|
+
// headers: {
|
|
268
|
+
// "Authorization": "Bearer "+process.env['ZAPPER_API_KEY'],
|
|
269
|
+
// }
|
|
270
|
+
// }
|
|
271
|
+
// let result = await axios({
|
|
272
|
+
// url,
|
|
273
|
+
// method: 'GET'
|
|
274
|
+
// },headers)
|
|
275
|
+
return [2 /*return*/, appsResponse.data];
|
|
276
|
+
case 3:
|
|
277
|
+
e_3 = _a.sent();
|
|
278
|
+
console.error(tag, "e: ", e_3);
|
|
279
|
+
return [3 /*break*/, 4];
|
|
280
|
+
case 4: return [2 /*return*/];
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
var get_nfts = function (address) {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
+
var tag, url, result, e_4;
|
|
288
|
+
return __generator(this, function (_a) {
|
|
289
|
+
switch (_a.label) {
|
|
290
|
+
case 0:
|
|
291
|
+
tag = TAG + " | get_tokens | ";
|
|
292
|
+
_a.label = 1;
|
|
293
|
+
case 1:
|
|
294
|
+
_a.trys.push([1, 3, , 4]);
|
|
295
|
+
url = URL_SERVICE + "v2/nft/user/tokens?userAddress=" + address;
|
|
296
|
+
return [4 /*yield*/, axios({
|
|
297
|
+
url: url,
|
|
298
|
+
method: 'GET'
|
|
299
|
+
})];
|
|
300
|
+
case 2:
|
|
301
|
+
result = _a.sent();
|
|
302
|
+
return [2 /*return*/, result.data];
|
|
303
|
+
case 3:
|
|
304
|
+
e_4 = _a.sent();
|
|
305
|
+
console.error(tag, "e: ", e_4);
|
|
306
|
+
return [3 /*break*/, 4];
|
|
307
|
+
case 4: return [2 /*return*/];
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pioneer-platform/zapper-client",
|
|
3
|
+
"version": "8.1.18",
|
|
4
|
+
"main": "./lib/index.js",
|
|
5
|
+
"types": "./lib/index.d.ts",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@pioneer-platform/loggerdog": "^8.1.17",
|
|
8
|
+
"axios": "^0.21.1",
|
|
9
|
+
"dotenv": "^8.2.0"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"npm": "npm i",
|
|
13
|
+
"test": "npm run build && node __tests__/test-module.js",
|
|
14
|
+
"build": "tsc -p .",
|
|
15
|
+
"prepublish": "npm run build",
|
|
16
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && npm install"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/jest": "^25.2.3",
|
|
20
|
+
"@types/node": "^13.13.21",
|
|
21
|
+
"@types/source-map-support": "^0.5.3",
|
|
22
|
+
"jest": "^26.4.2",
|
|
23
|
+
"onchange": "^7.0.2",
|
|
24
|
+
"serve": "^11.3.2",
|
|
25
|
+
"source-map-support": "^0.5.19",
|
|
26
|
+
"ts-jest": "^25.4.0",
|
|
27
|
+
"typescript": "^3.9.7"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "d0e74ea447175d6d7e9697793093f9155f0dab38"
|
|
30
|
+
}
|
package/tsconfig.json
ADDED