@pioneer-platform/pioneer-sdk 4.20.6 → 4.20.7
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 +87 -81
- package/dist/index.es.js +87 -81
- package/dist/index.js +87 -81
- package/package.json +6 -6
- package/src/index.ts +2 -79
- package/src/utils/sync-market.ts +86 -0
package/dist/index.cjs
CHANGED
|
@@ -3531,8 +3531,62 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3531
3531
|
return dashboardData;
|
|
3532
3532
|
}
|
|
3533
3533
|
|
|
3534
|
+
// src/utils/sync-market.ts
|
|
3535
|
+
var TAG8 = " | sync-market | ";
|
|
3536
|
+
async function syncMarket(balances, pioneer) {
|
|
3537
|
+
const tag5 = `${TAG8} | syncMarket | `;
|
|
3538
|
+
try {
|
|
3539
|
+
const invalidBalances = balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
3540
|
+
if (invalidBalances.length > 0) {
|
|
3541
|
+
console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b2) => ({
|
|
3542
|
+
caip: b2?.caip,
|
|
3543
|
+
type: typeof b2?.caip,
|
|
3544
|
+
symbol: b2?.symbol,
|
|
3545
|
+
balance: b2?.balance
|
|
3546
|
+
})));
|
|
3547
|
+
}
|
|
3548
|
+
let allCaips = balances.filter((b2) => b2 && b2.caip && typeof b2.caip === "string" && b2.caip.trim().length > 0).map((b2) => b2.caip);
|
|
3549
|
+
allCaips = [...new Set(allCaips)];
|
|
3550
|
+
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
3551
|
+
console.log("GetMarketInfo: payload: ", allCaips);
|
|
3552
|
+
console.log("GetMarketInfo: payload type: ", typeof allCaips);
|
|
3553
|
+
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
3554
|
+
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
3555
|
+
if (invalidEntries.length > 0) {
|
|
3556
|
+
console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
3557
|
+
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
3558
|
+
}
|
|
3559
|
+
if (allCaips && allCaips.length > 0) {
|
|
3560
|
+
try {
|
|
3561
|
+
let allPrices = await pioneer.GetMarketInfo(allCaips);
|
|
3562
|
+
console.log("GetMarketInfo: response: ", allPrices);
|
|
3563
|
+
const priceMap = {};
|
|
3564
|
+
if (allPrices && allPrices.data) {
|
|
3565
|
+
for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
|
|
3566
|
+
priceMap[allCaips[i]] = allPrices.data[i];
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
for (let balance of balances) {
|
|
3570
|
+
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
3571
|
+
balance.price = priceMap[balance.caip];
|
|
3572
|
+
balance.priceUsd = priceMap[balance.caip];
|
|
3573
|
+
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
} catch (apiError) {
|
|
3577
|
+
console.error(tag5, "API error fetching market info:", apiError);
|
|
3578
|
+
console.warn(tag5, "Continuing without market prices");
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
return true;
|
|
3582
|
+
} catch (e) {
|
|
3583
|
+
console.error(tag5, "e:", e);
|
|
3584
|
+
throw e;
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3534
3588
|
// src/index.ts
|
|
3535
|
-
var
|
|
3589
|
+
var TAG9 = " | Pioneer-sdk | ";
|
|
3536
3590
|
|
|
3537
3591
|
class SDK {
|
|
3538
3592
|
status;
|
|
@@ -3696,7 +3750,7 @@ class SDK {
|
|
|
3696
3750
|
return true;
|
|
3697
3751
|
};
|
|
3698
3752
|
this.setPubkeys = (newPubkeys) => {
|
|
3699
|
-
const tag5 = `${
|
|
3753
|
+
const tag5 = `${TAG9} | setPubkeys | `;
|
|
3700
3754
|
this.pubkeys = [];
|
|
3701
3755
|
this.pubkeySet.clear();
|
|
3702
3756
|
let added = 0;
|
|
@@ -3707,7 +3761,7 @@ class SDK {
|
|
|
3707
3761
|
}
|
|
3708
3762
|
};
|
|
3709
3763
|
this.getUnifiedPortfolio = async function() {
|
|
3710
|
-
const tag5 = `${
|
|
3764
|
+
const tag5 = `${TAG9} | getUnifiedPortfolio | `;
|
|
3711
3765
|
try {
|
|
3712
3766
|
const startTime = performance.now();
|
|
3713
3767
|
try {
|
|
@@ -3815,7 +3869,7 @@ class SDK {
|
|
|
3815
3869
|
}
|
|
3816
3870
|
};
|
|
3817
3871
|
this.init = async function(walletsVerbose, setup) {
|
|
3818
|
-
const tag5 = `${
|
|
3872
|
+
const tag5 = `${TAG9} | init | `;
|
|
3819
3873
|
try {
|
|
3820
3874
|
if (!this.username)
|
|
3821
3875
|
throw Error("username required!");
|
|
@@ -3906,58 +3960,10 @@ class SDK {
|
|
|
3906
3960
|
return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
|
|
3907
3961
|
};
|
|
3908
3962
|
this.syncMarket = async function() {
|
|
3909
|
-
|
|
3910
|
-
try {
|
|
3911
|
-
const invalidBalances = this.balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
|
|
3912
|
-
if (invalidBalances.length > 0) {
|
|
3913
|
-
console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b2) => ({
|
|
3914
|
-
caip: b2?.caip,
|
|
3915
|
-
type: typeof b2?.caip,
|
|
3916
|
-
symbol: b2?.symbol,
|
|
3917
|
-
balance: b2?.balance
|
|
3918
|
-
})));
|
|
3919
|
-
}
|
|
3920
|
-
let allCaips = this.balances.filter((b2) => b2 && b2.caip && typeof b2.caip === "string" && b2.caip.trim().length > 0).map((b2) => b2.caip);
|
|
3921
|
-
allCaips = [...new Set(allCaips)];
|
|
3922
|
-
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
3923
|
-
console.log("GetMarketInfo: payload: ", allCaips);
|
|
3924
|
-
console.log("GetMarketInfo: payload type: ", typeof allCaips);
|
|
3925
|
-
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
3926
|
-
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
3927
|
-
if (invalidEntries.length > 0) {
|
|
3928
|
-
console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
3929
|
-
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
3930
|
-
}
|
|
3931
|
-
if (allCaips && allCaips.length > 0) {
|
|
3932
|
-
try {
|
|
3933
|
-
let allPrices = await this.pioneer.GetMarketInfo(allCaips);
|
|
3934
|
-
console.log("GetMarketInfo: response: ", allPrices);
|
|
3935
|
-
const priceMap = {};
|
|
3936
|
-
if (allPrices && allPrices.data) {
|
|
3937
|
-
for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
|
|
3938
|
-
priceMap[allCaips[i]] = allPrices.data[i];
|
|
3939
|
-
}
|
|
3940
|
-
}
|
|
3941
|
-
for (let balance of this.balances) {
|
|
3942
|
-
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
3943
|
-
balance.price = priceMap[balance.caip];
|
|
3944
|
-
balance.priceUsd = priceMap[balance.caip];
|
|
3945
|
-
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
3946
|
-
}
|
|
3947
|
-
}
|
|
3948
|
-
} catch (apiError) {
|
|
3949
|
-
console.error(tag5, "API error fetching market info:", apiError);
|
|
3950
|
-
console.warn(tag5, "Continuing without market prices");
|
|
3951
|
-
}
|
|
3952
|
-
}
|
|
3953
|
-
return true;
|
|
3954
|
-
} catch (e) {
|
|
3955
|
-
console.error(tag5, "e:", e);
|
|
3956
|
-
throw e;
|
|
3957
|
-
}
|
|
3963
|
+
return syncMarket(this.balances, this.pioneer);
|
|
3958
3964
|
};
|
|
3959
3965
|
this.sync = async function() {
|
|
3960
|
-
const tag5 = `${
|
|
3966
|
+
const tag5 = `${TAG9} | sync | `;
|
|
3961
3967
|
try {
|
|
3962
3968
|
const matchesNetwork = (item, networkId) => {
|
|
3963
3969
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4110,7 +4116,7 @@ class SDK {
|
|
|
4110
4116
|
}
|
|
4111
4117
|
};
|
|
4112
4118
|
this.buildTx = async function(sendPayload) {
|
|
4113
|
-
let tag5 =
|
|
4119
|
+
let tag5 = TAG9 + " | buildTx | ";
|
|
4114
4120
|
try {
|
|
4115
4121
|
const transactionDependencies = {
|
|
4116
4122
|
context: this.context,
|
|
@@ -4132,7 +4138,7 @@ class SDK {
|
|
|
4132
4138
|
}
|
|
4133
4139
|
};
|
|
4134
4140
|
this.buildDelegateTx = async function(caip, params) {
|
|
4135
|
-
let tag5 =
|
|
4141
|
+
let tag5 = TAG9 + " | buildDelegateTx | ";
|
|
4136
4142
|
try {
|
|
4137
4143
|
const delegateParams = {
|
|
4138
4144
|
...params,
|
|
@@ -4147,7 +4153,7 @@ class SDK {
|
|
|
4147
4153
|
}
|
|
4148
4154
|
};
|
|
4149
4155
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4150
|
-
let tag5 =
|
|
4156
|
+
let tag5 = TAG9 + " | buildUndelegateTx | ";
|
|
4151
4157
|
try {
|
|
4152
4158
|
const undelegateParams = {
|
|
4153
4159
|
...params,
|
|
@@ -4162,7 +4168,7 @@ class SDK {
|
|
|
4162
4168
|
}
|
|
4163
4169
|
};
|
|
4164
4170
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4165
|
-
let tag5 =
|
|
4171
|
+
let tag5 = TAG9 + " | buildClaimRewardsTx | ";
|
|
4166
4172
|
try {
|
|
4167
4173
|
const claimParams = {
|
|
4168
4174
|
...params,
|
|
@@ -4177,7 +4183,7 @@ class SDK {
|
|
|
4177
4183
|
}
|
|
4178
4184
|
};
|
|
4179
4185
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4180
|
-
let tag5 =
|
|
4186
|
+
let tag5 = TAG9 + " | buildClaimAllRewardsTx | ";
|
|
4181
4187
|
try {
|
|
4182
4188
|
const claimAllParams = {
|
|
4183
4189
|
...params,
|
|
@@ -4191,7 +4197,7 @@ class SDK {
|
|
|
4191
4197
|
}
|
|
4192
4198
|
};
|
|
4193
4199
|
this.signTx = async function(unsignedTx) {
|
|
4194
|
-
let tag5 =
|
|
4200
|
+
let tag5 = TAG9 + " | signTx | ";
|
|
4195
4201
|
try {
|
|
4196
4202
|
const transactionDependencies = {
|
|
4197
4203
|
context: this.context,
|
|
@@ -4212,7 +4218,7 @@ class SDK {
|
|
|
4212
4218
|
}
|
|
4213
4219
|
};
|
|
4214
4220
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4215
|
-
let tag5 =
|
|
4221
|
+
let tag5 = TAG9 + " | broadcastTx | ";
|
|
4216
4222
|
try {
|
|
4217
4223
|
const transactionDependencies = {
|
|
4218
4224
|
context: this.context,
|
|
@@ -4236,7 +4242,7 @@ class SDK {
|
|
|
4236
4242
|
}
|
|
4237
4243
|
};
|
|
4238
4244
|
this.swap = async function(swapPayload) {
|
|
4239
|
-
let tag5 = `${
|
|
4245
|
+
let tag5 = `${TAG9} | swap | `;
|
|
4240
4246
|
try {
|
|
4241
4247
|
if (!swapPayload)
|
|
4242
4248
|
throw Error("swapPayload required!");
|
|
@@ -4371,7 +4377,7 @@ class SDK {
|
|
|
4371
4377
|
}
|
|
4372
4378
|
};
|
|
4373
4379
|
this.transfer = async function(sendPayload) {
|
|
4374
|
-
let tag5 = `${
|
|
4380
|
+
let tag5 = `${TAG9} | transfer | `;
|
|
4375
4381
|
try {
|
|
4376
4382
|
if (!sendPayload)
|
|
4377
4383
|
throw Error("sendPayload required!");
|
|
@@ -4466,7 +4472,7 @@ class SDK {
|
|
|
4466
4472
|
}
|
|
4467
4473
|
};
|
|
4468
4474
|
this.setBlockchains = async function(blockchains) {
|
|
4469
|
-
const tag5 = `${
|
|
4475
|
+
const tag5 = `${TAG9} | setBlockchains | `;
|
|
4470
4476
|
try {
|
|
4471
4477
|
if (!blockchains)
|
|
4472
4478
|
throw Error("blockchains required!");
|
|
@@ -4482,7 +4488,7 @@ class SDK {
|
|
|
4482
4488
|
}
|
|
4483
4489
|
};
|
|
4484
4490
|
this.addAsset = async function(caip, data) {
|
|
4485
|
-
let tag5 =
|
|
4491
|
+
let tag5 = TAG9 + " | addAsset | ";
|
|
4486
4492
|
try {
|
|
4487
4493
|
let success = false;
|
|
4488
4494
|
if (!caip)
|
|
@@ -4520,7 +4526,7 @@ class SDK {
|
|
|
4520
4526
|
}
|
|
4521
4527
|
};
|
|
4522
4528
|
this.clearWalletState = async function() {
|
|
4523
|
-
const tag5 = `${
|
|
4529
|
+
const tag5 = `${TAG9} | clearWalletState | `;
|
|
4524
4530
|
try {
|
|
4525
4531
|
this.context = null;
|
|
4526
4532
|
this.paths = [];
|
|
@@ -4535,7 +4541,7 @@ class SDK {
|
|
|
4535
4541
|
}
|
|
4536
4542
|
};
|
|
4537
4543
|
this.addPath = async function(path) {
|
|
4538
|
-
const tag5 = `${
|
|
4544
|
+
const tag5 = `${TAG9} | addPath | `;
|
|
4539
4545
|
try {
|
|
4540
4546
|
this.paths.push(path);
|
|
4541
4547
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -4549,7 +4555,7 @@ class SDK {
|
|
|
4549
4555
|
}
|
|
4550
4556
|
};
|
|
4551
4557
|
this.addPaths = async function(paths) {
|
|
4552
|
-
const tag5 = `${
|
|
4558
|
+
const tag5 = `${TAG9} | addPaths | `;
|
|
4553
4559
|
try {
|
|
4554
4560
|
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4555
4561
|
this.paths.push(...paths);
|
|
@@ -4585,7 +4591,7 @@ class SDK {
|
|
|
4585
4591
|
return this.getGasAssets();
|
|
4586
4592
|
};
|
|
4587
4593
|
this.getGasAssets = async function() {
|
|
4588
|
-
const tag5 = `${
|
|
4594
|
+
const tag5 = `${TAG9} | getGasAssets | `;
|
|
4589
4595
|
try {
|
|
4590
4596
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4591
4597
|
let networkId = this.blockchains[i];
|
|
@@ -4628,7 +4634,7 @@ class SDK {
|
|
|
4628
4634
|
}
|
|
4629
4635
|
};
|
|
4630
4636
|
this.getPubkeys = async function() {
|
|
4631
|
-
const tag5 = `${
|
|
4637
|
+
const tag5 = `${TAG9} | getPubkeys | `;
|
|
4632
4638
|
try {
|
|
4633
4639
|
if (this.paths.length === 0)
|
|
4634
4640
|
throw new Error("No paths found!");
|
|
@@ -4649,7 +4655,7 @@ class SDK {
|
|
|
4649
4655
|
}
|
|
4650
4656
|
};
|
|
4651
4657
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4652
|
-
const tag5 = `${
|
|
4658
|
+
const tag5 = `${TAG9} | getBalancesForNetworks | `;
|
|
4653
4659
|
try {
|
|
4654
4660
|
if (!this.pioneer) {
|
|
4655
4661
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -4704,7 +4710,7 @@ class SDK {
|
|
|
4704
4710
|
}
|
|
4705
4711
|
};
|
|
4706
4712
|
this.getBalances = async function() {
|
|
4707
|
-
const tag5 = `${
|
|
4713
|
+
const tag5 = `${TAG9} | getBalances | `;
|
|
4708
4714
|
try {
|
|
4709
4715
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4710
4716
|
} catch (e) {
|
|
@@ -4713,7 +4719,7 @@ class SDK {
|
|
|
4713
4719
|
}
|
|
4714
4720
|
};
|
|
4715
4721
|
this.getBalance = async function(networkId) {
|
|
4716
|
-
const tag5 = `${
|
|
4722
|
+
const tag5 = `${TAG9} | getBalance | `;
|
|
4717
4723
|
try {
|
|
4718
4724
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4719
4725
|
const filtered = results.filter(async (b2) => b2.networkId === await import_pioneer_caip7.networkIdToCaip(networkId));
|
|
@@ -4724,7 +4730,7 @@ class SDK {
|
|
|
4724
4730
|
}
|
|
4725
4731
|
};
|
|
4726
4732
|
this.getFees = async function(networkId) {
|
|
4727
|
-
const tag5 = `${
|
|
4733
|
+
const tag5 = `${TAG9} | getFees | `;
|
|
4728
4734
|
try {
|
|
4729
4735
|
if (!this.pioneer) {
|
|
4730
4736
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -4739,7 +4745,7 @@ class SDK {
|
|
|
4739
4745
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
4740
4746
|
};
|
|
4741
4747
|
this.getCharts = async function() {
|
|
4742
|
-
const tag5 = `${
|
|
4748
|
+
const tag5 = `${TAG9} | getCharts | `;
|
|
4743
4749
|
try {
|
|
4744
4750
|
console.log(tag5, "Fetching charts");
|
|
4745
4751
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -4761,7 +4767,7 @@ class SDK {
|
|
|
4761
4767
|
}
|
|
4762
4768
|
};
|
|
4763
4769
|
this.setContext = async (context) => {
|
|
4764
|
-
const tag5 = `${
|
|
4770
|
+
const tag5 = `${TAG9} | setContext | `;
|
|
4765
4771
|
try {
|
|
4766
4772
|
if (!context)
|
|
4767
4773
|
throw Error("context required!");
|
|
@@ -4774,7 +4780,7 @@ class SDK {
|
|
|
4774
4780
|
}
|
|
4775
4781
|
};
|
|
4776
4782
|
this.setContextType = async (contextType) => {
|
|
4777
|
-
const tag5 = `${
|
|
4783
|
+
const tag5 = `${TAG9} | setContextType | `;
|
|
4778
4784
|
try {
|
|
4779
4785
|
if (!contextType)
|
|
4780
4786
|
throw Error("contextType required!");
|
|
@@ -4787,7 +4793,7 @@ class SDK {
|
|
|
4787
4793
|
}
|
|
4788
4794
|
};
|
|
4789
4795
|
this.refresh = async () => {
|
|
4790
|
-
const tag5 = `${
|
|
4796
|
+
const tag5 = `${TAG9} | refresh | `;
|
|
4791
4797
|
try {
|
|
4792
4798
|
await this.sync();
|
|
4793
4799
|
return this.balances;
|
|
@@ -4797,7 +4803,7 @@ class SDK {
|
|
|
4797
4803
|
}
|
|
4798
4804
|
};
|
|
4799
4805
|
this.setAssetContext = async function(asset) {
|
|
4800
|
-
const tag5 = `${
|
|
4806
|
+
const tag5 = `${TAG9} | setAssetContext | `;
|
|
4801
4807
|
try {
|
|
4802
4808
|
if (!asset) {
|
|
4803
4809
|
this.assetContext = null;
|
|
@@ -4996,7 +5002,7 @@ class SDK {
|
|
|
4996
5002
|
}
|
|
4997
5003
|
};
|
|
4998
5004
|
this.setPubkeyContext = async function(pubkey) {
|
|
4999
|
-
let tag5 = `${
|
|
5005
|
+
let tag5 = `${TAG9} | setPubkeyContext | `;
|
|
5000
5006
|
try {
|
|
5001
5007
|
if (!pubkey)
|
|
5002
5008
|
throw Error("pubkey is required");
|
|
@@ -5015,7 +5021,7 @@ class SDK {
|
|
|
5015
5021
|
}
|
|
5016
5022
|
};
|
|
5017
5023
|
this.setOutboundAssetContext = async function(asset) {
|
|
5018
|
-
const tag5 = `${
|
|
5024
|
+
const tag5 = `${TAG9} | setOutputAssetContext | `;
|
|
5019
5025
|
try {
|
|
5020
5026
|
console.log(tag5, "0. asset: ", asset);
|
|
5021
5027
|
if (!asset) {
|
package/dist/index.es.js
CHANGED
|
@@ -3707,8 +3707,62 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3707
3707
|
return dashboardData;
|
|
3708
3708
|
}
|
|
3709
3709
|
|
|
3710
|
+
// src/utils/sync-market.ts
|
|
3711
|
+
var TAG8 = " | sync-market | ";
|
|
3712
|
+
async function syncMarket(balances, pioneer) {
|
|
3713
|
+
const tag5 = `${TAG8} | syncMarket | `;
|
|
3714
|
+
try {
|
|
3715
|
+
const invalidBalances = balances.filter((b3) => !b3 || !b3.caip || typeof b3.caip !== "string" || !b3.caip.includes(":"));
|
|
3716
|
+
if (invalidBalances.length > 0) {
|
|
3717
|
+
console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b3) => ({
|
|
3718
|
+
caip: b3?.caip,
|
|
3719
|
+
type: typeof b3?.caip,
|
|
3720
|
+
symbol: b3?.symbol,
|
|
3721
|
+
balance: b3?.balance
|
|
3722
|
+
})));
|
|
3723
|
+
}
|
|
3724
|
+
let allCaips = balances.filter((b3) => b3 && b3.caip && typeof b3.caip === "string" && b3.caip.trim().length > 0).map((b3) => b3.caip);
|
|
3725
|
+
allCaips = [...new Set(allCaips)];
|
|
3726
|
+
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
3727
|
+
console.log("GetMarketInfo: payload: ", allCaips);
|
|
3728
|
+
console.log("GetMarketInfo: payload type: ", typeof allCaips);
|
|
3729
|
+
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
3730
|
+
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
3731
|
+
if (invalidEntries.length > 0) {
|
|
3732
|
+
console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
3733
|
+
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
3734
|
+
}
|
|
3735
|
+
if (allCaips && allCaips.length > 0) {
|
|
3736
|
+
try {
|
|
3737
|
+
let allPrices = await pioneer.GetMarketInfo(allCaips);
|
|
3738
|
+
console.log("GetMarketInfo: response: ", allPrices);
|
|
3739
|
+
const priceMap = {};
|
|
3740
|
+
if (allPrices && allPrices.data) {
|
|
3741
|
+
for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
|
|
3742
|
+
priceMap[allCaips[i]] = allPrices.data[i];
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
for (let balance of balances) {
|
|
3746
|
+
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
3747
|
+
balance.price = priceMap[balance.caip];
|
|
3748
|
+
balance.priceUsd = priceMap[balance.caip];
|
|
3749
|
+
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
} catch (apiError) {
|
|
3753
|
+
console.error(tag5, "API error fetching market info:", apiError);
|
|
3754
|
+
console.warn(tag5, "Continuing without market prices");
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
return true;
|
|
3758
|
+
} catch (e) {
|
|
3759
|
+
console.error(tag5, "e:", e);
|
|
3760
|
+
throw e;
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
|
|
3710
3764
|
// src/index.ts
|
|
3711
|
-
var
|
|
3765
|
+
var TAG9 = " | Pioneer-sdk | ";
|
|
3712
3766
|
|
|
3713
3767
|
class SDK {
|
|
3714
3768
|
status;
|
|
@@ -3872,7 +3926,7 @@ class SDK {
|
|
|
3872
3926
|
return true;
|
|
3873
3927
|
};
|
|
3874
3928
|
this.setPubkeys = (newPubkeys) => {
|
|
3875
|
-
const tag5 = `${
|
|
3929
|
+
const tag5 = `${TAG9} | setPubkeys | `;
|
|
3876
3930
|
this.pubkeys = [];
|
|
3877
3931
|
this.pubkeySet.clear();
|
|
3878
3932
|
let added = 0;
|
|
@@ -3883,7 +3937,7 @@ class SDK {
|
|
|
3883
3937
|
}
|
|
3884
3938
|
};
|
|
3885
3939
|
this.getUnifiedPortfolio = async function() {
|
|
3886
|
-
const tag5 = `${
|
|
3940
|
+
const tag5 = `${TAG9} | getUnifiedPortfolio | `;
|
|
3887
3941
|
try {
|
|
3888
3942
|
const startTime = performance.now();
|
|
3889
3943
|
try {
|
|
@@ -3991,7 +4045,7 @@ class SDK {
|
|
|
3991
4045
|
}
|
|
3992
4046
|
};
|
|
3993
4047
|
this.init = async function(walletsVerbose, setup) {
|
|
3994
|
-
const tag5 = `${
|
|
4048
|
+
const tag5 = `${TAG9} | init | `;
|
|
3995
4049
|
try {
|
|
3996
4050
|
if (!this.username)
|
|
3997
4051
|
throw Error("username required!");
|
|
@@ -4082,58 +4136,10 @@ class SDK {
|
|
|
4082
4136
|
return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
|
|
4083
4137
|
};
|
|
4084
4138
|
this.syncMarket = async function() {
|
|
4085
|
-
|
|
4086
|
-
try {
|
|
4087
|
-
const invalidBalances = this.balances.filter((b3) => !b3 || !b3.caip || typeof b3.caip !== "string" || !b3.caip.includes(":"));
|
|
4088
|
-
if (invalidBalances.length > 0) {
|
|
4089
|
-
console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b3) => ({
|
|
4090
|
-
caip: b3?.caip,
|
|
4091
|
-
type: typeof b3?.caip,
|
|
4092
|
-
symbol: b3?.symbol,
|
|
4093
|
-
balance: b3?.balance
|
|
4094
|
-
})));
|
|
4095
|
-
}
|
|
4096
|
-
let allCaips = this.balances.filter((b3) => b3 && b3.caip && typeof b3.caip === "string" && b3.caip.trim().length > 0).map((b3) => b3.caip);
|
|
4097
|
-
allCaips = [...new Set(allCaips)];
|
|
4098
|
-
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
4099
|
-
console.log("GetMarketInfo: payload: ", allCaips);
|
|
4100
|
-
console.log("GetMarketInfo: payload type: ", typeof allCaips);
|
|
4101
|
-
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
4102
|
-
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
4103
|
-
if (invalidEntries.length > 0) {
|
|
4104
|
-
console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
4105
|
-
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
4106
|
-
}
|
|
4107
|
-
if (allCaips && allCaips.length > 0) {
|
|
4108
|
-
try {
|
|
4109
|
-
let allPrices = await this.pioneer.GetMarketInfo(allCaips);
|
|
4110
|
-
console.log("GetMarketInfo: response: ", allPrices);
|
|
4111
|
-
const priceMap = {};
|
|
4112
|
-
if (allPrices && allPrices.data) {
|
|
4113
|
-
for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
|
|
4114
|
-
priceMap[allCaips[i]] = allPrices.data[i];
|
|
4115
|
-
}
|
|
4116
|
-
}
|
|
4117
|
-
for (let balance of this.balances) {
|
|
4118
|
-
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
4119
|
-
balance.price = priceMap[balance.caip];
|
|
4120
|
-
balance.priceUsd = priceMap[balance.caip];
|
|
4121
|
-
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
4122
|
-
}
|
|
4123
|
-
}
|
|
4124
|
-
} catch (apiError) {
|
|
4125
|
-
console.error(tag5, "API error fetching market info:", apiError);
|
|
4126
|
-
console.warn(tag5, "Continuing without market prices");
|
|
4127
|
-
}
|
|
4128
|
-
}
|
|
4129
|
-
return true;
|
|
4130
|
-
} catch (e) {
|
|
4131
|
-
console.error(tag5, "e:", e);
|
|
4132
|
-
throw e;
|
|
4133
|
-
}
|
|
4139
|
+
return syncMarket(this.balances, this.pioneer);
|
|
4134
4140
|
};
|
|
4135
4141
|
this.sync = async function() {
|
|
4136
|
-
const tag5 = `${
|
|
4142
|
+
const tag5 = `${TAG9} | sync | `;
|
|
4137
4143
|
try {
|
|
4138
4144
|
const matchesNetwork = (item, networkId) => {
|
|
4139
4145
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4286,7 +4292,7 @@ class SDK {
|
|
|
4286
4292
|
}
|
|
4287
4293
|
};
|
|
4288
4294
|
this.buildTx = async function(sendPayload) {
|
|
4289
|
-
let tag5 =
|
|
4295
|
+
let tag5 = TAG9 + " | buildTx | ";
|
|
4290
4296
|
try {
|
|
4291
4297
|
const transactionDependencies = {
|
|
4292
4298
|
context: this.context,
|
|
@@ -4308,7 +4314,7 @@ class SDK {
|
|
|
4308
4314
|
}
|
|
4309
4315
|
};
|
|
4310
4316
|
this.buildDelegateTx = async function(caip, params) {
|
|
4311
|
-
let tag5 =
|
|
4317
|
+
let tag5 = TAG9 + " | buildDelegateTx | ";
|
|
4312
4318
|
try {
|
|
4313
4319
|
const delegateParams = {
|
|
4314
4320
|
...params,
|
|
@@ -4323,7 +4329,7 @@ class SDK {
|
|
|
4323
4329
|
}
|
|
4324
4330
|
};
|
|
4325
4331
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4326
|
-
let tag5 =
|
|
4332
|
+
let tag5 = TAG9 + " | buildUndelegateTx | ";
|
|
4327
4333
|
try {
|
|
4328
4334
|
const undelegateParams = {
|
|
4329
4335
|
...params,
|
|
@@ -4338,7 +4344,7 @@ class SDK {
|
|
|
4338
4344
|
}
|
|
4339
4345
|
};
|
|
4340
4346
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4341
|
-
let tag5 =
|
|
4347
|
+
let tag5 = TAG9 + " | buildClaimRewardsTx | ";
|
|
4342
4348
|
try {
|
|
4343
4349
|
const claimParams = {
|
|
4344
4350
|
...params,
|
|
@@ -4353,7 +4359,7 @@ class SDK {
|
|
|
4353
4359
|
}
|
|
4354
4360
|
};
|
|
4355
4361
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4356
|
-
let tag5 =
|
|
4362
|
+
let tag5 = TAG9 + " | buildClaimAllRewardsTx | ";
|
|
4357
4363
|
try {
|
|
4358
4364
|
const claimAllParams = {
|
|
4359
4365
|
...params,
|
|
@@ -4367,7 +4373,7 @@ class SDK {
|
|
|
4367
4373
|
}
|
|
4368
4374
|
};
|
|
4369
4375
|
this.signTx = async function(unsignedTx) {
|
|
4370
|
-
let tag5 =
|
|
4376
|
+
let tag5 = TAG9 + " | signTx | ";
|
|
4371
4377
|
try {
|
|
4372
4378
|
const transactionDependencies = {
|
|
4373
4379
|
context: this.context,
|
|
@@ -4388,7 +4394,7 @@ class SDK {
|
|
|
4388
4394
|
}
|
|
4389
4395
|
};
|
|
4390
4396
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4391
|
-
let tag5 =
|
|
4397
|
+
let tag5 = TAG9 + " | broadcastTx | ";
|
|
4392
4398
|
try {
|
|
4393
4399
|
const transactionDependencies = {
|
|
4394
4400
|
context: this.context,
|
|
@@ -4412,7 +4418,7 @@ class SDK {
|
|
|
4412
4418
|
}
|
|
4413
4419
|
};
|
|
4414
4420
|
this.swap = async function(swapPayload) {
|
|
4415
|
-
let tag5 = `${
|
|
4421
|
+
let tag5 = `${TAG9} | swap | `;
|
|
4416
4422
|
try {
|
|
4417
4423
|
if (!swapPayload)
|
|
4418
4424
|
throw Error("swapPayload required!");
|
|
@@ -4547,7 +4553,7 @@ class SDK {
|
|
|
4547
4553
|
}
|
|
4548
4554
|
};
|
|
4549
4555
|
this.transfer = async function(sendPayload) {
|
|
4550
|
-
let tag5 = `${
|
|
4556
|
+
let tag5 = `${TAG9} | transfer | `;
|
|
4551
4557
|
try {
|
|
4552
4558
|
if (!sendPayload)
|
|
4553
4559
|
throw Error("sendPayload required!");
|
|
@@ -4642,7 +4648,7 @@ class SDK {
|
|
|
4642
4648
|
}
|
|
4643
4649
|
};
|
|
4644
4650
|
this.setBlockchains = async function(blockchains) {
|
|
4645
|
-
const tag5 = `${
|
|
4651
|
+
const tag5 = `${TAG9} | setBlockchains | `;
|
|
4646
4652
|
try {
|
|
4647
4653
|
if (!blockchains)
|
|
4648
4654
|
throw Error("blockchains required!");
|
|
@@ -4658,7 +4664,7 @@ class SDK {
|
|
|
4658
4664
|
}
|
|
4659
4665
|
};
|
|
4660
4666
|
this.addAsset = async function(caip, data) {
|
|
4661
|
-
let tag5 =
|
|
4667
|
+
let tag5 = TAG9 + " | addAsset | ";
|
|
4662
4668
|
try {
|
|
4663
4669
|
let success = false;
|
|
4664
4670
|
if (!caip)
|
|
@@ -4696,7 +4702,7 @@ class SDK {
|
|
|
4696
4702
|
}
|
|
4697
4703
|
};
|
|
4698
4704
|
this.clearWalletState = async function() {
|
|
4699
|
-
const tag5 = `${
|
|
4705
|
+
const tag5 = `${TAG9} | clearWalletState | `;
|
|
4700
4706
|
try {
|
|
4701
4707
|
this.context = null;
|
|
4702
4708
|
this.paths = [];
|
|
@@ -4711,7 +4717,7 @@ class SDK {
|
|
|
4711
4717
|
}
|
|
4712
4718
|
};
|
|
4713
4719
|
this.addPath = async function(path) {
|
|
4714
|
-
const tag5 = `${
|
|
4720
|
+
const tag5 = `${TAG9} | addPath | `;
|
|
4715
4721
|
try {
|
|
4716
4722
|
this.paths.push(path);
|
|
4717
4723
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -4725,7 +4731,7 @@ class SDK {
|
|
|
4725
4731
|
}
|
|
4726
4732
|
};
|
|
4727
4733
|
this.addPaths = async function(paths) {
|
|
4728
|
-
const tag5 = `${
|
|
4734
|
+
const tag5 = `${TAG9} | addPaths | `;
|
|
4729
4735
|
try {
|
|
4730
4736
|
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4731
4737
|
this.paths.push(...paths);
|
|
@@ -4761,7 +4767,7 @@ class SDK {
|
|
|
4761
4767
|
return this.getGasAssets();
|
|
4762
4768
|
};
|
|
4763
4769
|
this.getGasAssets = async function() {
|
|
4764
|
-
const tag5 = `${
|
|
4770
|
+
const tag5 = `${TAG9} | getGasAssets | `;
|
|
4765
4771
|
try {
|
|
4766
4772
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4767
4773
|
let networkId = this.blockchains[i];
|
|
@@ -4804,7 +4810,7 @@ class SDK {
|
|
|
4804
4810
|
}
|
|
4805
4811
|
};
|
|
4806
4812
|
this.getPubkeys = async function() {
|
|
4807
|
-
const tag5 = `${
|
|
4813
|
+
const tag5 = `${TAG9} | getPubkeys | `;
|
|
4808
4814
|
try {
|
|
4809
4815
|
if (this.paths.length === 0)
|
|
4810
4816
|
throw new Error("No paths found!");
|
|
@@ -4825,7 +4831,7 @@ class SDK {
|
|
|
4825
4831
|
}
|
|
4826
4832
|
};
|
|
4827
4833
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4828
|
-
const tag5 = `${
|
|
4834
|
+
const tag5 = `${TAG9} | getBalancesForNetworks | `;
|
|
4829
4835
|
try {
|
|
4830
4836
|
if (!this.pioneer) {
|
|
4831
4837
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -4880,7 +4886,7 @@ class SDK {
|
|
|
4880
4886
|
}
|
|
4881
4887
|
};
|
|
4882
4888
|
this.getBalances = async function() {
|
|
4883
|
-
const tag5 = `${
|
|
4889
|
+
const tag5 = `${TAG9} | getBalances | `;
|
|
4884
4890
|
try {
|
|
4885
4891
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4886
4892
|
} catch (e) {
|
|
@@ -4889,7 +4895,7 @@ class SDK {
|
|
|
4889
4895
|
}
|
|
4890
4896
|
};
|
|
4891
4897
|
this.getBalance = async function(networkId) {
|
|
4892
|
-
const tag5 = `${
|
|
4898
|
+
const tag5 = `${TAG9} | getBalance | `;
|
|
4893
4899
|
try {
|
|
4894
4900
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4895
4901
|
const filtered = results.filter(async (b3) => b3.networkId === await networkIdToCaip2(networkId));
|
|
@@ -4900,7 +4906,7 @@ class SDK {
|
|
|
4900
4906
|
}
|
|
4901
4907
|
};
|
|
4902
4908
|
this.getFees = async function(networkId) {
|
|
4903
|
-
const tag5 = `${
|
|
4909
|
+
const tag5 = `${TAG9} | getFees | `;
|
|
4904
4910
|
try {
|
|
4905
4911
|
if (!this.pioneer) {
|
|
4906
4912
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -4915,7 +4921,7 @@ class SDK {
|
|
|
4915
4921
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
4916
4922
|
};
|
|
4917
4923
|
this.getCharts = async function() {
|
|
4918
|
-
const tag5 = `${
|
|
4924
|
+
const tag5 = `${TAG9} | getCharts | `;
|
|
4919
4925
|
try {
|
|
4920
4926
|
console.log(tag5, "Fetching charts");
|
|
4921
4927
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -4937,7 +4943,7 @@ class SDK {
|
|
|
4937
4943
|
}
|
|
4938
4944
|
};
|
|
4939
4945
|
this.setContext = async (context) => {
|
|
4940
|
-
const tag5 = `${
|
|
4946
|
+
const tag5 = `${TAG9} | setContext | `;
|
|
4941
4947
|
try {
|
|
4942
4948
|
if (!context)
|
|
4943
4949
|
throw Error("context required!");
|
|
@@ -4950,7 +4956,7 @@ class SDK {
|
|
|
4950
4956
|
}
|
|
4951
4957
|
};
|
|
4952
4958
|
this.setContextType = async (contextType) => {
|
|
4953
|
-
const tag5 = `${
|
|
4959
|
+
const tag5 = `${TAG9} | setContextType | `;
|
|
4954
4960
|
try {
|
|
4955
4961
|
if (!contextType)
|
|
4956
4962
|
throw Error("contextType required!");
|
|
@@ -4963,7 +4969,7 @@ class SDK {
|
|
|
4963
4969
|
}
|
|
4964
4970
|
};
|
|
4965
4971
|
this.refresh = async () => {
|
|
4966
|
-
const tag5 = `${
|
|
4972
|
+
const tag5 = `${TAG9} | refresh | `;
|
|
4967
4973
|
try {
|
|
4968
4974
|
await this.sync();
|
|
4969
4975
|
return this.balances;
|
|
@@ -4973,7 +4979,7 @@ class SDK {
|
|
|
4973
4979
|
}
|
|
4974
4980
|
};
|
|
4975
4981
|
this.setAssetContext = async function(asset) {
|
|
4976
|
-
const tag5 = `${
|
|
4982
|
+
const tag5 = `${TAG9} | setAssetContext | `;
|
|
4977
4983
|
try {
|
|
4978
4984
|
if (!asset) {
|
|
4979
4985
|
this.assetContext = null;
|
|
@@ -5172,7 +5178,7 @@ class SDK {
|
|
|
5172
5178
|
}
|
|
5173
5179
|
};
|
|
5174
5180
|
this.setPubkeyContext = async function(pubkey) {
|
|
5175
|
-
let tag5 = `${
|
|
5181
|
+
let tag5 = `${TAG9} | setPubkeyContext | `;
|
|
5176
5182
|
try {
|
|
5177
5183
|
if (!pubkey)
|
|
5178
5184
|
throw Error("pubkey is required");
|
|
@@ -5191,7 +5197,7 @@ class SDK {
|
|
|
5191
5197
|
}
|
|
5192
5198
|
};
|
|
5193
5199
|
this.setOutboundAssetContext = async function(asset) {
|
|
5194
|
-
const tag5 = `${
|
|
5200
|
+
const tag5 = `${TAG9} | setOutputAssetContext | `;
|
|
5195
5201
|
try {
|
|
5196
5202
|
console.log(tag5, "0. asset: ", asset);
|
|
5197
5203
|
if (!asset) {
|
package/dist/index.js
CHANGED
|
@@ -3707,8 +3707,62 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
|
|
|
3707
3707
|
return dashboardData;
|
|
3708
3708
|
}
|
|
3709
3709
|
|
|
3710
|
+
// src/utils/sync-market.ts
|
|
3711
|
+
var TAG8 = " | sync-market | ";
|
|
3712
|
+
async function syncMarket(balances, pioneer) {
|
|
3713
|
+
const tag5 = `${TAG8} | syncMarket | `;
|
|
3714
|
+
try {
|
|
3715
|
+
const invalidBalances = balances.filter((b3) => !b3 || !b3.caip || typeof b3.caip !== "string" || !b3.caip.includes(":"));
|
|
3716
|
+
if (invalidBalances.length > 0) {
|
|
3717
|
+
console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b3) => ({
|
|
3718
|
+
caip: b3?.caip,
|
|
3719
|
+
type: typeof b3?.caip,
|
|
3720
|
+
symbol: b3?.symbol,
|
|
3721
|
+
balance: b3?.balance
|
|
3722
|
+
})));
|
|
3723
|
+
}
|
|
3724
|
+
let allCaips = balances.filter((b3) => b3 && b3.caip && typeof b3.caip === "string" && b3.caip.trim().length > 0).map((b3) => b3.caip);
|
|
3725
|
+
allCaips = [...new Set(allCaips)];
|
|
3726
|
+
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
3727
|
+
console.log("GetMarketInfo: payload: ", allCaips);
|
|
3728
|
+
console.log("GetMarketInfo: payload type: ", typeof allCaips);
|
|
3729
|
+
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
3730
|
+
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
3731
|
+
if (invalidEntries.length > 0) {
|
|
3732
|
+
console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
3733
|
+
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
3734
|
+
}
|
|
3735
|
+
if (allCaips && allCaips.length > 0) {
|
|
3736
|
+
try {
|
|
3737
|
+
let allPrices = await pioneer.GetMarketInfo(allCaips);
|
|
3738
|
+
console.log("GetMarketInfo: response: ", allPrices);
|
|
3739
|
+
const priceMap = {};
|
|
3740
|
+
if (allPrices && allPrices.data) {
|
|
3741
|
+
for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
|
|
3742
|
+
priceMap[allCaips[i]] = allPrices.data[i];
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
for (let balance of balances) {
|
|
3746
|
+
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
3747
|
+
balance.price = priceMap[balance.caip];
|
|
3748
|
+
balance.priceUsd = priceMap[balance.caip];
|
|
3749
|
+
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
} catch (apiError) {
|
|
3753
|
+
console.error(tag5, "API error fetching market info:", apiError);
|
|
3754
|
+
console.warn(tag5, "Continuing without market prices");
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
return true;
|
|
3758
|
+
} catch (e) {
|
|
3759
|
+
console.error(tag5, "e:", e);
|
|
3760
|
+
throw e;
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
|
|
3710
3764
|
// src/index.ts
|
|
3711
|
-
var
|
|
3765
|
+
var TAG9 = " | Pioneer-sdk | ";
|
|
3712
3766
|
|
|
3713
3767
|
class SDK {
|
|
3714
3768
|
status;
|
|
@@ -3872,7 +3926,7 @@ class SDK {
|
|
|
3872
3926
|
return true;
|
|
3873
3927
|
};
|
|
3874
3928
|
this.setPubkeys = (newPubkeys) => {
|
|
3875
|
-
const tag5 = `${
|
|
3929
|
+
const tag5 = `${TAG9} | setPubkeys | `;
|
|
3876
3930
|
this.pubkeys = [];
|
|
3877
3931
|
this.pubkeySet.clear();
|
|
3878
3932
|
let added = 0;
|
|
@@ -3883,7 +3937,7 @@ class SDK {
|
|
|
3883
3937
|
}
|
|
3884
3938
|
};
|
|
3885
3939
|
this.getUnifiedPortfolio = async function() {
|
|
3886
|
-
const tag5 = `${
|
|
3940
|
+
const tag5 = `${TAG9} | getUnifiedPortfolio | `;
|
|
3887
3941
|
try {
|
|
3888
3942
|
const startTime = performance.now();
|
|
3889
3943
|
try {
|
|
@@ -3991,7 +4045,7 @@ class SDK {
|
|
|
3991
4045
|
}
|
|
3992
4046
|
};
|
|
3993
4047
|
this.init = async function(walletsVerbose, setup) {
|
|
3994
|
-
const tag5 = `${
|
|
4048
|
+
const tag5 = `${TAG9} | init | `;
|
|
3995
4049
|
try {
|
|
3996
4050
|
if (!this.username)
|
|
3997
4051
|
throw Error("username required!");
|
|
@@ -4082,58 +4136,10 @@ class SDK {
|
|
|
4082
4136
|
return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
|
|
4083
4137
|
};
|
|
4084
4138
|
this.syncMarket = async function() {
|
|
4085
|
-
|
|
4086
|
-
try {
|
|
4087
|
-
const invalidBalances = this.balances.filter((b3) => !b3 || !b3.caip || typeof b3.caip !== "string" || !b3.caip.includes(":"));
|
|
4088
|
-
if (invalidBalances.length > 0) {
|
|
4089
|
-
console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b3) => ({
|
|
4090
|
-
caip: b3?.caip,
|
|
4091
|
-
type: typeof b3?.caip,
|
|
4092
|
-
symbol: b3?.symbol,
|
|
4093
|
-
balance: b3?.balance
|
|
4094
|
-
})));
|
|
4095
|
-
}
|
|
4096
|
-
let allCaips = this.balances.filter((b3) => b3 && b3.caip && typeof b3.caip === "string" && b3.caip.trim().length > 0).map((b3) => b3.caip);
|
|
4097
|
-
allCaips = [...new Set(allCaips)];
|
|
4098
|
-
allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
|
|
4099
|
-
console.log("GetMarketInfo: payload: ", allCaips);
|
|
4100
|
-
console.log("GetMarketInfo: payload type: ", typeof allCaips);
|
|
4101
|
-
console.log("GetMarketInfo: payload length: ", allCaips.length);
|
|
4102
|
-
const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
|
|
4103
|
-
if (invalidEntries.length > 0) {
|
|
4104
|
-
console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
|
|
4105
|
-
throw new Error("Invalid CAIP entries detected - aborting market sync");
|
|
4106
|
-
}
|
|
4107
|
-
if (allCaips && allCaips.length > 0) {
|
|
4108
|
-
try {
|
|
4109
|
-
let allPrices = await this.pioneer.GetMarketInfo(allCaips);
|
|
4110
|
-
console.log("GetMarketInfo: response: ", allPrices);
|
|
4111
|
-
const priceMap = {};
|
|
4112
|
-
if (allPrices && allPrices.data) {
|
|
4113
|
-
for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
|
|
4114
|
-
priceMap[allCaips[i]] = allPrices.data[i];
|
|
4115
|
-
}
|
|
4116
|
-
}
|
|
4117
|
-
for (let balance of this.balances) {
|
|
4118
|
-
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
4119
|
-
balance.price = priceMap[balance.caip];
|
|
4120
|
-
balance.priceUsd = priceMap[balance.caip];
|
|
4121
|
-
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
4122
|
-
}
|
|
4123
|
-
}
|
|
4124
|
-
} catch (apiError) {
|
|
4125
|
-
console.error(tag5, "API error fetching market info:", apiError);
|
|
4126
|
-
console.warn(tag5, "Continuing without market prices");
|
|
4127
|
-
}
|
|
4128
|
-
}
|
|
4129
|
-
return true;
|
|
4130
|
-
} catch (e) {
|
|
4131
|
-
console.error(tag5, "e:", e);
|
|
4132
|
-
throw e;
|
|
4133
|
-
}
|
|
4139
|
+
return syncMarket(this.balances, this.pioneer);
|
|
4134
4140
|
};
|
|
4135
4141
|
this.sync = async function() {
|
|
4136
|
-
const tag5 = `${
|
|
4142
|
+
const tag5 = `${TAG9} | sync | `;
|
|
4137
4143
|
try {
|
|
4138
4144
|
const matchesNetwork = (item, networkId) => {
|
|
4139
4145
|
if (!item.networks || !Array.isArray(item.networks))
|
|
@@ -4286,7 +4292,7 @@ class SDK {
|
|
|
4286
4292
|
}
|
|
4287
4293
|
};
|
|
4288
4294
|
this.buildTx = async function(sendPayload) {
|
|
4289
|
-
let tag5 =
|
|
4295
|
+
let tag5 = TAG9 + " | buildTx | ";
|
|
4290
4296
|
try {
|
|
4291
4297
|
const transactionDependencies = {
|
|
4292
4298
|
context: this.context,
|
|
@@ -4308,7 +4314,7 @@ class SDK {
|
|
|
4308
4314
|
}
|
|
4309
4315
|
};
|
|
4310
4316
|
this.buildDelegateTx = async function(caip, params) {
|
|
4311
|
-
let tag5 =
|
|
4317
|
+
let tag5 = TAG9 + " | buildDelegateTx | ";
|
|
4312
4318
|
try {
|
|
4313
4319
|
const delegateParams = {
|
|
4314
4320
|
...params,
|
|
@@ -4323,7 +4329,7 @@ class SDK {
|
|
|
4323
4329
|
}
|
|
4324
4330
|
};
|
|
4325
4331
|
this.buildUndelegateTx = async function(caip, params) {
|
|
4326
|
-
let tag5 =
|
|
4332
|
+
let tag5 = TAG9 + " | buildUndelegateTx | ";
|
|
4327
4333
|
try {
|
|
4328
4334
|
const undelegateParams = {
|
|
4329
4335
|
...params,
|
|
@@ -4338,7 +4344,7 @@ class SDK {
|
|
|
4338
4344
|
}
|
|
4339
4345
|
};
|
|
4340
4346
|
this.buildClaimRewardsTx = async function(caip, params) {
|
|
4341
|
-
let tag5 =
|
|
4347
|
+
let tag5 = TAG9 + " | buildClaimRewardsTx | ";
|
|
4342
4348
|
try {
|
|
4343
4349
|
const claimParams = {
|
|
4344
4350
|
...params,
|
|
@@ -4353,7 +4359,7 @@ class SDK {
|
|
|
4353
4359
|
}
|
|
4354
4360
|
};
|
|
4355
4361
|
this.buildClaimAllRewardsTx = async function(caip, params) {
|
|
4356
|
-
let tag5 =
|
|
4362
|
+
let tag5 = TAG9 + " | buildClaimAllRewardsTx | ";
|
|
4357
4363
|
try {
|
|
4358
4364
|
const claimAllParams = {
|
|
4359
4365
|
...params,
|
|
@@ -4367,7 +4373,7 @@ class SDK {
|
|
|
4367
4373
|
}
|
|
4368
4374
|
};
|
|
4369
4375
|
this.signTx = async function(unsignedTx) {
|
|
4370
|
-
let tag5 =
|
|
4376
|
+
let tag5 = TAG9 + " | signTx | ";
|
|
4371
4377
|
try {
|
|
4372
4378
|
const transactionDependencies = {
|
|
4373
4379
|
context: this.context,
|
|
@@ -4388,7 +4394,7 @@ class SDK {
|
|
|
4388
4394
|
}
|
|
4389
4395
|
};
|
|
4390
4396
|
this.broadcastTx = async function(caip, signedTx) {
|
|
4391
|
-
let tag5 =
|
|
4397
|
+
let tag5 = TAG9 + " | broadcastTx | ";
|
|
4392
4398
|
try {
|
|
4393
4399
|
const transactionDependencies = {
|
|
4394
4400
|
context: this.context,
|
|
@@ -4412,7 +4418,7 @@ class SDK {
|
|
|
4412
4418
|
}
|
|
4413
4419
|
};
|
|
4414
4420
|
this.swap = async function(swapPayload) {
|
|
4415
|
-
let tag5 = `${
|
|
4421
|
+
let tag5 = `${TAG9} | swap | `;
|
|
4416
4422
|
try {
|
|
4417
4423
|
if (!swapPayload)
|
|
4418
4424
|
throw Error("swapPayload required!");
|
|
@@ -4547,7 +4553,7 @@ class SDK {
|
|
|
4547
4553
|
}
|
|
4548
4554
|
};
|
|
4549
4555
|
this.transfer = async function(sendPayload) {
|
|
4550
|
-
let tag5 = `${
|
|
4556
|
+
let tag5 = `${TAG9} | transfer | `;
|
|
4551
4557
|
try {
|
|
4552
4558
|
if (!sendPayload)
|
|
4553
4559
|
throw Error("sendPayload required!");
|
|
@@ -4642,7 +4648,7 @@ class SDK {
|
|
|
4642
4648
|
}
|
|
4643
4649
|
};
|
|
4644
4650
|
this.setBlockchains = async function(blockchains) {
|
|
4645
|
-
const tag5 = `${
|
|
4651
|
+
const tag5 = `${TAG9} | setBlockchains | `;
|
|
4646
4652
|
try {
|
|
4647
4653
|
if (!blockchains)
|
|
4648
4654
|
throw Error("blockchains required!");
|
|
@@ -4658,7 +4664,7 @@ class SDK {
|
|
|
4658
4664
|
}
|
|
4659
4665
|
};
|
|
4660
4666
|
this.addAsset = async function(caip, data) {
|
|
4661
|
-
let tag5 =
|
|
4667
|
+
let tag5 = TAG9 + " | addAsset | ";
|
|
4662
4668
|
try {
|
|
4663
4669
|
let success = false;
|
|
4664
4670
|
if (!caip)
|
|
@@ -4696,7 +4702,7 @@ class SDK {
|
|
|
4696
4702
|
}
|
|
4697
4703
|
};
|
|
4698
4704
|
this.clearWalletState = async function() {
|
|
4699
|
-
const tag5 = `${
|
|
4705
|
+
const tag5 = `${TAG9} | clearWalletState | `;
|
|
4700
4706
|
try {
|
|
4701
4707
|
this.context = null;
|
|
4702
4708
|
this.paths = [];
|
|
@@ -4711,7 +4717,7 @@ class SDK {
|
|
|
4711
4717
|
}
|
|
4712
4718
|
};
|
|
4713
4719
|
this.addPath = async function(path) {
|
|
4714
|
-
const tag5 = `${
|
|
4720
|
+
const tag5 = `${TAG9} | addPath | `;
|
|
4715
4721
|
try {
|
|
4716
4722
|
this.paths.push(path);
|
|
4717
4723
|
const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
|
|
@@ -4725,7 +4731,7 @@ class SDK {
|
|
|
4725
4731
|
}
|
|
4726
4732
|
};
|
|
4727
4733
|
this.addPaths = async function(paths) {
|
|
4728
|
-
const tag5 = `${
|
|
4734
|
+
const tag5 = `${TAG9} | addPaths | `;
|
|
4729
4735
|
try {
|
|
4730
4736
|
console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
|
|
4731
4737
|
this.paths.push(...paths);
|
|
@@ -4761,7 +4767,7 @@ class SDK {
|
|
|
4761
4767
|
return this.getGasAssets();
|
|
4762
4768
|
};
|
|
4763
4769
|
this.getGasAssets = async function() {
|
|
4764
|
-
const tag5 = `${
|
|
4770
|
+
const tag5 = `${TAG9} | getGasAssets | `;
|
|
4765
4771
|
try {
|
|
4766
4772
|
for (let i = 0;i < this.blockchains.length; i++) {
|
|
4767
4773
|
let networkId = this.blockchains[i];
|
|
@@ -4804,7 +4810,7 @@ class SDK {
|
|
|
4804
4810
|
}
|
|
4805
4811
|
};
|
|
4806
4812
|
this.getPubkeys = async function() {
|
|
4807
|
-
const tag5 = `${
|
|
4813
|
+
const tag5 = `${TAG9} | getPubkeys | `;
|
|
4808
4814
|
try {
|
|
4809
4815
|
if (this.paths.length === 0)
|
|
4810
4816
|
throw new Error("No paths found!");
|
|
@@ -4825,7 +4831,7 @@ class SDK {
|
|
|
4825
4831
|
}
|
|
4826
4832
|
};
|
|
4827
4833
|
this.getBalancesForNetworks = async function(networkIds) {
|
|
4828
|
-
const tag5 = `${
|
|
4834
|
+
const tag5 = `${TAG9} | getBalancesForNetworks | `;
|
|
4829
4835
|
try {
|
|
4830
4836
|
if (!this.pioneer) {
|
|
4831
4837
|
console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
|
|
@@ -4880,7 +4886,7 @@ class SDK {
|
|
|
4880
4886
|
}
|
|
4881
4887
|
};
|
|
4882
4888
|
this.getBalances = async function() {
|
|
4883
|
-
const tag5 = `${
|
|
4889
|
+
const tag5 = `${TAG9} | getBalances | `;
|
|
4884
4890
|
try {
|
|
4885
4891
|
return await this.getBalancesForNetworks(this.blockchains);
|
|
4886
4892
|
} catch (e) {
|
|
@@ -4889,7 +4895,7 @@ class SDK {
|
|
|
4889
4895
|
}
|
|
4890
4896
|
};
|
|
4891
4897
|
this.getBalance = async function(networkId) {
|
|
4892
|
-
const tag5 = `${
|
|
4898
|
+
const tag5 = `${TAG9} | getBalance | `;
|
|
4893
4899
|
try {
|
|
4894
4900
|
const results = await this.getBalancesForNetworks([networkId]);
|
|
4895
4901
|
const filtered = results.filter(async (b3) => b3.networkId === await networkIdToCaip2(networkId));
|
|
@@ -4900,7 +4906,7 @@ class SDK {
|
|
|
4900
4906
|
}
|
|
4901
4907
|
};
|
|
4902
4908
|
this.getFees = async function(networkId) {
|
|
4903
|
-
const tag5 = `${
|
|
4909
|
+
const tag5 = `${TAG9} | getFees | `;
|
|
4904
4910
|
try {
|
|
4905
4911
|
if (!this.pioneer) {
|
|
4906
4912
|
throw new Error("Pioneer client not initialized. Call init() first.");
|
|
@@ -4915,7 +4921,7 @@ class SDK {
|
|
|
4915
4921
|
return estimateTransactionFee(feeRate, unit, networkType, txSize);
|
|
4916
4922
|
};
|
|
4917
4923
|
this.getCharts = async function() {
|
|
4918
|
-
const tag5 = `${
|
|
4924
|
+
const tag5 = `${TAG9} | getCharts | `;
|
|
4919
4925
|
try {
|
|
4920
4926
|
console.log(tag5, "Fetching charts");
|
|
4921
4927
|
const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
|
|
@@ -4937,7 +4943,7 @@ class SDK {
|
|
|
4937
4943
|
}
|
|
4938
4944
|
};
|
|
4939
4945
|
this.setContext = async (context) => {
|
|
4940
|
-
const tag5 = `${
|
|
4946
|
+
const tag5 = `${TAG9} | setContext | `;
|
|
4941
4947
|
try {
|
|
4942
4948
|
if (!context)
|
|
4943
4949
|
throw Error("context required!");
|
|
@@ -4950,7 +4956,7 @@ class SDK {
|
|
|
4950
4956
|
}
|
|
4951
4957
|
};
|
|
4952
4958
|
this.setContextType = async (contextType) => {
|
|
4953
|
-
const tag5 = `${
|
|
4959
|
+
const tag5 = `${TAG9} | setContextType | `;
|
|
4954
4960
|
try {
|
|
4955
4961
|
if (!contextType)
|
|
4956
4962
|
throw Error("contextType required!");
|
|
@@ -4963,7 +4969,7 @@ class SDK {
|
|
|
4963
4969
|
}
|
|
4964
4970
|
};
|
|
4965
4971
|
this.refresh = async () => {
|
|
4966
|
-
const tag5 = `${
|
|
4972
|
+
const tag5 = `${TAG9} | refresh | `;
|
|
4967
4973
|
try {
|
|
4968
4974
|
await this.sync();
|
|
4969
4975
|
return this.balances;
|
|
@@ -4973,7 +4979,7 @@ class SDK {
|
|
|
4973
4979
|
}
|
|
4974
4980
|
};
|
|
4975
4981
|
this.setAssetContext = async function(asset) {
|
|
4976
|
-
const tag5 = `${
|
|
4982
|
+
const tag5 = `${TAG9} | setAssetContext | `;
|
|
4977
4983
|
try {
|
|
4978
4984
|
if (!asset) {
|
|
4979
4985
|
this.assetContext = null;
|
|
@@ -5172,7 +5178,7 @@ class SDK {
|
|
|
5172
5178
|
}
|
|
5173
5179
|
};
|
|
5174
5180
|
this.setPubkeyContext = async function(pubkey) {
|
|
5175
|
-
let tag5 = `${
|
|
5181
|
+
let tag5 = `${TAG9} | setPubkeyContext | `;
|
|
5176
5182
|
try {
|
|
5177
5183
|
if (!pubkey)
|
|
5178
5184
|
throw Error("pubkey is required");
|
|
@@ -5191,7 +5197,7 @@ class SDK {
|
|
|
5191
5197
|
}
|
|
5192
5198
|
};
|
|
5193
5199
|
this.setOutboundAssetContext = async function(asset) {
|
|
5194
|
-
const tag5 = `${
|
|
5200
|
+
const tag5 = `${TAG9} | setOutputAssetContext | `;
|
|
5195
5201
|
try {
|
|
5196
5202
|
console.log(tag5, "0. asset: ", asset);
|
|
5197
5203
|
if (!asset) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "highlander",
|
|
3
3
|
"name": "@pioneer-platform/pioneer-sdk",
|
|
4
|
-
"version": "4.20.
|
|
4
|
+
"version": "4.20.7",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@keepkey/keepkey-sdk": "^0.2.62",
|
|
7
7
|
"@pioneer-platform/loggerdog": "^8.11.0",
|
|
8
8
|
"@pioneer-platform/pioneer-caip": "^9.10.0",
|
|
9
|
-
"@pioneer-platform/pioneer-client": "^9.10.
|
|
9
|
+
"@pioneer-platform/pioneer-client": "^9.10.3",
|
|
10
10
|
"@pioneer-platform/pioneer-coins": "^9.11.0",
|
|
11
11
|
"@pioneer-platform/pioneer-discovery": "^0.8.0",
|
|
12
12
|
"@pioneer-platform/pioneer-events": "^8.11.0",
|
|
@@ -48,8 +48,6 @@
|
|
|
48
48
|
},
|
|
49
49
|
"react-native": "./src/index.ts",
|
|
50
50
|
"repository": "https://github.com/thorswap/SwapKit.git",
|
|
51
|
-
"type": "module",
|
|
52
|
-
"types": "./dist/index.d.ts",
|
|
53
51
|
"scripts": {
|
|
54
52
|
"build": "bash scripts/build.sh",
|
|
55
53
|
"build:watch": "nodemon --watch src --exec 'bun run build'",
|
|
@@ -57,5 +55,7 @@
|
|
|
57
55
|
"lint": "eslint ./ --ext .ts,.tsx --fix; tsc --noEmit",
|
|
58
56
|
"test": "echo 'vitest --run'",
|
|
59
57
|
"test:coverage": "echo 'vitest run --coverage'"
|
|
60
|
-
}
|
|
61
|
-
|
|
58
|
+
},
|
|
59
|
+
"type": "module",
|
|
60
|
+
"types": "./dist/index.d.ts"
|
|
61
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { getFees, estimateTransactionFee, type NormalizedFeeRates, type FeeEstim
|
|
|
19
19
|
import { detectKkApiAvailability } from './utils/kkapi-detection.js';
|
|
20
20
|
import { formatTime } from './utils/format-time.js';
|
|
21
21
|
import { buildDashboardFromBalances } from './utils/build-dashboard.js';
|
|
22
|
+
import { syncMarket } from './utils/sync-market.js';
|
|
22
23
|
|
|
23
24
|
const TAG = ' | Pioneer-sdk | ';
|
|
24
25
|
|
|
@@ -572,86 +573,8 @@ export class SDK {
|
|
|
572
573
|
this.buildDashboardFromBalances = function () {
|
|
573
574
|
return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
|
|
574
575
|
};
|
|
575
|
-
|
|
576
576
|
this.syncMarket = async function () {
|
|
577
|
-
|
|
578
|
-
try {
|
|
579
|
-
// Log balances with invalid CAIPs for debugging
|
|
580
|
-
const invalidBalances = this.balances.filter(b =>
|
|
581
|
-
!b || !b.caip || typeof b.caip !== 'string' || !b.caip.includes(':')
|
|
582
|
-
);
|
|
583
|
-
if (invalidBalances.length > 0) {
|
|
584
|
-
console.warn(tag, `Found ${invalidBalances.length} balances with invalid CAIPs:`,
|
|
585
|
-
invalidBalances.map(b => ({
|
|
586
|
-
caip: b?.caip,
|
|
587
|
-
type: typeof b?.caip,
|
|
588
|
-
symbol: b?.symbol,
|
|
589
|
-
balance: b?.balance
|
|
590
|
-
}))
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
// Extract all CAIP identifiers from balances, filtering out invalid entries
|
|
595
|
-
let allCaips = this.balances
|
|
596
|
-
.filter(b => b && b.caip && typeof b.caip === 'string' && b.caip.trim().length > 0)
|
|
597
|
-
.map((b) => b.caip);
|
|
598
|
-
|
|
599
|
-
// Remove duplicates
|
|
600
|
-
allCaips = [...new Set(allCaips)];
|
|
601
|
-
|
|
602
|
-
// CRITICAL: Double-check all elements are valid strings after Set deduplication
|
|
603
|
-
// Filter out any non-string or empty values that might have slipped through
|
|
604
|
-
allCaips = allCaips.filter(caip =>
|
|
605
|
-
caip &&
|
|
606
|
-
typeof caip === 'string' &&
|
|
607
|
-
caip.trim().length > 0 &&
|
|
608
|
-
caip.includes(':') // CAIP format always has a colon
|
|
609
|
-
);
|
|
610
|
-
|
|
611
|
-
// Fetch market prices for all CAIPs
|
|
612
|
-
console.log('GetMarketInfo: payload: ', allCaips);
|
|
613
|
-
console.log('GetMarketInfo: payload type: ', typeof allCaips);
|
|
614
|
-
console.log('GetMarketInfo: payload length: ', allCaips.length);
|
|
615
|
-
|
|
616
|
-
// Additional validation log to catch issues
|
|
617
|
-
const invalidEntries = allCaips.filter(caip => typeof caip !== 'string');
|
|
618
|
-
if (invalidEntries.length > 0) {
|
|
619
|
-
console.error(tag, 'CRITICAL: Invalid entries detected in allCaips:', invalidEntries);
|
|
620
|
-
throw new Error('Invalid CAIP entries detected - aborting market sync');
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
if (allCaips && allCaips.length > 0) {
|
|
624
|
-
try {
|
|
625
|
-
let allPrices = await this.pioneer.GetMarketInfo(allCaips);
|
|
626
|
-
console.log('GetMarketInfo: response: ', allPrices);
|
|
627
|
-
|
|
628
|
-
// Create a map of CAIP to price for easier lookup
|
|
629
|
-
const priceMap = {};
|
|
630
|
-
if (allPrices && allPrices.data) {
|
|
631
|
-
for (let i = 0; i < allCaips.length && i < allPrices.data.length; i++) {
|
|
632
|
-
priceMap[allCaips[i]] = allPrices.data[i];
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
// Update each balance with the corresponding price and value
|
|
637
|
-
for (let balance of this.balances) {
|
|
638
|
-
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
639
|
-
balance.price = priceMap[balance.caip];
|
|
640
|
-
balance.priceUsd = priceMap[balance.caip]; // Also set priceUsd for compatibility
|
|
641
|
-
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
} catch (apiError) {
|
|
645
|
-
console.error(tag, 'API error fetching market info:', apiError);
|
|
646
|
-
// Don't throw - just log and continue without prices
|
|
647
|
-
console.warn(tag, 'Continuing without market prices');
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
return true;
|
|
651
|
-
} catch (e) {
|
|
652
|
-
console.error(tag, 'e:', e);
|
|
653
|
-
throw e;
|
|
654
|
-
}
|
|
577
|
+
return syncMarket(this.balances, this.pioneer);
|
|
655
578
|
};
|
|
656
579
|
this.sync = async function () {
|
|
657
580
|
const tag = `${TAG} | sync | `;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Market data synchronization utility
|
|
2
|
+
const TAG = ' | sync-market | ';
|
|
3
|
+
|
|
4
|
+
export async function syncMarket(balances: any[], pioneer: any): Promise<boolean> {
|
|
5
|
+
const tag = `${TAG} | syncMarket | `;
|
|
6
|
+
try {
|
|
7
|
+
// Log balances with invalid CAIPs for debugging
|
|
8
|
+
const invalidBalances = balances.filter(
|
|
9
|
+
(b) => !b || !b.caip || typeof b.caip !== 'string' || !b.caip.includes(':'),
|
|
10
|
+
);
|
|
11
|
+
if (invalidBalances.length > 0) {
|
|
12
|
+
console.warn(
|
|
13
|
+
tag,
|
|
14
|
+
`Found ${invalidBalances.length} balances with invalid CAIPs:`,
|
|
15
|
+
invalidBalances.map((b) => ({
|
|
16
|
+
caip: b?.caip,
|
|
17
|
+
type: typeof b?.caip,
|
|
18
|
+
symbol: b?.symbol,
|
|
19
|
+
balance: b?.balance,
|
|
20
|
+
})),
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Extract all CAIP identifiers from balances, filtering out invalid entries
|
|
25
|
+
let allCaips = balances
|
|
26
|
+
.filter((b) => b && b.caip && typeof b.caip === 'string' && b.caip.trim().length > 0)
|
|
27
|
+
.map((b) => b.caip);
|
|
28
|
+
|
|
29
|
+
// Remove duplicates
|
|
30
|
+
allCaips = [...new Set(allCaips)];
|
|
31
|
+
|
|
32
|
+
// CRITICAL: Double-check all elements are valid strings after Set deduplication
|
|
33
|
+
// Filter out any non-string or empty values that might have slipped through
|
|
34
|
+
allCaips = allCaips.filter(
|
|
35
|
+
(caip) =>
|
|
36
|
+
caip &&
|
|
37
|
+
typeof caip === 'string' &&
|
|
38
|
+
caip.trim().length > 0 &&
|
|
39
|
+
caip.includes(':'), // CAIP format always has a colon
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Fetch market prices for all CAIPs
|
|
43
|
+
console.log('GetMarketInfo: payload: ', allCaips);
|
|
44
|
+
console.log('GetMarketInfo: payload type: ', typeof allCaips);
|
|
45
|
+
console.log('GetMarketInfo: payload length: ', allCaips.length);
|
|
46
|
+
|
|
47
|
+
// Additional validation log to catch issues
|
|
48
|
+
const invalidEntries = allCaips.filter((caip) => typeof caip !== 'string');
|
|
49
|
+
if (invalidEntries.length > 0) {
|
|
50
|
+
console.error(tag, 'CRITICAL: Invalid entries detected in allCaips:', invalidEntries);
|
|
51
|
+
throw new Error('Invalid CAIP entries detected - aborting market sync');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (allCaips && allCaips.length > 0) {
|
|
55
|
+
try {
|
|
56
|
+
let allPrices = await pioneer.GetMarketInfo(allCaips);
|
|
57
|
+
console.log('GetMarketInfo: response: ', allPrices);
|
|
58
|
+
|
|
59
|
+
// Create a map of CAIP to price for easier lookup
|
|
60
|
+
const priceMap: Record<string, number> = {};
|
|
61
|
+
if (allPrices && allPrices.data) {
|
|
62
|
+
for (let i = 0; i < allCaips.length && i < allPrices.data.length; i++) {
|
|
63
|
+
priceMap[allCaips[i]] = allPrices.data[i];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Update each balance with the corresponding price and value
|
|
68
|
+
for (let balance of balances) {
|
|
69
|
+
if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
|
|
70
|
+
balance.price = priceMap[balance.caip];
|
|
71
|
+
balance.priceUsd = priceMap[balance.caip]; // Also set priceUsd for compatibility
|
|
72
|
+
balance.valueUsd = balance.price * (balance.balance || 0);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} catch (apiError) {
|
|
76
|
+
console.error(tag, 'API error fetching market info:', apiError);
|
|
77
|
+
// Don't throw - just log and continue without prices
|
|
78
|
+
console.warn(tag, 'Continuing without market prices');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.error(tag, 'e:', e);
|
|
84
|
+
throw e;
|
|
85
|
+
}
|
|
86
|
+
}
|