@paraspell/sdk-pjs 11.9.2 → 11.9.3
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 +191 -78
- package/dist/index.mjs +192 -79
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -418,7 +418,12 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
418
418
|
}, {
|
|
419
419
|
key: "callDispatchAsMethod",
|
|
420
420
|
value: function callDispatchAsMethod(call, address) {
|
|
421
|
-
|
|
421
|
+
var origin = {
|
|
422
|
+
system: {
|
|
423
|
+
Signed: address
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
return this.api.tx.utility.dispatchAs(origin, call);
|
|
422
427
|
}
|
|
423
428
|
}, {
|
|
424
429
|
key: "objectToHex",
|
|
@@ -777,13 +782,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
777
782
|
}, {
|
|
778
783
|
key: "getDryRunCall",
|
|
779
784
|
value: function () {
|
|
780
|
-
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(
|
|
785
|
+
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(options) {
|
|
781
786
|
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,
|
|
787
|
+
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
788
|
return _regenerator().w(function (_context16) {
|
|
784
789
|
while (1) switch (_context16.p = _context16.n) {
|
|
785
790
|
case 0:
|
|
786
|
-
tx =
|
|
791
|
+
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
792
|
supportsDryRunApi = sdkCore.getAssetsObject(chain).supportsDryRunApi;
|
|
788
793
|
if (supportsDryRunApi) {
|
|
789
794
|
_context16.n = 1;
|
|
@@ -792,24 +797,45 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
792
797
|
throw new sdkCore.ChainNotSupportedError("DryRunApi is not available on chain ".concat(chain));
|
|
793
798
|
case 1:
|
|
794
799
|
DEFAULT_XCM_VERSION = 3;
|
|
800
|
+
basePayload = useRootOrigin ? {
|
|
801
|
+
system: {
|
|
802
|
+
Root: null
|
|
803
|
+
}
|
|
804
|
+
} : {
|
|
805
|
+
system: {
|
|
806
|
+
Signed: address
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
if (!useRootOrigin) {
|
|
810
|
+
_context16.n = 3;
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
_context16.n = 2;
|
|
814
|
+
return sdkCore.wrapTxBypass(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
815
|
+
api: this
|
|
816
|
+
}), bypassOptions);
|
|
817
|
+
case 2:
|
|
818
|
+
_t = _context16.v;
|
|
819
|
+
_context16.n = 4;
|
|
820
|
+
break;
|
|
821
|
+
case 3:
|
|
822
|
+
_t = tx;
|
|
823
|
+
case 4:
|
|
824
|
+
resolvedTx = _t;
|
|
795
825
|
usedAsset = feeAsset !== null && feeAsset !== void 0 ? feeAsset : sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
796
826
|
usedSymbol = usedAsset.symbol;
|
|
797
827
|
performDryRunCall = /*#__PURE__*/function () {
|
|
798
|
-
var
|
|
828
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(includeVersion) {
|
|
799
829
|
var _this$api$call$dryRun;
|
|
800
830
|
return _regenerator().w(function (_context15) {
|
|
801
831
|
while (1) switch (_context15.n) {
|
|
802
832
|
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] : []))));
|
|
833
|
+
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
834
|
}
|
|
809
835
|
}, _callee15);
|
|
810
836
|
}));
|
|
811
837
|
return function performDryRunCall(_x33) {
|
|
812
|
-
return
|
|
838
|
+
return _ref4.apply(this, arguments);
|
|
813
839
|
};
|
|
814
840
|
}();
|
|
815
841
|
getExecutionSuccessFromResult = function getExecutionSuccessFromResult(resultHuman) {
|
|
@@ -817,7 +843,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
817
843
|
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
844
|
};
|
|
819
845
|
extractFailureReasonFromResult = function extractFailureReasonFromResult(resultHuman, resultJson) {
|
|
820
|
-
var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok,
|
|
846
|
+
var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok, _ref5;
|
|
821
847
|
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
848
|
if (modErrHuman) {
|
|
823
849
|
return sdkCore.resolveModuleError(chain, modErrHuman);
|
|
@@ -833,15 +859,15 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
833
859
|
if (execErrJson !== null && execErrJson !== void 0 && execErrJson.other) {
|
|
834
860
|
return String(execErrJson.other);
|
|
835
861
|
}
|
|
836
|
-
return JSON.stringify((
|
|
862
|
+
return JSON.stringify((_ref5 = resultJson !== null && resultJson !== void 0 ? resultJson : resultHuman) !== null && _ref5 !== void 0 ? _ref5 : 'Unknown error');
|
|
837
863
|
}; // Attempt 1: WITHOUT version
|
|
838
864
|
isSuccess = false;
|
|
839
865
|
failureReason = '';
|
|
840
866
|
shouldRetryWithVersion = false;
|
|
841
|
-
_context16.p =
|
|
842
|
-
_context16.n =
|
|
867
|
+
_context16.p = 5;
|
|
868
|
+
_context16.n = 6;
|
|
843
869
|
return performDryRunCall(false);
|
|
844
|
-
case
|
|
870
|
+
case 6:
|
|
845
871
|
response = _context16.v;
|
|
846
872
|
resultHuman = response.toHuman();
|
|
847
873
|
resultJson = response.toJSON();
|
|
@@ -852,35 +878,35 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
852
878
|
shouldRetryWithVersion = true;
|
|
853
879
|
}
|
|
854
880
|
}
|
|
855
|
-
_context16.n =
|
|
881
|
+
_context16.n = 9;
|
|
856
882
|
break;
|
|
857
|
-
case
|
|
858
|
-
_context16.p =
|
|
859
|
-
|
|
860
|
-
msg =
|
|
883
|
+
case 7:
|
|
884
|
+
_context16.p = 7;
|
|
885
|
+
_t2 = _context16.v;
|
|
886
|
+
msg = _t2 instanceof Error ? _t2.message : String(_t2);
|
|
861
887
|
if (!msg.includes('Expected 3 arguments')) {
|
|
862
|
-
_context16.n =
|
|
888
|
+
_context16.n = 8;
|
|
863
889
|
break;
|
|
864
890
|
}
|
|
865
891
|
shouldRetryWithVersion = true;
|
|
866
|
-
_context16.n =
|
|
892
|
+
_context16.n = 9;
|
|
867
893
|
break;
|
|
868
|
-
case
|
|
894
|
+
case 8:
|
|
869
895
|
return _context16.a(2, {
|
|
870
896
|
success: false,
|
|
871
897
|
failureReason: msg,
|
|
872
898
|
currency: usedSymbol,
|
|
873
899
|
asset: usedAsset
|
|
874
900
|
});
|
|
875
|
-
case
|
|
901
|
+
case 9:
|
|
876
902
|
if (!shouldRetryWithVersion) {
|
|
877
|
-
_context16.n =
|
|
903
|
+
_context16.n = 13;
|
|
878
904
|
break;
|
|
879
905
|
}
|
|
880
|
-
_context16.p =
|
|
881
|
-
_context16.n =
|
|
906
|
+
_context16.p = 10;
|
|
907
|
+
_context16.n = 11;
|
|
882
908
|
return performDryRunCall(true);
|
|
883
|
-
case
|
|
909
|
+
case 11:
|
|
884
910
|
response = _context16.v;
|
|
885
911
|
resultHuman = response.toHuman();
|
|
886
912
|
resultJson = response.toJSON();
|
|
@@ -888,12 +914,12 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
888
914
|
if (!isSuccess) {
|
|
889
915
|
failureReason = extractFailureReasonFromResult(resultHuman, resultJson);
|
|
890
916
|
}
|
|
891
|
-
_context16.n =
|
|
917
|
+
_context16.n = 13;
|
|
892
918
|
break;
|
|
893
|
-
case
|
|
894
|
-
_context16.p =
|
|
895
|
-
|
|
896
|
-
_msg =
|
|
919
|
+
case 12:
|
|
920
|
+
_context16.p = 12;
|
|
921
|
+
_t3 = _context16.v;
|
|
922
|
+
_msg = _t3 instanceof Error ? _t3.message : String(_t3);
|
|
897
923
|
failureReason = failureReason || _msg;
|
|
898
924
|
return _context16.a(2, {
|
|
899
925
|
success: false,
|
|
@@ -901,9 +927,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
901
927
|
currency: usedSymbol,
|
|
902
928
|
asset: usedAsset
|
|
903
929
|
});
|
|
904
|
-
case
|
|
930
|
+
case 13:
|
|
905
931
|
if (isSuccess) {
|
|
906
|
-
_context16.n =
|
|
932
|
+
_context16.n = 14;
|
|
907
933
|
break;
|
|
908
934
|
}
|
|
909
935
|
return _context16.a(2, {
|
|
@@ -912,21 +938,45 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
912
938
|
currency: usedSymbol,
|
|
913
939
|
asset: usedAsset
|
|
914
940
|
});
|
|
915
|
-
case
|
|
916
|
-
|
|
917
|
-
return this.calculateTransactionFee(tx, address);
|
|
918
|
-
case 12:
|
|
919
|
-
executionFee = _context16.v;
|
|
920
|
-
fee = sdkCore.computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
|
|
941
|
+
case 14:
|
|
942
|
+
forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
|
|
921
943
|
actualWeight = resultJson.ok.executionResult.ok.actualWeight;
|
|
922
944
|
weight = actualWeight ? {
|
|
923
945
|
refTime: BigInt(actualWeight.refTime),
|
|
924
946
|
proofSize: BigInt(actualWeight.proofSize)
|
|
925
947
|
} : undefined;
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
948
|
+
nativeAsset = sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
949
|
+
hasLocation = feeAsset ? Boolean(feeAsset.location) : Boolean(nativeAsset === null || nativeAsset === void 0 ? void 0 : nativeAsset.location);
|
|
950
|
+
destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref6) {
|
|
951
|
+
return i.here === null ? 0 : (_ref6 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref6 === void 0 ? void 0 : _ref6.parachain;
|
|
929
952
|
}(Object.values(forwardedXcms[0])[0].interior);
|
|
953
|
+
if (!(sdkCore.hasXcmPaymentApiSupport(chain) && resultJson.ok.local_xcm && hasLocation && (feeAsset || chain.startsWith('AssetHub') && destination === 'Ethereum'))) {
|
|
954
|
+
_context16.n = 16;
|
|
955
|
+
break;
|
|
956
|
+
}
|
|
957
|
+
_context16.n = 15;
|
|
958
|
+
return this.getXcmPaymentApiFee(chain, resultJson.ok.local_xcm, forwardedXcms, feeAsset !== null && feeAsset !== void 0 ? feeAsset : nativeAsset);
|
|
959
|
+
case 15:
|
|
960
|
+
xcmFee = _context16.v;
|
|
961
|
+
if (!(typeof xcmFee === 'bigint')) {
|
|
962
|
+
_context16.n = 16;
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
return _context16.a(2, Promise.resolve({
|
|
966
|
+
success: true,
|
|
967
|
+
fee: xcmFee,
|
|
968
|
+
currency: usedSymbol,
|
|
969
|
+
asset: usedAsset,
|
|
970
|
+
weight: weight,
|
|
971
|
+
forwardedXcms: forwardedXcms,
|
|
972
|
+
destParaId: destParaId
|
|
973
|
+
}));
|
|
974
|
+
case 16:
|
|
975
|
+
_context16.n = 17;
|
|
976
|
+
return this.calculateTransactionFee(tx, address);
|
|
977
|
+
case 17:
|
|
978
|
+
executionFee = _context16.v;
|
|
979
|
+
fee = sdkCore.computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
|
|
930
980
|
return _context16.a(2, {
|
|
931
981
|
success: true,
|
|
932
982
|
fee: fee,
|
|
@@ -937,7 +987,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
937
987
|
destParaId: destParaId
|
|
938
988
|
});
|
|
939
989
|
}
|
|
940
|
-
}, _callee16, this, [[
|
|
990
|
+
}, _callee16, this, [[10, 12], [5, 7]]);
|
|
941
991
|
}));
|
|
942
992
|
function getDryRunCall(_x32) {
|
|
943
993
|
return _getDryRunCall.apply(this, arguments);
|
|
@@ -947,27 +997,68 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
947
997
|
}, {
|
|
948
998
|
key: "getXcmPaymentApiFee",
|
|
949
999
|
value: function () {
|
|
950
|
-
var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(chain,
|
|
951
|
-
var
|
|
1000
|
+
var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(chain, localXcm, forwardedXcm, asset) {
|
|
1001
|
+
var _ref7, _deliveryFeeResJson$o, _deliveryFeeResJson$o2, _deliveryFeeResJson$o3, _ref8, _deliveryFeeResJson$o4, _deliveryFeeResJson$o5, _deliveryFeeResJson$o6;
|
|
1002
|
+
var weight, assetLocalizedLoc, feeResult, execFeeRes, execFee, deliveryFeeRes, deliveryFeeResJson, deliveryFeeResolved, nativeAsset, deliveryFee, res, _t4;
|
|
952
1003
|
return _regenerator().w(function (_context17) {
|
|
953
|
-
while (1) switch (_context17.n) {
|
|
1004
|
+
while (1) switch (_context17.p = _context17.n) {
|
|
954
1005
|
case 0:
|
|
955
1006
|
_context17.n = 1;
|
|
956
|
-
return this.getXcmWeight(
|
|
1007
|
+
return this.getXcmWeight(localXcm);
|
|
957
1008
|
case 1:
|
|
958
1009
|
weight = _context17.v;
|
|
959
1010
|
sdkCore.assertHasLocation(asset);
|
|
960
|
-
|
|
1011
|
+
assetLocalizedLoc = sdkCore.localizeLocation(chain, asset.location);
|
|
961
1012
|
_context17.n = 2;
|
|
962
|
-
return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, sdkCore.addXcmVersionHeader(
|
|
1013
|
+
return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, sdkCore.addXcmVersionHeader(assetLocalizedLoc, sdkCore.Version.V4));
|
|
963
1014
|
case 2:
|
|
964
1015
|
feeResult = _context17.v;
|
|
965
|
-
|
|
966
|
-
|
|
1016
|
+
execFeeRes = feeResult.toJSON();
|
|
1017
|
+
execFee = BigInt(execFeeRes.ok);
|
|
1018
|
+
if (!(forwardedXcm.length > 0)) {
|
|
1019
|
+
_context17.n = 4;
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
_context17.n = 3;
|
|
1023
|
+
return this.api.call.xcmPaymentApi.queryDeliveryFees(forwardedXcm[0], forwardedXcm[1][0]);
|
|
1024
|
+
case 3:
|
|
1025
|
+
_t4 = _context17.v;
|
|
1026
|
+
_context17.n = 5;
|
|
1027
|
+
break;
|
|
1028
|
+
case 4:
|
|
1029
|
+
_t4 = undefined;
|
|
1030
|
+
case 5:
|
|
1031
|
+
deliveryFeeRes = _t4;
|
|
1032
|
+
deliveryFeeResJson = deliveryFeeRes === null || deliveryFeeRes === void 0 ? void 0 : deliveryFeeRes.toJSON();
|
|
1033
|
+
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;
|
|
1034
|
+
nativeAsset = sdkCore.findNativeAssetInfoOrThrow(chain);
|
|
1035
|
+
if (!sdkCore.isAssetXcEqual(asset, nativeAsset)) {
|
|
1036
|
+
_context17.n = 6;
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
deliveryFee = deliveryFeeResolved;
|
|
1040
|
+
_context17.n = 9;
|
|
1041
|
+
break;
|
|
1042
|
+
case 6:
|
|
1043
|
+
_context17.p = 6;
|
|
1044
|
+
sdkCore.assertHasLocation(nativeAsset);
|
|
1045
|
+
_context17.n = 7;
|
|
1046
|
+
return this.quoteAhPrice(sdkCore.localizeLocation(chain, nativeAsset.location), assetLocalizedLoc, deliveryFeeResolved, false);
|
|
1047
|
+
case 7:
|
|
1048
|
+
res = _context17.v;
|
|
1049
|
+
deliveryFee = res !== null && res !== void 0 ? res : 0n;
|
|
1050
|
+
_context17.n = 9;
|
|
1051
|
+
break;
|
|
1052
|
+
case 8:
|
|
1053
|
+
_context17.p = 8;
|
|
1054
|
+
_context17.v;
|
|
1055
|
+
deliveryFee = 0n;
|
|
1056
|
+
case 9:
|
|
1057
|
+
return _context17.a(2, execFee + deliveryFee);
|
|
967
1058
|
}
|
|
968
|
-
}, _callee17, this);
|
|
1059
|
+
}, _callee17, this, [[6, 8]]);
|
|
969
1060
|
}));
|
|
970
|
-
function getXcmPaymentApiFee(_x34, _x35, _x36) {
|
|
1061
|
+
function getXcmPaymentApiFee(_x34, _x35, _x36, _x37) {
|
|
971
1062
|
return _getXcmPaymentApiFee.apply(this, arguments);
|
|
972
1063
|
}
|
|
973
1064
|
return getXcmPaymentApiFee;
|
|
@@ -989,7 +1080,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
989
1080
|
}
|
|
990
1081
|
}, _callee18, this);
|
|
991
1082
|
}));
|
|
992
|
-
function getXcmWeight(
|
|
1083
|
+
function getXcmWeight(_x38) {
|
|
993
1084
|
return _getXcmWeight.apply(this, arguments);
|
|
994
1085
|
}
|
|
995
1086
|
return getXcmWeight;
|
|
@@ -997,13 +1088,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
997
1088
|
}, {
|
|
998
1089
|
key: "getDryRunXcm",
|
|
999
1090
|
value: function () {
|
|
1000
|
-
var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(
|
|
1001
|
-
var
|
|
1002
|
-
var originLocation, xcm, asset, chain, origin, supportsDryRunApi, response, result, resultJson, symbol, isSuccess, failureReason,
|
|
1091
|
+
var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(_ref9) {
|
|
1092
|
+
var _ref1, _ref10, _ref11;
|
|
1093
|
+
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
1094
|
return _regenerator().w(function (_context19) {
|
|
1004
1095
|
while (1) switch (_context19.n) {
|
|
1005
1096
|
case 0:
|
|
1006
|
-
originLocation =
|
|
1097
|
+
originLocation = _ref9.originLocation, xcm = _ref9.xcm, asset = _ref9.asset, chain = _ref9.chain, origin = _ref9.origin;
|
|
1007
1098
|
supportsDryRunApi = sdkCore.getAssetsObject(chain).supportsDryRunApi;
|
|
1008
1099
|
if (supportsDryRunApi) {
|
|
1009
1100
|
_context19.n = 1;
|
|
@@ -1031,24 +1122,55 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1031
1122
|
asset: asset
|
|
1032
1123
|
});
|
|
1033
1124
|
case 3:
|
|
1125
|
+
forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
|
|
1126
|
+
actualWeight = resultJson.ok.executionResult.used;
|
|
1127
|
+
weight = actualWeight ? {
|
|
1128
|
+
refTime: BigInt(actualWeight.refTime),
|
|
1129
|
+
proofSize: BigInt(actualWeight.proofSize)
|
|
1130
|
+
} : undefined;
|
|
1131
|
+
destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref0) {
|
|
1132
|
+
return i.Here ? 0 : (_ref0 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref0 === void 0 ? void 0 : _ref0.parachain;
|
|
1133
|
+
}(Object.values(forwardedXcms[0])[0].interior);
|
|
1134
|
+
if (!(sdkCore.hasXcmPaymentApiSupport(chain) && asset)) {
|
|
1135
|
+
_context19.n = 5;
|
|
1136
|
+
break;
|
|
1137
|
+
}
|
|
1138
|
+
_context19.n = 4;
|
|
1139
|
+
return this.getXcmPaymentApiFee(chain, xcm, forwardedXcms, asset);
|
|
1140
|
+
case 4:
|
|
1141
|
+
_fee = _context19.v;
|
|
1142
|
+
if (!(typeof _fee === 'bigint')) {
|
|
1143
|
+
_context19.n = 5;
|
|
1144
|
+
break;
|
|
1145
|
+
}
|
|
1146
|
+
return _context19.a(2, {
|
|
1147
|
+
success: true,
|
|
1148
|
+
fee: _fee,
|
|
1149
|
+
currency: symbol,
|
|
1150
|
+
asset: asset,
|
|
1151
|
+
weight: weight,
|
|
1152
|
+
forwardedXcms: forwardedXcms,
|
|
1153
|
+
destParaId: destParaId
|
|
1154
|
+
});
|
|
1155
|
+
case 5:
|
|
1034
1156
|
emitted = result.Ok.emittedEvents; // We want to look for the last event
|
|
1035
1157
|
reversedEvents = _toConsumableArray(emitted).reverse();
|
|
1036
1158
|
palletsWithIssued = ['balances', 'foreignAssets', 'assets'];
|
|
1037
|
-
feeEvent = (
|
|
1159
|
+
feeEvent = (_ref1 = (_ref10 = (_ref11 = origin === 'Mythos' ? reversedEvents.find(function (event) {
|
|
1038
1160
|
return event.section === 'assetConversion' && event.method === 'SwapCreditExecuted';
|
|
1039
|
-
}) : undefined) !== null &&
|
|
1161
|
+
}) : undefined) !== null && _ref11 !== void 0 ? _ref11 :
|
|
1040
1162
|
// Prefer an Issued event
|
|
1041
1163
|
reversedEvents.find(function (event) {
|
|
1042
1164
|
return palletsWithIssued.includes(event.section) && event.method === 'Issued';
|
|
1043
|
-
})) !== null &&
|
|
1165
|
+
})) !== null && _ref10 !== void 0 ? _ref10 :
|
|
1044
1166
|
// Fallback to Minted event
|
|
1045
1167
|
reversedEvents.find(function (event) {
|
|
1046
1168
|
return ['balances', 'foreignAssets'].includes(event.section) && event.method === 'Minted';
|
|
1047
|
-
})) !== null &&
|
|
1169
|
+
})) !== null && _ref1 !== void 0 ? _ref1 : reversedEvents.find(function (event) {
|
|
1048
1170
|
return ['currencies', 'tokens'].includes(event.section) && event.method === 'Deposited';
|
|
1049
1171
|
});
|
|
1050
1172
|
if (feeEvent) {
|
|
1051
|
-
_context19.n =
|
|
1173
|
+
_context19.n = 6;
|
|
1052
1174
|
break;
|
|
1053
1175
|
}
|
|
1054
1176
|
return _context19.a(2, Promise.resolve({
|
|
@@ -1057,18 +1179,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1057
1179
|
currency: symbol,
|
|
1058
1180
|
asset: asset
|
|
1059
1181
|
}));
|
|
1060
|
-
case
|
|
1182
|
+
case 6:
|
|
1061
1183
|
feeAmount = feeEvent.section === 'assetConversion' ? feeEvent.data.amountIn : feeEvent.data.amount;
|
|
1062
1184
|
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
1185
|
return _context19.a(2, {
|
|
1073
1186
|
success: true,
|
|
1074
1187
|
fee: fee,
|
|
@@ -1081,7 +1194,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1081
1194
|
}
|
|
1082
1195
|
}, _callee19, this);
|
|
1083
1196
|
}));
|
|
1084
|
-
function getDryRunXcm(
|
|
1197
|
+
function getDryRunXcm(_x39) {
|
|
1085
1198
|
return _getDryRunXcm.apply(this, arguments);
|
|
1086
1199
|
}
|
|
1087
1200
|
return getDryRunXcm;
|
|
@@ -1134,7 +1247,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1134
1247
|
}
|
|
1135
1248
|
}, _callee21, this);
|
|
1136
1249
|
}));
|
|
1137
|
-
function convertLocationToAccount(
|
|
1250
|
+
function convertLocationToAccount(_x40) {
|
|
1138
1251
|
return _convertLocationToAccount.apply(this, arguments);
|
|
1139
1252
|
}
|
|
1140
1253
|
return convertLocationToAccount;
|
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,
|
|
1
|
+
import { isConfig, BatchMode, MissingChainApiError, createChainClient as createChainClient$1, assertHasId, getChain, isForeignAsset, InvalidParameterError, computeFeeFromDryRunPjs, findNativeAssetInfoOrThrow, hasXcmPaymentApiSupport, resolveModuleError, getAssetsObject, ChainNotSupportedError, wrapTxBypass, assertHasLocation, localizeLocation, isAssetXcEqual, 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';
|
|
2
2
|
export * from '@paraspell/sdk-core';
|
|
3
3
|
import { WsProvider, ApiPromise } from '@polkadot/api';
|
|
4
4
|
import { u32 } from '@polkadot/types';
|
|
@@ -417,7 +417,12 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
417
417
|
}, {
|
|
418
418
|
key: "callDispatchAsMethod",
|
|
419
419
|
value: function callDispatchAsMethod(call, address) {
|
|
420
|
-
|
|
420
|
+
var origin = {
|
|
421
|
+
system: {
|
|
422
|
+
Signed: address
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
return this.api.tx.utility.dispatchAs(origin, call);
|
|
421
426
|
}
|
|
422
427
|
}, {
|
|
423
428
|
key: "objectToHex",
|
|
@@ -776,13 +781,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
776
781
|
}, {
|
|
777
782
|
key: "getDryRunCall",
|
|
778
783
|
value: function () {
|
|
779
|
-
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(
|
|
784
|
+
var _getDryRunCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(options) {
|
|
780
785
|
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,
|
|
786
|
+
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
787
|
return _regenerator().w(function (_context16) {
|
|
783
788
|
while (1) switch (_context16.p = _context16.n) {
|
|
784
789
|
case 0:
|
|
785
|
-
tx =
|
|
790
|
+
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
791
|
supportsDryRunApi = getAssetsObject(chain).supportsDryRunApi;
|
|
787
792
|
if (supportsDryRunApi) {
|
|
788
793
|
_context16.n = 1;
|
|
@@ -791,24 +796,45 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
791
796
|
throw new ChainNotSupportedError("DryRunApi is not available on chain ".concat(chain));
|
|
792
797
|
case 1:
|
|
793
798
|
DEFAULT_XCM_VERSION = 3;
|
|
799
|
+
basePayload = useRootOrigin ? {
|
|
800
|
+
system: {
|
|
801
|
+
Root: null
|
|
802
|
+
}
|
|
803
|
+
} : {
|
|
804
|
+
system: {
|
|
805
|
+
Signed: address
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
if (!useRootOrigin) {
|
|
809
|
+
_context16.n = 3;
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
_context16.n = 2;
|
|
813
|
+
return wrapTxBypass(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
814
|
+
api: this
|
|
815
|
+
}), bypassOptions);
|
|
816
|
+
case 2:
|
|
817
|
+
_t = _context16.v;
|
|
818
|
+
_context16.n = 4;
|
|
819
|
+
break;
|
|
820
|
+
case 3:
|
|
821
|
+
_t = tx;
|
|
822
|
+
case 4:
|
|
823
|
+
resolvedTx = _t;
|
|
794
824
|
usedAsset = feeAsset !== null && feeAsset !== void 0 ? feeAsset : findNativeAssetInfoOrThrow(chain);
|
|
795
825
|
usedSymbol = usedAsset.symbol;
|
|
796
826
|
performDryRunCall = /*#__PURE__*/function () {
|
|
797
|
-
var
|
|
827
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(includeVersion) {
|
|
798
828
|
var _this$api$call$dryRun;
|
|
799
829
|
return _regenerator().w(function (_context15) {
|
|
800
830
|
while (1) switch (_context15.n) {
|
|
801
831
|
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] : []))));
|
|
832
|
+
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
833
|
}
|
|
808
834
|
}, _callee15);
|
|
809
835
|
}));
|
|
810
836
|
return function performDryRunCall(_x33) {
|
|
811
|
-
return
|
|
837
|
+
return _ref4.apply(this, arguments);
|
|
812
838
|
};
|
|
813
839
|
}();
|
|
814
840
|
getExecutionSuccessFromResult = function getExecutionSuccessFromResult(resultHuman) {
|
|
@@ -816,7 +842,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
816
842
|
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
843
|
};
|
|
818
844
|
extractFailureReasonFromResult = function extractFailureReasonFromResult(resultHuman, resultJson) {
|
|
819
|
-
var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok,
|
|
845
|
+
var _resultHuman$Ok, _resultHuman$Ok2, _resultJson$ok, _ref5;
|
|
820
846
|
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
847
|
if (modErrHuman) {
|
|
822
848
|
return resolveModuleError(chain, modErrHuman);
|
|
@@ -832,15 +858,15 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
832
858
|
if (execErrJson !== null && execErrJson !== void 0 && execErrJson.other) {
|
|
833
859
|
return String(execErrJson.other);
|
|
834
860
|
}
|
|
835
|
-
return JSON.stringify((
|
|
861
|
+
return JSON.stringify((_ref5 = resultJson !== null && resultJson !== void 0 ? resultJson : resultHuman) !== null && _ref5 !== void 0 ? _ref5 : 'Unknown error');
|
|
836
862
|
}; // Attempt 1: WITHOUT version
|
|
837
863
|
isSuccess = false;
|
|
838
864
|
failureReason = '';
|
|
839
865
|
shouldRetryWithVersion = false;
|
|
840
|
-
_context16.p =
|
|
841
|
-
_context16.n =
|
|
866
|
+
_context16.p = 5;
|
|
867
|
+
_context16.n = 6;
|
|
842
868
|
return performDryRunCall(false);
|
|
843
|
-
case
|
|
869
|
+
case 6:
|
|
844
870
|
response = _context16.v;
|
|
845
871
|
resultHuman = response.toHuman();
|
|
846
872
|
resultJson = response.toJSON();
|
|
@@ -851,35 +877,35 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
851
877
|
shouldRetryWithVersion = true;
|
|
852
878
|
}
|
|
853
879
|
}
|
|
854
|
-
_context16.n =
|
|
880
|
+
_context16.n = 9;
|
|
855
881
|
break;
|
|
856
|
-
case
|
|
857
|
-
_context16.p =
|
|
858
|
-
|
|
859
|
-
msg =
|
|
882
|
+
case 7:
|
|
883
|
+
_context16.p = 7;
|
|
884
|
+
_t2 = _context16.v;
|
|
885
|
+
msg = _t2 instanceof Error ? _t2.message : String(_t2);
|
|
860
886
|
if (!msg.includes('Expected 3 arguments')) {
|
|
861
|
-
_context16.n =
|
|
887
|
+
_context16.n = 8;
|
|
862
888
|
break;
|
|
863
889
|
}
|
|
864
890
|
shouldRetryWithVersion = true;
|
|
865
|
-
_context16.n =
|
|
891
|
+
_context16.n = 9;
|
|
866
892
|
break;
|
|
867
|
-
case
|
|
893
|
+
case 8:
|
|
868
894
|
return _context16.a(2, {
|
|
869
895
|
success: false,
|
|
870
896
|
failureReason: msg,
|
|
871
897
|
currency: usedSymbol,
|
|
872
898
|
asset: usedAsset
|
|
873
899
|
});
|
|
874
|
-
case
|
|
900
|
+
case 9:
|
|
875
901
|
if (!shouldRetryWithVersion) {
|
|
876
|
-
_context16.n =
|
|
902
|
+
_context16.n = 13;
|
|
877
903
|
break;
|
|
878
904
|
}
|
|
879
|
-
_context16.p =
|
|
880
|
-
_context16.n =
|
|
905
|
+
_context16.p = 10;
|
|
906
|
+
_context16.n = 11;
|
|
881
907
|
return performDryRunCall(true);
|
|
882
|
-
case
|
|
908
|
+
case 11:
|
|
883
909
|
response = _context16.v;
|
|
884
910
|
resultHuman = response.toHuman();
|
|
885
911
|
resultJson = response.toJSON();
|
|
@@ -887,12 +913,12 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
887
913
|
if (!isSuccess) {
|
|
888
914
|
failureReason = extractFailureReasonFromResult(resultHuman, resultJson);
|
|
889
915
|
}
|
|
890
|
-
_context16.n =
|
|
916
|
+
_context16.n = 13;
|
|
891
917
|
break;
|
|
892
|
-
case
|
|
893
|
-
_context16.p =
|
|
894
|
-
|
|
895
|
-
_msg =
|
|
918
|
+
case 12:
|
|
919
|
+
_context16.p = 12;
|
|
920
|
+
_t3 = _context16.v;
|
|
921
|
+
_msg = _t3 instanceof Error ? _t3.message : String(_t3);
|
|
896
922
|
failureReason = failureReason || _msg;
|
|
897
923
|
return _context16.a(2, {
|
|
898
924
|
success: false,
|
|
@@ -900,9 +926,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
900
926
|
currency: usedSymbol,
|
|
901
927
|
asset: usedAsset
|
|
902
928
|
});
|
|
903
|
-
case
|
|
929
|
+
case 13:
|
|
904
930
|
if (isSuccess) {
|
|
905
|
-
_context16.n =
|
|
931
|
+
_context16.n = 14;
|
|
906
932
|
break;
|
|
907
933
|
}
|
|
908
934
|
return _context16.a(2, {
|
|
@@ -911,21 +937,45 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
911
937
|
currency: usedSymbol,
|
|
912
938
|
asset: usedAsset
|
|
913
939
|
});
|
|
914
|
-
case
|
|
915
|
-
|
|
916
|
-
return this.calculateTransactionFee(tx, address);
|
|
917
|
-
case 12:
|
|
918
|
-
executionFee = _context16.v;
|
|
919
|
-
fee = computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
|
|
940
|
+
case 14:
|
|
941
|
+
forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
|
|
920
942
|
actualWeight = resultJson.ok.executionResult.ok.actualWeight;
|
|
921
943
|
weight = actualWeight ? {
|
|
922
944
|
refTime: BigInt(actualWeight.refTime),
|
|
923
945
|
proofSize: BigInt(actualWeight.proofSize)
|
|
924
946
|
} : undefined;
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
947
|
+
nativeAsset = findNativeAssetInfoOrThrow(chain);
|
|
948
|
+
hasLocation = feeAsset ? Boolean(feeAsset.location) : Boolean(nativeAsset === null || nativeAsset === void 0 ? void 0 : nativeAsset.location);
|
|
949
|
+
destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref6) {
|
|
950
|
+
return i.here === null ? 0 : (_ref6 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref6 === void 0 ? void 0 : _ref6.parachain;
|
|
928
951
|
}(Object.values(forwardedXcms[0])[0].interior);
|
|
952
|
+
if (!(hasXcmPaymentApiSupport(chain) && resultJson.ok.local_xcm && hasLocation && (feeAsset || chain.startsWith('AssetHub') && destination === 'Ethereum'))) {
|
|
953
|
+
_context16.n = 16;
|
|
954
|
+
break;
|
|
955
|
+
}
|
|
956
|
+
_context16.n = 15;
|
|
957
|
+
return this.getXcmPaymentApiFee(chain, resultJson.ok.local_xcm, forwardedXcms, feeAsset !== null && feeAsset !== void 0 ? feeAsset : nativeAsset);
|
|
958
|
+
case 15:
|
|
959
|
+
xcmFee = _context16.v;
|
|
960
|
+
if (!(typeof xcmFee === 'bigint')) {
|
|
961
|
+
_context16.n = 16;
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
964
|
+
return _context16.a(2, Promise.resolve({
|
|
965
|
+
success: true,
|
|
966
|
+
fee: xcmFee,
|
|
967
|
+
currency: usedSymbol,
|
|
968
|
+
asset: usedAsset,
|
|
969
|
+
weight: weight,
|
|
970
|
+
forwardedXcms: forwardedXcms,
|
|
971
|
+
destParaId: destParaId
|
|
972
|
+
}));
|
|
973
|
+
case 16:
|
|
974
|
+
_context16.n = 17;
|
|
975
|
+
return this.calculateTransactionFee(tx, address);
|
|
976
|
+
case 17:
|
|
977
|
+
executionFee = _context16.v;
|
|
978
|
+
fee = computeFeeFromDryRunPjs(resultHuman, chain, executionFee);
|
|
929
979
|
return _context16.a(2, {
|
|
930
980
|
success: true,
|
|
931
981
|
fee: fee,
|
|
@@ -936,7 +986,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
936
986
|
destParaId: destParaId
|
|
937
987
|
});
|
|
938
988
|
}
|
|
939
|
-
}, _callee16, this, [[
|
|
989
|
+
}, _callee16, this, [[10, 12], [5, 7]]);
|
|
940
990
|
}));
|
|
941
991
|
function getDryRunCall(_x32) {
|
|
942
992
|
return _getDryRunCall.apply(this, arguments);
|
|
@@ -946,27 +996,68 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
946
996
|
}, {
|
|
947
997
|
key: "getXcmPaymentApiFee",
|
|
948
998
|
value: function () {
|
|
949
|
-
var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(chain,
|
|
950
|
-
var
|
|
999
|
+
var _getXcmPaymentApiFee = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(chain, localXcm, forwardedXcm, asset) {
|
|
1000
|
+
var _ref7, _deliveryFeeResJson$o, _deliveryFeeResJson$o2, _deliveryFeeResJson$o3, _ref8, _deliveryFeeResJson$o4, _deliveryFeeResJson$o5, _deliveryFeeResJson$o6;
|
|
1001
|
+
var weight, assetLocalizedLoc, feeResult, execFeeRes, execFee, deliveryFeeRes, deliveryFeeResJson, deliveryFeeResolved, nativeAsset, deliveryFee, res, _t4;
|
|
951
1002
|
return _regenerator().w(function (_context17) {
|
|
952
|
-
while (1) switch (_context17.n) {
|
|
1003
|
+
while (1) switch (_context17.p = _context17.n) {
|
|
953
1004
|
case 0:
|
|
954
1005
|
_context17.n = 1;
|
|
955
|
-
return this.getXcmWeight(
|
|
1006
|
+
return this.getXcmWeight(localXcm);
|
|
956
1007
|
case 1:
|
|
957
1008
|
weight = _context17.v;
|
|
958
1009
|
assertHasLocation(asset);
|
|
959
|
-
|
|
1010
|
+
assetLocalizedLoc = localizeLocation(chain, asset.location);
|
|
960
1011
|
_context17.n = 2;
|
|
961
|
-
return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, addXcmVersionHeader(
|
|
1012
|
+
return this.api.call.xcmPaymentApi.queryWeightToAssetFee(weight, addXcmVersionHeader(assetLocalizedLoc, Version.V4));
|
|
962
1013
|
case 2:
|
|
963
1014
|
feeResult = _context17.v;
|
|
964
|
-
|
|
965
|
-
|
|
1015
|
+
execFeeRes = feeResult.toJSON();
|
|
1016
|
+
execFee = BigInt(execFeeRes.ok);
|
|
1017
|
+
if (!(forwardedXcm.length > 0)) {
|
|
1018
|
+
_context17.n = 4;
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
_context17.n = 3;
|
|
1022
|
+
return this.api.call.xcmPaymentApi.queryDeliveryFees(forwardedXcm[0], forwardedXcm[1][0]);
|
|
1023
|
+
case 3:
|
|
1024
|
+
_t4 = _context17.v;
|
|
1025
|
+
_context17.n = 5;
|
|
1026
|
+
break;
|
|
1027
|
+
case 4:
|
|
1028
|
+
_t4 = undefined;
|
|
1029
|
+
case 5:
|
|
1030
|
+
deliveryFeeRes = _t4;
|
|
1031
|
+
deliveryFeeResJson = deliveryFeeRes === null || deliveryFeeRes === void 0 ? void 0 : deliveryFeeRes.toJSON();
|
|
1032
|
+
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;
|
|
1033
|
+
nativeAsset = findNativeAssetInfoOrThrow(chain);
|
|
1034
|
+
if (!isAssetXcEqual(asset, nativeAsset)) {
|
|
1035
|
+
_context17.n = 6;
|
|
1036
|
+
break;
|
|
1037
|
+
}
|
|
1038
|
+
deliveryFee = deliveryFeeResolved;
|
|
1039
|
+
_context17.n = 9;
|
|
1040
|
+
break;
|
|
1041
|
+
case 6:
|
|
1042
|
+
_context17.p = 6;
|
|
1043
|
+
assertHasLocation(nativeAsset);
|
|
1044
|
+
_context17.n = 7;
|
|
1045
|
+
return this.quoteAhPrice(localizeLocation(chain, nativeAsset.location), assetLocalizedLoc, deliveryFeeResolved, false);
|
|
1046
|
+
case 7:
|
|
1047
|
+
res = _context17.v;
|
|
1048
|
+
deliveryFee = res !== null && res !== void 0 ? res : 0n;
|
|
1049
|
+
_context17.n = 9;
|
|
1050
|
+
break;
|
|
1051
|
+
case 8:
|
|
1052
|
+
_context17.p = 8;
|
|
1053
|
+
_context17.v;
|
|
1054
|
+
deliveryFee = 0n;
|
|
1055
|
+
case 9:
|
|
1056
|
+
return _context17.a(2, execFee + deliveryFee);
|
|
966
1057
|
}
|
|
967
|
-
}, _callee17, this);
|
|
1058
|
+
}, _callee17, this, [[6, 8]]);
|
|
968
1059
|
}));
|
|
969
|
-
function getXcmPaymentApiFee(_x34, _x35, _x36) {
|
|
1060
|
+
function getXcmPaymentApiFee(_x34, _x35, _x36, _x37) {
|
|
970
1061
|
return _getXcmPaymentApiFee.apply(this, arguments);
|
|
971
1062
|
}
|
|
972
1063
|
return getXcmPaymentApiFee;
|
|
@@ -988,7 +1079,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
988
1079
|
}
|
|
989
1080
|
}, _callee18, this);
|
|
990
1081
|
}));
|
|
991
|
-
function getXcmWeight(
|
|
1082
|
+
function getXcmWeight(_x38) {
|
|
992
1083
|
return _getXcmWeight.apply(this, arguments);
|
|
993
1084
|
}
|
|
994
1085
|
return getXcmWeight;
|
|
@@ -996,13 +1087,13 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
996
1087
|
}, {
|
|
997
1088
|
key: "getDryRunXcm",
|
|
998
1089
|
value: function () {
|
|
999
|
-
var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(
|
|
1000
|
-
var
|
|
1001
|
-
var originLocation, xcm, asset, chain, origin, supportsDryRunApi, response, result, resultJson, symbol, isSuccess, failureReason,
|
|
1090
|
+
var _getDryRunXcm = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(_ref9) {
|
|
1091
|
+
var _ref1, _ref10, _ref11;
|
|
1092
|
+
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
1093
|
return _regenerator().w(function (_context19) {
|
|
1003
1094
|
while (1) switch (_context19.n) {
|
|
1004
1095
|
case 0:
|
|
1005
|
-
originLocation =
|
|
1096
|
+
originLocation = _ref9.originLocation, xcm = _ref9.xcm, asset = _ref9.asset, chain = _ref9.chain, origin = _ref9.origin;
|
|
1006
1097
|
supportsDryRunApi = getAssetsObject(chain).supportsDryRunApi;
|
|
1007
1098
|
if (supportsDryRunApi) {
|
|
1008
1099
|
_context19.n = 1;
|
|
@@ -1030,24 +1121,55 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1030
1121
|
asset: asset
|
|
1031
1122
|
});
|
|
1032
1123
|
case 3:
|
|
1124
|
+
forwardedXcms = resultJson.ok.forwardedXcms.length > 0 ? resultJson.ok.forwardedXcms[0] : [];
|
|
1125
|
+
actualWeight = resultJson.ok.executionResult.used;
|
|
1126
|
+
weight = actualWeight ? {
|
|
1127
|
+
refTime: BigInt(actualWeight.refTime),
|
|
1128
|
+
proofSize: BigInt(actualWeight.proofSize)
|
|
1129
|
+
} : undefined;
|
|
1130
|
+
destParaId = forwardedXcms.length === 0 ? undefined : function (i, _ref0) {
|
|
1131
|
+
return i.Here ? 0 : (_ref0 = Array.isArray(i.x1) ? i.x1[0] : i.x1) === null || _ref0 === void 0 ? void 0 : _ref0.parachain;
|
|
1132
|
+
}(Object.values(forwardedXcms[0])[0].interior);
|
|
1133
|
+
if (!(hasXcmPaymentApiSupport(chain) && asset)) {
|
|
1134
|
+
_context19.n = 5;
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
_context19.n = 4;
|
|
1138
|
+
return this.getXcmPaymentApiFee(chain, xcm, forwardedXcms, asset);
|
|
1139
|
+
case 4:
|
|
1140
|
+
_fee = _context19.v;
|
|
1141
|
+
if (!(typeof _fee === 'bigint')) {
|
|
1142
|
+
_context19.n = 5;
|
|
1143
|
+
break;
|
|
1144
|
+
}
|
|
1145
|
+
return _context19.a(2, {
|
|
1146
|
+
success: true,
|
|
1147
|
+
fee: _fee,
|
|
1148
|
+
currency: symbol,
|
|
1149
|
+
asset: asset,
|
|
1150
|
+
weight: weight,
|
|
1151
|
+
forwardedXcms: forwardedXcms,
|
|
1152
|
+
destParaId: destParaId
|
|
1153
|
+
});
|
|
1154
|
+
case 5:
|
|
1033
1155
|
emitted = result.Ok.emittedEvents; // We want to look for the last event
|
|
1034
1156
|
reversedEvents = _toConsumableArray(emitted).reverse();
|
|
1035
1157
|
palletsWithIssued = ['balances', 'foreignAssets', 'assets'];
|
|
1036
|
-
feeEvent = (
|
|
1158
|
+
feeEvent = (_ref1 = (_ref10 = (_ref11 = origin === 'Mythos' ? reversedEvents.find(function (event) {
|
|
1037
1159
|
return event.section === 'assetConversion' && event.method === 'SwapCreditExecuted';
|
|
1038
|
-
}) : undefined) !== null &&
|
|
1160
|
+
}) : undefined) !== null && _ref11 !== void 0 ? _ref11 :
|
|
1039
1161
|
// Prefer an Issued event
|
|
1040
1162
|
reversedEvents.find(function (event) {
|
|
1041
1163
|
return palletsWithIssued.includes(event.section) && event.method === 'Issued';
|
|
1042
|
-
})) !== null &&
|
|
1164
|
+
})) !== null && _ref10 !== void 0 ? _ref10 :
|
|
1043
1165
|
// Fallback to Minted event
|
|
1044
1166
|
reversedEvents.find(function (event) {
|
|
1045
1167
|
return ['balances', 'foreignAssets'].includes(event.section) && event.method === 'Minted';
|
|
1046
|
-
})) !== null &&
|
|
1168
|
+
})) !== null && _ref1 !== void 0 ? _ref1 : reversedEvents.find(function (event) {
|
|
1047
1169
|
return ['currencies', 'tokens'].includes(event.section) && event.method === 'Deposited';
|
|
1048
1170
|
});
|
|
1049
1171
|
if (feeEvent) {
|
|
1050
|
-
_context19.n =
|
|
1172
|
+
_context19.n = 6;
|
|
1051
1173
|
break;
|
|
1052
1174
|
}
|
|
1053
1175
|
return _context19.a(2, Promise.resolve({
|
|
@@ -1056,18 +1178,9 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1056
1178
|
currency: symbol,
|
|
1057
1179
|
asset: asset
|
|
1058
1180
|
}));
|
|
1059
|
-
case
|
|
1181
|
+
case 6:
|
|
1060
1182
|
feeAmount = feeEvent.section === 'assetConversion' ? feeEvent.data.amountIn : feeEvent.data.amount;
|
|
1061
1183
|
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
1184
|
return _context19.a(2, {
|
|
1072
1185
|
success: true,
|
|
1073
1186
|
fee: fee,
|
|
@@ -1080,7 +1193,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1080
1193
|
}
|
|
1081
1194
|
}, _callee19, this);
|
|
1082
1195
|
}));
|
|
1083
|
-
function getDryRunXcm(
|
|
1196
|
+
function getDryRunXcm(_x39) {
|
|
1084
1197
|
return _getDryRunXcm.apply(this, arguments);
|
|
1085
1198
|
}
|
|
1086
1199
|
return getDryRunXcm;
|
|
@@ -1133,7 +1246,7 @@ var PolkadotJsApi = /*#__PURE__*/function () {
|
|
|
1133
1246
|
}
|
|
1134
1247
|
}, _callee21, this);
|
|
1135
1248
|
}));
|
|
1136
|
-
function convertLocationToAccount(
|
|
1249
|
+
function convertLocationToAccount(_x40) {
|
|
1137
1250
|
return _convertLocationToAccount.apply(this, arguments);
|
|
1138
1251
|
}
|
|
1139
1252
|
return convertLocationToAccount;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paraspell/sdk-pjs",
|
|
3
|
-
"version": "11.9.
|
|
3
|
+
"version": "11.9.3",
|
|
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.
|
|
30
|
+
"@paraspell/sdk-core": "11.9.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@polkadot/api": ">= 16.0 < 17",
|