@pioneer-platform/pioneer-sdk 4.21.2 → 4.21.5

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 CHANGED
@@ -40,408 +40,6 @@ var __export = (target, all) => {
40
40
  });
41
41
  };
42
42
 
43
- // ../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.timeout || 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, finalPath, _i, _a2, _b2, key, value, placeholder, url, httpReq;
318
- return __generator(this, function(_c) {
319
- switch (_c.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
- finalPath = targetPath;
343
- if (parameters) {
344
- for (_i = 0, _a2 = Object.entries(parameters);_i < _a2.length; _i++) {
345
- _b2 = _a2[_i], key = _b2[0], value = _b2[1];
346
- placeholder = "{".concat(key, "}");
347
- if (finalPath.includes(placeholder)) {
348
- finalPath = finalPath.replace(placeholder, encodeURIComponent(String(value)));
349
- }
350
- }
351
- }
352
- url = "".concat(baseUrl).concat(finalPath);
353
- httpReq = {
354
- method: targetMethod.toUpperCase(),
355
- url,
356
- headers: {
357
- Authorization: this.queryKey,
358
- "Content-Type": "application/json"
359
- },
360
- body: requestBody
361
- };
362
- return [4, customHttpClient(httpReq)];
363
- case 1:
364
- return [2, _c.sent()];
365
- }
366
- });
367
- });
368
- }
369
- };
370
- _b.label = 6;
371
- case 6:
372
- Object.keys(this.client.spec.paths).forEach(function(path) {
373
- Object.keys(_this.client.spec.paths[path]).forEach(function(method) {
374
- var operationId = _this.client.spec.paths[path][method].operationId;
375
- _this.pioneer[operationId] = function(parameters) {
376
- return __awaiter(_this, undefined, undefined, function() {
377
- var invalidElements, request, result, e_2;
378
- return __generator(this, function(_a2) {
379
- switch (_a2.label) {
380
- case 0:
381
- _a2.trys.push([0, 2, , 3]);
382
- log.debug(TAG, "".concat(operationId, " called with:"), parameters);
383
- if (operationId === "GetMarketInfo") {
384
- if (!Array.isArray(parameters)) {
385
- throw new Error("GetMarketInfo requires an array of CAIP strings, got ".concat(typeof parameters));
386
- }
387
- invalidElements = parameters.map(function(item, index) {
388
- return { item, index, type: typeof item };
389
- }).filter(function(_a3) {
390
- var item = _a3.item;
391
- return !item || typeof item !== "string";
392
- });
393
- if (invalidElements.length > 0) {
394
- console.error("\uD83D\uDEA8 [PIONEER CLIENT] GetMarketInfo validation failed:", invalidElements);
395
- 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, ")"));
396
- }
397
- log.debug(TAG, "GetMarketInfo validation passed: ".concat(parameters.length, " valid CAIP strings"));
398
- }
399
- request = {
400
- operationId,
401
- parameters: {
402
- Authorization: this.queryKey
403
- },
404
- responseContentType: "application/json"
405
- };
406
- if (method === "post") {
407
- request.requestBody = parameters;
408
- } else {
409
- request.parameters = __assign(__assign({}, parameters), { Authorization: this.queryKey });
410
- }
411
- log.debug(TAG, "".concat(operationId, " request:"), request);
412
- return [4, this.client.execute(request)];
413
- case 1:
414
- result = _a2.sent();
415
- return [2, { data: result.body }];
416
- case 2:
417
- e_2 = _a2.sent();
418
- log.error(TAG, "Operation error:", e_2);
419
- throw e_2;
420
- case 3:
421
- return [2];
422
- }
423
- });
424
- });
425
- };
426
- });
427
- });
428
- return [2, this.pioneer];
429
- case 7:
430
- e_1 = _b.sent();
431
- log.error(TAG, "Initialization error:", e_1);
432
- throw e_1;
433
- case 8:
434
- return [2];
435
- }
436
- });
437
- });
438
- };
439
- return Pioneer2;
440
- }();
441
- exports2.Pioneer = Pioneer;
442
- exports2.default = Pioneer;
443
- });
444
-
445
43
  // ../../../node_modules/coinselect/utils.js
446
44
  var require_utils = __commonJS((exports2, module2) => {
447
45
  var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
@@ -647,7 +245,150 @@ __export(exports_src, {
647
245
  module.exports = __toCommonJS(exports_src);
648
246
  var import_keepkey_sdk = require("@keepkey/keepkey-sdk");
649
247
  var import_pioneer_caip7 = require("@pioneer-platform/pioneer-caip");
650
- var import_pioneer_client = __toESM(require_lib());
248
+
249
+ // ../pioneer-client/lib/index.js
250
+ var import_swagger_client = __toESM(require("swagger-client"));
251
+ var import_loggerdog = __toESM(require("@pioneer-platform/loggerdog"));
252
+ var log = typeof window === "undefined" ? import_loggerdog.default() : {
253
+ debug: (...args) => console.debug(...args),
254
+ info: (...args) => console.info(...args),
255
+ warn: (...args) => console.warn(...args),
256
+ error: (...args) => console.error(...args)
257
+ };
258
+ var Swagger = import_swagger_client.default;
259
+ var TAG = " | Client | ";
260
+ function customHttpClient(req) {
261
+ return new Promise((resolve, reject) => {
262
+ const timer = setTimeout(() => {
263
+ reject(new Error("Request timed out"));
264
+ }, 60000);
265
+ log.debug(TAG, "HTTP request URL:", req.url);
266
+ log.debug(TAG, "HTTP request details:", req);
267
+ if (Swagger.http) {
268
+ Swagger.http(req).then((response) => {
269
+ clearTimeout(timer);
270
+ resolve(response);
271
+ }).catch((err) => {
272
+ clearTimeout(timer);
273
+ reject(err);
274
+ });
275
+ } else {
276
+ const fetchOptions = {
277
+ method: req.method || "GET",
278
+ headers: req.headers,
279
+ body: req.body ? typeof req.body === "string" ? req.body : JSON.stringify(req.body) : undefined
280
+ };
281
+ fetch(req.url, fetchOptions).then(async (response) => {
282
+ clearTimeout(timer);
283
+ const text = await response.text();
284
+ let body;
285
+ try {
286
+ body = JSON.parse(text);
287
+ } catch (jsonError) {
288
+ body = text;
289
+ }
290
+ const headers = {};
291
+ response.headers.forEach((value, key) => {
292
+ headers[key] = value;
293
+ });
294
+ resolve({
295
+ status: response.status,
296
+ body,
297
+ headers
298
+ });
299
+ }).catch((err) => {
300
+ clearTimeout(timer);
301
+ reject(err);
302
+ });
303
+ }
304
+ });
305
+ }
306
+
307
+ class Pioneer {
308
+ constructor(spec, config) {
309
+ this.spec = spec;
310
+ this.queryKey = config.queryKey;
311
+ this.pioneer = {};
312
+ this.timeout = config.timeout || 45000;
313
+ }
314
+ async init() {
315
+ let tag = TAG + " | init | ";
316
+ try {
317
+ if (!this.queryKey)
318
+ throw Error(" You must create an api key! ");
319
+ this.client = await new Swagger({
320
+ url: this.spec,
321
+ requestInterceptor: (req) => {
322
+ req.headers.Authorization = this.queryKey;
323
+ if ((req.method === "POST" || req.method === "post") && req.body) {
324
+ log.debug(TAG, "Request interceptor - method:", req.method);
325
+ log.debug(TAG, "Body type:", typeof req.body);
326
+ log.debug(TAG, "Body preview:", typeof req.body === "string" ? req.body.substring(0, 200) : JSON.stringify(req.body).substring(0, 200));
327
+ if (!req.headers)
328
+ req.headers = {};
329
+ if (!req.headers["Content-Type"]) {
330
+ req.headers["Content-Type"] = "application/json";
331
+ }
332
+ if (typeof req.body !== "string") {
333
+ log.debug(TAG, "Converting body to JSON string");
334
+ req.body = JSON.stringify(req.body);
335
+ }
336
+ }
337
+ return req;
338
+ },
339
+ http: customHttpClient
340
+ });
341
+ Object.keys(this.client.spec.paths).forEach((path) => {
342
+ Object.keys(this.client.spec.paths[path]).forEach((method) => {
343
+ const operationId = this.client.spec.paths[path][method].operationId;
344
+ this.pioneer[operationId] = async (parameters) => {
345
+ try {
346
+ log.debug(TAG, `${operationId} called with:`, parameters);
347
+ if (operationId === "GetMarketInfo") {
348
+ if (!Array.isArray(parameters)) {
349
+ throw new Error(`GetMarketInfo requires an array of CAIP strings, got ${typeof parameters}`);
350
+ }
351
+ const invalidElements = parameters.map((item, index) => ({ item, index, type: typeof item })).filter(({ item }) => !item || typeof item !== "string");
352
+ if (invalidElements.length > 0) {
353
+ console.error(`\uD83D\uDEA8 [PIONEER CLIENT] GetMarketInfo validation failed:`, invalidElements);
354
+ throw new Error(`GetMarketInfo array contains ${invalidElements.length} invalid element(s). ` + `All elements must be CAIP strings. First invalid at index ${invalidElements[0].index}: ` + `${JSON.stringify(invalidElements[0].item)} (type: ${invalidElements[0].type})`);
355
+ }
356
+ log.debug(TAG, `GetMarketInfo validation passed: ${parameters.length} valid CAIP strings`);
357
+ }
358
+ let request = {
359
+ operationId,
360
+ parameters: {
361
+ Authorization: this.queryKey
362
+ },
363
+ responseContentType: "application/json"
364
+ };
365
+ if (method === "post") {
366
+ request.requestBody = parameters;
367
+ } else {
368
+ request.parameters = {
369
+ ...parameters,
370
+ Authorization: this.queryKey
371
+ };
372
+ }
373
+ log.debug(TAG, `${operationId} request:`, request);
374
+ const result = await this.client.execute(request);
375
+ return { data: result.body };
376
+ } catch (e) {
377
+ log.error(TAG, "Operation error:", e);
378
+ throw e;
379
+ }
380
+ };
381
+ });
382
+ });
383
+ return this.pioneer;
384
+ } catch (e) {
385
+ log.error(TAG, "Initialization error:", e);
386
+ throw e;
387
+ }
388
+ }
389
+ }
390
+
391
+ // src/index.ts
651
392
  var import_pioneer_coins4 = require("@pioneer-platform/pioneer-coins");
652
393
  var import_pioneer_discovery2 = require("@pioneer-platform/pioneer-discovery");
653
394
  var import_pioneer_events = require("@pioneer-platform/pioneer-events");
@@ -1808,7 +1549,7 @@ var SUPPORTED_CAIPS = {
1808
1549
  // src/txbuilder/createUnsignedEvmTx.ts
1809
1550
  var import_pioneer_caip = require("@pioneer-platform/pioneer-caip");
1810
1551
  var import_pioneer_coins2 = require("@pioneer-platform/pioneer-coins");
1811
- var TAG = " | createUnsignedEvmTx | ";
1552
+ var TAG2 = " | createUnsignedEvmTx | ";
1812
1553
  var toHex = (value) => {
1813
1554
  let hex = value.toString(16);
1814
1555
  if (hex.length % 2)
@@ -1887,7 +1628,7 @@ async function fetchTokenPriceInUsd(pioneer, caip) {
1887
1628
  }
1888
1629
  }
1889
1630
  async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5) {
1890
- const tag6 = TAG + " | createUnsignedEvmTx | ";
1631
+ const tag6 = TAG2 + " | createUnsignedEvmTx | ";
1891
1632
  try {
1892
1633
  if (!pioneer)
1893
1634
  throw new Error("Failed to initialize Pioneer");
@@ -2208,9 +1949,9 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
2208
1949
 
2209
1950
  // src/txbuilder/createUnsignedRippleTx.ts
2210
1951
  var import_pioneer_caip2 = require("@pioneer-platform/pioneer-caip");
2211
- var TAG2 = " | createUnsignedUxtoTx | ";
1952
+ var TAG3 = " | createUnsignedUxtoTx | ";
2212
1953
  async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax) {
2213
- let tag6 = TAG2 + " | createUnsignedRippleTx | ";
1954
+ let tag6 = TAG3 + " | createUnsignedRippleTx | ";
2214
1955
  try {
2215
1956
  if (!pioneer)
2216
1957
  throw new Error("Failed to init! pioneer");
@@ -2427,9 +2168,9 @@ var thorchainDepositTemplate = (params) => ({
2427
2168
  });
2428
2169
 
2429
2170
  // src/txbuilder/createUnsignedTendermintTx.ts
2430
- var TAG3 = " | createUnsignedTendermintTx | ";
2171
+ var TAG4 = " | createUnsignedTendermintTx | ";
2431
2172
  async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, to) {
2432
- const tag6 = TAG3 + " | createUnsignedTendermintTx | ";
2173
+ const tag6 = TAG4 + " | createUnsignedTendermintTx | ";
2433
2174
  try {
2434
2175
  if (!pioneer)
2435
2176
  throw new Error("Failed to init! pioneer");
@@ -2987,7 +2728,7 @@ function transformInput(input) {
2987
2728
  }
2988
2729
 
2989
2730
  // src/TransactionManager.ts
2990
- var TAG4 = " | Transaction | ";
2731
+ var TAG5 = " | Transaction | ";
2991
2732
 
2992
2733
  class TransactionManager {
2993
2734
  context;
@@ -3022,7 +2763,7 @@ class TransactionManager {
3022
2763
  throw new Error(`Unsupported CAIP: ${caip}`);
3023
2764
  }
3024
2765
  async transfer({ caip, to, amount, memo, isMax = false, feeLevel = 5, changeScriptType }) {
3025
- let tag6 = TAG4 + " | transfer | ";
2766
+ let tag6 = TAG5 + " | transfer | ";
3026
2767
  try {
3027
2768
  if (!this.pioneer)
3028
2769
  throw Error("Failed to init! pioneer");
@@ -3065,7 +2806,7 @@ class TransactionManager {
3065
2806
  }
3066
2807
  }
3067
2808
  async sign({ caip, unsignedTx }) {
3068
- let tag6 = TAG4 + " | sign | ";
2809
+ let tag6 = TAG5 + " | sign | ";
3069
2810
  try {
3070
2811
  if (!this.pioneer)
3071
2812
  throw Error("Failed to init! pioneer");
@@ -3223,7 +2964,7 @@ class TransactionManager {
3223
2964
  }
3224
2965
  }
3225
2966
  async broadcast({ networkId, serialized }) {
3226
- let tag6 = TAG4 + " | broadcast | ";
2967
+ let tag6 = TAG5 + " | broadcast | ";
3227
2968
  try {
3228
2969
  if (!this.pioneer)
3229
2970
  throw Error("Failed to init! pioneer");
@@ -3355,9 +3096,9 @@ var cosmosClaimAllRewardsTemplate = (params) => ({
3355
3096
  });
3356
3097
 
3357
3098
  // src/txbuilder/createUnsignedStakingTx.ts
3358
- var TAG5 = " | createUnsignedStakingTx | ";
3099
+ var TAG6 = " | createUnsignedStakingTx | ";
3359
3100
  async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyContext) {
3360
- const tag6 = TAG5 + " | createUnsignedStakingTx | ";
3101
+ const tag6 = TAG6 + " | createUnsignedStakingTx | ";
3361
3102
  try {
3362
3103
  if (!pioneer)
3363
3104
  throw new Error("Failed to init! pioneer");
@@ -3491,7 +3232,7 @@ async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyCon
3491
3232
  }
3492
3233
 
3493
3234
  // src/fees/index.ts
3494
- var TAG6 = " | Pioneer-sdk | fees | ";
3235
+ var TAG7 = " | Pioneer-sdk | fees | ";
3495
3236
  function getNetworkType(networkId) {
3496
3237
  if (networkId.startsWith("bip122:"))
3497
3238
  return "UTXO";
@@ -3531,7 +3272,7 @@ function withTimeout(promise, timeoutMs) {
3531
3272
  ]);
3532
3273
  }
3533
3274
  async function getFees(pioneer, networkId) {
3534
- const tag6 = TAG6 + " | getFees | ";
3275
+ const tag6 = TAG7 + " | getFees | ";
3535
3276
  try {
3536
3277
  console.log(tag6, `Fetching fees for network: ${networkId}`);
3537
3278
  const networkType = getNetworkType(networkId);
@@ -3998,9 +3739,9 @@ function formatTime(durationMs) {
3998
3739
 
3999
3740
  // src/utils/build-dashboard.ts
4000
3741
  var import_pioneer_caip6 = require("@pioneer-platform/pioneer-caip");
4001
- var TAG7 = " | build-dashboard | ";
3742
+ var TAG8 = " | build-dashboard | ";
4002
3743
  function buildDashboardFromBalances(balances, blockchains, assetsMap) {
4003
- console.log(TAG7, "[DASHBOARD] Building dashboard from cached balances...");
3744
+ console.log(TAG8, "[DASHBOARD] Building dashboard from cached balances...");
4004
3745
  const dashboardData = {
4005
3746
  networks: [],
4006
3747
  totalValueUsd: 0,
@@ -4008,7 +3749,7 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
4008
3749
  };
4009
3750
  let totalPortfolioValue = 0;
4010
3751
  const networksTemp = [];
4011
- console.log(TAG7, "balances: ", balances);
3752
+ console.log(TAG8, "balances: ", balances);
4012
3753
  for (const blockchain of blockchains) {
4013
3754
  const filteredBalances = balances.filter((b2) => {
4014
3755
  const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
@@ -4017,7 +3758,7 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
4017
3758
  const balanceMap = new Map;
4018
3759
  const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
4019
3760
  if (isBitcoin) {
4020
- console.log(TAG7, "Bitcoin network detected - checking for duplicate balances");
3761
+ console.log(TAG8, "Bitcoin network detected - checking for duplicate balances");
4021
3762
  const bitcoinByValue = new Map;
4022
3763
  filteredBalances.forEach((balance) => {
4023
3764
  const valueKey = `${balance.balance}_${balance.valueUsd}`;
@@ -4028,7 +3769,7 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
4028
3769
  });
4029
3770
  for (const [valueKey, balances2] of bitcoinByValue.entries()) {
4030
3771
  if (balances2.length === 3 && parseFloat(balances2[0].valueUsd || "0") > 0) {
4031
- console.log(TAG7, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
3772
+ console.log(TAG8, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
4032
3773
  const xpubBalance = balances2.find((b2) => b2.pubkey?.startsWith("xpub")) || balances2[0];
4033
3774
  const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
4034
3775
  balanceMap.set(key, xpubBalance);
@@ -4051,7 +3792,7 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
4051
3792
  const networkTotal = networkBalances.reduce((sum, balance, idx) => {
4052
3793
  const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
4053
3794
  if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
4054
- console.log(TAG7, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
3795
+ console.log(TAG8, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
4055
3796
  }
4056
3797
  return sum + valueUsd;
4057
3798
  }, 0);
@@ -4062,11 +3803,11 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
4062
3803
  return sum + balanceNum;
4063
3804
  }, 0).toString();
4064
3805
  const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
4065
- console.log(TAG7, `[DEBUG] Network: ${blockchain}`);
4066
- console.log(TAG7, `[DEBUG] nativeAssetCaip: ${nativeAssetCaip}`);
4067
- console.log(TAG7, `[DEBUG] assetInfo:`, assetInfo);
4068
- console.log(TAG7, `[DEBUG] gasAsset:`, gasAsset);
4069
- console.log(TAG7, `[DEBUG] Resolved name: ${gasAsset?.name || assetInfo?.name || "NO NAME"}`);
3806
+ console.log(TAG8, `[DEBUG] Network: ${blockchain}`);
3807
+ console.log(TAG8, `[DEBUG] nativeAssetCaip: ${nativeAssetCaip}`);
3808
+ console.log(TAG8, `[DEBUG] assetInfo:`, assetInfo);
3809
+ console.log(TAG8, `[DEBUG] gasAsset:`, gasAsset);
3810
+ console.log(TAG8, `[DEBUG] Resolved name: ${gasAsset?.name || assetInfo?.name || "NO NAME"}`);
4070
3811
  networksTemp.push({
4071
3812
  networkId: blockchain,
4072
3813
  totalValueUsd: networkTotal,
@@ -4090,9 +3831,9 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
4090
3831
  }
4091
3832
 
4092
3833
  // src/utils/sync-market.ts
4093
- var TAG8 = " | sync-market | ";
3834
+ var TAG9 = " | sync-market | ";
4094
3835
  async function syncMarket(balances, pioneer) {
4095
- const tag6 = `${TAG8} | syncMarket | `;
3836
+ const tag6 = `${TAG9} | syncMarket | `;
4096
3837
  try {
4097
3838
  const invalidBalances = balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
4098
3839
  if (invalidBalances.length > 0) {
@@ -4144,7 +3885,7 @@ async function syncMarket(balances, pioneer) {
4144
3885
  }
4145
3886
 
4146
3887
  // src/index.ts
4147
- var TAG9 = " | Pioneer-sdk | ";
3888
+ var TAG10 = " | Pioneer-sdk | ";
4148
3889
 
4149
3890
  class SDK {
4150
3891
  status;
@@ -4245,12 +3986,6 @@ class SDK {
4245
3986
  this.blockchains = config.blockchains ? [...new Set(config.blockchains)] : [];
4246
3987
  if (config.blockchains && config.blockchains.length !== this.blockchains.length) {
4247
3988
  }
4248
- if (config.pubkeys && config.pubkeys.length > 0) {
4249
- this.setPubkeys(config.pubkeys);
4250
- } else {
4251
- this.pubkeys = [];
4252
- this.pubkeySet.clear();
4253
- }
4254
3989
  this.balances = config.balances || [];
4255
3990
  this.nodes = config.nodes || [];
4256
3991
  this.charts = ["covalent", "zapper"];
@@ -4308,7 +4043,7 @@ class SDK {
4308
4043
  return true;
4309
4044
  };
4310
4045
  this.setPubkeys = (newPubkeys) => {
4311
- const tag6 = `${TAG9} | setPubkeys | `;
4046
+ const tag6 = `${TAG10} | setPubkeys | `;
4312
4047
  this.pubkeys = [];
4313
4048
  this.pubkeySet.clear();
4314
4049
  let added = 0;
@@ -4318,8 +4053,14 @@ class SDK {
4318
4053
  }
4319
4054
  }
4320
4055
  };
4056
+ if (config.pubkeys && config.pubkeys.length > 0) {
4057
+ this.setPubkeys(config.pubkeys);
4058
+ } else {
4059
+ this.pubkeys = [];
4060
+ this.pubkeySet.clear();
4061
+ }
4321
4062
  this.getUnifiedPortfolio = async function() {
4322
- const tag6 = `${TAG9} | getUnifiedPortfolio | `;
4063
+ const tag6 = `${TAG10} | getUnifiedPortfolio | `;
4323
4064
  try {
4324
4065
  const startTime = performance.now();
4325
4066
  try {
@@ -4427,7 +4168,7 @@ class SDK {
4427
4168
  }
4428
4169
  };
4429
4170
  this.init = async function(walletsVerbose, setup) {
4430
- const tag6 = `${TAG9} | init | `;
4171
+ const tag6 = `${TAG10} | init | `;
4431
4172
  try {
4432
4173
  if (!this.username)
4433
4174
  throw Error("username required!");
@@ -4444,7 +4185,7 @@ class SDK {
4444
4185
  const pioneerConfig = {
4445
4186
  ...config
4446
4187
  };
4447
- const PioneerClient = new import_pioneer_client.Pioneer(this.spec, pioneerConfig);
4188
+ const PioneerClient = new Pioneer(this.spec, pioneerConfig);
4448
4189
  this.pioneer = await PioneerClient.init();
4449
4190
  if (!this.pioneer)
4450
4191
  throw Error("Failed to init pioneer server!");
@@ -4521,7 +4262,7 @@ class SDK {
4521
4262
  return syncMarket(this.balances, this.pioneer);
4522
4263
  };
4523
4264
  this.sync = async function() {
4524
- const tag6 = `${TAG9} | sync | `;
4265
+ const tag6 = `${TAG10} | sync | `;
4525
4266
  try {
4526
4267
  const matchesNetwork = (item, networkId) => {
4527
4268
  if (!item.networks || !Array.isArray(item.networks))
@@ -4674,7 +4415,7 @@ class SDK {
4674
4415
  }
4675
4416
  };
4676
4417
  this.buildTx = async function(sendPayload) {
4677
- let tag6 = TAG9 + " | buildTx | ";
4418
+ let tag6 = TAG10 + " | buildTx | ";
4678
4419
  try {
4679
4420
  const transactionDependencies = {
4680
4421
  context: this.context,
@@ -4696,7 +4437,7 @@ class SDK {
4696
4437
  }
4697
4438
  };
4698
4439
  this.buildDelegateTx = async function(caip, params) {
4699
- let tag6 = TAG9 + " | buildDelegateTx | ";
4440
+ let tag6 = TAG10 + " | buildDelegateTx | ";
4700
4441
  try {
4701
4442
  const delegateParams = {
4702
4443
  ...params,
@@ -4711,7 +4452,7 @@ class SDK {
4711
4452
  }
4712
4453
  };
4713
4454
  this.buildUndelegateTx = async function(caip, params) {
4714
- let tag6 = TAG9 + " | buildUndelegateTx | ";
4455
+ let tag6 = TAG10 + " | buildUndelegateTx | ";
4715
4456
  try {
4716
4457
  const undelegateParams = {
4717
4458
  ...params,
@@ -4726,7 +4467,7 @@ class SDK {
4726
4467
  }
4727
4468
  };
4728
4469
  this.buildClaimRewardsTx = async function(caip, params) {
4729
- let tag6 = TAG9 + " | buildClaimRewardsTx | ";
4470
+ let tag6 = TAG10 + " | buildClaimRewardsTx | ";
4730
4471
  try {
4731
4472
  const claimParams = {
4732
4473
  ...params,
@@ -4741,7 +4482,7 @@ class SDK {
4741
4482
  }
4742
4483
  };
4743
4484
  this.buildClaimAllRewardsTx = async function(caip, params) {
4744
- let tag6 = TAG9 + " | buildClaimAllRewardsTx | ";
4485
+ let tag6 = TAG10 + " | buildClaimAllRewardsTx | ";
4745
4486
  try {
4746
4487
  const claimAllParams = {
4747
4488
  ...params,
@@ -4755,7 +4496,7 @@ class SDK {
4755
4496
  }
4756
4497
  };
4757
4498
  this.signTx = async function(caip, unsignedTx) {
4758
- let tag6 = TAG9 + " | signTx | ";
4499
+ let tag6 = TAG10 + " | signTx | ";
4759
4500
  try {
4760
4501
  const transactionDependencies = {
4761
4502
  context: this.context,
@@ -4776,7 +4517,7 @@ class SDK {
4776
4517
  }
4777
4518
  };
4778
4519
  this.broadcastTx = async function(caip, signedTx) {
4779
- let tag6 = TAG9 + " | broadcastTx | ";
4520
+ let tag6 = TAG10 + " | broadcastTx | ";
4780
4521
  try {
4781
4522
  const transactionDependencies = {
4782
4523
  context: this.context,
@@ -4800,7 +4541,7 @@ class SDK {
4800
4541
  }
4801
4542
  };
4802
4543
  this.swap = async function(swapPayload) {
4803
- let tag6 = `${TAG9} | swap | `;
4544
+ let tag6 = `${TAG10} | swap | `;
4804
4545
  try {
4805
4546
  if (!swapPayload)
4806
4547
  throw Error("swapPayload required!");
@@ -4939,7 +4680,7 @@ class SDK {
4939
4680
  }
4940
4681
  };
4941
4682
  this.transfer = async function(sendPayload) {
4942
- let tag6 = `${TAG9} | transfer | `;
4683
+ let tag6 = `${TAG10} | transfer | `;
4943
4684
  try {
4944
4685
  if (!sendPayload)
4945
4686
  throw Error("sendPayload required!");
@@ -5034,7 +4775,7 @@ class SDK {
5034
4775
  }
5035
4776
  };
5036
4777
  this.setBlockchains = async function(blockchains) {
5037
- const tag6 = `${TAG9} | setBlockchains | `;
4778
+ const tag6 = `${TAG10} | setBlockchains | `;
5038
4779
  try {
5039
4780
  if (!blockchains)
5040
4781
  throw Error("blockchains required!");
@@ -5050,7 +4791,7 @@ class SDK {
5050
4791
  }
5051
4792
  };
5052
4793
  this.addAsset = async function(caip, data) {
5053
- let tag6 = TAG9 + " | addAsset | ";
4794
+ let tag6 = TAG10 + " | addAsset | ";
5054
4795
  try {
5055
4796
  let success = false;
5056
4797
  if (!caip)
@@ -5088,7 +4829,7 @@ class SDK {
5088
4829
  }
5089
4830
  };
5090
4831
  this.clearWalletState = async function() {
5091
- const tag6 = `${TAG9} | clearWalletState | `;
4832
+ const tag6 = `${TAG10} | clearWalletState | `;
5092
4833
  try {
5093
4834
  this.context = null;
5094
4835
  this.paths = [];
@@ -5103,7 +4844,7 @@ class SDK {
5103
4844
  }
5104
4845
  };
5105
4846
  this.addPath = async function(path) {
5106
- const tag6 = `${TAG9} | addPath | `;
4847
+ const tag6 = `${TAG10} | addPath | `;
5107
4848
  try {
5108
4849
  this.paths.push(path);
5109
4850
  const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
@@ -5117,7 +4858,7 @@ class SDK {
5117
4858
  }
5118
4859
  };
5119
4860
  this.addPaths = async function(paths) {
5120
- const tag6 = `${TAG9} | addPaths | `;
4861
+ const tag6 = `${TAG10} | addPaths | `;
5121
4862
  try {
5122
4863
  console.log(tag6, `Adding ${paths.length} paths in batch mode...`);
5123
4864
  this.paths.push(...paths);
@@ -5153,7 +4894,7 @@ class SDK {
5153
4894
  return this.getGasAssets();
5154
4895
  };
5155
4896
  this.getGasAssets = async function() {
5156
- const tag6 = `${TAG9} | getGasAssets | `;
4897
+ const tag6 = `${TAG10} | getGasAssets | `;
5157
4898
  try {
5158
4899
  for (let i = 0;i < this.blockchains.length; i++) {
5159
4900
  let networkId = this.blockchains[i];
@@ -5196,7 +4937,7 @@ class SDK {
5196
4937
  }
5197
4938
  };
5198
4939
  this.getPubkeys = async function() {
5199
- const tag6 = `${TAG9} | getPubkeys | `;
4940
+ const tag6 = `${TAG10} | getPubkeys | `;
5200
4941
  try {
5201
4942
  if (this.paths.length === 0)
5202
4943
  throw new Error("No paths found!");
@@ -5217,7 +4958,7 @@ class SDK {
5217
4958
  }
5218
4959
  };
5219
4960
  this.getBalancesForNetworks = async function(networkIds) {
5220
- const tag6 = `${TAG9} | getBalancesForNetworks | `;
4961
+ const tag6 = `${TAG10} | getBalancesForNetworks | `;
5221
4962
  try {
5222
4963
  if (!this.pioneer) {
5223
4964
  console.error(tag6, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
@@ -5272,7 +5013,7 @@ class SDK {
5272
5013
  }
5273
5014
  };
5274
5015
  this.getBalances = async function() {
5275
- const tag6 = `${TAG9} | getBalances | `;
5016
+ const tag6 = `${TAG10} | getBalances | `;
5276
5017
  try {
5277
5018
  return await this.getBalancesForNetworks(this.blockchains);
5278
5019
  } catch (e) {
@@ -5281,7 +5022,7 @@ class SDK {
5281
5022
  }
5282
5023
  };
5283
5024
  this.getBalance = async function(networkId) {
5284
- const tag6 = `${TAG9} | getBalance | `;
5025
+ const tag6 = `${TAG10} | getBalance | `;
5285
5026
  try {
5286
5027
  const results = await this.getBalancesForNetworks([networkId]);
5287
5028
  const filtered = results.filter(async (b2) => b2.networkId === await import_pioneer_caip7.networkIdToCaip(networkId));
@@ -5292,7 +5033,7 @@ class SDK {
5292
5033
  }
5293
5034
  };
5294
5035
  this.getFees = async function(networkId) {
5295
- const tag6 = `${TAG9} | getFees | `;
5036
+ const tag6 = `${TAG10} | getFees | `;
5296
5037
  try {
5297
5038
  if (!this.pioneer) {
5298
5039
  throw new Error("Pioneer client not initialized. Call init() first.");
@@ -5307,7 +5048,7 @@ class SDK {
5307
5048
  return estimateTransactionFee(feeRate, unit, networkType, txSize);
5308
5049
  };
5309
5050
  this.getCharts = async function() {
5310
- const tag6 = `${TAG9} | getCharts | `;
5051
+ const tag6 = `${TAG10} | getCharts | `;
5311
5052
  try {
5312
5053
  console.log(tag6, "Fetching charts");
5313
5054
  const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
@@ -5329,7 +5070,7 @@ class SDK {
5329
5070
  }
5330
5071
  };
5331
5072
  this.setContext = async (context) => {
5332
- const tag6 = `${TAG9} | setContext | `;
5073
+ const tag6 = `${TAG10} | setContext | `;
5333
5074
  try {
5334
5075
  if (!context)
5335
5076
  throw Error("context required!");
@@ -5342,7 +5083,7 @@ class SDK {
5342
5083
  }
5343
5084
  };
5344
5085
  this.setContextType = async (contextType) => {
5345
- const tag6 = `${TAG9} | setContextType | `;
5086
+ const tag6 = `${TAG10} | setContextType | `;
5346
5087
  try {
5347
5088
  if (!contextType)
5348
5089
  throw Error("contextType required!");
@@ -5355,7 +5096,7 @@ class SDK {
5355
5096
  }
5356
5097
  };
5357
5098
  this.refresh = async () => {
5358
- const tag6 = `${TAG9} | refresh | `;
5099
+ const tag6 = `${TAG10} | refresh | `;
5359
5100
  try {
5360
5101
  await this.sync();
5361
5102
  return this.balances;
@@ -5365,7 +5106,7 @@ class SDK {
5365
5106
  }
5366
5107
  };
5367
5108
  this.setAssetContext = async function(asset) {
5368
- const tag6 = `${TAG9} | setAssetContext | `;
5109
+ const tag6 = `${TAG10} | setAssetContext | `;
5369
5110
  try {
5370
5111
  if (!asset) {
5371
5112
  this.assetContext = null;
@@ -5564,7 +5305,7 @@ class SDK {
5564
5305
  }
5565
5306
  };
5566
5307
  this.setPubkeyContext = async function(pubkey) {
5567
- let tag6 = `${TAG9} | setPubkeyContext | `;
5308
+ let tag6 = `${TAG10} | setPubkeyContext | `;
5568
5309
  try {
5569
5310
  if (!pubkey)
5570
5311
  throw Error("pubkey is required");
@@ -5583,7 +5324,7 @@ class SDK {
5583
5324
  }
5584
5325
  };
5585
5326
  this.setOutboundAssetContext = async function(asset) {
5586
- const tag6 = `${TAG9} | setOutputAssetContext | `;
5327
+ const tag6 = `${TAG10} | setOutputAssetContext | `;
5587
5328
  try {
5588
5329
  console.log(tag6, "0. asset: ", asset);
5589
5330
  if (!asset) {