@pioneer-platform/pioneer-sdk 4.21.12 → 4.21.14
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 +102 -347
- package/dist/index.es.js +78 -323
- package/dist/index.js +78 -323
- package/package.json +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.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})`);
|
|
@@ -3942,9 +3733,7 @@ function formatTime(durationMs) {
|
|
|
3942
3733
|
|
|
3943
3734
|
// src/utils/build-dashboard.ts
|
|
3944
3735
|
import { caipToNetworkId as caipToNetworkId6, networkIdToCaip } from "@pioneer-platform/pioneer-caip";
|
|
3945
|
-
var TAG8 = " | build-dashboard | ";
|
|
3946
3736
|
function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
3947
|
-
console.log(TAG8, "[DASHBOARD] Building dashboard from cached balances...");
|
|
3948
3737
|
const dashboardData = {
|
|
3949
3738
|
networks: [],
|
|
3950
3739
|
totalValueUsd: 0,
|
|
@@ -3952,16 +3741,14 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3952
3741
|
};
|
|
3953
3742
|
let totalPortfolioValue = 0;
|
|
3954
3743
|
const networksTemp = [];
|
|
3955
|
-
console.log(TAG8, "balances: ", balances);
|
|
3956
3744
|
for (const blockchain of blockchains) {
|
|
3957
|
-
const filteredBalances = balances.filter((
|
|
3958
|
-
const networkId = caipToNetworkId6(
|
|
3745
|
+
const filteredBalances = balances.filter((b2) => {
|
|
3746
|
+
const networkId = caipToNetworkId6(b2.caip);
|
|
3959
3747
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
3960
3748
|
});
|
|
3961
3749
|
const balanceMap = new Map;
|
|
3962
3750
|
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
3963
3751
|
if (isBitcoin) {
|
|
3964
|
-
console.log(TAG8, "Bitcoin network detected - checking for duplicate balances");
|
|
3965
3752
|
const bitcoinByValue = new Map;
|
|
3966
3753
|
filteredBalances.forEach((balance) => {
|
|
3967
3754
|
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
@@ -3972,8 +3759,7 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3972
3759
|
});
|
|
3973
3760
|
for (const [valueKey, balances2] of bitcoinByValue.entries()) {
|
|
3974
3761
|
if (balances2.length === 3 && parseFloat(balances2[0].valueUsd || "0") > 0) {
|
|
3975
|
-
|
|
3976
|
-
const xpubBalance = balances2.find((b3) => b3.pubkey?.startsWith("xpub")) || balances2[0];
|
|
3762
|
+
const xpubBalance = balances2.find((b2) => b2.pubkey?.startsWith("xpub")) || balances2[0];
|
|
3977
3763
|
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
3978
3764
|
balanceMap.set(key, xpubBalance);
|
|
3979
3765
|
} else {
|
|
@@ -3994,23 +3780,15 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3994
3780
|
const networkBalances = Array.from(balanceMap.values());
|
|
3995
3781
|
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
3996
3782
|
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
3997
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
3998
|
-
console.log(TAG8, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
3999
|
-
}
|
|
4000
3783
|
return sum + valueUsd;
|
|
4001
3784
|
}, 0);
|
|
4002
3785
|
const nativeAssetCaip = networkIdToCaip(blockchain);
|
|
4003
|
-
const gasAsset = networkBalances.find((
|
|
4004
|
-
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) => {
|
|
4005
3788
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
4006
3789
|
return sum + balanceNum;
|
|
4007
3790
|
}, 0).toString();
|
|
4008
3791
|
const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
|
|
4009
|
-
console.log(TAG8, `[DEBUG] Network: ${blockchain}`);
|
|
4010
|
-
console.log(TAG8, `[DEBUG] nativeAssetCaip: ${nativeAssetCaip}`);
|
|
4011
|
-
console.log(TAG8, `[DEBUG] assetInfo:`, assetInfo);
|
|
4012
|
-
console.log(TAG8, `[DEBUG] gasAsset:`, gasAsset);
|
|
4013
|
-
console.log(TAG8, `[DEBUG] Resolved name: ${gasAsset?.name || assetInfo?.name || "NO NAME"}`);
|
|
4014
3792
|
networksTemp.push({
|
|
4015
3793
|
networkId: blockchain,
|
|
4016
3794
|
totalValueUsd: networkTotal,
|
|
@@ -4023,7 +3801,7 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
4023
3801
|
});
|
|
4024
3802
|
totalPortfolioValue += networkTotal;
|
|
4025
3803
|
}
|
|
4026
|
-
dashboardData.networks = networksTemp.sort((a2,
|
|
3804
|
+
dashboardData.networks = networksTemp.sort((a2, b2) => b2.totalValueUsd - a2.totalValueUsd);
|
|
4027
3805
|
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
4028
3806
|
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
4029
3807
|
networkId: network.networkId,
|
|
@@ -4034,20 +3812,20 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
4034
3812
|
}
|
|
4035
3813
|
|
|
4036
3814
|
// src/utils/sync-market.ts
|
|
4037
|
-
var
|
|
3815
|
+
var TAG8 = " | sync-market | ";
|
|
4038
3816
|
async function syncMarket(balances, pioneer) {
|
|
4039
|
-
const tag6 = `${
|
|
3817
|
+
const tag6 = `${TAG8} | syncMarket | `;
|
|
4040
3818
|
try {
|
|
4041
|
-
const invalidBalances = balances.filter((
|
|
3819
|
+
const invalidBalances = balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
4042
3820
|
if (invalidBalances.length > 0) {
|
|
4043
|
-
console.warn(tag6, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((
|
|
4044
|
-
caip:
|
|
4045
|
-
type: typeof
|
|
4046
|
-
symbol:
|
|
4047
|
-
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
|
|
4048
3826
|
})));
|
|
4049
3827
|
}
|
|
4050
|
-
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);
|
|
4051
3829
|
allCaips = [...new Set(allCaips)];
|
|
4052
3830
|
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
4053
3831
|
console.log("GetMarketInfo: payload: ", allCaips);
|
|
@@ -4088,7 +3866,7 @@ async function syncMarket(balances, pioneer) {
|
|
|
4088
3866
|
}
|
|
4089
3867
|
|
|
4090
3868
|
// src/index.ts
|
|
4091
|
-
var
|
|
3869
|
+
var TAG9 = " | Pioneer-sdk | ";
|
|
4092
3870
|
|
|
4093
3871
|
class SDK {
|
|
4094
3872
|
status;
|
|
@@ -4246,7 +4024,7 @@ class SDK {
|
|
|
4246
4024
|
return true;
|
|
4247
4025
|
};
|
|
4248
4026
|
this.setPubkeys = (newPubkeys) => {
|
|
4249
|
-
const tag6 = `${
|
|
4027
|
+
const tag6 = `${TAG9} | setPubkeys | `;
|
|
4250
4028
|
this.pubkeys = [];
|
|
4251
4029
|
this.pubkeySet.clear();
|
|
4252
4030
|
let added = 0;
|
|
@@ -4263,7 +4041,7 @@ class SDK {
|
|
|
4263
4041
|
this.pubkeySet.clear();
|
|
4264
4042
|
}
|
|
4265
4043
|
this.getUnifiedPortfolio = async function() {
|
|
4266
|
-
const tag6 = `${
|
|
4044
|
+
const tag6 = `${TAG9} | getUnifiedPortfolio | `;
|
|
4267
4045
|
try {
|
|
4268
4046
|
const startTime = performance.now();
|
|
4269
4047
|
try {
|
|
@@ -4318,7 +4096,7 @@ class SDK {
|
|
|
4318
4096
|
console.error(`[CACHE VALIDATION] CORRUPTED: ${portfolioData2.networks.length} networks (should be < 50)`);
|
|
4319
4097
|
return false;
|
|
4320
4098
|
}
|
|
4321
|
-
const validNetworks = portfolioData2.networks.filter((
|
|
4099
|
+
const validNetworks = portfolioData2.networks.filter((n) => n.networkId && n.totalValueUsd !== undefined && n.gasAssetSymbol);
|
|
4322
4100
|
if (validNetworks.length === 0 && portfolioData2.networks.length > 0) {
|
|
4323
4101
|
console.error("[CACHE VALIDATION] CORRUPTED: No networks have required fields");
|
|
4324
4102
|
return false;
|
|
@@ -4371,7 +4149,7 @@ class SDK {
|
|
|
4371
4149
|
}
|
|
4372
4150
|
};
|
|
4373
4151
|
this.init = async function(walletsVerbose, setup) {
|
|
4374
|
-
const tag6 = `${
|
|
4152
|
+
const tag6 = `${TAG9} | init | `;
|
|
4375
4153
|
try {
|
|
4376
4154
|
if (!this.username)
|
|
4377
4155
|
throw Error("username required!");
|
|
@@ -4465,7 +4243,7 @@ class SDK {
|
|
|
4465
4243
|
return syncMarket(this.balances, this.pioneer);
|
|
4466
4244
|
};
|
|
4467
4245
|
this.sync = async function() {
|
|
4468
|
-
const tag6 = `${
|
|
4246
|
+
const tag6 = `${TAG9} | sync | `;
|
|
4469
4247
|
try {
|
|
4470
4248
|
const matchesNetwork = (item, networkId) => {
|
|
4471
4249
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4517,26 +4295,14 @@ class SDK {
|
|
|
4517
4295
|
let totalPortfolioValue = 0;
|
|
4518
4296
|
const networksTemp = [];
|
|
4519
4297
|
const uniqueBlockchains = [...new Set(this.blockchains)];
|
|
4520
|
-
console.log(tag6, "uniqueBlockchains: ", uniqueBlockchains);
|
|
4521
4298
|
for (const blockchain of uniqueBlockchains) {
|
|
4522
|
-
const filteredBalances = this.balances.filter((
|
|
4523
|
-
const networkId = caipToNetworkId7(
|
|
4299
|
+
const filteredBalances = this.balances.filter((b2) => {
|
|
4300
|
+
const networkId = caipToNetworkId7(b2.caip);
|
|
4524
4301
|
return networkId === blockchain || blockchain === "eip155:*" && networkId.startsWith("eip155:");
|
|
4525
4302
|
});
|
|
4526
|
-
console.log(tag6, `Filtering for blockchain: ${blockchain}`);
|
|
4527
|
-
console.log(tag6, `Found ${filteredBalances.length} balances before deduplication`);
|
|
4528
|
-
filteredBalances.forEach((balance, idx) => {
|
|
4529
|
-
console.log(tag6, `Balance[${idx}]:`, {
|
|
4530
|
-
caip: balance.caip,
|
|
4531
|
-
pubkey: balance.pubkey,
|
|
4532
|
-
balance: balance.balance,
|
|
4533
|
-
valueUsd: balance.valueUsd
|
|
4534
|
-
});
|
|
4535
|
-
});
|
|
4536
4303
|
const balanceMap = new Map;
|
|
4537
4304
|
const isBitcoin = blockchain.includes("bip122:000000000019d6689c085ae165831e93");
|
|
4538
4305
|
if (isBitcoin) {
|
|
4539
|
-
console.log(tag6, "Bitcoin network detected - checking for duplicate balances");
|
|
4540
4306
|
const bitcoinByValue = new Map;
|
|
4541
4307
|
filteredBalances.forEach((balance) => {
|
|
4542
4308
|
const valueKey = `${balance.balance}_${balance.valueUsd}`;
|
|
@@ -4547,8 +4313,7 @@ class SDK {
|
|
|
4547
4313
|
});
|
|
4548
4314
|
for (const [valueKey, balances] of bitcoinByValue.entries()) {
|
|
4549
4315
|
if (balances.length === 3 && parseFloat(balances[0].valueUsd || "0") > 0) {
|
|
4550
|
-
|
|
4551
|
-
const xpubBalance = balances.find((b3) => b3.pubkey?.startsWith("xpub")) || balances[0];
|
|
4316
|
+
const xpubBalance = balances.find((b2) => b2.pubkey?.startsWith("xpub")) || balances[0];
|
|
4552
4317
|
const key = `${xpubBalance.caip}_${xpubBalance.pubkey || "default"}`;
|
|
4553
4318
|
balanceMap.set(key, xpubBalance);
|
|
4554
4319
|
} else {
|
|
@@ -4567,20 +4332,13 @@ class SDK {
|
|
|
4567
4332
|
});
|
|
4568
4333
|
}
|
|
4569
4334
|
const networkBalances = Array.from(balanceMap.values());
|
|
4570
|
-
console.log(tag6, "networkBalances (deduplicated): ", networkBalances);
|
|
4571
|
-
console.log(tag6, "networkBalances count: ", networkBalances.length);
|
|
4572
4335
|
const networkTotal = networkBalances.reduce((sum, balance, idx) => {
|
|
4573
4336
|
const valueUsd = typeof balance.valueUsd === "string" ? parseFloat(balance.valueUsd) : balance.valueUsd || 0;
|
|
4574
|
-
console.log(tag6, `[${idx}] valueUsd:`, balance.valueUsd, "→ parsed:", valueUsd, "| running sum:", sum + valueUsd);
|
|
4575
|
-
if (blockchain.includes("bip122:000000000019d6689c085ae165831e93")) {
|
|
4576
|
-
console.log(tag6, `[BITCOIN DEBUG ${idx}] pubkey:`, balance.pubkey?.substring(0, 10) + "...", "| balance:", balance.balance, "| valueUsd:", balance.valueUsd, "→ parsed:", valueUsd);
|
|
4577
|
-
}
|
|
4578
4337
|
return sum + valueUsd;
|
|
4579
4338
|
}, 0);
|
|
4580
|
-
console.log("Final networkTotal:", networkTotal);
|
|
4581
4339
|
const nativeAssetCaip = networkIdToCaip2(blockchain);
|
|
4582
|
-
const gasAsset = networkBalances.find((
|
|
4583
|
-
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) => {
|
|
4584
4342
|
const balanceNum = typeof balance.balance === "string" ? parseFloat(balance.balance) : balance.balance || 0;
|
|
4585
4343
|
return sum + balanceNum;
|
|
4586
4344
|
}, 0).toString();
|
|
@@ -4595,7 +4353,7 @@ class SDK {
|
|
|
4595
4353
|
});
|
|
4596
4354
|
totalPortfolioValue += networkTotal;
|
|
4597
4355
|
}
|
|
4598
|
-
dashboardData.networks = networksTemp.sort((a2,
|
|
4356
|
+
dashboardData.networks = networksTemp.sort((a2, b2) => b2.totalValueUsd - a2.totalValueUsd);
|
|
4599
4357
|
dashboardData.totalValueUsd = totalPortfolioValue;
|
|
4600
4358
|
dashboardData.networkPercentages = dashboardData.networks.map((network) => ({
|
|
4601
4359
|
networkId: network.networkId,
|
|
@@ -4618,7 +4376,7 @@ class SDK {
|
|
|
4618
4376
|
}
|
|
4619
4377
|
};
|
|
4620
4378
|
this.buildTx = async function(sendPayload) {
|
|
4621
|
-
let tag6 =
|
|
4379
|
+
let tag6 = TAG9 + " | buildTx | ";
|
|
4622
4380
|
try {
|
|
4623
4381
|
const transactionDependencies = {
|
|
4624
4382
|
context: this.context,
|
|
@@ -4640,7 +4398,7 @@ class SDK {
|
|
|
4640
4398
|
}
|
|
4641
4399
|
};
|
|
4642
4400
|
this.buildDelegateTx = async function(caip, params) {
|
|
4643
|
-
let tag6 =
|
|
4401
|
+
let tag6 = TAG9 + " | buildDelegateTx | ";
|
|
4644
4402
|
try {
|
|
4645
4403
|
const delegateParams = {
|
|
4646
4404
|
...params,
|
|
@@ -4655,7 +4413,7 @@ class SDK {
|
|
|
4655
4413
|
}
|
|
4656
4414
|
};
|
|
4657
4415
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4658
|
-
let tag6 =
|
|
4416
|
+
let tag6 = TAG9 + " | buildUndelegateTx | ";
|
|
4659
4417
|
try {
|
|
4660
4418
|
const undelegateParams = {
|
|
4661
4419
|
...params,
|
|
@@ -4670,7 +4428,7 @@ class SDK {
|
|
|
4670
4428
|
}
|
|
4671
4429
|
};
|
|
4672
4430
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4673
|
-
let tag6 =
|
|
4431
|
+
let tag6 = TAG9 + " | buildClaimRewardsTx | ";
|
|
4674
4432
|
try {
|
|
4675
4433
|
const claimParams = {
|
|
4676
4434
|
...params,
|
|
@@ -4685,7 +4443,7 @@ class SDK {
|
|
|
4685
4443
|
}
|
|
4686
4444
|
};
|
|
4687
4445
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4688
|
-
let tag6 =
|
|
4446
|
+
let tag6 = TAG9 + " | buildClaimAllRewardsTx | ";
|
|
4689
4447
|
try {
|
|
4690
4448
|
const claimAllParams = {
|
|
4691
4449
|
...params,
|
|
@@ -4699,7 +4457,7 @@ class SDK {
|
|
|
4699
4457
|
}
|
|
4700
4458
|
};
|
|
4701
4459
|
this.signTx = async function(caip, unsignedTx) {
|
|
4702
|
-
let tag6 =
|
|
4460
|
+
let tag6 = TAG9 + " | signTx | ";
|
|
4703
4461
|
try {
|
|
4704
4462
|
const transactionDependencies = {
|
|
4705
4463
|
context: this.context,
|
|
@@ -4720,7 +4478,7 @@ class SDK {
|
|
|
4720
4478
|
}
|
|
4721
4479
|
};
|
|
4722
4480
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4723
|
-
let tag6 =
|
|
4481
|
+
let tag6 = TAG9 + " | broadcastTx | ";
|
|
4724
4482
|
try {
|
|
4725
4483
|
const transactionDependencies = {
|
|
4726
4484
|
context: this.context,
|
|
@@ -4744,7 +4502,7 @@ class SDK {
|
|
|
4744
4502
|
}
|
|
4745
4503
|
};
|
|
4746
4504
|
this.swap = async function(swapPayload) {
|
|
4747
|
-
let tag6 = `${
|
|
4505
|
+
let tag6 = `${TAG9} | swap | `;
|
|
4748
4506
|
try {
|
|
4749
4507
|
if (!swapPayload)
|
|
4750
4508
|
throw Error("swapPayload required!");
|
|
@@ -4883,7 +4641,7 @@ class SDK {
|
|
|
4883
4641
|
}
|
|
4884
4642
|
};
|
|
4885
4643
|
this.transfer = async function(sendPayload) {
|
|
4886
|
-
let tag6 = `${
|
|
4644
|
+
let tag6 = `${TAG9} | transfer | `;
|
|
4887
4645
|
try {
|
|
4888
4646
|
if (!sendPayload)
|
|
4889
4647
|
throw Error("sendPayload required!");
|
|
@@ -4978,7 +4736,7 @@ class SDK {
|
|
|
4978
4736
|
}
|
|
4979
4737
|
};
|
|
4980
4738
|
this.setBlockchains = async function(blockchains) {
|
|
4981
|
-
const tag6 = `${
|
|
4739
|
+
const tag6 = `${TAG9} | setBlockchains | `;
|
|
4982
4740
|
try {
|
|
4983
4741
|
if (!blockchains)
|
|
4984
4742
|
throw Error("blockchains required!");
|
|
@@ -4994,7 +4752,7 @@ class SDK {
|
|
|
4994
4752
|
}
|
|
4995
4753
|
};
|
|
4996
4754
|
this.addAsset = async function(caip, data) {
|
|
4997
|
-
let tag6 =
|
|
4755
|
+
let tag6 = TAG9 + " | addAsset | ";
|
|
4998
4756
|
try {
|
|
4999
4757
|
let success = false;
|
|
5000
4758
|
if (!caip)
|
|
@@ -5032,7 +4790,7 @@ class SDK {
|
|
|
5032
4790
|
}
|
|
5033
4791
|
};
|
|
5034
4792
|
this.clearWalletState = async function() {
|
|
5035
|
-
const tag6 = `${
|
|
4793
|
+
const tag6 = `${TAG9} | clearWalletState | `;
|
|
5036
4794
|
try {
|
|
5037
4795
|
this.context = null;
|
|
5038
4796
|
this.paths = [];
|
|
@@ -5047,7 +4805,7 @@ class SDK {
|
|
|
5047
4805
|
}
|
|
5048
4806
|
};
|
|
5049
4807
|
this.addPath = async function(path) {
|
|
5050
|
-
const tag6 = `${
|
|
4808
|
+
const tag6 = `${TAG9} | addPath | `;
|
|
5051
4809
|
try {
|
|
5052
4810
|
this.paths.push(path);
|
|
5053
4811
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -5061,7 +4819,7 @@ class SDK {
|
|
|
5061
4819
|
}
|
|
5062
4820
|
};
|
|
5063
4821
|
this.addPaths = async function(paths) {
|
|
5064
|
-
const tag6 = `${
|
|
4822
|
+
const tag6 = `${TAG9} | addPaths | `;
|
|
5065
4823
|
try {
|
|
5066
4824
|
console.log(tag6, `Adding ${paths.length} paths in batch mode...`);
|
|
5067
4825
|
this.paths.push(...paths);
|
|
@@ -5097,7 +4855,7 @@ class SDK {
|
|
|
5097
4855
|
return this.getGasAssets();
|
|
5098
4856
|
};
|
|
5099
4857
|
this.getGasAssets = async function() {
|
|
5100
|
-
const tag6 = `${
|
|
4858
|
+
const tag6 = `${TAG9} | getGasAssets | `;
|
|
5101
4859
|
try {
|
|
5102
4860
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
5103
4861
|
let networkId = this.blockchains[i];
|
|
@@ -5140,7 +4898,7 @@ class SDK {
|
|
|
5140
4898
|
}
|
|
5141
4899
|
};
|
|
5142
4900
|
this.getPubkeys = async function() {
|
|
5143
|
-
const tag6 = `${
|
|
4901
|
+
const tag6 = `${TAG9} | getPubkeys | `;
|
|
5144
4902
|
try {
|
|
5145
4903
|
if (this.paths.length === 0)
|
|
5146
4904
|
throw new Error("No paths found!");
|
|
@@ -5161,7 +4919,7 @@ class SDK {
|
|
|
5161
4919
|
}
|
|
5162
4920
|
};
|
|
5163
4921
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
5164
|
-
const tag6 = `${
|
|
4922
|
+
const tag6 = `${TAG9} | getBalancesForNetworks | `;
|
|
5165
4923
|
try {
|
|
5166
4924
|
if (!this.pioneer) {
|
|
5167
4925
|
console.error(tag6, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -5189,9 +4947,6 @@ class SDK {
|
|
|
5189
4947
|
let marketInfo = await this.pioneer.GetPortfolioBalances(assetQuery);
|
|
5190
4948
|
console.timeEnd("GetPortfolioBalances Response Time");
|
|
5191
4949
|
let balances = marketInfo.data;
|
|
5192
|
-
const bitcoinBalances = balances.filter((b3) => b3.caip === "bip122:000000000019d6689c085ae165831e93/slip44:0");
|
|
5193
|
-
if (bitcoinBalances.length > 0) {
|
|
5194
|
-
}
|
|
5195
4950
|
for (let balance of balances) {
|
|
5196
4951
|
const assetInfo = this.assetsMap.get(balance.caip);
|
|
5197
4952
|
if (!assetInfo)
|
|
@@ -5199,10 +4954,10 @@ class SDK {
|
|
|
5199
4954
|
Object.assign(balance, assetInfo, {
|
|
5200
4955
|
networkId: caipToNetworkId7(balance.caip),
|
|
5201
4956
|
icon: assetInfo.icon || "https://pioneers.dev/coins/etherum.png",
|
|
5202
|
-
identifier: `${balance.caip}:${balance.pubkey}
|
|
4957
|
+
identifier: `${balance.caip}:${balance.pubkey}`,
|
|
4958
|
+
updated: Date.now()
|
|
5203
4959
|
});
|
|
5204
4960
|
}
|
|
5205
|
-
console.log(tag6, "balances: ", balances);
|
|
5206
4961
|
this.balances = balances;
|
|
5207
4962
|
this.events.emit("SET_BALANCES", this.balances);
|
|
5208
4963
|
return this.balances;
|
|
@@ -5216,7 +4971,7 @@ class SDK {
|
|
|
5216
4971
|
}
|
|
5217
4972
|
};
|
|
5218
4973
|
this.getBalances = async function() {
|
|
5219
|
-
const tag6 = `${
|
|
4974
|
+
const tag6 = `${TAG9} | getBalances | `;
|
|
5220
4975
|
try {
|
|
5221
4976
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
5222
4977
|
} catch (e) {
|
|
@@ -5225,10 +4980,10 @@ class SDK {
|
|
|
5225
4980
|
}
|
|
5226
4981
|
};
|
|
5227
4982
|
this.getBalance = async function(networkId) {
|
|
5228
|
-
const tag6 = `${
|
|
4983
|
+
const tag6 = `${TAG9} | getBalance | `;
|
|
5229
4984
|
try {
|
|
5230
4985
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
5231
|
-
const filtered = results.filter(async (
|
|
4986
|
+
const filtered = results.filter(async (b2) => b2.networkId === await networkIdToCaip2(networkId));
|
|
5232
4987
|
return filtered;
|
|
5233
4988
|
} catch (e) {
|
|
5234
4989
|
console.error(tag6, "Error: ", e);
|
|
@@ -5236,7 +4991,7 @@ class SDK {
|
|
|
5236
4991
|
}
|
|
5237
4992
|
};
|
|
5238
4993
|
this.getFees = async function(networkId) {
|
|
5239
|
-
const tag6 = `${
|
|
4994
|
+
const tag6 = `${TAG9} | getFees | `;
|
|
5240
4995
|
try {
|
|
5241
4996
|
if (!this.pioneer) {
|
|
5242
4997
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -5251,7 +5006,7 @@ class SDK {
|
|
|
5251
5006
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
5252
5007
|
};
|
|
5253
5008
|
this.getCharts = async function() {
|
|
5254
|
-
const tag6 = `${
|
|
5009
|
+
const tag6 = `${TAG9} | getCharts | `;
|
|
5255
5010
|
try {
|
|
5256
5011
|
console.log(tag6, "Fetching charts");
|
|
5257
5012
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -5273,7 +5028,7 @@ class SDK {
|
|
|
5273
5028
|
}
|
|
5274
5029
|
};
|
|
5275
5030
|
this.setContext = async (context) => {
|
|
5276
|
-
const tag6 = `${
|
|
5031
|
+
const tag6 = `${TAG9} | setContext | `;
|
|
5277
5032
|
try {
|
|
5278
5033
|
if (!context)
|
|
5279
5034
|
throw Error("context required!");
|
|
@@ -5286,7 +5041,7 @@ class SDK {
|
|
|
5286
5041
|
}
|
|
5287
5042
|
};
|
|
5288
5043
|
this.setContextType = async (contextType) => {
|
|
5289
|
-
const tag6 = `${
|
|
5044
|
+
const tag6 = `${TAG9} | setContextType | `;
|
|
5290
5045
|
try {
|
|
5291
5046
|
if (!contextType)
|
|
5292
5047
|
throw Error("contextType required!");
|
|
@@ -5299,7 +5054,7 @@ class SDK {
|
|
|
5299
5054
|
}
|
|
5300
5055
|
};
|
|
5301
5056
|
this.refresh = async () => {
|
|
5302
|
-
const tag6 = `${
|
|
5057
|
+
const tag6 = `${TAG9} | refresh | `;
|
|
5303
5058
|
try {
|
|
5304
5059
|
await this.sync();
|
|
5305
5060
|
return this.balances;
|
|
@@ -5309,7 +5064,7 @@ class SDK {
|
|
|
5309
5064
|
}
|
|
5310
5065
|
};
|
|
5311
5066
|
this.setAssetContext = async function(asset) {
|
|
5312
|
-
const tag6 = `${
|
|
5067
|
+
const tag6 = `${TAG9} | setAssetContext | `;
|
|
5313
5068
|
try {
|
|
5314
5069
|
if (!asset) {
|
|
5315
5070
|
this.assetContext = null;
|
|
@@ -5338,20 +5093,20 @@ class SDK {
|
|
|
5338
5093
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no address/xpub found for network ${asset.networkId}`;
|
|
5339
5094
|
console.error(tag6, errorMsg);
|
|
5340
5095
|
console.error(tag6, "Available networks in pubkeys:", [
|
|
5341
|
-
...new Set(this.pubkeys.flatMap((
|
|
5096
|
+
...new Set(this.pubkeys.flatMap((p) => p.networks || []))
|
|
5342
5097
|
]);
|
|
5343
5098
|
throw new Error(errorMsg);
|
|
5344
5099
|
}
|
|
5345
5100
|
const isUtxoChain = asset.networkId.startsWith("bip122:");
|
|
5346
5101
|
if (isUtxoChain) {
|
|
5347
|
-
const xpubFound = pubkeysForNetwork.some((
|
|
5102
|
+
const xpubFound = pubkeysForNetwork.some((p) => p.type === "xpub" && p.pubkey);
|
|
5348
5103
|
if (!xpubFound) {
|
|
5349
5104
|
const errorMsg = `Cannot set asset context for UTXO chain ${asset.caip} - xpub required but not found`;
|
|
5350
5105
|
console.error(tag6, errorMsg);
|
|
5351
5106
|
throw new Error(errorMsg);
|
|
5352
5107
|
}
|
|
5353
5108
|
}
|
|
5354
|
-
const hasValidAddress = pubkeysForNetwork.some((
|
|
5109
|
+
const hasValidAddress = pubkeysForNetwork.some((p) => p.address || p.master || p.pubkey);
|
|
5355
5110
|
if (!hasValidAddress) {
|
|
5356
5111
|
const errorMsg = `Cannot set asset context for ${asset.caip} - no valid address found in pubkeys`;
|
|
5357
5112
|
console.error(tag6, errorMsg);
|
|
@@ -5392,7 +5147,7 @@ class SDK {
|
|
|
5392
5147
|
icon: asset.icon || "https://pioneers.dev/coins/ethereum.png"
|
|
5393
5148
|
};
|
|
5394
5149
|
}
|
|
5395
|
-
const matchingBalances = this.balances.filter((
|
|
5150
|
+
const matchingBalances = this.balances.filter((b2) => b2.caip === asset.caip);
|
|
5396
5151
|
if (matchingBalances.length > 0) {
|
|
5397
5152
|
let priceValue = matchingBalances[0].priceUsd || matchingBalances[0].price;
|
|
5398
5153
|
if ((!priceValue || priceValue === 0) && matchingBalances[0].valueUsd && matchingBalances[0].balance) {
|
|
@@ -5425,8 +5180,8 @@ class SDK {
|
|
|
5425
5180
|
assetInfo.valueUsd = totalValueUsd.toFixed(2);
|
|
5426
5181
|
console.log(tag6, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
5427
5182
|
}
|
|
5428
|
-
const assetBalances = this.balances.filter((
|
|
5429
|
-
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")));
|
|
5430
5185
|
const finalAssetContext = {
|
|
5431
5186
|
...assetInfo,
|
|
5432
5187
|
...asset,
|
|
@@ -5477,7 +5232,7 @@ class SDK {
|
|
|
5477
5232
|
}
|
|
5478
5233
|
this.assetContext.nativeSymbol = nativeSymbol;
|
|
5479
5234
|
if (nativeCaip) {
|
|
5480
|
-
const nativeBalance = this.balances.find((
|
|
5235
|
+
const nativeBalance = this.balances.find((b2) => b2.caip === nativeCaip);
|
|
5481
5236
|
if (nativeBalance) {
|
|
5482
5237
|
this.assetContext.nativeBalance = nativeBalance.balance || "0";
|
|
5483
5238
|
} else {
|
|
@@ -5508,7 +5263,7 @@ class SDK {
|
|
|
5508
5263
|
}
|
|
5509
5264
|
};
|
|
5510
5265
|
this.setPubkeyContext = async function(pubkey) {
|
|
5511
|
-
let tag6 = `${
|
|
5266
|
+
let tag6 = `${TAG9} | setPubkeyContext | `;
|
|
5512
5267
|
try {
|
|
5513
5268
|
if (!pubkey)
|
|
5514
5269
|
throw Error("pubkey is required");
|
|
@@ -5527,7 +5282,7 @@ class SDK {
|
|
|
5527
5282
|
}
|
|
5528
5283
|
};
|
|
5529
5284
|
this.setOutboundAssetContext = async function(asset) {
|
|
5530
|
-
const tag6 = `${
|
|
5285
|
+
const tag6 = `${TAG9} | setOutputAssetContext | `;
|
|
5531
5286
|
try {
|
|
5532
5287
|
console.log(tag6, "0. asset: ", asset);
|
|
5533
5288
|
if (!asset) {
|
|
@@ -5541,12 +5296,12 @@ class SDK {
|
|
|
5541
5296
|
asset.networkId = caipToNetworkId7(asset.caip);
|
|
5542
5297
|
console.log(tag6, "networkId: ", asset.networkId);
|
|
5543
5298
|
console.log(tag6, "this.pubkeys: ", this.pubkeys);
|
|
5544
|
-
const pubkey = this.pubkeys.find((
|
|
5545
|
-
if (!
|
|
5299
|
+
const pubkey = this.pubkeys.find((p) => {
|
|
5300
|
+
if (!p.networks || !Array.isArray(p.networks))
|
|
5546
5301
|
return false;
|
|
5547
|
-
if (
|
|
5302
|
+
if (p.networks.includes(asset.networkId))
|
|
5548
5303
|
return true;
|
|
5549
|
-
if (asset.networkId.startsWith("eip155:") &&
|
|
5304
|
+
if (asset.networkId.startsWith("eip155:") && p.networks.includes("eip155:*"))
|
|
5550
5305
|
return true;
|
|
5551
5306
|
return false;
|
|
5552
5307
|
});
|
|
@@ -5581,7 +5336,7 @@ class SDK {
|
|
|
5581
5336
|
icon: asset.icon || "https://pioneers.dev/coins/ethereum.png"
|
|
5582
5337
|
};
|
|
5583
5338
|
}
|
|
5584
|
-
const matchingBalances = this.balances.filter((
|
|
5339
|
+
const matchingBalances = this.balances.filter((b2) => b2.caip === asset.caip);
|
|
5585
5340
|
if (matchingBalances.length > 0) {
|
|
5586
5341
|
let priceValue = matchingBalances[0].priceUsd || matchingBalances[0].price;
|
|
5587
5342
|
if ((!priceValue || priceValue === 0) && matchingBalances[0].valueUsd && matchingBalances[0].balance) {
|