@pioneer-platform/pioneer-sdk 4.20.4 → 4.20.6
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 +146 -138
- package/dist/index.es.js +146 -138
- package/dist/index.js +146 -138
- package/package.json +6 -6
- package/src/index.ts +1 -187
- package/src/utils/sync-portfolio.ts +100 -0
- package/src/index.ts.tmp +0 -2580
- package/src/index.ts.tmp2 +0 -2584
package/dist/index.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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
|
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
|
-
//
|
|
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}.",
|
|
@@ -3606,8 +3606,7 @@ async function detectKkApiAvailability(forceLocalhost) {
|
|
|
3606
3606
|
}
|
|
3607
3607
|
}
|
|
3608
3608
|
|
|
3609
|
-
// src/
|
|
3610
|
-
var TAG7 = " | Pioneer-sdk | ";
|
|
3609
|
+
// src/utils/format-time.ts
|
|
3611
3610
|
function formatTime(durationMs) {
|
|
3612
3611
|
let seconds = Math.floor(durationMs / 1000 % 60);
|
|
3613
3612
|
let minutes = Math.floor(durationMs / (1000 * 60) % 60);
|
|
@@ -3621,6 +3620,96 @@ function formatTime(durationMs) {
|
|
|
3621
3620
|
return formatted.trim();
|
|
3622
3621
|
}
|
|
3623
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
|
+
|
|
3624
3713
|
class SDK {
|
|
3625
3714
|
status;
|
|
3626
3715
|
username;
|
|
@@ -3783,7 +3872,7 @@ class SDK {
|
|
|
3783
3872
|
return true;
|
|
3784
3873
|
};
|
|
3785
3874
|
this.setPubkeys = (newPubkeys) => {
|
|
3786
|
-
const tag5 = `${
|
|
3875
|
+
const tag5 = `${TAG8} | setPubkeys | `;
|
|
3787
3876
|
this.pubkeys = [];
|
|
3788
3877
|
this.pubkeySet.clear();
|
|
3789
3878
|
let added = 0;
|
|
@@ -3794,7 +3883,7 @@ class SDK {
|
|
|
3794
3883
|
}
|
|
3795
3884
|
};
|
|
3796
3885
|
this.getUnifiedPortfolio = async function() {
|
|
3797
|
-
const tag5 = `${
|
|
3886
|
+
const tag5 = `${TAG8} | getUnifiedPortfolio | `;
|
|
3798
3887
|
try {
|
|
3799
3888
|
const startTime = performance.now();
|
|
3800
3889
|
try {
|
|
@@ -3902,7 +3991,7 @@ class SDK {
|
|
|
3902
3991
|
}
|
|
3903
3992
|
};
|
|
3904
3993
|
this.init = async function(walletsVerbose, setup) {
|
|
3905
|
-
const tag5 = `${
|
|
3994
|
+
const tag5 = `${TAG8} | init | `;
|
|
3906
3995
|
try {
|
|
3907
3996
|
if (!this.username)
|
|
3908
3997
|
throw Error("username required!");
|
|
@@ -3990,91 +4079,10 @@ class SDK {
|
|
|
3990
4079
|
}
|
|
3991
4080
|
};
|
|
3992
4081
|
this.buildDashboardFromBalances = function() {
|
|
3993
|
-
|
|
3994
|
-
console.log(tag5, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3995
|
-
const dashboardData = {
|
|
3996
|
-
networks: [],
|
|
3997
|
-
totalValueUsd: 0,
|
|
3998
|
-
networkPercentages: []
|
|
3999
|
-
};
|
|
4000
|
-
let totalPortfolioValue = 0;
|
|
4001
|
-
const networksTemp = [];
|
|
4002
|
-
console.log(tag5, "this.balances: ", this.balances);
|
|
4003
|
-
for (const blockchain of this.blockchains) {
|
|
4004
|
-
const filteredBalances = this.balances.filter((b3) => {
|
|
4005
|
-
const networkId = caipToNetworkId6(b3.caip);
|
|
4006
|
-
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4007
|
-
});
|
|
4008
|
-
const balanceMap = new Map;
|
|
4009
|
-
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
4010
|
-
if (isBitcoin) {
|
|
4011
|
-
console.log(tag5, "Bitcoin network detected - checking for duplicate balances");
|
|
4012
|
-
const bitcoinByValue = new Map;
|
|
4013
|
-
filteredBalances.forEach((balance) => {
|
|
4014
|
-
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
4015
|
-
if (!bitcoinByValue.has(valueKey)) {
|
|
4016
|
-
bitcoinByValue.set(valueKey, []);
|
|
4017
|
-
}
|
|
4018
|
-
bitcoinByValue.get(valueKey).push(balance);
|
|
4019
|
-
});
|
|
4020
|
-
for (const [valueKey, balances] of bitcoinByValue.entries()) {
|
|
4021
|
-
if (balances.length === 3 && parseFloat(balances[0].valueUsd || "0") > 0) {
|
|
4022
|
-
console.log(tag5, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
4023
|
-
const xpubBalance = balances.find((b3) => b3.pubkey?.startsWith("xpub")) || balances[0];
|
|
4024
|
-
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
4025
|
-
balanceMap.set(key, xpubBalance);
|
|
4026
|
-
} else {
|
|
4027
|
-
balances.forEach((balance) => {
|
|
4028
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
4029
|
-
balanceMap.set(key, balance);
|
|
4030
|
-
});
|
|
4031
|
-
}
|
|
4032
|
-
}
|
|
4033
|
-
} else {
|
|
4034
|
-
filteredBalances.forEach((balance) => {
|
|
4035
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
4036
|
-
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
4037
|
-
balanceMap.set(key, balance);
|
|
4038
|
-
}
|
|
4039
|
-
});
|
|
4040
|
-
}
|
|
4041
|
-
const networkBalances = Array.from(balanceMap.values());
|
|
4042
|
-
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
4043
|
-
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
4044
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
4045
|
-
console.log(tag5, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
4046
|
-
}
|
|
4047
|
-
return sum + valueUsd;
|
|
4048
|
-
}, 0);
|
|
4049
|
-
const nativeAssetCaip = networkIdToCaip(blockchain);
|
|
4050
|
-
const gasAsset = networkBalances.find((b3) => b3.caip === nativeAssetCaip);
|
|
4051
|
-
const totalNativeBalance = networkBalances.filter((b3) => b3.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4052
|
-
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
4053
|
-
return sum + balanceNum;
|
|
4054
|
-
}, 0).toString();
|
|
4055
|
-
const assetInfo = nativeAssetCaip ? this.assetsMap.get(nativeAssetCaip) : null;
|
|
4056
|
-
networksTemp.push({
|
|
4057
|
-
networkId: blockchain,
|
|
4058
|
-
totalValueUsd: networkTotal,
|
|
4059
|
-
gasAssetCaip: nativeAssetCaip || null,
|
|
4060
|
-
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
4061
|
-
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
4062
|
-
color: gasAsset?.color || assetInfo?.color || null,
|
|
4063
|
-
totalNativeBalance
|
|
4064
|
-
});
|
|
4065
|
-
totalPortfolioValue += networkTotal;
|
|
4066
|
-
}
|
|
4067
|
-
dashboardData.networks = networksTemp.sort((a2, b3) => b3.totalValueUsd - a2.totalValueUsd);
|
|
4068
|
-
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
4069
|
-
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
4070
|
-
networkId: network.networkId,
|
|
4071
|
-
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
4072
|
-
})).filter((entry) => entry.percentage > 0);
|
|
4073
|
-
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
4074
|
-
return dashboardData;
|
|
4082
|
+
return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
|
|
4075
4083
|
};
|
|
4076
4084
|
this.syncMarket = async function() {
|
|
4077
|
-
const tag5 = `${
|
|
4085
|
+
const tag5 = `${TAG8} | syncMarket | `;
|
|
4078
4086
|
try {
|
|
4079
4087
|
const invalidBalances = this.balances.filter((b3) => !b3 || !b3.caip || typeof b3.caip !== "string" || !b3.caip.includes(":"));
|
|
4080
4088
|
if (invalidBalances.length > 0) {
|
|
@@ -4125,7 +4133,7 @@ class SDK {
|
|
|
4125
4133
|
}
|
|
4126
4134
|
};
|
|
4127
4135
|
this.sync = async function() {
|
|
4128
|
-
const tag5 = `${
|
|
4136
|
+
const tag5 = `${TAG8} | sync | `;
|
|
4129
4137
|
try {
|
|
4130
4138
|
const matchesNetwork = (item, networkId) => {
|
|
4131
4139
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4180,7 +4188,7 @@ class SDK {
|
|
|
4180
4188
|
console.log(tag5, "uniqueBlockchains: ", uniqueBlockchains);
|
|
4181
4189
|
for (const blockchain of uniqueBlockchains) {
|
|
4182
4190
|
const filteredBalances = this.balances.filter((b3) => {
|
|
4183
|
-
const networkId =
|
|
4191
|
+
const networkId = caipToNetworkId7(b3.caip);
|
|
4184
4192
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4185
4193
|
});
|
|
4186
4194
|
console.log(tag5, `Filtering for blockchain: ${blockchain}`);
|
|
@@ -4238,7 +4246,7 @@ class SDK {
|
|
|
4238
4246
|
return sum + valueUsd;
|
|
4239
4247
|
}, 0);
|
|
4240
4248
|
console.log("Final networkTotal:", networkTotal);
|
|
4241
|
-
const nativeAssetCaip =
|
|
4249
|
+
const nativeAssetCaip = networkIdToCaip2(blockchain);
|
|
4242
4250
|
const gasAsset = networkBalances.find((b3) => b3.caip === nativeAssetCaip);
|
|
4243
4251
|
const totalNativeBalance = networkBalances.filter((b3) => b3.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4244
4252
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
@@ -4278,7 +4286,7 @@ class SDK {
|
|
|
4278
4286
|
}
|
|
4279
4287
|
};
|
|
4280
4288
|
this.buildTx = async function(sendPayload) {
|
|
4281
|
-
let tag5 =
|
|
4289
|
+
let tag5 = TAG8 + " | buildTx | ";
|
|
4282
4290
|
try {
|
|
4283
4291
|
const transactionDependencies = {
|
|
4284
4292
|
context: this.context,
|
|
@@ -4300,7 +4308,7 @@ class SDK {
|
|
|
4300
4308
|
}
|
|
4301
4309
|
};
|
|
4302
4310
|
this.buildDelegateTx = async function(caip, params) {
|
|
4303
|
-
let tag5 =
|
|
4311
|
+
let tag5 = TAG8 + " | buildDelegateTx | ";
|
|
4304
4312
|
try {
|
|
4305
4313
|
const delegateParams = {
|
|
4306
4314
|
...params,
|
|
@@ -4315,7 +4323,7 @@ class SDK {
|
|
|
4315
4323
|
}
|
|
4316
4324
|
};
|
|
4317
4325
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4318
|
-
let tag5 =
|
|
4326
|
+
let tag5 = TAG8 + " | buildUndelegateTx | ";
|
|
4319
4327
|
try {
|
|
4320
4328
|
const undelegateParams = {
|
|
4321
4329
|
...params,
|
|
@@ -4330,7 +4338,7 @@ class SDK {
|
|
|
4330
4338
|
}
|
|
4331
4339
|
};
|
|
4332
4340
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4333
|
-
let tag5 =
|
|
4341
|
+
let tag5 = TAG8 + " | buildClaimRewardsTx | ";
|
|
4334
4342
|
try {
|
|
4335
4343
|
const claimParams = {
|
|
4336
4344
|
...params,
|
|
@@ -4345,7 +4353,7 @@ class SDK {
|
|
|
4345
4353
|
}
|
|
4346
4354
|
};
|
|
4347
4355
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4348
|
-
let tag5 =
|
|
4356
|
+
let tag5 = TAG8 + " | buildClaimAllRewardsTx | ";
|
|
4349
4357
|
try {
|
|
4350
4358
|
const claimAllParams = {
|
|
4351
4359
|
...params,
|
|
@@ -4359,7 +4367,7 @@ class SDK {
|
|
|
4359
4367
|
}
|
|
4360
4368
|
};
|
|
4361
4369
|
this.signTx = async function(unsignedTx) {
|
|
4362
|
-
let tag5 =
|
|
4370
|
+
let tag5 = TAG8 + " | signTx | ";
|
|
4363
4371
|
try {
|
|
4364
4372
|
const transactionDependencies = {
|
|
4365
4373
|
context: this.context,
|
|
@@ -4380,7 +4388,7 @@ class SDK {
|
|
|
4380
4388
|
}
|
|
4381
4389
|
};
|
|
4382
4390
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4383
|
-
let tag5 =
|
|
4391
|
+
let tag5 = TAG8 + " | broadcastTx | ";
|
|
4384
4392
|
try {
|
|
4385
4393
|
const transactionDependencies = {
|
|
4386
4394
|
context: this.context,
|
|
@@ -4393,7 +4401,7 @@ class SDK {
|
|
|
4393
4401
|
};
|
|
4394
4402
|
let txManager = new TransactionManager(transactionDependencies, this.events);
|
|
4395
4403
|
let payload = {
|
|
4396
|
-
networkId:
|
|
4404
|
+
networkId: caipToNetworkId7(caip),
|
|
4397
4405
|
serialized: signedTx
|
|
4398
4406
|
};
|
|
4399
4407
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4404,7 +4412,7 @@ class SDK {
|
|
|
4404
4412
|
}
|
|
4405
4413
|
};
|
|
4406
4414
|
this.swap = async function(swapPayload) {
|
|
4407
|
-
let tag5 = `${
|
|
4415
|
+
let tag5 = `${TAG8} | swap | `;
|
|
4408
4416
|
try {
|
|
4409
4417
|
if (!swapPayload)
|
|
4410
4418
|
throw Error("swapPayload required!");
|
|
@@ -4539,7 +4547,7 @@ class SDK {
|
|
|
4539
4547
|
}
|
|
4540
4548
|
};
|
|
4541
4549
|
this.transfer = async function(sendPayload) {
|
|
4542
|
-
let tag5 = `${
|
|
4550
|
+
let tag5 = `${TAG8} | transfer | `;
|
|
4543
4551
|
try {
|
|
4544
4552
|
if (!sendPayload)
|
|
4545
4553
|
throw Error("sendPayload required!");
|
|
@@ -4566,7 +4574,7 @@ class SDK {
|
|
|
4566
4574
|
if (!signedTx)
|
|
4567
4575
|
throw Error("Failed to sign transaction!");
|
|
4568
4576
|
let payload = {
|
|
4569
|
-
networkId:
|
|
4577
|
+
networkId: caipToNetworkId7(caip),
|
|
4570
4578
|
serialized: signedTx
|
|
4571
4579
|
};
|
|
4572
4580
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4595,7 +4603,7 @@ class SDK {
|
|
|
4595
4603
|
while (!isConfirmed) {
|
|
4596
4604
|
try {
|
|
4597
4605
|
const response = await this.pioneer.LookupTx({
|
|
4598
|
-
networkId:
|
|
4606
|
+
networkId: caipToNetworkId7(caip),
|
|
4599
4607
|
txid
|
|
4600
4608
|
});
|
|
4601
4609
|
if (response?.data?.data) {
|
|
@@ -4634,7 +4642,7 @@ class SDK {
|
|
|
4634
4642
|
}
|
|
4635
4643
|
};
|
|
4636
4644
|
this.setBlockchains = async function(blockchains) {
|
|
4637
|
-
const tag5 = `${
|
|
4645
|
+
const tag5 = `${TAG8} | setBlockchains | `;
|
|
4638
4646
|
try {
|
|
4639
4647
|
if (!blockchains)
|
|
4640
4648
|
throw Error("blockchains required!");
|
|
@@ -4650,7 +4658,7 @@ class SDK {
|
|
|
4650
4658
|
}
|
|
4651
4659
|
};
|
|
4652
4660
|
this.addAsset = async function(caip, data) {
|
|
4653
|
-
let tag5 =
|
|
4661
|
+
let tag5 = TAG8 + " | addAsset | ";
|
|
4654
4662
|
try {
|
|
4655
4663
|
let success = false;
|
|
4656
4664
|
if (!caip)
|
|
@@ -4688,7 +4696,7 @@ class SDK {
|
|
|
4688
4696
|
}
|
|
4689
4697
|
};
|
|
4690
4698
|
this.clearWalletState = async function() {
|
|
4691
|
-
const tag5 = `${
|
|
4699
|
+
const tag5 = `${TAG8} | clearWalletState | `;
|
|
4692
4700
|
try {
|
|
4693
4701
|
this.context = null;
|
|
4694
4702
|
this.paths = [];
|
|
@@ -4703,7 +4711,7 @@ class SDK {
|
|
|
4703
4711
|
}
|
|
4704
4712
|
};
|
|
4705
4713
|
this.addPath = async function(path) {
|
|
4706
|
-
const tag5 = `${
|
|
4714
|
+
const tag5 = `${TAG8} | addPath | `;
|
|
4707
4715
|
try {
|
|
4708
4716
|
this.paths.push(path);
|
|
4709
4717
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -4717,7 +4725,7 @@ class SDK {
|
|
|
4717
4725
|
}
|
|
4718
4726
|
};
|
|
4719
4727
|
this.addPaths = async function(paths) {
|
|
4720
|
-
const tag5 = `${
|
|
4728
|
+
const tag5 = `${TAG8} | addPaths | `;
|
|
4721
4729
|
try {
|
|
4722
4730
|
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4723
4731
|
this.paths.push(...paths);
|
|
@@ -4753,11 +4761,11 @@ class SDK {
|
|
|
4753
4761
|
return this.getGasAssets();
|
|
4754
4762
|
};
|
|
4755
4763
|
this.getGasAssets = async function() {
|
|
4756
|
-
const tag5 = `${
|
|
4764
|
+
const tag5 = `${TAG8} | getGasAssets | `;
|
|
4757
4765
|
try {
|
|
4758
4766
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4759
4767
|
let networkId = this.blockchains[i];
|
|
4760
|
-
let caip =
|
|
4768
|
+
let caip = networkIdToCaip2(networkId);
|
|
4761
4769
|
let asset = await assetData2[caip.toLowerCase()];
|
|
4762
4770
|
if (asset) {
|
|
4763
4771
|
asset.caip = caip.toLowerCase();
|
|
@@ -4796,7 +4804,7 @@ class SDK {
|
|
|
4796
4804
|
}
|
|
4797
4805
|
};
|
|
4798
4806
|
this.getPubkeys = async function() {
|
|
4799
|
-
const tag5 = `${
|
|
4807
|
+
const tag5 = `${TAG8} | getPubkeys | `;
|
|
4800
4808
|
try {
|
|
4801
4809
|
if (this.paths.length === 0)
|
|
4802
4810
|
throw new Error("No paths found!");
|
|
@@ -4817,7 +4825,7 @@ class SDK {
|
|
|
4817
4825
|
}
|
|
4818
4826
|
};
|
|
4819
4827
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4820
|
-
const tag5 = `${
|
|
4828
|
+
const tag5 = `${TAG8} | getBalancesForNetworks | `;
|
|
4821
4829
|
try {
|
|
4822
4830
|
if (!this.pioneer) {
|
|
4823
4831
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -4835,7 +4843,7 @@ class SDK {
|
|
|
4835
4843
|
return network.startsWith("eip155:");
|
|
4836
4844
|
return network === adjustedNetworkId;
|
|
4837
4845
|
}));
|
|
4838
|
-
const caipNative = await
|
|
4846
|
+
const caipNative = await networkIdToCaip2(networkId);
|
|
4839
4847
|
for (const pubkey of pubkeys) {
|
|
4840
4848
|
assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
|
|
4841
4849
|
}
|
|
@@ -4853,7 +4861,7 @@ class SDK {
|
|
|
4853
4861
|
if (!assetInfo)
|
|
4854
4862
|
continue;
|
|
4855
4863
|
Object.assign(balance, assetInfo, {
|
|
4856
|
-
networkId:
|
|
4864
|
+
networkId: caipToNetworkId7(balance.caip),
|
|
4857
4865
|
icon: assetInfo.icon || "https://pioneers.dev/coins/etherum.png",
|
|
4858
4866
|
identifier: `${balance.caip}:${balance.pubkey}`
|
|
4859
4867
|
});
|
|
@@ -4872,7 +4880,7 @@ class SDK {
|
|
|
4872
4880
|
}
|
|
4873
4881
|
};
|
|
4874
4882
|
this.getBalances = async function() {
|
|
4875
|
-
const tag5 = `${
|
|
4883
|
+
const tag5 = `${TAG8} | getBalances | `;
|
|
4876
4884
|
try {
|
|
4877
4885
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4878
4886
|
} catch (e) {
|
|
@@ -4881,10 +4889,10 @@ class SDK {
|
|
|
4881
4889
|
}
|
|
4882
4890
|
};
|
|
4883
4891
|
this.getBalance = async function(networkId) {
|
|
4884
|
-
const tag5 = `${
|
|
4892
|
+
const tag5 = `${TAG8} | getBalance | `;
|
|
4885
4893
|
try {
|
|
4886
4894
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4887
|
-
const filtered = results.filter(async (b3) => b3.networkId === await
|
|
4895
|
+
const filtered = results.filter(async (b3) => b3.networkId === await networkIdToCaip2(networkId));
|
|
4888
4896
|
return filtered;
|
|
4889
4897
|
} catch (e) {
|
|
4890
4898
|
console.error(tag5, "Error: ", e);
|
|
@@ -4892,7 +4900,7 @@ class SDK {
|
|
|
4892
4900
|
}
|
|
4893
4901
|
};
|
|
4894
4902
|
this.getFees = async function(networkId) {
|
|
4895
|
-
const tag5 = `${
|
|
4903
|
+
const tag5 = `${TAG8} | getFees | `;
|
|
4896
4904
|
try {
|
|
4897
4905
|
if (!this.pioneer) {
|
|
4898
4906
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -4907,7 +4915,7 @@ class SDK {
|
|
|
4907
4915
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
4908
4916
|
};
|
|
4909
4917
|
this.getCharts = async function() {
|
|
4910
|
-
const tag5 = `${
|
|
4918
|
+
const tag5 = `${TAG8} | getCharts | `;
|
|
4911
4919
|
try {
|
|
4912
4920
|
console.log(tag5, "Fetching charts");
|
|
4913
4921
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -4929,7 +4937,7 @@ class SDK {
|
|
|
4929
4937
|
}
|
|
4930
4938
|
};
|
|
4931
4939
|
this.setContext = async (context) => {
|
|
4932
|
-
const tag5 = `${
|
|
4940
|
+
const tag5 = `${TAG8} | setContext | `;
|
|
4933
4941
|
try {
|
|
4934
4942
|
if (!context)
|
|
4935
4943
|
throw Error("context required!");
|
|
@@ -4942,7 +4950,7 @@ class SDK {
|
|
|
4942
4950
|
}
|
|
4943
4951
|
};
|
|
4944
4952
|
this.setContextType = async (contextType) => {
|
|
4945
|
-
const tag5 = `${
|
|
4953
|
+
const tag5 = `${TAG8} | setContextType | `;
|
|
4946
4954
|
try {
|
|
4947
4955
|
if (!contextType)
|
|
4948
4956
|
throw Error("contextType required!");
|
|
@@ -4955,7 +4963,7 @@ class SDK {
|
|
|
4955
4963
|
}
|
|
4956
4964
|
};
|
|
4957
4965
|
this.refresh = async () => {
|
|
4958
|
-
const tag5 = `${
|
|
4966
|
+
const tag5 = `${TAG8} | refresh | `;
|
|
4959
4967
|
try {
|
|
4960
4968
|
await this.sync();
|
|
4961
4969
|
return this.balances;
|
|
@@ -4965,7 +4973,7 @@ class SDK {
|
|
|
4965
4973
|
}
|
|
4966
4974
|
};
|
|
4967
4975
|
this.setAssetContext = async function(asset) {
|
|
4968
|
-
const tag5 = `${
|
|
4976
|
+
const tag5 = `${TAG8} | setAssetContext | `;
|
|
4969
4977
|
try {
|
|
4970
4978
|
if (!asset) {
|
|
4971
4979
|
this.assetContext = null;
|
|
@@ -4974,7 +4982,7 @@ class SDK {
|
|
|
4974
4982
|
if (!asset.caip)
|
|
4975
4983
|
throw Error("Invalid Asset! missing caip!");
|
|
4976
4984
|
if (!asset.networkId)
|
|
4977
|
-
asset.networkId =
|
|
4985
|
+
asset.networkId = caipToNetworkId7(asset.caip);
|
|
4978
4986
|
if (!this.pubkeys || this.pubkeys.length === 0) {
|
|
4979
4987
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no pubkeys loaded. Please initialize wallet first.`;
|
|
4980
4988
|
console.error(tag5, errorMsg);
|
|
@@ -5082,7 +5090,7 @@ class SDK {
|
|
|
5082
5090
|
console.log(tag5, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
5083
5091
|
}
|
|
5084
5092
|
const assetBalances = this.balances.filter((b3) => b3.caip === asset.caip);
|
|
5085
|
-
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(
|
|
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")));
|
|
5086
5094
|
const finalAssetContext = {
|
|
5087
5095
|
...assetInfo,
|
|
5088
5096
|
...asset,
|
|
@@ -5142,12 +5150,12 @@ class SDK {
|
|
|
5142
5150
|
}
|
|
5143
5151
|
}
|
|
5144
5152
|
if (asset.caip) {
|
|
5145
|
-
this.blockchainContext =
|
|
5153
|
+
this.blockchainContext = caipToNetworkId7(asset.caip);
|
|
5146
5154
|
} else if (asset.networkId) {
|
|
5147
5155
|
this.blockchainContext = asset.networkId;
|
|
5148
5156
|
}
|
|
5149
5157
|
if (assetPubkeys && assetPubkeys.length > 0) {
|
|
5150
|
-
const networkId =
|
|
5158
|
+
const networkId = caipToNetworkId7(asset.caip || asset.networkId);
|
|
5151
5159
|
const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
|
|
5152
5160
|
if (!this.pubkeyContext || !currentContextValid) {
|
|
5153
5161
|
this.pubkeyContext = assetPubkeys[0];
|
|
@@ -5164,7 +5172,7 @@ class SDK {
|
|
|
5164
5172
|
}
|
|
5165
5173
|
};
|
|
5166
5174
|
this.setPubkeyContext = async function(pubkey) {
|
|
5167
|
-
let tag5 = `${
|
|
5175
|
+
let tag5 = `${TAG8} | setPubkeyContext | `;
|
|
5168
5176
|
try {
|
|
5169
5177
|
if (!pubkey)
|
|
5170
5178
|
throw Error("pubkey is required");
|
|
@@ -5183,7 +5191,7 @@ class SDK {
|
|
|
5183
5191
|
}
|
|
5184
5192
|
};
|
|
5185
5193
|
this.setOutboundAssetContext = async function(asset) {
|
|
5186
|
-
const tag5 = `${
|
|
5194
|
+
const tag5 = `${TAG8} | setOutputAssetContext | `;
|
|
5187
5195
|
try {
|
|
5188
5196
|
console.log(tag5, "0. asset: ", asset);
|
|
5189
5197
|
if (!asset) {
|
|
@@ -5194,7 +5202,7 @@ class SDK {
|
|
|
5194
5202
|
if (!asset.caip)
|
|
5195
5203
|
throw Error("Invalid Asset! missing caip!");
|
|
5196
5204
|
if (!asset.networkId)
|
|
5197
|
-
asset.networkId =
|
|
5205
|
+
asset.networkId = caipToNetworkId7(asset.caip);
|
|
5198
5206
|
console.log(tag5, "networkId: ", asset.networkId);
|
|
5199
5207
|
console.log(tag5, "this.pubkeys: ", this.pubkeys);
|
|
5200
5208
|
const pubkey = this.pubkeys.find((p2) => {
|
|
@@ -5275,7 +5283,7 @@ class SDK {
|
|
|
5275
5283
|
console.log(tag5, "CHECKPOINT 3");
|
|
5276
5284
|
console.log(tag5, "outboundAssetContext: assetInfo: ", assetInfo);
|
|
5277
5285
|
if (asset.caip) {
|
|
5278
|
-
this.outboundBlockchainContext =
|
|
5286
|
+
this.outboundBlockchainContext = caipToNetworkId7(asset.caip);
|
|
5279
5287
|
} else if (asset.networkId) {
|
|
5280
5288
|
this.outboundBlockchainContext = asset.networkId;
|
|
5281
5289
|
}
|