@pioneer-platform/pioneer-sdk 4.21.11 → 4.21.13
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 +123 -348
- package/dist/index.es.js +99 -324
- package/dist/index.js +99 -324
- package/package.json +5 -5
- package/src/TransactionManager.ts +27 -2
- package/src/fees/index.ts +1 -1
- package/src/getPubkey.ts +2 -2
- package/src/index.ts +1 -56
- package/src/utils/build-dashboard.ts +0 -32
- package/src/utils/sync-portfolio.ts +8 -3
package/dist/index.es.js
CHANGED
|
@@ -166,8 +166,8 @@ var require_coinselect = __commonJS((exports, module) => {
|
|
|
166
166
|
return x2.value - feeRate * utils.inputBytes(x2);
|
|
167
167
|
}
|
|
168
168
|
module.exports = function coinSelect(utxos, outputs, feeRate) {
|
|
169
|
-
utxos = utxos.concat().sort(function(a2,
|
|
170
|
-
return utxoScore(
|
|
169
|
+
utxos = utxos.concat().sort(function(a2, b2) {
|
|
170
|
+
return utxoScore(b2, feeRate) - utxoScore(a2, feeRate);
|
|
171
171
|
});
|
|
172
172
|
var base = blackjack(utxos, outputs, feeRate);
|
|
173
173
|
if (base.inputs)
|
|
@@ -1027,216 +1027,8 @@ var getCharts = async (blockchains, pioneer, pubkeys, context) => {
|
|
|
1027
1027
|
}
|
|
1028
1028
|
};
|
|
1029
1029
|
|
|
1030
|
-
// ../../../node_modules/@coinmasters/types/dist/index.es.js
|
|
1031
|
-
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 || {});
|
|
1032
|
-
var b2 = {
|
|
1033
|
-
[n.INVALID_INPUT_PARAMETERS]: "Invalid input parameters: {0}.",
|
|
1034
|
-
[n.UNKNOWN_PROVIDERS]: "Unknown providers: {0}.",
|
|
1035
|
-
[n.CANNOT_FIND_INBOUND_ADDRESS]: "Cannot find inbound address.",
|
|
1036
|
-
[n.NO_INBOUND_ADDRESSES]: "No inbound addresses.",
|
|
1037
|
-
[n.CHAIN_HALTED_OR_UNSUPPORTED]: "Chain {0} halted or unsupported.",
|
|
1038
|
-
[n.MISSING_INPUT_PARAMETER]: "Missing input parameter: {0}.",
|
|
1039
|
-
[n.INVALID_TYPE_GENERIC]: "Invalid type",
|
|
1040
|
-
[n.INVALID_NUMBER_STRING]: "Invalid number string.",
|
|
1041
|
-
[n.INVALID_NUMBER]: "Invalid number.",
|
|
1042
|
-
[n.INVALID_BOOLEAN]: "Invalid boolean.",
|
|
1043
|
-
[n.INVALID_OBJECT]: "Invalid object.",
|
|
1044
|
-
[n.INVALID_ARRAY]: "Invalid array.",
|
|
1045
|
-
[n.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER]: "Sell amount must be a positive integer.",
|
|
1046
|
-
[n.SELL_BUY_ASSETS_ARE_THE_SAME]: "Sell and buy assets are the same.",
|
|
1047
|
-
[n.MISSING_SOURCE_ADDRESS_FOR_SYNTH]: "Source address is required for synth quote.",
|
|
1048
|
-
[n.AFF_ADDRESS_AND_BPS_OR_NEITHER]: "Must provide affiliateAddress and affiliateBasisPoints params, or neither.",
|
|
1049
|
-
[n.AFF_ADDRESS_TOO_LONG]: "affiliateAddress too long: 3 characters max.",
|
|
1050
|
-
[n.AFF_BPS_INTEGER_0_100]: "affiliateBasisPoints must be an integer between 0 and 100.",
|
|
1051
|
-
[n.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN]: "Source address {0} invalid for sell chain.",
|
|
1052
|
-
[n.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN]: "Destination address {0} invalid for buy chain.",
|
|
1053
|
-
[n.PREFERRED_PROFVIDER_NOT_SUPPORTED]: "Preferred provider not supported.",
|
|
1054
|
-
[n.DESTINATION_ADDRESS_SMART_CONTRACT]: "Destination address is a smart contract.",
|
|
1055
|
-
[n.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER]: "Buy amount must be a positive integer.",
|
|
1056
|
-
[n.INVALID_PROVIDER]: "Invalid provider {0}.",
|
|
1057
|
-
[n.MISSING_CROSS_CHAIN_PROVIDER]: "Missing cross-chain provider.",
|
|
1058
|
-
[n.MISSING_AVAX_PROVIDER]: "Missing AVAX provider.",
|
|
1059
|
-
[n.MISSING_BSC_PROVIDER]: "Missing BSC provider.",
|
|
1060
|
-
[n.MISSING_ETH_PROVIDER]: "Missing ETH provider.",
|
|
1061
|
-
[n.MISSING_ARB_PROVIDER]: "Missing ARB provider.",
|
|
1062
|
-
[n.INVALID_PROVIDER_FOR_SWAP_OUT]: "Invalid provider for swap out.",
|
|
1063
|
-
[n.INVALID_CHAIN]: "Invalid chain {0}.",
|
|
1064
|
-
[n.INVALID_ASSET]: "Invalid asset {0}.",
|
|
1065
|
-
[n.UNSUPPORTED_CHAIN]: "Unsupported chain {0}.",
|
|
1066
|
-
[n.UNSUPPORTED_ASSET]: "Unsupported asset {0}.",
|
|
1067
|
-
[n.UNSUPPORTED_ASSET_FOR_SWAPOUT]: "Unsupported asset {0} for swap out.",
|
|
1068
|
-
[n.THORNODE_QUOTE_GENERIC_ERROR]: "ThorNode quote generic error.",
|
|
1069
|
-
[n.INVALID_SOURCE_ADDRESS]: "Invalid source address {0}",
|
|
1070
|
-
[n.INVALID_DESTINATION_ADDRESS]: "Invalid destination address {0}",
|
|
1071
|
-
[n.NOT_ENOUGH_SYNTH_BALANCE]: "Source address doesn't have enough synth balance for this quote.",
|
|
1072
|
-
[n.SYNTH_MINTING_CAP_REACHED]: "Synth minting cap reached.",
|
|
1073
|
-
[n.INVALID_QUOTE_MODE]: "Invalid quote mode.",
|
|
1074
|
-
[n.NO_QUOTES]: "No quotes to service this request.",
|
|
1075
|
-
[n.SERVICE_UNAVAILABLE_GENERIC]: "Service unavailable.",
|
|
1076
|
-
[n.MISSING_GAS_DATA_GENERIC]: "Missing gas data.",
|
|
1077
|
-
[n.MISSING_TOKEN_INFO_GENERIC]: "Missing token info.",
|
|
1078
|
-
[n.CANT_FIND_TOKEN_LIST]: "Can't find tokenlist {0}.",
|
|
1079
|
-
[n.NO_PRICE]: "No price for asset {0}.",
|
|
1080
|
-
[n.PRICE_IS_STALE]: "Price is stale for asset {0}.",
|
|
1081
|
-
[n.ADDRESS_NOT_WHITELISTED]: "Address {0} not whitelisted for airdrop.",
|
|
1082
|
-
[n.ADDRESS_ALREADY_CLAIMED]: "Address {0} already claimed the airdrop."
|
|
1083
|
-
};
|
|
1084
|
-
var t = /* @__PURE__ */ ((e) => (e.Arbitrum = "ARB", e.Avalanche = "AVAX", e.Base = "BASE", e.BinanceSmartChain = "BSC", e.Bitcoin = "BTC", e.BitcoinCash = "BCH", e.Cosmos = "GAIA", e.Dash = "DASH", e.Digibyte = "DGB", e.Dogecoin = "DOGE", e.EOS = "EOS", e.Ethereum = "ETH", e.Kujira = "KUJI", e.Litecoin = "LTC", e.Mayachain = "MAYA", e.Optimism = "OP", e.Osmosis = "OSMO", e.Polygon = "MATIC", e.Ripple = "XRP", e.THORChain = "THOR", e.Zcash = "ZEC", e))(t || {});
|
|
1085
|
-
var H = {
|
|
1086
|
-
ARB: "eip155:42161",
|
|
1087
|
-
AVAX: "eip155:43114",
|
|
1088
|
-
BSC: "eip155:56",
|
|
1089
|
-
BCH: "bip122:000000000000000000651ef99cb9fcbe",
|
|
1090
|
-
BTC: "bip122:000000000019d6689c085ae165831e93",
|
|
1091
|
-
BASE: "eip155:8453",
|
|
1092
|
-
GAIA: "cosmos:cosmoshub-4",
|
|
1093
|
-
DASH: "bip122:000007d91d1254d60e2dd1ae58038307",
|
|
1094
|
-
DGB: "bip122:digibytes-hash",
|
|
1095
|
-
DOGE: "bip122:00000000001a91e3dace36e2be3bf030",
|
|
1096
|
-
KUJI: "cosmos:kaiyo-1",
|
|
1097
|
-
EOS: "eos:cf057bbfb72640471fd910bcb67639c2",
|
|
1098
|
-
ETH: "eip155:1",
|
|
1099
|
-
LTC: "bip122:12a765e31ffd4059bada1e25190f6e98",
|
|
1100
|
-
MAYA: "cosmos:mayachain-mainnet-v1",
|
|
1101
|
-
OP: "eip155:10",
|
|
1102
|
-
OSMO: "cosmos:osmosis-1",
|
|
1103
|
-
MATIC: "eip155:137",
|
|
1104
|
-
XRP: "ripple:4109c6f2045fc7eff4cde8f9905d19c2",
|
|
1105
|
-
THOR: "cosmos:thorchain-mainnet-v1",
|
|
1106
|
-
ZEC: "bip122:0000000000196a45"
|
|
1107
|
-
};
|
|
1108
|
-
var V = {};
|
|
1109
|
-
for (const e in t) {
|
|
1110
|
-
const a2 = H[t[e]];
|
|
1111
|
-
V[a2] = t[e];
|
|
1112
|
-
}
|
|
1113
|
-
var p = [
|
|
1114
|
-
"ETH"
|
|
1115
|
-
];
|
|
1116
|
-
var T = /* @__PURE__ */ ((e) => (e.Arbitrum = "42161", e.ArbitrumHex = "0xa4b1", e.Avalanche = "43114", e.AvalancheHex = "0xa86a", e.Base = "8453", e.BinanceSmartChain = "56", e.BinanceSmartChainHex = "0x38", e.Bitcoin = "bitcoin", e.BitcoinCash = "bitcoincash", e.Cosmos = "cosmoshub-4", e.Dash = "dash", e.Dogecoin = "dogecoin", e.Kujira = "kaiyo-1", e.Ethereum = "1", e.EthereumHex = "0x1", e.Litecoin = "litecoin", e.Mayachain = "mayachain-mainnet-v1", e.MayaStagenet = "mayachain-stagenet-v1", e.Optimism = "10", e.OptimismHex = "0xa", e.Osmosis = "osmosis-1", e.Polygon = "137", e.PolygonHex = "0x89", e.THORChain = "thorchain-mainnet-v1", e.THORChainStagenet = "thorchain-stagenet-v2", e))(T || {});
|
|
1117
|
-
var E = /* @__PURE__ */ ((e) => (e.Arbitrum = "https://arb1.arbitrum.io/rpc", e.Avalanche = "https://avalanche-c-chain-rpc.publicnode.com", e.BinanceSmartChain = "https://binance.llamarpc.com", e.Base = "https://developer-access-mainnet.base.org", e.Bitcoin = "https://node-router.thorswap.net/bitcoin", e.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", e.Cosmos = "https://api.cosmos.shapeshift.com", e.Kujira = "https://rpc-kujira.synergynodes.com/", e.Dash = "https://dash.nownodes.io", e.Dogecoin = "https://node-router.thorswap.net/dogecoin", e.Ethereum = "https://daemon.ethereum.shapeshift.com", e.Litecoin = "https://node-router.thorswap.net/litecoin", e.Mayachain = "https://mayanode.mayachain.info", e.MayaStagenet = "https://stagenet.tendermint.mayachain.info", e.Optimism = "https://mainnet.optimism.io", e.Osmosis = "https://lcd-osmosis.keplr.app", e.Polygon = "https://polygon-rpc.com", e.Ripple = "https://xrplcluster.com", e.THORChain = "https://thornode.ninerealms.com", e.THORChainStagenet = "https://thornode.ninerealms.com", e))(E || {});
|
|
1118
|
-
var d2 = Object.values(t);
|
|
1119
|
-
var M = Object.keys(t);
|
|
1120
|
-
var m2 = d2.reduce((e, a2) => {
|
|
1121
|
-
const s = M.find((r) => t[r] === a2);
|
|
1122
|
-
return s && (e[a2] = s), e;
|
|
1123
|
-
}, {});
|
|
1124
|
-
var Q = d2.reduce((e, a2) => (e[a2] = T[m2[a2]], e), {});
|
|
1125
|
-
var ee = d2.reduce((e, a2) => (e[a2] = E[m2[a2]], e), {});
|
|
1126
|
-
var te = d2.reduce((e, a2) => {
|
|
1127
|
-
const s = `${m2[a2]}Hex`;
|
|
1128
|
-
return e[a2] = T[s], e;
|
|
1129
|
-
}, {});
|
|
1130
|
-
var X = [
|
|
1131
|
-
t.Arbitrum,
|
|
1132
|
-
t.Avalanche,
|
|
1133
|
-
t.BinanceSmartChain,
|
|
1134
|
-
t.Bitcoin,
|
|
1135
|
-
t.BitcoinCash,
|
|
1136
|
-
t.Cosmos,
|
|
1137
|
-
t.Osmosis,
|
|
1138
|
-
t.Ripple,
|
|
1139
|
-
t.Dogecoin,
|
|
1140
|
-
t.Dash,
|
|
1141
|
-
t.Ethereum,
|
|
1142
|
-
t.Litecoin,
|
|
1143
|
-
t.Optimism,
|
|
1144
|
-
t.Polygon,
|
|
1145
|
-
t.THORChain
|
|
1146
|
-
];
|
|
1147
|
-
var se = {
|
|
1148
|
-
BRAVE: p,
|
|
1149
|
-
COINBASE_WEB: p,
|
|
1150
|
-
KEPLR: [t.Cosmos],
|
|
1151
|
-
KEYSTORE: [
|
|
1152
|
-
t.Arbitrum,
|
|
1153
|
-
t.Base,
|
|
1154
|
-
t.Avalanche,
|
|
1155
|
-
t.BinanceSmartChain,
|
|
1156
|
-
t.Bitcoin,
|
|
1157
|
-
t.BitcoinCash,
|
|
1158
|
-
t.Cosmos,
|
|
1159
|
-
t.Dogecoin,
|
|
1160
|
-
t.Ethereum,
|
|
1161
|
-
t.Litecoin,
|
|
1162
|
-
t.Optimism,
|
|
1163
|
-
t.Polygon,
|
|
1164
|
-
t.THORChain
|
|
1165
|
-
],
|
|
1166
|
-
LEDGER: X,
|
|
1167
|
-
TREZOR: [
|
|
1168
|
-
t.Bitcoin,
|
|
1169
|
-
t.BitcoinCash,
|
|
1170
|
-
t.Litecoin,
|
|
1171
|
-
t.Dogecoin,
|
|
1172
|
-
t.Ethereum
|
|
1173
|
-
],
|
|
1174
|
-
KEEPKEY: [
|
|
1175
|
-
t.Arbitrum,
|
|
1176
|
-
t.Avalanche,
|
|
1177
|
-
t.Base,
|
|
1178
|
-
t.BinanceSmartChain,
|
|
1179
|
-
t.Bitcoin,
|
|
1180
|
-
t.BitcoinCash,
|
|
1181
|
-
t.Cosmos,
|
|
1182
|
-
t.Osmosis,
|
|
1183
|
-
t.Ripple,
|
|
1184
|
-
t.Dogecoin,
|
|
1185
|
-
t.Dash,
|
|
1186
|
-
t.Mayachain,
|
|
1187
|
-
t.Ethereum,
|
|
1188
|
-
t.Litecoin,
|
|
1189
|
-
t.Optimism,
|
|
1190
|
-
t.Polygon,
|
|
1191
|
-
t.THORChain
|
|
1192
|
-
],
|
|
1193
|
-
METAMASK_SHAPESHIFT: [
|
|
1194
|
-
t.Arbitrum,
|
|
1195
|
-
t.Avalanche,
|
|
1196
|
-
t.BinanceSmartChain,
|
|
1197
|
-
t.Bitcoin,
|
|
1198
|
-
t.BitcoinCash,
|
|
1199
|
-
t.Cosmos,
|
|
1200
|
-
t.Dogecoin,
|
|
1201
|
-
t.Ethereum,
|
|
1202
|
-
t.Litecoin,
|
|
1203
|
-
t.Optimism,
|
|
1204
|
-
t.Polygon,
|
|
1205
|
-
t.THORChain
|
|
1206
|
-
],
|
|
1207
|
-
METAMASK: p,
|
|
1208
|
-
TRUSTWALLET_WEB: p,
|
|
1209
|
-
XDEFI: [
|
|
1210
|
-
t.Arbitrum,
|
|
1211
|
-
t.Avalanche,
|
|
1212
|
-
t.BinanceSmartChain,
|
|
1213
|
-
t.Bitcoin,
|
|
1214
|
-
t.BitcoinCash,
|
|
1215
|
-
t.Cosmos,
|
|
1216
|
-
t.Ripple,
|
|
1217
|
-
t.Dogecoin,
|
|
1218
|
-
t.Ethereum,
|
|
1219
|
-
t.Litecoin,
|
|
1220
|
-
t.Optimism,
|
|
1221
|
-
t.Polygon,
|
|
1222
|
-
t.THORChain
|
|
1223
|
-
],
|
|
1224
|
-
WALLETCONNECT: [
|
|
1225
|
-
t.Ethereum
|
|
1226
|
-
],
|
|
1227
|
-
OKX: [
|
|
1228
|
-
t.Ethereum,
|
|
1229
|
-
t.Avalanche,
|
|
1230
|
-
t.BinanceSmartChain,
|
|
1231
|
-
t.Bitcoin,
|
|
1232
|
-
t.Cosmos
|
|
1233
|
-
]
|
|
1234
|
-
};
|
|
1235
|
-
var ie = {
|
|
1236
|
-
KEEPKEY: [t.Bitcoin, t.Ethereum, t.Base]
|
|
1237
|
-
};
|
|
1238
|
-
|
|
1239
1030
|
// src/getPubkey.ts
|
|
1031
|
+
import { NetworkIdToChain } from "@pioneer-platform/pioneer-caip";
|
|
1240
1032
|
import {
|
|
1241
1033
|
addressNListToBIP32,
|
|
1242
1034
|
COIN_MAP_KEEPKEY_LONG,
|
|
@@ -1249,7 +1041,7 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1249
1041
|
}
|
|
1250
1042
|
if (networkId.indexOf("eip155") > -1)
|
|
1251
1043
|
networkId = "eip155:*";
|
|
1252
|
-
let chain =
|
|
1044
|
+
let chain = NetworkIdToChain[networkId];
|
|
1253
1045
|
let pubkey = { type: path.type };
|
|
1254
1046
|
let addressInfo = {
|
|
1255
1047
|
address_n: path.addressNListMaster,
|
|
@@ -1380,7 +1172,6 @@ var getPubkey = async (networkId, path, sdk, context) => {
|
|
|
1380
1172
|
throw new Error(`FAIL FAST - xpub retrieval failed for ${networkId} at ${addressNListToBIP32(path.addressNList)}: ${xpubError.message}`);
|
|
1381
1173
|
}
|
|
1382
1174
|
} else {
|
|
1383
|
-
console.log("\uD83D\uDD11 [PUBKEY] Non-xpub path (address-based), using address as pubkey");
|
|
1384
1175
|
pubkey.pubkey = address;
|
|
1385
1176
|
pubkey.path = addressNListToBIP32(path.addressNList);
|
|
1386
1177
|
pubkey.pathMaster = addressNListToBIP32(path.addressNListMaster);
|
|
@@ -1478,7 +1269,7 @@ async function optimizedGetPubkeys(blockchains, paths, keepKeySdk, context, getP
|
|
|
1478
1269
|
if (vaultHealth.available && vaultHealth.cached_pubkeys > 0) {
|
|
1479
1270
|
const batchResponse = await batchGetPubkeys(paths, context, baseUrl);
|
|
1480
1271
|
pubkeys = batchResponse.pubkeys;
|
|
1481
|
-
const cachedPaths = new Set(batchResponse.pubkeys.map((
|
|
1272
|
+
const cachedPaths = new Set(batchResponse.pubkeys.map((p) => p.path));
|
|
1482
1273
|
for (let i = 0;i < blockchains.length; i++) {
|
|
1483
1274
|
const blockchain = blockchains[i];
|
|
1484
1275
|
const pathsForChain = paths.filter((path) => path.networks && Array.isArray(path.networks) && path.networks.includes(blockchain));
|
|
@@ -2564,10 +2355,10 @@ async function createUnsignedTendermintTx(caip, type, amount, memo, pubkeys, pio
|
|
|
2564
2355
|
// src/txbuilder/createUnsignedUxtoTx.ts
|
|
2565
2356
|
var import_coinselect = __toESM(require_coinselect(), 1);
|
|
2566
2357
|
var import_split = __toESM(require_split(), 1);
|
|
2567
|
-
import { caipToNetworkId as caipToNetworkId4, NetworkIdToChain } from "@pioneer-platform/pioneer-caip";
|
|
2358
|
+
import { caipToNetworkId as caipToNetworkId4, NetworkIdToChain as NetworkIdToChain2 } from "@pioneer-platform/pioneer-caip";
|
|
2568
2359
|
import { bip32ToAddressNList as bip32ToAddressNList2, SLIP_44_BY_LONG, COIN_MAP_LONG } from "@pioneer-platform/pioneer-coins";
|
|
2569
2360
|
function getCoinTypeFromNetworkId(networkId) {
|
|
2570
|
-
const chain =
|
|
2361
|
+
const chain = NetworkIdToChain2[networkId];
|
|
2571
2362
|
if (!chain) {
|
|
2572
2363
|
console.warn(`No chain mapping found for ${networkId}, defaulting to Bitcoin coin type 0`);
|
|
2573
2364
|
return 0;
|
|
@@ -2605,7 +2396,7 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2605
2396
|
"bip122:000000000019d6689c085ae165831e93"
|
|
2606
2397
|
];
|
|
2607
2398
|
const isSegwit = segwitNetworks.includes(networkId);
|
|
2608
|
-
let chain =
|
|
2399
|
+
let chain = NetworkIdToChain2[networkId];
|
|
2609
2400
|
const coinType = getCoinTypeFromNetworkId(networkId);
|
|
2610
2401
|
console.log(`${tag6}: Using SLIP-44 coin type ${coinType} for ${chain}`);
|
|
2611
2402
|
const utxos = [];
|
|
@@ -2638,7 +2429,7 @@ async function createUnsignedUxtoTx(caip, to, amount, memo, pubkeys, pioneer, pu
|
|
|
2638
2429
|
acc[type] = (acc[type] || 0) + 1;
|
|
2639
2430
|
return acc;
|
|
2640
2431
|
}, {});
|
|
2641
|
-
const mostCommonInputType = Object.entries(scriptTypeCount).sort(([, a2], [,
|
|
2432
|
+
const mostCommonInputType = Object.entries(scriptTypeCount).sort(([, a2], [, b2]) => b2 - a2)[0]?.[0] || "p2pkh";
|
|
2642
2433
|
const actualChangeScriptType = changeScriptType || mostCommonInputType || relevantPubkeys[0]?.scriptType || "p2pkh";
|
|
2643
2434
|
console.log(`${tag6}: Input script types:`, scriptTypeCount);
|
|
2644
2435
|
console.log(`${tag6}: Using change script type: ${actualChangeScriptType} (matches inputs: ${mostCommonInputType})`);
|
|
@@ -2928,7 +2719,27 @@ class TransactionManager {
|
|
|
2928
2719
|
this.events = events;
|
|
2929
2720
|
}
|
|
2930
2721
|
async classifyCaip(caip) {
|
|
2931
|
-
|
|
2722
|
+
let caipString;
|
|
2723
|
+
if (typeof caip === "string") {
|
|
2724
|
+
caipString = caip;
|
|
2725
|
+
} else if (caip && typeof caip === "object") {
|
|
2726
|
+
if (caip.caip && typeof caip.caip === "string") {
|
|
2727
|
+
caipString = caip.caip;
|
|
2728
|
+
} else if (caip.toString && typeof caip.toString === "function") {
|
|
2729
|
+
caipString = caip.toString();
|
|
2730
|
+
if (caipString === "[object Object]") {
|
|
2731
|
+
if (caip.chainId && caip.network) {
|
|
2732
|
+
caipString = `${caip.chainId}:${caip.network}`;
|
|
2733
|
+
} else {
|
|
2734
|
+
throw new Error(`Cannot extract CAIP string from object: ${JSON.stringify(caip)}`);
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
} else {
|
|
2738
|
+
throw new Error(`Cannot extract CAIP string from object: ${JSON.stringify(caip)}`);
|
|
2739
|
+
}
|
|
2740
|
+
} else {
|
|
2741
|
+
throw new Error(`Invalid CAIP parameter: ${caip}`);
|
|
2742
|
+
}
|
|
2932
2743
|
if (SUPPORTED_CAIPS.UTXO.includes(caipString))
|
|
2933
2744
|
return "UTXO";
|
|
2934
2745
|
if (SUPPORTED_CAIPS.TENDERMINT.includes(caipString))
|
|
@@ -3922,9 +3733,7 @@ function formatTime(durationMs) {
|
|
|
3922
3733
|
|
|
3923
3734
|
// src/utils/build-dashboard.ts
|
|
3924
3735
|
import { caipToNetworkId as caipToNetworkId6, networkIdToCaip } from "@pioneer-platform/pioneer-caip";
|
|
3925
|
-
var TAG8 = " | build-dashboard | ";
|
|
3926
3736
|
function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
3927
|
-
console.log(TAG8, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3928
3737
|
const dashboardData = {
|
|
3929
3738
|
networks: [],
|
|
3930
3739
|
totalValueUsd: 0,
|
|
@@ -3932,16 +3741,14 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3932
3741
|
};
|
|
3933
3742
|
let totalPortfolioValue = 0;
|
|
3934
3743
|
const networksTemp = [];
|
|
3935
|
-
console.log(TAG8, "balances: ", balances);
|
|
3936
3744
|
for (const blockchain of blockchains) {
|
|
3937
|
-
const filteredBalances = balances.filter((
|
|
3938
|
-
const networkId = caipToNetworkId6(
|
|
3745
|
+
const filteredBalances = balances.filter((b2) => {
|
|
3746
|
+
const networkId = caipToNetworkId6(b2.caip);
|
|
3939
3747
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
3940
3748
|
});
|
|
3941
3749
|
const balanceMap = new Map;
|
|
3942
3750
|
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
3943
3751
|
if (isBitcoin) {
|
|
3944
|
-
console.log(TAG8, "Bitcoin network detected - checking for duplicate balances");
|
|
3945
3752
|
const bitcoinByValue = new Map;
|
|
3946
3753
|
filteredBalances.forEach((balance) => {
|
|
3947
3754
|
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
@@ -3952,8 +3759,7 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3952
3759
|
});
|
|
3953
3760
|
for (const [valueKey, balances2] of bitcoinByValue.entries()) {
|
|
3954
3761
|
if (balances2.length === 3 && parseFloat(balances2[0].valueUsd || "0") > 0) {
|
|
3955
|
-
|
|
3956
|
-
const xpubBalance = balances2.find((b3) => b3.pubkey?.startsWith("xpub")) || balances2[0];
|
|
3762
|
+
const xpubBalance = balances2.find((b2) => b2.pubkey?.startsWith("xpub")) || balances2[0];
|
|
3957
3763
|
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
3958
3764
|
balanceMap.set(key, xpubBalance);
|
|
3959
3765
|
} else {
|
|
@@ -3974,23 +3780,15 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3974
3780
|
const networkBalances = Array.from(balanceMap.values());
|
|
3975
3781
|
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
3976
3782
|
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
3977
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
3978
|
-
console.log(TAG8, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
3979
|
-
}
|
|
3980
3783
|
return sum + valueUsd;
|
|
3981
3784
|
}, 0);
|
|
3982
3785
|
const nativeAssetCaip = networkIdToCaip(blockchain);
|
|
3983
|
-
const gasAsset = networkBalances.find((
|
|
3984
|
-
const totalNativeBalance = networkBalances.filter((
|
|
3786
|
+
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
3787
|
+
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
3985
3788
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
3986
3789
|
return sum + balanceNum;
|
|
3987
3790
|
}, 0).toString();
|
|
3988
3791
|
const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
|
|
3989
|
-
console.log(TAG8, `[DEBUG] Network: ${blockchain}`);
|
|
3990
|
-
console.log(TAG8, `[DEBUG] nativeAssetCaip: ${nativeAssetCaip}`);
|
|
3991
|
-
console.log(TAG8, `[DEBUG] assetInfo:`, assetInfo);
|
|
3992
|
-
console.log(TAG8, `[DEBUG] gasAsset:`, gasAsset);
|
|
3993
|
-
console.log(TAG8, `[DEBUG] Resolved name: ${gasAsset?.name || assetInfo?.name || "NO NAME"}`);
|
|
3994
3792
|
networksTemp.push({
|
|
3995
3793
|
networkId: blockchain,
|
|
3996
3794
|
totalValueUsd: networkTotal,
|
|
@@ -4003,7 +3801,7 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
4003
3801
|
});
|
|
4004
3802
|
totalPortfolioValue += networkTotal;
|
|
4005
3803
|
}
|
|
4006
|
-
dashboardData.networks = networksTemp.sort((a2,
|
|
3804
|
+
dashboardData.networks = networksTemp.sort((a2, b2) => b2.totalValueUsd - a2.totalValueUsd);
|
|
4007
3805
|
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
4008
3806
|
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
4009
3807
|
networkId: network.networkId,
|
|
@@ -4014,20 +3812,20 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
4014
3812
|
}
|
|
4015
3813
|
|
|
4016
3814
|
// src/utils/sync-market.ts
|
|
4017
|
-
var
|
|
3815
|
+
var TAG8 = " | sync-market | ";
|
|
4018
3816
|
async function syncMarket(balances, pioneer) {
|
|
4019
|
-
const tag6 = `${
|
|
3817
|
+
const tag6 = `${TAG8} | syncMarket | `;
|
|
4020
3818
|
try {
|
|
4021
|
-
const invalidBalances = balances.filter((
|
|
3819
|
+
const invalidBalances = balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
4022
3820
|
if (invalidBalances.length > 0) {
|
|
4023
|
-
console.warn(tag6, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((
|
|
4024
|
-
caip:
|
|
4025
|
-
type: typeof
|
|
4026
|
-
symbol:
|
|
4027
|
-
balance:
|
|
3821
|
+
console.warn(tag6, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b2) => ({
|
|
3822
|
+
caip: b2?.caip,
|
|
3823
|
+
type: typeof b2?.caip,
|
|
3824
|
+
symbol: b2?.symbol,
|
|
3825
|
+
balance: b2?.balance
|
|
4028
3826
|
})));
|
|
4029
3827
|
}
|
|
4030
|
-
let allCaips = balances.filter((
|
|
3828
|
+
let allCaips = balances.filter((b2) => b2 && b2.caip && typeof b2.caip === "string" && b2.caip.trim().length > 0).map((b2) => b2.caip);
|
|
4031
3829
|
allCaips = [...new Set(allCaips)];
|
|
4032
3830
|
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
4033
3831
|
console.log("GetMarketInfo: payload: ", allCaips);
|
|
@@ -4068,7 +3866,7 @@ async function syncMarket(balances, pioneer) {
|
|
|
4068
3866
|
}
|
|
4069
3867
|
|
|
4070
3868
|
// src/index.ts
|
|
4071
|
-
var
|
|
3869
|
+
var TAG9 = " | Pioneer-sdk | ";
|
|
4072
3870
|
|
|
4073
3871
|
class SDK {
|
|
4074
3872
|
status;
|
|
@@ -4226,7 +4024,7 @@ class SDK {
|
|
|
4226
4024
|
return true;
|
|
4227
4025
|
};
|
|
4228
4026
|
this.setPubkeys = (newPubkeys) => {
|
|
4229
|
-
const tag6 = `${
|
|
4027
|
+
const tag6 = `${TAG9} | setPubkeys | `;
|
|
4230
4028
|
this.pubkeys = [];
|
|
4231
4029
|
this.pubkeySet.clear();
|
|
4232
4030
|
let added = 0;
|
|
@@ -4243,7 +4041,7 @@ class SDK {
|
|
|
4243
4041
|
this.pubkeySet.clear();
|
|
4244
4042
|
}
|
|
4245
4043
|
this.getUnifiedPortfolio = async function() {
|
|
4246
|
-
const tag6 = `${
|
|
4044
|
+
const tag6 = `${TAG9} | getUnifiedPortfolio | `;
|
|
4247
4045
|
try {
|
|
4248
4046
|
const startTime = performance.now();
|
|
4249
4047
|
try {
|
|
@@ -4298,7 +4096,7 @@ class SDK {
|
|
|
4298
4096
|
console.error(`[CACHE VALIDATION] CORRUPTED: ${portfolioData2.networks.length} networks (should be < 50)`);
|
|
4299
4097
|
return false;
|
|
4300
4098
|
}
|
|
4301
|
-
const validNetworks = portfolioData2.networks.filter((
|
|
4099
|
+
const validNetworks = portfolioData2.networks.filter((n) => n.networkId && n.totalValueUsd !== undefined && n.gasAssetSymbol);
|
|
4302
4100
|
if (validNetworks.length === 0 && portfolioData2.networks.length > 0) {
|
|
4303
4101
|
console.error("[CACHE VALIDATION] CORRUPTED: No networks have required fields");
|
|
4304
4102
|
return false;
|
|
@@ -4351,7 +4149,7 @@ class SDK {
|
|
|
4351
4149
|
}
|
|
4352
4150
|
};
|
|
4353
4151
|
this.init = async function(walletsVerbose, setup) {
|
|
4354
|
-
const tag6 = `${
|
|
4152
|
+
const tag6 = `${TAG9} | init | `;
|
|
4355
4153
|
try {
|
|
4356
4154
|
if (!this.username)
|
|
4357
4155
|
throw Error("username required!");
|
|
@@ -4445,7 +4243,7 @@ class SDK {
|
|
|
4445
4243
|
return syncMarket(this.balances, this.pioneer);
|
|
4446
4244
|
};
|
|
4447
4245
|
this.sync = async function() {
|
|
4448
|
-
const tag6 = `${
|
|
4246
|
+
const tag6 = `${TAG9} | sync | `;
|
|
4449
4247
|
try {
|
|
4450
4248
|
const matchesNetwork = (item, networkId) => {
|
|
4451
4249
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4497,26 +4295,14 @@ class SDK {
|
|
|
4497
4295
|
let totalPortfolioValue = 0;
|
|
4498
4296
|
const networksTemp = [];
|
|
4499
4297
|
const uniqueBlockchains = [...new Set(this.blockchains)];
|
|
4500
|
-
console.log(tag6, "uniqueBlockchains: ", uniqueBlockchains);
|
|
4501
4298
|
for (const blockchain of uniqueBlockchains) {
|
|
4502
|
-
const filteredBalances = this.balances.filter((
|
|
4503
|
-
const networkId = caipToNetworkId7(
|
|
4299
|
+
const filteredBalances = this.balances.filter((b2) => {
|
|
4300
|
+
const networkId = caipToNetworkId7(b2.caip);
|
|
4504
4301
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4505
4302
|
});
|
|
4506
|
-
console.log(tag6, `Filtering for blockchain: ${blockchain}`);
|
|
4507
|
-
console.log(tag6, `Found ${filteredBalances.length} balances before deduplication`);
|
|
4508
|
-
filteredBalances.forEach((balance, idx) => {
|
|
4509
|
-
console.log(tag6, `Balance[${idx}]:`, {
|
|
4510
|
-
caip: balance.caip,
|
|
4511
|
-
pubkey: balance.pubkey,
|
|
4512
|
-
balance: balance.balance,
|
|
4513
|
-
valueUsd: balance.valueUsd
|
|
4514
|
-
});
|
|
4515
|
-
});
|
|
4516
4303
|
const balanceMap = new Map;
|
|
4517
4304
|
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
4518
4305
|
if (isBitcoin) {
|
|
4519
|
-
console.log(tag6, "Bitcoin network detected - checking for duplicate balances");
|
|
4520
4306
|
const bitcoinByValue = new Map;
|
|
4521
4307
|
filteredBalances.forEach((balance) => {
|
|
4522
4308
|
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
@@ -4527,8 +4313,7 @@ class SDK {
|
|
|
4527
4313
|
});
|
|
4528
4314
|
for (const [valueKey, balances] of bitcoinByValue.entries()) {
|
|
4529
4315
|
if (balances.length === 3 && parseFloat(balances[0].valueUsd || "0") > 0) {
|
|
4530
|
-
|
|
4531
|
-
const xpubBalance = balances.find((b3) => b3.pubkey?.startsWith("xpub")) || balances[0];
|
|
4316
|
+
const xpubBalance = balances.find((b2) => b2.pubkey?.startsWith("xpub")) || balances[0];
|
|
4532
4317
|
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
4533
4318
|
balanceMap.set(key, xpubBalance);
|
|
4534
4319
|
} else {
|
|
@@ -4547,20 +4332,13 @@ class SDK {
|
|
|
4547
4332
|
});
|
|
4548
4333
|
}
|
|
4549
4334
|
const networkBalances = Array.from(balanceMap.values());
|
|
4550
|
-
console.log(tag6, "networkBalances (deduplicated): ", networkBalances);
|
|
4551
|
-
console.log(tag6, "networkBalances count: ", networkBalances.length);
|
|
4552
4335
|
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
4553
4336
|
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
4554
|
-
console.log(tag6, `[${idx}] valueUsd:`, balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
4555
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
4556
|
-
console.log(tag6, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd);
|
|
4557
|
-
}
|
|
4558
4337
|
return sum + valueUsd;
|
|
4559
4338
|
}, 0);
|
|
4560
|
-
console.log("Final networkTotal:", networkTotal);
|
|
4561
4339
|
const nativeAssetCaip = networkIdToCaip2(blockchain);
|
|
4562
|
-
const gasAsset = networkBalances.find((
|
|
4563
|
-
const totalNativeBalance = networkBalances.filter((
|
|
4340
|
+
const gasAsset = networkBalances.find((b2) => b2.caip === nativeAssetCaip);
|
|
4341
|
+
const totalNativeBalance = networkBalances.filter((b2) => b2.caip === nativeAssetCaip).reduce((sum, balance) => {
|
|
4564
4342
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
4565
4343
|
return sum + balanceNum;
|
|
4566
4344
|
}, 0).toString();
|
|
@@ -4575,7 +4353,7 @@ class SDK {
|
|
|
4575
4353
|
});
|
|
4576
4354
|
totalPortfolioValue += networkTotal;
|
|
4577
4355
|
}
|
|
4578
|
-
dashboardData.networks = networksTemp.sort((a2,
|
|
4356
|
+
dashboardData.networks = networksTemp.sort((a2, b2) => b2.totalValueUsd - a2.totalValueUsd);
|
|
4579
4357
|
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
4580
4358
|
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
4581
4359
|
networkId: network.networkId,
|
|
@@ -4598,7 +4376,7 @@ class SDK {
|
|
|
4598
4376
|
}
|
|
4599
4377
|
};
|
|
4600
4378
|
this.buildTx = async function(sendPayload) {
|
|
4601
|
-
let tag6 =
|
|
4379
|
+
let tag6 = TAG9 + " | buildTx | ";
|
|
4602
4380
|
try {
|
|
4603
4381
|
const transactionDependencies = {
|
|
4604
4382
|
context: this.context,
|
|
@@ -4620,7 +4398,7 @@ class SDK {
|
|
|
4620
4398
|
}
|
|
4621
4399
|
};
|
|
4622
4400
|
this.buildDelegateTx = async function(caip, params) {
|
|
4623
|
-
let tag6 =
|
|
4401
|
+
let tag6 = TAG9 + " | buildDelegateTx | ";
|
|
4624
4402
|
try {
|
|
4625
4403
|
const delegateParams = {
|
|
4626
4404
|
...params,
|
|
@@ -4635,7 +4413,7 @@ class SDK {
|
|
|
4635
4413
|
}
|
|
4636
4414
|
};
|
|
4637
4415
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4638
|
-
let tag6 =
|
|
4416
|
+
let tag6 = TAG9 + " | buildUndelegateTx | ";
|
|
4639
4417
|
try {
|
|
4640
4418
|
const undelegateParams = {
|
|
4641
4419
|
...params,
|
|
@@ -4650,7 +4428,7 @@ class SDK {
|
|
|
4650
4428
|
}
|
|
4651
4429
|
};
|
|
4652
4430
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4653
|
-
let tag6 =
|
|
4431
|
+
let tag6 = TAG9 + " | buildClaimRewardsTx | ";
|
|
4654
4432
|
try {
|
|
4655
4433
|
const claimParams = {
|
|
4656
4434
|
...params,
|
|
@@ -4665,7 +4443,7 @@ class SDK {
|
|
|
4665
4443
|
}
|
|
4666
4444
|
};
|
|
4667
4445
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4668
|
-
let tag6 =
|
|
4446
|
+
let tag6 = TAG9 + " | buildClaimAllRewardsTx | ";
|
|
4669
4447
|
try {
|
|
4670
4448
|
const claimAllParams = {
|
|
4671
4449
|
...params,
|
|
@@ -4679,7 +4457,7 @@ class SDK {
|
|
|
4679
4457
|
}
|
|
4680
4458
|
};
|
|
4681
4459
|
this.signTx = async function(caip, unsignedTx) {
|
|
4682
|
-
let tag6 =
|
|
4460
|
+
let tag6 = TAG9 + " | signTx | ";
|
|
4683
4461
|
try {
|
|
4684
4462
|
const transactionDependencies = {
|
|
4685
4463
|
context: this.context,
|
|
@@ -4700,7 +4478,7 @@ class SDK {
|
|
|
4700
4478
|
}
|
|
4701
4479
|
};
|
|
4702
4480
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4703
|
-
let tag6 =
|
|
4481
|
+
let tag6 = TAG9 + " | broadcastTx | ";
|
|
4704
4482
|
try {
|
|
4705
4483
|
const transactionDependencies = {
|
|
4706
4484
|
context: this.context,
|
|
@@ -4724,7 +4502,7 @@ class SDK {
|
|
|
4724
4502
|
}
|
|
4725
4503
|
};
|
|
4726
4504
|
this.swap = async function(swapPayload) {
|
|
4727
|
-
let tag6 = `${
|
|
4505
|
+
let tag6 = `${TAG9} | swap | `;
|
|
4728
4506
|
try {
|
|
4729
4507
|
if (!swapPayload)
|
|
4730
4508
|
throw Error("swapPayload required!");
|
|
@@ -4863,7 +4641,7 @@ class SDK {
|
|
|
4863
4641
|
}
|
|
4864
4642
|
};
|
|
4865
4643
|
this.transfer = async function(sendPayload) {
|
|
4866
|
-
let tag6 = `${
|
|
4644
|
+
let tag6 = `${TAG9} | transfer | `;
|
|
4867
4645
|
try {
|
|
4868
4646
|
if (!sendPayload)
|
|
4869
4647
|
throw Error("sendPayload required!");
|
|
@@ -4958,7 +4736,7 @@ class SDK {
|
|
|
4958
4736
|
}
|
|
4959
4737
|
};
|
|
4960
4738
|
this.setBlockchains = async function(blockchains) {
|
|
4961
|
-
const tag6 = `${
|
|
4739
|
+
const tag6 = `${TAG9} | setBlockchains | `;
|
|
4962
4740
|
try {
|
|
4963
4741
|
if (!blockchains)
|
|
4964
4742
|
throw Error("blockchains required!");
|
|
@@ -4974,7 +4752,7 @@ class SDK {
|
|
|
4974
4752
|
}
|
|
4975
4753
|
};
|
|
4976
4754
|
this.addAsset = async function(caip, data) {
|
|
4977
|
-
let tag6 =
|
|
4755
|
+
let tag6 = TAG9 + " | addAsset | ";
|
|
4978
4756
|
try {
|
|
4979
4757
|
let success = false;
|
|
4980
4758
|
if (!caip)
|
|
@@ -5012,7 +4790,7 @@ class SDK {
|
|
|
5012
4790
|
}
|
|
5013
4791
|
};
|
|
5014
4792
|
this.clearWalletState = async function() {
|
|
5015
|
-
const tag6 = `${
|
|
4793
|
+
const tag6 = `${TAG9} | clearWalletState | `;
|
|
5016
4794
|
try {
|
|
5017
4795
|
this.context = null;
|
|
5018
4796
|
this.paths = [];
|
|
@@ -5027,7 +4805,7 @@ class SDK {
|
|
|
5027
4805
|
}
|
|
5028
4806
|
};
|
|
5029
4807
|
this.addPath = async function(path) {
|
|
5030
|
-
const tag6 = `${
|
|
4808
|
+
const tag6 = `${TAG9} | addPath | `;
|
|
5031
4809
|
try {
|
|
5032
4810
|
this.paths.push(path);
|
|
5033
4811
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -5041,7 +4819,7 @@ class SDK {
|
|
|
5041
4819
|
}
|
|
5042
4820
|
};
|
|
5043
4821
|
this.addPaths = async function(paths) {
|
|
5044
|
-
const tag6 = `${
|
|
4822
|
+
const tag6 = `${TAG9} | addPaths | `;
|
|
5045
4823
|
try {
|
|
5046
4824
|
console.log(tag6, `Adding ${paths.length} paths in batch mode...`);
|
|
5047
4825
|
this.paths.push(...paths);
|
|
@@ -5077,7 +4855,7 @@ class SDK {
|
|
|
5077
4855
|
return this.getGasAssets();
|
|
5078
4856
|
};
|
|
5079
4857
|
this.getGasAssets = async function() {
|
|
5080
|
-
const tag6 = `${
|
|
4858
|
+
const tag6 = `${TAG9} | getGasAssets | `;
|
|
5081
4859
|
try {
|
|
5082
4860
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
5083
4861
|
let networkId = this.blockchains[i];
|
|
@@ -5120,7 +4898,7 @@ class SDK {
|
|
|
5120
4898
|
}
|
|
5121
4899
|
};
|
|
5122
4900
|
this.getPubkeys = async function() {
|
|
5123
|
-
const tag6 = `${
|
|
4901
|
+
const tag6 = `${TAG9} | getPubkeys | `;
|
|
5124
4902
|
try {
|
|
5125
4903
|
if (this.paths.length === 0)
|
|
5126
4904
|
throw new Error("No paths found!");
|
|
@@ -5141,7 +4919,7 @@ class SDK {
|
|
|
5141
4919
|
}
|
|
5142
4920
|
};
|
|
5143
4921
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
5144
|
-
const tag6 = `${
|
|
4922
|
+
const tag6 = `${TAG9} | getBalancesForNetworks | `;
|
|
5145
4923
|
try {
|
|
5146
4924
|
if (!this.pioneer) {
|
|
5147
4925
|
console.error(tag6, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -5169,9 +4947,6 @@ class SDK {
|
|
|
5169
4947
|
let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
|
|
5170
4948
|
console.timeEnd("GetPortfolioBalances Response Time");
|
|
5171
4949
|
let balances = marketInfo.data;
|
|
5172
|
-
const bitcoinBalances = balances.filter((b3) => b3.caip === "bip122:000000000019d6689c085ae165831e93/slip44:0");
|
|
5173
|
-
if (bitcoinBalances.length > 0) {
|
|
5174
|
-
}
|
|
5175
4950
|
for (let balance of balances) {
|
|
5176
4951
|
const assetInfo = this.assetsMap.get(balance.caip);
|
|
5177
4952
|
if (!assetInfo)
|
|
@@ -5179,10 +4954,10 @@ class SDK {
|
|
|
5179
4954
|
Object.assign(balance, assetInfo, {
|
|
5180
4955
|
networkId: caipToNetworkId7(balance.caip),
|
|
5181
4956
|
icon: assetInfo.icon || "https://pioneers.dev/coins/etherum.png",
|
|
5182
|
-
identifier: `${balance.caip}:${balance.pubkey}
|
|
4957
|
+
identifier: `${balance.caip}:${balance.pubkey}`,
|
|
4958
|
+
updated: Date.now()
|
|
5183
4959
|
});
|
|
5184
4960
|
}
|
|
5185
|
-
console.log(tag6, "balances: ", balances);
|
|
5186
4961
|
this.balances = balances;
|
|
5187
4962
|
this.events.emit("SET_BALANCES", this.balances);
|
|
5188
4963
|
return this.balances;
|
|
@@ -5196,7 +4971,7 @@ class SDK {
|
|
|
5196
4971
|
}
|
|
5197
4972
|
};
|
|
5198
4973
|
this.getBalances = async function() {
|
|
5199
|
-
const tag6 = `${
|
|
4974
|
+
const tag6 = `${TAG9} | getBalances | `;
|
|
5200
4975
|
try {
|
|
5201
4976
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
5202
4977
|
} catch (e) {
|
|
@@ -5205,10 +4980,10 @@ class SDK {
|
|
|
5205
4980
|
}
|
|
5206
4981
|
};
|
|
5207
4982
|
this.getBalance = async function(networkId) {
|
|
5208
|
-
const tag6 = `${
|
|
4983
|
+
const tag6 = `${TAG9} | getBalance | `;
|
|
5209
4984
|
try {
|
|
5210
4985
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
5211
|
-
const filtered = results.filter(async (
|
|
4986
|
+
const filtered = results.filter(async (b2) => b2.networkId === await networkIdToCaip2(networkId));
|
|
5212
4987
|
return filtered;
|
|
5213
4988
|
} catch (e) {
|
|
5214
4989
|
console.error(tag6, "Error: ", e);
|
|
@@ -5216,7 +4991,7 @@ class SDK {
|
|
|
5216
4991
|
}
|
|
5217
4992
|
};
|
|
5218
4993
|
this.getFees = async function(networkId) {
|
|
5219
|
-
const tag6 = `${
|
|
4994
|
+
const tag6 = `${TAG9} | getFees | `;
|
|
5220
4995
|
try {
|
|
5221
4996
|
if (!this.pioneer) {
|
|
5222
4997
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -5231,7 +5006,7 @@ class SDK {
|
|
|
5231
5006
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
5232
5007
|
};
|
|
5233
5008
|
this.getCharts = async function() {
|
|
5234
|
-
const tag6 = `${
|
|
5009
|
+
const tag6 = `${TAG9} | getCharts | `;
|
|
5235
5010
|
try {
|
|
5236
5011
|
console.log(tag6, "Fetching charts");
|
|
5237
5012
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -5253,7 +5028,7 @@ class SDK {
|
|
|
5253
5028
|
}
|
|
5254
5029
|
};
|
|
5255
5030
|
this.setContext = async (context) => {
|
|
5256
|
-
const tag6 = `${
|
|
5031
|
+
const tag6 = `${TAG9} | setContext | `;
|
|
5257
5032
|
try {
|
|
5258
5033
|
if (!context)
|
|
5259
5034
|
throw Error("context required!");
|
|
@@ -5266,7 +5041,7 @@ class SDK {
|
|
|
5266
5041
|
}
|
|
5267
5042
|
};
|
|
5268
5043
|
this.setContextType = async (contextType) => {
|
|
5269
|
-
const tag6 = `${
|
|
5044
|
+
const tag6 = `${TAG9} | setContextType | `;
|
|
5270
5045
|
try {
|
|
5271
5046
|
if (!contextType)
|
|
5272
5047
|
throw Error("contextType required!");
|
|
@@ -5279,7 +5054,7 @@ class SDK {
|
|
|
5279
5054
|
}
|
|
5280
5055
|
};
|
|
5281
5056
|
this.refresh = async () => {
|
|
5282
|
-
const tag6 = `${
|
|
5057
|
+
const tag6 = `${TAG9} | refresh | `;
|
|
5283
5058
|
try {
|
|
5284
5059
|
await this.sync();
|
|
5285
5060
|
return this.balances;
|
|
@@ -5289,7 +5064,7 @@ class SDK {
|
|
|
5289
5064
|
}
|
|
5290
5065
|
};
|
|
5291
5066
|
this.setAssetContext = async function(asset) {
|
|
5292
|
-
const tag6 = `${
|
|
5067
|
+
const tag6 = `${TAG9} | setAssetContext | `;
|
|
5293
5068
|
try {
|
|
5294
5069
|
if (!asset) {
|
|
5295
5070
|
this.assetContext = null;
|
|
@@ -5318,20 +5093,20 @@ class SDK {
|
|
|
5318
5093
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no address/xpub found for network ${asset.networkId}`;
|
|
5319
5094
|
console.error(tag6, errorMsg);
|
|
5320
5095
|
console.error(tag6, "Available networks in pubkeys:", [
|
|
5321
|
-
...new Set(this.pubkeys.flatMap((
|
|
5096
|
+
...new Set(this.pubkeys.flatMap((p) => p.networks || []))
|
|
5322
5097
|
]);
|
|
5323
5098
|
throw new Error(errorMsg);
|
|
5324
5099
|
}
|
|
5325
5100
|
const isUtxoChain = asset.networkId.startsWith("bip122:");
|
|
5326
5101
|
if (isUtxoChain) {
|
|
5327
|
-
const xpubFound = pubkeysForNetwork.some((
|
|
5102
|
+
const xpubFound = pubkeysForNetwork.some((p) => p.type === "xpub" && p.pubkey);
|
|
5328
5103
|
if (!xpubFound) {
|
|
5329
5104
|
const errorMsg = `Cannot set asset context for UTXO chain ${asset.caip} - xpub required but not found`;
|
|
5330
5105
|
console.error(tag6, errorMsg);
|
|
5331
5106
|
throw new Error(errorMsg);
|
|
5332
5107
|
}
|
|
5333
5108
|
}
|
|
5334
|
-
const hasValidAddress = pubkeysForNetwork.some((
|
|
5109
|
+
const hasValidAddress = pubkeysForNetwork.some((p) => p.address || p.master || p.pubkey);
|
|
5335
5110
|
if (!hasValidAddress) {
|
|
5336
5111
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no valid address found in pubkeys`;
|
|
5337
5112
|
console.error(tag6, errorMsg);
|
|
@@ -5372,7 +5147,7 @@ class SDK {
|
|
|
5372
5147
|
icon: asset.icon || "https://pioneers.dev/coins/ethereum.png"
|
|
5373
5148
|
};
|
|
5374
5149
|
}
|
|
5375
|
-
const matchingBalances = this.balances.filter((
|
|
5150
|
+
const matchingBalances = this.balances.filter((b2) => b2.caip === asset.caip);
|
|
5376
5151
|
if (matchingBalances.length > 0) {
|
|
5377
5152
|
let priceValue = matchingBalances[0].priceUsd || matchingBalances[0].price;
|
|
5378
5153
|
if ((!priceValue || priceValue === 0) && matchingBalances[0].valueUsd && matchingBalances[0].balance) {
|
|
@@ -5405,8 +5180,8 @@ class SDK {
|
|
|
5405
5180
|
assetInfo.valueUsd = totalValueUsd.toFixed(2);
|
|
5406
5181
|
console.log(tag6, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
5407
5182
|
}
|
|
5408
|
-
const assetBalances = this.balances.filter((
|
|
5409
|
-
const assetPubkeys = this.pubkeys.filter((
|
|
5183
|
+
const assetBalances = this.balances.filter((b2) => b2.caip === asset.caip);
|
|
5184
|
+
const assetPubkeys = this.pubkeys.filter((p) => p.networks && Array.isArray(p.networks) && p.networks.includes(caipToNetworkId7(asset.caip)) || caipToNetworkId7(asset.caip).includes("eip155") && p.networks && Array.isArray(p.networks) && p.networks.some((n) => n.startsWith("eip155")));
|
|
5410
5185
|
const finalAssetContext = {
|
|
5411
5186
|
...assetInfo,
|
|
5412
5187
|
...asset,
|
|
@@ -5457,7 +5232,7 @@ class SDK {
|
|
|
5457
5232
|
}
|
|
5458
5233
|
this.assetContext.nativeSymbol = nativeSymbol;
|
|
5459
5234
|
if (nativeCaip) {
|
|
5460
|
-
const nativeBalance = this.balances.find((
|
|
5235
|
+
const nativeBalance = this.balances.find((b2) => b2.caip === nativeCaip);
|
|
5461
5236
|
if (nativeBalance) {
|
|
5462
5237
|
this.assetContext.nativeBalance = nativeBalance.balance || "0";
|
|
5463
5238
|
} else {
|
|
@@ -5488,7 +5263,7 @@ class SDK {
|
|
|
5488
5263
|
}
|
|
5489
5264
|
};
|
|
5490
5265
|
this.setPubkeyContext = async function(pubkey) {
|
|
5491
|
-
let tag6 = `${
|
|
5266
|
+
let tag6 = `${TAG9} | setPubkeyContext | `;
|
|
5492
5267
|
try {
|
|
5493
5268
|
if (!pubkey)
|
|
5494
5269
|
throw Error("pubkey is required");
|
|
@@ -5507,7 +5282,7 @@ class SDK {
|
|
|
5507
5282
|
}
|
|
5508
5283
|
};
|
|
5509
5284
|
this.setOutboundAssetContext = async function(asset) {
|
|
5510
|
-
const tag6 = `${
|
|
5285
|
+
const tag6 = `${TAG9} | setOutputAssetContext | `;
|
|
5511
5286
|
try {
|
|
5512
5287
|
console.log(tag6, "0. asset: ", asset);
|
|
5513
5288
|
if (!asset) {
|
|
@@ -5521,12 +5296,12 @@ class SDK {
|
|
|
5521
5296
|
asset.networkId = caipToNetworkId7(asset.caip);
|
|
5522
5297
|
console.log(tag6, "networkId: ", asset.networkId);
|
|
5523
5298
|
console.log(tag6, "this.pubkeys: ", this.pubkeys);
|
|
5524
|
-
const pubkey = this.pubkeys.find((
|
|
5525
|
-
if (!
|
|
5299
|
+
const pubkey = this.pubkeys.find((p) => {
|
|
5300
|
+
if (!p.networks || !Array.isArray(p.networks))
|
|
5526
5301
|
return false;
|
|
5527
|
-
if (
|
|
5302
|
+
if (p.networks.includes(asset.networkId))
|
|
5528
5303
|
return true;
|
|
5529
|
-
if (asset.networkId.startsWith("eip155:") &&
|
|
5304
|
+
if (asset.networkId.startsWith("eip155:") && p.networks.includes("eip155:*"))
|
|
5530
5305
|
return true;
|
|
5531
5306
|
return false;
|
|
5532
5307
|
});
|
|
@@ -5561,7 +5336,7 @@ class SDK {
|
|
|
5561
5336
|
icon: asset.icon || "https://pioneers.dev/coins/ethereum.png"
|
|
5562
5337
|
};
|
|
5563
5338
|
}
|
|
5564
|
-
const matchingBalances = this.balances.filter((
|
|
5339
|
+
const matchingBalances = this.balances.filter((b2) => b2.caip === asset.caip);
|
|
5565
5340
|
if (matchingBalances.length > 0) {
|
|
5566
5341
|
let priceValue = matchingBalances[0].priceUsd || matchingBalances[0].price;
|
|
5567
5342
|
if ((!priceValue || priceValue === 0) && matchingBalances[0].valueUsd && matchingBalances[0].balance) {
|