@pioneer-platform/pioneer-sdk 8.11.12 → 8.11.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 +330 -757
- package/dist/index.es.js +330 -757
- package/dist/index.js +330 -757
- package/package.json +2 -2
- package/src/charts/cosmos-staking.ts +32 -22
- package/src/charts/evm.ts +104 -37
- package/src/charts/maya.ts +9 -6
- package/src/index.ts +61 -13
- package/src/txbuilder/createUnsignedEvmTx.ts +4 -8
package/dist/index.cjs
CHANGED
|
@@ -390,471 +390,10 @@ class Pioneer {
|
|
|
390
390
|
|
|
391
391
|
// src/index.ts
|
|
392
392
|
var import_pioneer_coins4 = require("@pioneer-platform/pioneer-coins");
|
|
393
|
-
var
|
|
393
|
+
var import_pioneer_discovery = require("@pioneer-platform/pioneer-discovery");
|
|
394
394
|
var import_pioneer_events = require("@pioneer-platform/pioneer-events");
|
|
395
395
|
var import_events = __toESM(require("events"));
|
|
396
396
|
|
|
397
|
-
// src/charts/utils.ts
|
|
398
|
-
var import_pioneer_discovery = require("@pioneer-platform/pioneer-discovery");
|
|
399
|
-
function hydrateAssetData(caip) {
|
|
400
|
-
return import_pioneer_discovery.assetData[caip] || import_pioneer_discovery.assetData[caip.toLowerCase()];
|
|
401
|
-
}
|
|
402
|
-
function checkDuplicateBalance(balances, caip, pubkey, validator) {
|
|
403
|
-
return balances.some((b) => b.caip === caip && b.pubkey === pubkey && (!validator || b.validator === validator));
|
|
404
|
-
}
|
|
405
|
-
function createBalanceIdentifier(caip, pubkey) {
|
|
406
|
-
return `${caip}:${pubkey}`;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// src/charts/custom-tokens.ts
|
|
410
|
-
var tag = "| charts-custom-tokens |";
|
|
411
|
-
async function fetchCustomTokens(params, balances) {
|
|
412
|
-
const { pioneer, pubkeys, blockchains, context } = params;
|
|
413
|
-
console.log(tag, "Fetching custom tokens...");
|
|
414
|
-
const evmPubkey = pubkeys.find((e) => e.networks && Array.isArray(e.networks) && e.networks.includes("eip155:*"));
|
|
415
|
-
const primaryAddress = evmPubkey?.address || evmPubkey?.master;
|
|
416
|
-
if (!primaryAddress) {
|
|
417
|
-
console.log(tag, "No EVM address found, skipping custom tokens");
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
console.log(tag, "Using EVM address for custom tokens:", primaryAddress);
|
|
421
|
-
const supportedNetworks = blockchains.filter((net) => net.startsWith("eip155:"));
|
|
422
|
-
if (supportedNetworks.length === 0) {
|
|
423
|
-
console.log(tag, "No EVM networks for custom tokens");
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
console.log(tag, `Checking custom tokens on ${supportedNetworks.length} networks`);
|
|
427
|
-
for (const networkId of supportedNetworks) {
|
|
428
|
-
try {
|
|
429
|
-
const response = await pioneer.GetCustomTokens({ networkId, userAddress: primaryAddress });
|
|
430
|
-
const customTokens = response?.data?.tokens || [];
|
|
431
|
-
console.log(tag, `Found ${customTokens.length} custom tokens on ${networkId}`);
|
|
432
|
-
for (const token of customTokens) {
|
|
433
|
-
const chartBalance = processCustomToken(token, primaryAddress, context, blockchains);
|
|
434
|
-
if (chartBalance && !checkDuplicateBalance(balances, chartBalance.caip, chartBalance.pubkey)) {
|
|
435
|
-
balances.push(chartBalance);
|
|
436
|
-
console.log(tag, `Added custom token: ${chartBalance.symbol} = ${chartBalance.balance}`);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
} catch (error) {
|
|
440
|
-
console.error(tag, `Error fetching custom tokens for ${networkId}:`, error.message);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
console.log(tag, `Custom tokens complete. Total balances: ${balances.length}`);
|
|
444
|
-
}
|
|
445
|
-
function processCustomToken(token, primaryAddress, context, blockchains) {
|
|
446
|
-
if (!token.assetCaip || !token.networkId) {
|
|
447
|
-
return null;
|
|
448
|
-
}
|
|
449
|
-
let extractedNetworkId = token.networkId;
|
|
450
|
-
if (token.assetCaip.includes("/denom:")) {
|
|
451
|
-
const parts = token.assetCaip.split("/denom:");
|
|
452
|
-
if (parts.length > 0) {
|
|
453
|
-
extractedNetworkId = parts[0];
|
|
454
|
-
}
|
|
455
|
-
} else if (token.networkId && token.networkId.includes("/")) {
|
|
456
|
-
extractedNetworkId = token.networkId.split("/")[0];
|
|
457
|
-
}
|
|
458
|
-
const isEip155 = extractedNetworkId.startsWith("eip155:");
|
|
459
|
-
if (!isEip155 && !blockchains.includes(extractedNetworkId)) {
|
|
460
|
-
return null;
|
|
461
|
-
}
|
|
462
|
-
const tokenAssetInfo = hydrateAssetData(token.assetCaip);
|
|
463
|
-
const tokenPubkey = token.pubkey || primaryAddress;
|
|
464
|
-
const chartBalance = {
|
|
465
|
-
context,
|
|
466
|
-
chart: "pioneer",
|
|
467
|
-
contextType: context.split(":")[0],
|
|
468
|
-
name: tokenAssetInfo?.name || token.token?.name || "Unknown Custom Token",
|
|
469
|
-
caip: token.assetCaip,
|
|
470
|
-
icon: tokenAssetInfo?.icon || token.token?.icon || "",
|
|
471
|
-
pubkey: tokenPubkey,
|
|
472
|
-
ticker: tokenAssetInfo?.symbol || token.token?.symbol || "UNK",
|
|
473
|
-
ref: `${context}${token.assetCaip}`,
|
|
474
|
-
identifier: createBalanceIdentifier(token.assetCaip, tokenPubkey),
|
|
475
|
-
networkId: extractedNetworkId,
|
|
476
|
-
symbol: tokenAssetInfo?.symbol || token.token?.symbol || "UNK",
|
|
477
|
-
type: tokenAssetInfo?.type || "erc20",
|
|
478
|
-
token: true,
|
|
479
|
-
decimal: tokenAssetInfo?.decimal || token.token?.decimal,
|
|
480
|
-
balance: token.token?.balance?.toString() || "0",
|
|
481
|
-
priceUsd: token.token?.price || 0,
|
|
482
|
-
valueUsd: token.token?.balanceUSD || 0,
|
|
483
|
-
updated: new Date().getTime()
|
|
484
|
-
};
|
|
485
|
-
return chartBalance;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// src/charts/evm.ts
|
|
489
|
-
var tag2 = "| charts-evm |";
|
|
490
|
-
async function getEvmCharts(params) {
|
|
491
|
-
const { blockchains, pioneer, pubkeys, context } = params;
|
|
492
|
-
const balances = [];
|
|
493
|
-
const evmPubkey = pubkeys.find((e) => e.networks && Array.isArray(e.networks) && e.networks.includes("eip155:*"));
|
|
494
|
-
const primaryAddress = evmPubkey?.address || evmPubkey?.master;
|
|
495
|
-
console.log(tag2, "Total pubkeys available:", pubkeys.length);
|
|
496
|
-
console.log(tag2, "Blockchains to process:", blockchains);
|
|
497
|
-
if (!primaryAddress) {
|
|
498
|
-
console.log(tag2, "No EVM address found, skipping portfolio lookup (Zapper only supports Ethereum)");
|
|
499
|
-
return balances;
|
|
500
|
-
}
|
|
501
|
-
console.log(tag2, "Using EVM address for portfolio:", primaryAddress);
|
|
502
|
-
await fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context);
|
|
503
|
-
await fetchCustomTokens({ blockchains, pioneer, pubkeys, context }, balances);
|
|
504
|
-
try {
|
|
505
|
-
let portfolio = await pioneer.GetPortfolio({
|
|
506
|
-
networkId: "eip155:1",
|
|
507
|
-
address: primaryAddress
|
|
508
|
-
});
|
|
509
|
-
portfolio = portfolio.data?.data || portfolio.data;
|
|
510
|
-
if (!portfolio || !portfolio.balances) {
|
|
511
|
-
console.error(tag2, "No portfolio.balances found:", portfolio);
|
|
512
|
-
return balances;
|
|
513
|
-
}
|
|
514
|
-
console.log(tag2, `Portfolio returned ${portfolio.balances.length} balances`);
|
|
515
|
-
let processedCount = 0;
|
|
516
|
-
let skippedCount = 0;
|
|
517
|
-
for (const balance of portfolio.balances) {
|
|
518
|
-
const processedBalance = processPortfolioBalance(balance, primaryAddress, context, blockchains);
|
|
519
|
-
if (processedBalance) {
|
|
520
|
-
if (!checkDuplicateBalance(balances, processedBalance.caip, processedBalance.pubkey)) {
|
|
521
|
-
balances.push(processedBalance);
|
|
522
|
-
processedCount++;
|
|
523
|
-
}
|
|
524
|
-
} else {
|
|
525
|
-
skippedCount++;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
console.log(tag2, `Processed ${processedCount} balances, skipped ${skippedCount}`);
|
|
529
|
-
if (portfolio.tokens && portfolio.tokens.length > 0) {
|
|
530
|
-
console.log(tag2, "Processing portfolio.tokens:", portfolio.tokens.length);
|
|
531
|
-
for (const token of portfolio.tokens) {
|
|
532
|
-
const processedToken = processPortfolioToken(token, primaryAddress, context, blockchains);
|
|
533
|
-
if (processedToken && !checkDuplicateBalance(balances, processedToken.caip, processedToken.pubkey)) {
|
|
534
|
-
balances.push(processedToken);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
} catch (e) {
|
|
539
|
-
console.error(tag2, "Error fetching portfolio:", e);
|
|
540
|
-
}
|
|
541
|
-
return balances;
|
|
542
|
-
}
|
|
543
|
-
function processPortfolioBalance(balance, primaryAddress, context, blockchains) {
|
|
544
|
-
if (!balance.caip) {
|
|
545
|
-
console.error(tag2, "No caip found for:", balance);
|
|
546
|
-
return null;
|
|
547
|
-
}
|
|
548
|
-
const networkId = balance.caip.split("/")[0];
|
|
549
|
-
const isEip155 = networkId.startsWith("eip155:");
|
|
550
|
-
if (!isEip155 && !blockchains.includes(networkId)) {
|
|
551
|
-
return null;
|
|
552
|
-
}
|
|
553
|
-
const assetInfo = hydrateAssetData(balance.caip);
|
|
554
|
-
const balancePubkey = balance.pubkey || primaryAddress;
|
|
555
|
-
const balanceType = assetInfo?.type || balance.type || "native";
|
|
556
|
-
const isToken = balanceType !== "native" && balance.caip.includes("/erc20:");
|
|
557
|
-
let calculatedPrice = balance.priceUsd || balance.price || 0;
|
|
558
|
-
if ((!calculatedPrice || calculatedPrice === 0) && balance.valueUsd && balance.balance) {
|
|
559
|
-
const balanceNum = parseFloat(balance.balance.toString());
|
|
560
|
-
const valueNum = parseFloat(balance.valueUsd.toString());
|
|
561
|
-
if (balanceNum > 0 && valueNum > 0) {
|
|
562
|
-
calculatedPrice = valueNum / balanceNum;
|
|
563
|
-
console.log(tag2, `Calculated price from value/balance: ${calculatedPrice} for ${balance.caip}`);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
const chartBalance = {
|
|
567
|
-
context,
|
|
568
|
-
chart: "pioneer",
|
|
569
|
-
contextType: "keepkey",
|
|
570
|
-
name: assetInfo?.name || balance.name || "Unknown",
|
|
571
|
-
caip: balance.caip,
|
|
572
|
-
icon: assetInfo?.icon || balance.icon || "",
|
|
573
|
-
pubkey: balancePubkey,
|
|
574
|
-
ticker: assetInfo?.symbol || balance.symbol || "UNK",
|
|
575
|
-
ref: `${context}${balance.caip}`,
|
|
576
|
-
identifier: createBalanceIdentifier(balance.caip, balancePubkey),
|
|
577
|
-
networkId,
|
|
578
|
-
chain: networkId,
|
|
579
|
-
symbol: assetInfo?.symbol || balance.symbol || "UNK",
|
|
580
|
-
type: balanceType,
|
|
581
|
-
token: isToken,
|
|
582
|
-
decimal: assetInfo?.decimal || balance.decimal,
|
|
583
|
-
balance: balance.balance.toString(),
|
|
584
|
-
price: calculatedPrice,
|
|
585
|
-
priceUsd: calculatedPrice,
|
|
586
|
-
valueUsd: balance.valueUsd.toString(),
|
|
587
|
-
updated: new Date().getTime()
|
|
588
|
-
};
|
|
589
|
-
if (balance.display) {
|
|
590
|
-
chartBalance.icon = ["multi", chartBalance.icon, balance.display.toString()].toString();
|
|
591
|
-
}
|
|
592
|
-
return chartBalance;
|
|
593
|
-
}
|
|
594
|
-
function processPortfolioToken(token, primaryAddress, context, blockchains) {
|
|
595
|
-
if (!token.assetCaip || !token.networkId) {
|
|
596
|
-
return null;
|
|
597
|
-
}
|
|
598
|
-
let extractedNetworkId = token.networkId;
|
|
599
|
-
if (token.assetCaip.includes("/denom:")) {
|
|
600
|
-
const parts = token.assetCaip.split("/denom:");
|
|
601
|
-
if (parts.length > 0) {
|
|
602
|
-
extractedNetworkId = parts[0];
|
|
603
|
-
}
|
|
604
|
-
} else if (token.networkId && token.networkId.includes("/")) {
|
|
605
|
-
extractedNetworkId = token.networkId.split("/")[0];
|
|
606
|
-
}
|
|
607
|
-
const isEip155 = extractedNetworkId.startsWith("eip155:");
|
|
608
|
-
if (!isEip155 && !blockchains.includes(extractedNetworkId)) {
|
|
609
|
-
return null;
|
|
610
|
-
}
|
|
611
|
-
const tokenAssetInfo = hydrateAssetData(token.assetCaip);
|
|
612
|
-
const tokenPubkey = token.pubkey || primaryAddress;
|
|
613
|
-
const chartBalance = {
|
|
614
|
-
context,
|
|
615
|
-
chart: "pioneer",
|
|
616
|
-
contextType: context.split(":")[0],
|
|
617
|
-
name: tokenAssetInfo?.name || token.token?.coingeckoId || token.token?.name || "Unknown",
|
|
618
|
-
caip: token.assetCaip,
|
|
619
|
-
icon: tokenAssetInfo?.icon || token.token?.icon || "",
|
|
620
|
-
pubkey: tokenPubkey,
|
|
621
|
-
ticker: tokenAssetInfo?.symbol || token.token?.symbol || "UNK",
|
|
622
|
-
ref: `${context}${token.assetCaip}`,
|
|
623
|
-
identifier: createBalanceIdentifier(token.assetCaip, tokenPubkey),
|
|
624
|
-
networkId: extractedNetworkId,
|
|
625
|
-
symbol: tokenAssetInfo?.symbol || token.token?.symbol || "UNK",
|
|
626
|
-
type: tokenAssetInfo?.type || "token",
|
|
627
|
-
token: true,
|
|
628
|
-
decimal: tokenAssetInfo?.decimal || token.token?.decimal,
|
|
629
|
-
balance: token.token?.balance?.toString() || "0",
|
|
630
|
-
priceUsd: token.token?.price || 0,
|
|
631
|
-
valueUsd: token.token?.balanceUSD || 0,
|
|
632
|
-
updated: new Date().getTime()
|
|
633
|
-
};
|
|
634
|
-
return chartBalance;
|
|
635
|
-
}
|
|
636
|
-
async function fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context) {
|
|
637
|
-
console.log(tag2, "Fetching stable coins for redundancy...");
|
|
638
|
-
const supportedNetworks = ["eip155:1", "eip155:137", "eip155:8453", "eip155:56"];
|
|
639
|
-
const networksToCheck = blockchains.filter((net) => supportedNetworks.includes(net));
|
|
640
|
-
if (networksToCheck.length === 0) {
|
|
641
|
-
console.log(tag2, "No supported networks for stable coins");
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
console.log(tag2, `Checking stable coins on ${networksToCheck.length} networks`);
|
|
645
|
-
for (const networkId of networksToCheck) {
|
|
646
|
-
try {
|
|
647
|
-
const response = await pioneer.GetStableCoins({ networkId, address: primaryAddress });
|
|
648
|
-
const stableCoins = response?.data?.tokens || [];
|
|
649
|
-
console.log(tag2, `Found ${stableCoins.length} stable coins on ${networkId}`);
|
|
650
|
-
for (const token of stableCoins) {
|
|
651
|
-
const chartBalance = processPortfolioToken(token, primaryAddress, context, blockchains);
|
|
652
|
-
if (chartBalance && !checkDuplicateBalance(balances, chartBalance.caip, chartBalance.pubkey)) {
|
|
653
|
-
balances.push(chartBalance);
|
|
654
|
-
console.log(tag2, `Added stable coin: ${chartBalance.symbol} = ${chartBalance.balance}`);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
} catch (error) {
|
|
658
|
-
console.error(tag2, `Error fetching stable coins for ${networkId}:`, error.message);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
console.log(tag2, `Stable coin redundancy complete. Total balances: ${balances.length}`);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
// src/charts/maya.ts
|
|
665
|
-
var tag3 = "| charts-maya |";
|
|
666
|
-
async function getMayaCharts(params, existingBalances) {
|
|
667
|
-
const { blockchains, pioneer, pubkeys, context } = params;
|
|
668
|
-
const balances = [];
|
|
669
|
-
try {
|
|
670
|
-
const mayaPubkey = pubkeys.find((p) => p.networks && Array.isArray(p.networks) && p.networks.includes("cosmos:mayachain-mainnet-v1"));
|
|
671
|
-
if (!mayaPubkey || !mayaPubkey.address) {
|
|
672
|
-
console.log(tag3, "No MAYA pubkey found, skipping MAYA token fetch");
|
|
673
|
-
return balances;
|
|
674
|
-
}
|
|
675
|
-
if (!blockchains.includes("cosmos:mayachain-mainnet-v1")) {
|
|
676
|
-
console.log(tag3, "MAYA network not in blockchains list, skipping MAYA token fetch");
|
|
677
|
-
return balances;
|
|
678
|
-
}
|
|
679
|
-
const hasMayaToken = existingBalances.some((b) => b.caip === "cosmos:mayachain-mainnet-v1/denom:maya");
|
|
680
|
-
if (hasMayaToken) {
|
|
681
|
-
console.log(tag3, "MAYA token already exists in balances, skipping");
|
|
682
|
-
return balances;
|
|
683
|
-
}
|
|
684
|
-
console.log(tag3, "MAYA token not found in portfolio, fetching separately...");
|
|
685
|
-
console.log(tag3, "MAYA pubkey address:", mayaPubkey.address);
|
|
686
|
-
const mayaBalanceResponse = await pioneer.GetPortfolioBalances([
|
|
687
|
-
{
|
|
688
|
-
caip: "cosmos:mayachain-mainnet-v1/denom:maya",
|
|
689
|
-
pubkey: mayaPubkey.address
|
|
690
|
-
}
|
|
691
|
-
]);
|
|
692
|
-
console.log(tag3, "MAYA balance response:", JSON.stringify(mayaBalanceResponse?.data, null, 2));
|
|
693
|
-
if (!mayaBalanceResponse?.data || mayaBalanceResponse.data.length === 0) {
|
|
694
|
-
console.log(tag3, "No MAYA token balance returned from GetPortfolioBalances API");
|
|
695
|
-
return balances;
|
|
696
|
-
}
|
|
697
|
-
console.log(tag3, "Found MAYA token balances:", mayaBalanceResponse.data.length);
|
|
698
|
-
for (const mayaBalance of mayaBalanceResponse.data) {
|
|
699
|
-
if (mayaBalance.caip !== "cosmos:mayachain-mainnet-v1/denom:maya") {
|
|
700
|
-
console.log(tag3, "Unexpected balance in MAYA response:", mayaBalance);
|
|
701
|
-
continue;
|
|
702
|
-
}
|
|
703
|
-
const mayaAssetInfo = hydrateAssetData(mayaBalance.caip);
|
|
704
|
-
const isToken = mayaBalance.caip.includes("/denom:") && !mayaBalance.caip.endsWith("/denom:cacao");
|
|
705
|
-
const mayaTokenBalance = {
|
|
706
|
-
context,
|
|
707
|
-
chart: "pioneer",
|
|
708
|
-
contextType: context.split(":")[0],
|
|
709
|
-
name: mayaAssetInfo?.name || "Maya Token",
|
|
710
|
-
caip: mayaBalance.caip,
|
|
711
|
-
icon: mayaAssetInfo?.icon || "https://pioneers.dev/coins/maya.png",
|
|
712
|
-
pubkey: mayaPubkey.address,
|
|
713
|
-
ticker: mayaAssetInfo?.symbol || "MAYA",
|
|
714
|
-
ref: `${context}${mayaBalance.caip}`,
|
|
715
|
-
identifier: createBalanceIdentifier(mayaBalance.caip, mayaPubkey.address),
|
|
716
|
-
networkId: "cosmos:mayachain-mainnet-v1",
|
|
717
|
-
symbol: mayaAssetInfo?.symbol || "MAYA",
|
|
718
|
-
type: mayaAssetInfo?.type || "token",
|
|
719
|
-
token: isToken,
|
|
720
|
-
decimal: mayaAssetInfo?.decimal,
|
|
721
|
-
balance: mayaBalance.balance?.toString() || "0",
|
|
722
|
-
priceUsd: parseFloat(mayaBalance.priceUsd) || 0,
|
|
723
|
-
valueUsd: parseFloat(mayaBalance.valueUsd) || 0,
|
|
724
|
-
updated: new Date().getTime()
|
|
725
|
-
};
|
|
726
|
-
console.log(tag3, "Adding MAYA token to balances:", mayaTokenBalance);
|
|
727
|
-
balances.push(mayaTokenBalance);
|
|
728
|
-
}
|
|
729
|
-
} catch (mayaError) {
|
|
730
|
-
console.error(tag3, "Error fetching MAYA token balance:", mayaError);
|
|
731
|
-
}
|
|
732
|
-
return balances;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
// src/charts/cosmos-staking.ts
|
|
736
|
-
var tag4 = "| charts-cosmos-staking |";
|
|
737
|
-
async function getCosmosStakingCharts(params) {
|
|
738
|
-
const { blockchains, pioneer, pubkeys, context } = params;
|
|
739
|
-
const balances = [];
|
|
740
|
-
try {
|
|
741
|
-
console.log(tag4, "Adding Cosmos staking positions to charts...");
|
|
742
|
-
const cosmosPubkeys = pubkeys.filter((p) => p.networks && Array.isArray(p.networks) && p.networks.some((n) => n.includes("cosmos:cosmoshub") || n.includes("cosmos:osmosis")));
|
|
743
|
-
if (cosmosPubkeys.length === 0) {
|
|
744
|
-
console.log(tag4, "No cosmos pubkeys found for staking positions");
|
|
745
|
-
return balances;
|
|
746
|
-
}
|
|
747
|
-
console.log(tag4, "Found cosmos pubkeys for staking:", cosmosPubkeys.length);
|
|
748
|
-
for (const cosmosPubkey of cosmosPubkeys) {
|
|
749
|
-
if (!cosmosPubkey.address) {
|
|
750
|
-
continue;
|
|
751
|
-
}
|
|
752
|
-
const cosmosNetworks = cosmosPubkey.networks.filter((n) => n.includes("cosmos:cosmoshub") || n.includes("cosmos:osmosis"));
|
|
753
|
-
for (const networkId of cosmosNetworks) {
|
|
754
|
-
if (!blockchains.includes(networkId)) {
|
|
755
|
-
continue;
|
|
756
|
-
}
|
|
757
|
-
await fetchStakingPositionsForNetwork(networkId, cosmosPubkey.address, context, pioneer, balances);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
} catch (e) {
|
|
761
|
-
console.error(tag4, "Error adding cosmos staking positions:", e);
|
|
762
|
-
}
|
|
763
|
-
return balances;
|
|
764
|
-
}
|
|
765
|
-
async function fetchStakingPositionsForNetwork(networkId, address, context, pioneer, balances) {
|
|
766
|
-
try {
|
|
767
|
-
console.log(tag4, `Fetching staking positions for ${address} on ${networkId}...`);
|
|
768
|
-
let network;
|
|
769
|
-
if (networkId === "cosmos:cosmoshub-4") {
|
|
770
|
-
network = "cosmos";
|
|
771
|
-
} else if (networkId === "cosmos:osmosis-1") {
|
|
772
|
-
network = "osmosis";
|
|
773
|
-
} else {
|
|
774
|
-
console.error(tag4, `Unsupported networkId for staking: ${networkId}`);
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
const stakingResponse = await pioneer.GetStakingPositions({
|
|
778
|
-
network,
|
|
779
|
-
address
|
|
780
|
-
});
|
|
781
|
-
if (!stakingResponse?.data || !Array.isArray(stakingResponse.data)) {
|
|
782
|
-
console.log(tag4, `No staking positions found for ${address} on ${networkId}`);
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
console.log(tag4, `Found ${stakingResponse.data.length} staking positions for ${networkId}`);
|
|
786
|
-
for (const position of stakingResponse.data) {
|
|
787
|
-
const processedPosition = processStakingPosition(position, address, context, networkId);
|
|
788
|
-
if (processedPosition && !checkDuplicateBalance(balances, processedPosition.caip, processedPosition.pubkey, processedPosition.validator)) {
|
|
789
|
-
balances.push(processedPosition);
|
|
790
|
-
console.log(tag4, `Added ${position.type} position:`, {
|
|
791
|
-
balance: processedPosition.balance,
|
|
792
|
-
ticker: processedPosition.ticker,
|
|
793
|
-
valueUsd: processedPosition.valueUsd,
|
|
794
|
-
validator: processedPosition.validator
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
} catch (stakingError) {
|
|
799
|
-
console.error(tag4, `Error fetching staking positions for ${address} on ${networkId}:`, stakingError);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
function processStakingPosition(position, address, context, networkId) {
|
|
803
|
-
if (!position.balance || position.balance <= 0 || !position.caip) {
|
|
804
|
-
return null;
|
|
805
|
-
}
|
|
806
|
-
const stakingAssetInfo = hydrateAssetData(position.caip);
|
|
807
|
-
const stakingBalance = {
|
|
808
|
-
context,
|
|
809
|
-
chart: "staking",
|
|
810
|
-
contextType: context.split(":")[0],
|
|
811
|
-
name: stakingAssetInfo?.name || position.name || `${position.type} Position`,
|
|
812
|
-
caip: position.caip,
|
|
813
|
-
icon: stakingAssetInfo?.icon || position.icon || "",
|
|
814
|
-
pubkey: address,
|
|
815
|
-
ticker: stakingAssetInfo?.symbol || position.ticker || position.symbol || "UNK",
|
|
816
|
-
ref: `${context}${position.caip}`,
|
|
817
|
-
identifier: createBalanceIdentifier(position.caip, address),
|
|
818
|
-
networkId,
|
|
819
|
-
symbol: stakingAssetInfo?.symbol || position.symbol || position.ticker || "UNK",
|
|
820
|
-
type: stakingAssetInfo?.type || position.type || "staking",
|
|
821
|
-
token: false,
|
|
822
|
-
decimal: stakingAssetInfo?.decimal,
|
|
823
|
-
balance: position.balance.toString(),
|
|
824
|
-
priceUsd: position.priceUsd || 0,
|
|
825
|
-
valueUsd: position.valueUsd || position.balance * (position.priceUsd || 0),
|
|
826
|
-
status: position.status || "active",
|
|
827
|
-
validator: position.validatorAddress || position.validator || "",
|
|
828
|
-
updated: new Date().getTime()
|
|
829
|
-
};
|
|
830
|
-
return stakingBalance;
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// src/charts/index.ts
|
|
834
|
-
var tag5 = "| getCharts |";
|
|
835
|
-
var getCharts = async (blockchains, pioneer, pubkeys, context) => {
|
|
836
|
-
try {
|
|
837
|
-
const balances = [];
|
|
838
|
-
console.log(tag5, "init");
|
|
839
|
-
const params = {
|
|
840
|
-
blockchains,
|
|
841
|
-
pioneer,
|
|
842
|
-
pubkeys,
|
|
843
|
-
context
|
|
844
|
-
};
|
|
845
|
-
const evmBalances = await getEvmCharts(params);
|
|
846
|
-
balances.push(...evmBalances);
|
|
847
|
-
const mayaBalances = await getMayaCharts(params, balances);
|
|
848
|
-
balances.push(...mayaBalances);
|
|
849
|
-
const stakingBalances = await getCosmosStakingCharts(params);
|
|
850
|
-
balances.push(...stakingBalances);
|
|
851
|
-
return balances;
|
|
852
|
-
} catch (error) {
|
|
853
|
-
console.error(tag5, "Error processing charts:", error);
|
|
854
|
-
throw error;
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
|
-
|
|
858
397
|
// src/getPubkey.ts
|
|
859
398
|
var import_pioneer_caip = require("@pioneer-platform/pioneer-caip");
|
|
860
399
|
var import_pioneer_coins = require("@pioneer-platform/pioneer-coins");
|
|
@@ -1419,7 +958,7 @@ async function fetchTokenPriceInUsd(pioneer, caip) {
|
|
|
1419
958
|
}
|
|
1420
959
|
}
|
|
1421
960
|
async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5) {
|
|
1422
|
-
const
|
|
961
|
+
const tag = TAG2 + " | createUnsignedEvmTx | ";
|
|
1423
962
|
try {
|
|
1424
963
|
if (!pioneer)
|
|
1425
964
|
throw new Error("Failed to initialize Pioneer");
|
|
@@ -1440,11 +979,11 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1440
979
|
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
1441
980
|
}
|
|
1442
981
|
const address = pubkeyContext.address || pubkeyContext.pubkey;
|
|
1443
|
-
console.log(
|
|
982
|
+
console.log(tag, "✅ Using FROM address from pubkeyContext:", address, "note:", pubkeyContext.note);
|
|
1444
983
|
if (!address)
|
|
1445
984
|
throw new Error("No address found for the specified network");
|
|
1446
985
|
const gasPriceData = await pioneer.GetGasPriceByNetwork({ networkId });
|
|
1447
|
-
console.log(
|
|
986
|
+
console.log(tag, "Gas price data from API:", JSON.stringify(gasPriceData.data));
|
|
1448
987
|
let gasPrice;
|
|
1449
988
|
const defaultGasPrices = {
|
|
1450
989
|
1: 30,
|
|
@@ -1460,75 +999,75 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1460
999
|
let selectedGasPrice;
|
|
1461
1000
|
if (feeLevel <= 2) {
|
|
1462
1001
|
selectedGasPrice = gasPriceData.data.slow || gasPriceData.data.average || gasPriceData.data.fastest;
|
|
1463
|
-
console.log(
|
|
1002
|
+
console.log(tag, "Selecting SLOW gas price from API");
|
|
1464
1003
|
} else if (feeLevel >= 8) {
|
|
1465
1004
|
selectedGasPrice = gasPriceData.data.fastest || gasPriceData.data.fast || gasPriceData.data.average;
|
|
1466
|
-
console.log(
|
|
1005
|
+
console.log(tag, "Selecting FAST gas price from API");
|
|
1467
1006
|
} else {
|
|
1468
1007
|
selectedGasPrice = gasPriceData.data.average || gasPriceData.data.fast || gasPriceData.data.fastest;
|
|
1469
|
-
console.log(
|
|
1008
|
+
console.log(tag, "Selecting AVERAGE gas price from API");
|
|
1470
1009
|
}
|
|
1471
1010
|
let gasPriceNum;
|
|
1472
1011
|
if (selectedGasPrice === undefined || selectedGasPrice === null) {
|
|
1473
|
-
console.warn(
|
|
1012
|
+
console.warn(tag, "No valid gas price found in API response, using fallback:", fallbackGasGwei, "gwei");
|
|
1474
1013
|
gasPriceNum = fallbackGasGwei;
|
|
1475
1014
|
} else {
|
|
1476
1015
|
gasPriceNum = typeof selectedGasPrice === "string" ? parseFloat(selectedGasPrice) : selectedGasPrice;
|
|
1477
1016
|
if (isNaN(gasPriceNum) || !isFinite(gasPriceNum)) {
|
|
1478
|
-
console.warn(
|
|
1017
|
+
console.warn(tag, "Invalid gas price (NaN or Infinite):", selectedGasPrice, "- using fallback:", fallbackGasGwei, "gwei");
|
|
1479
1018
|
gasPriceNum = fallbackGasGwei;
|
|
1480
1019
|
}
|
|
1481
1020
|
}
|
|
1482
1021
|
gasPrice = BigInt(Math.round(gasPriceNum * 1e9));
|
|
1483
1022
|
if (gasPrice < MIN_GAS_PRICE_WEI) {
|
|
1484
|
-
console.warn(
|
|
1023
|
+
console.warn(tag, "Gas price from API too low:", gasPrice.toString(), "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1485
1024
|
gasPrice = MIN_GAS_PRICE_WEI;
|
|
1486
1025
|
}
|
|
1487
1026
|
} else {
|
|
1488
1027
|
let gasPriceNum;
|
|
1489
1028
|
if (gasPriceData.data === undefined || gasPriceData.data === null) {
|
|
1490
|
-
console.warn(
|
|
1029
|
+
console.warn(tag, "Gas price API returned null/undefined, using fallback:", fallbackGasGwei, "gwei");
|
|
1491
1030
|
gasPriceNum = fallbackGasGwei;
|
|
1492
1031
|
} else {
|
|
1493
1032
|
gasPriceNum = typeof gasPriceData.data === "string" ? parseFloat(gasPriceData.data) : gasPriceData.data;
|
|
1494
1033
|
if (isNaN(gasPriceNum) || !isFinite(gasPriceNum)) {
|
|
1495
|
-
console.warn(
|
|
1034
|
+
console.warn(tag, "Invalid gas price (NaN or Infinite):", gasPriceData.data, "- using fallback:", fallbackGasGwei, "gwei");
|
|
1496
1035
|
gasPriceNum = fallbackGasGwei;
|
|
1497
1036
|
}
|
|
1498
1037
|
}
|
|
1499
1038
|
const baseGasPrice = BigInt(Math.round(gasPriceNum * 1e9));
|
|
1500
1039
|
if (feeLevel <= 2) {
|
|
1501
1040
|
gasPrice = baseGasPrice * BigInt(80) / BigInt(100);
|
|
1502
|
-
console.log(
|
|
1041
|
+
console.log(tag, "Using SLOW gas price (80% of base)");
|
|
1503
1042
|
} else if (feeLevel >= 8) {
|
|
1504
1043
|
gasPrice = baseGasPrice * BigInt(150) / BigInt(100);
|
|
1505
|
-
console.log(
|
|
1044
|
+
console.log(tag, "Using FAST gas price (150% of base)");
|
|
1506
1045
|
} else {
|
|
1507
1046
|
gasPrice = baseGasPrice;
|
|
1508
|
-
console.log(
|
|
1047
|
+
console.log(tag, "Using AVERAGE gas price (100% of base)");
|
|
1509
1048
|
}
|
|
1510
1049
|
if (gasPrice < MIN_GAS_PRICE_WEI) {
|
|
1511
|
-
console.warn(
|
|
1050
|
+
console.warn(tag, "Gas price too low:", gasPrice.toString(), "wei - using minimum:", MIN_GAS_PRICE_WEI.toString());
|
|
1512
1051
|
gasPrice = MIN_GAS_PRICE_WEI;
|
|
1513
1052
|
}
|
|
1514
1053
|
}
|
|
1515
|
-
console.log(
|
|
1054
|
+
console.log(tag, "Final gasPrice:", gasPrice.toString(), "wei (", Number(gasPrice) / 1e9, "gwei)");
|
|
1516
1055
|
let nonce;
|
|
1517
1056
|
try {
|
|
1518
1057
|
const nonceData = await pioneer.GetNonceByNetwork({ networkId, address });
|
|
1519
1058
|
nonce = nonceData.data.nonce;
|
|
1520
1059
|
if (nonce === undefined || nonce === null) {
|
|
1521
|
-
console.log(
|
|
1060
|
+
console.log(tag, "No nonce found for address (likely fresh address), defaulting to 0");
|
|
1522
1061
|
nonce = 0;
|
|
1523
1062
|
}
|
|
1524
1063
|
} catch (nonceError) {
|
|
1525
|
-
console.log(
|
|
1064
|
+
console.log(tag, "Failed to fetch nonce (likely fresh address):", nonceError.message, "- defaulting to 0");
|
|
1526
1065
|
nonce = 0;
|
|
1527
1066
|
}
|
|
1528
1067
|
const balanceData = await pioneer.GetBalanceAddressByNetwork({ networkId, address });
|
|
1529
1068
|
const balanceEth = parseFloat(balanceData.data.nativeBalance || balanceData.data.balance || "0");
|
|
1530
1069
|
const balance = BigInt(Math.round(balanceEth * 1000000000000000000));
|
|
1531
|
-
console.log(
|
|
1070
|
+
console.log(tag, "Native ETH balance from API:", balanceData.data.nativeBalance || balanceData.data.balance, "ETH (", balance.toString(), "wei)");
|
|
1532
1071
|
if (balance <= 0n)
|
|
1533
1072
|
throw new Error("Wallet balance is zero");
|
|
1534
1073
|
const assetType = classifyCaipEvm(caip);
|
|
@@ -1541,7 +1080,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1541
1080
|
let gasLimit;
|
|
1542
1081
|
if (isThorchainOperation) {
|
|
1543
1082
|
gasLimit = BigInt(120000);
|
|
1544
|
-
console.log(
|
|
1083
|
+
console.log(tag, "Using higher gas limit for THORChain swap:", gasLimit.toString());
|
|
1545
1084
|
} else {
|
|
1546
1085
|
gasLimit = chainId === 1 ? BigInt(21000) : BigInt(25000);
|
|
1547
1086
|
}
|
|
@@ -1557,7 +1096,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1557
1096
|
}
|
|
1558
1097
|
const buffer = BigInt(100);
|
|
1559
1098
|
amountWei = balance - gasFee - buffer;
|
|
1560
|
-
console.log(
|
|
1099
|
+
console.log(tag, "isMax calculation - balance:", balance.toString(), "gasFee:", gasFee.toString(), "buffer:", buffer.toString(), "amountWei:", amountWei.toString());
|
|
1561
1100
|
} else {
|
|
1562
1101
|
amountWei = BigInt(Math.round(amount * 1000000000000000000));
|
|
1563
1102
|
if (amountWei + gasFee > balance) {
|
|
@@ -1567,14 +1106,14 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1567
1106
|
const isThorchainSwap = memo && (memo.startsWith("=") || memo.startsWith("SWAP") || memo.includes(":"));
|
|
1568
1107
|
let txData = "0x";
|
|
1569
1108
|
if (isThorchainSwap) {
|
|
1570
|
-
console.log(
|
|
1109
|
+
console.log(tag, "Detected THORChain swap, encoding deposit data for memo:", memo);
|
|
1571
1110
|
let fixedMemo = memo;
|
|
1572
1111
|
if (memo.startsWith("=:b:") || memo.startsWith("=:btc:")) {
|
|
1573
1112
|
fixedMemo = memo.replace(/^=:(b|btc):/, "=:BTC.BTC:");
|
|
1574
|
-
console.log(
|
|
1113
|
+
console.log(tag, "Fixed Bitcoin swap memo from:", memo, "to:", fixedMemo);
|
|
1575
1114
|
} else if (memo.startsWith("=:e:") || memo.startsWith("=:eth:")) {
|
|
1576
1115
|
fixedMemo = memo.replace(/^=:(e|eth):/, "=:ETH.ETH:");
|
|
1577
|
-
console.log(
|
|
1116
|
+
console.log(tag, "Fixed Ethereum swap memo from:", memo, "to:", fixedMemo);
|
|
1578
1117
|
}
|
|
1579
1118
|
if (fixedMemo.length > 250) {
|
|
1580
1119
|
throw new Error(`Memo too long for THORChain: ${fixedMemo.length} bytes (max 250)`);
|
|
@@ -1590,14 +1129,14 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1590
1129
|
if (ethInbound) {
|
|
1591
1130
|
vaultAddress = ethInbound.address;
|
|
1592
1131
|
routerAddress = ethInbound.router || to;
|
|
1593
|
-
console.log(
|
|
1132
|
+
console.log(tag, "Using THORChain inbound addresses - vault:", vaultAddress, "router:", routerAddress);
|
|
1594
1133
|
to = routerAddress;
|
|
1595
1134
|
} else {
|
|
1596
1135
|
throw new Error("ETH inbound is halted or not found - cannot proceed with swap");
|
|
1597
1136
|
}
|
|
1598
1137
|
}
|
|
1599
1138
|
} catch (fetchError) {
|
|
1600
|
-
console.error(
|
|
1139
|
+
console.error(tag, "Failed to fetch inbound addresses:", fetchError);
|
|
1601
1140
|
throw new Error(`Cannot proceed with THORChain swap - failed to fetch inbound addresses: ${fetchError.message}`);
|
|
1602
1141
|
}
|
|
1603
1142
|
if (vaultAddress === "0x0000000000000000000000000000000000000000") {
|
|
@@ -1617,7 +1156,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1617
1156
|
const paddingLength = (32 - memoBytes.length % 32) % 32;
|
|
1618
1157
|
const memoPadded = memoHex + "0".repeat(paddingLength * 2);
|
|
1619
1158
|
txData = "0x" + functionSelector + vaultPadded + assetPadded + amountPadded + stringOffset + expiryPadded + stringLength + memoPadded;
|
|
1620
|
-
console.log(
|
|
1159
|
+
console.log(tag, "Encoded THORChain depositWithExpiry data:", {
|
|
1621
1160
|
functionSelector: "0x" + functionSelector,
|
|
1622
1161
|
vault: vaultAddress,
|
|
1623
1162
|
asset: assetAddress,
|
|
@@ -1627,9 +1166,9 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1627
1166
|
stringOffset: "0x" + stringOffset,
|
|
1628
1167
|
fullData: txData
|
|
1629
1168
|
});
|
|
1630
|
-
console.log(
|
|
1169
|
+
console.log(tag, "Native ETH swap - value will be set to:", amountWei.toString(), "wei");
|
|
1631
1170
|
} catch (error) {
|
|
1632
|
-
console.error(
|
|
1171
|
+
console.error(tag, "Error encoding THORChain deposit:", error);
|
|
1633
1172
|
throw new Error(`Failed to encode THORChain swap: ${error.message}`);
|
|
1634
1173
|
}
|
|
1635
1174
|
} else if (memo) {
|
|
@@ -1648,20 +1187,18 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1648
1187
|
}
|
|
1649
1188
|
case "erc20": {
|
|
1650
1189
|
const contractAddress = extractContractAddressFromCaip(caip);
|
|
1651
|
-
console.log(
|
|
1190
|
+
console.log(tag, "Fetching token decimals via pioneer-server API for", contractAddress, "on", networkId);
|
|
1652
1191
|
let tokenDecimals;
|
|
1653
1192
|
try {
|
|
1654
|
-
console.log(tag6, "Fetching token decimals via pioneer-server API for", contractAddress, "on", networkId);
|
|
1655
1193
|
const decimalsResponse = await pioneer.GetTokenDecimals({
|
|
1656
1194
|
networkId,
|
|
1657
1195
|
contractAddress
|
|
1658
1196
|
});
|
|
1659
1197
|
tokenDecimals = Number(decimalsResponse.data.decimals);
|
|
1660
|
-
console.log(
|
|
1198
|
+
console.log(tag, "✅ Fetched decimals from pioneer-server:", tokenDecimals);
|
|
1661
1199
|
} catch (error) {
|
|
1662
|
-
console.error(
|
|
1663
|
-
|
|
1664
|
-
tokenDecimals = 18;
|
|
1200
|
+
console.error(tag, "❌ CRITICAL ERROR: Failed to fetch token decimals from pioneer-server:", error);
|
|
1201
|
+
throw new Error(`Cannot build transaction: Failed to fetch decimals for token ${contractAddress} on ${networkId}. Error: ${error.message}`);
|
|
1665
1202
|
}
|
|
1666
1203
|
const tokenMultiplier = 10n ** BigInt(tokenDecimals);
|
|
1667
1204
|
let gasLimit = BigInt(1e5);
|
|
@@ -1681,7 +1218,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1681
1218
|
amountWei = tokenBalance;
|
|
1682
1219
|
} else {
|
|
1683
1220
|
amountWei = BigInt(Math.round(amount * Number(tokenMultiplier)));
|
|
1684
|
-
console.log(
|
|
1221
|
+
console.log(tag, "Token amount calculation:", {
|
|
1685
1222
|
inputAmount: amount,
|
|
1686
1223
|
decimals: tokenDecimals,
|
|
1687
1224
|
multiplier: tokenMultiplier,
|
|
@@ -1717,23 +1254,23 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1717
1254
|
}
|
|
1718
1255
|
if (pubkeyContext.addressNListMaster) {
|
|
1719
1256
|
unsignedTx.addressNList = pubkeyContext.addressNListMaster;
|
|
1720
|
-
console.log(
|
|
1257
|
+
console.log(tag, "✅ Using addressNListMaster from pubkey context:", unsignedTx.addressNList, "for address:", address);
|
|
1721
1258
|
} else if (pubkeyContext.pathMaster) {
|
|
1722
1259
|
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(pubkeyContext.pathMaster);
|
|
1723
|
-
console.log(
|
|
1260
|
+
console.log(tag, "✅ Converted pathMaster to addressNList:", pubkeyContext.pathMaster, "→", unsignedTx.addressNList);
|
|
1724
1261
|
} else if (pubkeyContext.addressNList) {
|
|
1725
1262
|
unsignedTx.addressNList = pubkeyContext.addressNList;
|
|
1726
|
-
console.log(
|
|
1263
|
+
console.log(tag, "✅ Using addressNList from pubkey context:", unsignedTx.addressNList);
|
|
1727
1264
|
} else if (pubkeyContext.path) {
|
|
1728
1265
|
unsignedTx.addressNList = import_pioneer_coins2.bip32ToAddressNList(pubkeyContext.path);
|
|
1729
|
-
console.log(
|
|
1266
|
+
console.log(tag, "⚠️ Using regular path (not master):", pubkeyContext.path, "→", unsignedTx.addressNList);
|
|
1730
1267
|
} else {
|
|
1731
1268
|
unsignedTx.addressNList = [2147483648 + 44, 2147483648 + 60, 2147483648, 0, 0];
|
|
1732
|
-
console.warn(
|
|
1269
|
+
console.warn(tag, "⚠️ No path info in pubkey context, using default account 0");
|
|
1733
1270
|
}
|
|
1734
1271
|
return unsignedTx;
|
|
1735
1272
|
} catch (error) {
|
|
1736
|
-
console.error(
|
|
1273
|
+
console.error(tag, "Error:", error.message);
|
|
1737
1274
|
throw error;
|
|
1738
1275
|
}
|
|
1739
1276
|
}
|
|
@@ -1742,7 +1279,7 @@ async function createUnsignedEvmTx(caip, to, amount, memo, pubkeys, pioneer, pub
|
|
|
1742
1279
|
var import_pioneer_caip3 = require("@pioneer-platform/pioneer-caip");
|
|
1743
1280
|
var TAG3 = " | createUnsignedUxtoTx | ";
|
|
1744
1281
|
async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax) {
|
|
1745
|
-
let
|
|
1282
|
+
let tag = TAG3 + " | createUnsignedRippleTx | ";
|
|
1746
1283
|
try {
|
|
1747
1284
|
if (!pioneer)
|
|
1748
1285
|
throw new Error("Failed to init! pioneer");
|
|
@@ -1753,7 +1290,7 @@ async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer,
|
|
|
1753
1290
|
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
1754
1291
|
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
1755
1292
|
}
|
|
1756
|
-
console.log(
|
|
1293
|
+
console.log(tag, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
1757
1294
|
address: pubkeyContext.address
|
|
1758
1295
|
});
|
|
1759
1296
|
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
@@ -1821,7 +1358,7 @@ async function createUnsignedRippleTx(caip, to, amount, memo, pubkeys, pioneer,
|
|
|
1821
1358
|
};
|
|
1822
1359
|
return unsignedTx;
|
|
1823
1360
|
} catch (error) {
|
|
1824
|
-
console.error(
|
|
1361
|
+
console.error(tag, "Error:", error);
|
|
1825
1362
|
throw error;
|
|
1826
1363
|
}
|
|
1827
1364
|
}
|
|
@@ -1961,7 +1498,7 @@ var thorchainDepositTemplate = (params) => ({
|
|
|
1961
1498
|
// src/txbuilder/createUnsignedTendermintTx.ts
|
|
1962
1499
|
var TAG4 = " | createUnsignedTendermintTx | ";
|
|
1963
1500
|
async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, to) {
|
|
1964
|
-
const
|
|
1501
|
+
const tag = TAG4 + " | createUnsignedTendermintTx | ";
|
|
1965
1502
|
try {
|
|
1966
1503
|
if (!pioneer)
|
|
1967
1504
|
throw new Error("Failed to init! pioneer");
|
|
@@ -1972,7 +1509,7 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
1972
1509
|
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
1973
1510
|
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
1974
1511
|
}
|
|
1975
|
-
console.log(
|
|
1512
|
+
console.log(tag, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
1976
1513
|
address: pubkeyContext.address,
|
|
1977
1514
|
addressNList: pubkeyContext.addressNList || pubkeyContext.addressNListMaster
|
|
1978
1515
|
});
|
|
@@ -1995,11 +1532,11 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
1995
1532
|
}
|
|
1996
1533
|
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
1997
1534
|
let asset = caip.split(":")[1];
|
|
1998
|
-
console.log(
|
|
1535
|
+
console.log(tag, `\uD83D\uDD0D Fetching account info for address: ${fromAddress}`);
|
|
1999
1536
|
const accountInfo = (await pioneer.GetAccountInfo({ network: chain, address: fromAddress })).data;
|
|
2000
|
-
console.log(
|
|
1537
|
+
console.log(tag, "\uD83D\uDCCB accountInfo:", JSON.stringify(accountInfo, null, 2));
|
|
2001
1538
|
let balanceInfo = await pioneer.GetPubkeyBalance({ asset: chain, pubkey: fromAddress });
|
|
2002
|
-
console.log(
|
|
1539
|
+
console.log(tag, `\uD83D\uDCB0 balanceInfo:`, balanceInfo);
|
|
2003
1540
|
let account_number, sequence;
|
|
2004
1541
|
if (accountInfo.account) {
|
|
2005
1542
|
account_number = accountInfo.account.account_number || "0";
|
|
@@ -2010,13 +1547,13 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2010
1547
|
} else {
|
|
2011
1548
|
throw new Error(`Unexpected account info format for ${networkId}: ${JSON.stringify(accountInfo)}`);
|
|
2012
1549
|
}
|
|
2013
|
-
console.log(
|
|
1550
|
+
console.log(tag, `\uD83D\uDCCA Extracted account_number: ${account_number}, sequence: ${sequence}`);
|
|
2014
1551
|
if (account_number === "0" || account_number === 0) {
|
|
2015
|
-
console.log(
|
|
2016
|
-
console.log(
|
|
2017
|
-
console.log(
|
|
2018
|
-
console.log(
|
|
2019
|
-
console.log(
|
|
1552
|
+
console.log(tag, `⚠️ WARNING: Account number is 0 from Pioneer API`);
|
|
1553
|
+
console.log(tag, ` This is likely due to stale Pioneer API cache`);
|
|
1554
|
+
console.log(tag, ` The mayachain-network module queries nodes directly but Pioneer API may be cached`);
|
|
1555
|
+
console.log(tag, ` Proceeding with account_number: 0 but transaction will likely fail`);
|
|
1556
|
+
console.log(tag, ` TODO: Fix Pioneer API to use fresh data from mayachain-network module`);
|
|
2020
1557
|
}
|
|
2021
1558
|
const fees = {
|
|
2022
1559
|
"cosmos:thorchain-mainnet-v1": 0.02,
|
|
@@ -2171,7 +1708,7 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2171
1708
|
}
|
|
2172
1709
|
}
|
|
2173
1710
|
} catch (error) {
|
|
2174
|
-
console.error(
|
|
1711
|
+
console.error(tag, "Error:", error);
|
|
2175
1712
|
throw error;
|
|
2176
1713
|
}
|
|
2177
1714
|
}
|
|
@@ -2200,7 +1737,7 @@ function getCoinTypeFromNetworkId(networkId) {
|
|
|
2200
1737
|
return coinType;
|
|
2201
1738
|
}
|
|
2202
1739
|
async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pubkeyContext, isMax, feeLevel = 5, changeScriptType) {
|
|
2203
|
-
let
|
|
1740
|
+
let tag = " | createUnsignedUxtoTx | ";
|
|
2204
1741
|
try {
|
|
2205
1742
|
if (!pioneer)
|
|
2206
1743
|
throw Error("Failed to init! pioneer");
|
|
@@ -2211,7 +1748,7 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2211
1748
|
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2212
1749
|
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2213
1750
|
}
|
|
2214
|
-
console.log(
|
|
1751
|
+
console.log(tag, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2215
1752
|
address: pubkeyContext.address,
|
|
2216
1753
|
scriptType: pubkeyContext.scriptType
|
|
2217
1754
|
});
|
|
@@ -2222,15 +1759,15 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2222
1759
|
const isSegwit = segwitNetworks.includes(networkId);
|
|
2223
1760
|
let chain = import_pioneer_caip5.NetworkIdToChain[networkId];
|
|
2224
1761
|
const coinType = getCoinTypeFromNetworkId(networkId);
|
|
2225
|
-
console.log(`${
|
|
1762
|
+
console.log(`${tag}: Using SLIP-44 coin type ${coinType} for ${chain}`);
|
|
2226
1763
|
const utxos = [];
|
|
2227
1764
|
for (const pubkey of relevantPubkeys) {
|
|
2228
1765
|
try {
|
|
2229
1766
|
let utxosResp = await pioneer.ListUnspent({ network: chain, xpub: pubkey.pubkey });
|
|
2230
1767
|
utxosResp = utxosResp.data;
|
|
2231
|
-
console.log(`${
|
|
1768
|
+
console.log(`${tag}: ListUnspent response for ${pubkey.scriptType}:`, utxosResp?.length || 0, "UTXOs");
|
|
2232
1769
|
if (!utxosResp || !Array.isArray(utxosResp)) {
|
|
2233
|
-
console.warn(`${
|
|
1770
|
+
console.warn(`${tag}: Invalid or empty UTXO response for ${pubkey.pubkey}`);
|
|
2234
1771
|
continue;
|
|
2235
1772
|
}
|
|
2236
1773
|
let scriptType = pubkey.scriptType;
|
|
@@ -2239,10 +1776,10 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2239
1776
|
}
|
|
2240
1777
|
utxos.push(...utxosResp);
|
|
2241
1778
|
} catch (error) {
|
|
2242
|
-
console.error(`${
|
|
1779
|
+
console.error(`${tag}: Failed to fetch UTXOs for ${pubkey.pubkey}:`, error);
|
|
2243
1780
|
}
|
|
2244
1781
|
}
|
|
2245
|
-
console.log(`${
|
|
1782
|
+
console.log(`${tag}: Total UTXOs collected:`, utxos.length);
|
|
2246
1783
|
if (!utxos || utxos.length === 0)
|
|
2247
1784
|
throw Error("No UTXOs found across all addresses");
|
|
2248
1785
|
for (const utxo of utxos) {
|
|
@@ -2255,14 +1792,14 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2255
1792
|
}, {});
|
|
2256
1793
|
const mostCommonInputType = Object.entries(scriptTypeCount).sort(([, a], [, b]) => b - a)[0]?.[0] || "p2pkh";
|
|
2257
1794
|
const actualChangeScriptType = changeScriptType || mostCommonInputType || relevantPubkeys[0]?.scriptType || "p2pkh";
|
|
2258
|
-
console.log(`${
|
|
2259
|
-
console.log(`${
|
|
1795
|
+
console.log(`${tag}: Input script types:`, scriptTypeCount);
|
|
1796
|
+
console.log(`${tag}: Using change script type: ${actualChangeScriptType} (matches inputs: ${mostCommonInputType})`);
|
|
2260
1797
|
const changeXpubInfo = relevantPubkeys.find((pk) => pk.scriptType === actualChangeScriptType);
|
|
2261
1798
|
if (!changeXpubInfo) {
|
|
2262
1799
|
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.`);
|
|
2263
1800
|
}
|
|
2264
1801
|
const changeXpub = changeXpubInfo.pubkey;
|
|
2265
|
-
console.log(`${
|
|
1802
|
+
console.log(`${tag}: Change xpub selected for ${actualChangeScriptType}:`, changeXpub?.substring(0, 10) + "...");
|
|
2266
1803
|
let changeAddressIndex = await pioneer.GetChangeAddress({
|
|
2267
1804
|
network: chain,
|
|
2268
1805
|
xpub: changeXpub
|
|
@@ -2282,7 +1819,7 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2282
1819
|
break;
|
|
2283
1820
|
}
|
|
2284
1821
|
const path = bipPath;
|
|
2285
|
-
console.log(`${
|
|
1822
|
+
console.log(`${tag}: Change address path: ${path} (coin type: ${coinType}, index: ${changeAddressIndex})`);
|
|
2286
1823
|
const changeAddress = {
|
|
2287
1824
|
path,
|
|
2288
1825
|
isChange: true,
|
|
@@ -2292,7 +1829,7 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2292
1829
|
};
|
|
2293
1830
|
let feeRateFromNode;
|
|
2294
1831
|
if (networkId === "bip122:00000000001a91e3dace36e2be3bf030") {
|
|
2295
|
-
console.log(`${
|
|
1832
|
+
console.log(`${tag}: Using hardcoded fees for DOGE (10 sat/byte)`);
|
|
2296
1833
|
feeRateFromNode = {
|
|
2297
1834
|
slow: 10,
|
|
2298
1835
|
average: 10,
|
|
@@ -2305,19 +1842,19 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2305
1842
|
try {
|
|
2306
1843
|
let feeResponse;
|
|
2307
1844
|
if (pioneer.GetFeeRateByNetwork) {
|
|
2308
|
-
console.log(`${
|
|
1845
|
+
console.log(`${tag}: Trying GetFeeRateByNetwork for ${networkId}`);
|
|
2309
1846
|
feeResponse = await pioneer.GetFeeRateByNetwork({ networkId });
|
|
2310
1847
|
} else {
|
|
2311
|
-
console.log(`${
|
|
1848
|
+
console.log(`${tag}: Using GetFeeRate for ${networkId}`);
|
|
2312
1849
|
feeResponse = await pioneer.GetFeeRate({ networkId });
|
|
2313
1850
|
}
|
|
2314
1851
|
feeRateFromNode = feeResponse.data;
|
|
2315
|
-
console.log(`${
|
|
1852
|
+
console.log(`${tag}: Got fee rates from API:`, JSON.stringify(feeRateFromNode, null, 2));
|
|
2316
1853
|
const conversionThreshold = 500;
|
|
2317
1854
|
const needsConversion = feeRateFromNode.slow && feeRateFromNode.slow > conversionThreshold || feeRateFromNode.average && feeRateFromNode.average > conversionThreshold || feeRateFromNode.fast && feeRateFromNode.fast > conversionThreshold || feeRateFromNode.fastest && feeRateFromNode.fastest > conversionThreshold;
|
|
2318
1855
|
if (needsConversion) {
|
|
2319
|
-
console.warn(`${
|
|
2320
|
-
console.warn(`${
|
|
1856
|
+
console.warn(`${tag}: Detected wrong units - values appear to be in sat/kB instead of sat/byte`);
|
|
1857
|
+
console.warn(`${tag}: Original values:`, {
|
|
2321
1858
|
slow: feeRateFromNode.slow,
|
|
2322
1859
|
average: feeRateFromNode.average,
|
|
2323
1860
|
fast: feeRateFromNode.fast,
|
|
@@ -2331,12 +1868,12 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2331
1868
|
feeRateFromNode.fast = feeRateFromNode.fast / 1000;
|
|
2332
1869
|
if (feeRateFromNode.fastest)
|
|
2333
1870
|
feeRateFromNode.fastest = feeRateFromNode.fastest / 1000;
|
|
2334
|
-
console.warn(`${
|
|
1871
|
+
console.warn(`${tag}: Converted to sat/byte:`, feeRateFromNode);
|
|
2335
1872
|
}
|
|
2336
1873
|
if (!feeRateFromNode || typeof feeRateFromNode !== "object") {
|
|
2337
1874
|
throw new Error(`Invalid fee rate response from API: ${JSON.stringify(feeRateFromNode)}`);
|
|
2338
1875
|
}
|
|
2339
|
-
console.log(`${
|
|
1876
|
+
console.log(`${tag}: Available fee rates:`, {
|
|
2340
1877
|
slow: feeRateFromNode.slow,
|
|
2341
1878
|
average: feeRateFromNode.average,
|
|
2342
1879
|
fast: feeRateFromNode.fast,
|
|
@@ -2346,33 +1883,33 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2346
1883
|
throw new Error(`No valid fee rates in API response: ${JSON.stringify(feeRateFromNode)}`);
|
|
2347
1884
|
}
|
|
2348
1885
|
} catch (error) {
|
|
2349
|
-
console.error(`${
|
|
1886
|
+
console.error(`${tag}: Failed to get fee rates from Pioneer API:`, error.message || error);
|
|
2350
1887
|
throw new Error(`Unable to get fee rate for network ${networkId}: ${error.message || "API unavailable"}`);
|
|
2351
1888
|
}
|
|
2352
1889
|
}
|
|
2353
1890
|
let effectiveFeeRate;
|
|
2354
|
-
console.log(`${
|
|
1891
|
+
console.log(`${tag}: Using fee level ${feeLevel}`);
|
|
2355
1892
|
switch (feeLevel) {
|
|
2356
1893
|
case 1:
|
|
2357
1894
|
case 2:
|
|
2358
1895
|
effectiveFeeRate = feeRateFromNode.slow || feeRateFromNode.average;
|
|
2359
|
-
console.log(`${
|
|
1896
|
+
console.log(`${tag}: Using SLOW fee rate: ${effectiveFeeRate} sat/vB`);
|
|
2360
1897
|
break;
|
|
2361
1898
|
case 3:
|
|
2362
1899
|
case 4:
|
|
2363
1900
|
effectiveFeeRate = feeRateFromNode.average || feeRateFromNode.fast;
|
|
2364
|
-
console.log(`${
|
|
1901
|
+
console.log(`${tag}: Using AVERAGE fee rate: ${effectiveFeeRate} sat/vB`);
|
|
2365
1902
|
break;
|
|
2366
1903
|
case 5:
|
|
2367
1904
|
effectiveFeeRate = feeRateFromNode.fastest || feeRateFromNode.fast;
|
|
2368
|
-
console.log(`${
|
|
1905
|
+
console.log(`${tag}: Using FASTEST fee rate: ${effectiveFeeRate} sat/vB`);
|
|
2369
1906
|
break;
|
|
2370
1907
|
default:
|
|
2371
1908
|
throw new Error(`Invalid fee level: ${feeLevel}. Must be 1-5`);
|
|
2372
1909
|
}
|
|
2373
1910
|
if (!effectiveFeeRate)
|
|
2374
1911
|
throw new Error("Unable to get fee rate for network");
|
|
2375
|
-
console.log(`${
|
|
1912
|
+
console.log(`${tag}: Using fee rate from API:`, {
|
|
2376
1913
|
feeLevel,
|
|
2377
1914
|
selectedRate: effectiveFeeRate,
|
|
2378
1915
|
description: feeLevel <= 2 ? "slow" : feeLevel <= 4 ? "average" : "fast"
|
|
@@ -2382,22 +1919,22 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2382
1919
|
effectiveFeeRate = Math.ceil(effectiveFeeRate);
|
|
2383
1920
|
const MIN_RELAY_FEE_RATE = 3;
|
|
2384
1921
|
if (effectiveFeeRate < MIN_RELAY_FEE_RATE) {
|
|
2385
|
-
console.log(`${
|
|
1922
|
+
console.log(`${tag}: Fee rate ${effectiveFeeRate} is below minimum relay fee, increasing to ${MIN_RELAY_FEE_RATE} sat/vB`);
|
|
2386
1923
|
effectiveFeeRate = MIN_RELAY_FEE_RATE;
|
|
2387
1924
|
}
|
|
2388
|
-
console.log(`${
|
|
1925
|
+
console.log(`${tag}: Final fee rate to use (rounded, with minimums): ${effectiveFeeRate} sat/vB`);
|
|
2389
1926
|
amount = parseInt(String(amount * 1e8));
|
|
2390
1927
|
if (amount <= 0 && !isMax)
|
|
2391
1928
|
throw Error("Invalid amount! 0");
|
|
2392
1929
|
const totalBalance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
2393
|
-
console.log(`${
|
|
1930
|
+
console.log(`${tag}: Coin selection inputs:`, {
|
|
2394
1931
|
utxoCount: utxos.length,
|
|
2395
1932
|
totalBalance: totalBalance / 1e8,
|
|
2396
1933
|
requestedAmount: amount / 1e8,
|
|
2397
1934
|
isMax,
|
|
2398
1935
|
feeRate: effectiveFeeRate
|
|
2399
1936
|
});
|
|
2400
|
-
console.log(`${
|
|
1937
|
+
console.log(`${tag}: UTXO details for coin selection:`, utxos.map((u) => ({
|
|
2401
1938
|
value: u.value,
|
|
2402
1939
|
txid: u.txid?.substring(0, 10) + "...",
|
|
2403
1940
|
vout: u.vout,
|
|
@@ -2411,8 +1948,8 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2411
1948
|
} else {
|
|
2412
1949
|
result = import_coinselect.default(utxos, [{ address: to, value: amount }], effectiveFeeRate);
|
|
2413
1950
|
}
|
|
2414
|
-
console.log(
|
|
2415
|
-
console.log(
|
|
1951
|
+
console.log(tag, "coinSelect result object:", result);
|
|
1952
|
+
console.log(tag, "coinSelect result.inputs:", result?.inputs);
|
|
2416
1953
|
if (!result || !result.inputs) {
|
|
2417
1954
|
const errorDetails = {
|
|
2418
1955
|
utxoCount: utxos.length,
|
|
@@ -2421,7 +1958,7 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2421
1958
|
feeRate: effectiveFeeRate,
|
|
2422
1959
|
insufficientFunds: totalBalance < amount
|
|
2423
1960
|
};
|
|
2424
|
-
console.error(`${
|
|
1961
|
+
console.error(`${tag}: Coin selection failed:`, errorDetails);
|
|
2425
1962
|
if (utxos.length === 0) {
|
|
2426
1963
|
throw Error("No UTXOs available for coin selection");
|
|
2427
1964
|
} else if (totalBalance < amount) {
|
|
@@ -2437,7 +1974,7 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2437
1974
|
throw Error("Failed to create transaction: Missing outputs");
|
|
2438
1975
|
if (fee === undefined)
|
|
2439
1976
|
throw Error("Failed to calculate transaction fee");
|
|
2440
|
-
console.log(`${
|
|
1977
|
+
console.log(`${tag}: Transaction built with:`, {
|
|
2441
1978
|
feeLevel,
|
|
2442
1979
|
effectiveFeeRate: `${effectiveFeeRate} sat/vB`,
|
|
2443
1980
|
calculatedFee: `${fee} satoshis`,
|
|
@@ -2445,8 +1982,8 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2445
1982
|
outputCount: outputs.length
|
|
2446
1983
|
});
|
|
2447
1984
|
const uniqueInputSet = new Set;
|
|
2448
|
-
console.log(
|
|
2449
|
-
console.log(
|
|
1985
|
+
console.log(tag, "inputs:", inputs);
|
|
1986
|
+
console.log(tag, "inputs:", inputs[0]);
|
|
2450
1987
|
const preparedInputs = inputs.map(transformInput).filter(({ hash, index }) => uniqueInputSet.has(`${hash}:${index}`) ? false : uniqueInputSet.add(`${hash}:${index}`)).map(({ value, index, hash, txHex, path: path2, scriptType }) => ({
|
|
2451
1988
|
addressNList: import_pioneer_coins3.bip32ToAddressNList(path2),
|
|
2452
1989
|
scriptType,
|
|
@@ -2575,7 +2112,7 @@ class TransactionManager {
|
|
|
2575
2112
|
throw new Error(`Unsupported CAIP: ${caipString}`);
|
|
2576
2113
|
}
|
|
2577
2114
|
async transfer({ caip, to, amount, memo, isMax = false, feeLevel = 5, changeScriptType }) {
|
|
2578
|
-
let
|
|
2115
|
+
let tag = TAG5 + " | transfer | ";
|
|
2579
2116
|
try {
|
|
2580
2117
|
if (!this.pioneer)
|
|
2581
2118
|
throw Error("Failed to init! pioneer");
|
|
@@ -2613,12 +2150,12 @@ class TransactionManager {
|
|
|
2613
2150
|
}
|
|
2614
2151
|
return unsignedTx;
|
|
2615
2152
|
} catch (e) {
|
|
2616
|
-
console.error(
|
|
2153
|
+
console.error(tag, e);
|
|
2617
2154
|
throw e;
|
|
2618
2155
|
}
|
|
2619
2156
|
}
|
|
2620
2157
|
async sign({ caip, unsignedTx }) {
|
|
2621
|
-
let
|
|
2158
|
+
let tag = TAG5 + " | sign | ";
|
|
2622
2159
|
try {
|
|
2623
2160
|
if (!this.pioneer)
|
|
2624
2161
|
throw Error("Failed to init! pioneer");
|
|
@@ -2704,20 +2241,20 @@ class TransactionManager {
|
|
|
2704
2241
|
}
|
|
2705
2242
|
case "cosmos:mayachain-mainnet-v1/slip44:931":
|
|
2706
2243
|
case "cosmos:mayachain-mainnet-v1/denom:maya": {
|
|
2707
|
-
console.log(
|
|
2708
|
-
console.log(
|
|
2709
|
-
console.log(
|
|
2710
|
-
console.log(
|
|
2711
|
-
console.log(
|
|
2712
|
-
console.log(
|
|
2713
|
-
console.log(
|
|
2714
|
-
console.log(
|
|
2715
|
-
console.log(
|
|
2244
|
+
console.log(tag, "\uD83D\uDD0D ===== MAYACHAIN SIGNING AUDIT =====");
|
|
2245
|
+
console.log(tag, "\uD83D\uDCCB unsignedTx:", JSON.stringify(unsignedTx, null, 2));
|
|
2246
|
+
console.log(tag, "\uD83D\uDD11 unsignedTx.addressNList:", unsignedTx.addressNList);
|
|
2247
|
+
console.log(tag, "\uD83D\uDCCD unsignedTx.signerAddress:", unsignedTx.signerAddress);
|
|
2248
|
+
console.log(tag, "\uD83C\uDF10 pubkeyContext:", this.pubkeyContext);
|
|
2249
|
+
console.log(tag, "\uD83D\uDD10 pubkeyContext.addressNList:", this.pubkeyContext?.addressNList);
|
|
2250
|
+
console.log(tag, "\uD83D\uDD10 pubkeyContext.addressNListMaster:", this.pubkeyContext?.addressNListMaster);
|
|
2251
|
+
console.log(tag, "\uD83D\uDCEC pubkeyContext.address:", this.pubkeyContext?.address);
|
|
2252
|
+
console.log(tag, "=======================================");
|
|
2716
2253
|
if (unsignedTx.signDoc.msgs[0].type === "mayachain/MsgSend") {
|
|
2717
2254
|
const responseSign = await this.keepKeySdk.mayachain.mayachainSignAminoTransfer(unsignedTx);
|
|
2718
2255
|
signedTx = responseSign.serialized;
|
|
2719
|
-
console.log(
|
|
2720
|
-
console.log(
|
|
2256
|
+
console.log(tag, "✅ Signing completed");
|
|
2257
|
+
console.log(tag, "\uD83D\uDCE6 responseSign:", responseSign);
|
|
2721
2258
|
} else if (unsignedTx.signDoc.msgs[0].type === "mayachain/MsgDeposit") {
|
|
2722
2259
|
const responseSign = await this.keepKeySdk.mayachain.mayachainSignAminoDeposit(unsignedTx);
|
|
2723
2260
|
signedTx = responseSign.serialized;
|
|
@@ -2739,11 +2276,11 @@ class TransactionManager {
|
|
|
2739
2276
|
if (serialized.length > 140) {
|
|
2740
2277
|
signedTx = serialized;
|
|
2741
2278
|
} else {
|
|
2742
|
-
console.error(
|
|
2279
|
+
console.error(tag, "EIP155 signing returned incomplete transaction - only signature components");
|
|
2743
2280
|
throw new Error("KeepKey returned incomplete transaction - cannot reconstruct without r,s,v components");
|
|
2744
2281
|
}
|
|
2745
2282
|
} else {
|
|
2746
|
-
console.error(
|
|
2283
|
+
console.error(tag, "EIP155 signing failed - no valid signature in response:", responseSign);
|
|
2747
2284
|
throw new Error("Failed to sign transaction - no valid signature in response");
|
|
2748
2285
|
}
|
|
2749
2286
|
break;
|
|
@@ -2764,19 +2301,19 @@ class TransactionManager {
|
|
|
2764
2301
|
}
|
|
2765
2302
|
}
|
|
2766
2303
|
if (!signedTx) {
|
|
2767
|
-
console.error(
|
|
2768
|
-
console.error(
|
|
2769
|
-
console.error(
|
|
2304
|
+
console.error(tag, "CRITICAL ERROR: signedTx is missing after signing process");
|
|
2305
|
+
console.error(tag, "CAIP:", caip);
|
|
2306
|
+
console.error(tag, "Type:", type);
|
|
2770
2307
|
throw Error("Failed to sign! missing signedTx");
|
|
2771
2308
|
}
|
|
2772
2309
|
return signedTx;
|
|
2773
2310
|
} catch (e) {
|
|
2774
|
-
console.error(
|
|
2311
|
+
console.error(tag, e);
|
|
2775
2312
|
throw e;
|
|
2776
2313
|
}
|
|
2777
2314
|
}
|
|
2778
2315
|
async broadcast({ networkId, serialized }) {
|
|
2779
|
-
let
|
|
2316
|
+
let tag = TAG5 + " | broadcast | ";
|
|
2780
2317
|
try {
|
|
2781
2318
|
if (!this.pioneer)
|
|
2782
2319
|
throw Error("Failed to init! pioneer");
|
|
@@ -2790,7 +2327,7 @@ class TransactionManager {
|
|
|
2790
2327
|
return result.txid;
|
|
2791
2328
|
}
|
|
2792
2329
|
} catch (e) {
|
|
2793
|
-
console.error(
|
|
2330
|
+
console.error(tag, e);
|
|
2794
2331
|
throw e;
|
|
2795
2332
|
}
|
|
2796
2333
|
}
|
|
@@ -2910,7 +2447,7 @@ var cosmosClaimAllRewardsTemplate = (params) => ({
|
|
|
2910
2447
|
// src/txbuilder/createUnsignedStakingTx.ts
|
|
2911
2448
|
var TAG6 = " | createUnsignedStakingTx | ";
|
|
2912
2449
|
async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyContext) {
|
|
2913
|
-
const
|
|
2450
|
+
const tag = TAG6 + " | createUnsignedStakingTx | ";
|
|
2914
2451
|
try {
|
|
2915
2452
|
if (!pioneer)
|
|
2916
2453
|
throw new Error("Failed to init! pioneer");
|
|
@@ -2921,7 +2458,7 @@ async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyCon
|
|
|
2921
2458
|
if (!pubkeyContext.networks?.includes(networkId)) {
|
|
2922
2459
|
throw new Error(`Pubkey context is for wrong network. Expected ${networkId}, got ${pubkeyContext.networks}`);
|
|
2923
2460
|
}
|
|
2924
|
-
console.log(
|
|
2461
|
+
console.log(tag, `✅ Using pubkeyContext for network ${networkId}:`, {
|
|
2925
2462
|
address: pubkeyContext.address
|
|
2926
2463
|
});
|
|
2927
2464
|
let chain;
|
|
@@ -2953,10 +2490,10 @@ async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyCon
|
|
|
2953
2490
|
default:
|
|
2954
2491
|
throw new Error(`Unsupported networkId for staking: ${networkId}`);
|
|
2955
2492
|
}
|
|
2956
|
-
console.log(
|
|
2493
|
+
console.log(tag, `Building ${params.type} transaction for ${chain}`);
|
|
2957
2494
|
const fromAddress = pubkeyContext.address || pubkeyContext.pubkey;
|
|
2958
2495
|
const accountInfo = (await pioneer.GetAccountInfo({ network: chain, address: fromAddress })).data;
|
|
2959
|
-
console.log(
|
|
2496
|
+
console.log(tag, "accountInfo: ", accountInfo);
|
|
2960
2497
|
let account_number;
|
|
2961
2498
|
let sequence;
|
|
2962
2499
|
if (networkId === "cosmos:cosmoshub-4" || networkId === "cosmos:osmosis-1") {
|
|
@@ -3038,7 +2575,7 @@ async function createUnsignedStakingTx(caip, params, pubkeys, pioneer, pubkeyCon
|
|
|
3038
2575
|
throw new Error(`Unsupported staking transaction type: ${params.type}`);
|
|
3039
2576
|
}
|
|
3040
2577
|
} catch (error) {
|
|
3041
|
-
console.error(
|
|
2578
|
+
console.error(tag, "Error:", error);
|
|
3042
2579
|
throw error;
|
|
3043
2580
|
}
|
|
3044
2581
|
}
|
|
@@ -3084,16 +2621,16 @@ function withTimeout(promise, timeoutMs) {
|
|
|
3084
2621
|
]);
|
|
3085
2622
|
}
|
|
3086
2623
|
async function getFees(pioneer, networkId) {
|
|
3087
|
-
const
|
|
2624
|
+
const tag = TAG7 + " | getFees | ";
|
|
3088
2625
|
try {
|
|
3089
|
-
console.log(
|
|
2626
|
+
console.log(tag, `Fetching fees for network: ${networkId}`);
|
|
3090
2627
|
const networkType = getNetworkType(networkId);
|
|
3091
2628
|
if (networkType === "COSMOS") {
|
|
3092
|
-
console.log(
|
|
2629
|
+
console.log(tag, "Using hardcoded fees for Cosmos network:", networkId);
|
|
3093
2630
|
return getCosmosFees(networkId);
|
|
3094
2631
|
}
|
|
3095
2632
|
if (networkId === "bip122:00000000001a91e3dace36e2be3bf030") {
|
|
3096
|
-
console.log(
|
|
2633
|
+
console.log(tag, "Using hardcoded fees for Dogecoin: 10 sat/byte");
|
|
3097
2634
|
return {
|
|
3098
2635
|
slow: {
|
|
3099
2636
|
label: "Slow",
|
|
@@ -3130,7 +2667,7 @@ async function getFees(pioneer, networkId) {
|
|
|
3130
2667
|
const apiCall = pioneer.GetFeeRateByNetwork ? pioneer.GetFeeRateByNetwork({ networkId }) : pioneer.GetFeeRate({ networkId });
|
|
3131
2668
|
feeResponse = await withTimeout(apiCall, 3000);
|
|
3132
2669
|
} catch (timeoutError) {
|
|
3133
|
-
console.warn(
|
|
2670
|
+
console.warn(tag, "Dash fee API timeout, using fallback fees");
|
|
3134
2671
|
return {
|
|
3135
2672
|
slow: {
|
|
3136
2673
|
label: "Economy",
|
|
@@ -3163,10 +2700,10 @@ async function getFees(pioneer, networkId) {
|
|
|
3163
2700
|
}
|
|
3164
2701
|
} else {
|
|
3165
2702
|
if (networkType === "EVM") {
|
|
3166
|
-
console.log(
|
|
2703
|
+
console.log(tag, "Using GetGasPriceByNetwork for EVM network:", networkId);
|
|
3167
2704
|
feeResponse = await (pioneer.GetGasPriceByNetwork ? pioneer.GetGasPriceByNetwork({ networkId }) : Promise.reject(new Error("GetGasPriceByNetwork not available")));
|
|
3168
2705
|
} else {
|
|
3169
|
-
console.log(
|
|
2706
|
+
console.log(tag, "Using GetFeeRateByNetwork for UTXO network:", networkId);
|
|
3170
2707
|
feeResponse = await (pioneer.GetFeeRateByNetwork ? pioneer.GetFeeRateByNetwork({ networkId }) : pioneer.GetFeeRate({ networkId }));
|
|
3171
2708
|
}
|
|
3172
2709
|
}
|
|
@@ -3174,17 +2711,17 @@ async function getFees(pioneer, networkId) {
|
|
|
3174
2711
|
throw new Error(`No fee data returned for ${networkId}`);
|
|
3175
2712
|
}
|
|
3176
2713
|
const feeData = feeResponse.data;
|
|
3177
|
-
console.log(
|
|
2714
|
+
console.log(tag, "Raw fee data:", feeData);
|
|
3178
2715
|
const networkName = getNetworkName(networkId);
|
|
3179
2716
|
let normalizedFees = normalizeFeeData(feeData, networkType, networkName, networkId);
|
|
3180
2717
|
normalizedFees = ensureFeeDifferentiation(normalizedFees, networkType);
|
|
3181
2718
|
normalizedFees.networkId = networkId;
|
|
3182
2719
|
normalizedFees.networkType = networkType;
|
|
3183
2720
|
normalizedFees.raw = feeData;
|
|
3184
|
-
console.log(
|
|
2721
|
+
console.log(tag, "Normalized fees:", normalizedFees);
|
|
3185
2722
|
return normalizedFees;
|
|
3186
2723
|
} catch (error) {
|
|
3187
|
-
console.error(
|
|
2724
|
+
console.error(tag, "Failed to fetch fees:", error);
|
|
3188
2725
|
return getFallbackFees(networkId);
|
|
3189
2726
|
}
|
|
3190
2727
|
}
|
|
@@ -3493,7 +3030,7 @@ function estimateTransactionFee(feeRate, unit, networkType, txSize) {
|
|
|
3493
3030
|
|
|
3494
3031
|
// src/utils/kkapi-detection.ts
|
|
3495
3032
|
async function detectKkApiAvailability(forceLocalhost) {
|
|
3496
|
-
const
|
|
3033
|
+
const tag = " | detectKkApiAvailability | ";
|
|
3497
3034
|
try {
|
|
3498
3035
|
const isTauri = typeof window !== "undefined" && "__TAURI__" in window;
|
|
3499
3036
|
const isBrowser = typeof window !== "undefined";
|
|
@@ -3652,11 +3189,11 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3652
3189
|
// src/utils/sync-market.ts
|
|
3653
3190
|
var TAG8 = " | sync-market | ";
|
|
3654
3191
|
async function syncMarket(balances, pioneer) {
|
|
3655
|
-
const
|
|
3192
|
+
const tag = `${TAG8} | syncMarket | `;
|
|
3656
3193
|
try {
|
|
3657
3194
|
const invalidBalances = balances.filter((b) => !b || !b.caip || typeof b.caip !== "string" || !b.caip.includes(":"));
|
|
3658
3195
|
if (invalidBalances.length > 0) {
|
|
3659
|
-
console.warn(
|
|
3196
|
+
console.warn(tag, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b) => ({
|
|
3660
3197
|
caip: b?.caip,
|
|
3661
3198
|
type: typeof b?.caip,
|
|
3662
3199
|
symbol: b?.symbol,
|
|
@@ -3671,7 +3208,7 @@ async function syncMarket(balances, pioneer) {
|
|
|
3671
3208
|
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
3672
3209
|
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
3673
3210
|
if (invalidEntries.length > 0) {
|
|
3674
|
-
console.error(
|
|
3211
|
+
console.error(tag, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
3675
3212
|
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
3676
3213
|
}
|
|
3677
3214
|
if (allCaips && allCaips.length > 0) {
|
|
@@ -3692,13 +3229,13 @@ async function syncMarket(balances, pioneer) {
|
|
|
3692
3229
|
}
|
|
3693
3230
|
}
|
|
3694
3231
|
} catch (apiError) {
|
|
3695
|
-
console.error(
|
|
3696
|
-
console.warn(
|
|
3232
|
+
console.error(tag, "API error fetching market info:", apiError);
|
|
3233
|
+
console.warn(tag, "Continuing without market prices");
|
|
3697
3234
|
}
|
|
3698
3235
|
}
|
|
3699
3236
|
return true;
|
|
3700
3237
|
} catch (e) {
|
|
3701
|
-
console.error(
|
|
3238
|
+
console.error(tag, "e:", e);
|
|
3702
3239
|
throw e;
|
|
3703
3240
|
}
|
|
3704
3241
|
}
|
|
@@ -3813,7 +3350,7 @@ class SDK {
|
|
|
3813
3350
|
this.appIcon = config.appIcon || "https://pioneers.dev/coins/keepkey.png";
|
|
3814
3351
|
this.spec = spec || config.spec || "https://api.keepkey.info/spec/swagger";
|
|
3815
3352
|
this.wss = config.wss || "wss://pioneers.dev";
|
|
3816
|
-
this.assets =
|
|
3353
|
+
this.assets = import_pioneer_discovery.assetData;
|
|
3817
3354
|
this.assetsMap = new Map;
|
|
3818
3355
|
this.username = config.username;
|
|
3819
3356
|
this.queryKey = config.queryKey;
|
|
@@ -3891,7 +3428,7 @@ class SDK {
|
|
|
3891
3428
|
return true;
|
|
3892
3429
|
};
|
|
3893
3430
|
this.setPubkeys = (newPubkeys) => {
|
|
3894
|
-
const
|
|
3431
|
+
const tag = `${TAG9} | setPubkeys | `;
|
|
3895
3432
|
this.pubkeys = [];
|
|
3896
3433
|
this.pubkeySet.clear();
|
|
3897
3434
|
let added = 0;
|
|
@@ -3908,7 +3445,7 @@ class SDK {
|
|
|
3908
3445
|
this.pubkeySet.clear();
|
|
3909
3446
|
}
|
|
3910
3447
|
this.getUnifiedPortfolio = async function() {
|
|
3911
|
-
const
|
|
3448
|
+
const tag = `${TAG9} | getUnifiedPortfolio | `;
|
|
3912
3449
|
try {
|
|
3913
3450
|
const startTime = performance.now();
|
|
3914
3451
|
try {
|
|
@@ -3919,17 +3456,17 @@ class SDK {
|
|
|
3919
3456
|
signal: AbortSignal.timeout(2000)
|
|
3920
3457
|
});
|
|
3921
3458
|
if (!portfolioResponse.ok) {
|
|
3922
|
-
console.warn(
|
|
3459
|
+
console.warn(tag, "Portfolio endpoint returned", portfolioResponse.status);
|
|
3923
3460
|
return null;
|
|
3924
3461
|
}
|
|
3925
3462
|
const portfolioData = await portfolioResponse.json();
|
|
3926
3463
|
const loadTime = performance.now() - startTime;
|
|
3927
3464
|
if (!portfolioData.success) {
|
|
3928
|
-
console.warn(
|
|
3465
|
+
console.warn(tag, "Portfolio API returned success=false");
|
|
3929
3466
|
return null;
|
|
3930
3467
|
}
|
|
3931
3468
|
if (portfolioData.totalValueUsd === 0 || !portfolioData.totalValueUsd) {
|
|
3932
|
-
console.warn(
|
|
3469
|
+
console.warn(tag, "Portfolio value is $0.00 - may need device connection or sync");
|
|
3933
3470
|
return null;
|
|
3934
3471
|
}
|
|
3935
3472
|
let allBalances = [];
|
|
@@ -4016,14 +3553,14 @@ class SDK {
|
|
|
4016
3553
|
};
|
|
4017
3554
|
} catch (fetchError) {
|
|
4018
3555
|
if (fetchError.name === "AbortError") {
|
|
4019
|
-
console.log(
|
|
3556
|
+
console.log(tag, "Unified portfolio request timed out (this is normal if vault not running)");
|
|
4020
3557
|
} else {
|
|
4021
|
-
console.log(
|
|
3558
|
+
console.log(tag, "Failed to fetch unified portfolio:", fetchError.message);
|
|
4022
3559
|
}
|
|
4023
3560
|
return null;
|
|
4024
3561
|
}
|
|
4025
3562
|
} catch (e) {
|
|
4026
|
-
console.error(
|
|
3563
|
+
console.error(tag, "Error:", e);
|
|
4027
3564
|
return null;
|
|
4028
3565
|
}
|
|
4029
3566
|
};
|
|
@@ -4034,7 +3571,7 @@ class SDK {
|
|
|
4034
3571
|
return this.syncState.isSynced;
|
|
4035
3572
|
};
|
|
4036
3573
|
this.init = async function(walletsVerbose, setup) {
|
|
4037
|
-
const
|
|
3574
|
+
const tag = `${TAG9} | init | `;
|
|
4038
3575
|
try {
|
|
4039
3576
|
if (!this.username)
|
|
4040
3577
|
throw Error("username required!");
|
|
@@ -4090,11 +3627,11 @@ class SDK {
|
|
|
4090
3627
|
this.events.emit("message", request);
|
|
4091
3628
|
});
|
|
4092
3629
|
clientEvents.events.on("balance:update", (data) => {
|
|
4093
|
-
const
|
|
3630
|
+
const tag2 = TAG9 + " | balance:update | ";
|
|
4094
3631
|
try {
|
|
4095
3632
|
const payload = typeof data === "string" ? JSON.parse(data) : data;
|
|
4096
3633
|
const balance = payload.balance;
|
|
4097
|
-
console.log(
|
|
3634
|
+
console.log(tag2, "Received balance update:", balance.caip);
|
|
4098
3635
|
const exists = this.balances.find((b) => b.caip === balance.caip && b.pubkey === balance.pubkey);
|
|
4099
3636
|
if (!exists) {
|
|
4100
3637
|
this.balances.push(balance);
|
|
@@ -4104,27 +3641,27 @@ class SDK {
|
|
|
4104
3641
|
}
|
|
4105
3642
|
this.events.emit("BALANCE_UPDATE", balance);
|
|
4106
3643
|
} catch (e) {
|
|
4107
|
-
console.error(
|
|
3644
|
+
console.error(tag2, "Error processing balance update:", e);
|
|
4108
3645
|
}
|
|
4109
3646
|
});
|
|
4110
3647
|
clientEvents.events.on("sync:progress", (data) => {
|
|
4111
|
-
const
|
|
3648
|
+
const tag2 = TAG9 + " | sync:progress | ";
|
|
4112
3649
|
try {
|
|
4113
3650
|
const payload = typeof data === "string" ? JSON.parse(data) : data;
|
|
4114
|
-
console.log(
|
|
3651
|
+
console.log(tag2, `Sync progress: ${payload.percentage}%`);
|
|
4115
3652
|
this.syncState.syncProgress = payload.percentage;
|
|
4116
3653
|
this.syncState.syncedChains = payload.completed;
|
|
4117
3654
|
this.syncState.totalChains = payload.total;
|
|
4118
3655
|
this.events.emit("SYNC_PROGRESS", this.syncState);
|
|
4119
3656
|
} catch (e) {
|
|
4120
|
-
console.error(
|
|
3657
|
+
console.error(tag2, "Error processing sync progress:", e);
|
|
4121
3658
|
}
|
|
4122
3659
|
});
|
|
4123
3660
|
clientEvents.events.on("sync:complete", (data) => {
|
|
4124
|
-
const
|
|
3661
|
+
const tag2 = TAG9 + " | sync:complete | ";
|
|
4125
3662
|
try {
|
|
4126
3663
|
const payload = typeof data === "string" ? JSON.parse(data) : data;
|
|
4127
|
-
console.log(
|
|
3664
|
+
console.log(tag2, `Sync complete: ${payload.balances} balances in ${payload.duration}ms`);
|
|
4128
3665
|
this.syncState.isSynced = true;
|
|
4129
3666
|
this.syncState.isInitialSync = false;
|
|
4130
3667
|
this.syncState.syncProgress = 100;
|
|
@@ -4133,7 +3670,7 @@ class SDK {
|
|
|
4133
3670
|
this.events.emit("SYNC_COMPLETE", this.syncState);
|
|
4134
3671
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4135
3672
|
} catch (e) {
|
|
4136
|
-
console.error(
|
|
3673
|
+
console.error(tag2, "Error processing sync complete:", e);
|
|
4137
3674
|
}
|
|
4138
3675
|
});
|
|
4139
3676
|
this.events.emit("SET_STATUS", "init");
|
|
@@ -4165,7 +3702,7 @@ class SDK {
|
|
|
4165
3702
|
}
|
|
4166
3703
|
return this.pioneer;
|
|
4167
3704
|
} catch (e) {
|
|
4168
|
-
console.error(
|
|
3705
|
+
console.error(tag, "e: ", e);
|
|
4169
3706
|
throw e;
|
|
4170
3707
|
}
|
|
4171
3708
|
};
|
|
@@ -4176,7 +3713,7 @@ class SDK {
|
|
|
4176
3713
|
return syncMarket(this.balances, this.pioneer);
|
|
4177
3714
|
};
|
|
4178
3715
|
this.sync = async function() {
|
|
4179
|
-
const
|
|
3716
|
+
const tag = `${TAG9} | sync | `;
|
|
4180
3717
|
try {
|
|
4181
3718
|
const matchesNetwork = (item, networkId) => {
|
|
4182
3719
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4308,7 +3845,7 @@ class SDK {
|
|
|
4308
3845
|
this.events.emit("SYNC_COMPLETE", this.syncState);
|
|
4309
3846
|
return true;
|
|
4310
3847
|
} catch (e) {
|
|
4311
|
-
console.error(
|
|
3848
|
+
console.error(tag, "Error in sync:", e);
|
|
4312
3849
|
throw e;
|
|
4313
3850
|
}
|
|
4314
3851
|
};
|
|
@@ -4322,7 +3859,7 @@ class SDK {
|
|
|
4322
3859
|
}
|
|
4323
3860
|
};
|
|
4324
3861
|
this.buildTx = async function(sendPayload) {
|
|
4325
|
-
let
|
|
3862
|
+
let tag = TAG9 + " | buildTx | ";
|
|
4326
3863
|
try {
|
|
4327
3864
|
const transactionDependencies = {
|
|
4328
3865
|
context: this.context,
|
|
@@ -4336,7 +3873,7 @@ class SDK {
|
|
|
4336
3873
|
};
|
|
4337
3874
|
let txManager = new TransactionManager(transactionDependencies, this.events);
|
|
4338
3875
|
let unsignedTx = await txManager.transfer(sendPayload);
|
|
4339
|
-
console.log(
|
|
3876
|
+
console.log(tag, "unsignedTx: ", unsignedTx);
|
|
4340
3877
|
return unsignedTx;
|
|
4341
3878
|
} catch (e) {
|
|
4342
3879
|
console.error(e);
|
|
@@ -4344,14 +3881,14 @@ class SDK {
|
|
|
4344
3881
|
}
|
|
4345
3882
|
};
|
|
4346
3883
|
this.buildDelegateTx = async function(caip, params) {
|
|
4347
|
-
let
|
|
3884
|
+
let tag = TAG9 + " | buildDelegateTx | ";
|
|
4348
3885
|
try {
|
|
4349
3886
|
const delegateParams = {
|
|
4350
3887
|
...params,
|
|
4351
3888
|
type: "delegate"
|
|
4352
3889
|
};
|
|
4353
3890
|
let unsignedTx = await createUnsignedStakingTx(caip, delegateParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4354
|
-
console.log(
|
|
3891
|
+
console.log(tag, "unsignedTx: ", unsignedTx);
|
|
4355
3892
|
return unsignedTx;
|
|
4356
3893
|
} catch (e) {
|
|
4357
3894
|
console.error(e);
|
|
@@ -4359,14 +3896,14 @@ class SDK {
|
|
|
4359
3896
|
}
|
|
4360
3897
|
};
|
|
4361
3898
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4362
|
-
let
|
|
3899
|
+
let tag = TAG9 + " | buildUndelegateTx | ";
|
|
4363
3900
|
try {
|
|
4364
3901
|
const undelegateParams = {
|
|
4365
3902
|
...params,
|
|
4366
3903
|
type: "undelegate"
|
|
4367
3904
|
};
|
|
4368
3905
|
let unsignedTx = await createUnsignedStakingTx(caip, undelegateParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4369
|
-
console.log(
|
|
3906
|
+
console.log(tag, "unsignedTx: ", unsignedTx);
|
|
4370
3907
|
return unsignedTx;
|
|
4371
3908
|
} catch (e) {
|
|
4372
3909
|
console.error(e);
|
|
@@ -4374,14 +3911,14 @@ class SDK {
|
|
|
4374
3911
|
}
|
|
4375
3912
|
};
|
|
4376
3913
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4377
|
-
let
|
|
3914
|
+
let tag = TAG9 + " | buildClaimRewardsTx | ";
|
|
4378
3915
|
try {
|
|
4379
3916
|
const claimParams = {
|
|
4380
3917
|
...params,
|
|
4381
3918
|
type: "claim_rewards"
|
|
4382
3919
|
};
|
|
4383
3920
|
let unsignedTx = await createUnsignedStakingTx(caip, claimParams, this.pubkeys, this.pioneer, this.pubkeyContext);
|
|
4384
|
-
console.log(
|
|
3921
|
+
console.log(tag, "unsignedTx: ", unsignedTx);
|
|
4385
3922
|
return unsignedTx;
|
|
4386
3923
|
} catch (e) {
|
|
4387
3924
|
console.error(e);
|
|
@@ -4389,7 +3926,7 @@ class SDK {
|
|
|
4389
3926
|
}
|
|
4390
3927
|
};
|
|
4391
3928
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4392
|
-
let
|
|
3929
|
+
let tag = TAG9 + " | buildClaimAllRewardsTx | ";
|
|
4393
3930
|
try {
|
|
4394
3931
|
const claimAllParams = {
|
|
4395
3932
|
...params,
|
|
@@ -4403,7 +3940,7 @@ class SDK {
|
|
|
4403
3940
|
}
|
|
4404
3941
|
};
|
|
4405
3942
|
this.signTx = async function(caip, unsignedTx) {
|
|
4406
|
-
let
|
|
3943
|
+
let tag = TAG9 + " | signTx | ";
|
|
4407
3944
|
try {
|
|
4408
3945
|
const transactionDependencies = {
|
|
4409
3946
|
context: this.context,
|
|
@@ -4424,7 +3961,7 @@ class SDK {
|
|
|
4424
3961
|
}
|
|
4425
3962
|
};
|
|
4426
3963
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4427
|
-
let
|
|
3964
|
+
let tag = TAG9 + " | broadcastTx | ";
|
|
4428
3965
|
try {
|
|
4429
3966
|
const transactionDependencies = {
|
|
4430
3967
|
context: this.context,
|
|
@@ -4448,7 +3985,7 @@ class SDK {
|
|
|
4448
3985
|
}
|
|
4449
3986
|
};
|
|
4450
3987
|
this.swap = async function(swapPayload) {
|
|
4451
|
-
let
|
|
3988
|
+
let tag = `${TAG9} | swap | `;
|
|
4452
3989
|
try {
|
|
4453
3990
|
if (!swapPayload)
|
|
4454
3991
|
throw Error("swapPayload required!");
|
|
@@ -4497,15 +4034,15 @@ class SDK {
|
|
|
4497
4034
|
throw new Error(`Cannot use max amount: no balance found for ${swapPayload.caipIn}`);
|
|
4498
4035
|
}
|
|
4499
4036
|
let totalBalance = 0;
|
|
4500
|
-
console.log(
|
|
4037
|
+
console.log(tag, `Found ${inputBalances.length} balance entries for ${swapPayload.caipIn}`);
|
|
4501
4038
|
for (const balanceEntry of inputBalances) {
|
|
4502
4039
|
const balance = parseFloat(balanceEntry.balance) || 0;
|
|
4503
4040
|
totalBalance += balance;
|
|
4504
|
-
console.log(
|
|
4041
|
+
console.log(tag, ` - ${balanceEntry.pubkey || balanceEntry.identifier}: ${balance}`);
|
|
4505
4042
|
}
|
|
4506
4043
|
this.assetContext.balance = totalBalance.toString();
|
|
4507
4044
|
this.assetContext.valueUsd = (totalBalance * parseFloat(this.assetContext.priceUsd || "0")).toFixed(2);
|
|
4508
|
-
console.log(
|
|
4045
|
+
console.log(tag, `Updated assetContext balance to aggregated total: ${totalBalance}`);
|
|
4509
4046
|
const feeReserves = {
|
|
4510
4047
|
"bip122:000000000019d6689c085ae165831e93/slip44:0": 0.00005,
|
|
4511
4048
|
"eip155:1/slip44:60": 0.001,
|
|
@@ -4516,7 +4053,7 @@ class SDK {
|
|
|
4516
4053
|
};
|
|
4517
4054
|
const reserve = feeReserves[swapPayload.caipIn] || 0.0001;
|
|
4518
4055
|
inputAmount = Math.max(0, totalBalance - reserve);
|
|
4519
|
-
console.log(
|
|
4056
|
+
console.log(tag, `Using max amount for swap: ${inputAmount} (total balance: ${totalBalance}, reserve: ${reserve})`);
|
|
4520
4057
|
} else {
|
|
4521
4058
|
inputAmount = typeof swapPayload.amount === "string" ? parseFloat(swapPayload.amount) : swapPayload.amount;
|
|
4522
4059
|
if (isNaN(inputAmount) || inputAmount <= 0) {
|
|
@@ -4536,7 +4073,7 @@ class SDK {
|
|
|
4536
4073
|
result = await this.pioneer.Quote(quote);
|
|
4537
4074
|
result = result.data;
|
|
4538
4075
|
} catch (e) {
|
|
4539
|
-
console.error(
|
|
4076
|
+
console.error(tag, "Failed to get quote: ", e);
|
|
4540
4077
|
throw Error("Quote API failed for path: " + quote.sellAsset + " -> " + quote.buyAsset + ". Error: " + e);
|
|
4541
4078
|
}
|
|
4542
4079
|
if (!result || result.length === 0)
|
|
@@ -4563,7 +4100,7 @@ class SDK {
|
|
|
4563
4100
|
if (tx.type === "deposit") {
|
|
4564
4101
|
unsignedTx = await createUnsignedTendermintTx(caip, tx.type, tx.txParams.amount, tx.txParams.memo, this.pubkeys, this.pioneer, this.pubkeyContext, false, undefined);
|
|
4565
4102
|
} else if (tx.type === "EVM" || tx.type === "evm") {
|
|
4566
|
-
console.log(
|
|
4103
|
+
console.log(tag, "Using pre-built EVM transaction from integration");
|
|
4567
4104
|
unsignedTx = tx.txParams;
|
|
4568
4105
|
} else {
|
|
4569
4106
|
if (!tx.txParams.memo)
|
|
@@ -4582,12 +4119,12 @@ class SDK {
|
|
|
4582
4119
|
return unsignedTx;
|
|
4583
4120
|
}
|
|
4584
4121
|
} catch (e) {
|
|
4585
|
-
console.error(
|
|
4122
|
+
console.error(tag, "Error: ", e);
|
|
4586
4123
|
throw e;
|
|
4587
4124
|
}
|
|
4588
4125
|
};
|
|
4589
4126
|
this.transfer = async function(sendPayload) {
|
|
4590
|
-
let
|
|
4127
|
+
let tag = `${TAG9} | transfer | `;
|
|
4591
4128
|
try {
|
|
4592
4129
|
if (!sendPayload)
|
|
4593
4130
|
throw Error("sendPayload required!");
|
|
@@ -4621,15 +4158,15 @@ class SDK {
|
|
|
4621
4158
|
return { txid, events: this.events };
|
|
4622
4159
|
} catch (error) {
|
|
4623
4160
|
if (error instanceof Error) {
|
|
4624
|
-
console.error(
|
|
4161
|
+
console.error(tag, "An error occurred during the transfer process:", error.message);
|
|
4625
4162
|
} else {
|
|
4626
|
-
console.error(
|
|
4163
|
+
console.error(tag, "An unknown error occurred during the transfer process");
|
|
4627
4164
|
}
|
|
4628
4165
|
throw error;
|
|
4629
4166
|
}
|
|
4630
4167
|
};
|
|
4631
4168
|
this.followTransaction = async function(caip, txid) {
|
|
4632
|
-
let
|
|
4169
|
+
let tag = " | followTransaction | ";
|
|
4633
4170
|
try {
|
|
4634
4171
|
const finalConfirmationBlocksByCaip = {
|
|
4635
4172
|
dogecoin: 3,
|
|
@@ -4659,7 +4196,7 @@ class SDK {
|
|
|
4659
4196
|
}
|
|
4660
4197
|
}
|
|
4661
4198
|
} catch (error) {
|
|
4662
|
-
console.error(
|
|
4199
|
+
console.error(tag, "Error:", error);
|
|
4663
4200
|
}
|
|
4664
4201
|
if (!isConfirmed) {
|
|
4665
4202
|
await new Promise((resolve) => setTimeout(resolve, 8000));
|
|
@@ -4677,18 +4214,18 @@ class SDK {
|
|
|
4677
4214
|
requiredConfirmations
|
|
4678
4215
|
};
|
|
4679
4216
|
} catch (error) {
|
|
4680
|
-
console.error(
|
|
4217
|
+
console.error(tag, "Error:", error);
|
|
4681
4218
|
throw new Error("Failed to follow transaction");
|
|
4682
4219
|
}
|
|
4683
4220
|
};
|
|
4684
4221
|
this.setBlockchains = async function(blockchains) {
|
|
4685
|
-
const
|
|
4222
|
+
const tag = `${TAG9} | setBlockchains | `;
|
|
4686
4223
|
try {
|
|
4687
4224
|
if (!blockchains)
|
|
4688
4225
|
throw Error("blockchains required!");
|
|
4689
4226
|
const uniqueBlockchains = [...new Set(blockchains)];
|
|
4690
4227
|
if (blockchains.length !== uniqueBlockchains.length) {
|
|
4691
|
-
console.warn(
|
|
4228
|
+
console.warn(tag, `Removed ${blockchains.length - uniqueBlockchains.length} duplicate blockchains`);
|
|
4692
4229
|
}
|
|
4693
4230
|
this.blockchains = uniqueBlockchains;
|
|
4694
4231
|
this.events.emit("SET_BLOCKCHAINS", this.blockchains);
|
|
@@ -4698,12 +4235,12 @@ class SDK {
|
|
|
4698
4235
|
}
|
|
4699
4236
|
};
|
|
4700
4237
|
this.addAsset = async function(caip, data) {
|
|
4701
|
-
let
|
|
4238
|
+
let tag = TAG9 + " | addAsset | ";
|
|
4702
4239
|
try {
|
|
4703
4240
|
let success = false;
|
|
4704
4241
|
if (!caip)
|
|
4705
4242
|
throw new Error("caip required!");
|
|
4706
|
-
let dataLocal =
|
|
4243
|
+
let dataLocal = import_pioneer_discovery.assetData[caip];
|
|
4707
4244
|
if (!dataLocal) {
|
|
4708
4245
|
if (!data.networkId)
|
|
4709
4246
|
throw new Error("networkId required! can not build asset");
|
|
@@ -4736,22 +4273,22 @@ class SDK {
|
|
|
4736
4273
|
}
|
|
4737
4274
|
};
|
|
4738
4275
|
this.clearWalletState = async function() {
|
|
4739
|
-
const
|
|
4276
|
+
const tag = `${TAG9} | clearWalletState | `;
|
|
4740
4277
|
try {
|
|
4741
4278
|
this.context = null;
|
|
4742
4279
|
this.paths = [];
|
|
4743
4280
|
this.blockchains = [];
|
|
4744
4281
|
this.pubkeys = [];
|
|
4745
4282
|
this.pubkeySet.clear();
|
|
4746
|
-
console.log(
|
|
4283
|
+
console.log(tag, "Cleared wallet state including pubkeys and tracking set");
|
|
4747
4284
|
return true;
|
|
4748
4285
|
} catch (e) {
|
|
4749
|
-
console.error(
|
|
4286
|
+
console.error(tag, "e: ", e);
|
|
4750
4287
|
throw e;
|
|
4751
4288
|
}
|
|
4752
4289
|
};
|
|
4753
4290
|
this.addPath = async function(path) {
|
|
4754
|
-
const
|
|
4291
|
+
const tag = `${TAG9} | addPath | `;
|
|
4755
4292
|
try {
|
|
4756
4293
|
this.paths.push(path);
|
|
4757
4294
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -4760,14 +4297,14 @@ class SDK {
|
|
|
4760
4297
|
this.buildDashboardFromBalances();
|
|
4761
4298
|
return { success: true, pubkey };
|
|
4762
4299
|
} catch (e) {
|
|
4763
|
-
console.error(
|
|
4300
|
+
console.error(tag, "Failed:", e);
|
|
4764
4301
|
throw e;
|
|
4765
4302
|
}
|
|
4766
4303
|
};
|
|
4767
4304
|
this.addPaths = async function(paths) {
|
|
4768
|
-
const
|
|
4305
|
+
const tag = `${TAG9} | addPaths | `;
|
|
4769
4306
|
try {
|
|
4770
|
-
console.log(
|
|
4307
|
+
console.log(tag, `Adding ${paths.length} paths in batch mode...`);
|
|
4771
4308
|
this.paths.push(...paths);
|
|
4772
4309
|
const newPubkeys = [];
|
|
4773
4310
|
for (const path of paths) {
|
|
@@ -4776,10 +4313,10 @@ class SDK {
|
|
|
4776
4313
|
this.addPubkey(pubkey);
|
|
4777
4314
|
newPubkeys.push(pubkey);
|
|
4778
4315
|
} catch (error) {
|
|
4779
|
-
console.warn(
|
|
4316
|
+
console.warn(tag, `Failed to get pubkey for path ${path.note}:`, error.message);
|
|
4780
4317
|
}
|
|
4781
4318
|
}
|
|
4782
|
-
console.log(
|
|
4319
|
+
console.log(tag, `Successfully added ${newPubkeys.length} pubkeys`);
|
|
4783
4320
|
const networkSet = new Set;
|
|
4784
4321
|
for (const path of paths) {
|
|
4785
4322
|
if (path.networks && Array.isArray(path.networks)) {
|
|
@@ -4787,13 +4324,13 @@ class SDK {
|
|
|
4787
4324
|
}
|
|
4788
4325
|
}
|
|
4789
4326
|
const uniqueNetworks = [...networkSet];
|
|
4790
|
-
console.log(
|
|
4327
|
+
console.log(tag, `Fetching balances for ${uniqueNetworks.length} unique networks in single API call...`);
|
|
4791
4328
|
await this.getBalancesForNetworks(uniqueNetworks);
|
|
4792
4329
|
this.buildDashboardFromBalances();
|
|
4793
|
-
console.log(
|
|
4330
|
+
console.log(tag, `Batch add complete: ${paths.length} paths, ${newPubkeys.length} pubkeys, ${this.balances?.length || 0} balances`);
|
|
4794
4331
|
return { success: true, pubkeys: newPubkeys };
|
|
4795
4332
|
} catch (e) {
|
|
4796
|
-
console.error(
|
|
4333
|
+
console.error(tag, "Failed:", e);
|
|
4797
4334
|
throw e;
|
|
4798
4335
|
}
|
|
4799
4336
|
};
|
|
@@ -4801,12 +4338,12 @@ class SDK {
|
|
|
4801
4338
|
return this.getGasAssets();
|
|
4802
4339
|
};
|
|
4803
4340
|
this.getGasAssets = async function() {
|
|
4804
|
-
const
|
|
4341
|
+
const tag = `${TAG9} | getGasAssets | `;
|
|
4805
4342
|
try {
|
|
4806
4343
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4807
4344
|
let networkId = this.blockchains[i];
|
|
4808
4345
|
let caip = import_pioneer_caip8.networkIdToCaip(networkId);
|
|
4809
|
-
let asset = await
|
|
4346
|
+
let asset = await import_pioneer_discovery.assetData[caip.toLowerCase()];
|
|
4810
4347
|
if (asset) {
|
|
4811
4348
|
asset.caip = caip.toLowerCase();
|
|
4812
4349
|
asset.networkId = networkId;
|
|
@@ -4835,7 +4372,7 @@ class SDK {
|
|
|
4835
4372
|
denom: "maya"
|
|
4836
4373
|
};
|
|
4837
4374
|
this.assetsMap.set(mayaTokenCaip, mayaToken);
|
|
4838
|
-
console.log(
|
|
4375
|
+
console.log(tag, "Added MAYA token to assetsMap");
|
|
4839
4376
|
}
|
|
4840
4377
|
return this.assetsMap;
|
|
4841
4378
|
} catch (e) {
|
|
@@ -4844,7 +4381,7 @@ class SDK {
|
|
|
4844
4381
|
}
|
|
4845
4382
|
};
|
|
4846
4383
|
this.getPubkeys = async function() {
|
|
4847
|
-
const
|
|
4384
|
+
const tag = `${TAG9} | getPubkeys | `;
|
|
4848
4385
|
try {
|
|
4849
4386
|
if (this.paths.length === 0)
|
|
4850
4387
|
throw new Error("No paths found!");
|
|
@@ -4858,41 +4395,41 @@ class SDK {
|
|
|
4858
4395
|
}
|
|
4859
4396
|
const pubkeysWithoutNetworks = this.pubkeys.filter((pk) => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0);
|
|
4860
4397
|
if (pubkeysWithoutNetworks.length > 0) {
|
|
4861
|
-
console.error(
|
|
4862
|
-
console.error(
|
|
4398
|
+
console.error(tag, "ERROR: Some pubkeys missing networks field!");
|
|
4399
|
+
console.error(tag, "Affected pubkeys:", pubkeysWithoutNetworks.length);
|
|
4863
4400
|
pubkeysWithoutNetworks.forEach((pk) => {
|
|
4864
|
-
console.error(
|
|
4401
|
+
console.error(tag, ` - ${pk.note || pk.pubkey}: networks=${pk.networks}`);
|
|
4865
4402
|
});
|
|
4866
4403
|
for (const pubkey of pubkeysWithoutNetworks) {
|
|
4867
4404
|
const matchingPath = this.paths.find((p) => JSON.stringify(p.addressNList) === JSON.stringify(pubkey.addressNList));
|
|
4868
4405
|
if (matchingPath && matchingPath.networks) {
|
|
4869
|
-
console.warn(
|
|
4406
|
+
console.warn(tag, ` ⚠️ Auto-fixing: Adding networks from path ${matchingPath.note}`);
|
|
4870
4407
|
pubkey.networks = matchingPath.networks;
|
|
4871
4408
|
}
|
|
4872
4409
|
}
|
|
4873
4410
|
const stillMissing = this.pubkeys.filter((pk) => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0);
|
|
4874
4411
|
if (stillMissing.length > 0) {
|
|
4875
|
-
console.error(
|
|
4412
|
+
console.error(tag, `❌ CRITICAL: ${stillMissing.length} pubkeys still missing networks after auto-fix!`);
|
|
4876
4413
|
stillMissing.forEach((pk) => {
|
|
4877
|
-
console.error(
|
|
4414
|
+
console.error(tag, ` - ${pk.note || pk.pubkey}`);
|
|
4878
4415
|
});
|
|
4879
4416
|
} else {
|
|
4880
|
-
console.log(
|
|
4417
|
+
console.log(tag, `✅ Auto-fix successful: All pubkeys now have networks field`);
|
|
4881
4418
|
}
|
|
4882
4419
|
}
|
|
4883
4420
|
this.events.emit("SET_PUBKEYS", this.pubkeys);
|
|
4884
4421
|
return pubkeys;
|
|
4885
4422
|
} catch (error) {
|
|
4886
4423
|
console.error("Error in getPubkeys:", error);
|
|
4887
|
-
console.error(
|
|
4424
|
+
console.error(tag, "Error in getPubkeys:", error);
|
|
4888
4425
|
throw error;
|
|
4889
4426
|
}
|
|
4890
4427
|
};
|
|
4891
4428
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4892
|
-
const
|
|
4429
|
+
const tag = `${TAG9} | getBalancesForNetworks | `;
|
|
4893
4430
|
try {
|
|
4894
4431
|
if (!this.pioneer) {
|
|
4895
|
-
console.error(
|
|
4432
|
+
console.error(tag, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
4896
4433
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
4897
4434
|
}
|
|
4898
4435
|
console.log("\uD83D\uDD0D [DIAGNOSTIC] Input networks:", networkIds);
|
|
@@ -4920,20 +4457,20 @@ class SDK {
|
|
|
4920
4457
|
return network === adjustedNetworkId;
|
|
4921
4458
|
}));
|
|
4922
4459
|
if (pubkeys.length === 0) {
|
|
4923
|
-
console.warn(
|
|
4924
|
-
console.warn(
|
|
4460
|
+
console.warn(tag, `⚠️ No pubkeys found for ${networkId} with networks field`);
|
|
4461
|
+
console.warn(tag, "Attempting fallback: finding pubkeys by path matching");
|
|
4925
4462
|
const pathsForNetwork = this.paths.filter((p) => p.networks?.includes(networkId) || networkId.startsWith("eip155:") && p.networks?.includes("eip155:*"));
|
|
4926
4463
|
for (const path of pathsForNetwork) {
|
|
4927
4464
|
const matchingPubkey = this.pubkeys.find((pk) => JSON.stringify(pk.addressNList) === JSON.stringify(path.addressNList));
|
|
4928
4465
|
if (matchingPubkey) {
|
|
4929
|
-
console.warn(
|
|
4466
|
+
console.warn(tag, ` ✓ Found pubkey via path matching: ${matchingPubkey.note || matchingPubkey.pubkey.slice(0, 10)}`);
|
|
4930
4467
|
pubkeys.push(matchingPubkey);
|
|
4931
4468
|
}
|
|
4932
4469
|
}
|
|
4933
4470
|
if (pubkeys.length > 0) {
|
|
4934
|
-
console.warn(
|
|
4471
|
+
console.warn(tag, ` ✅ Fallback successful: Found ${pubkeys.length} pubkeys for ${networkId}`);
|
|
4935
4472
|
} else {
|
|
4936
|
-
console.error(
|
|
4473
|
+
console.error(tag, ` ❌ Fallback failed: No pubkeys found for ${networkId}`);
|
|
4937
4474
|
}
|
|
4938
4475
|
}
|
|
4939
4476
|
const caipNative = await import_pioneer_caip8.networkIdToCaip(networkId);
|
|
@@ -4951,11 +4488,18 @@ class SDK {
|
|
|
4951
4488
|
caipCounts.forEach((count, caip) => {
|
|
4952
4489
|
console.log(` - ${caip}: ${count} queries`);
|
|
4953
4490
|
});
|
|
4491
|
+
console.log(`⏱️ [PERF] Starting GetPortfolioBalances API call...`);
|
|
4492
|
+
const apiCallStart = performance.now();
|
|
4954
4493
|
console.time("GetPortfolioBalances Response Time");
|
|
4955
4494
|
try {
|
|
4956
|
-
let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
|
|
4495
|
+
let marketInfo = await this.pioneer.GetPortfolioBalances({ pubkeys: assetQuery });
|
|
4496
|
+
const apiCallTime = performance.now() - apiCallStart;
|
|
4957
4497
|
console.timeEnd("GetPortfolioBalances Response Time");
|
|
4498
|
+
console.log(`⏱️ [PERF] API call completed in ${apiCallTime.toFixed(0)}ms`);
|
|
4499
|
+
const enrichStart = performance.now();
|
|
4958
4500
|
let balances = marketInfo.data;
|
|
4501
|
+
console.log(`⏱️ [PERF] Received ${balances?.length || 0} balances from server`);
|
|
4502
|
+
console.log(`⏱️ [PERF] Starting balance enrichment...`);
|
|
4959
4503
|
for (let balance of balances) {
|
|
4960
4504
|
const assetInfo = this.assetsMap.get(balance.caip.toLowerCase()) || this.assetsMap.get(balance.caip);
|
|
4961
4505
|
if (!assetInfo)
|
|
@@ -4969,47 +4513,50 @@ class SDK {
|
|
|
4969
4513
|
color
|
|
4970
4514
|
});
|
|
4971
4515
|
}
|
|
4516
|
+
const enrichTime = performance.now() - enrichStart;
|
|
4517
|
+
console.log(`⏱️ [PERF] Enrichment completed in ${enrichTime.toFixed(0)}ms`);
|
|
4972
4518
|
this.balances = balances;
|
|
4973
4519
|
this.events.emit("SET_BALANCES", this.balances);
|
|
4520
|
+
console.log(`⏱️ [PERF] Total getBalancesForNetworks: ${(performance.now() - apiCallStart).toFixed(0)}ms`);
|
|
4974
4521
|
return this.balances;
|
|
4975
4522
|
} catch (apiError) {
|
|
4976
|
-
console.error(
|
|
4523
|
+
console.error(tag, "GetPortfolioBalances API call failed:", apiError);
|
|
4977
4524
|
throw new Error(`GetPortfolioBalances API call failed: ${apiError?.message || "Unknown error"}`);
|
|
4978
4525
|
}
|
|
4979
4526
|
} catch (e) {
|
|
4980
|
-
console.error(
|
|
4527
|
+
console.error(tag, "Error: ", e);
|
|
4981
4528
|
throw e;
|
|
4982
4529
|
}
|
|
4983
4530
|
};
|
|
4984
4531
|
this.getBalances = async function() {
|
|
4985
|
-
const
|
|
4532
|
+
const tag = `${TAG9} | getBalances | `;
|
|
4986
4533
|
try {
|
|
4987
4534
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4988
4535
|
} catch (e) {
|
|
4989
|
-
console.error(
|
|
4536
|
+
console.error(tag, "Error in getBalances: ", e);
|
|
4990
4537
|
throw e;
|
|
4991
4538
|
}
|
|
4992
4539
|
};
|
|
4993
4540
|
this.getBalance = async function(networkId) {
|
|
4994
|
-
const
|
|
4541
|
+
const tag = `${TAG9} | getBalance | `;
|
|
4995
4542
|
try {
|
|
4996
4543
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4997
4544
|
const filtered = results.filter(async (b) => b.networkId === await import_pioneer_caip8.networkIdToCaip(networkId));
|
|
4998
4545
|
return filtered;
|
|
4999
4546
|
} catch (e) {
|
|
5000
|
-
console.error(
|
|
4547
|
+
console.error(tag, "Error: ", e);
|
|
5001
4548
|
throw e;
|
|
5002
4549
|
}
|
|
5003
4550
|
};
|
|
5004
4551
|
this.getFees = async function(networkId) {
|
|
5005
|
-
const
|
|
4552
|
+
const tag = `${TAG9} | getFees | `;
|
|
5006
4553
|
try {
|
|
5007
4554
|
if (!this.pioneer) {
|
|
5008
4555
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
5009
4556
|
}
|
|
5010
4557
|
return await getFees(this.pioneer, networkId);
|
|
5011
4558
|
} catch (e) {
|
|
5012
|
-
console.error(
|
|
4559
|
+
console.error(tag, "Error getting fees: ", e);
|
|
5013
4560
|
throw e;
|
|
5014
4561
|
}
|
|
5015
4562
|
};
|
|
@@ -5017,29 +4564,55 @@ class SDK {
|
|
|
5017
4564
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
5018
4565
|
};
|
|
5019
4566
|
this.getCharts = async function() {
|
|
5020
|
-
const
|
|
4567
|
+
const tag = `${TAG9} | getCharts | `;
|
|
5021
4568
|
try {
|
|
5022
|
-
console.log(
|
|
5023
|
-
const
|
|
5024
|
-
|
|
4569
|
+
console.log(tag, "Fetching charts from batch endpoint");
|
|
4570
|
+
const pubkeysForBatch = [];
|
|
4571
|
+
for (const pubkey of this.pubkeys) {
|
|
4572
|
+
const address = pubkey.address || pubkey.master || pubkey.pubkey;
|
|
4573
|
+
if (!address)
|
|
4574
|
+
continue;
|
|
4575
|
+
const supportedNetworks = pubkey.networks || [];
|
|
4576
|
+
for (const blockchain of this.blockchains) {
|
|
4577
|
+
const supportsNetwork = supportedNetworks.some((net) => net === blockchain || net.endsWith(":*") && blockchain.startsWith(net.replace(":*", ":")));
|
|
4578
|
+
if (supportsNetwork) {
|
|
4579
|
+
let caip;
|
|
4580
|
+
if (blockchain.startsWith("eip155:")) {
|
|
4581
|
+
caip = `${blockchain}/slip44:60`;
|
|
4582
|
+
} else {
|
|
4583
|
+
caip = `${blockchain}/slip44:0`;
|
|
4584
|
+
}
|
|
4585
|
+
pubkeysForBatch.push({
|
|
4586
|
+
pubkey: address,
|
|
4587
|
+
caip
|
|
4588
|
+
});
|
|
4589
|
+
}
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
console.log(tag, `Calling batch GetCharts with ${pubkeysForBatch.length} pubkeys`);
|
|
4593
|
+
const chartsResponse = await this.pioneer.GetCharts({
|
|
4594
|
+
pubkeys: pubkeysForBatch
|
|
4595
|
+
});
|
|
4596
|
+
const newBalances = chartsResponse?.data?.balances || [];
|
|
4597
|
+
console.log(tag, `Received ${newBalances.length} balances from batch endpoint`);
|
|
5025
4598
|
const uniqueBalances = new Map([...this.balances, ...newBalances].map((balance) => [
|
|
5026
|
-
balance.identifier
|
|
4599
|
+
balance.identifier || `${balance.caip}:${balance.pubkey}`,
|
|
5027
4600
|
{
|
|
5028
4601
|
...balance,
|
|
5029
4602
|
type: balance.type || "balance"
|
|
5030
4603
|
}
|
|
5031
4604
|
]));
|
|
5032
|
-
console.log(
|
|
4605
|
+
console.log(tag, "uniqueBalances: ", uniqueBalances.size);
|
|
5033
4606
|
this.balances = Array.from(uniqueBalances.values());
|
|
5034
|
-
console.log(
|
|
4607
|
+
console.log(tag, "Updated this.balances: ", this.balances.length);
|
|
5035
4608
|
return this.balances;
|
|
5036
4609
|
} catch (e) {
|
|
5037
|
-
console.error(
|
|
4610
|
+
console.error(tag, "Error in getCharts:", e);
|
|
5038
4611
|
throw e;
|
|
5039
4612
|
}
|
|
5040
4613
|
};
|
|
5041
4614
|
this.setContext = async (context) => {
|
|
5042
|
-
const
|
|
4615
|
+
const tag = `${TAG9} | setContext | `;
|
|
5043
4616
|
try {
|
|
5044
4617
|
if (!context)
|
|
5045
4618
|
throw Error("context required!");
|
|
@@ -5047,12 +4620,12 @@ class SDK {
|
|
|
5047
4620
|
this.events.emit("SET_CONTEXT", context);
|
|
5048
4621
|
return { success: true };
|
|
5049
4622
|
} catch (e) {
|
|
5050
|
-
console.error(
|
|
4623
|
+
console.error(tag, "e: ", e);
|
|
5051
4624
|
return { success: false };
|
|
5052
4625
|
}
|
|
5053
4626
|
};
|
|
5054
4627
|
this.setContextType = async (contextType) => {
|
|
5055
|
-
const
|
|
4628
|
+
const tag = `${TAG9} | setContextType | `;
|
|
5056
4629
|
try {
|
|
5057
4630
|
if (!contextType)
|
|
5058
4631
|
throw Error("contextType required!");
|
|
@@ -5060,22 +4633,22 @@ class SDK {
|
|
|
5060
4633
|
this.events.emit("SET_CONTEXT_TYPE", contextType);
|
|
5061
4634
|
return { success: true };
|
|
5062
4635
|
} catch (e) {
|
|
5063
|
-
console.error(
|
|
4636
|
+
console.error(tag, "e: ", e);
|
|
5064
4637
|
return { success: false };
|
|
5065
4638
|
}
|
|
5066
4639
|
};
|
|
5067
4640
|
this.refresh = async () => {
|
|
5068
|
-
const
|
|
4641
|
+
const tag = `${TAG9} | refresh | `;
|
|
5069
4642
|
try {
|
|
5070
4643
|
await this.sync();
|
|
5071
4644
|
return this.balances;
|
|
5072
4645
|
} catch (e) {
|
|
5073
|
-
console.error(
|
|
4646
|
+
console.error(tag, "e: ", e);
|
|
5074
4647
|
throw e;
|
|
5075
4648
|
}
|
|
5076
4649
|
};
|
|
5077
4650
|
this.setAssetContext = async function(asset) {
|
|
5078
|
-
const
|
|
4651
|
+
const tag = `${TAG9} | setAssetContext | `;
|
|
5079
4652
|
try {
|
|
5080
4653
|
if (!asset) {
|
|
5081
4654
|
this.assetContext = null;
|
|
@@ -5087,7 +4660,7 @@ class SDK {
|
|
|
5087
4660
|
asset.networkId = import_pioneer_caip8.caipToNetworkId(asset.caip);
|
|
5088
4661
|
if (!this.pubkeys || this.pubkeys.length === 0) {
|
|
5089
4662
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no pubkeys loaded. Please initialize wallet first.`;
|
|
5090
|
-
console.error(
|
|
4663
|
+
console.error(tag, errorMsg);
|
|
5091
4664
|
throw new Error(errorMsg);
|
|
5092
4665
|
}
|
|
5093
4666
|
const pubkeysForNetwork = this.pubkeys.filter((e) => {
|
|
@@ -5102,8 +4675,8 @@ class SDK {
|
|
|
5102
4675
|
});
|
|
5103
4676
|
if (pubkeysForNetwork.length === 0) {
|
|
5104
4677
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no address/xpub found for network ${asset.networkId}`;
|
|
5105
|
-
console.error(
|
|
5106
|
-
console.error(
|
|
4678
|
+
console.error(tag, errorMsg);
|
|
4679
|
+
console.error(tag, "Available networks in pubkeys:", [
|
|
5107
4680
|
...new Set(this.pubkeys.flatMap((p) => p.networks || []))
|
|
5108
4681
|
]);
|
|
5109
4682
|
throw new Error(errorMsg);
|
|
@@ -5113,43 +4686,43 @@ class SDK {
|
|
|
5113
4686
|
const xpubFound = pubkeysForNetwork.some((p) => p.type === "xpub" && p.pubkey);
|
|
5114
4687
|
if (!xpubFound) {
|
|
5115
4688
|
const errorMsg = `Cannot set asset context for UTXO chain ${asset.caip} - xpub required but not found`;
|
|
5116
|
-
console.error(
|
|
4689
|
+
console.error(tag, errorMsg);
|
|
5117
4690
|
throw new Error(errorMsg);
|
|
5118
4691
|
}
|
|
5119
4692
|
}
|
|
5120
4693
|
const hasValidAddress = pubkeysForNetwork.some((p) => p.address || p.master || p.pubkey);
|
|
5121
4694
|
if (!hasValidAddress) {
|
|
5122
4695
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no valid address found in pubkeys`;
|
|
5123
|
-
console.error(
|
|
4696
|
+
console.error(tag, errorMsg);
|
|
5124
4697
|
throw new Error(errorMsg);
|
|
5125
4698
|
}
|
|
5126
|
-
console.log(
|
|
4699
|
+
console.log(tag, `✅ Validated: Found ${pubkeysForNetwork.length} addresses for ${asset.networkId}`);
|
|
5127
4700
|
let freshPriceUsd = 0;
|
|
5128
4701
|
try {
|
|
5129
4702
|
if (!asset.caip || typeof asset.caip !== "string" || !asset.caip.includes(":")) {
|
|
5130
|
-
console.warn(
|
|
4703
|
+
console.warn(tag, "Invalid or missing CAIP, skipping market price fetch:", asset.caip);
|
|
5131
4704
|
} else {
|
|
5132
|
-
console.log(
|
|
4705
|
+
console.log(tag, "Fetching fresh market price for:", asset.caip);
|
|
5133
4706
|
const marketData = await this.pioneer.GetMarketInfo([asset.caip]);
|
|
5134
|
-
console.log(
|
|
4707
|
+
console.log(tag, "Market data response:", marketData);
|
|
5135
4708
|
if (marketData && marketData.data && marketData.data.length > 0) {
|
|
5136
4709
|
freshPriceUsd = marketData.data[0];
|
|
5137
|
-
console.log(
|
|
4710
|
+
console.log(tag, "✅ Fresh market price:", freshPriceUsd);
|
|
5138
4711
|
} else {
|
|
5139
|
-
console.warn(
|
|
4712
|
+
console.warn(tag, "No market data returned for:", asset.caip);
|
|
5140
4713
|
}
|
|
5141
4714
|
}
|
|
5142
4715
|
} catch (marketError) {
|
|
5143
|
-
console.error(
|
|
4716
|
+
console.error(tag, "Error fetching market price:", marketError);
|
|
5144
4717
|
}
|
|
5145
4718
|
let assetInfo = this.assetsMap.get(asset.caip.toLowerCase());
|
|
5146
|
-
console.log(
|
|
5147
|
-
let assetInfoDiscovery =
|
|
5148
|
-
console.log(
|
|
4719
|
+
console.log(tag, "assetInfo: ", assetInfo);
|
|
4720
|
+
let assetInfoDiscovery = import_pioneer_discovery.assetData[asset.caip];
|
|
4721
|
+
console.log(tag, "assetInfoDiscovery: ", assetInfoDiscovery);
|
|
5149
4722
|
if (assetInfoDiscovery)
|
|
5150
4723
|
assetInfo = assetInfoDiscovery;
|
|
5151
4724
|
if (!assetInfo) {
|
|
5152
|
-
console.log(
|
|
4725
|
+
console.log(tag, "Building placeholder asset!");
|
|
5153
4726
|
assetInfo = {
|
|
5154
4727
|
caip: asset.caip.toLowerCase(),
|
|
5155
4728
|
networkId: asset.networkId,
|
|
@@ -5166,30 +4739,30 @@ class SDK {
|
|
|
5166
4739
|
const valueUsd = parseFloat(matchingBalances[0].valueUsd);
|
|
5167
4740
|
if (balance > 0 && valueUsd > 0) {
|
|
5168
4741
|
priceValue = valueUsd / balance;
|
|
5169
|
-
console.log(
|
|
4742
|
+
console.log(tag, "calculated priceUsd from valueUsd/balance:", priceValue);
|
|
5170
4743
|
}
|
|
5171
4744
|
}
|
|
5172
4745
|
if (priceValue && priceValue > 0) {
|
|
5173
|
-
console.log(
|
|
4746
|
+
console.log(tag, "detected priceUsd from balance:", priceValue);
|
|
5174
4747
|
assetInfo.priceUsd = priceValue;
|
|
5175
4748
|
}
|
|
5176
4749
|
}
|
|
5177
4750
|
if (freshPriceUsd && freshPriceUsd > 0) {
|
|
5178
4751
|
assetInfo.priceUsd = freshPriceUsd;
|
|
5179
|
-
console.log(
|
|
4752
|
+
console.log(tag, "✅ Using fresh market price:", freshPriceUsd);
|
|
5180
4753
|
let totalBalance = 0;
|
|
5181
4754
|
let totalValueUsd = 0;
|
|
5182
|
-
console.log(
|
|
4755
|
+
console.log(tag, `Found ${matchingBalances.length} balance entries for ${asset.caip}`);
|
|
5183
4756
|
for (const balanceEntry of matchingBalances) {
|
|
5184
4757
|
const balance = parseFloat(balanceEntry.balance) || 0;
|
|
5185
4758
|
const valueUsd = parseFloat(balanceEntry.valueUsd) || 0;
|
|
5186
4759
|
totalBalance += balance;
|
|
5187
4760
|
totalValueUsd += valueUsd;
|
|
5188
|
-
console.log(
|
|
4761
|
+
console.log(tag, ` Balance entry: ${balance} (${valueUsd} USD)`);
|
|
5189
4762
|
}
|
|
5190
4763
|
assetInfo.balance = totalBalance.toString();
|
|
5191
4764
|
assetInfo.valueUsd = totalValueUsd.toFixed(2);
|
|
5192
|
-
console.log(
|
|
4765
|
+
console.log(tag, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
5193
4766
|
}
|
|
5194
4767
|
const assetBalances = this.balances.filter((b) => b.caip === asset.caip);
|
|
5195
4768
|
const assetPubkeys = this.pubkeys.filter((p) => p.networks && Array.isArray(p.networks) && p.networks.includes(import_pioneer_caip8.caipToNetworkId(asset.caip)) || import_pioneer_caip8.caipToNetworkId(asset.caip).includes("eip155") && p.networks && Array.isArray(p.networks) && p.networks.some((n) => n.startsWith("eip155")));
|
|
@@ -5209,7 +4782,7 @@ class SDK {
|
|
|
5209
4782
|
const balanceAmount = parseFloat(balance.balance || 0);
|
|
5210
4783
|
balance.valueUsd = (balanceAmount * freshPriceUsd).toString();
|
|
5211
4784
|
}
|
|
5212
|
-
console.log(
|
|
4785
|
+
console.log(tag, "Updated all balances with fresh price data");
|
|
5213
4786
|
}
|
|
5214
4787
|
this.assetContext = finalAssetContext;
|
|
5215
4788
|
if (asset.isToken || asset.type === "token" || assetInfo.isToken || assetInfo.type === "token") {
|
|
@@ -5261,20 +4834,20 @@ class SDK {
|
|
|
5261
4834
|
const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
|
|
5262
4835
|
if (!this.pubkeyContext || !currentContextValid) {
|
|
5263
4836
|
this.pubkeyContext = assetPubkeys[0];
|
|
5264
|
-
console.log(
|
|
4837
|
+
console.log(tag, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
|
|
5265
4838
|
} else {
|
|
5266
|
-
console.log(
|
|
4839
|
+
console.log(tag, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
|
|
5267
4840
|
}
|
|
5268
4841
|
}
|
|
5269
4842
|
this.events.emit("SET_ASSET_CONTEXT", this.assetContext);
|
|
5270
4843
|
return this.assetContext;
|
|
5271
4844
|
} catch (e) {
|
|
5272
|
-
console.error(
|
|
4845
|
+
console.error(tag, "e: ", e);
|
|
5273
4846
|
throw e;
|
|
5274
4847
|
}
|
|
5275
4848
|
};
|
|
5276
4849
|
this.setPubkeyContext = async function(pubkey) {
|
|
5277
|
-
let
|
|
4850
|
+
let tag = `${TAG9} | setPubkeyContext | `;
|
|
5278
4851
|
try {
|
|
5279
4852
|
if (!pubkey)
|
|
5280
4853
|
throw Error("pubkey is required");
|
|
@@ -5282,31 +4855,31 @@ class SDK {
|
|
|
5282
4855
|
throw Error("invalid pubkey: missing pubkey or address");
|
|
5283
4856
|
const exists = this.pubkeys.some((pk) => pk.pubkey === pubkey.pubkey || pk.address === pubkey.address || pk.pubkey === pubkey.address);
|
|
5284
4857
|
if (!exists) {
|
|
5285
|
-
console.warn(
|
|
4858
|
+
console.warn(tag, "Pubkey not found in current pubkeys array");
|
|
5286
4859
|
}
|
|
5287
4860
|
this.pubkeyContext = pubkey;
|
|
5288
|
-
console.log(
|
|
4861
|
+
console.log(tag, "Pubkey context set to:", pubkey.address || pubkey.pubkey, "note:", pubkey.note, "addressNList:", pubkey.addressNList || pubkey.addressNListMaster);
|
|
5289
4862
|
return true;
|
|
5290
4863
|
} catch (e) {
|
|
5291
|
-
console.error(
|
|
4864
|
+
console.error(tag, "e: ", e);
|
|
5292
4865
|
throw e;
|
|
5293
4866
|
}
|
|
5294
4867
|
};
|
|
5295
4868
|
this.setOutboundAssetContext = async function(asset) {
|
|
5296
|
-
const
|
|
4869
|
+
const tag = `${TAG9} | setOutputAssetContext | `;
|
|
5297
4870
|
try {
|
|
5298
|
-
console.log(
|
|
4871
|
+
console.log(tag, "0. asset: ", asset);
|
|
5299
4872
|
if (!asset) {
|
|
5300
4873
|
this.outboundAssetContext = null;
|
|
5301
4874
|
return;
|
|
5302
4875
|
}
|
|
5303
|
-
console.log(
|
|
4876
|
+
console.log(tag, "1 asset: ", asset);
|
|
5304
4877
|
if (!asset.caip)
|
|
5305
4878
|
throw Error("Invalid Asset! missing caip!");
|
|
5306
4879
|
if (!asset.networkId)
|
|
5307
4880
|
asset.networkId = import_pioneer_caip8.caipToNetworkId(asset.caip);
|
|
5308
|
-
console.log(
|
|
5309
|
-
console.log(
|
|
4881
|
+
console.log(tag, "networkId: ", asset.networkId);
|
|
4882
|
+
console.log(tag, "this.pubkeys: ", this.pubkeys);
|
|
5310
4883
|
const pubkey = this.pubkeys.find((p) => {
|
|
5311
4884
|
if (!p.networks || !Array.isArray(p.networks))
|
|
5312
4885
|
return false;
|
|
@@ -5321,23 +4894,23 @@ class SDK {
|
|
|
5321
4894
|
let freshPriceUsd = 0;
|
|
5322
4895
|
try {
|
|
5323
4896
|
if (!asset.caip || typeof asset.caip !== "string" || !asset.caip.includes(":")) {
|
|
5324
|
-
console.warn(
|
|
4897
|
+
console.warn(tag, "Invalid or missing CAIP, skipping market price fetch:", asset.caip);
|
|
5325
4898
|
} else {
|
|
5326
|
-
console.log(
|
|
4899
|
+
console.log(tag, "Fetching fresh market price for:", asset.caip);
|
|
5327
4900
|
const marketData = await this.pioneer.GetMarketInfo([asset.caip]);
|
|
5328
|
-
console.log(
|
|
4901
|
+
console.log(tag, "Market data response:", marketData);
|
|
5329
4902
|
if (marketData && marketData.data && marketData.data.length > 0) {
|
|
5330
4903
|
freshPriceUsd = marketData.data[0];
|
|
5331
|
-
console.log(
|
|
4904
|
+
console.log(tag, "✅ Fresh market price:", freshPriceUsd);
|
|
5332
4905
|
} else {
|
|
5333
|
-
console.warn(
|
|
4906
|
+
console.warn(tag, "No market data returned for:", asset.caip);
|
|
5334
4907
|
}
|
|
5335
4908
|
}
|
|
5336
4909
|
} catch (marketError) {
|
|
5337
|
-
console.error(
|
|
4910
|
+
console.error(tag, "Error fetching market price:", marketError);
|
|
5338
4911
|
}
|
|
5339
4912
|
let assetInfo = this.assetsMap.get(asset.caip.toLowerCase());
|
|
5340
|
-
console.log(
|
|
4913
|
+
console.log(tag, "assetInfo: ", assetInfo);
|
|
5341
4914
|
if (!assetInfo) {
|
|
5342
4915
|
assetInfo = {
|
|
5343
4916
|
caip: asset.caip.toLowerCase(),
|
|
@@ -5355,45 +4928,45 @@ class SDK {
|
|
|
5355
4928
|
const valueUsd = parseFloat(matchingBalances[0].valueUsd);
|
|
5356
4929
|
if (balance > 0 && valueUsd > 0) {
|
|
5357
4930
|
priceValue = valueUsd / balance;
|
|
5358
|
-
console.log(
|
|
4931
|
+
console.log(tag, "calculated priceUsd from valueUsd/balance:", priceValue);
|
|
5359
4932
|
}
|
|
5360
4933
|
}
|
|
5361
4934
|
if (priceValue && priceValue > 0) {
|
|
5362
|
-
console.log(
|
|
4935
|
+
console.log(tag, "detected priceUsd from balance:", priceValue);
|
|
5363
4936
|
assetInfo.priceUsd = priceValue;
|
|
5364
4937
|
}
|
|
5365
4938
|
}
|
|
5366
4939
|
if (freshPriceUsd && freshPriceUsd > 0) {
|
|
5367
4940
|
assetInfo.priceUsd = freshPriceUsd;
|
|
5368
|
-
console.log(
|
|
4941
|
+
console.log(tag, "✅ Using fresh market price:", freshPriceUsd);
|
|
5369
4942
|
let totalBalance = 0;
|
|
5370
4943
|
let totalValueUsd = 0;
|
|
5371
|
-
console.log(
|
|
4944
|
+
console.log(tag, `Found ${matchingBalances.length} balance entries for ${asset.caip}`);
|
|
5372
4945
|
for (const balanceEntry of matchingBalances) {
|
|
5373
4946
|
const balance = parseFloat(balanceEntry.balance) || 0;
|
|
5374
4947
|
const valueUsd = parseFloat(balanceEntry.valueUsd) || 0;
|
|
5375
4948
|
totalBalance += balance;
|
|
5376
4949
|
totalValueUsd += valueUsd;
|
|
5377
|
-
console.log(
|
|
4950
|
+
console.log(tag, ` Balance entry: ${balance} (${valueUsd} USD)`);
|
|
5378
4951
|
}
|
|
5379
4952
|
assetInfo.balance = totalBalance.toString();
|
|
5380
4953
|
assetInfo.valueUsd = totalValueUsd.toFixed(2);
|
|
5381
|
-
console.log(
|
|
4954
|
+
console.log(tag, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
5382
4955
|
}
|
|
5383
|
-
console.log(
|
|
4956
|
+
console.log(tag, "CHECKPOINT 1");
|
|
5384
4957
|
this.outboundAssetContext = { ...assetInfo, ...asset, ...pubkey };
|
|
5385
|
-
console.log(
|
|
5386
|
-
console.log(
|
|
4958
|
+
console.log(tag, "CHECKPOINT 3");
|
|
4959
|
+
console.log(tag, "outboundAssetContext: assetInfo: ", assetInfo);
|
|
5387
4960
|
if (asset.caip) {
|
|
5388
4961
|
this.outboundBlockchainContext = import_pioneer_caip8.caipToNetworkId(asset.caip);
|
|
5389
4962
|
} else if (asset.networkId) {
|
|
5390
4963
|
this.outboundBlockchainContext = asset.networkId;
|
|
5391
4964
|
}
|
|
5392
|
-
console.log(
|
|
4965
|
+
console.log(tag, "CHECKPOINT 4");
|
|
5393
4966
|
this.events.emit("SET_OUTBOUND_ASSET_CONTEXT", this.outboundAssetContext);
|
|
5394
4967
|
return this.outboundAssetContext;
|
|
5395
4968
|
} catch (e) {
|
|
5396
|
-
console.error(
|
|
4969
|
+
console.error(tag, "e: ", e);
|
|
5397
4970
|
throw e;
|
|
5398
4971
|
}
|
|
5399
4972
|
};
|