@paraspell/sdk-core 9.1.1 → 9.2.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 +193 -192
- package/dist/index.d.ts +13 -1
- package/dist/index.mjs +193 -194
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -733,6 +733,18 @@ var ScenarioNotSupportedError = /*#__PURE__*/function (_Error) {
|
|
|
733
733
|
return _createClass(ScenarioNotSupportedError);
|
|
734
734
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
735
735
|
|
|
736
|
+
var TransferToAhNotSupported = /*#__PURE__*/function (_Error) {
|
|
737
|
+
function TransferToAhNotSupported(message) {
|
|
738
|
+
var _this;
|
|
739
|
+
_classCallCheck(this, TransferToAhNotSupported);
|
|
740
|
+
_this = _callSuper(this, TransferToAhNotSupported, [message]);
|
|
741
|
+
_this.name = 'TransferToAhNotSupported';
|
|
742
|
+
return _this;
|
|
743
|
+
}
|
|
744
|
+
_inherits(TransferToAhNotSupported, _Error);
|
|
745
|
+
return _createClass(TransferToAhNotSupported);
|
|
746
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
747
|
+
|
|
736
748
|
// Inspired by Talisman Society’s SS58 encoder:
|
|
737
749
|
// https://github.com/TalismanSociety/talisman/blob/dev/packages/crypto/src/address/encoding/ss58.ts
|
|
738
750
|
var blake2b256 = function blake2b256(msg) {
|
|
@@ -2945,6 +2957,41 @@ var padFee = function padFee(raw, origin, dest, side) {
|
|
|
2945
2957
|
return mul(raw, 130n, 100n);
|
|
2946
2958
|
};
|
|
2947
2959
|
|
|
2960
|
+
var getReverseTxFee = /*#__PURE__*/function () {
|
|
2961
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, currencyInput) {
|
|
2962
|
+
var api, origin, destination, senderAddress, address, currency, tx, rawFee;
|
|
2963
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2964
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2965
|
+
case 0:
|
|
2966
|
+
api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
|
|
2967
|
+
if (!('multiasset' in currency)) {
|
|
2968
|
+
_context.next = 3;
|
|
2969
|
+
break;
|
|
2970
|
+
}
|
|
2971
|
+
throw new assets.InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
|
|
2972
|
+
case 3:
|
|
2973
|
+
_context.next = 5;
|
|
2974
|
+
return Builder(api).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
|
|
2975
|
+
amount: currency.amount
|
|
2976
|
+
})).build();
|
|
2977
|
+
case 5:
|
|
2978
|
+
tx = _context.sent;
|
|
2979
|
+
_context.next = 8;
|
|
2980
|
+
return api.calculateTransactionFee(tx, address);
|
|
2981
|
+
case 8:
|
|
2982
|
+
rawFee = _context.sent;
|
|
2983
|
+
return _context.abrupt("return", padFee(rawFee, origin, destination, 'destination'));
|
|
2984
|
+
case 10:
|
|
2985
|
+
case "end":
|
|
2986
|
+
return _context.stop();
|
|
2987
|
+
}
|
|
2988
|
+
}, _callee);
|
|
2989
|
+
}));
|
|
2990
|
+
return function getReverseTxFee(_x, _x2) {
|
|
2991
|
+
return _ref2.apply(this, arguments);
|
|
2992
|
+
};
|
|
2993
|
+
}();
|
|
2994
|
+
|
|
2948
2995
|
var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
2949
2996
|
if (sdkCommon.isRelayChain(origin)) return DOT_MULTILOCATION;
|
|
2950
2997
|
return {
|
|
@@ -2957,55 +3004,66 @@ var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
|
2957
3004
|
};
|
|
2958
3005
|
};
|
|
2959
3006
|
var getFeeForDestNode = /*#__PURE__*/function () {
|
|
2960
|
-
var
|
|
2961
|
-
var api,
|
|
3007
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
3008
|
+
var api, origin, destination, currency, forwardedXcms, disableFallback, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
|
|
2962
3009
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
2963
3010
|
while (1) switch (_context2.prev = _context2.next) {
|
|
2964
3011
|
case 0:
|
|
2965
|
-
api =
|
|
3012
|
+
api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, disableFallback = options.disableFallback;
|
|
2966
3013
|
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
2967
|
-
var
|
|
2968
|
-
var originAsset
|
|
3014
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
3015
|
+
var originAsset;
|
|
2969
3016
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2970
3017
|
while (1) switch (_context.prev = _context.next) {
|
|
2971
3018
|
case 0:
|
|
2972
|
-
if (!('multiasset' in currency)) {
|
|
2973
|
-
_context.next = 2;
|
|
2974
|
-
break;
|
|
2975
|
-
}
|
|
2976
|
-
throw new assets.InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
|
|
2977
|
-
case 2:
|
|
2978
3019
|
originAsset = assets.findAsset(origin, currency, destination);
|
|
2979
3020
|
if (originAsset) {
|
|
2980
|
-
_context.next =
|
|
3021
|
+
_context.next = 3;
|
|
2981
3022
|
break;
|
|
2982
3023
|
}
|
|
2983
3024
|
throw new assets.InvalidCurrencyError("Currency ".concat(JSON.stringify(currency), " not found in ").concat(origin));
|
|
2984
|
-
case
|
|
2985
|
-
|
|
3025
|
+
case 3:
|
|
3026
|
+
if (!originAsset.multiLocation) {
|
|
3027
|
+
_context.next = 17;
|
|
3028
|
+
break;
|
|
3029
|
+
}
|
|
3030
|
+
_context.prev = 4;
|
|
3031
|
+
_context.next = 7;
|
|
3032
|
+
return getReverseTxFee(options, {
|
|
2986
3033
|
multilocation: originAsset.multiLocation
|
|
2987
|
-
}
|
|
3034
|
+
});
|
|
3035
|
+
case 7:
|
|
3036
|
+
return _context.abrupt("return", _context.sent);
|
|
3037
|
+
case 10:
|
|
3038
|
+
_context.prev = 10;
|
|
3039
|
+
_context.t0 = _context["catch"](4);
|
|
3040
|
+
if (!(_context.t0 instanceof assets.InvalidCurrencyError)) {
|
|
3041
|
+
_context.next = 16;
|
|
3042
|
+
break;
|
|
3043
|
+
}
|
|
3044
|
+
_context.next = 15;
|
|
3045
|
+
return getReverseTxFee(options, {
|
|
2988
3046
|
symbol: originAsset.symbol
|
|
2989
|
-
};
|
|
2990
|
-
|
|
2991
|
-
return
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
case
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
return _context.abrupt("return",
|
|
3001
|
-
case
|
|
3047
|
+
});
|
|
3048
|
+
case 15:
|
|
3049
|
+
return _context.abrupt("return", _context.sent);
|
|
3050
|
+
case 16:
|
|
3051
|
+
throw _context.t0;
|
|
3052
|
+
case 17:
|
|
3053
|
+
_context.next = 19;
|
|
3054
|
+
return getReverseTxFee(options, {
|
|
3055
|
+
symbol: originAsset.symbol
|
|
3056
|
+
});
|
|
3057
|
+
case 19:
|
|
3058
|
+
return _context.abrupt("return", _context.sent);
|
|
3059
|
+
case 20:
|
|
3002
3060
|
case "end":
|
|
3003
3061
|
return _context.stop();
|
|
3004
3062
|
}
|
|
3005
|
-
}, _callee);
|
|
3063
|
+
}, _callee, null, [[4, 10]]);
|
|
3006
3064
|
}));
|
|
3007
3065
|
return function calcPaymentInfoFee() {
|
|
3008
|
-
return
|
|
3066
|
+
return _ref2.apply(this, arguments);
|
|
3009
3067
|
};
|
|
3010
3068
|
}();
|
|
3011
3069
|
if (!(!assets.hasDryRunSupport(destination) || !forwardedXcms)) {
|
|
@@ -3067,7 +3125,7 @@ var getFeeForDestNode = /*#__PURE__*/function () {
|
|
|
3067
3125
|
}, _callee2);
|
|
3068
3126
|
}));
|
|
3069
3127
|
return function getFeeForDestNode(_x) {
|
|
3070
|
-
return
|
|
3128
|
+
return _ref.apply(this, arguments);
|
|
3071
3129
|
};
|
|
3072
3130
|
}();
|
|
3073
3131
|
|
|
@@ -3930,49 +3988,52 @@ var getFeeForOriginNode = /*#__PURE__*/function () {
|
|
|
3930
3988
|
while (1) switch (_context.prev = _context.next) {
|
|
3931
3989
|
case 0:
|
|
3932
3990
|
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback;
|
|
3991
|
+
_context.next = 3;
|
|
3992
|
+
return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
3993
|
+
case 3:
|
|
3933
3994
|
if (assets.hasDryRunSupport(origin)) {
|
|
3934
|
-
_context.next =
|
|
3995
|
+
_context.next = 8;
|
|
3935
3996
|
break;
|
|
3936
3997
|
}
|
|
3937
|
-
_context.next =
|
|
3998
|
+
_context.next = 6;
|
|
3938
3999
|
return api.calculateTransactionFee(tx, senderAddress);
|
|
3939
|
-
case
|
|
4000
|
+
case 6:
|
|
3940
4001
|
rawFee = _context.sent;
|
|
3941
4002
|
return _context.abrupt("return", {
|
|
3942
4003
|
fee: padFee(rawFee, origin, destination, 'origin'),
|
|
3943
4004
|
feeType: 'paymentInfo'
|
|
3944
4005
|
});
|
|
3945
|
-
case
|
|
3946
|
-
_context.next =
|
|
4006
|
+
case 8:
|
|
4007
|
+
_context.next = 10;
|
|
3947
4008
|
return api.getDryRunCall({
|
|
3948
4009
|
tx: tx,
|
|
3949
4010
|
node: origin,
|
|
3950
4011
|
address: senderAddress
|
|
3951
4012
|
});
|
|
3952
|
-
case
|
|
4013
|
+
case 10:
|
|
3953
4014
|
dryRunResult = _context.sent;
|
|
3954
4015
|
if (dryRunResult.success) {
|
|
3955
|
-
_context.next =
|
|
4016
|
+
_context.next = 18;
|
|
3956
4017
|
break;
|
|
3957
4018
|
}
|
|
3958
4019
|
if (!disableFallback) {
|
|
3959
|
-
_context.next =
|
|
4020
|
+
_context.next = 14;
|
|
3960
4021
|
break;
|
|
3961
4022
|
}
|
|
3962
4023
|
return _context.abrupt("return", {
|
|
3963
4024
|
dryRunError: dryRunResult.failureReason
|
|
3964
4025
|
});
|
|
3965
|
-
case 12:
|
|
3966
|
-
_context.next = 14;
|
|
3967
|
-
return api.calculateTransactionFee(tx, senderAddress);
|
|
3968
4026
|
case 14:
|
|
4027
|
+
_context.next = 16;
|
|
4028
|
+
return api.calculateTransactionFee(tx, senderAddress);
|
|
4029
|
+
case 16:
|
|
3969
4030
|
_rawFee = _context.sent;
|
|
3970
4031
|
return _context.abrupt("return", {
|
|
3971
4032
|
fee: padFee(_rawFee, origin, destination, 'origin'),
|
|
3972
4033
|
feeType: 'paymentInfo',
|
|
3973
4034
|
dryRunError: dryRunResult.failureReason
|
|
3974
4035
|
});
|
|
3975
|
-
case
|
|
4036
|
+
case 18:
|
|
3976
4037
|
fee = dryRunResult.fee, forwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
3977
4038
|
return _context.abrupt("return", {
|
|
3978
4039
|
fee: fee,
|
|
@@ -3980,7 +4041,7 @@ var getFeeForOriginNode = /*#__PURE__*/function () {
|
|
|
3980
4041
|
forwardedXcms: forwardedXcms,
|
|
3981
4042
|
destParaId: destParaId
|
|
3982
4043
|
});
|
|
3983
|
-
case
|
|
4044
|
+
case 20:
|
|
3984
4045
|
case "end":
|
|
3985
4046
|
return _context.stop();
|
|
3986
4047
|
}
|
|
@@ -3994,7 +4055,7 @@ var getFeeForOriginNode = /*#__PURE__*/function () {
|
|
|
3994
4055
|
var getXcmFee = /*#__PURE__*/function () {
|
|
3995
4056
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
3996
4057
|
var _findAsset;
|
|
3997
|
-
var api, tx, origin, destination, senderAddress, address, currency, disableFallback, asset, _yield$getFeeForOrigi, originFee, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, destApi,
|
|
4058
|
+
var api, tx, origin, destination, senderAddress, address, currency, disableFallback, asset, _yield$getFeeForOrigi, originFee, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, destApi, destFeeRes, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, nextChain, hopApi, hopResult, failingRecord, hopIsDestination, destFallback;
|
|
3998
4059
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3999
4060
|
while (1) switch (_context.prev = _context.next) {
|
|
4000
4061
|
case 0:
|
|
@@ -4022,14 +4083,14 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4022
4083
|
originDryRunError = _yield$getFeeForOrigi.dryRunError;
|
|
4023
4084
|
initialForwardedXcm = _yield$getFeeForOrigi.forwardedXcms;
|
|
4024
4085
|
initialDestParaId = _yield$getFeeForOrigi.destParaId;
|
|
4025
|
-
|
|
4086
|
+
api.setDisconnectAllowed(true);
|
|
4087
|
+
_context.next = 15;
|
|
4088
|
+
return api.disconnect();
|
|
4089
|
+
case 15:
|
|
4090
|
+
if (!(originDryRunError || originFeeType === 'paymentInfo')) {
|
|
4026
4091
|
_context.next = 30;
|
|
4027
4092
|
break;
|
|
4028
4093
|
}
|
|
4029
|
-
api.setDisconnectAllowed(true);
|
|
4030
|
-
_context.next = 16;
|
|
4031
|
-
return api.disconnect();
|
|
4032
|
-
case 16:
|
|
4033
4094
|
destApi = api.clone();
|
|
4034
4095
|
_context.prev = 17;
|
|
4035
4096
|
_context.next = 20;
|
|
@@ -4040,6 +4101,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4040
4101
|
return getFeeForDestNode({
|
|
4041
4102
|
api: destApi,
|
|
4042
4103
|
forwardedXcms: undefined,
|
|
4104
|
+
// force paymentInfo
|
|
4043
4105
|
origin: origin,
|
|
4044
4106
|
destination: destination,
|
|
4045
4107
|
currency: currency,
|
|
@@ -4048,7 +4110,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4048
4110
|
disableFallback: disableFallback
|
|
4049
4111
|
});
|
|
4050
4112
|
case 23:
|
|
4051
|
-
|
|
4113
|
+
destFeeRes = _context.sent;
|
|
4052
4114
|
return _context.abrupt("return", {
|
|
4053
4115
|
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
4054
4116
|
fee: originFee
|
|
@@ -4059,10 +4121,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4059
4121
|
}, originDryRunError && {
|
|
4060
4122
|
dryRunError: originDryRunError
|
|
4061
4123
|
}),
|
|
4062
|
-
destination: _objectSpread2(_objectSpread2(_objectSpread2({},
|
|
4063
|
-
fee:
|
|
4064
|
-
}),
|
|
4065
|
-
feeType:
|
|
4124
|
+
destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee && {
|
|
4125
|
+
fee: destFeeRes.fee
|
|
4126
|
+
}), destFeeRes.feeType && {
|
|
4127
|
+
feeType: destFeeRes.feeType
|
|
4066
4128
|
}), {}, {
|
|
4067
4129
|
currency: assets.getNativeAssetSymbol(destination)
|
|
4068
4130
|
})
|
|
@@ -4075,83 +4137,30 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4075
4137
|
case 29:
|
|
4076
4138
|
return _context.finish(25);
|
|
4077
4139
|
case 30:
|
|
4078
|
-
api.setDisconnectAllowed(true);
|
|
4079
|
-
_context.next = 33;
|
|
4080
|
-
return api.disconnect();
|
|
4081
|
-
case 33:
|
|
4082
|
-
if (!originDryRunError) {
|
|
4083
|
-
_context.next = 48;
|
|
4084
|
-
break;
|
|
4085
|
-
}
|
|
4086
|
-
_destApi = api.clone();
|
|
4087
|
-
_context.prev = 35;
|
|
4088
|
-
_context.next = 38;
|
|
4089
|
-
return _destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4090
|
-
case 38:
|
|
4091
|
-
_destApi.setDisconnectAllowed(false);
|
|
4092
|
-
_context.next = 41;
|
|
4093
|
-
return getFeeForDestNode({
|
|
4094
|
-
api: _destApi,
|
|
4095
|
-
forwardedXcms: undefined,
|
|
4096
|
-
// force paymentInfo
|
|
4097
|
-
origin: origin,
|
|
4098
|
-
destination: destination,
|
|
4099
|
-
currency: currency,
|
|
4100
|
-
address: address,
|
|
4101
|
-
senderAddress: senderAddress,
|
|
4102
|
-
disableFallback: disableFallback
|
|
4103
|
-
});
|
|
4104
|
-
case 41:
|
|
4105
|
-
destFeeRes = _context.sent;
|
|
4106
|
-
return _context.abrupt("return", {
|
|
4107
|
-
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
4108
|
-
fee: originFee
|
|
4109
|
-
}), originFeeType && {
|
|
4110
|
-
feeType: originFeeType
|
|
4111
|
-
}), {}, {
|
|
4112
|
-
currency: assets.getNativeAssetSymbol(origin),
|
|
4113
|
-
dryRunError: originDryRunError
|
|
4114
|
-
}),
|
|
4115
|
-
destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee && {
|
|
4116
|
-
fee: destFeeRes.fee
|
|
4117
|
-
}), destFeeRes.feeType && {
|
|
4118
|
-
feeType: destFeeRes.feeType
|
|
4119
|
-
}), {}, {
|
|
4120
|
-
currency: assets.getNativeAssetSymbol(destination)
|
|
4121
|
-
})
|
|
4122
|
-
});
|
|
4123
|
-
case 43:
|
|
4124
|
-
_context.prev = 43;
|
|
4125
|
-
_destApi.setDisconnectAllowed(true);
|
|
4126
|
-
_context.next = 47;
|
|
4127
|
-
return _destApi.disconnect();
|
|
4128
|
-
case 47:
|
|
4129
|
-
return _context.finish(43);
|
|
4130
|
-
case 48:
|
|
4131
4140
|
currentOrigin = origin;
|
|
4132
4141
|
forwardedXcms = initialForwardedXcm;
|
|
4133
4142
|
nextParaId = initialDestParaId;
|
|
4134
4143
|
intermediateFees = {};
|
|
4135
4144
|
destinationFee = 0n;
|
|
4136
4145
|
destinationFeeType = 'paymentInfo';
|
|
4137
|
-
case
|
|
4146
|
+
case 36:
|
|
4138
4147
|
if (!(Array.isArray(forwardedXcms) && forwardedXcms.length > 0 && forwardedXcms[1].length > 0 && ('disconnect' in api.getApi() ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
|
|
4139
|
-
_context.next =
|
|
4148
|
+
_context.next = 68;
|
|
4140
4149
|
break;
|
|
4141
4150
|
}
|
|
4142
4151
|
nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
|
|
4143
4152
|
if (!(nextChain === null)) {
|
|
4144
|
-
_context.next =
|
|
4153
|
+
_context.next = 40;
|
|
4145
4154
|
break;
|
|
4146
4155
|
}
|
|
4147
4156
|
throw new Error("Unable to find TNode for paraId ".concat(nextParaId));
|
|
4148
|
-
case
|
|
4157
|
+
case 40:
|
|
4149
4158
|
hopApi = api.clone();
|
|
4150
|
-
_context.prev =
|
|
4151
|
-
_context.next =
|
|
4159
|
+
_context.prev = 41;
|
|
4160
|
+
_context.next = 44;
|
|
4152
4161
|
return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4153
|
-
case
|
|
4154
|
-
_context.next =
|
|
4162
|
+
case 44:
|
|
4163
|
+
_context.next = 46;
|
|
4155
4164
|
return getFeeForDestNode({
|
|
4156
4165
|
api: hopApi,
|
|
4157
4166
|
forwardedXcms: forwardedXcms,
|
|
@@ -4162,10 +4171,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4162
4171
|
senderAddress: senderAddress,
|
|
4163
4172
|
disableFallback: disableFallback
|
|
4164
4173
|
});
|
|
4165
|
-
case
|
|
4174
|
+
case 46:
|
|
4166
4175
|
hopResult = _context.sent;
|
|
4167
4176
|
if (!hopResult.dryRunError) {
|
|
4168
|
-
_context.next =
|
|
4177
|
+
_context.next = 58;
|
|
4169
4178
|
break;
|
|
4170
4179
|
}
|
|
4171
4180
|
failingRecord = {
|
|
@@ -4186,10 +4195,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4186
4195
|
}
|
|
4187
4196
|
// We failed before the true destination, use fallback via paymentInfo.
|
|
4188
4197
|
if (hopIsDestination) {
|
|
4189
|
-
_context.next =
|
|
4198
|
+
_context.next = 57;
|
|
4190
4199
|
break;
|
|
4191
4200
|
}
|
|
4192
|
-
_context.next =
|
|
4201
|
+
_context.next = 54;
|
|
4193
4202
|
return getFeeForDestNode({
|
|
4194
4203
|
api: hopApi,
|
|
4195
4204
|
forwardedXcms: undefined,
|
|
@@ -4200,13 +4209,13 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4200
4209
|
senderAddress: senderAddress,
|
|
4201
4210
|
disableFallback: disableFallback
|
|
4202
4211
|
});
|
|
4203
|
-
case
|
|
4212
|
+
case 54:
|
|
4204
4213
|
destFallback = _context.sent;
|
|
4205
4214
|
destinationFee = destFallback.fee;
|
|
4206
4215
|
destinationFeeType = destFallback.feeType;
|
|
4207
|
-
case
|
|
4208
|
-
return _context.abrupt("break",
|
|
4209
|
-
case
|
|
4216
|
+
case 57:
|
|
4217
|
+
return _context.abrupt("break", 68);
|
|
4218
|
+
case 58:
|
|
4210
4219
|
if (nextChain === destination || sdkCommon.isRelayChain(nextChain) && !sdkCommon.isRelayChain(destination)) {
|
|
4211
4220
|
destinationFee = hopResult.fee;
|
|
4212
4221
|
destinationFeeType = hopResult.feeType;
|
|
@@ -4226,16 +4235,16 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4226
4235
|
forwardedXcms = hopResult.forwardedXcms;
|
|
4227
4236
|
nextParaId = hopResult.destParaId;
|
|
4228
4237
|
currentOrigin = nextChain;
|
|
4229
|
-
case
|
|
4230
|
-
_context.prev =
|
|
4231
|
-
_context.next =
|
|
4238
|
+
case 62:
|
|
4239
|
+
_context.prev = 62;
|
|
4240
|
+
_context.next = 65;
|
|
4232
4241
|
return hopApi.disconnect();
|
|
4233
|
-
case
|
|
4234
|
-
return _context.finish(
|
|
4235
|
-
case
|
|
4236
|
-
_context.next =
|
|
4242
|
+
case 65:
|
|
4243
|
+
return _context.finish(62);
|
|
4244
|
+
case 66:
|
|
4245
|
+
_context.next = 36;
|
|
4237
4246
|
break;
|
|
4238
|
-
case
|
|
4247
|
+
case 68:
|
|
4239
4248
|
return _context.abrupt("return", _objectSpread2(_objectSpread2({
|
|
4240
4249
|
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
4241
4250
|
fee: originFee
|
|
@@ -4257,11 +4266,11 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4257
4266
|
dryRunError: destinationDryRunError
|
|
4258
4267
|
})
|
|
4259
4268
|
}));
|
|
4260
|
-
case
|
|
4269
|
+
case 69:
|
|
4261
4270
|
case "end":
|
|
4262
4271
|
return _context.stop();
|
|
4263
4272
|
}
|
|
4264
|
-
}, _callee, null, [[17,, 25, 30], [
|
|
4273
|
+
}, _callee, null, [[17,, 25, 30], [41,, 62, 66]]);
|
|
4265
4274
|
}));
|
|
4266
4275
|
return function getXcmFee(_x) {
|
|
4267
4276
|
return _ref2.apply(this, arguments);
|
|
@@ -4429,70 +4438,17 @@ var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, cu
|
|
|
4429
4438
|
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
4430
4439
|
};
|
|
4431
4440
|
|
|
4432
|
-
var validateCurrency = function validateCurrency(currency, feeAsset) {
|
|
4433
|
-
if ('multiasset' in currency) {
|
|
4434
|
-
if (currency.multiasset.length === 0) {
|
|
4435
|
-
throw new assets.InvalidCurrencyError('Overridden multi assets cannot be empty');
|
|
4436
|
-
}
|
|
4437
|
-
if (currency.multiasset.length === 1) {
|
|
4438
|
-
throw new assets.InvalidCurrencyError('Please provide more than one multi asset');
|
|
4439
|
-
}
|
|
4440
|
-
if (currency.multiasset.length > 1 && !currency.multiasset.every(function (asset) {
|
|
4441
|
-
return assets.isTMultiAsset(asset);
|
|
4442
|
-
}) && !feeAsset) {
|
|
4443
|
-
throw new assets.InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
|
|
4444
|
-
}
|
|
4445
|
-
}
|
|
4446
|
-
};
|
|
4447
|
-
var validateDestination = function validateDestination(origin, destination) {
|
|
4448
|
-
if (sdkCommon.isRelayChain(origin) && !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination) && origin !== destination) {
|
|
4449
|
-
throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
|
|
4450
|
-
}
|
|
4451
|
-
if (destination === 'Ethereum' && origin !== 'AssetHubPolkadot' && origin !== 'Hydration' && origin !== 'BifrostPolkadot' && origin !== 'Moonbeam') {
|
|
4452
|
-
throw new IncompatibleNodesError('Transfers to Ethereum are only supported from AssetHubPolkadot and Hydration.');
|
|
4453
|
-
}
|
|
4454
|
-
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
4455
|
-
var isBridge = isBridgeTransfer(origin, destination);
|
|
4456
|
-
var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
|
|
4457
|
-
if (!isRelayDestination && !isMultiLocationDestination) {
|
|
4458
|
-
var originRelayChainSymbol = assets.getRelayChainSymbol(origin);
|
|
4459
|
-
var destinationRelayChainSymbol = assets.getRelayChainSymbol(destination);
|
|
4460
|
-
if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
|
|
4461
|
-
throw new IncompatibleNodesError();
|
|
4462
|
-
}
|
|
4463
|
-
}
|
|
4464
|
-
};
|
|
4465
|
-
var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
|
|
4466
|
-
if (!assetCheckEnabled && 'symbol' in currency && assets.isSymbolSpecifier(currency.symbol)) {
|
|
4467
|
-
throw new assets.InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
|
|
4468
|
-
}
|
|
4469
|
-
if (!assetCheckEnabled && 'id' in currency) {
|
|
4470
|
-
throw new assets.InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
|
|
4471
|
-
}
|
|
4472
|
-
};
|
|
4473
4441
|
var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
|
|
4474
4442
|
var origin = _ref.from,
|
|
4475
4443
|
destination = _ref.to,
|
|
4476
4444
|
currency = _ref.currency;
|
|
4477
|
-
var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
|
|
4478
|
-
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
4479
4445
|
var isDestAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
|
|
4480
|
-
var
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
var nativeAssets = assets.getNativeAssets(destination);
|
|
4484
|
-
if (origin === 'Hydration') {
|
|
4485
|
-
nativeAssets = nativeAssets.filter(function (nativeAsset) {
|
|
4486
|
-
return nativeAsset.symbol !== 'DOT';
|
|
4487
|
-
});
|
|
4488
|
-
}
|
|
4489
|
-
if ('symbol' in currency && nativeAssets.some(function (nativeAsset) {
|
|
4490
|
-
var _asset$symbol;
|
|
4491
|
-
return nativeAsset.symbol.toLowerCase() === (asset === null || asset === void 0 || (_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toLowerCase());
|
|
4492
|
-
})) {
|
|
4493
|
-
throw new assets.InvalidCurrencyError("".concat(JSON.stringify(asset === null || asset === void 0 ? void 0 : asset.symbol), " is not supported for transfers to ").concat(destination, "."));
|
|
4494
|
-
}
|
|
4446
|
+
var allowedChainsToAh = ['BifrostPolkadot', 'BifrostKusama', 'Hydration', 'Moonbeam', 'Ajuna', 'Polimec'];
|
|
4447
|
+
if (!sdkCommon.isRelayChain(origin) && !isBridge && isDestAssetHub && !allowedChainsToAh.includes(origin) && (asset === null || asset === void 0 ? void 0 : asset.symbol) === 'DOT') {
|
|
4448
|
+
throw new TransferToAhNotSupported("Node ".concat(origin, " does not support DOT transfer to AssetHub"));
|
|
4495
4449
|
}
|
|
4450
|
+
var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
|
|
4451
|
+
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
4496
4452
|
if (!isBridge && !isRelayDestination && !isMultiLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !assets.hasSupportForAsset(destination, asset.symbol)) {
|
|
4497
4453
|
throw new assets.InvalidCurrencyError("Destination node ".concat(destination, " does not support currency ").concat(JSON.stringify(currency), "."));
|
|
4498
4454
|
}
|
|
@@ -4572,6 +4528,49 @@ var validateDestinationAddress = function validateDestinationAddress(address, de
|
|
|
4572
4528
|
}
|
|
4573
4529
|
};
|
|
4574
4530
|
|
|
4531
|
+
var validateCurrency = function validateCurrency(currency, feeAsset) {
|
|
4532
|
+
if ('multiasset' in currency) {
|
|
4533
|
+
if (currency.multiasset.length === 0) {
|
|
4534
|
+
throw new assets.InvalidCurrencyError('Overridden multi assets cannot be empty');
|
|
4535
|
+
}
|
|
4536
|
+
if (currency.multiasset.length === 1) {
|
|
4537
|
+
throw new assets.InvalidCurrencyError('Please provide more than one multi asset');
|
|
4538
|
+
}
|
|
4539
|
+
if (currency.multiasset.length > 1 && !currency.multiasset.every(function (asset) {
|
|
4540
|
+
return assets.isTMultiAsset(asset);
|
|
4541
|
+
}) && !feeAsset) {
|
|
4542
|
+
throw new assets.InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
|
|
4543
|
+
}
|
|
4544
|
+
}
|
|
4545
|
+
};
|
|
4546
|
+
var validateDestination = function validateDestination(origin, destination) {
|
|
4547
|
+
if (sdkCommon.isRelayChain(origin) && !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination) && origin !== destination) {
|
|
4548
|
+
throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
|
|
4549
|
+
}
|
|
4550
|
+
var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam'];
|
|
4551
|
+
if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
|
|
4552
|
+
throw new IncompatibleNodesError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
|
|
4553
|
+
}
|
|
4554
|
+
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
4555
|
+
var isBridge = isBridgeTransfer(origin, destination);
|
|
4556
|
+
var isRelayDestination = !sdkCommon.isTMultiLocation(destination) && sdkCommon.isRelayChain(destination);
|
|
4557
|
+
if (!isRelayDestination && !isMultiLocationDestination) {
|
|
4558
|
+
var originRelayChainSymbol = assets.getRelayChainSymbol(origin);
|
|
4559
|
+
var destinationRelayChainSymbol = assets.getRelayChainSymbol(destination);
|
|
4560
|
+
if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
|
|
4561
|
+
throw new IncompatibleNodesError();
|
|
4562
|
+
}
|
|
4563
|
+
}
|
|
4564
|
+
};
|
|
4565
|
+
var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
|
|
4566
|
+
if (!assetCheckEnabled && 'symbol' in currency && assets.isSymbolSpecifier(currency.symbol)) {
|
|
4567
|
+
throw new assets.InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
|
|
4568
|
+
}
|
|
4569
|
+
if (!assetCheckEnabled && 'id' in currency) {
|
|
4570
|
+
throw new assets.InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
|
|
4571
|
+
}
|
|
4572
|
+
};
|
|
4573
|
+
|
|
4575
4574
|
var send = /*#__PURE__*/function () {
|
|
4576
4575
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
4577
4576
|
var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, isLocalTransfer, overriddenAsset, resolvedAsset, originNode;
|
|
@@ -9684,6 +9683,7 @@ exports.NoXCMSupportImplementedError = NoXCMSupportImplementedError;
|
|
|
9684
9683
|
exports.NodeNotSupportedError = NodeNotSupportedError;
|
|
9685
9684
|
exports.ScenarioNotSupportedError = ScenarioNotSupportedError;
|
|
9686
9685
|
exports.TX_CLIENT_TIMEOUT_MS = TX_CLIENT_TIMEOUT_MS;
|
|
9686
|
+
exports.TransferToAhNotSupported = TransferToAhNotSupported;
|
|
9687
9687
|
exports.blake2b256 = blake2b256;
|
|
9688
9688
|
exports.blake2b512 = blake2b512;
|
|
9689
9689
|
exports.claimAssets = claimAssets;
|
|
@@ -9707,6 +9707,7 @@ exports.getBalanceForeignInternal = getBalanceForeignInternal;
|
|
|
9707
9707
|
exports.getBalanceNative = getBalanceNative;
|
|
9708
9708
|
exports.getBalanceNativeInternal = getBalanceNativeInternal;
|
|
9709
9709
|
exports.getBridgeStatus = getBridgeStatus;
|
|
9710
|
+
exports.getFeeForOriginNode = getFeeForOriginNode;
|
|
9710
9711
|
exports.getFees = getFees;
|
|
9711
9712
|
exports.getMaxForeignTransferableAmount = getMaxForeignTransferableAmount;
|
|
9712
9713
|
exports.getMaxForeignTransferableAmountInternal = getMaxForeignTransferableAmountInternal;
|
package/dist/index.d.ts
CHANGED
|
@@ -1639,6 +1639,10 @@ declare class ScenarioNotSupportedError extends Error {
|
|
|
1639
1639
|
constructor(node: TNode, scenario: TScenario, message?: string);
|
|
1640
1640
|
}
|
|
1641
1641
|
|
|
1642
|
+
declare class TransferToAhNotSupported extends Error {
|
|
1643
|
+
constructor(message?: string);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1642
1646
|
declare const getNodeConfig: (node: TNodeDotKsmWithRelayChains) => TNodeConfig;
|
|
1643
1647
|
|
|
1644
1648
|
declare const getNodeProviders: (node: TNodeDotKsmWithRelayChains) => string[];
|
|
@@ -1697,6 +1701,14 @@ declare const transferMoonbeamToEth: <TApi, TRes>({ api, from, to, signer, addre
|
|
|
1697
1701
|
declare const isEthersSigner: (signer: Signer | WalletClient) => signer is Signer;
|
|
1698
1702
|
declare const isEthersContract: (contract: Contract | GetContractReturnType<Abi | readonly unknown[]>) => contract is Contract;
|
|
1699
1703
|
|
|
1704
|
+
declare const getFeeForOriginNode: <TApi, TRes>({ api, tx, origin, destination, senderAddress, disableFallback }: TGetFeeForOriginNodeOptions<TApi, TRes>) => Promise<{
|
|
1705
|
+
fee?: bigint;
|
|
1706
|
+
feeType?: TFeeType;
|
|
1707
|
+
dryRunError?: string;
|
|
1708
|
+
forwardedXcms?: any;
|
|
1709
|
+
destParaId?: number;
|
|
1710
|
+
}>;
|
|
1711
|
+
|
|
1700
1712
|
declare const getXcmFee: <TApi, TRes>({ api, tx, origin, destination, senderAddress, address, currency, disableFallback }: TGetXcmFeeOptions<TApi, TRes>) => Promise<TGetXcmFeeResult>;
|
|
1701
1713
|
|
|
1702
1714
|
declare const getXcmFeeEstimate: <TApi, TRes>({ api, tx, origin, destination, address, senderAddress, currency }: TGetXcmFeeEstimateOptions<TApi, TRes>) => Promise<TGetXcmFeeEstimateResult>;
|
|
@@ -1756,5 +1768,5 @@ declare const validateAddress: (address: TAddress, node: TNodeWithRelayChains, i
|
|
|
1756
1768
|
*/
|
|
1757
1769
|
declare const determineRelayChain: (node: TNodeWithRelayChains) => TRelaychain;
|
|
1758
1770
|
|
|
1759
|
-
export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, Version, XTokensError, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, deriveAccountId, determineRelayChain, dryRun, dryRunOrigin, encodeSs58, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getFees, getMaxForeignTransferableAmount, getMaxForeignTransferableAmountInternal, getMaxNativeTransferableAmount, getMaxNativeTransferableAmountInternal, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, reverseTransformMultiLocation, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
|
|
1771
|
+
export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, Version, XTokensError, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, deriveAccountId, determineRelayChain, dryRun, dryRunOrigin, encodeSs58, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getFeeForOriginNode, getFees, getMaxForeignTransferableAmount, getMaxForeignTransferableAmountInternal, getMaxNativeTransferableAmount, getMaxNativeTransferableAmountInternal, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, reverseTransformMultiLocation, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
|
|
1760
1772
|
export type { IPolkadotApi, IPolkadotXCMTransfer, IXTokensTransfer, IXTransferTransfer, OneKey, TAddress, TApiOrUrl, TAssetClaimOptions, TAssetClaimOptionsBase, TBalanceResponse, TBatchOptions, TBifrostToken, TBridgeStatus, TCreateBeneficiaryOptions, TDestWeight, TDestination, TDryRunBaseOptions, TDryRunCallBaseOptions, TDryRunCallOptions, TDryRunNodeFailure, TDryRunNodeResult, TDryRunNodeResultInternal, TDryRunNodeSuccess, TDryRunOptions, TDryRunResult, TDryRunXcmBaseOptions, TDryRunXcmOptions, TEdJsonMap, TEvmBuilderOptions, TEvmBuilderOptionsBase, TEvmNodeFrom, TFeeType, TForeignAssetId, TForeignOrNativeAsset, TForeignOrTokenAsset, TGetAssetBalanceOptions, TGetAssetBalanceOptionsBase, TGetBalanceForeignOptions, TGetBalanceForeignOptionsBase, TGetBalanceNativeOptions, TGetBalanceNativeOptionsBase, TGetFeeForDestNodeBaseOptions, TGetFeeForDestNodeOptions, TGetFeeForOriginNodeBaseOptions, TGetFeeForOriginNodeOptions, TGetMaxForeignTransferableAmountOptions, TGetMaxForeignTransferableAmountOptionsBase, TGetMaxNativeTransferableAmountOptions, TGetMaxNativeTransferableAmountOptionsBase, TGetOriginFeeDetailsOptions, TGetOriginFeeDetailsOptionsBase, TGetTransferInfoOptions, TGetTransferInfoOptionsBase, TGetTransferableAmountOptions, TGetTransferableAmountOptionsBase, TGetXcmFeeBaseOptions, TGetXcmFeeBuilderOptions, TGetXcmFeeEstimateDetail, TGetXcmFeeEstimateOptions, TGetXcmFeeEstimateResult, TGetXcmFeeOptions, TGetXcmFeeResult, THubKey, TMantaAsset, TModuleError, TNativeTokenAsset, TNodeConfig, TNodeConfigMap, TNodleAsset, TOriginFeeDetails, TOtherReserveAsset, TPolkadotXCMTransferOptions, TPolkadotXcmSection, TProviderEntry, TRelayToParaDestination, TRelayToParaOptions, TRelayToParaOverrides, TRelaychain, TReserveAsset, TScenario, TSelfReserveAsset, TSendBaseOptions, TSendBaseOptionsWithSenderAddress, TSendInternalOptions, TSendOptions, TSerializeEthTransferOptions, TSerializedApiCall, TSerializedEthTransfer, TTransferInfo, TTransferLocalOptions, TVerifyEdOnDestinationOptions, TVerifyEdOnDestinationOptionsBase, TVersionClaimAssets, TWeight, TXTokensCurrencySelection, TXTokensSection, TXTokensTransferOptions, TXTransferSection, TXTransferTransferOptions, TXcmAsset, TXcmFeeDetail, TXcmForeignAsset, TXcmPalletSection, TXcmVersioned, TZeitgeistAsset, WithApi };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blake2b } from '@noble/hashes/blake2';
|
|
2
|
-
import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, getRelayChainSymbol, isForeignAsset, hasDryRunSupport, findAsset, isOverrideMultiLocationSpecifier, findAssetByMultiLocation, isTMultiAsset,
|
|
2
|
+
import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, getRelayChainSymbol, isForeignAsset, hasDryRunSupport, findAsset, isOverrideMultiLocationSpecifier, findAssetByMultiLocation, isTMultiAsset, hasSupportForAsset, extractMultiAssetLoc, isAssetEqual, isSymbolSpecifier, getAssetId, getExistentialDeposit } from '@paraspell/assets';
|
|
3
3
|
export * from '@paraspell/assets';
|
|
4
4
|
import { base58 } from '@scure/base';
|
|
5
5
|
import { ethers, Contract } from 'ethers';
|
|
@@ -734,6 +734,18 @@ var ScenarioNotSupportedError = /*#__PURE__*/function (_Error) {
|
|
|
734
734
|
return _createClass(ScenarioNotSupportedError);
|
|
735
735
|
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
736
736
|
|
|
737
|
+
var TransferToAhNotSupported = /*#__PURE__*/function (_Error) {
|
|
738
|
+
function TransferToAhNotSupported(message) {
|
|
739
|
+
var _this;
|
|
740
|
+
_classCallCheck(this, TransferToAhNotSupported);
|
|
741
|
+
_this = _callSuper(this, TransferToAhNotSupported, [message]);
|
|
742
|
+
_this.name = 'TransferToAhNotSupported';
|
|
743
|
+
return _this;
|
|
744
|
+
}
|
|
745
|
+
_inherits(TransferToAhNotSupported, _Error);
|
|
746
|
+
return _createClass(TransferToAhNotSupported);
|
|
747
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
748
|
+
|
|
737
749
|
// Inspired by Talisman Society’s SS58 encoder:
|
|
738
750
|
// https://github.com/TalismanSociety/talisman/blob/dev/packages/crypto/src/address/encoding/ss58.ts
|
|
739
751
|
var blake2b256 = function blake2b256(msg) {
|
|
@@ -2946,6 +2958,41 @@ var padFee = function padFee(raw, origin, dest, side) {
|
|
|
2946
2958
|
return mul(raw, 130n, 100n);
|
|
2947
2959
|
};
|
|
2948
2960
|
|
|
2961
|
+
var getReverseTxFee = /*#__PURE__*/function () {
|
|
2962
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref, currencyInput) {
|
|
2963
|
+
var api, origin, destination, senderAddress, address, currency, tx, rawFee;
|
|
2964
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2965
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2966
|
+
case 0:
|
|
2967
|
+
api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
|
|
2968
|
+
if (!('multiasset' in currency)) {
|
|
2969
|
+
_context.next = 3;
|
|
2970
|
+
break;
|
|
2971
|
+
}
|
|
2972
|
+
throw new InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
|
|
2973
|
+
case 3:
|
|
2974
|
+
_context.next = 5;
|
|
2975
|
+
return Builder(api).from(destination).to(origin).address(senderAddress).senderAddress(address).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
|
|
2976
|
+
amount: currency.amount
|
|
2977
|
+
})).build();
|
|
2978
|
+
case 5:
|
|
2979
|
+
tx = _context.sent;
|
|
2980
|
+
_context.next = 8;
|
|
2981
|
+
return api.calculateTransactionFee(tx, address);
|
|
2982
|
+
case 8:
|
|
2983
|
+
rawFee = _context.sent;
|
|
2984
|
+
return _context.abrupt("return", padFee(rawFee, origin, destination, 'destination'));
|
|
2985
|
+
case 10:
|
|
2986
|
+
case "end":
|
|
2987
|
+
return _context.stop();
|
|
2988
|
+
}
|
|
2989
|
+
}, _callee);
|
|
2990
|
+
}));
|
|
2991
|
+
return function getReverseTxFee(_x, _x2) {
|
|
2992
|
+
return _ref2.apply(this, arguments);
|
|
2993
|
+
};
|
|
2994
|
+
}();
|
|
2995
|
+
|
|
2949
2996
|
var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
2950
2997
|
if (isRelayChain(origin)) return DOT_MULTILOCATION;
|
|
2951
2998
|
return {
|
|
@@ -2958,55 +3005,66 @@ var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
|
2958
3005
|
};
|
|
2959
3006
|
};
|
|
2960
3007
|
var getFeeForDestNode = /*#__PURE__*/function () {
|
|
2961
|
-
var
|
|
2962
|
-
var api,
|
|
3008
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
3009
|
+
var api, origin, destination, currency, forwardedXcms, disableFallback, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
|
|
2963
3010
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
2964
3011
|
while (1) switch (_context2.prev = _context2.next) {
|
|
2965
3012
|
case 0:
|
|
2966
|
-
api =
|
|
3013
|
+
api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, disableFallback = options.disableFallback;
|
|
2967
3014
|
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
2968
|
-
var
|
|
2969
|
-
var originAsset
|
|
3015
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
3016
|
+
var originAsset;
|
|
2970
3017
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2971
3018
|
while (1) switch (_context.prev = _context.next) {
|
|
2972
3019
|
case 0:
|
|
2973
|
-
if (!('multiasset' in currency)) {
|
|
2974
|
-
_context.next = 2;
|
|
2975
|
-
break;
|
|
2976
|
-
}
|
|
2977
|
-
throw new InvalidCurrencyError('Multi-assets are not yet supported for XCM fee calculation.');
|
|
2978
|
-
case 2:
|
|
2979
3020
|
originAsset = findAsset(origin, currency, destination);
|
|
2980
3021
|
if (originAsset) {
|
|
2981
|
-
_context.next =
|
|
3022
|
+
_context.next = 3;
|
|
2982
3023
|
break;
|
|
2983
3024
|
}
|
|
2984
3025
|
throw new InvalidCurrencyError("Currency ".concat(JSON.stringify(currency), " not found in ").concat(origin));
|
|
2985
|
-
case
|
|
2986
|
-
|
|
3026
|
+
case 3:
|
|
3027
|
+
if (!originAsset.multiLocation) {
|
|
3028
|
+
_context.next = 17;
|
|
3029
|
+
break;
|
|
3030
|
+
}
|
|
3031
|
+
_context.prev = 4;
|
|
3032
|
+
_context.next = 7;
|
|
3033
|
+
return getReverseTxFee(options, {
|
|
2987
3034
|
multilocation: originAsset.multiLocation
|
|
2988
|
-
}
|
|
3035
|
+
});
|
|
3036
|
+
case 7:
|
|
3037
|
+
return _context.abrupt("return", _context.sent);
|
|
3038
|
+
case 10:
|
|
3039
|
+
_context.prev = 10;
|
|
3040
|
+
_context.t0 = _context["catch"](4);
|
|
3041
|
+
if (!(_context.t0 instanceof InvalidCurrencyError)) {
|
|
3042
|
+
_context.next = 16;
|
|
3043
|
+
break;
|
|
3044
|
+
}
|
|
3045
|
+
_context.next = 15;
|
|
3046
|
+
return getReverseTxFee(options, {
|
|
2989
3047
|
symbol: originAsset.symbol
|
|
2990
|
-
};
|
|
2991
|
-
|
|
2992
|
-
return
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
case
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
return _context.abrupt("return",
|
|
3002
|
-
case
|
|
3048
|
+
});
|
|
3049
|
+
case 15:
|
|
3050
|
+
return _context.abrupt("return", _context.sent);
|
|
3051
|
+
case 16:
|
|
3052
|
+
throw _context.t0;
|
|
3053
|
+
case 17:
|
|
3054
|
+
_context.next = 19;
|
|
3055
|
+
return getReverseTxFee(options, {
|
|
3056
|
+
symbol: originAsset.symbol
|
|
3057
|
+
});
|
|
3058
|
+
case 19:
|
|
3059
|
+
return _context.abrupt("return", _context.sent);
|
|
3060
|
+
case 20:
|
|
3003
3061
|
case "end":
|
|
3004
3062
|
return _context.stop();
|
|
3005
3063
|
}
|
|
3006
|
-
}, _callee);
|
|
3064
|
+
}, _callee, null, [[4, 10]]);
|
|
3007
3065
|
}));
|
|
3008
3066
|
return function calcPaymentInfoFee() {
|
|
3009
|
-
return
|
|
3067
|
+
return _ref2.apply(this, arguments);
|
|
3010
3068
|
};
|
|
3011
3069
|
}();
|
|
3012
3070
|
if (!(!hasDryRunSupport(destination) || !forwardedXcms)) {
|
|
@@ -3068,7 +3126,7 @@ var getFeeForDestNode = /*#__PURE__*/function () {
|
|
|
3068
3126
|
}, _callee2);
|
|
3069
3127
|
}));
|
|
3070
3128
|
return function getFeeForDestNode(_x) {
|
|
3071
|
-
return
|
|
3129
|
+
return _ref.apply(this, arguments);
|
|
3072
3130
|
};
|
|
3073
3131
|
}();
|
|
3074
3132
|
|
|
@@ -3931,49 +3989,52 @@ var getFeeForOriginNode = /*#__PURE__*/function () {
|
|
|
3931
3989
|
while (1) switch (_context.prev = _context.next) {
|
|
3932
3990
|
case 0:
|
|
3933
3991
|
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback;
|
|
3992
|
+
_context.next = 3;
|
|
3993
|
+
return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
3994
|
+
case 3:
|
|
3934
3995
|
if (hasDryRunSupport(origin)) {
|
|
3935
|
-
_context.next =
|
|
3996
|
+
_context.next = 8;
|
|
3936
3997
|
break;
|
|
3937
3998
|
}
|
|
3938
|
-
_context.next =
|
|
3999
|
+
_context.next = 6;
|
|
3939
4000
|
return api.calculateTransactionFee(tx, senderAddress);
|
|
3940
|
-
case
|
|
4001
|
+
case 6:
|
|
3941
4002
|
rawFee = _context.sent;
|
|
3942
4003
|
return _context.abrupt("return", {
|
|
3943
4004
|
fee: padFee(rawFee, origin, destination, 'origin'),
|
|
3944
4005
|
feeType: 'paymentInfo'
|
|
3945
4006
|
});
|
|
3946
|
-
case
|
|
3947
|
-
_context.next =
|
|
4007
|
+
case 8:
|
|
4008
|
+
_context.next = 10;
|
|
3948
4009
|
return api.getDryRunCall({
|
|
3949
4010
|
tx: tx,
|
|
3950
4011
|
node: origin,
|
|
3951
4012
|
address: senderAddress
|
|
3952
4013
|
});
|
|
3953
|
-
case
|
|
4014
|
+
case 10:
|
|
3954
4015
|
dryRunResult = _context.sent;
|
|
3955
4016
|
if (dryRunResult.success) {
|
|
3956
|
-
_context.next =
|
|
4017
|
+
_context.next = 18;
|
|
3957
4018
|
break;
|
|
3958
4019
|
}
|
|
3959
4020
|
if (!disableFallback) {
|
|
3960
|
-
_context.next =
|
|
4021
|
+
_context.next = 14;
|
|
3961
4022
|
break;
|
|
3962
4023
|
}
|
|
3963
4024
|
return _context.abrupt("return", {
|
|
3964
4025
|
dryRunError: dryRunResult.failureReason
|
|
3965
4026
|
});
|
|
3966
|
-
case 12:
|
|
3967
|
-
_context.next = 14;
|
|
3968
|
-
return api.calculateTransactionFee(tx, senderAddress);
|
|
3969
4027
|
case 14:
|
|
4028
|
+
_context.next = 16;
|
|
4029
|
+
return api.calculateTransactionFee(tx, senderAddress);
|
|
4030
|
+
case 16:
|
|
3970
4031
|
_rawFee = _context.sent;
|
|
3971
4032
|
return _context.abrupt("return", {
|
|
3972
4033
|
fee: padFee(_rawFee, origin, destination, 'origin'),
|
|
3973
4034
|
feeType: 'paymentInfo',
|
|
3974
4035
|
dryRunError: dryRunResult.failureReason
|
|
3975
4036
|
});
|
|
3976
|
-
case
|
|
4037
|
+
case 18:
|
|
3977
4038
|
fee = dryRunResult.fee, forwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
3978
4039
|
return _context.abrupt("return", {
|
|
3979
4040
|
fee: fee,
|
|
@@ -3981,7 +4042,7 @@ var getFeeForOriginNode = /*#__PURE__*/function () {
|
|
|
3981
4042
|
forwardedXcms: forwardedXcms,
|
|
3982
4043
|
destParaId: destParaId
|
|
3983
4044
|
});
|
|
3984
|
-
case
|
|
4045
|
+
case 20:
|
|
3985
4046
|
case "end":
|
|
3986
4047
|
return _context.stop();
|
|
3987
4048
|
}
|
|
@@ -3995,7 +4056,7 @@ var getFeeForOriginNode = /*#__PURE__*/function () {
|
|
|
3995
4056
|
var getXcmFee = /*#__PURE__*/function () {
|
|
3996
4057
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
3997
4058
|
var _findAsset;
|
|
3998
|
-
var api, tx, origin, destination, senderAddress, address, currency, disableFallback, asset, _yield$getFeeForOrigi, originFee, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, destApi,
|
|
4059
|
+
var api, tx, origin, destination, senderAddress, address, currency, disableFallback, asset, _yield$getFeeForOrigi, originFee, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, destApi, destFeeRes, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, nextChain, hopApi, hopResult, failingRecord, hopIsDestination, destFallback;
|
|
3999
4060
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4000
4061
|
while (1) switch (_context.prev = _context.next) {
|
|
4001
4062
|
case 0:
|
|
@@ -4023,14 +4084,14 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4023
4084
|
originDryRunError = _yield$getFeeForOrigi.dryRunError;
|
|
4024
4085
|
initialForwardedXcm = _yield$getFeeForOrigi.forwardedXcms;
|
|
4025
4086
|
initialDestParaId = _yield$getFeeForOrigi.destParaId;
|
|
4026
|
-
|
|
4087
|
+
api.setDisconnectAllowed(true);
|
|
4088
|
+
_context.next = 15;
|
|
4089
|
+
return api.disconnect();
|
|
4090
|
+
case 15:
|
|
4091
|
+
if (!(originDryRunError || originFeeType === 'paymentInfo')) {
|
|
4027
4092
|
_context.next = 30;
|
|
4028
4093
|
break;
|
|
4029
4094
|
}
|
|
4030
|
-
api.setDisconnectAllowed(true);
|
|
4031
|
-
_context.next = 16;
|
|
4032
|
-
return api.disconnect();
|
|
4033
|
-
case 16:
|
|
4034
4095
|
destApi = api.clone();
|
|
4035
4096
|
_context.prev = 17;
|
|
4036
4097
|
_context.next = 20;
|
|
@@ -4041,6 +4102,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4041
4102
|
return getFeeForDestNode({
|
|
4042
4103
|
api: destApi,
|
|
4043
4104
|
forwardedXcms: undefined,
|
|
4105
|
+
// force paymentInfo
|
|
4044
4106
|
origin: origin,
|
|
4045
4107
|
destination: destination,
|
|
4046
4108
|
currency: currency,
|
|
@@ -4049,7 +4111,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4049
4111
|
disableFallback: disableFallback
|
|
4050
4112
|
});
|
|
4051
4113
|
case 23:
|
|
4052
|
-
|
|
4114
|
+
destFeeRes = _context.sent;
|
|
4053
4115
|
return _context.abrupt("return", {
|
|
4054
4116
|
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
4055
4117
|
fee: originFee
|
|
@@ -4060,10 +4122,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4060
4122
|
}, originDryRunError && {
|
|
4061
4123
|
dryRunError: originDryRunError
|
|
4062
4124
|
}),
|
|
4063
|
-
destination: _objectSpread2(_objectSpread2(_objectSpread2({},
|
|
4064
|
-
fee:
|
|
4065
|
-
}),
|
|
4066
|
-
feeType:
|
|
4125
|
+
destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee && {
|
|
4126
|
+
fee: destFeeRes.fee
|
|
4127
|
+
}), destFeeRes.feeType && {
|
|
4128
|
+
feeType: destFeeRes.feeType
|
|
4067
4129
|
}), {}, {
|
|
4068
4130
|
currency: getNativeAssetSymbol(destination)
|
|
4069
4131
|
})
|
|
@@ -4076,83 +4138,30 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4076
4138
|
case 29:
|
|
4077
4139
|
return _context.finish(25);
|
|
4078
4140
|
case 30:
|
|
4079
|
-
api.setDisconnectAllowed(true);
|
|
4080
|
-
_context.next = 33;
|
|
4081
|
-
return api.disconnect();
|
|
4082
|
-
case 33:
|
|
4083
|
-
if (!originDryRunError) {
|
|
4084
|
-
_context.next = 48;
|
|
4085
|
-
break;
|
|
4086
|
-
}
|
|
4087
|
-
_destApi = api.clone();
|
|
4088
|
-
_context.prev = 35;
|
|
4089
|
-
_context.next = 38;
|
|
4090
|
-
return _destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4091
|
-
case 38:
|
|
4092
|
-
_destApi.setDisconnectAllowed(false);
|
|
4093
|
-
_context.next = 41;
|
|
4094
|
-
return getFeeForDestNode({
|
|
4095
|
-
api: _destApi,
|
|
4096
|
-
forwardedXcms: undefined,
|
|
4097
|
-
// force paymentInfo
|
|
4098
|
-
origin: origin,
|
|
4099
|
-
destination: destination,
|
|
4100
|
-
currency: currency,
|
|
4101
|
-
address: address,
|
|
4102
|
-
senderAddress: senderAddress,
|
|
4103
|
-
disableFallback: disableFallback
|
|
4104
|
-
});
|
|
4105
|
-
case 41:
|
|
4106
|
-
destFeeRes = _context.sent;
|
|
4107
|
-
return _context.abrupt("return", {
|
|
4108
|
-
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
4109
|
-
fee: originFee
|
|
4110
|
-
}), originFeeType && {
|
|
4111
|
-
feeType: originFeeType
|
|
4112
|
-
}), {}, {
|
|
4113
|
-
currency: getNativeAssetSymbol(origin),
|
|
4114
|
-
dryRunError: originDryRunError
|
|
4115
|
-
}),
|
|
4116
|
-
destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFeeRes.fee && {
|
|
4117
|
-
fee: destFeeRes.fee
|
|
4118
|
-
}), destFeeRes.feeType && {
|
|
4119
|
-
feeType: destFeeRes.feeType
|
|
4120
|
-
}), {}, {
|
|
4121
|
-
currency: getNativeAssetSymbol(destination)
|
|
4122
|
-
})
|
|
4123
|
-
});
|
|
4124
|
-
case 43:
|
|
4125
|
-
_context.prev = 43;
|
|
4126
|
-
_destApi.setDisconnectAllowed(true);
|
|
4127
|
-
_context.next = 47;
|
|
4128
|
-
return _destApi.disconnect();
|
|
4129
|
-
case 47:
|
|
4130
|
-
return _context.finish(43);
|
|
4131
|
-
case 48:
|
|
4132
4141
|
currentOrigin = origin;
|
|
4133
4142
|
forwardedXcms = initialForwardedXcm;
|
|
4134
4143
|
nextParaId = initialDestParaId;
|
|
4135
4144
|
intermediateFees = {};
|
|
4136
4145
|
destinationFee = 0n;
|
|
4137
4146
|
destinationFeeType = 'paymentInfo';
|
|
4138
|
-
case
|
|
4147
|
+
case 36:
|
|
4139
4148
|
if (!(Array.isArray(forwardedXcms) && forwardedXcms.length > 0 && forwardedXcms[1].length > 0 && ('disconnect' in api.getApi() ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
|
|
4140
|
-
_context.next =
|
|
4149
|
+
_context.next = 68;
|
|
4141
4150
|
break;
|
|
4142
4151
|
}
|
|
4143
4152
|
nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
|
|
4144
4153
|
if (!(nextChain === null)) {
|
|
4145
|
-
_context.next =
|
|
4154
|
+
_context.next = 40;
|
|
4146
4155
|
break;
|
|
4147
4156
|
}
|
|
4148
4157
|
throw new Error("Unable to find TNode for paraId ".concat(nextParaId));
|
|
4149
|
-
case
|
|
4158
|
+
case 40:
|
|
4150
4159
|
hopApi = api.clone();
|
|
4151
|
-
_context.prev =
|
|
4152
|
-
_context.next =
|
|
4160
|
+
_context.prev = 41;
|
|
4161
|
+
_context.next = 44;
|
|
4153
4162
|
return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4154
|
-
case
|
|
4155
|
-
_context.next =
|
|
4163
|
+
case 44:
|
|
4164
|
+
_context.next = 46;
|
|
4156
4165
|
return getFeeForDestNode({
|
|
4157
4166
|
api: hopApi,
|
|
4158
4167
|
forwardedXcms: forwardedXcms,
|
|
@@ -4163,10 +4172,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4163
4172
|
senderAddress: senderAddress,
|
|
4164
4173
|
disableFallback: disableFallback
|
|
4165
4174
|
});
|
|
4166
|
-
case
|
|
4175
|
+
case 46:
|
|
4167
4176
|
hopResult = _context.sent;
|
|
4168
4177
|
if (!hopResult.dryRunError) {
|
|
4169
|
-
_context.next =
|
|
4178
|
+
_context.next = 58;
|
|
4170
4179
|
break;
|
|
4171
4180
|
}
|
|
4172
4181
|
failingRecord = {
|
|
@@ -4187,10 +4196,10 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4187
4196
|
}
|
|
4188
4197
|
// We failed before the true destination, use fallback via paymentInfo.
|
|
4189
4198
|
if (hopIsDestination) {
|
|
4190
|
-
_context.next =
|
|
4199
|
+
_context.next = 57;
|
|
4191
4200
|
break;
|
|
4192
4201
|
}
|
|
4193
|
-
_context.next =
|
|
4202
|
+
_context.next = 54;
|
|
4194
4203
|
return getFeeForDestNode({
|
|
4195
4204
|
api: hopApi,
|
|
4196
4205
|
forwardedXcms: undefined,
|
|
@@ -4201,13 +4210,13 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4201
4210
|
senderAddress: senderAddress,
|
|
4202
4211
|
disableFallback: disableFallback
|
|
4203
4212
|
});
|
|
4204
|
-
case
|
|
4213
|
+
case 54:
|
|
4205
4214
|
destFallback = _context.sent;
|
|
4206
4215
|
destinationFee = destFallback.fee;
|
|
4207
4216
|
destinationFeeType = destFallback.feeType;
|
|
4208
|
-
case
|
|
4209
|
-
return _context.abrupt("break",
|
|
4210
|
-
case
|
|
4217
|
+
case 57:
|
|
4218
|
+
return _context.abrupt("break", 68);
|
|
4219
|
+
case 58:
|
|
4211
4220
|
if (nextChain === destination || isRelayChain(nextChain) && !isRelayChain(destination)) {
|
|
4212
4221
|
destinationFee = hopResult.fee;
|
|
4213
4222
|
destinationFeeType = hopResult.feeType;
|
|
@@ -4227,16 +4236,16 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4227
4236
|
forwardedXcms = hopResult.forwardedXcms;
|
|
4228
4237
|
nextParaId = hopResult.destParaId;
|
|
4229
4238
|
currentOrigin = nextChain;
|
|
4230
|
-
case
|
|
4231
|
-
_context.prev =
|
|
4232
|
-
_context.next =
|
|
4239
|
+
case 62:
|
|
4240
|
+
_context.prev = 62;
|
|
4241
|
+
_context.next = 65;
|
|
4233
4242
|
return hopApi.disconnect();
|
|
4234
|
-
case
|
|
4235
|
-
return _context.finish(
|
|
4236
|
-
case
|
|
4237
|
-
_context.next =
|
|
4243
|
+
case 65:
|
|
4244
|
+
return _context.finish(62);
|
|
4245
|
+
case 66:
|
|
4246
|
+
_context.next = 36;
|
|
4238
4247
|
break;
|
|
4239
|
-
case
|
|
4248
|
+
case 68:
|
|
4240
4249
|
return _context.abrupt("return", _objectSpread2(_objectSpread2({
|
|
4241
4250
|
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
4242
4251
|
fee: originFee
|
|
@@ -4258,11 +4267,11 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4258
4267
|
dryRunError: destinationDryRunError
|
|
4259
4268
|
})
|
|
4260
4269
|
}));
|
|
4261
|
-
case
|
|
4270
|
+
case 69:
|
|
4262
4271
|
case "end":
|
|
4263
4272
|
return _context.stop();
|
|
4264
4273
|
}
|
|
4265
|
-
}, _callee, null, [[17,, 25, 30], [
|
|
4274
|
+
}, _callee, null, [[17,, 25, 30], [41,, 62, 66]]);
|
|
4266
4275
|
}));
|
|
4267
4276
|
return function getXcmFee(_x) {
|
|
4268
4277
|
return _ref2.apply(this, arguments);
|
|
@@ -4430,70 +4439,17 @@ var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, cu
|
|
|
4430
4439
|
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
4431
4440
|
};
|
|
4432
4441
|
|
|
4433
|
-
var validateCurrency = function validateCurrency(currency, feeAsset) {
|
|
4434
|
-
if ('multiasset' in currency) {
|
|
4435
|
-
if (currency.multiasset.length === 0) {
|
|
4436
|
-
throw new InvalidCurrencyError('Overridden multi assets cannot be empty');
|
|
4437
|
-
}
|
|
4438
|
-
if (currency.multiasset.length === 1) {
|
|
4439
|
-
throw new InvalidCurrencyError('Please provide more than one multi asset');
|
|
4440
|
-
}
|
|
4441
|
-
if (currency.multiasset.length > 1 && !currency.multiasset.every(function (asset) {
|
|
4442
|
-
return isTMultiAsset(asset);
|
|
4443
|
-
}) && !feeAsset) {
|
|
4444
|
-
throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
|
|
4445
|
-
}
|
|
4446
|
-
}
|
|
4447
|
-
};
|
|
4448
|
-
var validateDestination = function validateDestination(origin, destination) {
|
|
4449
|
-
if (isRelayChain(origin) && !isTMultiLocation(destination) && isRelayChain(destination) && origin !== destination) {
|
|
4450
|
-
throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
|
|
4451
|
-
}
|
|
4452
|
-
if (destination === 'Ethereum' && origin !== 'AssetHubPolkadot' && origin !== 'Hydration' && origin !== 'BifrostPolkadot' && origin !== 'Moonbeam') {
|
|
4453
|
-
throw new IncompatibleNodesError('Transfers to Ethereum are only supported from AssetHubPolkadot and Hydration.');
|
|
4454
|
-
}
|
|
4455
|
-
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
4456
|
-
var isBridge = isBridgeTransfer(origin, destination);
|
|
4457
|
-
var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
|
|
4458
|
-
if (!isRelayDestination && !isMultiLocationDestination) {
|
|
4459
|
-
var originRelayChainSymbol = getRelayChainSymbol(origin);
|
|
4460
|
-
var destinationRelayChainSymbol = getRelayChainSymbol(destination);
|
|
4461
|
-
if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
|
|
4462
|
-
throw new IncompatibleNodesError();
|
|
4463
|
-
}
|
|
4464
|
-
}
|
|
4465
|
-
};
|
|
4466
|
-
var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
|
|
4467
|
-
if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
|
|
4468
|
-
throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
|
|
4469
|
-
}
|
|
4470
|
-
if (!assetCheckEnabled && 'id' in currency) {
|
|
4471
|
-
throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
|
|
4472
|
-
}
|
|
4473
|
-
};
|
|
4474
4442
|
var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
|
|
4475
4443
|
var origin = _ref.from,
|
|
4476
4444
|
destination = _ref.to,
|
|
4477
4445
|
currency = _ref.currency;
|
|
4478
|
-
var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
|
|
4479
|
-
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
4480
4446
|
var isDestAssetHub = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
|
|
4481
|
-
var
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
var nativeAssets = getNativeAssets(destination);
|
|
4485
|
-
if (origin === 'Hydration') {
|
|
4486
|
-
nativeAssets = nativeAssets.filter(function (nativeAsset) {
|
|
4487
|
-
return nativeAsset.symbol !== 'DOT';
|
|
4488
|
-
});
|
|
4489
|
-
}
|
|
4490
|
-
if ('symbol' in currency && nativeAssets.some(function (nativeAsset) {
|
|
4491
|
-
var _asset$symbol;
|
|
4492
|
-
return nativeAsset.symbol.toLowerCase() === (asset === null || asset === void 0 || (_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toLowerCase());
|
|
4493
|
-
})) {
|
|
4494
|
-
throw new InvalidCurrencyError("".concat(JSON.stringify(asset === null || asset === void 0 ? void 0 : asset.symbol), " is not supported for transfers to ").concat(destination, "."));
|
|
4495
|
-
}
|
|
4447
|
+
var allowedChainsToAh = ['BifrostPolkadot', 'BifrostKusama', 'Hydration', 'Moonbeam', 'Ajuna', 'Polimec'];
|
|
4448
|
+
if (!isRelayChain(origin) && !isBridge && isDestAssetHub && !allowedChainsToAh.includes(origin) && (asset === null || asset === void 0 ? void 0 : asset.symbol) === 'DOT') {
|
|
4449
|
+
throw new TransferToAhNotSupported("Node ".concat(origin, " does not support DOT transfer to AssetHub"));
|
|
4496
4450
|
}
|
|
4451
|
+
var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
|
|
4452
|
+
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
4497
4453
|
if (!isBridge && !isRelayDestination && !isMultiLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !hasSupportForAsset(destination, asset.symbol)) {
|
|
4498
4454
|
throw new InvalidCurrencyError("Destination node ".concat(destination, " does not support currency ").concat(JSON.stringify(currency), "."));
|
|
4499
4455
|
}
|
|
@@ -4573,6 +4529,49 @@ var validateDestinationAddress = function validateDestinationAddress(address, de
|
|
|
4573
4529
|
}
|
|
4574
4530
|
};
|
|
4575
4531
|
|
|
4532
|
+
var validateCurrency = function validateCurrency(currency, feeAsset) {
|
|
4533
|
+
if ('multiasset' in currency) {
|
|
4534
|
+
if (currency.multiasset.length === 0) {
|
|
4535
|
+
throw new InvalidCurrencyError('Overridden multi assets cannot be empty');
|
|
4536
|
+
}
|
|
4537
|
+
if (currency.multiasset.length === 1) {
|
|
4538
|
+
throw new InvalidCurrencyError('Please provide more than one multi asset');
|
|
4539
|
+
}
|
|
4540
|
+
if (currency.multiasset.length > 1 && !currency.multiasset.every(function (asset) {
|
|
4541
|
+
return isTMultiAsset(asset);
|
|
4542
|
+
}) && !feeAsset) {
|
|
4543
|
+
throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
|
|
4544
|
+
}
|
|
4545
|
+
}
|
|
4546
|
+
};
|
|
4547
|
+
var validateDestination = function validateDestination(origin, destination) {
|
|
4548
|
+
if (isRelayChain(origin) && !isTMultiLocation(destination) && isRelayChain(destination) && origin !== destination) {
|
|
4549
|
+
throw new IncompatibleNodesError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
|
|
4550
|
+
}
|
|
4551
|
+
var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam'];
|
|
4552
|
+
if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
|
|
4553
|
+
throw new IncompatibleNodesError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
|
|
4554
|
+
}
|
|
4555
|
+
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
4556
|
+
var isBridge = isBridgeTransfer(origin, destination);
|
|
4557
|
+
var isRelayDestination = !isTMultiLocation(destination) && isRelayChain(destination);
|
|
4558
|
+
if (!isRelayDestination && !isMultiLocationDestination) {
|
|
4559
|
+
var originRelayChainSymbol = getRelayChainSymbol(origin);
|
|
4560
|
+
var destinationRelayChainSymbol = getRelayChainSymbol(destination);
|
|
4561
|
+
if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
|
|
4562
|
+
throw new IncompatibleNodesError();
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4565
|
+
};
|
|
4566
|
+
var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
|
|
4567
|
+
if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
|
|
4568
|
+
throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
|
|
4569
|
+
}
|
|
4570
|
+
if (!assetCheckEnabled && 'id' in currency) {
|
|
4571
|
+
throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
|
|
4572
|
+
}
|
|
4573
|
+
};
|
|
4574
|
+
|
|
4576
4575
|
var send = /*#__PURE__*/function () {
|
|
4577
4576
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
4578
4577
|
var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, isLocalTransfer, overriddenAsset, resolvedAsset, originNode;
|
|
@@ -9670,4 +9669,4 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
|
|
|
9670
9669
|
};
|
|
9671
9670
|
}();
|
|
9672
9671
|
|
|
9673
|
-
export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, Version, XTokensError, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, deriveAccountId, determineRelayChain, dryRun, dryRunOrigin, encodeSs58, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getFees, getMaxForeignTransferableAmount, getMaxForeignTransferableAmountInternal, getMaxNativeTransferableAmount, getMaxNativeTransferableAmountInternal, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, reverseTransformMultiLocation, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
|
|
9672
|
+
export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleNodesError, InvalidAddressError, InvalidParameterError, NoXCMSupportImplementedError, NodeNotSupportedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, Version, XTokensError, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createApiInstanceForNode, createBeneficiaryMultiLocation, createVersionedBeneficiary, createX1Payload, deriveAccountId, determineRelayChain, dryRun, dryRunOrigin, encodeSs58, generateAddressMultiLocationV4, getAssetBalance, getAssetBalanceInternal, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getFeeForOriginNode, getFees, getMaxForeignTransferableAmount, getMaxForeignTransferableAmountInternal, getMaxNativeTransferableAmount, getMaxNativeTransferableAmountInternal, getNode, getNodeConfig, getNodeProviders, getOriginFeeDetails, getOriginFeeDetailsInternal, getParaEthTransferFees, getParaId, getTNode, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, isEthersContract, isEthersSigner, resolveModuleError, resolveParaId, reverseTransformMultiLocation, send, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, transformMultiLocation, validateAddress, verifyEdOnDestination };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paraspell/sdk-core",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "SDK core for ParaSpell XCM/XCMP tool for developers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@scure/base": "^1.2.5",
|
|
28
28
|
"ethers": "^6.13.7",
|
|
29
29
|
"viem": "^2.28.1",
|
|
30
|
-
"@paraspell/
|
|
31
|
-
"@paraspell/sdk-common": "9.
|
|
32
|
-
"@paraspell/
|
|
30
|
+
"@paraspell/assets": "9.2.0",
|
|
31
|
+
"@paraspell/sdk-common": "9.2.0",
|
|
32
|
+
"@paraspell/pallets": "9.2.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@babel/plugin-syntax-import-attributes": "^7.27.1",
|