@pioneer-platform/pioneer-sdk 4.20.4 → 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.cjs +146 -138
- package/dist/index.es.js +146 -138
- package/dist/index.js +146 -138
- package/package.json +2 -2
- package/src/index.ts +1 -187
- package/src/index.ts.tmp +0 -2580
- package/src/index.ts.tmp2 +0 -2584
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ var __export = (target, all) => {
|
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
//
|
|
43
|
+
// node_modules/coinselect/utils.js
|
|
44
44
|
var require_utils = __commonJS((exports2, module2) => {
|
|
45
45
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
46
46
|
var TX_INPUT_BASE = 32 + 4 + 1 + 4;
|
|
@@ -113,7 +113,7 @@ var require_utils = __commonJS((exports2, module2) => {
|
|
|
113
113
|
};
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
//
|
|
116
|
+
// node_modules/coinselect/accumulative.js
|
|
117
117
|
var require_accumulative = __commonJS((exports2, module2) => {
|
|
118
118
|
var utils = require_utils();
|
|
119
119
|
module2.exports = function accumulative(utxos, outputs, feeRate) {
|
|
@@ -145,7 +145,7 @@ var require_accumulative = __commonJS((exports2, module2) => {
|
|
|
145
145
|
};
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
//
|
|
148
|
+
// node_modules/coinselect/blackjack.js
|
|
149
149
|
var require_blackjack = __commonJS((exports2, module2) => {
|
|
150
150
|
var utils = require_utils();
|
|
151
151
|
module2.exports = function blackjack(utxos, outputs, feeRate) {
|
|
@@ -174,7 +174,7 @@ var require_blackjack = __commonJS((exports2, module2) => {
|
|
|
174
174
|
};
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
//
|
|
177
|
+
// node_modules/coinselect/index.js
|
|
178
178
|
var require_coinselect = __commonJS((exports2, module2) => {
|
|
179
179
|
var accumulative = require_accumulative();
|
|
180
180
|
var blackjack = require_blackjack();
|
|
@@ -193,7 +193,7 @@ var require_coinselect = __commonJS((exports2, module2) => {
|
|
|
193
193
|
};
|
|
194
194
|
});
|
|
195
195
|
|
|
196
|
-
//
|
|
196
|
+
// node_modules/coinselect/split.js
|
|
197
197
|
var require_split = __commonJS((exports2, module2) => {
|
|
198
198
|
var utils = require_utils();
|
|
199
199
|
module2.exports = function split(utxos, outputs, feeRate) {
|
|
@@ -244,7 +244,7 @@ __export(exports_src, {
|
|
|
244
244
|
});
|
|
245
245
|
module.exports = __toCommonJS(exports_src);
|
|
246
246
|
var import_keepkey_sdk = require("@keepkey/keepkey-sdk");
|
|
247
|
-
var
|
|
247
|
+
var import_pioneer_caip7 = require("@pioneer-platform/pioneer-caip");
|
|
248
248
|
var import_pioneer_client = __toESM(require("@pioneer-platform/pioneer-client"));
|
|
249
249
|
var import_pioneer_coins4 = require("@pioneer-platform/pioneer-coins");
|
|
250
250
|
var import_pioneer_discovery2 = require("@pioneer-platform/pioneer-discovery");
|
|
@@ -590,7 +590,7 @@ var getCharts = async (blockchains, pioneer, pubkeys, context) => {
|
|
|
590
590
|
}
|
|
591
591
|
};
|
|
592
592
|
|
|
593
|
-
//
|
|
593
|
+
// node_modules/@coinmasters/types/dist/index.es.js
|
|
594
594
|
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 || {});
|
|
595
595
|
var b = {
|
|
596
596
|
[n.INVALID_INPUT_PARAMETERS]: "Invalid input parameters: {0}.",
|
|
@@ -3430,8 +3430,7 @@ async function detectKkApiAvailability(forceLocalhost) {
|
|
|
3430
3430
|
}
|
|
3431
3431
|
}
|
|
3432
3432
|
|
|
3433
|
-
// src/
|
|
3434
|
-
var TAG7 = " | Pioneer-sdk | ";
|
|
3433
|
+
// src/utils/format-time.ts
|
|
3435
3434
|
function formatTime(durationMs) {
|
|
3436
3435
|
let seconds = Math.floor(durationMs / 1000 % 60);
|
|
3437
3436
|
let minutes = Math.floor(durationMs / (1000 * 60) % 60);
|
|
@@ -3445,6 +3444,96 @@ function formatTime(durationMs) {
|
|
|
3445
3444
|
return formatted.trim();
|
|
3446
3445
|
}
|
|
3447
3446
|
|
|
3447
|
+
// src/utils/build-dashboard.ts
|
|
3448
|
+
var import_pioneer_caip6 = require("@pioneer-platform/pioneer-caip");
|
|
3449
|
+
var TAG7 = " | build-dashboard | ";
|
|
3450
|
+
function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
3451
|
+
console.log(TAG7, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3452
|
+
const dashboardData = {
|
|
3453
|
+
networks: [],
|
|
3454
|
+
totalValueUsd: 0,
|
|
3455
|
+
networkPercentages: []
|
|
3456
|
+
};
|
|
3457
|
+
let totalPortfolioValue = 0;
|
|
3458
|
+
const networksTemp = [];
|
|
3459
|
+
console.log(TAG7, "balances: ", balances);
|
|
3460
|
+
for (const blockchain of blockchains) {
|
|
3461
|
+
const filteredBalances = balances.filter((b2) => {
|
|
3462
|
+
const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
|
|
3463
|
+
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
3464
|
+
});
|
|
3465
|
+
const balanceMap = new Map;
|
|
3466
|
+
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
3467
|
+
if (isBitcoin) {
|
|
3468
|
+
console.log(TAG7, "Bitcoin network detected - checking for duplicate balances");
|
|
3469
|
+
const bitcoinByValue = new Map;
|
|
3470
|
+
filteredBalances.forEach((balance) => {
|
|
3471
|
+
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
3472
|
+
if (!bitcoinByValue.has(valueKey)) {
|
|
3473
|
+
bitcoinByValue.set(valueKey, []);
|
|
3474
|
+
}
|
|
3475
|
+
bitcoinByValue.get(valueKey).push(balance);
|
|
3476
|
+
});
|
|
3477
|
+
for (const [valueKey, balances2] of bitcoinByValue.entries()) {
|
|
3478
|
+
if (balances2.length === 3 && parseFloat(balances2[0].valueUsd || "0") > 0) {
|
|
3479
|
+
console.log(TAG7, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
3480
|
+
const xpubBalance = balances2.find((b2) => b2.pubkey?.startsWith("xpub")) || balances2[0];
|
|
3481
|
+
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
3482
|
+
balanceMap.set(key, xpubBalance);
|
|
3483
|
+
} else {
|
|
3484
|
+
balances2.forEach((balance) => {
|
|
3485
|
+
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3486
|
+
balanceMap.set(key, balance);
|
|
3487
|
+
});
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
} else {
|
|
3491
|
+
filteredBalances.forEach((balance) => {
|
|
3492
|
+
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3493
|
+
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
3494
|
+
balanceMap.set(key, balance);
|
|
3495
|
+
}
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
const networkBalances = Array.from(balanceMap.values());
|
|
3499
|
+
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
3500
|
+
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
3501
|
+
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
3502
|
+
console.log(TAG7, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
3503
|
+
}
|
|
3504
|
+
return sum + valueUsd;
|
|
3505
|
+
}, 0);
|
|
3506
|
+
const nativeAssetCaip = import_pioneer_caip6.networkIdToCaip(blockchain);
|
|
3507
|
+
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
3508
|
+
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
3509
|
+
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
3510
|
+
return sum + balanceNum;
|
|
3511
|
+
}, 0).toString();
|
|
3512
|
+
const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
|
|
3513
|
+
networksTemp.push({
|
|
3514
|
+
networkId: blockchain,
|
|
3515
|
+
totalValueUsd: networkTotal,
|
|
3516
|
+
gasAssetCaip: nativeAssetCaip || null,
|
|
3517
|
+
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
3518
|
+
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
3519
|
+
color: gasAsset?.color || assetInfo?.color || null,
|
|
3520
|
+
totalNativeBalance
|
|
3521
|
+
});
|
|
3522
|
+
totalPortfolioValue += networkTotal;
|
|
3523
|
+
}
|
|
3524
|
+
dashboardData.networks = networksTemp.sort((a, b2) => b2.totalValueUsd - a.totalValueUsd);
|
|
3525
|
+
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
3526
|
+
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
3527
|
+
networkId: network.networkId,
|
|
3528
|
+
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
3529
|
+
})).filter((entry) => entry.percentage > 0);
|
|
3530
|
+
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
3531
|
+
return dashboardData;
|
|
3532
|
+
}
|
|
3533
|
+
|
|
3534
|
+
// src/index.ts
|
|
3535
|
+
var TAG8 = " | Pioneer-sdk | ";
|
|
3536
|
+
|
|
3448
3537
|
class SDK {
|
|
3449
3538
|
status;
|
|
3450
3539
|
username;
|
|
@@ -3607,7 +3696,7 @@ class SDK {
|
|
|
3607
3696
|
return true;
|
|
3608
3697
|
};
|
|
3609
3698
|
this.setPubkeys = (newPubkeys) => {
|
|
3610
|
-
const tag5 = `${
|
|
3699
|
+
const tag5 = `${TAG8} | setPubkeys | `;
|
|
3611
3700
|
this.pubkeys = [];
|
|
3612
3701
|
this.pubkeySet.clear();
|
|
3613
3702
|
let added = 0;
|
|
@@ -3618,7 +3707,7 @@ class SDK {
|
|
|
3618
3707
|
}
|
|
3619
3708
|
};
|
|
3620
3709
|
this.getUnifiedPortfolio = async function() {
|
|
3621
|
-
const tag5 = `${
|
|
3710
|
+
const tag5 = `${TAG8} | getUnifiedPortfolio | `;
|
|
3622
3711
|
try {
|
|
3623
3712
|
const startTime = performance.now();
|
|
3624
3713
|
try {
|
|
@@ -3726,7 +3815,7 @@ class SDK {
|
|
|
3726
3815
|
}
|
|
3727
3816
|
};
|
|
3728
3817
|
this.init = async function(walletsVerbose, setup) {
|
|
3729
|
-
const tag5 = `${
|
|
3818
|
+
const tag5 = `${TAG8} | init | `;
|
|
3730
3819
|
try {
|
|
3731
3820
|
if (!this.username)
|
|
3732
3821
|
throw Error("username required!");
|
|
@@ -3814,91 +3903,10 @@ class SDK {
|
|
|
3814
3903
|
}
|
|
3815
3904
|
};
|
|
3816
3905
|
this.buildDashboardFromBalances = function() {
|
|
3817
|
-
|
|
3818
|
-
console.log(tag5, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3819
|
-
const dashboardData = {
|
|
3820
|
-
networks: [],
|
|
3821
|
-
totalValueUsd: 0,
|
|
3822
|
-
networkPercentages: []
|
|
3823
|
-
};
|
|
3824
|
-
let totalPortfolioValue = 0;
|
|
3825
|
-
const networksTemp = [];
|
|
3826
|
-
console.log(tag5, "this.balances: ", this.balances);
|
|
3827
|
-
for (const blockchain of this.blockchains) {
|
|
3828
|
-
const filteredBalances = this.balances.filter((b2) => {
|
|
3829
|
-
const networkId = import_pioneer_caip6.caipToNetworkId(b2.caip);
|
|
3830
|
-
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
3831
|
-
});
|
|
3832
|
-
const balanceMap = new Map;
|
|
3833
|
-
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
3834
|
-
if (isBitcoin) {
|
|
3835
|
-
console.log(tag5, "Bitcoin network detected - checking for duplicate balances");
|
|
3836
|
-
const bitcoinByValue = new Map;
|
|
3837
|
-
filteredBalances.forEach((balance) => {
|
|
3838
|
-
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
3839
|
-
if (!bitcoinByValue.has(valueKey)) {
|
|
3840
|
-
bitcoinByValue.set(valueKey, []);
|
|
3841
|
-
}
|
|
3842
|
-
bitcoinByValue.get(valueKey).push(balance);
|
|
3843
|
-
});
|
|
3844
|
-
for (const [valueKey, balances] of bitcoinByValue.entries()) {
|
|
3845
|
-
if (balances.length === 3 && parseFloat(balances[0].valueUsd || "0") > 0) {
|
|
3846
|
-
console.log(tag5, "BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub");
|
|
3847
|
-
const xpubBalance = balances.find((b2) => b2.pubkey?.startsWith("xpub")) || balances[0];
|
|
3848
|
-
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
3849
|
-
balanceMap.set(key, xpubBalance);
|
|
3850
|
-
} else {
|
|
3851
|
-
balances.forEach((balance) => {
|
|
3852
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3853
|
-
balanceMap.set(key, balance);
|
|
3854
|
-
});
|
|
3855
|
-
}
|
|
3856
|
-
}
|
|
3857
|
-
} else {
|
|
3858
|
-
filteredBalances.forEach((balance) => {
|
|
3859
|
-
const key = `${balance.caip}_${balance.pubkey || "default"}`;
|
|
3860
|
-
if (!balanceMap.has(key) || parseFloat(balance.valueUsd || "0") > parseFloat(balanceMap.get(key).valueUsd || "0")) {
|
|
3861
|
-
balanceMap.set(key, balance);
|
|
3862
|
-
}
|
|
3863
|
-
});
|
|
3864
|
-
}
|
|
3865
|
-
const networkBalances = Array.from(balanceMap.values());
|
|
3866
|
-
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
3867
|
-
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
3868
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
3869
|
-
console.log(tag5, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
3870
|
-
}
|
|
3871
|
-
return sum + valueUsd;
|
|
3872
|
-
}, 0);
|
|
3873
|
-
const nativeAssetCaip = import_pioneer_caip6.networkIdToCaip(blockchain);
|
|
3874
|
-
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
3875
|
-
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
3876
|
-
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
3877
|
-
return sum + balanceNum;
|
|
3878
|
-
}, 0).toString();
|
|
3879
|
-
const assetInfo = nativeAssetCaip ? this.assetsMap.get(nativeAssetCaip) : null;
|
|
3880
|
-
networksTemp.push({
|
|
3881
|
-
networkId: blockchain,
|
|
3882
|
-
totalValueUsd: networkTotal,
|
|
3883
|
-
gasAssetCaip: nativeAssetCaip || null,
|
|
3884
|
-
gasAssetSymbol: gasAsset?.ticker || gasAsset?.symbol || assetInfo?.symbol || null,
|
|
3885
|
-
icon: gasAsset?.icon || assetInfo?.icon || null,
|
|
3886
|
-
color: gasAsset?.color || assetInfo?.color || null,
|
|
3887
|
-
totalNativeBalance
|
|
3888
|
-
});
|
|
3889
|
-
totalPortfolioValue += networkTotal;
|
|
3890
|
-
}
|
|
3891
|
-
dashboardData.networks = networksTemp.sort((a, b2) => b2.totalValueUsd - a.totalValueUsd);
|
|
3892
|
-
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
3893
|
-
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
3894
|
-
networkId: network.networkId,
|
|
3895
|
-
percentage: totalPortfolioValue > 0 ? Number((network.totalValueUsd / totalPortfolioValue * 100).toFixed(2)) : 0
|
|
3896
|
-
})).filter((entry) => entry.percentage > 0);
|
|
3897
|
-
console.log(`[FAST DASHBOARD] ✅ Built dashboard: ${dashboardData.networks.length} networks, $${totalPortfolioValue.toFixed(2)} total`);
|
|
3898
|
-
return dashboardData;
|
|
3906
|
+
return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
|
|
3899
3907
|
};
|
|
3900
3908
|
this.syncMarket = async function() {
|
|
3901
|
-
const tag5 = `${
|
|
3909
|
+
const tag5 = `${TAG8} | syncMarket | `;
|
|
3902
3910
|
try {
|
|
3903
3911
|
const invalidBalances = this.balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
3904
3912
|
if (invalidBalances.length > 0) {
|
|
@@ -3949,7 +3957,7 @@ class SDK {
|
|
|
3949
3957
|
}
|
|
3950
3958
|
};
|
|
3951
3959
|
this.sync = async function() {
|
|
3952
|
-
const tag5 = `${
|
|
3960
|
+
const tag5 = `${TAG8} | sync | `;
|
|
3953
3961
|
try {
|
|
3954
3962
|
const matchesNetwork = (item, networkId) => {
|
|
3955
3963
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4004,7 +4012,7 @@ class SDK {
|
|
|
4004
4012
|
console.log(tag5, "uniqueBlockchains: ", uniqueBlockchains);
|
|
4005
4013
|
for (const blockchain of uniqueBlockchains) {
|
|
4006
4014
|
const filteredBalances = this.balances.filter((b2) => {
|
|
4007
|
-
const networkId =
|
|
4015
|
+
const networkId = import_pioneer_caip7.caipToNetworkId(b2.caip);
|
|
4008
4016
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4009
4017
|
});
|
|
4010
4018
|
console.log(tag5, `Filtering for blockchain: ${blockchain}`);
|
|
@@ -4062,7 +4070,7 @@ class SDK {
|
|
|
4062
4070
|
return sum + valueUsd;
|
|
4063
4071
|
}, 0);
|
|
4064
4072
|
console.log("Final networkTotal:", networkTotal);
|
|
4065
|
-
const nativeAssetCaip =
|
|
4073
|
+
const nativeAssetCaip = import_pioneer_caip7.networkIdToCaip(blockchain);
|
|
4066
4074
|
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
4067
4075
|
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4068
4076
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
@@ -4102,7 +4110,7 @@ class SDK {
|
|
|
4102
4110
|
}
|
|
4103
4111
|
};
|
|
4104
4112
|
this.buildTx = async function(sendPayload) {
|
|
4105
|
-
let tag5 =
|
|
4113
|
+
let tag5 = TAG8 + " | buildTx | ";
|
|
4106
4114
|
try {
|
|
4107
4115
|
const transactionDependencies = {
|
|
4108
4116
|
context: this.context,
|
|
@@ -4124,7 +4132,7 @@ class SDK {
|
|
|
4124
4132
|
}
|
|
4125
4133
|
};
|
|
4126
4134
|
this.buildDelegateTx = async function(caip, params) {
|
|
4127
|
-
let tag5 =
|
|
4135
|
+
let tag5 = TAG8 + " | buildDelegateTx | ";
|
|
4128
4136
|
try {
|
|
4129
4137
|
const delegateParams = {
|
|
4130
4138
|
...params,
|
|
@@ -4139,7 +4147,7 @@ class SDK {
|
|
|
4139
4147
|
}
|
|
4140
4148
|
};
|
|
4141
4149
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4142
|
-
let tag5 =
|
|
4150
|
+
let tag5 = TAG8 + " | buildUndelegateTx | ";
|
|
4143
4151
|
try {
|
|
4144
4152
|
const undelegateParams = {
|
|
4145
4153
|
...params,
|
|
@@ -4154,7 +4162,7 @@ class SDK {
|
|
|
4154
4162
|
}
|
|
4155
4163
|
};
|
|
4156
4164
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4157
|
-
let tag5 =
|
|
4165
|
+
let tag5 = TAG8 + " | buildClaimRewardsTx | ";
|
|
4158
4166
|
try {
|
|
4159
4167
|
const claimParams = {
|
|
4160
4168
|
...params,
|
|
@@ -4169,7 +4177,7 @@ class SDK {
|
|
|
4169
4177
|
}
|
|
4170
4178
|
};
|
|
4171
4179
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4172
|
-
let tag5 =
|
|
4180
|
+
let tag5 = TAG8 + " | buildClaimAllRewardsTx | ";
|
|
4173
4181
|
try {
|
|
4174
4182
|
const claimAllParams = {
|
|
4175
4183
|
...params,
|
|
@@ -4183,7 +4191,7 @@ class SDK {
|
|
|
4183
4191
|
}
|
|
4184
4192
|
};
|
|
4185
4193
|
this.signTx = async function(unsignedTx) {
|
|
4186
|
-
let tag5 =
|
|
4194
|
+
let tag5 = TAG8 + " | signTx | ";
|
|
4187
4195
|
try {
|
|
4188
4196
|
const transactionDependencies = {
|
|
4189
4197
|
context: this.context,
|
|
@@ -4204,7 +4212,7 @@ class SDK {
|
|
|
4204
4212
|
}
|
|
4205
4213
|
};
|
|
4206
4214
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4207
|
-
let tag5 =
|
|
4215
|
+
let tag5 = TAG8 + " | broadcastTx | ";
|
|
4208
4216
|
try {
|
|
4209
4217
|
const transactionDependencies = {
|
|
4210
4218
|
context: this.context,
|
|
@@ -4217,7 +4225,7 @@ class SDK {
|
|
|
4217
4225
|
};
|
|
4218
4226
|
let txManager = new TransactionManager(transactionDependencies, this.events);
|
|
4219
4227
|
let payload = {
|
|
4220
|
-
networkId:
|
|
4228
|
+
networkId: import_pioneer_caip7.caipToNetworkId(caip),
|
|
4221
4229
|
serialized: signedTx
|
|
4222
4230
|
};
|
|
4223
4231
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4228,7 +4236,7 @@ class SDK {
|
|
|
4228
4236
|
}
|
|
4229
4237
|
};
|
|
4230
4238
|
this.swap = async function(swapPayload) {
|
|
4231
|
-
let tag5 = `${
|
|
4239
|
+
let tag5 = `${TAG8} | swap | `;
|
|
4232
4240
|
try {
|
|
4233
4241
|
if (!swapPayload)
|
|
4234
4242
|
throw Error("swapPayload required!");
|
|
@@ -4363,7 +4371,7 @@ class SDK {
|
|
|
4363
4371
|
}
|
|
4364
4372
|
};
|
|
4365
4373
|
this.transfer = async function(sendPayload) {
|
|
4366
|
-
let tag5 = `${
|
|
4374
|
+
let tag5 = `${TAG8} | transfer | `;
|
|
4367
4375
|
try {
|
|
4368
4376
|
if (!sendPayload)
|
|
4369
4377
|
throw Error("sendPayload required!");
|
|
@@ -4390,7 +4398,7 @@ class SDK {
|
|
|
4390
4398
|
if (!signedTx)
|
|
4391
4399
|
throw Error("Failed to sign transaction!");
|
|
4392
4400
|
let payload = {
|
|
4393
|
-
networkId:
|
|
4401
|
+
networkId: import_pioneer_caip7.caipToNetworkId(caip),
|
|
4394
4402
|
serialized: signedTx
|
|
4395
4403
|
};
|
|
4396
4404
|
let txid = await txManager.broadcast(payload);
|
|
@@ -4419,7 +4427,7 @@ class SDK {
|
|
|
4419
4427
|
while (!isConfirmed) {
|
|
4420
4428
|
try {
|
|
4421
4429
|
const response = await this.pioneer.LookupTx({
|
|
4422
|
-
networkId:
|
|
4430
|
+
networkId: import_pioneer_caip7.caipToNetworkId(caip),
|
|
4423
4431
|
txid
|
|
4424
4432
|
});
|
|
4425
4433
|
if (response?.data?.data) {
|
|
@@ -4458,7 +4466,7 @@ class SDK {
|
|
|
4458
4466
|
}
|
|
4459
4467
|
};
|
|
4460
4468
|
this.setBlockchains = async function(blockchains) {
|
|
4461
|
-
const tag5 = `${
|
|
4469
|
+
const tag5 = `${TAG8} | setBlockchains | `;
|
|
4462
4470
|
try {
|
|
4463
4471
|
if (!blockchains)
|
|
4464
4472
|
throw Error("blockchains required!");
|
|
@@ -4474,7 +4482,7 @@ class SDK {
|
|
|
4474
4482
|
}
|
|
4475
4483
|
};
|
|
4476
4484
|
this.addAsset = async function(caip, data) {
|
|
4477
|
-
let tag5 =
|
|
4485
|
+
let tag5 = TAG8 + " | addAsset | ";
|
|
4478
4486
|
try {
|
|
4479
4487
|
let success = false;
|
|
4480
4488
|
if (!caip)
|
|
@@ -4512,7 +4520,7 @@ class SDK {
|
|
|
4512
4520
|
}
|
|
4513
4521
|
};
|
|
4514
4522
|
this.clearWalletState = async function() {
|
|
4515
|
-
const tag5 = `${
|
|
4523
|
+
const tag5 = `${TAG8} | clearWalletState | `;
|
|
4516
4524
|
try {
|
|
4517
4525
|
this.context = null;
|
|
4518
4526
|
this.paths = [];
|
|
@@ -4527,7 +4535,7 @@ class SDK {
|
|
|
4527
4535
|
}
|
|
4528
4536
|
};
|
|
4529
4537
|
this.addPath = async function(path) {
|
|
4530
|
-
const tag5 = `${
|
|
4538
|
+
const tag5 = `${TAG8} | addPath | `;
|
|
4531
4539
|
try {
|
|
4532
4540
|
this.paths.push(path);
|
|
4533
4541
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -4541,7 +4549,7 @@ class SDK {
|
|
|
4541
4549
|
}
|
|
4542
4550
|
};
|
|
4543
4551
|
this.addPaths = async function(paths) {
|
|
4544
|
-
const tag5 = `${
|
|
4552
|
+
const tag5 = `${TAG8} | addPaths | `;
|
|
4545
4553
|
try {
|
|
4546
4554
|
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4547
4555
|
this.paths.push(...paths);
|
|
@@ -4577,11 +4585,11 @@ class SDK {
|
|
|
4577
4585
|
return this.getGasAssets();
|
|
4578
4586
|
};
|
|
4579
4587
|
this.getGasAssets = async function() {
|
|
4580
|
-
const tag5 = `${
|
|
4588
|
+
const tag5 = `${TAG8} | getGasAssets | `;
|
|
4581
4589
|
try {
|
|
4582
4590
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4583
4591
|
let networkId = this.blockchains[i];
|
|
4584
|
-
let caip =
|
|
4592
|
+
let caip = import_pioneer_caip7.networkIdToCaip(networkId);
|
|
4585
4593
|
let asset = await import_pioneer_discovery2.assetData[caip.toLowerCase()];
|
|
4586
4594
|
if (asset) {
|
|
4587
4595
|
asset.caip = caip.toLowerCase();
|
|
@@ -4620,7 +4628,7 @@ class SDK {
|
|
|
4620
4628
|
}
|
|
4621
4629
|
};
|
|
4622
4630
|
this.getPubkeys = async function() {
|
|
4623
|
-
const tag5 = `${
|
|
4631
|
+
const tag5 = `${TAG8} | getPubkeys | `;
|
|
4624
4632
|
try {
|
|
4625
4633
|
if (this.paths.length === 0)
|
|
4626
4634
|
throw new Error("No paths found!");
|
|
@@ -4641,7 +4649,7 @@ class SDK {
|
|
|
4641
4649
|
}
|
|
4642
4650
|
};
|
|
4643
4651
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4644
|
-
const tag5 = `${
|
|
4652
|
+
const tag5 = `${TAG8} | getBalancesForNetworks | `;
|
|
4645
4653
|
try {
|
|
4646
4654
|
if (!this.pioneer) {
|
|
4647
4655
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -4659,7 +4667,7 @@ class SDK {
|
|
|
4659
4667
|
return network.startsWith("eip155:");
|
|
4660
4668
|
return network === adjustedNetworkId;
|
|
4661
4669
|
}));
|
|
4662
|
-
const caipNative = await
|
|
4670
|
+
const caipNative = await import_pioneer_caip7.networkIdToCaip(networkId);
|
|
4663
4671
|
for (const pubkey of pubkeys) {
|
|
4664
4672
|
assetQuery.push({ caip: caipNative, pubkey: pubkey.pubkey });
|
|
4665
4673
|
}
|
|
@@ -4677,7 +4685,7 @@ class SDK {
|
|
|
4677
4685
|
if (!assetInfo)
|
|
4678
4686
|
continue;
|
|
4679
4687
|
Object.assign(balance, assetInfo, {
|
|
4680
|
-
networkId:
|
|
4688
|
+
networkId: import_pioneer_caip7.caipToNetworkId(balance.caip),
|
|
4681
4689
|
icon: assetInfo.icon || "https://pioneers.dev/coins/etherum.png",
|
|
4682
4690
|
identifier: `${balance.caip}:${balance.pubkey}`
|
|
4683
4691
|
});
|
|
@@ -4696,7 +4704,7 @@ class SDK {
|
|
|
4696
4704
|
}
|
|
4697
4705
|
};
|
|
4698
4706
|
this.getBalances = async function() {
|
|
4699
|
-
const tag5 = `${
|
|
4707
|
+
const tag5 = `${TAG8} | getBalances | `;
|
|
4700
4708
|
try {
|
|
4701
4709
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4702
4710
|
} catch (e) {
|
|
@@ -4705,10 +4713,10 @@ class SDK {
|
|
|
4705
4713
|
}
|
|
4706
4714
|
};
|
|
4707
4715
|
this.getBalance = async function(networkId) {
|
|
4708
|
-
const tag5 = `${
|
|
4716
|
+
const tag5 = `${TAG8} | getBalance | `;
|
|
4709
4717
|
try {
|
|
4710
4718
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4711
|
-
const filtered = results.filter(async (b2) => b2.networkId === await
|
|
4719
|
+
const filtered = results.filter(async (b2) => b2.networkId === await import_pioneer_caip7.networkIdToCaip(networkId));
|
|
4712
4720
|
return filtered;
|
|
4713
4721
|
} catch (e) {
|
|
4714
4722
|
console.error(tag5, "Error: ", e);
|
|
@@ -4716,7 +4724,7 @@ class SDK {
|
|
|
4716
4724
|
}
|
|
4717
4725
|
};
|
|
4718
4726
|
this.getFees = async function(networkId) {
|
|
4719
|
-
const tag5 = `${
|
|
4727
|
+
const tag5 = `${TAG8} | getFees | `;
|
|
4720
4728
|
try {
|
|
4721
4729
|
if (!this.pioneer) {
|
|
4722
4730
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -4731,7 +4739,7 @@ class SDK {
|
|
|
4731
4739
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
4732
4740
|
};
|
|
4733
4741
|
this.getCharts = async function() {
|
|
4734
|
-
const tag5 = `${
|
|
4742
|
+
const tag5 = `${TAG8} | getCharts | `;
|
|
4735
4743
|
try {
|
|
4736
4744
|
console.log(tag5, "Fetching charts");
|
|
4737
4745
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -4753,7 +4761,7 @@ class SDK {
|
|
|
4753
4761
|
}
|
|
4754
4762
|
};
|
|
4755
4763
|
this.setContext = async (context) => {
|
|
4756
|
-
const tag5 = `${
|
|
4764
|
+
const tag5 = `${TAG8} | setContext | `;
|
|
4757
4765
|
try {
|
|
4758
4766
|
if (!context)
|
|
4759
4767
|
throw Error("context required!");
|
|
@@ -4766,7 +4774,7 @@ class SDK {
|
|
|
4766
4774
|
}
|
|
4767
4775
|
};
|
|
4768
4776
|
this.setContextType = async (contextType) => {
|
|
4769
|
-
const tag5 = `${
|
|
4777
|
+
const tag5 = `${TAG8} | setContextType | `;
|
|
4770
4778
|
try {
|
|
4771
4779
|
if (!contextType)
|
|
4772
4780
|
throw Error("contextType required!");
|
|
@@ -4779,7 +4787,7 @@ class SDK {
|
|
|
4779
4787
|
}
|
|
4780
4788
|
};
|
|
4781
4789
|
this.refresh = async () => {
|
|
4782
|
-
const tag5 = `${
|
|
4790
|
+
const tag5 = `${TAG8} | refresh | `;
|
|
4783
4791
|
try {
|
|
4784
4792
|
await this.sync();
|
|
4785
4793
|
return this.balances;
|
|
@@ -4789,7 +4797,7 @@ class SDK {
|
|
|
4789
4797
|
}
|
|
4790
4798
|
};
|
|
4791
4799
|
this.setAssetContext = async function(asset) {
|
|
4792
|
-
const tag5 = `${
|
|
4800
|
+
const tag5 = `${TAG8} | setAssetContext | `;
|
|
4793
4801
|
try {
|
|
4794
4802
|
if (!asset) {
|
|
4795
4803
|
this.assetContext = null;
|
|
@@ -4798,7 +4806,7 @@ class SDK {
|
|
|
4798
4806
|
if (!asset.caip)
|
|
4799
4807
|
throw Error("Invalid Asset! missing caip!");
|
|
4800
4808
|
if (!asset.networkId)
|
|
4801
|
-
asset.networkId =
|
|
4809
|
+
asset.networkId = import_pioneer_caip7.caipToNetworkId(asset.caip);
|
|
4802
4810
|
if (!this.pubkeys || this.pubkeys.length === 0) {
|
|
4803
4811
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no pubkeys loaded. Please initialize wallet first.`;
|
|
4804
4812
|
console.error(tag5, errorMsg);
|
|
@@ -4906,7 +4914,7 @@ class SDK {
|
|
|
4906
4914
|
console.log(tag5, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
4907
4915
|
}
|
|
4908
4916
|
const assetBalances = this.balances.filter((b2) => b2.caip === asset.caip);
|
|
4909
|
-
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(
|
|
4917
|
+
const assetPubkeys = this.pubkeys.filter((p2) => p2.networks && Array.isArray(p2.networks) && p2.networks.includes(import_pioneer_caip7.caipToNetworkId(asset.caip)) || import_pioneer_caip7.caipToNetworkId(asset.caip).includes("eip155") && p2.networks && Array.isArray(p2.networks) && p2.networks.some((n2) => n2.startsWith("eip155")));
|
|
4910
4918
|
const finalAssetContext = {
|
|
4911
4919
|
...assetInfo,
|
|
4912
4920
|
...asset,
|
|
@@ -4966,12 +4974,12 @@ class SDK {
|
|
|
4966
4974
|
}
|
|
4967
4975
|
}
|
|
4968
4976
|
if (asset.caip) {
|
|
4969
|
-
this.blockchainContext =
|
|
4977
|
+
this.blockchainContext = import_pioneer_caip7.caipToNetworkId(asset.caip);
|
|
4970
4978
|
} else if (asset.networkId) {
|
|
4971
4979
|
this.blockchainContext = asset.networkId;
|
|
4972
4980
|
}
|
|
4973
4981
|
if (assetPubkeys && assetPubkeys.length > 0) {
|
|
4974
|
-
const networkId =
|
|
4982
|
+
const networkId = import_pioneer_caip7.caipToNetworkId(asset.caip || asset.networkId);
|
|
4975
4983
|
const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
|
|
4976
4984
|
if (!this.pubkeyContext || !currentContextValid) {
|
|
4977
4985
|
this.pubkeyContext = assetPubkeys[0];
|
|
@@ -4988,7 +4996,7 @@ class SDK {
|
|
|
4988
4996
|
}
|
|
4989
4997
|
};
|
|
4990
4998
|
this.setPubkeyContext = async function(pubkey) {
|
|
4991
|
-
let tag5 = `${
|
|
4999
|
+
let tag5 = `${TAG8} | setPubkeyContext | `;
|
|
4992
5000
|
try {
|
|
4993
5001
|
if (!pubkey)
|
|
4994
5002
|
throw Error("pubkey is required");
|
|
@@ -5007,7 +5015,7 @@ class SDK {
|
|
|
5007
5015
|
}
|
|
5008
5016
|
};
|
|
5009
5017
|
this.setOutboundAssetContext = async function(asset) {
|
|
5010
|
-
const tag5 = `${
|
|
5018
|
+
const tag5 = `${TAG8} | setOutputAssetContext | `;
|
|
5011
5019
|
try {
|
|
5012
5020
|
console.log(tag5, "0. asset: ", asset);
|
|
5013
5021
|
if (!asset) {
|
|
@@ -5018,7 +5026,7 @@ class SDK {
|
|
|
5018
5026
|
if (!asset.caip)
|
|
5019
5027
|
throw Error("Invalid Asset! missing caip!");
|
|
5020
5028
|
if (!asset.networkId)
|
|
5021
|
-
asset.networkId =
|
|
5029
|
+
asset.networkId = import_pioneer_caip7.caipToNetworkId(asset.caip);
|
|
5022
5030
|
console.log(tag5, "networkId: ", asset.networkId);
|
|
5023
5031
|
console.log(tag5, "this.pubkeys: ", this.pubkeys);
|
|
5024
5032
|
const pubkey = this.pubkeys.find((p2) => {
|
|
@@ -5099,7 +5107,7 @@ class SDK {
|
|
|
5099
5107
|
console.log(tag5, "CHECKPOINT 3");
|
|
5100
5108
|
console.log(tag5, "outboundAssetContext: assetInfo: ", assetInfo);
|
|
5101
5109
|
if (asset.caip) {
|
|
5102
|
-
this.outboundBlockchainContext =
|
|
5110
|
+
this.outboundBlockchainContext = import_pioneer_caip7.caipToNetworkId(asset.caip);
|
|
5103
5111
|
} else if (asset.networkId) {
|
|
5104
5112
|
this.outboundBlockchainContext = asset.networkId;
|
|
5105
5113
|
}
|