@paraspell/sdk-pjs 11.9.2 → 11.10.0

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
@@ -340,6 +340,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
340
340
  key: "resolveApi",
341
341
  value: function () {
342
342
  var _resolveApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(apiConfig, chain) {
343
+ var wsUrl;
343
344
  return _regenerator().w(function (_context2) {
344
345
  while (1) switch (_context2.n) {
345
346
  case 0:
@@ -347,7 +348,8 @@ var PolkadotJsApi = /*#__PURE__*/function () {
347
348
  _context2.n = 1;
348
349
  break;
349
350
  }
350
- return _context2.a(2, sdkCore.createChainClient(this, chain));
351
+ wsUrl = sdkCore.getChainProviders(chain);
352
+ return _context2.a(2, this.createApiInstance(wsUrl, chain));
351
353
  case 1:
352
354
  if (!(typeof apiConfig === 'string' || apiConfig instanceof Array)) {
353
355
  _context2.n = 2;
@@ -418,7 +420,12 @@ var PolkadotJsApi = /*#__PURE__*/function () {
418
420
  }, {
419
421
  key: "callDispatchAsMethod",
420
422
  value: function callDispatchAsMethod(call, address) {
421
- return this.api.tx.utility.dispatchAs(address, call);
423
+ var origin = {
424
+ system: {
425
+ Signed: address
426
+ }
427
+ };
428
+ return this.api.tx.utility.dispatchAs(origin, call);
422
429
  }
423
430
  }, {
424
431
  key: "objectToHex",
@@ -777,13 +784,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
777
784
  }, {
778
785
  key: "getDryRunCall",
779
786
  value: function () {
780
- var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(_ref4) {
787
+ var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(options) {
781
788
  var _this = this;
782
- var tx, address, feeAsset, chain, supportsDryRunApi, DEFAULT_XCM_VERSION, usedAsset, usedSymbol, performDryRunCall, getExecutionSuccessFromResult, extractFailureReasonFromResult, response, resultHuman, resultJson, isSuccess, failureReason, shouldRetryWithVersion, msg, _msg, executionFee, fee, actualWeight, weight, forwardedXcms, destParaId, _t, _t2;
789
+ var tx, address, feeAsset, chain, destination, _options$useRootOrigi, useRootOrigin, bypassOptions, supportsDryRunApi, DEFAULT_XCM_VERSION, basePayload, resolvedTx, usedAsset, usedSymbol, performDryRunCall, getExecutionSuccessFromResult, extractFailureReasonFromResult, response, resultHuman, resultJson, isSuccess, failureReason, shouldRetryWithVersion, msg, _msg, forwardedXcms, actualWeight, weight, nativeAsset, hasLocation, destParaId, xcmFee, executionFee, fee, _t, _t2, _t3;
783
790
  return _regenerator().w(function (_context16) {
784
791
  while (1) switch (_context16.p = _context16.n) {
785
792
  case 0:
786
- tx = _ref4.tx, address = _ref4.address, feeAsset = _ref4.feeAsset, chain = _ref4.chain;
793
+ tx = options.tx, address = options.address, feeAsset = options.feeAsset, chain = options.chain, destination = options.destination, _options$useRootOrigi = options.useRootOrigin, useRootOrigin = _options$useRootOrigi === void 0 ? false : _options$useRootOrigi, bypassOptions = options.bypassOptions;
787
794
  supportsDryRunApi = sdkCore.getAssetsObject(chain).supportsDryRunApi;
788
795
  if (supportsDryRunApi) {
789
796
  _context16.n = 1;
@@ -792,24 +799,45 @@ var PolkadotJsApi = /*#__PURE__*/function () {
792
799
  throw new sdkCore.ChainNotSupportedError("DryRunApi is not available on chain ".concat(chain));
793
800
  case 1:
794
801
  DEFAULT_XCM_VERSION = 3;
802
+ basePayload = useRootOrigin ? {
803
+ system: {
804
+ Root: null
805
+ }
806
+ } : {
807
+ system: {
808
+ Signed: address
809
+ }
810
+ };
811
+ if (!useRootOrigin) {
812
+ _context16.n = 3;
813
+ break;
814
+ }
815
+ _context16.n = 2;
816
+ return sdkCore.wrapTxBypass(_objectSpread2(_objectSpread2({}, options), {}, {
817
+ api: this
818
+ }), bypassOptions);
819
+ case 2:
820
+ _t = _context16.v;
821
+ _context16.n = 4;
822
+ break;
823
+ case 3:
824
+ _t = tx;
825
+ case 4:
826
+ resolvedTx = _t;
795
827
  usedAsset = feeAsset !== null && feeAsset !== void 0 ? feeAsset : sdkCore.findNativeAssetInfoOrThrow(chain);
796
828
  usedSymbol = usedAsset.symbol;
797
829
  performDryRunCall = /*#__PURE__*/function () {
798
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(includeVersion) {
830
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(includeVersion) {
799
831
  var _this$api$call$dryRun;
800
832
  return _regenerator().w(function (_context15) {
801
833
  while (1) switch (_context15.n) {
802
834
  case 0:
803
- return _context15.a(2, (_this$api$call$dryRun = _this.api.call.dryRunApi).dryRunCall.apply(_this$api$call$dryRun, [{
804
- system: {
805
- Signed: address
806
- }
807
- }, tx].concat(_toConsumableArray(includeVersion ? [DEFAULT_XCM_VERSION] : []))));
835
+ return _context15.a(2, (_this$api$call$dryRun = _this.api.call.dryRunApi).dryRunCall.apply(_this$api$call$dryRun, [basePayload, resolvedTx].concat(_toConsumableArray(includeVersion ? [DEFAULT_XCM_VERSION] : []))));
808
836
  }
809
837
  }, _callee15);
810
838
  }));
811
839
  return function performDryRunCall(_x33) {
812
- return _ref5.apply(this, arguments);
840
+ return _ref4.apply(this, arguments);
813
841
  };
814
842
  }();
815
843
  getExecutionSuccessFromResult = function getExecutionSuccessFromResult(resultHuman) {
@@ -817,7 +845,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
817
845
  return Boolean((resultHuman === null || resultHuman === void 0 ? void 0 : resultHuman.Ok) && ((_resultHuman$Ok$execu = resultHuman.Ok.executionResult) === null || _resultHuman$Ok$execu === void 0 ? void 0 : _resultHuman$Ok$execu.Ok));
818
846
  };
819
847
  extractFailureReasonFromResult = function extractFailureReasonFromResult(resultHuman, resultJson) {
820
- var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok, _ref6;
848
+ var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok, _ref5;
821
849
  var modErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$Ok = resultHuman.Ok) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.executionResult) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.Err) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.error) === null || _resultHuman$Ok === void 0 ? void 0 : _resultHuman$Ok.Module;
822
850
  if (modErrHuman) {
823
851
  return sdkCore.resolveModuleError(chain, modErrHuman);
@@ -833,15 +861,15 @@ var PolkadotJsApi = /*#__PURE__*/function () {
833
861
  if (execErrJson !== null && execErrJson !== void 0 && execErrJson.other) {
834
862
  return String(execErrJson.other);
835
863
  }
836
- return JSON.stringify((_ref6 = resultJson !== null && resultJson !== void 0 ? resultJson : resultHuman) !== null && _ref6 !== void 0 ? _ref6 : 'Unknown error');
864
+ return JSON.stringify((_ref5 = resultJson !== null && resultJson !== void 0 ? resultJson : resultHuman) !== null && _ref5 !== void 0 ? _ref5 : 'Unknown error');
837
865
  }; // Attempt 1: WITHOUT version
838
866
  isSuccess = false;
839
867
  failureReason = '';
840
868
  shouldRetryWithVersion = false;
841
- _context16.p = 2;
842
- _context16.n = 3;
869
+ _context16.p = 5;
870
+ _context16.n = 6;
843
871
  return performDryRunCall(false);
844
- case 3:
872
+ case 6:
845
873
  response = _context16.v;
846
874
  resultHuman = response.toHuman();
847
875
  resultJson = response.toJSON();
@@ -852,35 +880,35 @@ var PolkadotJsApi = /*#__PURE__*/function () {
852
880
  shouldRetryWithVersion = true;
853
881
  }
854
882
  }
855
- _context16.n = 6;
883
+ _context16.n = 9;
856
884
  break;
857
- case 4:
858
- _context16.p = 4;
859
- _t = _context16.v;
860
- msg = _t instanceof Error ? _t.message : String(_t);
885
+ case 7:
886
+ _context16.p = 7;
887
+ _t2 = _context16.v;
888
+ msg = _t2 instanceof Error ? _t2.message : String(_t2);
861
889
  if (!msg.includes('Expected 3 arguments')) {
862
- _context16.n = 5;
890
+ _context16.n = 8;
863
891
  break;
864
892
  }
865
893
  shouldRetryWithVersion = true;
866
- _context16.n = 6;
894
+ _context16.n = 9;
867
895
  break;
868
- case 5:
896
+ case 8:
869
897
  return _context16.a(2, {
870
898
  success: false,
871
899
  failureReason: msg,
872
900
  currency: usedSymbol,
873
901
  asset: usedAsset
874
902
  });
875
- case 6:
903
+ case 9:
876
904
  if (!shouldRetryWithVersion) {
877
- _context16.n = 10;
905
+ _context16.n = 13;
878
906
  break;
879
907
  }
880
- _context16.p = 7;
881
- _context16.n = 8;
908
+ _context16.p = 10;
909
+ _context16.n = 11;
882
910
  return performDryRunCall(true);
883
- case 8:
911
+ case 11:
884
912
  response = _context16.v;
885
913
  resultHuman = response.toHuman();
886
914
  resultJson = response.toJSON();
@@ -888,12 +916,12 @@ var PolkadotJsApi = /*#__PURE__*/function () {
888
916
  if (!isSuccess) {
889
917
  failureReason = extractFailureReasonFromResult(resultHuman, resultJson);
890
918
  }
891
- _context16.n = 10;
919
+ _context16.n = 13;
892
920
  break;
893
- case 9:
894
- _context16.p = 9;
895
- _t2 = _context16.v;
896
- _msg = _t2 instanceof Error ? _t2.message : String(_t2);
921
+ case 12:
922
+ _context16.p = 12;
923
+ _t3 = _context16.v;
924
+ _msg = _t3 instanceof Error ? _t3.message : String(_t3);
897
925
  failureReason = failureReason || _msg;
898
926
  return _context16.a(2, {
899
927
  success: false,
@@ -901,9 +929,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
901
929
  currency: usedSymbol,
902
930
  asset: usedAsset
903
931
  });
904
- case 10:
932
+ case 13:
905
933
  if (isSuccess) {
906
- _context16.n = 11;
934
+ _context16.n = 14;
907
935
  break;
908
936
  }
909
937
  return _context16.a(2, {
@@ -912,21 +940,45 @@ var PolkadotJsApi = /*#__PURE__*/function () {
912
940
  currency: usedSymbol,
913
941
  asset: usedAsset
914
942
  });
915
- case 11:
916
- _context16.n = 12;
917
- return this.calculateTransactionFee(tx, address);
918
- case 12:
919
- executionFee = _context16.v;
920
- fee = sdkCore.computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
943
+ case 14:
944
+ forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
921
945
  actualWeight = resultJson.ok.executionResult.ok.actualWeight;
922
946
  weight = actualWeight ? {
923
947
  refTime: BigInt(actualWeight.refTime),
924
948
  proofSize: BigInt(actualWeight.proofSize)
925
949
  } : undefined;
926
- forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
927
- destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref7) {
928
- return i.here === null ? 0 : (_ref7 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref7 === void 0 ? void 0 : _ref7.parachain;
950
+ nativeAsset = sdkCore.findNativeAssetInfoOrThrow(chain);
951
+ hasLocation = feeAsset ? Boolean(feeAsset.location) : Boolean(nativeAsset === null || nativeAsset === void 0 ? void 0 : nativeAsset.location);
952
+ destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref6) {
953
+ return i.here === null ? 0 : (_ref6 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref6 === void 0 ? void 0 : _ref6.parachain;
929
954
  }(Object.values(forwardedXcms[0])[0].interior);
955
+ if (!(sdkCore.hasXcmPaymentApiSupport(chain) && resultJson.ok.local_xcm && hasLocation && (feeAsset || chain.startsWith('AssetHub') && destination === 'Ethereum'))) {
956
+ _context16.n = 16;
957
+ break;
958
+ }
959
+ _context16.n = 15;
960
+ return this.getXcmPaymentApiFee(chain, resultJson.ok.local_xcm, forwardedXcms, feeAsset !== null && feeAsset !== void 0 ? feeAsset : nativeAsset);
961
+ case 15:
962
+ xcmFee = _context16.v;
963
+ if (!(typeof xcmFee === 'bigint')) {
964
+ _context16.n = 16;
965
+ break;
966
+ }
967
+ return _context16.a(2, Promise.resolve({
968
+ success: true,
969
+ fee: xcmFee,
970
+ currency: usedSymbol,
971
+ asset: usedAsset,
972
+ weight: weight,
973
+ forwardedXcms: forwardedXcms,
974
+ destParaId: destParaId
975
+ }));
976
+ case 16:
977
+ _context16.n = 17;
978
+ return this.calculateTransactionFee(tx, address);
979
+ case 17:
980
+ executionFee = _context16.v;
981
+ fee = sdkCore.computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
930
982
  return _context16.a(2, {
931
983
  success: true,
932
984
  fee: fee,
@@ -937,7 +989,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
937
989
  destParaId: destParaId
938
990
  });
939
991
  }
940
- }, _callee16, this, [[7, 9], [2, 4]]);
992
+ }, _callee16, this, [[10, 12], [5, 7]]);
941
993
  }));
942
994
  function getDryRunCall(_x32) {
943
995
  return _getDryRunCall.apply(this, arguments);
@@ -947,27 +999,68 @@ var PolkadotJsApi = /*#__PURE__*/function () {
947
999
  }, {
948
1000
  key: "getXcmPaymentApiFee",
949
1001
  value: function () {
950
- var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(chain, xcm, asset) {
951
- var weight, localizedLocation, feeResult, res;
1002
+ var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(chain, localXcm, forwardedXcm, asset) {
1003
+ var _ref7, _deliveryFeeResJson$o, _deliveryFeeResJson$o2, _deliveryFeeResJson$o3, _ref8, _deliveryFeeResJson$o4, _deliveryFeeResJson$o5, _deliveryFeeResJson$o6;
1004
+ var weight, assetLocalizedLoc, feeResult, execFeeRes, execFee, deliveryFeeRes, deliveryFeeResJson, deliveryFeeResolved, nativeAsset, deliveryFee, res, _t4;
952
1005
  return _regenerator().w(function (_context17) {
953
- while (1) switch (_context17.n) {
1006
+ while (1) switch (_context17.p = _context17.n) {
954
1007
  case 0:
955
1008
  _context17.n = 1;
956
- return this.getXcmWeight(xcm);
1009
+ return this.getXcmWeight(localXcm);
957
1010
  case 1:
958
1011
  weight = _context17.v;
959
1012
  sdkCore.assertHasLocation(asset);
960
- localizedLocation = chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama' || sdkCore.isRelayChain(chain) ? sdkCore.localizeLocation(chain, asset.location) : asset.location;
1013
+ assetLocalizedLoc = sdkCore.localizeLocation(chain, asset.location);
961
1014
  _context17.n = 2;
962
- return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, sdkCore.addXcmVersionHeader(localizedLocation, sdkCore.Version.V4));
1015
+ return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, sdkCore.addXcmVersionHeader(assetLocalizedLoc, sdkCore.Version.V4));
963
1016
  case 2:
964
1017
  feeResult = _context17.v;
965
- res = feeResult.toJSON();
966
- return _context17.a(2, BigInt(res.ok));
1018
+ execFeeRes = feeResult.toJSON();
1019
+ execFee = BigInt(execFeeRes.ok);
1020
+ if (!(forwardedXcm.length > 0)) {
1021
+ _context17.n = 4;
1022
+ break;
1023
+ }
1024
+ _context17.n = 3;
1025
+ return this.api.call.xcmPaymentApi.queryDeliveryFees(forwardedXcm[0], forwardedXcm[1][0]);
1026
+ case 3:
1027
+ _t4 = _context17.v;
1028
+ _context17.n = 5;
1029
+ break;
1030
+ case 4:
1031
+ _t4 = undefined;
1032
+ case 5:
1033
+ deliveryFeeRes = _t4;
1034
+ deliveryFeeResJson = deliveryFeeRes === null || deliveryFeeRes === void 0 ? void 0 : deliveryFeeRes.toJSON();
1035
+ deliveryFeeResolved = deliveryFeeRes && ((_ref7 = (_deliveryFeeResJson$o = (_deliveryFeeResJson$o2 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o2 === void 0 ? void 0 : _deliveryFeeResJson$o2.v4) !== null && _deliveryFeeResJson$o !== void 0 ? _deliveryFeeResJson$o : (_deliveryFeeResJson$o3 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o3 === void 0 ? void 0 : _deliveryFeeResJson$o3.v3) === null || _ref7 === void 0 ? void 0 : _ref7.length) > 0 ? BigInt((_ref8 = (_deliveryFeeResJson$o4 = deliveryFeeResJson === null || deliveryFeeResJson === void 0 || (_deliveryFeeResJson$o5 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o5 === void 0 ? void 0 : _deliveryFeeResJson$o5.v4) !== null && _deliveryFeeResJson$o4 !== void 0 ? _deliveryFeeResJson$o4 : deliveryFeeResJson === null || deliveryFeeResJson === void 0 || (_deliveryFeeResJson$o6 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o6 === void 0 ? void 0 : _deliveryFeeResJson$o6.v3) === null || _ref8 === void 0 || (_ref8 = _ref8[0]) === null || _ref8 === void 0 || (_ref8 = _ref8.fun) === null || _ref8 === void 0 ? void 0 : _ref8.fungible) : 0n;
1036
+ nativeAsset = sdkCore.findNativeAssetInfoOrThrow(chain);
1037
+ if (!sdkCore.isAssetXcEqual(asset, nativeAsset)) {
1038
+ _context17.n = 6;
1039
+ break;
1040
+ }
1041
+ deliveryFee = deliveryFeeResolved;
1042
+ _context17.n = 9;
1043
+ break;
1044
+ case 6:
1045
+ _context17.p = 6;
1046
+ sdkCore.assertHasLocation(nativeAsset);
1047
+ _context17.n = 7;
1048
+ return this.quoteAhPrice(sdkCore.localizeLocation(chain, nativeAsset.location), assetLocalizedLoc, deliveryFeeResolved, false);
1049
+ case 7:
1050
+ res = _context17.v;
1051
+ deliveryFee = res !== null && res !== void 0 ? res : 0n;
1052
+ _context17.n = 9;
1053
+ break;
1054
+ case 8:
1055
+ _context17.p = 8;
1056
+ _context17.v;
1057
+ deliveryFee = 0n;
1058
+ case 9:
1059
+ return _context17.a(2, execFee + deliveryFee);
967
1060
  }
968
- }, _callee17, this);
1061
+ }, _callee17, this, [[6, 8]]);
969
1062
  }));
970
- function getXcmPaymentApiFee(_x34, _x35, _x36) {
1063
+ function getXcmPaymentApiFee(_x34, _x35, _x36, _x37) {
971
1064
  return _getXcmPaymentApiFee.apply(this, arguments);
972
1065
  }
973
1066
  return getXcmPaymentApiFee;
@@ -989,7 +1082,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
989
1082
  }
990
1083
  }, _callee18, this);
991
1084
  }));
992
- function getXcmWeight(_x37) {
1085
+ function getXcmWeight(_x38) {
993
1086
  return _getXcmWeight.apply(this, arguments);
994
1087
  }
995
1088
  return getXcmWeight;
@@ -997,13 +1090,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
997
1090
  }, {
998
1091
  key: "getDryRunXcm",
999
1092
  value: function () {
1000
- var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(_ref8) {
1001
- var _ref9, _ref0, _ref1;
1002
- var originLocation, xcm, asset, chain, origin, supportsDryRunApi, response, result, resultJson, symbol, isSuccess, failureReason, emitted, reversedEvents, palletsWithIssued, feeEvent, feeAmount, fee, actualWeight, weight, forwardedXcms, destParaId;
1093
+ var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(_ref9) {
1094
+ var _ref1, _ref10, _ref11;
1095
+ var originLocation, xcm, asset, chain, origin, supportsDryRunApi, response, result, resultJson, symbol, isSuccess, failureReason, forwardedXcms, actualWeight, weight, destParaId, _fee, emitted, reversedEvents, palletsWithIssued, feeEvent, feeAmount, fee;
1003
1096
  return _regenerator().w(function (_context19) {
1004
1097
  while (1) switch (_context19.n) {
1005
1098
  case 0:
1006
- originLocation = _ref8.originLocation, xcm = _ref8.xcm, asset = _ref8.asset, chain = _ref8.chain, origin = _ref8.origin;
1099
+ originLocation = _ref9.originLocation, xcm = _ref9.xcm, asset = _ref9.asset, chain = _ref9.chain, origin = _ref9.origin;
1007
1100
  supportsDryRunApi = sdkCore.getAssetsObject(chain).supportsDryRunApi;
1008
1101
  if (supportsDryRunApi) {
1009
1102
  _context19.n = 1;
@@ -1031,24 +1124,55 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1031
1124
  asset: asset
1032
1125
  });
1033
1126
  case 3:
1127
+ forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
1128
+ actualWeight = resultJson.ok.executionResult.used;
1129
+ weight = actualWeight ? {
1130
+ refTime: BigInt(actualWeight.refTime),
1131
+ proofSize: BigInt(actualWeight.proofSize)
1132
+ } : undefined;
1133
+ destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref0) {
1134
+ return i.Here ? 0 : (_ref0 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref0 === void 0 ? void 0 : _ref0.parachain;
1135
+ }(Object.values(forwardedXcms[0])[0].interior);
1136
+ if (!(sdkCore.hasXcmPaymentApiSupport(chain) && asset)) {
1137
+ _context19.n = 5;
1138
+ break;
1139
+ }
1140
+ _context19.n = 4;
1141
+ return this.getXcmPaymentApiFee(chain, xcm, forwardedXcms, asset);
1142
+ case 4:
1143
+ _fee = _context19.v;
1144
+ if (!(typeof _fee === 'bigint')) {
1145
+ _context19.n = 5;
1146
+ break;
1147
+ }
1148
+ return _context19.a(2, {
1149
+ success: true,
1150
+ fee: _fee,
1151
+ currency: symbol,
1152
+ asset: asset,
1153
+ weight: weight,
1154
+ forwardedXcms: forwardedXcms,
1155
+ destParaId: destParaId
1156
+ });
1157
+ case 5:
1034
1158
  emitted = result.Ok.emittedEvents; // We want to look for the last event
1035
1159
  reversedEvents = _toConsumableArray(emitted).reverse();
1036
1160
  palletsWithIssued = ['balances', 'foreignAssets', 'assets'];
1037
- feeEvent = (_ref9 = (_ref0 = (_ref1 = origin === 'Mythos' ? reversedEvents.find(function (event) {
1161
+ feeEvent = (_ref1 = (_ref10 = (_ref11 = origin === 'Mythos' ? reversedEvents.find(function (event) {
1038
1162
  return event.section === 'assetConversion' && event.method === 'SwapCreditExecuted';
1039
- }) : undefined) !== null && _ref1 !== void 0 ? _ref1 :
1163
+ }) : undefined) !== null && _ref11 !== void 0 ? _ref11 :
1040
1164
  // Prefer an Issued event
1041
1165
  reversedEvents.find(function (event) {
1042
1166
  return palletsWithIssued.includes(event.section) && event.method === 'Issued';
1043
- })) !== null && _ref0 !== void 0 ? _ref0 :
1167
+ })) !== null && _ref10 !== void 0 ? _ref10 :
1044
1168
  // Fallback to Minted event
1045
1169
  reversedEvents.find(function (event) {
1046
1170
  return ['balances', 'foreignAssets'].includes(event.section) && event.method === 'Minted';
1047
- })) !== null && _ref9 !== void 0 ? _ref9 : reversedEvents.find(function (event) {
1171
+ })) !== null && _ref1 !== void 0 ? _ref1 : reversedEvents.find(function (event) {
1048
1172
  return ['currencies', 'tokens'].includes(event.section) && event.method === 'Deposited';
1049
1173
  });
1050
1174
  if (feeEvent) {
1051
- _context19.n = 4;
1175
+ _context19.n = 6;
1052
1176
  break;
1053
1177
  }
1054
1178
  return _context19.a(2, Promise.resolve({
@@ -1057,18 +1181,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1057
1181
  currency: symbol,
1058
1182
  asset: asset
1059
1183
  }));
1060
- case 4:
1184
+ case 6:
1061
1185
  feeAmount = feeEvent.section === 'assetConversion' ? feeEvent.data.amountIn : feeEvent.data.amount;
1062
1186
  fee = BigInt(feeAmount.replace(/,/g, ''));
1063
- actualWeight = resultJson.ok.executionResult.used;
1064
- weight = actualWeight ? {
1065
- refTime: BigInt(actualWeight.refTime),
1066
- proofSize: BigInt(actualWeight.proofSize)
1067
- } : undefined;
1068
- forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
1069
- destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref10) {
1070
- return i.Here ? 0 : (_ref10 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref10 === void 0 ? void 0 : _ref10.parachain;
1071
- }(Object.values(forwardedXcms[0])[0].interior);
1072
1187
  return _context19.a(2, {
1073
1188
  success: true,
1074
1189
  fee: fee,
@@ -1081,7 +1196,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1081
1196
  }
1082
1197
  }, _callee19, this);
1083
1198
  }));
1084
- function getDryRunXcm(_x38) {
1199
+ function getDryRunXcm(_x39) {
1085
1200
  return _getDryRunXcm.apply(this, arguments);
1086
1201
  }
1087
1202
  return getDryRunXcm;
@@ -1134,7 +1249,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1134
1249
  }
1135
1250
  }, _callee21, this);
1136
1251
  }));
1137
- function convertLocationToAccount(_x39) {
1252
+ function convertLocationToAccount(_x40) {
1138
1253
  return _convertLocationToAccount.apply(this, arguments);
1139
1254
  }
1140
1255
  return convertLocationToAccount;
@@ -1183,8 +1298,8 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1183
1298
  }]);
1184
1299
  }();
1185
1300
 
1186
- var createChainClient = function createChainClient(chain) {
1187
- var pjsApi = new PolkadotJsApi();
1301
+ var createChainClient = function createChainClient(chain, builderOptions) {
1302
+ var pjsApi = new PolkadotJsApi(builderOptions);
1188
1303
  return sdkCore.createChainClient(pjsApi, chain);
1189
1304
  };
1190
1305
  var createPolkadotJsApiCall = function createPolkadotJsApiCall(apiCall) {
package/dist/index.d.ts CHANGED
@@ -282,7 +282,7 @@ declare namespace transfer {
282
282
  };
283
283
  }
284
284
 
285
- declare const createChainClient: (chain: TSubstrateChain) => Promise<_polkadot_api.ApiPromise>;
285
+ declare const createChainClient: (chain: TSubstrateChain, builderOptions?: TBuilderOptions<TPjsApiOrUrl>) => Promise<_polkadot_api.ApiPromise>;
286
286
 
287
287
  export { Builder, EvmBuilder, approveToken, assets, claimAssets, convertSs58, createChainClient, depositToken, dryRun, dryRunOrigin, getAssetBalance, getBalanceForeign, getBalanceNative, getBridgeStatus, getOriginFeeDetails, getParaEthTransferFees, getTokenBalance, send, transferEthToPolkadot, transfer as xcmPallet };
288
288
  export type { Extrinsic, GeneralBuilder, TBalanceResponse, TPjsApi, TPjsApiOrUrl, TPjsEvmBuilderOptions };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isConfig, BatchMode, MissingChainApiError, createChainClient as createChainClient$1, assertHasId, getChain, isForeignAsset, InvalidParameterError, computeFeeFromDryRunPjs, findNativeAssetInfoOrThrow, resolveModuleError, getAssetsObject, ChainNotSupportedError, assertHasLocation, localizeLocation, isRelayChain, addXcmVersionHeader, Version, getBalanceNative as getBalanceNative$1, getBalanceForeign as getBalanceForeign$1, getAssetBalance as getAssetBalance$1, claimAssets as claimAssets$1, getOriginFeeDetails as getOriginFeeDetails$1, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, convertSs58 as convertSs58$1, getParaId, ETH_CHAIN_ID, findAssetInfoOrThrow, abstractDecimals, isOverrideLocationSpecifier, transferMoonbeamEvm, transferMoonbeamToEth, validateAddress, Builder as Builder$1, getParaEthTransferFees as getParaEthTransferFees$1, DRY_RUN_CLIENT_TIMEOUT_MS, getBridgeStatus as getBridgeStatus$1, send as send$1, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1 } from '@paraspell/sdk-core';
1
+ import { isConfig, BatchMode, MissingChainApiError, getChainProviders, assertHasId, getChain, isForeignAsset, InvalidParameterError, computeFeeFromDryRunPjs, findNativeAssetInfoOrThrow, hasXcmPaymentApiSupport, resolveModuleError, getAssetsObject, ChainNotSupportedError, wrapTxBypass, assertHasLocation, localizeLocation, isAssetXcEqual, addXcmVersionHeader, Version, createChainClient as createChainClient$1, getBalanceNative as getBalanceNative$1, getBalanceForeign as getBalanceForeign$1, getAssetBalance as getAssetBalance$1, claimAssets as claimAssets$1, getOriginFeeDetails as getOriginFeeDetails$1, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, convertSs58 as convertSs58$1, getParaId, ETH_CHAIN_ID, findAssetInfoOrThrow, abstractDecimals, isOverrideLocationSpecifier, transferMoonbeamEvm, transferMoonbeamToEth, validateAddress, Builder as Builder$1, getParaEthTransferFees as getParaEthTransferFees$1, DRY_RUN_CLIENT_TIMEOUT_MS, getBridgeStatus as getBridgeStatus$1, send as send$1, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1 } from '@paraspell/sdk-core';
2
2
  export * from '@paraspell/sdk-core';
3
3
  import { WsProvider, ApiPromise } from '@polkadot/api';
4
4
  import { u32 } from '@polkadot/types';
@@ -339,6 +339,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
339
339
  key: "resolveApi",
340
340
  value: function () {
341
341
  var _resolveApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(apiConfig, chain) {
342
+ var wsUrl;
342
343
  return _regenerator().w(function (_context2) {
343
344
  while (1) switch (_context2.n) {
344
345
  case 0:
@@ -346,7 +347,8 @@ var PolkadotJsApi = /*#__PURE__*/function () {
346
347
  _context2.n = 1;
347
348
  break;
348
349
  }
349
- return _context2.a(2, createChainClient$1(this, chain));
350
+ wsUrl = getChainProviders(chain);
351
+ return _context2.a(2, this.createApiInstance(wsUrl, chain));
350
352
  case 1:
351
353
  if (!(typeof apiConfig === 'string' || apiConfig instanceof Array)) {
352
354
  _context2.n = 2;
@@ -417,7 +419,12 @@ var PolkadotJsApi = /*#__PURE__*/function () {
417
419
  }, {
418
420
  key: "callDispatchAsMethod",
419
421
  value: function callDispatchAsMethod(call, address) {
420
- return this.api.tx.utility.dispatchAs(address, call);
422
+ var origin = {
423
+ system: {
424
+ Signed: address
425
+ }
426
+ };
427
+ return this.api.tx.utility.dispatchAs(origin, call);
421
428
  }
422
429
  }, {
423
430
  key: "objectToHex",
@@ -776,13 +783,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
776
783
  }, {
777
784
  key: "getDryRunCall",
778
785
  value: function () {
779
- var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(_ref4) {
786
+ var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(options) {
780
787
  var _this = this;
781
- var tx, address, feeAsset, chain, supportsDryRunApi, DEFAULT_XCM_VERSION, usedAsset, usedSymbol, performDryRunCall, getExecutionSuccessFromResult, extractFailureReasonFromResult, response, resultHuman, resultJson, isSuccess, failureReason, shouldRetryWithVersion, msg, _msg, executionFee, fee, actualWeight, weight, forwardedXcms, destParaId, _t, _t2;
788
+ var tx, address, feeAsset, chain, destination, _options$useRootOrigi, useRootOrigin, bypassOptions, supportsDryRunApi, DEFAULT_XCM_VERSION, basePayload, resolvedTx, usedAsset, usedSymbol, performDryRunCall, getExecutionSuccessFromResult, extractFailureReasonFromResult, response, resultHuman, resultJson, isSuccess, failureReason, shouldRetryWithVersion, msg, _msg, forwardedXcms, actualWeight, weight, nativeAsset, hasLocation, destParaId, xcmFee, executionFee, fee, _t, _t2, _t3;
782
789
  return _regenerator().w(function (_context16) {
783
790
  while (1) switch (_context16.p = _context16.n) {
784
791
  case 0:
785
- tx = _ref4.tx, address = _ref4.address, feeAsset = _ref4.feeAsset, chain = _ref4.chain;
792
+ tx = options.tx, address = options.address, feeAsset = options.feeAsset, chain = options.chain, destination = options.destination, _options$useRootOrigi = options.useRootOrigin, useRootOrigin = _options$useRootOrigi === void 0 ? false : _options$useRootOrigi, bypassOptions = options.bypassOptions;
786
793
  supportsDryRunApi = getAssetsObject(chain).supportsDryRunApi;
787
794
  if (supportsDryRunApi) {
788
795
  _context16.n = 1;
@@ -791,24 +798,45 @@ var PolkadotJsApi = /*#__PURE__*/function () {
791
798
  throw new ChainNotSupportedError("DryRunApi is not available on chain ".concat(chain));
792
799
  case 1:
793
800
  DEFAULT_XCM_VERSION = 3;
801
+ basePayload = useRootOrigin ? {
802
+ system: {
803
+ Root: null
804
+ }
805
+ } : {
806
+ system: {
807
+ Signed: address
808
+ }
809
+ };
810
+ if (!useRootOrigin) {
811
+ _context16.n = 3;
812
+ break;
813
+ }
814
+ _context16.n = 2;
815
+ return wrapTxBypass(_objectSpread2(_objectSpread2({}, options), {}, {
816
+ api: this
817
+ }), bypassOptions);
818
+ case 2:
819
+ _t = _context16.v;
820
+ _context16.n = 4;
821
+ break;
822
+ case 3:
823
+ _t = tx;
824
+ case 4:
825
+ resolvedTx = _t;
794
826
  usedAsset = feeAsset !== null && feeAsset !== void 0 ? feeAsset : findNativeAssetInfoOrThrow(chain);
795
827
  usedSymbol = usedAsset.symbol;
796
828
  performDryRunCall = /*#__PURE__*/function () {
797
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(includeVersion) {
829
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(includeVersion) {
798
830
  var _this$api$call$dryRun;
799
831
  return _regenerator().w(function (_context15) {
800
832
  while (1) switch (_context15.n) {
801
833
  case 0:
802
- return _context15.a(2, (_this$api$call$dryRun = _this.api.call.dryRunApi).dryRunCall.apply(_this$api$call$dryRun, [{
803
- system: {
804
- Signed: address
805
- }
806
- }, tx].concat(_toConsumableArray(includeVersion ? [DEFAULT_XCM_VERSION] : []))));
834
+ return _context15.a(2, (_this$api$call$dryRun = _this.api.call.dryRunApi).dryRunCall.apply(_this$api$call$dryRun, [basePayload, resolvedTx].concat(_toConsumableArray(includeVersion ? [DEFAULT_XCM_VERSION] : []))));
807
835
  }
808
836
  }, _callee15);
809
837
  }));
810
838
  return function performDryRunCall(_x33) {
811
- return _ref5.apply(this, arguments);
839
+ return _ref4.apply(this, arguments);
812
840
  };
813
841
  }();
814
842
  getExecutionSuccessFromResult = function getExecutionSuccessFromResult(resultHuman) {
@@ -816,7 +844,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
816
844
  return Boolean((resultHuman === null || resultHuman === void 0 ? void 0 : resultHuman.Ok) && ((_resultHuman$Ok$execu = resultHuman.Ok.executionResult) === null || _resultHuman$Ok$execu === void 0 ? void 0 : _resultHuman$Ok$execu.Ok));
817
845
  };
818
846
  extractFailureReasonFromResult = function extractFailureReasonFromResult(resultHuman, resultJson) {
819
- var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok, _ref6;
847
+ var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok, _ref5;
820
848
  var modErrHuman = resultHuman === null || resultHuman === void 0 || (_resultHuman$Ok = resultHuman.Ok) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.executionResult) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.Err) === null || _resultHuman$Ok === void 0 || (_resultHuman$Ok = _resultHuman$Ok.error) === null || _resultHuman$Ok === void 0 ? void 0 : _resultHuman$Ok.Module;
821
849
  if (modErrHuman) {
822
850
  return resolveModuleError(chain, modErrHuman);
@@ -832,15 +860,15 @@ var PolkadotJsApi = /*#__PURE__*/function () {
832
860
  if (execErrJson !== null && execErrJson !== void 0 && execErrJson.other) {
833
861
  return String(execErrJson.other);
834
862
  }
835
- return JSON.stringify((_ref6 = resultJson !== null && resultJson !== void 0 ? resultJson : resultHuman) !== null && _ref6 !== void 0 ? _ref6 : 'Unknown error');
863
+ return JSON.stringify((_ref5 = resultJson !== null && resultJson !== void 0 ? resultJson : resultHuman) !== null && _ref5 !== void 0 ? _ref5 : 'Unknown error');
836
864
  }; // Attempt 1: WITHOUT version
837
865
  isSuccess = false;
838
866
  failureReason = '';
839
867
  shouldRetryWithVersion = false;
840
- _context16.p = 2;
841
- _context16.n = 3;
868
+ _context16.p = 5;
869
+ _context16.n = 6;
842
870
  return performDryRunCall(false);
843
- case 3:
871
+ case 6:
844
872
  response = _context16.v;
845
873
  resultHuman = response.toHuman();
846
874
  resultJson = response.toJSON();
@@ -851,35 +879,35 @@ var PolkadotJsApi = /*#__PURE__*/function () {
851
879
  shouldRetryWithVersion = true;
852
880
  }
853
881
  }
854
- _context16.n = 6;
882
+ _context16.n = 9;
855
883
  break;
856
- case 4:
857
- _context16.p = 4;
858
- _t = _context16.v;
859
- msg = _t instanceof Error ? _t.message : String(_t);
884
+ case 7:
885
+ _context16.p = 7;
886
+ _t2 = _context16.v;
887
+ msg = _t2 instanceof Error ? _t2.message : String(_t2);
860
888
  if (!msg.includes('Expected 3 arguments')) {
861
- _context16.n = 5;
889
+ _context16.n = 8;
862
890
  break;
863
891
  }
864
892
  shouldRetryWithVersion = true;
865
- _context16.n = 6;
893
+ _context16.n = 9;
866
894
  break;
867
- case 5:
895
+ case 8:
868
896
  return _context16.a(2, {
869
897
  success: false,
870
898
  failureReason: msg,
871
899
  currency: usedSymbol,
872
900
  asset: usedAsset
873
901
  });
874
- case 6:
902
+ case 9:
875
903
  if (!shouldRetryWithVersion) {
876
- _context16.n = 10;
904
+ _context16.n = 13;
877
905
  break;
878
906
  }
879
- _context16.p = 7;
880
- _context16.n = 8;
907
+ _context16.p = 10;
908
+ _context16.n = 11;
881
909
  return performDryRunCall(true);
882
- case 8:
910
+ case 11:
883
911
  response = _context16.v;
884
912
  resultHuman = response.toHuman();
885
913
  resultJson = response.toJSON();
@@ -887,12 +915,12 @@ var PolkadotJsApi = /*#__PURE__*/function () {
887
915
  if (!isSuccess) {
888
916
  failureReason = extractFailureReasonFromResult(resultHuman, resultJson);
889
917
  }
890
- _context16.n = 10;
918
+ _context16.n = 13;
891
919
  break;
892
- case 9:
893
- _context16.p = 9;
894
- _t2 = _context16.v;
895
- _msg = _t2 instanceof Error ? _t2.message : String(_t2);
920
+ case 12:
921
+ _context16.p = 12;
922
+ _t3 = _context16.v;
923
+ _msg = _t3 instanceof Error ? _t3.message : String(_t3);
896
924
  failureReason = failureReason || _msg;
897
925
  return _context16.a(2, {
898
926
  success: false,
@@ -900,9 +928,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
900
928
  currency: usedSymbol,
901
929
  asset: usedAsset
902
930
  });
903
- case 10:
931
+ case 13:
904
932
  if (isSuccess) {
905
- _context16.n = 11;
933
+ _context16.n = 14;
906
934
  break;
907
935
  }
908
936
  return _context16.a(2, {
@@ -911,21 +939,45 @@ var PolkadotJsApi = /*#__PURE__*/function () {
911
939
  currency: usedSymbol,
912
940
  asset: usedAsset
913
941
  });
914
- case 11:
915
- _context16.n = 12;
916
- return this.calculateTransactionFee(tx, address);
917
- case 12:
918
- executionFee = _context16.v;
919
- fee = computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
942
+ case 14:
943
+ forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
920
944
  actualWeight = resultJson.ok.executionResult.ok.actualWeight;
921
945
  weight = actualWeight ? {
922
946
  refTime: BigInt(actualWeight.refTime),
923
947
  proofSize: BigInt(actualWeight.proofSize)
924
948
  } : undefined;
925
- forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
926
- destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref7) {
927
- return i.here === null ? 0 : (_ref7 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref7 === void 0 ? void 0 : _ref7.parachain;
949
+ nativeAsset = findNativeAssetInfoOrThrow(chain);
950
+ hasLocation = feeAsset ? Boolean(feeAsset.location) : Boolean(nativeAsset === null || nativeAsset === void 0 ? void 0 : nativeAsset.location);
951
+ destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref6) {
952
+ return i.here === null ? 0 : (_ref6 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref6 === void 0 ? void 0 : _ref6.parachain;
928
953
  }(Object.values(forwardedXcms[0])[0].interior);
954
+ if (!(hasXcmPaymentApiSupport(chain) && resultJson.ok.local_xcm && hasLocation && (feeAsset || chain.startsWith('AssetHub') && destination === 'Ethereum'))) {
955
+ _context16.n = 16;
956
+ break;
957
+ }
958
+ _context16.n = 15;
959
+ return this.getXcmPaymentApiFee(chain, resultJson.ok.local_xcm, forwardedXcms, feeAsset !== null && feeAsset !== void 0 ? feeAsset : nativeAsset);
960
+ case 15:
961
+ xcmFee = _context16.v;
962
+ if (!(typeof xcmFee === 'bigint')) {
963
+ _context16.n = 16;
964
+ break;
965
+ }
966
+ return _context16.a(2, Promise.resolve({
967
+ success: true,
968
+ fee: xcmFee,
969
+ currency: usedSymbol,
970
+ asset: usedAsset,
971
+ weight: weight,
972
+ forwardedXcms: forwardedXcms,
973
+ destParaId: destParaId
974
+ }));
975
+ case 16:
976
+ _context16.n = 17;
977
+ return this.calculateTransactionFee(tx, address);
978
+ case 17:
979
+ executionFee = _context16.v;
980
+ fee = computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
929
981
  return _context16.a(2, {
930
982
  success: true,
931
983
  fee: fee,
@@ -936,7 +988,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
936
988
  destParaId: destParaId
937
989
  });
938
990
  }
939
- }, _callee16, this, [[7, 9], [2, 4]]);
991
+ }, _callee16, this, [[10, 12], [5, 7]]);
940
992
  }));
941
993
  function getDryRunCall(_x32) {
942
994
  return _getDryRunCall.apply(this, arguments);
@@ -946,27 +998,68 @@ var PolkadotJsApi = /*#__PURE__*/function () {
946
998
  }, {
947
999
  key: "getXcmPaymentApiFee",
948
1000
  value: function () {
949
- var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(chain, xcm, asset) {
950
- var weight, localizedLocation, feeResult, res;
1001
+ var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(chain, localXcm, forwardedXcm, asset) {
1002
+ var _ref7, _deliveryFeeResJson$o, _deliveryFeeResJson$o2, _deliveryFeeResJson$o3, _ref8, _deliveryFeeResJson$o4, _deliveryFeeResJson$o5, _deliveryFeeResJson$o6;
1003
+ var weight, assetLocalizedLoc, feeResult, execFeeRes, execFee, deliveryFeeRes, deliveryFeeResJson, deliveryFeeResolved, nativeAsset, deliveryFee, res, _t4;
951
1004
  return _regenerator().w(function (_context17) {
952
- while (1) switch (_context17.n) {
1005
+ while (1) switch (_context17.p = _context17.n) {
953
1006
  case 0:
954
1007
  _context17.n = 1;
955
- return this.getXcmWeight(xcm);
1008
+ return this.getXcmWeight(localXcm);
956
1009
  case 1:
957
1010
  weight = _context17.v;
958
1011
  assertHasLocation(asset);
959
- localizedLocation = chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama' || isRelayChain(chain) ? localizeLocation(chain, asset.location) : asset.location;
1012
+ assetLocalizedLoc = localizeLocation(chain, asset.location);
960
1013
  _context17.n = 2;
961
- return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, addXcmVersionHeader(localizedLocation, Version.V4));
1014
+ return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, addXcmVersionHeader(assetLocalizedLoc, Version.V4));
962
1015
  case 2:
963
1016
  feeResult = _context17.v;
964
- res = feeResult.toJSON();
965
- return _context17.a(2, BigInt(res.ok));
1017
+ execFeeRes = feeResult.toJSON();
1018
+ execFee = BigInt(execFeeRes.ok);
1019
+ if (!(forwardedXcm.length > 0)) {
1020
+ _context17.n = 4;
1021
+ break;
1022
+ }
1023
+ _context17.n = 3;
1024
+ return this.api.call.xcmPaymentApi.queryDeliveryFees(forwardedXcm[0], forwardedXcm[1][0]);
1025
+ case 3:
1026
+ _t4 = _context17.v;
1027
+ _context17.n = 5;
1028
+ break;
1029
+ case 4:
1030
+ _t4 = undefined;
1031
+ case 5:
1032
+ deliveryFeeRes = _t4;
1033
+ deliveryFeeResJson = deliveryFeeRes === null || deliveryFeeRes === void 0 ? void 0 : deliveryFeeRes.toJSON();
1034
+ deliveryFeeResolved = deliveryFeeRes && ((_ref7 = (_deliveryFeeResJson$o = (_deliveryFeeResJson$o2 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o2 === void 0 ? void 0 : _deliveryFeeResJson$o2.v4) !== null && _deliveryFeeResJson$o !== void 0 ? _deliveryFeeResJson$o : (_deliveryFeeResJson$o3 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o3 === void 0 ? void 0 : _deliveryFeeResJson$o3.v3) === null || _ref7 === void 0 ? void 0 : _ref7.length) > 0 ? BigInt((_ref8 = (_deliveryFeeResJson$o4 = deliveryFeeResJson === null || deliveryFeeResJson === void 0 || (_deliveryFeeResJson$o5 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o5 === void 0 ? void 0 : _deliveryFeeResJson$o5.v4) !== null && _deliveryFeeResJson$o4 !== void 0 ? _deliveryFeeResJson$o4 : deliveryFeeResJson === null || deliveryFeeResJson === void 0 || (_deliveryFeeResJson$o6 = deliveryFeeResJson.ok) === null || _deliveryFeeResJson$o6 === void 0 ? void 0 : _deliveryFeeResJson$o6.v3) === null || _ref8 === void 0 || (_ref8 = _ref8[0]) === null || _ref8 === void 0 || (_ref8 = _ref8.fun) === null || _ref8 === void 0 ? void 0 : _ref8.fungible) : 0n;
1035
+ nativeAsset = findNativeAssetInfoOrThrow(chain);
1036
+ if (!isAssetXcEqual(asset, nativeAsset)) {
1037
+ _context17.n = 6;
1038
+ break;
1039
+ }
1040
+ deliveryFee = deliveryFeeResolved;
1041
+ _context17.n = 9;
1042
+ break;
1043
+ case 6:
1044
+ _context17.p = 6;
1045
+ assertHasLocation(nativeAsset);
1046
+ _context17.n = 7;
1047
+ return this.quoteAhPrice(localizeLocation(chain, nativeAsset.location), assetLocalizedLoc, deliveryFeeResolved, false);
1048
+ case 7:
1049
+ res = _context17.v;
1050
+ deliveryFee = res !== null && res !== void 0 ? res : 0n;
1051
+ _context17.n = 9;
1052
+ break;
1053
+ case 8:
1054
+ _context17.p = 8;
1055
+ _context17.v;
1056
+ deliveryFee = 0n;
1057
+ case 9:
1058
+ return _context17.a(2, execFee + deliveryFee);
966
1059
  }
967
- }, _callee17, this);
1060
+ }, _callee17, this, [[6, 8]]);
968
1061
  }));
969
- function getXcmPaymentApiFee(_x34, _x35, _x36) {
1062
+ function getXcmPaymentApiFee(_x34, _x35, _x36, _x37) {
970
1063
  return _getXcmPaymentApiFee.apply(this, arguments);
971
1064
  }
972
1065
  return getXcmPaymentApiFee;
@@ -988,7 +1081,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
988
1081
  }
989
1082
  }, _callee18, this);
990
1083
  }));
991
- function getXcmWeight(_x37) {
1084
+ function getXcmWeight(_x38) {
992
1085
  return _getXcmWeight.apply(this, arguments);
993
1086
  }
994
1087
  return getXcmWeight;
@@ -996,13 +1089,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
996
1089
  }, {
997
1090
  key: "getDryRunXcm",
998
1091
  value: function () {
999
- var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(_ref8) {
1000
- var _ref9, _ref0, _ref1;
1001
- var originLocation, xcm, asset, chain, origin, supportsDryRunApi, response, result, resultJson, symbol, isSuccess, failureReason, emitted, reversedEvents, palletsWithIssued, feeEvent, feeAmount, fee, actualWeight, weight, forwardedXcms, destParaId;
1092
+ var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(_ref9) {
1093
+ var _ref1, _ref10, _ref11;
1094
+ var originLocation, xcm, asset, chain, origin, supportsDryRunApi, response, result, resultJson, symbol, isSuccess, failureReason, forwardedXcms, actualWeight, weight, destParaId, _fee, emitted, reversedEvents, palletsWithIssued, feeEvent, feeAmount, fee;
1002
1095
  return _regenerator().w(function (_context19) {
1003
1096
  while (1) switch (_context19.n) {
1004
1097
  case 0:
1005
- originLocation = _ref8.originLocation, xcm = _ref8.xcm, asset = _ref8.asset, chain = _ref8.chain, origin = _ref8.origin;
1098
+ originLocation = _ref9.originLocation, xcm = _ref9.xcm, asset = _ref9.asset, chain = _ref9.chain, origin = _ref9.origin;
1006
1099
  supportsDryRunApi = getAssetsObject(chain).supportsDryRunApi;
1007
1100
  if (supportsDryRunApi) {
1008
1101
  _context19.n = 1;
@@ -1030,24 +1123,55 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1030
1123
  asset: asset
1031
1124
  });
1032
1125
  case 3:
1126
+ forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
1127
+ actualWeight = resultJson.ok.executionResult.used;
1128
+ weight = actualWeight ? {
1129
+ refTime: BigInt(actualWeight.refTime),
1130
+ proofSize: BigInt(actualWeight.proofSize)
1131
+ } : undefined;
1132
+ destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref0) {
1133
+ return i.Here ? 0 : (_ref0 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref0 === void 0 ? void 0 : _ref0.parachain;
1134
+ }(Object.values(forwardedXcms[0])[0].interior);
1135
+ if (!(hasXcmPaymentApiSupport(chain) && asset)) {
1136
+ _context19.n = 5;
1137
+ break;
1138
+ }
1139
+ _context19.n = 4;
1140
+ return this.getXcmPaymentApiFee(chain, xcm, forwardedXcms, asset);
1141
+ case 4:
1142
+ _fee = _context19.v;
1143
+ if (!(typeof _fee === 'bigint')) {
1144
+ _context19.n = 5;
1145
+ break;
1146
+ }
1147
+ return _context19.a(2, {
1148
+ success: true,
1149
+ fee: _fee,
1150
+ currency: symbol,
1151
+ asset: asset,
1152
+ weight: weight,
1153
+ forwardedXcms: forwardedXcms,
1154
+ destParaId: destParaId
1155
+ });
1156
+ case 5:
1033
1157
  emitted = result.Ok.emittedEvents; // We want to look for the last event
1034
1158
  reversedEvents = _toConsumableArray(emitted).reverse();
1035
1159
  palletsWithIssued = ['balances', 'foreignAssets', 'assets'];
1036
- feeEvent = (_ref9 = (_ref0 = (_ref1 = origin === 'Mythos' ? reversedEvents.find(function (event) {
1160
+ feeEvent = (_ref1 = (_ref10 = (_ref11 = origin === 'Mythos' ? reversedEvents.find(function (event) {
1037
1161
  return event.section === 'assetConversion' && event.method === 'SwapCreditExecuted';
1038
- }) : undefined) !== null && _ref1 !== void 0 ? _ref1 :
1162
+ }) : undefined) !== null && _ref11 !== void 0 ? _ref11 :
1039
1163
  // Prefer an Issued event
1040
1164
  reversedEvents.find(function (event) {
1041
1165
  return palletsWithIssued.includes(event.section) && event.method === 'Issued';
1042
- })) !== null && _ref0 !== void 0 ? _ref0 :
1166
+ })) !== null && _ref10 !== void 0 ? _ref10 :
1043
1167
  // Fallback to Minted event
1044
1168
  reversedEvents.find(function (event) {
1045
1169
  return ['balances', 'foreignAssets'].includes(event.section) && event.method === 'Minted';
1046
- })) !== null && _ref9 !== void 0 ? _ref9 : reversedEvents.find(function (event) {
1170
+ })) !== null && _ref1 !== void 0 ? _ref1 : reversedEvents.find(function (event) {
1047
1171
  return ['currencies', 'tokens'].includes(event.section) && event.method === 'Deposited';
1048
1172
  });
1049
1173
  if (feeEvent) {
1050
- _context19.n = 4;
1174
+ _context19.n = 6;
1051
1175
  break;
1052
1176
  }
1053
1177
  return _context19.a(2, Promise.resolve({
@@ -1056,18 +1180,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1056
1180
  currency: symbol,
1057
1181
  asset: asset
1058
1182
  }));
1059
- case 4:
1183
+ case 6:
1060
1184
  feeAmount = feeEvent.section === 'assetConversion' ? feeEvent.data.amountIn : feeEvent.data.amount;
1061
1185
  fee = BigInt(feeAmount.replace(/,/g, ''));
1062
- actualWeight = resultJson.ok.executionResult.used;
1063
- weight = actualWeight ? {
1064
- refTime: BigInt(actualWeight.refTime),
1065
- proofSize: BigInt(actualWeight.proofSize)
1066
- } : undefined;
1067
- forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
1068
- destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref10) {
1069
- return i.Here ? 0 : (_ref10 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref10 === void 0 ? void 0 : _ref10.parachain;
1070
- }(Object.values(forwardedXcms[0])[0].interior);
1071
1186
  return _context19.a(2, {
1072
1187
  success: true,
1073
1188
  fee: fee,
@@ -1080,7 +1195,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1080
1195
  }
1081
1196
  }, _callee19, this);
1082
1197
  }));
1083
- function getDryRunXcm(_x38) {
1198
+ function getDryRunXcm(_x39) {
1084
1199
  return _getDryRunXcm.apply(this, arguments);
1085
1200
  }
1086
1201
  return getDryRunXcm;
@@ -1133,7 +1248,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1133
1248
  }
1134
1249
  }, _callee21, this);
1135
1250
  }));
1136
- function convertLocationToAccount(_x39) {
1251
+ function convertLocationToAccount(_x40) {
1137
1252
  return _convertLocationToAccount.apply(this, arguments);
1138
1253
  }
1139
1254
  return convertLocationToAccount;
@@ -1182,8 +1297,8 @@ var PolkadotJsApi = /*#__PURE__*/function () {
1182
1297
  }]);
1183
1298
  }();
1184
1299
 
1185
- var createChainClient = function createChainClient(chain) {
1186
- var pjsApi = new PolkadotJsApi();
1300
+ var createChainClient = function createChainClient(chain, builderOptions) {
1301
+ var pjsApi = new PolkadotJsApi(builderOptions);
1187
1302
  return createChainClient$1(pjsApi, chain);
1188
1303
  };
1189
1304
  var createPolkadotJsApiCall = function createPolkadotJsApiCall(apiCall) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraspell/sdk-pjs",
3
- "version": "11.9.2",
3
+ "version": "11.10.0",
4
4
  "description": "Polkadot.js based SDK for ParaSpell XCM/XCMP tool for developers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,7 +27,7 @@
27
27
  "@snowbridge/contract-types": "0.2.0",
28
28
  "ethers": "^6.15.0",
29
29
  "viem": "^2.37.9",
30
- "@paraspell/sdk-core": "11.9.2"
30
+ "@paraspell/sdk-core": "11.10.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@polkadot/api": ">= 16.0 < 17",