@paraspell/sdk-core 10.10.4 → 10.10.6
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 +788 -691
- package/dist/index.d.ts +85 -13
- package/dist/index.mjs +788 -693
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -3302,7 +3302,7 @@ var createExecuteExchangeXcm = function createExecuteExchangeXcm(input, origin,
|
|
|
3302
3302
|
version: version
|
|
3303
3303
|
});
|
|
3304
3304
|
assertHasLocation(asset);
|
|
3305
|
-
var transformedMultiLocation = localizeLocation(
|
|
3305
|
+
var transformedMultiLocation = localizeLocation(origin, asset.multiLocation);
|
|
3306
3306
|
var call = {
|
|
3307
3307
|
module: 'PolkadotXcm',
|
|
3308
3308
|
method: 'execute',
|
|
@@ -3958,6 +3958,324 @@ var getOriginFeeDetails = /*#__PURE__*/function () {
|
|
|
3958
3958
|
};
|
|
3959
3959
|
}();
|
|
3960
3960
|
|
|
3961
|
+
var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
|
|
3962
|
+
var asset = assets.findAsset(origin, feeAsset, !sdkCommon.isTMultiLocation(destination) ? destination : null);
|
|
3963
|
+
var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(assets.isTMultiAsset);
|
|
3964
|
+
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
3965
|
+
throwUnsupportedCurrency(feeAsset, origin);
|
|
3966
|
+
}
|
|
3967
|
+
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
3968
|
+
};
|
|
3969
|
+
|
|
3970
|
+
var isAssetHub = function isAssetHub(chain) {
|
|
3971
|
+
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
3972
|
+
};
|
|
3973
|
+
var isBridgeHub = function isBridgeHub(chain) {
|
|
3974
|
+
return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
|
|
3975
|
+
};
|
|
3976
|
+
var isPeople = function isPeople(chain) {
|
|
3977
|
+
return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
|
|
3978
|
+
};
|
|
3979
|
+
var isSystemPara = function isSystemPara(chain) {
|
|
3980
|
+
return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
|
|
3981
|
+
};
|
|
3982
|
+
var mul = function mul(v, num) {
|
|
3983
|
+
var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
|
|
3984
|
+
return v * num / den;
|
|
3985
|
+
};
|
|
3986
|
+
var padFee = function padFee(raw, origin, dest, side) {
|
|
3987
|
+
var relayOrigin = sdkCommon.isRelayChain(origin);
|
|
3988
|
+
var relayDest = sdkCommon.isRelayChain(dest);
|
|
3989
|
+
var sysParaOrigin = isSystemPara(origin);
|
|
3990
|
+
var sysParaDest = isSystemPara(dest);
|
|
3991
|
+
var relayToPara = relayOrigin && !relayDest;
|
|
3992
|
+
var sysParaToPara = sysParaOrigin && !sysParaDest;
|
|
3993
|
+
var paraToPara = !relayOrigin && !sysParaOrigin;
|
|
3994
|
+
if (sysParaToPara) return raw * 40n;
|
|
3995
|
+
if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
|
|
3996
|
+
if (paraToPara && side == 'origin' && origin === 'Mythos' && dest !== 'Ethereum') {
|
|
3997
|
+
return 150000000000000000n;
|
|
3998
|
+
}
|
|
3999
|
+
if (paraToPara) return mul(raw, 130n, 100n);
|
|
4000
|
+
// apply default 30% padding
|
|
4001
|
+
return mul(raw, 130n, 100n);
|
|
4002
|
+
};
|
|
4003
|
+
var padFeeBy = function padFeeBy(amount, percent) {
|
|
4004
|
+
return mul(amount, BigInt(100 + percent), 100n);
|
|
4005
|
+
};
|
|
4006
|
+
|
|
4007
|
+
var determineAddress = function determineAddress(chain, address, senderAddress) {
|
|
4008
|
+
if (assets.isNodeEvm(chain)) {
|
|
4009
|
+
return viem.isAddress(address) ? address : senderAddress;
|
|
4010
|
+
}
|
|
4011
|
+
return viem.isAddress(address) ? senderAddress : address;
|
|
4012
|
+
};
|
|
4013
|
+
var getReverseTxFee = /*#__PURE__*/function () {
|
|
4014
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
|
|
4015
|
+
var api, origin, destination, senderAddress, address, currency, toAddress, fromAddress, tx, rawFee;
|
|
4016
|
+
return _regenerator().w(function (_context) {
|
|
4017
|
+
while (1) switch (_context.n) {
|
|
4018
|
+
case 0:
|
|
4019
|
+
api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
|
|
4020
|
+
toAddress = determineAddress(origin, address, senderAddress);
|
|
4021
|
+
fromAddress = determineAddress(destination, address, senderAddress);
|
|
4022
|
+
_context.n = 1;
|
|
4023
|
+
return Builder(api).from(destination).to(origin).address(toAddress).senderAddress(fromAddress).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
|
|
4024
|
+
amount: currency.amount
|
|
4025
|
+
})).build();
|
|
4026
|
+
case 1:
|
|
4027
|
+
tx = _context.v;
|
|
4028
|
+
_context.n = 2;
|
|
4029
|
+
return api.calculateTransactionFee(tx, fromAddress);
|
|
4030
|
+
case 2:
|
|
4031
|
+
rawFee = _context.v;
|
|
4032
|
+
return _context.a(2, padFee(rawFee, origin, destination, 'destination'));
|
|
4033
|
+
}
|
|
4034
|
+
}, _callee);
|
|
4035
|
+
}));
|
|
4036
|
+
return function getReverseTxFee(_x, _x2) {
|
|
4037
|
+
return _ref2.apply(this, arguments);
|
|
4038
|
+
};
|
|
4039
|
+
}();
|
|
4040
|
+
|
|
4041
|
+
var isSufficientOrigin = /*#__PURE__*/function () {
|
|
4042
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, origin, destination, senderAddress, feeNative, currency, asset, feeAsset) {
|
|
4043
|
+
var edNative, balanceNative, isNativeAssetToOrigin, isNativeAssetToDest, isSufficientNative, balanceAsset, edAsset, isSufficientAsset;
|
|
4044
|
+
return _regenerator().w(function (_context) {
|
|
4045
|
+
while (1) switch (_context.n) {
|
|
4046
|
+
case 0:
|
|
4047
|
+
if (!feeAsset) {
|
|
4048
|
+
_context.n = 1;
|
|
4049
|
+
break;
|
|
4050
|
+
}
|
|
4051
|
+
return _context.a(2, undefined);
|
|
4052
|
+
case 1:
|
|
4053
|
+
edNative = assets.getExistentialDepositOrThrow(origin);
|
|
4054
|
+
_context.n = 2;
|
|
4055
|
+
return getBalanceNativeInternal({
|
|
4056
|
+
api: api,
|
|
4057
|
+
node: origin,
|
|
4058
|
+
address: senderAddress
|
|
4059
|
+
});
|
|
4060
|
+
case 2:
|
|
4061
|
+
balanceNative = _context.v;
|
|
4062
|
+
isNativeAssetToOrigin = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(origin));
|
|
4063
|
+
isNativeAssetToDest = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(destination));
|
|
4064
|
+
if (!(isNativeAssetToOrigin && isNativeAssetToDest)) {
|
|
4065
|
+
_context.n = 3;
|
|
4066
|
+
break;
|
|
4067
|
+
}
|
|
4068
|
+
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
4069
|
+
case 3:
|
|
4070
|
+
if (isNativeAssetToOrigin) {
|
|
4071
|
+
_context.n = 5;
|
|
4072
|
+
break;
|
|
4073
|
+
}
|
|
4074
|
+
isSufficientNative = balanceNative - edNative - feeNative > 0n;
|
|
4075
|
+
_context.n = 4;
|
|
4076
|
+
return getAssetBalance({
|
|
4077
|
+
api: api,
|
|
4078
|
+
node: origin,
|
|
4079
|
+
address: senderAddress,
|
|
4080
|
+
currency: currency
|
|
4081
|
+
});
|
|
4082
|
+
case 4:
|
|
4083
|
+
balanceAsset = _context.v;
|
|
4084
|
+
edAsset = assets.getExistentialDepositOrThrow(origin, currency);
|
|
4085
|
+
isSufficientAsset = balanceAsset - edAsset > 0n;
|
|
4086
|
+
return _context.a(2, isSufficientNative && isSufficientAsset);
|
|
4087
|
+
case 5:
|
|
4088
|
+
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
4089
|
+
}
|
|
4090
|
+
}, _callee);
|
|
4091
|
+
}));
|
|
4092
|
+
return function isSufficientOrigin(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) {
|
|
4093
|
+
return _ref.apply(this, arguments);
|
|
4094
|
+
};
|
|
4095
|
+
}();
|
|
4096
|
+
var isSufficientDestination = /*#__PURE__*/function () {
|
|
4097
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, destination, address, amount, asset, feeNative) {
|
|
4098
|
+
var isNativeAsset, existentialDeposit, nativeBalance;
|
|
4099
|
+
return _regenerator().w(function (_context2) {
|
|
4100
|
+
while (1) switch (_context2.n) {
|
|
4101
|
+
case 0:
|
|
4102
|
+
isNativeAsset = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(destination));
|
|
4103
|
+
if (isNativeAsset) {
|
|
4104
|
+
_context2.n = 1;
|
|
4105
|
+
break;
|
|
4106
|
+
}
|
|
4107
|
+
return _context2.a(2, undefined);
|
|
4108
|
+
case 1:
|
|
4109
|
+
existentialDeposit = assets.getExistentialDepositOrThrow(destination);
|
|
4110
|
+
_context2.n = 2;
|
|
4111
|
+
return getBalanceNativeInternal({
|
|
4112
|
+
api: api,
|
|
4113
|
+
node: destination,
|
|
4114
|
+
address: address
|
|
4115
|
+
});
|
|
4116
|
+
case 2:
|
|
4117
|
+
nativeBalance = _context2.v;
|
|
4118
|
+
return _context2.a(2, nativeBalance + amount - existentialDeposit - feeNative > 0n);
|
|
4119
|
+
}
|
|
4120
|
+
}, _callee2);
|
|
4121
|
+
}));
|
|
4122
|
+
return function isSufficientDestination(_x9, _x0, _x1, _x10, _x11, _x12) {
|
|
4123
|
+
return _ref2.apply(this, arguments);
|
|
4124
|
+
};
|
|
4125
|
+
}();
|
|
4126
|
+
|
|
4127
|
+
var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
4128
|
+
if (sdkCommon.isRelayChain(origin)) return DOT_MULTILOCATION;
|
|
4129
|
+
return {
|
|
4130
|
+
parents: sdkCommon.isRelayChain(destination) ? sdkCommon.Parents.ZERO : sdkCommon.Parents.ONE,
|
|
4131
|
+
interior: {
|
|
4132
|
+
X1: [{
|
|
4133
|
+
Parachain: getParaId(origin)
|
|
4134
|
+
}]
|
|
4135
|
+
}
|
|
4136
|
+
};
|
|
4137
|
+
};
|
|
4138
|
+
var getDestXcmFee = /*#__PURE__*/function () {
|
|
4139
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
4140
|
+
var api, origin, hopNode, destination, currency, forwardedXcms, asset, address, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, _fee, sufficient, dryRunResult, _fee2, _sufficient, fee, newForwardedXcms, destParaId;
|
|
4141
|
+
return _regenerator().w(function (_context2) {
|
|
4142
|
+
while (1) switch (_context2.n) {
|
|
4143
|
+
case 0:
|
|
4144
|
+
api = options.api, origin = options.origin, hopNode = options.prevNode, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, asset = options.asset, address = options.address, feeAsset = options.feeAsset, originFee = options.originFee, disableFallback = options.disableFallback;
|
|
4145
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4146
|
+
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
4147
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
4148
|
+
var originAsset, _t;
|
|
4149
|
+
return _regenerator().w(function (_context) {
|
|
4150
|
+
while (1) switch (_context.n) {
|
|
4151
|
+
case 0:
|
|
4152
|
+
if (!(destination === 'Ethereum')) {
|
|
4153
|
+
_context.n = 1;
|
|
4154
|
+
break;
|
|
4155
|
+
}
|
|
4156
|
+
return _context.a(2, 0n);
|
|
4157
|
+
case 1:
|
|
4158
|
+
originAsset = assets.findAssetForNodeOrThrow(origin, currency, destination);
|
|
4159
|
+
if (!originAsset.multiLocation) {
|
|
4160
|
+
_context.n = 7;
|
|
4161
|
+
break;
|
|
4162
|
+
}
|
|
4163
|
+
_context.p = 2;
|
|
4164
|
+
_context.n = 3;
|
|
4165
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4166
|
+
destination: destination
|
|
4167
|
+
}), {
|
|
4168
|
+
multilocation: originAsset.multiLocation
|
|
4169
|
+
});
|
|
4170
|
+
case 3:
|
|
4171
|
+
return _context.a(2, _context.v);
|
|
4172
|
+
case 4:
|
|
4173
|
+
_context.p = 4;
|
|
4174
|
+
_t = _context.v;
|
|
4175
|
+
if (!(_t instanceof assets.InvalidCurrencyError)) {
|
|
4176
|
+
_context.n = 6;
|
|
4177
|
+
break;
|
|
4178
|
+
}
|
|
4179
|
+
_context.n = 5;
|
|
4180
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4181
|
+
destination: destination
|
|
4182
|
+
}), {
|
|
4183
|
+
symbol: originAsset.symbol
|
|
4184
|
+
});
|
|
4185
|
+
case 5:
|
|
4186
|
+
return _context.a(2, _context.v);
|
|
4187
|
+
case 6:
|
|
4188
|
+
throw _t;
|
|
4189
|
+
case 7:
|
|
4190
|
+
_context.n = 8;
|
|
4191
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4192
|
+
destination: destination
|
|
4193
|
+
}), {
|
|
4194
|
+
symbol: originAsset.symbol
|
|
4195
|
+
});
|
|
4196
|
+
case 8:
|
|
4197
|
+
return _context.a(2, _context.v);
|
|
4198
|
+
}
|
|
4199
|
+
}, _callee, null, [[2, 4]]);
|
|
4200
|
+
}));
|
|
4201
|
+
return function calcPaymentInfoFee() {
|
|
4202
|
+
return _ref2.apply(this, arguments);
|
|
4203
|
+
};
|
|
4204
|
+
}();
|
|
4205
|
+
if (!(!assets.hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
|
|
4206
|
+
_context2.n = 3;
|
|
4207
|
+
break;
|
|
4208
|
+
}
|
|
4209
|
+
_context2.n = 1;
|
|
4210
|
+
return calcPaymentInfoFee();
|
|
4211
|
+
case 1:
|
|
4212
|
+
_fee = _context2.v;
|
|
4213
|
+
_context2.n = 2;
|
|
4214
|
+
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee);
|
|
4215
|
+
case 2:
|
|
4216
|
+
sufficient = _context2.v;
|
|
4217
|
+
return _context2.a(2, {
|
|
4218
|
+
fee: _fee,
|
|
4219
|
+
feeType: 'paymentInfo',
|
|
4220
|
+
sufficient: sufficient
|
|
4221
|
+
});
|
|
4222
|
+
case 3:
|
|
4223
|
+
_context2.n = 4;
|
|
4224
|
+
return api.getDryRunXcm({
|
|
4225
|
+
originLocation: addXcmVersionHeader(createOriginLocation(hopNode, destination), sdkCommon.Version.V4),
|
|
4226
|
+
xcm: forwardedXcms[1][0],
|
|
4227
|
+
node: destination,
|
|
4228
|
+
origin: origin,
|
|
4229
|
+
asset: asset,
|
|
4230
|
+
originFee: originFee,
|
|
4231
|
+
feeAsset: resolvedFeeAsset,
|
|
4232
|
+
amount: BigInt(currency.amount) < 2n ? 2n : BigInt(currency.amount)
|
|
4233
|
+
});
|
|
4234
|
+
case 4:
|
|
4235
|
+
dryRunResult = _context2.v;
|
|
4236
|
+
if (dryRunResult.success) {
|
|
4237
|
+
_context2.n = 8;
|
|
4238
|
+
break;
|
|
4239
|
+
}
|
|
4240
|
+
if (!disableFallback) {
|
|
4241
|
+
_context2.n = 5;
|
|
4242
|
+
break;
|
|
4243
|
+
}
|
|
4244
|
+
return _context2.a(2, {
|
|
4245
|
+
dryRunError: dryRunResult.failureReason
|
|
4246
|
+
});
|
|
4247
|
+
case 5:
|
|
4248
|
+
_context2.n = 6;
|
|
4249
|
+
return calcPaymentInfoFee();
|
|
4250
|
+
case 6:
|
|
4251
|
+
_fee2 = _context2.v;
|
|
4252
|
+
_context2.n = 7;
|
|
4253
|
+
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee2);
|
|
4254
|
+
case 7:
|
|
4255
|
+
_sufficient = _context2.v;
|
|
4256
|
+
return _context2.a(2, {
|
|
4257
|
+
fee: _fee2,
|
|
4258
|
+
feeType: 'paymentInfo',
|
|
4259
|
+
dryRunError: dryRunResult.failureReason,
|
|
4260
|
+
sufficient: _sufficient
|
|
4261
|
+
});
|
|
4262
|
+
case 8:
|
|
4263
|
+
fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
4264
|
+
return _context2.a(2, {
|
|
4265
|
+
fee: fee,
|
|
4266
|
+
feeType: 'dryRun',
|
|
4267
|
+
sufficient: true,
|
|
4268
|
+
forwardedXcms: newForwardedXcms,
|
|
4269
|
+
destParaId: destParaId
|
|
4270
|
+
});
|
|
4271
|
+
}
|
|
4272
|
+
}, _callee2);
|
|
4273
|
+
}));
|
|
4274
|
+
return function getDestXcmFee(_x) {
|
|
4275
|
+
return _ref.apply(this, arguments);
|
|
4276
|
+
};
|
|
4277
|
+
}();
|
|
4278
|
+
|
|
3961
4279
|
var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
3962
4280
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ahApi) {
|
|
3963
4281
|
var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, finalBridgeFee, finalAssethubExecutionFee;
|
|
@@ -4525,339 +4843,162 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
|
|
|
4525
4843
|
return createTx('transferAssetsUsingTypeAndThenAddress', [
|
|
4526
4844
|
// This represents (1,X1(Parachain(1000)))
|
|
4527
4845
|
[1, ['0x00' + numberToHex32(getParaId('AssetHubPolkadot')).slice(2)]],
|
|
4528
|
-
// Assets including fee and the ERC20 asset, with fee be the first
|
|
4529
|
-
[[XCDOT, transferFee], [ethAsset.assetId, currency.amount.toString()]],
|
|
4530
|
-
// The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
|
|
4531
|
-
2,
|
|
4532
|
-
// index for the fee
|
|
4533
|
-
0,
|
|
4534
|
-
// The TransferType corresponding to fee asset
|
|
4535
|
-
2, customXcmOnDest]);
|
|
4536
|
-
case 14:
|
|
4537
|
-
tx = _context.v;
|
|
4538
|
-
return _context.a(2, tx);
|
|
4539
|
-
}
|
|
4540
|
-
}, _callee);
|
|
4541
|
-
}));
|
|
4542
|
-
return function transferMoonbeamToEth(_x) {
|
|
4543
|
-
return _ref2.apply(this, arguments);
|
|
4544
|
-
};
|
|
4545
|
-
}();
|
|
4546
|
-
|
|
4547
|
-
var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
|
|
4548
|
-
var asset = assets.findAsset(origin, feeAsset, !sdkCommon.isTMultiLocation(destination) ? destination : null);
|
|
4549
|
-
var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(assets.isTMultiAsset);
|
|
4550
|
-
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
4551
|
-
throwUnsupportedCurrency(feeAsset, origin);
|
|
4552
|
-
}
|
|
4553
|
-
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
4554
|
-
};
|
|
4555
|
-
|
|
4556
|
-
var isAssetHub = function isAssetHub(chain) {
|
|
4557
|
-
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
4558
|
-
};
|
|
4559
|
-
var isBridgeHub = function isBridgeHub(chain) {
|
|
4560
|
-
return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
|
|
4561
|
-
};
|
|
4562
|
-
var isPeople = function isPeople(chain) {
|
|
4563
|
-
return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
|
|
4564
|
-
};
|
|
4565
|
-
var isSystemPara = function isSystemPara(chain) {
|
|
4566
|
-
return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
|
|
4567
|
-
};
|
|
4568
|
-
var mul = function mul(v, num) {
|
|
4569
|
-
var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
|
|
4570
|
-
return v * num / den;
|
|
4571
|
-
};
|
|
4572
|
-
var padFee = function padFee(raw, origin, dest, side) {
|
|
4573
|
-
var relayOrigin = sdkCommon.isRelayChain(origin);
|
|
4574
|
-
var relayDest = sdkCommon.isRelayChain(dest);
|
|
4575
|
-
var sysParaOrigin = isSystemPara(origin);
|
|
4576
|
-
var sysParaDest = isSystemPara(dest);
|
|
4577
|
-
var relayToPara = relayOrigin && !relayDest;
|
|
4578
|
-
var sysParaToPara = sysParaOrigin && !sysParaDest;
|
|
4579
|
-
var paraToPara = !relayOrigin && !sysParaOrigin;
|
|
4580
|
-
if (sysParaToPara) return raw * 40n;
|
|
4581
|
-
if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
|
|
4582
|
-
if (paraToPara && side == 'origin' && origin === 'Mythos' && dest !== 'Ethereum') {
|
|
4583
|
-
return 150000000000000000n;
|
|
4584
|
-
}
|
|
4585
|
-
if (paraToPara) return mul(raw, 130n, 100n);
|
|
4586
|
-
// apply default 30% padding
|
|
4587
|
-
return mul(raw, 130n, 100n);
|
|
4588
|
-
};
|
|
4589
|
-
var padFeeBy = function padFeeBy(amount, percent) {
|
|
4590
|
-
return mul(amount, BigInt(100 + percent), 100n);
|
|
4591
|
-
};
|
|
4592
|
-
|
|
4593
|
-
var determineAddress = function determineAddress(chain, address, senderAddress) {
|
|
4594
|
-
if (assets.isNodeEvm(chain)) {
|
|
4595
|
-
return viem.isAddress(address) ? address : senderAddress;
|
|
4596
|
-
}
|
|
4597
|
-
return viem.isAddress(address) ? senderAddress : address;
|
|
4598
|
-
};
|
|
4599
|
-
var getReverseTxFee = /*#__PURE__*/function () {
|
|
4600
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
|
|
4601
|
-
var api, origin, destination, senderAddress, address, currency, toAddress, fromAddress, tx, rawFee;
|
|
4602
|
-
return _regenerator().w(function (_context) {
|
|
4603
|
-
while (1) switch (_context.n) {
|
|
4604
|
-
case 0:
|
|
4605
|
-
api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
|
|
4606
|
-
toAddress = determineAddress(origin, address, senderAddress);
|
|
4607
|
-
fromAddress = determineAddress(destination, address, senderAddress);
|
|
4608
|
-
_context.n = 1;
|
|
4609
|
-
return Builder(api).from(destination).to(origin).address(toAddress).senderAddress(fromAddress).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
|
|
4610
|
-
amount: currency.amount
|
|
4611
|
-
})).build();
|
|
4612
|
-
case 1:
|
|
4613
|
-
tx = _context.v;
|
|
4614
|
-
_context.n = 2;
|
|
4615
|
-
return api.calculateTransactionFee(tx, fromAddress);
|
|
4616
|
-
case 2:
|
|
4617
|
-
rawFee = _context.v;
|
|
4618
|
-
return _context.a(2, padFee(rawFee, origin, destination, 'destination'));
|
|
4619
|
-
}
|
|
4620
|
-
}, _callee);
|
|
4621
|
-
}));
|
|
4622
|
-
return function getReverseTxFee(_x, _x2) {
|
|
4623
|
-
return _ref2.apply(this, arguments);
|
|
4624
|
-
};
|
|
4625
|
-
}();
|
|
4626
|
-
|
|
4627
|
-
var isSufficientOrigin = /*#__PURE__*/function () {
|
|
4628
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, origin, destination, senderAddress, feeNative, currency, asset, feeAsset) {
|
|
4629
|
-
var edNative, balanceNative, isNativeAssetToOrigin, isNativeAssetToDest, isSufficientNative, balanceAsset, edAsset, isSufficientAsset;
|
|
4630
|
-
return _regenerator().w(function (_context) {
|
|
4631
|
-
while (1) switch (_context.n) {
|
|
4632
|
-
case 0:
|
|
4633
|
-
if (!feeAsset) {
|
|
4634
|
-
_context.n = 1;
|
|
4635
|
-
break;
|
|
4636
|
-
}
|
|
4637
|
-
return _context.a(2, undefined);
|
|
4638
|
-
case 1:
|
|
4639
|
-
edNative = assets.getExistentialDepositOrThrow(origin);
|
|
4640
|
-
_context.n = 2;
|
|
4641
|
-
return getBalanceNativeInternal({
|
|
4642
|
-
api: api,
|
|
4643
|
-
node: origin,
|
|
4644
|
-
address: senderAddress
|
|
4645
|
-
});
|
|
4646
|
-
case 2:
|
|
4647
|
-
balanceNative = _context.v;
|
|
4648
|
-
isNativeAssetToOrigin = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(origin));
|
|
4649
|
-
isNativeAssetToDest = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(destination));
|
|
4650
|
-
if (!(isNativeAssetToOrigin && isNativeAssetToDest)) {
|
|
4651
|
-
_context.n = 3;
|
|
4652
|
-
break;
|
|
4653
|
-
}
|
|
4654
|
-
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
4655
|
-
case 3:
|
|
4656
|
-
if (isNativeAssetToOrigin) {
|
|
4657
|
-
_context.n = 5;
|
|
4658
|
-
break;
|
|
4659
|
-
}
|
|
4660
|
-
isSufficientNative = balanceNative - edNative - feeNative > 0n;
|
|
4661
|
-
_context.n = 4;
|
|
4662
|
-
return getAssetBalance({
|
|
4663
|
-
api: api,
|
|
4664
|
-
node: origin,
|
|
4665
|
-
address: senderAddress,
|
|
4666
|
-
currency: currency
|
|
4667
|
-
});
|
|
4668
|
-
case 4:
|
|
4669
|
-
balanceAsset = _context.v;
|
|
4670
|
-
edAsset = assets.getExistentialDepositOrThrow(origin, currency);
|
|
4671
|
-
isSufficientAsset = balanceAsset - edAsset > 0n;
|
|
4672
|
-
return _context.a(2, isSufficientNative && isSufficientAsset);
|
|
4673
|
-
case 5:
|
|
4674
|
-
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
4675
|
-
}
|
|
4676
|
-
}, _callee);
|
|
4677
|
-
}));
|
|
4678
|
-
return function isSufficientOrigin(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) {
|
|
4679
|
-
return _ref.apply(this, arguments);
|
|
4680
|
-
};
|
|
4681
|
-
}();
|
|
4682
|
-
var isSufficientDestination = /*#__PURE__*/function () {
|
|
4683
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, destination, address, amount, asset, feeNative) {
|
|
4684
|
-
var isNativeAsset, existentialDeposit, nativeBalance;
|
|
4685
|
-
return _regenerator().w(function (_context2) {
|
|
4686
|
-
while (1) switch (_context2.n) {
|
|
4687
|
-
case 0:
|
|
4688
|
-
isNativeAsset = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(destination));
|
|
4689
|
-
if (isNativeAsset) {
|
|
4690
|
-
_context2.n = 1;
|
|
4691
|
-
break;
|
|
4692
|
-
}
|
|
4693
|
-
return _context2.a(2, undefined);
|
|
4694
|
-
case 1:
|
|
4695
|
-
existentialDeposit = assets.getExistentialDepositOrThrow(destination);
|
|
4696
|
-
_context2.n = 2;
|
|
4697
|
-
return getBalanceNativeInternal({
|
|
4698
|
-
api: api,
|
|
4699
|
-
node: destination,
|
|
4700
|
-
address: address
|
|
4701
|
-
});
|
|
4702
|
-
case 2:
|
|
4703
|
-
nativeBalance = _context2.v;
|
|
4704
|
-
return _context2.a(2, nativeBalance + amount - existentialDeposit - feeNative > 0n);
|
|
4846
|
+
// Assets including fee and the ERC20 asset, with fee be the first
|
|
4847
|
+
[[XCDOT, transferFee], [ethAsset.assetId, currency.amount.toString()]],
|
|
4848
|
+
// The TransferType corresponding to asset being sent, 2 represents `DestinationReserve`
|
|
4849
|
+
2,
|
|
4850
|
+
// index for the fee
|
|
4851
|
+
0,
|
|
4852
|
+
// The TransferType corresponding to fee asset
|
|
4853
|
+
2, customXcmOnDest]);
|
|
4854
|
+
case 14:
|
|
4855
|
+
tx = _context.v;
|
|
4856
|
+
return _context.a(2, tx);
|
|
4705
4857
|
}
|
|
4706
|
-
},
|
|
4858
|
+
}, _callee);
|
|
4707
4859
|
}));
|
|
4708
|
-
return function
|
|
4860
|
+
return function transferMoonbeamToEth(_x) {
|
|
4709
4861
|
return _ref2.apply(this, arguments);
|
|
4710
4862
|
};
|
|
4711
4863
|
}();
|
|
4712
4864
|
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
Parachain: getParaId(origin)
|
|
4720
|
-
}]
|
|
4721
|
-
}
|
|
4722
|
-
};
|
|
4723
|
-
};
|
|
4724
|
-
var getDestXcmFee = /*#__PURE__*/function () {
|
|
4725
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
4726
|
-
var api, origin, hopNode, destination, currency, forwardedXcms, asset, address, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, _fee, sufficient, dryRunResult, _fee2, _sufficient, fee, newForwardedXcms, destParaId;
|
|
4865
|
+
function traverseXcmHops(_x) {
|
|
4866
|
+
return _traverseXcmHops.apply(this, arguments);
|
|
4867
|
+
}
|
|
4868
|
+
function _traverseXcmHops() {
|
|
4869
|
+
_traverseXcmHops = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(config) {
|
|
4870
|
+
var api, origin, destination, currency, initialForwardedXcms, initialDestParaId, swapConfig, processHop, shouldContinue, extractNextHopData, assetHubNode, bridgeHubNode, currentOrigin, forwardedXcms, nextParaId, asset, currentAsset, hasPassedExchange, hops, intermediateResults, destinationResult, nextChain, hopApi, isDestination, isAssetHub, isBridgeHub, hopResult, _extractNextHopData, newXcms, destParaId;
|
|
4727
4871
|
return _regenerator().w(function (_context2) {
|
|
4728
4872
|
while (1) switch (_context2.n) {
|
|
4729
4873
|
case 0:
|
|
4730
|
-
api =
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
originAsset = assets.findAssetForNodeOrThrow(origin, currency, destination);
|
|
4745
|
-
if (!originAsset.multiLocation) {
|
|
4746
|
-
_context.n = 7;
|
|
4747
|
-
break;
|
|
4748
|
-
}
|
|
4749
|
-
_context.p = 2;
|
|
4750
|
-
_context.n = 3;
|
|
4751
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4752
|
-
destination: destination
|
|
4753
|
-
}), {
|
|
4754
|
-
multilocation: originAsset.multiLocation
|
|
4755
|
-
});
|
|
4756
|
-
case 3:
|
|
4757
|
-
return _context.a(2, _context.v);
|
|
4758
|
-
case 4:
|
|
4759
|
-
_context.p = 4;
|
|
4760
|
-
_t = _context.v;
|
|
4761
|
-
if (!(_t instanceof assets.InvalidCurrencyError)) {
|
|
4762
|
-
_context.n = 6;
|
|
4763
|
-
break;
|
|
4764
|
-
}
|
|
4765
|
-
_context.n = 5;
|
|
4766
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4767
|
-
destination: destination
|
|
4768
|
-
}), {
|
|
4769
|
-
symbol: originAsset.symbol
|
|
4770
|
-
});
|
|
4771
|
-
case 5:
|
|
4772
|
-
return _context.a(2, _context.v);
|
|
4773
|
-
case 6:
|
|
4774
|
-
throw _t;
|
|
4775
|
-
case 7:
|
|
4776
|
-
_context.n = 8;
|
|
4777
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4778
|
-
destination: destination
|
|
4779
|
-
}), {
|
|
4780
|
-
symbol: originAsset.symbol
|
|
4781
|
-
});
|
|
4782
|
-
case 8:
|
|
4783
|
-
return _context.a(2, _context.v);
|
|
4784
|
-
}
|
|
4785
|
-
}, _callee, null, [[2, 4]]);
|
|
4786
|
-
}));
|
|
4787
|
-
return function calcPaymentInfoFee() {
|
|
4788
|
-
return _ref2.apply(this, arguments);
|
|
4789
|
-
};
|
|
4790
|
-
}();
|
|
4791
|
-
if (!(!assets.hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
|
|
4792
|
-
_context2.n = 3;
|
|
4874
|
+
api = config.api, origin = config.origin, destination = config.destination, currency = config.currency, initialForwardedXcms = config.initialForwardedXcms, initialDestParaId = config.initialDestParaId, swapConfig = config.swapConfig, processHop = config.processHop, shouldContinue = config.shouldContinue, extractNextHopData = config.extractNextHopData;
|
|
4875
|
+
assetHubNode = "AssetHub".concat(getRelayChainOf(origin));
|
|
4876
|
+
bridgeHubNode = "BridgeHub".concat(getRelayChainOf(origin));
|
|
4877
|
+
currentOrigin = origin;
|
|
4878
|
+
forwardedXcms = initialForwardedXcms;
|
|
4879
|
+
nextParaId = initialDestParaId;
|
|
4880
|
+
asset = assets.findAssetForNodeOrThrow(origin, currency, destination);
|
|
4881
|
+
currentAsset = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain) ? assets.findAssetForNodeOrThrow(swapConfig.exchangeChain, swapConfig.currencyTo, null) : asset;
|
|
4882
|
+
hasPassedExchange = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain);
|
|
4883
|
+
hops = [];
|
|
4884
|
+
intermediateResults = {};
|
|
4885
|
+
case 1:
|
|
4886
|
+
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)) {
|
|
4887
|
+
_context2.n = 10;
|
|
4793
4888
|
break;
|
|
4794
4889
|
}
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4890
|
+
nextChain = getTNode(nextParaId, getRelayChainOf(origin).toLowerCase());
|
|
4891
|
+
if (nextChain) {
|
|
4892
|
+
_context2.n = 2;
|
|
4893
|
+
break;
|
|
4894
|
+
}
|
|
4895
|
+
throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
|
|
4801
4896
|
case 2:
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
fee: _fee,
|
|
4805
|
-
feeType: 'paymentInfo',
|
|
4806
|
-
sufficient: sufficient
|
|
4807
|
-
});
|
|
4808
|
-
case 3:
|
|
4897
|
+
hopApi = api.clone();
|
|
4898
|
+
_context2.p = 3;
|
|
4809
4899
|
_context2.n = 4;
|
|
4810
|
-
return
|
|
4811
|
-
originLocation: addXcmVersionHeader(createOriginLocation(hopNode, destination), sdkCommon.Version.V4),
|
|
4812
|
-
xcm: forwardedXcms[1][0],
|
|
4813
|
-
node: destination,
|
|
4814
|
-
origin: origin,
|
|
4815
|
-
asset: asset,
|
|
4816
|
-
originFee: originFee,
|
|
4817
|
-
feeAsset: resolvedFeeAsset,
|
|
4818
|
-
amount: BigInt(currency.amount) < 2n ? 2n : BigInt(currency.amount)
|
|
4819
|
-
});
|
|
4900
|
+
return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4820
4901
|
case 4:
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4902
|
+
isDestination = nextChain === destination || sdkCommon.isRelayChain(nextChain) && !sdkCommon.isRelayChain(destination);
|
|
4903
|
+
isAssetHub = nextChain === assetHubNode;
|
|
4904
|
+
isBridgeHub = nextChain === bridgeHubNode;
|
|
4905
|
+
_context2.n = 5;
|
|
4906
|
+
return processHop({
|
|
4907
|
+
api: hopApi,
|
|
4908
|
+
currentChain: nextChain,
|
|
4909
|
+
currentOrigin: currentOrigin,
|
|
4910
|
+
currentAsset: currentAsset,
|
|
4911
|
+
forwardedXcms: forwardedXcms,
|
|
4912
|
+
hasPassedExchange: hasPassedExchange,
|
|
4913
|
+
isDestination: isDestination,
|
|
4914
|
+
isAssetHub: isAssetHub,
|
|
4915
|
+
isBridgeHub: isBridgeHub
|
|
4916
|
+
});
|
|
4917
|
+
case 5:
|
|
4918
|
+
hopResult = _context2.v;
|
|
4919
|
+
if (!isDestination) {
|
|
4920
|
+
hops.push({
|
|
4921
|
+
chain: nextChain,
|
|
4922
|
+
result: hopResult
|
|
4923
|
+
});
|
|
4825
4924
|
}
|
|
4826
|
-
if (
|
|
4827
|
-
|
|
4925
|
+
if (isDestination) {
|
|
4926
|
+
destinationResult = hopResult;
|
|
4927
|
+
} else if (isAssetHub) {
|
|
4928
|
+
intermediateResults.assetHub = hopResult;
|
|
4929
|
+
} else if (isBridgeHub) {
|
|
4930
|
+
intermediateResults.bridgeHub = hopResult;
|
|
4931
|
+
}
|
|
4932
|
+
if (shouldContinue(hopResult)) {
|
|
4933
|
+
_context2.n = 6;
|
|
4828
4934
|
break;
|
|
4829
4935
|
}
|
|
4830
|
-
return _context2.a(
|
|
4831
|
-
dryRunError: dryRunResult.failureReason
|
|
4832
|
-
});
|
|
4833
|
-
case 5:
|
|
4834
|
-
_context2.n = 6;
|
|
4835
|
-
return calcPaymentInfoFee();
|
|
4936
|
+
return _context2.a(3, 10);
|
|
4836
4937
|
case 6:
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4938
|
+
// Update state for next iteration
|
|
4939
|
+
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
4940
|
+
hasPassedExchange = true;
|
|
4941
|
+
currentAsset = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
4942
|
+
}
|
|
4943
|
+
_extractNextHopData = extractNextHopData(hopResult), newXcms = _extractNextHopData.forwardedXcms, destParaId = _extractNextHopData.destParaId;
|
|
4944
|
+
forwardedXcms = newXcms;
|
|
4945
|
+
nextParaId = destParaId;
|
|
4946
|
+
currentOrigin = nextChain;
|
|
4840
4947
|
case 7:
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
feeType: 'paymentInfo',
|
|
4845
|
-
dryRunError: dryRunResult.failureReason,
|
|
4846
|
-
sufficient: _sufficient
|
|
4847
|
-
});
|
|
4948
|
+
_context2.p = 7;
|
|
4949
|
+
_context2.n = 8;
|
|
4950
|
+
return hopApi.disconnect();
|
|
4848
4951
|
case 8:
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
}
|
|
4952
|
+
return _context2.f(7);
|
|
4953
|
+
case 9:
|
|
4954
|
+
_context2.n = 1;
|
|
4955
|
+
break;
|
|
4956
|
+
case 10:
|
|
4957
|
+
return _context2.a(2, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
4958
|
+
hops: hops
|
|
4959
|
+
}, intermediateResults.assetHub && {
|
|
4960
|
+
assetHub: intermediateResults.assetHub
|
|
4961
|
+
}), intermediateResults.bridgeHub && {
|
|
4962
|
+
bridgeHub: intermediateResults.bridgeHub
|
|
4963
|
+
}), destinationResult && {
|
|
4964
|
+
destination: destinationResult
|
|
4965
|
+
}), {}, {
|
|
4966
|
+
lastProcessedChain: currentOrigin
|
|
4967
|
+
}));
|
|
4857
4968
|
}
|
|
4858
|
-
}, _callee2);
|
|
4969
|
+
}, _callee2, null, [[3,, 7, 9]]);
|
|
4859
4970
|
}));
|
|
4860
|
-
return
|
|
4971
|
+
return _traverseXcmHops.apply(this, arguments);
|
|
4972
|
+
}
|
|
4973
|
+
var addEthereumBridgeFees = /*#__PURE__*/function () {
|
|
4974
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, bridgeHubResult, destination, assetHubNode) {
|
|
4975
|
+
var ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee;
|
|
4976
|
+
return _regenerator().w(function (_context) {
|
|
4977
|
+
while (1) switch (_context.n) {
|
|
4978
|
+
case 0:
|
|
4979
|
+
if (!(!bridgeHubResult || !('fee' in bridgeHubResult) || destination !== 'Ethereum')) {
|
|
4980
|
+
_context.n = 1;
|
|
4981
|
+
break;
|
|
4982
|
+
}
|
|
4983
|
+
return _context.a(2, bridgeHubResult);
|
|
4984
|
+
case 1:
|
|
4985
|
+
ahApi = api.clone();
|
|
4986
|
+
_context.n = 2;
|
|
4987
|
+
return ahApi.init(assetHubNode, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4988
|
+
case 2:
|
|
4989
|
+
_context.n = 3;
|
|
4990
|
+
return getParaEthTransferFees(ahApi);
|
|
4991
|
+
case 3:
|
|
4992
|
+
_yield$getParaEthTran = _context.v;
|
|
4993
|
+
_yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 1);
|
|
4994
|
+
bridgeFee = _yield$getParaEthTran2[0];
|
|
4995
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, bridgeHubResult), {}, {
|
|
4996
|
+
fee: bridgeHubResult.fee + bridgeFee
|
|
4997
|
+
}));
|
|
4998
|
+
}
|
|
4999
|
+
}, _callee);
|
|
5000
|
+
}));
|
|
5001
|
+
return function addEthereumBridgeFees(_x2, _x3, _x4, _x5) {
|
|
4861
5002
|
return _ref.apply(this, arguments);
|
|
4862
5003
|
};
|
|
4863
5004
|
}();
|
|
@@ -4894,186 +5035,166 @@ var getFailureInfo$1 = function getFailureInfo(results, hops) {
|
|
|
4894
5035
|
return {};
|
|
4895
5036
|
};
|
|
4896
5037
|
var dryRunInternal = /*#__PURE__*/function () {
|
|
4897
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
4898
|
-
var
|
|
4899
|
-
var origin, destination, currency, api, tx, senderAddress, feeAsset, swapConfig, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId,
|
|
4900
|
-
return _regenerator().w(function (
|
|
4901
|
-
while (1) switch (
|
|
5038
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
5039
|
+
var _traversalResult$brid, _traversalResult$asse, _traversalResult$dest;
|
|
5040
|
+
var origin, destination, currency, api, tx, senderAddress, feeAsset, swapConfig, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, processHop, traversalResult, assetHubNode, bridgeHubNode, processedBridgeHub, bridgeHubHopIndex, originWithCurrency, assetHubWithCurrency, bridgeHubWithCurrency, destinationWithCurrency, _getFailureInfo, failureReason, failureChain, _t;
|
|
5041
|
+
return _regenerator().w(function (_context2) {
|
|
5042
|
+
while (1) switch (_context2.n) {
|
|
4902
5043
|
case 0:
|
|
4903
5044
|
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset, swapConfig = options.swapConfig;
|
|
4904
5045
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4905
5046
|
asset = assets.findAssetForNodeOrThrow(origin, currency, destination);
|
|
4906
|
-
|
|
5047
|
+
_context2.n = 1;
|
|
4907
5048
|
return api.getDryRunCall({
|
|
4908
5049
|
tx: tx,
|
|
4909
5050
|
node: origin,
|
|
4910
5051
|
address: senderAddress,
|
|
4911
|
-
feeAsset: resolvedFeeAsset
|
|
4912
|
-
});
|
|
4913
|
-
case 1:
|
|
4914
|
-
originDryRun =
|
|
4915
|
-
if (originDryRun.success) {
|
|
4916
|
-
|
|
4917
|
-
break;
|
|
4918
|
-
}
|
|
4919
|
-
return _context.a(2, {
|
|
4920
|
-
failureReason: originDryRun.failureReason,
|
|
4921
|
-
failureChain: 'origin',
|
|
4922
|
-
origin: originDryRun,
|
|
4923
|
-
hops: []
|
|
4924
|
-
});
|
|
4925
|
-
case 2:
|
|
4926
|
-
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
4927
|
-
assetHubNode = "AssetHub".concat(getRelayChainOf(origin));
|
|
4928
|
-
bridgeHubNode = "BridgeHub".concat(getRelayChainOf(origin));
|
|
4929
|
-
currentAsset = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain) ? assets.findAssetForNodeOrThrow(swapConfig.exchangeChain, swapConfig.currencyTo, null) : asset;
|
|
4930
|
-
hasPassedExchange = origin === (swapConfig === null || swapConfig === void 0 ? void 0 : swapConfig.exchangeChain);
|
|
4931
|
-
currentOrigin = origin;
|
|
4932
|
-
forwardedXcms = initialForwardedXcms;
|
|
4933
|
-
nextParaId = initialDestParaId;
|
|
4934
|
-
intermediateFees = {};
|
|
4935
|
-
hops = [];
|
|
4936
|
-
case 3:
|
|
4937
|
-
if (!(Array.isArray(forwardedXcms) && forwardedXcms.length && forwardedXcms[1].length && ('disconnect' in api.getApi() ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
|
|
4938
|
-
_context.n = 13;
|
|
4939
|
-
break;
|
|
4940
|
-
}
|
|
4941
|
-
nextChain = getTNode(nextParaId, getRelayChainOf(origin).toLowerCase());
|
|
4942
|
-
if (nextChain) {
|
|
4943
|
-
_context.n = 4;
|
|
4944
|
-
break;
|
|
4945
|
-
}
|
|
4946
|
-
throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
|
|
4947
|
-
case 4:
|
|
4948
|
-
hopApi = api.clone();
|
|
4949
|
-
_context.p = 5;
|
|
4950
|
-
if (assets.hasDryRunSupport(nextChain)) {
|
|
4951
|
-
_context.n = 6;
|
|
5052
|
+
feeAsset: resolvedFeeAsset
|
|
5053
|
+
});
|
|
5054
|
+
case 1:
|
|
5055
|
+
originDryRun = _context2.v;
|
|
5056
|
+
if (originDryRun.success) {
|
|
5057
|
+
_context2.n = 2;
|
|
4952
5058
|
break;
|
|
4953
5059
|
}
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
5060
|
+
return _context2.a(2, {
|
|
5061
|
+
failureReason: originDryRun.failureReason,
|
|
5062
|
+
failureChain: 'origin',
|
|
5063
|
+
origin: originDryRun,
|
|
5064
|
+
hops: []
|
|
5065
|
+
});
|
|
5066
|
+
case 2:
|
|
5067
|
+
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
5068
|
+
processHop = /*#__PURE__*/function () {
|
|
5069
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
5070
|
+
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, isDestination, hopDryRun, hopCurrency;
|
|
5071
|
+
return _regenerator().w(function (_context) {
|
|
5072
|
+
while (1) switch (_context.n) {
|
|
5073
|
+
case 0:
|
|
5074
|
+
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange, isDestination = params.isDestination;
|
|
5075
|
+
if (assets.hasDryRunSupport(currentChain)) {
|
|
5076
|
+
_context.n = 1;
|
|
5077
|
+
break;
|
|
5078
|
+
}
|
|
5079
|
+
return _context.a(2, {
|
|
5080
|
+
success: false,
|
|
5081
|
+
failureReason: "DryRunApi is not available on node ".concat(currentChain)
|
|
5082
|
+
});
|
|
5083
|
+
case 1:
|
|
5084
|
+
_context.n = 2;
|
|
5085
|
+
return hopApi.getDryRunXcm({
|
|
5086
|
+
originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain), sdkCommon.Version.V4),
|
|
5087
|
+
xcm: forwardedXcms[1][0],
|
|
5088
|
+
node: currentChain,
|
|
5089
|
+
origin: currentOrigin,
|
|
5090
|
+
asset: currentAsset,
|
|
5091
|
+
feeAsset: resolvedFeeAsset,
|
|
5092
|
+
originFee: originDryRun.fee,
|
|
5093
|
+
amount: BigInt(currency.amount)
|
|
5094
|
+
});
|
|
5095
|
+
case 2:
|
|
5096
|
+
hopDryRun = _context.v;
|
|
5097
|
+
if (!hopDryRun.success) {
|
|
5098
|
+
_context.n = 3;
|
|
5099
|
+
break;
|
|
5100
|
+
}
|
|
5101
|
+
if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
|
|
5102
|
+
hopCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo).symbol;
|
|
5103
|
+
} else if (isDestination) {
|
|
5104
|
+
hopCurrency = assets.findAssetOnDestOrThrow(origin, currentChain, currency).symbol;
|
|
5105
|
+
} else {
|
|
5106
|
+
hopCurrency = asset.symbol;
|
|
5107
|
+
}
|
|
5108
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, hopDryRun), {}, {
|
|
5109
|
+
currency: hopCurrency
|
|
5110
|
+
}));
|
|
5111
|
+
case 3:
|
|
5112
|
+
return _context.a(2, hopDryRun);
|
|
5113
|
+
}
|
|
5114
|
+
}, _callee);
|
|
5115
|
+
}));
|
|
5116
|
+
return function processHop(_x2) {
|
|
5117
|
+
return _ref2.apply(this, arguments);
|
|
4958
5118
|
};
|
|
4959
|
-
}
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
5119
|
+
}();
|
|
5120
|
+
_context2.n = 3;
|
|
5121
|
+
return traverseXcmHops({
|
|
5122
|
+
api: api,
|
|
5123
|
+
origin: origin,
|
|
5124
|
+
destination: destination,
|
|
5125
|
+
currency: currency,
|
|
5126
|
+
initialForwardedXcms: initialForwardedXcms,
|
|
5127
|
+
initialDestParaId: initialDestParaId,
|
|
5128
|
+
swapConfig: swapConfig,
|
|
5129
|
+
processHop: processHop,
|
|
5130
|
+
shouldContinue: function shouldContinue(hopResult) {
|
|
5131
|
+
return hopResult.success;
|
|
5132
|
+
},
|
|
5133
|
+
extractNextHopData: function extractNextHopData(hopResult) {
|
|
5134
|
+
return {
|
|
5135
|
+
forwardedXcms: hopResult.success ? hopResult.forwardedXcms : undefined,
|
|
5136
|
+
destParaId: hopResult.success ? hopResult.destParaId : undefined
|
|
5137
|
+
};
|
|
5138
|
+
}
|
|
4975
5139
|
});
|
|
4976
|
-
case
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
}
|
|
4984
|
-
// Add to hops array (only if not the destination)
|
|
4985
|
-
if (nextChain !== destination) {
|
|
4986
|
-
hops.push({
|
|
4987
|
-
chain: nextChain,
|
|
4988
|
-
result: hopDryRun.success && hopCurrency ? _objectSpread2(_objectSpread2({}, hopDryRun), {}, {
|
|
4989
|
-
currency: hopCurrency
|
|
4990
|
-
}) : hopDryRun
|
|
4991
|
-
});
|
|
4992
|
-
}
|
|
4993
|
-
// Keep existing logic for backwards compatibility
|
|
4994
|
-
if (nextChain === destination || sdkCommon.isRelayChain(nextChain) && !sdkCommon.isRelayChain(destination)) {
|
|
4995
|
-
destinationDryRun = hopDryRun;
|
|
4996
|
-
} else if (nextChain === assetHubNode) {
|
|
4997
|
-
intermediateFees.assetHub = hopDryRun;
|
|
4998
|
-
} else if (nextChain === bridgeHubNode) {
|
|
4999
|
-
intermediateFees.bridgeHub = hopDryRun;
|
|
5000
|
-
}
|
|
5001
|
-
if (hopDryRun.success) {
|
|
5002
|
-
_context.n = 9;
|
|
5140
|
+
case 3:
|
|
5141
|
+
traversalResult = _context2.v;
|
|
5142
|
+
// Process Ethereum bridge fees
|
|
5143
|
+
assetHubNode = "AssetHub".concat(getRelayChainOf(origin));
|
|
5144
|
+
bridgeHubNode = "BridgeHub".concat(getRelayChainOf(origin));
|
|
5145
|
+
if (!((_traversalResult$brid = traversalResult.bridgeHub) !== null && _traversalResult$brid !== void 0 && _traversalResult$brid.success)) {
|
|
5146
|
+
_context2.n = 5;
|
|
5003
5147
|
break;
|
|
5004
5148
|
}
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
}
|
|
5011
|
-
newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
|
|
5012
|
-
forwardedXcms = newXcms;
|
|
5013
|
-
nextParaId = destParaId;
|
|
5014
|
-
currentOrigin = nextChain;
|
|
5015
|
-
case 10:
|
|
5016
|
-
_context.p = 10;
|
|
5017
|
-
_context.n = 11;
|
|
5018
|
-
return hopApi.disconnect();
|
|
5019
|
-
case 11:
|
|
5020
|
-
return _context.f(10);
|
|
5021
|
-
case 12:
|
|
5022
|
-
_context.n = 3;
|
|
5149
|
+
_context2.n = 4;
|
|
5150
|
+
return addEthereumBridgeFees(api, traversalResult.bridgeHub, destination, assetHubNode);
|
|
5151
|
+
case 4:
|
|
5152
|
+
_t = _context2.v;
|
|
5153
|
+
_context2.n = 6;
|
|
5023
5154
|
break;
|
|
5024
|
-
case
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
return ahApi.init(assetHubNode, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
5033
|
-
case 14:
|
|
5034
|
-
_context.n = 15;
|
|
5035
|
-
return getParaEthTransferFees(ahApi);
|
|
5036
|
-
case 15:
|
|
5037
|
-
_yield$getParaEthTran = _context.v;
|
|
5038
|
-
_yield$getParaEthTran2 = _slicedToArray(_yield$getParaEthTran, 1);
|
|
5039
|
-
bridgeFee = _yield$getParaEthTran2[0];
|
|
5040
|
-
processedBridgeHubData = _objectSpread2(_objectSpread2({}, intermediateFees.bridgeHub), {}, {
|
|
5041
|
-
fee: intermediateFees.bridgeHub.fee + bridgeFee
|
|
5042
|
-
});
|
|
5043
|
-
// Update the hop data if BridgeHub is in the hops array
|
|
5044
|
-
bridgeHubHopIndex = hops.findIndex(function (hop) {
|
|
5045
|
-
return hop.chain === bridgeHubNode;
|
|
5046
|
-
});
|
|
5047
|
-
if (bridgeHubHopIndex !== -1 && hops[bridgeHubHopIndex].result.success) {
|
|
5048
|
-
hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, hops[bridgeHubHopIndex].result), {}, {
|
|
5049
|
-
fee: intermediateFees.bridgeHub.fee + bridgeFee
|
|
5155
|
+
case 5:
|
|
5156
|
+
_t = traversalResult.bridgeHub;
|
|
5157
|
+
case 6:
|
|
5158
|
+
processedBridgeHub = _t;
|
|
5159
|
+
// Update bridge hub in hops if needed
|
|
5160
|
+
if (processedBridgeHub && processedBridgeHub.success && traversalResult.bridgeHub && traversalResult.bridgeHub.success && processedBridgeHub.fee !== traversalResult.bridgeHub.fee) {
|
|
5161
|
+
bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
|
|
5162
|
+
return hop.chain === bridgeHubNode;
|
|
5050
5163
|
});
|
|
5164
|
+
if (bridgeHubHopIndex !== -1 && traversalResult.hops[bridgeHubHopIndex].result.success) {
|
|
5165
|
+
traversalResult.hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, traversalResult.hops[bridgeHubHopIndex].result), {}, {
|
|
5166
|
+
fee: processedBridgeHub.fee
|
|
5167
|
+
});
|
|
5168
|
+
}
|
|
5051
5169
|
}
|
|
5052
|
-
|
|
5170
|
+
originWithCurrency = originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
|
|
5171
|
+
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(origin)
|
|
5172
|
+
}) : originDryRun;
|
|
5173
|
+
assetHubWithCurrency = (_traversalResult$asse = traversalResult.assetHub) !== null && _traversalResult$asse !== void 0 && _traversalResult$asse.success ? _objectSpread2(_objectSpread2({}, traversalResult.assetHub), {}, {
|
|
5174
|
+
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(assetHubNode)
|
|
5175
|
+
}) : traversalResult.assetHub;
|
|
5176
|
+
bridgeHubWithCurrency = processedBridgeHub !== null && processedBridgeHub !== void 0 && processedBridgeHub.success ? _objectSpread2(_objectSpread2({}, processedBridgeHub), {}, {
|
|
5177
|
+
currency: assets.getNativeAssetSymbol(bridgeHubNode)
|
|
5178
|
+
}) : processedBridgeHub;
|
|
5179
|
+
destinationWithCurrency = (_traversalResult$dest = traversalResult.destination) !== null && _traversalResult$dest !== void 0 && _traversalResult$dest.success ? _objectSpread2(_objectSpread2({}, traversalResult.destination), {}, {
|
|
5180
|
+
currency: asset === null || asset === void 0 ? void 0 : asset.symbol
|
|
5181
|
+
}) : traversalResult.destination;
|
|
5053
5182
|
_getFailureInfo = getFailureInfo$1({
|
|
5054
|
-
destination:
|
|
5055
|
-
assetHub:
|
|
5056
|
-
bridgeHub:
|
|
5057
|
-
}, hops), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
|
|
5058
|
-
return
|
|
5183
|
+
destination: destinationWithCurrency,
|
|
5184
|
+
assetHub: assetHubWithCurrency,
|
|
5185
|
+
bridgeHub: bridgeHubWithCurrency
|
|
5186
|
+
}, traversalResult.hops), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
|
|
5187
|
+
return _context2.a(2, {
|
|
5059
5188
|
failureReason: failureReason,
|
|
5060
5189
|
failureChain: failureChain,
|
|
5061
|
-
origin:
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
}) : intermediateFees.assetHub,
|
|
5067
|
-
bridgeHub: (_processedBridgeHubDa = processedBridgeHubData) !== null && _processedBridgeHubDa !== void 0 && _processedBridgeHubDa.success ? _objectSpread2(_objectSpread2({}, processedBridgeHubData), {}, {
|
|
5068
|
-
currency: assets.getNativeAssetSymbol(bridgeHubNode)
|
|
5069
|
-
}) : processedBridgeHubData,
|
|
5070
|
-
destination: (_destinationDryRun = destinationDryRun) !== null && _destinationDryRun !== void 0 && _destinationDryRun.success ? _objectSpread2(_objectSpread2({}, destinationDryRun), {}, {
|
|
5071
|
-
currency: asset === null || asset === void 0 ? void 0 : asset.symbol
|
|
5072
|
-
}) : destinationDryRun,
|
|
5073
|
-
hops: hops
|
|
5190
|
+
origin: originWithCurrency,
|
|
5191
|
+
assetHub: assetHubWithCurrency,
|
|
5192
|
+
bridgeHub: bridgeHubWithCurrency,
|
|
5193
|
+
destination: destinationWithCurrency,
|
|
5194
|
+
hops: traversalResult.hops
|
|
5074
5195
|
});
|
|
5075
5196
|
}
|
|
5076
|
-
},
|
|
5197
|
+
}, _callee2);
|
|
5077
5198
|
}));
|
|
5078
5199
|
return function dryRunInternal(_x) {
|
|
5079
5200
|
return _ref.apply(this, arguments);
|
|
@@ -5485,14 +5606,14 @@ var getFailureInfo = function getFailureInfo(nodes, hops) {
|
|
|
5485
5606
|
return {};
|
|
5486
5607
|
};
|
|
5487
5608
|
var getXcmFee = /*#__PURE__*/function () {
|
|
5488
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
5489
|
-
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee,
|
|
5490
|
-
return _regenerator().w(function (
|
|
5491
|
-
while (1) switch (
|
|
5609
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
5610
|
+
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, destApi, destFeeRes, _result, _getFailureInfo, _failureChain, _failureReason, processHop, traversalResult, destFee, destCurrency, destFeeType, destDryRunError, destSufficient, destResult, _destApi, destFallback, assetHubNode, processedBridgeHub, bridgeHubNode, bridgeHubHopIndex, convertToFeeDetail, result, _getFailureInfo2, failureChain, failureReason;
|
|
5611
|
+
return _regenerator().w(function (_context2) {
|
|
5612
|
+
while (1) switch (_context2.n) {
|
|
5492
5613
|
case 0:
|
|
5493
5614
|
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset, disableFallback = _ref.disableFallback, swapConfig = _ref.swapConfig;
|
|
5494
|
-
asset = assets.findAssetForNodeOrThrow(origin, currency, destination);
|
|
5495
|
-
|
|
5615
|
+
asset = assets.findAssetForNodeOrThrow(origin, currency, destination);
|
|
5616
|
+
_context2.n = 1;
|
|
5496
5617
|
return getOriginXcmFee({
|
|
5497
5618
|
api: api,
|
|
5498
5619
|
tx: tx,
|
|
@@ -5504,7 +5625,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5504
5625
|
disableFallback: disableFallback
|
|
5505
5626
|
});
|
|
5506
5627
|
case 1:
|
|
5507
|
-
_yield$getOriginXcmFe =
|
|
5628
|
+
_yield$getOriginXcmFe = _context2.v;
|
|
5508
5629
|
originFee = _yield$getOriginXcmFe.fee;
|
|
5509
5630
|
originCurrency = _yield$getOriginXcmFe.currency;
|
|
5510
5631
|
originFeeType = _yield$getOriginXcmFe.feeType;
|
|
@@ -5514,22 +5635,20 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5514
5635
|
originWeight = _yield$getOriginXcmFe.weight;
|
|
5515
5636
|
sufficientOriginFee = _yield$getOriginXcmFe.sufficient;
|
|
5516
5637
|
api.setDisconnectAllowed(true);
|
|
5517
|
-
|
|
5638
|
+
_context2.n = 2;
|
|
5518
5639
|
return api.disconnect();
|
|
5519
5640
|
case 2:
|
|
5520
|
-
// Initialize hops array
|
|
5521
|
-
hops = [];
|
|
5522
5641
|
if (!(originDryRunError || originFeeType === 'paymentInfo')) {
|
|
5523
|
-
|
|
5642
|
+
_context2.n = 8;
|
|
5524
5643
|
break;
|
|
5525
5644
|
}
|
|
5526
5645
|
destApi = api.clone();
|
|
5527
|
-
|
|
5528
|
-
|
|
5646
|
+
_context2.p = 3;
|
|
5647
|
+
_context2.n = 4;
|
|
5529
5648
|
return destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
5530
5649
|
case 4:
|
|
5531
5650
|
destApi.setDisconnectAllowed(false);
|
|
5532
|
-
|
|
5651
|
+
_context2.n = 5;
|
|
5533
5652
|
return getDestXcmFee({
|
|
5534
5653
|
api: destApi,
|
|
5535
5654
|
forwardedXcms: undefined,
|
|
@@ -5545,7 +5664,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5545
5664
|
disableFallback: disableFallback
|
|
5546
5665
|
});
|
|
5547
5666
|
case 5:
|
|
5548
|
-
destFeeRes =
|
|
5667
|
+
destFeeRes = _context2.v;
|
|
5549
5668
|
_result = {
|
|
5550
5669
|
origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
5551
5670
|
fee: originFee
|
|
@@ -5569,134 +5688,127 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5569
5688
|
}), {}, {
|
|
5570
5689
|
currency: assets.getNativeAssetSymbol(destination)
|
|
5571
5690
|
}),
|
|
5572
|
-
hops:
|
|
5691
|
+
hops: []
|
|
5573
5692
|
};
|
|
5574
5693
|
_getFailureInfo = getFailureInfo({
|
|
5575
5694
|
origin: _result.origin,
|
|
5576
5695
|
destination: _result.destination
|
|
5577
|
-
},
|
|
5578
|
-
return
|
|
5696
|
+
}, []), _failureChain = _getFailureInfo.failureChain, _failureReason = _getFailureInfo.failureReason;
|
|
5697
|
+
return _context2.a(2, _objectSpread2(_objectSpread2({}, _result), {}, {
|
|
5579
5698
|
failureChain: _failureChain,
|
|
5580
5699
|
failureReason: _failureReason
|
|
5581
5700
|
}));
|
|
5582
5701
|
case 6:
|
|
5583
|
-
|
|
5702
|
+
_context2.p = 6;
|
|
5584
5703
|
destApi.setDisconnectAllowed(true);
|
|
5585
|
-
|
|
5704
|
+
_context2.n = 7;
|
|
5586
5705
|
return destApi.disconnect();
|
|
5587
5706
|
case 7:
|
|
5588
|
-
return
|
|
5707
|
+
return _context2.f(6);
|
|
5589
5708
|
case 8:
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5709
|
+
processHop = /*#__PURE__*/function () {
|
|
5710
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
5711
|
+
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopResult, hopCurrency;
|
|
5712
|
+
return _regenerator().w(function (_context) {
|
|
5713
|
+
while (1) switch (_context.n) {
|
|
5714
|
+
case 0:
|
|
5715
|
+
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange;
|
|
5716
|
+
_context.n = 1;
|
|
5717
|
+
return getDestXcmFee({
|
|
5718
|
+
api: hopApi,
|
|
5719
|
+
forwardedXcms: forwardedXcms,
|
|
5720
|
+
origin: origin,
|
|
5721
|
+
prevNode: currentOrigin,
|
|
5722
|
+
destination: currentChain,
|
|
5723
|
+
currency: currency,
|
|
5724
|
+
address: address,
|
|
5725
|
+
senderAddress: senderAddress,
|
|
5726
|
+
asset: currentAsset,
|
|
5727
|
+
feeAsset: feeAsset,
|
|
5728
|
+
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
5729
|
+
disableFallback: disableFallback
|
|
5730
|
+
});
|
|
5731
|
+
case 1:
|
|
5732
|
+
hopResult = _context.v;
|
|
5733
|
+
if (hopResult.feeType === 'dryRun') {
|
|
5734
|
+
if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
|
|
5735
|
+
hopCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo).symbol;
|
|
5736
|
+
} else if (destination === currentChain) {
|
|
5737
|
+
hopCurrency = assets.findAssetOnDestOrThrow(origin, currentChain, currency).symbol;
|
|
5738
|
+
} else {
|
|
5739
|
+
hopCurrency = asset.symbol;
|
|
5740
|
+
}
|
|
5741
|
+
} else {
|
|
5742
|
+
hopCurrency = assets.getNativeAssetSymbol(currentChain);
|
|
5743
|
+
}
|
|
5744
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, hopResult), {}, {
|
|
5745
|
+
currency: hopCurrency
|
|
5746
|
+
}));
|
|
5747
|
+
}
|
|
5748
|
+
}, _callee);
|
|
5749
|
+
}));
|
|
5750
|
+
return function processHop(_x2) {
|
|
5751
|
+
return _ref3.apply(this, arguments);
|
|
5752
|
+
};
|
|
5753
|
+
}();
|
|
5754
|
+
_context2.n = 9;
|
|
5755
|
+
return traverseXcmHops({
|
|
5756
|
+
api: api,
|
|
5622
5757
|
origin: origin,
|
|
5623
|
-
|
|
5624
|
-
destination: nextChain,
|
|
5758
|
+
destination: destination,
|
|
5625
5759
|
currency: currency,
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
hopCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo).symbol;
|
|
5639
|
-
} else if (destination === nextChain) {
|
|
5640
|
-
hopCurrency = assets.findAssetOnDestOrThrow(origin, nextChain, currency).symbol;
|
|
5641
|
-
} else {
|
|
5642
|
-
hopCurrency = asset.symbol;
|
|
5760
|
+
initialForwardedXcms: initialForwardedXcm,
|
|
5761
|
+
initialDestParaId: initialDestParaId,
|
|
5762
|
+
swapConfig: swapConfig,
|
|
5763
|
+
processHop: processHop,
|
|
5764
|
+
shouldContinue: function shouldContinue(hopResult) {
|
|
5765
|
+
return !hopResult.dryRunError;
|
|
5766
|
+
},
|
|
5767
|
+
extractNextHopData: function extractNextHopData(hopResult) {
|
|
5768
|
+
return {
|
|
5769
|
+
forwardedXcms: hopResult.forwardedXcms,
|
|
5770
|
+
destParaId: hopResult.destParaId
|
|
5771
|
+
};
|
|
5643
5772
|
}
|
|
5644
|
-
}
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
} : {
|
|
5654
|
-
fee: hopResult.fee,
|
|
5655
|
-
feeType: hopResult.feeType,
|
|
5656
|
-
currency: hopCurrency,
|
|
5657
|
-
sufficient: hopResult.sufficient
|
|
5658
|
-
};
|
|
5659
|
-
if (nextChain !== destination) {
|
|
5660
|
-
hops.push({
|
|
5661
|
-
chain: nextChain,
|
|
5662
|
-
result: hopDetail
|
|
5663
|
-
});
|
|
5664
|
-
}
|
|
5665
|
-
if (!hopResult.dryRunError) {
|
|
5666
|
-
_context.n = 17;
|
|
5773
|
+
});
|
|
5774
|
+
case 9:
|
|
5775
|
+
traversalResult = _context2.v;
|
|
5776
|
+
// Handle case where we failed before reaching destination
|
|
5777
|
+
destFee = 0n;
|
|
5778
|
+
destFeeType = destination === 'Ethereum' ? 'noFeeRequired' : 'paymentInfo';
|
|
5779
|
+
destSufficient = undefined;
|
|
5780
|
+
if (!traversalResult.destination) {
|
|
5781
|
+
_context2.n = 10;
|
|
5667
5782
|
break;
|
|
5668
5783
|
}
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
}
|
|
5681
|
-
// We failed before the true destination, use fallback via paymentInfo.
|
|
5682
|
-
if (hopIsDestination) {
|
|
5683
|
-
_context.n = 16;
|
|
5784
|
+
destResult = traversalResult.destination;
|
|
5785
|
+
destFee = destResult.fee;
|
|
5786
|
+
destFeeType = destResult.feeType;
|
|
5787
|
+
destDryRunError = destResult.dryRunError;
|
|
5788
|
+
destSufficient = destResult.sufficient;
|
|
5789
|
+
destCurrency = destResult.currency;
|
|
5790
|
+
_context2.n = 14;
|
|
5791
|
+
break;
|
|
5792
|
+
case 10:
|
|
5793
|
+
if (!(traversalResult.hops.length > 0 && traversalResult.hops[traversalResult.hops.length - 1].result.dryRunError)) {
|
|
5794
|
+
_context2.n = 13;
|
|
5684
5795
|
break;
|
|
5685
5796
|
}
|
|
5797
|
+
// We failed before reaching destination, use fallback
|
|
5686
5798
|
_destApi = api.clone();
|
|
5687
5799
|
if (!(destination !== 'Ethereum')) {
|
|
5688
|
-
|
|
5800
|
+
_context2.n = 11;
|
|
5689
5801
|
break;
|
|
5690
5802
|
}
|
|
5691
|
-
|
|
5803
|
+
_context2.n = 11;
|
|
5692
5804
|
return _destApi.init(destination, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
5693
|
-
case
|
|
5694
|
-
|
|
5805
|
+
case 11:
|
|
5806
|
+
_context2.n = 12;
|
|
5695
5807
|
return getDestXcmFee({
|
|
5696
5808
|
api: _destApi,
|
|
5697
5809
|
forwardedXcms: undefined,
|
|
5698
5810
|
origin: origin,
|
|
5699
|
-
prevNode:
|
|
5811
|
+
prevNode: traversalResult.lastProcessedChain || origin,
|
|
5700
5812
|
destination: destination,
|
|
5701
5813
|
currency: currency,
|
|
5702
5814
|
address: address,
|
|
@@ -5705,78 +5817,52 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5705
5817
|
senderAddress: senderAddress,
|
|
5706
5818
|
disableFallback: disableFallback
|
|
5707
5819
|
});
|
|
5708
|
-
case
|
|
5709
|
-
destFallback =
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
case 17:
|
|
5716
|
-
if (nextChain === destination || sdkCommon.isRelayChain(nextChain) && !sdkCommon.isRelayChain(destination)) {
|
|
5717
|
-
destinationFee = hopResult.fee;
|
|
5718
|
-
destinationFeeType = hopResult.feeType;
|
|
5719
|
-
destinationSufficient = hopResult.sufficient;
|
|
5720
|
-
} else if (nextChain === assetHubNode) {
|
|
5721
|
-
intermediateFees.assetHub = hopDetail;
|
|
5722
|
-
} else if (nextChain === bridgeHubNode) {
|
|
5723
|
-
intermediateFees.bridgeHub = hopDetail;
|
|
5724
|
-
} else ;
|
|
5725
|
-
if (swapConfig && nextChain === swapConfig.exchangeChain) {
|
|
5726
|
-
hasPassedExchange = true;
|
|
5727
|
-
currentAsset = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, nextChain, swapConfig.currencyTo);
|
|
5728
|
-
}
|
|
5729
|
-
forwardedXcms = hopResult.forwardedXcms;
|
|
5730
|
-
nextParaId = hopResult.destParaId;
|
|
5731
|
-
currentOrigin = nextChain;
|
|
5732
|
-
case 18:
|
|
5733
|
-
_context.p = 18;
|
|
5734
|
-
_context.n = 19;
|
|
5735
|
-
return hopApi.disconnect();
|
|
5736
|
-
case 19:
|
|
5737
|
-
return _context.f(18);
|
|
5738
|
-
case 20:
|
|
5739
|
-
_context.n = 9;
|
|
5820
|
+
case 12:
|
|
5821
|
+
destFallback = _context2.v;
|
|
5822
|
+
destFee = destFallback.fee;
|
|
5823
|
+
destFeeType = destFallback.feeType;
|
|
5824
|
+
destSufficient = destFallback.sufficient;
|
|
5825
|
+
destCurrency = assets.getNativeAssetSymbol(destination);
|
|
5826
|
+
_context2.n = 14;
|
|
5740
5827
|
break;
|
|
5741
|
-
case
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
fee: intermediateFees.bridgeHub.fee + bridgeFee
|
|
5759
|
-
});
|
|
5760
|
-
bridgeHubHopIndex = hops.findIndex(function (hop) {
|
|
5761
|
-
return hop.chain === bridgeHubNode;
|
|
5762
|
-
});
|
|
5763
|
-
if (bridgeHubHopIndex !== -1) {
|
|
5764
|
-
hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, hops[bridgeHubHopIndex].result), {}, {
|
|
5765
|
-
fee: intermediateFees.bridgeHub.fee + bridgeFee
|
|
5828
|
+
case 13:
|
|
5829
|
+
destFee = 0n;
|
|
5830
|
+
destFeeType = 'noFeeRequired';
|
|
5831
|
+
destSufficient = true;
|
|
5832
|
+
destCurrency = assets.getNativeAssetSymbol(destination);
|
|
5833
|
+
case 14:
|
|
5834
|
+
// Process Ethereum bridge fees
|
|
5835
|
+
assetHubNode = "AssetHub".concat(getRelayChainOf(origin));
|
|
5836
|
+
_context2.n = 15;
|
|
5837
|
+
return addEthereumBridgeFees(api, traversalResult.bridgeHub, destination, assetHubNode);
|
|
5838
|
+
case 15:
|
|
5839
|
+
processedBridgeHub = _context2.v;
|
|
5840
|
+
// Update bridge hub fee in hops if needed
|
|
5841
|
+
if (processedBridgeHub && traversalResult.bridgeHub && processedBridgeHub.fee !== traversalResult.bridgeHub.fee) {
|
|
5842
|
+
bridgeHubNode = "BridgeHub".concat(getRelayChainOf(origin));
|
|
5843
|
+
bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
|
|
5844
|
+
return hop.chain === bridgeHubNode;
|
|
5766
5845
|
});
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
if (hasPassedExchange && swapConfig && destination !== swapConfig.exchangeChain) {
|
|
5772
|
-
destCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, destination, swapConfig.currencyTo).symbol;
|
|
5773
|
-
} else {
|
|
5774
|
-
destCurrency = assets.findAssetOnDestOrThrow(origin, destination, currency).symbol;
|
|
5846
|
+
if (bridgeHubHopIndex !== -1) {
|
|
5847
|
+
traversalResult.hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, traversalResult.hops[bridgeHubHopIndex].result), {}, {
|
|
5848
|
+
fee: processedBridgeHub.fee
|
|
5849
|
+
});
|
|
5775
5850
|
}
|
|
5776
|
-
} else {
|
|
5777
|
-
destCurrency = assets.getNativeAssetSymbol(destination);
|
|
5778
5851
|
}
|
|
5779
|
-
|
|
5852
|
+
convertToFeeDetail = function convertToFeeDetail(result) {
|
|
5853
|
+
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, result.fee !== undefined && {
|
|
5854
|
+
fee: result.fee
|
|
5855
|
+
}), result.feeType && {
|
|
5856
|
+
feeType: result.feeType
|
|
5857
|
+
}), result.sufficient !== undefined && {
|
|
5858
|
+
sufficient: result.sufficient
|
|
5859
|
+
}), {}, {
|
|
5860
|
+
currency: result.currency
|
|
5861
|
+
}, result.dryRunError && {
|
|
5862
|
+
dryRunError: result.dryRunError
|
|
5863
|
+
});
|
|
5864
|
+
};
|
|
5865
|
+
result = _objectSpread2(_objectSpread2(_objectSpread2({
|
|
5780
5866
|
origin: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, originWeight && {
|
|
5781
5867
|
weight: originWeight
|
|
5782
5868
|
}), originFee && {
|
|
@@ -5790,31 +5876,40 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5790
5876
|
}, originDryRunError && {
|
|
5791
5877
|
dryRunError: originDryRunError
|
|
5792
5878
|
})
|
|
5793
|
-
},
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5879
|
+
}, traversalResult.assetHub && {
|
|
5880
|
+
assetHub: convertToFeeDetail(traversalResult.assetHub)
|
|
5881
|
+
}), processedBridgeHub && {
|
|
5882
|
+
bridgeHub: convertToFeeDetail(processedBridgeHub)
|
|
5883
|
+
}), {}, {
|
|
5884
|
+
destination: _objectSpread2(_objectSpread2(_objectSpread2({}, destFee !== undefined && {
|
|
5885
|
+
fee: destFee
|
|
5886
|
+
}), destFeeType && {
|
|
5887
|
+
feeType: destFeeType
|
|
5798
5888
|
}), {}, {
|
|
5799
|
-
sufficient:
|
|
5889
|
+
sufficient: destSufficient,
|
|
5800
5890
|
currency: destCurrency
|
|
5801
|
-
},
|
|
5802
|
-
dryRunError:
|
|
5891
|
+
}, destDryRunError && {
|
|
5892
|
+
dryRunError: destDryRunError
|
|
5803
5893
|
}),
|
|
5804
|
-
hops: hops
|
|
5894
|
+
hops: traversalResult.hops.map(function (hop) {
|
|
5895
|
+
return {
|
|
5896
|
+
chain: hop.chain,
|
|
5897
|
+
result: convertToFeeDetail(hop.result)
|
|
5898
|
+
};
|
|
5899
|
+
})
|
|
5805
5900
|
});
|
|
5806
5901
|
_getFailureInfo2 = getFailureInfo({
|
|
5807
5902
|
origin: result.origin,
|
|
5808
5903
|
assetHub: result.assetHub,
|
|
5809
5904
|
bridgeHub: result.bridgeHub,
|
|
5810
5905
|
destination: result.destination
|
|
5811
|
-
}, hops), failureChain = _getFailureInfo2.failureChain, failureReason = _getFailureInfo2.failureReason;
|
|
5812
|
-
return
|
|
5906
|
+
}, result.hops), failureChain = _getFailureInfo2.failureChain, failureReason = _getFailureInfo2.failureReason;
|
|
5907
|
+
return _context2.a(2, _objectSpread2(_objectSpread2({}, result), {}, {
|
|
5813
5908
|
failureChain: failureChain,
|
|
5814
5909
|
failureReason: failureReason
|
|
5815
5910
|
}));
|
|
5816
5911
|
}
|
|
5817
|
-
},
|
|
5912
|
+
}, _callee2, null, [[3,, 6, 8]]);
|
|
5818
5913
|
}));
|
|
5819
5914
|
return function getXcmFee(_x) {
|
|
5820
5915
|
return _ref2.apply(this, arguments);
|
|
@@ -7088,8 +7183,8 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, dryRunResult,
|
|
|
7088
7183
|
return fees;
|
|
7089
7184
|
};
|
|
7090
7185
|
var createXcmAndCall = /*#__PURE__*/function () {
|
|
7091
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
7092
|
-
var xcm, api, chain, exchangeChain, weight, call;
|
|
7186
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options, dryRunWeight) {
|
|
7187
|
+
var xcm, api, chain, exchangeChain, hasApiSupport, weight, call, _t;
|
|
7093
7188
|
return _regenerator().w(function (_context2) {
|
|
7094
7189
|
while (1) switch (_context2.n) {
|
|
7095
7190
|
case 0:
|
|
@@ -7098,10 +7193,21 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
7098
7193
|
case 1:
|
|
7099
7194
|
xcm = _context2.v;
|
|
7100
7195
|
api = options.api, chain = options.chain, exchangeChain = options.exchangeChain;
|
|
7196
|
+
hasApiSupport = assets.hasXcmPaymentApiSupport(chain !== null && chain !== void 0 ? chain : exchangeChain);
|
|
7197
|
+
if (!hasApiSupport) {
|
|
7198
|
+
_context2.n = 3;
|
|
7199
|
+
break;
|
|
7200
|
+
}
|
|
7101
7201
|
_context2.n = 2;
|
|
7102
7202
|
return api.getXcmWeight(xcm);
|
|
7103
7203
|
case 2:
|
|
7104
|
-
|
|
7204
|
+
_t = _context2.v;
|
|
7205
|
+
_context2.n = 4;
|
|
7206
|
+
break;
|
|
7207
|
+
case 3:
|
|
7208
|
+
_t = dryRunWeight !== null && dryRunWeight !== void 0 ? dryRunWeight : MAX_WEIGHT;
|
|
7209
|
+
case 4:
|
|
7210
|
+
weight = _t;
|
|
7105
7211
|
call = createExecuteCall(chain !== null && chain !== void 0 ? chain : exchangeChain, xcm, weight);
|
|
7106
7212
|
return _context2.a(2, {
|
|
7107
7213
|
xcm: xcm,
|
|
@@ -7111,7 +7217,7 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
7111
7217
|
}
|
|
7112
7218
|
}, _callee2);
|
|
7113
7219
|
}));
|
|
7114
|
-
return function createXcmAndCall(_x2) {
|
|
7220
|
+
return function createXcmAndCall(_x2, _x3) {
|
|
7115
7221
|
return _ref2.apply(this, arguments);
|
|
7116
7222
|
};
|
|
7117
7223
|
}();
|
|
@@ -7220,7 +7326,7 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7220
7326
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7221
7327
|
assetTo: updatedAssetTo,
|
|
7222
7328
|
fees: extractedFees
|
|
7223
|
-
}));
|
|
7329
|
+
}), firstDryRunResult.origin.success ? firstDryRunResult.origin.weight : undefined);
|
|
7224
7330
|
case 9:
|
|
7225
7331
|
_yield$createXcmAndCa2 = _context3.v;
|
|
7226
7332
|
secondCall = _yield$createXcmAndCa2.call;
|
|
@@ -7258,7 +7364,7 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7258
7364
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7259
7365
|
assetTo: finalAssetTo,
|
|
7260
7366
|
fees: finalFees
|
|
7261
|
-
}));
|
|
7367
|
+
}), secondDryRunResult.origin.success ? secondDryRunResult.origin.weight : undefined);
|
|
7262
7368
|
case 12:
|
|
7263
7369
|
_yield$createXcmAndCa3 = _context3.v;
|
|
7264
7370
|
finalCall = _yield$createXcmAndCa3.call;
|
|
@@ -7268,7 +7374,7 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7268
7374
|
}
|
|
7269
7375
|
}, _callee3);
|
|
7270
7376
|
}));
|
|
7271
|
-
return function handleSwapExecuteTransfer(
|
|
7377
|
+
return function handleSwapExecuteTransfer(_x4) {
|
|
7272
7378
|
return _ref3.apply(this, arguments);
|
|
7273
7379
|
};
|
|
7274
7380
|
}();
|
|
@@ -11532,24 +11638,12 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
11532
11638
|
}, {
|
|
11533
11639
|
key: "getXcmFee",
|
|
11534
11640
|
value: (function () {
|
|
11535
|
-
var _getXcmFee2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
11536
|
-
var
|
|
11537
|
-
|
|
11538
|
-
_this$_options3,
|
|
11539
|
-
from,
|
|
11540
|
-
to,
|
|
11541
|
-
address,
|
|
11542
|
-
senderAddress,
|
|
11543
|
-
feeAsset,
|
|
11544
|
-
currency,
|
|
11545
|
-
tx,
|
|
11546
|
-
_args4 = arguments;
|
|
11641
|
+
var _getXcmFee2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(options) {
|
|
11642
|
+
var _options$disableFallb;
|
|
11643
|
+
var _this$_options3, from, to, address, senderAddress, feeAsset, currency, tx, disableFallback;
|
|
11547
11644
|
return _regenerator().w(function (_context4) {
|
|
11548
11645
|
while (1) switch (_context4.n) {
|
|
11549
11646
|
case 0:
|
|
11550
|
-
_ref = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {
|
|
11551
|
-
disableFallback: false
|
|
11552
|
-
}, disableFallback = _ref.disableFallback;
|
|
11553
11647
|
_this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress, feeAsset = _this$_options3.feeAsset, currency = _this$_options3.currency;
|
|
11554
11648
|
assertToIsString(to);
|
|
11555
11649
|
assertAddressIsString(address);
|
|
@@ -11557,6 +11651,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
11557
11651
|
return this.build();
|
|
11558
11652
|
case 1:
|
|
11559
11653
|
tx = _context4.v;
|
|
11654
|
+
disableFallback = (_options$disableFallb = options === null || options === void 0 ? void 0 : options.disableFallback) !== null && _options$disableFallb !== void 0 ? _options$disableFallb : false;
|
|
11560
11655
|
_context4.p = 2;
|
|
11561
11656
|
_context4.n = 3;
|
|
11562
11657
|
return getXcmFee({
|
|
@@ -11583,7 +11678,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
11583
11678
|
}
|
|
11584
11679
|
}, _callee4, this, [[2,, 4, 6]]);
|
|
11585
11680
|
}));
|
|
11586
|
-
function getXcmFee$1() {
|
|
11681
|
+
function getXcmFee$1(_x2) {
|
|
11587
11682
|
return _getXcmFee2.apply(this, arguments);
|
|
11588
11683
|
}
|
|
11589
11684
|
return getXcmFee$1;
|
|
@@ -11598,7 +11693,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
11598
11693
|
key: "getOriginXcmFee",
|
|
11599
11694
|
value: (function () {
|
|
11600
11695
|
var _getOriginXcmFee2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
|
|
11601
|
-
var
|
|
11696
|
+
var _ref,
|
|
11602
11697
|
disableFallback,
|
|
11603
11698
|
_this$_options4,
|
|
11604
11699
|
from,
|
|
@@ -11611,9 +11706,9 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
11611
11706
|
return _regenerator().w(function (_context5) {
|
|
11612
11707
|
while (1) switch (_context5.n) {
|
|
11613
11708
|
case 0:
|
|
11614
|
-
|
|
11709
|
+
_ref = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {
|
|
11615
11710
|
disableFallback: false
|
|
11616
|
-
}, disableFallback =
|
|
11711
|
+
}, disableFallback = _ref.disableFallback;
|
|
11617
11712
|
_this$_options4 = this._options, from = _this$_options4.from, to = _this$_options4.to, senderAddress = _this$_options4.senderAddress, currency = _this$_options4.currency, feeAsset = _this$_options4.feeAsset;
|
|
11618
11713
|
assertToIsString(to);
|
|
11619
11714
|
_context5.n = 1;
|
|
@@ -11917,6 +12012,7 @@ exports.ScenarioNotSupportedError = ScenarioNotSupportedError;
|
|
|
11917
12012
|
exports.TX_CLIENT_TIMEOUT_MS = TX_CLIENT_TIMEOUT_MS;
|
|
11918
12013
|
exports.TransferToAhNotSupported = TransferToAhNotSupported;
|
|
11919
12014
|
exports.UnableToComputeError = UnableToComputeError;
|
|
12015
|
+
exports.addEthereumBridgeFees = addEthereumBridgeFees;
|
|
11920
12016
|
exports.addXcmVersionHeader = addXcmVersionHeader;
|
|
11921
12017
|
exports.assertAddressIsString = assertAddressIsString;
|
|
11922
12018
|
exports.assertHasLocation = assertHasLocation;
|
|
@@ -11981,6 +12077,7 @@ exports.sortMultiAssets = sortMultiAssets;
|
|
|
11981
12077
|
exports.transferMoonbeamEvm = transferMoonbeamEvm;
|
|
11982
12078
|
exports.transferMoonbeamToEth = transferMoonbeamToEth;
|
|
11983
12079
|
exports.transferRelayToPara = transferRelayToPara;
|
|
12080
|
+
exports.traverseXcmHops = traverseXcmHops;
|
|
11984
12081
|
exports.validateAddress = validateAddress;
|
|
11985
12082
|
exports.verifyEdOnDestination = verifyEdOnDestination;
|
|
11986
12083
|
Object.keys(assets).forEach(function (k) {
|