@paraspell/sdk 10.10.1 → 10.10.2

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 CHANGED
@@ -329,29 +329,28 @@ var processAssetsDepositedEvents = function processAssetsDepositedEvents(events,
329
329
  if (assetsDepositedEvents.length === 1) {
330
330
  return BigInt(assetsDepositedEvents[0].value.value.amount);
331
331
  }
332
- var sortedEvents = _toConsumableArray(assetsDepositedEvents).sort(function (a, b) {
333
- return Number(BigInt(b.value.value.amount) - BigInt(a.value.value.amount));
334
- });
335
- // If only 2 events and their sum is not greater than amount, return the sum
336
- if (sortedEvents.length === 2) {
337
- var _sum = BigInt(sortedEvents[0].value.value.amount) + BigInt(sortedEvents[1].value.value.amount);
338
- if (_sum <= amount) {
339
- return _sum;
340
- }
341
- }
342
- // Remove the biggest event
343
- var filteredEvents = sortedEvents.slice(1);
344
- var sum = filteredEvents.reduce(function (total, event) {
345
- return total + BigInt(event.value.value.amount);
346
- }, BigInt(0));
347
- // Remove next biggest until sum <= amount or nothing left
348
- while (sum > amount && filteredEvents.length > 0) {
349
- filteredEvents = filteredEvents.slice(1);
350
- sum = filteredEvents.reduce(function (total, event) {
332
+ // Start with all events
333
+ var currentEvents = _toConsumableArray(assetsDepositedEvents);
334
+ var threshold = amount * BigInt(90) / BigInt(100); // 90% of amount
335
+ while (currentEvents.length > 0) {
336
+ // 1. Make a sum of all amounts in events
337
+ var sum = currentEvents.reduce(function (total, event) {
351
338
  return total + BigInt(event.value.value.amount);
352
339
  }, BigInt(0));
340
+ // 2. If that sum is bigger than 90% of amount, remove the biggest event
341
+ if (sum > threshold) {
342
+ // Sort events by amount (descending) and remove the biggest
343
+ currentEvents.sort(function (a, b) {
344
+ return Number(BigInt(b.value.value.amount) - BigInt(a.value.value.amount));
345
+ });
346
+ currentEvents = currentEvents.slice(1); // Remove the biggest event
347
+ } else {
348
+ // If not, return the summed value
349
+ return sum;
350
+ }
353
351
  }
354
- return sum > 0 ? sum : undefined;
352
+ // If we've removed all events, return undefined
353
+ return undefined;
355
354
  };
356
355
 
357
356
  var checkAndConvertToNumberOrBigInt = function checkAndConvertToNumberOrBigInt(input) {
@@ -1531,7 +1530,7 @@ var PapiApi = /*#__PURE__*/function () {
1531
1530
  } : undefined;
1532
1531
  forwardedXcms = result.value.forwarded_xcms.length > 0 ? result.value.forwarded_xcms[0] : [];
1533
1532
  destParaId = forwardedXcms.length === 0 ? undefined : forwardedXcms[0].value.interior.type === 'Here' ? 0 : forwardedXcms[0].value.interior.value.value;
1534
- if (!(sdkCore.hasXcmPaymentApiSupport(node) && asset && node !== 'AssetHubPolkadot')) {
1533
+ if (!(sdkCore.hasXcmPaymentApiSupport(node) && asset && node !== 'AssetHubPolkadot' && node !== 'Polkadot')) {
1535
1534
  _context21.n = 5;
1536
1535
  break;
1537
1536
  }
package/dist/index.mjs CHANGED
@@ -328,29 +328,28 @@ var processAssetsDepositedEvents = function processAssetsDepositedEvents(events,
328
328
  if (assetsDepositedEvents.length === 1) {
329
329
  return BigInt(assetsDepositedEvents[0].value.value.amount);
330
330
  }
331
- var sortedEvents = _toConsumableArray(assetsDepositedEvents).sort(function (a, b) {
332
- return Number(BigInt(b.value.value.amount) - BigInt(a.value.value.amount));
333
- });
334
- // If only 2 events and their sum is not greater than amount, return the sum
335
- if (sortedEvents.length === 2) {
336
- var _sum = BigInt(sortedEvents[0].value.value.amount) + BigInt(sortedEvents[1].value.value.amount);
337
- if (_sum <= amount) {
338
- return _sum;
339
- }
340
- }
341
- // Remove the biggest event
342
- var filteredEvents = sortedEvents.slice(1);
343
- var sum = filteredEvents.reduce(function (total, event) {
344
- return total + BigInt(event.value.value.amount);
345
- }, BigInt(0));
346
- // Remove next biggest until sum <= amount or nothing left
347
- while (sum > amount && filteredEvents.length > 0) {
348
- filteredEvents = filteredEvents.slice(1);
349
- sum = filteredEvents.reduce(function (total, event) {
331
+ // Start with all events
332
+ var currentEvents = _toConsumableArray(assetsDepositedEvents);
333
+ var threshold = amount * BigInt(90) / BigInt(100); // 90% of amount
334
+ while (currentEvents.length > 0) {
335
+ // 1. Make a sum of all amounts in events
336
+ var sum = currentEvents.reduce(function (total, event) {
350
337
  return total + BigInt(event.value.value.amount);
351
338
  }, BigInt(0));
339
+ // 2. If that sum is bigger than 90% of amount, remove the biggest event
340
+ if (sum > threshold) {
341
+ // Sort events by amount (descending) and remove the biggest
342
+ currentEvents.sort(function (a, b) {
343
+ return Number(BigInt(b.value.value.amount) - BigInt(a.value.value.amount));
344
+ });
345
+ currentEvents = currentEvents.slice(1); // Remove the biggest event
346
+ } else {
347
+ // If not, return the summed value
348
+ return sum;
349
+ }
352
350
  }
353
- return sum > 0 ? sum : undefined;
351
+ // If we've removed all events, return undefined
352
+ return undefined;
354
353
  };
355
354
 
356
355
  var checkAndConvertToNumberOrBigInt = function checkAndConvertToNumberOrBigInt(input) {
@@ -1530,7 +1529,7 @@ var PapiApi = /*#__PURE__*/function () {
1530
1529
  } : undefined;
1531
1530
  forwardedXcms = result.value.forwarded_xcms.length > 0 ? result.value.forwarded_xcms[0] : [];
1532
1531
  destParaId = forwardedXcms.length === 0 ? undefined : forwardedXcms[0].value.interior.type === 'Here' ? 0 : forwardedXcms[0].value.interior.value.value;
1533
- if (!(hasXcmPaymentApiSupport(node) && asset && node !== 'AssetHubPolkadot')) {
1532
+ if (!(hasXcmPaymentApiSupport(node) && asset && node !== 'AssetHubPolkadot' && node !== 'Polkadot')) {
1534
1533
  _context21.n = 5;
1535
1534
  break;
1536
1535
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk",
3
- "version": "10.10.1",
3
+ "version": "10.10.2",
4
4
  "description": "SDK for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@noble/hashes": "^1.8.0",
27
27
  "viem": "^2.31.6",
28
- "@paraspell/sdk-core": "10.10.1"
28
+ "@paraspell/sdk-core": "10.10.2"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "polkadot-api": ">= 1.14.1 < 2"