@pioneer-platform/pioneer-sdk 4.19.0 → 4.20.1
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 +595 -447
- package/dist/index.es.js +596 -447
- package/dist/index.js +596 -447
- package/package.json +7 -7
- package/src/TransactionManager.ts +21 -4
- package/src/fees/index.ts +60 -57
- package/src/fees/index.ts.backup +510 -0
- package/src/getPubkey.ts +57 -26
- package/src/index.ts +391 -61
- package/src/txbuilder/createUnsignedEvmTx.ts +118 -63
- package/src/txbuilder/createUnsignedRippleTx.ts +12 -11
- package/src/txbuilder/createUnsignedStakingTx.ts +13 -11
- package/src/txbuilder/createUnsignedTendermintTx.ts +45 -20
- package/src/txbuilder/createUnsignedUxtoTx.ts +122 -57
- package/src/txbuilder/createUnsignedUxtoTx.ts.backup +384 -0
- package/src/txbuilder/templates/mayachain.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -505,49 +505,6 @@ var require_utils = __commonJS((exports2, module2) => {
|
|
|
505
505
|
};
|
|
506
506
|
});
|
|
507
507
|
|
|
508
|
-
// ../../../node_modules/coinselect/split.js
|
|
509
|
-
var require_split = __commonJS((exports2, module2) => {
|
|
510
|
-
var utils = require_utils();
|
|
511
|
-
module2.exports = function split(utxos, outputs, feeRate) {
|
|
512
|
-
if (!isFinite(utils.uintOrNaN(feeRate)))
|
|
513
|
-
return {};
|
|
514
|
-
var bytesAccum = utils.transactionBytes(utxos, outputs);
|
|
515
|
-
var fee = feeRate * bytesAccum;
|
|
516
|
-
if (outputs.length === 0)
|
|
517
|
-
return { fee };
|
|
518
|
-
var inAccum = utils.sumOrNaN(utxos);
|
|
519
|
-
var outAccum = utils.sumForgiving(outputs);
|
|
520
|
-
var remaining = inAccum - outAccum - fee;
|
|
521
|
-
if (!isFinite(remaining) || remaining < 0)
|
|
522
|
-
return { fee };
|
|
523
|
-
var unspecified = outputs.reduce(function(a, x) {
|
|
524
|
-
return a + !isFinite(x.value);
|
|
525
|
-
}, 0);
|
|
526
|
-
if (remaining === 0 && unspecified === 0)
|
|
527
|
-
return utils.finalize(utxos, outputs, feeRate);
|
|
528
|
-
var splitOutputsCount = outputs.reduce(function(a, x) {
|
|
529
|
-
if (x.value !== undefined)
|
|
530
|
-
return a;
|
|
531
|
-
return a + 1;
|
|
532
|
-
}, 0);
|
|
533
|
-
var splitValue = Math.floor(remaining / splitOutputsCount);
|
|
534
|
-
if (!outputs.every(function(x) {
|
|
535
|
-
return x.value !== undefined || splitValue > utils.dustThreshold(x, feeRate);
|
|
536
|
-
}))
|
|
537
|
-
return { fee };
|
|
538
|
-
outputs = outputs.map(function(x) {
|
|
539
|
-
if (x.value !== undefined)
|
|
540
|
-
return x;
|
|
541
|
-
var y = {};
|
|
542
|
-
for (var k in x)
|
|
543
|
-
y[k] = x[k];
|
|
544
|
-
y.value = splitValue;
|
|
545
|
-
return y;
|
|
546
|
-
});
|
|
547
|
-
return utils.finalize(utxos, outputs, feeRate);
|
|
548
|
-
};
|
|
549
|
-
});
|
|
550
|
-
|
|
551
508
|
// ../../../node_modules/coinselect/accumulative.js
|
|
552
509
|
var require_accumulative = __commonJS((exports2, module2) => {
|
|
553
510
|
var utils = require_utils();
|
|
@@ -628,6 +585,49 @@ var require_coinselect = __commonJS((exports2, module2) => {
|
|
|
628
585
|
};
|
|
629
586
|
});
|
|
630
587
|
|
|
588
|
+
// ../../../node_modules/coinselect/split.js
|
|
589
|
+
var require_split = __commonJS((exports2, module2) => {
|
|
590
|
+
var utils = require_utils();
|
|
591
|
+
module2.exports = function split(utxos, outputs, feeRate) {
|
|
592
|
+
if (!isFinite(utils.uintOrNaN(feeRate)))
|
|
593
|
+
return {};
|
|
594
|
+
var bytesAccum = utils.transactionBytes(utxos, outputs);
|
|
595
|
+
var fee = feeRate * bytesAccum;
|
|
596
|
+
if (outputs.length === 0)
|
|
597
|
+
return { fee };
|
|
598
|
+
var inAccum = utils.sumOrNaN(utxos);
|
|
599
|
+
var outAccum = utils.sumForgiving(outputs);
|
|
600
|
+
var remaining = inAccum - outAccum - fee;
|
|
601
|
+
if (!isFinite(remaining) || remaining < 0)
|
|
602
|
+
return { fee };
|
|
603
|
+
var unspecified = outputs.reduce(function(a, x) {
|
|
604
|
+
return a + !isFinite(x.value);
|
|
605
|
+
}, 0);
|
|
606
|
+
if (remaining === 0 && unspecified === 0)
|
|
607
|
+
return utils.finalize(utxos, outputs, feeRate);
|
|
608
|
+
var splitOutputsCount = outputs.reduce(function(a, x) {
|
|
609
|
+
if (x.value !== undefined)
|
|
610
|
+
return a;
|
|
611
|
+
return a + 1;
|
|
612
|
+
}, 0);
|
|
613
|
+
var splitValue = Math.floor(remaining / splitOutputsCount);
|
|
614
|
+
if (!outputs.every(function(x) {
|
|
615
|
+
return x.value !== undefined || splitValue > utils.dustThreshold(x, feeRate);
|
|
616
|
+
}))
|
|
617
|
+
return { fee };
|
|
618
|
+
outputs = outputs.map(function(x) {
|
|
619
|
+
if (x.value !== undefined)
|
|
620
|
+
return x;
|
|
621
|
+
var y = {};
|
|
622
|
+
for (var k in x)
|
|
623
|
+
y[k] = x[k];
|
|
624
|
+
y.value = splitValue;
|
|
625
|
+
return y;
|
|
626
|
+
});
|
|
627
|
+
return utils.finalize(utxos, outputs, feeRate);
|
|
628
|
+
};
|
|
629
|
+
});
|
|
630
|
+
|
|
631
631
|
// src/index.ts
|
|
632
632
|
var exports_src = {};
|
|
633
633
|
__export(exports_src, {
|
|
@@ -636,12 +636,12 @@ __export(exports_src, {
|
|
|
636
636
|
});
|
|
637
637
|
module.exports = __toCommonJS(exports_src);
|
|
638
638
|
var import_keepkey_sdk = require("@keepkey/keepkey-sdk");
|
|
639
|
-
var
|
|
639
|
+
var import_pioneer_caip6 = require("@pioneer-platform/pioneer-caip");
|
|
640
640
|
var import_pioneer_client = __toESM(require_lib());
|
|
641
641
|
var import_pioneer_coins4 = require("@pioneer-platform/pioneer-coins");
|
|
642
642
|
var import_pioneer_discovery2 = require("@pioneer-platform/pioneer-discovery");
|
|
643
643
|
var import_pioneer_events = require("@pioneer-platform/pioneer-events");
|
|
644
|
-
var import_events = require("events");
|
|
644
|
+
var import_events = __toESM(require("events"));
|
|
645
645
|
|
|
646
646
|
// src/charts/utils.ts
|
|
647
647
|
var import_pioneer_discovery = require("@pioneer-platform/pioneer-discovery");
|
|
@@ -1230,42 +1230,31 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1230
1230
|
console.error("⏰ [PUBKEY] Address retrieval timeout for", networkId);
|
|
1231
1231
|
}, 30000);
|
|
1232
1232
|
try {
|
|
1233
|
-
let result;
|
|
1234
1233
|
switch (networkType) {
|
|
1235
1234
|
case "UTXO":
|
|
1236
|
-
|
|
1235
|
+
({ address } = await sdk.address.utxoGetAddress(addressInfo));
|
|
1237
1236
|
break;
|
|
1238
1237
|
case "EVM":
|
|
1239
|
-
|
|
1238
|
+
({ address } = await sdk.address.ethereumGetAddress(addressInfo));
|
|
1240
1239
|
break;
|
|
1241
1240
|
case "OSMOSIS":
|
|
1242
|
-
|
|
1241
|
+
({ address } = await sdk.address.osmosisGetAddress(addressInfo));
|
|
1243
1242
|
break;
|
|
1244
1243
|
case "COSMOS":
|
|
1245
|
-
|
|
1244
|
+
({ address } = await sdk.address.cosmosGetAddress(addressInfo));
|
|
1246
1245
|
break;
|
|
1247
1246
|
case "MAYACHAIN":
|
|
1248
|
-
|
|
1247
|
+
({ address } = await sdk.address.mayachainGetAddress(addressInfo));
|
|
1249
1248
|
break;
|
|
1250
1249
|
case "THORCHAIN":
|
|
1251
|
-
|
|
1250
|
+
({ address } = await sdk.address.thorchainGetAddress(addressInfo));
|
|
1252
1251
|
break;
|
|
1253
1252
|
case "XRP":
|
|
1254
|
-
|
|
1253
|
+
({ address } = await sdk.address.xrpGetAddress(addressInfo));
|
|
1255
1254
|
break;
|
|
1256
1255
|
default:
|
|
1257
1256
|
throw new Error(`Unsupported network type for networkId: ${networkId}`);
|
|
1258
1257
|
}
|
|
1259
|
-
if (!result) {
|
|
1260
|
-
throw new Error(`Address call returned null/undefined for ${networkType} (${networkId})`);
|
|
1261
|
-
}
|
|
1262
|
-
if (typeof result === "object" && result.address) {
|
|
1263
|
-
address = result.address;
|
|
1264
|
-
} else if (typeof result === "string") {
|
|
1265
|
-
address = result;
|
|
1266
|
-
} else {
|
|
1267
|
-
throw new Error(`Invalid address response format for ${networkType} (${networkId}): ${JSON.stringify(result)}`);
|
|
1268
|
-
}
|
|
1269
1258
|
clearTimeout(addressTimeout);
|
|
1270
1259
|
} catch (addressError) {
|
|
1271
1260
|
clearTimeout(addressTimeout);
|
|
@@ -1280,6 +1269,10 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1280
1269
|
pubkey.master = address;
|
|
1281
1270
|
pubkey.address = address;
|
|
1282
1271
|
if (["xpub", "ypub", "zpub"].includes(path.type)) {
|
|
1272
|
+
console.log("\uD83D\uDD11 [XPUB] Starting xpub retrieval for path type:", path.type);
|
|
1273
|
+
console.log("\uD83D\uDD11 [XPUB] Network:", networkId);
|
|
1274
|
+
console.log("\uD83D\uDD11 [XPUB] Path:", import_pioneer_coins.addressNListToBIP32(path.addressNList));
|
|
1275
|
+
console.log("\uD83D\uDD11 [XPUB] Script type:", path.script_type);
|
|
1283
1276
|
const pathQuery = {
|
|
1284
1277
|
symbol: "BTC",
|
|
1285
1278
|
coin: "Bitcoin",
|
|
@@ -1287,26 +1280,58 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1287
1280
|
address_n: path.addressNList,
|
|
1288
1281
|
showDisplay: false
|
|
1289
1282
|
};
|
|
1283
|
+
console.log("\uD83D\uDD11 [XPUB] Calling sdk.system.info.getPublicKey with:", JSON.stringify(pathQuery, null, 2));
|
|
1290
1284
|
const xpubTimeout = setTimeout(() => {
|
|
1291
|
-
console.error("getPublicKey timeout after 20 seconds");
|
|
1285
|
+
console.error("⏰ [XPUB TIMEOUT] getPublicKey timeout after 20 seconds");
|
|
1286
|
+
console.error("⏰ [XPUB TIMEOUT] Path:", import_pioneer_coins.addressNListToBIP32(path.addressNList));
|
|
1287
|
+
console.error("⏰ [XPUB TIMEOUT] This is a CRITICAL FAILURE - UTXO balances require xpubs");
|
|
1292
1288
|
}, 20000);
|
|
1293
1289
|
try {
|
|
1290
|
+
console.log("\uD83D\uDD11 [XPUB] Calling getPublicKey...");
|
|
1294
1291
|
const responsePubkey = await sdk.system.info.getPublicKey(pathQuery);
|
|
1295
1292
|
clearTimeout(xpubTimeout);
|
|
1293
|
+
console.log("✅ [XPUB] getPublicKey SUCCESS");
|
|
1294
|
+
console.log("✅ [XPUB] Response:", JSON.stringify(responsePubkey, null, 2));
|
|
1295
|
+
if (!responsePubkey || !responsePubkey.xpub) {
|
|
1296
|
+
const error = new Error("FAIL FAST: getPublicKey returned null or missing xpub");
|
|
1297
|
+
console.error("❌ [XPUB] CRITICAL:", error.message);
|
|
1298
|
+
console.error("❌ [XPUB] Response was:", responsePubkey);
|
|
1299
|
+
throw error;
|
|
1300
|
+
}
|
|
1296
1301
|
if (path.script_type === "p2wpkh") {
|
|
1302
|
+
console.log("\uD83D\uDD11 [XPUB] Converting xpub to zpub for native segwit");
|
|
1297
1303
|
responsePubkey.xpub = import_pioneer_coins.xpubConvert(responsePubkey.xpub, "zpub");
|
|
1298
1304
|
} else if (path.script_type === "p2sh-p2wpkh") {
|
|
1305
|
+
console.log("\uD83D\uDD11 [XPUB] Converting xpub to ypub for wrapped segwit");
|
|
1299
1306
|
responsePubkey.xpub = import_pioneer_coins.xpubConvert(responsePubkey.xpub, "ypub");
|
|
1300
1307
|
}
|
|
1308
|
+
console.log("✅ [XPUB] Final xpub:", responsePubkey.xpub.substring(0, 20) + "...");
|
|
1301
1309
|
pubkey.pubkey = responsePubkey.xpub;
|
|
1302
1310
|
pubkey.path = import_pioneer_coins.addressNListToBIP32(path.addressNList);
|
|
1303
1311
|
pubkey.pathMaster = import_pioneer_coins.addressNListToBIP32(path.addressNListMaster);
|
|
1312
|
+
console.log("✅ [XPUB] Xpub retrieval COMPLETE for", path.note || path.type);
|
|
1304
1313
|
} catch (xpubError) {
|
|
1305
1314
|
clearTimeout(xpubTimeout);
|
|
1306
|
-
console.error("getPublicKey failed
|
|
1307
|
-
|
|
1315
|
+
console.error("❌ [XPUB] CRITICAL FAILURE - getPublicKey failed");
|
|
1316
|
+
console.error("❌ [XPUB] Error:", xpubError);
|
|
1317
|
+
console.error("❌ [XPUB] Error message:", xpubError.message);
|
|
1318
|
+
console.error("❌ [XPUB] Error stack:", xpubError.stack);
|
|
1319
|
+
console.error("❌ [XPUB] Path:", import_pioneer_coins.addressNListToBIP32(path.addressNList));
|
|
1320
|
+
console.error("❌ [XPUB] Network:", networkId);
|
|
1321
|
+
console.error("❌ [XPUB] Query:", JSON.stringify(pathQuery, null, 2));
|
|
1322
|
+
console.error("❌ [XPUB] SDK available:", !!sdk);
|
|
1323
|
+
console.error("❌ [XPUB] SDK.system available:", !!sdk?.system);
|
|
1324
|
+
console.error("❌ [XPUB] SDK.system.info available:", !!sdk?.system?.info);
|
|
1325
|
+
console.error("❌ [XPUB] SDK.system.info.getPublicKey available:", !!sdk?.system?.info?.getPublicKey);
|
|
1326
|
+
console.error("");
|
|
1327
|
+
console.error("\uD83D\uDEA8 FAIL FAST: Cannot proceed without xpub for UTXO chains");
|
|
1328
|
+
console.error("\uD83D\uDEA8 UTXO balance queries REQUIRE extended public keys (xpubs)");
|
|
1329
|
+
console.error("\uD83D\uDEA8 This is a device communication or SDK issue that must be resolved");
|
|
1330
|
+
console.error("");
|
|
1331
|
+
throw new Error(`FAIL FAST - xpub retrieval failed for ${networkId} at ${import_pioneer_coins.addressNListToBIP32(path.addressNList)}: ${xpubError.message}`);
|
|
1308
1332
|
}
|
|
1309
1333
|
} else {
|
|
1334
|
+
console.log("\uD83D\uDD11 [PUBKEY] Non-xpub path (address-based), using address as pubkey");
|
|
1310
1335
|
pubkey.pubkey = address;
|
|
1311
1336
|
pubkey.path = import_pioneer_coins.addressNListToBIP32(path.addressNList);
|
|
1312
1337
|
pubkey.pathMaster = import_pioneer_coins.addressNListToBIP32(path.addressNListMaster);
|
|
@@ -1716,13 +1741,16 @@ async function fetchTokenPriceInUsd(contractAddress) {
|
|
|
1716
1741
|
}
|
|
1717
1742
|
return price;
|
|
1718
1743
|
}
|
|
1719
|
-
async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer,
|
|
1744
|
+
async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5) {
|
|
1720
1745
|
const tag5 = TAG + " | createUnsignedEvmTx | ";
|
|
1721
1746
|
try {
|
|
1722
1747
|
if (!pioneer)
|
|
1723
1748
|
throw new Error("Failed to initialize Pioneer");
|
|
1724
1749
|
const networkId = import_pioneer_caip.caipToNetworkId(caip);
|
|
1725
1750
|
const chainId = extractChainIdFromNetworkId(networkId);
|
|
1751
|
+
if (!pubkeyContext) {
|
|
1752
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
1753
|
+
}
|
|
1726
1754
|
const isValidForNetwork = (pubkey) => {
|
|
1727
1755
|
if (!pubkey?.networks)
|
|
1728
1756
|
return false;
|
|
@@ -1731,43 +1759,83 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
1731
1759
|
}
|
|
1732
1760
|
return pubkey.networks.includes(networkId);
|
|
1733
1761
|
};
|
|
1734
|
-
if (!
|
|
1735
|
-
|
|
1736
|
-
keepKeySdk.pubkeyContext = pubkeys.find((pk) => isValidForNetwork(pk));
|
|
1737
|
-
} else {
|
|
1738
|
-
console.log(tag5, "Current context networks:", keepKeySdk.pubkeyContext.networks, "For networkId:", networkId);
|
|
1739
|
-
if (!isValidForNetwork(keepKeySdk.pubkeyContext)) {
|
|
1740
|
-
console.log(tag5, "Auto-correcting context - wrong network detected");
|
|
1741
|
-
keepKeySdk.pubkeyContext = pubkeys.find((pk) => isValidForNetwork(pk));
|
|
1742
|
-
} else {
|
|
1743
|
-
console.log(tag5, "Context is valid for this network - using existing context");
|
|
1744
|
-
}
|
|
1762
|
+
if (!isValidForNetwork(pubkeyContext)) {
|
|
1763
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
1745
1764
|
}
|
|
1746
|
-
const address =
|
|
1747
|
-
console.log(tag5, "✅ Using FROM address from pubkeyContext:", address, "note:",
|
|
1765
|
+
const address = pubkeyContext.address || pubkeyContext.pubkey;
|
|
1766
|
+
console.log(tag5, "✅ Using FROM address from pubkeyContext:", address, "note:", pubkeyContext.note);
|
|
1748
1767
|
if (!address)
|
|
1749
1768
|
throw new Error("No address found for the specified network");
|
|
1750
1769
|
const gasPriceData = await pioneer.GetGasPriceByNetwork({ networkId });
|
|
1751
|
-
|
|
1752
|
-
const MIN_GAS_PRICE_WEI = BigInt(10000000000);
|
|
1753
|
-
if (BigInt(gasPriceData.data) < MIN_GAS_PRICE_WEI) {
|
|
1754
|
-
console.log(tag5, "Gas price from API too low:", gasPriceData.data, "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1755
|
-
baseGasPrice = MIN_GAS_PRICE_WEI;
|
|
1756
|
-
} else {
|
|
1757
|
-
baseGasPrice = BigInt(gasPriceData.data);
|
|
1758
|
-
}
|
|
1770
|
+
console.log(tag5, "Gas price data from API:", JSON.stringify(gasPriceData.data));
|
|
1759
1771
|
let gasPrice;
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1772
|
+
const defaultGasPrices = {
|
|
1773
|
+
1: 30,
|
|
1774
|
+
56: 3,
|
|
1775
|
+
137: 50,
|
|
1776
|
+
43114: 25,
|
|
1777
|
+
8453: 0.1,
|
|
1778
|
+
10: 0.1
|
|
1779
|
+
};
|
|
1780
|
+
const fallbackGasGwei = defaultGasPrices[chainId] || 20;
|
|
1781
|
+
const MIN_GAS_PRICE_WEI = BigInt(fallbackGasGwei * 1e9);
|
|
1782
|
+
if (typeof gasPriceData.data === "object" && gasPriceData.data !== null && !Array.isArray(gasPriceData.data)) {
|
|
1783
|
+
let selectedGasPrice;
|
|
1784
|
+
if (feeLevel <= 2) {
|
|
1785
|
+
selectedGasPrice = gasPriceData.data.slow || gasPriceData.data.average || gasPriceData.data.fastest;
|
|
1786
|
+
console.log(tag5, "Selecting SLOW gas price from API");
|
|
1787
|
+
} else if (feeLevel >= 8) {
|
|
1788
|
+
selectedGasPrice = gasPriceData.data.fastest || gasPriceData.data.fast || gasPriceData.data.average;
|
|
1789
|
+
console.log(tag5, "Selecting FAST gas price from API");
|
|
1790
|
+
} else {
|
|
1791
|
+
selectedGasPrice = gasPriceData.data.average || gasPriceData.data.fast || gasPriceData.data.fastest;
|
|
1792
|
+
console.log(tag5, "Selecting AVERAGE gas price from API");
|
|
1793
|
+
}
|
|
1794
|
+
let gasPriceNum;
|
|
1795
|
+
if (selectedGasPrice === undefined || selectedGasPrice === null) {
|
|
1796
|
+
console.warn(tag5, "No valid gas price found in API response, using fallback:", fallbackGasGwei, "gwei");
|
|
1797
|
+
gasPriceNum = fallbackGasGwei;
|
|
1798
|
+
} else {
|
|
1799
|
+
gasPriceNum = typeof selectedGasPrice === "string" ? parseFloat(selectedGasPrice) : selectedGasPrice;
|
|
1800
|
+
if (isNaN(gasPriceNum) || !isFinite(gasPriceNum)) {
|
|
1801
|
+
console.warn(tag5, "Invalid gas price (NaN or Infinite):", selectedGasPrice, "- using fallback:", fallbackGasGwei, "gwei");
|
|
1802
|
+
gasPriceNum = fallbackGasGwei;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
gasPrice = BigInt(Math.round(gasPriceNum * 1e9));
|
|
1806
|
+
if (gasPrice < MIN_GAS_PRICE_WEI) {
|
|
1807
|
+
console.warn(tag5, "Gas price from API too low:", gasPrice.toString(), "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1808
|
+
gasPrice = MIN_GAS_PRICE_WEI;
|
|
1809
|
+
}
|
|
1766
1810
|
} else {
|
|
1767
|
-
|
|
1768
|
-
|
|
1811
|
+
let gasPriceNum;
|
|
1812
|
+
if (gasPriceData.data === undefined || gasPriceData.data === null) {
|
|
1813
|
+
console.warn(tag5, "Gas price API returned null/undefined, using fallback:", fallbackGasGwei, "gwei");
|
|
1814
|
+
gasPriceNum = fallbackGasGwei;
|
|
1815
|
+
} else {
|
|
1816
|
+
gasPriceNum = typeof gasPriceData.data === "string" ? parseFloat(gasPriceData.data) : gasPriceData.data;
|
|
1817
|
+
if (isNaN(gasPriceNum) || !isFinite(gasPriceNum)) {
|
|
1818
|
+
console.warn(tag5, "Invalid gas price (NaN or Infinite):", gasPriceData.data, "- using fallback:", fallbackGasGwei, "gwei");
|
|
1819
|
+
gasPriceNum = fallbackGasGwei;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
const baseGasPrice = BigInt(Math.round(gasPriceNum * 1e9));
|
|
1823
|
+
if (feeLevel <= 2) {
|
|
1824
|
+
gasPrice = baseGasPrice * BigInt(80) / BigInt(100);
|
|
1825
|
+
console.log(tag5, "Using SLOW gas price (80% of base)");
|
|
1826
|
+
} else if (feeLevel >= 8) {
|
|
1827
|
+
gasPrice = baseGasPrice * BigInt(150) / BigInt(100);
|
|
1828
|
+
console.log(tag5, "Using FAST gas price (150% of base)");
|
|
1829
|
+
} else {
|
|
1830
|
+
gasPrice = baseGasPrice;
|
|
1831
|
+
console.log(tag5, "Using AVERAGE gas price (100% of base)");
|
|
1832
|
+
}
|
|
1833
|
+
if (gasPrice < MIN_GAS_PRICE_WEI) {
|
|
1834
|
+
console.warn(tag5, "Gas price too low:", gasPrice.toString(), "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1835
|
+
gasPrice = MIN_GAS_PRICE_WEI;
|
|
1836
|
+
}
|
|
1769
1837
|
}
|
|
1770
|
-
console.log(tag5, "
|
|
1838
|
+
console.log(tag5, "Final gasPrice:", gasPrice.toString(), "wei (", Number(gasPrice) / 1e9, "gwei)");
|
|
1771
1839
|
let nonce;
|
|
1772
1840
|
try {
|
|
1773
1841
|
const nonceData = await pioneer.GetNonceByNetwork({ networkId, address });
|
|
@@ -1958,18 +2026,18 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
1958
2026
|
throw new Error(`Unsupported asset type for CAIP ${caip}`);
|
|
1959
2027
|
}
|
|
1960
2028
|
}
|
|
1961
|
-
if (
|
|
1962
|
-
unsignedTx.addressNList =
|
|
2029
|
+
if (pubkeyContext.addressNListMaster) {
|
|
2030
|
+
unsignedTx.addressNList = pubkeyContext.addressNListMaster;
|
|
1963
2031
|
console.log(tag5, "✅ Using addressNListMaster from pubkey context:", unsignedTx.addressNList, "for address:", address);
|
|
1964
|
-
} else if (
|
|
1965
|
-
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(
|
|
1966
|
-
console.log(tag5, "✅ Converted pathMaster to addressNList:",
|
|
1967
|
-
} else if (
|
|
1968
|
-
unsignedTx.addressNList =
|
|
2032
|
+
} else if (pubkeyContext.pathMaster) {
|
|
2033
|
+
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(pubkeyContext.pathMaster);
|
|
2034
|
+
console.log(tag5, "✅ Converted pathMaster to addressNList:", pubkeyContext.pathMaster, "→", unsignedTx.addressNList);
|
|
2035
|
+
} else if (pubkeyContext.addressNList) {
|
|
2036
|
+
unsignedTx.addressNList = pubkeyContext.addressNList;
|
|
1969
2037
|
console.log(tag5, "✅ Using addressNList from pubkey context:", unsignedTx.addressNList);
|
|
1970
|
-
} else if (
|
|
1971
|
-
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(
|
|
1972
|
-
console.log(tag5, "⚠️ Using regular path (not master):",
|
|
2038
|
+
} else if (pubkeyContext.path) {
|
|
2039
|
+
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(pubkeyContext.path);
|
|
2040
|
+
console.log(tag5, "⚠️ Using regular path (not master):", pubkeyContext.path, "→", unsignedTx.addressNList);
|
|
1973
2041
|
} else {
|
|
1974
2042
|
unsignedTx.addressNList = [2147483648 + 44, 2147483648 + 60, 2147483648, 0, 0];
|
|
1975
2043
|
console.warn(tag5, "⚠️ No path info in pubkey context, using default account 0");
|
|
@@ -1984,19 +2052,22 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, kee
|
|
|
1984
2052
|
// src/txbuilder/createUnsignedRippleTx.ts
|
|
1985
2053
|
var import_pioneer_caip2 = require("@pioneer-platform/pioneer-caip");
|
|
1986
2054
|
var TAG2 = " | createUnsignedUxtoTx | ";
|
|
1987
|
-
async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer,
|
|
2055
|
+
async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax) {
|
|
1988
2056
|
let tag5 = TAG2 + " | createUnsignedRippleTx | ";
|
|
1989
2057
|
try {
|
|
1990
2058
|
if (!pioneer)
|
|
1991
2059
|
throw new Error("Failed to init! pioneer");
|
|
1992
2060
|
const networkId = import_pioneer_caip2.caipToNetworkId(caip);
|
|
1993
|
-
if (!
|
|
1994
|
-
|
|
2061
|
+
if (!pubkeyContext) {
|
|
2062
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
1995
2063
|
}
|
|
1996
|
-
if (!
|
|
1997
|
-
throw new Error(`
|
|
2064
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2065
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
1998
2066
|
}
|
|
1999
|
-
|
|
2067
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2068
|
+
address: pubkeyContext.address
|
|
2069
|
+
});
|
|
2070
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
2000
2071
|
let accountInfo = await pioneer.GetAccountInfo({
|
|
2001
2072
|
address: fromAddress,
|
|
2002
2073
|
network: "ripple"
|
|
@@ -2094,6 +2165,7 @@ var cosmosTransferTemplate = (params) => ({
|
|
|
2094
2165
|
// src/txbuilder/templates/mayachain.ts
|
|
2095
2166
|
var mayachainTransferTemplate = (params) => ({
|
|
2096
2167
|
signerAddress: params.from_address,
|
|
2168
|
+
addressNList: params.addressNList,
|
|
2097
2169
|
signDoc: {
|
|
2098
2170
|
account_number: params.account_number,
|
|
2099
2171
|
chain_id: params.chain_id,
|
|
@@ -2199,18 +2271,22 @@ var thorchainDepositTemplate = (params) => ({
|
|
|
2199
2271
|
|
|
2200
2272
|
// src/txbuilder/createUnsignedTendermintTx.ts
|
|
2201
2273
|
var TAG3 = " | createUnsignedTendermintTx | ";
|
|
2202
|
-
async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pioneer,
|
|
2274
|
+
async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, to) {
|
|
2203
2275
|
const tag5 = TAG3 + " | createUnsignedTendermintTx | ";
|
|
2204
2276
|
try {
|
|
2205
2277
|
if (!pioneer)
|
|
2206
2278
|
throw new Error("Failed to init! pioneer");
|
|
2207
2279
|
const networkId = import_pioneer_caip3.caipToNetworkId(caip);
|
|
2208
|
-
if (!
|
|
2209
|
-
|
|
2280
|
+
if (!pubkeyContext) {
|
|
2281
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
2210
2282
|
}
|
|
2211
|
-
if (!
|
|
2212
|
-
throw new Error(`
|
|
2283
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2284
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2213
2285
|
}
|
|
2286
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2287
|
+
address: pubkeyContext.address,
|
|
2288
|
+
addressNList: pubkeyContext.addressNList || pubkeyContext.addressNListMaster
|
|
2289
|
+
});
|
|
2214
2290
|
let chain;
|
|
2215
2291
|
switch (networkId) {
|
|
2216
2292
|
case "cosmos:thorchain-mainnet-v1":
|
|
@@ -2228,10 +2304,13 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2228
2304
|
default:
|
|
2229
2305
|
throw new Error(`Unhandled networkId: ${networkId}`);
|
|
2230
2306
|
}
|
|
2231
|
-
const fromAddress =
|
|
2307
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
2232
2308
|
let asset = caip.split(":")[1];
|
|
2309
|
+
console.log(tag5, `\uD83D\uDD0D Fetching account info for address: ${fromAddress}`);
|
|
2233
2310
|
const accountInfo = (await pioneer.GetAccountInfo({ network: chain, address: fromAddress })).data;
|
|
2311
|
+
console.log(tag5, "\uD83D\uDCCB accountInfo:", JSON.stringify(accountInfo, null, 2));
|
|
2234
2312
|
let balanceInfo = await pioneer.GetPubkeyBalance({ asset: chain, pubkey: fromAddress });
|
|
2313
|
+
console.log(tag5, `\uD83D\uDCB0 balanceInfo:`, balanceInfo);
|
|
2235
2314
|
let account_number, sequence;
|
|
2236
2315
|
if (networkId === "cosmos:cosmoshub-4" || networkId === "cosmos:osmosis-1") {
|
|
2237
2316
|
account_number = accountInfo.account.account_number || "0";
|
|
@@ -2240,9 +2319,17 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2240
2319
|
account_number = accountInfo.result.value.account_number || "0";
|
|
2241
2320
|
sequence = accountInfo.result.value.sequence || "0";
|
|
2242
2321
|
}
|
|
2322
|
+
console.log(tag5, `\uD83D\uDCCA Extracted account_number: ${account_number}, sequence: ${sequence}`);
|
|
2323
|
+
if (account_number === "0" || account_number === 0) {
|
|
2324
|
+
console.log(tag5, `⚠️ WARNING: Account number is 0 from Pioneer API`);
|
|
2325
|
+
console.log(tag5, ` This is likely due to stale Pioneer API cache`);
|
|
2326
|
+
console.log(tag5, ` The mayachain-network module queries nodes directly but Pioneer API may be cached`);
|
|
2327
|
+
console.log(tag5, ` Proceeding with account_number: 0 but transaction will likely fail`);
|
|
2328
|
+
console.log(tag5, ` TODO: Fix Pioneer API to use fresh data from mayachain-network module`);
|
|
2329
|
+
}
|
|
2243
2330
|
const fees = {
|
|
2244
2331
|
"cosmos:thorchain-mainnet-v1": 0.02,
|
|
2245
|
-
"cosmos:mayachain-mainnet-v1": 0
|
|
2332
|
+
"cosmos:mayachain-mainnet-v1": 0,
|
|
2246
2333
|
"cosmos:cosmoshub-4": 0.005,
|
|
2247
2334
|
"cosmos:osmosis-1": 0.035
|
|
2248
2335
|
};
|
|
@@ -2295,17 +2382,18 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2295
2382
|
case "cosmos:mayachain-mainnet-v1": {
|
|
2296
2383
|
let mayaAsset;
|
|
2297
2384
|
if (caip.includes("/denom:maya")) {
|
|
2298
|
-
mayaAsset = "
|
|
2385
|
+
mayaAsset = "maya";
|
|
2299
2386
|
} else if (caip.includes("/slip44:931")) {
|
|
2300
|
-
mayaAsset = "
|
|
2387
|
+
mayaAsset = "cacao";
|
|
2301
2388
|
} else {
|
|
2302
2389
|
throw new Error(`Unsupported Maya chain CAIP: ${caip}`);
|
|
2303
2390
|
}
|
|
2391
|
+
const decimals = mayaAsset === "maya" ? 1e4 : 10000000000;
|
|
2304
2392
|
if (isMax) {
|
|
2305
|
-
const fee = Math.floor(fees[networkId] *
|
|
2306
|
-
amount = Math.max(0, Math.floor(balanceInfo.data *
|
|
2393
|
+
const fee = Math.floor(fees[networkId] * decimals);
|
|
2394
|
+
amount = Math.max(0, Math.floor(balanceInfo.data * decimals) - fee);
|
|
2307
2395
|
} else {
|
|
2308
|
-
amount = Math.max(Math.floor(amount *
|
|
2396
|
+
amount = Math.max(Math.floor(amount * decimals), 0);
|
|
2309
2397
|
}
|
|
2310
2398
|
return to ? mayachainTransferTemplate({
|
|
2311
2399
|
account_number,
|
|
@@ -2324,7 +2412,8 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2324
2412
|
asset: mayaAsset,
|
|
2325
2413
|
amount: amount.toString(),
|
|
2326
2414
|
memo,
|
|
2327
|
-
sequence
|
|
2415
|
+
sequence,
|
|
2416
|
+
addressNList: pubkeyContext.addressNList || pubkeyContext.addressNListMaster
|
|
2328
2417
|
}) : mayachainDepositTemplate({
|
|
2329
2418
|
account_number,
|
|
2330
2419
|
chain_id: "mayachain-mainnet-v1",
|
|
@@ -2399,52 +2488,50 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2399
2488
|
// src/txbuilder/createUnsignedUxtoTx.ts
|
|
2400
2489
|
var import_pioneer_caip4 = require("@pioneer-platform/pioneer-caip");
|
|
2401
2490
|
var import_pioneer_coins3 = require("@pioneer-platform/pioneer-coins");
|
|
2402
|
-
|
|
2491
|
+
var import_coinselect = __toESM(require_coinselect());
|
|
2492
|
+
var import_split = __toESM(require_split());
|
|
2493
|
+
function getCoinTypeFromNetworkId(networkId) {
|
|
2494
|
+
const chain = import_pioneer_caip4.NetworkIdToChain[networkId];
|
|
2495
|
+
if (!chain) {
|
|
2496
|
+
console.warn(`No chain mapping found for ${networkId}, defaulting to Bitcoin coin type 0`);
|
|
2497
|
+
return 0;
|
|
2498
|
+
}
|
|
2499
|
+
const blockchainName = import_pioneer_coins3.COIN_MAP_LONG[chain]?.toLowerCase();
|
|
2500
|
+
if (!blockchainName) {
|
|
2501
|
+
console.warn(`No blockchain name found for chain ${chain}, defaulting to Bitcoin coin type 0`);
|
|
2502
|
+
return 0;
|
|
2503
|
+
}
|
|
2504
|
+
const coinType = import_pioneer_coins3.SLIP_44_BY_LONG[blockchainName];
|
|
2505
|
+
if (coinType === undefined) {
|
|
2506
|
+
console.warn(`No SLIP-44 coin type found for ${blockchainName}, defaulting to Bitcoin coin type 0`);
|
|
2507
|
+
return 0;
|
|
2508
|
+
}
|
|
2509
|
+
return coinType;
|
|
2510
|
+
}
|
|
2511
|
+
async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5, changeScriptType) {
|
|
2403
2512
|
let tag5 = " | createUnsignedUxtoTx | ";
|
|
2404
2513
|
try {
|
|
2405
2514
|
if (!pioneer)
|
|
2406
2515
|
throw Error("Failed to init! pioneer");
|
|
2407
2516
|
const networkId = import_pioneer_caip4.caipToNetworkId(caip);
|
|
2408
|
-
if (!
|
|
2409
|
-
|
|
2517
|
+
if (!pubkeyContext) {
|
|
2518
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
2410
2519
|
}
|
|
2520
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2521
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2522
|
+
}
|
|
2523
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2524
|
+
address: pubkeyContext.address,
|
|
2525
|
+
scriptType: pubkeyContext.scriptType
|
|
2526
|
+
});
|
|
2411
2527
|
const relevantPubkeys = pubkeys.filter((e) => e.networks && Array.isArray(e.networks) && e.networks.includes(networkId));
|
|
2412
2528
|
const segwitNetworks = [
|
|
2413
2529
|
"bip122:000000000019d6689c085ae165831e93"
|
|
2414
2530
|
];
|
|
2415
2531
|
const isSegwit = segwitNetworks.includes(networkId);
|
|
2416
2532
|
let chain = import_pioneer_caip4.NetworkIdToChain[networkId];
|
|
2417
|
-
const
|
|
2418
|
-
console.log(`${tag5}: Using
|
|
2419
|
-
const changeXpub = relevantPubkeys.find((pk) => pk.scriptType === actualChangeScriptType)?.pubkey || relevantPubkeys.find((pk) => pk.scriptType === "p2wpkh")?.pubkey || relevantPubkeys[0].pubkey;
|
|
2420
|
-
console.log(`${tag5}: Change xpub selected for ${actualChangeScriptType}:`, changeXpub?.substring(0, 10) + "...");
|
|
2421
|
-
let changeAddressIndex = await pioneer.GetChangeAddress({
|
|
2422
|
-
network: chain,
|
|
2423
|
-
xpub: changeXpub
|
|
2424
|
-
});
|
|
2425
|
-
changeAddressIndex = changeAddressIndex.data.changeIndex;
|
|
2426
|
-
let bipPath;
|
|
2427
|
-
switch (actualChangeScriptType) {
|
|
2428
|
-
case "p2pkh":
|
|
2429
|
-
bipPath = `m/44'/0'/0'/1/${changeAddressIndex}`;
|
|
2430
|
-
break;
|
|
2431
|
-
case "p2sh-p2wpkh":
|
|
2432
|
-
bipPath = `m/49'/0'/0'/1/${changeAddressIndex}`;
|
|
2433
|
-
break;
|
|
2434
|
-
case "p2wpkh":
|
|
2435
|
-
default:
|
|
2436
|
-
bipPath = `m/84'/0'/0'/1/${changeAddressIndex}`;
|
|
2437
|
-
break;
|
|
2438
|
-
}
|
|
2439
|
-
const path = bipPath;
|
|
2440
|
-
console.log(`${tag5}: Change address path: ${path} (index: ${changeAddressIndex})`);
|
|
2441
|
-
const changeAddress = {
|
|
2442
|
-
path,
|
|
2443
|
-
isChange: true,
|
|
2444
|
-
index: changeAddressIndex,
|
|
2445
|
-
addressNList: import_pioneer_coins3.bip32ToAddressNList(path),
|
|
2446
|
-
scriptType: actualChangeScriptType
|
|
2447
|
-
};
|
|
2533
|
+
const coinType = getCoinTypeFromNetworkId(networkId);
|
|
2534
|
+
console.log(`${tag5}: Using SLIP-44 coin type ${coinType} for ${chain}`);
|
|
2448
2535
|
const utxos = [];
|
|
2449
2536
|
for (const pubkey of relevantPubkeys) {
|
|
2450
2537
|
try {
|
|
@@ -2470,6 +2557,48 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, ke
|
|
|
2470
2557
|
for (const utxo of utxos) {
|
|
2471
2558
|
utxo.value = Number(utxo.value);
|
|
2472
2559
|
}
|
|
2560
|
+
const inputScriptTypes = utxos.map((u) => u.scriptType).filter(Boolean);
|
|
2561
|
+
const scriptTypeCount = inputScriptTypes.reduce((acc, type) => {
|
|
2562
|
+
acc[type] = (acc[type] || 0) + 1;
|
|
2563
|
+
return acc;
|
|
2564
|
+
}, {});
|
|
2565
|
+
const mostCommonInputType = Object.entries(scriptTypeCount).sort(([, a], [, b2]) => b2 - a)[0]?.[0] || "p2pkh";
|
|
2566
|
+
const actualChangeScriptType = changeScriptType || mostCommonInputType || relevantPubkeys[0]?.scriptType || "p2pkh";
|
|
2567
|
+
console.log(`${tag5}: Input script types:`, scriptTypeCount);
|
|
2568
|
+
console.log(`${tag5}: Using change script type: ${actualChangeScriptType} (matches inputs: ${mostCommonInputType})`);
|
|
2569
|
+
const changeXpubInfo = relevantPubkeys.find((pk) => pk.scriptType === actualChangeScriptType);
|
|
2570
|
+
if (!changeXpubInfo) {
|
|
2571
|
+
throw new Error(`No ${actualChangeScriptType} xpub available for change address. ` + `Available types: ${relevantPubkeys.map((pk) => pk.scriptType).join(", ")}. ` + `Cannot create change output with mismatched script type.`);
|
|
2572
|
+
}
|
|
2573
|
+
const changeXpub = changeXpubInfo.pubkey;
|
|
2574
|
+
console.log(`${tag5}: Change xpub selected for ${actualChangeScriptType}:`, changeXpub?.substring(0, 10) + "...");
|
|
2575
|
+
let changeAddressIndex = await pioneer.GetChangeAddress({
|
|
2576
|
+
network: chain,
|
|
2577
|
+
xpub: changeXpub
|
|
2578
|
+
});
|
|
2579
|
+
changeAddressIndex = changeAddressIndex.data.changeIndex;
|
|
2580
|
+
let bipPath;
|
|
2581
|
+
switch (actualChangeScriptType) {
|
|
2582
|
+
case "p2pkh":
|
|
2583
|
+
bipPath = `m/44'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2584
|
+
break;
|
|
2585
|
+
case "p2sh-p2wpkh":
|
|
2586
|
+
bipPath = `m/49'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2587
|
+
break;
|
|
2588
|
+
case "p2wpkh":
|
|
2589
|
+
default:
|
|
2590
|
+
bipPath = `m/84'/${coinType}'/0'/1/${changeAddressIndex}`;
|
|
2591
|
+
break;
|
|
2592
|
+
}
|
|
2593
|
+
const path = bipPath;
|
|
2594
|
+
console.log(`${tag5}: Change address path: ${path} (coin type: ${coinType}, index: ${changeAddressIndex})`);
|
|
2595
|
+
const changeAddress = {
|
|
2596
|
+
path,
|
|
2597
|
+
isChange: true,
|
|
2598
|
+
index: changeAddressIndex,
|
|
2599
|
+
addressNList: import_pioneer_coins3.bip32ToAddressNList(path),
|
|
2600
|
+
scriptType: actualChangeScriptType
|
|
2601
|
+
};
|
|
2473
2602
|
let feeRateFromNode;
|
|
2474
2603
|
if (networkId === "bip122:00000000001a91e3dace36e2be3bf030") {
|
|
2475
2604
|
console.log(`${tag5}: Using hardcoded fees for DOGE (10 sat/byte)`);
|
|
@@ -2587,11 +2716,9 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, ke
|
|
|
2587
2716
|
})));
|
|
2588
2717
|
let result;
|
|
2589
2718
|
if (isMax) {
|
|
2590
|
-
|
|
2591
|
-
result = coinSelectSplit(utxos, [{ address: to }], effectiveFeeRate);
|
|
2719
|
+
result = import_split.default(utxos, [{ address: to }], effectiveFeeRate);
|
|
2592
2720
|
} else {
|
|
2593
|
-
|
|
2594
|
-
result = coinSelect(utxos, [{ address: to, value: amount }], effectiveFeeRate);
|
|
2721
|
+
result = import_coinselect.default(utxos, [{ address: to, value: amount }], effectiveFeeRate);
|
|
2595
2722
|
}
|
|
2596
2723
|
console.log(tag5, "coinSelect result object:", result);
|
|
2597
2724
|
console.log(tag5, "coinSelect result.inputs:", result?.inputs);
|
|
@@ -2708,6 +2835,7 @@ class TransactionManager {
|
|
|
2708
2835
|
assetContext;
|
|
2709
2836
|
balances;
|
|
2710
2837
|
pubkeys;
|
|
2838
|
+
pubkeyContext;
|
|
2711
2839
|
nodes;
|
|
2712
2840
|
pioneer;
|
|
2713
2841
|
keepKeySdk;
|
|
@@ -2717,6 +2845,7 @@ class TransactionManager {
|
|
|
2717
2845
|
this.assetContext = dependencies.assetContext;
|
|
2718
2846
|
this.balances = dependencies.balances;
|
|
2719
2847
|
this.pubkeys = dependencies.pubkeys;
|
|
2848
|
+
this.pubkeyContext = dependencies.pubkeyContext;
|
|
2720
2849
|
this.nodes = dependencies.nodes;
|
|
2721
2850
|
this.pioneer = dependencies.pioneer;
|
|
2722
2851
|
this.keepKeySdk = dependencies.keepKeySdk;
|
|
@@ -2750,20 +2879,20 @@ class TransactionManager {
|
|
|
2750
2879
|
let unsignedTx;
|
|
2751
2880
|
switch (type) {
|
|
2752
2881
|
case "UTXO": {
|
|
2753
|
-
unsignedTx = await createUnsignedUxtoTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2882
|
+
unsignedTx = await createUnsignedUxtoTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, feeLevel, changeScriptType);
|
|
2754
2883
|
break;
|
|
2755
2884
|
}
|
|
2756
2885
|
case "TENDERMINT": {
|
|
2757
2886
|
const txType = "transfer";
|
|
2758
|
-
unsignedTx = await createUnsignedTendermintTx(caip, txType, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2887
|
+
unsignedTx = await createUnsignedTendermintTx(caip, txType, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, to);
|
|
2759
2888
|
break;
|
|
2760
2889
|
}
|
|
2761
2890
|
case "EIP155": {
|
|
2762
|
-
unsignedTx = await createUnsignedEvmTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2891
|
+
unsignedTx = await createUnsignedEvmTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax, feeLevel);
|
|
2763
2892
|
break;
|
|
2764
2893
|
}
|
|
2765
2894
|
case "OTHER": {
|
|
2766
|
-
unsignedTx = await createUnsignedRippleTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.
|
|
2895
|
+
unsignedTx = await createUnsignedRippleTx(caip, to, amount, memo, this.pubkeys, this.pioneer, this.pubkeyContext, isMax);
|
|
2767
2896
|
break;
|
|
2768
2897
|
}
|
|
2769
2898
|
default: {
|
|
@@ -2862,9 +2991,20 @@ class TransactionManager {
|
|
|
2862
2991
|
}
|
|
2863
2992
|
case "cosmos:mayachain-mainnet-v1/slip44:931":
|
|
2864
2993
|
case "cosmos:mayachain-mainnet-v1/denom:maya": {
|
|
2994
|
+
console.log(tag5, "\uD83D\uDD0D ===== MAYACHAIN SIGNING AUDIT =====");
|
|
2995
|
+
console.log(tag5, "\uD83D\uDCCB unsignedTx:", JSON.stringify(unsignedTx, null, 2));
|
|
2996
|
+
console.log(tag5, "\uD83D\uDD11 unsignedTx.addressNList:", unsignedTx.addressNList);
|
|
2997
|
+
console.log(tag5, "\uD83D\uDCCD unsignedTx.signerAddress:", unsignedTx.signerAddress);
|
|
2998
|
+
console.log(tag5, "\uD83C\uDF10 pubkeyContext:", this.pubkeyContext);
|
|
2999
|
+
console.log(tag5, "\uD83D\uDD10 pubkeyContext.addressNList:", this.pubkeyContext?.addressNList);
|
|
3000
|
+
console.log(tag5, "\uD83D\uDD10 pubkeyContext.addressNListMaster:", this.pubkeyContext?.addressNListMaster);
|
|
3001
|
+
console.log(tag5, "\uD83D\uDCEC pubkeyContext.address:", this.pubkeyContext?.address);
|
|
3002
|
+
console.log(tag5, "=======================================");
|
|
2865
3003
|
if (unsignedTx.signDoc.msgs[0].type === "mayachain/MsgSend") {
|
|
2866
3004
|
const responseSign = await this.keepKeySdk.mayachain.mayachainSignAminoTransfer(unsignedTx);
|
|
2867
3005
|
signedTx = responseSign.serialized;
|
|
3006
|
+
console.log(tag5, "✅ Signing completed");
|
|
3007
|
+
console.log(tag5, "\uD83D\uDCE6 responseSign:", responseSign);
|
|
2868
3008
|
} else if (unsignedTx.signDoc.msgs[0].type === "mayachain/MsgDeposit") {
|
|
2869
3009
|
const responseSign = await this.keepKeySdk.mayachain.mayachainSignAminoDeposit(unsignedTx);
|
|
2870
3010
|
signedTx = responseSign.serialized;
|
|
@@ -3056,18 +3196,21 @@ var cosmosClaimAllRewardsTemplate = (params) => ({
|
|
|
3056
3196
|
|
|
3057
3197
|
// src/txbuilder/createUnsignedStakingTx.ts
|
|
3058
3198
|
var TAG5 = " | createUnsignedStakingTx | ";
|
|
3059
|
-
async function createUnsignedStakingTx(caip, params, pubkeys, pioneer,
|
|
3199
|
+
async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyContext) {
|
|
3060
3200
|
const tag5 = TAG5 + " | createUnsignedStakingTx | ";
|
|
3061
3201
|
try {
|
|
3062
3202
|
if (!pioneer)
|
|
3063
3203
|
throw new Error("Failed to init! pioneer");
|
|
3064
3204
|
const networkId = import_pioneer_caip5.caipToNetworkId(caip);
|
|
3065
|
-
if (!
|
|
3066
|
-
|
|
3205
|
+
if (!pubkeyContext) {
|
|
3206
|
+
throw new Error(`No pubkey context provided for networkId: ${networkId}`);
|
|
3067
3207
|
}
|
|
3068
|
-
if (!
|
|
3069
|
-
throw new Error(`
|
|
3208
|
+
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
3209
|
+
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
3070
3210
|
}
|
|
3211
|
+
console.log(tag5, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
3212
|
+
address: pubkeyContext.address
|
|
3213
|
+
});
|
|
3071
3214
|
let chain;
|
|
3072
3215
|
let chainId;
|
|
3073
3216
|
let denom;
|
|
@@ -3098,7 +3241,7 @@ async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, keepKeySd
|
|
|
3098
3241
|
throw new Error(`Unsupported networkId for staking: ${networkId}`);
|
|
3099
3242
|
}
|
|
3100
3243
|
console.log(tag5, `Building ${params.type} transaction for ${chain}`);
|
|
3101
|
-
const fromAddress =
|
|
3244
|
+
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
3102
3245
|
const accountInfo = (await pioneer.GetAccountInfo({ network: chain, address: fromAddress })).data;
|
|
3103
3246
|
console.log(tag5, "accountInfo: ", accountInfo);
|
|
3104
3247
|
let account_number;
|
|
@@ -3221,6 +3364,12 @@ function getNetworkName(networkId) {
|
|
|
3221
3364
|
};
|
|
3222
3365
|
return networkNames[networkId] || networkId;
|
|
3223
3366
|
}
|
|
3367
|
+
function withTimeout(promise, timeoutMs) {
|
|
3368
|
+
return Promise.race([
|
|
3369
|
+
promise,
|
|
3370
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Request timeout")), timeoutMs))
|
|
3371
|
+
]);
|
|
3372
|
+
}
|
|
3224
3373
|
async function getFees(pioneer, networkId) {
|
|
3225
3374
|
const tag5 = TAG6 + " | getFees | ";
|
|
3226
3375
|
try {
|
|
@@ -3230,10 +3379,6 @@ async function getFees(pioneer, networkId) {
|
|
|
3230
3379
|
console.log(tag5, "Using hardcoded fees for Cosmos network:", networkId);
|
|
3231
3380
|
return getCosmosFees(networkId);
|
|
3232
3381
|
}
|
|
3233
|
-
if (networkType === "RIPPLE") {
|
|
3234
|
-
console.log(tag5, "Using hardcoded fees for Ripple:", networkId);
|
|
3235
|
-
return getRippleFees(networkId);
|
|
3236
|
-
}
|
|
3237
3382
|
if (networkId === "bip122:00000000001a91e3dace36e2be3bf030") {
|
|
3238
3383
|
console.log(tag5, "Using hardcoded fees for Dogecoin: 10 sat/byte");
|
|
3239
3384
|
return {
|
|
@@ -3266,15 +3411,51 @@ async function getFees(pioneer, networkId) {
|
|
|
3266
3411
|
raw: { hardcoded: true, reason: "DOGE fee estimation unreliable" }
|
|
3267
3412
|
};
|
|
3268
3413
|
}
|
|
3269
|
-
|
|
3414
|
+
let feeResponse;
|
|
3415
|
+
if (networkId === "bip122:000007d91d1254d60e2dd1ae58038307") {
|
|
3416
|
+
try {
|
|
3417
|
+
const apiCall = pioneer.GetFeeRateByNetwork ? pioneer.GetFeeRateByNetwork({ networkId }) : pioneer.GetFeeRate({ networkId });
|
|
3418
|
+
feeResponse = await withTimeout(apiCall, 3000);
|
|
3419
|
+
} catch (timeoutError) {
|
|
3420
|
+
console.warn(tag5, "Dash fee API timeout, using fallback fees");
|
|
3421
|
+
return {
|
|
3422
|
+
slow: {
|
|
3423
|
+
label: "Economy",
|
|
3424
|
+
value: "5",
|
|
3425
|
+
unit: "sat/byte",
|
|
3426
|
+
description: "Low priority - 30+ minutes",
|
|
3427
|
+
estimatedTime: "~30 minutes",
|
|
3428
|
+
priority: "low"
|
|
3429
|
+
},
|
|
3430
|
+
average: {
|
|
3431
|
+
label: "Standard",
|
|
3432
|
+
value: "8",
|
|
3433
|
+
unit: "sat/byte",
|
|
3434
|
+
description: "Normal priority - 10-30 minutes",
|
|
3435
|
+
estimatedTime: "~15 minutes",
|
|
3436
|
+
priority: "medium"
|
|
3437
|
+
},
|
|
3438
|
+
fastest: {
|
|
3439
|
+
label: "Priority",
|
|
3440
|
+
value: "10",
|
|
3441
|
+
unit: "sat/byte",
|
|
3442
|
+
description: "High priority - next block",
|
|
3443
|
+
estimatedTime: "~5 minutes",
|
|
3444
|
+
priority: "high"
|
|
3445
|
+
},
|
|
3446
|
+
networkId,
|
|
3447
|
+
networkType: "UTXO",
|
|
3448
|
+
raw: { hardcoded: true, reason: "Dash API timeout, using conservative fallback fees" }
|
|
3449
|
+
};
|
|
3450
|
+
}
|
|
3451
|
+
} else {
|
|
3452
|
+
feeResponse = await (pioneer.GetFeeRateByNetwork ? pioneer.GetFeeRateByNetwork({ networkId }) : pioneer.GetFeeRate({ networkId }));
|
|
3453
|
+
}
|
|
3270
3454
|
if (!feeResponse || !feeResponse.data) {
|
|
3271
3455
|
throw new Error(`No fee data returned for ${networkId}`);
|
|
3272
3456
|
}
|
|
3273
3457
|
const feeData = feeResponse.data;
|
|
3274
3458
|
console.log(tag5, "Raw fee data:", feeData);
|
|
3275
|
-
if (feeData.success === false || feeData.error) {
|
|
3276
|
-
throw new Error(feeData.error || `API error for ${networkId}`);
|
|
3277
|
-
}
|
|
3278
3459
|
const networkName = getNetworkName(networkId);
|
|
3279
3460
|
let normalizedFees = normalizeFeeData(feeData, networkType, networkName, networkId);
|
|
3280
3461
|
normalizedFees = ensureFeeDifferentiation(normalizedFees, networkType);
|
|
@@ -3480,7 +3661,7 @@ function getCosmosFees(networkId) {
|
|
|
3480
3661
|
const networkName = getNetworkName(networkId);
|
|
3481
3662
|
const cosmosFeesMap = {
|
|
3482
3663
|
"cosmos:thorchain-mainnet-v1": { base: 0.02, unit: "RUNE", denom: "rune" },
|
|
3483
|
-
"cosmos:mayachain-mainnet-v1": { base: 0.
|
|
3664
|
+
"cosmos:mayachain-mainnet-v1": { base: 0.5, unit: "CACAO", denom: "cacao" },
|
|
3484
3665
|
"cosmos:cosmoshub-4": { base: 0.005, unit: "ATOM", denom: "uatom" },
|
|
3485
3666
|
"cosmos:osmosis-1": { base: 0.035, unit: "OSMO", denom: "uosmo" }
|
|
3486
3667
|
};
|
|
@@ -3518,39 +3699,6 @@ function getCosmosFees(networkId) {
|
|
|
3518
3699
|
raw: { hardcoded: true, base: feeConfig.base, unit: feeConfig.unit, denom: feeConfig.denom }
|
|
3519
3700
|
};
|
|
3520
3701
|
}
|
|
3521
|
-
function getRippleFees(networkId) {
|
|
3522
|
-
const networkName = getNetworkName(networkId);
|
|
3523
|
-
const baseFee = "0.00001";
|
|
3524
|
-
return {
|
|
3525
|
-
slow: {
|
|
3526
|
-
label: "Standard",
|
|
3527
|
-
value: baseFee,
|
|
3528
|
-
unit: "XRP",
|
|
3529
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3530
|
-
estimatedTime: "~4 seconds",
|
|
3531
|
-
priority: "low"
|
|
3532
|
-
},
|
|
3533
|
-
average: {
|
|
3534
|
-
label: "Standard",
|
|
3535
|
-
value: baseFee,
|
|
3536
|
-
unit: "XRP",
|
|
3537
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3538
|
-
estimatedTime: "~4 seconds",
|
|
3539
|
-
priority: "medium"
|
|
3540
|
-
},
|
|
3541
|
-
fastest: {
|
|
3542
|
-
label: "Standard",
|
|
3543
|
-
value: baseFee,
|
|
3544
|
-
unit: "XRP",
|
|
3545
|
-
description: `Fixed network fee for ${networkName}. All transactions use the same fee.`,
|
|
3546
|
-
estimatedTime: "~4 seconds",
|
|
3547
|
-
priority: "high"
|
|
3548
|
-
},
|
|
3549
|
-
networkId,
|
|
3550
|
-
networkType: "RIPPLE",
|
|
3551
|
-
raw: { hardcoded: true, baseFee, reason: "Ripple uses fixed network fees" }
|
|
3552
|
-
};
|
|
3553
|
-
}
|
|
3554
3702
|
function getFallbackFees(networkId) {
|
|
3555
3703
|
const networkType = getNetworkType(networkId);
|
|
3556
3704
|
const networkName = getNetworkName(networkId);
|
|
@@ -3624,9 +3772,10 @@ function estimateTransactionFee(feeRate, unit, networkType, txSize) {
|
|
|
3624
3772
|
}
|
|
3625
3773
|
}
|
|
3626
3774
|
|
|
3627
|
-
// src/
|
|
3775
|
+
// src/index.ts
|
|
3776
|
+
var TAG7 = " | Pioneer-sdk | ";
|
|
3628
3777
|
async function detectKkApiAvailability(forceLocalhost) {
|
|
3629
|
-
const tag5 =
|
|
3778
|
+
const tag5 = `${TAG7} | detectKkApiAvailability | `;
|
|
3630
3779
|
try {
|
|
3631
3780
|
const isTauri = typeof window !== "undefined" && "__TAURI__" in window;
|
|
3632
3781
|
const isBrowser = typeof window !== "undefined";
|
|
@@ -3673,8 +3822,6 @@ async function detectKkApiAvailability(forceLocalhost) {
|
|
|
3673
3822
|
};
|
|
3674
3823
|
}
|
|
3675
3824
|
}
|
|
3676
|
-
|
|
3677
|
-
// src/utils/format-time.ts
|
|
3678
3825
|
function formatTime(durationMs) {
|
|
3679
3826
|
let seconds = Math.floor(durationMs / 1000 % 60);
|
|
3680
3827
|
let minutes = Math.floor(durationMs / (1000 * 60) % 60);
|
|
@@ -3688,150 +3835,6 @@ function formatTime(durationMs) {
|
|
|
3688
3835
|
return formatted.trim();
|
|
3689
3836
|
}
|
|
3690
3837
|
|
|
3691
|
-
// src/utils/build-dashboard.ts
|
|
3692
|
-
var import_pioneer_caip6 = require("@pioneer-platform/pioneer-caip");
|
|
3693
|
-
var TAG7 = " | build-dashboard | ";
|
|
3694
|
-
function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
3695
|
-
console.log(TAG7, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3696
|
-
const dashboardData = {
|
|
3697
|
-
networks: [],
|
|
3698
|
-
totalValueUsd: 0,
|
|
3699
|
-
networkPercentages: []
|
|
3700
|
-
};
|
|
3701
|
-
let totalPortfolioValue = 0;
|
|
3702
|
-
const networksTemp = [];
|
|
3703
|
-
console.log(TAG7, "balances: ", balances);
|
|
3704
|
-
for (const blockchain of blockchains) {
|
|
3705
|
-
const filteredBalances = balances.filter((b2) => {
|
|
3706
|
-
const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
|
|
3707
|
-
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
3708
|
-
});
|
|
3709
|
-
const balanceMap = new Map;
|
|
3710
|
-
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
3711
|
-
if (isBitcoin) {
|
|
3712
|
-
console.log(TAG7, "Bitcoin network detected - checking for duplicate balances");
|
|
3713
|
-
const bitcoinByValue = new Map;
|
|
3714
|
-
filteredBalances.forEach((balance) => {
|
|
3715
|
-
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
3716
|
-
if (!bitcoinByValue.has(valueKey)) {
|
|
3717
|
-
bitcoinByValue.set(valueKey, []);
|
|
3718
|
-
}
|
|
3719
|
-
bitcoinByValue.get(valueKey).push(balance);
|
|
3720
|
-
});
|
|
3721
|
-
for (const [valueKey, balances2] of bitcoinByValue.entries()) {
|
|
3722
|
-
if (balances2.length === 3 && parseFloat(balances2[0].valueUsd || "0") > 0) {
|
|
3723
|
-
console.log(TAG7, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
3724
|
-
const xpubBalance = balances2.find((b2) => b2.pubkey?.startsWith("xpub")) || balances2[0];
|
|
3725
|
-
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
3726
|
-
balanceMap.set(key, xpubBalance);
|
|
3727
|
-
} else {
|
|
3728
|
-
balances2.forEach((balance) => {
|
|
3729
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3730
|
-
balanceMap.set(key, balance);
|
|
3731
|
-
});
|
|
3732
|
-
}
|
|
3733
|
-
}
|
|
3734
|
-
} else {
|
|
3735
|
-
filteredBalances.forEach((balance) => {
|
|
3736
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3737
|
-
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
3738
|
-
balanceMap.set(key, balance);
|
|
3739
|
-
}
|
|
3740
|
-
});
|
|
3741
|
-
}
|
|
3742
|
-
const networkBalances = Array.from(balanceMap.values());
|
|
3743
|
-
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
3744
|
-
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
3745
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
3746
|
-
console.log(TAG7, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
3747
|
-
}
|
|
3748
|
-
return sum + valueUsd;
|
|
3749
|
-
}, 0);
|
|
3750
|
-
const nativeAssetCaip = import_pioneer_caip6.networkIdToCaip(blockchain);
|
|
3751
|
-
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
3752
|
-
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
3753
|
-
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
3754
|
-
return sum + balanceNum;
|
|
3755
|
-
}, 0).toString();
|
|
3756
|
-
const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
|
|
3757
|
-
networksTemp.push({
|
|
3758
|
-
networkId: blockchain,
|
|
3759
|
-
totalValueUsd: networkTotal,
|
|
3760
|
-
gasAssetCaip: nativeAssetCaip || null,
|
|
3761
|
-
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
3762
|
-
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
3763
|
-
color: gasAsset?.color || assetInfo?.color || null,
|
|
3764
|
-
totalNativeBalance
|
|
3765
|
-
});
|
|
3766
|
-
totalPortfolioValue += networkTotal;
|
|
3767
|
-
}
|
|
3768
|
-
dashboardData.networks = networksTemp.sort((a, b2) => b2.totalValueUsd - a.totalValueUsd);
|
|
3769
|
-
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
3770
|
-
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
3771
|
-
networkId: network.networkId,
|
|
3772
|
-
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
3773
|
-
})).filter((entry) => entry.percentage > 0);
|
|
3774
|
-
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
3775
|
-
return dashboardData;
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
// src/utils/pubkey-helpers.ts
|
|
3779
|
-
function getPubkeyKey(pubkey) {
|
|
3780
|
-
return `${pubkey.pubkey}_${pubkey.pathMaster}`;
|
|
3781
|
-
}
|
|
3782
|
-
function deduplicatePubkeys(pubkeys) {
|
|
3783
|
-
const seen = new Set;
|
|
3784
|
-
const deduped = pubkeys.filter((pubkey) => {
|
|
3785
|
-
const key = getPubkeyKey(pubkey);
|
|
3786
|
-
if (seen.has(key)) {
|
|
3787
|
-
return false;
|
|
3788
|
-
}
|
|
3789
|
-
seen.add(key);
|
|
3790
|
-
return true;
|
|
3791
|
-
});
|
|
3792
|
-
return deduped;
|
|
3793
|
-
}
|
|
3794
|
-
function validatePubkey(pubkey) {
|
|
3795
|
-
return !!(pubkey.pubkey && pubkey.pathMaster);
|
|
3796
|
-
}
|
|
3797
|
-
|
|
3798
|
-
class PubkeyManager {
|
|
3799
|
-
pubkeys = [];
|
|
3800
|
-
pubkeySet = new Set;
|
|
3801
|
-
addPubkey(pubkey) {
|
|
3802
|
-
if (!validatePubkey(pubkey)) {
|
|
3803
|
-
return false;
|
|
3804
|
-
}
|
|
3805
|
-
const key = getPubkeyKey(pubkey);
|
|
3806
|
-
if (this.pubkeySet.has(key)) {
|
|
3807
|
-
return false;
|
|
3808
|
-
}
|
|
3809
|
-
this.pubkeys.push(pubkey);
|
|
3810
|
-
this.pubkeySet.add(key);
|
|
3811
|
-
return true;
|
|
3812
|
-
}
|
|
3813
|
-
setPubkeys(newPubkeys) {
|
|
3814
|
-
this.pubkeys = [];
|
|
3815
|
-
this.pubkeySet.clear();
|
|
3816
|
-
let added = 0;
|
|
3817
|
-
for (const pubkey of newPubkeys) {
|
|
3818
|
-
if (this.addPubkey(pubkey)) {
|
|
3819
|
-
added++;
|
|
3820
|
-
}
|
|
3821
|
-
}
|
|
3822
|
-
}
|
|
3823
|
-
getPubkeys() {
|
|
3824
|
-
return this.pubkeys;
|
|
3825
|
-
}
|
|
3826
|
-
clear() {
|
|
3827
|
-
this.pubkeys = [];
|
|
3828
|
-
this.pubkeySet.clear();
|
|
3829
|
-
}
|
|
3830
|
-
}
|
|
3831
|
-
|
|
3832
|
-
// src/index.ts
|
|
3833
|
-
var TAG8 = " | Pioneer-sdk | ";
|
|
3834
|
-
|
|
3835
3838
|
class SDK {
|
|
3836
3839
|
status;
|
|
3837
3840
|
username;
|
|
@@ -3855,7 +3858,7 @@ class SDK {
|
|
|
3855
3858
|
charts;
|
|
3856
3859
|
paths;
|
|
3857
3860
|
pubkeys = [];
|
|
3858
|
-
|
|
3861
|
+
pubkeySet = new Set;
|
|
3859
3862
|
wallets;
|
|
3860
3863
|
balances;
|
|
3861
3864
|
nodes;
|
|
@@ -3932,11 +3935,10 @@ class SDK {
|
|
|
3932
3935
|
if (config.blockchains && config.blockchains.length !== this.blockchains.length) {
|
|
3933
3936
|
}
|
|
3934
3937
|
if (config.pubkeys && config.pubkeys.length > 0) {
|
|
3935
|
-
this.
|
|
3936
|
-
this.pubkeys = this.pubkeyManager.getPubkeys();
|
|
3938
|
+
this.setPubkeys(config.pubkeys);
|
|
3937
3939
|
} else {
|
|
3938
3940
|
this.pubkeys = [];
|
|
3939
|
-
this.
|
|
3941
|
+
this.pubkeySet.clear();
|
|
3940
3942
|
}
|
|
3941
3943
|
this.balances = config.balances || [];
|
|
3942
3944
|
this.nodes = config.nodes || [];
|
|
@@ -3952,7 +3954,7 @@ class SDK {
|
|
|
3952
3954
|
this.outboundBlockchainContext = null;
|
|
3953
3955
|
this.outboundPubkeyContext = null;
|
|
3954
3956
|
this.wallets = [];
|
|
3955
|
-
this.events = new import_events.
|
|
3957
|
+
this.events = new import_events.default;
|
|
3956
3958
|
this.transactions = null;
|
|
3957
3959
|
this.ethplorerApiKey = config.ethplorerApiKey;
|
|
3958
3960
|
this.covalentApiKey = config.covalentApiKey;
|
|
@@ -3967,21 +3969,46 @@ class SDK {
|
|
|
3967
3969
|
this.pairWallet = async (options) => {
|
|
3968
3970
|
return Promise.resolve({});
|
|
3969
3971
|
};
|
|
3970
|
-
this.getPubkeyKey =
|
|
3971
|
-
|
|
3972
|
+
this.getPubkeyKey = (pubkey) => {
|
|
3973
|
+
return `${pubkey.pubkey}_${pubkey.pathMaster}`;
|
|
3974
|
+
};
|
|
3975
|
+
this.deduplicatePubkeys = (pubkeys) => {
|
|
3976
|
+
const seen = new Set;
|
|
3977
|
+
const deduped = pubkeys.filter((pubkey) => {
|
|
3978
|
+
const key = this.getPubkeyKey(pubkey);
|
|
3979
|
+
if (seen.has(key)) {
|
|
3980
|
+
return false;
|
|
3981
|
+
}
|
|
3982
|
+
seen.add(key);
|
|
3983
|
+
return true;
|
|
3984
|
+
});
|
|
3985
|
+
return deduped;
|
|
3986
|
+
};
|
|
3972
3987
|
this.addPubkey = (pubkey) => {
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3988
|
+
if (!pubkey.pubkey || !pubkey.pathMaster) {
|
|
3989
|
+
return false;
|
|
3990
|
+
}
|
|
3991
|
+
const key = this.getPubkeyKey(pubkey);
|
|
3992
|
+
if (this.pubkeySet.has(key)) {
|
|
3993
|
+
return false;
|
|
3976
3994
|
}
|
|
3977
|
-
|
|
3995
|
+
this.pubkeys.push(pubkey);
|
|
3996
|
+
this.pubkeySet.add(key);
|
|
3997
|
+
return true;
|
|
3978
3998
|
};
|
|
3979
3999
|
this.setPubkeys = (newPubkeys) => {
|
|
3980
|
-
|
|
3981
|
-
this.pubkeys =
|
|
4000
|
+
const tag5 = `${TAG7} | setPubkeys | `;
|
|
4001
|
+
this.pubkeys = [];
|
|
4002
|
+
this.pubkeySet.clear();
|
|
4003
|
+
let added = 0;
|
|
4004
|
+
for (const pubkey of newPubkeys) {
|
|
4005
|
+
if (this.addPubkey(pubkey)) {
|
|
4006
|
+
added++;
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
3982
4009
|
};
|
|
3983
4010
|
this.getUnifiedPortfolio = async function() {
|
|
3984
|
-
const tag5 = `${
|
|
4011
|
+
const tag5 = `${TAG7} | getUnifiedPortfolio | `;
|
|
3985
4012
|
try {
|
|
3986
4013
|
const startTime = performance.now();
|
|
3987
4014
|
try {
|
|
@@ -4013,9 +4040,8 @@ class SDK {
|
|
|
4013
4040
|
this.events.emit("SET_BALANCES", this.balances);
|
|
4014
4041
|
}
|
|
4015
4042
|
if (portfolioData.pubkeys && portfolioData.pubkeys.length > 0) {
|
|
4016
|
-
const convertedPubkeys = portfolioData.pubkeys;
|
|
4017
|
-
this.
|
|
4018
|
-
this.pubkeys = this.pubkeyManager.getPubkeys();
|
|
4043
|
+
const convertedPubkeys = this.convertVaultPubkeysToPioneerFormat(portfolioData.pubkeys);
|
|
4044
|
+
this.setPubkeys(convertedPubkeys);
|
|
4019
4045
|
this.events.emit("SET_PUBKEYS", this.pubkeys);
|
|
4020
4046
|
}
|
|
4021
4047
|
if (portfolioData.devices && portfolioData.devices.length > 0) {
|
|
@@ -4065,7 +4091,7 @@ class SDK {
|
|
|
4065
4091
|
this.events.emit("SET_DASHBOARD", this.dashboard);
|
|
4066
4092
|
} else {
|
|
4067
4093
|
console.warn("[CACHE VALIDATION] ❌ Cache data corrupted, building dashboard from cached balances");
|
|
4068
|
-
const dashboardData = buildDashboardFromBalances(
|
|
4094
|
+
const dashboardData = this.buildDashboardFromBalances();
|
|
4069
4095
|
this.dashboard = dashboardData;
|
|
4070
4096
|
this.events.emit("SET_DASHBOARD", this.dashboard);
|
|
4071
4097
|
}
|
|
@@ -4090,7 +4116,7 @@ class SDK {
|
|
|
4090
4116
|
}
|
|
4091
4117
|
};
|
|
4092
4118
|
this.init = async function(walletsVerbose, setup) {
|
|
4093
|
-
const tag5 = `${
|
|
4119
|
+
const tag5 = `${TAG7} | init | `;
|
|
4094
4120
|
try {
|
|
4095
4121
|
if (!this.username)
|
|
4096
4122
|
throw Error("username required!");
|
|
@@ -4107,7 +4133,7 @@ class SDK {
|
|
|
4107
4133
|
const pioneerConfig = {
|
|
4108
4134
|
...config
|
|
4109
4135
|
};
|
|
4110
|
-
const PioneerClient = new import_pioneer_client.
|
|
4136
|
+
const PioneerClient = new import_pioneer_client.default(this.spec, pioneerConfig);
|
|
4111
4137
|
this.pioneer = await PioneerClient.init();
|
|
4112
4138
|
if (!this.pioneer)
|
|
4113
4139
|
throw Error("Failed to init pioneer server!");
|
|
@@ -4177,11 +4203,92 @@ class SDK {
|
|
|
4177
4203
|
throw e;
|
|
4178
4204
|
}
|
|
4179
4205
|
};
|
|
4180
|
-
this.buildDashboardFromBalances = ()
|
|
4181
|
-
|
|
4206
|
+
this.buildDashboardFromBalances = function() {
|
|
4207
|
+
const tag5 = `${TAG7} | buildDashboardFromBalances | `;
|
|
4208
|
+
console.log(tag5, "[DASHBOARD] Building dashboard from cached balances...");
|
|
4209
|
+
const dashboardData = {
|
|
4210
|
+
networks: [],
|
|
4211
|
+
totalValueUsd: 0,
|
|
4212
|
+
networkPercentages: []
|
|
4213
|
+
};
|
|
4214
|
+
let totalPortfolioValue = 0;
|
|
4215
|
+
const networksTemp = [];
|
|
4216
|
+
console.log(tag5, "this.balances: ", this.balances);
|
|
4217
|
+
for (const blockchain of this.blockchains) {
|
|
4218
|
+
const filteredBalances = this.balances.filter((b2) => {
|
|
4219
|
+
const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
|
|
4220
|
+
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4221
|
+
});
|
|
4222
|
+
const balanceMap = new Map;
|
|
4223
|
+
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
4224
|
+
if (isBitcoin) {
|
|
4225
|
+
console.log(tag5, "Bitcoin network detected - checking for duplicate balances");
|
|
4226
|
+
const bitcoinByValue = new Map;
|
|
4227
|
+
filteredBalances.forEach((balance) => {
|
|
4228
|
+
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
4229
|
+
if (!bitcoinByValue.has(valueKey)) {
|
|
4230
|
+
bitcoinByValue.set(valueKey, []);
|
|
4231
|
+
}
|
|
4232
|
+
bitcoinByValue.get(valueKey).push(balance);
|
|
4233
|
+
});
|
|
4234
|
+
for (const [valueKey, balances] of bitcoinByValue.entries()) {
|
|
4235
|
+
if (balances.length === 3 && parseFloat(balances[0].valueUsd || "0") > 0) {
|
|
4236
|
+
console.log(tag5, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
4237
|
+
const xpubBalance = balances.find((b2) => b2.pubkey?.startsWith("xpub")) || balances[0];
|
|
4238
|
+
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
4239
|
+
balanceMap.set(key, xpubBalance);
|
|
4240
|
+
} else {
|
|
4241
|
+
balances.forEach((balance) => {
|
|
4242
|
+
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
4243
|
+
balanceMap.set(key, balance);
|
|
4244
|
+
});
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4247
|
+
} else {
|
|
4248
|
+
filteredBalances.forEach((balance) => {
|
|
4249
|
+
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
4250
|
+
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
4251
|
+
balanceMap.set(key, balance);
|
|
4252
|
+
}
|
|
4253
|
+
});
|
|
4254
|
+
}
|
|
4255
|
+
const networkBalances = Array.from(balanceMap.values());
|
|
4256
|
+
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
4257
|
+
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
4258
|
+
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
4259
|
+
console.log(tag5, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
4260
|
+
}
|
|
4261
|
+
return sum + valueUsd;
|
|
4262
|
+
}, 0);
|
|
4263
|
+
const nativeAssetCaip = import_pioneer_caip6.networkIdToCaip(blockchain);
|
|
4264
|
+
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
4265
|
+
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4266
|
+
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
4267
|
+
return sum + balanceNum;
|
|
4268
|
+
}, 0).toString();
|
|
4269
|
+
const assetInfo = nativeAssetCaip ? this.assetsMap.get(nativeAssetCaip) : null;
|
|
4270
|
+
networksTemp.push({
|
|
4271
|
+
networkId: blockchain,
|
|
4272
|
+
totalValueUsd: networkTotal,
|
|
4273
|
+
gasAssetCaip: nativeAssetCaip || null,
|
|
4274
|
+
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
4275
|
+
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
4276
|
+
color: gasAsset?.color || assetInfo?.color || null,
|
|
4277
|
+
totalNativeBalance
|
|
4278
|
+
});
|
|
4279
|
+
totalPortfolioValue += networkTotal;
|
|
4280
|
+
}
|
|
4281
|
+
dashboardData.networks = networksTemp.sort((a, b2) => b2.totalValueUsd - a.totalValueUsd);
|
|
4282
|
+
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
4283
|
+
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
4284
|
+
networkId: network.networkId,
|
|
4285
|
+
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
4286
|
+
})).filter((entry) => entry.percentage > 0);
|
|
4287
|
+
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
4288
|
+
return dashboardData;
|
|
4182
4289
|
};
|
|
4183
4290
|
this.syncMarket = async function() {
|
|
4184
|
-
const tag5 = `${
|
|
4291
|
+
const tag5 = `${TAG7} | syncMarket | `;
|
|
4185
4292
|
try {
|
|
4186
4293
|
const invalidBalances = this.balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
4187
4294
|
if (invalidBalances.length > 0) {
|
|
@@ -4232,7 +4339,7 @@ class SDK {
|
|
|
4232
4339
|
}
|
|
4233
4340
|
};
|
|
4234
4341
|
this.sync = async function() {
|
|
4235
|
-
const tag5 = `${
|
|
4342
|
+
const tag5 = `${TAG7} | sync | `;
|
|
4236
4343
|
try {
|
|
4237
4344
|
const matchesNetwork = (item, networkId) => {
|
|
4238
4345
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4287,7 +4394,7 @@ class SDK {
|
|
|
4287
4394
|
console.log(tag5, "uniqueBlockchains: ", uniqueBlockchains);
|
|
4288
4395
|
for (const blockchain of uniqueBlockchains) {
|
|
4289
4396
|
const filteredBalances = this.balances.filter((b2) => {
|
|
4290
|
-
const networkId =
|
|
4397
|
+
const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
|
|
4291
4398
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4292
4399
|
});
|
|
4293
4400
|
console.log(tag5, `Filtering for blockchain: ${blockchain}`);
|
|
@@ -4345,7 +4452,7 @@ class SDK {
|
|
|
4345
4452
|
return sum + valueUsd;
|
|
4346
4453
|
}, 0);
|
|
4347
4454
|
console.log("Final networkTotal:", networkTotal);
|
|
4348
|
-
const nativeAssetCaip =
|
|
4455
|
+
const nativeAssetCaip = import_pioneer_caip6.networkIdToCaip(blockchain);
|
|
4349
4456
|
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
4350
4457
|
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4351
4458
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
@@ -4385,7 +4492,7 @@ class SDK {
|
|
|
4385
4492
|
}
|
|
4386
4493
|
};
|
|
4387
4494
|
this.buildTx = async function(sendPayload) {
|
|
4388
|
-
let tag5 =
|
|
4495
|
+
let tag5 = TAG7 + " | buildTx | ";
|
|
4389
4496
|
try {
|
|
4390
4497
|
const transactionDependencies = {
|
|
4391
4498
|
context: this.context,
|
|
@@ -4393,6 +4500,7 @@ class SDK {
|
|
|
4393
4500
|
balances: this.balances,
|
|
4394
4501
|
pioneer: this.pioneer,
|
|
4395
4502
|
pubkeys: this.pubkeys,
|
|
4503
|
+
pubkeyContext: this.pubkeyContext,
|
|
4396
4504
|
nodes: this.nodes,
|
|
4397
4505
|
keepKeySdk: this.keepKeySdk
|
|
4398
4506
|
};
|
|
@@ -4406,13 +4514,13 @@ class SDK {
|
|
|
4406
4514
|
}
|
|
4407
4515
|
};
|
|
4408
4516
|
this.buildDelegateTx = async function(caip, params) {
|
|
4409
|
-
let tag5 =
|
|
4517
|
+
let tag5 = TAG7 + " | buildDelegateTx | ";
|
|
4410
4518
|
try {
|
|
4411
4519
|
const delegateParams = {
|
|
4412
4520
|
...params,
|
|
4413
4521
|
type: "delegate"
|
|
4414
4522
|
};
|
|
4415
|
-
let unsignedTx = await createUnsignedStakingTx(caip, delegateParams, this.pubkeys, this.pioneer, this.
|
|
4523
|
+
let unsignedTx = await createUnsignedStakingTx(caip, delegateParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4416
4524
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4417
4525
|
return unsignedTx;
|
|
4418
4526
|
} catch (e) {
|
|
@@ -4421,13 +4529,13 @@ class SDK {
|
|
|
4421
4529
|
}
|
|
4422
4530
|
};
|
|
4423
4531
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4424
|
-
let tag5 =
|
|
4532
|
+
let tag5 = TAG7 + " | buildUndelegateTx | ";
|
|
4425
4533
|
try {
|
|
4426
4534
|
const undelegateParams = {
|
|
4427
4535
|
...params,
|
|
4428
4536
|
type: "undelegate"
|
|
4429
4537
|
};
|
|
4430
|
-
let unsignedTx = await createUnsignedStakingTx(caip, undelegateParams, this.pubkeys, this.pioneer, this.
|
|
4538
|
+
let unsignedTx = await createUnsignedStakingTx(caip, undelegateParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4431
4539
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4432
4540
|
return unsignedTx;
|
|
4433
4541
|
} catch (e) {
|
|
@@ -4436,13 +4544,13 @@ class SDK {
|
|
|
4436
4544
|
}
|
|
4437
4545
|
};
|
|
4438
4546
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4439
|
-
let tag5 =
|
|
4547
|
+
let tag5 = TAG7 + " | buildClaimRewardsTx | ";
|
|
4440
4548
|
try {
|
|
4441
4549
|
const claimParams = {
|
|
4442
4550
|
...params,
|
|
4443
4551
|
type: "claim_rewards"
|
|
4444
4552
|
};
|
|
4445
|
-
let unsignedTx = await createUnsignedStakingTx(caip, claimParams, this.pubkeys, this.pioneer, this.
|
|
4553
|
+
let unsignedTx = await createUnsignedStakingTx(caip, claimParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4446
4554
|
console.log(tag5, "unsignedTx: ", unsignedTx);
|
|
4447
4555
|
return unsignedTx;
|
|
4448
4556
|
} catch (e) {
|
|
@@ -4451,13 +4559,13 @@ class SDK {
|
|
|
4451
4559
|
}
|
|
4452
4560
|
};
|
|
4453
4561
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4454
|
-
let tag5 =
|
|
4562
|
+
let tag5 = TAG7 + " | buildClaimAllRewardsTx | ";
|
|
4455
4563
|
try {
|
|
4456
4564
|
const claimAllParams = {
|
|
4457
4565
|
...params,
|
|
4458
4566
|
type: "claim_all_rewards"
|
|
4459
4567
|
};
|
|
4460
|
-
let unsignedTx = await createUnsignedStakingTx(caip, claimAllParams, this.pubkeys, this.pioneer, this.
|
|
4568
|
+
let unsignedTx = await createUnsignedStakingTx(caip, claimAllParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4461
4569
|
return unsignedTx;
|
|
4462
4570
|
} catch (e) {
|
|
4463
4571
|
console.error(e);
|
|
@@ -4465,7 +4573,7 @@ class SDK {
|
|
|
4465
4573
|
}
|
|
4466
4574
|
};
|
|
4467
4575
|
this.signTx = async function(unsignedTx) {
|
|
4468
|
-
let tag5 =
|
|
4576
|
+
let tag5 = TAG7 + " | signTx | ";
|
|
4469
4577
|
try {
|
|
4470
4578
|
const transactionDependencies = {
|
|
4471
4579
|
context: this.context,
|
|
@@ -4473,6 +4581,7 @@ class SDK {
|
|
|
4473
4581
|
balances: this.balances,
|
|
4474
4582
|
pioneer: this.pioneer,
|
|
4475
4583
|
pubkeys: this.pubkeys,
|
|
4584
|
+
pubkeyContext: this.pubkeyContext,
|
|
4476
4585
|
nodes: this.nodes,
|
|
4477
4586
|
keepKeySdk: this.keepKeySdk
|
|
4478
4587
|
};
|
|
@@ -4485,7 +4594,7 @@ class SDK {
|
|
|
4485
4594
|
}
|
|
4486
4595
|
};
|
|
4487
4596
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4488
|
-
let tag5 =
|
|
4597
|
+
let tag5 = TAG7 + " | broadcastTx | ";
|
|
4489
4598
|
try {
|
|
4490
4599
|
const transactionDependencies = {
|
|
4491
4600
|
context: this.context,
|
|
@@ -4498,7 +4607,7 @@ class SDK {
|
|
|
4498
4607
|
};
|
|
4499
4608
|
let txManager = new TransactionManager(transactionDependencies, this.events);
|
|
4500
4609
|
let payload = {
|
|
4501
|
-
networkId:
|
|
4610
|
+
networkId: import_pioneer_caip6.caipToNetworkId(caip),
|
|
4502
4611
|
serialized: signedTx
|
|
4503
4612
|
};
|
|
4504
4613
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4509,7 +4618,7 @@ class SDK {
|
|
|
4509
4618
|
}
|
|
4510
4619
|
};
|
|
4511
4620
|
this.swap = async function(swapPayload) {
|
|
4512
|
-
let tag5 = `${
|
|
4621
|
+
let tag5 = `${TAG7} | swap | `;
|
|
4513
4622
|
try {
|
|
4514
4623
|
if (!swapPayload)
|
|
4515
4624
|
throw Error("swapPayload required!");
|
|
@@ -4644,7 +4753,7 @@ class SDK {
|
|
|
4644
4753
|
}
|
|
4645
4754
|
};
|
|
4646
4755
|
this.transfer = async function(sendPayload) {
|
|
4647
|
-
let tag5 = `${
|
|
4756
|
+
let tag5 = `${TAG7} | transfer | `;
|
|
4648
4757
|
try {
|
|
4649
4758
|
if (!sendPayload)
|
|
4650
4759
|
throw Error("sendPayload required!");
|
|
@@ -4671,7 +4780,7 @@ class SDK {
|
|
|
4671
4780
|
if (!signedTx)
|
|
4672
4781
|
throw Error("Failed to sign transaction!");
|
|
4673
4782
|
let payload = {
|
|
4674
|
-
networkId:
|
|
4783
|
+
networkId: import_pioneer_caip6.caipToNetworkId(caip),
|
|
4675
4784
|
serialized: signedTx
|
|
4676
4785
|
};
|
|
4677
4786
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4700,7 +4809,7 @@ class SDK {
|
|
|
4700
4809
|
while (!isConfirmed) {
|
|
4701
4810
|
try {
|
|
4702
4811
|
const response = await this.pioneer.LookupTx({
|
|
4703
|
-
networkId:
|
|
4812
|
+
networkId: import_pioneer_caip6.caipToNetworkId(caip),
|
|
4704
4813
|
txid
|
|
4705
4814
|
});
|
|
4706
4815
|
if (response?.data?.data) {
|
|
@@ -4739,7 +4848,7 @@ class SDK {
|
|
|
4739
4848
|
}
|
|
4740
4849
|
};
|
|
4741
4850
|
this.setBlockchains = async function(blockchains) {
|
|
4742
|
-
const tag5 = `${
|
|
4851
|
+
const tag5 = `${TAG7} | setBlockchains | `;
|
|
4743
4852
|
try {
|
|
4744
4853
|
if (!blockchains)
|
|
4745
4854
|
throw Error("blockchains required!");
|
|
@@ -4755,7 +4864,7 @@ class SDK {
|
|
|
4755
4864
|
}
|
|
4756
4865
|
};
|
|
4757
4866
|
this.addAsset = async function(caip, data) {
|
|
4758
|
-
let tag5 =
|
|
4867
|
+
let tag5 = TAG7 + " | addAsset | ";
|
|
4759
4868
|
try {
|
|
4760
4869
|
let success = false;
|
|
4761
4870
|
if (!caip)
|
|
@@ -4793,7 +4902,7 @@ class SDK {
|
|
|
4793
4902
|
}
|
|
4794
4903
|
};
|
|
4795
4904
|
this.clearWalletState = async function() {
|
|
4796
|
-
const tag5 = `${
|
|
4905
|
+
const tag5 = `${TAG7} | clearWalletState | `;
|
|
4797
4906
|
try {
|
|
4798
4907
|
this.context = null;
|
|
4799
4908
|
this.paths = [];
|
|
@@ -4807,15 +4916,62 @@ class SDK {
|
|
|
4807
4916
|
throw e;
|
|
4808
4917
|
}
|
|
4809
4918
|
};
|
|
4919
|
+
this.addPath = async function(path) {
|
|
4920
|
+
const tag5 = `${TAG7} | addPath | `;
|
|
4921
|
+
try {
|
|
4922
|
+
this.paths.push(path);
|
|
4923
|
+
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
4924
|
+
this.addPubkey(pubkey);
|
|
4925
|
+
await this.getBalancesForNetworks(path.networks);
|
|
4926
|
+
this.buildDashboardFromBalances();
|
|
4927
|
+
return { success: true, pubkey };
|
|
4928
|
+
} catch (e) {
|
|
4929
|
+
console.error(tag5, "Failed:", e);
|
|
4930
|
+
throw e;
|
|
4931
|
+
}
|
|
4932
|
+
};
|
|
4933
|
+
this.addPaths = async function(paths) {
|
|
4934
|
+
const tag5 = `${TAG7} | addPaths | `;
|
|
4935
|
+
try {
|
|
4936
|
+
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4937
|
+
this.paths.push(...paths);
|
|
4938
|
+
const newPubkeys = [];
|
|
4939
|
+
for (const path of paths) {
|
|
4940
|
+
try {
|
|
4941
|
+
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
4942
|
+
this.addPubkey(pubkey);
|
|
4943
|
+
newPubkeys.push(pubkey);
|
|
4944
|
+
} catch (error) {
|
|
4945
|
+
console.warn(tag5, `Failed to get pubkey for path ${path.note}:`, error.message);
|
|
4946
|
+
}
|
|
4947
|
+
}
|
|
4948
|
+
console.log(tag5, `Successfully added ${newPubkeys.length} pubkeys`);
|
|
4949
|
+
const networkSet = new Set;
|
|
4950
|
+
for (const path of paths) {
|
|
4951
|
+
if (path.networks && Array.isArray(path.networks)) {
|
|
4952
|
+
path.networks.forEach((net) => networkSet.add(net));
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4955
|
+
const uniqueNetworks = [...networkSet];
|
|
4956
|
+
console.log(tag5, `Fetching balances for ${uniqueNetworks.length} unique networks in single API call...`);
|
|
4957
|
+
await this.getBalancesForNetworks(uniqueNetworks);
|
|
4958
|
+
this.buildDashboardFromBalances();
|
|
4959
|
+
console.log(tag5, `Batch add complete: ${paths.length} paths, ${newPubkeys.length} pubkeys, ${this.balances?.length || 0} balances`);
|
|
4960
|
+
return { success: true, pubkeys: newPubkeys };
|
|
4961
|
+
} catch (e) {
|
|
4962
|
+
console.error(tag5, "Failed:", e);
|
|
4963
|
+
throw e;
|
|
4964
|
+
}
|
|
4965
|
+
};
|
|
4810
4966
|
this.getAssets = async function() {
|
|
4811
4967
|
return this.getGasAssets();
|
|
4812
4968
|
};
|
|
4813
4969
|
this.getGasAssets = async function() {
|
|
4814
|
-
const tag5 = `${
|
|
4970
|
+
const tag5 = `${TAG7} | getGasAssets | `;
|
|
4815
4971
|
try {
|
|
4816
4972
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4817
4973
|
let networkId = this.blockchains[i];
|
|
4818
|
-
let caip =
|
|
4974
|
+
let caip = import_pioneer_caip6.networkIdToCaip(networkId);
|
|
4819
4975
|
let asset = await import_pioneer_discovery2.assetData[caip.toLowerCase()];
|
|
4820
4976
|
if (asset) {
|
|
4821
4977
|
asset.caip = caip.toLowerCase();
|
|
@@ -4854,7 +5010,7 @@ class SDK {
|
|
|
4854
5010
|
}
|
|
4855
5011
|
};
|
|
4856
5012
|
this.getPubkeys = async function() {
|
|
4857
|
-
const tag5 = `${
|
|
5013
|
+
const tag5 = `${TAG7} | getPubkeys | `;
|
|
4858
5014
|
try {
|
|
4859
5015
|
if (this.paths.length === 0)
|
|
4860
5016
|
throw new Error("No paths found!");
|
|
@@ -4875,7 +5031,7 @@ class SDK {
|
|
|
4875
5031
|
}
|
|
4876
5032
|
};
|
|
4877
5033
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4878
|
-
const tag5 = `${
|
|
5034
|
+
const tag5 = `${TAG7} | getBalancesForNetworks | `;
|
|
4879
5035
|
try {
|
|
4880
5036
|
if (!this.pioneer) {
|
|
4881
5037
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -4893,7 +5049,7 @@ class SDK {
|
|
|
4893
5049
|
return network.startsWith("eip155:");
|
|
4894
5050
|
return network === adjustedNetworkId;
|
|
4895
5051
|
}));
|
|
4896
|
-
const caipNative = await
|
|
5052
|
+
const caipNative = await import_pioneer_caip6.networkIdToCaip(networkId);
|
|
4897
5053
|
for (const pubkey of pubkeys) {
|
|
4898
5054
|
assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
|
|
4899
5055
|
}
|
|
@@ -4902,14 +5058,6 @@ class SDK {
|
|
|
4902
5058
|
try {
|
|
4903
5059
|
let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
|
|
4904
5060
|
console.timeEnd("GetPortfolioBalances Response Time");
|
|
4905
|
-
if (!marketInfo || !marketInfo.data) {
|
|
4906
|
-
console.error(tag5, "Invalid response structure:", marketInfo);
|
|
4907
|
-
throw new Error("GetPortfolioBalances returned invalid response: missing data field");
|
|
4908
|
-
}
|
|
4909
|
-
if (!Array.isArray(marketInfo.data)) {
|
|
4910
|
-
console.error(tag5, "GetPortfolioBalances returned non-array data:", typeof marketInfo.data, marketInfo.data);
|
|
4911
|
-
throw new Error(`GetPortfolioBalances returned invalid data type: expected array, got ${typeof marketInfo.data}`);
|
|
4912
|
-
}
|
|
4913
5061
|
let balances = marketInfo.data;
|
|
4914
5062
|
const bitcoinBalances = balances.filter((b2) => b2.caip === "bip122:000000000019d6689c085ae165831e93/slip44:0");
|
|
4915
5063
|
if (bitcoinBalances.length > 0) {
|
|
@@ -4919,7 +5067,7 @@ class SDK {
|
|
|
4919
5067
|
if (!assetInfo)
|
|
4920
5068
|
continue;
|
|
4921
5069
|
Object.assign(balance, assetInfo, {
|
|
4922
|
-
networkId:
|
|
5070
|
+
networkId: import_pioneer_caip6.caipToNetworkId(balance.caip),
|
|
4923
5071
|
icon: assetInfo.icon || "https://pioneers.dev/coins/etherum.png",
|
|
4924
5072
|
identifier: `${balance.caip}:${balance.pubkey}`
|
|
4925
5073
|
});
|
|
@@ -4938,7 +5086,7 @@ class SDK {
|
|
|
4938
5086
|
}
|
|
4939
5087
|
};
|
|
4940
5088
|
this.getBalances = async function() {
|
|
4941
|
-
const tag5 = `${
|
|
5089
|
+
const tag5 = `${TAG7} | getBalances | `;
|
|
4942
5090
|
try {
|
|
4943
5091
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4944
5092
|
} catch (e) {
|
|
@@ -4947,10 +5095,10 @@ class SDK {
|
|
|
4947
5095
|
}
|
|
4948
5096
|
};
|
|
4949
5097
|
this.getBalance = async function(networkId) {
|
|
4950
|
-
const tag5 = `${
|
|
5098
|
+
const tag5 = `${TAG7} | getBalance | `;
|
|
4951
5099
|
try {
|
|
4952
5100
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4953
|
-
const filtered = results.filter(async (b2) => b2.networkId === await
|
|
5101
|
+
const filtered = results.filter(async (b2) => b2.networkId === await import_pioneer_caip6.networkIdToCaip(networkId));
|
|
4954
5102
|
return filtered;
|
|
4955
5103
|
} catch (e) {
|
|
4956
5104
|
console.error(tag5, "Error: ", e);
|
|
@@ -4958,7 +5106,7 @@ class SDK {
|
|
|
4958
5106
|
}
|
|
4959
5107
|
};
|
|
4960
5108
|
this.getFees = async function(networkId) {
|
|
4961
|
-
const tag5 = `${
|
|
5109
|
+
const tag5 = `${TAG7} | getFees | `;
|
|
4962
5110
|
try {
|
|
4963
5111
|
if (!this.pioneer) {
|
|
4964
5112
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -4973,7 +5121,7 @@ class SDK {
|
|
|
4973
5121
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
4974
5122
|
};
|
|
4975
5123
|
this.getCharts = async function() {
|
|
4976
|
-
const tag5 = `${
|
|
5124
|
+
const tag5 = `${TAG7} | getCharts | `;
|
|
4977
5125
|
try {
|
|
4978
5126
|
console.log(tag5, "Fetching charts");
|
|
4979
5127
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -4995,7 +5143,7 @@ class SDK {
|
|
|
4995
5143
|
}
|
|
4996
5144
|
};
|
|
4997
5145
|
this.setContext = async (context) => {
|
|
4998
|
-
const tag5 = `${
|
|
5146
|
+
const tag5 = `${TAG7} | setContext | `;
|
|
4999
5147
|
try {
|
|
5000
5148
|
if (!context)
|
|
5001
5149
|
throw Error("context required!");
|
|
@@ -5008,7 +5156,7 @@ class SDK {
|
|
|
5008
5156
|
}
|
|
5009
5157
|
};
|
|
5010
5158
|
this.setContextType = async (contextType) => {
|
|
5011
|
-
const tag5 = `${
|
|
5159
|
+
const tag5 = `${TAG7} | setContextType | `;
|
|
5012
5160
|
try {
|
|
5013
5161
|
if (!contextType)
|
|
5014
5162
|
throw Error("contextType required!");
|
|
@@ -5021,7 +5169,7 @@ class SDK {
|
|
|
5021
5169
|
}
|
|
5022
5170
|
};
|
|
5023
5171
|
this.refresh = async () => {
|
|
5024
|
-
const tag5 = `${
|
|
5172
|
+
const tag5 = `${TAG7} | refresh | `;
|
|
5025
5173
|
try {
|
|
5026
5174
|
await this.sync();
|
|
5027
5175
|
return this.balances;
|
|
@@ -5031,7 +5179,7 @@ class SDK {
|
|
|
5031
5179
|
}
|
|
5032
5180
|
};
|
|
5033
5181
|
this.setAssetContext = async function(asset) {
|
|
5034
|
-
const tag5 = `${
|
|
5182
|
+
const tag5 = `${TAG7} | setAssetContext | `;
|
|
5035
5183
|
try {
|
|
5036
5184
|
if (!asset) {
|
|
5037
5185
|
this.assetContext = null;
|
|
@@ -5040,7 +5188,7 @@ class SDK {
|
|
|
5040
5188
|
if (!asset.caip)
|
|
5041
5189
|
throw Error("Invalid Asset! missing caip!");
|
|
5042
5190
|
if (!asset.networkId)
|
|
5043
|
-
asset.networkId =
|
|
5191
|
+
asset.networkId = import_pioneer_caip6.caipToNetworkId(asset.caip);
|
|
5044
5192
|
if (!this.pubkeys || this.pubkeys.length === 0) {
|
|
5045
5193
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no pubkeys loaded. Please initialize wallet first.`;
|
|
5046
5194
|
console.error(tag5, errorMsg);
|
|
@@ -5148,7 +5296,7 @@ class SDK {
|
|
|
5148
5296
|
console.log(tag5, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
5149
5297
|
}
|
|
5150
5298
|
const assetBalances = this.balances.filter((b2) => b2.caip === asset.caip);
|
|
5151
|
-
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(
|
|
5299
|
+
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(import_pioneer_caip6.caipToNetworkId(asset.caip)) || import_pioneer_caip6.caipToNetworkId(asset.caip).includes("eip155") && p2.networks && Array.isArray(p2.networks) && p2.networks.some((n2) => n2.startsWith("eip155")));
|
|
5152
5300
|
const finalAssetContext = {
|
|
5153
5301
|
...assetInfo,
|
|
5154
5302
|
...asset,
|
|
@@ -5208,16 +5356,19 @@ class SDK {
|
|
|
5208
5356
|
}
|
|
5209
5357
|
}
|
|
5210
5358
|
if (asset.caip) {
|
|
5211
|
-
this.blockchainContext =
|
|
5359
|
+
this.blockchainContext = import_pioneer_caip6.caipToNetworkId(asset.caip);
|
|
5212
5360
|
} else if (asset.networkId) {
|
|
5213
5361
|
this.blockchainContext = asset.networkId;
|
|
5214
5362
|
}
|
|
5215
5363
|
if (assetPubkeys && assetPubkeys.length > 0) {
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5364
|
+
const networkId = import_pioneer_caip6.caipToNetworkId(asset.caip || asset.networkId);
|
|
5365
|
+
const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
|
|
5366
|
+
if (!this.pubkeyContext || !currentContextValid) {
|
|
5367
|
+
this.pubkeyContext = assetPubkeys[0];
|
|
5368
|
+
console.log(tag5, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
|
|
5369
|
+
} else {
|
|
5370
|
+
console.log(tag5, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
|
|
5219
5371
|
}
|
|
5220
|
-
console.log(tag5, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
|
|
5221
5372
|
}
|
|
5222
5373
|
this.events.emit("SET_ASSET_CONTEXT", this.assetContext);
|
|
5223
5374
|
return this.assetContext;
|
|
@@ -5227,7 +5378,7 @@ class SDK {
|
|
|
5227
5378
|
}
|
|
5228
5379
|
};
|
|
5229
5380
|
this.setPubkeyContext = async function(pubkey) {
|
|
5230
|
-
let tag5 = `${
|
|
5381
|
+
let tag5 = `${TAG7} | setPubkeyContext | `;
|
|
5231
5382
|
try {
|
|
5232
5383
|
if (!pubkey)
|
|
5233
5384
|
throw Error("pubkey is required");
|
|
@@ -5238,10 +5389,7 @@ class SDK {
|
|
|
5238
5389
|
console.warn(tag5, "Pubkey not found in current pubkeys array");
|
|
5239
5390
|
}
|
|
5240
5391
|
this.pubkeyContext = pubkey;
|
|
5241
|
-
|
|
5242
|
-
this.keepKeySdk.pubkeyContext = pubkey;
|
|
5243
|
-
}
|
|
5244
|
-
console.log(tag5, "Pubkey context set to:", pubkey.address || pubkey.pubkey, "note:", pubkey.note);
|
|
5392
|
+
console.log(tag5, "Pubkey context set to:", pubkey.address || pubkey.pubkey, "note:", pubkey.note, "addressNList:", pubkey.addressNList || pubkey.addressNListMaster);
|
|
5245
5393
|
return true;
|
|
5246
5394
|
} catch (e) {
|
|
5247
5395
|
console.error(tag5, "e: ", e);
|
|
@@ -5249,7 +5397,7 @@ class SDK {
|
|
|
5249
5397
|
}
|
|
5250
5398
|
};
|
|
5251
5399
|
this.setOutboundAssetContext = async function(asset) {
|
|
5252
|
-
const tag5 = `${
|
|
5400
|
+
const tag5 = `${TAG7} | setOutputAssetContext | `;
|
|
5253
5401
|
try {
|
|
5254
5402
|
console.log(tag5, "0. asset: ", asset);
|
|
5255
5403
|
if (!asset) {
|
|
@@ -5260,7 +5408,7 @@ class SDK {
|
|
|
5260
5408
|
if (!asset.caip)
|
|
5261
5409
|
throw Error("Invalid Asset! missing caip!");
|
|
5262
5410
|
if (!asset.networkId)
|
|
5263
|
-
asset.networkId =
|
|
5411
|
+
asset.networkId = import_pioneer_caip6.caipToNetworkId(asset.caip);
|
|
5264
5412
|
console.log(tag5, "networkId: ", asset.networkId);
|
|
5265
5413
|
console.log(tag5, "this.pubkeys: ", this.pubkeys);
|
|
5266
5414
|
const pubkey = this.pubkeys.find((p2) => {
|
|
@@ -5341,7 +5489,7 @@ class SDK {
|
|
|
5341
5489
|
console.log(tag5, "CHECKPOINT 3");
|
|
5342
5490
|
console.log(tag5, "outboundAssetContext: assetInfo: ", assetInfo);
|
|
5343
5491
|
if (asset.caip) {
|
|
5344
|
-
this.outboundBlockchainContext =
|
|
5492
|
+
this.outboundBlockchainContext = import_pioneer_caip6.caipToNetworkId(asset.caip);
|
|
5345
5493
|
} else if (asset.networkId) {
|
|
5346
5494
|
this.outboundBlockchainContext = asset.networkId;
|
|
5347
5495
|
}
|