@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.cjs
CHANGED
|
@@ -41,117 +41,6 @@ var __export = (target, all) => {
|
|
|
41
41
|
};
|
|
42
42
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
43
43
|
|
|
44
|
-
// ../../support/loggerdog/lib/index.js
|
|
45
|
-
var require_lib = __commonJS((exports2, module2) => {
|
|
46
|
-
var __spreadArray = exports2 && exports2.__spreadArray || function(to, from, pack) {
|
|
47
|
-
if (pack || arguments.length === 2)
|
|
48
|
-
for (var i = 0, l = from.length, ar;i < l; i++) {
|
|
49
|
-
if (ar || !(i in from)) {
|
|
50
|
-
if (!ar)
|
|
51
|
-
ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
-
ar[i] = from[i];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
-
};
|
|
57
|
-
var LOG_LEVELS = {
|
|
58
|
-
TEST: { val: 0, label: "TEST", color: "color: cyan" },
|
|
59
|
-
EMERG: { val: 0, label: "EMERG", color: "color: magenta" },
|
|
60
|
-
ALERT: { val: 1, label: "ALERT", color: "color: magenta" },
|
|
61
|
-
CRIT: { val: 2, label: "CRIT", color: "color: red" },
|
|
62
|
-
ERROR: { val: 3, label: "ERROR", color: "color: red" },
|
|
63
|
-
WARN: { val: 4, label: "WARN", color: "color: orange" },
|
|
64
|
-
NOTICE: { val: 5, label: "NOTICE", color: "color: yellow" },
|
|
65
|
-
VERBOSE: { val: 6, label: "VERBOSE", color: "color: cyan" },
|
|
66
|
-
INFO: { val: 6, label: "INFO", color: "color: cyan" },
|
|
67
|
-
DEBUG: { val: 7, label: "DEBUG", color: "color: green" },
|
|
68
|
-
DEBUGV: { val: 8, label: "DEBUG", color: "color: green" },
|
|
69
|
-
DEBUGVV: { val: 9, label: "DEBUG", color: "color: green" }
|
|
70
|
-
};
|
|
71
|
-
var DEFAULT_LOG_LEVEL = typeof process !== "undefined" ? process.env["DEFAULT_LOG_LEVEL"] || "INFO" : "INFO";
|
|
72
|
-
function _extractContext(stack, depth) {
|
|
73
|
-
try {
|
|
74
|
-
var arr = stack.split(`
|
|
75
|
-
`);
|
|
76
|
-
var chunks = arr[depth].split("/");
|
|
77
|
-
var business = chunks[chunks.length - 1];
|
|
78
|
-
var matches = business.match(/^([^:]+):(\d+):(\d+)/i) || "";
|
|
79
|
-
var filename = matches[1];
|
|
80
|
-
var line = matches[2];
|
|
81
|
-
var pos = matches[3];
|
|
82
|
-
return { filename, line, pos };
|
|
83
|
-
} catch (ex) {
|
|
84
|
-
return { filename: "unknown" };
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function _getContextString() {
|
|
88
|
-
var stack = new Error().stack || "";
|
|
89
|
-
var _a = _extractContext(stack, 3), filename = _a.filename, line = _a.line, pos = _a.pos;
|
|
90
|
-
return "[".concat(filename, ":").concat(line, ":").concat(pos, "]");
|
|
91
|
-
}
|
|
92
|
-
var Logger = function() {
|
|
93
|
-
function Logger2() {
|
|
94
|
-
var stack = new Error().stack || "";
|
|
95
|
-
var ctx = _extractContext(stack, 3);
|
|
96
|
-
this._tag = ctx.filename || "";
|
|
97
|
-
for (var lvl in LOG_LEVELS) {
|
|
98
|
-
this[lvl.toLowerCase()] = this._log.bind(this, lvl);
|
|
99
|
-
}
|
|
100
|
-
this._setLogLevel();
|
|
101
|
-
}
|
|
102
|
-
Logger2.prototype._setLogLevel = function() {
|
|
103
|
-
var tag = this._tag.split(".")[0];
|
|
104
|
-
tag = tag.toUpperCase().replace("-", "_");
|
|
105
|
-
var level = typeof process !== "undefined" ? process.env["LOG_LEVEL_" + tag] || null : null;
|
|
106
|
-
if (level && LOG_LEVELS[level] !== undefined) {
|
|
107
|
-
this._level = LOG_LEVELS[level].val;
|
|
108
|
-
} else {
|
|
109
|
-
this._level = LOG_LEVELS[DEFAULT_LOG_LEVEL].val;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
Logger2.prototype._log = function(level) {
|
|
113
|
-
var args = [];
|
|
114
|
-
for (var _i = 1;_i < arguments.length; _i++) {
|
|
115
|
-
args[_i - 1] = arguments[_i];
|
|
116
|
-
}
|
|
117
|
-
if (this._level >= LOG_LEVELS[level].val) {
|
|
118
|
-
var dt = new Date().toISOString().replace("T", " ");
|
|
119
|
-
var ctx = _getContextString();
|
|
120
|
-
var label = LOG_LEVELS[level].label;
|
|
121
|
-
var color = LOG_LEVELS[level].color;
|
|
122
|
-
var message = undefined;
|
|
123
|
-
if (typeof process !== "undefined" && process.env["STRUCTURED_LOGGING"]) {
|
|
124
|
-
message = {};
|
|
125
|
-
var tag = args[0];
|
|
126
|
-
var param = args[1];
|
|
127
|
-
var value = args[2];
|
|
128
|
-
if (typeof args === "object") {
|
|
129
|
-
message.loggerdog = true;
|
|
130
|
-
message.label = label;
|
|
131
|
-
message.param = param;
|
|
132
|
-
message.value = value;
|
|
133
|
-
message.ctx = ctx;
|
|
134
|
-
message.dt = dt;
|
|
135
|
-
message.tag = tag.toString();
|
|
136
|
-
message.raw = args.toString();
|
|
137
|
-
} else {
|
|
138
|
-
message.raw = args;
|
|
139
|
-
}
|
|
140
|
-
console.log("%c " + dt, color, label, ctx, message);
|
|
141
|
-
} else {
|
|
142
|
-
console.log.apply(console, __spreadArray(["%c " + dt, color, label, ctx], args, false));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
return Logger2;
|
|
147
|
-
}();
|
|
148
|
-
var getLogger = function() {
|
|
149
|
-
return new Logger;
|
|
150
|
-
};
|
|
151
|
-
exports2.default = getLogger;
|
|
152
|
-
module2.exports = getLogger;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
44
|
// ../../../node_modules/coinselect/utils.js
|
|
156
45
|
var require_utils = __commonJS((exports2, module2) => {
|
|
157
46
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
@@ -909,13 +798,27 @@ var import_pioneer_caip8 = require("@pioneer-platform/pioneer-caip");
|
|
|
909
798
|
|
|
910
799
|
// ../pioneer-client/lib/index.js
|
|
911
800
|
var import_swagger_client = __toESM(require("swagger-client"));
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
801
|
+
|
|
802
|
+
// ../pioneer-client/lib/utils/logger.js
|
|
803
|
+
var DEBUG = process.env.DEBUG === "true" || typeof window !== "undefined" && window.DEBUG;
|
|
804
|
+
var logger = {
|
|
805
|
+
info: (tag, ...args) => {
|
|
806
|
+
console.log(`[INFO] ${tag}`, ...args);
|
|
807
|
+
},
|
|
808
|
+
debug: (tag, ...args) => {
|
|
809
|
+
if (DEBUG) {
|
|
810
|
+
console.log(`[DEBUG] ${tag}`, ...args);
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
warn: (tag, ...args) => {
|
|
814
|
+
console.warn(`[WARN] ${tag}`, ...args);
|
|
815
|
+
},
|
|
816
|
+
error: (tag, ...args) => {
|
|
817
|
+
console.error(`[ERROR] ${tag}`, ...args);
|
|
818
|
+
}
|
|
918
819
|
};
|
|
820
|
+
|
|
821
|
+
// ../pioneer-client/lib/index.js
|
|
919
822
|
var Swagger = import_swagger_client.default;
|
|
920
823
|
var TAG = " | Client | ";
|
|
921
824
|
function customHttpClient(req) {
|
|
@@ -923,8 +826,8 @@ function customHttpClient(req) {
|
|
|
923
826
|
const timer = setTimeout(() => {
|
|
924
827
|
reject(new Error("Request timed out"));
|
|
925
828
|
}, 60000);
|
|
926
|
-
|
|
927
|
-
|
|
829
|
+
logger.debug(TAG, "HTTP request URL:", req.url);
|
|
830
|
+
logger.debug(TAG, "HTTP request details:", req);
|
|
928
831
|
if (Swagger.http) {
|
|
929
832
|
Swagger.http(req).then((response) => {
|
|
930
833
|
clearTimeout(timer);
|
|
@@ -982,16 +885,16 @@ class Pioneer {
|
|
|
982
885
|
requestInterceptor: (req) => {
|
|
983
886
|
req.headers.Authorization = this.queryKey;
|
|
984
887
|
if ((req.method === "POST" || req.method === "post") && req.body) {
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
888
|
+
logger.debug(TAG, "Request interceptor - method:", req.method);
|
|
889
|
+
logger.debug(TAG, "Body type:", typeof req.body);
|
|
890
|
+
logger.debug(TAG, "Body preview:", typeof req.body === "string" ? req.body.substring(0, 200) : JSON.stringify(req.body).substring(0, 200));
|
|
988
891
|
if (!req.headers)
|
|
989
892
|
req.headers = {};
|
|
990
893
|
if (!req.headers["Content-Type"]) {
|
|
991
894
|
req.headers["Content-Type"] = "application/json";
|
|
992
895
|
}
|
|
993
896
|
if (typeof req.body !== "string") {
|
|
994
|
-
|
|
897
|
+
logger.debug(TAG, "Converting body to JSON string");
|
|
995
898
|
req.body = JSON.stringify(req.body);
|
|
996
899
|
}
|
|
997
900
|
}
|
|
@@ -1004,9 +907,9 @@ class Pioneer {
|
|
|
1004
907
|
const operationId = this.client.spec.paths[path][method].operationId;
|
|
1005
908
|
this.pioneer[operationId] = async (parameters, queryParams) => {
|
|
1006
909
|
try {
|
|
1007
|
-
|
|
910
|
+
logger.debug(TAG, `${operationId} called with:`, parameters);
|
|
1008
911
|
if (queryParams) {
|
|
1009
|
-
|
|
912
|
+
logger.debug(TAG, `${operationId} query params:`, queryParams);
|
|
1010
913
|
}
|
|
1011
914
|
if (operationId === "GetMarketInfo") {
|
|
1012
915
|
if (!Array.isArray(parameters)) {
|
|
@@ -1017,7 +920,7 @@ class Pioneer {
|
|
|
1017
920
|
console.error(`\uD83D\uDEA8 [PIONEER CLIENT] GetMarketInfo validation failed:`, invalidElements);
|
|
1018
921
|
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})`);
|
|
1019
922
|
}
|
|
1020
|
-
|
|
923
|
+
logger.debug(TAG, `GetMarketInfo validation passed: ${parameters.length} valid CAIP strings`);
|
|
1021
924
|
}
|
|
1022
925
|
let request = {
|
|
1023
926
|
operationId,
|
|
@@ -1036,11 +939,11 @@ class Pioneer {
|
|
|
1036
939
|
Authorization: this.queryKey
|
|
1037
940
|
};
|
|
1038
941
|
}
|
|
1039
|
-
|
|
942
|
+
logger.debug(TAG, `${operationId} request:`, request);
|
|
1040
943
|
const result = await this.client.execute(request);
|
|
1041
944
|
return { data: result.body };
|
|
1042
945
|
} catch (e) {
|
|
1043
|
-
|
|
946
|
+
logger.error(TAG, "Operation error:", e);
|
|
1044
947
|
throw e;
|
|
1045
948
|
}
|
|
1046
949
|
};
|
|
@@ -1048,7 +951,7 @@ class Pioneer {
|
|
|
1048
951
|
});
|
|
1049
952
|
return this.pioneer;
|
|
1050
953
|
} catch (e) {
|
|
1051
|
-
|
|
954
|
+
logger.error(TAG, "Initialization error:", e);
|
|
1052
955
|
throw e;
|
|
1053
956
|
}
|
|
1054
957
|
}
|
|
@@ -1061,13 +964,13 @@ var import_pioneer_events = require("@pioneer-platform/pioneer-events");
|
|
|
1061
964
|
var import_events = __toESM(require("events"));
|
|
1062
965
|
|
|
1063
966
|
// src/utils/logger.ts
|
|
1064
|
-
var
|
|
1065
|
-
var
|
|
967
|
+
var DEBUG2 = process.env.DEBUG === "true" || typeof window !== "undefined" && window.DEBUG;
|
|
968
|
+
var logger2 = {
|
|
1066
969
|
info: (tag, ...args) => {
|
|
1067
970
|
console.log(`[INFO] ${tag}`, ...args);
|
|
1068
971
|
},
|
|
1069
972
|
debug: (tag, ...args) => {
|
|
1070
|
-
if (
|
|
973
|
+
if (DEBUG2) {
|
|
1071
974
|
console.log(`[DEBUG] ${tag}`, ...args);
|
|
1072
975
|
}
|
|
1073
976
|
},
|
|
@@ -3600,7 +3503,7 @@ function normalizeFeeData(feeData, networkType, networkName, networkId) {
|
|
|
3600
3503
|
"bip122:000000000000000000651ef99cb9fcbe": 50,
|
|
3601
3504
|
"bip122:000007d91d1254d60e2dd1ae58038307": 50,
|
|
3602
3505
|
"bip122:000000000019d6689c085ae165831e93": 5000,
|
|
3603
|
-
"bip122:4da631f2ac1bed857bd968c67c913978":
|
|
3506
|
+
"bip122:4da631f2ac1bed857bd968c67c913978": 150
|
|
3604
3507
|
};
|
|
3605
3508
|
const matchedNetworkId = networkId && sanityLimits[networkId] ? networkId : Object.keys(sanityLimits).find((id) => networkName.toLowerCase().includes(id.split(":")[1]?.substring(0, 8)));
|
|
3606
3509
|
if (matchedNetworkId && sanityLimits[matchedNetworkId]) {
|
|
@@ -4211,22 +4114,22 @@ async function fetchMarketPrice(pioneer, caip) {
|
|
|
4211
4114
|
const tag = TAG9 + " | fetchMarketPrice | ";
|
|
4212
4115
|
try {
|
|
4213
4116
|
if (!caip || typeof caip !== "string" || !caip.includes(":")) {
|
|
4214
|
-
|
|
4117
|
+
logger2.warn(tag, "Invalid or missing CAIP, skipping market price fetch:", caip);
|
|
4215
4118
|
return 0;
|
|
4216
4119
|
}
|
|
4217
|
-
|
|
4120
|
+
logger2.debug(tag, "Fetching fresh market price for:", caip);
|
|
4218
4121
|
const marketData = await pioneer.GetMarketInfo([caip]);
|
|
4219
|
-
|
|
4122
|
+
logger2.debug(tag, "Market data response:", marketData);
|
|
4220
4123
|
if (marketData && marketData.data && marketData.data.length > 0) {
|
|
4221
4124
|
const price = marketData.data[0];
|
|
4222
|
-
|
|
4125
|
+
logger2.debug(tag, "✅ Fresh market price:", price);
|
|
4223
4126
|
return price;
|
|
4224
4127
|
} else {
|
|
4225
|
-
|
|
4128
|
+
logger2.warn(tag, "No market data returned for:", caip);
|
|
4226
4129
|
return 0;
|
|
4227
4130
|
}
|
|
4228
4131
|
} catch (marketError) {
|
|
4229
|
-
|
|
4132
|
+
logger2.error(tag, "Error fetching market price:", marketError);
|
|
4230
4133
|
return 0;
|
|
4231
4134
|
}
|
|
4232
4135
|
}
|
|
@@ -4240,7 +4143,7 @@ function extractPriceFromBalances(balances) {
|
|
|
4240
4143
|
const valueUsd = parseFloat(balances[0].valueUsd);
|
|
4241
4144
|
if (balance > 0 && valueUsd > 0) {
|
|
4242
4145
|
priceValue = valueUsd / balance;
|
|
4243
|
-
|
|
4146
|
+
logger2.debug(tag, "Calculated priceUsd from valueUsd/balance:", priceValue);
|
|
4244
4147
|
}
|
|
4245
4148
|
}
|
|
4246
4149
|
return priceValue || 0;
|
|
@@ -4249,15 +4152,15 @@ function aggregateBalances(balances, caip) {
|
|
|
4249
4152
|
const tag = TAG9 + " | aggregateBalances | ";
|
|
4250
4153
|
let totalBalance = 0;
|
|
4251
4154
|
let totalValueUsd = 0;
|
|
4252
|
-
|
|
4155
|
+
logger2.debug(tag, `Aggregating ${balances.length} balance entries for ${caip}`);
|
|
4253
4156
|
for (const balanceEntry of balances) {
|
|
4254
4157
|
const balance = parseFloat(balanceEntry.balance) || 0;
|
|
4255
4158
|
const valueUsd = parseFloat(balanceEntry.valueUsd) || 0;
|
|
4256
4159
|
totalBalance += balance;
|
|
4257
4160
|
totalValueUsd += valueUsd;
|
|
4258
|
-
|
|
4161
|
+
logger2.debug(tag, ` Balance entry: ${balance} (${valueUsd} USD)`);
|
|
4259
4162
|
}
|
|
4260
|
-
|
|
4163
|
+
logger2.debug(tag, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
4261
4164
|
return { totalBalance, totalValueUsd };
|
|
4262
4165
|
}
|
|
4263
4166
|
function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
@@ -4268,7 +4171,7 @@ function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
|
4268
4171
|
const balanceAmount = parseFloat(balance.balance || 0);
|
|
4269
4172
|
balance.valueUsd = (balanceAmount * freshPriceUsd).toString();
|
|
4270
4173
|
}
|
|
4271
|
-
|
|
4174
|
+
logger2.debug(tag, "Updated all balances with fresh price data");
|
|
4272
4175
|
}
|
|
4273
4176
|
function buildDashboardFromPortfolioData(portfolioData) {
|
|
4274
4177
|
const cacheAge = portfolioData.lastUpdated ? Math.floor((Date.now() - portfolioData.lastUpdated) / 1000) : 0;
|
|
@@ -4330,14 +4233,14 @@ var TAG10 = " | sync-state | ";
|
|
|
4330
4233
|
function resolveAssetInfo(assetsMap, assetData, asset) {
|
|
4331
4234
|
const tag = TAG10 + " | resolveAssetInfo | ";
|
|
4332
4235
|
let assetInfo = assetsMap.get(asset.caip.toLowerCase());
|
|
4333
|
-
|
|
4236
|
+
logger2.debug(tag, "assetInfo from assetsMap:", assetInfo);
|
|
4334
4237
|
const assetInfoDiscovery = assetData[asset.caip];
|
|
4335
|
-
|
|
4238
|
+
logger2.debug(tag, "assetInfoDiscovery:", assetInfoDiscovery);
|
|
4336
4239
|
if (assetInfoDiscovery) {
|
|
4337
4240
|
assetInfo = assetInfoDiscovery;
|
|
4338
4241
|
}
|
|
4339
4242
|
if (!assetInfo) {
|
|
4340
|
-
|
|
4243
|
+
logger2.debug(tag, "Building placeholder asset for", asset.caip);
|
|
4341
4244
|
assetInfo = {
|
|
4342
4245
|
caip: asset.caip.toLowerCase(),
|
|
4343
4246
|
networkId: asset.networkId,
|
|
@@ -4465,12 +4368,12 @@ async function ensurePathsForBlockchains(blockchains, currentPaths, tag) {
|
|
|
4465
4368
|
const networkId = normalizeNetworkId(blockchain);
|
|
4466
4369
|
const existingPaths = allPaths.filter((path) => matchesNetwork(path, networkId));
|
|
4467
4370
|
if (existingPaths.length === 0) {
|
|
4468
|
-
|
|
4371
|
+
logger2.info(tag, `Discovering paths for ${networkId}...`);
|
|
4469
4372
|
const newPaths = import_pioneer_coins4.getPaths([networkId]);
|
|
4470
4373
|
if (!newPaths || newPaths.length === 0) {
|
|
4471
4374
|
throw new Error(`Path discovery failed for ${networkId}. ` + `Available blockchains: ${blockchains.join(", ")}`);
|
|
4472
4375
|
}
|
|
4473
|
-
|
|
4376
|
+
logger2.debug(tag, `Added ${newPaths.length} paths for ${networkId}`);
|
|
4474
4377
|
allPaths = allPaths.concat(newPaths);
|
|
4475
4378
|
}
|
|
4476
4379
|
}
|
|
@@ -4487,22 +4390,22 @@ async function syncPubkeysForBlockchains(blockchains, paths, existingPubkeys, ke
|
|
|
4487
4390
|
const availablePaths = paths.map((p) => p.note || p.path || "unnamed").join(", ");
|
|
4488
4391
|
throw new Error(`No paths found for ${networkId}. ` + `Available paths: ${availablePaths || "none"}`);
|
|
4489
4392
|
}
|
|
4490
|
-
|
|
4393
|
+
logger2.info(tag, `Syncing ${pathsForChain.length} pubkeys for ${networkId}...`);
|
|
4491
4394
|
for (const path of pathsForChain) {
|
|
4492
4395
|
const pathBip32 = import_pioneer_coins5.addressNListToBIP32(path.addressNListMaster);
|
|
4493
4396
|
const existingPubkey = existingPubkeys.find((p) => p.pathMaster === pathBip32);
|
|
4494
4397
|
if (!existingPubkey) {
|
|
4495
|
-
|
|
4398
|
+
logger2.debug(tag, `Fetching pubkey for path ${pathBip32}...`);
|
|
4496
4399
|
const newPubkey = await getPubkeyFn(blockchain, path, keepKeySdk, context);
|
|
4497
4400
|
if (!newPubkey) {
|
|
4498
4401
|
throw new Error(`Pubkey fetch failed for ${networkId} at path ${pathBip32}. ` + `Ensure hardware wallet is connected and unlocked.`);
|
|
4499
4402
|
}
|
|
4500
4403
|
addPubkeyCallback(newPubkey);
|
|
4501
|
-
|
|
4404
|
+
logger2.debug(tag, `✓ Added pubkey for ${pathBip32}`);
|
|
4502
4405
|
}
|
|
4503
4406
|
}
|
|
4504
4407
|
}
|
|
4505
|
-
|
|
4408
|
+
logger2.info(tag, `✅ Pubkey sync complete. Total pubkeys: ${existingPubkeys.length}`);
|
|
4506
4409
|
}
|
|
4507
4410
|
|
|
4508
4411
|
// src/index.ts
|
|
@@ -4923,48 +4826,48 @@ class SDK {
|
|
|
4923
4826
|
};
|
|
4924
4827
|
this.sync = async function() {
|
|
4925
4828
|
const tag6 = `${TAG12} | sync | `;
|
|
4926
|
-
const
|
|
4829
|
+
const log = logger2;
|
|
4927
4830
|
try {
|
|
4928
4831
|
this.syncState = {
|
|
4929
4832
|
...createInitialSyncState(this.blockchains.length),
|
|
4930
4833
|
syncProgress: 10
|
|
4931
4834
|
};
|
|
4932
4835
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4933
|
-
|
|
4836
|
+
log.info(tag6, "Fetching initial pubkeys...");
|
|
4934
4837
|
await this.getPubkeys();
|
|
4935
4838
|
this.syncState.syncProgress = 20;
|
|
4936
4839
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4937
|
-
|
|
4840
|
+
log.info(tag6, "Discovering paths for blockchains...");
|
|
4938
4841
|
this.paths = await ensurePathsForBlockchains(this.blockchains, this.paths, tag6);
|
|
4939
4842
|
this.syncState.syncProgress = 30;
|
|
4940
4843
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4941
|
-
|
|
4844
|
+
log.info(tag6, "Synchronizing pubkeys...");
|
|
4942
4845
|
await syncPubkeysForBlockchains(this.blockchains, this.paths, this.pubkeys, this.keepKeySdk, this.context, getPubkey, (pubkey) => this.addPubkey(pubkey), tag6);
|
|
4943
4846
|
this.syncState.syncProgress = 50;
|
|
4944
4847
|
this.syncState.syncedChains = this.blockchains.length;
|
|
4945
4848
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4946
|
-
|
|
4849
|
+
log.info(tag6, "Fetching balances...");
|
|
4947
4850
|
await this.getBalances();
|
|
4948
4851
|
this.syncState.syncProgress = 70;
|
|
4949
4852
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4950
|
-
|
|
4853
|
+
log.info(tag6, "Loading charts (tokens + portfolio)...");
|
|
4951
4854
|
await this.getCharts();
|
|
4952
|
-
|
|
4855
|
+
log.info(tag6, `Charts loaded. Total balances: ${this.balances.length}`);
|
|
4953
4856
|
this.syncState.syncProgress = 85;
|
|
4954
4857
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4955
|
-
|
|
4858
|
+
log.info(tag6, "Syncing market prices...");
|
|
4956
4859
|
await this.syncMarket();
|
|
4957
4860
|
this.syncState.syncProgress = 95;
|
|
4958
4861
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4959
|
-
|
|
4862
|
+
log.info(tag6, "Building dashboard...");
|
|
4960
4863
|
this.dashboard = buildDashboardFromBalances(this.balances, [...new Set(this.blockchains)], this.assetsMap);
|
|
4961
4864
|
this.syncState = createFreshSyncState(this.blockchains.length);
|
|
4962
4865
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4963
4866
|
this.events.emit("SYNC_COMPLETE", this.syncState);
|
|
4964
|
-
|
|
4867
|
+
log.info(tag6, "✅ Sync complete!");
|
|
4965
4868
|
return true;
|
|
4966
4869
|
} catch (e) {
|
|
4967
|
-
|
|
4870
|
+
log.error(tag6, "Sync failed:", e);
|
|
4968
4871
|
this.syncState = {
|
|
4969
4872
|
...this.syncState,
|
|
4970
4873
|
isSynced: false,
|