@pioneer-platform/pioneer-sdk 8.15.16 → 8.15.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +67 -164
- package/dist/index.es.js +67 -164
- package/dist/index.js +67 -164
- package/package.json +3 -3
- package/src/fees/index.ts +1 -1
package/dist/index.es.js
CHANGED
|
@@ -33,117 +33,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
33
33
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
// ../../support/loggerdog/lib/index.js
|
|
37
|
-
var require_lib = __commonJS((exports, module) => {
|
|
38
|
-
var __spreadArray = exports && exports.__spreadArray || function(to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2)
|
|
40
|
-
for (var i = 0, l = from.length, ar;i < l; i++) {
|
|
41
|
-
if (ar || !(i in from)) {
|
|
42
|
-
if (!ar)
|
|
43
|
-
ar = Array.prototype.slice.call(from, 0, i);
|
|
44
|
-
ar[i] = from[i];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
|
-
};
|
|
49
|
-
var LOG_LEVELS = {
|
|
50
|
-
TEST: { val: 0, label: "TEST", color: "color: cyan" },
|
|
51
|
-
EMERG: { val: 0, label: "EMERG", color: "color: magenta" },
|
|
52
|
-
ALERT: { val: 1, label: "ALERT", color: "color: magenta" },
|
|
53
|
-
CRIT: { val: 2, label: "CRIT", color: "color: red" },
|
|
54
|
-
ERROR: { val: 3, label: "ERROR", color: "color: red" },
|
|
55
|
-
WARN: { val: 4, label: "WARN", color: "color: orange" },
|
|
56
|
-
NOTICE: { val: 5, label: "NOTICE", color: "color: yellow" },
|
|
57
|
-
VERBOSE: { val: 6, label: "VERBOSE", color: "color: cyan" },
|
|
58
|
-
INFO: { val: 6, label: "INFO", color: "color: cyan" },
|
|
59
|
-
DEBUG: { val: 7, label: "DEBUG", color: "color: green" },
|
|
60
|
-
DEBUGV: { val: 8, label: "DEBUG", color: "color: green" },
|
|
61
|
-
DEBUGVV: { val: 9, label: "DEBUG", color: "color: green" }
|
|
62
|
-
};
|
|
63
|
-
var DEFAULT_LOG_LEVEL = typeof process !== "undefined" ? process.env["DEFAULT_LOG_LEVEL"] || "INFO" : "INFO";
|
|
64
|
-
function _extractContext(stack, depth) {
|
|
65
|
-
try {
|
|
66
|
-
var arr = stack.split(`
|
|
67
|
-
`);
|
|
68
|
-
var chunks = arr[depth].split("/");
|
|
69
|
-
var business = chunks[chunks.length - 1];
|
|
70
|
-
var matches = business.match(/^([^:]+):(\d+):(\d+)/i) || "";
|
|
71
|
-
var filename = matches[1];
|
|
72
|
-
var line = matches[2];
|
|
73
|
-
var pos = matches[3];
|
|
74
|
-
return { filename, line, pos };
|
|
75
|
-
} catch (ex) {
|
|
76
|
-
return { filename: "unknown" };
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function _getContextString() {
|
|
80
|
-
var stack = new Error().stack || "";
|
|
81
|
-
var _a = _extractContext(stack, 3), filename = _a.filename, line = _a.line, pos = _a.pos;
|
|
82
|
-
return "[".concat(filename, ":").concat(line, ":").concat(pos, "]");
|
|
83
|
-
}
|
|
84
|
-
var Logger = function() {
|
|
85
|
-
function Logger2() {
|
|
86
|
-
var stack = new Error().stack || "";
|
|
87
|
-
var ctx = _extractContext(stack, 3);
|
|
88
|
-
this._tag = ctx.filename || "";
|
|
89
|
-
for (var lvl in LOG_LEVELS) {
|
|
90
|
-
this[lvl.toLowerCase()] = this._log.bind(this, lvl);
|
|
91
|
-
}
|
|
92
|
-
this._setLogLevel();
|
|
93
|
-
}
|
|
94
|
-
Logger2.prototype._setLogLevel = function() {
|
|
95
|
-
var tag = this._tag.split(".")[0];
|
|
96
|
-
tag = tag.toUpperCase().replace("-", "_");
|
|
97
|
-
var level = typeof process !== "undefined" ? process.env["LOG_LEVEL_" + tag] || null : null;
|
|
98
|
-
if (level && LOG_LEVELS[level] !== undefined) {
|
|
99
|
-
this._level = LOG_LEVELS[level].val;
|
|
100
|
-
} else {
|
|
101
|
-
this._level = LOG_LEVELS[DEFAULT_LOG_LEVEL].val;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
Logger2.prototype._log = function(level) {
|
|
105
|
-
var args = [];
|
|
106
|
-
for (var _i = 1;_i < arguments.length; _i++) {
|
|
107
|
-
args[_i - 1] = arguments[_i];
|
|
108
|
-
}
|
|
109
|
-
if (this._level >= LOG_LEVELS[level].val) {
|
|
110
|
-
var dt = new Date().toISOString().replace("T", " ");
|
|
111
|
-
var ctx = _getContextString();
|
|
112
|
-
var label = LOG_LEVELS[level].label;
|
|
113
|
-
var color = LOG_LEVELS[level].color;
|
|
114
|
-
var message = undefined;
|
|
115
|
-
if (typeof process !== "undefined" && process.env["STRUCTURED_LOGGING"]) {
|
|
116
|
-
message = {};
|
|
117
|
-
var tag = args[0];
|
|
118
|
-
var param = args[1];
|
|
119
|
-
var value = args[2];
|
|
120
|
-
if (typeof args === "object") {
|
|
121
|
-
message.loggerdog = true;
|
|
122
|
-
message.label = label;
|
|
123
|
-
message.param = param;
|
|
124
|
-
message.value = value;
|
|
125
|
-
message.ctx = ctx;
|
|
126
|
-
message.dt = dt;
|
|
127
|
-
message.tag = tag.toString();
|
|
128
|
-
message.raw = args.toString();
|
|
129
|
-
} else {
|
|
130
|
-
message.raw = args;
|
|
131
|
-
}
|
|
132
|
-
console.log("%c " + dt, color, label, ctx, message);
|
|
133
|
-
} else {
|
|
134
|
-
console.log.apply(console, __spreadArray(["%c " + dt, color, label, ctx], args, false));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
return Logger2;
|
|
139
|
-
}();
|
|
140
|
-
var getLogger = function() {
|
|
141
|
-
return new Logger;
|
|
142
|
-
};
|
|
143
|
-
exports.default = getLogger;
|
|
144
|
-
module.exports = getLogger;
|
|
145
|
-
});
|
|
146
|
-
|
|
147
36
|
// ../../../node_modules/coinselect/utils.js
|
|
148
37
|
var require_utils = __commonJS((exports, module) => {
|
|
149
38
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
@@ -893,14 +782,28 @@ import { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
|
893
782
|
import { caipToNetworkId as caipToNetworkId7, networkIdToCaip as networkIdToCaip2 } from "@pioneer-platform/pioneer-caip";
|
|
894
783
|
|
|
895
784
|
// ../pioneer-client/lib/index.js
|
|
896
|
-
var import_loggerdog = __toESM(require_lib(), 1);
|
|
897
785
|
import SwaggerClient from "swagger-client";
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
786
|
+
|
|
787
|
+
// ../pioneer-client/lib/utils/logger.js
|
|
788
|
+
var DEBUG = process.env.DEBUG === "true" || typeof window !== "undefined" && window.DEBUG;
|
|
789
|
+
var logger = {
|
|
790
|
+
info: (tag, ...args) => {
|
|
791
|
+
console.log(`[INFO] ${tag}`, ...args);
|
|
792
|
+
},
|
|
793
|
+
debug: (tag, ...args) => {
|
|
794
|
+
if (DEBUG) {
|
|
795
|
+
console.log(`[DEBUG] ${tag}`, ...args);
|
|
796
|
+
}
|
|
797
|
+
},
|
|
798
|
+
warn: (tag, ...args) => {
|
|
799
|
+
console.warn(`[WARN] ${tag}`, ...args);
|
|
800
|
+
},
|
|
801
|
+
error: (tag, ...args) => {
|
|
802
|
+
console.error(`[ERROR] ${tag}`, ...args);
|
|
803
|
+
}
|
|
903
804
|
};
|
|
805
|
+
|
|
806
|
+
// ../pioneer-client/lib/index.js
|
|
904
807
|
var Swagger = SwaggerClient;
|
|
905
808
|
var TAG = " | Client | ";
|
|
906
809
|
function customHttpClient(req) {
|
|
@@ -908,8 +811,8 @@ function customHttpClient(req) {
|
|
|
908
811
|
const timer = setTimeout(() => {
|
|
909
812
|
reject(new Error("Request timed out"));
|
|
910
813
|
}, 60000);
|
|
911
|
-
|
|
912
|
-
|
|
814
|
+
logger.debug(TAG, "HTTP request URL:", req.url);
|
|
815
|
+
logger.debug(TAG, "HTTP request details:", req);
|
|
913
816
|
if (Swagger.http) {
|
|
914
817
|
Swagger.http(req).then((response) => {
|
|
915
818
|
clearTimeout(timer);
|
|
@@ -967,16 +870,16 @@ class Pioneer {
|
|
|
967
870
|
requestInterceptor: (req) => {
|
|
968
871
|
req.headers.Authorization = this.queryKey;
|
|
969
872
|
if ((req.method === "POST" || req.method === "post") && req.body) {
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
873
|
+
logger.debug(TAG, "Request interceptor - method:", req.method);
|
|
874
|
+
logger.debug(TAG, "Body type:", typeof req.body);
|
|
875
|
+
logger.debug(TAG, "Body preview:", typeof req.body === "string" ? req.body.substring(0, 200) : JSON.stringify(req.body).substring(0, 200));
|
|
973
876
|
if (!req.headers)
|
|
974
877
|
req.headers = {};
|
|
975
878
|
if (!req.headers["Content-Type"]) {
|
|
976
879
|
req.headers["Content-Type"] = "application/json";
|
|
977
880
|
}
|
|
978
881
|
if (typeof req.body !== "string") {
|
|
979
|
-
|
|
882
|
+
logger.debug(TAG, "Converting body to JSON string");
|
|
980
883
|
req.body = JSON.stringify(req.body);
|
|
981
884
|
}
|
|
982
885
|
}
|
|
@@ -989,9 +892,9 @@ class Pioneer {
|
|
|
989
892
|
const operationId = this.client.spec.paths[path][method].operationId;
|
|
990
893
|
this.pioneer[operationId] = async (parameters, queryParams) => {
|
|
991
894
|
try {
|
|
992
|
-
|
|
895
|
+
logger.debug(TAG, `${operationId} called with:`, parameters);
|
|
993
896
|
if (queryParams) {
|
|
994
|
-
|
|
897
|
+
logger.debug(TAG, `${operationId} query params:`, queryParams);
|
|
995
898
|
}
|
|
996
899
|
if (operationId === "GetMarketInfo") {
|
|
997
900
|
if (!Array.isArray(parameters)) {
|
|
@@ -1002,7 +905,7 @@ class Pioneer {
|
|
|
1002
905
|
console.error(`\uD83D\uDEA8 [PIONEER CLIENT] GetMarketInfo validation failed:`, invalidElements);
|
|
1003
906
|
throw new Error(`GetMarketInfo array contains ${invalidElements.length} invalid element(s). ` + `All elements must be CAIP strings. First invalid at index ${invalidElements[0].index}: ` + `${JSON.stringify(invalidElements[0].item)} (type: ${invalidElements[0].type})`);
|
|
1004
907
|
}
|
|
1005
|
-
|
|
908
|
+
logger.debug(TAG, `GetMarketInfo validation passed: ${parameters.length} valid CAIP strings`);
|
|
1006
909
|
}
|
|
1007
910
|
let request = {
|
|
1008
911
|
operationId,
|
|
@@ -1021,11 +924,11 @@ class Pioneer {
|
|
|
1021
924
|
Authorization: this.queryKey
|
|
1022
925
|
};
|
|
1023
926
|
}
|
|
1024
|
-
|
|
927
|
+
logger.debug(TAG, `${operationId} request:`, request);
|
|
1025
928
|
const result = await this.client.execute(request);
|
|
1026
929
|
return { data: result.body };
|
|
1027
930
|
} catch (e) {
|
|
1028
|
-
|
|
931
|
+
logger.error(TAG, "Operation error:", e);
|
|
1029
932
|
throw e;
|
|
1030
933
|
}
|
|
1031
934
|
};
|
|
@@ -1033,7 +936,7 @@ class Pioneer {
|
|
|
1033
936
|
});
|
|
1034
937
|
return this.pioneer;
|
|
1035
938
|
} catch (e) {
|
|
1036
|
-
|
|
939
|
+
logger.error(TAG, "Initialization error:", e);
|
|
1037
940
|
throw e;
|
|
1038
941
|
}
|
|
1039
942
|
}
|
|
@@ -1241,13 +1144,13 @@ var A = o;
|
|
|
1241
1144
|
var P = o.prototype;
|
|
1242
1145
|
|
|
1243
1146
|
// src/utils/logger.ts
|
|
1244
|
-
var
|
|
1245
|
-
var
|
|
1147
|
+
var DEBUG2 = process.env.DEBUG === "true" || typeof window !== "undefined" && window.DEBUG;
|
|
1148
|
+
var logger2 = {
|
|
1246
1149
|
info: (tag, ...args) => {
|
|
1247
1150
|
console.log(`[INFO] ${tag}`, ...args);
|
|
1248
1151
|
},
|
|
1249
1152
|
debug: (tag, ...args) => {
|
|
1250
|
-
if (
|
|
1153
|
+
if (DEBUG2) {
|
|
1251
1154
|
console.log(`[DEBUG] ${tag}`, ...args);
|
|
1252
1155
|
}
|
|
1253
1156
|
},
|
|
@@ -3784,7 +3687,7 @@ function normalizeFeeData(feeData, networkType, networkName, networkId) {
|
|
|
3784
3687
|
"bip122:000000000000000000651ef99cb9fcbe": 50,
|
|
3785
3688
|
"bip122:000007d91d1254d60e2dd1ae58038307": 50,
|
|
3786
3689
|
"bip122:000000000019d6689c085ae165831e93": 5000,
|
|
3787
|
-
"bip122:4da631f2ac1bed857bd968c67c913978":
|
|
3690
|
+
"bip122:4da631f2ac1bed857bd968c67c913978": 150
|
|
3788
3691
|
};
|
|
3789
3692
|
const matchedNetworkId = networkId && sanityLimits[networkId] ? networkId : Object.keys(sanityLimits).find((id) => networkName.toLowerCase().includes(id.split(":")[1]?.substring(0, 8)));
|
|
3790
3693
|
if (matchedNetworkId && sanityLimits[matchedNetworkId]) {
|
|
@@ -4395,22 +4298,22 @@ async function fetchMarketPrice(pioneer, caip) {
|
|
|
4395
4298
|
const tag = TAG9 + " | fetchMarketPrice | ";
|
|
4396
4299
|
try {
|
|
4397
4300
|
if (!caip || typeof caip !== "string" || !caip.includes(":")) {
|
|
4398
|
-
|
|
4301
|
+
logger2.warn(tag, "Invalid or missing CAIP, skipping market price fetch:", caip);
|
|
4399
4302
|
return 0;
|
|
4400
4303
|
}
|
|
4401
|
-
|
|
4304
|
+
logger2.debug(tag, "Fetching fresh market price for:", caip);
|
|
4402
4305
|
const marketData = await pioneer.GetMarketInfo([caip]);
|
|
4403
|
-
|
|
4306
|
+
logger2.debug(tag, "Market data response:", marketData);
|
|
4404
4307
|
if (marketData && marketData.data && marketData.data.length > 0) {
|
|
4405
4308
|
const price = marketData.data[0];
|
|
4406
|
-
|
|
4309
|
+
logger2.debug(tag, "✅ Fresh market price:", price);
|
|
4407
4310
|
return price;
|
|
4408
4311
|
} else {
|
|
4409
|
-
|
|
4312
|
+
logger2.warn(tag, "No market data returned for:", caip);
|
|
4410
4313
|
return 0;
|
|
4411
4314
|
}
|
|
4412
4315
|
} catch (marketError) {
|
|
4413
|
-
|
|
4316
|
+
logger2.error(tag, "Error fetching market price:", marketError);
|
|
4414
4317
|
return 0;
|
|
4415
4318
|
}
|
|
4416
4319
|
}
|
|
@@ -4424,7 +4327,7 @@ function extractPriceFromBalances(balances) {
|
|
|
4424
4327
|
const valueUsd = parseFloat(balances[0].valueUsd);
|
|
4425
4328
|
if (balance > 0 && valueUsd > 0) {
|
|
4426
4329
|
priceValue = valueUsd / balance;
|
|
4427
|
-
|
|
4330
|
+
logger2.debug(tag, "Calculated priceUsd from valueUsd/balance:", priceValue);
|
|
4428
4331
|
}
|
|
4429
4332
|
}
|
|
4430
4333
|
return priceValue || 0;
|
|
@@ -4433,15 +4336,15 @@ function aggregateBalances(balances, caip) {
|
|
|
4433
4336
|
const tag = TAG9 + " | aggregateBalances | ";
|
|
4434
4337
|
let totalBalance = 0;
|
|
4435
4338
|
let totalValueUsd = 0;
|
|
4436
|
-
|
|
4339
|
+
logger2.debug(tag, `Aggregating ${balances.length} balance entries for ${caip}`);
|
|
4437
4340
|
for (const balanceEntry of balances) {
|
|
4438
4341
|
const balance = parseFloat(balanceEntry.balance) || 0;
|
|
4439
4342
|
const valueUsd = parseFloat(balanceEntry.valueUsd) || 0;
|
|
4440
4343
|
totalBalance += balance;
|
|
4441
4344
|
totalValueUsd += valueUsd;
|
|
4442
|
-
|
|
4345
|
+
logger2.debug(tag, ` Balance entry: ${balance} (${valueUsd} USD)`);
|
|
4443
4346
|
}
|
|
4444
|
-
|
|
4347
|
+
logger2.debug(tag, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
4445
4348
|
return { totalBalance, totalValueUsd };
|
|
4446
4349
|
}
|
|
4447
4350
|
function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
@@ -4452,7 +4355,7 @@ function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
|
4452
4355
|
const balanceAmount = parseFloat(balance.balance || 0);
|
|
4453
4356
|
balance.valueUsd = (balanceAmount * freshPriceUsd).toString();
|
|
4454
4357
|
}
|
|
4455
|
-
|
|
4358
|
+
logger2.debug(tag, "Updated all balances with fresh price data");
|
|
4456
4359
|
}
|
|
4457
4360
|
function buildDashboardFromPortfolioData(portfolioData) {
|
|
4458
4361
|
const cacheAge = portfolioData.lastUpdated ? Math.floor((Date.now() - portfolioData.lastUpdated) / 1000) : 0;
|
|
@@ -4514,14 +4417,14 @@ var TAG10 = " | sync-state | ";
|
|
|
4514
4417
|
function resolveAssetInfo(assetsMap, assetData, asset) {
|
|
4515
4418
|
const tag = TAG10 + " | resolveAssetInfo | ";
|
|
4516
4419
|
let assetInfo = assetsMap.get(asset.caip.toLowerCase());
|
|
4517
|
-
|
|
4420
|
+
logger2.debug(tag, "assetInfo from assetsMap:", assetInfo);
|
|
4518
4421
|
const assetInfoDiscovery = assetData[asset.caip];
|
|
4519
|
-
|
|
4422
|
+
logger2.debug(tag, "assetInfoDiscovery:", assetInfoDiscovery);
|
|
4520
4423
|
if (assetInfoDiscovery) {
|
|
4521
4424
|
assetInfo = assetInfoDiscovery;
|
|
4522
4425
|
}
|
|
4523
4426
|
if (!assetInfo) {
|
|
4524
|
-
|
|
4427
|
+
logger2.debug(tag, "Building placeholder asset for", asset.caip);
|
|
4525
4428
|
assetInfo = {
|
|
4526
4429
|
caip: asset.caip.toLowerCase(),
|
|
4527
4430
|
networkId: asset.networkId,
|
|
@@ -4649,12 +4552,12 @@ async function ensurePathsForBlockchains(blockchains, currentPaths, tag) {
|
|
|
4649
4552
|
const networkId = normalizeNetworkId(blockchain);
|
|
4650
4553
|
const existingPaths = allPaths.filter((path) => matchesNetwork(path, networkId));
|
|
4651
4554
|
if (existingPaths.length === 0) {
|
|
4652
|
-
|
|
4555
|
+
logger2.info(tag, `Discovering paths for ${networkId}...`);
|
|
4653
4556
|
const newPaths = getPaths([networkId]);
|
|
4654
4557
|
if (!newPaths || newPaths.length === 0) {
|
|
4655
4558
|
throw new Error(`Path discovery failed for ${networkId}. ` + `Available blockchains: ${blockchains.join(", ")}`);
|
|
4656
4559
|
}
|
|
4657
|
-
|
|
4560
|
+
logger2.debug(tag, `Added ${newPaths.length} paths for ${networkId}`);
|
|
4658
4561
|
allPaths = allPaths.concat(newPaths);
|
|
4659
4562
|
}
|
|
4660
4563
|
}
|
|
@@ -4671,22 +4574,22 @@ async function syncPubkeysForBlockchains(blockchains, paths, existingPubkeys, ke
|
|
|
4671
4574
|
const availablePaths = paths.map((p) => p.note || p.path || "unnamed").join(", ");
|
|
4672
4575
|
throw new Error(`No paths found for ${networkId}. ` + `Available paths: ${availablePaths || "none"}`);
|
|
4673
4576
|
}
|
|
4674
|
-
|
|
4577
|
+
logger2.info(tag, `Syncing ${pathsForChain.length} pubkeys for ${networkId}...`);
|
|
4675
4578
|
for (const path of pathsForChain) {
|
|
4676
4579
|
const pathBip32 = addressNListToBIP322(path.addressNListMaster);
|
|
4677
4580
|
const existingPubkey = existingPubkeys.find((p) => p.pathMaster === pathBip32);
|
|
4678
4581
|
if (!existingPubkey) {
|
|
4679
|
-
|
|
4582
|
+
logger2.debug(tag, `Fetching pubkey for path ${pathBip32}...`);
|
|
4680
4583
|
const newPubkey = await getPubkeyFn(blockchain, path, keepKeySdk, context);
|
|
4681
4584
|
if (!newPubkey) {
|
|
4682
4585
|
throw new Error(`Pubkey fetch failed for ${networkId} at path ${pathBip32}. ` + `Ensure hardware wallet is connected and unlocked.`);
|
|
4683
4586
|
}
|
|
4684
4587
|
addPubkeyCallback(newPubkey);
|
|
4685
|
-
|
|
4588
|
+
logger2.debug(tag, `✓ Added pubkey for ${pathBip32}`);
|
|
4686
4589
|
}
|
|
4687
4590
|
}
|
|
4688
4591
|
}
|
|
4689
|
-
|
|
4592
|
+
logger2.info(tag, `✅ Pubkey sync complete. Total pubkeys: ${existingPubkeys.length}`);
|
|
4690
4593
|
}
|
|
4691
4594
|
|
|
4692
4595
|
// src/index.ts
|
|
@@ -5107,48 +5010,48 @@ class SDK {
|
|
|
5107
5010
|
};
|
|
5108
5011
|
this.sync = async function() {
|
|
5109
5012
|
const tag6 = `${TAG12} | sync | `;
|
|
5110
|
-
const
|
|
5013
|
+
const log = logger2;
|
|
5111
5014
|
try {
|
|
5112
5015
|
this.syncState = {
|
|
5113
5016
|
...createInitialSyncState(this.blockchains.length),
|
|
5114
5017
|
syncProgress: 10
|
|
5115
5018
|
};
|
|
5116
5019
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5117
|
-
|
|
5020
|
+
log.info(tag6, "Fetching initial pubkeys...");
|
|
5118
5021
|
await this.getPubkeys();
|
|
5119
5022
|
this.syncState.syncProgress = 20;
|
|
5120
5023
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5121
|
-
|
|
5024
|
+
log.info(tag6, "Discovering paths for blockchains...");
|
|
5122
5025
|
this.paths = await ensurePathsForBlockchains(this.blockchains, this.paths, tag6);
|
|
5123
5026
|
this.syncState.syncProgress = 30;
|
|
5124
5027
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5125
|
-
|
|
5028
|
+
log.info(tag6, "Synchronizing pubkeys...");
|
|
5126
5029
|
await syncPubkeysForBlockchains(this.blockchains, this.paths, this.pubkeys, this.keepKeySdk, this.context, getPubkey, (pubkey) => this.addPubkey(pubkey), tag6);
|
|
5127
5030
|
this.syncState.syncProgress = 50;
|
|
5128
5031
|
this.syncState.syncedChains = this.blockchains.length;
|
|
5129
5032
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5130
|
-
|
|
5033
|
+
log.info(tag6, "Fetching balances...");
|
|
5131
5034
|
await this.getBalances();
|
|
5132
5035
|
this.syncState.syncProgress = 70;
|
|
5133
5036
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5134
|
-
|
|
5037
|
+
log.info(tag6, "Loading charts (tokens + portfolio)...");
|
|
5135
5038
|
await this.getCharts();
|
|
5136
|
-
|
|
5039
|
+
log.info(tag6, `Charts loaded. Total balances: ${this.balances.length}`);
|
|
5137
5040
|
this.syncState.syncProgress = 85;
|
|
5138
5041
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5139
|
-
|
|
5042
|
+
log.info(tag6, "Syncing market prices...");
|
|
5140
5043
|
await this.syncMarket();
|
|
5141
5044
|
this.syncState.syncProgress = 95;
|
|
5142
5045
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5143
|
-
|
|
5046
|
+
log.info(tag6, "Building dashboard...");
|
|
5144
5047
|
this.dashboard = buildDashboardFromBalances(this.balances, [...new Set(this.blockchains)], this.assetsMap);
|
|
5145
5048
|
this.syncState = createFreshSyncState(this.blockchains.length);
|
|
5146
5049
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5147
5050
|
this.events.emit("SYNC_COMPLETE", this.syncState);
|
|
5148
|
-
|
|
5051
|
+
log.info(tag6, "✅ Sync complete!");
|
|
5149
5052
|
return true;
|
|
5150
5053
|
} catch (e) {
|
|
5151
|
-
|
|
5054
|
+
log.error(tag6, "Sync failed:", e);
|
|
5152
5055
|
this.syncState = {
|
|
5153
5056
|
...this.syncState,
|
|
5154
5057
|
isSynced: false,
|