@pioneer-platform/pioneer-sdk 8.15.16 → 8.15.17
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 +66 -163
- package/dist/index.es.js +66 -163
- package/dist/index.js +66 -163
- package/package.json +3 -3
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
|
},
|
|
@@ -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,
|
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
|
},
|
|
@@ -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,
|
package/dist/index.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
|
},
|
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "highlander",
|
|
3
3
|
"name": "@pioneer-platform/pioneer-sdk",
|
|
4
|
-
"version": "8.15.
|
|
4
|
+
"version": "8.15.17",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@keepkey/keepkey-sdk": "^0.2.62",
|
|
7
7
|
"@pioneer-platform/pioneer-caip": "^9.10.2",
|
|
8
|
-
"@pioneer-platform/pioneer-client": "^9.10.
|
|
8
|
+
"@pioneer-platform/pioneer-client": "^9.10.12",
|
|
9
9
|
"@pioneer-platform/pioneer-coins": "^9.11.2",
|
|
10
|
-
"@pioneer-platform/pioneer-discovery": "^8.15.
|
|
10
|
+
"@pioneer-platform/pioneer-discovery": "^8.15.17",
|
|
11
11
|
"@pioneer-platform/pioneer-events": "^8.12.0",
|
|
12
12
|
"coinselect": "^3.1.13",
|
|
13
13
|
"eventemitter3": "^5.0.1",
|