@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.js
CHANGED
|
@@ -23,398 +23,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
23
23
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
// ../pioneer-client/lib/index.js
|
|
27
|
-
var require_lib = __commonJS((exports) => {
|
|
28
|
-
var __assign = exports && exports.__assign || function() {
|
|
29
|
-
__assign = Object.assign || function(t) {
|
|
30
|
-
for (var s, i = 1, n = arguments.length;i < n; i++) {
|
|
31
|
-
s = arguments[i];
|
|
32
|
-
for (var p in s)
|
|
33
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
34
|
-
t[p] = s[p];
|
|
35
|
-
}
|
|
36
|
-
return t;
|
|
37
|
-
};
|
|
38
|
-
return __assign.apply(this, arguments);
|
|
39
|
-
};
|
|
40
|
-
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
41
|
-
function adopt(value) {
|
|
42
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
43
|
-
resolve(value);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
47
|
-
function fulfilled(value) {
|
|
48
|
-
try {
|
|
49
|
-
step(generator.next(value));
|
|
50
|
-
} catch (e) {
|
|
51
|
-
reject(e);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function rejected(value) {
|
|
55
|
-
try {
|
|
56
|
-
step(generator["throw"](value));
|
|
57
|
-
} catch (e) {
|
|
58
|
-
reject(e);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function step(result) {
|
|
62
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
63
|
-
}
|
|
64
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
var __generator = exports && exports.__generator || function(thisArg, body) {
|
|
68
|
-
var _ = { label: 0, sent: function() {
|
|
69
|
-
if (t[0] & 1)
|
|
70
|
-
throw t[1];
|
|
71
|
-
return t[1];
|
|
72
|
-
}, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
73
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
74
|
-
return this;
|
|
75
|
-
}), g;
|
|
76
|
-
function verb(n) {
|
|
77
|
-
return function(v) {
|
|
78
|
-
return step([n, v]);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function step(op) {
|
|
82
|
-
if (f)
|
|
83
|
-
throw new TypeError("Generator is already executing.");
|
|
84
|
-
while (g && (g = 0, op[0] && (_ = 0)), _)
|
|
85
|
-
try {
|
|
86
|
-
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)
|
|
87
|
-
return t;
|
|
88
|
-
if (y = 0, t)
|
|
89
|
-
op = [op[0] & 2, t.value];
|
|
90
|
-
switch (op[0]) {
|
|
91
|
-
case 0:
|
|
92
|
-
case 1:
|
|
93
|
-
t = op;
|
|
94
|
-
break;
|
|
95
|
-
case 4:
|
|
96
|
-
_.label++;
|
|
97
|
-
return { value: op[1], done: false };
|
|
98
|
-
case 5:
|
|
99
|
-
_.label++;
|
|
100
|
-
y = op[1];
|
|
101
|
-
op = [0];
|
|
102
|
-
continue;
|
|
103
|
-
case 7:
|
|
104
|
-
op = _.ops.pop();
|
|
105
|
-
_.trys.pop();
|
|
106
|
-
continue;
|
|
107
|
-
default:
|
|
108
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
109
|
-
_ = 0;
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
113
|
-
_.label = op[1];
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
117
|
-
_.label = t[1];
|
|
118
|
-
t = op;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
if (t && _.label < t[2]) {
|
|
122
|
-
_.label = t[2];
|
|
123
|
-
_.ops.push(op);
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
if (t[2])
|
|
127
|
-
_.ops.pop();
|
|
128
|
-
_.trys.pop();
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
op = body.call(thisArg, _);
|
|
132
|
-
} catch (e) {
|
|
133
|
-
op = [6, e];
|
|
134
|
-
y = 0;
|
|
135
|
-
} finally {
|
|
136
|
-
f = t = 0;
|
|
137
|
-
}
|
|
138
|
-
if (op[0] & 5)
|
|
139
|
-
throw op[1];
|
|
140
|
-
return { value: op[0] ? op[1] : undefined, done: true };
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
144
|
-
exports.Pioneer = undefined;
|
|
145
|
-
var Swagger;
|
|
146
|
-
var log;
|
|
147
|
-
if (typeof window === "undefined") {
|
|
148
|
-
Swagger = __require("swagger-client");
|
|
149
|
-
log = __require("@pioneer-platform/loggerdog")();
|
|
150
|
-
} else {
|
|
151
|
-
Swagger = null;
|
|
152
|
-
log = {
|
|
153
|
-
debug: function() {
|
|
154
|
-
var args = [];
|
|
155
|
-
for (var _i = 0;_i < arguments.length; _i++) {
|
|
156
|
-
args[_i] = arguments[_i];
|
|
157
|
-
}
|
|
158
|
-
return console.debug.apply(console, args);
|
|
159
|
-
},
|
|
160
|
-
info: function() {
|
|
161
|
-
var args = [];
|
|
162
|
-
for (var _i = 0;_i < arguments.length; _i++) {
|
|
163
|
-
args[_i] = arguments[_i];
|
|
164
|
-
}
|
|
165
|
-
return console.info.apply(console, args);
|
|
166
|
-
},
|
|
167
|
-
warn: function() {
|
|
168
|
-
var args = [];
|
|
169
|
-
for (var _i = 0;_i < arguments.length; _i++) {
|
|
170
|
-
args[_i] = arguments[_i];
|
|
171
|
-
}
|
|
172
|
-
return console.warn.apply(console, args);
|
|
173
|
-
},
|
|
174
|
-
error: function() {
|
|
175
|
-
var args = [];
|
|
176
|
-
for (var _i = 0;_i < arguments.length; _i++) {
|
|
177
|
-
args[_i] = arguments[_i];
|
|
178
|
-
}
|
|
179
|
-
return console.error.apply(console, args);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
var TAG = " | Client | ";
|
|
184
|
-
function customHttpClient(req) {
|
|
185
|
-
var _this = this;
|
|
186
|
-
return new Promise(function(resolve, reject) {
|
|
187
|
-
var timer = setTimeout(function() {
|
|
188
|
-
reject(new Error("Request timed out"));
|
|
189
|
-
}, 60000);
|
|
190
|
-
log.debug(TAG, "HTTP request URL:", req.url);
|
|
191
|
-
log.debug(TAG, "HTTP request details:", req);
|
|
192
|
-
if (Swagger && Swagger.http) {
|
|
193
|
-
Swagger.http(req).then(function(response) {
|
|
194
|
-
clearTimeout(timer);
|
|
195
|
-
resolve(response);
|
|
196
|
-
}).catch(function(err) {
|
|
197
|
-
clearTimeout(timer);
|
|
198
|
-
reject(err);
|
|
199
|
-
});
|
|
200
|
-
} else {
|
|
201
|
-
var fetchOptions = {
|
|
202
|
-
method: req.method || "GET",
|
|
203
|
-
headers: req.headers,
|
|
204
|
-
body: req.body ? typeof req.body === "string" ? req.body : JSON.stringify(req.body) : undefined
|
|
205
|
-
};
|
|
206
|
-
fetch(req.url, fetchOptions).then(function(response) {
|
|
207
|
-
return __awaiter(_this, undefined, undefined, function() {
|
|
208
|
-
var text, body, headers;
|
|
209
|
-
return __generator(this, function(_a) {
|
|
210
|
-
switch (_a.label) {
|
|
211
|
-
case 0:
|
|
212
|
-
clearTimeout(timer);
|
|
213
|
-
return [4, response.text()];
|
|
214
|
-
case 1:
|
|
215
|
-
text = _a.sent();
|
|
216
|
-
try {
|
|
217
|
-
body = JSON.parse(text);
|
|
218
|
-
} catch (jsonError) {
|
|
219
|
-
body = text;
|
|
220
|
-
}
|
|
221
|
-
headers = {};
|
|
222
|
-
response.headers.forEach(function(value, key) {
|
|
223
|
-
headers[key] = value;
|
|
224
|
-
});
|
|
225
|
-
resolve({
|
|
226
|
-
status: response.status,
|
|
227
|
-
body,
|
|
228
|
-
headers
|
|
229
|
-
});
|
|
230
|
-
return [2];
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
}).catch(function(err) {
|
|
235
|
-
clearTimeout(timer);
|
|
236
|
-
reject(err);
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
var Pioneer = function() {
|
|
242
|
-
function Pioneer2(spec, config) {
|
|
243
|
-
this.spec = spec;
|
|
244
|
-
this.queryKey = config.queryKey;
|
|
245
|
-
this.pioneer = {};
|
|
246
|
-
this.timeout = config.queryKey || 45000;
|
|
247
|
-
}
|
|
248
|
-
Pioneer2.prototype.init = function() {
|
|
249
|
-
return __awaiter(this, undefined, undefined, function() {
|
|
250
|
-
var tag, _a, specResponse, specData_1, e_1;
|
|
251
|
-
var _this = this;
|
|
252
|
-
return __generator(this, function(_b) {
|
|
253
|
-
switch (_b.label) {
|
|
254
|
-
case 0:
|
|
255
|
-
tag = TAG + " | init | ";
|
|
256
|
-
_b.label = 1;
|
|
257
|
-
case 1:
|
|
258
|
-
_b.trys.push([1, 7, , 8]);
|
|
259
|
-
if (!this.queryKey)
|
|
260
|
-
throw Error(" You must create an api key! ");
|
|
261
|
-
if (!Swagger)
|
|
262
|
-
return [3, 3];
|
|
263
|
-
_a = this;
|
|
264
|
-
return [4, new Swagger({
|
|
265
|
-
url: this.spec,
|
|
266
|
-
requestInterceptor: function(req) {
|
|
267
|
-
req.headers.Authorization = _this.queryKey;
|
|
268
|
-
if ((req.method === "POST" || req.method === "post") && req.body) {
|
|
269
|
-
log.debug(TAG, "Request interceptor - method:", req.method);
|
|
270
|
-
log.debug(TAG, "Body type:", typeof req.body);
|
|
271
|
-
log.debug(TAG, "Body preview:", typeof req.body === "string" ? req.body.substring(0, 200) : JSON.stringify(req.body).substring(0, 200));
|
|
272
|
-
if (!req.headers)
|
|
273
|
-
req.headers = {};
|
|
274
|
-
if (!req.headers["Content-Type"]) {
|
|
275
|
-
req.headers["Content-Type"] = "application/json";
|
|
276
|
-
}
|
|
277
|
-
if (typeof req.body !== "string") {
|
|
278
|
-
log.debug(TAG, "Converting body to JSON string");
|
|
279
|
-
req.body = JSON.stringify(req.body);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return req;
|
|
283
|
-
},
|
|
284
|
-
http: customHttpClient
|
|
285
|
-
})];
|
|
286
|
-
case 2:
|
|
287
|
-
_a.client = _b.sent();
|
|
288
|
-
return [3, 6];
|
|
289
|
-
case 3:
|
|
290
|
-
return [4, fetch(this.spec)];
|
|
291
|
-
case 4:
|
|
292
|
-
specResponse = _b.sent();
|
|
293
|
-
return [4, specResponse.json()];
|
|
294
|
-
case 5:
|
|
295
|
-
specData_1 = _b.sent();
|
|
296
|
-
this.client = {
|
|
297
|
-
spec: specData_1,
|
|
298
|
-
execute: function(request) {
|
|
299
|
-
return __awaiter(_this, undefined, undefined, function() {
|
|
300
|
-
var operationId, parameters, requestBody, targetPath, targetMethod, path, method, baseUrl, url, httpReq;
|
|
301
|
-
return __generator(this, function(_a2) {
|
|
302
|
-
switch (_a2.label) {
|
|
303
|
-
case 0:
|
|
304
|
-
operationId = request.operationId, parameters = request.parameters, requestBody = request.requestBody;
|
|
305
|
-
targetPath = "";
|
|
306
|
-
targetMethod = "";
|
|
307
|
-
for (path in specData_1.paths) {
|
|
308
|
-
for (method in specData_1.paths[path]) {
|
|
309
|
-
if (specData_1.paths[path][method].operationId === operationId) {
|
|
310
|
-
targetPath = path;
|
|
311
|
-
targetMethod = method;
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (targetPath)
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
if (!targetPath) {
|
|
319
|
-
throw new Error("Operation ".concat(operationId, " not found in spec"));
|
|
320
|
-
}
|
|
321
|
-
baseUrl = this.spec.replace("/spec/swagger.json", "");
|
|
322
|
-
if (specData_1.servers && specData_1.servers.length > 0) {
|
|
323
|
-
baseUrl = specData_1.servers[0].url;
|
|
324
|
-
}
|
|
325
|
-
url = "".concat(baseUrl).concat(targetPath);
|
|
326
|
-
httpReq = {
|
|
327
|
-
method: targetMethod.toUpperCase(),
|
|
328
|
-
url,
|
|
329
|
-
headers: {
|
|
330
|
-
Authorization: this.queryKey,
|
|
331
|
-
"Content-Type": "application/json"
|
|
332
|
-
},
|
|
333
|
-
body: requestBody
|
|
334
|
-
};
|
|
335
|
-
return [4, customHttpClient(httpReq)];
|
|
336
|
-
case 1:
|
|
337
|
-
return [2, _a2.sent()];
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
_b.label = 6;
|
|
344
|
-
case 6:
|
|
345
|
-
Object.keys(this.client.spec.paths).forEach(function(path) {
|
|
346
|
-
Object.keys(_this.client.spec.paths[path]).forEach(function(method) {
|
|
347
|
-
var operationId = _this.client.spec.paths[path][method].operationId;
|
|
348
|
-
_this.pioneer[operationId] = function(parameters) {
|
|
349
|
-
return __awaiter(_this, undefined, undefined, function() {
|
|
350
|
-
var invalidElements, request, result, e_2;
|
|
351
|
-
return __generator(this, function(_a2) {
|
|
352
|
-
switch (_a2.label) {
|
|
353
|
-
case 0:
|
|
354
|
-
_a2.trys.push([0, 2, , 3]);
|
|
355
|
-
log.debug(TAG, "".concat(operationId, " called with:"), parameters);
|
|
356
|
-
if (operationId === "GetMarketInfo") {
|
|
357
|
-
if (!Array.isArray(parameters)) {
|
|
358
|
-
throw new Error("GetMarketInfo requires an array of CAIP strings, got ".concat(typeof parameters));
|
|
359
|
-
}
|
|
360
|
-
invalidElements = parameters.map(function(item, index) {
|
|
361
|
-
return { item, index, type: typeof item };
|
|
362
|
-
}).filter(function(_a3) {
|
|
363
|
-
var item = _a3.item;
|
|
364
|
-
return !item || typeof item !== "string";
|
|
365
|
-
});
|
|
366
|
-
if (invalidElements.length > 0) {
|
|
367
|
-
console.error("\uD83D\uDEA8 [PIONEER CLIENT] GetMarketInfo validation failed:", invalidElements);
|
|
368
|
-
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, ")"));
|
|
369
|
-
}
|
|
370
|
-
log.debug(TAG, "GetMarketInfo validation passed: ".concat(parameters.length, " valid CAIP strings"));
|
|
371
|
-
}
|
|
372
|
-
request = {
|
|
373
|
-
operationId,
|
|
374
|
-
parameters: {
|
|
375
|
-
Authorization: this.queryKey
|
|
376
|
-
},
|
|
377
|
-
responseContentType: "application/json"
|
|
378
|
-
};
|
|
379
|
-
if (method === "post") {
|
|
380
|
-
request.requestBody = parameters;
|
|
381
|
-
} else {
|
|
382
|
-
request.parameters = __assign(__assign({}, parameters), { Authorization: this.queryKey });
|
|
383
|
-
}
|
|
384
|
-
log.debug(TAG, "".concat(operationId, " request:"), request);
|
|
385
|
-
return [4, this.client.execute(request)];
|
|
386
|
-
case 1:
|
|
387
|
-
result = _a2.sent();
|
|
388
|
-
return [2, { data: result.body }];
|
|
389
|
-
case 2:
|
|
390
|
-
e_2 = _a2.sent();
|
|
391
|
-
log.error(TAG, "Operation error:", e_2);
|
|
392
|
-
throw e_2;
|
|
393
|
-
case 3:
|
|
394
|
-
return [2];
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
};
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
return [2, this.pioneer];
|
|
402
|
-
case 7:
|
|
403
|
-
e_1 = _b.sent();
|
|
404
|
-
log.error(TAG, "Initialization error:", e_1);
|
|
405
|
-
throw e_1;
|
|
406
|
-
case 8:
|
|
407
|
-
return [2];
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
};
|
|
412
|
-
return Pioneer2;
|
|
413
|
-
}();
|
|
414
|
-
exports.Pioneer = Pioneer;
|
|
415
|
-
exports.default = Pioneer;
|
|
416
|
-
});
|
|
417
|
-
|
|
418
26
|
// ../../../node_modules/coinselect/utils.js
|
|
419
27
|
var require_utils = __commonJS((exports, module) => {
|
|
420
28
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
@@ -488,49 +96,6 @@ var require_utils = __commonJS((exports, module) => {
|
|
|
488
96
|
};
|
|
489
97
|
});
|
|
490
98
|
|
|
491
|
-
// ../../../node_modules/coinselect/split.js
|
|
492
|
-
var require_split = __commonJS((exports, module) => {
|
|
493
|
-
var utils = require_utils();
|
|
494
|
-
module.exports = function split(utxos, outputs, feeRate) {
|
|
495
|
-
if (!isFinite(utils.uintOrNaN(feeRate)))
|
|
496
|
-
return {};
|
|
497
|
-
var bytesAccum = utils.transactionBytes(utxos, outputs);
|
|
498
|
-
var fee = feeRate * bytesAccum;
|
|
499
|
-
if (outputs.length === 0)
|
|
500
|
-
return { fee };
|
|
501
|
-
var inAccum = utils.sumOrNaN(utxos);
|
|
502
|
-
var outAccum = utils.sumForgiving(outputs);
|
|
503
|
-
var remaining = inAccum - outAccum - fee;
|
|
504
|
-
if (!isFinite(remaining) || remaining < 0)
|
|
505
|
-
return { fee };
|
|
506
|
-
var unspecified = outputs.reduce(function(a2, x2) {
|
|
507
|
-
return a2 + !isFinite(x2.value);
|
|
508
|
-
}, 0);
|
|
509
|
-
if (remaining === 0 && unspecified === 0)
|
|
510
|
-
return utils.finalize(utxos, outputs, feeRate);
|
|
511
|
-
var splitOutputsCount = outputs.reduce(function(a2, x2) {
|
|
512
|
-
if (x2.value !== undefined)
|
|
513
|
-
return a2;
|
|
514
|
-
return a2 + 1;
|
|
515
|
-
}, 0);
|
|
516
|
-
var splitValue = Math.floor(remaining / splitOutputsCount);
|
|
517
|
-
if (!outputs.every(function(x2) {
|
|
518
|
-
return x2.value !== undefined || splitValue > utils.dustThreshold(x2, feeRate);
|
|
519
|
-
}))
|
|
520
|
-
return { fee };
|
|
521
|
-
outputs = outputs.map(function(x2) {
|
|
522
|
-
if (x2.value !== undefined)
|
|
523
|
-
return x2;
|
|
524
|
-
var y2 = {};
|
|
525
|
-
for (var k in x2)
|
|
526
|
-
y2[k] = x2[k];
|
|
527
|
-
y2.value = splitValue;
|
|
528
|
-
return y2;
|
|
529
|
-
});
|
|
530
|
-
return utils.finalize(utxos, outputs, feeRate);
|
|
531
|
-
};
|
|
532
|
-
});
|
|
533
|
-
|
|
534
99
|
// ../../../node_modules/coinselect/accumulative.js
|
|
535
100
|
var require_accumulative = __commonJS((exports, module) => {
|
|
536
101
|
var utils = require_utils();
|
|
@@ -611,10 +176,53 @@ var require_coinselect = __commonJS((exports, module) => {
|
|
|
611
176
|
};
|
|
612
177
|
});
|
|
613
178
|
|
|
179
|
+
// ../../../node_modules/coinselect/split.js
|
|
180
|
+
var require_split = __commonJS((exports, module) => {
|
|
181
|
+
var utils = require_utils();
|
|
182
|
+
module.exports = function split(utxos, outputs, feeRate) {
|
|
183
|
+
if (!isFinite(utils.uintOrNaN(feeRate)))
|
|
184
|
+
return {};
|
|
185
|
+
var bytesAccum = utils.transactionBytes(utxos, outputs);
|
|
186
|
+
var fee = feeRate * bytesAccum;
|
|
187
|
+
if (outputs.length === 0)
|
|
188
|
+
return { fee };
|
|
189
|
+
var inAccum = utils.sumOrNaN(utxos);
|
|
190
|
+
var outAccum = utils.sumForgiving(outputs);
|
|
191
|
+
var remaining = inAccum - outAccum - fee;
|
|
192
|
+
if (!isFinite(remaining) || remaining < 0)
|
|
193
|
+
return { fee };
|
|
194
|
+
var unspecified = outputs.reduce(function(a2, x2) {
|
|
195
|
+
return a2 + !isFinite(x2.value);
|
|
196
|
+
}, 0);
|
|
197
|
+
if (remaining === 0 && unspecified === 0)
|
|
198
|
+
return utils.finalize(utxos, outputs, feeRate);
|
|
199
|
+
var splitOutputsCount = outputs.reduce(function(a2, x2) {
|
|
200
|
+
if (x2.value !== undefined)
|
|
201
|
+
return a2;
|
|
202
|
+
return a2 + 1;
|
|
203
|
+
}, 0);
|
|
204
|
+
var splitValue = Math.floor(remaining / splitOutputsCount);
|
|
205
|
+
if (!outputs.every(function(x2) {
|
|
206
|
+
return x2.value !== undefined || splitValue > utils.dustThreshold(x2, feeRate);
|
|
207
|
+
}))
|
|
208
|
+
return { fee };
|
|
209
|
+
outputs = outputs.map(function(x2) {
|
|
210
|
+
if (x2.value !== undefined)
|
|
211
|
+
return x2;
|
|
212
|
+
var y2 = {};
|
|
213
|
+
for (var k in x2)
|
|
214
|
+
y2[k] = x2[k];
|
|
215
|
+
y2.value = splitValue;
|
|
216
|
+
return y2;
|
|
217
|
+
});
|
|
218
|
+
return utils.finalize(utxos, outputs, feeRate);
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
|
|
614
222
|
// src/index.ts
|
|
615
|
-
var import_pioneer_client = __toESM(require_lib(), 1);
|
|
616
223
|
import { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
617
|
-
import { caipToNetworkId as
|
|
224
|
+
import { caipToNetworkId as caipToNetworkId6, networkIdToCaip } from "@pioneer-platform/pioneer-caip";
|
|
225
|
+
import Pioneer from "@pioneer-platform/pioneer-client";
|
|
618
226
|
import { addressNListToBIP32 as addressNListToBIP322, getPaths } from "@pioneer-platform/pioneer-coins";
|
|
619
227
|
import { assetData as assetData2 } from "@pioneer-platform/pioneer-discovery";
|
|
620
228
|
import { Events } from "@pioneer-platform/pioneer-events";
|
|
@@ -812,6 +420,7 @@ function R(t) {
|
|
|
812
420
|
e[n] = t[n].listener || t[n];
|
|
813
421
|
return e;
|
|
814
422
|
}
|
|
423
|
+
var A = o;
|
|
815
424
|
var P = o.prototype;
|
|
816
425
|
|
|
817
426
|
// src/charts/utils.ts
|
|
@@ -1405,42 +1014,31 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1405
1014
|
console.error("⏰ [PUBKEY] Address retrieval timeout for", networkId);
|
|
1406
1015
|
}, 30000);
|
|
1407
1016
|
try {
|
|
1408
|
-
let result;
|
|
1409
1017
|
switch (networkType) {
|
|
1410
1018
|
case "UTXO":
|
|
1411
|
-
|
|
1019
|
+
({ address } = await sdk.address.utxoGetAddress(addressInfo));
|
|
1412
1020
|
break;
|
|
1413
1021
|
case "EVM":
|
|
1414
|
-
|
|
1022
|
+
({ address } = await sdk.address.ethereumGetAddress(addressInfo));
|
|
1415
1023
|
break;
|
|
1416
1024
|
case "OSMOSIS":
|
|
1417
|
-
|
|
1025
|
+
({ address } = await sdk.address.osmosisGetAddress(addressInfo));
|
|
1418
1026
|
break;
|
|
1419
1027
|
case "COSMOS":
|
|
1420
|
-
|
|
1028
|
+
({ address } = await sdk.address.cosmosGetAddress(addressInfo));
|
|
1421
1029
|
break;
|
|
1422
1030
|
case "MAYACHAIN":
|
|
1423
|
-
|
|
1031
|
+
({ address } = await sdk.address.mayachainGetAddress(addressInfo));
|
|
1424
1032
|
break;
|
|
1425
1033
|
case "THORCHAIN":
|
|
1426
|
-
|
|
1034
|
+
({ address } = await sdk.address.thorchainGetAddress(addressInfo));
|
|
1427
1035
|
break;
|
|
1428
1036
|
case "XRP":
|
|
1429
|
-
|
|
1037
|
+
({ address } = await sdk.address.xrpGetAddress(addressInfo));
|
|
1430
1038
|
break;
|
|
1431
1039
|
default:
|
|
1432
1040
|
throw new Error(`Unsupported network type for networkId: ${networkId}`);
|
|
1433
1041
|
}
|
|
1434
|
-
if (!result) {
|
|
1435
|
-
throw new Error(`Address call returned null/undefined for ${networkType} (${networkId})`);
|
|
1436
|
-
}
|
|
1437
|
-
if (typeof result === "object" && result.address) {
|
|
1438
|
-
address = result.address;
|
|
1439
|
-
} else if (typeof result === "string") {
|
|
1440
|
-
address = result;
|
|
1441
|
-
} else {
|
|
1442
|
-
throw new Error(`Invalid address response format for ${networkType} (${networkId}): ${JSON.stringify(result)}`);
|
|
1443
|
-
}
|
|
1444
1042
|
clearTimeout(addressTimeout);
|
|
1445
1043
|
} catch (addressError) {
|
|
1446
1044
|
clearTimeout(addressTimeout);
|
|
@@ -1455,6 +1053,10 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1455
1053
|
pubkey.master = address;
|
|
1456
1054
|
pubkey.address = address;
|
|
1457
1055
|
if (["xpub", "ypub", "zpub"].includes(path.type)) {
|
|
1056
|
+
console.log("\uD83D\uDD11 [XPUB] Starting xpub retrieval for path type:", path.type);
|
|
1057
|
+
console.log("\uD83D\uDD11 [XPUB] Network:", networkId);
|
|
1058
|
+
console.log("\uD83D\uDD11 [XPUB] Path:", addressNListToBIP32(path.addressNList));
|
|
1059
|
+
console.log("\uD83D\uDD11 [XPUB] Script type:", path.script_type);
|
|
1458
1060
|
const pathQuery = {
|
|
1459
1061
|
symbol: "BTC",
|
|
1460
1062
|
coin: "Bitcoin",
|
|
@@ -1462,26 +1064,58 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1462
1064
|
address_n: path.addressNList,
|
|
1463
1065
|
showDisplay: false
|
|
1464
1066
|
};
|
|
1067
|
+
console.log("\uD83D\uDD11 [XPUB] Calling sdk.system.info.getPublicKey with:", JSON.stringify(pathQuery, null, 2));
|
|
1465
1068
|
const xpubTimeout = setTimeout(() => {
|
|
1466
|
-
console.error("getPublicKey timeout after 20 seconds");
|
|
1069
|
+
console.error("⏰ [XPUB TIMEOUT] getPublicKey timeout after 20 seconds");
|
|
1070
|
+
console.error("⏰ [XPUB TIMEOUT] Path:", addressNListToBIP32(path.addressNList));
|
|
1071
|
+
console.error("⏰ [XPUB TIMEOUT] This is a CRITICAL FAILURE - UTXO balances require xpubs");
|
|
1467
1072
|
}, 20000);
|
|
1468
1073
|
try {
|
|
1074
|
+
console.log("\uD83D\uDD11 [XPUB] Calling getPublicKey...");
|
|
1469
1075
|
const responsePubkey = await sdk.system.info.getPublicKey(pathQuery);
|
|
1470
1076
|
clearTimeout(xpubTimeout);
|
|
1077
|
+
console.log("✅ [XPUB] getPublicKey SUCCESS");
|
|
1078
|
+
console.log("✅ [XPUB] Response:", JSON.stringify(responsePubkey, null, 2));
|
|
1079
|
+
if (!responsePubkey || !responsePubkey.xpub) {
|
|
1080
|
+
const error = new Error("FAIL FAST: getPublicKey returned null or missing xpub");
|
|
1081
|
+
console.error("❌ [XPUB] CRITICAL:", error.message);
|
|
1082
|
+
console.error("❌ [XPUB] Response was:", responsePubkey);
|
|
1083
|
+
throw error;
|
|
1084
|
+
}
|
|
1471
1085
|
if (path.script_type === "p2wpkh") {
|
|
1086
|
+
console.log("\uD83D\uDD11 [XPUB] Converting xpub to zpub for native segwit");
|
|
1472
1087
|
responsePubkey.xpub = xpubConvert(responsePubkey.xpub, "zpub");
|
|
1473
1088
|
} else if (path.script_type === "p2sh-p2wpkh") {
|
|
1089
|
+
console.log("\uD83D\uDD11 [XPUB] Converting xpub to ypub for wrapped segwit");
|
|
1474
1090
|
responsePubkey.xpub = xpubConvert(responsePubkey.xpub, "ypub");
|
|
1475
1091
|
}
|
|
1092
|
+
console.log("✅ [XPUB] Final xpub:", responsePubkey.xpub.substring(0, 20) + "...");
|
|
1476
1093
|
pubkey.pubkey = responsePubkey.xpub;
|
|
1477
1094
|
pubkey.path = addressNListToBIP32(path.addressNList);
|
|
1478
1095
|
pubkey.pathMaster = addressNListToBIP32(path.addressNListMaster);
|
|
1096
|
+
console.log("✅ [XPUB] Xpub retrieval COMPLETE for", path.note || path.type);
|
|
1479
1097
|
} catch (xpubError) {
|
|
1480
1098
|
clearTimeout(xpubTimeout);
|
|
1481
|
-
console.error("getPublicKey failed
|
|
1482
|
-
|
|
1099
|
+
console.error("❌ [XPUB] CRITICAL FAILURE - getPublicKey failed");
|
|
1100
|
+
console.error("❌ [XPUB] Error:", xpubError);
|
|
1101
|
+
console.error("❌ [XPUB] Error message:", xpubError.message);
|
|
1102
|
+
console.error("❌ [XPUB] Error stack:", xpubError.stack);
|
|
1103
|
+
console.error("❌ [XPUB] Path:", addressNListToBIP32(path.addressNList));
|
|
1104
|
+
console.error("❌ [XPUB] Network:", networkId);
|
|
1105
|
+
console.error("❌ [XPUB] Query:", JSON.stringify(pathQuery, null, 2));
|
|
1106
|
+
console.error("❌ [XPUB] SDK available:", !!sdk);
|
|
1107
|
+
console.error("❌ [XPUB] SDK.system available:", !!sdk?.system);
|
|
1108
|
+
console.error("❌ [XPUB] SDK.system.info available:", !!sdk?.system?.info);
|
|
1109
|
+
console.error("❌ [XPUB] SDK.system.info.getPublicKey available:", !!sdk?.system?.info?.getPublicKey);
|
|
1110
|
+
console.error("");
|
|
1111
|
+
console.error("\uD83D\uDEA8 FAIL FAST: Cannot proceed without xpub for UTXO chains");
|
|
1112
|
+
console.error("\uD83D\uDEA8 UTXO balance queries REQUIRE extended public keys (xpubs)");
|
|
1113
|
+
console.error("\uD83D\uDEA8 This is a device communication or SDK issue that must be resolved");
|
|
1114
|
+
console.error("");
|
|
1115
|
+
throw new Error(`FAIL FAST - xpub retrieval failed for ${networkId} at ${addressNListToBIP32(path.addressNList)}: ${xpubError.message}`);
|
|
1483
1116
|
}
|
|
1484
1117
|
} else {
|
|
1118
|
+
console.log("\uD83D\uDD11 [PUBKEY] Non-xpub path (address-based), using address as pubkey");
|
|
1485
1119
|
pubkey.pubkey = address;
|
|
1486
1120
|
pubkey.path = addressNListToBIP32(path.addressNList);
|
|
1487
1121
|
pubkey.pathMaster = addressNListToBIP32(path.addressNListMaster);
|
|
@@ -1891,13 +1525,16 @@ async function fetchTokenPriceInUsd(contractAddress) {
|
|
|
1891
1525
|
}
|
|
1892
1526
|
return price;
|
|
1893
1527
|
}
|
|
1894
|
-
async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer,
|
|
1528
|
+
async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5) {
|
|
1895
1529
|
const tag5 = TAG + " | createUnsignedEvmTx | ";
|
|
1896
1530
|
try {
|
|
1897
1531
|
if (!pioneer)
|
|
1898
1532
|
throw new Error("Failed to initialize Pioneer");
|
|
1899
1533
|
const networkId = caipToNetworkId(caip);
|
|
1900
1534
|
const chainId = extractChainIdFromNetworkId(networkId);
|
|
1535
|
+
if (!pubkeyContext) {
|
|
1536
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
1537
|
+
}
|
|
1901
1538
|
const isValidForNetwork = (pubkey) => {
|
|
1902
1539
|
if (!pubkey?.networks)
|
|
1903
1540
|
return false;
|
|
@@ -1906,43 +1543,83 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
1906
1543
|
}
|
|
1907
1544
|
return pubkey.networks.includes(networkId);
|
|
1908
1545
|
};
|
|
1909
|
-
if (!
|
|
1910
|
-
|
|
1911
|
-
keepKeySdk.pubkeyContext = pubkeys.find((pk) => isValidForNetwork(pk));
|
|
1912
|
-
} else {
|
|
1913
|
-
console.log(tag5, "Current context networks:", keepKeySdk.pubkeyContext.networks, "For networkId:", networkId);
|
|
1914
|
-
if (!isValidForNetwork(keepKeySdk.pubkeyContext)) {
|
|
1915
|
-
console.log(tag5, "Auto-correcting context - wrong network detected");
|
|
1916
|
-
keepKeySdk.pubkeyContext = pubkeys.find((pk) => isValidForNetwork(pk));
|
|
1917
|
-
} else {
|
|
1918
|
-
console.log(tag5, "Context is valid for this network - using existing context");
|
|
1919
|
-
}
|
|
1546
|
+
if (!isValidForNetwork(pubkeyContext)) {
|
|
1547
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
1920
1548
|
}
|
|
1921
|
-
const address =
|
|
1922
|
-
console.log(tag5, "✅ Using FROM address from pubkeyContext:", address, "note:",
|
|
1549
|
+
const address = pubkeyContext.address || pubkeyContext.pubkey;
|
|
1550
|
+
console.log(tag5, "✅ Using FROM address from pubkeyContext:", address, "note:", pubkeyContext.note);
|
|
1923
1551
|
if (!address)
|
|
1924
1552
|
throw new Error("No address found for the specified network");
|
|
1925
1553
|
const gasPriceData = await pioneer.GetGasPriceByNetwork({ networkId });
|
|
1926
|
-
|
|
1927
|
-
const MIN_GAS_PRICE_WEI = BigInt(10000000000);
|
|
1928
|
-
if (BigInt(gasPriceData.data) < MIN_GAS_PRICE_WEI) {
|
|
1929
|
-
console.log(tag5, "Gas price from API too low:", gasPriceData.data, "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1930
|
-
baseGasPrice = MIN_GAS_PRICE_WEI;
|
|
1931
|
-
} else {
|
|
1932
|
-
baseGasPrice = BigInt(gasPriceData.data);
|
|
1933
|
-
}
|
|
1554
|
+
console.log(tag5, "Gas price data from API:", JSON.stringify(gasPriceData.data));
|
|
1934
1555
|
let gasPrice;
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1556
|
+
const defaultGasPrices = {
|
|
1557
|
+
1: 30,
|
|
1558
|
+
56: 3,
|
|
1559
|
+
137: 50,
|
|
1560
|
+
43114: 25,
|
|
1561
|
+
8453: 0.1,
|
|
1562
|
+
10: 0.1
|
|
1563
|
+
};
|
|
1564
|
+
const fallbackGasGwei = defaultGasPrices[chainId] || 20;
|
|
1565
|
+
const MIN_GAS_PRICE_WEI = BigInt(fallbackGasGwei * 1e9);
|
|
1566
|
+
if (typeof gasPriceData.data === "object" && gasPriceData.data !== null && !Array.isArray(gasPriceData.data)) {
|
|
1567
|
+
let selectedGasPrice;
|
|
1568
|
+
if (feeLevel <= 2) {
|
|
1569
|
+
selectedGasPrice = gasPriceData.data.slow || gasPriceData.data.average || gasPriceData.data.fastest;
|
|
1570
|
+
console.log(tag5, "Selecting SLOW gas price from API");
|
|
1571
|
+
} else if (feeLevel >= 8) {
|
|
1572
|
+
selectedGasPrice = gasPriceData.data.fastest || gasPriceData.data.fast || gasPriceData.data.average;
|
|
1573
|
+
console.log(tag5, "Selecting FAST gas price from API");
|
|
1574
|
+
} else {
|
|
1575
|
+
selectedGasPrice = gasPriceData.data.average || gasPriceData.data.fast || gasPriceData.data.fastest;
|
|
1576
|
+
console.log(tag5, "Selecting AVERAGE gas price from API");
|
|
1577
|
+
}
|
|
1578
|
+
let gasPriceNum;
|
|
1579
|
+
if (selectedGasPrice === undefined || selectedGasPrice === null) {
|
|
1580
|
+
console.warn(tag5, "No valid gas price found in API response, using fallback:", fallbackGasGwei, "gwei");
|
|
1581
|
+
gasPriceNum = fallbackGasGwei;
|
|
1582
|
+
} else {
|
|
1583
|
+
gasPriceNum = typeof selectedGasPrice === "string" ? parseFloat(selectedGasPrice) : selectedGasPrice;
|
|
1584
|
+
if (isNaN(gasPriceNum) || !isFinite(gasPriceNum)) {
|
|
1585
|
+
console.warn(tag5, "Invalid gas price (NaN or Infinite):", selectedGasPrice, "- using fallback:", fallbackGasGwei, "gwei");
|
|
1586
|
+
gasPriceNum = fallbackGasGwei;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
gasPrice = BigInt(Math.round(gasPriceNum * 1e9));
|
|
1590
|
+
if (gasPrice < MIN_GAS_PRICE_WEI) {
|
|
1591
|
+
console.warn(tag5, "Gas price from API too low:", gasPrice.toString(), "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1592
|
+
gasPrice = MIN_GAS_PRICE_WEI;
|
|
1593
|
+
}
|
|
1941
1594
|
} else {
|
|
1942
|
-
|
|
1943
|
-
|
|
1595
|
+
let gasPriceNum;
|
|
1596
|
+
if (gasPriceData.data === undefined || gasPriceData.data === null) {
|
|
1597
|
+
console.warn(tag5, "Gas price API returned null/undefined, using fallback:", fallbackGasGwei, "gwei");
|
|
1598
|
+
gasPriceNum = fallbackGasGwei;
|
|
1599
|
+
} else {
|
|
1600
|
+
gasPriceNum = typeof gasPriceData.data === "string" ? parseFloat(gasPriceData.data) : gasPriceData.data;
|
|
1601
|
+
if (isNaN(gasPriceNum) || !isFinite(gasPriceNum)) {
|
|
1602
|
+
console.warn(tag5, "Invalid gas price (NaN or Infinite):", gasPriceData.data, "- using fallback:", fallbackGasGwei, "gwei");
|
|
1603
|
+
gasPriceNum = fallbackGasGwei;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
const baseGasPrice = BigInt(Math.round(gasPriceNum * 1e9));
|
|
1607
|
+
if (feeLevel <= 2) {
|
|
1608
|
+
gasPrice = baseGasPrice * BigInt(80) / BigInt(100);
|
|
1609
|
+
console.log(tag5, "Using SLOW gas price (80% of base)");
|
|
1610
|
+
} else if (feeLevel >= 8) {
|
|
1611
|
+
gasPrice = baseGasPrice * BigInt(150) / BigInt(100);
|
|
1612
|
+
console.log(tag5, "Using FAST gas price (150% of base)");
|
|
1613
|
+
} else {
|
|
1614
|
+
gasPrice = baseGasPrice;
|
|
1615
|
+
console.log(tag5, "Using AVERAGE gas price (100% of base)");
|
|
1616
|
+
}
|
|
1617
|
+
if (gasPrice < MIN_GAS_PRICE_WEI) {
|
|
1618
|
+
console.warn(tag5, "Gas price too low:", gasPrice.toString(), "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1619
|
+
gasPrice = MIN_GAS_PRICE_WEI;
|
|
1620
|
+
}
|
|
1944
1621
|
}
|
|
1945
|
-
console.log(tag5, "
|
|
1622
|
+
console.log(tag5, "Final gasPrice:", gasPrice.toString(), "wei (", Number(gasPrice) / 1e9, "gwei)");
|
|
1946
1623
|
let nonce;
|
|
1947
1624
|
try {
|
|
1948
1625
|
const nonceData = await pioneer.GetNonceByNetwork({ networkId, address });
|
|
@@ -2133,18 +1810,18 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
2133
1810
|
throw new Error(`Unsupported asset type for CAIP ${caip}`);
|
|
2134
1811
|
}
|
|
2135
1812
|
}
|
|
2136
|
-
if (
|
|
2137
|
-
unsignedTx.addressNList =
|
|
1813
|
+
if (pubkeyContext.addressNListMaster) {
|
|
1814
|
+
unsignedTx.addressNList = pubkeyContext.addressNListMaster;
|
|
2138
1815
|
console.log(tag5, "✅ Using addressNListMaster from pubkey context:", unsignedTx.addressNList, "for address:", address);
|
|
2139
|
-
} else if (
|
|
2140
|
-
unsignedTx.addressNList = bip32ToAddressNList(
|
|
2141
|
-
console.log(tag5, "✅ Converted pathMaster to addressNList:",
|
|
2142
|
-
} else if (
|
|
2143
|
-
unsignedTx.addressNList =
|
|
1816
|
+
} else if (pubkeyContext.pathMaster) {
|
|
1817
|
+
unsignedTx.addressNList = bip32ToAddressNList(pubkeyContext.pathMaster);
|
|
1818
|
+
console.log(tag5, "✅ Converted pathMaster to addressNList:", pubkeyContext.pathMaster, "→", unsignedTx.addressNList);
|
|
1819
|
+
} else if (pubkeyContext.addressNList) {
|
|
1820
|
+
unsignedTx.addressNList = pubkeyContext.addressNList;
|
|
2144
1821
|
console.log(tag5, "✅ Using addressNList from pubkey context:", unsignedTx.addressNList);
|
|
2145
|
-
} else if (
|
|
2146
|
-
unsignedTx.addressNList = bip32ToAddressNList(
|
|
2147
|
-
console.log(tag5, "⚠️ Using regular path (not master):",
|
|
1822
|
+
} else if (pubkeyContext.path) {
|
|
1823
|
+
unsignedTx.addressNList = bip32ToAddressNList(pubkeyContext.path);
|
|
1824
|
+
console.log(tag5, "⚠️ Using regular path (not master):", pubkeyContext.path, "→", unsignedTx.addressNList);
|
|
2148
1825
|
} else {
|
|
2149
1826
|
unsignedTx.addressNList = [2147483648 + 44, 2147483648 + 60, 2147483648, 0, 0];
|
|
2150
1827
|
console.warn(tag5, "⚠️ No path info in pubkey context, using default account 0");
|
|
@@ -2159,19 +1836,22 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
2159
1836
|
// src/txbuilder/createUnsignedRippleTx.ts
|
|
2160
1837
|
import { caipToNetworkId as caipToNetworkId2 } from "@pioneer-platform/pioneer-caip";
|
|
2161
1838
|
var TAG2 = " | createUnsignedUxtoTx | ";
|
|
2162
|
-
async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer,
|
|
1839
|
+
async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax) {
|
|
2163
1840
|
let tag5 = TAG2 + " | createUnsignedRippleTx | ";
|
|
2164
1841
|
try {
|
|
2165
1842
|
if (!pioneer)
|
|
2166
1843
|
throw new Error("Failed to init! pioneer");
|
|
2167
1844
|
const networkId = caipToNetworkId2(caip);
|
|
2168
|
-
if (!
|
|
2169
|
-
|
|
1845
|
+
if (!pubkeyContext) {
|
|
1846
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
2170
1847
|
}
|
|
2171
|
-
if (!
|
|
2172
|
-
throw new Error(`
|
|
1848
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
1849
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2173
1850
|
}
|
|
2174
|
-
|
|
1851
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
1852
|
+
address: pubkeyContext.address
|
|
1853
|
+
});
|
|
1854
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
2175
1855
|
let accountInfo = await pioneer.GetAccountInfo({
|
|
2176
1856
|
address: fromAddress,
|
|
2177
1857
|
network: "ripple"
|
|
@@ -2269,6 +1949,7 @@ var cosmosTransferTemplate = (params) => ({
|
|
|
2269
1949
|
// src/txbuilder/templates/mayachain.ts
|
|
2270
1950
|
var mayachainTransferTemplate = (params) => ({
|
|
2271
1951
|
signerAddress: params.from_address,
|
|
1952
|
+
addressNList: params.addressNList,
|
|
2272
1953
|
signDoc: {
|
|
2273
1954
|
account_number: params.account_number,
|
|
2274
1955
|
chain_id: params.chain_id,
|
|
@@ -2374,18 +2055,22 @@ var thorchainDepositTemplate = (params) => ({
|
|
|
2374
2055
|
|
|
2375
2056
|
// src/txbuilder/createUnsignedTendermintTx.ts
|
|
2376
2057
|
var TAG3 = " | createUnsignedTendermintTx | ";
|
|
2377
|
-
async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pioneer,
|
|
2058
|
+
async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, to) {
|
|
2378
2059
|
const tag5 = TAG3 + " | createUnsignedTendermintTx | ";
|
|
2379
2060
|
try {
|
|
2380
2061
|
if (!pioneer)
|
|
2381
2062
|
throw new Error("Failed to init! pioneer");
|
|
2382
2063
|
const networkId = caipToNetworkId3(caip);
|
|
2383
|
-
if (!
|
|
2384
|
-
|
|
2064
|
+
if (!pubkeyContext) {
|
|
2065
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
2385
2066
|
}
|
|
2386
|
-
if (!
|
|
2387
|
-
throw new Error(`
|
|
2067
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2068
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2388
2069
|
}
|
|
2070
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2071
|
+
address: pubkeyContext.address,
|
|
2072
|
+
addressNList: pubkeyContext.addressNList || pubkeyContext.addressNListMaster
|
|
2073
|
+
});
|
|
2389
2074
|
let chain;
|
|
2390
2075
|
switch (networkId) {
|
|
2391
2076
|
case "cosmos:thorchain-mainnet-v1":
|
|
@@ -2403,10 +2088,13 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2403
2088
|
default:
|
|
2404
2089
|
throw new Error(`Unhandled networkId: ${networkId}`);
|
|
2405
2090
|
}
|
|
2406
|
-
const fromAddress =
|
|
2091
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
2407
2092
|
let asset = caip.split(":")[1];
|
|
2093
|
+
console.log(tag5, `\uD83D\uDD0D Fetching account info for address: ${fromAddress}`);
|
|
2408
2094
|
const accountInfo = (await pioneer.GetAccountInfo({ network: chain, address: fromAddress })).data;
|
|
2095
|
+
console.log(tag5, "\uD83D\uDCCB accountInfo:", JSON.stringify(accountInfo, null, 2));
|
|
2409
2096
|
let balanceInfo = await pioneer.GetPubkeyBalance({ asset: chain, pubkey: fromAddress });
|
|
2097
|
+
console.log(tag5, `\uD83D\uDCB0 balanceInfo:`, balanceInfo);
|
|
2410
2098
|
let account_number, sequence;
|
|
2411
2099
|
if (networkId === "cosmos:cosmoshub-4" || networkId === "cosmos:osmosis-1") {
|
|
2412
2100
|
account_number = accountInfo.account.account_number || "0";
|
|
@@ -2415,9 +2103,17 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2415
2103
|
account_number = accountInfo.result.value.account_number || "0";
|
|
2416
2104
|
sequence = accountInfo.result.value.sequence || "0";
|
|
2417
2105
|
}
|
|
2106
|
+
console.log(tag5, `\uD83D\uDCCA Extracted account_number: ${account_number}, sequence: ${sequence}`);
|
|
2107
|
+
if (account_number === "0" || account_number === 0) {
|
|
2108
|
+
console.log(tag5, `⚠️ WARNING: Account number is 0 from Pioneer API`);
|
|
2109
|
+
console.log(tag5, ` This is likely due to stale Pioneer API cache`);
|
|
2110
|
+
console.log(tag5, ` The mayachain-network module queries nodes directly but Pioneer API may be cached`);
|
|
2111
|
+
console.log(tag5, ` Proceeding with account_number: 0 but transaction will likely fail`);
|
|
2112
|
+
console.log(tag5, ` TODO: Fix Pioneer API to use fresh data from mayachain-network module`);
|
|
2113
|
+
}
|
|
2418
2114
|
const fees = {
|
|
2419
2115
|
"cosmos:thorchain-mainnet-v1": 0.02,
|
|
2420
|
-
"cosmos:mayachain-mainnet-v1": 0
|
|
2116
|
+
"cosmos:mayachain-mainnet-v1": 0,
|
|
2421
2117
|
"cosmos:cosmoshub-4": 0.005,
|
|
2422
2118
|
"cosmos:osmosis-1": 0.035
|
|
2423
2119
|
};
|
|
@@ -2476,11 +2172,12 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2476
2172
|
} else {
|
|
2477
2173
|
throw new Error(`Unsupported Maya chain CAIP: ${caip}`);
|
|
2478
2174
|
}
|
|
2175
|
+
const decimals = mayaAsset === "maya" ? 1e4 : 10000000000;
|
|
2479
2176
|
if (isMax) {
|
|
2480
|
-
const fee = Math.floor(fees[networkId] *
|
|
2481
|
-
amount = Math.max(0, Math.floor(balanceInfo.data *
|
|
2177
|
+
const fee = Math.floor(fees[networkId] * decimals);
|
|
2178
|
+
amount = Math.max(0, Math.floor(balanceInfo.data * decimals) - fee);
|
|
2482
2179
|
} else {
|
|
2483
|
-
amount = Math.max(Math.floor(amount *
|
|
2180
|
+
amount = Math.max(Math.floor(amount * decimals), 0);
|
|
2484
2181
|
}
|
|
2485
2182
|
return to ? mayachainTransferTemplate({
|
|
2486
2183
|
account_number,
|
|
@@ -2499,7 +2196,8 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2499
2196
|
asset: mayaAsset,
|
|
2500
2197
|
amount: amount.toString(),
|
|
2501
2198
|
memo,
|
|
2502
|
-
sequence
|
|
2199
|
+
sequence,
|
|
2200
|
+
addressNList: pubkeyContext.addressNList || pubkeyContext.addressNListMaster
|
|
2503
2201
|
}) : mayachainDepositTemplate({
|
|
2504
2202
|
account_number,
|
|
2505
2203
|
chain_id: "mayachain-mainnet-v1",
|
|
@@ -2572,54 +2270,52 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2572
2270
|
}
|
|
2573
2271
|
|
|
2574
2272
|
// src/txbuilder/createUnsignedUxtoTx.ts
|
|
2273
|
+
var import_coinselect = __toESM(require_coinselect(), 1);
|
|
2274
|
+
var import_split = __toESM(require_split(), 1);
|
|
2575
2275
|
import { caipToNetworkId as caipToNetworkId4, NetworkIdToChain } from "@pioneer-platform/pioneer-caip";
|
|
2576
|
-
import { bip32ToAddressNList as bip32ToAddressNList2 } from "@pioneer-platform/pioneer-coins";
|
|
2577
|
-
|
|
2276
|
+
import { bip32ToAddressNList as bip32ToAddressNList2, SLIP_44_BY_LONG, COIN_MAP_LONG } from "@pioneer-platform/pioneer-coins";
|
|
2277
|
+
function getCoinTypeFromNetworkId(networkId) {
|
|
2278
|
+
const chain = NetworkIdToChain[networkId];
|
|
2279
|
+
if (!chain) {
|
|
2280
|
+
console.warn(`No chain mapping found for ${networkId}, defaulting to Bitcoin coin type 0`);
|
|
2281
|
+
return 0;
|
|
2282
|
+
}
|
|
2283
|
+
const blockchainName = COIN_MAP_LONG[chain]?.toLowerCase();
|
|
2284
|
+
if (!blockchainName) {
|
|
2285
|
+
console.warn(`No blockchain name found for chain ${chain}, defaulting to Bitcoin coin type 0`);
|
|
2286
|
+
return 0;
|
|
2287
|
+
}
|
|
2288
|
+
const coinType = SLIP_44_BY_LONG[blockchainName];
|
|
2289
|
+
if (coinType === undefined) {
|
|
2290
|
+
console.warn(`No SLIP-44 coin type found for ${blockchainName}, defaulting to Bitcoin coin type 0`);
|
|
2291
|
+
return 0;
|
|
2292
|
+
}
|
|
2293
|
+
return coinType;
|
|
2294
|
+
}
|
|
2295
|
+
async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5, changeScriptType) {
|
|
2578
2296
|
let tag5 = " | createUnsignedUxtoTx | ";
|
|
2579
2297
|
try {
|
|
2580
2298
|
if (!pioneer)
|
|
2581
2299
|
throw Error("Failed to init! pioneer");
|
|
2582
2300
|
const networkId = caipToNetworkId4(caip);
|
|
2583
|
-
if (!
|
|
2584
|
-
|
|
2301
|
+
if (!pubkeyContext) {
|
|
2302
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
2585
2303
|
}
|
|
2304
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2305
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2306
|
+
}
|
|
2307
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2308
|
+
address: pubkeyContext.address,
|
|
2309
|
+
scriptType: pubkeyContext.scriptType
|
|
2310
|
+
});
|
|
2586
2311
|
const relevantPubkeys = pubkeys.filter((e) => e.networks && Array.isArray(e.networks) && e.networks.includes(networkId));
|
|
2587
2312
|
const segwitNetworks = [
|
|
2588
2313
|
"bip122:000000000019d6689c085ae165831e93"
|
|
2589
2314
|
];
|
|
2590
2315
|
const isSegwit = segwitNetworks.includes(networkId);
|
|
2591
2316
|
let chain = NetworkIdToChain[networkId];
|
|
2592
|
-
const
|
|
2593
|
-
console.log(`${tag5}: Using
|
|
2594
|
-
const changeXpub = relevantPubkeys.find((pk) => pk.scriptType === actualChangeScriptType)?.pubkey || relevantPubkeys.find((pk) => pk.scriptType === "p2wpkh")?.pubkey || relevantPubkeys[0].pubkey;
|
|
2595
|
-
console.log(`${tag5}: Change xpub selected for ${actualChangeScriptType}:`, changeXpub?.substring(0, 10) + "...");
|
|
2596
|
-
let changeAddressIndex = await pioneer.GetChangeAddress({
|
|
2597
|
-
network: chain,
|
|
2598
|
-
xpub: changeXpub
|
|
2599
|
-
});
|
|
2600
|
-
changeAddressIndex = changeAddressIndex.data.changeIndex;
|
|
2601
|
-
let bipPath;
|
|
2602
|
-
switch (actualChangeScriptType) {
|
|
2603
|
-
case "p2pkh":
|
|
2604
|
-
bipPath = `m/44'/0'/0'/1/${changeAddressIndex}`;
|
|
2605
|
-
break;
|
|
2606
|
-
case "p2sh-p2wpkh":
|
|
2607
|
-
bipPath = `m/49'/0'/0'/1/${changeAddressIndex}`;
|
|
2608
|
-
break;
|
|
2609
|
-
case "p2wpkh":
|
|
2610
|
-
default:
|
|
2611
|
-
bipPath = `m/84'/0'/0'/1/${changeAddressIndex}`;
|
|
2612
|
-
break;
|
|
2613
|
-
}
|
|
2614
|
-
const path = bipPath;
|
|
2615
|
-
console.log(`${tag5}: Change address path: ${path} (index: ${changeAddressIndex})`);
|
|
2616
|
-
const changeAddress = {
|
|
2617
|
-
path,
|
|
2618
|
-
isChange: true,
|
|
2619
|
-
index: changeAddressIndex,
|
|
2620
|
-
addressNList: bip32ToAddressNList2(path),
|
|
2621
|
-
scriptType: actualChangeScriptType
|
|
2622
|
-
};
|
|
2317
|
+
const coinType = getCoinTypeFromNetworkId(networkId);
|
|
2318
|
+
console.log(`${tag5}: Using SLIP-44 coin type ${coinType} for ${chain}`);
|
|
2623
2319
|
const utxos = [];
|
|
2624
2320
|
for (const pubkey of relevantPubkeys) {
|
|
2625
2321
|
try {
|
|
@@ -2645,6 +2341,48 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, ke
|
|
|
2645
2341
|
for (const utxo of utxos) {
|
|
2646
2342
|
utxo.value = Number(utxo.value);
|
|
2647
2343
|
}
|
|
2344
|
+
const inputScriptTypes = utxos.map((u) => u.scriptType).filter(Boolean);
|
|
2345
|
+
const scriptTypeCount = inputScriptTypes.reduce((acc, type) => {
|
|
2346
|
+
acc[type] = (acc[type] || 0) + 1;
|
|
2347
|
+
return acc;
|
|
2348
|
+
}, {});
|
|
2349
|
+
const mostCommonInputType = Object.entries(scriptTypeCount).sort(([, a2], [, b3]) => b3 - a2)[0]?.[0] || "p2pkh";
|
|
2350
|
+
const actualChangeScriptType = changeScriptType || mostCommonInputType || relevantPubkeys[0]?.scriptType || "p2pkh";
|
|
2351
|
+
console.log(`${tag5}: Input script types:`, scriptTypeCount);
|
|
2352
|
+
console.log(`${tag5}: Using change script type: ${actualChangeScriptType} (matches inputs: ${mostCommonInputType})`);
|
|
2353
|
+
const changeXpubInfo = relevantPubkeys.find((pk) => pk.scriptType === actualChangeScriptType);
|
|
2354
|
+
if (!changeXpubInfo) {
|
|
2355
|
+
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.`);
|
|
2356
|
+
}
|
|
2357
|
+
const changeXpub = changeXpubInfo.pubkey;
|
|
2358
|
+
console.log(`${tag5}: Change xpub selected for ${actualChangeScriptType}:`, changeXpub?.substring(0, 10) + "...");
|
|
2359
|
+
let changeAddressIndex = await pioneer.GetChangeAddress({
|
|
2360
|
+
network: chain,
|
|
2361
|
+
xpub: changeXpub
|
|
2362
|
+
});
|
|
2363
|
+
changeAddressIndex = changeAddressIndex.data.changeIndex;
|
|
2364
|
+
let bipPath;
|
|
2365
|
+
switch (actualChangeScriptType) {
|
|
2366
|
+
case "p2pkh":
|
|
2367
|
+
bipPath = `m/44'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2368
|
+
break;
|
|
2369
|
+
case "p2sh-p2wpkh":
|
|
2370
|
+
bipPath = `m/49'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2371
|
+
break;
|
|
2372
|
+
case "p2wpkh":
|
|
2373
|
+
default:
|
|
2374
|
+
bipPath = `m/84'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2375
|
+
break;
|
|
2376
|
+
}
|
|
2377
|
+
const path = bipPath;
|
|
2378
|
+
console.log(`${tag5}: Change address path: ${path} (coin type: ${coinType}, index: ${changeAddressIndex})`);
|
|
2379
|
+
const changeAddress = {
|
|
2380
|
+
path,
|
|
2381
|
+
isChange: true,
|
|
2382
|
+
index: changeAddressIndex,
|
|
2383
|
+
addressNList: bip32ToAddressNList2(path),
|
|
2384
|
+
scriptType: actualChangeScriptType
|
|
2385
|
+
};
|
|
2648
2386
|
let feeRateFromNode;
|
|
2649
2387
|
if (networkId === "bip122:00000000001a91e3dace36e2be3bf030") {
|
|
2650
2388
|
console.log(`${tag5}: Using hardcoded fees for DOGE (10 sat/byte)`);
|
|
@@ -2762,11 +2500,9 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, ke
|
|
|
2762
2500
|
})));
|
|
2763
2501
|
let result;
|
|
2764
2502
|
if (isMax) {
|
|
2765
|
-
|
|
2766
|
-
result = coinSelectSplit(utxos, [{ address: to }], effectiveFeeRate);
|
|
2503
|
+
result = import_split.default(utxos, [{ address: to }], effectiveFeeRate);
|
|
2767
2504
|
} else {
|
|
2768
|
-
|
|
2769
|
-
result = coinSelect(utxos, [{ address: to, value: amount }], effectiveFeeRate);
|
|
2505
|
+
result = import_coinselect.default(utxos, [{ address: to, value: amount }], effectiveFeeRate);
|
|
2770
2506
|
}
|
|
2771
2507
|
console.log(tag5, "coinSelect result object:", result);
|
|
2772
2508
|
console.log(tag5, "coinSelect result.inputs:", result?.inputs);
|
|
@@ -2883,6 +2619,7 @@ class TransactionManager {
|
|
|
2883
2619
|
assetContext;
|
|
2884
2620
|
balances;
|
|
2885
2621
|
pubkeys;
|
|
2622
|
+
pubkeyContext;
|
|
2886
2623
|
nodes;
|
|
2887
2624
|
pioneer;
|
|
2888
2625
|
keepKeySdk;
|
|
@@ -2892,6 +2629,7 @@ class TransactionManager {
|
|
|
2892
2629
|
this.assetContext = dependencies.assetContext;
|
|
2893
2630
|
this.balances = dependencies.balances;
|
|
2894
2631
|
this.pubkeys = dependencies.pubkeys;
|
|
2632
|
+
this.pubkeyContext = dependencies.pubkeyContext;
|
|
2895
2633
|
this.nodes = dependencies.nodes;
|
|
2896
2634
|
this.pioneer = dependencies.pioneer;
|
|
2897
2635
|
this.keepKeySdk = dependencies.keepKeySdk;
|
|
@@ -2925,20 +2663,20 @@ class TransactionManager {
|
|
|
2925
2663
|
let unsignedTx;
|
|
2926
2664
|
switch (type) {
|
|
2927
2665
|
case "UTXO": {
|
|
2928
|
-
unsignedTx = await createUnsignedUxtoTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2666
|
+
unsignedTx = await createUnsignedUxtoTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, feeLevel, changeScriptType);
|
|
2929
2667
|
break;
|
|
2930
2668
|
}
|
|
2931
2669
|
case "TENDERMINT": {
|
|
2932
2670
|
const txType = "transfer";
|
|
2933
|
-
unsignedTx = await createUnsignedTendermintTx(caip, txType, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2671
|
+
unsignedTx = await createUnsignedTendermintTx(caip, txType, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, to);
|
|
2934
2672
|
break;
|
|
2935
2673
|
}
|
|
2936
2674
|
case "EIP155": {
|
|
2937
|
-
unsignedTx = await createUnsignedEvmTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2675
|
+
unsignedTx = await createUnsignedEvmTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, feeLevel);
|
|
2938
2676
|
break;
|
|
2939
2677
|
}
|
|
2940
2678
|
case "OTHER": {
|
|
2941
|
-
unsignedTx = await createUnsignedRippleTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2679
|
+
unsignedTx = await createUnsignedRippleTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax);
|
|
2942
2680
|
break;
|
|
2943
2681
|
}
|
|
2944
2682
|
default: {
|
|
@@ -3037,9 +2775,20 @@ class TransactionManager {
|
|
|
3037
2775
|
}
|
|
3038
2776
|
case "cosmos:mayachain-mainnet-v1/slip44:931":
|
|
3039
2777
|
case "cosmos:mayachain-mainnet-v1/denom:maya": {
|
|
2778
|
+
console.log(tag5, "\uD83D\uDD0D ===== MAYACHAIN SIGNING AUDIT =====");
|
|
2779
|
+
console.log(tag5, "\uD83D\uDCCB unsignedTx:", JSON.stringify(unsignedTx, null, 2));
|
|
2780
|
+
console.log(tag5, "\uD83D\uDD11 unsignedTx.addressNList:", unsignedTx.addressNList);
|
|
2781
|
+
console.log(tag5, "\uD83D\uDCCD unsignedTx.signerAddress:", unsignedTx.signerAddress);
|
|
2782
|
+
console.log(tag5, "\uD83C\uDF10 pubkeyContext:", this.pubkeyContext);
|
|
2783
|
+
console.log(tag5, "\uD83D\uDD10 pubkeyContext.addressNList:", this.pubkeyContext?.addressNList);
|
|
2784
|
+
console.log(tag5, "\uD83D\uDD10 pubkeyContext.addressNListMaster:", this.pubkeyContext?.addressNListMaster);
|
|
2785
|
+
console.log(tag5, "\uD83D\uDCEC pubkeyContext.address:", this.pubkeyContext?.address);
|
|
2786
|
+
console.log(tag5, "=======================================");
|
|
3040
2787
|
if (unsignedTx.signDoc.msgs[0].type === "mayachain/MsgSend") {
|
|
3041
2788
|
const responseSign = await this.keepKeySdk.mayachain.mayachainSignAminoTransfer(unsignedTx);
|
|
3042
2789
|
signedTx = responseSign.serialized;
|
|
2790
|
+
console.log(tag5, "✅ Signing completed");
|
|
2791
|
+
console.log(tag5, "\uD83D\uDCE6 responseSign:", responseSign);
|
|
3043
2792
|
} else if (unsignedTx.signDoc.msgs[0].type === "mayachain/MsgDeposit") {
|
|
3044
2793
|
const responseSign = await this.keepKeySdk.mayachain.mayachainSignAminoDeposit(unsignedTx);
|
|
3045
2794
|
signedTx = responseSign.serialized;
|
|
@@ -3231,18 +2980,21 @@ var cosmosClaimAllRewardsTemplate = (params) => ({
|
|
|
3231
2980
|
|
|
3232
2981
|
// src/txbuilder/createUnsignedStakingTx.ts
|
|
3233
2982
|
var TAG5 = " | createUnsignedStakingTx | ";
|
|
3234
|
-
async function createUnsignedStakingTx(caip, params, pubkeys, pioneer,
|
|
2983
|
+
async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyContext) {
|
|
3235
2984
|
const tag5 = TAG5 + " | createUnsignedStakingTx | ";
|
|
3236
2985
|
try {
|
|
3237
2986
|
if (!pioneer)
|
|
3238
2987
|
throw new Error("Failed to init! pioneer");
|
|
3239
2988
|
const networkId = caipToNetworkId5(caip);
|
|
3240
|
-
if (!
|
|
3241
|
-
|
|
2989
|
+
if (!pubkeyContext) {
|
|
2990
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
3242
2991
|
}
|
|
3243
|
-
if (!
|
|
3244
|
-
throw new Error(`
|
|
2992
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2993
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
3245
2994
|
}
|
|
2995
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2996
|
+
address: pubkeyContext.address
|
|
2997
|
+
});
|
|
3246
2998
|
let chain;
|
|
3247
2999
|
let chainId;
|
|
3248
3000
|
let denom;
|
|
@@ -3273,7 +3025,7 @@ async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, keepKeySd
|
|
|
3273
3025
|
throw new Error(`Unsupported networkId for staking: ${networkId}`);
|
|
3274
3026
|
}
|
|
3275
3027
|
console.log(tag5, `Building ${params.type} transaction for ${chain}`);
|
|
3276
|
-
const fromAddress =
|
|
3028
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
3277
3029
|
const accountInfo = (await pioneer.GetAccountInfo({ network: chain, address: fromAddress })).data;
|
|
3278
3030
|
console.log(tag5, "accountInfo: ", accountInfo);
|
|
3279
3031
|
let account_number;
|
|
@@ -3396,6 +3148,12 @@ function getNetworkName(networkId) {
|
|
|
3396
3148
|
};
|
|
3397
3149
|
return networkNames[networkId] || networkId;
|
|
3398
3150
|
}
|
|
3151
|
+
function withTimeout(promise, timeoutMs) {
|
|
3152
|
+
return Promise.race([
|
|
3153
|
+
promise,
|
|
3154
|
+
new Promise((_2, reject) => setTimeout(() => reject(new Error("Request timeout")), timeoutMs))
|
|
3155
|
+
]);
|
|
3156
|
+
}
|
|
3399
3157
|
async function getFees(pioneer, networkId) {
|
|
3400
3158
|
const tag5 = TAG6 + " | getFees | ";
|
|
3401
3159
|
try {
|
|
@@ -3405,10 +3163,6 @@ async function getFees(pioneer, networkId) {
|
|
|
3405
3163
|
console.log(tag5, "Using hardcoded fees for Cosmos network:", networkId);
|
|
3406
3164
|
return getCosmosFees(networkId);
|
|
3407
3165
|
}
|
|
3408
|
-
if (networkType === "RIPPLE") {
|
|
3409
|
-
console.log(tag5, "Using hardcoded fees for Ripple:", networkId);
|
|
3410
|
-
return getRippleFees(networkId);
|
|
3411
|
-
}
|
|
3412
3166
|
if (networkId === "bip122:00000000001a91e3dace36e2be3bf030") {
|
|
3413
3167
|
console.log(tag5, "Using hardcoded fees for Dogecoin: 10 sat/byte");
|
|
3414
3168
|
return {
|
|
@@ -3441,15 +3195,51 @@ async function getFees(pioneer, networkId) {
|
|
|
3441
3195
|
raw: { hardcoded: true, reason: "DOGE fee estimation unreliable" }
|
|
3442
3196
|
};
|
|
3443
3197
|
}
|
|
3444
|
-
|
|
3198
|
+
let feeResponse;
|
|
3199
|
+
if (networkId === "bip122:000007d91d1254d60e2dd1ae58038307") {
|
|
3200
|
+
try {
|
|
3201
|
+
const apiCall = pioneer.GetFeeRateByNetwork ? pioneer.GetFeeRateByNetwork({ networkId }) : pioneer.GetFeeRate({ networkId });
|
|
3202
|
+
feeResponse = await withTimeout(apiCall, 3000);
|
|
3203
|
+
} catch (timeoutError) {
|
|
3204
|
+
console.warn(tag5, "Dash fee API timeout, using fallback fees");
|
|
3205
|
+
return {
|
|
3206
|
+
slow: {
|
|
3207
|
+
label: "Economy",
|
|
3208
|
+
value: "5",
|
|
3209
|
+
unit: "sat/byte",
|
|
3210
|
+
description: "Low priority - 30+ minutes",
|
|
3211
|
+
estimatedTime: "~30 minutes",
|
|
3212
|
+
priority: "low"
|
|
3213
|
+
},
|
|
3214
|
+
average: {
|
|
3215
|
+
label: "Standard",
|
|
3216
|
+
value: "8",
|
|
3217
|
+
unit: "sat/byte",
|
|
3218
|
+
description: "Normal priority - 10-30 minutes",
|
|
3219
|
+
estimatedTime: "~15 minutes",
|
|
3220
|
+
priority: "medium"
|
|
3221
|
+
},
|
|
3222
|
+
fastest: {
|
|
3223
|
+
label: "Priority",
|
|
3224
|
+
value: "10",
|
|
3225
|
+
unit: "sat/byte",
|
|
3226
|
+
description: "High priority - next block",
|
|
3227
|
+
estimatedTime: "~5 minutes",
|
|
3228
|
+
priority: "high"
|
|
3229
|
+
},
|
|
3230
|
+
networkId,
|
|
3231
|
+
networkType: "UTXO",
|
|
3232
|
+
raw: { hardcoded: true, reason: "Dash API timeout, using conservative fallback fees" }
|
|
3233
|
+
};
|
|
3234
|
+
}
|
|
3235
|
+
} else {
|
|
3236
|
+
feeResponse = await (pioneer.GetFeeRateByNetwork ? pioneer.GetFeeRateByNetwork({ networkId }) : pioneer.GetFeeRate({ networkId }));
|
|
3237
|
+
}
|
|
3445
3238
|
if (!feeResponse || !feeResponse.data) {
|
|
3446
3239
|
throw new Error(`No fee data returned for ${networkId}`);
|
|
3447
3240
|
}
|
|
3448
3241
|
const feeData = feeResponse.data;
|
|
3449
3242
|
console.log(tag5, "Raw fee data:", feeData);
|
|
3450
|
-
if (feeData.success === false || feeData.error) {
|
|
3451
|
-
throw new Error(feeData.error || `API error for ${networkId}`);
|
|
3452
|
-
}
|
|
3453
3243
|
const networkName = getNetworkName(networkId);
|
|
3454
3244
|
let normalizedFees = normalizeFeeData(feeData, networkType, networkName, networkId);
|
|
3455
3245
|
normalizedFees = ensureFeeDifferentiation(normalizedFees, networkType);
|
|
@@ -3655,7 +3445,7 @@ function getCosmosFees(networkId) {
|
|
|
3655
3445
|
const networkName = getNetworkName(networkId);
|
|
3656
3446
|
const cosmosFeesMap = {
|
|
3657
3447
|
"cosmos:thorchain-mainnet-v1": { base: 0.02, unit: "RUNE", denom: "rune" },
|
|
3658
|
-
"cosmos:mayachain-mainnet-v1": { base: 0.
|
|
3448
|
+
"cosmos:mayachain-mainnet-v1": { base: 0.5, unit: "CACAO", denom: "cacao" },
|
|
3659
3449
|
"cosmos:cosmoshub-4": { base: 0.005, unit: "ATOM", denom: "uatom" },
|
|
3660
3450
|
"cosmos:osmosis-1": { base: 0.035, unit: "OSMO", denom: "uosmo" }
|
|
3661
3451
|
};
|
|
@@ -3693,39 +3483,6 @@ function getCosmosFees(networkId) {
|
|
|
3693
3483
|
raw: { hardcoded: true, base: feeConfig.base, unit: feeConfig.unit, denom: feeConfig.denom }
|
|
3694
3484
|
};
|
|
3695
3485
|
}
|
|
3696
|
-
function getRippleFees(networkId) {
|
|
3697
|
-
const networkName = getNetworkName(networkId);
|
|
3698
|
-
const baseFee = "0.00001";
|
|
3699
|
-
return {
|
|
3700
|
-
slow: {
|
|
3701
|
-
label: "Standard",
|
|
3702
|
-
value: baseFee,
|
|
3703
|
-
unit: "XRP",
|
|
3704
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3705
|
-
estimatedTime: "~4 seconds",
|
|
3706
|
-
priority: "low"
|
|
3707
|
-
},
|
|
3708
|
-
average: {
|
|
3709
|
-
label: "Standard",
|
|
3710
|
-
value: baseFee,
|
|
3711
|
-
unit: "XRP",
|
|
3712
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3713
|
-
estimatedTime: "~4 seconds",
|
|
3714
|
-
priority: "medium"
|
|
3715
|
-
},
|
|
3716
|
-
fastest: {
|
|
3717
|
-
label: "Standard",
|
|
3718
|
-
value: baseFee,
|
|
3719
|
-
unit: "XRP",
|
|
3720
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3721
|
-
estimatedTime: "~4 seconds",
|
|
3722
|
-
priority: "high"
|
|
3723
|
-
},
|
|
3724
|
-
networkId,
|
|
3725
|
-
networkType: "RIPPLE",
|
|
3726
|
-
raw: { hardcoded: true, baseFee, reason: "Ripple uses fixed network fees" }
|
|
3727
|
-
};
|
|
3728
|
-
}
|
|
3729
3486
|
function getFallbackFees(networkId) {
|
|
3730
3487
|
const networkType = getNetworkType(networkId);
|
|
3731
3488
|
const networkName = getNetworkName(networkId);
|
|
@@ -3799,9 +3556,10 @@ function estimateTransactionFee(feeRate, unit, networkType, txSize) {
|
|
|
3799
3556
|
}
|
|
3800
3557
|
}
|
|
3801
3558
|
|
|
3802
|
-
// src/
|
|
3559
|
+
// src/index.ts
|
|
3560
|
+
var TAG7 = " | Pioneer-sdk | ";
|
|
3803
3561
|
async function detectKkApiAvailability(forceLocalhost) {
|
|
3804
|
-
const tag5 =
|
|
3562
|
+
const tag5 = `${TAG7} | detectKkApiAvailability | `;
|
|
3805
3563
|
try {
|
|
3806
3564
|
const isTauri = typeof window !== "undefined" && "__TAURI__" in window;
|
|
3807
3565
|
const isBrowser = typeof window !== "undefined";
|
|
@@ -3848,8 +3606,6 @@ async function detectKkApiAvailability(forceLocalhost) {
|
|
|
3848
3606
|
};
|
|
3849
3607
|
}
|
|
3850
3608
|
}
|
|
3851
|
-
|
|
3852
|
-
// src/utils/format-time.ts
|
|
3853
3609
|
function formatTime(durationMs) {
|
|
3854
3610
|
let seconds = Math.floor(durationMs / 1000 % 60);
|
|
3855
3611
|
let minutes = Math.floor(durationMs / (1000 * 60) % 60);
|
|
@@ -3863,150 +3619,6 @@ function formatTime(durationMs) {
|
|
|
3863
3619
|
return formatted.trim();
|
|
3864
3620
|
}
|
|
3865
3621
|
|
|
3866
|
-
// src/utils/build-dashboard.ts
|
|
3867
|
-
import { caipToNetworkId as caipToNetworkId6, networkIdToCaip } from "@pioneer-platform/pioneer-caip";
|
|
3868
|
-
var TAG7 = " | build-dashboard | ";
|
|
3869
|
-
function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
3870
|
-
console.log(TAG7, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3871
|
-
const dashboardData = {
|
|
3872
|
-
networks: [],
|
|
3873
|
-
totalValueUsd: 0,
|
|
3874
|
-
networkPercentages: []
|
|
3875
|
-
};
|
|
3876
|
-
let totalPortfolioValue = 0;
|
|
3877
|
-
const networksTemp = [];
|
|
3878
|
-
console.log(TAG7, "balances: ", balances);
|
|
3879
|
-
for (const blockchain of blockchains) {
|
|
3880
|
-
const filteredBalances = balances.filter((b3) => {
|
|
3881
|
-
const networkId = caipToNetworkId6(b3.caip);
|
|
3882
|
-
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
3883
|
-
});
|
|
3884
|
-
const balanceMap = new Map;
|
|
3885
|
-
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
3886
|
-
if (isBitcoin) {
|
|
3887
|
-
console.log(TAG7, "Bitcoin network detected - checking for duplicate balances");
|
|
3888
|
-
const bitcoinByValue = new Map;
|
|
3889
|
-
filteredBalances.forEach((balance) => {
|
|
3890
|
-
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
3891
|
-
if (!bitcoinByValue.has(valueKey)) {
|
|
3892
|
-
bitcoinByValue.set(valueKey, []);
|
|
3893
|
-
}
|
|
3894
|
-
bitcoinByValue.get(valueKey).push(balance);
|
|
3895
|
-
});
|
|
3896
|
-
for (const [valueKey, balances2] of bitcoinByValue.entries()) {
|
|
3897
|
-
if (balances2.length === 3 && parseFloat(balances2[0].valueUsd || "0") > 0) {
|
|
3898
|
-
console.log(TAG7, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
3899
|
-
const xpubBalance = balances2.find((b3) => b3.pubkey?.startsWith("xpub")) || balances2[0];
|
|
3900
|
-
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
3901
|
-
balanceMap.set(key, xpubBalance);
|
|
3902
|
-
} else {
|
|
3903
|
-
balances2.forEach((balance) => {
|
|
3904
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3905
|
-
balanceMap.set(key, balance);
|
|
3906
|
-
});
|
|
3907
|
-
}
|
|
3908
|
-
}
|
|
3909
|
-
} else {
|
|
3910
|
-
filteredBalances.forEach((balance) => {
|
|
3911
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3912
|
-
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
3913
|
-
balanceMap.set(key, balance);
|
|
3914
|
-
}
|
|
3915
|
-
});
|
|
3916
|
-
}
|
|
3917
|
-
const networkBalances = Array.from(balanceMap.values());
|
|
3918
|
-
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
3919
|
-
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
3920
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
3921
|
-
console.log(TAG7, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
3922
|
-
}
|
|
3923
|
-
return sum + valueUsd;
|
|
3924
|
-
}, 0);
|
|
3925
|
-
const nativeAssetCaip = networkIdToCaip(blockchain);
|
|
3926
|
-
const gasAsset = networkBalances.find((b3) => b3.caip === nativeAssetCaip);
|
|
3927
|
-
const totalNativeBalance = networkBalances.filter((b3) => b3.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
3928
|
-
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
3929
|
-
return sum + balanceNum;
|
|
3930
|
-
}, 0).toString();
|
|
3931
|
-
const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
|
|
3932
|
-
networksTemp.push({
|
|
3933
|
-
networkId: blockchain,
|
|
3934
|
-
totalValueUsd: networkTotal,
|
|
3935
|
-
gasAssetCaip: nativeAssetCaip || null,
|
|
3936
|
-
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
3937
|
-
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
3938
|
-
color: gasAsset?.color || assetInfo?.color || null,
|
|
3939
|
-
totalNativeBalance
|
|
3940
|
-
});
|
|
3941
|
-
totalPortfolioValue += networkTotal;
|
|
3942
|
-
}
|
|
3943
|
-
dashboardData.networks = networksTemp.sort((a2, b3) => b3.totalValueUsd - a2.totalValueUsd);
|
|
3944
|
-
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
3945
|
-
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
3946
|
-
networkId: network.networkId,
|
|
3947
|
-
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
3948
|
-
})).filter((entry) => entry.percentage > 0);
|
|
3949
|
-
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
3950
|
-
return dashboardData;
|
|
3951
|
-
}
|
|
3952
|
-
|
|
3953
|
-
// src/utils/pubkey-helpers.ts
|
|
3954
|
-
function getPubkeyKey(pubkey) {
|
|
3955
|
-
return `${pubkey.pubkey}_${pubkey.pathMaster}`;
|
|
3956
|
-
}
|
|
3957
|
-
function deduplicatePubkeys(pubkeys) {
|
|
3958
|
-
const seen = new Set;
|
|
3959
|
-
const deduped = pubkeys.filter((pubkey) => {
|
|
3960
|
-
const key = getPubkeyKey(pubkey);
|
|
3961
|
-
if (seen.has(key)) {
|
|
3962
|
-
return false;
|
|
3963
|
-
}
|
|
3964
|
-
seen.add(key);
|
|
3965
|
-
return true;
|
|
3966
|
-
});
|
|
3967
|
-
return deduped;
|
|
3968
|
-
}
|
|
3969
|
-
function validatePubkey(pubkey) {
|
|
3970
|
-
return !!(pubkey.pubkey && pubkey.pathMaster);
|
|
3971
|
-
}
|
|
3972
|
-
|
|
3973
|
-
class PubkeyManager {
|
|
3974
|
-
pubkeys = [];
|
|
3975
|
-
pubkeySet = new Set;
|
|
3976
|
-
addPubkey(pubkey) {
|
|
3977
|
-
if (!validatePubkey(pubkey)) {
|
|
3978
|
-
return false;
|
|
3979
|
-
}
|
|
3980
|
-
const key = getPubkeyKey(pubkey);
|
|
3981
|
-
if (this.pubkeySet.has(key)) {
|
|
3982
|
-
return false;
|
|
3983
|
-
}
|
|
3984
|
-
this.pubkeys.push(pubkey);
|
|
3985
|
-
this.pubkeySet.add(key);
|
|
3986
|
-
return true;
|
|
3987
|
-
}
|
|
3988
|
-
setPubkeys(newPubkeys) {
|
|
3989
|
-
this.pubkeys = [];
|
|
3990
|
-
this.pubkeySet.clear();
|
|
3991
|
-
let added = 0;
|
|
3992
|
-
for (const pubkey of newPubkeys) {
|
|
3993
|
-
if (this.addPubkey(pubkey)) {
|
|
3994
|
-
added++;
|
|
3995
|
-
}
|
|
3996
|
-
}
|
|
3997
|
-
}
|
|
3998
|
-
getPubkeys() {
|
|
3999
|
-
return this.pubkeys;
|
|
4000
|
-
}
|
|
4001
|
-
clear() {
|
|
4002
|
-
this.pubkeys = [];
|
|
4003
|
-
this.pubkeySet.clear();
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
|
|
4007
|
-
// src/index.ts
|
|
4008
|
-
var TAG8 = " | Pioneer-sdk | ";
|
|
4009
|
-
|
|
4010
3622
|
class SDK {
|
|
4011
3623
|
status;
|
|
4012
3624
|
username;
|
|
@@ -4030,7 +3642,7 @@ class SDK {
|
|
|
4030
3642
|
charts;
|
|
4031
3643
|
paths;
|
|
4032
3644
|
pubkeys = [];
|
|
4033
|
-
|
|
3645
|
+
pubkeySet = new Set;
|
|
4034
3646
|
wallets;
|
|
4035
3647
|
balances;
|
|
4036
3648
|
nodes;
|
|
@@ -4107,11 +3719,10 @@ class SDK {
|
|
|
4107
3719
|
if (config.blockchains && config.blockchains.length !== this.blockchains.length) {
|
|
4108
3720
|
}
|
|
4109
3721
|
if (config.pubkeys && config.pubkeys.length > 0) {
|
|
4110
|
-
this.
|
|
4111
|
-
this.pubkeys = this.pubkeyManager.getPubkeys();
|
|
3722
|
+
this.setPubkeys(config.pubkeys);
|
|
4112
3723
|
} else {
|
|
4113
3724
|
this.pubkeys = [];
|
|
4114
|
-
this.
|
|
3725
|
+
this.pubkeySet.clear();
|
|
4115
3726
|
}
|
|
4116
3727
|
this.balances = config.balances || [];
|
|
4117
3728
|
this.nodes = config.nodes || [];
|
|
@@ -4127,7 +3738,7 @@ class SDK {
|
|
|
4127
3738
|
this.outboundBlockchainContext = null;
|
|
4128
3739
|
this.outboundPubkeyContext = null;
|
|
4129
3740
|
this.wallets = [];
|
|
4130
|
-
this.events = new
|
|
3741
|
+
this.events = new A;
|
|
4131
3742
|
this.transactions = null;
|
|
4132
3743
|
this.ethplorerApiKey = config.ethplorerApiKey;
|
|
4133
3744
|
this.covalentApiKey = config.covalentApiKey;
|
|
@@ -4142,21 +3753,46 @@ class SDK {
|
|
|
4142
3753
|
this.pairWallet = async (options) => {
|
|
4143
3754
|
return Promise.resolve({});
|
|
4144
3755
|
};
|
|
4145
|
-
this.getPubkeyKey =
|
|
4146
|
-
|
|
3756
|
+
this.getPubkeyKey = (pubkey) => {
|
|
3757
|
+
return `${pubkey.pubkey}_${pubkey.pathMaster}`;
|
|
3758
|
+
};
|
|
3759
|
+
this.deduplicatePubkeys = (pubkeys) => {
|
|
3760
|
+
const seen = new Set;
|
|
3761
|
+
const deduped = pubkeys.filter((pubkey) => {
|
|
3762
|
+
const key = this.getPubkeyKey(pubkey);
|
|
3763
|
+
if (seen.has(key)) {
|
|
3764
|
+
return false;
|
|
3765
|
+
}
|
|
3766
|
+
seen.add(key);
|
|
3767
|
+
return true;
|
|
3768
|
+
});
|
|
3769
|
+
return deduped;
|
|
3770
|
+
};
|
|
4147
3771
|
this.addPubkey = (pubkey) => {
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
3772
|
+
if (!pubkey.pubkey || !pubkey.pathMaster) {
|
|
3773
|
+
return false;
|
|
3774
|
+
}
|
|
3775
|
+
const key = this.getPubkeyKey(pubkey);
|
|
3776
|
+
if (this.pubkeySet.has(key)) {
|
|
3777
|
+
return false;
|
|
4151
3778
|
}
|
|
4152
|
-
|
|
3779
|
+
this.pubkeys.push(pubkey);
|
|
3780
|
+
this.pubkeySet.add(key);
|
|
3781
|
+
return true;
|
|
4153
3782
|
};
|
|
4154
3783
|
this.setPubkeys = (newPubkeys) => {
|
|
4155
|
-
|
|
4156
|
-
this.pubkeys =
|
|
3784
|
+
const tag5 = `${TAG7} | setPubkeys | `;
|
|
3785
|
+
this.pubkeys = [];
|
|
3786
|
+
this.pubkeySet.clear();
|
|
3787
|
+
let added = 0;
|
|
3788
|
+
for (const pubkey of newPubkeys) {
|
|
3789
|
+
if (this.addPubkey(pubkey)) {
|
|
3790
|
+
added++;
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
4157
3793
|
};
|
|
4158
3794
|
this.getUnifiedPortfolio = async function() {
|
|
4159
|
-
const tag5 = `${
|
|
3795
|
+
const tag5 = `${TAG7} | getUnifiedPortfolio | `;
|
|
4160
3796
|
try {
|
|
4161
3797
|
const startTime = performance.now();
|
|
4162
3798
|
try {
|
|
@@ -4188,9 +3824,8 @@ class SDK {
|
|
|
4188
3824
|
this.events.emit("SET_BALANCES", this.balances);
|
|
4189
3825
|
}
|
|
4190
3826
|
if (portfolioData.pubkeys && portfolioData.pubkeys.length > 0) {
|
|
4191
|
-
const convertedPubkeys = portfolioData.pubkeys;
|
|
4192
|
-
this.
|
|
4193
|
-
this.pubkeys = this.pubkeyManager.getPubkeys();
|
|
3827
|
+
const convertedPubkeys = this.convertVaultPubkeysToPioneerFormat(portfolioData.pubkeys);
|
|
3828
|
+
this.setPubkeys(convertedPubkeys);
|
|
4194
3829
|
this.events.emit("SET_PUBKEYS", this.pubkeys);
|
|
4195
3830
|
}
|
|
4196
3831
|
if (portfolioData.devices && portfolioData.devices.length > 0) {
|
|
@@ -4240,7 +3875,7 @@ class SDK {
|
|
|
4240
3875
|
this.events.emit("SET_DASHBOARD", this.dashboard);
|
|
4241
3876
|
} else {
|
|
4242
3877
|
console.warn("[CACHE VALIDATION] ❌ Cache data corrupted, building dashboard from cached balances");
|
|
4243
|
-
const dashboardData = buildDashboardFromBalances(
|
|
3878
|
+
const dashboardData = this.buildDashboardFromBalances();
|
|
4244
3879
|
this.dashboard = dashboardData;
|
|
4245
3880
|
this.events.emit("SET_DASHBOARD", this.dashboard);
|
|
4246
3881
|
}
|
|
@@ -4265,7 +3900,7 @@ class SDK {
|
|
|
4265
3900
|
}
|
|
4266
3901
|
};
|
|
4267
3902
|
this.init = async function(walletsVerbose, setup) {
|
|
4268
|
-
const tag5 = `${
|
|
3903
|
+
const tag5 = `${TAG7} | init | `;
|
|
4269
3904
|
try {
|
|
4270
3905
|
if (!this.username)
|
|
4271
3906
|
throw Error("username required!");
|
|
@@ -4282,7 +3917,7 @@ class SDK {
|
|
|
4282
3917
|
const pioneerConfig = {
|
|
4283
3918
|
...config
|
|
4284
3919
|
};
|
|
4285
|
-
const PioneerClient = new
|
|
3920
|
+
const PioneerClient = new Pioneer(this.spec, pioneerConfig);
|
|
4286
3921
|
this.pioneer = await PioneerClient.init();
|
|
4287
3922
|
if (!this.pioneer)
|
|
4288
3923
|
throw Error("Failed to init pioneer server!");
|
|
@@ -4352,11 +3987,92 @@ class SDK {
|
|
|
4352
3987
|
throw e;
|
|
4353
3988
|
}
|
|
4354
3989
|
};
|
|
4355
|
-
this.buildDashboardFromBalances = ()
|
|
4356
|
-
|
|
3990
|
+
this.buildDashboardFromBalances = function() {
|
|
3991
|
+
const tag5 = `${TAG7} | buildDashboardFromBalances | `;
|
|
3992
|
+
console.log(tag5, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3993
|
+
const dashboardData = {
|
|
3994
|
+
networks: [],
|
|
3995
|
+
totalValueUsd: 0,
|
|
3996
|
+
networkPercentages: []
|
|
3997
|
+
};
|
|
3998
|
+
let totalPortfolioValue = 0;
|
|
3999
|
+
const networksTemp = [];
|
|
4000
|
+
console.log(tag5, "this.balances: ", this.balances);
|
|
4001
|
+
for (const blockchain of this.blockchains) {
|
|
4002
|
+
const filteredBalances = this.balances.filter((b3) => {
|
|
4003
|
+
const networkId = caipToNetworkId6(b3.caip);
|
|
4004
|
+
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4005
|
+
});
|
|
4006
|
+
const balanceMap = new Map;
|
|
4007
|
+
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
4008
|
+
if (isBitcoin) {
|
|
4009
|
+
console.log(tag5, "Bitcoin network detected - checking for duplicate balances");
|
|
4010
|
+
const bitcoinByValue = new Map;
|
|
4011
|
+
filteredBalances.forEach((balance) => {
|
|
4012
|
+
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
4013
|
+
if (!bitcoinByValue.has(valueKey)) {
|
|
4014
|
+
bitcoinByValue.set(valueKey, []);
|
|
4015
|
+
}
|
|
4016
|
+
bitcoinByValue.get(valueKey).push(balance);
|
|
4017
|
+
});
|
|
4018
|
+
for (const [valueKey, balances] of bitcoinByValue.entries()) {
|
|
4019
|
+
if (balances.length === 3 && parseFloat(balances[0].valueUsd || "0") > 0) {
|
|
4020
|
+
console.log(tag5, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
4021
|
+
const xpubBalance = balances.find((b3) => b3.pubkey?.startsWith("xpub")) || balances[0];
|
|
4022
|
+
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
4023
|
+
balanceMap.set(key, xpubBalance);
|
|
4024
|
+
} else {
|
|
4025
|
+
balances.forEach((balance) => {
|
|
4026
|
+
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
4027
|
+
balanceMap.set(key, balance);
|
|
4028
|
+
});
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
} else {
|
|
4032
|
+
filteredBalances.forEach((balance) => {
|
|
4033
|
+
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
4034
|
+
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
4035
|
+
balanceMap.set(key, balance);
|
|
4036
|
+
}
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
4039
|
+
const networkBalances = Array.from(balanceMap.values());
|
|
4040
|
+
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
4041
|
+
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
4042
|
+
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
4043
|
+
console.log(tag5, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
4044
|
+
}
|
|
4045
|
+
return sum + valueUsd;
|
|
4046
|
+
}, 0);
|
|
4047
|
+
const nativeAssetCaip = networkIdToCaip(blockchain);
|
|
4048
|
+
const gasAsset = networkBalances.find((b3) => b3.caip === nativeAssetCaip);
|
|
4049
|
+
const totalNativeBalance = networkBalances.filter((b3) => b3.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4050
|
+
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
4051
|
+
return sum + balanceNum;
|
|
4052
|
+
}, 0).toString();
|
|
4053
|
+
const assetInfo = nativeAssetCaip ? this.assetsMap.get(nativeAssetCaip) : null;
|
|
4054
|
+
networksTemp.push({
|
|
4055
|
+
networkId: blockchain,
|
|
4056
|
+
totalValueUsd: networkTotal,
|
|
4057
|
+
gasAssetCaip: nativeAssetCaip || null,
|
|
4058
|
+
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
4059
|
+
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
4060
|
+
color: gasAsset?.color || assetInfo?.color || null,
|
|
4061
|
+
totalNativeBalance
|
|
4062
|
+
});
|
|
4063
|
+
totalPortfolioValue += networkTotal;
|
|
4064
|
+
}
|
|
4065
|
+
dashboardData.networks = networksTemp.sort((a2, b3) => b3.totalValueUsd - a2.totalValueUsd);
|
|
4066
|
+
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
4067
|
+
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
4068
|
+
networkId: network.networkId,
|
|
4069
|
+
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
4070
|
+
})).filter((entry) => entry.percentage > 0);
|
|
4071
|
+
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
4072
|
+
return dashboardData;
|
|
4357
4073
|
};
|
|
4358
4074
|
this.syncMarket = async function() {
|
|
4359
|
-
const tag5 = `${
|
|
4075
|
+
const tag5 = `${TAG7} | syncMarket | `;
|
|
4360
4076
|
try {
|
|
4361
4077
|
const invalidBalances = this.balances.filter((b3) => !b3 || !b3.caip || typeof b3.caip !== "string" || !b3.caip.includes(":"));
|
|
4362
4078
|
if (invalidBalances.length > 0) {
|
|
@@ -4407,7 +4123,7 @@ class SDK {
|
|
|
4407
4123
|
}
|
|
4408
4124
|
};
|
|
4409
4125
|
this.sync = async function() {
|
|
4410
|
-
const tag5 = `${
|
|
4126
|
+
const tag5 = `${TAG7} | sync | `;
|
|
4411
4127
|
try {
|
|
4412
4128
|
const matchesNetwork = (item, networkId) => {
|
|
4413
4129
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4462,7 +4178,7 @@ class SDK {
|
|
|
4462
4178
|
console.log(tag5, "uniqueBlockchains: ", uniqueBlockchains);
|
|
4463
4179
|
for (const blockchain of uniqueBlockchains) {
|
|
4464
4180
|
const filteredBalances = this.balances.filter((b3) => {
|
|
4465
|
-
const networkId =
|
|
4181
|
+
const networkId = caipToNetworkId6(b3.caip);
|
|
4466
4182
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4467
4183
|
});
|
|
4468
4184
|
console.log(tag5, `Filtering for blockchain: ${blockchain}`);
|
|
@@ -4520,7 +4236,7 @@ class SDK {
|
|
|
4520
4236
|
return sum + valueUsd;
|
|
4521
4237
|
}, 0);
|
|
4522
4238
|
console.log("Final networkTotal:", networkTotal);
|
|
4523
|
-
const nativeAssetCaip =
|
|
4239
|
+
const nativeAssetCaip = networkIdToCaip(blockchain);
|
|
4524
4240
|
const gasAsset = networkBalances.find((b3) => b3.caip === nativeAssetCaip);
|
|
4525
4241
|
const totalNativeBalance = networkBalances.filter((b3) => b3.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4526
4242
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
@@ -4560,7 +4276,7 @@ class SDK {
|
|
|
4560
4276
|
}
|
|
4561
4277
|
};
|
|
4562
4278
|
this.buildTx = async function(sendPayload) {
|
|
4563
|
-
let tag5 =
|
|
4279
|
+
let tag5 = TAG7 + " | buildTx | ";
|
|
4564
4280
|
try {
|
|
4565
4281
|
const transactionDependencies = {
|
|
4566
4282
|
context: this.context,
|
|
@@ -4568,6 +4284,7 @@ class SDK {
|
|
|
4568
4284
|
balances: this.balances,
|
|
4569
4285
|
pioneer: this.pioneer,
|
|
4570
4286
|
pubkeys: this.pubkeys,
|
|
4287
|
+
pubkeyContext: this.pubkeyContext,
|
|
4571
4288
|
nodes: this.nodes,
|
|
4572
4289
|
keepKeySdk: this.keepKeySdk
|
|
4573
4290
|
};
|
|
@@ -4581,13 +4298,13 @@ class SDK {
|
|
|
4581
4298
|
}
|
|
4582
4299
|
};
|
|
4583
4300
|
this.buildDelegateTx = async function(caip, params) {
|
|
4584
|
-
let tag5 =
|
|
4301
|
+
let tag5 = TAG7 + " | buildDelegateTx | ";
|
|
4585
4302
|
try {
|
|
4586
4303
|
const delegateParams = {
|
|
4587
4304
|
...params,
|
|
4588
4305
|
type: "delegate"
|
|
4589
4306
|
};
|
|
4590
|
-
let unsignedTx = await createUnsignedStakingTx(caip, delegateParams, this.pubkeys, this.pioneer, this.
|
|
4307
|
+
let unsignedTx = await createUnsignedStakingTx(caip, delegateParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4591
4308
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4592
4309
|
return unsignedTx;
|
|
4593
4310
|
} catch (e) {
|
|
@@ -4596,13 +4313,13 @@ class SDK {
|
|
|
4596
4313
|
}
|
|
4597
4314
|
};
|
|
4598
4315
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4599
|
-
let tag5 =
|
|
4316
|
+
let tag5 = TAG7 + " | buildUndelegateTx | ";
|
|
4600
4317
|
try {
|
|
4601
4318
|
const undelegateParams = {
|
|
4602
4319
|
...params,
|
|
4603
4320
|
type: "undelegate"
|
|
4604
4321
|
};
|
|
4605
|
-
let unsignedTx = await createUnsignedStakingTx(caip, undelegateParams, this.pubkeys, this.pioneer, this.
|
|
4322
|
+
let unsignedTx = await createUnsignedStakingTx(caip, undelegateParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4606
4323
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4607
4324
|
return unsignedTx;
|
|
4608
4325
|
} catch (e) {
|
|
@@ -4611,13 +4328,13 @@ class SDK {
|
|
|
4611
4328
|
}
|
|
4612
4329
|
};
|
|
4613
4330
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4614
|
-
let tag5 =
|
|
4331
|
+
let tag5 = TAG7 + " | buildClaimRewardsTx | ";
|
|
4615
4332
|
try {
|
|
4616
4333
|
const claimParams = {
|
|
4617
4334
|
...params,
|
|
4618
4335
|
type: "claim_rewards"
|
|
4619
4336
|
};
|
|
4620
|
-
let unsignedTx = await createUnsignedStakingTx(caip, claimParams, this.pubkeys, this.pioneer, this.
|
|
4337
|
+
let unsignedTx = await createUnsignedStakingTx(caip, claimParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4621
4338
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4622
4339
|
return unsignedTx;
|
|
4623
4340
|
} catch (e) {
|
|
@@ -4626,13 +4343,13 @@ class SDK {
|
|
|
4626
4343
|
}
|
|
4627
4344
|
};
|
|
4628
4345
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4629
|
-
let tag5 =
|
|
4346
|
+
let tag5 = TAG7 + " | buildClaimAllRewardsTx | ";
|
|
4630
4347
|
try {
|
|
4631
4348
|
const claimAllParams = {
|
|
4632
4349
|
...params,
|
|
4633
4350
|
type: "claim_all_rewards"
|
|
4634
4351
|
};
|
|
4635
|
-
let unsignedTx = await createUnsignedStakingTx(caip, claimAllParams, this.pubkeys, this.pioneer, this.
|
|
4352
|
+
let unsignedTx = await createUnsignedStakingTx(caip, claimAllParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4636
4353
|
return unsignedTx;
|
|
4637
4354
|
} catch (e) {
|
|
4638
4355
|
console.error(e);
|
|
@@ -4640,7 +4357,7 @@ class SDK {
|
|
|
4640
4357
|
}
|
|
4641
4358
|
};
|
|
4642
4359
|
this.signTx = async function(unsignedTx) {
|
|
4643
|
-
let tag5 =
|
|
4360
|
+
let tag5 = TAG7 + " | signTx | ";
|
|
4644
4361
|
try {
|
|
4645
4362
|
const transactionDependencies = {
|
|
4646
4363
|
context: this.context,
|
|
@@ -4648,6 +4365,7 @@ class SDK {
|
|
|
4648
4365
|
balances: this.balances,
|
|
4649
4366
|
pioneer: this.pioneer,
|
|
4650
4367
|
pubkeys: this.pubkeys,
|
|
4368
|
+
pubkeyContext: this.pubkeyContext,
|
|
4651
4369
|
nodes: this.nodes,
|
|
4652
4370
|
keepKeySdk: this.keepKeySdk
|
|
4653
4371
|
};
|
|
@@ -4660,7 +4378,7 @@ class SDK {
|
|
|
4660
4378
|
}
|
|
4661
4379
|
};
|
|
4662
4380
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4663
|
-
let tag5 =
|
|
4381
|
+
let tag5 = TAG7 + " | broadcastTx | ";
|
|
4664
4382
|
try {
|
|
4665
4383
|
const transactionDependencies = {
|
|
4666
4384
|
context: this.context,
|
|
@@ -4673,7 +4391,7 @@ class SDK {
|
|
|
4673
4391
|
};
|
|
4674
4392
|
let txManager = new TransactionManager(transactionDependencies, this.events);
|
|
4675
4393
|
let payload = {
|
|
4676
|
-
networkId:
|
|
4394
|
+
networkId: caipToNetworkId6(caip),
|
|
4677
4395
|
serialized: signedTx
|
|
4678
4396
|
};
|
|
4679
4397
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4684,7 +4402,7 @@ class SDK {
|
|
|
4684
4402
|
}
|
|
4685
4403
|
};
|
|
4686
4404
|
this.swap = async function(swapPayload) {
|
|
4687
|
-
let tag5 = `${
|
|
4405
|
+
let tag5 = `${TAG7} | swap | `;
|
|
4688
4406
|
try {
|
|
4689
4407
|
if (!swapPayload)
|
|
4690
4408
|
throw Error("swapPayload required!");
|
|
@@ -4819,7 +4537,7 @@ class SDK {
|
|
|
4819
4537
|
}
|
|
4820
4538
|
};
|
|
4821
4539
|
this.transfer = async function(sendPayload) {
|
|
4822
|
-
let tag5 = `${
|
|
4540
|
+
let tag5 = `${TAG7} | transfer | `;
|
|
4823
4541
|
try {
|
|
4824
4542
|
if (!sendPayload)
|
|
4825
4543
|
throw Error("sendPayload required!");
|
|
@@ -4846,7 +4564,7 @@ class SDK {
|
|
|
4846
4564
|
if (!signedTx)
|
|
4847
4565
|
throw Error("Failed to sign transaction!");
|
|
4848
4566
|
let payload = {
|
|
4849
|
-
networkId:
|
|
4567
|
+
networkId: caipToNetworkId6(caip),
|
|
4850
4568
|
serialized: signedTx
|
|
4851
4569
|
};
|
|
4852
4570
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4875,7 +4593,7 @@ class SDK {
|
|
|
4875
4593
|
while (!isConfirmed) {
|
|
4876
4594
|
try {
|
|
4877
4595
|
const response = await this.pioneer.LookupTx({
|
|
4878
|
-
networkId:
|
|
4596
|
+
networkId: caipToNetworkId6(caip),
|
|
4879
4597
|
txid
|
|
4880
4598
|
});
|
|
4881
4599
|
if (response?.data?.data) {
|
|
@@ -4914,7 +4632,7 @@ class SDK {
|
|
|
4914
4632
|
}
|
|
4915
4633
|
};
|
|
4916
4634
|
this.setBlockchains = async function(blockchains) {
|
|
4917
|
-
const tag5 = `${
|
|
4635
|
+
const tag5 = `${TAG7} | setBlockchains | `;
|
|
4918
4636
|
try {
|
|
4919
4637
|
if (!blockchains)
|
|
4920
4638
|
throw Error("blockchains required!");
|
|
@@ -4930,7 +4648,7 @@ class SDK {
|
|
|
4930
4648
|
}
|
|
4931
4649
|
};
|
|
4932
4650
|
this.addAsset = async function(caip, data) {
|
|
4933
|
-
let tag5 =
|
|
4651
|
+
let tag5 = TAG7 + " | addAsset | ";
|
|
4934
4652
|
try {
|
|
4935
4653
|
let success = false;
|
|
4936
4654
|
if (!caip)
|
|
@@ -4968,7 +4686,7 @@ class SDK {
|
|
|
4968
4686
|
}
|
|
4969
4687
|
};
|
|
4970
4688
|
this.clearWalletState = async function() {
|
|
4971
|
-
const tag5 = `${
|
|
4689
|
+
const tag5 = `${TAG7} | clearWalletState | `;
|
|
4972
4690
|
try {
|
|
4973
4691
|
this.context = null;
|
|
4974
4692
|
this.paths = [];
|
|
@@ -4982,15 +4700,62 @@ class SDK {
|
|
|
4982
4700
|
throw e;
|
|
4983
4701
|
}
|
|
4984
4702
|
};
|
|
4703
|
+
this.addPath = async function(path) {
|
|
4704
|
+
const tag5 = `${TAG7} | addPath | `;
|
|
4705
|
+
try {
|
|
4706
|
+
this.paths.push(path);
|
|
4707
|
+
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
4708
|
+
this.addPubkey(pubkey);
|
|
4709
|
+
await this.getBalancesForNetworks(path.networks);
|
|
4710
|
+
this.buildDashboardFromBalances();
|
|
4711
|
+
return { success: true, pubkey };
|
|
4712
|
+
} catch (e) {
|
|
4713
|
+
console.error(tag5, "Failed:", e);
|
|
4714
|
+
throw e;
|
|
4715
|
+
}
|
|
4716
|
+
};
|
|
4717
|
+
this.addPaths = async function(paths) {
|
|
4718
|
+
const tag5 = `${TAG7} | addPaths | `;
|
|
4719
|
+
try {
|
|
4720
|
+
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4721
|
+
this.paths.push(...paths);
|
|
4722
|
+
const newPubkeys = [];
|
|
4723
|
+
for (const path of paths) {
|
|
4724
|
+
try {
|
|
4725
|
+
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
4726
|
+
this.addPubkey(pubkey);
|
|
4727
|
+
newPubkeys.push(pubkey);
|
|
4728
|
+
} catch (error) {
|
|
4729
|
+
console.warn(tag5, `Failed to get pubkey for path ${path.note}:`, error.message);
|
|
4730
|
+
}
|
|
4731
|
+
}
|
|
4732
|
+
console.log(tag5, `Successfully added ${newPubkeys.length} pubkeys`);
|
|
4733
|
+
const networkSet = new Set;
|
|
4734
|
+
for (const path of paths) {
|
|
4735
|
+
if (path.networks && Array.isArray(path.networks)) {
|
|
4736
|
+
path.networks.forEach((net) => networkSet.add(net));
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
const uniqueNetworks = [...networkSet];
|
|
4740
|
+
console.log(tag5, `Fetching balances for ${uniqueNetworks.length} unique networks in single API call...`);
|
|
4741
|
+
await this.getBalancesForNetworks(uniqueNetworks);
|
|
4742
|
+
this.buildDashboardFromBalances();
|
|
4743
|
+
console.log(tag5, `Batch add complete: ${paths.length} paths, ${newPubkeys.length} pubkeys, ${this.balances?.length || 0} balances`);
|
|
4744
|
+
return { success: true, pubkeys: newPubkeys };
|
|
4745
|
+
} catch (e) {
|
|
4746
|
+
console.error(tag5, "Failed:", e);
|
|
4747
|
+
throw e;
|
|
4748
|
+
}
|
|
4749
|
+
};
|
|
4985
4750
|
this.getAssets = async function() {
|
|
4986
4751
|
return this.getGasAssets();
|
|
4987
4752
|
};
|
|
4988
4753
|
this.getGasAssets = async function() {
|
|
4989
|
-
const tag5 = `${
|
|
4754
|
+
const tag5 = `${TAG7} | getGasAssets | `;
|
|
4990
4755
|
try {
|
|
4991
4756
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4992
4757
|
let networkId = this.blockchains[i];
|
|
4993
|
-
let caip =
|
|
4758
|
+
let caip = networkIdToCaip(networkId);
|
|
4994
4759
|
let asset = await assetData2[caip.toLowerCase()];
|
|
4995
4760
|
if (asset) {
|
|
4996
4761
|
asset.caip = caip.toLowerCase();
|
|
@@ -5029,7 +4794,7 @@ class SDK {
|
|
|
5029
4794
|
}
|
|
5030
4795
|
};
|
|
5031
4796
|
this.getPubkeys = async function() {
|
|
5032
|
-
const tag5 = `${
|
|
4797
|
+
const tag5 = `${TAG7} | getPubkeys | `;
|
|
5033
4798
|
try {
|
|
5034
4799
|
if (this.paths.length === 0)
|
|
5035
4800
|
throw new Error("No paths found!");
|
|
@@ -5050,7 +4815,7 @@ class SDK {
|
|
|
5050
4815
|
}
|
|
5051
4816
|
};
|
|
5052
4817
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
5053
|
-
const tag5 = `${
|
|
4818
|
+
const tag5 = `${TAG7} | getBalancesForNetworks | `;
|
|
5054
4819
|
try {
|
|
5055
4820
|
if (!this.pioneer) {
|
|
5056
4821
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -5068,7 +4833,7 @@ class SDK {
|
|
|
5068
4833
|
return network.startsWith("eip155:");
|
|
5069
4834
|
return network === adjustedNetworkId;
|
|
5070
4835
|
}));
|
|
5071
|
-
const caipNative = await
|
|
4836
|
+
const caipNative = await networkIdToCaip(networkId);
|
|
5072
4837
|
for (const pubkey of pubkeys) {
|
|
5073
4838
|
assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
|
|
5074
4839
|
}
|
|
@@ -5077,14 +4842,6 @@ class SDK {
|
|
|
5077
4842
|
try {
|
|
5078
4843
|
let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
|
|
5079
4844
|
console.timeEnd("GetPortfolioBalances Response Time");
|
|
5080
|
-
if (!marketInfo || !marketInfo.data) {
|
|
5081
|
-
console.error(tag5, "Invalid response structure:", marketInfo);
|
|
5082
|
-
throw new Error("GetPortfolioBalances returned invalid response: missing data field");
|
|
5083
|
-
}
|
|
5084
|
-
if (!Array.isArray(marketInfo.data)) {
|
|
5085
|
-
console.error(tag5, "GetPortfolioBalances returned non-array data:", typeof marketInfo.data, marketInfo.data);
|
|
5086
|
-
throw new Error(`GetPortfolioBalances returned invalid data type: expected array, got ${typeof marketInfo.data}`);
|
|
5087
|
-
}
|
|
5088
4845
|
let balances = marketInfo.data;
|
|
5089
4846
|
const bitcoinBalances = balances.filter((b3) => b3.caip === "bip122:000000000019d6689c085ae165831e93/slip44:0");
|
|
5090
4847
|
if (bitcoinBalances.length > 0) {
|
|
@@ -5094,7 +4851,7 @@ class SDK {
|
|
|
5094
4851
|
if (!assetInfo)
|
|
5095
4852
|
continue;
|
|
5096
4853
|
Object.assign(balance, assetInfo, {
|
|
5097
|
-
networkId:
|
|
4854
|
+
networkId: caipToNetworkId6(balance.caip),
|
|
5098
4855
|
icon: assetInfo.icon || "https://pioneers.dev/coins/etherum.png",
|
|
5099
4856
|
identifier: `${balance.caip}:${balance.pubkey}`
|
|
5100
4857
|
});
|
|
@@ -5113,7 +4870,7 @@ class SDK {
|
|
|
5113
4870
|
}
|
|
5114
4871
|
};
|
|
5115
4872
|
this.getBalances = async function() {
|
|
5116
|
-
const tag5 = `${
|
|
4873
|
+
const tag5 = `${TAG7} | getBalances | `;
|
|
5117
4874
|
try {
|
|
5118
4875
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
5119
4876
|
} catch (e) {
|
|
@@ -5122,10 +4879,10 @@ class SDK {
|
|
|
5122
4879
|
}
|
|
5123
4880
|
};
|
|
5124
4881
|
this.getBalance = async function(networkId) {
|
|
5125
|
-
const tag5 = `${
|
|
4882
|
+
const tag5 = `${TAG7} | getBalance | `;
|
|
5126
4883
|
try {
|
|
5127
4884
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
5128
|
-
const filtered = results.filter(async (b3) => b3.networkId === await
|
|
4885
|
+
const filtered = results.filter(async (b3) => b3.networkId === await networkIdToCaip(networkId));
|
|
5129
4886
|
return filtered;
|
|
5130
4887
|
} catch (e) {
|
|
5131
4888
|
console.error(tag5, "Error: ", e);
|
|
@@ -5133,7 +4890,7 @@ class SDK {
|
|
|
5133
4890
|
}
|
|
5134
4891
|
};
|
|
5135
4892
|
this.getFees = async function(networkId) {
|
|
5136
|
-
const tag5 = `${
|
|
4893
|
+
const tag5 = `${TAG7} | getFees | `;
|
|
5137
4894
|
try {
|
|
5138
4895
|
if (!this.pioneer) {
|
|
5139
4896
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -5148,7 +4905,7 @@ class SDK {
|
|
|
5148
4905
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
5149
4906
|
};
|
|
5150
4907
|
this.getCharts = async function() {
|
|
5151
|
-
const tag5 = `${
|
|
4908
|
+
const tag5 = `${TAG7} | getCharts | `;
|
|
5152
4909
|
try {
|
|
5153
4910
|
console.log(tag5, "Fetching charts");
|
|
5154
4911
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -5170,7 +4927,7 @@ class SDK {
|
|
|
5170
4927
|
}
|
|
5171
4928
|
};
|
|
5172
4929
|
this.setContext = async (context) => {
|
|
5173
|
-
const tag5 = `${
|
|
4930
|
+
const tag5 = `${TAG7} | setContext | `;
|
|
5174
4931
|
try {
|
|
5175
4932
|
if (!context)
|
|
5176
4933
|
throw Error("context required!");
|
|
@@ -5183,7 +4940,7 @@ class SDK {
|
|
|
5183
4940
|
}
|
|
5184
4941
|
};
|
|
5185
4942
|
this.setContextType = async (contextType) => {
|
|
5186
|
-
const tag5 = `${
|
|
4943
|
+
const tag5 = `${TAG7} | setContextType | `;
|
|
5187
4944
|
try {
|
|
5188
4945
|
if (!contextType)
|
|
5189
4946
|
throw Error("contextType required!");
|
|
@@ -5196,7 +4953,7 @@ class SDK {
|
|
|
5196
4953
|
}
|
|
5197
4954
|
};
|
|
5198
4955
|
this.refresh = async () => {
|
|
5199
|
-
const tag5 = `${
|
|
4956
|
+
const tag5 = `${TAG7} | refresh | `;
|
|
5200
4957
|
try {
|
|
5201
4958
|
await this.sync();
|
|
5202
4959
|
return this.balances;
|
|
@@ -5206,7 +4963,7 @@ class SDK {
|
|
|
5206
4963
|
}
|
|
5207
4964
|
};
|
|
5208
4965
|
this.setAssetContext = async function(asset) {
|
|
5209
|
-
const tag5 = `${
|
|
4966
|
+
const tag5 = `${TAG7} | setAssetContext | `;
|
|
5210
4967
|
try {
|
|
5211
4968
|
if (!asset) {
|
|
5212
4969
|
this.assetContext = null;
|
|
@@ -5215,7 +4972,7 @@ class SDK {
|
|
|
5215
4972
|
if (!asset.caip)
|
|
5216
4973
|
throw Error("Invalid Asset! missing caip!");
|
|
5217
4974
|
if (!asset.networkId)
|
|
5218
|
-
asset.networkId =
|
|
4975
|
+
asset.networkId = caipToNetworkId6(asset.caip);
|
|
5219
4976
|
if (!this.pubkeys || this.pubkeys.length === 0) {
|
|
5220
4977
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no pubkeys loaded. Please initialize wallet first.`;
|
|
5221
4978
|
console.error(tag5, errorMsg);
|
|
@@ -5323,7 +5080,7 @@ class SDK {
|
|
|
5323
5080
|
console.log(tag5, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
5324
5081
|
}
|
|
5325
5082
|
const assetBalances = this.balances.filter((b3) => b3.caip === asset.caip);
|
|
5326
|
-
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(
|
|
5083
|
+
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(caipToNetworkId6(asset.caip)) || caipToNetworkId6(asset.caip).includes("eip155") && p2.networks && Array.isArray(p2.networks) && p2.networks.some((n2) => n2.startsWith("eip155")));
|
|
5327
5084
|
const finalAssetContext = {
|
|
5328
5085
|
...assetInfo,
|
|
5329
5086
|
...asset,
|
|
@@ -5383,16 +5140,19 @@ class SDK {
|
|
|
5383
5140
|
}
|
|
5384
5141
|
}
|
|
5385
5142
|
if (asset.caip) {
|
|
5386
|
-
this.blockchainContext =
|
|
5143
|
+
this.blockchainContext = caipToNetworkId6(asset.caip);
|
|
5387
5144
|
} else if (asset.networkId) {
|
|
5388
5145
|
this.blockchainContext = asset.networkId;
|
|
5389
5146
|
}
|
|
5390
5147
|
if (assetPubkeys && assetPubkeys.length > 0) {
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5148
|
+
const networkId = caipToNetworkId6(asset.caip || asset.networkId);
|
|
5149
|
+
const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
|
|
5150
|
+
if (!this.pubkeyContext || !currentContextValid) {
|
|
5151
|
+
this.pubkeyContext = assetPubkeys[0];
|
|
5152
|
+
console.log(tag5, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
|
|
5153
|
+
} else {
|
|
5154
|
+
console.log(tag5, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
|
|
5394
5155
|
}
|
|
5395
|
-
console.log(tag5, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
|
|
5396
5156
|
}
|
|
5397
5157
|
this.events.emit("SET_ASSET_CONTEXT", this.assetContext);
|
|
5398
5158
|
return this.assetContext;
|
|
@@ -5402,7 +5162,7 @@ class SDK {
|
|
|
5402
5162
|
}
|
|
5403
5163
|
};
|
|
5404
5164
|
this.setPubkeyContext = async function(pubkey) {
|
|
5405
|
-
let tag5 = `${
|
|
5165
|
+
let tag5 = `${TAG7} | setPubkeyContext | `;
|
|
5406
5166
|
try {
|
|
5407
5167
|
if (!pubkey)
|
|
5408
5168
|
throw Error("pubkey is required");
|
|
@@ -5413,10 +5173,7 @@ class SDK {
|
|
|
5413
5173
|
console.warn(tag5, "Pubkey not found in current pubkeys array");
|
|
5414
5174
|
}
|
|
5415
5175
|
this.pubkeyContext = pubkey;
|
|
5416
|
-
|
|
5417
|
-
this.keepKeySdk.pubkeyContext = pubkey;
|
|
5418
|
-
}
|
|
5419
|
-
console.log(tag5, "Pubkey context set to:", pubkey.address || pubkey.pubkey, "note:", pubkey.note);
|
|
5176
|
+
console.log(tag5, "Pubkey context set to:", pubkey.address || pubkey.pubkey, "note:", pubkey.note, "addressNList:", pubkey.addressNList || pubkey.addressNListMaster);
|
|
5420
5177
|
return true;
|
|
5421
5178
|
} catch (e) {
|
|
5422
5179
|
console.error(tag5, "e: ", e);
|
|
@@ -5424,7 +5181,7 @@ class SDK {
|
|
|
5424
5181
|
}
|
|
5425
5182
|
};
|
|
5426
5183
|
this.setOutboundAssetContext = async function(asset) {
|
|
5427
|
-
const tag5 = `${
|
|
5184
|
+
const tag5 = `${TAG7} | setOutputAssetContext | `;
|
|
5428
5185
|
try {
|
|
5429
5186
|
console.log(tag5, "0. asset: ", asset);
|
|
5430
5187
|
if (!asset) {
|
|
@@ -5435,7 +5192,7 @@ class SDK {
|
|
|
5435
5192
|
if (!asset.caip)
|
|
5436
5193
|
throw Error("Invalid Asset! missing caip!");
|
|
5437
5194
|
if (!asset.networkId)
|
|
5438
|
-
asset.networkId =
|
|
5195
|
+
asset.networkId = caipToNetworkId6(asset.caip);
|
|
5439
5196
|
console.log(tag5, "networkId: ", asset.networkId);
|
|
5440
5197
|
console.log(tag5, "this.pubkeys: ", this.pubkeys);
|
|
5441
5198
|
const pubkey = this.pubkeys.find((p2) => {
|
|
@@ -5516,7 +5273,7 @@ class SDK {
|
|
|
5516
5273
|
console.log(tag5, "CHECKPOINT 3");
|
|
5517
5274
|
console.log(tag5, "outboundAssetContext: assetInfo: ", assetInfo);
|
|
5518
5275
|
if (asset.caip) {
|
|
5519
|
-
this.outboundBlockchainContext =
|
|
5276
|
+
this.outboundBlockchainContext = caipToNetworkId6(asset.caip);
|
|
5520
5277
|
} else if (asset.networkId) {
|
|
5521
5278
|
this.outboundBlockchainContext = asset.networkId;
|
|
5522
5279
|
}
|