@pioneer-platform/pioneer-sdk 4.20.6 → 4.20.8
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/dist/index.cjs +480 -82
- package/dist/index.es.js +481 -83
- package/dist/index.js +481 -83
- package/package.json +6 -6
- package/src/index.ts +2 -79
- package/src/utils/sync-market.ts +86 -0
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,398 @@ var __export = (target, all) => {
|
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
// node_modules/@pioneer-platform/pioneer-client/lib/index.js
|
|
44
|
+
var require_lib = __commonJS((exports2) => {
|
|
45
|
+
var __assign = exports2 && exports2.__assign || function() {
|
|
46
|
+
__assign = Object.assign || function(t) {
|
|
47
|
+
for (var s, i = 1, n = arguments.length;i < n; i++) {
|
|
48
|
+
s = arguments[i];
|
|
49
|
+
for (var p in s)
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
51
|
+
t[p] = s[p];
|
|
52
|
+
}
|
|
53
|
+
return t;
|
|
54
|
+
};
|
|
55
|
+
return __assign.apply(this, arguments);
|
|
56
|
+
};
|
|
57
|
+
var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
58
|
+
function adopt(value) {
|
|
59
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
60
|
+
resolve(value);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
64
|
+
function fulfilled(value) {
|
|
65
|
+
try {
|
|
66
|
+
step(generator.next(value));
|
|
67
|
+
} catch (e) {
|
|
68
|
+
reject(e);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function rejected(value) {
|
|
72
|
+
try {
|
|
73
|
+
step(generator["throw"](value));
|
|
74
|
+
} catch (e) {
|
|
75
|
+
reject(e);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function step(result) {
|
|
79
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
80
|
+
}
|
|
81
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
var __generator = exports2 && exports2.__generator || function(thisArg, body) {
|
|
85
|
+
var _ = { label: 0, sent: function() {
|
|
86
|
+
if (t[0] & 1)
|
|
87
|
+
throw t[1];
|
|
88
|
+
return t[1];
|
|
89
|
+
}, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
90
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
91
|
+
return this;
|
|
92
|
+
}), g;
|
|
93
|
+
function verb(n) {
|
|
94
|
+
return function(v) {
|
|
95
|
+
return step([n, v]);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function step(op) {
|
|
99
|
+
if (f)
|
|
100
|
+
throw new TypeError("Generator is already executing.");
|
|
101
|
+
while (g && (g = 0, op[0] && (_ = 0)), _)
|
|
102
|
+
try {
|
|
103
|
+
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)
|
|
104
|
+
return t;
|
|
105
|
+
if (y = 0, t)
|
|
106
|
+
op = [op[0] & 2, t.value];
|
|
107
|
+
switch (op[0]) {
|
|
108
|
+
case 0:
|
|
109
|
+
case 1:
|
|
110
|
+
t = op;
|
|
111
|
+
break;
|
|
112
|
+
case 4:
|
|
113
|
+
_.label++;
|
|
114
|
+
return { value: op[1], done: false };
|
|
115
|
+
case 5:
|
|
116
|
+
_.label++;
|
|
117
|
+
y = op[1];
|
|
118
|
+
op = [0];
|
|
119
|
+
continue;
|
|
120
|
+
case 7:
|
|
121
|
+
op = _.ops.pop();
|
|
122
|
+
_.trys.pop();
|
|
123
|
+
continue;
|
|
124
|
+
default:
|
|
125
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
126
|
+
_ = 0;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
130
|
+
_.label = op[1];
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
134
|
+
_.label = t[1];
|
|
135
|
+
t = op;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
if (t && _.label < t[2]) {
|
|
139
|
+
_.label = t[2];
|
|
140
|
+
_.ops.push(op);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (t[2])
|
|
144
|
+
_.ops.pop();
|
|
145
|
+
_.trys.pop();
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
op = body.call(thisArg, _);
|
|
149
|
+
} catch (e) {
|
|
150
|
+
op = [6, e];
|
|
151
|
+
y = 0;
|
|
152
|
+
} finally {
|
|
153
|
+
f = t = 0;
|
|
154
|
+
}
|
|
155
|
+
if (op[0] & 5)
|
|
156
|
+
throw op[1];
|
|
157
|
+
return { value: op[0] ? op[1] : undefined, done: true };
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
161
|
+
exports2.Pioneer = undefined;
|
|
162
|
+
var Swagger;
|
|
163
|
+
var log;
|
|
164
|
+
if (typeof window === "undefined") {
|
|
165
|
+
Swagger = require("swagger-client");
|
|
166
|
+
log = require("@pioneer-platform/loggerdog")();
|
|
167
|
+
} else {
|
|
168
|
+
Swagger = null;
|
|
169
|
+
log = {
|
|
170
|
+
debug: function() {
|
|
171
|
+
var args = [];
|
|
172
|
+
for (var _i = 0;_i < arguments.length; _i++) {
|
|
173
|
+
args[_i] = arguments[_i];
|
|
174
|
+
}
|
|
175
|
+
return console.debug.apply(console, args);
|
|
176
|
+
},
|
|
177
|
+
info: function() {
|
|
178
|
+
var args = [];
|
|
179
|
+
for (var _i = 0;_i < arguments.length; _i++) {
|
|
180
|
+
args[_i] = arguments[_i];
|
|
181
|
+
}
|
|
182
|
+
return console.info.apply(console, args);
|
|
183
|
+
},
|
|
184
|
+
warn: function() {
|
|
185
|
+
var args = [];
|
|
186
|
+
for (var _i = 0;_i < arguments.length; _i++) {
|
|
187
|
+
args[_i] = arguments[_i];
|
|
188
|
+
}
|
|
189
|
+
return console.warn.apply(console, args);
|
|
190
|
+
},
|
|
191
|
+
error: function() {
|
|
192
|
+
var args = [];
|
|
193
|
+
for (var _i = 0;_i < arguments.length; _i++) {
|
|
194
|
+
args[_i] = arguments[_i];
|
|
195
|
+
}
|
|
196
|
+
return console.error.apply(console, args);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
var TAG = " | Client | ";
|
|
201
|
+
function customHttpClient(req) {
|
|
202
|
+
var _this = this;
|
|
203
|
+
return new Promise(function(resolve, reject) {
|
|
204
|
+
var timer = setTimeout(function() {
|
|
205
|
+
reject(new Error("Request timed out"));
|
|
206
|
+
}, 60000);
|
|
207
|
+
log.debug(TAG, "HTTP request URL:", req.url);
|
|
208
|
+
log.debug(TAG, "HTTP request details:", req);
|
|
209
|
+
if (Swagger && Swagger.http) {
|
|
210
|
+
Swagger.http(req).then(function(response) {
|
|
211
|
+
clearTimeout(timer);
|
|
212
|
+
resolve(response);
|
|
213
|
+
}).catch(function(err) {
|
|
214
|
+
clearTimeout(timer);
|
|
215
|
+
reject(err);
|
|
216
|
+
});
|
|
217
|
+
} else {
|
|
218
|
+
var fetchOptions = {
|
|
219
|
+
method: req.method || "GET",
|
|
220
|
+
headers: req.headers,
|
|
221
|
+
body: req.body ? typeof req.body === "string" ? req.body : JSON.stringify(req.body) : undefined
|
|
222
|
+
};
|
|
223
|
+
fetch(req.url, fetchOptions).then(function(response) {
|
|
224
|
+
return __awaiter(_this, undefined, undefined, function() {
|
|
225
|
+
var text, body, headers;
|
|
226
|
+
return __generator(this, function(_a) {
|
|
227
|
+
switch (_a.label) {
|
|
228
|
+
case 0:
|
|
229
|
+
clearTimeout(timer);
|
|
230
|
+
return [4, response.text()];
|
|
231
|
+
case 1:
|
|
232
|
+
text = _a.sent();
|
|
233
|
+
try {
|
|
234
|
+
body = JSON.parse(text);
|
|
235
|
+
} catch (jsonError) {
|
|
236
|
+
body = text;
|
|
237
|
+
}
|
|
238
|
+
headers = {};
|
|
239
|
+
response.headers.forEach(function(value, key) {
|
|
240
|
+
headers[key] = value;
|
|
241
|
+
});
|
|
242
|
+
resolve({
|
|
243
|
+
status: response.status,
|
|
244
|
+
body,
|
|
245
|
+
headers
|
|
246
|
+
});
|
|
247
|
+
return [2];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}).catch(function(err) {
|
|
252
|
+
clearTimeout(timer);
|
|
253
|
+
reject(err);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
var Pioneer = function() {
|
|
259
|
+
function Pioneer2(spec, config) {
|
|
260
|
+
this.spec = spec;
|
|
261
|
+
this.queryKey = config.queryKey;
|
|
262
|
+
this.pioneer = {};
|
|
263
|
+
this.timeout = config.queryKey || 45000;
|
|
264
|
+
}
|
|
265
|
+
Pioneer2.prototype.init = function() {
|
|
266
|
+
return __awaiter(this, undefined, undefined, function() {
|
|
267
|
+
var tag, _a, specResponse, specData_1, e_1;
|
|
268
|
+
var _this = this;
|
|
269
|
+
return __generator(this, function(_b) {
|
|
270
|
+
switch (_b.label) {
|
|
271
|
+
case 0:
|
|
272
|
+
tag = TAG + " | init | ";
|
|
273
|
+
_b.label = 1;
|
|
274
|
+
case 1:
|
|
275
|
+
_b.trys.push([1, 7, , 8]);
|
|
276
|
+
if (!this.queryKey)
|
|
277
|
+
throw Error(" You must create an api key! ");
|
|
278
|
+
if (!Swagger)
|
|
279
|
+
return [3, 3];
|
|
280
|
+
_a = this;
|
|
281
|
+
return [4, new Swagger({
|
|
282
|
+
url: this.spec,
|
|
283
|
+
requestInterceptor: function(req) {
|
|
284
|
+
req.headers.Authorization = _this.queryKey;
|
|
285
|
+
if ((req.method === "POST" || req.method === "post") && req.body) {
|
|
286
|
+
log.debug(TAG, "Request interceptor - method:", req.method);
|
|
287
|
+
log.debug(TAG, "Body type:", typeof req.body);
|
|
288
|
+
log.debug(TAG, "Body preview:", typeof req.body === "string" ? req.body.substring(0, 200) : JSON.stringify(req.body).substring(0, 200));
|
|
289
|
+
if (!req.headers)
|
|
290
|
+
req.headers = {};
|
|
291
|
+
if (!req.headers["Content-Type"]) {
|
|
292
|
+
req.headers["Content-Type"] = "application/json";
|
|
293
|
+
}
|
|
294
|
+
if (typeof req.body !== "string") {
|
|
295
|
+
log.debug(TAG, "Converting body to JSON string");
|
|
296
|
+
req.body = JSON.stringify(req.body);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return req;
|
|
300
|
+
},
|
|
301
|
+
http: customHttpClient
|
|
302
|
+
})];
|
|
303
|
+
case 2:
|
|
304
|
+
_a.client = _b.sent();
|
|
305
|
+
return [3, 6];
|
|
306
|
+
case 3:
|
|
307
|
+
return [4, fetch(this.spec)];
|
|
308
|
+
case 4:
|
|
309
|
+
specResponse = _b.sent();
|
|
310
|
+
return [4, specResponse.json()];
|
|
311
|
+
case 5:
|
|
312
|
+
specData_1 = _b.sent();
|
|
313
|
+
this.client = {
|
|
314
|
+
spec: specData_1,
|
|
315
|
+
execute: function(request) {
|
|
316
|
+
return __awaiter(_this, undefined, undefined, function() {
|
|
317
|
+
var operationId, parameters, requestBody, targetPath, targetMethod, path, method, baseUrl, url, httpReq;
|
|
318
|
+
return __generator(this, function(_a2) {
|
|
319
|
+
switch (_a2.label) {
|
|
320
|
+
case 0:
|
|
321
|
+
operationId = request.operationId, parameters = request.parameters, requestBody = request.requestBody;
|
|
322
|
+
targetPath = "";
|
|
323
|
+
targetMethod = "";
|
|
324
|
+
for (path in specData_1.paths) {
|
|
325
|
+
for (method in specData_1.paths[path]) {
|
|
326
|
+
if (specData_1.paths[path][method].operationId === operationId) {
|
|
327
|
+
targetPath = path;
|
|
328
|
+
targetMethod = method;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (targetPath)
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
if (!targetPath) {
|
|
336
|
+
throw new Error("Operation ".concat(operationId, " not found in spec"));
|
|
337
|
+
}
|
|
338
|
+
baseUrl = this.spec.replace("/spec/swagger.json", "");
|
|
339
|
+
if (specData_1.servers && specData_1.servers.length > 0) {
|
|
340
|
+
baseUrl = specData_1.servers[0].url;
|
|
341
|
+
}
|
|
342
|
+
url = "".concat(baseUrl).concat(targetPath);
|
|
343
|
+
httpReq = {
|
|
344
|
+
method: targetMethod.toUpperCase(),
|
|
345
|
+
url,
|
|
346
|
+
headers: {
|
|
347
|
+
Authorization: this.queryKey,
|
|
348
|
+
"Content-Type": "application/json"
|
|
349
|
+
},
|
|
350
|
+
body: requestBody
|
|
351
|
+
};
|
|
352
|
+
return [4, customHttpClient(httpReq)];
|
|
353
|
+
case 1:
|
|
354
|
+
return [2, _a2.sent()];
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
_b.label = 6;
|
|
361
|
+
case 6:
|
|
362
|
+
Object.keys(this.client.spec.paths).forEach(function(path) {
|
|
363
|
+
Object.keys(_this.client.spec.paths[path]).forEach(function(method) {
|
|
364
|
+
var operationId = _this.client.spec.paths[path][method].operationId;
|
|
365
|
+
_this.pioneer[operationId] = function(parameters) {
|
|
366
|
+
return __awaiter(_this, undefined, undefined, function() {
|
|
367
|
+
var invalidElements, request, result, e_2;
|
|
368
|
+
return __generator(this, function(_a2) {
|
|
369
|
+
switch (_a2.label) {
|
|
370
|
+
case 0:
|
|
371
|
+
_a2.trys.push([0, 2, , 3]);
|
|
372
|
+
log.debug(TAG, "".concat(operationId, " called with:"), parameters);
|
|
373
|
+
if (operationId === "GetMarketInfo") {
|
|
374
|
+
if (!Array.isArray(parameters)) {
|
|
375
|
+
throw new Error("GetMarketInfo requires an array of CAIP strings, got ".concat(typeof parameters));
|
|
376
|
+
}
|
|
377
|
+
invalidElements = parameters.map(function(item, index) {
|
|
378
|
+
return { item, index, type: typeof item };
|
|
379
|
+
}).filter(function(_a3) {
|
|
380
|
+
var item = _a3.item;
|
|
381
|
+
return !item || typeof item !== "string";
|
|
382
|
+
});
|
|
383
|
+
if (invalidElements.length > 0) {
|
|
384
|
+
console.error("\uD83D\uDEA8 [PIONEER CLIENT] GetMarketInfo validation failed:", invalidElements);
|
|
385
|
+
throw new Error("GetMarketInfo array contains ".concat(invalidElements.length, " invalid element(s). ") + "All elements must be CAIP strings. First invalid at index ".concat(invalidElements[0].index, ": ") + "".concat(JSON.stringify(invalidElements[0].item), " (type: ").concat(invalidElements[0].type, ")"));
|
|
386
|
+
}
|
|
387
|
+
log.debug(TAG, "GetMarketInfo validation passed: ".concat(parameters.length, " valid CAIP strings"));
|
|
388
|
+
}
|
|
389
|
+
request = {
|
|
390
|
+
operationId,
|
|
391
|
+
parameters: {
|
|
392
|
+
Authorization: this.queryKey
|
|
393
|
+
},
|
|
394
|
+
responseContentType: "application/json"
|
|
395
|
+
};
|
|
396
|
+
if (method === "post") {
|
|
397
|
+
request.requestBody = parameters;
|
|
398
|
+
} else {
|
|
399
|
+
request.parameters = __assign(__assign({}, parameters), { Authorization: this.queryKey });
|
|
400
|
+
}
|
|
401
|
+
log.debug(TAG, "".concat(operationId, " request:"), request);
|
|
402
|
+
return [4, this.client.execute(request)];
|
|
403
|
+
case 1:
|
|
404
|
+
result = _a2.sent();
|
|
405
|
+
return [2, { data: result.body }];
|
|
406
|
+
case 2:
|
|
407
|
+
e_2 = _a2.sent();
|
|
408
|
+
log.error(TAG, "Operation error:", e_2);
|
|
409
|
+
throw e_2;
|
|
410
|
+
case 3:
|
|
411
|
+
return [2];
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
return [2, this.pioneer];
|
|
419
|
+
case 7:
|
|
420
|
+
e_1 = _b.sent();
|
|
421
|
+
log.error(TAG, "Initialization error:", e_1);
|
|
422
|
+
throw e_1;
|
|
423
|
+
case 8:
|
|
424
|
+
return [2];
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
};
|
|
429
|
+
return Pioneer2;
|
|
430
|
+
}();
|
|
431
|
+
exports2.Pioneer = Pioneer;
|
|
432
|
+
exports2.default = Pioneer;
|
|
433
|
+
});
|
|
434
|
+
|
|
43
435
|
// node_modules/coinselect/utils.js
|
|
44
436
|
var require_utils = __commonJS((exports2, module2) => {
|
|
45
437
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
@@ -245,7 +637,7 @@ __export(exports_src, {
|
|
|
245
637
|
module.exports = __toCommonJS(exports_src);
|
|
246
638
|
var import_keepkey_sdk = require("@keepkey/keepkey-sdk");
|
|
247
639
|
var import_pioneer_caip7 = require("@pioneer-platform/pioneer-caip");
|
|
248
|
-
var import_pioneer_client = __toESM(
|
|
640
|
+
var import_pioneer_client = __toESM(require_lib());
|
|
249
641
|
var import_pioneer_coins4 = require("@pioneer-platform/pioneer-coins");
|
|
250
642
|
var import_pioneer_discovery2 = require("@pioneer-platform/pioneer-discovery");
|
|
251
643
|
var import_pioneer_events = require("@pioneer-platform/pioneer-events");
|
|
@@ -3531,8 +3923,62 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3531
3923
|
return dashboardData;
|
|
3532
3924
|
}
|
|
3533
3925
|
|
|
3926
|
+
// src/utils/sync-market.ts
|
|
3927
|
+
var TAG8 = " | sync-market | ";
|
|
3928
|
+
async function syncMarket(balances, pioneer) {
|
|
3929
|
+
const tag5 = `${TAG8} | syncMarket | `;
|
|
3930
|
+
try {
|
|
3931
|
+
const invalidBalances = balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
3932
|
+
if (invalidBalances.length > 0) {
|
|
3933
|
+
console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b2) => ({
|
|
3934
|
+
caip: b2?.caip,
|
|
3935
|
+
type: typeof b2?.caip,
|
|
3936
|
+
symbol: b2?.symbol,
|
|
3937
|
+
balance: b2?.balance
|
|
3938
|
+
})));
|
|
3939
|
+
}
|
|
3940
|
+
let allCaips = balances.filter((b2) => b2 && b2.caip && typeof b2.caip === "string" && b2.caip.trim().length > 0).map((b2) => b2.caip);
|
|
3941
|
+
allCaips = [...new Set(allCaips)];
|
|
3942
|
+
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
3943
|
+
console.log("GetMarketInfo: payload: ", allCaips);
|
|
3944
|
+
console.log("GetMarketInfo: payload type: ", typeof allCaips);
|
|
3945
|
+
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
3946
|
+
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
3947
|
+
if (invalidEntries.length > 0) {
|
|
3948
|
+
console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
3949
|
+
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
3950
|
+
}
|
|
3951
|
+
if (allCaips && allCaips.length > 0) {
|
|
3952
|
+
try {
|
|
3953
|
+
let allPrices = await pioneer.GetMarketInfo(allCaips);
|
|
3954
|
+
console.log("GetMarketInfo: response: ", allPrices);
|
|
3955
|
+
const priceMap = {};
|
|
3956
|
+
if (allPrices && allPrices.data) {
|
|
3957
|
+
for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
|
|
3958
|
+
priceMap[allCaips[i]] = allPrices.data[i];
|
|
3959
|
+
}
|
|
3960
|
+
}
|
|
3961
|
+
for (let balance of balances) {
|
|
3962
|
+
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
3963
|
+
balance.price = priceMap[balance.caip];
|
|
3964
|
+
balance.priceUsd = priceMap[balance.caip];
|
|
3965
|
+
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
} catch (apiError) {
|
|
3969
|
+
console.error(tag5, "API error fetching market info:", apiError);
|
|
3970
|
+
console.warn(tag5, "Continuing without market prices");
|
|
3971
|
+
}
|
|
3972
|
+
}
|
|
3973
|
+
return true;
|
|
3974
|
+
} catch (e) {
|
|
3975
|
+
console.error(tag5, "e:", e);
|
|
3976
|
+
throw e;
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
|
|
3534
3980
|
// src/index.ts
|
|
3535
|
-
var
|
|
3981
|
+
var TAG9 = " | Pioneer-sdk | ";
|
|
3536
3982
|
|
|
3537
3983
|
class SDK {
|
|
3538
3984
|
status;
|
|
@@ -3696,7 +4142,7 @@ class SDK {
|
|
|
3696
4142
|
return true;
|
|
3697
4143
|
};
|
|
3698
4144
|
this.setPubkeys = (newPubkeys) => {
|
|
3699
|
-
const tag5 = `${
|
|
4145
|
+
const tag5 = `${TAG9} | setPubkeys | `;
|
|
3700
4146
|
this.pubkeys = [];
|
|
3701
4147
|
this.pubkeySet.clear();
|
|
3702
4148
|
let added = 0;
|
|
@@ -3707,7 +4153,7 @@ class SDK {
|
|
|
3707
4153
|
}
|
|
3708
4154
|
};
|
|
3709
4155
|
this.getUnifiedPortfolio = async function() {
|
|
3710
|
-
const tag5 = `${
|
|
4156
|
+
const tag5 = `${TAG9} | getUnifiedPortfolio | `;
|
|
3711
4157
|
try {
|
|
3712
4158
|
const startTime = performance.now();
|
|
3713
4159
|
try {
|
|
@@ -3815,7 +4261,7 @@ class SDK {
|
|
|
3815
4261
|
}
|
|
3816
4262
|
};
|
|
3817
4263
|
this.init = async function(walletsVerbose, setup) {
|
|
3818
|
-
const tag5 = `${
|
|
4264
|
+
const tag5 = `${TAG9} | init | `;
|
|
3819
4265
|
try {
|
|
3820
4266
|
if (!this.username)
|
|
3821
4267
|
throw Error("username required!");
|
|
@@ -3906,58 +4352,10 @@ class SDK {
|
|
|
3906
4352
|
return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
|
|
3907
4353
|
};
|
|
3908
4354
|
this.syncMarket = async function() {
|
|
3909
|
-
|
|
3910
|
-
try {
|
|
3911
|
-
const invalidBalances = this.balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
3912
|
-
if (invalidBalances.length > 0) {
|
|
3913
|
-
console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b2) => ({
|
|
3914
|
-
caip: b2?.caip,
|
|
3915
|
-
type: typeof b2?.caip,
|
|
3916
|
-
symbol: b2?.symbol,
|
|
3917
|
-
balance: b2?.balance
|
|
3918
|
-
})));
|
|
3919
|
-
}
|
|
3920
|
-
let allCaips = this.balances.filter((b2) => b2 && b2.caip && typeof b2.caip === "string" && b2.caip.trim().length > 0).map((b2) => b2.caip);
|
|
3921
|
-
allCaips = [...new Set(allCaips)];
|
|
3922
|
-
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
3923
|
-
console.log("GetMarketInfo: payload: ", allCaips);
|
|
3924
|
-
console.log("GetMarketInfo: payload type: ", typeof allCaips);
|
|
3925
|
-
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
3926
|
-
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
3927
|
-
if (invalidEntries.length > 0) {
|
|
3928
|
-
console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
3929
|
-
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
3930
|
-
}
|
|
3931
|
-
if (allCaips && allCaips.length > 0) {
|
|
3932
|
-
try {
|
|
3933
|
-
let allPrices = await this.pioneer.GetMarketInfo(allCaips);
|
|
3934
|
-
console.log("GetMarketInfo: response: ", allPrices);
|
|
3935
|
-
const priceMap = {};
|
|
3936
|
-
if (allPrices && allPrices.data) {
|
|
3937
|
-
for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
|
|
3938
|
-
priceMap[allCaips[i]] = allPrices.data[i];
|
|
3939
|
-
}
|
|
3940
|
-
}
|
|
3941
|
-
for (let balance of this.balances) {
|
|
3942
|
-
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
3943
|
-
balance.price = priceMap[balance.caip];
|
|
3944
|
-
balance.priceUsd = priceMap[balance.caip];
|
|
3945
|
-
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
3946
|
-
}
|
|
3947
|
-
}
|
|
3948
|
-
} catch (apiError) {
|
|
3949
|
-
console.error(tag5, "API error fetching market info:", apiError);
|
|
3950
|
-
console.warn(tag5, "Continuing without market prices");
|
|
3951
|
-
}
|
|
3952
|
-
}
|
|
3953
|
-
return true;
|
|
3954
|
-
} catch (e) {
|
|
3955
|
-
console.error(tag5, "e:", e);
|
|
3956
|
-
throw e;
|
|
3957
|
-
}
|
|
4355
|
+
return syncMarket(this.balances, this.pioneer);
|
|
3958
4356
|
};
|
|
3959
4357
|
this.sync = async function() {
|
|
3960
|
-
const tag5 = `${
|
|
4358
|
+
const tag5 = `${TAG9} | sync | `;
|
|
3961
4359
|
try {
|
|
3962
4360
|
const matchesNetwork = (item, networkId) => {
|
|
3963
4361
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4110,7 +4508,7 @@ class SDK {
|
|
|
4110
4508
|
}
|
|
4111
4509
|
};
|
|
4112
4510
|
this.buildTx = async function(sendPayload) {
|
|
4113
|
-
let tag5 =
|
|
4511
|
+
let tag5 = TAG9 + " | buildTx | ";
|
|
4114
4512
|
try {
|
|
4115
4513
|
const transactionDependencies = {
|
|
4116
4514
|
context: this.context,
|
|
@@ -4132,7 +4530,7 @@ class SDK {
|
|
|
4132
4530
|
}
|
|
4133
4531
|
};
|
|
4134
4532
|
this.buildDelegateTx = async function(caip, params) {
|
|
4135
|
-
let tag5 =
|
|
4533
|
+
let tag5 = TAG9 + " | buildDelegateTx | ";
|
|
4136
4534
|
try {
|
|
4137
4535
|
const delegateParams = {
|
|
4138
4536
|
...params,
|
|
@@ -4147,7 +4545,7 @@ class SDK {
|
|
|
4147
4545
|
}
|
|
4148
4546
|
};
|
|
4149
4547
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4150
|
-
let tag5 =
|
|
4548
|
+
let tag5 = TAG9 + " | buildUndelegateTx | ";
|
|
4151
4549
|
try {
|
|
4152
4550
|
const undelegateParams = {
|
|
4153
4551
|
...params,
|
|
@@ -4162,7 +4560,7 @@ class SDK {
|
|
|
4162
4560
|
}
|
|
4163
4561
|
};
|
|
4164
4562
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4165
|
-
let tag5 =
|
|
4563
|
+
let tag5 = TAG9 + " | buildClaimRewardsTx | ";
|
|
4166
4564
|
try {
|
|
4167
4565
|
const claimParams = {
|
|
4168
4566
|
...params,
|
|
@@ -4177,7 +4575,7 @@ class SDK {
|
|
|
4177
4575
|
}
|
|
4178
4576
|
};
|
|
4179
4577
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4180
|
-
let tag5 =
|
|
4578
|
+
let tag5 = TAG9 + " | buildClaimAllRewardsTx | ";
|
|
4181
4579
|
try {
|
|
4182
4580
|
const claimAllParams = {
|
|
4183
4581
|
...params,
|
|
@@ -4191,7 +4589,7 @@ class SDK {
|
|
|
4191
4589
|
}
|
|
4192
4590
|
};
|
|
4193
4591
|
this.signTx = async function(unsignedTx) {
|
|
4194
|
-
let tag5 =
|
|
4592
|
+
let tag5 = TAG9 + " | signTx | ";
|
|
4195
4593
|
try {
|
|
4196
4594
|
const transactionDependencies = {
|
|
4197
4595
|
context: this.context,
|
|
@@ -4212,7 +4610,7 @@ class SDK {
|
|
|
4212
4610
|
}
|
|
4213
4611
|
};
|
|
4214
4612
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4215
|
-
let tag5 =
|
|
4613
|
+
let tag5 = TAG9 + " | broadcastTx | ";
|
|
4216
4614
|
try {
|
|
4217
4615
|
const transactionDependencies = {
|
|
4218
4616
|
context: this.context,
|
|
@@ -4236,7 +4634,7 @@ class SDK {
|
|
|
4236
4634
|
}
|
|
4237
4635
|
};
|
|
4238
4636
|
this.swap = async function(swapPayload) {
|
|
4239
|
-
let tag5 = `${
|
|
4637
|
+
let tag5 = `${TAG9} | swap | `;
|
|
4240
4638
|
try {
|
|
4241
4639
|
if (!swapPayload)
|
|
4242
4640
|
throw Error("swapPayload required!");
|
|
@@ -4371,7 +4769,7 @@ class SDK {
|
|
|
4371
4769
|
}
|
|
4372
4770
|
};
|
|
4373
4771
|
this.transfer = async function(sendPayload) {
|
|
4374
|
-
let tag5 = `${
|
|
4772
|
+
let tag5 = `${TAG9} | transfer | `;
|
|
4375
4773
|
try {
|
|
4376
4774
|
if (!sendPayload)
|
|
4377
4775
|
throw Error("sendPayload required!");
|
|
@@ -4466,7 +4864,7 @@ class SDK {
|
|
|
4466
4864
|
}
|
|
4467
4865
|
};
|
|
4468
4866
|
this.setBlockchains = async function(blockchains) {
|
|
4469
|
-
const tag5 = `${
|
|
4867
|
+
const tag5 = `${TAG9} | setBlockchains | `;
|
|
4470
4868
|
try {
|
|
4471
4869
|
if (!blockchains)
|
|
4472
4870
|
throw Error("blockchains required!");
|
|
@@ -4482,7 +4880,7 @@ class SDK {
|
|
|
4482
4880
|
}
|
|
4483
4881
|
};
|
|
4484
4882
|
this.addAsset = async function(caip, data) {
|
|
4485
|
-
let tag5 =
|
|
4883
|
+
let tag5 = TAG9 + " | addAsset | ";
|
|
4486
4884
|
try {
|
|
4487
4885
|
let success = false;
|
|
4488
4886
|
if (!caip)
|
|
@@ -4520,7 +4918,7 @@ class SDK {
|
|
|
4520
4918
|
}
|
|
4521
4919
|
};
|
|
4522
4920
|
this.clearWalletState = async function() {
|
|
4523
|
-
const tag5 = `${
|
|
4921
|
+
const tag5 = `${TAG9} | clearWalletState | `;
|
|
4524
4922
|
try {
|
|
4525
4923
|
this.context = null;
|
|
4526
4924
|
this.paths = [];
|
|
@@ -4535,7 +4933,7 @@ class SDK {
|
|
|
4535
4933
|
}
|
|
4536
4934
|
};
|
|
4537
4935
|
this.addPath = async function(path) {
|
|
4538
|
-
const tag5 = `${
|
|
4936
|
+
const tag5 = `${TAG9} | addPath | `;
|
|
4539
4937
|
try {
|
|
4540
4938
|
this.paths.push(path);
|
|
4541
4939
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -4549,7 +4947,7 @@ class SDK {
|
|
|
4549
4947
|
}
|
|
4550
4948
|
};
|
|
4551
4949
|
this.addPaths = async function(paths) {
|
|
4552
|
-
const tag5 = `${
|
|
4950
|
+
const tag5 = `${TAG9} | addPaths | `;
|
|
4553
4951
|
try {
|
|
4554
4952
|
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4555
4953
|
this.paths.push(...paths);
|
|
@@ -4585,7 +4983,7 @@ class SDK {
|
|
|
4585
4983
|
return this.getGasAssets();
|
|
4586
4984
|
};
|
|
4587
4985
|
this.getGasAssets = async function() {
|
|
4588
|
-
const tag5 = `${
|
|
4986
|
+
const tag5 = `${TAG9} | getGasAssets | `;
|
|
4589
4987
|
try {
|
|
4590
4988
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4591
4989
|
let networkId = this.blockchains[i];
|
|
@@ -4628,7 +5026,7 @@ class SDK {
|
|
|
4628
5026
|
}
|
|
4629
5027
|
};
|
|
4630
5028
|
this.getPubkeys = async function() {
|
|
4631
|
-
const tag5 = `${
|
|
5029
|
+
const tag5 = `${TAG9} | getPubkeys | `;
|
|
4632
5030
|
try {
|
|
4633
5031
|
if (this.paths.length === 0)
|
|
4634
5032
|
throw new Error("No paths found!");
|
|
@@ -4649,7 +5047,7 @@ class SDK {
|
|
|
4649
5047
|
}
|
|
4650
5048
|
};
|
|
4651
5049
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4652
|
-
const tag5 = `${
|
|
5050
|
+
const tag5 = `${TAG9} | getBalancesForNetworks | `;
|
|
4653
5051
|
try {
|
|
4654
5052
|
if (!this.pioneer) {
|
|
4655
5053
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -4704,7 +5102,7 @@ class SDK {
|
|
|
4704
5102
|
}
|
|
4705
5103
|
};
|
|
4706
5104
|
this.getBalances = async function() {
|
|
4707
|
-
const tag5 = `${
|
|
5105
|
+
const tag5 = `${TAG9} | getBalances | `;
|
|
4708
5106
|
try {
|
|
4709
5107
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4710
5108
|
} catch (e) {
|
|
@@ -4713,7 +5111,7 @@ class SDK {
|
|
|
4713
5111
|
}
|
|
4714
5112
|
};
|
|
4715
5113
|
this.getBalance = async function(networkId) {
|
|
4716
|
-
const tag5 = `${
|
|
5114
|
+
const tag5 = `${TAG9} | getBalance | `;
|
|
4717
5115
|
try {
|
|
4718
5116
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4719
5117
|
const filtered = results.filter(async (b2) => b2.networkId === await import_pioneer_caip7.networkIdToCaip(networkId));
|
|
@@ -4724,7 +5122,7 @@ class SDK {
|
|
|
4724
5122
|
}
|
|
4725
5123
|
};
|
|
4726
5124
|
this.getFees = async function(networkId) {
|
|
4727
|
-
const tag5 = `${
|
|
5125
|
+
const tag5 = `${TAG9} | getFees | `;
|
|
4728
5126
|
try {
|
|
4729
5127
|
if (!this.pioneer) {
|
|
4730
5128
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -4739,7 +5137,7 @@ class SDK {
|
|
|
4739
5137
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
4740
5138
|
};
|
|
4741
5139
|
this.getCharts = async function() {
|
|
4742
|
-
const tag5 = `${
|
|
5140
|
+
const tag5 = `${TAG9} | getCharts | `;
|
|
4743
5141
|
try {
|
|
4744
5142
|
console.log(tag5, "Fetching charts");
|
|
4745
5143
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -4761,7 +5159,7 @@ class SDK {
|
|
|
4761
5159
|
}
|
|
4762
5160
|
};
|
|
4763
5161
|
this.setContext = async (context) => {
|
|
4764
|
-
const tag5 = `${
|
|
5162
|
+
const tag5 = `${TAG9} | setContext | `;
|
|
4765
5163
|
try {
|
|
4766
5164
|
if (!context)
|
|
4767
5165
|
throw Error("context required!");
|
|
@@ -4774,7 +5172,7 @@ class SDK {
|
|
|
4774
5172
|
}
|
|
4775
5173
|
};
|
|
4776
5174
|
this.setContextType = async (contextType) => {
|
|
4777
|
-
const tag5 = `${
|
|
5175
|
+
const tag5 = `${TAG9} | setContextType | `;
|
|
4778
5176
|
try {
|
|
4779
5177
|
if (!contextType)
|
|
4780
5178
|
throw Error("contextType required!");
|
|
@@ -4787,7 +5185,7 @@ class SDK {
|
|
|
4787
5185
|
}
|
|
4788
5186
|
};
|
|
4789
5187
|
this.refresh = async () => {
|
|
4790
|
-
const tag5 = `${
|
|
5188
|
+
const tag5 = `${TAG9} | refresh | `;
|
|
4791
5189
|
try {
|
|
4792
5190
|
await this.sync();
|
|
4793
5191
|
return this.balances;
|
|
@@ -4797,7 +5195,7 @@ class SDK {
|
|
|
4797
5195
|
}
|
|
4798
5196
|
};
|
|
4799
5197
|
this.setAssetContext = async function(asset) {
|
|
4800
|
-
const tag5 = `${
|
|
5198
|
+
const tag5 = `${TAG9} | setAssetContext | `;
|
|
4801
5199
|
try {
|
|
4802
5200
|
if (!asset) {
|
|
4803
5201
|
this.assetContext = null;
|
|
@@ -4996,7 +5394,7 @@ class SDK {
|
|
|
4996
5394
|
}
|
|
4997
5395
|
};
|
|
4998
5396
|
this.setPubkeyContext = async function(pubkey) {
|
|
4999
|
-
let tag5 = `${
|
|
5397
|
+
let tag5 = `${TAG9} | setPubkeyContext | `;
|
|
5000
5398
|
try {
|
|
5001
5399
|
if (!pubkey)
|
|
5002
5400
|
throw Error("pubkey is required");
|
|
@@ -5015,7 +5413,7 @@ class SDK {
|
|
|
5015
5413
|
}
|
|
5016
5414
|
};
|
|
5017
5415
|
this.setOutboundAssetContext = async function(asset) {
|
|
5018
|
-
const tag5 = `${
|
|
5416
|
+
const tag5 = `${TAG9} | setOutputAssetContext | `;
|
|
5019
5417
|
try {
|
|
5020
5418
|
console.log(tag5, "0. asset: ", asset);
|
|
5021
5419
|
if (!asset) {
|