@paraspell/sdk-core 11.14.2 → 11.14.4

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
@@ -4647,11 +4647,12 @@ var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency)
4647
4647
  return !(isMultipleAssets || hasOverriddenLocation);
4648
4648
  };
4649
4649
 
4650
- var validateAddress = function validateAddress(address, chain) {
4651
- var isDestination = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
4650
+ var validateAddress = function validateAddress(api, address, chain) {
4651
+ var isDestination = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
4652
4652
  if (sdkCommon.isTLocation(address)) return;
4653
4653
  var isEvm = assets.isChainEvm(chain);
4654
4654
  var isEthereumAddress = viem.isAddress(address);
4655
+ var isPublicKeyFormat = typeof address === 'string' && address.startsWith('0x') && !isEthereumAddress;
4655
4656
  if (isEvm) {
4656
4657
  if (!isEthereumAddress) {
4657
4658
  throw new InvalidAddressError("".concat(isDestination ? 'Destination chain' : 'Chain', " is an EVM chain, but the address provided is not a valid Ethereum address."));
@@ -4660,12 +4661,21 @@ var validateAddress = function validateAddress(address, chain) {
4660
4661
  if (isEthereumAddress) {
4661
4662
  throw new InvalidAddressError("EVM address provided but ".concat(isDestination ? 'destination ' : '', "chain is not an EVM chain."));
4662
4663
  }
4664
+ if (isPublicKeyFormat) {
4665
+ return;
4666
+ }
4667
+ if (typeof address === 'string') {
4668
+ var isValid = api.validateSubstrateAddress(address);
4669
+ if (!isValid) {
4670
+ throw new InvalidAddressError("Invalid address: ".concat(address));
4671
+ }
4672
+ }
4663
4673
  }
4664
4674
  };
4665
4675
 
4666
- var validateDestinationAddress = function validateDestinationAddress(address, destination) {
4676
+ var validateDestinationAddress = function validateDestinationAddress(address, destination, api) {
4667
4677
  if (typeof address === 'string' && !sdkCommon.isTLocation(destination)) {
4668
- validateAddress(address, destination);
4678
+ validateAddress(api, address, destination, true);
4669
4679
  }
4670
4680
  };
4671
4681
 
@@ -7508,7 +7518,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_Parachain) {
7508
7518
  key: "transferPolkadotXCM",
7509
7519
  value: function () {
7510
7520
  var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
7511
- var api, scenario, assetInfo, destination, feeAssetInfo, overriddenAsset, call, isNativeAsset, isNativeFeeAsset, isExternalAsset, _call, method, modifiedInput, _t, _t2;
7521
+ var api, scenario, assetInfo, destination, feeAssetInfo, overriddenAsset, call, isNativeAsset, isNativeFeeAsset, isExternalAsset, requiresTypeThen, _call, method, modifiedInput, _t, _t2;
7512
7522
  return _regenerator().w(function (_context3) {
7513
7523
  while (1) switch (_context3.n) {
7514
7524
  case 0:
@@ -7558,7 +7568,10 @@ var AssetHubPolkadot = /*#__PURE__*/function (_Parachain) {
7558
7568
  return _context3.a(2, this.handleMythosTransfer(options));
7559
7569
  case 7:
7560
7570
  isExternalAsset = assetInfo.location && assetInfo.location.parents === sdkCommon.Parents.TWO;
7561
- if (!isExternalAsset) {
7571
+ requiresTypeThen = AH_REQUIRES_FEE_ASSET_LOCS.some(function (loc) {
7572
+ return sdkCommon.deepEqual(loc, assetInfo.location);
7573
+ });
7574
+ if (!(isExternalAsset || requiresTypeThen)) {
7562
7575
  _context3.n = 9;
7563
7576
  break;
7564
7577
  }
@@ -8433,24 +8446,6 @@ var HeimaPaseo = /*#__PURE__*/function (_Heima) {
8433
8446
  return _createClass(HeimaPaseo);
8434
8447
  }(Heima);
8435
8448
 
8436
- var createCustomXcmAh = function createCustomXcmAh(_ref, version) {
8437
- var api = _ref.api,
8438
- address = _ref.address;
8439
- return _defineProperty({}, version, [{
8440
- DepositAsset: {
8441
- assets: {
8442
- Wild: {
8443
- AllCounted: 2
8444
- }
8445
- },
8446
- beneficiary: createBeneficiaryLocation({
8447
- api: api,
8448
- address: address,
8449
- version: version
8450
- })
8451
- }
8452
- }]);
8453
- };
8454
8449
  var Hydration = /*#__PURE__*/function (_Parachain) {
8455
8450
  function Hydration() {
8456
8451
  var chain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Hydration';
@@ -8462,35 +8457,10 @@ var Hydration = /*#__PURE__*/function (_Parachain) {
8462
8457
  }
8463
8458
  _inherits(Hydration, _Parachain);
8464
8459
  return _createClass(Hydration, [{
8465
- key: "transferToAssetHub",
8466
- value: function transferToAssetHub(input) {
8467
- var api = input.api,
8468
- asset = input.assetInfo,
8469
- version = input.version,
8470
- destination = input.destination;
8471
- var call = {
8472
- module: 'PolkadotXcm',
8473
- method: 'transfer_assets_using_type_and_then',
8474
- parameters: {
8475
- dest: createVersionedDestination(version, this.chain, destination, getParaId('AssetHubPolkadot')),
8476
- assets: _defineProperty({}, version, [createAsset(version, asset.amount, DOT_LOCATION)]),
8477
- assets_transfer_type: 'DestinationReserve',
8478
- remote_fees_id: _defineProperty({}, version, {
8479
- parents: sdkCommon.Parents.ONE,
8480
- interior: 'Here'
8481
- }),
8482
- fees_transfer_type: 'DestinationReserve',
8483
- custom_xcm_on_dest: createCustomXcmAh(input, version),
8484
- weight_limit: 'Unlimited'
8485
- }
8486
- };
8487
- return api.callTxMethod(call);
8488
- }
8489
- }, {
8490
8460
  key: "transferPolkadotXCM",
8491
8461
  value: function () {
8492
8462
  var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
8493
- var api, destination, feeAsset, asset, overriddenAsset, isNativeAsset, isNativeFeeAsset, _t;
8463
+ var api, destination, feeAsset, asset, overriddenAsset, isNativeAsset, isNativeFeeAsset, _t, _t2;
8494
8464
  return _regenerator().w(function (_context) {
8495
8465
  while (1) switch (_context.n) {
8496
8466
  case 0:
@@ -8523,7 +8493,11 @@ var Hydration = /*#__PURE__*/function (_Parachain) {
8523
8493
  case 3:
8524
8494
  return _context.a(2, _t.callTxMethod.call(_t, _context.v));
8525
8495
  case 4:
8526
- return _context.a(2, this.transferToAssetHub(input));
8496
+ _t2 = api;
8497
+ _context.n = 5;
8498
+ return createTypeAndThenCall(this.chain, input);
8499
+ case 5:
8500
+ return _context.a(2, _t2.callTxMethod.call(_t2, _context.v));
8527
8501
  }
8528
8502
  }, _callee, this);
8529
8503
  }));
@@ -8571,7 +8545,10 @@ var Hydration = /*#__PURE__*/function (_Parachain) {
8571
8545
  assetInfo = options.assetInfo,
8572
8546
  feeAsset = options.feeAsset;
8573
8547
  var baseCanUseXTokens = _superPropGet(Hydration, "canUseXTokens", this, 3)([options]);
8574
- return destination !== 'Ethereum' && !(destination === 'AssetHubPolkadot' && assetInfo.symbol === 'DOT') && baseCanUseXTokens && !feeAsset;
8548
+ var requiresTypeThen = AH_REQUIRES_FEE_ASSET_LOCS.some(function (loc) {
8549
+ return sdkCommon.deepEqual(loc, assetInfo.location);
8550
+ });
8551
+ return destination !== 'Ethereum' && !(destination === 'AssetHubPolkadot' && assetInfo.symbol === 'DOT') && baseCanUseXTokens && !feeAsset && !requiresTypeThen;
8575
8552
  }
8576
8553
  }, {
8577
8554
  key: "transferLocalNativeAsset",
@@ -9989,6 +9966,18 @@ var RELAY_LOCATION = {
9989
9966
  Here: null
9990
9967
  }
9991
9968
  };
9969
+ var AH_REQUIRES_FEE_ASSET_LOCS = [{
9970
+ parents: sdkCommon.Parents.ONE,
9971
+ interior: {
9972
+ X3: [{
9973
+ Parachain: 1000
9974
+ }, {
9975
+ PalletInstance: 50
9976
+ }, {
9977
+ GeneralIndex: 50000075
9978
+ }]
9979
+ }
9980
+ }];
9992
9981
  var ASSET_HUB_EXECUTION_FEE = 2200000000n; // 0.22 DOT
9993
9982
  var TX_CLIENT_TIMEOUT_MS = 20 * 60 * 1000; // 20 minutes
9994
9983
  var DRY_RUN_CLIENT_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
@@ -10048,7 +10037,7 @@ var claimAssets = /*#__PURE__*/function () {
10048
10037
  while (1) switch (_context.n) {
10049
10038
  case 0:
10050
10039
  api = options.api, chain = options.chain, address = options.address;
10051
- validateAddress(address, chain);
10040
+ validateAddress(api, address, chain, true);
10052
10041
  _context.n = 1;
10053
10042
  return api.init(chain, TX_CLIENT_TIMEOUT_MS);
10054
10043
  case 1:
@@ -10089,7 +10078,7 @@ var dryRun = /*#__PURE__*/function () {
10089
10078
  while (1) switch (_context.p = _context.n) {
10090
10079
  case 0:
10091
10080
  api = options.api, senderAddress = options.senderAddress, origin = options.origin;
10092
- validateAddress(senderAddress, origin, false);
10081
+ validateAddress(api, senderAddress, origin, false);
10093
10082
  _context.n = 1;
10094
10083
  return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
10095
10084
  case 1:
@@ -10121,7 +10110,7 @@ var dryRunOrigin = /*#__PURE__*/function () {
10121
10110
  while (1) switch (_context.p = _context.n) {
10122
10111
  case 0:
10123
10112
  api = options.api, chain = options.chain, address = options.address;
10124
- validateAddress(address, chain, false);
10113
+ validateAddress(api, address, chain, false);
10125
10114
  _context.n = 1;
10126
10115
  return api.init(chain, DRY_RUN_CLIENT_TIMEOUT_MS);
10127
10116
  case 1:
@@ -11683,8 +11672,8 @@ var send = /*#__PURE__*/function () {
11683
11672
  api = options.api, origin = options.from, currency = options.currency, feeAsset = options.feeAsset, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, version = options.version, senderAddress = options.senderAddress, ahAddress = options.ahAddress, pallet = options.pallet, method = options.method, isAmountAll = options.isAmountAll;
11684
11673
  validateCurrency(currency, feeAsset);
11685
11674
  validateDestination(origin, destination);
11686
- validateDestinationAddress(address, destination);
11687
- if (senderAddress) validateAddress(senderAddress, origin, false);
11675
+ validateDestinationAddress(address, destination, api);
11676
+ if (senderAddress) validateAddress(api, senderAddress, origin, false);
11688
11677
  isBridge = !sdkCommon.isTLocation(destination) && sdkCommon.isSubstrateBridge(origin, destination);
11689
11678
  assetCheckEnabled = shouldPerformAssetCheck(origin, currency);
11690
11679
  validateAssetSpecifiers(assetCheckEnabled, currency);
@@ -12200,14 +12189,65 @@ var getTransferInfo = /*#__PURE__*/function () {
12200
12189
  };
12201
12190
  }();
12202
12191
 
12203
- var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12204
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
12205
- var api, origin, senderAddress, address, chain, destination, currency, feeAsset, buildTx, builder, resolvedFeeAsset, asset, destAsset, destCurrency, destApi, destBalance, destEd, nativeAssetInfo, isNativeAsset, paysOriginInSendingAsset, amount, result, originFee, hopFeeTotal, destinationFee, edComponent, minAmount, modifiedBuilder, _yield$modifiedBuilde, tx, dryRunResult;
12192
+ var FEE_PADDING = 30;
12193
+ var sumHopFees = function sumHopFees(result, asset) {
12194
+ return result.hops.reduce(function (acc, hop) {
12195
+ // only add if asset is equal
12196
+ return assets.isAssetEqual(hop.result.asset, asset) ? acc + hop.result.fee : acc;
12197
+ }, 0n);
12198
+ };
12199
+ var computeAllFees = /*#__PURE__*/function () {
12200
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, buildTx) {
12201
+ var origin, dest, assetInfo, _context$options, senderAddress, address, currency, feeCurrency, result, hopFees, destFee;
12206
12202
  return _regenerator().w(function (_context) {
12207
12203
  while (1) switch (_context.n) {
12204
+ case 0:
12205
+ origin = context.origin, dest = context.dest, assetInfo = context.assetInfo, _context$options = context.options, senderAddress = _context$options.senderAddress, address = _context$options.address, currency = _context$options.currency, feeCurrency = _context$options.feeCurrency;
12206
+ assertSenderAddress(senderAddress);
12207
+ assertAddressIsString(address);
12208
+ if (assets.hasDryRunSupport(context.origin.chain)) {
12209
+ _context.n = 1;
12210
+ break;
12211
+ }
12212
+ return _context.a(2, null);
12213
+ case 1:
12214
+ _context.n = 2;
12215
+ return getXcmFeeInternal({
12216
+ api: origin.api,
12217
+ buildTx: buildTx,
12218
+ origin: origin.chain,
12219
+ destination: dest.chain,
12220
+ senderAddress: senderAddress,
12221
+ address: address,
12222
+ currency: currency,
12223
+ feeAsset: feeCurrency,
12224
+ disableFallback: false,
12225
+ skipReverseFeeCalculation: true
12226
+ });
12227
+ case 2:
12228
+ result = _context.v;
12229
+ hopFees = sumHopFees(result, assetInfo);
12230
+ destFee = result.destination.fee;
12231
+ return _context.a(2, {
12232
+ hopFees: padValueBy(hopFees, FEE_PADDING),
12233
+ destFee: padValueBy(destFee, FEE_PADDING)
12234
+ });
12235
+ }
12236
+ }, _callee);
12237
+ }));
12238
+ return function computeAllFees(_x, _x2) {
12239
+ return _ref.apply(this, arguments);
12240
+ };
12241
+ }();
12242
+
12243
+ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12244
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
12245
+ var api, origin, senderAddress, address, chain, destination, currency, feeAsset, buildTx, builder, resolvedFeeAsset, asset, destAsset, destCurrency, destApi, destBalance, destEd, nativeAssetInfo, isNativeAsset, paysOriginInSendingAsset, amount, result, originFee, hopFeeTotal, destinationFee, edComponent, minAmount, createTx, tx, dryRunResult, _t;
12246
+ return _regenerator().w(function (_context2) {
12247
+ while (1) switch (_context2.p = _context2.n) {
12208
12248
  case 0:
12209
12249
  api = _ref.api, origin = _ref.origin, senderAddress = _ref.senderAddress, address = _ref.address, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency, feeAsset = _ref.feeAsset, buildTx = _ref.buildTx, builder = _ref.builder;
12210
- validateAddress(senderAddress, chain, false);
12250
+ validateAddress(api, senderAddress, chain, false);
12211
12251
  resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, chain, destination, currency) : undefined;
12212
12252
  asset = assets.findAssetInfoOrThrow(chain, currency, null);
12213
12253
  destAsset = assets.findAssetOnDestOrThrow(origin, destination, currency);
@@ -12217,10 +12257,10 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12217
12257
  symbol: destAsset.symbol
12218
12258
  };
12219
12259
  destApi = api.clone();
12220
- _context.n = 1;
12260
+ _context2.n = 1;
12221
12261
  return destApi.init(destination);
12222
12262
  case 1:
12223
- _context.n = 2;
12263
+ _context2.n = 2;
12224
12264
  return getAssetBalanceInternal({
12225
12265
  api: destApi,
12226
12266
  address: address,
@@ -12228,13 +12268,13 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12228
12268
  currency: destCurrency
12229
12269
  });
12230
12270
  case 2:
12231
- destBalance = _context.v;
12271
+ destBalance = _context2.v;
12232
12272
  destEd = assets.getEdFromAssetOrThrow(destAsset);
12233
12273
  nativeAssetInfo = assets.findNativeAssetInfoOrThrow(chain);
12234
12274
  isNativeAsset = assets.isAssetEqual(nativeAssetInfo, asset);
12235
12275
  paysOriginInSendingAsset = !resolvedFeeAsset && isNativeAsset || resolvedFeeAsset && assets.isAssetEqual(resolvedFeeAsset, asset);
12236
12276
  amount = abstractDecimals(currency.amount, asset.decimals, api);
12237
- _context.n = 3;
12277
+ _context2.n = 3;
12238
12278
  return getXcmFee({
12239
12279
  api: api,
12240
12280
  origin: origin,
@@ -12249,7 +12289,7 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12249
12289
  disableFallback: false
12250
12290
  });
12251
12291
  case 3:
12252
- result = _context.v;
12292
+ result = _context2.v;
12253
12293
  originFee = result.origin && paysOriginInSendingAsset && assets.isAssetEqual(result.origin.asset, asset) ? result.origin.fee : 0n;
12254
12294
  hopFeeTotal = result.hops.reduce(function (acc, hop) {
12255
12295
  // only add if asset is equal
@@ -12258,15 +12298,59 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12258
12298
  destinationFee = result.destination && assets.isAssetEqual(result.destination.asset, asset) ? result.destination.fee : 0n;
12259
12299
  edComponent = destBalance === 0n ? destEd : 0n;
12260
12300
  minAmount = hopFeeTotal + destinationFee + originFee + edComponent + 1n;
12261
- modifiedBuilder = builder.currency(_objectSpread2(_objectSpread2({}, currency), {}, {
12262
- amount: minAmount
12263
- }));
12264
- _context.n = 4;
12265
- return modifiedBuilder['buildInternal']();
12266
- case 4:
12267
- _yield$modifiedBuilde = _context.v;
12268
- tx = _yield$modifiedBuilde.tx;
12269
- _context.n = 5;
12301
+ createTx = /*#__PURE__*/function () {
12302
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(amount) {
12303
+ var _yield$builder$curren, tx;
12304
+ return _regenerator().w(function (_context) {
12305
+ while (1) switch (_context.n) {
12306
+ case 0:
12307
+ _context.n = 1;
12308
+ return builder.currency(_objectSpread2(_objectSpread2({}, currency), {}, {
12309
+ amount: amount
12310
+ }))['buildInternal']();
12311
+ case 1:
12312
+ _yield$builder$curren = _context.v;
12313
+ tx = _yield$builder$curren.tx;
12314
+ return _context.a(2, tx);
12315
+ }
12316
+ }, _callee);
12317
+ }));
12318
+ return function createTx(_x2) {
12319
+ return _ref3.apply(this, arguments);
12320
+ };
12321
+ }();
12322
+ _context2.p = 4;
12323
+ _context2.n = 5;
12324
+ return createTx(minAmount);
12325
+ case 5:
12326
+ tx = _context2.v;
12327
+ _context2.n = 10;
12328
+ break;
12329
+ case 6:
12330
+ _context2.p = 6;
12331
+ _t = _context2.v;
12332
+ if (!(_t instanceof AmountTooLowError)) {
12333
+ _context2.n = 10;
12334
+ break;
12335
+ }
12336
+ minAmount = padValueBy(minAmount, FEE_PADDING);
12337
+ _context2.p = 7;
12338
+ _context2.n = 8;
12339
+ return createTx(minAmount);
12340
+ case 8:
12341
+ tx = _context2.v;
12342
+ _context2.n = 10;
12343
+ break;
12344
+ case 9:
12345
+ _context2.p = 9;
12346
+ _context2.v;
12347
+ if (!(_t instanceof AmountTooLowError)) {
12348
+ _context2.n = 10;
12349
+ break;
12350
+ }
12351
+ return _context2.a(2, 0n);
12352
+ case 10:
12353
+ _context2.n = 11;
12270
12354
  return dryRunInternal({
12271
12355
  api: api,
12272
12356
  tx: tx,
@@ -12279,49 +12363,49 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12279
12363
  }),
12280
12364
  feeAsset: feeAsset
12281
12365
  });
12282
- case 5:
12283
- dryRunResult = _context.v;
12366
+ case 11:
12367
+ dryRunResult = _context2.v;
12284
12368
  if (!dryRunResult.failureReason) {
12285
- _context.n = 6;
12369
+ _context2.n = 12;
12286
12370
  break;
12287
12371
  }
12288
- return _context.a(2, 0n);
12289
- case 6:
12290
- return _context.a(2, minAmount);
12372
+ return _context2.a(2, 0n);
12373
+ case 12:
12374
+ return _context2.a(2, minAmount);
12291
12375
  }
12292
- }, _callee);
12376
+ }, _callee2, null, [[7, 9], [4, 6]]);
12293
12377
  }));
12294
12378
  return function getMinTransferableAmountInternal(_x) {
12295
12379
  return _ref2.apply(this, arguments);
12296
12380
  };
12297
12381
  }();
12298
12382
  var getMinTransferableAmount = /*#__PURE__*/function () {
12299
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
12383
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
12300
12384
  var api;
12301
- return _regenerator().w(function (_context2) {
12302
- while (1) switch (_context2.p = _context2.n) {
12385
+ return _regenerator().w(function (_context3) {
12386
+ while (1) switch (_context3.p = _context3.n) {
12303
12387
  case 0:
12304
12388
  api = options.api;
12305
12389
  api.setDisconnectAllowed(false);
12306
- _context2.p = 1;
12307
- _context2.n = 2;
12390
+ _context3.p = 1;
12391
+ _context3.n = 2;
12308
12392
  return getMinTransferableAmountInternal(options);
12309
12393
  case 2:
12310
- return _context2.a(2, _context2.v);
12394
+ return _context3.a(2, _context3.v);
12311
12395
  case 3:
12312
- _context2.p = 3;
12396
+ _context3.p = 3;
12313
12397
  api.setDisconnectAllowed(true);
12314
- _context2.n = 4;
12398
+ _context3.n = 4;
12315
12399
  return api.disconnect();
12316
12400
  case 4:
12317
- return _context2.f(3);
12401
+ return _context3.f(3);
12318
12402
  case 5:
12319
- return _context2.a(2);
12403
+ return _context3.a(2);
12320
12404
  }
12321
- }, _callee2, null, [[1,, 3, 5]]);
12405
+ }, _callee3, null, [[1,, 3, 5]]);
12322
12406
  }));
12323
- return function getMinTransferableAmount(_x2) {
12324
- return _ref3.apply(this, arguments);
12407
+ return function getMinTransferableAmount(_x3) {
12408
+ return _ref4.apply(this, arguments);
12325
12409
  };
12326
12410
  }();
12327
12411
 
@@ -12332,7 +12416,7 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
12332
12416
  while (1) switch (_context.n) {
12333
12417
  case 0:
12334
12418
  api = _ref.api, senderAddress = _ref.senderAddress, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency, buildTx = _ref.buildTx, feeAsset = _ref.feeAsset;
12335
- validateAddress(senderAddress, chain, false);
12419
+ validateAddress(api, senderAddress, chain, false);
12336
12420
  resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, chain, destination, currency) : undefined;
12337
12421
  asset = assets.findAssetInfoOrThrow(chain, currency, null);
12338
12422
  amount = abstractDecimals(currency.amount, asset.decimals, api);
@@ -12448,57 +12532,6 @@ var buildTypeAndThenCall = function buildTypeAndThenCall(_ref, isDotAsset, custo
12448
12532
  };
12449
12533
  };
12450
12534
 
12451
- var FEE_PADDING = 30;
12452
- var sumHopFees = function sumHopFees(result, asset) {
12453
- return result.hops.reduce(function (acc, hop) {
12454
- // only add if asset is equal
12455
- return assets.isAssetEqual(hop.result.asset, asset) ? acc + hop.result.fee : acc;
12456
- }, 0n);
12457
- };
12458
- var computeAllFees = /*#__PURE__*/function () {
12459
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, buildTx) {
12460
- var origin, dest, assetInfo, _context$options, senderAddress, address, currency, feeCurrency, result, hopFees, destFee;
12461
- return _regenerator().w(function (_context) {
12462
- while (1) switch (_context.n) {
12463
- case 0:
12464
- origin = context.origin, dest = context.dest, assetInfo = context.assetInfo, _context$options = context.options, senderAddress = _context$options.senderAddress, address = _context$options.address, currency = _context$options.currency, feeCurrency = _context$options.feeCurrency;
12465
- assertSenderAddress(senderAddress);
12466
- assertAddressIsString(address);
12467
- if (assets.hasDryRunSupport(context.origin.chain)) {
12468
- _context.n = 1;
12469
- break;
12470
- }
12471
- return _context.a(2, null);
12472
- case 1:
12473
- _context.n = 2;
12474
- return getXcmFeeInternal({
12475
- api: origin.api,
12476
- buildTx: buildTx,
12477
- origin: origin.chain,
12478
- destination: dest.chain,
12479
- senderAddress: senderAddress,
12480
- address: address,
12481
- currency: currency,
12482
- feeAsset: feeCurrency,
12483
- disableFallback: false,
12484
- skipReverseFeeCalculation: true
12485
- });
12486
- case 2:
12487
- result = _context.v;
12488
- hopFees = sumHopFees(result, assetInfo);
12489
- destFee = result.destination.fee;
12490
- return _context.a(2, {
12491
- hopFees: padValueBy(hopFees, FEE_PADDING),
12492
- destFee: padValueBy(destFee, FEE_PADDING)
12493
- });
12494
- }
12495
- }, _callee);
12496
- }));
12497
- return function computeAllFees(_x, _x2) {
12498
- return _ref.apply(this, arguments);
12499
- };
12500
- }();
12501
-
12502
12535
  var RELAY_ASSET_LOCATIONS = [RELAY_LOCATION, {
12503
12536
  parents: 2,
12504
12537
  interior: {
@@ -12638,9 +12671,7 @@ var createCustomXcm = function createCustomXcm(context, assetCount, isForFeeCalc
12638
12671
  if (isSubBridge || origin.chain !== reserve.chain && dest.chain !== reserve.chain) {
12639
12672
  var buyExecutionAmount = resolveBuyExecutionAmount(context, isForFeeCalc, fees, systemAssetAmount);
12640
12673
  if (buyExecutionAmount < 0n && !isForFeeCalc) throw new AmountTooLowError();
12641
- var filter = isForFeeCalc ? {
12642
- Wild: 'All'
12643
- } : {
12674
+ var filter = {
12644
12675
  Definite: assetsFilter
12645
12676
  };
12646
12677
  var buyExecution = {
@@ -12695,11 +12726,12 @@ var createRefundInstruction = function createRefundInstruction(api, senderAddres
12695
12726
 
12696
12727
  var buildAssets = function buildAssets(chain, asset, feeAmount, isDotAsset, version) {
12697
12728
  var assets = [];
12729
+ var shouldLocalizeAndSort = sdkCommon.isRelayChain(chain) || chain.startsWith('AssetHub');
12698
12730
  if (!isDotAsset) {
12699
12731
  assets.push(createAsset(version, feeAmount, RELAY_LOCATION));
12700
12732
  }
12701
- assets.push(createAsset(version, asset.amount, sdkCommon.isRelayChain(chain) ? localizeLocation(chain, asset.location) : asset.location));
12702
- return assets;
12733
+ assets.push(createAsset(version, asset.amount, shouldLocalizeAndSort ? localizeLocation(chain, asset.location) : asset.location));
12734
+ return shouldLocalizeAndSort ? sortAssets(assets) : assets;
12703
12735
  };
12704
12736
  var DEFAULT_SYSTEM_ASSET_AMOUNT = '1';
12705
12737
  var resolveSystemAssetAmount = function resolveSystemAssetAmount(_ref, isForFeeCalc, fees) {
@@ -12886,7 +12918,7 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
12886
12918
  }
12887
12919
  return _context.a(2, true);
12888
12920
  case 1:
12889
- validateAddress(address, destination);
12921
+ validateAddress(api, address, destination, true);
12890
12922
  if (!(origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama')) {
12891
12923
  _context.n = 2;
12892
12924
  break;
package/dist/index.d.ts CHANGED
@@ -1538,6 +1538,7 @@ interface IPolkadotApi<TApi, TRes> {
1538
1538
  * Convert a location to a chain account address using the runtime LocationToAccount API, if available.
1539
1539
  */
1540
1540
  convertLocationToAccount(location: TLocation): Promise<string | undefined>;
1541
+ validateSubstrateAddress(address: string): boolean;
1541
1542
  }
1542
1543
 
1543
1544
  declare const blake2b256: (msg: Uint8Array) => Uint8Array<ArrayBufferLike>;
@@ -1851,7 +1852,6 @@ declare class HeimaPaseo<TApi, TRes> extends Heima<TApi, TRes> {
1851
1852
  declare class Hydration<TApi, TRes> extends Parachain<TApi, TRes> implements IXTokensTransfer, IPolkadotXCMTransfer {
1852
1853
  private static NATIVE_ASSET_ID;
1853
1854
  constructor(chain?: TParachain, info?: string, ecosystem?: TRelaychain, version?: Version);
1854
- transferToAssetHub<TApi, TRes>(input: TPolkadotXCMTransferOptions<TApi, TRes>): TRes;
1855
1855
  transferPolkadotXCM<TApi, TRes>(input: TPolkadotXCMTransferOptions<TApi, TRes>): Promise<TRes>;
1856
1856
  transferMoonbeamWhAsset<TApi, TRes>(input: TXTokensTransferOptions<TApi, TRes>): TRes;
1857
1857
  transferXTokens<TApi, TRes>(input: TXTokensTransferOptions<TApi, TRes>): TRes;
@@ -2377,7 +2377,7 @@ declare const handleToAhTeleport: <TApi, TRes>(origin: TParachain, input: TPolka
2377
2377
  declare const parseUnits: typeof parseUnits$1;
2378
2378
  declare const formatUnits: typeof formatUnits$1;
2379
2379
 
2380
- declare const validateAddress: (address: TAddress, chain: TChain, isDestination?: boolean) => void;
2380
+ declare const validateAddress: <TApi, TRes>(api: IPolkadotApi<TApi, TRes>, address: TAddress, chain: TChain, isDestination?: boolean) => void;
2381
2381
 
2382
2382
  export { AmountTooLowError, AssetClaimBuilder, AssetsPallet, BatchMode, BridgeHaltedError, Builder, ChainNotSupportedError, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleChainsError, InvalidAddressError, InvalidParameterError, MissingChainApiError, NoXCMSupportImplementedError, PolkadotXcmError, PolkadotXcmExecutionError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, UnableToComputeError, XTokensError, abstractDecimals, addEthereumBridgeFees, addXcmVersionHeader, applyDecimalAbstraction, assertAddressIsString, assertHasId, assertHasLocation, assertIsForeign, assertSenderAddress, assertToIsString, blake2b256, blake2b512, calcPreviewMintAmount, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, computeOverridenAmount, constructTypeAndThenCall, convertSs58, createAsset, createAssetsFilter, createBaseExecuteXcm, createBeneficiaryLocXTokens, createBeneficiaryLocation, createChainClient, createDirectExecuteXcm, createExecuteCall, createExecuteExchangeXcm, createTx, createTypeAndThenCall, createTypeThenAutoReserve, createVersionedAssets, createX1Payload, deriveAccountId, dryRun, dryRunInternal, dryRunOrigin, encodeSs58, formatUnits, getAssetBalance, getAssetBalanceInternal, getAssetReserveChain, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getChain, getChainConfig, getChainLocation, getChainProviders, getChainVersion, getCurrencySelection, getFailureInfo, getMinTransferableAmount, getMinTransferableAmountInternal, getOriginFeeDetails, getOriginFeeDetailsInternal, getOriginXcmFee, getOriginXcmFeeEstimate, getOriginXcmFeeInternal, getParaEthTransferFees, getParaId, getRelayChainOf, getTChain, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, getXcmFeeInternal, getXcmFeeOnce, handleExecuteTransfer, handleSwapExecuteTransfer, handleToAhTeleport, isConfig, localizeLocation, maybeOverrideAsset, maybeOverrideAssets, normalizeAmount, overrideTxAmount, padFee, padValueBy, parseUnits, resolveDestChain, resolveModuleError, resolveParaId, reverseTransformLocation, send, sortAssets, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, traverseXcmHops, validateAddress, validateAssetSpecifiers, validateCurrency, validateDestination, verifyEdOnDestination, wrapTxBypass };
2383
2383
  export type { BuildHopInfoOptions, HopProcessParams, HopTraversalConfig, HopTraversalResult, IPolkadotApi, IPolkadotXCMTransfer, IXTokensTransfer, IXTransferTransfer, OneKey, TAddress, TApiOrUrl, TAssetClaimInternalOptions, TAssetClaimOptions, TAssetClaimOptionsBase, TBatchOptions, TBatchedSendOptions, TBifrostToken, TBridgeStatus, TBuildDestInfoOptions, TBuildInternalRes, TBuilderConfig, TBuilderOptions, TBypassOptions, TChainConfig, TChainConfigMap, TChainWithApi, TConditionalXcmFeeDetail, TConditionalXcmFeeHopInfo, TCreateBaseSwapXcmOptions, TCreateBaseTransferXcmOptions, TCreateBeneficiaryOptions, TCreateBeneficiaryXTokensOptions, TCreateSwapXcmInternalOptions, TCreateSwapXcmOptions, TCreateTransferXcmOptions, TCreateTxsOptions, TDestWeight, TDestXcmFeeDetail, TDestination, TDryRunBaseOptions, TDryRunBypassOptions, TDryRunCallBaseOptions, TDryRunCallOptions, TDryRunChain, TDryRunChainFailure, TDryRunChainResult, TDryRunChainSuccess, TDryRunError, TDryRunOptions, TDryRunPreviewOptions, TDryRunResBase, TDryRunResult, TDryRunXcmBaseOptions, TDryRunXcmOptions, TEvmBuilderOptions, TEvmBuilderOptionsBase, TEvmChainFrom, TFeeType, TForeignAssetId, TForeignOrNativeAsset, TForeignOrTokenAsset, TGetAssetBalanceOptions, TGetAssetBalanceOptionsBase, TGetBalanceForeignByAssetOptions, TGetBalanceForeignOptions, TGetBalanceForeignOptionsBase, TGetBalanceNativeOptions, TGetBalanceNativeOptionsBase, TGetFeeForDestChainBaseOptions, TGetFeeForDestChainOptions, TGetMinTransferableAmountOptions, TGetOriginFeeDetailsOptions, TGetOriginFeeDetailsOptionsBase, TGetOriginXcmFeeBaseOptions, TGetOriginXcmFeeEstimateOptions, TGetOriginXcmFeeInternalOptions, TGetOriginXcmFeeOptions, TGetReverseTxFeeOptions, TGetTransferInfoOptions, TGetTransferInfoOptionsBase, TGetTransferableAmountOptions, TGetTransferableAmountOptionsBase, TGetXcmFeeBaseOptions, TGetXcmFeeBuilderOptions, TGetXcmFeeEstimateDetail, TGetXcmFeeEstimateOptions, TGetXcmFeeEstimateResult, TGetXcmFeeInternalOptions, TGetXcmFeeOptions, TGetXcmFeeResult, THopInfo, THopTransferInfo, THubKey, TMantaAsset, TModuleError, TNativeTokenAsset, TNodleAsset, TOriginFeeDetails, TOtherReserveAsset, TPolkadotXCMTransferOptions, TPolkadotXcmMethod, TProviderEntry, TRelayToParaDestination, TRelayToParaOptions, TRelayToParaOverrides, TReserveAsset, TResolveHopParams, TScenario, TSelfReserveAsset, TSendBaseOptions, TSendBaseOptionsWithSenderAddress, TSendInternalOptions, TSendOptions, TSerializeEthTransferOptions, TSerializedApiCall, TSerializedEthTransfer, TSwapConfig, TSwapFeeEstimates, TTransferFeeEstimates, TTransferInfo, TTransferLocalOptions, TTxFactory, TTypeAndThenCallContext, TTypeAndThenFees, TUrl, TVerifyEdOnDestinationOptions, TVerifyEdOnDestinationOptionsBase, TWeight, TXTokensCurrencySelection, TXTokensMethod, TXTokensTransferOptions, TXTransferMethod, TXTransferTransferOptions, TXcmAsset, TXcmFeeBase, TXcmFeeChain, TXcmFeeDetail, TXcmFeeDetailError, TXcmFeeDetailSuccess, TXcmFeeDetailWithFallback, TXcmFeeHopInfo, TXcmFeeHopResult, TXcmFeeSwapConfig, TXcmForeignAsset, TXcmPalletMethod, TXcmVersioned, TZeitgeistAsset, WithApi, WithRequiredSenderAddress };
package/dist/index.mjs CHANGED
@@ -4648,11 +4648,12 @@ var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency)
4648
4648
  return !(isMultipleAssets || hasOverriddenLocation);
4649
4649
  };
4650
4650
 
4651
- var validateAddress = function validateAddress(address, chain) {
4652
- var isDestination = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
4651
+ var validateAddress = function validateAddress(api, address, chain) {
4652
+ var isDestination = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
4653
4653
  if (isTLocation(address)) return;
4654
4654
  var isEvm = isChainEvm(chain);
4655
4655
  var isEthereumAddress = isAddress(address);
4656
+ var isPublicKeyFormat = typeof address === 'string' && address.startsWith('0x') && !isEthereumAddress;
4656
4657
  if (isEvm) {
4657
4658
  if (!isEthereumAddress) {
4658
4659
  throw new InvalidAddressError("".concat(isDestination ? 'Destination chain' : 'Chain', " is an EVM chain, but the address provided is not a valid Ethereum address."));
@@ -4661,12 +4662,21 @@ var validateAddress = function validateAddress(address, chain) {
4661
4662
  if (isEthereumAddress) {
4662
4663
  throw new InvalidAddressError("EVM address provided but ".concat(isDestination ? 'destination ' : '', "chain is not an EVM chain."));
4663
4664
  }
4665
+ if (isPublicKeyFormat) {
4666
+ return;
4667
+ }
4668
+ if (typeof address === 'string') {
4669
+ var isValid = api.validateSubstrateAddress(address);
4670
+ if (!isValid) {
4671
+ throw new InvalidAddressError("Invalid address: ".concat(address));
4672
+ }
4673
+ }
4664
4674
  }
4665
4675
  };
4666
4676
 
4667
- var validateDestinationAddress = function validateDestinationAddress(address, destination) {
4677
+ var validateDestinationAddress = function validateDestinationAddress(address, destination, api) {
4668
4678
  if (typeof address === 'string' && !isTLocation(destination)) {
4669
- validateAddress(address, destination);
4679
+ validateAddress(api, address, destination, true);
4670
4680
  }
4671
4681
  };
4672
4682
 
@@ -7509,7 +7519,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_Parachain) {
7509
7519
  key: "transferPolkadotXCM",
7510
7520
  value: function () {
7511
7521
  var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
7512
- var api, scenario, assetInfo, destination, feeAssetInfo, overriddenAsset, call, isNativeAsset, isNativeFeeAsset, isExternalAsset, _call, method, modifiedInput, _t, _t2;
7522
+ var api, scenario, assetInfo, destination, feeAssetInfo, overriddenAsset, call, isNativeAsset, isNativeFeeAsset, isExternalAsset, requiresTypeThen, _call, method, modifiedInput, _t, _t2;
7513
7523
  return _regenerator().w(function (_context3) {
7514
7524
  while (1) switch (_context3.n) {
7515
7525
  case 0:
@@ -7559,7 +7569,10 @@ var AssetHubPolkadot = /*#__PURE__*/function (_Parachain) {
7559
7569
  return _context3.a(2, this.handleMythosTransfer(options));
7560
7570
  case 7:
7561
7571
  isExternalAsset = assetInfo.location && assetInfo.location.parents === Parents.TWO;
7562
- if (!isExternalAsset) {
7572
+ requiresTypeThen = AH_REQUIRES_FEE_ASSET_LOCS.some(function (loc) {
7573
+ return deepEqual(loc, assetInfo.location);
7574
+ });
7575
+ if (!(isExternalAsset || requiresTypeThen)) {
7563
7576
  _context3.n = 9;
7564
7577
  break;
7565
7578
  }
@@ -8434,24 +8447,6 @@ var HeimaPaseo = /*#__PURE__*/function (_Heima) {
8434
8447
  return _createClass(HeimaPaseo);
8435
8448
  }(Heima);
8436
8449
 
8437
- var createCustomXcmAh = function createCustomXcmAh(_ref, version) {
8438
- var api = _ref.api,
8439
- address = _ref.address;
8440
- return _defineProperty({}, version, [{
8441
- DepositAsset: {
8442
- assets: {
8443
- Wild: {
8444
- AllCounted: 2
8445
- }
8446
- },
8447
- beneficiary: createBeneficiaryLocation({
8448
- api: api,
8449
- address: address,
8450
- version: version
8451
- })
8452
- }
8453
- }]);
8454
- };
8455
8450
  var Hydration = /*#__PURE__*/function (_Parachain) {
8456
8451
  function Hydration() {
8457
8452
  var chain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Hydration';
@@ -8463,35 +8458,10 @@ var Hydration = /*#__PURE__*/function (_Parachain) {
8463
8458
  }
8464
8459
  _inherits(Hydration, _Parachain);
8465
8460
  return _createClass(Hydration, [{
8466
- key: "transferToAssetHub",
8467
- value: function transferToAssetHub(input) {
8468
- var api = input.api,
8469
- asset = input.assetInfo,
8470
- version = input.version,
8471
- destination = input.destination;
8472
- var call = {
8473
- module: 'PolkadotXcm',
8474
- method: 'transfer_assets_using_type_and_then',
8475
- parameters: {
8476
- dest: createVersionedDestination(version, this.chain, destination, getParaId('AssetHubPolkadot')),
8477
- assets: _defineProperty({}, version, [createAsset(version, asset.amount, DOT_LOCATION)]),
8478
- assets_transfer_type: 'DestinationReserve',
8479
- remote_fees_id: _defineProperty({}, version, {
8480
- parents: Parents.ONE,
8481
- interior: 'Here'
8482
- }),
8483
- fees_transfer_type: 'DestinationReserve',
8484
- custom_xcm_on_dest: createCustomXcmAh(input, version),
8485
- weight_limit: 'Unlimited'
8486
- }
8487
- };
8488
- return api.callTxMethod(call);
8489
- }
8490
- }, {
8491
8461
  key: "transferPolkadotXCM",
8492
8462
  value: function () {
8493
8463
  var _transferPolkadotXCM = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
8494
- var api, destination, feeAsset, asset, overriddenAsset, isNativeAsset, isNativeFeeAsset, _t;
8464
+ var api, destination, feeAsset, asset, overriddenAsset, isNativeAsset, isNativeFeeAsset, _t, _t2;
8495
8465
  return _regenerator().w(function (_context) {
8496
8466
  while (1) switch (_context.n) {
8497
8467
  case 0:
@@ -8524,7 +8494,11 @@ var Hydration = /*#__PURE__*/function (_Parachain) {
8524
8494
  case 3:
8525
8495
  return _context.a(2, _t.callTxMethod.call(_t, _context.v));
8526
8496
  case 4:
8527
- return _context.a(2, this.transferToAssetHub(input));
8497
+ _t2 = api;
8498
+ _context.n = 5;
8499
+ return createTypeAndThenCall(this.chain, input);
8500
+ case 5:
8501
+ return _context.a(2, _t2.callTxMethod.call(_t2, _context.v));
8528
8502
  }
8529
8503
  }, _callee, this);
8530
8504
  }));
@@ -8572,7 +8546,10 @@ var Hydration = /*#__PURE__*/function (_Parachain) {
8572
8546
  assetInfo = options.assetInfo,
8573
8547
  feeAsset = options.feeAsset;
8574
8548
  var baseCanUseXTokens = _superPropGet(Hydration, "canUseXTokens", this, 3)([options]);
8575
- return destination !== 'Ethereum' && !(destination === 'AssetHubPolkadot' && assetInfo.symbol === 'DOT') && baseCanUseXTokens && !feeAsset;
8549
+ var requiresTypeThen = AH_REQUIRES_FEE_ASSET_LOCS.some(function (loc) {
8550
+ return deepEqual(loc, assetInfo.location);
8551
+ });
8552
+ return destination !== 'Ethereum' && !(destination === 'AssetHubPolkadot' && assetInfo.symbol === 'DOT') && baseCanUseXTokens && !feeAsset && !requiresTypeThen;
8576
8553
  }
8577
8554
  }, {
8578
8555
  key: "transferLocalNativeAsset",
@@ -9990,6 +9967,18 @@ var RELAY_LOCATION = {
9990
9967
  Here: null
9991
9968
  }
9992
9969
  };
9970
+ var AH_REQUIRES_FEE_ASSET_LOCS = [{
9971
+ parents: Parents.ONE,
9972
+ interior: {
9973
+ X3: [{
9974
+ Parachain: 1000
9975
+ }, {
9976
+ PalletInstance: 50
9977
+ }, {
9978
+ GeneralIndex: 50000075
9979
+ }]
9980
+ }
9981
+ }];
9993
9982
  var ASSET_HUB_EXECUTION_FEE = 2200000000n; // 0.22 DOT
9994
9983
  var TX_CLIENT_TIMEOUT_MS = 20 * 60 * 1000; // 20 minutes
9995
9984
  var DRY_RUN_CLIENT_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
@@ -10049,7 +10038,7 @@ var claimAssets = /*#__PURE__*/function () {
10049
10038
  while (1) switch (_context.n) {
10050
10039
  case 0:
10051
10040
  api = options.api, chain = options.chain, address = options.address;
10052
- validateAddress(address, chain);
10041
+ validateAddress(api, address, chain, true);
10053
10042
  _context.n = 1;
10054
10043
  return api.init(chain, TX_CLIENT_TIMEOUT_MS);
10055
10044
  case 1:
@@ -10090,7 +10079,7 @@ var dryRun = /*#__PURE__*/function () {
10090
10079
  while (1) switch (_context.p = _context.n) {
10091
10080
  case 0:
10092
10081
  api = options.api, senderAddress = options.senderAddress, origin = options.origin;
10093
- validateAddress(senderAddress, origin, false);
10082
+ validateAddress(api, senderAddress, origin, false);
10094
10083
  _context.n = 1;
10095
10084
  return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
10096
10085
  case 1:
@@ -10122,7 +10111,7 @@ var dryRunOrigin = /*#__PURE__*/function () {
10122
10111
  while (1) switch (_context.p = _context.n) {
10123
10112
  case 0:
10124
10113
  api = options.api, chain = options.chain, address = options.address;
10125
- validateAddress(address, chain, false);
10114
+ validateAddress(api, address, chain, false);
10126
10115
  _context.n = 1;
10127
10116
  return api.init(chain, DRY_RUN_CLIENT_TIMEOUT_MS);
10128
10117
  case 1:
@@ -11684,8 +11673,8 @@ var send = /*#__PURE__*/function () {
11684
11673
  api = options.api, origin = options.from, currency = options.currency, feeAsset = options.feeAsset, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, version = options.version, senderAddress = options.senderAddress, ahAddress = options.ahAddress, pallet = options.pallet, method = options.method, isAmountAll = options.isAmountAll;
11685
11674
  validateCurrency(currency, feeAsset);
11686
11675
  validateDestination(origin, destination);
11687
- validateDestinationAddress(address, destination);
11688
- if (senderAddress) validateAddress(senderAddress, origin, false);
11676
+ validateDestinationAddress(address, destination, api);
11677
+ if (senderAddress) validateAddress(api, senderAddress, origin, false);
11689
11678
  isBridge = !isTLocation(destination) && isSubstrateBridge(origin, destination);
11690
11679
  assetCheckEnabled = shouldPerformAssetCheck(origin, currency);
11691
11680
  validateAssetSpecifiers(assetCheckEnabled, currency);
@@ -12201,14 +12190,65 @@ var getTransferInfo = /*#__PURE__*/function () {
12201
12190
  };
12202
12191
  }();
12203
12192
 
12204
- var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12205
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
12206
- var api, origin, senderAddress, address, chain, destination, currency, feeAsset, buildTx, builder, resolvedFeeAsset, asset, destAsset, destCurrency, destApi, destBalance, destEd, nativeAssetInfo, isNativeAsset, paysOriginInSendingAsset, amount, result, originFee, hopFeeTotal, destinationFee, edComponent, minAmount, modifiedBuilder, _yield$modifiedBuilde, tx, dryRunResult;
12193
+ var FEE_PADDING = 30;
12194
+ var sumHopFees = function sumHopFees(result, asset) {
12195
+ return result.hops.reduce(function (acc, hop) {
12196
+ // only add if asset is equal
12197
+ return isAssetEqual(hop.result.asset, asset) ? acc + hop.result.fee : acc;
12198
+ }, 0n);
12199
+ };
12200
+ var computeAllFees = /*#__PURE__*/function () {
12201
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, buildTx) {
12202
+ var origin, dest, assetInfo, _context$options, senderAddress, address, currency, feeCurrency, result, hopFees, destFee;
12207
12203
  return _regenerator().w(function (_context) {
12208
12204
  while (1) switch (_context.n) {
12205
+ case 0:
12206
+ origin = context.origin, dest = context.dest, assetInfo = context.assetInfo, _context$options = context.options, senderAddress = _context$options.senderAddress, address = _context$options.address, currency = _context$options.currency, feeCurrency = _context$options.feeCurrency;
12207
+ assertSenderAddress(senderAddress);
12208
+ assertAddressIsString(address);
12209
+ if (hasDryRunSupport(context.origin.chain)) {
12210
+ _context.n = 1;
12211
+ break;
12212
+ }
12213
+ return _context.a(2, null);
12214
+ case 1:
12215
+ _context.n = 2;
12216
+ return getXcmFeeInternal({
12217
+ api: origin.api,
12218
+ buildTx: buildTx,
12219
+ origin: origin.chain,
12220
+ destination: dest.chain,
12221
+ senderAddress: senderAddress,
12222
+ address: address,
12223
+ currency: currency,
12224
+ feeAsset: feeCurrency,
12225
+ disableFallback: false,
12226
+ skipReverseFeeCalculation: true
12227
+ });
12228
+ case 2:
12229
+ result = _context.v;
12230
+ hopFees = sumHopFees(result, assetInfo);
12231
+ destFee = result.destination.fee;
12232
+ return _context.a(2, {
12233
+ hopFees: padValueBy(hopFees, FEE_PADDING),
12234
+ destFee: padValueBy(destFee, FEE_PADDING)
12235
+ });
12236
+ }
12237
+ }, _callee);
12238
+ }));
12239
+ return function computeAllFees(_x, _x2) {
12240
+ return _ref.apply(this, arguments);
12241
+ };
12242
+ }();
12243
+
12244
+ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12245
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
12246
+ var api, origin, senderAddress, address, chain, destination, currency, feeAsset, buildTx, builder, resolvedFeeAsset, asset, destAsset, destCurrency, destApi, destBalance, destEd, nativeAssetInfo, isNativeAsset, paysOriginInSendingAsset, amount, result, originFee, hopFeeTotal, destinationFee, edComponent, minAmount, createTx, tx, dryRunResult, _t;
12247
+ return _regenerator().w(function (_context2) {
12248
+ while (1) switch (_context2.p = _context2.n) {
12209
12249
  case 0:
12210
12250
  api = _ref.api, origin = _ref.origin, senderAddress = _ref.senderAddress, address = _ref.address, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency, feeAsset = _ref.feeAsset, buildTx = _ref.buildTx, builder = _ref.builder;
12211
- validateAddress(senderAddress, chain, false);
12251
+ validateAddress(api, senderAddress, chain, false);
12212
12252
  resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, chain, destination, currency) : undefined;
12213
12253
  asset = findAssetInfoOrThrow(chain, currency, null);
12214
12254
  destAsset = findAssetOnDestOrThrow(origin, destination, currency);
@@ -12218,10 +12258,10 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12218
12258
  symbol: destAsset.symbol
12219
12259
  };
12220
12260
  destApi = api.clone();
12221
- _context.n = 1;
12261
+ _context2.n = 1;
12222
12262
  return destApi.init(destination);
12223
12263
  case 1:
12224
- _context.n = 2;
12264
+ _context2.n = 2;
12225
12265
  return getAssetBalanceInternal({
12226
12266
  api: destApi,
12227
12267
  address: address,
@@ -12229,13 +12269,13 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12229
12269
  currency: destCurrency
12230
12270
  });
12231
12271
  case 2:
12232
- destBalance = _context.v;
12272
+ destBalance = _context2.v;
12233
12273
  destEd = getEdFromAssetOrThrow(destAsset);
12234
12274
  nativeAssetInfo = findNativeAssetInfoOrThrow(chain);
12235
12275
  isNativeAsset = isAssetEqual(nativeAssetInfo, asset);
12236
12276
  paysOriginInSendingAsset = !resolvedFeeAsset && isNativeAsset || resolvedFeeAsset && isAssetEqual(resolvedFeeAsset, asset);
12237
12277
  amount = abstractDecimals(currency.amount, asset.decimals, api);
12238
- _context.n = 3;
12278
+ _context2.n = 3;
12239
12279
  return getXcmFee({
12240
12280
  api: api,
12241
12281
  origin: origin,
@@ -12250,7 +12290,7 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12250
12290
  disableFallback: false
12251
12291
  });
12252
12292
  case 3:
12253
- result = _context.v;
12293
+ result = _context2.v;
12254
12294
  originFee = result.origin && paysOriginInSendingAsset && isAssetEqual(result.origin.asset, asset) ? result.origin.fee : 0n;
12255
12295
  hopFeeTotal = result.hops.reduce(function (acc, hop) {
12256
12296
  // only add if asset is equal
@@ -12259,15 +12299,59 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12259
12299
  destinationFee = result.destination && isAssetEqual(result.destination.asset, asset) ? result.destination.fee : 0n;
12260
12300
  edComponent = destBalance === 0n ? destEd : 0n;
12261
12301
  minAmount = hopFeeTotal + destinationFee + originFee + edComponent + 1n;
12262
- modifiedBuilder = builder.currency(_objectSpread2(_objectSpread2({}, currency), {}, {
12263
- amount: minAmount
12264
- }));
12265
- _context.n = 4;
12266
- return modifiedBuilder['buildInternal']();
12267
- case 4:
12268
- _yield$modifiedBuilde = _context.v;
12269
- tx = _yield$modifiedBuilde.tx;
12270
- _context.n = 5;
12302
+ createTx = /*#__PURE__*/function () {
12303
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(amount) {
12304
+ var _yield$builder$curren, tx;
12305
+ return _regenerator().w(function (_context) {
12306
+ while (1) switch (_context.n) {
12307
+ case 0:
12308
+ _context.n = 1;
12309
+ return builder.currency(_objectSpread2(_objectSpread2({}, currency), {}, {
12310
+ amount: amount
12311
+ }))['buildInternal']();
12312
+ case 1:
12313
+ _yield$builder$curren = _context.v;
12314
+ tx = _yield$builder$curren.tx;
12315
+ return _context.a(2, tx);
12316
+ }
12317
+ }, _callee);
12318
+ }));
12319
+ return function createTx(_x2) {
12320
+ return _ref3.apply(this, arguments);
12321
+ };
12322
+ }();
12323
+ _context2.p = 4;
12324
+ _context2.n = 5;
12325
+ return createTx(minAmount);
12326
+ case 5:
12327
+ tx = _context2.v;
12328
+ _context2.n = 10;
12329
+ break;
12330
+ case 6:
12331
+ _context2.p = 6;
12332
+ _t = _context2.v;
12333
+ if (!(_t instanceof AmountTooLowError)) {
12334
+ _context2.n = 10;
12335
+ break;
12336
+ }
12337
+ minAmount = padValueBy(minAmount, FEE_PADDING);
12338
+ _context2.p = 7;
12339
+ _context2.n = 8;
12340
+ return createTx(minAmount);
12341
+ case 8:
12342
+ tx = _context2.v;
12343
+ _context2.n = 10;
12344
+ break;
12345
+ case 9:
12346
+ _context2.p = 9;
12347
+ _context2.v;
12348
+ if (!(_t instanceof AmountTooLowError)) {
12349
+ _context2.n = 10;
12350
+ break;
12351
+ }
12352
+ return _context2.a(2, 0n);
12353
+ case 10:
12354
+ _context2.n = 11;
12271
12355
  return dryRunInternal({
12272
12356
  api: api,
12273
12357
  tx: tx,
@@ -12280,49 +12364,49 @@ var getMinTransferableAmountInternal = /*#__PURE__*/function () {
12280
12364
  }),
12281
12365
  feeAsset: feeAsset
12282
12366
  });
12283
- case 5:
12284
- dryRunResult = _context.v;
12367
+ case 11:
12368
+ dryRunResult = _context2.v;
12285
12369
  if (!dryRunResult.failureReason) {
12286
- _context.n = 6;
12370
+ _context2.n = 12;
12287
12371
  break;
12288
12372
  }
12289
- return _context.a(2, 0n);
12290
- case 6:
12291
- return _context.a(2, minAmount);
12373
+ return _context2.a(2, 0n);
12374
+ case 12:
12375
+ return _context2.a(2, minAmount);
12292
12376
  }
12293
- }, _callee);
12377
+ }, _callee2, null, [[7, 9], [4, 6]]);
12294
12378
  }));
12295
12379
  return function getMinTransferableAmountInternal(_x) {
12296
12380
  return _ref2.apply(this, arguments);
12297
12381
  };
12298
12382
  }();
12299
12383
  var getMinTransferableAmount = /*#__PURE__*/function () {
12300
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
12384
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
12301
12385
  var api;
12302
- return _regenerator().w(function (_context2) {
12303
- while (1) switch (_context2.p = _context2.n) {
12386
+ return _regenerator().w(function (_context3) {
12387
+ while (1) switch (_context3.p = _context3.n) {
12304
12388
  case 0:
12305
12389
  api = options.api;
12306
12390
  api.setDisconnectAllowed(false);
12307
- _context2.p = 1;
12308
- _context2.n = 2;
12391
+ _context3.p = 1;
12392
+ _context3.n = 2;
12309
12393
  return getMinTransferableAmountInternal(options);
12310
12394
  case 2:
12311
- return _context2.a(2, _context2.v);
12395
+ return _context3.a(2, _context3.v);
12312
12396
  case 3:
12313
- _context2.p = 3;
12397
+ _context3.p = 3;
12314
12398
  api.setDisconnectAllowed(true);
12315
- _context2.n = 4;
12399
+ _context3.n = 4;
12316
12400
  return api.disconnect();
12317
12401
  case 4:
12318
- return _context2.f(3);
12402
+ return _context3.f(3);
12319
12403
  case 5:
12320
- return _context2.a(2);
12404
+ return _context3.a(2);
12321
12405
  }
12322
- }, _callee2, null, [[1,, 3, 5]]);
12406
+ }, _callee3, null, [[1,, 3, 5]]);
12323
12407
  }));
12324
- return function getMinTransferableAmount(_x2) {
12325
- return _ref3.apply(this, arguments);
12408
+ return function getMinTransferableAmount(_x3) {
12409
+ return _ref4.apply(this, arguments);
12326
12410
  };
12327
12411
  }();
12328
12412
 
@@ -12333,7 +12417,7 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
12333
12417
  while (1) switch (_context.n) {
12334
12418
  case 0:
12335
12419
  api = _ref.api, senderAddress = _ref.senderAddress, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency, buildTx = _ref.buildTx, feeAsset = _ref.feeAsset;
12336
- validateAddress(senderAddress, chain, false);
12420
+ validateAddress(api, senderAddress, chain, false);
12337
12421
  resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, chain, destination, currency) : undefined;
12338
12422
  asset = findAssetInfoOrThrow(chain, currency, null);
12339
12423
  amount = abstractDecimals(currency.amount, asset.decimals, api);
@@ -12449,57 +12533,6 @@ var buildTypeAndThenCall = function buildTypeAndThenCall(_ref, isDotAsset, custo
12449
12533
  };
12450
12534
  };
12451
12535
 
12452
- var FEE_PADDING = 30;
12453
- var sumHopFees = function sumHopFees(result, asset) {
12454
- return result.hops.reduce(function (acc, hop) {
12455
- // only add if asset is equal
12456
- return isAssetEqual(hop.result.asset, asset) ? acc + hop.result.fee : acc;
12457
- }, 0n);
12458
- };
12459
- var computeAllFees = /*#__PURE__*/function () {
12460
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context, buildTx) {
12461
- var origin, dest, assetInfo, _context$options, senderAddress, address, currency, feeCurrency, result, hopFees, destFee;
12462
- return _regenerator().w(function (_context) {
12463
- while (1) switch (_context.n) {
12464
- case 0:
12465
- origin = context.origin, dest = context.dest, assetInfo = context.assetInfo, _context$options = context.options, senderAddress = _context$options.senderAddress, address = _context$options.address, currency = _context$options.currency, feeCurrency = _context$options.feeCurrency;
12466
- assertSenderAddress(senderAddress);
12467
- assertAddressIsString(address);
12468
- if (hasDryRunSupport(context.origin.chain)) {
12469
- _context.n = 1;
12470
- break;
12471
- }
12472
- return _context.a(2, null);
12473
- case 1:
12474
- _context.n = 2;
12475
- return getXcmFeeInternal({
12476
- api: origin.api,
12477
- buildTx: buildTx,
12478
- origin: origin.chain,
12479
- destination: dest.chain,
12480
- senderAddress: senderAddress,
12481
- address: address,
12482
- currency: currency,
12483
- feeAsset: feeCurrency,
12484
- disableFallback: false,
12485
- skipReverseFeeCalculation: true
12486
- });
12487
- case 2:
12488
- result = _context.v;
12489
- hopFees = sumHopFees(result, assetInfo);
12490
- destFee = result.destination.fee;
12491
- return _context.a(2, {
12492
- hopFees: padValueBy(hopFees, FEE_PADDING),
12493
- destFee: padValueBy(destFee, FEE_PADDING)
12494
- });
12495
- }
12496
- }, _callee);
12497
- }));
12498
- return function computeAllFees(_x, _x2) {
12499
- return _ref.apply(this, arguments);
12500
- };
12501
- }();
12502
-
12503
12536
  var RELAY_ASSET_LOCATIONS = [RELAY_LOCATION, {
12504
12537
  parents: 2,
12505
12538
  interior: {
@@ -12639,9 +12672,7 @@ var createCustomXcm = function createCustomXcm(context, assetCount, isForFeeCalc
12639
12672
  if (isSubBridge || origin.chain !== reserve.chain && dest.chain !== reserve.chain) {
12640
12673
  var buyExecutionAmount = resolveBuyExecutionAmount(context, isForFeeCalc, fees, systemAssetAmount);
12641
12674
  if (buyExecutionAmount < 0n && !isForFeeCalc) throw new AmountTooLowError();
12642
- var filter = isForFeeCalc ? {
12643
- Wild: 'All'
12644
- } : {
12675
+ var filter = {
12645
12676
  Definite: assetsFilter
12646
12677
  };
12647
12678
  var buyExecution = {
@@ -12696,11 +12727,12 @@ var createRefundInstruction = function createRefundInstruction(api, senderAddres
12696
12727
 
12697
12728
  var buildAssets = function buildAssets(chain, asset, feeAmount, isDotAsset, version) {
12698
12729
  var assets = [];
12730
+ var shouldLocalizeAndSort = isRelayChain(chain) || chain.startsWith('AssetHub');
12699
12731
  if (!isDotAsset) {
12700
12732
  assets.push(createAsset(version, feeAmount, RELAY_LOCATION));
12701
12733
  }
12702
- assets.push(createAsset(version, asset.amount, isRelayChain(chain) ? localizeLocation(chain, asset.location) : asset.location));
12703
- return assets;
12734
+ assets.push(createAsset(version, asset.amount, shouldLocalizeAndSort ? localizeLocation(chain, asset.location) : asset.location));
12735
+ return shouldLocalizeAndSort ? sortAssets(assets) : assets;
12704
12736
  };
12705
12737
  var DEFAULT_SYSTEM_ASSET_AMOUNT = '1';
12706
12738
  var resolveSystemAssetAmount = function resolveSystemAssetAmount(_ref, isForFeeCalc, fees) {
@@ -12887,7 +12919,7 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
12887
12919
  }
12888
12920
  return _context.a(2, true);
12889
12921
  case 1:
12890
- validateAddress(address, destination);
12922
+ validateAddress(api, address, destination, true);
12891
12923
  if (!(origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama')) {
12892
12924
  _context.n = 2;
12893
12925
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-core",
3
- "version": "11.14.2",
3
+ "version": "11.14.4",
4
4
  "description": "SDK core for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,9 +26,9 @@
26
26
  "@noble/hashes": "^1.8.0",
27
27
  "@scure/base": "^2.0.0",
28
28
  "viem": "^2.38.5",
29
- "@paraspell/assets": "11.14.2",
30
- "@paraspell/pallets": "11.14.2",
31
- "@paraspell/sdk-common": "11.14.2"
29
+ "@paraspell/assets": "11.14.4",
30
+ "@paraspell/sdk-common": "11.14.4",
31
+ "@paraspell/pallets": "11.14.4"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/plugin-syntax-import-attributes": "^7.27.1",