@pioneer-platform/pioneer-sdk 4.20.3 → 4.20.5

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.es.js CHANGED
@@ -23,7 +23,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
23
23
  throw Error('Dynamic require of "' + x + '" is not supported');
24
24
  });
25
25
 
26
- // ../../../node_modules/coinselect/utils.js
26
+ // node_modules/coinselect/utils.js
27
27
  var require_utils = __commonJS((exports, module) => {
28
28
  var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
29
29
  var TX_INPUT_BASE = 32 + 4 + 1 + 4;
@@ -96,7 +96,7 @@ var require_utils = __commonJS((exports, module) => {
96
96
  };
97
97
  });
98
98
 
99
- // ../../../node_modules/coinselect/accumulative.js
99
+ // node_modules/coinselect/accumulative.js
100
100
  var require_accumulative = __commonJS((exports, module) => {
101
101
  var utils = require_utils();
102
102
  module.exports = function accumulative(utxos, outputs, feeRate) {
@@ -128,7 +128,7 @@ var require_accumulative = __commonJS((exports, module) => {
128
128
  };
129
129
  });
130
130
 
131
- // ../../../node_modules/coinselect/blackjack.js
131
+ // node_modules/coinselect/blackjack.js
132
132
  var require_blackjack = __commonJS((exports, module) => {
133
133
  var utils = require_utils();
134
134
  module.exports = function blackjack(utxos, outputs, feeRate) {
@@ -157,7 +157,7 @@ var require_blackjack = __commonJS((exports, module) => {
157
157
  };
158
158
  });
159
159
 
160
- // ../../../node_modules/coinselect/index.js
160
+ // node_modules/coinselect/index.js
161
161
  var require_coinselect = __commonJS((exports, module) => {
162
162
  var accumulative = require_accumulative();
163
163
  var blackjack = require_blackjack();
@@ -176,7 +176,7 @@ var require_coinselect = __commonJS((exports, module) => {
176
176
  };
177
177
  });
178
178
 
179
- // ../../../node_modules/coinselect/split.js
179
+ // node_modules/coinselect/split.js
180
180
  var require_split = __commonJS((exports, module) => {
181
181
  var utils = require_utils();
182
182
  module.exports = function split(utxos, outputs, feeRate) {
@@ -221,7 +221,7 @@ var require_split = __commonJS((exports, module) => {
221
221
 
222
222
  // src/index.ts
223
223
  import { KeepKeySdk } from "@keepkey/keepkey-sdk";
224
- import { caipToNetworkId as caipToNetworkId6, networkIdToCaip } from "@pioneer-platform/pioneer-caip";
224
+ import { caipToNetworkId as caipToNetworkId7, networkIdToCaip as networkIdToCaip2 } from "@pioneer-platform/pioneer-caip";
225
225
  import Pioneer from "@pioneer-platform/pioneer-client";
226
226
  import { addressNListToBIP32 as addressNListToBIP322, getPaths } from "@pioneer-platform/pioneer-coins";
227
227
  import { assetData as assetData2 } from "@pioneer-platform/pioneer-discovery";
@@ -762,7 +762,7 @@ var getCharts = async (blockchains, pioneer, pubkeys, context) => {
762
762
  }
763
763
  };
764
764
 
765
- // ../../../node_modules/@coinmasters/types/dist/index.es.js
765
+ // node_modules/@coinmasters/types/dist/index.es.js
766
766
  var n = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_0_100 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROFVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(n || {});
767
767
  var b2 = {
768
768
  [n.INVALID_INPUT_PARAMETERS]: "Invalid input parameters: {0}.",
@@ -3556,10 +3556,9 @@ function estimateTransactionFee(feeRate, unit, networkType, txSize) {
3556
3556
  }
3557
3557
  }
3558
3558
 
3559
- // src/index.ts
3560
- var TAG7 = " | Pioneer-sdk | ";
3559
+ // src/utils/kkapi-detection.ts
3561
3560
  async function detectKkApiAvailability(forceLocalhost) {
3562
- const tag5 = `${TAG7} | detectKkApiAvailability | `;
3561
+ const tag5 = " | detectKkApiAvailability | ";
3563
3562
  try {
3564
3563
  const isTauri = typeof window !== "undefined" && "__TAURI__" in window;
3565
3564
  const isBrowser = typeof window !== "undefined";
@@ -3606,6 +3605,8 @@ async function detectKkApiAvailability(forceLocalhost) {
3606
3605
  };
3607
3606
  }
3608
3607
  }
3608
+
3609
+ // src/utils/format-time.ts
3609
3610
  function formatTime(durationMs) {
3610
3611
  let seconds = Math.floor(durationMs / 1000 % 60);
3611
3612
  let minutes = Math.floor(durationMs / (1000 * 60) % 60);
@@ -3619,6 +3620,96 @@ function formatTime(durationMs) {
3619
3620
  return formatted.trim();
3620
3621
  }
3621
3622
 
3623
+ // src/utils/build-dashboard.ts
3624
+ import { caipToNetworkId as caipToNetworkId6, networkIdToCaip } from "@pioneer-platform/pioneer-caip";
3625
+ var TAG7 = " | build-dashboard | ";
3626
+ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
3627
+ console.log(TAG7, "[DASHBOARD] Building dashboard from cached balances...");
3628
+ const dashboardData = {
3629
+ networks: [],
3630
+ totalValueUsd: 0,
3631
+ networkPercentages: []
3632
+ };
3633
+ let totalPortfolioValue = 0;
3634
+ const networksTemp = [];
3635
+ console.log(TAG7, "balances: ", balances);
3636
+ for (const blockchain of blockchains) {
3637
+ const filteredBalances = balances.filter((b3) => {
3638
+ const networkId = caipToNetworkId6(b3.caip);
3639
+ return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
3640
+ });
3641
+ const balanceMap = new Map;
3642
+ const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
3643
+ if (isBitcoin) {
3644
+ console.log(TAG7, "Bitcoin network detected - checking for duplicate balances");
3645
+ const bitcoinByValue = new Map;
3646
+ filteredBalances.forEach((balance) => {
3647
+ const valueKey = `${balance.balance}_${balance.valueUsd}`;
3648
+ if (!bitcoinByValue.has(valueKey)) {
3649
+ bitcoinByValue.set(valueKey, []);
3650
+ }
3651
+ bitcoinByValue.get(valueKey).push(balance);
3652
+ });
3653
+ for (const [valueKey, balances2] of bitcoinByValue.entries()) {
3654
+ if (balances2.length === 3 && parseFloat(balances2[0].valueUsd || "0") > 0) {
3655
+ console.log(TAG7, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
3656
+ const xpubBalance = balances2.find((b3) => b3.pubkey?.startsWith("xpub")) || balances2[0];
3657
+ const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
3658
+ balanceMap.set(key, xpubBalance);
3659
+ } else {
3660
+ balances2.forEach((balance) => {
3661
+ const key = `${balance.caip}_${balance.pubkey || "default"}`;
3662
+ balanceMap.set(key, balance);
3663
+ });
3664
+ }
3665
+ }
3666
+ } else {
3667
+ filteredBalances.forEach((balance) => {
3668
+ const key = `${balance.caip}_${balance.pubkey || "default"}`;
3669
+ if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
3670
+ balanceMap.set(key, balance);
3671
+ }
3672
+ });
3673
+ }
3674
+ const networkBalances = Array.from(balanceMap.values());
3675
+ const networkTotal = networkBalances.reduce((sum, balance, idx) => {
3676
+ const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
3677
+ if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
3678
+ console.log(TAG7, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
3679
+ }
3680
+ return sum + valueUsd;
3681
+ }, 0);
3682
+ const nativeAssetCaip = networkIdToCaip(blockchain);
3683
+ const gasAsset = networkBalances.find((b3) => b3.caip === nativeAssetCaip);
3684
+ const totalNativeBalance = networkBalances.filter((b3) => b3.caip === nativeAssetCaip).reduce((sum, balance) => {
3685
+ const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
3686
+ return sum + balanceNum;
3687
+ }, 0).toString();
3688
+ const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
3689
+ networksTemp.push({
3690
+ networkId: blockchain,
3691
+ totalValueUsd: networkTotal,
3692
+ gasAssetCaip: nativeAssetCaip || null,
3693
+ gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
3694
+ icon: gasAsset?.icon || assetInfo?.icon || null,
3695
+ color: gasAsset?.color || assetInfo?.color || null,
3696
+ totalNativeBalance
3697
+ });
3698
+ totalPortfolioValue += networkTotal;
3699
+ }
3700
+ dashboardData.networks = networksTemp.sort((a2, b3) => b3.totalValueUsd - a2.totalValueUsd);
3701
+ dashboardData.totalValueUsd = totalPortfolioValue;
3702
+ dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
3703
+ networkId: network.networkId,
3704
+ percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
3705
+ })).filter((entry) => entry.percentage > 0);
3706
+ console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
3707
+ return dashboardData;
3708
+ }
3709
+
3710
+ // src/index.ts
3711
+ var TAG8 = " | Pioneer-sdk | ";
3712
+
3622
3713
  class SDK {
3623
3714
  status;
3624
3715
  username;
@@ -3781,7 +3872,7 @@ class SDK {
3781
3872
  return true;
3782
3873
  };
3783
3874
  this.setPubkeys = (newPubkeys) => {
3784
- const tag5 = `${TAG7} | setPubkeys | `;
3875
+ const tag5 = `${TAG8} | setPubkeys | `;
3785
3876
  this.pubkeys = [];
3786
3877
  this.pubkeySet.clear();
3787
3878
  let added = 0;
@@ -3792,7 +3883,7 @@ class SDK {
3792
3883
  }
3793
3884
  };
3794
3885
  this.getUnifiedPortfolio = async function() {
3795
- const tag5 = `${TAG7} | getUnifiedPortfolio | `;
3886
+ const tag5 = `${TAG8} | getUnifiedPortfolio | `;
3796
3887
  try {
3797
3888
  const startTime = performance.now();
3798
3889
  try {
@@ -3900,7 +3991,7 @@ class SDK {
3900
3991
  }
3901
3992
  };
3902
3993
  this.init = async function(walletsVerbose, setup) {
3903
- const tag5 = `${TAG7} | init | `;
3994
+ const tag5 = `${TAG8} | init | `;
3904
3995
  try {
3905
3996
  if (!this.username)
3906
3997
  throw Error("username required!");
@@ -3988,91 +4079,10 @@ class SDK {
3988
4079
  }
3989
4080
  };
3990
4081
  this.buildDashboardFromBalances = function() {
3991
- const tag5 = `${TAG7} | buildDashboardFromBalances | `;
3992
- console.log(tag5, "[DASHBOARD] Building dashboard from cached balances...");
3993
- const dashboardData = {
3994
- networks: [],
3995
- totalValueUsd: 0,
3996
- networkPercentages: []
3997
- };
3998
- let totalPortfolioValue = 0;
3999
- const networksTemp = [];
4000
- console.log(tag5, "this.balances: ", this.balances);
4001
- for (const blockchain of this.blockchains) {
4002
- const filteredBalances = this.balances.filter((b3) => {
4003
- const networkId = caipToNetworkId6(b3.caip);
4004
- return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
4005
- });
4006
- const balanceMap = new Map;
4007
- const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
4008
- if (isBitcoin) {
4009
- console.log(tag5, "Bitcoin network detected - checking for duplicate balances");
4010
- const bitcoinByValue = new Map;
4011
- filteredBalances.forEach((balance) => {
4012
- const valueKey = `${balance.balance}_${balance.valueUsd}`;
4013
- if (!bitcoinByValue.has(valueKey)) {
4014
- bitcoinByValue.set(valueKey, []);
4015
- }
4016
- bitcoinByValue.get(valueKey).push(balance);
4017
- });
4018
- for (const [valueKey, balances] of bitcoinByValue.entries()) {
4019
- if (balances.length === 3 && parseFloat(balances[0].valueUsd || "0") > 0) {
4020
- console.log(tag5, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
4021
- const xpubBalance = balances.find((b3) => b3.pubkey?.startsWith("xpub")) || balances[0];
4022
- const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
4023
- balanceMap.set(key, xpubBalance);
4024
- } else {
4025
- balances.forEach((balance) => {
4026
- const key = `${balance.caip}_${balance.pubkey || "default"}`;
4027
- balanceMap.set(key, balance);
4028
- });
4029
- }
4030
- }
4031
- } else {
4032
- filteredBalances.forEach((balance) => {
4033
- const key = `${balance.caip}_${balance.pubkey || "default"}`;
4034
- if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
4035
- balanceMap.set(key, balance);
4036
- }
4037
- });
4038
- }
4039
- const networkBalances = Array.from(balanceMap.values());
4040
- const networkTotal = networkBalances.reduce((sum, balance, idx) => {
4041
- const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
4042
- if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
4043
- console.log(tag5, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
4044
- }
4045
- return sum + valueUsd;
4046
- }, 0);
4047
- const nativeAssetCaip = networkIdToCaip(blockchain);
4048
- const gasAsset = networkBalances.find((b3) => b3.caip === nativeAssetCaip);
4049
- const totalNativeBalance = networkBalances.filter((b3) => b3.caip === nativeAssetCaip).reduce((sum, balance) => {
4050
- const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
4051
- return sum + balanceNum;
4052
- }, 0).toString();
4053
- const assetInfo = nativeAssetCaip ? this.assetsMap.get(nativeAssetCaip) : null;
4054
- networksTemp.push({
4055
- networkId: blockchain,
4056
- totalValueUsd: networkTotal,
4057
- gasAssetCaip: nativeAssetCaip || null,
4058
- gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
4059
- icon: gasAsset?.icon || assetInfo?.icon || null,
4060
- color: gasAsset?.color || assetInfo?.color || null,
4061
- totalNativeBalance
4062
- });
4063
- totalPortfolioValue += networkTotal;
4064
- }
4065
- dashboardData.networks = networksTemp.sort((a2, b3) => b3.totalValueUsd - a2.totalValueUsd);
4066
- dashboardData.totalValueUsd = totalPortfolioValue;
4067
- dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
4068
- networkId: network.networkId,
4069
- percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
4070
- })).filter((entry) => entry.percentage > 0);
4071
- console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
4072
- return dashboardData;
4082
+ return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
4073
4083
  };
4074
4084
  this.syncMarket = async function() {
4075
- const tag5 = `${TAG7} | syncMarket | `;
4085
+ const tag5 = `${TAG8} | syncMarket | `;
4076
4086
  try {
4077
4087
  const invalidBalances = this.balances.filter((b3) => !b3 || !b3.caip || typeof b3.caip !== "string" || !b3.caip.includes(":"));
4078
4088
  if (invalidBalances.length > 0) {
@@ -4123,7 +4133,7 @@ class SDK {
4123
4133
  }
4124
4134
  };
4125
4135
  this.sync = async function() {
4126
- const tag5 = `${TAG7} | sync | `;
4136
+ const tag5 = `${TAG8} | sync | `;
4127
4137
  try {
4128
4138
  const matchesNetwork = (item, networkId) => {
4129
4139
  if (!item.networks || !Array.isArray(item.networks))
@@ -4178,7 +4188,7 @@ class SDK {
4178
4188
  console.log(tag5, "uniqueBlockchains: ", uniqueBlockchains);
4179
4189
  for (const blockchain of uniqueBlockchains) {
4180
4190
  const filteredBalances = this.balances.filter((b3) => {
4181
- const networkId = caipToNetworkId6(b3.caip);
4191
+ const networkId = caipToNetworkId7(b3.caip);
4182
4192
  return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
4183
4193
  });
4184
4194
  console.log(tag5, `Filtering for blockchain: ${blockchain}`);
@@ -4236,7 +4246,7 @@ class SDK {
4236
4246
  return sum + valueUsd;
4237
4247
  }, 0);
4238
4248
  console.log("Final networkTotal:", networkTotal);
4239
- const nativeAssetCaip = networkIdToCaip(blockchain);
4249
+ const nativeAssetCaip = networkIdToCaip2(blockchain);
4240
4250
  const gasAsset = networkBalances.find((b3) => b3.caip === nativeAssetCaip);
4241
4251
  const totalNativeBalance = networkBalances.filter((b3) => b3.caip === nativeAssetCaip).reduce((sum, balance) => {
4242
4252
  const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
@@ -4276,7 +4286,7 @@ class SDK {
4276
4286
  }
4277
4287
  };
4278
4288
  this.buildTx = async function(sendPayload) {
4279
- let tag5 = TAG7 + " | buildTx | ";
4289
+ let tag5 = TAG8 + " | buildTx | ";
4280
4290
  try {
4281
4291
  const transactionDependencies = {
4282
4292
  context: this.context,
@@ -4298,7 +4308,7 @@ class SDK {
4298
4308
  }
4299
4309
  };
4300
4310
  this.buildDelegateTx = async function(caip, params) {
4301
- let tag5 = TAG7 + " | buildDelegateTx | ";
4311
+ let tag5 = TAG8 + " | buildDelegateTx | ";
4302
4312
  try {
4303
4313
  const delegateParams = {
4304
4314
  ...params,
@@ -4313,7 +4323,7 @@ class SDK {
4313
4323
  }
4314
4324
  };
4315
4325
  this.buildUndelegateTx = async function(caip, params) {
4316
- let tag5 = TAG7 + " | buildUndelegateTx | ";
4326
+ let tag5 = TAG8 + " | buildUndelegateTx | ";
4317
4327
  try {
4318
4328
  const undelegateParams = {
4319
4329
  ...params,
@@ -4328,7 +4338,7 @@ class SDK {
4328
4338
  }
4329
4339
  };
4330
4340
  this.buildClaimRewardsTx = async function(caip, params) {
4331
- let tag5 = TAG7 + " | buildClaimRewardsTx | ";
4341
+ let tag5 = TAG8 + " | buildClaimRewardsTx | ";
4332
4342
  try {
4333
4343
  const claimParams = {
4334
4344
  ...params,
@@ -4343,7 +4353,7 @@ class SDK {
4343
4353
  }
4344
4354
  };
4345
4355
  this.buildClaimAllRewardsTx = async function(caip, params) {
4346
- let tag5 = TAG7 + " | buildClaimAllRewardsTx | ";
4356
+ let tag5 = TAG8 + " | buildClaimAllRewardsTx | ";
4347
4357
  try {
4348
4358
  const claimAllParams = {
4349
4359
  ...params,
@@ -4357,7 +4367,7 @@ class SDK {
4357
4367
  }
4358
4368
  };
4359
4369
  this.signTx = async function(unsignedTx) {
4360
- let tag5 = TAG7 + " | signTx | ";
4370
+ let tag5 = TAG8 + " | signTx | ";
4361
4371
  try {
4362
4372
  const transactionDependencies = {
4363
4373
  context: this.context,
@@ -4378,7 +4388,7 @@ class SDK {
4378
4388
  }
4379
4389
  };
4380
4390
  this.broadcastTx = async function(caip, signedTx) {
4381
- let tag5 = TAG7 + " | broadcastTx | ";
4391
+ let tag5 = TAG8 + " | broadcastTx | ";
4382
4392
  try {
4383
4393
  const transactionDependencies = {
4384
4394
  context: this.context,
@@ -4391,7 +4401,7 @@ class SDK {
4391
4401
  };
4392
4402
  let txManager = new TransactionManager(transactionDependencies, this.events);
4393
4403
  let payload = {
4394
- networkId: caipToNetworkId6(caip),
4404
+ networkId: caipToNetworkId7(caip),
4395
4405
  serialized: signedTx
4396
4406
  };
4397
4407
  let txid = await txManager.broadcast(payload);
@@ -4402,7 +4412,7 @@ class SDK {
4402
4412
  }
4403
4413
  };
4404
4414
  this.swap = async function(swapPayload) {
4405
- let tag5 = `${TAG7} | swap | `;
4415
+ let tag5 = `${TAG8} | swap | `;
4406
4416
  try {
4407
4417
  if (!swapPayload)
4408
4418
  throw Error("swapPayload required!");
@@ -4537,7 +4547,7 @@ class SDK {
4537
4547
  }
4538
4548
  };
4539
4549
  this.transfer = async function(sendPayload) {
4540
- let tag5 = `${TAG7} | transfer | `;
4550
+ let tag5 = `${TAG8} | transfer | `;
4541
4551
  try {
4542
4552
  if (!sendPayload)
4543
4553
  throw Error("sendPayload required!");
@@ -4564,7 +4574,7 @@ class SDK {
4564
4574
  if (!signedTx)
4565
4575
  throw Error("Failed to sign transaction!");
4566
4576
  let payload = {
4567
- networkId: caipToNetworkId6(caip),
4577
+ networkId: caipToNetworkId7(caip),
4568
4578
  serialized: signedTx
4569
4579
  };
4570
4580
  let txid = await txManager.broadcast(payload);
@@ -4593,7 +4603,7 @@ class SDK {
4593
4603
  while (!isConfirmed) {
4594
4604
  try {
4595
4605
  const response = await this.pioneer.LookupTx({
4596
- networkId: caipToNetworkId6(caip),
4606
+ networkId: caipToNetworkId7(caip),
4597
4607
  txid
4598
4608
  });
4599
4609
  if (response?.data?.data) {
@@ -4632,7 +4642,7 @@ class SDK {
4632
4642
  }
4633
4643
  };
4634
4644
  this.setBlockchains = async function(blockchains) {
4635
- const tag5 = `${TAG7} | setBlockchains | `;
4645
+ const tag5 = `${TAG8} | setBlockchains | `;
4636
4646
  try {
4637
4647
  if (!blockchains)
4638
4648
  throw Error("blockchains required!");
@@ -4648,7 +4658,7 @@ class SDK {
4648
4658
  }
4649
4659
  };
4650
4660
  this.addAsset = async function(caip, data) {
4651
- let tag5 = TAG7 + " | addAsset | ";
4661
+ let tag5 = TAG8 + " | addAsset | ";
4652
4662
  try {
4653
4663
  let success = false;
4654
4664
  if (!caip)
@@ -4686,7 +4696,7 @@ class SDK {
4686
4696
  }
4687
4697
  };
4688
4698
  this.clearWalletState = async function() {
4689
- const tag5 = `${TAG7} | clearWalletState | `;
4699
+ const tag5 = `${TAG8} | clearWalletState | `;
4690
4700
  try {
4691
4701
  this.context = null;
4692
4702
  this.paths = [];
@@ -4701,7 +4711,7 @@ class SDK {
4701
4711
  }
4702
4712
  };
4703
4713
  this.addPath = async function(path) {
4704
- const tag5 = `${TAG7} | addPath | `;
4714
+ const tag5 = `${TAG8} | addPath | `;
4705
4715
  try {
4706
4716
  this.paths.push(path);
4707
4717
  const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
@@ -4715,7 +4725,7 @@ class SDK {
4715
4725
  }
4716
4726
  };
4717
4727
  this.addPaths = async function(paths) {
4718
- const tag5 = `${TAG7} | addPaths | `;
4728
+ const tag5 = `${TAG8} | addPaths | `;
4719
4729
  try {
4720
4730
  console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
4721
4731
  this.paths.push(...paths);
@@ -4751,11 +4761,11 @@ class SDK {
4751
4761
  return this.getGasAssets();
4752
4762
  };
4753
4763
  this.getGasAssets = async function() {
4754
- const tag5 = `${TAG7} | getGasAssets | `;
4764
+ const tag5 = `${TAG8} | getGasAssets | `;
4755
4765
  try {
4756
4766
  for (let i = 0;i < this.blockchains.length; i++) {
4757
4767
  let networkId = this.blockchains[i];
4758
- let caip = networkIdToCaip(networkId);
4768
+ let caip = networkIdToCaip2(networkId);
4759
4769
  let asset = await assetData2[caip.toLowerCase()];
4760
4770
  if (asset) {
4761
4771
  asset.caip = caip.toLowerCase();
@@ -4794,7 +4804,7 @@ class SDK {
4794
4804
  }
4795
4805
  };
4796
4806
  this.getPubkeys = async function() {
4797
- const tag5 = `${TAG7} | getPubkeys | `;
4807
+ const tag5 = `${TAG8} | getPubkeys | `;
4798
4808
  try {
4799
4809
  if (this.paths.length === 0)
4800
4810
  throw new Error("No paths found!");
@@ -4815,7 +4825,7 @@ class SDK {
4815
4825
  }
4816
4826
  };
4817
4827
  this.getBalancesForNetworks = async function(networkIds) {
4818
- const tag5 = `${TAG7} | getBalancesForNetworks | `;
4828
+ const tag5 = `${TAG8} | getBalancesForNetworks | `;
4819
4829
  try {
4820
4830
  if (!this.pioneer) {
4821
4831
  console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
@@ -4833,7 +4843,7 @@ class SDK {
4833
4843
  return network.startsWith("eip155:");
4834
4844
  return network === adjustedNetworkId;
4835
4845
  }));
4836
- const caipNative = await networkIdToCaip(networkId);
4846
+ const caipNative = await networkIdToCaip2(networkId);
4837
4847
  for (const pubkey of pubkeys) {
4838
4848
  assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
4839
4849
  }
@@ -4851,7 +4861,7 @@ class SDK {
4851
4861
  if (!assetInfo)
4852
4862
  continue;
4853
4863
  Object.assign(balance, assetInfo, {
4854
- networkId: caipToNetworkId6(balance.caip),
4864
+ networkId: caipToNetworkId7(balance.caip),
4855
4865
  icon: assetInfo.icon || "https://pioneers.dev/coins/etherum.png",
4856
4866
  identifier: `${balance.caip}:${balance.pubkey}`
4857
4867
  });
@@ -4870,7 +4880,7 @@ class SDK {
4870
4880
  }
4871
4881
  };
4872
4882
  this.getBalances = async function() {
4873
- const tag5 = `${TAG7} | getBalances | `;
4883
+ const tag5 = `${TAG8} | getBalances | `;
4874
4884
  try {
4875
4885
  return await this.getBalancesForNetworks(this.blockchains);
4876
4886
  } catch (e) {
@@ -4879,10 +4889,10 @@ class SDK {
4879
4889
  }
4880
4890
  };
4881
4891
  this.getBalance = async function(networkId) {
4882
- const tag5 = `${TAG7} | getBalance | `;
4892
+ const tag5 = `${TAG8} | getBalance | `;
4883
4893
  try {
4884
4894
  const results = await this.getBalancesForNetworks([networkId]);
4885
- const filtered = results.filter(async (b3) => b3.networkId === await networkIdToCaip(networkId));
4895
+ const filtered = results.filter(async (b3) => b3.networkId === await networkIdToCaip2(networkId));
4886
4896
  return filtered;
4887
4897
  } catch (e) {
4888
4898
  console.error(tag5, "Error: ", e);
@@ -4890,7 +4900,7 @@ class SDK {
4890
4900
  }
4891
4901
  };
4892
4902
  this.getFees = async function(networkId) {
4893
- const tag5 = `${TAG7} | getFees | `;
4903
+ const tag5 = `${TAG8} | getFees | `;
4894
4904
  try {
4895
4905
  if (!this.pioneer) {
4896
4906
  throw new Error("Pioneer client not initialized. Call init() first.");
@@ -4905,7 +4915,7 @@ class SDK {
4905
4915
  return estimateTransactionFee(feeRate, unit, networkType, txSize);
4906
4916
  };
4907
4917
  this.getCharts = async function() {
4908
- const tag5 = `${TAG7} | getCharts | `;
4918
+ const tag5 = `${TAG8} | getCharts | `;
4909
4919
  try {
4910
4920
  console.log(tag5, "Fetching charts");
4911
4921
  const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
@@ -4927,7 +4937,7 @@ class SDK {
4927
4937
  }
4928
4938
  };
4929
4939
  this.setContext = async (context) => {
4930
- const tag5 = `${TAG7} | setContext | `;
4940
+ const tag5 = `${TAG8} | setContext | `;
4931
4941
  try {
4932
4942
  if (!context)
4933
4943
  throw Error("context required!");
@@ -4940,7 +4950,7 @@ class SDK {
4940
4950
  }
4941
4951
  };
4942
4952
  this.setContextType = async (contextType) => {
4943
- const tag5 = `${TAG7} | setContextType | `;
4953
+ const tag5 = `${TAG8} | setContextType | `;
4944
4954
  try {
4945
4955
  if (!contextType)
4946
4956
  throw Error("contextType required!");
@@ -4953,7 +4963,7 @@ class SDK {
4953
4963
  }
4954
4964
  };
4955
4965
  this.refresh = async () => {
4956
- const tag5 = `${TAG7} | refresh | `;
4966
+ const tag5 = `${TAG8} | refresh | `;
4957
4967
  try {
4958
4968
  await this.sync();
4959
4969
  return this.balances;
@@ -4963,7 +4973,7 @@ class SDK {
4963
4973
  }
4964
4974
  };
4965
4975
  this.setAssetContext = async function(asset) {
4966
- const tag5 = `${TAG7} | setAssetContext | `;
4976
+ const tag5 = `${TAG8} | setAssetContext | `;
4967
4977
  try {
4968
4978
  if (!asset) {
4969
4979
  this.assetContext = null;
@@ -4972,7 +4982,7 @@ class SDK {
4972
4982
  if (!asset.caip)
4973
4983
  throw Error("Invalid Asset! missing caip!");
4974
4984
  if (!asset.networkId)
4975
- asset.networkId = caipToNetworkId6(asset.caip);
4985
+ asset.networkId = caipToNetworkId7(asset.caip);
4976
4986
  if (!this.pubkeys || this.pubkeys.length === 0) {
4977
4987
  const errorMsg = `Cannot set asset context for ${asset.caip} - no pubkeys loaded. Please initialize wallet first.`;
4978
4988
  console.error(tag5, errorMsg);
@@ -5080,7 +5090,7 @@ class SDK {
5080
5090
  console.log(tag5, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
5081
5091
  }
5082
5092
  const assetBalances = this.balances.filter((b3) => b3.caip === asset.caip);
5083
- const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(caipToNetworkId6(asset.caip)) || caipToNetworkId6(asset.caip).includes("eip155") && p2.networks && Array.isArray(p2.networks) && p2.networks.some((n2) => n2.startsWith("eip155")));
5093
+ const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(caipToNetworkId7(asset.caip)) || caipToNetworkId7(asset.caip).includes("eip155") && p2.networks && Array.isArray(p2.networks) && p2.networks.some((n2) => n2.startsWith("eip155")));
5084
5094
  const finalAssetContext = {
5085
5095
  ...assetInfo,
5086
5096
  ...asset,
@@ -5140,12 +5150,12 @@ class SDK {
5140
5150
  }
5141
5151
  }
5142
5152
  if (asset.caip) {
5143
- this.blockchainContext = caipToNetworkId6(asset.caip);
5153
+ this.blockchainContext = caipToNetworkId7(asset.caip);
5144
5154
  } else if (asset.networkId) {
5145
5155
  this.blockchainContext = asset.networkId;
5146
5156
  }
5147
5157
  if (assetPubkeys && assetPubkeys.length > 0) {
5148
- const networkId = caipToNetworkId6(asset.caip || asset.networkId);
5158
+ const networkId = caipToNetworkId7(asset.caip || asset.networkId);
5149
5159
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
5150
5160
  if (!this.pubkeyContext || !currentContextValid) {
5151
5161
  this.pubkeyContext = assetPubkeys[0];
@@ -5162,7 +5172,7 @@ class SDK {
5162
5172
  }
5163
5173
  };
5164
5174
  this.setPubkeyContext = async function(pubkey) {
5165
- let tag5 = `${TAG7} | setPubkeyContext | `;
5175
+ let tag5 = `${TAG8} | setPubkeyContext | `;
5166
5176
  try {
5167
5177
  if (!pubkey)
5168
5178
  throw Error("pubkey is required");
@@ -5181,7 +5191,7 @@ class SDK {
5181
5191
  }
5182
5192
  };
5183
5193
  this.setOutboundAssetContext = async function(asset) {
5184
- const tag5 = `${TAG7} | setOutputAssetContext | `;
5194
+ const tag5 = `${TAG8} | setOutputAssetContext | `;
5185
5195
  try {
5186
5196
  console.log(tag5, "0. asset: ", asset);
5187
5197
  if (!asset) {
@@ -5192,7 +5202,7 @@ class SDK {
5192
5202
  if (!asset.caip)
5193
5203
  throw Error("Invalid Asset! missing caip!");
5194
5204
  if (!asset.networkId)
5195
- asset.networkId = caipToNetworkId6(asset.caip);
5205
+ asset.networkId = caipToNetworkId7(asset.caip);
5196
5206
  console.log(tag5, "networkId: ", asset.networkId);
5197
5207
  console.log(tag5, "this.pubkeys: ", this.pubkeys);
5198
5208
  const pubkey = this.pubkeys.find((p2) => {
@@ -5273,7 +5283,7 @@ class SDK {
5273
5283
  console.log(tag5, "CHECKPOINT 3");
5274
5284
  console.log(tag5, "outboundAssetContext: assetInfo: ", assetInfo);
5275
5285
  if (asset.caip) {
5276
- this.outboundBlockchainContext = caipToNetworkId6(asset.caip);
5286
+ this.outboundBlockchainContext = caipToNetworkId7(asset.caip);
5277
5287
  } else if (asset.networkId) {
5278
5288
  this.outboundBlockchainContext = asset.networkId;
5279
5289
  }