@pioneer-platform/pioneer-sdk 4.20.0 → 4.20.2
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 +594 -838
- package/dist/index.es.js +595 -838
- package/dist/index.js +595 -838
- package/package.json +2 -2
- package/src/TransactionManager.ts +21 -4
- package/src/fees/index.ts +60 -57
- package/src/fees/index.ts.backup +510 -0
- package/src/getPubkey.ts +57 -26
- package/src/index.ts +391 -61
- package/src/txbuilder/createUnsignedEvmTx.ts +118 -63
- package/src/txbuilder/createUnsignedRippleTx.ts +12 -11
- package/src/txbuilder/createUnsignedStakingTx.ts +13 -11
- package/src/txbuilder/createUnsignedTendermintTx.ts +41 -17
- package/src/txbuilder/createUnsignedUxtoTx.ts +122 -57
- package/src/txbuilder/createUnsignedUxtoTx.ts.backup +384 -0
- package/src/txbuilder/templates/mayachain.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -40,398 +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.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
|
-
|
|
435
43
|
// ../../../node_modules/coinselect/utils.js
|
|
436
44
|
var require_utils = __commonJS((exports2, module2) => {
|
|
437
45
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
@@ -505,49 +113,6 @@ var require_utils = __commonJS((exports2, module2) => {
|
|
|
505
113
|
};
|
|
506
114
|
});
|
|
507
115
|
|
|
508
|
-
// ../../../node_modules/coinselect/split.js
|
|
509
|
-
var require_split = __commonJS((exports2, module2) => {
|
|
510
|
-
var utils = require_utils();
|
|
511
|
-
module2.exports = function split(utxos, outputs, feeRate) {
|
|
512
|
-
if (!isFinite(utils.uintOrNaN(feeRate)))
|
|
513
|
-
return {};
|
|
514
|
-
var bytesAccum = utils.transactionBytes(utxos, outputs);
|
|
515
|
-
var fee = feeRate * bytesAccum;
|
|
516
|
-
if (outputs.length === 0)
|
|
517
|
-
return { fee };
|
|
518
|
-
var inAccum = utils.sumOrNaN(utxos);
|
|
519
|
-
var outAccum = utils.sumForgiving(outputs);
|
|
520
|
-
var remaining = inAccum - outAccum - fee;
|
|
521
|
-
if (!isFinite(remaining) || remaining < 0)
|
|
522
|
-
return { fee };
|
|
523
|
-
var unspecified = outputs.reduce(function(a, x) {
|
|
524
|
-
return a + !isFinite(x.value);
|
|
525
|
-
}, 0);
|
|
526
|
-
if (remaining === 0 && unspecified === 0)
|
|
527
|
-
return utils.finalize(utxos, outputs, feeRate);
|
|
528
|
-
var splitOutputsCount = outputs.reduce(function(a, x) {
|
|
529
|
-
if (x.value !== undefined)
|
|
530
|
-
return a;
|
|
531
|
-
return a + 1;
|
|
532
|
-
}, 0);
|
|
533
|
-
var splitValue = Math.floor(remaining / splitOutputsCount);
|
|
534
|
-
if (!outputs.every(function(x) {
|
|
535
|
-
return x.value !== undefined || splitValue > utils.dustThreshold(x, feeRate);
|
|
536
|
-
}))
|
|
537
|
-
return { fee };
|
|
538
|
-
outputs = outputs.map(function(x) {
|
|
539
|
-
if (x.value !== undefined)
|
|
540
|
-
return x;
|
|
541
|
-
var y = {};
|
|
542
|
-
for (var k in x)
|
|
543
|
-
y[k] = x[k];
|
|
544
|
-
y.value = splitValue;
|
|
545
|
-
return y;
|
|
546
|
-
});
|
|
547
|
-
return utils.finalize(utxos, outputs, feeRate);
|
|
548
|
-
};
|
|
549
|
-
});
|
|
550
|
-
|
|
551
116
|
// ../../../node_modules/coinselect/accumulative.js
|
|
552
117
|
var require_accumulative = __commonJS((exports2, module2) => {
|
|
553
118
|
var utils = require_utils();
|
|
@@ -628,6 +193,49 @@ var require_coinselect = __commonJS((exports2, module2) => {
|
|
|
628
193
|
};
|
|
629
194
|
});
|
|
630
195
|
|
|
196
|
+
// ../../../node_modules/coinselect/split.js
|
|
197
|
+
var require_split = __commonJS((exports2, module2) => {
|
|
198
|
+
var utils = require_utils();
|
|
199
|
+
module2.exports = function split(utxos, outputs, feeRate) {
|
|
200
|
+
if (!isFinite(utils.uintOrNaN(feeRate)))
|
|
201
|
+
return {};
|
|
202
|
+
var bytesAccum = utils.transactionBytes(utxos, outputs);
|
|
203
|
+
var fee = feeRate * bytesAccum;
|
|
204
|
+
if (outputs.length === 0)
|
|
205
|
+
return { fee };
|
|
206
|
+
var inAccum = utils.sumOrNaN(utxos);
|
|
207
|
+
var outAccum = utils.sumForgiving(outputs);
|
|
208
|
+
var remaining = inAccum - outAccum - fee;
|
|
209
|
+
if (!isFinite(remaining) || remaining < 0)
|
|
210
|
+
return { fee };
|
|
211
|
+
var unspecified = outputs.reduce(function(a, x) {
|
|
212
|
+
return a + !isFinite(x.value);
|
|
213
|
+
}, 0);
|
|
214
|
+
if (remaining === 0 && unspecified === 0)
|
|
215
|
+
return utils.finalize(utxos, outputs, feeRate);
|
|
216
|
+
var splitOutputsCount = outputs.reduce(function(a, x) {
|
|
217
|
+
if (x.value !== undefined)
|
|
218
|
+
return a;
|
|
219
|
+
return a + 1;
|
|
220
|
+
}, 0);
|
|
221
|
+
var splitValue = Math.floor(remaining / splitOutputsCount);
|
|
222
|
+
if (!outputs.every(function(x) {
|
|
223
|
+
return x.value !== undefined || splitValue > utils.dustThreshold(x, feeRate);
|
|
224
|
+
}))
|
|
225
|
+
return { fee };
|
|
226
|
+
outputs = outputs.map(function(x) {
|
|
227
|
+
if (x.value !== undefined)
|
|
228
|
+
return x;
|
|
229
|
+
var y = {};
|
|
230
|
+
for (var k in x)
|
|
231
|
+
y[k] = x[k];
|
|
232
|
+
y.value = splitValue;
|
|
233
|
+
return y;
|
|
234
|
+
});
|
|
235
|
+
return utils.finalize(utxos, outputs, feeRate);
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
|
|
631
239
|
// src/index.ts
|
|
632
240
|
var exports_src = {};
|
|
633
241
|
__export(exports_src, {
|
|
@@ -636,12 +244,12 @@ __export(exports_src, {
|
|
|
636
244
|
});
|
|
637
245
|
module.exports = __toCommonJS(exports_src);
|
|
638
246
|
var import_keepkey_sdk = require("@keepkey/keepkey-sdk");
|
|
639
|
-
var
|
|
640
|
-
var import_pioneer_client = __toESM(
|
|
247
|
+
var import_pioneer_caip6 = require("@pioneer-platform/pioneer-caip");
|
|
248
|
+
var import_pioneer_client = __toESM(require("@pioneer-platform/pioneer-client"));
|
|
641
249
|
var import_pioneer_coins4 = require("@pioneer-platform/pioneer-coins");
|
|
642
250
|
var import_pioneer_discovery2 = require("@pioneer-platform/pioneer-discovery");
|
|
643
251
|
var import_pioneer_events = require("@pioneer-platform/pioneer-events");
|
|
644
|
-
var import_events = require("events");
|
|
252
|
+
var import_events = __toESM(require("events"));
|
|
645
253
|
|
|
646
254
|
// src/charts/utils.ts
|
|
647
255
|
var import_pioneer_discovery = require("@pioneer-platform/pioneer-discovery");
|
|
@@ -1230,42 +838,31 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1230
838
|
console.error("⏰ [PUBKEY] Address retrieval timeout for", networkId);
|
|
1231
839
|
}, 30000);
|
|
1232
840
|
try {
|
|
1233
|
-
let result;
|
|
1234
841
|
switch (networkType) {
|
|
1235
842
|
case "UTXO":
|
|
1236
|
-
|
|
843
|
+
({ address } = await sdk.address.utxoGetAddress(addressInfo));
|
|
1237
844
|
break;
|
|
1238
845
|
case "EVM":
|
|
1239
|
-
|
|
846
|
+
({ address } = await sdk.address.ethereumGetAddress(addressInfo));
|
|
1240
847
|
break;
|
|
1241
848
|
case "OSMOSIS":
|
|
1242
|
-
|
|
849
|
+
({ address } = await sdk.address.osmosisGetAddress(addressInfo));
|
|
1243
850
|
break;
|
|
1244
851
|
case "COSMOS":
|
|
1245
|
-
|
|
852
|
+
({ address } = await sdk.address.cosmosGetAddress(addressInfo));
|
|
1246
853
|
break;
|
|
1247
854
|
case "MAYACHAIN":
|
|
1248
|
-
|
|
855
|
+
({ address } = await sdk.address.mayachainGetAddress(addressInfo));
|
|
1249
856
|
break;
|
|
1250
857
|
case "THORCHAIN":
|
|
1251
|
-
|
|
858
|
+
({ address } = await sdk.address.thorchainGetAddress(addressInfo));
|
|
1252
859
|
break;
|
|
1253
860
|
case "XRP":
|
|
1254
|
-
|
|
861
|
+
({ address } = await sdk.address.xrpGetAddress(addressInfo));
|
|
1255
862
|
break;
|
|
1256
863
|
default:
|
|
1257
864
|
throw new Error(`Unsupported network type for networkId: ${networkId}`);
|
|
1258
865
|
}
|
|
1259
|
-
if (!result) {
|
|
1260
|
-
throw new Error(`Address call returned null/undefined for ${networkType} (${networkId})`);
|
|
1261
|
-
}
|
|
1262
|
-
if (typeof result === "object" && result.address) {
|
|
1263
|
-
address = result.address;
|
|
1264
|
-
} else if (typeof result === "string") {
|
|
1265
|
-
address = result;
|
|
1266
|
-
} else {
|
|
1267
|
-
throw new Error(`Invalid address response format for ${networkType} (${networkId}): ${JSON.stringify(result)}`);
|
|
1268
|
-
}
|
|
1269
866
|
clearTimeout(addressTimeout);
|
|
1270
867
|
} catch (addressError) {
|
|
1271
868
|
clearTimeout(addressTimeout);
|
|
@@ -1280,6 +877,10 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1280
877
|
pubkey.master = address;
|
|
1281
878
|
pubkey.address = address;
|
|
1282
879
|
if (["xpub", "ypub", "zpub"].includes(path.type)) {
|
|
880
|
+
console.log("\uD83D\uDD11 [XPUB] Starting xpub retrieval for path type:", path.type);
|
|
881
|
+
console.log("\uD83D\uDD11 [XPUB] Network:", networkId);
|
|
882
|
+
console.log("\uD83D\uDD11 [XPUB] Path:", import_pioneer_coins.addressNListToBIP32(path.addressNList));
|
|
883
|
+
console.log("\uD83D\uDD11 [XPUB] Script type:", path.script_type);
|
|
1283
884
|
const pathQuery = {
|
|
1284
885
|
symbol: "BTC",
|
|
1285
886
|
coin: "Bitcoin",
|
|
@@ -1287,26 +888,58 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1287
888
|
address_n: path.addressNList,
|
|
1288
889
|
showDisplay: false
|
|
1289
890
|
};
|
|
891
|
+
console.log("\uD83D\uDD11 [XPUB] Calling sdk.system.info.getPublicKey with:", JSON.stringify(pathQuery, null, 2));
|
|
1290
892
|
const xpubTimeout = setTimeout(() => {
|
|
1291
|
-
console.error("getPublicKey timeout after 20 seconds");
|
|
893
|
+
console.error("⏰ [XPUB TIMEOUT] getPublicKey timeout after 20 seconds");
|
|
894
|
+
console.error("⏰ [XPUB TIMEOUT] Path:", import_pioneer_coins.addressNListToBIP32(path.addressNList));
|
|
895
|
+
console.error("⏰ [XPUB TIMEOUT] This is a CRITICAL FAILURE - UTXO balances require xpubs");
|
|
1292
896
|
}, 20000);
|
|
1293
897
|
try {
|
|
898
|
+
console.log("\uD83D\uDD11 [XPUB] Calling getPublicKey...");
|
|
1294
899
|
const responsePubkey = await sdk.system.info.getPublicKey(pathQuery);
|
|
1295
900
|
clearTimeout(xpubTimeout);
|
|
901
|
+
console.log("✅ [XPUB] getPublicKey SUCCESS");
|
|
902
|
+
console.log("✅ [XPUB] Response:", JSON.stringify(responsePubkey, null, 2));
|
|
903
|
+
if (!responsePubkey || !responsePubkey.xpub) {
|
|
904
|
+
const error = new Error("FAIL FAST: getPublicKey returned null or missing xpub");
|
|
905
|
+
console.error("❌ [XPUB] CRITICAL:", error.message);
|
|
906
|
+
console.error("❌ [XPUB] Response was:", responsePubkey);
|
|
907
|
+
throw error;
|
|
908
|
+
}
|
|
1296
909
|
if (path.script_type === "p2wpkh") {
|
|
910
|
+
console.log("\uD83D\uDD11 [XPUB] Converting xpub to zpub for native segwit");
|
|
1297
911
|
responsePubkey.xpub = import_pioneer_coins.xpubConvert(responsePubkey.xpub, "zpub");
|
|
1298
912
|
} else if (path.script_type === "p2sh-p2wpkh") {
|
|
913
|
+
console.log("\uD83D\uDD11 [XPUB] Converting xpub to ypub for wrapped segwit");
|
|
1299
914
|
responsePubkey.xpub = import_pioneer_coins.xpubConvert(responsePubkey.xpub, "ypub");
|
|
1300
915
|
}
|
|
916
|
+
console.log("✅ [XPUB] Final xpub:", responsePubkey.xpub.substring(0, 20) + "...");
|
|
1301
917
|
pubkey.pubkey = responsePubkey.xpub;
|
|
1302
918
|
pubkey.path = import_pioneer_coins.addressNListToBIP32(path.addressNList);
|
|
1303
919
|
pubkey.pathMaster = import_pioneer_coins.addressNListToBIP32(path.addressNListMaster);
|
|
920
|
+
console.log("✅ [XPUB] Xpub retrieval COMPLETE for", path.note || path.type);
|
|
1304
921
|
} catch (xpubError) {
|
|
1305
922
|
clearTimeout(xpubTimeout);
|
|
1306
|
-
console.error("getPublicKey failed
|
|
1307
|
-
|
|
923
|
+
console.error("❌ [XPUB] CRITICAL FAILURE - getPublicKey failed");
|
|
924
|
+
console.error("❌ [XPUB] Error:", xpubError);
|
|
925
|
+
console.error("❌ [XPUB] Error message:", xpubError.message);
|
|
926
|
+
console.error("❌ [XPUB] Error stack:", xpubError.stack);
|
|
927
|
+
console.error("❌ [XPUB] Path:", import_pioneer_coins.addressNListToBIP32(path.addressNList));
|
|
928
|
+
console.error("❌ [XPUB] Network:", networkId);
|
|
929
|
+
console.error("❌ [XPUB] Query:", JSON.stringify(pathQuery, null, 2));
|
|
930
|
+
console.error("❌ [XPUB] SDK available:", !!sdk);
|
|
931
|
+
console.error("❌ [XPUB] SDK.system available:", !!sdk?.system);
|
|
932
|
+
console.error("❌ [XPUB] SDK.system.info available:", !!sdk?.system?.info);
|
|
933
|
+
console.error("❌ [XPUB] SDK.system.info.getPublicKey available:", !!sdk?.system?.info?.getPublicKey);
|
|
934
|
+
console.error("");
|
|
935
|
+
console.error("\uD83D\uDEA8 FAIL FAST: Cannot proceed without xpub for UTXO chains");
|
|
936
|
+
console.error("\uD83D\uDEA8 UTXO balance queries REQUIRE extended public keys (xpubs)");
|
|
937
|
+
console.error("\uD83D\uDEA8 This is a device communication or SDK issue that must be resolved");
|
|
938
|
+
console.error("");
|
|
939
|
+
throw new Error(`FAIL FAST - xpub retrieval failed for ${networkId} at ${import_pioneer_coins.addressNListToBIP32(path.addressNList)}: ${xpubError.message}`);
|
|
1308
940
|
}
|
|
1309
941
|
} else {
|
|
942
|
+
console.log("\uD83D\uDD11 [PUBKEY] Non-xpub path (address-based), using address as pubkey");
|
|
1310
943
|
pubkey.pubkey = address;
|
|
1311
944
|
pubkey.path = import_pioneer_coins.addressNListToBIP32(path.addressNList);
|
|
1312
945
|
pubkey.pathMaster = import_pioneer_coins.addressNListToBIP32(path.addressNListMaster);
|
|
@@ -1716,13 +1349,16 @@ async function fetchTokenPriceInUsd(contractAddress) {
|
|
|
1716
1349
|
}
|
|
1717
1350
|
return price;
|
|
1718
1351
|
}
|
|
1719
|
-
async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer,
|
|
1352
|
+
async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5) {
|
|
1720
1353
|
const tag5 = TAG + " | createUnsignedEvmTx | ";
|
|
1721
1354
|
try {
|
|
1722
1355
|
if (!pioneer)
|
|
1723
1356
|
throw new Error("Failed to initialize Pioneer");
|
|
1724
1357
|
const networkId = import_pioneer_caip.caipToNetworkId(caip);
|
|
1725
1358
|
const chainId = extractChainIdFromNetworkId(networkId);
|
|
1359
|
+
if (!pubkeyContext) {
|
|
1360
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
1361
|
+
}
|
|
1726
1362
|
const isValidForNetwork = (pubkey) => {
|
|
1727
1363
|
if (!pubkey?.networks)
|
|
1728
1364
|
return false;
|
|
@@ -1731,43 +1367,83 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
1731
1367
|
}
|
|
1732
1368
|
return pubkey.networks.includes(networkId);
|
|
1733
1369
|
};
|
|
1734
|
-
if (!
|
|
1735
|
-
|
|
1736
|
-
keepKeySdk.pubkeyContext = pubkeys.find((pk) => isValidForNetwork(pk));
|
|
1737
|
-
} else {
|
|
1738
|
-
console.log(tag5, "Current context networks:", keepKeySdk.pubkeyContext.networks, "For networkId:", networkId);
|
|
1739
|
-
if (!isValidForNetwork(keepKeySdk.pubkeyContext)) {
|
|
1740
|
-
console.log(tag5, "Auto-correcting context - wrong network detected");
|
|
1741
|
-
keepKeySdk.pubkeyContext = pubkeys.find((pk) => isValidForNetwork(pk));
|
|
1742
|
-
} else {
|
|
1743
|
-
console.log(tag5, "Context is valid for this network - using existing context");
|
|
1744
|
-
}
|
|
1370
|
+
if (!isValidForNetwork(pubkeyContext)) {
|
|
1371
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
1745
1372
|
}
|
|
1746
|
-
const address =
|
|
1747
|
-
console.log(tag5, "✅ Using FROM address from pubkeyContext:", address, "note:",
|
|
1373
|
+
const address = pubkeyContext.address || pubkeyContext.pubkey;
|
|
1374
|
+
console.log(tag5, "✅ Using FROM address from pubkeyContext:", address, "note:", pubkeyContext.note);
|
|
1748
1375
|
if (!address)
|
|
1749
1376
|
throw new Error("No address found for the specified network");
|
|
1750
1377
|
const gasPriceData = await pioneer.GetGasPriceByNetwork({ networkId });
|
|
1751
|
-
|
|
1752
|
-
const MIN_GAS_PRICE_WEI = BigInt(10000000000);
|
|
1753
|
-
if (BigInt(gasPriceData.data) < MIN_GAS_PRICE_WEI) {
|
|
1754
|
-
console.log(tag5, "Gas price from API too low:", gasPriceData.data, "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1755
|
-
baseGasPrice = MIN_GAS_PRICE_WEI;
|
|
1756
|
-
} else {
|
|
1757
|
-
baseGasPrice = BigInt(gasPriceData.data);
|
|
1758
|
-
}
|
|
1378
|
+
console.log(tag5, "Gas price data from API:", JSON.stringify(gasPriceData.data));
|
|
1759
1379
|
let gasPrice;
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1380
|
+
const defaultGasPrices = {
|
|
1381
|
+
1: 30,
|
|
1382
|
+
56: 3,
|
|
1383
|
+
137: 50,
|
|
1384
|
+
43114: 25,
|
|
1385
|
+
8453: 0.1,
|
|
1386
|
+
10: 0.1
|
|
1387
|
+
};
|
|
1388
|
+
const fallbackGasGwei = defaultGasPrices[chainId] || 20;
|
|
1389
|
+
const MIN_GAS_PRICE_WEI = BigInt(fallbackGasGwei * 1e9);
|
|
1390
|
+
if (typeof gasPriceData.data === "object" && gasPriceData.data !== null && !Array.isArray(gasPriceData.data)) {
|
|
1391
|
+
let selectedGasPrice;
|
|
1392
|
+
if (feeLevel <= 2) {
|
|
1393
|
+
selectedGasPrice = gasPriceData.data.slow || gasPriceData.data.average || gasPriceData.data.fastest;
|
|
1394
|
+
console.log(tag5, "Selecting SLOW gas price from API");
|
|
1395
|
+
} else if (feeLevel >= 8) {
|
|
1396
|
+
selectedGasPrice = gasPriceData.data.fastest || gasPriceData.data.fast || gasPriceData.data.average;
|
|
1397
|
+
console.log(tag5, "Selecting FAST gas price from API");
|
|
1398
|
+
} else {
|
|
1399
|
+
selectedGasPrice = gasPriceData.data.average || gasPriceData.data.fast || gasPriceData.data.fastest;
|
|
1400
|
+
console.log(tag5, "Selecting AVERAGE gas price from API");
|
|
1401
|
+
}
|
|
1402
|
+
let gasPriceNum;
|
|
1403
|
+
if (selectedGasPrice === undefined || selectedGasPrice === null) {
|
|
1404
|
+
console.warn(tag5, "No valid gas price found in API response, using fallback:", fallbackGasGwei, "gwei");
|
|
1405
|
+
gasPriceNum = fallbackGasGwei;
|
|
1406
|
+
} else {
|
|
1407
|
+
gasPriceNum = typeof selectedGasPrice === "string" ? parseFloat(selectedGasPrice) : selectedGasPrice;
|
|
1408
|
+
if (isNaN(gasPriceNum) || !isFinite(gasPriceNum)) {
|
|
1409
|
+
console.warn(tag5, "Invalid gas price (NaN or Infinite):", selectedGasPrice, "- using fallback:", fallbackGasGwei, "gwei");
|
|
1410
|
+
gasPriceNum = fallbackGasGwei;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
gasPrice = BigInt(Math.round(gasPriceNum * 1e9));
|
|
1414
|
+
if (gasPrice < MIN_GAS_PRICE_WEI) {
|
|
1415
|
+
console.warn(tag5, "Gas price from API too low:", gasPrice.toString(), "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1416
|
+
gasPrice = MIN_GAS_PRICE_WEI;
|
|
1417
|
+
}
|
|
1766
1418
|
} else {
|
|
1767
|
-
|
|
1768
|
-
|
|
1419
|
+
let gasPriceNum;
|
|
1420
|
+
if (gasPriceData.data === undefined || gasPriceData.data === null) {
|
|
1421
|
+
console.warn(tag5, "Gas price API returned null/undefined, using fallback:", fallbackGasGwei, "gwei");
|
|
1422
|
+
gasPriceNum = fallbackGasGwei;
|
|
1423
|
+
} else {
|
|
1424
|
+
gasPriceNum = typeof gasPriceData.data === "string" ? parseFloat(gasPriceData.data) : gasPriceData.data;
|
|
1425
|
+
if (isNaN(gasPriceNum) || !isFinite(gasPriceNum)) {
|
|
1426
|
+
console.warn(tag5, "Invalid gas price (NaN or Infinite):", gasPriceData.data, "- using fallback:", fallbackGasGwei, "gwei");
|
|
1427
|
+
gasPriceNum = fallbackGasGwei;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
const baseGasPrice = BigInt(Math.round(gasPriceNum * 1e9));
|
|
1431
|
+
if (feeLevel <= 2) {
|
|
1432
|
+
gasPrice = baseGasPrice * BigInt(80) / BigInt(100);
|
|
1433
|
+
console.log(tag5, "Using SLOW gas price (80% of base)");
|
|
1434
|
+
} else if (feeLevel >= 8) {
|
|
1435
|
+
gasPrice = baseGasPrice * BigInt(150) / BigInt(100);
|
|
1436
|
+
console.log(tag5, "Using FAST gas price (150% of base)");
|
|
1437
|
+
} else {
|
|
1438
|
+
gasPrice = baseGasPrice;
|
|
1439
|
+
console.log(tag5, "Using AVERAGE gas price (100% of base)");
|
|
1440
|
+
}
|
|
1441
|
+
if (gasPrice < MIN_GAS_PRICE_WEI) {
|
|
1442
|
+
console.warn(tag5, "Gas price too low:", gasPrice.toString(), "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1443
|
+
gasPrice = MIN_GAS_PRICE_WEI;
|
|
1444
|
+
}
|
|
1769
1445
|
}
|
|
1770
|
-
console.log(tag5, "
|
|
1446
|
+
console.log(tag5, "Final gasPrice:", gasPrice.toString(), "wei (", Number(gasPrice) / 1e9, "gwei)");
|
|
1771
1447
|
let nonce;
|
|
1772
1448
|
try {
|
|
1773
1449
|
const nonceData = await pioneer.GetNonceByNetwork({ networkId, address });
|
|
@@ -1958,18 +1634,18 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
1958
1634
|
throw new Error(`Unsupported asset type for CAIP ${caip}`);
|
|
1959
1635
|
}
|
|
1960
1636
|
}
|
|
1961
|
-
if (
|
|
1962
|
-
unsignedTx.addressNList =
|
|
1637
|
+
if (pubkeyContext.addressNListMaster) {
|
|
1638
|
+
unsignedTx.addressNList = pubkeyContext.addressNListMaster;
|
|
1963
1639
|
console.log(tag5, "✅ Using addressNListMaster from pubkey context:", unsignedTx.addressNList, "for address:", address);
|
|
1964
|
-
} else if (
|
|
1965
|
-
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(
|
|
1966
|
-
console.log(tag5, "✅ Converted pathMaster to addressNList:",
|
|
1967
|
-
} else if (
|
|
1968
|
-
unsignedTx.addressNList =
|
|
1640
|
+
} else if (pubkeyContext.pathMaster) {
|
|
1641
|
+
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(pubkeyContext.pathMaster);
|
|
1642
|
+
console.log(tag5, "✅ Converted pathMaster to addressNList:", pubkeyContext.pathMaster, "→", unsignedTx.addressNList);
|
|
1643
|
+
} else if (pubkeyContext.addressNList) {
|
|
1644
|
+
unsignedTx.addressNList = pubkeyContext.addressNList;
|
|
1969
1645
|
console.log(tag5, "✅ Using addressNList from pubkey context:", unsignedTx.addressNList);
|
|
1970
|
-
} else if (
|
|
1971
|
-
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(
|
|
1972
|
-
console.log(tag5, "⚠️ Using regular path (not master):",
|
|
1646
|
+
} else if (pubkeyContext.path) {
|
|
1647
|
+
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(pubkeyContext.path);
|
|
1648
|
+
console.log(tag5, "⚠️ Using regular path (not master):", pubkeyContext.path, "→", unsignedTx.addressNList);
|
|
1973
1649
|
} else {
|
|
1974
1650
|
unsignedTx.addressNList = [2147483648 + 44, 2147483648 + 60, 2147483648, 0, 0];
|
|
1975
1651
|
console.warn(tag5, "⚠️ No path info in pubkey context, using default account 0");
|
|
@@ -1984,19 +1660,22 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
1984
1660
|
// src/txbuilder/createUnsignedRippleTx.ts
|
|
1985
1661
|
var import_pioneer_caip2 = require("@pioneer-platform/pioneer-caip");
|
|
1986
1662
|
var TAG2 = " | createUnsignedUxtoTx | ";
|
|
1987
|
-
async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer,
|
|
1663
|
+
async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax) {
|
|
1988
1664
|
let tag5 = TAG2 + " | createUnsignedRippleTx | ";
|
|
1989
1665
|
try {
|
|
1990
1666
|
if (!pioneer)
|
|
1991
1667
|
throw new Error("Failed to init! pioneer");
|
|
1992
1668
|
const networkId = import_pioneer_caip2.caipToNetworkId(caip);
|
|
1993
|
-
if (!
|
|
1994
|
-
|
|
1669
|
+
if (!pubkeyContext) {
|
|
1670
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
1995
1671
|
}
|
|
1996
|
-
if (!
|
|
1997
|
-
throw new Error(`
|
|
1672
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
1673
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
1998
1674
|
}
|
|
1999
|
-
|
|
1675
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
1676
|
+
address: pubkeyContext.address
|
|
1677
|
+
});
|
|
1678
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
2000
1679
|
let accountInfo = await pioneer.GetAccountInfo({
|
|
2001
1680
|
address: fromAddress,
|
|
2002
1681
|
network: "ripple"
|
|
@@ -2094,6 +1773,7 @@ var cosmosTransferTemplate = (params) => ({
|
|
|
2094
1773
|
// src/txbuilder/templates/mayachain.ts
|
|
2095
1774
|
var mayachainTransferTemplate = (params) => ({
|
|
2096
1775
|
signerAddress: params.from_address,
|
|
1776
|
+
addressNList: params.addressNList,
|
|
2097
1777
|
signDoc: {
|
|
2098
1778
|
account_number: params.account_number,
|
|
2099
1779
|
chain_id: params.chain_id,
|
|
@@ -2199,18 +1879,22 @@ var thorchainDepositTemplate = (params) => ({
|
|
|
2199
1879
|
|
|
2200
1880
|
// src/txbuilder/createUnsignedTendermintTx.ts
|
|
2201
1881
|
var TAG3 = " | createUnsignedTendermintTx | ";
|
|
2202
|
-
async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pioneer,
|
|
1882
|
+
async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, to) {
|
|
2203
1883
|
const tag5 = TAG3 + " | createUnsignedTendermintTx | ";
|
|
2204
1884
|
try {
|
|
2205
1885
|
if (!pioneer)
|
|
2206
1886
|
throw new Error("Failed to init! pioneer");
|
|
2207
1887
|
const networkId = import_pioneer_caip3.caipToNetworkId(caip);
|
|
2208
|
-
if (!
|
|
2209
|
-
|
|
1888
|
+
if (!pubkeyContext) {
|
|
1889
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
2210
1890
|
}
|
|
2211
|
-
if (!
|
|
2212
|
-
throw new Error(`
|
|
1891
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
1892
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2213
1893
|
}
|
|
1894
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
1895
|
+
address: pubkeyContext.address,
|
|
1896
|
+
addressNList: pubkeyContext.addressNList || pubkeyContext.addressNListMaster
|
|
1897
|
+
});
|
|
2214
1898
|
let chain;
|
|
2215
1899
|
switch (networkId) {
|
|
2216
1900
|
case "cosmos:thorchain-mainnet-v1":
|
|
@@ -2228,10 +1912,13 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2228
1912
|
default:
|
|
2229
1913
|
throw new Error(`Unhandled networkId: ${networkId}`);
|
|
2230
1914
|
}
|
|
2231
|
-
const fromAddress =
|
|
1915
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
2232
1916
|
let asset = caip.split(":")[1];
|
|
1917
|
+
console.log(tag5, `\uD83D\uDD0D Fetching account info for address: ${fromAddress}`);
|
|
2233
1918
|
const accountInfo = (await pioneer.GetAccountInfo({ network: chain, address: fromAddress })).data;
|
|
1919
|
+
console.log(tag5, "\uD83D\uDCCB accountInfo:", JSON.stringify(accountInfo, null, 2));
|
|
2234
1920
|
let balanceInfo = await pioneer.GetPubkeyBalance({ asset: chain, pubkey: fromAddress });
|
|
1921
|
+
console.log(tag5, `\uD83D\uDCB0 balanceInfo:`, balanceInfo);
|
|
2235
1922
|
let account_number, sequence;
|
|
2236
1923
|
if (networkId === "cosmos:cosmoshub-4" || networkId === "cosmos:osmosis-1") {
|
|
2237
1924
|
account_number = accountInfo.account.account_number || "0";
|
|
@@ -2240,9 +1927,17 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2240
1927
|
account_number = accountInfo.result.value.account_number || "0";
|
|
2241
1928
|
sequence = accountInfo.result.value.sequence || "0";
|
|
2242
1929
|
}
|
|
1930
|
+
console.log(tag5, `\uD83D\uDCCA Extracted account_number: ${account_number}, sequence: ${sequence}`);
|
|
1931
|
+
if (account_number === "0" || account_number === 0) {
|
|
1932
|
+
console.log(tag5, `⚠️ WARNING: Account number is 0 from Pioneer API`);
|
|
1933
|
+
console.log(tag5, ` This is likely due to stale Pioneer API cache`);
|
|
1934
|
+
console.log(tag5, ` The mayachain-network module queries nodes directly but Pioneer API may be cached`);
|
|
1935
|
+
console.log(tag5, ` Proceeding with account_number: 0 but transaction will likely fail`);
|
|
1936
|
+
console.log(tag5, ` TODO: Fix Pioneer API to use fresh data from mayachain-network module`);
|
|
1937
|
+
}
|
|
2243
1938
|
const fees = {
|
|
2244
1939
|
"cosmos:thorchain-mainnet-v1": 0.02,
|
|
2245
|
-
"cosmos:mayachain-mainnet-v1": 0
|
|
1940
|
+
"cosmos:mayachain-mainnet-v1": 0,
|
|
2246
1941
|
"cosmos:cosmoshub-4": 0.005,
|
|
2247
1942
|
"cosmos:osmosis-1": 0.035
|
|
2248
1943
|
};
|
|
@@ -2301,11 +1996,12 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2301
1996
|
} else {
|
|
2302
1997
|
throw new Error(`Unsupported Maya chain CAIP: ${caip}`);
|
|
2303
1998
|
}
|
|
1999
|
+
const decimals = mayaAsset === "maya" ? 1e4 : 10000000000;
|
|
2304
2000
|
if (isMax) {
|
|
2305
|
-
const fee = Math.floor(fees[networkId] *
|
|
2306
|
-
amount = Math.max(0, Math.floor(balanceInfo.data *
|
|
2001
|
+
const fee = Math.floor(fees[networkId] * decimals);
|
|
2002
|
+
amount = Math.max(0, Math.floor(balanceInfo.data * decimals) - fee);
|
|
2307
2003
|
} else {
|
|
2308
|
-
amount = Math.max(Math.floor(amount *
|
|
2004
|
+
amount = Math.max(Math.floor(amount * decimals), 0);
|
|
2309
2005
|
}
|
|
2310
2006
|
return to ? mayachainTransferTemplate({
|
|
2311
2007
|
account_number,
|
|
@@ -2324,7 +2020,8 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2324
2020
|
asset: mayaAsset,
|
|
2325
2021
|
amount: amount.toString(),
|
|
2326
2022
|
memo,
|
|
2327
|
-
sequence
|
|
2023
|
+
sequence,
|
|
2024
|
+
addressNList: pubkeyContext.addressNList || pubkeyContext.addressNListMaster
|
|
2328
2025
|
}) : mayachainDepositTemplate({
|
|
2329
2026
|
account_number,
|
|
2330
2027
|
chain_id: "mayachain-mainnet-v1",
|
|
@@ -2399,52 +2096,50 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2399
2096
|
// src/txbuilder/createUnsignedUxtoTx.ts
|
|
2400
2097
|
var import_pioneer_caip4 = require("@pioneer-platform/pioneer-caip");
|
|
2401
2098
|
var import_pioneer_coins3 = require("@pioneer-platform/pioneer-coins");
|
|
2402
|
-
|
|
2099
|
+
var import_coinselect = __toESM(require_coinselect());
|
|
2100
|
+
var import_split = __toESM(require_split());
|
|
2101
|
+
function getCoinTypeFromNetworkId(networkId) {
|
|
2102
|
+
const chain = import_pioneer_caip4.NetworkIdToChain[networkId];
|
|
2103
|
+
if (!chain) {
|
|
2104
|
+
console.warn(`No chain mapping found for ${networkId}, defaulting to Bitcoin coin type 0`);
|
|
2105
|
+
return 0;
|
|
2106
|
+
}
|
|
2107
|
+
const blockchainName = import_pioneer_coins3.COIN_MAP_LONG[chain]?.toLowerCase();
|
|
2108
|
+
if (!blockchainName) {
|
|
2109
|
+
console.warn(`No blockchain name found for chain ${chain}, defaulting to Bitcoin coin type 0`);
|
|
2110
|
+
return 0;
|
|
2111
|
+
}
|
|
2112
|
+
const coinType = import_pioneer_coins3.SLIP_44_BY_LONG[blockchainName];
|
|
2113
|
+
if (coinType === undefined) {
|
|
2114
|
+
console.warn(`No SLIP-44 coin type found for ${blockchainName}, defaulting to Bitcoin coin type 0`);
|
|
2115
|
+
return 0;
|
|
2116
|
+
}
|
|
2117
|
+
return coinType;
|
|
2118
|
+
}
|
|
2119
|
+
async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5, changeScriptType) {
|
|
2403
2120
|
let tag5 = " | createUnsignedUxtoTx | ";
|
|
2404
2121
|
try {
|
|
2405
2122
|
if (!pioneer)
|
|
2406
2123
|
throw Error("Failed to init! pioneer");
|
|
2407
2124
|
const networkId = import_pioneer_caip4.caipToNetworkId(caip);
|
|
2408
|
-
if (!
|
|
2409
|
-
|
|
2125
|
+
if (!pubkeyContext) {
|
|
2126
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
2410
2127
|
}
|
|
2128
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2129
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2130
|
+
}
|
|
2131
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2132
|
+
address: pubkeyContext.address,
|
|
2133
|
+
scriptType: pubkeyContext.scriptType
|
|
2134
|
+
});
|
|
2411
2135
|
const relevantPubkeys = pubkeys.filter((e) => e.networks && Array.isArray(e.networks) && e.networks.includes(networkId));
|
|
2412
2136
|
const segwitNetworks = [
|
|
2413
2137
|
"bip122:000000000019d6689c085ae165831e93"
|
|
2414
2138
|
];
|
|
2415
2139
|
const isSegwit = segwitNetworks.includes(networkId);
|
|
2416
2140
|
let chain = import_pioneer_caip4.NetworkIdToChain[networkId];
|
|
2417
|
-
const
|
|
2418
|
-
console.log(`${tag5}: Using
|
|
2419
|
-
const changeXpub = relevantPubkeys.find((pk) => pk.scriptType === actualChangeScriptType)?.pubkey || relevantPubkeys.find((pk) => pk.scriptType === "p2wpkh")?.pubkey || relevantPubkeys[0].pubkey;
|
|
2420
|
-
console.log(`${tag5}: Change xpub selected for ${actualChangeScriptType}:`, changeXpub?.substring(0, 10) + "...");
|
|
2421
|
-
let changeAddressIndex = await pioneer.GetChangeAddress({
|
|
2422
|
-
network: chain,
|
|
2423
|
-
xpub: changeXpub
|
|
2424
|
-
});
|
|
2425
|
-
changeAddressIndex = changeAddressIndex.data.changeIndex;
|
|
2426
|
-
let bipPath;
|
|
2427
|
-
switch (actualChangeScriptType) {
|
|
2428
|
-
case "p2pkh":
|
|
2429
|
-
bipPath = `m/44'/0'/0'/1/${changeAddressIndex}`;
|
|
2430
|
-
break;
|
|
2431
|
-
case "p2sh-p2wpkh":
|
|
2432
|
-
bipPath = `m/49'/0'/0'/1/${changeAddressIndex}`;
|
|
2433
|
-
break;
|
|
2434
|
-
case "p2wpkh":
|
|
2435
|
-
default:
|
|
2436
|
-
bipPath = `m/84'/0'/0'/1/${changeAddressIndex}`;
|
|
2437
|
-
break;
|
|
2438
|
-
}
|
|
2439
|
-
const path = bipPath;
|
|
2440
|
-
console.log(`${tag5}: Change address path: ${path} (index: ${changeAddressIndex})`);
|
|
2441
|
-
const changeAddress = {
|
|
2442
|
-
path,
|
|
2443
|
-
isChange: true,
|
|
2444
|
-
index: changeAddressIndex,
|
|
2445
|
-
addressNList: import_pioneer_coins3.bip32ToAddressNList(path),
|
|
2446
|
-
scriptType: actualChangeScriptType
|
|
2447
|
-
};
|
|
2141
|
+
const coinType = getCoinTypeFromNetworkId(networkId);
|
|
2142
|
+
console.log(`${tag5}: Using SLIP-44 coin type ${coinType} for ${chain}`);
|
|
2448
2143
|
const utxos = [];
|
|
2449
2144
|
for (const pubkey of relevantPubkeys) {
|
|
2450
2145
|
try {
|
|
@@ -2470,6 +2165,48 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, ke
|
|
|
2470
2165
|
for (const utxo of utxos) {
|
|
2471
2166
|
utxo.value = Number(utxo.value);
|
|
2472
2167
|
}
|
|
2168
|
+
const inputScriptTypes = utxos.map((u) => u.scriptType).filter(Boolean);
|
|
2169
|
+
const scriptTypeCount = inputScriptTypes.reduce((acc, type) => {
|
|
2170
|
+
acc[type] = (acc[type] || 0) + 1;
|
|
2171
|
+
return acc;
|
|
2172
|
+
}, {});
|
|
2173
|
+
const mostCommonInputType = Object.entries(scriptTypeCount).sort(([, a], [, b2]) => b2 - a)[0]?.[0] || "p2pkh";
|
|
2174
|
+
const actualChangeScriptType = changeScriptType || mostCommonInputType || relevantPubkeys[0]?.scriptType || "p2pkh";
|
|
2175
|
+
console.log(`${tag5}: Input script types:`, scriptTypeCount);
|
|
2176
|
+
console.log(`${tag5}: Using change script type: ${actualChangeScriptType} (matches inputs: ${mostCommonInputType})`);
|
|
2177
|
+
const changeXpubInfo = relevantPubkeys.find((pk) => pk.scriptType === actualChangeScriptType);
|
|
2178
|
+
if (!changeXpubInfo) {
|
|
2179
|
+
throw new Error(`No ${actualChangeScriptType} xpub available for change address. ` + `Available types: ${relevantPubkeys.map((pk) => pk.scriptType).join(", ")}. ` + `Cannot create change output with mismatched script type.`);
|
|
2180
|
+
}
|
|
2181
|
+
const changeXpub = changeXpubInfo.pubkey;
|
|
2182
|
+
console.log(`${tag5}: Change xpub selected for ${actualChangeScriptType}:`, changeXpub?.substring(0, 10) + "...");
|
|
2183
|
+
let changeAddressIndex = await pioneer.GetChangeAddress({
|
|
2184
|
+
network: chain,
|
|
2185
|
+
xpub: changeXpub
|
|
2186
|
+
});
|
|
2187
|
+
changeAddressIndex = changeAddressIndex.data.changeIndex;
|
|
2188
|
+
let bipPath;
|
|
2189
|
+
switch (actualChangeScriptType) {
|
|
2190
|
+
case "p2pkh":
|
|
2191
|
+
bipPath = `m/44'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2192
|
+
break;
|
|
2193
|
+
case "p2sh-p2wpkh":
|
|
2194
|
+
bipPath = `m/49'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2195
|
+
break;
|
|
2196
|
+
case "p2wpkh":
|
|
2197
|
+
default:
|
|
2198
|
+
bipPath = `m/84'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2199
|
+
break;
|
|
2200
|
+
}
|
|
2201
|
+
const path = bipPath;
|
|
2202
|
+
console.log(`${tag5}: Change address path: ${path} (coin type: ${coinType}, index: ${changeAddressIndex})`);
|
|
2203
|
+
const changeAddress = {
|
|
2204
|
+
path,
|
|
2205
|
+
isChange: true,
|
|
2206
|
+
index: changeAddressIndex,
|
|
2207
|
+
addressNList: import_pioneer_coins3.bip32ToAddressNList(path),
|
|
2208
|
+
scriptType: actualChangeScriptType
|
|
2209
|
+
};
|
|
2473
2210
|
let feeRateFromNode;
|
|
2474
2211
|
if (networkId === "bip122:00000000001a91e3dace36e2be3bf030") {
|
|
2475
2212
|
console.log(`${tag5}: Using hardcoded fees for DOGE (10 sat/byte)`);
|
|
@@ -2587,11 +2324,9 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, ke
|
|
|
2587
2324
|
})));
|
|
2588
2325
|
let result;
|
|
2589
2326
|
if (isMax) {
|
|
2590
|
-
|
|
2591
|
-
result = coinSelectSplit(utxos, [{ address: to }], effectiveFeeRate);
|
|
2327
|
+
result = import_split.default(utxos, [{ address: to }], effectiveFeeRate);
|
|
2592
2328
|
} else {
|
|
2593
|
-
|
|
2594
|
-
result = coinSelect(utxos, [{ address: to, value: amount }], effectiveFeeRate);
|
|
2329
|
+
result = import_coinselect.default(utxos, [{ address: to, value: amount }], effectiveFeeRate);
|
|
2595
2330
|
}
|
|
2596
2331
|
console.log(tag5, "coinSelect result object:", result);
|
|
2597
2332
|
console.log(tag5, "coinSelect result.inputs:", result?.inputs);
|
|
@@ -2708,6 +2443,7 @@ class TransactionManager {
|
|
|
2708
2443
|
assetContext;
|
|
2709
2444
|
balances;
|
|
2710
2445
|
pubkeys;
|
|
2446
|
+
pubkeyContext;
|
|
2711
2447
|
nodes;
|
|
2712
2448
|
pioneer;
|
|
2713
2449
|
keepKeySdk;
|
|
@@ -2717,6 +2453,7 @@ class TransactionManager {
|
|
|
2717
2453
|
this.assetContext = dependencies.assetContext;
|
|
2718
2454
|
this.balances = dependencies.balances;
|
|
2719
2455
|
this.pubkeys = dependencies.pubkeys;
|
|
2456
|
+
this.pubkeyContext = dependencies.pubkeyContext;
|
|
2720
2457
|
this.nodes = dependencies.nodes;
|
|
2721
2458
|
this.pioneer = dependencies.pioneer;
|
|
2722
2459
|
this.keepKeySdk = dependencies.keepKeySdk;
|
|
@@ -2750,20 +2487,20 @@ class TransactionManager {
|
|
|
2750
2487
|
let unsignedTx;
|
|
2751
2488
|
switch (type) {
|
|
2752
2489
|
case "UTXO": {
|
|
2753
|
-
unsignedTx = await createUnsignedUxtoTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2490
|
+
unsignedTx = await createUnsignedUxtoTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, feeLevel, changeScriptType);
|
|
2754
2491
|
break;
|
|
2755
2492
|
}
|
|
2756
2493
|
case "TENDERMINT": {
|
|
2757
2494
|
const txType = "transfer";
|
|
2758
|
-
unsignedTx = await createUnsignedTendermintTx(caip, txType, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2495
|
+
unsignedTx = await createUnsignedTendermintTx(caip, txType, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, to);
|
|
2759
2496
|
break;
|
|
2760
2497
|
}
|
|
2761
2498
|
case "EIP155": {
|
|
2762
|
-
unsignedTx = await createUnsignedEvmTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2499
|
+
unsignedTx = await createUnsignedEvmTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, feeLevel);
|
|
2763
2500
|
break;
|
|
2764
2501
|
}
|
|
2765
2502
|
case "OTHER": {
|
|
2766
|
-
unsignedTx = await createUnsignedRippleTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2503
|
+
unsignedTx = await createUnsignedRippleTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax);
|
|
2767
2504
|
break;
|
|
2768
2505
|
}
|
|
2769
2506
|
default: {
|
|
@@ -2862,9 +2599,20 @@ class TransactionManager {
|
|
|
2862
2599
|
}
|
|
2863
2600
|
case "cosmos:mayachain-mainnet-v1/slip44:931":
|
|
2864
2601
|
case "cosmos:mayachain-mainnet-v1/denom:maya": {
|
|
2602
|
+
console.log(tag5, "\uD83D\uDD0D ===== MAYACHAIN SIGNING AUDIT =====");
|
|
2603
|
+
console.log(tag5, "\uD83D\uDCCB unsignedTx:", JSON.stringify(unsignedTx, null, 2));
|
|
2604
|
+
console.log(tag5, "\uD83D\uDD11 unsignedTx.addressNList:", unsignedTx.addressNList);
|
|
2605
|
+
console.log(tag5, "\uD83D\uDCCD unsignedTx.signerAddress:", unsignedTx.signerAddress);
|
|
2606
|
+
console.log(tag5, "\uD83C\uDF10 pubkeyContext:", this.pubkeyContext);
|
|
2607
|
+
console.log(tag5, "\uD83D\uDD10 pubkeyContext.addressNList:", this.pubkeyContext?.addressNList);
|
|
2608
|
+
console.log(tag5, "\uD83D\uDD10 pubkeyContext.addressNListMaster:", this.pubkeyContext?.addressNListMaster);
|
|
2609
|
+
console.log(tag5, "\uD83D\uDCEC pubkeyContext.address:", this.pubkeyContext?.address);
|
|
2610
|
+
console.log(tag5, "=======================================");
|
|
2865
2611
|
if (unsignedTx.signDoc.msgs[0].type === "mayachain/MsgSend") {
|
|
2866
2612
|
const responseSign = await this.keepKeySdk.mayachain.mayachainSignAminoTransfer(unsignedTx);
|
|
2867
2613
|
signedTx = responseSign.serialized;
|
|
2614
|
+
console.log(tag5, "✅ Signing completed");
|
|
2615
|
+
console.log(tag5, "\uD83D\uDCE6 responseSign:", responseSign);
|
|
2868
2616
|
} else if (unsignedTx.signDoc.msgs[0].type === "mayachain/MsgDeposit") {
|
|
2869
2617
|
const responseSign = await this.keepKeySdk.mayachain.mayachainSignAminoDeposit(unsignedTx);
|
|
2870
2618
|
signedTx = responseSign.serialized;
|
|
@@ -3056,18 +2804,21 @@ var cosmosClaimAllRewardsTemplate = (params) => ({
|
|
|
3056
2804
|
|
|
3057
2805
|
// src/txbuilder/createUnsignedStakingTx.ts
|
|
3058
2806
|
var TAG5 = " | createUnsignedStakingTx | ";
|
|
3059
|
-
async function createUnsignedStakingTx(caip, params, pubkeys, pioneer,
|
|
2807
|
+
async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyContext) {
|
|
3060
2808
|
const tag5 = TAG5 + " | createUnsignedStakingTx | ";
|
|
3061
2809
|
try {
|
|
3062
2810
|
if (!pioneer)
|
|
3063
2811
|
throw new Error("Failed to init! pioneer");
|
|
3064
2812
|
const networkId = import_pioneer_caip5.caipToNetworkId(caip);
|
|
3065
|
-
if (!
|
|
3066
|
-
|
|
2813
|
+
if (!pubkeyContext) {
|
|
2814
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
3067
2815
|
}
|
|
3068
|
-
if (!
|
|
3069
|
-
throw new Error(`
|
|
2816
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2817
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
3070
2818
|
}
|
|
2819
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2820
|
+
address: pubkeyContext.address
|
|
2821
|
+
});
|
|
3071
2822
|
let chain;
|
|
3072
2823
|
let chainId;
|
|
3073
2824
|
let denom;
|
|
@@ -3098,7 +2849,7 @@ async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, keepKeySd
|
|
|
3098
2849
|
throw new Error(`Unsupported networkId for staking: ${networkId}`);
|
|
3099
2850
|
}
|
|
3100
2851
|
console.log(tag5, `Building ${params.type} transaction for ${chain}`);
|
|
3101
|
-
const fromAddress =
|
|
2852
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
3102
2853
|
const accountInfo = (await pioneer.GetAccountInfo({ network: chain, address: fromAddress })).data;
|
|
3103
2854
|
console.log(tag5, "accountInfo: ", accountInfo);
|
|
3104
2855
|
let account_number;
|
|
@@ -3221,6 +2972,12 @@ function getNetworkName(networkId) {
|
|
|
3221
2972
|
};
|
|
3222
2973
|
return networkNames[networkId] || networkId;
|
|
3223
2974
|
}
|
|
2975
|
+
function withTimeout(promise, timeoutMs) {
|
|
2976
|
+
return Promise.race([
|
|
2977
|
+
promise,
|
|
2978
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Request timeout")), timeoutMs))
|
|
2979
|
+
]);
|
|
2980
|
+
}
|
|
3224
2981
|
async function getFees(pioneer, networkId) {
|
|
3225
2982
|
const tag5 = TAG6 + " | getFees | ";
|
|
3226
2983
|
try {
|
|
@@ -3230,10 +2987,6 @@ async function getFees(pioneer, networkId) {
|
|
|
3230
2987
|
console.log(tag5, "Using hardcoded fees for Cosmos network:", networkId);
|
|
3231
2988
|
return getCosmosFees(networkId);
|
|
3232
2989
|
}
|
|
3233
|
-
if (networkType === "RIPPLE") {
|
|
3234
|
-
console.log(tag5, "Using hardcoded fees for Ripple:", networkId);
|
|
3235
|
-
return getRippleFees(networkId);
|
|
3236
|
-
}
|
|
3237
2990
|
if (networkId === "bip122:00000000001a91e3dace36e2be3bf030") {
|
|
3238
2991
|
console.log(tag5, "Using hardcoded fees for Dogecoin: 10 sat/byte");
|
|
3239
2992
|
return {
|
|
@@ -3266,15 +3019,51 @@ async function getFees(pioneer, networkId) {
|
|
|
3266
3019
|
raw: { hardcoded: true, reason: "DOGE fee estimation unreliable" }
|
|
3267
3020
|
};
|
|
3268
3021
|
}
|
|
3269
|
-
|
|
3022
|
+
let feeResponse;
|
|
3023
|
+
if (networkId === "bip122:000007d91d1254d60e2dd1ae58038307") {
|
|
3024
|
+
try {
|
|
3025
|
+
const apiCall = pioneer.GetFeeRateByNetwork ? pioneer.GetFeeRateByNetwork({ networkId }) : pioneer.GetFeeRate({ networkId });
|
|
3026
|
+
feeResponse = await withTimeout(apiCall, 3000);
|
|
3027
|
+
} catch (timeoutError) {
|
|
3028
|
+
console.warn(tag5, "Dash fee API timeout, using fallback fees");
|
|
3029
|
+
return {
|
|
3030
|
+
slow: {
|
|
3031
|
+
label: "Economy",
|
|
3032
|
+
value: "5",
|
|
3033
|
+
unit: "sat/byte",
|
|
3034
|
+
description: "Low priority - 30+ minutes",
|
|
3035
|
+
estimatedTime: "~30 minutes",
|
|
3036
|
+
priority: "low"
|
|
3037
|
+
},
|
|
3038
|
+
average: {
|
|
3039
|
+
label: "Standard",
|
|
3040
|
+
value: "8",
|
|
3041
|
+
unit: "sat/byte",
|
|
3042
|
+
description: "Normal priority - 10-30 minutes",
|
|
3043
|
+
estimatedTime: "~15 minutes",
|
|
3044
|
+
priority: "medium"
|
|
3045
|
+
},
|
|
3046
|
+
fastest: {
|
|
3047
|
+
label: "Priority",
|
|
3048
|
+
value: "10",
|
|
3049
|
+
unit: "sat/byte",
|
|
3050
|
+
description: "High priority - next block",
|
|
3051
|
+
estimatedTime: "~5 minutes",
|
|
3052
|
+
priority: "high"
|
|
3053
|
+
},
|
|
3054
|
+
networkId,
|
|
3055
|
+
networkType: "UTXO",
|
|
3056
|
+
raw: { hardcoded: true, reason: "Dash API timeout, using conservative fallback fees" }
|
|
3057
|
+
};
|
|
3058
|
+
}
|
|
3059
|
+
} else {
|
|
3060
|
+
feeResponse = await (pioneer.GetFeeRateByNetwork ? pioneer.GetFeeRateByNetwork({ networkId }) : pioneer.GetFeeRate({ networkId }));
|
|
3061
|
+
}
|
|
3270
3062
|
if (!feeResponse || !feeResponse.data) {
|
|
3271
3063
|
throw new Error(`No fee data returned for ${networkId}`);
|
|
3272
3064
|
}
|
|
3273
3065
|
const feeData = feeResponse.data;
|
|
3274
3066
|
console.log(tag5, "Raw fee data:", feeData);
|
|
3275
|
-
if (feeData.success === false || feeData.error) {
|
|
3276
|
-
throw new Error(feeData.error || `API error for ${networkId}`);
|
|
3277
|
-
}
|
|
3278
3067
|
const networkName = getNetworkName(networkId);
|
|
3279
3068
|
let normalizedFees = normalizeFeeData(feeData, networkType, networkName, networkId);
|
|
3280
3069
|
normalizedFees = ensureFeeDifferentiation(normalizedFees, networkType);
|
|
@@ -3480,7 +3269,7 @@ function getCosmosFees(networkId) {
|
|
|
3480
3269
|
const networkName = getNetworkName(networkId);
|
|
3481
3270
|
const cosmosFeesMap = {
|
|
3482
3271
|
"cosmos:thorchain-mainnet-v1": { base: 0.02, unit: "RUNE", denom: "rune" },
|
|
3483
|
-
"cosmos:mayachain-mainnet-v1": { base: 0.
|
|
3272
|
+
"cosmos:mayachain-mainnet-v1": { base: 0.5, unit: "CACAO", denom: "cacao" },
|
|
3484
3273
|
"cosmos:cosmoshub-4": { base: 0.005, unit: "ATOM", denom: "uatom" },
|
|
3485
3274
|
"cosmos:osmosis-1": { base: 0.035, unit: "OSMO", denom: "uosmo" }
|
|
3486
3275
|
};
|
|
@@ -3518,39 +3307,6 @@ function getCosmosFees(networkId) {
|
|
|
3518
3307
|
raw: { hardcoded: true, base: feeConfig.base, unit: feeConfig.unit, denom: feeConfig.denom }
|
|
3519
3308
|
};
|
|
3520
3309
|
}
|
|
3521
|
-
function getRippleFees(networkId) {
|
|
3522
|
-
const networkName = getNetworkName(networkId);
|
|
3523
|
-
const baseFee = "0.00001";
|
|
3524
|
-
return {
|
|
3525
|
-
slow: {
|
|
3526
|
-
label: "Standard",
|
|
3527
|
-
value: baseFee,
|
|
3528
|
-
unit: "XRP",
|
|
3529
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3530
|
-
estimatedTime: "~4 seconds",
|
|
3531
|
-
priority: "low"
|
|
3532
|
-
},
|
|
3533
|
-
average: {
|
|
3534
|
-
label: "Standard",
|
|
3535
|
-
value: baseFee,
|
|
3536
|
-
unit: "XRP",
|
|
3537
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3538
|
-
estimatedTime: "~4 seconds",
|
|
3539
|
-
priority: "medium"
|
|
3540
|
-
},
|
|
3541
|
-
fastest: {
|
|
3542
|
-
label: "Standard",
|
|
3543
|
-
value: baseFee,
|
|
3544
|
-
unit: "XRP",
|
|
3545
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3546
|
-
estimatedTime: "~4 seconds",
|
|
3547
|
-
priority: "high"
|
|
3548
|
-
},
|
|
3549
|
-
networkId,
|
|
3550
|
-
networkType: "RIPPLE",
|
|
3551
|
-
raw: { hardcoded: true, baseFee, reason: "Ripple uses fixed network fees" }
|
|
3552
|
-
};
|
|
3553
|
-
}
|
|
3554
3310
|
function getFallbackFees(networkId) {
|
|
3555
3311
|
const networkType = getNetworkType(networkId);
|
|
3556
3312
|
const networkName = getNetworkName(networkId);
|
|
@@ -3624,9 +3380,10 @@ function estimateTransactionFee(feeRate, unit, networkType, txSize) {
|
|
|
3624
3380
|
}
|
|
3625
3381
|
}
|
|
3626
3382
|
|
|
3627
|
-
// src/
|
|
3383
|
+
// src/index.ts
|
|
3384
|
+
var TAG7 = " | Pioneer-sdk | ";
|
|
3628
3385
|
async function detectKkApiAvailability(forceLocalhost) {
|
|
3629
|
-
const tag5 =
|
|
3386
|
+
const tag5 = `${TAG7} | detectKkApiAvailability | `;
|
|
3630
3387
|
try {
|
|
3631
3388
|
const isTauri = typeof window !== "undefined" && "__TAURI__" in window;
|
|
3632
3389
|
const isBrowser = typeof window !== "undefined";
|
|
@@ -3673,8 +3430,6 @@ async function detectKkApiAvailability(forceLocalhost) {
|
|
|
3673
3430
|
};
|
|
3674
3431
|
}
|
|
3675
3432
|
}
|
|
3676
|
-
|
|
3677
|
-
// src/utils/format-time.ts
|
|
3678
3433
|
function formatTime(durationMs) {
|
|
3679
3434
|
let seconds = Math.floor(durationMs / 1000 % 60);
|
|
3680
3435
|
let minutes = Math.floor(durationMs / (1000 * 60) % 60);
|
|
@@ -3688,150 +3443,6 @@ function formatTime(durationMs) {
|
|
|
3688
3443
|
return formatted.trim();
|
|
3689
3444
|
}
|
|
3690
3445
|
|
|
3691
|
-
// src/utils/build-dashboard.ts
|
|
3692
|
-
var import_pioneer_caip6 = require("@pioneer-platform/pioneer-caip");
|
|
3693
|
-
var TAG7 = " | build-dashboard | ";
|
|
3694
|
-
function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
3695
|
-
console.log(TAG7, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3696
|
-
const dashboardData = {
|
|
3697
|
-
networks: [],
|
|
3698
|
-
totalValueUsd: 0,
|
|
3699
|
-
networkPercentages: []
|
|
3700
|
-
};
|
|
3701
|
-
let totalPortfolioValue = 0;
|
|
3702
|
-
const networksTemp = [];
|
|
3703
|
-
console.log(TAG7, "balances: ", balances);
|
|
3704
|
-
for (const blockchain of blockchains) {
|
|
3705
|
-
const filteredBalances = balances.filter((b2) => {
|
|
3706
|
-
const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
|
|
3707
|
-
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
3708
|
-
});
|
|
3709
|
-
const balanceMap = new Map;
|
|
3710
|
-
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
3711
|
-
if (isBitcoin) {
|
|
3712
|
-
console.log(TAG7, "Bitcoin network detected - checking for duplicate balances");
|
|
3713
|
-
const bitcoinByValue = new Map;
|
|
3714
|
-
filteredBalances.forEach((balance) => {
|
|
3715
|
-
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
3716
|
-
if (!bitcoinByValue.has(valueKey)) {
|
|
3717
|
-
bitcoinByValue.set(valueKey, []);
|
|
3718
|
-
}
|
|
3719
|
-
bitcoinByValue.get(valueKey).push(balance);
|
|
3720
|
-
});
|
|
3721
|
-
for (const [valueKey, balances2] of bitcoinByValue.entries()) {
|
|
3722
|
-
if (balances2.length === 3 && parseFloat(balances2[0].valueUsd || "0") > 0) {
|
|
3723
|
-
console.log(TAG7, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
3724
|
-
const xpubBalance = balances2.find((b2) => b2.pubkey?.startsWith("xpub")) || balances2[0];
|
|
3725
|
-
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
3726
|
-
balanceMap.set(key, xpubBalance);
|
|
3727
|
-
} else {
|
|
3728
|
-
balances2.forEach((balance) => {
|
|
3729
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3730
|
-
balanceMap.set(key, balance);
|
|
3731
|
-
});
|
|
3732
|
-
}
|
|
3733
|
-
}
|
|
3734
|
-
} else {
|
|
3735
|
-
filteredBalances.forEach((balance) => {
|
|
3736
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3737
|
-
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
3738
|
-
balanceMap.set(key, balance);
|
|
3739
|
-
}
|
|
3740
|
-
});
|
|
3741
|
-
}
|
|
3742
|
-
const networkBalances = Array.from(balanceMap.values());
|
|
3743
|
-
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
3744
|
-
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
3745
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
3746
|
-
console.log(TAG7, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
3747
|
-
}
|
|
3748
|
-
return sum + valueUsd;
|
|
3749
|
-
}, 0);
|
|
3750
|
-
const nativeAssetCaip = import_pioneer_caip6.networkIdToCaip(blockchain);
|
|
3751
|
-
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
3752
|
-
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
3753
|
-
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
3754
|
-
return sum + balanceNum;
|
|
3755
|
-
}, 0).toString();
|
|
3756
|
-
const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
|
|
3757
|
-
networksTemp.push({
|
|
3758
|
-
networkId: blockchain,
|
|
3759
|
-
totalValueUsd: networkTotal,
|
|
3760
|
-
gasAssetCaip: nativeAssetCaip || null,
|
|
3761
|
-
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
3762
|
-
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
3763
|
-
color: gasAsset?.color || assetInfo?.color || null,
|
|
3764
|
-
totalNativeBalance
|
|
3765
|
-
});
|
|
3766
|
-
totalPortfolioValue += networkTotal;
|
|
3767
|
-
}
|
|
3768
|
-
dashboardData.networks = networksTemp.sort((a, b2) => b2.totalValueUsd - a.totalValueUsd);
|
|
3769
|
-
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
3770
|
-
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
3771
|
-
networkId: network.networkId,
|
|
3772
|
-
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
3773
|
-
})).filter((entry) => entry.percentage > 0);
|
|
3774
|
-
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
3775
|
-
return dashboardData;
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
// src/utils/pubkey-helpers.ts
|
|
3779
|
-
function getPubkeyKey(pubkey) {
|
|
3780
|
-
return `${pubkey.pubkey}_${pubkey.pathMaster}`;
|
|
3781
|
-
}
|
|
3782
|
-
function deduplicatePubkeys(pubkeys) {
|
|
3783
|
-
const seen = new Set;
|
|
3784
|
-
const deduped = pubkeys.filter((pubkey) => {
|
|
3785
|
-
const key = getPubkeyKey(pubkey);
|
|
3786
|
-
if (seen.has(key)) {
|
|
3787
|
-
return false;
|
|
3788
|
-
}
|
|
3789
|
-
seen.add(key);
|
|
3790
|
-
return true;
|
|
3791
|
-
});
|
|
3792
|
-
return deduped;
|
|
3793
|
-
}
|
|
3794
|
-
function validatePubkey(pubkey) {
|
|
3795
|
-
return !!(pubkey.pubkey && pubkey.pathMaster);
|
|
3796
|
-
}
|
|
3797
|
-
|
|
3798
|
-
class PubkeyManager {
|
|
3799
|
-
pubkeys = [];
|
|
3800
|
-
pubkeySet = new Set;
|
|
3801
|
-
addPubkey(pubkey) {
|
|
3802
|
-
if (!validatePubkey(pubkey)) {
|
|
3803
|
-
return false;
|
|
3804
|
-
}
|
|
3805
|
-
const key = getPubkeyKey(pubkey);
|
|
3806
|
-
if (this.pubkeySet.has(key)) {
|
|
3807
|
-
return false;
|
|
3808
|
-
}
|
|
3809
|
-
this.pubkeys.push(pubkey);
|
|
3810
|
-
this.pubkeySet.add(key);
|
|
3811
|
-
return true;
|
|
3812
|
-
}
|
|
3813
|
-
setPubkeys(newPubkeys) {
|
|
3814
|
-
this.pubkeys = [];
|
|
3815
|
-
this.pubkeySet.clear();
|
|
3816
|
-
let added = 0;
|
|
3817
|
-
for (const pubkey of newPubkeys) {
|
|
3818
|
-
if (this.addPubkey(pubkey)) {
|
|
3819
|
-
added++;
|
|
3820
|
-
}
|
|
3821
|
-
}
|
|
3822
|
-
}
|
|
3823
|
-
getPubkeys() {
|
|
3824
|
-
return this.pubkeys;
|
|
3825
|
-
}
|
|
3826
|
-
clear() {
|
|
3827
|
-
this.pubkeys = [];
|
|
3828
|
-
this.pubkeySet.clear();
|
|
3829
|
-
}
|
|
3830
|
-
}
|
|
3831
|
-
|
|
3832
|
-
// src/index.ts
|
|
3833
|
-
var TAG8 = " | Pioneer-sdk | ";
|
|
3834
|
-
|
|
3835
3446
|
class SDK {
|
|
3836
3447
|
status;
|
|
3837
3448
|
username;
|
|
@@ -3855,7 +3466,7 @@ class SDK {
|
|
|
3855
3466
|
charts;
|
|
3856
3467
|
paths;
|
|
3857
3468
|
pubkeys = [];
|
|
3858
|
-
|
|
3469
|
+
pubkeySet = new Set;
|
|
3859
3470
|
wallets;
|
|
3860
3471
|
balances;
|
|
3861
3472
|
nodes;
|
|
@@ -3932,11 +3543,10 @@ class SDK {
|
|
|
3932
3543
|
if (config.blockchains && config.blockchains.length !== this.blockchains.length) {
|
|
3933
3544
|
}
|
|
3934
3545
|
if (config.pubkeys && config.pubkeys.length > 0) {
|
|
3935
|
-
this.
|
|
3936
|
-
this.pubkeys = this.pubkeyManager.getPubkeys();
|
|
3546
|
+
this.setPubkeys(config.pubkeys);
|
|
3937
3547
|
} else {
|
|
3938
3548
|
this.pubkeys = [];
|
|
3939
|
-
this.
|
|
3549
|
+
this.pubkeySet.clear();
|
|
3940
3550
|
}
|
|
3941
3551
|
this.balances = config.balances || [];
|
|
3942
3552
|
this.nodes = config.nodes || [];
|
|
@@ -3952,7 +3562,7 @@ class SDK {
|
|
|
3952
3562
|
this.outboundBlockchainContext = null;
|
|
3953
3563
|
this.outboundPubkeyContext = null;
|
|
3954
3564
|
this.wallets = [];
|
|
3955
|
-
this.events = new import_events.
|
|
3565
|
+
this.events = new import_events.default;
|
|
3956
3566
|
this.transactions = null;
|
|
3957
3567
|
this.ethplorerApiKey = config.ethplorerApiKey;
|
|
3958
3568
|
this.covalentApiKey = config.covalentApiKey;
|
|
@@ -3967,21 +3577,46 @@ class SDK {
|
|
|
3967
3577
|
this.pairWallet = async (options) => {
|
|
3968
3578
|
return Promise.resolve({});
|
|
3969
3579
|
};
|
|
3970
|
-
this.getPubkeyKey =
|
|
3971
|
-
|
|
3580
|
+
this.getPubkeyKey = (pubkey) => {
|
|
3581
|
+
return `${pubkey.pubkey}_${pubkey.pathMaster}`;
|
|
3582
|
+
};
|
|
3583
|
+
this.deduplicatePubkeys = (pubkeys) => {
|
|
3584
|
+
const seen = new Set;
|
|
3585
|
+
const deduped = pubkeys.filter((pubkey) => {
|
|
3586
|
+
const key = this.getPubkeyKey(pubkey);
|
|
3587
|
+
if (seen.has(key)) {
|
|
3588
|
+
return false;
|
|
3589
|
+
}
|
|
3590
|
+
seen.add(key);
|
|
3591
|
+
return true;
|
|
3592
|
+
});
|
|
3593
|
+
return deduped;
|
|
3594
|
+
};
|
|
3972
3595
|
this.addPubkey = (pubkey) => {
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3596
|
+
if (!pubkey.pubkey || !pubkey.pathMaster) {
|
|
3597
|
+
return false;
|
|
3598
|
+
}
|
|
3599
|
+
const key = this.getPubkeyKey(pubkey);
|
|
3600
|
+
if (this.pubkeySet.has(key)) {
|
|
3601
|
+
return false;
|
|
3976
3602
|
}
|
|
3977
|
-
|
|
3603
|
+
this.pubkeys.push(pubkey);
|
|
3604
|
+
this.pubkeySet.add(key);
|
|
3605
|
+
return true;
|
|
3978
3606
|
};
|
|
3979
3607
|
this.setPubkeys = (newPubkeys) => {
|
|
3980
|
-
|
|
3981
|
-
this.pubkeys =
|
|
3608
|
+
const tag5 = `${TAG7} | setPubkeys | `;
|
|
3609
|
+
this.pubkeys = [];
|
|
3610
|
+
this.pubkeySet.clear();
|
|
3611
|
+
let added = 0;
|
|
3612
|
+
for (const pubkey of newPubkeys) {
|
|
3613
|
+
if (this.addPubkey(pubkey)) {
|
|
3614
|
+
added++;
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3982
3617
|
};
|
|
3983
3618
|
this.getUnifiedPortfolio = async function() {
|
|
3984
|
-
const tag5 = `${
|
|
3619
|
+
const tag5 = `${TAG7} | getUnifiedPortfolio | `;
|
|
3985
3620
|
try {
|
|
3986
3621
|
const startTime = performance.now();
|
|
3987
3622
|
try {
|
|
@@ -4013,9 +3648,8 @@ class SDK {
|
|
|
4013
3648
|
this.events.emit("SET_BALANCES", this.balances);
|
|
4014
3649
|
}
|
|
4015
3650
|
if (portfolioData.pubkeys && portfolioData.pubkeys.length > 0) {
|
|
4016
|
-
const convertedPubkeys = portfolioData.pubkeys;
|
|
4017
|
-
this.
|
|
4018
|
-
this.pubkeys = this.pubkeyManager.getPubkeys();
|
|
3651
|
+
const convertedPubkeys = this.convertVaultPubkeysToPioneerFormat(portfolioData.pubkeys);
|
|
3652
|
+
this.setPubkeys(convertedPubkeys);
|
|
4019
3653
|
this.events.emit("SET_PUBKEYS", this.pubkeys);
|
|
4020
3654
|
}
|
|
4021
3655
|
if (portfolioData.devices && portfolioData.devices.length > 0) {
|
|
@@ -4065,7 +3699,7 @@ class SDK {
|
|
|
4065
3699
|
this.events.emit("SET_DASHBOARD", this.dashboard);
|
|
4066
3700
|
} else {
|
|
4067
3701
|
console.warn("[CACHE VALIDATION] ❌ Cache data corrupted, building dashboard from cached balances");
|
|
4068
|
-
const dashboardData = buildDashboardFromBalances(
|
|
3702
|
+
const dashboardData = this.buildDashboardFromBalances();
|
|
4069
3703
|
this.dashboard = dashboardData;
|
|
4070
3704
|
this.events.emit("SET_DASHBOARD", this.dashboard);
|
|
4071
3705
|
}
|
|
@@ -4090,7 +3724,7 @@ class SDK {
|
|
|
4090
3724
|
}
|
|
4091
3725
|
};
|
|
4092
3726
|
this.init = async function(walletsVerbose, setup) {
|
|
4093
|
-
const tag5 = `${
|
|
3727
|
+
const tag5 = `${TAG7} | init | `;
|
|
4094
3728
|
try {
|
|
4095
3729
|
if (!this.username)
|
|
4096
3730
|
throw Error("username required!");
|
|
@@ -4107,7 +3741,7 @@ class SDK {
|
|
|
4107
3741
|
const pioneerConfig = {
|
|
4108
3742
|
...config
|
|
4109
3743
|
};
|
|
4110
|
-
const PioneerClient = new import_pioneer_client.
|
|
3744
|
+
const PioneerClient = new import_pioneer_client.default(this.spec, pioneerConfig);
|
|
4111
3745
|
this.pioneer = await PioneerClient.init();
|
|
4112
3746
|
if (!this.pioneer)
|
|
4113
3747
|
throw Error("Failed to init pioneer server!");
|
|
@@ -4177,11 +3811,92 @@ class SDK {
|
|
|
4177
3811
|
throw e;
|
|
4178
3812
|
}
|
|
4179
3813
|
};
|
|
4180
|
-
this.buildDashboardFromBalances = ()
|
|
4181
|
-
|
|
3814
|
+
this.buildDashboardFromBalances = function() {
|
|
3815
|
+
const tag5 = `${TAG7} | buildDashboardFromBalances | `;
|
|
3816
|
+
console.log(tag5, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3817
|
+
const dashboardData = {
|
|
3818
|
+
networks: [],
|
|
3819
|
+
totalValueUsd: 0,
|
|
3820
|
+
networkPercentages: []
|
|
3821
|
+
};
|
|
3822
|
+
let totalPortfolioValue = 0;
|
|
3823
|
+
const networksTemp = [];
|
|
3824
|
+
console.log(tag5, "this.balances: ", this.balances);
|
|
3825
|
+
for (const blockchain of this.blockchains) {
|
|
3826
|
+
const filteredBalances = this.balances.filter((b2) => {
|
|
3827
|
+
const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
|
|
3828
|
+
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
3829
|
+
});
|
|
3830
|
+
const balanceMap = new Map;
|
|
3831
|
+
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
3832
|
+
if (isBitcoin) {
|
|
3833
|
+
console.log(tag5, "Bitcoin network detected - checking for duplicate balances");
|
|
3834
|
+
const bitcoinByValue = new Map;
|
|
3835
|
+
filteredBalances.forEach((balance) => {
|
|
3836
|
+
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
3837
|
+
if (!bitcoinByValue.has(valueKey)) {
|
|
3838
|
+
bitcoinByValue.set(valueKey, []);
|
|
3839
|
+
}
|
|
3840
|
+
bitcoinByValue.get(valueKey).push(balance);
|
|
3841
|
+
});
|
|
3842
|
+
for (const [valueKey, balances] of bitcoinByValue.entries()) {
|
|
3843
|
+
if (balances.length === 3 && parseFloat(balances[0].valueUsd || "0") > 0) {
|
|
3844
|
+
console.log(tag5, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
3845
|
+
const xpubBalance = balances.find((b2) => b2.pubkey?.startsWith("xpub")) || balances[0];
|
|
3846
|
+
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
3847
|
+
balanceMap.set(key, xpubBalance);
|
|
3848
|
+
} else {
|
|
3849
|
+
balances.forEach((balance) => {
|
|
3850
|
+
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3851
|
+
balanceMap.set(key, balance);
|
|
3852
|
+
});
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
} else {
|
|
3856
|
+
filteredBalances.forEach((balance) => {
|
|
3857
|
+
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3858
|
+
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
3859
|
+
balanceMap.set(key, balance);
|
|
3860
|
+
}
|
|
3861
|
+
});
|
|
3862
|
+
}
|
|
3863
|
+
const networkBalances = Array.from(balanceMap.values());
|
|
3864
|
+
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
3865
|
+
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
3866
|
+
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
3867
|
+
console.log(tag5, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
3868
|
+
}
|
|
3869
|
+
return sum + valueUsd;
|
|
3870
|
+
}, 0);
|
|
3871
|
+
const nativeAssetCaip = import_pioneer_caip6.networkIdToCaip(blockchain);
|
|
3872
|
+
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
3873
|
+
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
3874
|
+
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
3875
|
+
return sum + balanceNum;
|
|
3876
|
+
}, 0).toString();
|
|
3877
|
+
const assetInfo = nativeAssetCaip ? this.assetsMap.get(nativeAssetCaip) : null;
|
|
3878
|
+
networksTemp.push({
|
|
3879
|
+
networkId: blockchain,
|
|
3880
|
+
totalValueUsd: networkTotal,
|
|
3881
|
+
gasAssetCaip: nativeAssetCaip || null,
|
|
3882
|
+
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
3883
|
+
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
3884
|
+
color: gasAsset?.color || assetInfo?.color || null,
|
|
3885
|
+
totalNativeBalance
|
|
3886
|
+
});
|
|
3887
|
+
totalPortfolioValue += networkTotal;
|
|
3888
|
+
}
|
|
3889
|
+
dashboardData.networks = networksTemp.sort((a, b2) => b2.totalValueUsd - a.totalValueUsd);
|
|
3890
|
+
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
3891
|
+
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
3892
|
+
networkId: network.networkId,
|
|
3893
|
+
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
3894
|
+
})).filter((entry) => entry.percentage > 0);
|
|
3895
|
+
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
3896
|
+
return dashboardData;
|
|
4182
3897
|
};
|
|
4183
3898
|
this.syncMarket = async function() {
|
|
4184
|
-
const tag5 = `${
|
|
3899
|
+
const tag5 = `${TAG7} | syncMarket | `;
|
|
4185
3900
|
try {
|
|
4186
3901
|
const invalidBalances = this.balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
4187
3902
|
if (invalidBalances.length > 0) {
|
|
@@ -4232,7 +3947,7 @@ class SDK {
|
|
|
4232
3947
|
}
|
|
4233
3948
|
};
|
|
4234
3949
|
this.sync = async function() {
|
|
4235
|
-
const tag5 = `${
|
|
3950
|
+
const tag5 = `${TAG7} | sync | `;
|
|
4236
3951
|
try {
|
|
4237
3952
|
const matchesNetwork = (item, networkId) => {
|
|
4238
3953
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4287,7 +4002,7 @@ class SDK {
|
|
|
4287
4002
|
console.log(tag5, "uniqueBlockchains: ", uniqueBlockchains);
|
|
4288
4003
|
for (const blockchain of uniqueBlockchains) {
|
|
4289
4004
|
const filteredBalances = this.balances.filter((b2) => {
|
|
4290
|
-
const networkId =
|
|
4005
|
+
const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
|
|
4291
4006
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4292
4007
|
});
|
|
4293
4008
|
console.log(tag5, `Filtering for blockchain: ${blockchain}`);
|
|
@@ -4345,7 +4060,7 @@ class SDK {
|
|
|
4345
4060
|
return sum + valueUsd;
|
|
4346
4061
|
}, 0);
|
|
4347
4062
|
console.log("Final networkTotal:", networkTotal);
|
|
4348
|
-
const nativeAssetCaip =
|
|
4063
|
+
const nativeAssetCaip = import_pioneer_caip6.networkIdToCaip(blockchain);
|
|
4349
4064
|
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
4350
4065
|
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4351
4066
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
@@ -4385,7 +4100,7 @@ class SDK {
|
|
|
4385
4100
|
}
|
|
4386
4101
|
};
|
|
4387
4102
|
this.buildTx = async function(sendPayload) {
|
|
4388
|
-
let tag5 =
|
|
4103
|
+
let tag5 = TAG7 + " | buildTx | ";
|
|
4389
4104
|
try {
|
|
4390
4105
|
const transactionDependencies = {
|
|
4391
4106
|
context: this.context,
|
|
@@ -4393,6 +4108,7 @@ class SDK {
|
|
|
4393
4108
|
balances: this.balances,
|
|
4394
4109
|
pioneer: this.pioneer,
|
|
4395
4110
|
pubkeys: this.pubkeys,
|
|
4111
|
+
pubkeyContext: this.pubkeyContext,
|
|
4396
4112
|
nodes: this.nodes,
|
|
4397
4113
|
keepKeySdk: this.keepKeySdk
|
|
4398
4114
|
};
|
|
@@ -4406,13 +4122,13 @@ class SDK {
|
|
|
4406
4122
|
}
|
|
4407
4123
|
};
|
|
4408
4124
|
this.buildDelegateTx = async function(caip, params) {
|
|
4409
|
-
let tag5 =
|
|
4125
|
+
let tag5 = TAG7 + " | buildDelegateTx | ";
|
|
4410
4126
|
try {
|
|
4411
4127
|
const delegateParams = {
|
|
4412
4128
|
...params,
|
|
4413
4129
|
type: "delegate"
|
|
4414
4130
|
};
|
|
4415
|
-
let unsignedTx = await createUnsignedStakingTx(caip, delegateParams, this.pubkeys, this.pioneer, this.
|
|
4131
|
+
let unsignedTx = await createUnsignedStakingTx(caip, delegateParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4416
4132
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4417
4133
|
return unsignedTx;
|
|
4418
4134
|
} catch (e) {
|
|
@@ -4421,13 +4137,13 @@ class SDK {
|
|
|
4421
4137
|
}
|
|
4422
4138
|
};
|
|
4423
4139
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4424
|
-
let tag5 =
|
|
4140
|
+
let tag5 = TAG7 + " | buildUndelegateTx | ";
|
|
4425
4141
|
try {
|
|
4426
4142
|
const undelegateParams = {
|
|
4427
4143
|
...params,
|
|
4428
4144
|
type: "undelegate"
|
|
4429
4145
|
};
|
|
4430
|
-
let unsignedTx = await createUnsignedStakingTx(caip, undelegateParams, this.pubkeys, this.pioneer, this.
|
|
4146
|
+
let unsignedTx = await createUnsignedStakingTx(caip, undelegateParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4431
4147
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4432
4148
|
return unsignedTx;
|
|
4433
4149
|
} catch (e) {
|
|
@@ -4436,13 +4152,13 @@ class SDK {
|
|
|
4436
4152
|
}
|
|
4437
4153
|
};
|
|
4438
4154
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4439
|
-
let tag5 =
|
|
4155
|
+
let tag5 = TAG7 + " | buildClaimRewardsTx | ";
|
|
4440
4156
|
try {
|
|
4441
4157
|
const claimParams = {
|
|
4442
4158
|
...params,
|
|
4443
4159
|
type: "claim_rewards"
|
|
4444
4160
|
};
|
|
4445
|
-
let unsignedTx = await createUnsignedStakingTx(caip, claimParams, this.pubkeys, this.pioneer, this.
|
|
4161
|
+
let unsignedTx = await createUnsignedStakingTx(caip, claimParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4446
4162
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4447
4163
|
return unsignedTx;
|
|
4448
4164
|
} catch (e) {
|
|
@@ -4451,13 +4167,13 @@ class SDK {
|
|
|
4451
4167
|
}
|
|
4452
4168
|
};
|
|
4453
4169
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4454
|
-
let tag5 =
|
|
4170
|
+
let tag5 = TAG7 + " | buildClaimAllRewardsTx | ";
|
|
4455
4171
|
try {
|
|
4456
4172
|
const claimAllParams = {
|
|
4457
4173
|
...params,
|
|
4458
4174
|
type: "claim_all_rewards"
|
|
4459
4175
|
};
|
|
4460
|
-
let unsignedTx = await createUnsignedStakingTx(caip, claimAllParams, this.pubkeys, this.pioneer, this.
|
|
4176
|
+
let unsignedTx = await createUnsignedStakingTx(caip, claimAllParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4461
4177
|
return unsignedTx;
|
|
4462
4178
|
} catch (e) {
|
|
4463
4179
|
console.error(e);
|
|
@@ -4465,7 +4181,7 @@ class SDK {
|
|
|
4465
4181
|
}
|
|
4466
4182
|
};
|
|
4467
4183
|
this.signTx = async function(unsignedTx) {
|
|
4468
|
-
let tag5 =
|
|
4184
|
+
let tag5 = TAG7 + " | signTx | ";
|
|
4469
4185
|
try {
|
|
4470
4186
|
const transactionDependencies = {
|
|
4471
4187
|
context: this.context,
|
|
@@ -4473,6 +4189,7 @@ class SDK {
|
|
|
4473
4189
|
balances: this.balances,
|
|
4474
4190
|
pioneer: this.pioneer,
|
|
4475
4191
|
pubkeys: this.pubkeys,
|
|
4192
|
+
pubkeyContext: this.pubkeyContext,
|
|
4476
4193
|
nodes: this.nodes,
|
|
4477
4194
|
keepKeySdk: this.keepKeySdk
|
|
4478
4195
|
};
|
|
@@ -4485,7 +4202,7 @@ class SDK {
|
|
|
4485
4202
|
}
|
|
4486
4203
|
};
|
|
4487
4204
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4488
|
-
let tag5 =
|
|
4205
|
+
let tag5 = TAG7 + " | broadcastTx | ";
|
|
4489
4206
|
try {
|
|
4490
4207
|
const transactionDependencies = {
|
|
4491
4208
|
context: this.context,
|
|
@@ -4498,7 +4215,7 @@ class SDK {
|
|
|
4498
4215
|
};
|
|
4499
4216
|
let txManager = new TransactionManager(transactionDependencies, this.events);
|
|
4500
4217
|
let payload = {
|
|
4501
|
-
networkId:
|
|
4218
|
+
networkId: import_pioneer_caip6.caipToNetworkId(caip),
|
|
4502
4219
|
serialized: signedTx
|
|
4503
4220
|
};
|
|
4504
4221
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4509,7 +4226,7 @@ class SDK {
|
|
|
4509
4226
|
}
|
|
4510
4227
|
};
|
|
4511
4228
|
this.swap = async function(swapPayload) {
|
|
4512
|
-
let tag5 = `${
|
|
4229
|
+
let tag5 = `${TAG7} | swap | `;
|
|
4513
4230
|
try {
|
|
4514
4231
|
if (!swapPayload)
|
|
4515
4232
|
throw Error("swapPayload required!");
|
|
@@ -4644,7 +4361,7 @@ class SDK {
|
|
|
4644
4361
|
}
|
|
4645
4362
|
};
|
|
4646
4363
|
this.transfer = async function(sendPayload) {
|
|
4647
|
-
let tag5 = `${
|
|
4364
|
+
let tag5 = `${TAG7} | transfer | `;
|
|
4648
4365
|
try {
|
|
4649
4366
|
if (!sendPayload)
|
|
4650
4367
|
throw Error("sendPayload required!");
|
|
@@ -4671,7 +4388,7 @@ class SDK {
|
|
|
4671
4388
|
if (!signedTx)
|
|
4672
4389
|
throw Error("Failed to sign transaction!");
|
|
4673
4390
|
let payload = {
|
|
4674
|
-
networkId:
|
|
4391
|
+
networkId: import_pioneer_caip6.caipToNetworkId(caip),
|
|
4675
4392
|
serialized: signedTx
|
|
4676
4393
|
};
|
|
4677
4394
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4700,7 +4417,7 @@ class SDK {
|
|
|
4700
4417
|
while (!isConfirmed) {
|
|
4701
4418
|
try {
|
|
4702
4419
|
const response = await this.pioneer.LookupTx({
|
|
4703
|
-
networkId:
|
|
4420
|
+
networkId: import_pioneer_caip6.caipToNetworkId(caip),
|
|
4704
4421
|
txid
|
|
4705
4422
|
});
|
|
4706
4423
|
if (response?.data?.data) {
|
|
@@ -4739,7 +4456,7 @@ class SDK {
|
|
|
4739
4456
|
}
|
|
4740
4457
|
};
|
|
4741
4458
|
this.setBlockchains = async function(blockchains) {
|
|
4742
|
-
const tag5 = `${
|
|
4459
|
+
const tag5 = `${TAG7} | setBlockchains | `;
|
|
4743
4460
|
try {
|
|
4744
4461
|
if (!blockchains)
|
|
4745
4462
|
throw Error("blockchains required!");
|
|
@@ -4755,7 +4472,7 @@ class SDK {
|
|
|
4755
4472
|
}
|
|
4756
4473
|
};
|
|
4757
4474
|
this.addAsset = async function(caip, data) {
|
|
4758
|
-
let tag5 =
|
|
4475
|
+
let tag5 = TAG7 + " | addAsset | ";
|
|
4759
4476
|
try {
|
|
4760
4477
|
let success = false;
|
|
4761
4478
|
if (!caip)
|
|
@@ -4793,7 +4510,7 @@ class SDK {
|
|
|
4793
4510
|
}
|
|
4794
4511
|
};
|
|
4795
4512
|
this.clearWalletState = async function() {
|
|
4796
|
-
const tag5 = `${
|
|
4513
|
+
const tag5 = `${TAG7} | clearWalletState | `;
|
|
4797
4514
|
try {
|
|
4798
4515
|
this.context = null;
|
|
4799
4516
|
this.paths = [];
|
|
@@ -4807,15 +4524,62 @@ class SDK {
|
|
|
4807
4524
|
throw e;
|
|
4808
4525
|
}
|
|
4809
4526
|
};
|
|
4527
|
+
this.addPath = async function(path) {
|
|
4528
|
+
const tag5 = `${TAG7} | addPath | `;
|
|
4529
|
+
try {
|
|
4530
|
+
this.paths.push(path);
|
|
4531
|
+
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
4532
|
+
this.addPubkey(pubkey);
|
|
4533
|
+
await this.getBalancesForNetworks(path.networks);
|
|
4534
|
+
this.buildDashboardFromBalances();
|
|
4535
|
+
return { success: true, pubkey };
|
|
4536
|
+
} catch (e) {
|
|
4537
|
+
console.error(tag5, "Failed:", e);
|
|
4538
|
+
throw e;
|
|
4539
|
+
}
|
|
4540
|
+
};
|
|
4541
|
+
this.addPaths = async function(paths) {
|
|
4542
|
+
const tag5 = `${TAG7} | addPaths | `;
|
|
4543
|
+
try {
|
|
4544
|
+
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4545
|
+
this.paths.push(...paths);
|
|
4546
|
+
const newPubkeys = [];
|
|
4547
|
+
for (const path of paths) {
|
|
4548
|
+
try {
|
|
4549
|
+
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
4550
|
+
this.addPubkey(pubkey);
|
|
4551
|
+
newPubkeys.push(pubkey);
|
|
4552
|
+
} catch (error) {
|
|
4553
|
+
console.warn(tag5, `Failed to get pubkey for path ${path.note}:`, error.message);
|
|
4554
|
+
}
|
|
4555
|
+
}
|
|
4556
|
+
console.log(tag5, `Successfully added ${newPubkeys.length} pubkeys`);
|
|
4557
|
+
const networkSet = new Set;
|
|
4558
|
+
for (const path of paths) {
|
|
4559
|
+
if (path.networks && Array.isArray(path.networks)) {
|
|
4560
|
+
path.networks.forEach((net) => networkSet.add(net));
|
|
4561
|
+
}
|
|
4562
|
+
}
|
|
4563
|
+
const uniqueNetworks = [...networkSet];
|
|
4564
|
+
console.log(tag5, `Fetching balances for ${uniqueNetworks.length} unique networks in single API call...`);
|
|
4565
|
+
await this.getBalancesForNetworks(uniqueNetworks);
|
|
4566
|
+
this.buildDashboardFromBalances();
|
|
4567
|
+
console.log(tag5, `Batch add complete: ${paths.length} paths, ${newPubkeys.length} pubkeys, ${this.balances?.length || 0} balances`);
|
|
4568
|
+
return { success: true, pubkeys: newPubkeys };
|
|
4569
|
+
} catch (e) {
|
|
4570
|
+
console.error(tag5, "Failed:", e);
|
|
4571
|
+
throw e;
|
|
4572
|
+
}
|
|
4573
|
+
};
|
|
4810
4574
|
this.getAssets = async function() {
|
|
4811
4575
|
return this.getGasAssets();
|
|
4812
4576
|
};
|
|
4813
4577
|
this.getGasAssets = async function() {
|
|
4814
|
-
const tag5 = `${
|
|
4578
|
+
const tag5 = `${TAG7} | getGasAssets | `;
|
|
4815
4579
|
try {
|
|
4816
4580
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4817
4581
|
let networkId = this.blockchains[i];
|
|
4818
|
-
let caip =
|
|
4582
|
+
let caip = import_pioneer_caip6.networkIdToCaip(networkId);
|
|
4819
4583
|
let asset = await import_pioneer_discovery2.assetData[caip.toLowerCase()];
|
|
4820
4584
|
if (asset) {
|
|
4821
4585
|
asset.caip = caip.toLowerCase();
|
|
@@ -4854,7 +4618,7 @@ class SDK {
|
|
|
4854
4618
|
}
|
|
4855
4619
|
};
|
|
4856
4620
|
this.getPubkeys = async function() {
|
|
4857
|
-
const tag5 = `${
|
|
4621
|
+
const tag5 = `${TAG7} | getPubkeys | `;
|
|
4858
4622
|
try {
|
|
4859
4623
|
if (this.paths.length === 0)
|
|
4860
4624
|
throw new Error("No paths found!");
|
|
@@ -4875,7 +4639,7 @@ class SDK {
|
|
|
4875
4639
|
}
|
|
4876
4640
|
};
|
|
4877
4641
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4878
|
-
const tag5 = `${
|
|
4642
|
+
const tag5 = `${TAG7} | getBalancesForNetworks | `;
|
|
4879
4643
|
try {
|
|
4880
4644
|
if (!this.pioneer) {
|
|
4881
4645
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -4893,7 +4657,7 @@ class SDK {
|
|
|
4893
4657
|
return network.startsWith("eip155:");
|
|
4894
4658
|
return network === adjustedNetworkId;
|
|
4895
4659
|
}));
|
|
4896
|
-
const caipNative = await
|
|
4660
|
+
const caipNative = await import_pioneer_caip6.networkIdToCaip(networkId);
|
|
4897
4661
|
for (const pubkey of pubkeys) {
|
|
4898
4662
|
assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
|
|
4899
4663
|
}
|
|
@@ -4902,14 +4666,6 @@ class SDK {
|
|
|
4902
4666
|
try {
|
|
4903
4667
|
let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
|
|
4904
4668
|
console.timeEnd("GetPortfolioBalances Response Time");
|
|
4905
|
-
if (!marketInfo || !marketInfo.data) {
|
|
4906
|
-
console.error(tag5, "Invalid response structure:", marketInfo);
|
|
4907
|
-
throw new Error("GetPortfolioBalances returned invalid response: missing data field");
|
|
4908
|
-
}
|
|
4909
|
-
if (!Array.isArray(marketInfo.data)) {
|
|
4910
|
-
console.error(tag5, "GetPortfolioBalances returned non-array data:", typeof marketInfo.data, marketInfo.data);
|
|
4911
|
-
throw new Error(`GetPortfolioBalances returned invalid data type: expected array, got ${typeof marketInfo.data}`);
|
|
4912
|
-
}
|
|
4913
4669
|
let balances = marketInfo.data;
|
|
4914
4670
|
const bitcoinBalances = balances.filter((b2) => b2.caip === "bip122:000000000019d6689c085ae165831e93/slip44:0");
|
|
4915
4671
|
if (bitcoinBalances.length > 0) {
|
|
@@ -4919,7 +4675,7 @@ class SDK {
|
|
|
4919
4675
|
if (!assetInfo)
|
|
4920
4676
|
continue;
|
|
4921
4677
|
Object.assign(balance, assetInfo, {
|
|
4922
|
-
networkId:
|
|
4678
|
+
networkId: import_pioneer_caip6.caipToNetworkId(balance.caip),
|
|
4923
4679
|
icon: assetInfo.icon || "https://pioneers.dev/coins/etherum.png",
|
|
4924
4680
|
identifier: `${balance.caip}:${balance.pubkey}`
|
|
4925
4681
|
});
|
|
@@ -4938,7 +4694,7 @@ class SDK {
|
|
|
4938
4694
|
}
|
|
4939
4695
|
};
|
|
4940
4696
|
this.getBalances = async function() {
|
|
4941
|
-
const tag5 = `${
|
|
4697
|
+
const tag5 = `${TAG7} | getBalances | `;
|
|
4942
4698
|
try {
|
|
4943
4699
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4944
4700
|
} catch (e) {
|
|
@@ -4947,10 +4703,10 @@ class SDK {
|
|
|
4947
4703
|
}
|
|
4948
4704
|
};
|
|
4949
4705
|
this.getBalance = async function(networkId) {
|
|
4950
|
-
const tag5 = `${
|
|
4706
|
+
const tag5 = `${TAG7} | getBalance | `;
|
|
4951
4707
|
try {
|
|
4952
4708
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4953
|
-
const filtered = results.filter(async (b2) => b2.networkId === await
|
|
4709
|
+
const filtered = results.filter(async (b2) => b2.networkId === await import_pioneer_caip6.networkIdToCaip(networkId));
|
|
4954
4710
|
return filtered;
|
|
4955
4711
|
} catch (e) {
|
|
4956
4712
|
console.error(tag5, "Error: ", e);
|
|
@@ -4958,7 +4714,7 @@ class SDK {
|
|
|
4958
4714
|
}
|
|
4959
4715
|
};
|
|
4960
4716
|
this.getFees = async function(networkId) {
|
|
4961
|
-
const tag5 = `${
|
|
4717
|
+
const tag5 = `${TAG7} | getFees | `;
|
|
4962
4718
|
try {
|
|
4963
4719
|
if (!this.pioneer) {
|
|
4964
4720
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -4973,7 +4729,7 @@ class SDK {
|
|
|
4973
4729
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
4974
4730
|
};
|
|
4975
4731
|
this.getCharts = async function() {
|
|
4976
|
-
const tag5 = `${
|
|
4732
|
+
const tag5 = `${TAG7} | getCharts | `;
|
|
4977
4733
|
try {
|
|
4978
4734
|
console.log(tag5, "Fetching charts");
|
|
4979
4735
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -4995,7 +4751,7 @@ class SDK {
|
|
|
4995
4751
|
}
|
|
4996
4752
|
};
|
|
4997
4753
|
this.setContext = async (context) => {
|
|
4998
|
-
const tag5 = `${
|
|
4754
|
+
const tag5 = `${TAG7} | setContext | `;
|
|
4999
4755
|
try {
|
|
5000
4756
|
if (!context)
|
|
5001
4757
|
throw Error("context required!");
|
|
@@ -5008,7 +4764,7 @@ class SDK {
|
|
|
5008
4764
|
}
|
|
5009
4765
|
};
|
|
5010
4766
|
this.setContextType = async (contextType) => {
|
|
5011
|
-
const tag5 = `${
|
|
4767
|
+
const tag5 = `${TAG7} | setContextType | `;
|
|
5012
4768
|
try {
|
|
5013
4769
|
if (!contextType)
|
|
5014
4770
|
throw Error("contextType required!");
|
|
@@ -5021,7 +4777,7 @@ class SDK {
|
|
|
5021
4777
|
}
|
|
5022
4778
|
};
|
|
5023
4779
|
this.refresh = async () => {
|
|
5024
|
-
const tag5 = `${
|
|
4780
|
+
const tag5 = `${TAG7} | refresh | `;
|
|
5025
4781
|
try {
|
|
5026
4782
|
await this.sync();
|
|
5027
4783
|
return this.balances;
|
|
@@ -5031,7 +4787,7 @@ class SDK {
|
|
|
5031
4787
|
}
|
|
5032
4788
|
};
|
|
5033
4789
|
this.setAssetContext = async function(asset) {
|
|
5034
|
-
const tag5 = `${
|
|
4790
|
+
const tag5 = `${TAG7} | setAssetContext | `;
|
|
5035
4791
|
try {
|
|
5036
4792
|
if (!asset) {
|
|
5037
4793
|
this.assetContext = null;
|
|
@@ -5040,7 +4796,7 @@ class SDK {
|
|
|
5040
4796
|
if (!asset.caip)
|
|
5041
4797
|
throw Error("Invalid Asset! missing caip!");
|
|
5042
4798
|
if (!asset.networkId)
|
|
5043
|
-
asset.networkId =
|
|
4799
|
+
asset.networkId = import_pioneer_caip6.caipToNetworkId(asset.caip);
|
|
5044
4800
|
if (!this.pubkeys || this.pubkeys.length === 0) {
|
|
5045
4801
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no pubkeys loaded. Please initialize wallet first.`;
|
|
5046
4802
|
console.error(tag5, errorMsg);
|
|
@@ -5148,7 +4904,7 @@ class SDK {
|
|
|
5148
4904
|
console.log(tag5, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
5149
4905
|
}
|
|
5150
4906
|
const assetBalances = this.balances.filter((b2) => b2.caip === asset.caip);
|
|
5151
|
-
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(
|
|
4907
|
+
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(import_pioneer_caip6.caipToNetworkId(asset.caip)) || import_pioneer_caip6.caipToNetworkId(asset.caip).includes("eip155") && p2.networks && Array.isArray(p2.networks) && p2.networks.some((n2) => n2.startsWith("eip155")));
|
|
5152
4908
|
const finalAssetContext = {
|
|
5153
4909
|
...assetInfo,
|
|
5154
4910
|
...asset,
|
|
@@ -5208,16 +4964,19 @@ class SDK {
|
|
|
5208
4964
|
}
|
|
5209
4965
|
}
|
|
5210
4966
|
if (asset.caip) {
|
|
5211
|
-
this.blockchainContext =
|
|
4967
|
+
this.blockchainContext = import_pioneer_caip6.caipToNetworkId(asset.caip);
|
|
5212
4968
|
} else if (asset.networkId) {
|
|
5213
4969
|
this.blockchainContext = asset.networkId;
|
|
5214
4970
|
}
|
|
5215
4971
|
if (assetPubkeys && assetPubkeys.length > 0) {
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
4972
|
+
const networkId = import_pioneer_caip6.caipToNetworkId(asset.caip || asset.networkId);
|
|
4973
|
+
const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
|
|
4974
|
+
if (!this.pubkeyContext || !currentContextValid) {
|
|
4975
|
+
this.pubkeyContext = assetPubkeys[0];
|
|
4976
|
+
console.log(tag5, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
|
|
4977
|
+
} else {
|
|
4978
|
+
console.log(tag5, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
|
|
5219
4979
|
}
|
|
5220
|
-
console.log(tag5, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
|
|
5221
4980
|
}
|
|
5222
4981
|
this.events.emit("SET_ASSET_CONTEXT", this.assetContext);
|
|
5223
4982
|
return this.assetContext;
|
|
@@ -5227,7 +4986,7 @@ class SDK {
|
|
|
5227
4986
|
}
|
|
5228
4987
|
};
|
|
5229
4988
|
this.setPubkeyContext = async function(pubkey) {
|
|
5230
|
-
let tag5 = `${
|
|
4989
|
+
let tag5 = `${TAG7} | setPubkeyContext | `;
|
|
5231
4990
|
try {
|
|
5232
4991
|
if (!pubkey)
|
|
5233
4992
|
throw Error("pubkey is required");
|
|
@@ -5238,10 +4997,7 @@ class SDK {
|
|
|
5238
4997
|
console.warn(tag5, "Pubkey not found in current pubkeys array");
|
|
5239
4998
|
}
|
|
5240
4999
|
this.pubkeyContext = pubkey;
|
|
5241
|
-
|
|
5242
|
-
this.keepKeySdk.pubkeyContext = pubkey;
|
|
5243
|
-
}
|
|
5244
|
-
console.log(tag5, "Pubkey context set to:", pubkey.address || pubkey.pubkey, "note:", pubkey.note);
|
|
5000
|
+
console.log(tag5, "Pubkey context set to:", pubkey.address || pubkey.pubkey, "note:", pubkey.note, "addressNList:", pubkey.addressNList || pubkey.addressNListMaster);
|
|
5245
5001
|
return true;
|
|
5246
5002
|
} catch (e) {
|
|
5247
5003
|
console.error(tag5, "e: ", e);
|
|
@@ -5249,7 +5005,7 @@ class SDK {
|
|
|
5249
5005
|
}
|
|
5250
5006
|
};
|
|
5251
5007
|
this.setOutboundAssetContext = async function(asset) {
|
|
5252
|
-
const tag5 = `${
|
|
5008
|
+
const tag5 = `${TAG7} | setOutputAssetContext | `;
|
|
5253
5009
|
try {
|
|
5254
5010
|
console.log(tag5, "0. asset: ", asset);
|
|
5255
5011
|
if (!asset) {
|
|
@@ -5260,7 +5016,7 @@ class SDK {
|
|
|
5260
5016
|
if (!asset.caip)
|
|
5261
5017
|
throw Error("Invalid Asset! missing caip!");
|
|
5262
5018
|
if (!asset.networkId)
|
|
5263
|
-
asset.networkId =
|
|
5019
|
+
asset.networkId = import_pioneer_caip6.caipToNetworkId(asset.caip);
|
|
5264
5020
|
console.log(tag5, "networkId: ", asset.networkId);
|
|
5265
5021
|
console.log(tag5, "this.pubkeys: ", this.pubkeys);
|
|
5266
5022
|
const pubkey = this.pubkeys.find((p2) => {
|
|
@@ -5341,7 +5097,7 @@ class SDK {
|
|
|
5341
5097
|
console.log(tag5, "CHECKPOINT 3");
|
|
5342
5098
|
console.log(tag5, "outboundAssetContext: assetInfo: ", assetInfo);
|
|
5343
5099
|
if (asset.caip) {
|
|
5344
|
-
this.outboundBlockchainContext =
|
|
5100
|
+
this.outboundBlockchainContext = import_pioneer_caip6.caipToNetworkId(asset.caip);
|
|
5345
5101
|
} else if (asset.networkId) {
|
|
5346
5102
|
this.outboundBlockchainContext = asset.networkId;
|
|
5347
5103
|
}
|