@pioneer-platform/pioneer-sdk 8.11.9 → 8.11.12

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 CHANGED
@@ -4856,6 +4856,30 @@ class SDK {
4856
4856
  const duplicatesRemoved = allPubkeys.length - this.pubkeys.length;
4857
4857
  if (duplicatesRemoved > 0) {
4858
4858
  }
4859
+ const pubkeysWithoutNetworks = this.pubkeys.filter((pk) => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0);
4860
+ if (pubkeysWithoutNetworks.length > 0) {
4861
+ console.error(tag6, "ERROR: Some pubkeys missing networks field!");
4862
+ console.error(tag6, "Affected pubkeys:", pubkeysWithoutNetworks.length);
4863
+ pubkeysWithoutNetworks.forEach((pk) => {
4864
+ console.error(tag6, ` - ${pk.note || pk.pubkey}: networks=${pk.networks}`);
4865
+ });
4866
+ for (const pubkey of pubkeysWithoutNetworks) {
4867
+ const matchingPath = this.paths.find((p) => JSON.stringify(p.addressNList) === JSON.stringify(pubkey.addressNList));
4868
+ if (matchingPath && matchingPath.networks) {
4869
+ console.warn(tag6, ` ⚠️ Auto-fixing: Adding networks from path ${matchingPath.note}`);
4870
+ pubkey.networks = matchingPath.networks;
4871
+ }
4872
+ }
4873
+ const stillMissing = this.pubkeys.filter((pk) => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0);
4874
+ if (stillMissing.length > 0) {
4875
+ console.error(tag6, `❌ CRITICAL: ${stillMissing.length} pubkeys still missing networks after auto-fix!`);
4876
+ stillMissing.forEach((pk) => {
4877
+ console.error(tag6, ` - ${pk.note || pk.pubkey}`);
4878
+ });
4879
+ } else {
4880
+ console.log(tag6, `✅ Auto-fix successful: All pubkeys now have networks field`);
4881
+ }
4882
+ }
4859
4883
  this.events.emit("SET_PUBKEYS", this.pubkeys);
4860
4884
  return pubkeys;
4861
4885
  } catch (error) {
@@ -4871,6 +4895,18 @@ class SDK {
4871
4895
  console.error(tag6, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
4872
4896
  throw new Error("Pioneer client not initialized. Call init() first.");
4873
4897
  }
4898
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Input networks:", networkIds);
4899
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Total pubkeys:", this.pubkeys.length);
4900
+ const pubkeysWithNetworks = this.pubkeys.filter((p) => p.networks && Array.isArray(p.networks));
4901
+ const pubkeysWithoutNetworks = this.pubkeys.filter((p) => !p.networks || !Array.isArray(p.networks));
4902
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Pubkeys WITH networks:", pubkeysWithNetworks.length);
4903
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Pubkeys WITHOUT networks:", pubkeysWithoutNetworks.length);
4904
+ if (pubkeysWithoutNetworks.length > 0) {
4905
+ console.warn("⚠️ [WARNING] Some pubkeys missing networks field:");
4906
+ pubkeysWithoutNetworks.forEach((pk) => {
4907
+ console.warn(` - ${pk.note || pk.pubkey.slice(0, 10)}: networks=${pk.networks}`);
4908
+ });
4909
+ }
4874
4910
  const assetQuery = [];
4875
4911
  for (const networkId of networkIds) {
4876
4912
  let adjustedNetworkId = networkId;
@@ -4878,16 +4914,43 @@ class SDK {
4878
4914
  adjustedNetworkId = "eip155:*";
4879
4915
  }
4880
4916
  const isEip155 = adjustedNetworkId.includes("eip155");
4881
- const pubkeys = this.pubkeys.filter((pubkey) => pubkey.networks && Array.isArray(pubkey.networks) && pubkey.networks.some((network) => {
4917
+ let pubkeys = this.pubkeys.filter((pubkey) => pubkey.networks && Array.isArray(pubkey.networks) && pubkey.networks.some((network) => {
4882
4918
  if (isEip155)
4883
4919
  return network.startsWith("eip155:");
4884
4920
  return network === adjustedNetworkId;
4885
4921
  }));
4922
+ if (pubkeys.length === 0) {
4923
+ console.warn(tag6, `⚠️ No pubkeys found for ${networkId} with networks field`);
4924
+ console.warn(tag6, "Attempting fallback: finding pubkeys by path matching");
4925
+ const pathsForNetwork = this.paths.filter((p) => p.networks?.includes(networkId) || networkId.startsWith("eip155:") && p.networks?.includes("eip155:*"));
4926
+ for (const path of pathsForNetwork) {
4927
+ const matchingPubkey = this.pubkeys.find((pk) => JSON.stringify(pk.addressNList) === JSON.stringify(path.addressNList));
4928
+ if (matchingPubkey) {
4929
+ console.warn(tag6, ` ✓ Found pubkey via path matching: ${matchingPubkey.note || matchingPubkey.pubkey.slice(0, 10)}`);
4930
+ pubkeys.push(matchingPubkey);
4931
+ }
4932
+ }
4933
+ if (pubkeys.length > 0) {
4934
+ console.warn(tag6, ` ✅ Fallback successful: Found ${pubkeys.length} pubkeys for ${networkId}`);
4935
+ } else {
4936
+ console.error(tag6, ` ❌ Fallback failed: No pubkeys found for ${networkId}`);
4937
+ }
4938
+ }
4886
4939
  const caipNative = await import_pioneer_caip8.networkIdToCaip(networkId);
4887
4940
  for (const pubkey of pubkeys) {
4888
4941
  assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
4889
4942
  }
4890
4943
  }
4944
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Built assetQuery with", assetQuery.length, "entries");
4945
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Sample queries:", assetQuery.slice(0, 5));
4946
+ const caipCounts = new Map;
4947
+ for (const query of assetQuery) {
4948
+ caipCounts.set(query.caip, (caipCounts.get(query.caip) || 0) + 1);
4949
+ }
4950
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Queries by chain:");
4951
+ caipCounts.forEach((count, caip) => {
4952
+ console.log(` - ${caip}: ${count} queries`);
4953
+ });
4891
4954
  console.time("GetPortfolioBalances Response Time");
4892
4955
  try {
4893
4956
  let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
package/dist/index.es.js CHANGED
@@ -5032,6 +5032,30 @@ class SDK {
5032
5032
  const duplicatesRemoved = allPubkeys.length - this.pubkeys.length;
5033
5033
  if (duplicatesRemoved > 0) {
5034
5034
  }
5035
+ const pubkeysWithoutNetworks = this.pubkeys.filter((pk) => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0);
5036
+ if (pubkeysWithoutNetworks.length > 0) {
5037
+ console.error(tag6, "ERROR: Some pubkeys missing networks field!");
5038
+ console.error(tag6, "Affected pubkeys:", pubkeysWithoutNetworks.length);
5039
+ pubkeysWithoutNetworks.forEach((pk) => {
5040
+ console.error(tag6, ` - ${pk.note || pk.pubkey}: networks=${pk.networks}`);
5041
+ });
5042
+ for (const pubkey of pubkeysWithoutNetworks) {
5043
+ const matchingPath = this.paths.find((p) => JSON.stringify(p.addressNList) === JSON.stringify(pubkey.addressNList));
5044
+ if (matchingPath && matchingPath.networks) {
5045
+ console.warn(tag6, ` ⚠️ Auto-fixing: Adding networks from path ${matchingPath.note}`);
5046
+ pubkey.networks = matchingPath.networks;
5047
+ }
5048
+ }
5049
+ const stillMissing = this.pubkeys.filter((pk) => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0);
5050
+ if (stillMissing.length > 0) {
5051
+ console.error(tag6, `❌ CRITICAL: ${stillMissing.length} pubkeys still missing networks after auto-fix!`);
5052
+ stillMissing.forEach((pk) => {
5053
+ console.error(tag6, ` - ${pk.note || pk.pubkey}`);
5054
+ });
5055
+ } else {
5056
+ console.log(tag6, `✅ Auto-fix successful: All pubkeys now have networks field`);
5057
+ }
5058
+ }
5035
5059
  this.events.emit("SET_PUBKEYS", this.pubkeys);
5036
5060
  return pubkeys;
5037
5061
  } catch (error) {
@@ -5047,6 +5071,18 @@ class SDK {
5047
5071
  console.error(tag6, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
5048
5072
  throw new Error("Pioneer client not initialized. Call init() first.");
5049
5073
  }
5074
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Input networks:", networkIds);
5075
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Total pubkeys:", this.pubkeys.length);
5076
+ const pubkeysWithNetworks = this.pubkeys.filter((p) => p.networks && Array.isArray(p.networks));
5077
+ const pubkeysWithoutNetworks = this.pubkeys.filter((p) => !p.networks || !Array.isArray(p.networks));
5078
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Pubkeys WITH networks:", pubkeysWithNetworks.length);
5079
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Pubkeys WITHOUT networks:", pubkeysWithoutNetworks.length);
5080
+ if (pubkeysWithoutNetworks.length > 0) {
5081
+ console.warn("⚠️ [WARNING] Some pubkeys missing networks field:");
5082
+ pubkeysWithoutNetworks.forEach((pk) => {
5083
+ console.warn(` - ${pk.note || pk.pubkey.slice(0, 10)}: networks=${pk.networks}`);
5084
+ });
5085
+ }
5050
5086
  const assetQuery = [];
5051
5087
  for (const networkId of networkIds) {
5052
5088
  let adjustedNetworkId = networkId;
@@ -5054,16 +5090,43 @@ class SDK {
5054
5090
  adjustedNetworkId = "eip155:*";
5055
5091
  }
5056
5092
  const isEip155 = adjustedNetworkId.includes("eip155");
5057
- const pubkeys = this.pubkeys.filter((pubkey) => pubkey.networks && Array.isArray(pubkey.networks) && pubkey.networks.some((network) => {
5093
+ let pubkeys = this.pubkeys.filter((pubkey) => pubkey.networks && Array.isArray(pubkey.networks) && pubkey.networks.some((network) => {
5058
5094
  if (isEip155)
5059
5095
  return network.startsWith("eip155:");
5060
5096
  return network === adjustedNetworkId;
5061
5097
  }));
5098
+ if (pubkeys.length === 0) {
5099
+ console.warn(tag6, `⚠️ No pubkeys found for ${networkId} with networks field`);
5100
+ console.warn(tag6, "Attempting fallback: finding pubkeys by path matching");
5101
+ const pathsForNetwork = this.paths.filter((p) => p.networks?.includes(networkId) || networkId.startsWith("eip155:") && p.networks?.includes("eip155:*"));
5102
+ for (const path of pathsForNetwork) {
5103
+ const matchingPubkey = this.pubkeys.find((pk) => JSON.stringify(pk.addressNList) === JSON.stringify(path.addressNList));
5104
+ if (matchingPubkey) {
5105
+ console.warn(tag6, ` ✓ Found pubkey via path matching: ${matchingPubkey.note || matchingPubkey.pubkey.slice(0, 10)}`);
5106
+ pubkeys.push(matchingPubkey);
5107
+ }
5108
+ }
5109
+ if (pubkeys.length > 0) {
5110
+ console.warn(tag6, ` ✅ Fallback successful: Found ${pubkeys.length} pubkeys for ${networkId}`);
5111
+ } else {
5112
+ console.error(tag6, ` ❌ Fallback failed: No pubkeys found for ${networkId}`);
5113
+ }
5114
+ }
5062
5115
  const caipNative = await networkIdToCaip2(networkId);
5063
5116
  for (const pubkey of pubkeys) {
5064
5117
  assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
5065
5118
  }
5066
5119
  }
5120
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Built assetQuery with", assetQuery.length, "entries");
5121
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Sample queries:", assetQuery.slice(0, 5));
5122
+ const caipCounts = new Map;
5123
+ for (const query of assetQuery) {
5124
+ caipCounts.set(query.caip, (caipCounts.get(query.caip) || 0) + 1);
5125
+ }
5126
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Queries by chain:");
5127
+ caipCounts.forEach((count, caip) => {
5128
+ console.log(` - ${caip}: ${count} queries`);
5129
+ });
5067
5130
  console.time("GetPortfolioBalances Response Time");
5068
5131
  try {
5069
5132
  let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
package/dist/index.js CHANGED
@@ -5032,6 +5032,30 @@ class SDK {
5032
5032
  const duplicatesRemoved = allPubkeys.length - this.pubkeys.length;
5033
5033
  if (duplicatesRemoved > 0) {
5034
5034
  }
5035
+ const pubkeysWithoutNetworks = this.pubkeys.filter((pk) => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0);
5036
+ if (pubkeysWithoutNetworks.length > 0) {
5037
+ console.error(tag6, "ERROR: Some pubkeys missing networks field!");
5038
+ console.error(tag6, "Affected pubkeys:", pubkeysWithoutNetworks.length);
5039
+ pubkeysWithoutNetworks.forEach((pk) => {
5040
+ console.error(tag6, ` - ${pk.note || pk.pubkey}: networks=${pk.networks}`);
5041
+ });
5042
+ for (const pubkey of pubkeysWithoutNetworks) {
5043
+ const matchingPath = this.paths.find((p) => JSON.stringify(p.addressNList) === JSON.stringify(pubkey.addressNList));
5044
+ if (matchingPath && matchingPath.networks) {
5045
+ console.warn(tag6, ` ⚠️ Auto-fixing: Adding networks from path ${matchingPath.note}`);
5046
+ pubkey.networks = matchingPath.networks;
5047
+ }
5048
+ }
5049
+ const stillMissing = this.pubkeys.filter((pk) => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0);
5050
+ if (stillMissing.length > 0) {
5051
+ console.error(tag6, `❌ CRITICAL: ${stillMissing.length} pubkeys still missing networks after auto-fix!`);
5052
+ stillMissing.forEach((pk) => {
5053
+ console.error(tag6, ` - ${pk.note || pk.pubkey}`);
5054
+ });
5055
+ } else {
5056
+ console.log(tag6, `✅ Auto-fix successful: All pubkeys now have networks field`);
5057
+ }
5058
+ }
5035
5059
  this.events.emit("SET_PUBKEYS", this.pubkeys);
5036
5060
  return pubkeys;
5037
5061
  } catch (error) {
@@ -5047,6 +5071,18 @@ class SDK {
5047
5071
  console.error(tag6, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
5048
5072
  throw new Error("Pioneer client not initialized. Call init() first.");
5049
5073
  }
5074
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Input networks:", networkIds);
5075
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Total pubkeys:", this.pubkeys.length);
5076
+ const pubkeysWithNetworks = this.pubkeys.filter((p) => p.networks && Array.isArray(p.networks));
5077
+ const pubkeysWithoutNetworks = this.pubkeys.filter((p) => !p.networks || !Array.isArray(p.networks));
5078
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Pubkeys WITH networks:", pubkeysWithNetworks.length);
5079
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Pubkeys WITHOUT networks:", pubkeysWithoutNetworks.length);
5080
+ if (pubkeysWithoutNetworks.length > 0) {
5081
+ console.warn("⚠️ [WARNING] Some pubkeys missing networks field:");
5082
+ pubkeysWithoutNetworks.forEach((pk) => {
5083
+ console.warn(` - ${pk.note || pk.pubkey.slice(0, 10)}: networks=${pk.networks}`);
5084
+ });
5085
+ }
5050
5086
  const assetQuery = [];
5051
5087
  for (const networkId of networkIds) {
5052
5088
  let adjustedNetworkId = networkId;
@@ -5054,16 +5090,43 @@ class SDK {
5054
5090
  adjustedNetworkId = "eip155:*";
5055
5091
  }
5056
5092
  const isEip155 = adjustedNetworkId.includes("eip155");
5057
- const pubkeys = this.pubkeys.filter((pubkey) => pubkey.networks && Array.isArray(pubkey.networks) && pubkey.networks.some((network) => {
5093
+ let pubkeys = this.pubkeys.filter((pubkey) => pubkey.networks && Array.isArray(pubkey.networks) && pubkey.networks.some((network) => {
5058
5094
  if (isEip155)
5059
5095
  return network.startsWith("eip155:");
5060
5096
  return network === adjustedNetworkId;
5061
5097
  }));
5098
+ if (pubkeys.length === 0) {
5099
+ console.warn(tag6, `⚠️ No pubkeys found for ${networkId} with networks field`);
5100
+ console.warn(tag6, "Attempting fallback: finding pubkeys by path matching");
5101
+ const pathsForNetwork = this.paths.filter((p) => p.networks?.includes(networkId) || networkId.startsWith("eip155:") && p.networks?.includes("eip155:*"));
5102
+ for (const path of pathsForNetwork) {
5103
+ const matchingPubkey = this.pubkeys.find((pk) => JSON.stringify(pk.addressNList) === JSON.stringify(path.addressNList));
5104
+ if (matchingPubkey) {
5105
+ console.warn(tag6, ` ✓ Found pubkey via path matching: ${matchingPubkey.note || matchingPubkey.pubkey.slice(0, 10)}`);
5106
+ pubkeys.push(matchingPubkey);
5107
+ }
5108
+ }
5109
+ if (pubkeys.length > 0) {
5110
+ console.warn(tag6, ` ✅ Fallback successful: Found ${pubkeys.length} pubkeys for ${networkId}`);
5111
+ } else {
5112
+ console.error(tag6, ` ❌ Fallback failed: No pubkeys found for ${networkId}`);
5113
+ }
5114
+ }
5062
5115
  const caipNative = await networkIdToCaip2(networkId);
5063
5116
  for (const pubkey of pubkeys) {
5064
5117
  assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
5065
5118
  }
5066
5119
  }
5120
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Built assetQuery with", assetQuery.length, "entries");
5121
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Sample queries:", assetQuery.slice(0, 5));
5122
+ const caipCounts = new Map;
5123
+ for (const query of assetQuery) {
5124
+ caipCounts.set(query.caip, (caipCounts.get(query.caip) || 0) + 1);
5125
+ }
5126
+ console.log("\uD83D\uDD0D [DIAGNOSTIC] Queries by chain:");
5127
+ caipCounts.forEach((count, caip) => {
5128
+ console.log(` - ${caip}: ${count} queries`);
5129
+ });
5067
5130
  console.time("GetPortfolioBalances Response Time");
5068
5131
  try {
5069
5132
  let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "author": "highlander",
3
3
  "name": "@pioneer-platform/pioneer-sdk",
4
- "version": "8.11.9",
4
+ "version": "8.11.12",
5
5
  "dependencies": {
6
6
  "@keepkey/keepkey-sdk": "^0.2.62",
7
7
  "@pioneer-platform/loggerdog": "^8.11.0",
8
8
  "@pioneer-platform/pioneer-caip": "^9.10.0",
9
9
  "@pioneer-platform/pioneer-client": "^9.10.10",
10
10
  "@pioneer-platform/pioneer-coins": "^9.11.0",
11
- "@pioneer-platform/pioneer-discovery": "^8.11.4",
11
+ "@pioneer-platform/pioneer-discovery": "^8.11.11",
12
12
  "@pioneer-platform/pioneer-events": "^8.11.0",
13
13
  "coinselect": "^3.1.13",
14
14
  "eventemitter3": "^5.0.1",
package/src/index.ts CHANGED
@@ -1678,6 +1678,47 @@ export class SDK {
1678
1678
  if (duplicatesRemoved > 0) {
1679
1679
  }
1680
1680
 
1681
+ // FIX 1: Validate that all pubkeys have networks field
1682
+ const pubkeysWithoutNetworks = this.pubkeys.filter(
1683
+ pk => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0
1684
+ );
1685
+
1686
+ if (pubkeysWithoutNetworks.length > 0) {
1687
+ console.error(tag, 'ERROR: Some pubkeys missing networks field!');
1688
+ console.error(tag, 'Affected pubkeys:', pubkeysWithoutNetworks.length);
1689
+
1690
+ // Log details
1691
+ pubkeysWithoutNetworks.forEach(pk => {
1692
+ console.error(tag, ` - ${pk.note || pk.pubkey}: networks=${pk.networks}`);
1693
+ });
1694
+
1695
+ // Try to fix by matching with paths
1696
+ for (const pubkey of pubkeysWithoutNetworks) {
1697
+ const matchingPath = this.paths.find(p =>
1698
+ JSON.stringify(p.addressNList) === JSON.stringify(pubkey.addressNList)
1699
+ );
1700
+
1701
+ if (matchingPath && matchingPath.networks) {
1702
+ console.warn(tag, ` ⚠️ Auto-fixing: Adding networks from path ${matchingPath.note}`);
1703
+ pubkey.networks = matchingPath.networks;
1704
+ }
1705
+ }
1706
+
1707
+ // Check if auto-fix worked
1708
+ const stillMissing = this.pubkeys.filter(
1709
+ pk => !pk.networks || !Array.isArray(pk.networks) || pk.networks.length === 0
1710
+ );
1711
+
1712
+ if (stillMissing.length > 0) {
1713
+ console.error(tag, `❌ CRITICAL: ${stillMissing.length} pubkeys still missing networks after auto-fix!`);
1714
+ stillMissing.forEach(pk => {
1715
+ console.error(tag, ` - ${pk.note || pk.pubkey}`);
1716
+ });
1717
+ } else {
1718
+ console.log(tag, `✅ Auto-fix successful: All pubkeys now have networks field`);
1719
+ }
1720
+ }
1721
+
1681
1722
  // Emit event to notify that pubkeys have been set
1682
1723
  this.events.emit('SET_PUBKEYS', this.pubkeys);
1683
1724
 
@@ -1701,6 +1742,24 @@ export class SDK {
1701
1742
  throw new Error('Pioneer client not initialized. Call init() first.');
1702
1743
  }
1703
1744
 
1745
+ // DIAGNOSTIC: Log input
1746
+ console.log('🔍 [DIAGNOSTIC] Input networks:', networkIds);
1747
+ console.log('🔍 [DIAGNOSTIC] Total pubkeys:', this.pubkeys.length);
1748
+
1749
+ // DIAGNOSTIC: Check which pubkeys have networks field
1750
+ const pubkeysWithNetworks = this.pubkeys.filter(p => p.networks && Array.isArray(p.networks));
1751
+ const pubkeysWithoutNetworks = this.pubkeys.filter(p => !p.networks || !Array.isArray(p.networks));
1752
+
1753
+ console.log('🔍 [DIAGNOSTIC] Pubkeys WITH networks:', pubkeysWithNetworks.length);
1754
+ console.log('🔍 [DIAGNOSTIC] Pubkeys WITHOUT networks:', pubkeysWithoutNetworks.length);
1755
+
1756
+ if (pubkeysWithoutNetworks.length > 0) {
1757
+ console.warn('⚠️ [WARNING] Some pubkeys missing networks field:');
1758
+ pubkeysWithoutNetworks.forEach(pk => {
1759
+ console.warn(` - ${pk.note || pk.pubkey.slice(0, 10)}: networks=${pk.networks}`);
1760
+ });
1761
+ }
1762
+
1704
1763
  const assetQuery: { caip: string; pubkey: string }[] = [];
1705
1764
 
1706
1765
  for (const networkId of networkIds) {
@@ -1711,7 +1770,7 @@ export class SDK {
1711
1770
  }
1712
1771
 
1713
1772
  const isEip155 = adjustedNetworkId.includes('eip155');
1714
- const pubkeys = this.pubkeys.filter(
1773
+ let pubkeys = this.pubkeys.filter(
1715
1774
  (pubkey) =>
1716
1775
  pubkey.networks &&
1717
1776
  Array.isArray(pubkey.networks) &&
@@ -1721,12 +1780,56 @@ export class SDK {
1721
1780
  }),
1722
1781
  );
1723
1782
 
1783
+ // FIX 2: Fallback query for missing networks
1784
+ if (pubkeys.length === 0) {
1785
+ console.warn(tag, `⚠️ No pubkeys found for ${networkId} with networks field`);
1786
+ console.warn(tag, 'Attempting fallback: finding pubkeys by path matching');
1787
+
1788
+ // Find paths for this network
1789
+ const pathsForNetwork = this.paths.filter(p =>
1790
+ p.networks?.includes(networkId) ||
1791
+ (networkId.startsWith('eip155:') && p.networks?.includes('eip155:*'))
1792
+ );
1793
+
1794
+ // Find pubkeys matching those paths
1795
+ for (const path of pathsForNetwork) {
1796
+ const matchingPubkey = this.pubkeys.find(pk =>
1797
+ JSON.stringify(pk.addressNList) === JSON.stringify(path.addressNList)
1798
+ );
1799
+
1800
+ if (matchingPubkey) {
1801
+ console.warn(tag, ` ✓ Found pubkey via path matching: ${matchingPubkey.note || matchingPubkey.pubkey.slice(0, 10)}`);
1802
+ pubkeys.push(matchingPubkey);
1803
+ }
1804
+ }
1805
+
1806
+ if (pubkeys.length > 0) {
1807
+ console.warn(tag, ` ✅ Fallback successful: Found ${pubkeys.length} pubkeys for ${networkId}`);
1808
+ } else {
1809
+ console.error(tag, ` ❌ Fallback failed: No pubkeys found for ${networkId}`);
1810
+ }
1811
+ }
1812
+
1724
1813
  const caipNative = await networkIdToCaip(networkId);
1725
1814
  for (const pubkey of pubkeys) {
1726
1815
  assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
1727
1816
  }
1728
1817
  }
1729
1818
 
1819
+ // DIAGNOSTIC: Log assetQuery before API call
1820
+ console.log('🔍 [DIAGNOSTIC] Built assetQuery with', assetQuery.length, 'entries');
1821
+ console.log('🔍 [DIAGNOSTIC] Sample queries:', assetQuery.slice(0, 5));
1822
+
1823
+ // Group by CAIP to see which chains are included
1824
+ const caipCounts = new Map<string, number>();
1825
+ for (const query of assetQuery) {
1826
+ caipCounts.set(query.caip, (caipCounts.get(query.caip) || 0) + 1);
1827
+ }
1828
+ console.log('🔍 [DIAGNOSTIC] Queries by chain:');
1829
+ caipCounts.forEach((count, caip) => {
1830
+ console.log(` - ${caip}: ${count} queries`);
1831
+ });
1832
+
1730
1833
  console.time('GetPortfolioBalances Response Time');
1731
1834
 
1732
1835
  try {