@paraspell/sdk-core 11.2.0 → 11.2.1
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 +1545 -1703
- package/dist/index.d.ts +257 -256
- package/dist/index.mjs +1546 -1704
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blake2b } from '@noble/hashes/blake2';
|
|
2
|
-
import { isChainEvm, getAssetsObject, InvalidCurrencyError, isForeignAsset, extractAssetLocation, getNativeAssetSymbol, getOtherAssets, isAssetEqual,
|
|
2
|
+
import { isChainEvm, getAssetsObject, InvalidCurrencyError, isForeignAsset, extractAssetLocation, getNativeAssetSymbol, getOtherAssets, isAssetEqual, findAssetInfo, isTAsset, findAssetInfoOrThrow, getExistentialDeposit, isOverrideLocationSpecifier, findAssetInfoByLoc, findAssetOnDestOrThrow, Native, isSymbolMatch, hasDryRunSupport, hasSupportForAsset, getRelayChainSymbol, isSymbolSpecifier, normalizeLocation, hasXcmPaymentApiSupport, getExistentialDepositOrThrow, normalizeSymbol, getNativeAssets } from '@paraspell/assets';
|
|
3
3
|
export * from '@paraspell/assets';
|
|
4
4
|
import { base58 } from '@scure/base';
|
|
5
5
|
import { isAddress, parseUnits, createPublicClient, http, getContract, pad, toHex, getAddress, concat, keccak256 } from 'viem';
|
|
@@ -3474,6 +3474,86 @@ var createDirectExecuteXcm = function createDirectExecuteXcm(options) {
|
|
|
3474
3474
|
return addXcmVersionHeader(fullXcm, version);
|
|
3475
3475
|
};
|
|
3476
3476
|
|
|
3477
|
+
var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
|
|
3478
|
+
var asset = findAssetInfo(origin, feeAsset, !isTLocation(destination) ? destination : null);
|
|
3479
|
+
var usesRawOverriddenMultiAssets = Array.isArray(currency) && currency.every(isTAsset);
|
|
3480
|
+
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
3481
|
+
throwUnsupportedCurrency(feeAsset, origin);
|
|
3482
|
+
}
|
|
3483
|
+
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
3484
|
+
};
|
|
3485
|
+
|
|
3486
|
+
var isAssetHub = function isAssetHub(chain) {
|
|
3487
|
+
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
3488
|
+
};
|
|
3489
|
+
var isBridgeHub = function isBridgeHub(chain) {
|
|
3490
|
+
return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
|
|
3491
|
+
};
|
|
3492
|
+
var isPeople = function isPeople(chain) {
|
|
3493
|
+
return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
|
|
3494
|
+
};
|
|
3495
|
+
var isSystemPara = function isSystemPara(chain) {
|
|
3496
|
+
return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
|
|
3497
|
+
};
|
|
3498
|
+
var mul = function mul(v, num) {
|
|
3499
|
+
var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
|
|
3500
|
+
return v * num / den;
|
|
3501
|
+
};
|
|
3502
|
+
var padFee = function padFee(raw, origin, dest, side) {
|
|
3503
|
+
var relayOrigin = isRelayChain(origin);
|
|
3504
|
+
var relayDest = isRelayChain(dest);
|
|
3505
|
+
var sysParaOrigin = isSystemPara(origin);
|
|
3506
|
+
var sysParaDest = isSystemPara(dest);
|
|
3507
|
+
var relayToPara = relayOrigin && !relayDest;
|
|
3508
|
+
var sysParaToPara = sysParaOrigin && !sysParaDest;
|
|
3509
|
+
var paraToPara = !relayOrigin && !sysParaOrigin;
|
|
3510
|
+
if (sysParaToPara) return raw * 40n;
|
|
3511
|
+
if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
|
|
3512
|
+
if (paraToPara && side == 'origin' && origin === 'Mythos' && dest !== 'Ethereum') {
|
|
3513
|
+
return 150000000000000000n;
|
|
3514
|
+
}
|
|
3515
|
+
if (paraToPara) return mul(raw, 130n, 100n);
|
|
3516
|
+
// apply default 30% padding
|
|
3517
|
+
return mul(raw, 130n, 100n);
|
|
3518
|
+
};
|
|
3519
|
+
var padFeeBy = function padFeeBy(amount, percent) {
|
|
3520
|
+
return mul(amount, BigInt(100 + percent), 100n);
|
|
3521
|
+
};
|
|
3522
|
+
|
|
3523
|
+
var determineAddress = function determineAddress(chain, address, senderAddress) {
|
|
3524
|
+
if (isChainEvm(chain)) {
|
|
3525
|
+
return isAddress(address) ? address : senderAddress;
|
|
3526
|
+
}
|
|
3527
|
+
return isAddress(address) ? senderAddress : address;
|
|
3528
|
+
};
|
|
3529
|
+
var getReverseTxFee = /*#__PURE__*/function () {
|
|
3530
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
|
|
3531
|
+
var api, origin, destination, senderAddress, address, currency, toAddress, fromAddress, tx, rawFee;
|
|
3532
|
+
return _regenerator().w(function (_context) {
|
|
3533
|
+
while (1) switch (_context.n) {
|
|
3534
|
+
case 0:
|
|
3535
|
+
api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
|
|
3536
|
+
toAddress = determineAddress(origin, address, senderAddress);
|
|
3537
|
+
fromAddress = determineAddress(destination, address, senderAddress);
|
|
3538
|
+
_context.n = 1;
|
|
3539
|
+
return Builder(api).from(destination).to(origin).address(toAddress).senderAddress(fromAddress).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
|
|
3540
|
+
amount: currency.amount
|
|
3541
|
+
})).build();
|
|
3542
|
+
case 1:
|
|
3543
|
+
tx = _context.v;
|
|
3544
|
+
_context.n = 2;
|
|
3545
|
+
return api.calculateTransactionFee(tx, fromAddress);
|
|
3546
|
+
case 2:
|
|
3547
|
+
rawFee = _context.v;
|
|
3548
|
+
return _context.a(2, padFee(rawFee, origin, destination, 'destination'));
|
|
3549
|
+
}
|
|
3550
|
+
}, _callee);
|
|
3551
|
+
}));
|
|
3552
|
+
return function getReverseTxFee(_x, _x2) {
|
|
3553
|
+
return _ref2.apply(this, arguments);
|
|
3554
|
+
};
|
|
3555
|
+
}();
|
|
3556
|
+
|
|
3477
3557
|
var AssetsPallet = /*#__PURE__*/function () {
|
|
3478
3558
|
function AssetsPallet() {
|
|
3479
3559
|
_classCallCheck(this, AssetsPallet);
|
|
@@ -4010,331 +4090,88 @@ var getOriginFeeDetails = /*#__PURE__*/function () {
|
|
|
4010
4090
|
};
|
|
4011
4091
|
}();
|
|
4012
4092
|
|
|
4013
|
-
var
|
|
4014
|
-
var
|
|
4015
|
-
|
|
4016
|
-
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
4017
|
-
throwUnsupportedCurrency(feeAsset, origin);
|
|
4018
|
-
}
|
|
4019
|
-
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
4020
|
-
};
|
|
4021
|
-
|
|
4022
|
-
var isAssetHub = function isAssetHub(chain) {
|
|
4023
|
-
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
4024
|
-
};
|
|
4025
|
-
var isBridgeHub = function isBridgeHub(chain) {
|
|
4026
|
-
return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
|
|
4027
|
-
};
|
|
4028
|
-
var isPeople = function isPeople(chain) {
|
|
4029
|
-
return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
|
|
4030
|
-
};
|
|
4031
|
-
var isSystemPara = function isSystemPara(chain) {
|
|
4032
|
-
return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
|
|
4033
|
-
};
|
|
4034
|
-
var mul = function mul(v, num) {
|
|
4035
|
-
var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
|
|
4036
|
-
return v * num / den;
|
|
4037
|
-
};
|
|
4038
|
-
var padFee = function padFee(raw, origin, dest, side) {
|
|
4039
|
-
var relayOrigin = isRelayChain(origin);
|
|
4040
|
-
var relayDest = isRelayChain(dest);
|
|
4041
|
-
var sysParaOrigin = isSystemPara(origin);
|
|
4042
|
-
var sysParaDest = isSystemPara(dest);
|
|
4043
|
-
var relayToPara = relayOrigin && !relayDest;
|
|
4044
|
-
var sysParaToPara = sysParaOrigin && !sysParaDest;
|
|
4045
|
-
var paraToPara = !relayOrigin && !sysParaOrigin;
|
|
4046
|
-
if (sysParaToPara) return raw * 40n;
|
|
4047
|
-
if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
|
|
4048
|
-
if (paraToPara && side == 'origin' && origin === 'Mythos' && dest !== 'Ethereum') {
|
|
4049
|
-
return 150000000000000000n;
|
|
4050
|
-
}
|
|
4051
|
-
if (paraToPara) return mul(raw, 130n, 100n);
|
|
4052
|
-
// apply default 30% padding
|
|
4053
|
-
return mul(raw, 130n, 100n);
|
|
4054
|
-
};
|
|
4055
|
-
var padFeeBy = function padFeeBy(amount, percent) {
|
|
4056
|
-
return mul(amount, BigInt(100 + percent), 100n);
|
|
4057
|
-
};
|
|
4058
|
-
|
|
4059
|
-
var determineAddress = function determineAddress(chain, address, senderAddress) {
|
|
4060
|
-
if (isChainEvm(chain)) {
|
|
4061
|
-
return isAddress(address) ? address : senderAddress;
|
|
4062
|
-
}
|
|
4063
|
-
return isAddress(address) ? senderAddress : address;
|
|
4064
|
-
};
|
|
4065
|
-
var getReverseTxFee = /*#__PURE__*/function () {
|
|
4066
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
|
|
4067
|
-
var api, origin, destination, senderAddress, address, currency, toAddress, fromAddress, tx, rawFee;
|
|
4093
|
+
var dryRun = /*#__PURE__*/function () {
|
|
4094
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
4095
|
+
var api, senderAddress, origin;
|
|
4068
4096
|
return _regenerator().w(function (_context) {
|
|
4069
|
-
while (1) switch (_context.n) {
|
|
4097
|
+
while (1) switch (_context.p = _context.n) {
|
|
4070
4098
|
case 0:
|
|
4071
|
-
api =
|
|
4072
|
-
|
|
4073
|
-
fromAddress = determineAddress(destination, address, senderAddress);
|
|
4099
|
+
api = options.api, senderAddress = options.senderAddress, origin = options.origin;
|
|
4100
|
+
validateAddress(senderAddress, origin, false);
|
|
4074
4101
|
_context.n = 1;
|
|
4075
|
-
return
|
|
4076
|
-
amount: currency.amount
|
|
4077
|
-
})).build();
|
|
4102
|
+
return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4078
4103
|
case 1:
|
|
4079
|
-
|
|
4104
|
+
_context.p = 1;
|
|
4080
4105
|
_context.n = 2;
|
|
4081
|
-
return
|
|
4106
|
+
return dryRunInternal(options);
|
|
4082
4107
|
case 2:
|
|
4083
|
-
|
|
4084
|
-
|
|
4108
|
+
return _context.a(2, _context.v);
|
|
4109
|
+
case 3:
|
|
4110
|
+
_context.p = 3;
|
|
4111
|
+
_context.n = 4;
|
|
4112
|
+
return api.disconnect();
|
|
4113
|
+
case 4:
|
|
4114
|
+
return _context.f(3);
|
|
4115
|
+
case 5:
|
|
4116
|
+
return _context.a(2);
|
|
4085
4117
|
}
|
|
4086
|
-
}, _callee);
|
|
4118
|
+
}, _callee, null, [[1,, 3, 5]]);
|
|
4087
4119
|
}));
|
|
4088
|
-
return function
|
|
4089
|
-
return
|
|
4120
|
+
return function dryRun(_x) {
|
|
4121
|
+
return _ref.apply(this, arguments);
|
|
4090
4122
|
};
|
|
4091
4123
|
}();
|
|
4092
4124
|
|
|
4093
|
-
var
|
|
4094
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(
|
|
4095
|
-
var
|
|
4125
|
+
var dryRunOrigin = /*#__PURE__*/function () {
|
|
4126
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
4127
|
+
var api, chain, address, result;
|
|
4096
4128
|
return _regenerator().w(function (_context) {
|
|
4097
|
-
while (1) switch (_context.n) {
|
|
4129
|
+
while (1) switch (_context.p = _context.n) {
|
|
4098
4130
|
case 0:
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
return _context.a(2, undefined);
|
|
4131
|
+
api = options.api, chain = options.chain, address = options.address;
|
|
4132
|
+
validateAddress(address, chain, false);
|
|
4133
|
+
_context.n = 1;
|
|
4134
|
+
return api.init(chain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4104
4135
|
case 1:
|
|
4105
|
-
|
|
4136
|
+
_context.p = 1;
|
|
4106
4137
|
_context.n = 2;
|
|
4107
|
-
return
|
|
4108
|
-
api: api,
|
|
4109
|
-
chain: origin,
|
|
4110
|
-
address: senderAddress
|
|
4111
|
-
});
|
|
4138
|
+
return api.getDryRunCall(options);
|
|
4112
4139
|
case 2:
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
isNativeAssetToDest = isSymbolMatch(asset.symbol, getNativeAssetSymbol(destination));
|
|
4116
|
-
if (!(isNativeAssetToOrigin && isNativeAssetToDest)) {
|
|
4140
|
+
result = _context.v;
|
|
4141
|
+
if (!result.success) {
|
|
4117
4142
|
_context.n = 3;
|
|
4118
4143
|
break;
|
|
4119
4144
|
}
|
|
4120
|
-
return _context.a(2,
|
|
4145
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, result), {}, {
|
|
4146
|
+
currency: getNativeAssetSymbol(chain)
|
|
4147
|
+
}));
|
|
4121
4148
|
case 3:
|
|
4122
|
-
|
|
4123
|
-
_context.n = 5;
|
|
4124
|
-
break;
|
|
4125
|
-
}
|
|
4126
|
-
isSufficientNative = balanceNative - edNative - feeNative > 0n;
|
|
4127
|
-
_context.n = 4;
|
|
4128
|
-
return getAssetBalance({
|
|
4129
|
-
api: api,
|
|
4130
|
-
chain: origin,
|
|
4131
|
-
address: senderAddress,
|
|
4132
|
-
currency: currency
|
|
4133
|
-
});
|
|
4149
|
+
return _context.a(2, result);
|
|
4134
4150
|
case 4:
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
return _context.a(2, isSufficientNative && isSufficientAsset);
|
|
4151
|
+
_context.p = 4;
|
|
4152
|
+
_context.n = 5;
|
|
4153
|
+
return api.disconnect();
|
|
4139
4154
|
case 5:
|
|
4140
|
-
return _context.
|
|
4155
|
+
return _context.f(4);
|
|
4141
4156
|
case 6:
|
|
4142
4157
|
return _context.a(2);
|
|
4143
4158
|
}
|
|
4144
|
-
}, _callee);
|
|
4159
|
+
}, _callee, null, [[1,, 4, 6]]);
|
|
4145
4160
|
}));
|
|
4146
|
-
return function
|
|
4161
|
+
return function dryRunOrigin(_x) {
|
|
4147
4162
|
return _ref.apply(this, arguments);
|
|
4148
4163
|
};
|
|
4149
4164
|
}();
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4165
|
+
|
|
4166
|
+
var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
4167
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ahApi) {
|
|
4168
|
+
var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, finalBridgeFee, finalAssethubExecutionFee;
|
|
4169
|
+
return _regenerator().w(function (_context) {
|
|
4170
|
+
while (1) switch (_context.n) {
|
|
4155
4171
|
case 0:
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
break;
|
|
4160
|
-
}
|
|
4161
|
-
return _context2.a(2, undefined);
|
|
4162
|
-
case 1:
|
|
4163
|
-
existentialDeposit = getExistentialDepositOrThrow(destination);
|
|
4164
|
-
_context2.n = 2;
|
|
4165
|
-
return getBalanceNativeInternal({
|
|
4166
|
-
api: api,
|
|
4167
|
-
chain: destination,
|
|
4168
|
-
address: address
|
|
4169
|
-
});
|
|
4170
|
-
case 2:
|
|
4171
|
-
nativeBalance = _context2.v;
|
|
4172
|
-
return _context2.a(2, nativeBalance + amount - existentialDeposit - feeNative > 0n);
|
|
4173
|
-
}
|
|
4174
|
-
}, _callee2);
|
|
4175
|
-
}));
|
|
4176
|
-
return function isSufficientDestination(_x9, _x0, _x1, _x10, _x11, _x12) {
|
|
4177
|
-
return _ref2.apply(this, arguments);
|
|
4178
|
-
};
|
|
4179
|
-
}();
|
|
4180
|
-
|
|
4181
|
-
var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
4182
|
-
if (isRelayChain(origin)) return DOT_LOCATION;
|
|
4183
|
-
return {
|
|
4184
|
-
parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
|
|
4185
|
-
interior: {
|
|
4186
|
-
X1: [{
|
|
4187
|
-
Parachain: getParaId(origin)
|
|
4188
|
-
}]
|
|
4189
|
-
}
|
|
4190
|
-
};
|
|
4191
|
-
};
|
|
4192
|
-
var getDestXcmFee = /*#__PURE__*/function () {
|
|
4193
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
4194
|
-
var api, origin, hopChain, destination, currency, forwardedXcms, asset, address, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, _fee, sufficient, dryRunResult, _fee2, fee, newForwardedXcms, destParaId;
|
|
4195
|
-
return _regenerator().w(function (_context2) {
|
|
4196
|
-
while (1) switch (_context2.n) {
|
|
4197
|
-
case 0:
|
|
4198
|
-
api = options.api, origin = options.origin, hopChain = options.prevChain, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, asset = options.asset, address = options.address, feeAsset = options.feeAsset, originFee = options.originFee, disableFallback = options.disableFallback;
|
|
4199
|
-
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4200
|
-
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
4201
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
4202
|
-
var originAsset, _t;
|
|
4203
|
-
return _regenerator().w(function (_context) {
|
|
4204
|
-
while (1) switch (_context.p = _context.n) {
|
|
4205
|
-
case 0:
|
|
4206
|
-
if (!(destination === 'Ethereum')) {
|
|
4207
|
-
_context.n = 1;
|
|
4208
|
-
break;
|
|
4209
|
-
}
|
|
4210
|
-
return _context.a(2, 0n);
|
|
4211
|
-
case 1:
|
|
4212
|
-
originAsset = findAssetInfoOrThrow(origin, currency, destination);
|
|
4213
|
-
if (!originAsset.location) {
|
|
4214
|
-
_context.n = 7;
|
|
4215
|
-
break;
|
|
4216
|
-
}
|
|
4217
|
-
_context.p = 2;
|
|
4218
|
-
_context.n = 3;
|
|
4219
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4220
|
-
destination: destination
|
|
4221
|
-
}), {
|
|
4222
|
-
location: originAsset.location
|
|
4223
|
-
});
|
|
4224
|
-
case 3:
|
|
4225
|
-
return _context.a(2, _context.v);
|
|
4226
|
-
case 4:
|
|
4227
|
-
_context.p = 4;
|
|
4228
|
-
_t = _context.v;
|
|
4229
|
-
if (!(_t instanceof InvalidCurrencyError)) {
|
|
4230
|
-
_context.n = 6;
|
|
4231
|
-
break;
|
|
4232
|
-
}
|
|
4233
|
-
_context.n = 5;
|
|
4234
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4235
|
-
destination: destination
|
|
4236
|
-
}), {
|
|
4237
|
-
symbol: originAsset.symbol
|
|
4238
|
-
});
|
|
4239
|
-
case 5:
|
|
4240
|
-
return _context.a(2, _context.v);
|
|
4241
|
-
case 6:
|
|
4242
|
-
throw _t;
|
|
4243
|
-
case 7:
|
|
4244
|
-
_context.n = 8;
|
|
4245
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4246
|
-
destination: destination
|
|
4247
|
-
}), {
|
|
4248
|
-
symbol: originAsset.symbol
|
|
4249
|
-
});
|
|
4250
|
-
case 8:
|
|
4251
|
-
return _context.a(2, _context.v);
|
|
4252
|
-
}
|
|
4253
|
-
}, _callee, null, [[2, 4]]);
|
|
4254
|
-
}));
|
|
4255
|
-
return function calcPaymentInfoFee() {
|
|
4256
|
-
return _ref2.apply(this, arguments);
|
|
4257
|
-
};
|
|
4258
|
-
}();
|
|
4259
|
-
if (!(!hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
|
|
4260
|
-
_context2.n = 3;
|
|
4261
|
-
break;
|
|
4262
|
-
}
|
|
4263
|
-
_context2.n = 1;
|
|
4264
|
-
return calcPaymentInfoFee();
|
|
4265
|
-
case 1:
|
|
4266
|
-
_fee = _context2.v;
|
|
4267
|
-
_context2.n = 2;
|
|
4268
|
-
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee);
|
|
4269
|
-
case 2:
|
|
4270
|
-
sufficient = _context2.v;
|
|
4271
|
-
return _context2.a(2, {
|
|
4272
|
-
fee: _fee,
|
|
4273
|
-
feeType: 'paymentInfo',
|
|
4274
|
-
sufficient: !hasDryRunSupport(destination) ? sufficient : false
|
|
4275
|
-
});
|
|
4276
|
-
case 3:
|
|
4277
|
-
_context2.n = 4;
|
|
4278
|
-
return api.getDryRunXcm({
|
|
4279
|
-
originLocation: addXcmVersionHeader(createOriginLocation(hopChain, destination), Version.V4),
|
|
4280
|
-
xcm: forwardedXcms[1][0],
|
|
4281
|
-
chain: destination,
|
|
4282
|
-
origin: origin,
|
|
4283
|
-
asset: asset,
|
|
4284
|
-
originFee: originFee,
|
|
4285
|
-
feeAsset: resolvedFeeAsset,
|
|
4286
|
-
amount: BigInt(currency.amount) < 2n ? 2n : BigInt(currency.amount)
|
|
4287
|
-
});
|
|
4288
|
-
case 4:
|
|
4289
|
-
dryRunResult = _context2.v;
|
|
4290
|
-
if (dryRunResult.success) {
|
|
4291
|
-
_context2.n = 7;
|
|
4292
|
-
break;
|
|
4293
|
-
}
|
|
4294
|
-
if (!disableFallback) {
|
|
4295
|
-
_context2.n = 5;
|
|
4296
|
-
break;
|
|
4297
|
-
}
|
|
4298
|
-
return _context2.a(2, {
|
|
4299
|
-
dryRunError: dryRunResult.failureReason
|
|
4300
|
-
});
|
|
4301
|
-
case 5:
|
|
4302
|
-
_context2.n = 6;
|
|
4303
|
-
return calcPaymentInfoFee();
|
|
4304
|
-
case 6:
|
|
4305
|
-
_fee2 = _context2.v;
|
|
4306
|
-
return _context2.a(2, {
|
|
4307
|
-
fee: _fee2,
|
|
4308
|
-
feeType: 'paymentInfo',
|
|
4309
|
-
dryRunError: dryRunResult.failureReason,
|
|
4310
|
-
sufficient: false
|
|
4311
|
-
});
|
|
4312
|
-
case 7:
|
|
4313
|
-
fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
4314
|
-
return _context2.a(2, {
|
|
4315
|
-
fee: fee,
|
|
4316
|
-
feeType: 'dryRun',
|
|
4317
|
-
sufficient: true,
|
|
4318
|
-
forwardedXcms: newForwardedXcms,
|
|
4319
|
-
destParaId: destParaId
|
|
4320
|
-
});
|
|
4321
|
-
}
|
|
4322
|
-
}, _callee2);
|
|
4323
|
-
}));
|
|
4324
|
-
return function getDestXcmFee(_x) {
|
|
4325
|
-
return _ref.apply(this, arguments);
|
|
4326
|
-
};
|
|
4327
|
-
}();
|
|
4328
|
-
|
|
4329
|
-
var getParaEthTransferFees = /*#__PURE__*/function () {
|
|
4330
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(ahApi) {
|
|
4331
|
-
var DEFAULT_FEE, feeStorageItem, leFeeHex, bytes, reversedHex, validReversedHex, leFee, transferBridgeFee, finalBridgeFee, finalAssethubExecutionFee;
|
|
4332
|
-
return _regenerator().w(function (_context) {
|
|
4333
|
-
while (1) switch (_context.n) {
|
|
4334
|
-
case 0:
|
|
4335
|
-
DEFAULT_FEE = 2750872500000n;
|
|
4336
|
-
_context.n = 1;
|
|
4337
|
-
return ahApi.getFromRpc('state', 'getStorage', '0x5fbc5c7ba58845ad1f1a9a7c5bc12fad');
|
|
4172
|
+
DEFAULT_FEE = 2750872500000n;
|
|
4173
|
+
_context.n = 1;
|
|
4174
|
+
return ahApi.getFromRpc('state', 'getStorage', '0x5fbc5c7ba58845ad1f1a9a7c5bc12fad');
|
|
4338
4175
|
case 1:
|
|
4339
4176
|
feeStorageItem = _context.v;
|
|
4340
4177
|
leFeeHex = feeStorageItem.replace('0x', '');
|
|
@@ -5056,340 +4893,63 @@ var addEthereumBridgeFees = /*#__PURE__*/function () {
|
|
|
5056
4893
|
};
|
|
5057
4894
|
}();
|
|
5058
4895
|
|
|
5059
|
-
var
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
4896
|
+
var AssetManagerPallet = /*#__PURE__*/function () {
|
|
4897
|
+
function AssetManagerPallet() {
|
|
4898
|
+
_classCallCheck(this, AssetManagerPallet);
|
|
4899
|
+
}
|
|
4900
|
+
return _createClass(AssetManagerPallet, [{
|
|
4901
|
+
key: "setBalance",
|
|
4902
|
+
value: function setBalance(address, asset) {
|
|
4903
|
+
assertHasId(asset);
|
|
4904
|
+
var assetId = asset.assetId,
|
|
4905
|
+
amount = asset.amount;
|
|
4906
|
+
return Promise.resolve({
|
|
4907
|
+
balanceTx: {
|
|
4908
|
+
module: 'AssetManager',
|
|
4909
|
+
method: 'updateBalance',
|
|
4910
|
+
parameters: {
|
|
4911
|
+
who: {
|
|
4912
|
+
Id: address
|
|
4913
|
+
},
|
|
4914
|
+
currency_id: {
|
|
4915
|
+
ForeignAsset: assetId
|
|
4916
|
+
},
|
|
4917
|
+
amount: amount
|
|
4918
|
+
}
|
|
4919
|
+
}
|
|
4920
|
+
});
|
|
5069
4921
|
}
|
|
4922
|
+
}]);
|
|
4923
|
+
}();
|
|
4924
|
+
|
|
4925
|
+
var BalancesPallet = /*#__PURE__*/function () {
|
|
4926
|
+
function BalancesPallet() {
|
|
4927
|
+
_classCallCheck(this, BalancesPallet);
|
|
5070
4928
|
}
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
var
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
4929
|
+
return _createClass(BalancesPallet, [{
|
|
4930
|
+
key: "setBalance",
|
|
4931
|
+
value: function setBalance(address, assetInfo, chain) {
|
|
4932
|
+
var amount = assetInfo.amount;
|
|
4933
|
+
var notUseId = chain.startsWith('Hydration') || chain === 'Basilisk' || isChainEvm(chain);
|
|
4934
|
+
return Promise.resolve({
|
|
4935
|
+
balanceTx: {
|
|
4936
|
+
module: 'Balances',
|
|
4937
|
+
method: 'force_set_balance',
|
|
4938
|
+
parameters: {
|
|
4939
|
+
who: notUseId ? address : {
|
|
4940
|
+
Id: address
|
|
4941
|
+
},
|
|
4942
|
+
new_free: amount
|
|
4943
|
+
}
|
|
4944
|
+
}
|
|
4945
|
+
});
|
|
5082
4946
|
}
|
|
5083
|
-
}
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
};
|
|
5090
|
-
var dryRunInternal = /*#__PURE__*/function () {
|
|
5091
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
5092
|
-
var _traversalResult$brid, _traversalResult$asse, _traversalResult$dest;
|
|
5093
|
-
var api, origin, destination, currency, tx, senderAddress, feeAsset, swapConfig, resolvedFeeAsset, asset, amount, originDryRun, initialForwardedXcms, initialDestParaId, processHop, traversalResult, assetHubChain, bridgeHubChain, processedBridgeHub, bridgeHubHopIndex, originWithCurrency, assetHubWithCurrency, bridgeHubWithCurrency, destinationWithCurrency, _getFailureInfo, failureReason, failureChain, _t;
|
|
5094
|
-
return _regenerator().w(function (_context2) {
|
|
5095
|
-
while (1) switch (_context2.n) {
|
|
5096
|
-
case 0:
|
|
5097
|
-
api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset, swapConfig = options.swapConfig;
|
|
5098
|
-
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
5099
|
-
asset = findAssetInfoOrThrow(origin, currency, destination);
|
|
5100
|
-
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
5101
|
-
_context2.n = 1;
|
|
5102
|
-
return api.getDryRunCall({
|
|
5103
|
-
tx: tx,
|
|
5104
|
-
chain: origin,
|
|
5105
|
-
address: senderAddress,
|
|
5106
|
-
asset: _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5107
|
-
amount: amount
|
|
5108
|
-
}),
|
|
5109
|
-
feeAsset: resolvedFeeAsset
|
|
5110
|
-
});
|
|
5111
|
-
case 1:
|
|
5112
|
-
originDryRun = _context2.v;
|
|
5113
|
-
if (originDryRun.success) {
|
|
5114
|
-
_context2.n = 2;
|
|
5115
|
-
break;
|
|
5116
|
-
}
|
|
5117
|
-
return _context2.a(2, {
|
|
5118
|
-
failureReason: originDryRun.failureReason,
|
|
5119
|
-
failureChain: 'origin',
|
|
5120
|
-
origin: originDryRun,
|
|
5121
|
-
hops: []
|
|
5122
|
-
});
|
|
5123
|
-
case 2:
|
|
5124
|
-
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
5125
|
-
processHop = /*#__PURE__*/function () {
|
|
5126
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
5127
|
-
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, isDestination, hopDryRun, hopCurrency;
|
|
5128
|
-
return _regenerator().w(function (_context) {
|
|
5129
|
-
while (1) switch (_context.n) {
|
|
5130
|
-
case 0:
|
|
5131
|
-
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange, isDestination = params.isDestination;
|
|
5132
|
-
if (hasDryRunSupport(currentChain)) {
|
|
5133
|
-
_context.n = 1;
|
|
5134
|
-
break;
|
|
5135
|
-
}
|
|
5136
|
-
return _context.a(2, {
|
|
5137
|
-
success: false,
|
|
5138
|
-
failureReason: "DryRunApi is not available on chain ".concat(currentChain)
|
|
5139
|
-
});
|
|
5140
|
-
case 1:
|
|
5141
|
-
_context.n = 2;
|
|
5142
|
-
return hopApi.getDryRunXcm({
|
|
5143
|
-
originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain), Version.V4),
|
|
5144
|
-
xcm: forwardedXcms[1][0],
|
|
5145
|
-
chain: currentChain,
|
|
5146
|
-
origin: currentOrigin,
|
|
5147
|
-
asset: currentAsset,
|
|
5148
|
-
feeAsset: resolvedFeeAsset,
|
|
5149
|
-
originFee: originDryRun.fee,
|
|
5150
|
-
amount: amount
|
|
5151
|
-
});
|
|
5152
|
-
case 2:
|
|
5153
|
-
hopDryRun = _context.v;
|
|
5154
|
-
if (!hopDryRun.success) {
|
|
5155
|
-
_context.n = 3;
|
|
5156
|
-
break;
|
|
5157
|
-
}
|
|
5158
|
-
if (destination === 'Ethereum' && (currentChain.includes('AssetHub') || currentChain.includes('BridgeHub'))) {
|
|
5159
|
-
hopCurrency = getNativeAssetSymbol(currentChain);
|
|
5160
|
-
} else if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
|
|
5161
|
-
hopCurrency = findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo).symbol;
|
|
5162
|
-
} else if (isDestination) {
|
|
5163
|
-
hopCurrency = findAssetOnDestOrThrow(origin, currentChain, currency).symbol;
|
|
5164
|
-
} else {
|
|
5165
|
-
hopCurrency = asset.symbol;
|
|
5166
|
-
}
|
|
5167
|
-
return _context.a(2, _objectSpread2(_objectSpread2({}, hopDryRun), {}, {
|
|
5168
|
-
currency: hopCurrency
|
|
5169
|
-
}));
|
|
5170
|
-
case 3:
|
|
5171
|
-
return _context.a(2, hopDryRun);
|
|
5172
|
-
}
|
|
5173
|
-
}, _callee);
|
|
5174
|
-
}));
|
|
5175
|
-
return function processHop(_x2) {
|
|
5176
|
-
return _ref2.apply(this, arguments);
|
|
5177
|
-
};
|
|
5178
|
-
}();
|
|
5179
|
-
_context2.n = 3;
|
|
5180
|
-
return traverseXcmHops({
|
|
5181
|
-
api: api,
|
|
5182
|
-
origin: origin,
|
|
5183
|
-
destination: destination,
|
|
5184
|
-
currency: currency,
|
|
5185
|
-
initialForwardedXcms: initialForwardedXcms,
|
|
5186
|
-
initialDestParaId: initialDestParaId,
|
|
5187
|
-
swapConfig: swapConfig,
|
|
5188
|
-
processHop: processHop,
|
|
5189
|
-
shouldContinue: function shouldContinue(hopResult) {
|
|
5190
|
-
return hopResult.success;
|
|
5191
|
-
},
|
|
5192
|
-
extractNextHopData: function extractNextHopData(hopResult) {
|
|
5193
|
-
return {
|
|
5194
|
-
forwardedXcms: hopResult.success ? hopResult.forwardedXcms : undefined,
|
|
5195
|
-
destParaId: hopResult.success ? hopResult.destParaId : undefined
|
|
5196
|
-
};
|
|
5197
|
-
}
|
|
5198
|
-
});
|
|
5199
|
-
case 3:
|
|
5200
|
-
traversalResult = _context2.v;
|
|
5201
|
-
// Process Ethereum bridge fees
|
|
5202
|
-
assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
|
|
5203
|
-
bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
|
|
5204
|
-
if (!((_traversalResult$brid = traversalResult.bridgeHub) !== null && _traversalResult$brid !== void 0 && _traversalResult$brid.success)) {
|
|
5205
|
-
_context2.n = 5;
|
|
5206
|
-
break;
|
|
5207
|
-
}
|
|
5208
|
-
_context2.n = 4;
|
|
5209
|
-
return addEthereumBridgeFees(api, traversalResult.bridgeHub, destination, assetHubChain);
|
|
5210
|
-
case 4:
|
|
5211
|
-
_t = _context2.v;
|
|
5212
|
-
_context2.n = 6;
|
|
5213
|
-
break;
|
|
5214
|
-
case 5:
|
|
5215
|
-
_t = traversalResult.bridgeHub;
|
|
5216
|
-
case 6:
|
|
5217
|
-
processedBridgeHub = _t;
|
|
5218
|
-
// Update bridge hub in hops if needed
|
|
5219
|
-
if (processedBridgeHub && processedBridgeHub.success && traversalResult.bridgeHub && traversalResult.bridgeHub.success && processedBridgeHub.fee !== traversalResult.bridgeHub.fee) {
|
|
5220
|
-
bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
|
|
5221
|
-
return hop.chain === bridgeHubChain;
|
|
5222
|
-
});
|
|
5223
|
-
if (bridgeHubHopIndex !== -1 && traversalResult.hops[bridgeHubHopIndex].result.success) {
|
|
5224
|
-
traversalResult.hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, traversalResult.hops[bridgeHubHopIndex].result), {}, {
|
|
5225
|
-
fee: processedBridgeHub.fee
|
|
5226
|
-
});
|
|
5227
|
-
}
|
|
5228
|
-
}
|
|
5229
|
-
originWithCurrency = originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
|
|
5230
|
-
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(origin)
|
|
5231
|
-
}) : originDryRun;
|
|
5232
|
-
assetHubWithCurrency = (_traversalResult$asse = traversalResult.assetHub) !== null && _traversalResult$asse !== void 0 && _traversalResult$asse.success ? _objectSpread2(_objectSpread2({}, traversalResult.assetHub), {}, {
|
|
5233
|
-
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(assetHubChain)
|
|
5234
|
-
}) : traversalResult.assetHub;
|
|
5235
|
-
bridgeHubWithCurrency = processedBridgeHub !== null && processedBridgeHub !== void 0 && processedBridgeHub.success ? _objectSpread2(_objectSpread2({}, processedBridgeHub), {}, {
|
|
5236
|
-
currency: getNativeAssetSymbol(bridgeHubChain)
|
|
5237
|
-
}) : processedBridgeHub;
|
|
5238
|
-
destinationWithCurrency = (_traversalResult$dest = traversalResult.destination) !== null && _traversalResult$dest !== void 0 && _traversalResult$dest.success ? _objectSpread2(_objectSpread2({}, traversalResult.destination), {}, {
|
|
5239
|
-
currency: asset === null || asset === void 0 ? void 0 : asset.symbol
|
|
5240
|
-
}) : traversalResult.destination;
|
|
5241
|
-
_getFailureInfo = getFailureInfo$1({
|
|
5242
|
-
destination: destinationWithCurrency,
|
|
5243
|
-
assetHub: assetHubWithCurrency,
|
|
5244
|
-
bridgeHub: bridgeHubWithCurrency
|
|
5245
|
-
}, traversalResult.hops), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
|
|
5246
|
-
return _context2.a(2, {
|
|
5247
|
-
failureReason: failureReason,
|
|
5248
|
-
failureChain: failureChain,
|
|
5249
|
-
origin: originWithCurrency,
|
|
5250
|
-
assetHub: assetHubWithCurrency,
|
|
5251
|
-
bridgeHub: bridgeHubWithCurrency,
|
|
5252
|
-
destination: destinationWithCurrency,
|
|
5253
|
-
hops: traversalResult.hops
|
|
5254
|
-
});
|
|
5255
|
-
}
|
|
5256
|
-
}, _callee2);
|
|
5257
|
-
}));
|
|
5258
|
-
return function dryRunInternal(_x) {
|
|
5259
|
-
return _ref.apply(this, arguments);
|
|
5260
|
-
};
|
|
5261
|
-
}();
|
|
5262
|
-
|
|
5263
|
-
var dryRun = /*#__PURE__*/function () {
|
|
5264
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
5265
|
-
var api, senderAddress, origin;
|
|
5266
|
-
return _regenerator().w(function (_context) {
|
|
5267
|
-
while (1) switch (_context.p = _context.n) {
|
|
5268
|
-
case 0:
|
|
5269
|
-
api = options.api, senderAddress = options.senderAddress, origin = options.origin;
|
|
5270
|
-
validateAddress(senderAddress, origin, false);
|
|
5271
|
-
_context.n = 1;
|
|
5272
|
-
return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
5273
|
-
case 1:
|
|
5274
|
-
_context.p = 1;
|
|
5275
|
-
_context.n = 2;
|
|
5276
|
-
return dryRunInternal(options);
|
|
5277
|
-
case 2:
|
|
5278
|
-
return _context.a(2, _context.v);
|
|
5279
|
-
case 3:
|
|
5280
|
-
_context.p = 3;
|
|
5281
|
-
_context.n = 4;
|
|
5282
|
-
return api.disconnect();
|
|
5283
|
-
case 4:
|
|
5284
|
-
return _context.f(3);
|
|
5285
|
-
case 5:
|
|
5286
|
-
return _context.a(2);
|
|
5287
|
-
}
|
|
5288
|
-
}, _callee, null, [[1,, 3, 5]]);
|
|
5289
|
-
}));
|
|
5290
|
-
return function dryRun(_x) {
|
|
5291
|
-
return _ref.apply(this, arguments);
|
|
5292
|
-
};
|
|
5293
|
-
}();
|
|
5294
|
-
|
|
5295
|
-
var dryRunOrigin = /*#__PURE__*/function () {
|
|
5296
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
5297
|
-
var api, chain, address, result;
|
|
5298
|
-
return _regenerator().w(function (_context) {
|
|
5299
|
-
while (1) switch (_context.p = _context.n) {
|
|
5300
|
-
case 0:
|
|
5301
|
-
api = options.api, chain = options.chain, address = options.address;
|
|
5302
|
-
validateAddress(address, chain, false);
|
|
5303
|
-
_context.n = 1;
|
|
5304
|
-
return api.init(chain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
5305
|
-
case 1:
|
|
5306
|
-
_context.p = 1;
|
|
5307
|
-
_context.n = 2;
|
|
5308
|
-
return api.getDryRunCall(options);
|
|
5309
|
-
case 2:
|
|
5310
|
-
result = _context.v;
|
|
5311
|
-
if (!result.success) {
|
|
5312
|
-
_context.n = 3;
|
|
5313
|
-
break;
|
|
5314
|
-
}
|
|
5315
|
-
return _context.a(2, _objectSpread2(_objectSpread2({}, result), {}, {
|
|
5316
|
-
currency: getNativeAssetSymbol(chain)
|
|
5317
|
-
}));
|
|
5318
|
-
case 3:
|
|
5319
|
-
return _context.a(2, result);
|
|
5320
|
-
case 4:
|
|
5321
|
-
_context.p = 4;
|
|
5322
|
-
_context.n = 5;
|
|
5323
|
-
return api.disconnect();
|
|
5324
|
-
case 5:
|
|
5325
|
-
return _context.f(4);
|
|
5326
|
-
case 6:
|
|
5327
|
-
return _context.a(2);
|
|
5328
|
-
}
|
|
5329
|
-
}, _callee, null, [[1,, 4, 6]]);
|
|
5330
|
-
}));
|
|
5331
|
-
return function dryRunOrigin(_x) {
|
|
5332
|
-
return _ref.apply(this, arguments);
|
|
5333
|
-
};
|
|
5334
|
-
}();
|
|
5335
|
-
|
|
5336
|
-
var AssetManagerPallet = /*#__PURE__*/function () {
|
|
5337
|
-
function AssetManagerPallet() {
|
|
5338
|
-
_classCallCheck(this, AssetManagerPallet);
|
|
5339
|
-
}
|
|
5340
|
-
return _createClass(AssetManagerPallet, [{
|
|
5341
|
-
key: "setBalance",
|
|
5342
|
-
value: function setBalance(address, asset) {
|
|
5343
|
-
assertHasId(asset);
|
|
5344
|
-
var assetId = asset.assetId,
|
|
5345
|
-
amount = asset.amount;
|
|
5346
|
-
return Promise.resolve({
|
|
5347
|
-
balanceTx: {
|
|
5348
|
-
module: 'AssetManager',
|
|
5349
|
-
method: 'updateBalance',
|
|
5350
|
-
parameters: {
|
|
5351
|
-
who: {
|
|
5352
|
-
Id: address
|
|
5353
|
-
},
|
|
5354
|
-
currency_id: {
|
|
5355
|
-
ForeignAsset: assetId
|
|
5356
|
-
},
|
|
5357
|
-
amount: amount
|
|
5358
|
-
}
|
|
5359
|
-
}
|
|
5360
|
-
});
|
|
5361
|
-
}
|
|
5362
|
-
}]);
|
|
5363
|
-
}();
|
|
5364
|
-
|
|
5365
|
-
var BalancesPallet = /*#__PURE__*/function () {
|
|
5366
|
-
function BalancesPallet() {
|
|
5367
|
-
_classCallCheck(this, BalancesPallet);
|
|
5368
|
-
}
|
|
5369
|
-
return _createClass(BalancesPallet, [{
|
|
5370
|
-
key: "setBalance",
|
|
5371
|
-
value: function setBalance(address, assetInfo, chain) {
|
|
5372
|
-
var amount = assetInfo.amount;
|
|
5373
|
-
var notUseId = chain.startsWith('Hydration') || chain === 'Basilisk' || isChainEvm(chain);
|
|
5374
|
-
return Promise.resolve({
|
|
5375
|
-
balanceTx: {
|
|
5376
|
-
module: 'Balances',
|
|
5377
|
-
method: 'force_set_balance',
|
|
5378
|
-
parameters: {
|
|
5379
|
-
who: notUseId ? address : {
|
|
5380
|
-
Id: address
|
|
5381
|
-
},
|
|
5382
|
-
new_free: amount
|
|
5383
|
-
}
|
|
5384
|
-
}
|
|
5385
|
-
});
|
|
5386
|
-
}
|
|
5387
|
-
}]);
|
|
5388
|
-
}();
|
|
5389
|
-
|
|
5390
|
-
var CurrenciesPallet = /*#__PURE__*/function () {
|
|
5391
|
-
function CurrenciesPallet() {
|
|
5392
|
-
_classCallCheck(this, CurrenciesPallet);
|
|
4947
|
+
}]);
|
|
4948
|
+
}();
|
|
4949
|
+
|
|
4950
|
+
var CurrenciesPallet = /*#__PURE__*/function () {
|
|
4951
|
+
function CurrenciesPallet() {
|
|
4952
|
+
_classCallCheck(this, CurrenciesPallet);
|
|
5393
4953
|
}
|
|
5394
4954
|
return _createClass(CurrenciesPallet, [{
|
|
5395
4955
|
key: "setBalance",
|
|
@@ -5977,7 +5537,7 @@ var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
|
|
|
5977
5537
|
};
|
|
5978
5538
|
}();
|
|
5979
5539
|
|
|
5980
|
-
var getFailureInfo = function getFailureInfo(chains, hops) {
|
|
5540
|
+
var getFailureInfo$1 = function getFailureInfo(chains, hops) {
|
|
5981
5541
|
var _chains$origin, _chains$assetHub, _chains$bridgeHub, _chains$destination;
|
|
5982
5542
|
// Check standard chains first for backwards compatibility
|
|
5983
5543
|
if ((_chains$origin = chains.origin) !== null && _chains$origin !== void 0 && _chains$origin.dryRunError) return {
|
|
@@ -6104,7 +5664,7 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
6104
5664
|
}),
|
|
6105
5665
|
hops: []
|
|
6106
5666
|
};
|
|
6107
|
-
_getFailureInfo = getFailureInfo({
|
|
5667
|
+
_getFailureInfo = getFailureInfo$1({
|
|
6108
5668
|
origin: _result.origin,
|
|
6109
5669
|
destination: _result.destination
|
|
6110
5670
|
}, []), _failureChain = _getFailureInfo.failureChain, _failureReason = _getFailureInfo.failureReason;
|
|
@@ -6316,7 +5876,7 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
6316
5876
|
};
|
|
6317
5877
|
})
|
|
6318
5878
|
});
|
|
6319
|
-
_getFailureInfo2 = getFailureInfo({
|
|
5879
|
+
_getFailureInfo2 = getFailureInfo$1({
|
|
6320
5880
|
origin: result.origin,
|
|
6321
5881
|
assetHub: result.assetHub,
|
|
6322
5882
|
bridgeHub: result.bridgeHub,
|
|
@@ -6513,1162 +6073,1526 @@ var transferRelayToPara = /*#__PURE__*/function () {
|
|
|
6513
6073
|
};
|
|
6514
6074
|
}();
|
|
6515
6075
|
|
|
6516
|
-
var send = /*#__PURE__*/function () {
|
|
6517
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
6518
|
-
var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, amount, finalAmount, originVersion, destVersion, resolvedVersion, isLocalTransfer, overriddenAsset, resolvedAsset, finalAsset, finalVersion, normalizedAsset;
|
|
6076
|
+
var send = /*#__PURE__*/function () {
|
|
6077
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
6078
|
+
var api, origin, currency, feeAsset, address, destination, paraIdTo, version, senderAddress, ahAddress, pallet, method, isBridge, assetCheckEnabled, asset, resolvedFeeAsset, amount, finalAmount, originVersion, destVersion, resolvedVersion, isLocalTransfer, overriddenAsset, resolvedAsset, finalAsset, finalVersion, normalizedAsset;
|
|
6079
|
+
return _regenerator().w(function (_context) {
|
|
6080
|
+
while (1) switch (_context.n) {
|
|
6081
|
+
case 0:
|
|
6082
|
+
api = options.api, origin = options.from, currency = options.currency, feeAsset = options.feeAsset, address = options.address, destination = options.to, paraIdTo = options.paraIdTo, version = options.version, senderAddress = options.senderAddress, ahAddress = options.ahAddress, pallet = options.pallet, method = options.method;
|
|
6083
|
+
validateCurrency(currency, feeAsset);
|
|
6084
|
+
validateDestination(origin, destination);
|
|
6085
|
+
validateDestinationAddress(address, destination);
|
|
6086
|
+
if (senderAddress) validateAddress(senderAddress, origin, false);
|
|
6087
|
+
isBridge = !isTLocation(destination) && isDotKsmBridge(origin, destination);
|
|
6088
|
+
assetCheckEnabled = shouldPerformAssetCheck(origin, currency);
|
|
6089
|
+
validateAssetSpecifiers(assetCheckEnabled, currency);
|
|
6090
|
+
asset = resolveAsset(currency, origin, destination, assetCheckEnabled);
|
|
6091
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
6092
|
+
validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
|
|
6093
|
+
amount = Array.isArray(currency) ? 0n : abstractDecimals(currency.amount, asset === null || asset === void 0 ? void 0 : asset.decimals, api); // Ensure amount is at least 2 to avoid Rust panic (only for non-array currencies)
|
|
6094
|
+
finalAmount = !Array.isArray(currency) && amount < 2n ? 2n : amount;
|
|
6095
|
+
originVersion = getChainVersion(origin);
|
|
6096
|
+
destVersion = !isTLocation(destination) ? getChainVersion(destination) : undefined;
|
|
6097
|
+
resolvedVersion = selectXcmVersion(version, originVersion, destVersion);
|
|
6098
|
+
if (!isRelayChain(origin)) {
|
|
6099
|
+
_context.n = 6;
|
|
6100
|
+
break;
|
|
6101
|
+
}
|
|
6102
|
+
if (!(destination === 'Ethereum')) {
|
|
6103
|
+
_context.n = 1;
|
|
6104
|
+
break;
|
|
6105
|
+
}
|
|
6106
|
+
throw new InvalidParameterError('Transfers from relay chain to Ethereum are not supported.');
|
|
6107
|
+
case 1:
|
|
6108
|
+
if (asset) {
|
|
6109
|
+
_context.n = 2;
|
|
6110
|
+
break;
|
|
6111
|
+
}
|
|
6112
|
+
throw new InvalidParameterError('Asset is required for relay chain to relay chain transfers.');
|
|
6113
|
+
case 2:
|
|
6114
|
+
isLocalTransfer = origin === destination;
|
|
6115
|
+
if (!isLocalTransfer) {
|
|
6116
|
+
_context.n = 5;
|
|
6117
|
+
break;
|
|
6118
|
+
}
|
|
6119
|
+
if (!isTLocation(address)) {
|
|
6120
|
+
_context.n = 3;
|
|
6121
|
+
break;
|
|
6122
|
+
}
|
|
6123
|
+
throw new InvalidAddressError('Location address is not supported for local transfers.');
|
|
6124
|
+
case 3:
|
|
6125
|
+
_context.n = 4;
|
|
6126
|
+
return api.init(origin, TX_CLIENT_TIMEOUT_MS);
|
|
6127
|
+
case 4:
|
|
6128
|
+
return _context.a(2, api.callTxMethod({
|
|
6129
|
+
module: 'Balances',
|
|
6130
|
+
method: 'transfer_keep_alive',
|
|
6131
|
+
parameters: {
|
|
6132
|
+
dest: {
|
|
6133
|
+
Id: address
|
|
6134
|
+
},
|
|
6135
|
+
value: finalAmount
|
|
6136
|
+
}
|
|
6137
|
+
}));
|
|
6138
|
+
case 5:
|
|
6139
|
+
return _context.a(2, transferRelayToPara({
|
|
6140
|
+
api: api,
|
|
6141
|
+
origin: origin,
|
|
6142
|
+
destination: destination,
|
|
6143
|
+
address: address,
|
|
6144
|
+
assetInfo: _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
6145
|
+
amount: finalAmount
|
|
6146
|
+
}),
|
|
6147
|
+
paraIdTo: paraIdTo,
|
|
6148
|
+
version: resolvedVersion,
|
|
6149
|
+
pallet: pallet,
|
|
6150
|
+
method: method
|
|
6151
|
+
}));
|
|
6152
|
+
case 6:
|
|
6153
|
+
overriddenAsset = resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset);
|
|
6154
|
+
_context.n = 7;
|
|
6155
|
+
return api.init(origin, TX_CLIENT_TIMEOUT_MS);
|
|
6156
|
+
case 7:
|
|
6157
|
+
// In case asset check is disabled, we create asset object from currency symbol
|
|
6158
|
+
resolvedAsset = asset !== null && asset !== void 0 ? asset : {
|
|
6159
|
+
symbol: 'symbol' in currency ? currency.symbol : undefined
|
|
6160
|
+
};
|
|
6161
|
+
finalAsset = Array.isArray(currency) ? _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
|
|
6162
|
+
amount: 0n,
|
|
6163
|
+
assetId: '1'
|
|
6164
|
+
}) : _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
|
|
6165
|
+
amount: finalAmount
|
|
6166
|
+
});
|
|
6167
|
+
finalVersion = selectXcmVersion(version, originVersion, destVersion);
|
|
6168
|
+
normalizedAsset = finalAsset.location ? _objectSpread2(_objectSpread2({}, finalAsset), {}, {
|
|
6169
|
+
location: normalizeLocation(finalAsset.location, finalVersion)
|
|
6170
|
+
}) : finalAsset;
|
|
6171
|
+
return _context.a(2, getChain(origin).transfer({
|
|
6172
|
+
api: api,
|
|
6173
|
+
assetInfo: normalizedAsset,
|
|
6174
|
+
currency: currency,
|
|
6175
|
+
feeAsset: resolvedFeeAsset,
|
|
6176
|
+
feeCurrency: feeAsset,
|
|
6177
|
+
address: address,
|
|
6178
|
+
to: destination,
|
|
6179
|
+
paraIdTo: paraIdTo,
|
|
6180
|
+
overriddenAsset: overriddenAsset,
|
|
6181
|
+
version: finalVersion,
|
|
6182
|
+
senderAddress: senderAddress,
|
|
6183
|
+
ahAddress: ahAddress,
|
|
6184
|
+
pallet: pallet,
|
|
6185
|
+
method: method
|
|
6186
|
+
}));
|
|
6187
|
+
}
|
|
6188
|
+
}, _callee);
|
|
6189
|
+
}));
|
|
6190
|
+
return function send(_x) {
|
|
6191
|
+
return _ref.apply(this, arguments);
|
|
6192
|
+
};
|
|
6193
|
+
}();
|
|
6194
|
+
|
|
6195
|
+
var buildTypeAndThenCall = function buildTypeAndThenCall(_ref, isDotAsset, customXcm, assets) {
|
|
6196
|
+
var origin = _ref.origin,
|
|
6197
|
+
reserve = _ref.reserve,
|
|
6198
|
+
dest = _ref.dest,
|
|
6199
|
+
assetInfo = _ref.assetInfo,
|
|
6200
|
+
version = _ref.options.version;
|
|
6201
|
+
var feeAssetLocation = !isDotAsset ? RELAY_LOCATION : assetInfo.location;
|
|
6202
|
+
var finalDest = origin.chain === reserve.chain ? dest.chain : reserve.chain;
|
|
6203
|
+
var destLocation = createDestination(version, origin.chain, finalDest, getParaId(finalDest));
|
|
6204
|
+
var reserveType = origin.chain === reserve.chain ? 'LocalReserve' : 'DestinationReserve';
|
|
6205
|
+
var feeMultiAsset = createAsset(version, assetInfo.amount, feeAssetLocation);
|
|
6206
|
+
return {
|
|
6207
|
+
module: 'PolkadotXcm',
|
|
6208
|
+
method: 'transfer_assets_using_type_and_then',
|
|
6209
|
+
parameters: {
|
|
6210
|
+
dest: addXcmVersionHeader(destLocation, version),
|
|
6211
|
+
assets: addXcmVersionHeader(assets, version),
|
|
6212
|
+
assets_transfer_type: reserveType,
|
|
6213
|
+
remote_fees_id: addXcmVersionHeader(feeMultiAsset.id, version),
|
|
6214
|
+
fees_transfer_type: reserveType,
|
|
6215
|
+
custom_xcm_on_dest: addXcmVersionHeader(customXcm, version),
|
|
6216
|
+
weight_limit: 'Unlimited'
|
|
6217
|
+
}
|
|
6218
|
+
};
|
|
6219
|
+
};
|
|
6220
|
+
|
|
6221
|
+
var FEE_PADDING_PERCENTAGE$2 = 20;
|
|
6222
|
+
var FEE_PADDING_HYDRATION = 150;
|
|
6223
|
+
var computeInstructionFee = /*#__PURE__*/function () {
|
|
6224
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, version, xcm) {
|
|
6225
|
+
var chain, api, _t, _t2, _t3;
|
|
6226
|
+
return _regenerator().w(function (_context) {
|
|
6227
|
+
while (1) switch (_context.n) {
|
|
6228
|
+
case 0:
|
|
6229
|
+
chain = _ref.chain, api = _ref.api;
|
|
6230
|
+
_t = padFeeBy;
|
|
6231
|
+
_context.n = 1;
|
|
6232
|
+
return api.getXcmPaymentApiFee(chain, addXcmVersionHeader(xcm, version), {
|
|
6233
|
+
location: DOT_LOCATION
|
|
6234
|
+
}, true);
|
|
6235
|
+
case 1:
|
|
6236
|
+
_t2 = _context.v;
|
|
6237
|
+
_t3 = chain === 'Hydration' ? FEE_PADDING_HYDRATION : FEE_PADDING_PERCENTAGE$2;
|
|
6238
|
+
return _context.a(2, _t(_t2, _t3));
|
|
6239
|
+
}
|
|
6240
|
+
}, _callee);
|
|
6241
|
+
}));
|
|
6242
|
+
return function computeInstructionFee(_x, _x2, _x3) {
|
|
6243
|
+
return _ref2.apply(this, arguments);
|
|
6244
|
+
};
|
|
6245
|
+
}();
|
|
6246
|
+
var computeAllFees = /*#__PURE__*/function () {
|
|
6247
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref3, customXcm, isDotAsset, refundInstruction) {
|
|
6248
|
+
var reserve, dest, version, _t4, _t5, _t6, _t7, _t8, _t9, _t0, _t1, _t10;
|
|
6249
|
+
return _regenerator().w(function (_context2) {
|
|
6250
|
+
while (1) switch (_context2.n) {
|
|
6251
|
+
case 0:
|
|
6252
|
+
reserve = _ref3.reserve, dest = _ref3.dest, version = _ref3.options.version;
|
|
6253
|
+
if (!('DepositReserveAsset' in customXcm)) {
|
|
6254
|
+
_context2.n = 6;
|
|
6255
|
+
break;
|
|
6256
|
+
}
|
|
6257
|
+
_context2.n = 1;
|
|
6258
|
+
return computeInstructionFee(reserve, version, [customXcm]);
|
|
6259
|
+
case 1:
|
|
6260
|
+
_t5 = _context2.v;
|
|
6261
|
+
if (!refundInstruction) {
|
|
6262
|
+
_context2.n = 3;
|
|
6263
|
+
break;
|
|
6264
|
+
}
|
|
6265
|
+
_context2.n = 2;
|
|
6266
|
+
return computeInstructionFee(reserve, version, [refundInstruction]);
|
|
6267
|
+
case 2:
|
|
6268
|
+
_t6 = _context2.v;
|
|
6269
|
+
_context2.n = 4;
|
|
6270
|
+
break;
|
|
6271
|
+
case 3:
|
|
6272
|
+
_t6 = 0n;
|
|
6273
|
+
case 4:
|
|
6274
|
+
_t7 = _t6;
|
|
6275
|
+
_context2.n = 5;
|
|
6276
|
+
return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, customXcm.DepositReserveAsset.xcm);
|
|
6277
|
+
case 5:
|
|
6278
|
+
_t8 = _context2.v;
|
|
6279
|
+
_t4 = {
|
|
6280
|
+
reserveFee: _t5,
|
|
6281
|
+
refundFee: _t7,
|
|
6282
|
+
destFee: _t8
|
|
6283
|
+
};
|
|
6284
|
+
_context2.n = 13;
|
|
6285
|
+
break;
|
|
6286
|
+
case 6:
|
|
6287
|
+
if (isDotAsset) {
|
|
6288
|
+
_context2.n = 8;
|
|
6289
|
+
break;
|
|
6290
|
+
}
|
|
6291
|
+
_context2.n = 7;
|
|
6292
|
+
return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, [customXcm]);
|
|
6293
|
+
case 7:
|
|
6294
|
+
_t9 = _context2.v;
|
|
6295
|
+
_context2.n = 9;
|
|
6296
|
+
break;
|
|
6297
|
+
case 8:
|
|
6298
|
+
_t9 = 0n;
|
|
6299
|
+
case 9:
|
|
6300
|
+
_t0 = _t9;
|
|
6301
|
+
if (isDotAsset) {
|
|
6302
|
+
_context2.n = 11;
|
|
6303
|
+
break;
|
|
6304
|
+
}
|
|
6305
|
+
_context2.n = 10;
|
|
6306
|
+
return computeInstructionFee(hasXcmPaymentApiSupport(reserve.chain) ? reserve : dest, version, [refundInstruction]);
|
|
6307
|
+
case 10:
|
|
6308
|
+
_t1 = _context2.v;
|
|
6309
|
+
_context2.n = 12;
|
|
6310
|
+
break;
|
|
6311
|
+
case 11:
|
|
6312
|
+
_t1 = 0n;
|
|
6313
|
+
case 12:
|
|
6314
|
+
_t10 = _t1;
|
|
6315
|
+
_t4 = {
|
|
6316
|
+
reserveFee: 0n,
|
|
6317
|
+
destFee: _t0,
|
|
6318
|
+
refundFee: _t10
|
|
6319
|
+
};
|
|
6320
|
+
case 13:
|
|
6321
|
+
return _context2.a(2, _t4);
|
|
6322
|
+
}
|
|
6323
|
+
}, _callee2);
|
|
6324
|
+
}));
|
|
6325
|
+
return function computeAllFees(_x4, _x5, _x6, _x7) {
|
|
6326
|
+
return _ref4.apply(this, arguments);
|
|
6327
|
+
};
|
|
6328
|
+
}();
|
|
6329
|
+
|
|
6330
|
+
var createTypeAndThenCallContext = /*#__PURE__*/function () {
|
|
6331
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options) {
|
|
6332
|
+
var api, paraIdTo, assetInfo, destChain, reserveChain, destApi, reserveApi;
|
|
6519
6333
|
return _regenerator().w(function (_context) {
|
|
6520
6334
|
while (1) switch (_context.n) {
|
|
6521
6335
|
case 0:
|
|
6522
|
-
api = options.api,
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
validateAssetSpecifiers(assetCheckEnabled, currency);
|
|
6530
|
-
asset = resolveAsset(currency, origin, destination, assetCheckEnabled);
|
|
6531
|
-
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
6532
|
-
validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
|
|
6533
|
-
amount = Array.isArray(currency) ? 0n : abstractDecimals(currency.amount, asset === null || asset === void 0 ? void 0 : asset.decimals, api); // Ensure amount is at least 2 to avoid Rust panic (only for non-array currencies)
|
|
6534
|
-
finalAmount = !Array.isArray(currency) && amount < 2n ? 2n : amount;
|
|
6535
|
-
originVersion = getChainVersion(origin);
|
|
6536
|
-
destVersion = !isTLocation(destination) ? getChainVersion(destination) : undefined;
|
|
6537
|
-
resolvedVersion = selectXcmVersion(version, originVersion, destVersion);
|
|
6538
|
-
if (!isRelayChain(origin)) {
|
|
6539
|
-
_context.n = 6;
|
|
6540
|
-
break;
|
|
6541
|
-
}
|
|
6542
|
-
if (!(destination === 'Ethereum')) {
|
|
6543
|
-
_context.n = 1;
|
|
6544
|
-
break;
|
|
6545
|
-
}
|
|
6546
|
-
throw new InvalidParameterError('Transfers from relay chain to Ethereum are not supported.');
|
|
6336
|
+
api = options.api, paraIdTo = options.paraIdTo, assetInfo = options.assetInfo;
|
|
6337
|
+
assertHasLocation(assetInfo);
|
|
6338
|
+
destChain = getTChain(paraIdTo, getRelayChainOf(chain));
|
|
6339
|
+
reserveChain = isRelayChain(destChain) ? destChain : getAssetReserveChain(chain, chain, assetInfo.location);
|
|
6340
|
+
destApi = api.clone();
|
|
6341
|
+
_context.n = 1;
|
|
6342
|
+
return destApi.init(destChain);
|
|
6547
6343
|
case 1:
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
}
|
|
6552
|
-
throw new InvalidParameterError('Asset is required for relay chain to relay chain transfers.');
|
|
6344
|
+
reserveApi = reserveChain !== chain ? api.clone() : destApi;
|
|
6345
|
+
_context.n = 2;
|
|
6346
|
+
return reserveApi.init(reserveChain);
|
|
6553
6347
|
case 2:
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
module: 'Balances',
|
|
6570
|
-
method: 'transfer_keep_alive',
|
|
6571
|
-
parameters: {
|
|
6572
|
-
dest: {
|
|
6573
|
-
Id: address
|
|
6574
|
-
},
|
|
6575
|
-
value: finalAmount
|
|
6576
|
-
}
|
|
6577
|
-
}));
|
|
6578
|
-
case 5:
|
|
6579
|
-
return _context.a(2, transferRelayToPara({
|
|
6580
|
-
api: api,
|
|
6581
|
-
origin: origin,
|
|
6582
|
-
destination: destination,
|
|
6583
|
-
address: address,
|
|
6584
|
-
assetInfo: _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
6585
|
-
amount: finalAmount
|
|
6586
|
-
}),
|
|
6587
|
-
paraIdTo: paraIdTo,
|
|
6588
|
-
version: resolvedVersion,
|
|
6589
|
-
pallet: pallet,
|
|
6590
|
-
method: method
|
|
6591
|
-
}));
|
|
6592
|
-
case 6:
|
|
6593
|
-
overriddenAsset = resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset);
|
|
6594
|
-
_context.n = 7;
|
|
6595
|
-
return api.init(origin, TX_CLIENT_TIMEOUT_MS);
|
|
6596
|
-
case 7:
|
|
6597
|
-
// In case asset check is disabled, we create asset object from currency symbol
|
|
6598
|
-
resolvedAsset = asset !== null && asset !== void 0 ? asset : {
|
|
6599
|
-
symbol: 'symbol' in currency ? currency.symbol : undefined
|
|
6600
|
-
};
|
|
6601
|
-
finalAsset = Array.isArray(currency) ? _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
|
|
6602
|
-
amount: 0n,
|
|
6603
|
-
assetId: '1'
|
|
6604
|
-
}) : _objectSpread2(_objectSpread2({}, resolvedAsset), {}, {
|
|
6605
|
-
amount: finalAmount
|
|
6348
|
+
return _context.a(2, {
|
|
6349
|
+
origin: {
|
|
6350
|
+
api: api,
|
|
6351
|
+
chain: chain
|
|
6352
|
+
},
|
|
6353
|
+
dest: {
|
|
6354
|
+
api: destApi,
|
|
6355
|
+
chain: destChain
|
|
6356
|
+
},
|
|
6357
|
+
reserve: {
|
|
6358
|
+
api: reserveApi,
|
|
6359
|
+
chain: reserveChain
|
|
6360
|
+
},
|
|
6361
|
+
assetInfo: assetInfo,
|
|
6362
|
+
options: options
|
|
6606
6363
|
});
|
|
6607
|
-
finalVersion = selectXcmVersion(version, originVersion, destVersion);
|
|
6608
|
-
normalizedAsset = finalAsset.location ? _objectSpread2(_objectSpread2({}, finalAsset), {}, {
|
|
6609
|
-
location: normalizeLocation(finalAsset.location, finalVersion)
|
|
6610
|
-
}) : finalAsset;
|
|
6611
|
-
return _context.a(2, getChain(origin).transfer({
|
|
6612
|
-
api: api,
|
|
6613
|
-
assetInfo: normalizedAsset,
|
|
6614
|
-
currency: currency,
|
|
6615
|
-
feeAsset: resolvedFeeAsset,
|
|
6616
|
-
feeCurrency: feeAsset,
|
|
6617
|
-
address: address,
|
|
6618
|
-
to: destination,
|
|
6619
|
-
paraIdTo: paraIdTo,
|
|
6620
|
-
overriddenAsset: overriddenAsset,
|
|
6621
|
-
version: finalVersion,
|
|
6622
|
-
senderAddress: senderAddress,
|
|
6623
|
-
ahAddress: ahAddress,
|
|
6624
|
-
pallet: pallet,
|
|
6625
|
-
method: method
|
|
6626
|
-
}));
|
|
6627
6364
|
}
|
|
6628
6365
|
}, _callee);
|
|
6629
6366
|
}));
|
|
6630
|
-
return function
|
|
6367
|
+
return function createTypeAndThenCallContext(_x, _x2) {
|
|
6631
6368
|
return _ref.apply(this, arguments);
|
|
6632
6369
|
};
|
|
6633
6370
|
}();
|
|
6634
6371
|
|
|
6635
|
-
var
|
|
6372
|
+
var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
|
|
6636
6373
|
var origin = _ref.origin,
|
|
6637
|
-
reserve = _ref.reserve,
|
|
6638
6374
|
dest = _ref.dest,
|
|
6375
|
+
reserve = _ref.reserve,
|
|
6639
6376
|
assetInfo = _ref.assetInfo,
|
|
6640
|
-
|
|
6377
|
+
options = _ref.options;
|
|
6378
|
+
var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
6379
|
+
reserveFee: MIN_FEE,
|
|
6380
|
+
refundFee: 0n,
|
|
6381
|
+
destFee: MIN_FEE
|
|
6382
|
+
};
|
|
6383
|
+
var destination = options.destination,
|
|
6384
|
+
version = options.version,
|
|
6385
|
+
address = options.address,
|
|
6386
|
+
paraIdTo = options.paraIdTo;
|
|
6387
|
+
var reserveFee = fees.reserveFee,
|
|
6388
|
+
refundFee = fees.refundFee,
|
|
6389
|
+
destFee = fees.destFee;
|
|
6641
6390
|
var feeAssetLocation = !isDotAsset ? RELAY_LOCATION : assetInfo.location;
|
|
6642
|
-
var
|
|
6643
|
-
var
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6391
|
+
var asset = createAsset(version, assetInfo.amount, localizeLocation(dest.chain, assetInfo.location));
|
|
6392
|
+
var depositInstruction = {
|
|
6393
|
+
DepositAsset: {
|
|
6394
|
+
assets: {
|
|
6395
|
+
Wild: {
|
|
6396
|
+
AllOf: {
|
|
6397
|
+
id: asset.id,
|
|
6398
|
+
fun: 'Fungible'
|
|
6399
|
+
}
|
|
6400
|
+
}
|
|
6401
|
+
},
|
|
6402
|
+
beneficiary: createBeneficiaryLocation({
|
|
6403
|
+
api: origin.api,
|
|
6404
|
+
address: address,
|
|
6405
|
+
version: version
|
|
6406
|
+
})
|
|
6407
|
+
}
|
|
6408
|
+
};
|
|
6409
|
+
var assetsFilter = [];
|
|
6410
|
+
if (!isDotAsset) assetsFilter.push(createAsset(version, reserveFee + destFee, localizeLocation(reserve.chain, RELAY_LOCATION)));
|
|
6411
|
+
assetsFilter.push(createAsset(version, assetInfo.amount, localizeLocation(reserve.chain, assetInfo.location)));
|
|
6412
|
+
return origin.chain !== reserve.chain && dest.chain !== reserve.chain ? {
|
|
6413
|
+
DepositReserveAsset: {
|
|
6414
|
+
assets: fees.destFee === MIN_FEE ? {
|
|
6415
|
+
Wild: 'All'
|
|
6416
|
+
} : {
|
|
6417
|
+
Definite: assetsFilter
|
|
6418
|
+
},
|
|
6419
|
+
dest: createDestination(version, origin.chain, destination, paraIdTo),
|
|
6420
|
+
xcm: [{
|
|
6421
|
+
BuyExecution: {
|
|
6422
|
+
fees: createAsset(version, !isDotAsset ? destFee : assetInfo.amount - reserveFee - refundFee, feeAssetLocation),
|
|
6423
|
+
weight_limit: 'Unlimited'
|
|
6424
|
+
}
|
|
6425
|
+
}, depositInstruction]
|
|
6657
6426
|
}
|
|
6427
|
+
} : depositInstruction;
|
|
6428
|
+
};
|
|
6429
|
+
|
|
6430
|
+
var createRefundInstruction = function createRefundInstruction(api, senderAddress, version) {
|
|
6431
|
+
return {
|
|
6432
|
+
SetAppendix: [{
|
|
6433
|
+
DepositAsset: {
|
|
6434
|
+
assets: {
|
|
6435
|
+
Wild: 'All'
|
|
6436
|
+
},
|
|
6437
|
+
beneficiary: createBeneficiaryLocation({
|
|
6438
|
+
api: api,
|
|
6439
|
+
address: senderAddress,
|
|
6440
|
+
version: version
|
|
6441
|
+
})
|
|
6442
|
+
}
|
|
6443
|
+
}]
|
|
6444
|
+
};
|
|
6445
|
+
};
|
|
6446
|
+
|
|
6447
|
+
var buildAssets = function buildAssets(asset, feeAmount, isDotAsset, version) {
|
|
6448
|
+
var assets = [];
|
|
6449
|
+
if (!isDotAsset) {
|
|
6450
|
+
assets.push(createAsset(version, feeAmount, RELAY_LOCATION));
|
|
6451
|
+
}
|
|
6452
|
+
assets.push(createAsset(version, asset.amount, asset.location));
|
|
6453
|
+
return assets;
|
|
6454
|
+
};
|
|
6455
|
+
/**
|
|
6456
|
+
* Creates a type and then call for transferring assets using XCM. Works only for DOT and snowbridge assets so far.
|
|
6457
|
+
*/
|
|
6458
|
+
var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
6459
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options) {
|
|
6460
|
+
var api, senderAddress, version, context, assetInfo, isDotAsset, customXcm, refundInstruction, fees, finalCustomXcm, totalFee, assets;
|
|
6461
|
+
return _regenerator().w(function (_context) {
|
|
6462
|
+
while (1) switch (_context.n) {
|
|
6463
|
+
case 0:
|
|
6464
|
+
api = options.api, senderAddress = options.senderAddress, version = options.version;
|
|
6465
|
+
_context.n = 1;
|
|
6466
|
+
return createTypeAndThenCallContext(chain, options);
|
|
6467
|
+
case 1:
|
|
6468
|
+
context = _context.v;
|
|
6469
|
+
assetInfo = context.assetInfo;
|
|
6470
|
+
isDotAsset = deepEqual(assetInfo.location, RELAY_LOCATION) || deepEqual(assetInfo.location, {
|
|
6471
|
+
parents: 2,
|
|
6472
|
+
interior: {
|
|
6473
|
+
X1: [{
|
|
6474
|
+
GlobalConsensus: {
|
|
6475
|
+
Kusama: null
|
|
6476
|
+
}
|
|
6477
|
+
}]
|
|
6478
|
+
}
|
|
6479
|
+
});
|
|
6480
|
+
customXcm = createCustomXcm(context, isDotAsset);
|
|
6481
|
+
refundInstruction = senderAddress ? createRefundInstruction(api, senderAddress, version) : null;
|
|
6482
|
+
_context.n = 2;
|
|
6483
|
+
return computeAllFees(context, customXcm, isDotAsset, refundInstruction);
|
|
6484
|
+
case 2:
|
|
6485
|
+
fees = _context.v;
|
|
6486
|
+
finalCustomXcm = [];
|
|
6487
|
+
if (refundInstruction) finalCustomXcm.push(refundInstruction);
|
|
6488
|
+
finalCustomXcm.push(createCustomXcm(context, isDotAsset, fees));
|
|
6489
|
+
totalFee = fees.reserveFee + fees.destFee + fees.refundFee;
|
|
6490
|
+
assets = buildAssets(assetInfo, totalFee, isDotAsset, version);
|
|
6491
|
+
return _context.a(2, buildTypeAndThenCall(context, isDotAsset, finalCustomXcm, assets));
|
|
6492
|
+
}
|
|
6493
|
+
}, _callee);
|
|
6494
|
+
}));
|
|
6495
|
+
return function createTypeAndThenCall(_x, _x2) {
|
|
6496
|
+
return _ref.apply(this, arguments);
|
|
6658
6497
|
};
|
|
6659
|
-
};
|
|
6498
|
+
}();
|
|
6660
6499
|
|
|
6661
|
-
var
|
|
6662
|
-
var
|
|
6663
|
-
var
|
|
6664
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, version, xcm) {
|
|
6665
|
-
var chain, api, _t, _t2, _t3;
|
|
6500
|
+
var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
6501
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
6502
|
+
var api, senderAddress, chain, destination, currency, tx, feeAsset, resolvedFeeAsset, asset, amount, balance, ed, isNativeAsset, shouldSubstractFee, feeToSubtract, _yield$getOriginXcmFe, fee, transferable;
|
|
6666
6503
|
return _regenerator().w(function (_context) {
|
|
6667
6504
|
while (1) switch (_context.n) {
|
|
6668
6505
|
case 0:
|
|
6669
|
-
chain = _ref.
|
|
6670
|
-
|
|
6506
|
+
api = _ref.api, senderAddress = _ref.senderAddress, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency, tx = _ref.tx, feeAsset = _ref.feeAsset;
|
|
6507
|
+
validateAddress(senderAddress, chain, false);
|
|
6508
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, chain, destination, currency) : undefined;
|
|
6509
|
+
asset = findAssetInfoOrThrow(chain, currency, null);
|
|
6510
|
+
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
6671
6511
|
_context.n = 1;
|
|
6672
|
-
return
|
|
6673
|
-
|
|
6674
|
-
|
|
6512
|
+
return getAssetBalanceInternal({
|
|
6513
|
+
api: api,
|
|
6514
|
+
address: senderAddress,
|
|
6515
|
+
chain: chain,
|
|
6516
|
+
currency: currency
|
|
6517
|
+
});
|
|
6675
6518
|
case 1:
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6519
|
+
balance = _context.v;
|
|
6520
|
+
ed = getExistentialDepositOrThrow(chain, currency);
|
|
6521
|
+
isNativeAsset = getNativeAssetSymbol(chain) === asset.symbol;
|
|
6522
|
+
shouldSubstractFee = isNativeAsset || chain === 'AssetHubPolkadot' && resolvedFeeAsset && isAssetEqual(resolvedFeeAsset, asset);
|
|
6523
|
+
feeToSubtract = 0n;
|
|
6524
|
+
if (!shouldSubstractFee) {
|
|
6525
|
+
_context.n = 4;
|
|
6526
|
+
break;
|
|
6527
|
+
}
|
|
6528
|
+
_context.n = 2;
|
|
6529
|
+
return getOriginXcmFee({
|
|
6530
|
+
api: api,
|
|
6531
|
+
tx: tx,
|
|
6532
|
+
origin: chain,
|
|
6533
|
+
destination: chain,
|
|
6534
|
+
senderAddress: senderAddress,
|
|
6535
|
+
feeAsset: feeAsset,
|
|
6536
|
+
currency: _objectSpread2(_objectSpread2({}, currency), {}, {
|
|
6537
|
+
amount: amount
|
|
6538
|
+
}),
|
|
6539
|
+
disableFallback: false
|
|
6540
|
+
});
|
|
6541
|
+
case 2:
|
|
6542
|
+
_yield$getOriginXcmFe = _context.v;
|
|
6543
|
+
fee = _yield$getOriginXcmFe.fee;
|
|
6544
|
+
if (!(fee === undefined)) {
|
|
6545
|
+
_context.n = 3;
|
|
6546
|
+
break;
|
|
6547
|
+
}
|
|
6548
|
+
throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency, replaceBigInt), " on chain ").concat(chain, "."));
|
|
6549
|
+
case 3:
|
|
6550
|
+
feeToSubtract = fee;
|
|
6551
|
+
case 4:
|
|
6552
|
+
transferable = balance - ed - feeToSubtract;
|
|
6553
|
+
return _context.a(2, transferable > 0n ? transferable : 0n);
|
|
6679
6554
|
}
|
|
6680
6555
|
}, _callee);
|
|
6681
6556
|
}));
|
|
6682
|
-
return function
|
|
6557
|
+
return function getTransferableAmountInternal(_x) {
|
|
6683
6558
|
return _ref2.apply(this, arguments);
|
|
6684
6559
|
};
|
|
6685
6560
|
}();
|
|
6686
|
-
var
|
|
6687
|
-
var
|
|
6688
|
-
var
|
|
6561
|
+
var getTransferableAmount = /*#__PURE__*/function () {
|
|
6562
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
6563
|
+
var api;
|
|
6689
6564
|
return _regenerator().w(function (_context2) {
|
|
6690
|
-
while (1) switch (_context2.n) {
|
|
6565
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
6691
6566
|
case 0:
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
break;
|
|
6696
|
-
}
|
|
6697
|
-
_context2.n = 1;
|
|
6698
|
-
return computeInstructionFee(reserve, version, [customXcm]);
|
|
6699
|
-
case 1:
|
|
6700
|
-
_t5 = _context2.v;
|
|
6701
|
-
if (!refundInstruction) {
|
|
6702
|
-
_context2.n = 3;
|
|
6703
|
-
break;
|
|
6704
|
-
}
|
|
6567
|
+
api = options.api;
|
|
6568
|
+
api.setDisconnectAllowed(false);
|
|
6569
|
+
_context2.p = 1;
|
|
6705
6570
|
_context2.n = 2;
|
|
6706
|
-
return
|
|
6571
|
+
return getTransferableAmountInternal(options);
|
|
6707
6572
|
case 2:
|
|
6708
|
-
|
|
6709
|
-
_context2.n = 4;
|
|
6710
|
-
break;
|
|
6573
|
+
return _context2.a(2, _context2.v);
|
|
6711
6574
|
case 3:
|
|
6712
|
-
|
|
6575
|
+
_context2.p = 3;
|
|
6576
|
+
api.setDisconnectAllowed(true);
|
|
6577
|
+
_context2.n = 4;
|
|
6578
|
+
return api.disconnect();
|
|
6713
6579
|
case 4:
|
|
6714
|
-
|
|
6715
|
-
_context2.n = 5;
|
|
6716
|
-
return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, customXcm.DepositReserveAsset.xcm);
|
|
6580
|
+
return _context2.f(3);
|
|
6717
6581
|
case 5:
|
|
6718
|
-
|
|
6719
|
-
_t4 = {
|
|
6720
|
-
reserveFee: _t5,
|
|
6721
|
-
refundFee: _t7,
|
|
6722
|
-
destFee: _t8
|
|
6723
|
-
};
|
|
6724
|
-
_context2.n = 13;
|
|
6725
|
-
break;
|
|
6726
|
-
case 6:
|
|
6727
|
-
if (isDotAsset) {
|
|
6728
|
-
_context2.n = 8;
|
|
6729
|
-
break;
|
|
6730
|
-
}
|
|
6731
|
-
_context2.n = 7;
|
|
6732
|
-
return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, [customXcm]);
|
|
6733
|
-
case 7:
|
|
6734
|
-
_t9 = _context2.v;
|
|
6735
|
-
_context2.n = 9;
|
|
6736
|
-
break;
|
|
6737
|
-
case 8:
|
|
6738
|
-
_t9 = 0n;
|
|
6739
|
-
case 9:
|
|
6740
|
-
_t0 = _t9;
|
|
6741
|
-
if (isDotAsset) {
|
|
6742
|
-
_context2.n = 11;
|
|
6743
|
-
break;
|
|
6744
|
-
}
|
|
6745
|
-
_context2.n = 10;
|
|
6746
|
-
return computeInstructionFee(hasXcmPaymentApiSupport(reserve.chain) ? reserve : dest, version, [refundInstruction]);
|
|
6747
|
-
case 10:
|
|
6748
|
-
_t1 = _context2.v;
|
|
6749
|
-
_context2.n = 12;
|
|
6750
|
-
break;
|
|
6751
|
-
case 11:
|
|
6752
|
-
_t1 = 0n;
|
|
6753
|
-
case 12:
|
|
6754
|
-
_t10 = _t1;
|
|
6755
|
-
_t4 = {
|
|
6756
|
-
reserveFee: 0n,
|
|
6757
|
-
destFee: _t0,
|
|
6758
|
-
refundFee: _t10
|
|
6759
|
-
};
|
|
6760
|
-
case 13:
|
|
6761
|
-
return _context2.a(2, _t4);
|
|
6582
|
+
return _context2.a(2);
|
|
6762
6583
|
}
|
|
6763
|
-
}, _callee2);
|
|
6584
|
+
}, _callee2, null, [[1,, 3, 5]]);
|
|
6764
6585
|
}));
|
|
6765
|
-
return function
|
|
6766
|
-
return
|
|
6586
|
+
return function getTransferableAmount(_x2) {
|
|
6587
|
+
return _ref3.apply(this, arguments);
|
|
6767
6588
|
};
|
|
6768
6589
|
}();
|
|
6769
6590
|
|
|
6770
|
-
var
|
|
6771
|
-
var
|
|
6772
|
-
var api,
|
|
6591
|
+
var buildDestInfo = /*#__PURE__*/function () {
|
|
6592
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
6593
|
+
var api, origin, destination, address, currency, originFee, isFeeAssetAh, destFeeDetail, assetHubFee, bridgeFee, destApi, destAsset, edDest, edDestBn, destCurrency, destBalance, destAmount, effectiveAmountForBalance, destBalanceSufficient, destBalanceSufficientResult, destBalanceAfter, destbalanceAfterResult, receivedAmount, isAssetHubToAssetHubRoute, nativeAssetOfOriginSymbol, isOriginAssetNative, destXcmFeeBalance, isDestFeeInNativeCurrency, destRecipientNativeBalance, destXcmFeeBalanceAfter;
|
|
6773
6594
|
return _regenerator().w(function (_context) {
|
|
6774
6595
|
while (1) switch (_context.n) {
|
|
6775
6596
|
case 0:
|
|
6776
|
-
api =
|
|
6777
|
-
assertHasLocation(assetInfo);
|
|
6778
|
-
destChain = getTChain(paraIdTo, getRelayChainOf(chain));
|
|
6779
|
-
reserveChain = isRelayChain(destChain) ? destChain : getAssetReserveChain(chain, chain, assetInfo.location);
|
|
6597
|
+
api = _ref.api, origin = _ref.origin, destination = _ref.destination, address = _ref.address, currency = _ref.currency, originFee = _ref.originFee, isFeeAssetAh = _ref.isFeeAssetAh, destFeeDetail = _ref.destFeeDetail, assetHubFee = _ref.assetHubFee, bridgeFee = _ref.bridgeFee;
|
|
6780
6598
|
destApi = api.clone();
|
|
6599
|
+
if (!(destination !== 'Ethereum')) {
|
|
6600
|
+
_context.n = 1;
|
|
6601
|
+
break;
|
|
6602
|
+
}
|
|
6781
6603
|
_context.n = 1;
|
|
6782
|
-
return destApi.init(
|
|
6604
|
+
return destApi.init(destination);
|
|
6783
6605
|
case 1:
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6606
|
+
destAsset = findAssetOnDestOrThrow(origin, destination, currency);
|
|
6607
|
+
edDest = destAsset.existentialDeposit;
|
|
6608
|
+
if (edDest) {
|
|
6609
|
+
_context.n = 2;
|
|
6610
|
+
break;
|
|
6611
|
+
}
|
|
6612
|
+
throw new InvalidParameterError("Existential deposit not found for ".concat(destination, " with currency ").concat(JSON.stringify(currency, replaceBigInt)));
|
|
6787
6613
|
case 2:
|
|
6614
|
+
edDestBn = BigInt(edDest);
|
|
6615
|
+
destCurrency = destAsset.location ? {
|
|
6616
|
+
location: destAsset.location
|
|
6617
|
+
} : {
|
|
6618
|
+
symbol: destAsset.symbol
|
|
6619
|
+
};
|
|
6620
|
+
_context.n = 3;
|
|
6621
|
+
return getAssetBalanceInternal({
|
|
6622
|
+
api: destApi,
|
|
6623
|
+
address: address,
|
|
6624
|
+
chain: destination,
|
|
6625
|
+
currency: destCurrency
|
|
6626
|
+
});
|
|
6627
|
+
case 3:
|
|
6628
|
+
destBalance = _context.v;
|
|
6629
|
+
destAmount = isFeeAssetAh ? BigInt(currency.amount) - originFee : BigInt(currency.amount);
|
|
6630
|
+
effectiveAmountForBalance = destAmount;
|
|
6631
|
+
if (destination === 'Ethereum' && assetHubFee !== undefined) {
|
|
6632
|
+
effectiveAmountForBalance -= assetHubFee;
|
|
6633
|
+
}
|
|
6634
|
+
destBalanceSufficient = effectiveAmountForBalance - destFeeDetail.fee > (destBalance < edDestBn ? edDestBn : 0);
|
|
6635
|
+
destBalanceSufficientResult = destFeeDetail.currency !== destAsset.symbol && destination !== 'Ethereum' ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceSufficient;
|
|
6636
|
+
destBalanceAfter = destBalance - (destFeeDetail.currency === destAsset.symbol ? destFeeDetail.fee : 0n) + effectiveAmountForBalance;
|
|
6637
|
+
destbalanceAfterResult = destFeeDetail.currency !== destAsset.symbol && destination !== 'Ethereum' ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceAfter;
|
|
6638
|
+
isAssetHubToAssetHubRoute = origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot' || origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama';
|
|
6639
|
+
if (isAssetHubToAssetHubRoute) {
|
|
6640
|
+
nativeAssetOfOriginSymbol = getNativeAssetSymbol(origin);
|
|
6641
|
+
isOriginAssetNative = false;
|
|
6642
|
+
if (destAsset.symbol === nativeAssetOfOriginSymbol) {
|
|
6643
|
+
isOriginAssetNative = true;
|
|
6644
|
+
}
|
|
6645
|
+
if (isOriginAssetNative) {
|
|
6646
|
+
if (bridgeFee === undefined) {
|
|
6647
|
+
receivedAmount = new UnableToComputeError("bridgeFee is required for native asset transfer from ".concat(origin, " to ").concat(destination, " but was not provided."));
|
|
6648
|
+
} else {
|
|
6649
|
+
receivedAmount = BigInt(currency.amount) - originFee - bridgeFee;
|
|
6650
|
+
}
|
|
6651
|
+
} else {
|
|
6652
|
+
receivedAmount = new UnableToComputeError("Unable to compute received amount: The transferred asset (".concat(destAsset.symbol, ") is not the native asset (").concat(nativeAssetOfOriginSymbol, ") of origin ").concat(origin, " for the ").concat(origin, "->").concat(destination, " route."));
|
|
6653
|
+
}
|
|
6654
|
+
} else {
|
|
6655
|
+
if (destbalanceAfterResult instanceof UnableToComputeError) {
|
|
6656
|
+
receivedAmount = destbalanceAfterResult;
|
|
6657
|
+
} else {
|
|
6658
|
+
receivedAmount = destbalanceAfterResult - destBalance;
|
|
6659
|
+
}
|
|
6660
|
+
}
|
|
6661
|
+
isDestFeeInNativeCurrency = destFeeDetail.currency === getNativeAssetSymbol(destination);
|
|
6662
|
+
if (!isDestFeeInNativeCurrency) {
|
|
6663
|
+
_context.n = 5;
|
|
6664
|
+
break;
|
|
6665
|
+
}
|
|
6666
|
+
_context.n = 4;
|
|
6667
|
+
return getBalanceNativeInternal({
|
|
6668
|
+
address: address,
|
|
6669
|
+
chain: destination,
|
|
6670
|
+
api: destApi
|
|
6671
|
+
});
|
|
6672
|
+
case 4:
|
|
6673
|
+
destRecipientNativeBalance = _context.v;
|
|
6674
|
+
destXcmFeeBalance = destRecipientNativeBalance;
|
|
6675
|
+
_context.n = 6;
|
|
6676
|
+
break;
|
|
6677
|
+
case 5:
|
|
6678
|
+
destXcmFeeBalance = destBalance;
|
|
6679
|
+
case 6:
|
|
6680
|
+
destXcmFeeBalanceAfter = isFeeAssetAh ? destBalanceAfter : destXcmFeeBalance - destFeeDetail.fee + (destFeeDetail.currency === destAsset.symbol ? effectiveAmountForBalance : 0n);
|
|
6788
6681
|
return _context.a(2, {
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
},
|
|
6797
|
-
reserve: {
|
|
6798
|
-
api: reserveApi,
|
|
6799
|
-
chain: reserveChain
|
|
6682
|
+
receivedCurrency: {
|
|
6683
|
+
sufficient: destBalanceSufficientResult,
|
|
6684
|
+
receivedAmount: receivedAmount,
|
|
6685
|
+
balance: destBalance,
|
|
6686
|
+
balanceAfter: destbalanceAfterResult,
|
|
6687
|
+
currencySymbol: destAsset.symbol,
|
|
6688
|
+
existentialDeposit: edDestBn
|
|
6800
6689
|
},
|
|
6801
|
-
|
|
6802
|
-
|
|
6690
|
+
xcmFee: {
|
|
6691
|
+
fee: destFeeDetail.fee,
|
|
6692
|
+
balance: destXcmFeeBalance,
|
|
6693
|
+
balanceAfter: destXcmFeeBalanceAfter,
|
|
6694
|
+
currencySymbol: destFeeDetail.currency
|
|
6695
|
+
}
|
|
6803
6696
|
});
|
|
6804
6697
|
}
|
|
6805
6698
|
}, _callee);
|
|
6806
6699
|
}));
|
|
6807
|
-
return function
|
|
6808
|
-
return
|
|
6700
|
+
return function buildDestInfo(_x) {
|
|
6701
|
+
return _ref2.apply(this, arguments);
|
|
6809
6702
|
};
|
|
6810
6703
|
}();
|
|
6811
6704
|
|
|
6812
|
-
var
|
|
6813
|
-
var
|
|
6814
|
-
|
|
6815
|
-
reserve = _ref.reserve,
|
|
6816
|
-
assetInfo = _ref.assetInfo,
|
|
6817
|
-
options = _ref.options;
|
|
6818
|
-
var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
6819
|
-
reserveFee: MIN_FEE,
|
|
6820
|
-
refundFee: 0n,
|
|
6821
|
-
destFee: MIN_FEE
|
|
6822
|
-
};
|
|
6823
|
-
var destination = options.destination,
|
|
6824
|
-
version = options.version,
|
|
6825
|
-
address = options.address,
|
|
6826
|
-
paraIdTo = options.paraIdTo;
|
|
6827
|
-
var reserveFee = fees.reserveFee,
|
|
6828
|
-
refundFee = fees.refundFee,
|
|
6829
|
-
destFee = fees.destFee;
|
|
6830
|
-
var feeAssetLocation = !isDotAsset ? RELAY_LOCATION : assetInfo.location;
|
|
6831
|
-
var asset = createAsset(version, assetInfo.amount, localizeLocation(dest.chain, assetInfo.location));
|
|
6832
|
-
var depositInstruction = {
|
|
6833
|
-
DepositAsset: {
|
|
6834
|
-
assets: {
|
|
6835
|
-
Wild: {
|
|
6836
|
-
AllOf: {
|
|
6837
|
-
id: asset.id,
|
|
6838
|
-
fun: 'Fungible'
|
|
6839
|
-
}
|
|
6840
|
-
}
|
|
6841
|
-
},
|
|
6842
|
-
beneficiary: createBeneficiaryLocation({
|
|
6843
|
-
api: origin.api,
|
|
6844
|
-
address: address,
|
|
6845
|
-
version: version
|
|
6846
|
-
})
|
|
6847
|
-
}
|
|
6848
|
-
};
|
|
6849
|
-
var assetsFilter = [];
|
|
6850
|
-
if (!isDotAsset) assetsFilter.push(createAsset(version, reserveFee + destFee, localizeLocation(reserve.chain, RELAY_LOCATION)));
|
|
6851
|
-
assetsFilter.push(createAsset(version, assetInfo.amount, localizeLocation(reserve.chain, assetInfo.location)));
|
|
6852
|
-
return origin.chain !== reserve.chain && dest.chain !== reserve.chain ? {
|
|
6853
|
-
DepositReserveAsset: {
|
|
6854
|
-
assets: fees.destFee === MIN_FEE ? {
|
|
6855
|
-
Wild: 'All'
|
|
6856
|
-
} : {
|
|
6857
|
-
Definite: assetsFilter
|
|
6858
|
-
},
|
|
6859
|
-
dest: createDestination(version, origin.chain, destination, paraIdTo),
|
|
6860
|
-
xcm: [{
|
|
6861
|
-
BuyExecution: {
|
|
6862
|
-
fees: createAsset(version, !isDotAsset ? destFee : assetInfo.amount - reserveFee - refundFee, feeAssetLocation),
|
|
6863
|
-
weight_limit: 'Unlimited'
|
|
6864
|
-
}
|
|
6865
|
-
}, depositInstruction]
|
|
6866
|
-
}
|
|
6867
|
-
} : depositInstruction;
|
|
6868
|
-
};
|
|
6869
|
-
|
|
6870
|
-
var createRefundInstruction = function createRefundInstruction(api, senderAddress, version) {
|
|
6871
|
-
return {
|
|
6872
|
-
SetAppendix: [{
|
|
6873
|
-
DepositAsset: {
|
|
6874
|
-
assets: {
|
|
6875
|
-
Wild: 'All'
|
|
6876
|
-
},
|
|
6877
|
-
beneficiary: createBeneficiaryLocation({
|
|
6878
|
-
api: api,
|
|
6879
|
-
address: senderAddress,
|
|
6880
|
-
version: version
|
|
6881
|
-
})
|
|
6882
|
-
}
|
|
6883
|
-
}]
|
|
6884
|
-
};
|
|
6885
|
-
};
|
|
6886
|
-
|
|
6887
|
-
var buildAssets = function buildAssets(asset, feeAmount, isDotAsset, version) {
|
|
6888
|
-
var assets = [];
|
|
6889
|
-
if (!isDotAsset) {
|
|
6890
|
-
assets.push(createAsset(version, feeAmount, RELAY_LOCATION));
|
|
6891
|
-
}
|
|
6892
|
-
assets.push(createAsset(version, asset.amount, asset.location));
|
|
6893
|
-
return assets;
|
|
6894
|
-
};
|
|
6895
|
-
/**
|
|
6896
|
-
* Creates a type and then call for transferring assets using XCM. Works only for DOT and snowbridge assets so far.
|
|
6897
|
-
*/
|
|
6898
|
-
var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
6899
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options) {
|
|
6900
|
-
var api, senderAddress, version, context, assetInfo, isDotAsset, customXcm, refundInstruction, fees, finalCustomXcm, totalFee, assets;
|
|
6705
|
+
var buildHopInfo = /*#__PURE__*/function () {
|
|
6706
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
6707
|
+
var api, chain, feeData, originChain, currency, senderAddress, ahAddress, hopApi, resolvedAddress, nativeBalanceOnHop, nativeAssetSymbolOnHop, xcmFeeDetails, isBridgeHub, hopAsset, hopCurrencyPayload, balance, ed;
|
|
6901
6708
|
return _regenerator().w(function (_context) {
|
|
6902
|
-
while (1) switch (_context.n) {
|
|
6709
|
+
while (1) switch (_context.p = _context.n) {
|
|
6903
6710
|
case 0:
|
|
6904
|
-
api =
|
|
6711
|
+
api = _ref.api, chain = _ref.chain, feeData = _ref.feeData, originChain = _ref.originChain, currency = _ref.currency, senderAddress = _ref.senderAddress, ahAddress = _ref.ahAddress;
|
|
6712
|
+
hopApi = api.clone();
|
|
6905
6713
|
_context.n = 1;
|
|
6906
|
-
return
|
|
6714
|
+
return hopApi.init(chain);
|
|
6907
6715
|
case 1:
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
}
|
|
6917
|
-
}]
|
|
6918
|
-
}
|
|
6716
|
+
hopApi.setDisconnectAllowed(false);
|
|
6717
|
+
_context.p = 2;
|
|
6718
|
+
resolvedAddress = isChainEvm(originChain) && ahAddress ? ahAddress : senderAddress;
|
|
6719
|
+
_context.n = 3;
|
|
6720
|
+
return getBalanceNativeInternal({
|
|
6721
|
+
api: hopApi,
|
|
6722
|
+
address: resolvedAddress,
|
|
6723
|
+
chain: chain
|
|
6919
6724
|
});
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6725
|
+
case 3:
|
|
6726
|
+
nativeBalanceOnHop = _context.v;
|
|
6727
|
+
nativeAssetSymbolOnHop = getNativeAssetSymbol(chain);
|
|
6728
|
+
xcmFeeDetails = {
|
|
6729
|
+
fee: feeData.fee,
|
|
6730
|
+
balance: nativeBalanceOnHop,
|
|
6731
|
+
currencySymbol: nativeAssetSymbolOnHop
|
|
6732
|
+
};
|
|
6733
|
+
isBridgeHub = chain.includes('BridgeHub');
|
|
6734
|
+
if (!isBridgeHub) {
|
|
6735
|
+
_context.n = 4;
|
|
6736
|
+
break;
|
|
6737
|
+
}
|
|
6738
|
+
return _context.a(2, {
|
|
6739
|
+
currencySymbol: getNativeAssetSymbol(chain),
|
|
6740
|
+
xcmFee: xcmFeeDetails
|
|
6741
|
+
});
|
|
6742
|
+
case 4:
|
|
6743
|
+
hopAsset = findAssetOnDestOrThrow(originChain, chain, currency);
|
|
6744
|
+
hopCurrencyPayload = hopAsset.location ? {
|
|
6745
|
+
location: hopAsset.location
|
|
6746
|
+
} : {
|
|
6747
|
+
symbol: hopAsset.symbol
|
|
6748
|
+
};
|
|
6749
|
+
_context.n = 5;
|
|
6750
|
+
return getAssetBalanceInternal({
|
|
6751
|
+
api: hopApi,
|
|
6752
|
+
address: resolvedAddress,
|
|
6753
|
+
chain: chain,
|
|
6754
|
+
currency: hopCurrencyPayload
|
|
6755
|
+
});
|
|
6756
|
+
case 5:
|
|
6757
|
+
balance = _context.v;
|
|
6758
|
+
ed = getExistentialDeposit(chain, hopCurrencyPayload);
|
|
6759
|
+
if (ed) {
|
|
6760
|
+
_context.n = 6;
|
|
6761
|
+
break;
|
|
6762
|
+
}
|
|
6763
|
+
throw new InvalidParameterError("Existential deposit not found for chain ".concat(chain, " with currency ").concat(JSON.stringify(hopCurrencyPayload)));
|
|
6764
|
+
case 6:
|
|
6765
|
+
return _context.a(2, {
|
|
6766
|
+
balance: balance,
|
|
6767
|
+
currencySymbol: hopAsset.symbol,
|
|
6768
|
+
existentialDeposit: BigInt(ed),
|
|
6769
|
+
xcmFee: xcmFeeDetails
|
|
6770
|
+
});
|
|
6771
|
+
case 7:
|
|
6772
|
+
_context.p = 7;
|
|
6773
|
+
hopApi.setDisconnectAllowed(true);
|
|
6774
|
+
_context.n = 8;
|
|
6775
|
+
return hopApi.disconnect();
|
|
6776
|
+
case 8:
|
|
6777
|
+
return _context.f(7);
|
|
6778
|
+
case 9:
|
|
6779
|
+
return _context.a(2);
|
|
6932
6780
|
}
|
|
6933
|
-
}, _callee);
|
|
6781
|
+
}, _callee, null, [[2,, 7, 9]]);
|
|
6934
6782
|
}));
|
|
6935
|
-
return function
|
|
6936
|
-
return
|
|
6783
|
+
return function buildHopInfo(_x) {
|
|
6784
|
+
return _ref2.apply(this, arguments);
|
|
6937
6785
|
};
|
|
6938
6786
|
}();
|
|
6939
6787
|
|
|
6940
|
-
var
|
|
6941
|
-
var
|
|
6942
|
-
var origin, currency,
|
|
6943
|
-
return _regenerator().w(function (
|
|
6944
|
-
while (1) switch (
|
|
6788
|
+
var getTransferInfo = /*#__PURE__*/function () {
|
|
6789
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
6790
|
+
var api, tx, origin, destination, senderAddress, ahAddress, address, currency, feeAsset, resolvedFeeAsset, originAsset, amount, originBalanceFee, originBalance, edOrigin, _yield$getXcmFee, _yield$getXcmFee$orig, originFee, originFeeCurrency, assetHubFeeResult, bridgeHubFeeResult, destFeeDetail, hops, isFeeAssetAh, originBalanceAfter, originBalanceFeeAfter, originBalanceNativeSufficient, originBalanceSufficient, assetHub, bridgeHub, bridgeHubChain, builtHops, destinationInfo, _t;
|
|
6791
|
+
return _regenerator().w(function (_context2) {
|
|
6792
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
6945
6793
|
case 0:
|
|
6946
|
-
origin =
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
result = null;
|
|
6950
|
-
_i = 0, _reductionPcts = reductionPcts;
|
|
6951
|
-
case 1:
|
|
6952
|
-
if (!(_i < _reductionPcts.length)) {
|
|
6953
|
-
_context.n = 5;
|
|
6794
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, ahAddress = _ref.ahAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset;
|
|
6795
|
+
if (!(isChainEvm(origin) && !ahAddress)) {
|
|
6796
|
+
_context2.n = 1;
|
|
6954
6797
|
break;
|
|
6955
6798
|
}
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
_t2 = _objectSpread2;
|
|
6962
|
-
_t3 = _objectSpread2({}, options);
|
|
6963
|
-
_t4 = {};
|
|
6964
|
-
_context.n = 2;
|
|
6965
|
-
return modifiedBuilder.build();
|
|
6799
|
+
throw new InvalidParameterError("ahAddress is required for EVM origin ".concat(origin, "."));
|
|
6800
|
+
case 1:
|
|
6801
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
6802
|
+
_context2.n = 2;
|
|
6803
|
+
return api.init(origin);
|
|
6966
6804
|
case 2:
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
return _t(_t7);
|
|
6974
|
-
case 3:
|
|
6975
|
-
result = _context.v;
|
|
6976
|
-
if (!(result.feeType === 'dryRun' || percentage === lastReduction || !hasDryRunSupport(origin))) {
|
|
6977
|
-
_context.n = 4;
|
|
6805
|
+
api.setDisconnectAllowed(false);
|
|
6806
|
+
_context2.p = 3;
|
|
6807
|
+
originAsset = findAssetInfoOrThrow(origin, currency, destination);
|
|
6808
|
+
amount = abstractDecimals(currency.amount, originAsset.decimals, api);
|
|
6809
|
+
if (!(feeAsset && resolvedFeeAsset)) {
|
|
6810
|
+
_context2.n = 5;
|
|
6978
6811
|
break;
|
|
6979
6812
|
}
|
|
6980
|
-
|
|
6813
|
+
_context2.n = 4;
|
|
6814
|
+
return getAssetBalanceInternal({
|
|
6815
|
+
api: api,
|
|
6816
|
+
address: senderAddress,
|
|
6817
|
+
chain: origin,
|
|
6818
|
+
currency: feeAsset
|
|
6819
|
+
});
|
|
6981
6820
|
case 4:
|
|
6982
|
-
|
|
6983
|
-
|
|
6821
|
+
_t = _context2.v;
|
|
6822
|
+
_context2.n = 7;
|
|
6984
6823
|
break;
|
|
6985
6824
|
case 5:
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
var api, senderAddress, chain, destination, currency, builder, feeAsset, resolvedFeeAsset, asset, amount, balance, ed, isNativeAsset, shouldSubstractFee, feeToSubtract, _yield$attemptDryRunF, fee, transferable;
|
|
6998
|
-
return _regenerator().w(function (_context) {
|
|
6999
|
-
while (1) switch (_context.n) {
|
|
7000
|
-
case 0:
|
|
7001
|
-
api = _ref.api, senderAddress = _ref.senderAddress, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency, builder = _ref.builder, feeAsset = _ref.feeAsset;
|
|
7002
|
-
validateAddress(senderAddress, chain, false);
|
|
7003
|
-
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, chain, destination, currency) : undefined;
|
|
7004
|
-
asset = findAssetInfoOrThrow(chain, currency, null);
|
|
7005
|
-
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
7006
|
-
_context.n = 1;
|
|
6825
|
+
_context2.n = 6;
|
|
6826
|
+
return getBalanceNativeInternal({
|
|
6827
|
+
api: api,
|
|
6828
|
+
address: senderAddress,
|
|
6829
|
+
chain: origin
|
|
6830
|
+
});
|
|
6831
|
+
case 6:
|
|
6832
|
+
_t = _context2.v;
|
|
6833
|
+
case 7:
|
|
6834
|
+
originBalanceFee = _t;
|
|
6835
|
+
_context2.n = 8;
|
|
7007
6836
|
return getAssetBalanceInternal({
|
|
7008
6837
|
api: api,
|
|
7009
6838
|
address: senderAddress,
|
|
7010
|
-
chain:
|
|
6839
|
+
chain: origin,
|
|
7011
6840
|
currency: currency
|
|
7012
6841
|
});
|
|
7013
|
-
case
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
6842
|
+
case 8:
|
|
6843
|
+
originBalance = _context2.v;
|
|
6844
|
+
edOrigin = getExistentialDepositOrThrow(origin, currency);
|
|
6845
|
+
_context2.n = 9;
|
|
6846
|
+
return getXcmFee({
|
|
6847
|
+
api: api,
|
|
6848
|
+
tx: tx,
|
|
6849
|
+
origin: origin,
|
|
6850
|
+
destination: destination,
|
|
6851
|
+
senderAddress: senderAddress,
|
|
6852
|
+
address: address,
|
|
6853
|
+
currency: currency,
|
|
6854
|
+
feeAsset: feeAsset,
|
|
6855
|
+
disableFallback: false
|
|
6856
|
+
});
|
|
6857
|
+
case 9:
|
|
6858
|
+
_yield$getXcmFee = _context2.v;
|
|
6859
|
+
_yield$getXcmFee$orig = _yield$getXcmFee.origin;
|
|
6860
|
+
originFee = _yield$getXcmFee$orig.fee;
|
|
6861
|
+
originFeeCurrency = _yield$getXcmFee$orig.currency;
|
|
6862
|
+
assetHubFeeResult = _yield$getXcmFee.assetHub;
|
|
6863
|
+
bridgeHubFeeResult = _yield$getXcmFee.bridgeHub;
|
|
6864
|
+
destFeeDetail = _yield$getXcmFee.destination;
|
|
6865
|
+
hops = _yield$getXcmFee.hops;
|
|
6866
|
+
isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && isAssetEqual(resolvedFeeAsset, originAsset);
|
|
6867
|
+
originBalanceAfter = originBalance - amount;
|
|
6868
|
+
originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - amount : originBalanceFee - originFee;
|
|
6869
|
+
originBalanceNativeSufficient = originBalanceFee >= originFee;
|
|
6870
|
+
originBalanceSufficient = originBalanceAfter >= edOrigin;
|
|
6871
|
+
if (!assetHubFeeResult) {
|
|
6872
|
+
_context2.n = 11;
|
|
7021
6873
|
break;
|
|
7022
6874
|
}
|
|
7023
|
-
|
|
7024
|
-
return
|
|
6875
|
+
_context2.n = 10;
|
|
6876
|
+
return buildHopInfo({
|
|
7025
6877
|
api: api,
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
6878
|
+
chain: "AssetHub".concat(getRelayChainOf(origin)),
|
|
6879
|
+
feeData: assetHubFeeResult,
|
|
6880
|
+
originChain: origin,
|
|
6881
|
+
currency: currency,
|
|
7029
6882
|
senderAddress: senderAddress,
|
|
7030
|
-
|
|
6883
|
+
ahAddress: ahAddress
|
|
6884
|
+
});
|
|
6885
|
+
case 10:
|
|
6886
|
+
assetHub = _context2.v;
|
|
6887
|
+
case 11:
|
|
6888
|
+
if (!bridgeHubFeeResult) {
|
|
6889
|
+
_context2.n = 13;
|
|
6890
|
+
break;
|
|
6891
|
+
}
|
|
6892
|
+
bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
|
|
6893
|
+
_context2.n = 12;
|
|
6894
|
+
return buildHopInfo({
|
|
6895
|
+
api: api,
|
|
6896
|
+
chain: bridgeHubChain,
|
|
6897
|
+
feeData: bridgeHubFeeResult,
|
|
6898
|
+
originChain: origin,
|
|
6899
|
+
currency: currency,
|
|
6900
|
+
senderAddress: senderAddress,
|
|
6901
|
+
ahAddress: ahAddress
|
|
6902
|
+
});
|
|
6903
|
+
case 12:
|
|
6904
|
+
bridgeHub = _context2.v;
|
|
6905
|
+
case 13:
|
|
6906
|
+
builtHops = [];
|
|
6907
|
+
if (!(hops && hops.length > 0)) {
|
|
6908
|
+
_context2.n = 15;
|
|
6909
|
+
break;
|
|
6910
|
+
}
|
|
6911
|
+
_context2.n = 14;
|
|
6912
|
+
return Promise.all(hops.map(/*#__PURE__*/function () {
|
|
6913
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(hop) {
|
|
6914
|
+
var result;
|
|
6915
|
+
return _regenerator().w(function (_context) {
|
|
6916
|
+
while (1) switch (_context.n) {
|
|
6917
|
+
case 0:
|
|
6918
|
+
_context.n = 1;
|
|
6919
|
+
return buildHopInfo({
|
|
6920
|
+
api: api,
|
|
6921
|
+
chain: hop.chain,
|
|
6922
|
+
feeData: hop.result,
|
|
6923
|
+
originChain: origin,
|
|
6924
|
+
currency: currency,
|
|
6925
|
+
senderAddress: senderAddress,
|
|
6926
|
+
ahAddress: ahAddress
|
|
6927
|
+
});
|
|
6928
|
+
case 1:
|
|
6929
|
+
result = _context.v;
|
|
6930
|
+
return _context.a(2, {
|
|
6931
|
+
chain: hop.chain,
|
|
6932
|
+
result: result
|
|
6933
|
+
});
|
|
6934
|
+
}
|
|
6935
|
+
}, _callee);
|
|
6936
|
+
}));
|
|
6937
|
+
return function (_x2) {
|
|
6938
|
+
return _ref3.apply(this, arguments);
|
|
6939
|
+
};
|
|
6940
|
+
}()));
|
|
6941
|
+
case 14:
|
|
6942
|
+
builtHops = _context2.v;
|
|
6943
|
+
case 15:
|
|
6944
|
+
_context2.n = 16;
|
|
6945
|
+
return buildDestInfo({
|
|
6946
|
+
api: api,
|
|
6947
|
+
origin: origin,
|
|
6948
|
+
destination: destination,
|
|
6949
|
+
address: address,
|
|
7031
6950
|
currency: _objectSpread2(_objectSpread2({}, currency), {}, {
|
|
7032
6951
|
amount: amount
|
|
7033
6952
|
}),
|
|
7034
|
-
|
|
6953
|
+
originFee: originFee,
|
|
6954
|
+
isFeeAssetAh: !!isFeeAssetAh,
|
|
6955
|
+
destFeeDetail: destFeeDetail,
|
|
6956
|
+
assetHubFee: assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.fee,
|
|
6957
|
+
bridgeFee: bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.fee
|
|
7035
6958
|
});
|
|
7036
|
-
case
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
case 2:
|
|
7068
|
-
return _context2.a(2, _context2.v);
|
|
7069
|
-
case 3:
|
|
7070
|
-
_context2.p = 3;
|
|
6959
|
+
case 16:
|
|
6960
|
+
destinationInfo = _context2.v;
|
|
6961
|
+
return _context2.a(2, {
|
|
6962
|
+
chain: {
|
|
6963
|
+
origin: origin,
|
|
6964
|
+
destination: destination,
|
|
6965
|
+
ecosystem: getRelayChainSymbol(origin)
|
|
6966
|
+
},
|
|
6967
|
+
origin: {
|
|
6968
|
+
selectedCurrency: {
|
|
6969
|
+
sufficient: originBalanceSufficient,
|
|
6970
|
+
balance: originBalance,
|
|
6971
|
+
balanceAfter: originBalanceAfter,
|
|
6972
|
+
currencySymbol: originAsset.symbol,
|
|
6973
|
+
existentialDeposit: edOrigin
|
|
6974
|
+
},
|
|
6975
|
+
xcmFee: {
|
|
6976
|
+
sufficient: originBalanceNativeSufficient,
|
|
6977
|
+
fee: originFee,
|
|
6978
|
+
balance: originBalanceFee,
|
|
6979
|
+
balanceAfter: originBalanceFeeAfter,
|
|
6980
|
+
currencySymbol: originFeeCurrency
|
|
6981
|
+
}
|
|
6982
|
+
},
|
|
6983
|
+
assetHub: assetHub,
|
|
6984
|
+
bridgeHub: bridgeHub,
|
|
6985
|
+
hops: builtHops,
|
|
6986
|
+
destination: destinationInfo
|
|
6987
|
+
});
|
|
6988
|
+
case 17:
|
|
6989
|
+
_context2.p = 17;
|
|
7071
6990
|
api.setDisconnectAllowed(true);
|
|
7072
|
-
_context2.n =
|
|
6991
|
+
_context2.n = 18;
|
|
7073
6992
|
return api.disconnect();
|
|
7074
|
-
case
|
|
7075
|
-
return _context2.f(
|
|
7076
|
-
case
|
|
6993
|
+
case 18:
|
|
6994
|
+
return _context2.f(17);
|
|
6995
|
+
case 19:
|
|
7077
6996
|
return _context2.a(2);
|
|
7078
6997
|
}
|
|
7079
|
-
}, _callee2, null, [[
|
|
6998
|
+
}, _callee2, null, [[3,, 17, 19]]);
|
|
7080
6999
|
}));
|
|
7081
|
-
return function
|
|
7082
|
-
return
|
|
7000
|
+
return function getTransferInfo(_x) {
|
|
7001
|
+
return _ref2.apply(this, arguments);
|
|
7083
7002
|
};
|
|
7084
7003
|
}();
|
|
7085
7004
|
|
|
7086
|
-
var
|
|
7005
|
+
var calculateTotalXcmFee = function calculateTotalXcmFee(feeResult) {
|
|
7006
|
+
var _feeResult$assetHub;
|
|
7007
|
+
var totalFee = 0n;
|
|
7008
|
+
if (((_feeResult$assetHub = feeResult.assetHub) === null || _feeResult$assetHub === void 0 ? void 0 : _feeResult$assetHub.fee) !== undefined) {
|
|
7009
|
+
totalFee += feeResult.assetHub.fee;
|
|
7010
|
+
}
|
|
7011
|
+
if (feeResult.destination.fee !== undefined) {
|
|
7012
|
+
totalFee += feeResult.destination.fee;
|
|
7013
|
+
}
|
|
7014
|
+
return totalFee;
|
|
7015
|
+
};
|
|
7016
|
+
var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
7087
7017
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
7088
|
-
var api, origin, destination, address,
|
|
7018
|
+
var api, tx, origin, destination, address, senderAddress, feeAsset, currency, destApi, asset, amount, destCurrency, ed, balance, xcmFeeResult, dryRunError, assetHubFeeResult, bridgeHubFeeResult, _xcmFeeResult$destina, destFee, destFeeCurrency, destDryRunError, hopDryRunError, totalFee, method, feeToSubtract;
|
|
7089
7019
|
return _regenerator().w(function (_context) {
|
|
7090
7020
|
while (1) switch (_context.n) {
|
|
7091
7021
|
case 0:
|
|
7092
|
-
api = _ref.api,
|
|
7093
|
-
|
|
7094
|
-
if (!(destination !== 'Ethereum')) {
|
|
7022
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, feeAsset = _ref.feeAsset, currency = _ref.currency;
|
|
7023
|
+
if (!(destination === 'Ethereum')) {
|
|
7095
7024
|
_context.n = 1;
|
|
7096
7025
|
break;
|
|
7097
7026
|
}
|
|
7098
|
-
_context.
|
|
7099
|
-
return destApi.init(destination);
|
|
7027
|
+
return _context.a(2, true);
|
|
7100
7028
|
case 1:
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
if (edDest) {
|
|
7029
|
+
validateAddress(address, destination);
|
|
7030
|
+
if (!(origin === 'AssetHubPolkadot' && destination === 'AssetHubKusama')) {
|
|
7104
7031
|
_context.n = 2;
|
|
7105
7032
|
break;
|
|
7106
7033
|
}
|
|
7107
|
-
throw new InvalidParameterError(
|
|
7034
|
+
throw new InvalidParameterError('Kusama is outside of Polkadot ecosystem, thus function is unable to verify the existential deposit for it.');
|
|
7108
7035
|
case 2:
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7036
|
+
if (!(origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot')) {
|
|
7037
|
+
_context.n = 3;
|
|
7038
|
+
break;
|
|
7039
|
+
}
|
|
7040
|
+
throw new InvalidParameterError('Polkadot is outside of Kusama ecosystem, thus function is unable to verify the existential deposit for it.');
|
|
7041
|
+
case 3:
|
|
7042
|
+
destApi = api.clone();
|
|
7043
|
+
_context.n = 4;
|
|
7044
|
+
return destApi.init(destination);
|
|
7045
|
+
case 4:
|
|
7046
|
+
asset = findAssetOnDestOrThrow(origin, destination, currency);
|
|
7047
|
+
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
7048
|
+
destCurrency = asset.location ? {
|
|
7049
|
+
location: asset.location
|
|
7112
7050
|
} : {
|
|
7113
|
-
symbol:
|
|
7051
|
+
symbol: asset.symbol
|
|
7114
7052
|
};
|
|
7115
|
-
|
|
7053
|
+
ed = getExistentialDepositOrThrow(destination, destCurrency);
|
|
7054
|
+
_context.n = 5;
|
|
7116
7055
|
return getAssetBalanceInternal({
|
|
7117
|
-
api: destApi,
|
|
7118
7056
|
address: address,
|
|
7119
7057
|
chain: destination,
|
|
7058
|
+
api: destApi,
|
|
7120
7059
|
currency: destCurrency
|
|
7121
7060
|
});
|
|
7122
|
-
case
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7061
|
+
case 5:
|
|
7062
|
+
balance = _context.v;
|
|
7063
|
+
_context.n = 6;
|
|
7064
|
+
return getXcmFee({
|
|
7065
|
+
api: api,
|
|
7066
|
+
tx: tx,
|
|
7067
|
+
origin: origin,
|
|
7068
|
+
destination: destination,
|
|
7069
|
+
senderAddress: senderAddress,
|
|
7070
|
+
address: address,
|
|
7071
|
+
currency: _objectSpread2(_objectSpread2({}, currency), {}, {
|
|
7072
|
+
amount: amount
|
|
7073
|
+
}),
|
|
7074
|
+
feeAsset: feeAsset,
|
|
7075
|
+
disableFallback: false
|
|
7076
|
+
});
|
|
7077
|
+
case 6:
|
|
7078
|
+
xcmFeeResult = _context.v;
|
|
7079
|
+
dryRunError = xcmFeeResult.origin.dryRunError, assetHubFeeResult = xcmFeeResult.assetHub, bridgeHubFeeResult = xcmFeeResult.bridgeHub, _xcmFeeResult$destina = xcmFeeResult.destination, destFee = _xcmFeeResult$destina.fee, destFeeCurrency = _xcmFeeResult$destina.currency, destDryRunError = _xcmFeeResult$destina.dryRunError;
|
|
7080
|
+
if (!(destFee === undefined)) {
|
|
7081
|
+
_context.n = 7;
|
|
7082
|
+
break;
|
|
7128
7083
|
}
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
if (isAssetHubToAssetHubRoute) {
|
|
7135
|
-
nativeAssetOfOriginSymbol = getNativeAssetSymbol(origin);
|
|
7136
|
-
isOriginAssetNative = false;
|
|
7137
|
-
if (destAsset.symbol === nativeAssetOfOriginSymbol) {
|
|
7138
|
-
isOriginAssetNative = true;
|
|
7139
|
-
}
|
|
7140
|
-
if (isOriginAssetNative) {
|
|
7141
|
-
if (bridgeFee === undefined) {
|
|
7142
|
-
receivedAmount = new UnableToComputeError("bridgeFee is required for native asset transfer from ".concat(origin, " to ").concat(destination, " but was not provided."));
|
|
7143
|
-
} else {
|
|
7144
|
-
receivedAmount = BigInt(currency.amount) - originFee - bridgeFee;
|
|
7145
|
-
}
|
|
7146
|
-
} else {
|
|
7147
|
-
receivedAmount = new UnableToComputeError("Unable to compute received amount: The transferred asset (".concat(destAsset.symbol, ") is not the native asset (").concat(nativeAssetOfOriginSymbol, ") of origin ").concat(origin, " for the ").concat(origin, "->").concat(destination, " route."));
|
|
7148
|
-
}
|
|
7149
|
-
} else {
|
|
7150
|
-
if (destbalanceAfterResult instanceof UnableToComputeError) {
|
|
7151
|
-
receivedAmount = destbalanceAfterResult;
|
|
7152
|
-
} else {
|
|
7153
|
-
receivedAmount = destbalanceAfterResult - destBalance;
|
|
7154
|
-
}
|
|
7084
|
+
throw new InvalidParameterError("Cannot get destination xcm fee for currency ".concat(JSON.stringify(currency, replaceBigInt), " on chain ").concat(destination, "."));
|
|
7085
|
+
case 7:
|
|
7086
|
+
if (!dryRunError) {
|
|
7087
|
+
_context.n = 8;
|
|
7088
|
+
break;
|
|
7155
7089
|
}
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7090
|
+
throw new DryRunFailedError(dryRunError, 'origin');
|
|
7091
|
+
case 8:
|
|
7092
|
+
hopDryRunError = (assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.dryRunError) || (bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.dryRunError);
|
|
7093
|
+
if (!hopDryRunError) {
|
|
7094
|
+
_context.n = 9;
|
|
7159
7095
|
break;
|
|
7160
7096
|
}
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
}
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
case
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
existentialDeposit: edDestBn
|
|
7184
|
-
},
|
|
7185
|
-
xcmFee: {
|
|
7186
|
-
fee: destFeeDetail.fee,
|
|
7187
|
-
balance: destXcmFeeBalance,
|
|
7188
|
-
balanceAfter: destXcmFeeBalanceAfter,
|
|
7189
|
-
currencySymbol: destFeeDetail.currency
|
|
7190
|
-
}
|
|
7191
|
-
});
|
|
7097
|
+
throw new DryRunFailedError(hopDryRunError, assetHubFeeResult !== null && assetHubFeeResult !== void 0 && assetHubFeeResult.dryRunError ? 'assetHub' : 'bridgeHub');
|
|
7098
|
+
case 9:
|
|
7099
|
+
if (!destDryRunError) {
|
|
7100
|
+
_context.n = 10;
|
|
7101
|
+
break;
|
|
7102
|
+
}
|
|
7103
|
+
throw new UnableToComputeError("Unable to compute fee for the destination asset. Destination dry run error: ".concat(destDryRunError));
|
|
7104
|
+
case 10:
|
|
7105
|
+
if (!(normalizeSymbol(asset.symbol) !== normalizeSymbol(destFeeCurrency))) {
|
|
7106
|
+
_context.n = 11;
|
|
7107
|
+
break;
|
|
7108
|
+
}
|
|
7109
|
+
throw new UnableToComputeError("The XCM fee could not be calculated because the origin or destination chain does not support DryRun.\n As a result, fee estimation is only available through PaymentInfo, which provides the cost in the native asset.\n This limitation restricts support to transfers involving the native asset of the Destination chain only.");
|
|
7110
|
+
case 11:
|
|
7111
|
+
totalFee = calculateTotalXcmFee(xcmFeeResult);
|
|
7112
|
+
method = api.getMethod(tx);
|
|
7113
|
+
if (method === 'transfer_assets_using_type_and_then' || method === 'transferAssetsUsingTypeAndThen') {
|
|
7114
|
+
feeToSubtract = totalFee;
|
|
7115
|
+
} else {
|
|
7116
|
+
feeToSubtract = destFee;
|
|
7117
|
+
}
|
|
7118
|
+
return _context.a(2, amount - feeToSubtract > (balance < ed ? ed : 0));
|
|
7192
7119
|
}
|
|
7193
7120
|
}, _callee);
|
|
7194
7121
|
}));
|
|
7195
|
-
return function
|
|
7122
|
+
return function verifyEdOnDestinationInternal(_x) {
|
|
7196
7123
|
return _ref2.apply(this, arguments);
|
|
7197
7124
|
};
|
|
7198
7125
|
}();
|
|
7199
7126
|
|
|
7200
|
-
var
|
|
7201
|
-
var
|
|
7202
|
-
var api
|
|
7127
|
+
var verifyEdOnDestination = /*#__PURE__*/function () {
|
|
7128
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
7129
|
+
var api;
|
|
7203
7130
|
return _regenerator().w(function (_context) {
|
|
7204
7131
|
while (1) switch (_context.p = _context.n) {
|
|
7205
7132
|
case 0:
|
|
7206
|
-
api =
|
|
7207
|
-
|
|
7208
|
-
_context.n =
|
|
7209
|
-
return
|
|
7210
|
-
case
|
|
7211
|
-
|
|
7212
|
-
_context.p = 2;
|
|
7213
|
-
resolvedAddress = isChainEvm(originChain) && ahAddress ? ahAddress : senderAddress;
|
|
7214
|
-
_context.n = 3;
|
|
7215
|
-
return getBalanceNativeInternal({
|
|
7216
|
-
api: hopApi,
|
|
7217
|
-
address: resolvedAddress,
|
|
7218
|
-
chain: chain
|
|
7219
|
-
});
|
|
7133
|
+
api = options.api;
|
|
7134
|
+
_context.p = 1;
|
|
7135
|
+
_context.n = 2;
|
|
7136
|
+
return verifyEdOnDestinationInternal(options);
|
|
7137
|
+
case 2:
|
|
7138
|
+
return _context.a(2, _context.v);
|
|
7220
7139
|
case 3:
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
fee: feeData.fee,
|
|
7225
|
-
balance: nativeBalanceOnHop,
|
|
7226
|
-
currencySymbol: nativeAssetSymbolOnHop
|
|
7227
|
-
};
|
|
7228
|
-
isBridgeHub = chain.includes('BridgeHub');
|
|
7229
|
-
if (!isBridgeHub) {
|
|
7230
|
-
_context.n = 4;
|
|
7231
|
-
break;
|
|
7232
|
-
}
|
|
7233
|
-
return _context.a(2, {
|
|
7234
|
-
currencySymbol: getNativeAssetSymbol(chain),
|
|
7235
|
-
xcmFee: xcmFeeDetails
|
|
7236
|
-
});
|
|
7140
|
+
_context.p = 3;
|
|
7141
|
+
_context.n = 4;
|
|
7142
|
+
return api.disconnect();
|
|
7237
7143
|
case 4:
|
|
7238
|
-
|
|
7239
|
-
hopCurrencyPayload = hopAsset.location ? {
|
|
7240
|
-
location: hopAsset.location
|
|
7241
|
-
} : {
|
|
7242
|
-
symbol: hopAsset.symbol
|
|
7243
|
-
};
|
|
7244
|
-
_context.n = 5;
|
|
7245
|
-
return getAssetBalanceInternal({
|
|
7246
|
-
api: hopApi,
|
|
7247
|
-
address: resolvedAddress,
|
|
7248
|
-
chain: chain,
|
|
7249
|
-
currency: hopCurrencyPayload
|
|
7250
|
-
});
|
|
7144
|
+
return _context.f(3);
|
|
7251
7145
|
case 5:
|
|
7252
|
-
balance = _context.v;
|
|
7253
|
-
ed = getExistentialDeposit(chain, hopCurrencyPayload);
|
|
7254
|
-
if (ed) {
|
|
7255
|
-
_context.n = 6;
|
|
7256
|
-
break;
|
|
7257
|
-
}
|
|
7258
|
-
throw new InvalidParameterError("Existential deposit not found for chain ".concat(chain, " with currency ").concat(JSON.stringify(hopCurrencyPayload)));
|
|
7259
|
-
case 6:
|
|
7260
|
-
return _context.a(2, {
|
|
7261
|
-
balance: balance,
|
|
7262
|
-
currencySymbol: hopAsset.symbol,
|
|
7263
|
-
existentialDeposit: BigInt(ed),
|
|
7264
|
-
xcmFee: xcmFeeDetails
|
|
7265
|
-
});
|
|
7266
|
-
case 7:
|
|
7267
|
-
_context.p = 7;
|
|
7268
|
-
hopApi.setDisconnectAllowed(true);
|
|
7269
|
-
_context.n = 8;
|
|
7270
|
-
return hopApi.disconnect();
|
|
7271
|
-
case 8:
|
|
7272
|
-
return _context.f(7);
|
|
7273
|
-
case 9:
|
|
7274
7146
|
return _context.a(2);
|
|
7275
7147
|
}
|
|
7276
|
-
}, _callee, null, [[
|
|
7148
|
+
}, _callee, null, [[1,, 3, 5]]);
|
|
7277
7149
|
}));
|
|
7278
|
-
return function
|
|
7279
|
-
return
|
|
7280
|
-
};
|
|
7281
|
-
}();
|
|
7282
|
-
|
|
7283
|
-
var
|
|
7284
|
-
var
|
|
7285
|
-
var
|
|
7286
|
-
return _regenerator().w(function (
|
|
7287
|
-
while (1) switch (
|
|
7150
|
+
return function verifyEdOnDestination(_x) {
|
|
7151
|
+
return _ref.apply(this, arguments);
|
|
7152
|
+
};
|
|
7153
|
+
}();
|
|
7154
|
+
|
|
7155
|
+
var isSufficientOrigin = /*#__PURE__*/function () {
|
|
7156
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, origin, destination, senderAddress, feeNative, currency, asset, feeAsset) {
|
|
7157
|
+
var edNative, balanceNative, isNativeAssetToOrigin, isNativeAssetToDest, isSufficientNative, balanceAsset, edAsset, isSufficientAsset;
|
|
7158
|
+
return _regenerator().w(function (_context) {
|
|
7159
|
+
while (1) switch (_context.n) {
|
|
7288
7160
|
case 0:
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
_context2.n = 1;
|
|
7161
|
+
if (!feeAsset) {
|
|
7162
|
+
_context.n = 1;
|
|
7292
7163
|
break;
|
|
7293
7164
|
}
|
|
7294
|
-
|
|
7165
|
+
return _context.a(2, undefined);
|
|
7295
7166
|
case 1:
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
return api.init(origin);
|
|
7299
|
-
case 2:
|
|
7300
|
-
api.setDisconnectAllowed(false);
|
|
7301
|
-
_context2.p = 3;
|
|
7302
|
-
originAsset = findAssetInfoOrThrow(origin, currency, destination);
|
|
7303
|
-
amount = abstractDecimals(currency.amount, originAsset.decimals, api);
|
|
7304
|
-
if (!(feeAsset && resolvedFeeAsset)) {
|
|
7305
|
-
_context2.n = 5;
|
|
7306
|
-
break;
|
|
7307
|
-
}
|
|
7308
|
-
_context2.n = 4;
|
|
7309
|
-
return getAssetBalanceInternal({
|
|
7310
|
-
api: api,
|
|
7311
|
-
address: senderAddress,
|
|
7312
|
-
chain: origin,
|
|
7313
|
-
currency: feeAsset
|
|
7314
|
-
});
|
|
7315
|
-
case 4:
|
|
7316
|
-
_t = _context2.v;
|
|
7317
|
-
_context2.n = 7;
|
|
7318
|
-
break;
|
|
7319
|
-
case 5:
|
|
7320
|
-
_context2.n = 6;
|
|
7167
|
+
edNative = getExistentialDepositOrThrow(origin);
|
|
7168
|
+
_context.n = 2;
|
|
7321
7169
|
return getBalanceNativeInternal({
|
|
7322
7170
|
api: api,
|
|
7323
|
-
address: senderAddress,
|
|
7324
|
-
chain: origin
|
|
7325
|
-
});
|
|
7326
|
-
case 6:
|
|
7327
|
-
_t = _context2.v;
|
|
7328
|
-
case 7:
|
|
7329
|
-
originBalanceFee = _t;
|
|
7330
|
-
_context2.n = 8;
|
|
7331
|
-
return getAssetBalanceInternal({
|
|
7332
|
-
api: api,
|
|
7333
|
-
address: senderAddress,
|
|
7334
7171
|
chain: origin,
|
|
7335
|
-
|
|
7336
|
-
});
|
|
7337
|
-
case 8:
|
|
7338
|
-
originBalance = _context2.v;
|
|
7339
|
-
edOrigin = getExistentialDepositOrThrow(origin, currency);
|
|
7340
|
-
_context2.n = 9;
|
|
7341
|
-
return getXcmFee({
|
|
7342
|
-
api: api,
|
|
7343
|
-
tx: tx,
|
|
7344
|
-
origin: origin,
|
|
7345
|
-
destination: destination,
|
|
7346
|
-
senderAddress: senderAddress,
|
|
7347
|
-
address: address,
|
|
7348
|
-
currency: currency,
|
|
7349
|
-
feeAsset: feeAsset,
|
|
7350
|
-
disableFallback: false
|
|
7172
|
+
address: senderAddress
|
|
7351
7173
|
});
|
|
7352
|
-
case
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
bridgeHubFeeResult = _yield$getXcmFee.bridgeHub;
|
|
7359
|
-
destFeeDetail = _yield$getXcmFee.destination;
|
|
7360
|
-
hops = _yield$getXcmFee.hops;
|
|
7361
|
-
if (!(originFee === undefined)) {
|
|
7362
|
-
_context2.n = 10;
|
|
7174
|
+
case 2:
|
|
7175
|
+
balanceNative = _context.v;
|
|
7176
|
+
isNativeAssetToOrigin = isSymbolMatch(asset.symbol, getNativeAssetSymbol(origin));
|
|
7177
|
+
isNativeAssetToDest = isSymbolMatch(asset.symbol, getNativeAssetSymbol(destination));
|
|
7178
|
+
if (!(isNativeAssetToOrigin && isNativeAssetToDest)) {
|
|
7179
|
+
_context.n = 3;
|
|
7363
7180
|
break;
|
|
7364
7181
|
}
|
|
7365
|
-
|
|
7366
|
-
case
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - amount : originBalanceFee - originFee;
|
|
7370
|
-
originBalanceNativeSufficient = originBalanceFee >= originFee;
|
|
7371
|
-
originBalanceSufficient = originBalanceAfter >= edOrigin;
|
|
7372
|
-
if (!assetHubFeeResult) {
|
|
7373
|
-
_context2.n = 12;
|
|
7182
|
+
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
7183
|
+
case 3:
|
|
7184
|
+
if (isNativeAssetToOrigin) {
|
|
7185
|
+
_context.n = 5;
|
|
7374
7186
|
break;
|
|
7375
7187
|
}
|
|
7376
|
-
|
|
7377
|
-
|
|
7188
|
+
isSufficientNative = balanceNative - edNative - feeNative > 0n;
|
|
7189
|
+
_context.n = 4;
|
|
7190
|
+
return getAssetBalance({
|
|
7378
7191
|
api: api,
|
|
7379
|
-
chain:
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
currency: currency,
|
|
7383
|
-
senderAddress: senderAddress,
|
|
7384
|
-
ahAddress: ahAddress
|
|
7192
|
+
chain: origin,
|
|
7193
|
+
address: senderAddress,
|
|
7194
|
+
currency: currency
|
|
7385
7195
|
});
|
|
7386
|
-
case
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7196
|
+
case 4:
|
|
7197
|
+
balanceAsset = _context.v;
|
|
7198
|
+
edAsset = getExistentialDepositOrThrow(origin, currency);
|
|
7199
|
+
isSufficientAsset = balanceAsset - edAsset > 0n;
|
|
7200
|
+
return _context.a(2, isSufficientNative && isSufficientAsset);
|
|
7201
|
+
case 5:
|
|
7202
|
+
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
7203
|
+
case 6:
|
|
7204
|
+
return _context.a(2);
|
|
7205
|
+
}
|
|
7206
|
+
}, _callee);
|
|
7207
|
+
}));
|
|
7208
|
+
return function isSufficientOrigin(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) {
|
|
7209
|
+
return _ref.apply(this, arguments);
|
|
7210
|
+
};
|
|
7211
|
+
}();
|
|
7212
|
+
var isSufficientDestination = /*#__PURE__*/function () {
|
|
7213
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, destination, address, amount, asset, feeNative) {
|
|
7214
|
+
var isNativeAsset, existentialDeposit, nativeBalance;
|
|
7215
|
+
return _regenerator().w(function (_context2) {
|
|
7216
|
+
while (1) switch (_context2.n) {
|
|
7217
|
+
case 0:
|
|
7218
|
+
isNativeAsset = isSymbolMatch(asset.symbol, getNativeAssetSymbol(destination));
|
|
7219
|
+
if (isNativeAsset) {
|
|
7220
|
+
_context2.n = 1;
|
|
7391
7221
|
break;
|
|
7392
7222
|
}
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7223
|
+
return _context2.a(2, undefined);
|
|
7224
|
+
case 1:
|
|
7225
|
+
existentialDeposit = getExistentialDepositOrThrow(destination);
|
|
7226
|
+
_context2.n = 2;
|
|
7227
|
+
return getBalanceNativeInternal({
|
|
7396
7228
|
api: api,
|
|
7397
|
-
chain:
|
|
7398
|
-
|
|
7399
|
-
originChain: origin,
|
|
7400
|
-
currency: currency,
|
|
7401
|
-
senderAddress: senderAddress,
|
|
7402
|
-
ahAddress: ahAddress
|
|
7229
|
+
chain: destination,
|
|
7230
|
+
address: address
|
|
7403
7231
|
});
|
|
7404
|
-
case
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7232
|
+
case 2:
|
|
7233
|
+
nativeBalance = _context2.v;
|
|
7234
|
+
return _context2.a(2, nativeBalance + amount - existentialDeposit - feeNative > 0n);
|
|
7235
|
+
}
|
|
7236
|
+
}, _callee2);
|
|
7237
|
+
}));
|
|
7238
|
+
return function isSufficientDestination(_x9, _x0, _x1, _x10, _x11, _x12) {
|
|
7239
|
+
return _ref2.apply(this, arguments);
|
|
7240
|
+
};
|
|
7241
|
+
}();
|
|
7242
|
+
|
|
7243
|
+
var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
7244
|
+
if (isRelayChain(origin)) return DOT_LOCATION;
|
|
7245
|
+
return {
|
|
7246
|
+
parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
|
|
7247
|
+
interior: {
|
|
7248
|
+
X1: [{
|
|
7249
|
+
Parachain: getParaId(origin)
|
|
7250
|
+
}]
|
|
7251
|
+
}
|
|
7252
|
+
};
|
|
7253
|
+
};
|
|
7254
|
+
var getDestXcmFee = /*#__PURE__*/function () {
|
|
7255
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
7256
|
+
var api, origin, hopChain, destination, currency, forwardedXcms, asset, address, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, _fee, sufficient, dryRunResult, _fee2, fee, newForwardedXcms, destParaId;
|
|
7257
|
+
return _regenerator().w(function (_context2) {
|
|
7258
|
+
while (1) switch (_context2.n) {
|
|
7259
|
+
case 0:
|
|
7260
|
+
api = options.api, origin = options.origin, hopChain = options.prevChain, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, asset = options.asset, address = options.address, feeAsset = options.feeAsset, originFee = options.originFee, disableFallback = options.disableFallback;
|
|
7261
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
7262
|
+
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
7263
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
7264
|
+
var originAsset, _t;
|
|
7416
7265
|
return _regenerator().w(function (_context) {
|
|
7417
|
-
while (1) switch (_context.n) {
|
|
7266
|
+
while (1) switch (_context.p = _context.n) {
|
|
7418
7267
|
case 0:
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
originChain: origin,
|
|
7425
|
-
currency: currency,
|
|
7426
|
-
senderAddress: senderAddress,
|
|
7427
|
-
ahAddress: ahAddress
|
|
7428
|
-
});
|
|
7268
|
+
if (!(destination === 'Ethereum')) {
|
|
7269
|
+
_context.n = 1;
|
|
7270
|
+
break;
|
|
7271
|
+
}
|
|
7272
|
+
return _context.a(2, 0n);
|
|
7429
7273
|
case 1:
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7274
|
+
originAsset = findAssetInfoOrThrow(origin, currency, destination);
|
|
7275
|
+
if (!originAsset.location) {
|
|
7276
|
+
_context.n = 7;
|
|
7277
|
+
break;
|
|
7278
|
+
}
|
|
7279
|
+
_context.p = 2;
|
|
7280
|
+
_context.n = 3;
|
|
7281
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
7282
|
+
destination: destination
|
|
7283
|
+
}), {
|
|
7284
|
+
location: originAsset.location
|
|
7285
|
+
});
|
|
7286
|
+
case 3:
|
|
7287
|
+
return _context.a(2, _context.v);
|
|
7288
|
+
case 4:
|
|
7289
|
+
_context.p = 4;
|
|
7290
|
+
_t = _context.v;
|
|
7291
|
+
if (!(_t instanceof InvalidCurrencyError)) {
|
|
7292
|
+
_context.n = 6;
|
|
7293
|
+
break;
|
|
7294
|
+
}
|
|
7295
|
+
_context.n = 5;
|
|
7296
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
7297
|
+
destination: destination
|
|
7298
|
+
}), {
|
|
7299
|
+
symbol: originAsset.symbol
|
|
7300
|
+
});
|
|
7301
|
+
case 5:
|
|
7302
|
+
return _context.a(2, _context.v);
|
|
7303
|
+
case 6:
|
|
7304
|
+
throw _t;
|
|
7305
|
+
case 7:
|
|
7306
|
+
_context.n = 8;
|
|
7307
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
7308
|
+
destination: destination
|
|
7309
|
+
}), {
|
|
7310
|
+
symbol: originAsset.symbol
|
|
7434
7311
|
});
|
|
7312
|
+
case 8:
|
|
7313
|
+
return _context.a(2, _context.v);
|
|
7435
7314
|
}
|
|
7436
|
-
}, _callee);
|
|
7315
|
+
}, _callee, null, [[2, 4]]);
|
|
7437
7316
|
}));
|
|
7438
|
-
return function (
|
|
7439
|
-
return
|
|
7317
|
+
return function calcPaymentInfoFee() {
|
|
7318
|
+
return _ref2.apply(this, arguments);
|
|
7440
7319
|
};
|
|
7441
|
-
}()
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7320
|
+
}();
|
|
7321
|
+
if (!(!hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
|
|
7322
|
+
_context2.n = 3;
|
|
7323
|
+
break;
|
|
7324
|
+
}
|
|
7325
|
+
_context2.n = 1;
|
|
7326
|
+
return calcPaymentInfoFee();
|
|
7327
|
+
case 1:
|
|
7328
|
+
_fee = _context2.v;
|
|
7329
|
+
_context2.n = 2;
|
|
7330
|
+
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee);
|
|
7331
|
+
case 2:
|
|
7332
|
+
sufficient = _context2.v;
|
|
7333
|
+
return _context2.a(2, {
|
|
7334
|
+
fee: _fee,
|
|
7335
|
+
feeType: 'paymentInfo',
|
|
7336
|
+
sufficient: !hasDryRunSupport(destination) ? sufficient : false
|
|
7337
|
+
});
|
|
7338
|
+
case 3:
|
|
7339
|
+
_context2.n = 4;
|
|
7340
|
+
return api.getDryRunXcm({
|
|
7341
|
+
originLocation: addXcmVersionHeader(createOriginLocation(hopChain, destination), Version.V4),
|
|
7342
|
+
xcm: forwardedXcms[1][0],
|
|
7343
|
+
chain: destination,
|
|
7448
7344
|
origin: origin,
|
|
7449
|
-
|
|
7450
|
-
address: address,
|
|
7451
|
-
currency: _objectSpread2(_objectSpread2({}, currency), {}, {
|
|
7452
|
-
amount: amount
|
|
7453
|
-
}),
|
|
7345
|
+
asset: asset,
|
|
7454
7346
|
originFee: originFee,
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
assetHubFee: assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.fee,
|
|
7458
|
-
bridgeFee: bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.fee
|
|
7347
|
+
feeAsset: resolvedFeeAsset,
|
|
7348
|
+
amount: BigInt(currency.amount) < 2n ? 2n : BigInt(currency.amount)
|
|
7459
7349
|
});
|
|
7460
|
-
case
|
|
7461
|
-
|
|
7350
|
+
case 4:
|
|
7351
|
+
dryRunResult = _context2.v;
|
|
7352
|
+
if (dryRunResult.success) {
|
|
7353
|
+
_context2.n = 7;
|
|
7354
|
+
break;
|
|
7355
|
+
}
|
|
7356
|
+
if (!disableFallback) {
|
|
7357
|
+
_context2.n = 5;
|
|
7358
|
+
break;
|
|
7359
|
+
}
|
|
7462
7360
|
return _context2.a(2, {
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
7467
|
-
|
|
7468
|
-
|
|
7469
|
-
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
assetHub: assetHub,
|
|
7485
|
-
bridgeHub: bridgeHub,
|
|
7486
|
-
hops: builtHops,
|
|
7487
|
-
destination: destinationInfo
|
|
7361
|
+
dryRunError: dryRunResult.failureReason
|
|
7362
|
+
});
|
|
7363
|
+
case 5:
|
|
7364
|
+
_context2.n = 6;
|
|
7365
|
+
return calcPaymentInfoFee();
|
|
7366
|
+
case 6:
|
|
7367
|
+
_fee2 = _context2.v;
|
|
7368
|
+
return _context2.a(2, {
|
|
7369
|
+
fee: _fee2,
|
|
7370
|
+
feeType: 'paymentInfo',
|
|
7371
|
+
dryRunError: dryRunResult.failureReason,
|
|
7372
|
+
sufficient: false
|
|
7373
|
+
});
|
|
7374
|
+
case 7:
|
|
7375
|
+
fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
7376
|
+
return _context2.a(2, {
|
|
7377
|
+
fee: fee,
|
|
7378
|
+
feeType: 'dryRun',
|
|
7379
|
+
sufficient: true,
|
|
7380
|
+
forwardedXcms: newForwardedXcms,
|
|
7381
|
+
destParaId: destParaId
|
|
7488
7382
|
});
|
|
7489
|
-
case 18:
|
|
7490
|
-
_context2.p = 18;
|
|
7491
|
-
api.setDisconnectAllowed(true);
|
|
7492
|
-
_context2.n = 19;
|
|
7493
|
-
return api.disconnect();
|
|
7494
|
-
case 19:
|
|
7495
|
-
return _context2.f(18);
|
|
7496
|
-
case 20:
|
|
7497
|
-
return _context2.a(2);
|
|
7498
7383
|
}
|
|
7499
|
-
}, _callee2
|
|
7384
|
+
}, _callee2);
|
|
7500
7385
|
}));
|
|
7501
|
-
return function
|
|
7502
|
-
return
|
|
7386
|
+
return function getDestXcmFee(_x) {
|
|
7387
|
+
return _ref.apply(this, arguments);
|
|
7503
7388
|
};
|
|
7504
7389
|
}();
|
|
7505
7390
|
|
|
7506
|
-
var
|
|
7507
|
-
|
|
7508
|
-
var
|
|
7509
|
-
|
|
7510
|
-
|
|
7391
|
+
var getFailureInfo = function getFailureInfo(results, hops) {
|
|
7392
|
+
// Check standard chains first for backwards compatibility
|
|
7393
|
+
for (var _i = 0, _arr = ['destination', 'assetHub', 'bridgeHub']; _i < _arr.length; _i++) {
|
|
7394
|
+
var chain = _arr[_i];
|
|
7395
|
+
var res = results[chain];
|
|
7396
|
+
if (res && !res.success && res.failureReason) {
|
|
7397
|
+
return {
|
|
7398
|
+
failureReason: res.failureReason,
|
|
7399
|
+
failureChain: chain
|
|
7400
|
+
};
|
|
7401
|
+
}
|
|
7511
7402
|
}
|
|
7512
|
-
|
|
7513
|
-
|
|
7403
|
+
var _iterator = _createForOfIteratorHelper(hops),
|
|
7404
|
+
_step;
|
|
7405
|
+
try {
|
|
7406
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
7407
|
+
var hop = _step.value;
|
|
7408
|
+
if (!hop.result.success && hop.result.failureReason) {
|
|
7409
|
+
return {
|
|
7410
|
+
failureReason: hop.result.failureReason,
|
|
7411
|
+
failureChain: hop.chain
|
|
7412
|
+
};
|
|
7413
|
+
}
|
|
7414
|
+
}
|
|
7415
|
+
} catch (err) {
|
|
7416
|
+
_iterator.e(err);
|
|
7417
|
+
} finally {
|
|
7418
|
+
_iterator.f();
|
|
7514
7419
|
}
|
|
7515
|
-
return
|
|
7420
|
+
return {};
|
|
7516
7421
|
};
|
|
7517
|
-
var
|
|
7518
|
-
var
|
|
7519
|
-
var
|
|
7520
|
-
|
|
7521
|
-
|
|
7422
|
+
var dryRunInternal = /*#__PURE__*/function () {
|
|
7423
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
7424
|
+
var _traversalResult$brid, _traversalResult$asse, _traversalResult$dest;
|
|
7425
|
+
var api, origin, destination, currency, tx, senderAddress, feeAsset, swapConfig, _options$useRootOrigi, useRootOrigin, resolvedFeeAsset, asset, amount, originDryRun, initialForwardedXcms, initialDestParaId, processHop, traversalResult, assetHubChain, bridgeHubChain, processedBridgeHub, bridgeHubHopIndex, originWithCurrency, assetHubWithCurrency, bridgeHubWithCurrency, destinationWithCurrency, _getFailureInfo, failureReason, failureChain, _t;
|
|
7426
|
+
return _regenerator().w(function (_context2) {
|
|
7427
|
+
while (1) switch (_context2.n) {
|
|
7522
7428
|
case 0:
|
|
7523
|
-
api =
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
return
|
|
7429
|
+
api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset, swapConfig = options.swapConfig, _options$useRootOrigi = options.useRootOrigin, useRootOrigin = _options$useRootOrigi === void 0 ? false : _options$useRootOrigi;
|
|
7430
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
7431
|
+
asset = findAssetInfoOrThrow(origin, currency, destination);
|
|
7432
|
+
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
7433
|
+
_context2.n = 1;
|
|
7434
|
+
return api.getDryRunCall({
|
|
7435
|
+
tx: tx,
|
|
7436
|
+
chain: origin,
|
|
7437
|
+
address: senderAddress,
|
|
7438
|
+
asset: _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
7439
|
+
amount: amount
|
|
7440
|
+
}),
|
|
7441
|
+
feeAsset: resolvedFeeAsset,
|
|
7442
|
+
useRootOrigin: useRootOrigin
|
|
7443
|
+
});
|
|
7529
7444
|
case 1:
|
|
7530
|
-
|
|
7531
|
-
if (
|
|
7532
|
-
|
|
7533
|
-
break;
|
|
7534
|
-
}
|
|
7535
|
-
throw new InvalidParameterError('Kusama is outside of Polkadot ecosystem, thus function is unable to verify the existential deposit for it.');
|
|
7536
|
-
case 2:
|
|
7537
|
-
if (!(origin === 'AssetHubKusama' && destination === 'AssetHubPolkadot')) {
|
|
7538
|
-
_context.n = 3;
|
|
7445
|
+
originDryRun = _context2.v;
|
|
7446
|
+
if (originDryRun.success) {
|
|
7447
|
+
_context2.n = 2;
|
|
7539
7448
|
break;
|
|
7540
7449
|
}
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
case 4:
|
|
7547
|
-
asset = findAssetOnDestOrThrow(origin, destination, currency);
|
|
7548
|
-
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
7549
|
-
destCurrency = asset.location ? {
|
|
7550
|
-
location: asset.location
|
|
7551
|
-
} : {
|
|
7552
|
-
symbol: asset.symbol
|
|
7553
|
-
};
|
|
7554
|
-
ed = getExistentialDepositOrThrow(destination, destCurrency);
|
|
7555
|
-
_context.n = 5;
|
|
7556
|
-
return getAssetBalanceInternal({
|
|
7557
|
-
address: address,
|
|
7558
|
-
chain: destination,
|
|
7559
|
-
api: destApi,
|
|
7560
|
-
currency: destCurrency
|
|
7450
|
+
return _context2.a(2, {
|
|
7451
|
+
failureReason: originDryRun.failureReason,
|
|
7452
|
+
failureChain: 'origin',
|
|
7453
|
+
origin: originDryRun,
|
|
7454
|
+
hops: []
|
|
7561
7455
|
});
|
|
7562
|
-
case
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7456
|
+
case 2:
|
|
7457
|
+
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
7458
|
+
processHop = /*#__PURE__*/function () {
|
|
7459
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
7460
|
+
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, isDestination, hopDryRun, hopCurrency;
|
|
7461
|
+
return _regenerator().w(function (_context) {
|
|
7462
|
+
while (1) switch (_context.n) {
|
|
7463
|
+
case 0:
|
|
7464
|
+
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange, isDestination = params.isDestination;
|
|
7465
|
+
if (hasDryRunSupport(currentChain)) {
|
|
7466
|
+
_context.n = 1;
|
|
7467
|
+
break;
|
|
7468
|
+
}
|
|
7469
|
+
return _context.a(2, {
|
|
7470
|
+
success: false,
|
|
7471
|
+
failureReason: "DryRunApi is not available on chain ".concat(currentChain)
|
|
7472
|
+
});
|
|
7473
|
+
case 1:
|
|
7474
|
+
_context.n = 2;
|
|
7475
|
+
return hopApi.getDryRunXcm({
|
|
7476
|
+
originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain), Version.V4),
|
|
7477
|
+
xcm: forwardedXcms[1][0],
|
|
7478
|
+
chain: currentChain,
|
|
7479
|
+
origin: currentOrigin,
|
|
7480
|
+
asset: currentAsset,
|
|
7481
|
+
feeAsset: resolvedFeeAsset,
|
|
7482
|
+
originFee: originDryRun.fee,
|
|
7483
|
+
amount: amount
|
|
7484
|
+
});
|
|
7485
|
+
case 2:
|
|
7486
|
+
hopDryRun = _context.v;
|
|
7487
|
+
if (!hopDryRun.success) {
|
|
7488
|
+
_context.n = 3;
|
|
7489
|
+
break;
|
|
7490
|
+
}
|
|
7491
|
+
if (destination === 'Ethereum' && (currentChain.includes('AssetHub') || currentChain.includes('BridgeHub'))) {
|
|
7492
|
+
hopCurrency = getNativeAssetSymbol(currentChain);
|
|
7493
|
+
} else if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
|
|
7494
|
+
hopCurrency = findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo).symbol;
|
|
7495
|
+
} else if (isDestination) {
|
|
7496
|
+
hopCurrency = findAssetOnDestOrThrow(origin, currentChain, currency).symbol;
|
|
7497
|
+
} else {
|
|
7498
|
+
hopCurrency = asset.symbol;
|
|
7499
|
+
}
|
|
7500
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, hopDryRun), {}, {
|
|
7501
|
+
currency: hopCurrency
|
|
7502
|
+
}));
|
|
7503
|
+
case 3:
|
|
7504
|
+
return _context.a(2, hopDryRun);
|
|
7505
|
+
}
|
|
7506
|
+
}, _callee);
|
|
7507
|
+
}));
|
|
7508
|
+
return function processHop(_x2) {
|
|
7509
|
+
return _ref2.apply(this, arguments);
|
|
7510
|
+
};
|
|
7511
|
+
}();
|
|
7512
|
+
_context2.n = 3;
|
|
7513
|
+
return traverseXcmHops({
|
|
7566
7514
|
api: api,
|
|
7567
|
-
tx: tx,
|
|
7568
7515
|
origin: origin,
|
|
7569
7516
|
destination: destination,
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7517
|
+
currency: currency,
|
|
7518
|
+
initialForwardedXcms: initialForwardedXcms,
|
|
7519
|
+
initialDestParaId: initialDestParaId,
|
|
7520
|
+
swapConfig: swapConfig,
|
|
7521
|
+
processHop: processHop,
|
|
7522
|
+
shouldContinue: function shouldContinue(hopResult) {
|
|
7523
|
+
return hopResult.success;
|
|
7524
|
+
},
|
|
7525
|
+
extractNextHopData: function extractNextHopData(hopResult) {
|
|
7526
|
+
return {
|
|
7527
|
+
forwardedXcms: hopResult.success ? hopResult.forwardedXcms : undefined,
|
|
7528
|
+
destParaId: hopResult.success ? hopResult.destParaId : undefined
|
|
7529
|
+
};
|
|
7530
|
+
}
|
|
7577
7531
|
});
|
|
7578
|
-
case
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
throw new InvalidParameterError("Cannot get destination xcm fee for currency ".concat(JSON.stringify(currency, replaceBigInt), " on chain ").concat(destination, "."));
|
|
7586
|
-
case 7:
|
|
7587
|
-
if (!dryRunError) {
|
|
7588
|
-
_context.n = 8;
|
|
7589
|
-
break;
|
|
7590
|
-
}
|
|
7591
|
-
throw new DryRunFailedError(dryRunError, 'origin');
|
|
7592
|
-
case 8:
|
|
7593
|
-
hopDryRunError = (assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.dryRunError) || (bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.dryRunError);
|
|
7594
|
-
if (!hopDryRunError) {
|
|
7595
|
-
_context.n = 9;
|
|
7596
|
-
break;
|
|
7597
|
-
}
|
|
7598
|
-
throw new DryRunFailedError(hopDryRunError, assetHubFeeResult !== null && assetHubFeeResult !== void 0 && assetHubFeeResult.dryRunError ? 'assetHub' : 'bridgeHub');
|
|
7599
|
-
case 9:
|
|
7600
|
-
if (!destDryRunError) {
|
|
7601
|
-
_context.n = 10;
|
|
7602
|
-
break;
|
|
7603
|
-
}
|
|
7604
|
-
throw new UnableToComputeError("Unable to compute fee for the destination asset. Destination dry run error: ".concat(destDryRunError));
|
|
7605
|
-
case 10:
|
|
7606
|
-
if (!(normalizeSymbol(asset.symbol) !== normalizeSymbol(destFeeCurrency))) {
|
|
7607
|
-
_context.n = 11;
|
|
7532
|
+
case 3:
|
|
7533
|
+
traversalResult = _context2.v;
|
|
7534
|
+
// Process Ethereum bridge fees
|
|
7535
|
+
assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
|
|
7536
|
+
bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
|
|
7537
|
+
if (!((_traversalResult$brid = traversalResult.bridgeHub) !== null && _traversalResult$brid !== void 0 && _traversalResult$brid.success)) {
|
|
7538
|
+
_context2.n = 5;
|
|
7608
7539
|
break;
|
|
7609
7540
|
}
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
totalFee = calculateTotalXcmFee(xcmFeeResult);
|
|
7613
|
-
method = api.getMethod(tx);
|
|
7614
|
-
if (method === 'transfer_assets_using_type_and_then' || method === 'transferAssetsUsingTypeAndThen') {
|
|
7615
|
-
feeToSubtract = totalFee;
|
|
7616
|
-
} else {
|
|
7617
|
-
feeToSubtract = destFee;
|
|
7618
|
-
}
|
|
7619
|
-
return _context.a(2, amount - feeToSubtract > (balance < ed ? ed : 0));
|
|
7620
|
-
}
|
|
7621
|
-
}, _callee);
|
|
7622
|
-
}));
|
|
7623
|
-
return function verifyEdOnDestinationInternal(_x) {
|
|
7624
|
-
return _ref2.apply(this, arguments);
|
|
7625
|
-
};
|
|
7626
|
-
}();
|
|
7627
|
-
|
|
7628
|
-
var verifyEdOnDestination = /*#__PURE__*/function () {
|
|
7629
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
7630
|
-
var api;
|
|
7631
|
-
return _regenerator().w(function (_context) {
|
|
7632
|
-
while (1) switch (_context.p = _context.n) {
|
|
7633
|
-
case 0:
|
|
7634
|
-
api = options.api;
|
|
7635
|
-
_context.p = 1;
|
|
7636
|
-
_context.n = 2;
|
|
7637
|
-
return verifyEdOnDestinationInternal(options);
|
|
7638
|
-
case 2:
|
|
7639
|
-
return _context.a(2, _context.v);
|
|
7640
|
-
case 3:
|
|
7641
|
-
_context.p = 3;
|
|
7642
|
-
_context.n = 4;
|
|
7643
|
-
return api.disconnect();
|
|
7541
|
+
_context2.n = 4;
|
|
7542
|
+
return addEthereumBridgeFees(api, traversalResult.bridgeHub, destination, assetHubChain);
|
|
7644
7543
|
case 4:
|
|
7645
|
-
|
|
7544
|
+
_t = _context2.v;
|
|
7545
|
+
_context2.n = 6;
|
|
7546
|
+
break;
|
|
7646
7547
|
case 5:
|
|
7647
|
-
|
|
7548
|
+
_t = traversalResult.bridgeHub;
|
|
7549
|
+
case 6:
|
|
7550
|
+
processedBridgeHub = _t;
|
|
7551
|
+
// Update bridge hub in hops if needed
|
|
7552
|
+
if (processedBridgeHub && processedBridgeHub.success && traversalResult.bridgeHub && traversalResult.bridgeHub.success && processedBridgeHub.fee !== traversalResult.bridgeHub.fee) {
|
|
7553
|
+
bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
|
|
7554
|
+
return hop.chain === bridgeHubChain;
|
|
7555
|
+
});
|
|
7556
|
+
if (bridgeHubHopIndex !== -1 && traversalResult.hops[bridgeHubHopIndex].result.success) {
|
|
7557
|
+
traversalResult.hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, traversalResult.hops[bridgeHubHopIndex].result), {}, {
|
|
7558
|
+
fee: processedBridgeHub.fee
|
|
7559
|
+
});
|
|
7560
|
+
}
|
|
7561
|
+
}
|
|
7562
|
+
originWithCurrency = originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
|
|
7563
|
+
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(origin)
|
|
7564
|
+
}) : originDryRun;
|
|
7565
|
+
assetHubWithCurrency = (_traversalResult$asse = traversalResult.assetHub) !== null && _traversalResult$asse !== void 0 && _traversalResult$asse.success ? _objectSpread2(_objectSpread2({}, traversalResult.assetHub), {}, {
|
|
7566
|
+
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(assetHubChain)
|
|
7567
|
+
}) : traversalResult.assetHub;
|
|
7568
|
+
bridgeHubWithCurrency = processedBridgeHub !== null && processedBridgeHub !== void 0 && processedBridgeHub.success ? _objectSpread2(_objectSpread2({}, processedBridgeHub), {}, {
|
|
7569
|
+
currency: getNativeAssetSymbol(bridgeHubChain)
|
|
7570
|
+
}) : processedBridgeHub;
|
|
7571
|
+
destinationWithCurrency = (_traversalResult$dest = traversalResult.destination) !== null && _traversalResult$dest !== void 0 && _traversalResult$dest.success ? _objectSpread2(_objectSpread2({}, traversalResult.destination), {}, {
|
|
7572
|
+
currency: asset === null || asset === void 0 ? void 0 : asset.symbol
|
|
7573
|
+
}) : traversalResult.destination;
|
|
7574
|
+
_getFailureInfo = getFailureInfo({
|
|
7575
|
+
destination: destinationWithCurrency,
|
|
7576
|
+
assetHub: assetHubWithCurrency,
|
|
7577
|
+
bridgeHub: bridgeHubWithCurrency
|
|
7578
|
+
}, traversalResult.hops), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
|
|
7579
|
+
return _context2.a(2, {
|
|
7580
|
+
failureReason: failureReason,
|
|
7581
|
+
failureChain: failureChain,
|
|
7582
|
+
origin: originWithCurrency,
|
|
7583
|
+
assetHub: assetHubWithCurrency,
|
|
7584
|
+
bridgeHub: bridgeHubWithCurrency,
|
|
7585
|
+
destination: destinationWithCurrency,
|
|
7586
|
+
hops: traversalResult.hops
|
|
7587
|
+
});
|
|
7648
7588
|
}
|
|
7649
|
-
},
|
|
7589
|
+
}, _callee2);
|
|
7650
7590
|
}));
|
|
7651
|
-
return function
|
|
7591
|
+
return function dryRunInternal(_x) {
|
|
7652
7592
|
return _ref.apply(this, arguments);
|
|
7653
7593
|
};
|
|
7654
7594
|
}();
|
|
7655
7595
|
|
|
7656
|
-
var validateHops = function validateHops(hops) {
|
|
7657
|
-
var _iterator = _createForOfIteratorHelper(hops),
|
|
7658
|
-
_step;
|
|
7659
|
-
try {
|
|
7660
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
7661
|
-
var hop = _step.value;
|
|
7662
|
-
if (!hop.result.success) {
|
|
7663
|
-
throw new DryRunFailedError("Dry run failed on an intermediate hop (".concat(hop.chain, "). Reason: ").concat(hop.result.failureReason || 'Unknown'));
|
|
7664
|
-
}
|
|
7665
|
-
}
|
|
7666
|
-
} catch (err) {
|
|
7667
|
-
_iterator.e(err);
|
|
7668
|
-
} finally {
|
|
7669
|
-
_iterator.f();
|
|
7670
|
-
}
|
|
7671
|
-
};
|
|
7672
7596
|
var getReserveFeeFromHops = function getReserveFeeFromHops(hops) {
|
|
7673
7597
|
if (!hops || hops.length === 0 || !hops[0].result.success) {
|
|
7674
7598
|
return MIN_FEE;
|
|
@@ -7678,7 +7602,7 @@ var getReserveFeeFromHops = function getReserveFeeFromHops(hops) {
|
|
|
7678
7602
|
var FEE_PADDING_PERCENTAGE$1 = 40;
|
|
7679
7603
|
var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
7680
7604
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options) {
|
|
7681
|
-
var api, senderAddress, paraIdTo, assetInfo, currency, feeCurrency, address, feeAssetInfo, version,
|
|
7605
|
+
var api, senderAddress, paraIdTo, assetInfo, currency, feeCurrency, address, feeAssetInfo, version, checkAmount, destChain, internalOptions, FEE_ASSET_AMOUNT, feeAssetAmount, call, dryRunResult, originFeeEstimate, originFee, reserveFeeEstimate, reserveFee, xcm, weight;
|
|
7682
7606
|
return _regenerator().w(function (_context) {
|
|
7683
7607
|
while (1) switch (_context.n) {
|
|
7684
7608
|
case 0:
|
|
@@ -7690,25 +7614,6 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7690
7614
|
throw new InvalidParameterError('Please provide senderAddress');
|
|
7691
7615
|
case 1:
|
|
7692
7616
|
assertAddressIsString(address);
|
|
7693
|
-
if (!(feeCurrency && feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo))) {
|
|
7694
|
-
_context.n = 3;
|
|
7695
|
-
break;
|
|
7696
|
-
}
|
|
7697
|
-
_context.n = 2;
|
|
7698
|
-
return getAssetBalanceInternal({
|
|
7699
|
-
api: api,
|
|
7700
|
-
address: senderAddress,
|
|
7701
|
-
chain: chain,
|
|
7702
|
-
currency: feeCurrency
|
|
7703
|
-
});
|
|
7704
|
-
case 2:
|
|
7705
|
-
_t = _context.v;
|
|
7706
|
-
_context.n = 4;
|
|
7707
|
-
break;
|
|
7708
|
-
case 3:
|
|
7709
|
-
_t = undefined;
|
|
7710
|
-
case 4:
|
|
7711
|
-
feeAssetBalance = _t;
|
|
7712
7617
|
checkAmount = function checkAmount(fee) {
|
|
7713
7618
|
if (assetInfo.amount <= fee) {
|
|
7714
7619
|
throw new InvalidParameterError("Asset amount is too low, please increase the amount or use a different fee asset.");
|
|
@@ -7729,14 +7634,16 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7729
7634
|
senderAddress: senderAddress,
|
|
7730
7635
|
version: version,
|
|
7731
7636
|
paraIdTo: paraIdTo
|
|
7732
|
-
};
|
|
7637
|
+
}; // We mint 1000 units of feeAsset and use 100
|
|
7638
|
+
FEE_ASSET_AMOUNT = 100;
|
|
7639
|
+
feeAssetAmount = feeAssetInfo ? parseUnits(FEE_ASSET_AMOUNT.toString(), feeAssetInfo.decimals) : MIN_FEE;
|
|
7733
7640
|
call = createExecuteCall(chain, createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7734
7641
|
fees: {
|
|
7735
|
-
originFee:
|
|
7642
|
+
originFee: feeAssetAmount,
|
|
7736
7643
|
reserveFee: MIN_FEE
|
|
7737
7644
|
}
|
|
7738
7645
|
})), MAX_WEIGHT);
|
|
7739
|
-
_context.n =
|
|
7646
|
+
_context.n = 2;
|
|
7740
7647
|
return dryRunInternal({
|
|
7741
7648
|
api: api,
|
|
7742
7649
|
tx: api.callTxMethod(call),
|
|
@@ -7745,17 +7652,17 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7745
7652
|
senderAddress: senderAddress,
|
|
7746
7653
|
address: address,
|
|
7747
7654
|
currency: currency,
|
|
7748
|
-
feeAsset: feeCurrency
|
|
7655
|
+
feeAsset: feeCurrency,
|
|
7656
|
+
useRootOrigin: true
|
|
7749
7657
|
});
|
|
7750
|
-
case
|
|
7658
|
+
case 2:
|
|
7751
7659
|
dryRunResult = _context.v;
|
|
7752
7660
|
if (dryRunResult.origin.success) {
|
|
7753
|
-
_context.n =
|
|
7661
|
+
_context.n = 3;
|
|
7754
7662
|
break;
|
|
7755
7663
|
}
|
|
7756
7664
|
throw new DryRunFailedError(dryRunResult.failureReason);
|
|
7757
|
-
case
|
|
7758
|
-
validateHops(dryRunResult.hops);
|
|
7665
|
+
case 3:
|
|
7759
7666
|
originFeeEstimate = dryRunResult.origin.fee;
|
|
7760
7667
|
originFee = padFeeBy(originFeeEstimate, FEE_PADDING_PERCENTAGE$1);
|
|
7761
7668
|
reserveFeeEstimate = getReserveFeeFromHops(dryRunResult.hops);
|
|
@@ -7767,9 +7674,9 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7767
7674
|
reserveFee: reserveFee
|
|
7768
7675
|
}
|
|
7769
7676
|
}));
|
|
7770
|
-
_context.n =
|
|
7677
|
+
_context.n = 4;
|
|
7771
7678
|
return api.getXcmWeight(xcm);
|
|
7772
|
-
case
|
|
7679
|
+
case 4:
|
|
7773
7680
|
weight = _context.v;
|
|
7774
7681
|
return _context.a(2, createExecuteCall(chain, xcm, weight));
|
|
7775
7682
|
}
|
|
@@ -8060,7 +7967,7 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
8060
7967
|
}();
|
|
8061
7968
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
8062
7969
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
8063
|
-
var api, chain, exchangeChain, destChain, assetFrom, assetTo, currencyTo, senderAddress, recipientAddress, calculateMinAmountOut, version, internalOptions, dryRunParams, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex,
|
|
7970
|
+
var api, chain, exchangeChain, destChain, assetFrom, assetTo, currencyTo, senderAddress, recipientAddress, calculateMinAmountOut, version, internalOptions, dryRunParams, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex, extractedFees, totalFeesInFromAsset, updatedAssetTo, amountAvailableForSwap, recalculatedMinAmountOut, _yield$createXcmAndCa2, finalCall;
|
|
8064
7971
|
return _regenerator().w(function (_context3) {
|
|
8065
7972
|
while (1) switch (_context3.n) {
|
|
8066
7973
|
case 0:
|
|
@@ -8087,7 +7994,8 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
8087
7994
|
swapConfig: {
|
|
8088
7995
|
currencyTo: currencyTo,
|
|
8089
7996
|
exchangeChain: exchangeChain
|
|
8090
|
-
}
|
|
7997
|
+
},
|
|
7998
|
+
useRootOrigin: true
|
|
8091
7999
|
}; // First dry run with dummy fees to extract actual fees
|
|
8092
8000
|
_context3.n = 2;
|
|
8093
8001
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
@@ -8106,38 +8014,8 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
8106
8014
|
}));
|
|
8107
8015
|
case 3:
|
|
8108
8016
|
firstDryRunResult = _context3.v;
|
|
8109
|
-
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult.hops, exchangeChain, destChain);
|
|
8110
|
-
|
|
8111
|
-
requireExchangeSuccess = !hasOriginReserveHop;
|
|
8112
|
-
extractedFees = extractFeesFromDryRun(chain, firstDryRunResult, exchangeHopIndex, destChain, false); // If we need exchange to succeed but it failed, throw error
|
|
8113
|
-
if (!(requireExchangeSuccess && extractedFees.exchangeFee === 0n)) {
|
|
8114
|
-
_context3.n = 6;
|
|
8115
|
-
break;
|
|
8116
|
-
}
|
|
8117
|
-
if (!destChain) {
|
|
8118
|
-
_context3.n = 5;
|
|
8119
|
-
break;
|
|
8120
|
-
}
|
|
8121
|
-
if (!chain) {
|
|
8122
|
-
_context3.n = 4;
|
|
8123
|
-
break;
|
|
8124
|
-
}
|
|
8125
|
-
exchangeHop = firstDryRunResult.hops[exchangeHopIndex];
|
|
8126
|
-
if (exchangeHop.result.success) {
|
|
8127
|
-
_context3.n = 4;
|
|
8128
|
-
break;
|
|
8129
|
-
}
|
|
8130
|
-
throw new DryRunFailedError("Exchange hop failed when no origin reserve exists: ".concat(exchangeHop.result.failureReason || 'Unknown reason'));
|
|
8131
|
-
case 4:
|
|
8132
|
-
_context3.n = 6;
|
|
8133
|
-
break;
|
|
8134
|
-
case 5:
|
|
8135
|
-
if (!(firstDryRunResult.destination && !firstDryRunResult.destination.success)) {
|
|
8136
|
-
_context3.n = 6;
|
|
8137
|
-
break;
|
|
8138
|
-
}
|
|
8139
|
-
throw new DryRunFailedError("Exchange (destination) failed when no origin reserve exists: ".concat(firstDryRunResult.destination.failureReason || 'Unknown reason'));
|
|
8140
|
-
case 6:
|
|
8017
|
+
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult.hops, exchangeChain, destChain);
|
|
8018
|
+
extractedFees = extractFeesFromDryRun(chain, firstDryRunResult, exchangeHopIndex, destChain, false);
|
|
8141
8019
|
if (extractedFees.exchangeFee === 0n) {
|
|
8142
8020
|
// We set the exchange fee to non-zero value to prevent creating dummy tx
|
|
8143
8021
|
extractedFees.exchangeFee = MIN_FEE;
|
|
@@ -8147,67 +8025,27 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
8147
8025
|
validateAmount(BigInt(assetFrom.amount), totalFeesInFromAsset);
|
|
8148
8026
|
updatedAssetTo = assetTo;
|
|
8149
8027
|
if (!chain) {
|
|
8150
|
-
_context3.n =
|
|
8028
|
+
_context3.n = 5;
|
|
8151
8029
|
break;
|
|
8152
8030
|
}
|
|
8153
8031
|
amountAvailableForSwap = BigInt(assetFrom.amount) - totalFeesInFromAsset;
|
|
8154
|
-
_context3.n =
|
|
8032
|
+
_context3.n = 4;
|
|
8155
8033
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
8156
|
-
case
|
|
8034
|
+
case 4:
|
|
8157
8035
|
recalculatedMinAmountOut = _context3.v;
|
|
8158
8036
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
8159
8037
|
amount: recalculatedMinAmountOut
|
|
8160
8038
|
});
|
|
8161
|
-
case
|
|
8162
|
-
_context3.n =
|
|
8039
|
+
case 5:
|
|
8040
|
+
_context3.n = 6;
|
|
8163
8041
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
8164
8042
|
assetInfoTo: updatedAssetTo,
|
|
8165
8043
|
fees: extractedFees
|
|
8166
8044
|
}), firstDryRunResult.origin.success ? firstDryRunResult.origin.weight : undefined);
|
|
8167
|
-
case
|
|
8045
|
+
case 6:
|
|
8168
8046
|
_yield$createXcmAndCa2 = _context3.v;
|
|
8169
|
-
|
|
8170
|
-
_context3.n = 10;
|
|
8171
|
-
return executeDryRun(_objectSpread2(_objectSpread2({}, dryRunParams), {}, {
|
|
8172
|
-
tx: api.callTxMethod(secondCall)
|
|
8173
|
-
}));
|
|
8174
|
-
case 10:
|
|
8175
|
-
secondDryRunResult = _context3.v;
|
|
8176
|
-
hasHopsInSecondRun = secondDryRunResult.hops && secondDryRunResult.hops.length > 0;
|
|
8177
|
-
isOnExchangeChain = chain === exchangeChain;
|
|
8178
|
-
if (hasHopsInSecondRun && !isOnExchangeChain) {
|
|
8179
|
-
finalExchangeHopIndex = findExchangeHopIndex(chain, secondDryRunResult.hops, exchangeChain, destChain);
|
|
8180
|
-
finalFees = extractFeesFromDryRun(chain, secondDryRunResult, finalExchangeHopIndex, destChain, true);
|
|
8181
|
-
} else {
|
|
8182
|
-
finalFees = extractFeesFromDryRun(chain, secondDryRunResult, 0, destChain, true);
|
|
8183
|
-
}
|
|
8184
|
-
// Validate that we have enough after accounting for final fees
|
|
8185
|
-
finalTotalFeesInFromAsset = chain ? finalFees.originReserveFee + finalFees.exchangeFee : 0n;
|
|
8186
|
-
validateAmount(BigInt(assetFrom.amount), finalTotalFeesInFromAsset);
|
|
8187
|
-
// If the final fees are different, we might need one more iteration
|
|
8188
|
-
if (!(finalFees.exchangeFee !== extractedFees.exchangeFee || finalFees.originReserveFee !== extractedFees.originReserveFee)) {
|
|
8189
|
-
_context3.n = 13;
|
|
8190
|
-
break;
|
|
8191
|
-
}
|
|
8192
|
-
finalAmountAvailableForSwap = BigInt(assetFrom.amount) - finalTotalFeesInFromAsset;
|
|
8193
|
-
_context3.n = 11;
|
|
8194
|
-
return calculateMinAmountOut(finalAmountAvailableForSwap);
|
|
8195
|
-
case 11:
|
|
8196
|
-
finalMinAmountOut = _context3.v;
|
|
8197
|
-
finalAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
8198
|
-
amount: finalMinAmountOut
|
|
8199
|
-
});
|
|
8200
|
-
_context3.n = 12;
|
|
8201
|
-
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
8202
|
-
assetInfoTo: finalAssetTo,
|
|
8203
|
-
fees: finalFees
|
|
8204
|
-
}), secondDryRunResult.origin.success ? secondDryRunResult.origin.weight : undefined);
|
|
8205
|
-
case 12:
|
|
8206
|
-
_yield$createXcmAndCa3 = _context3.v;
|
|
8207
|
-
finalCall = _yield$createXcmAndCa3.call;
|
|
8047
|
+
finalCall = _yield$createXcmAndCa2.call;
|
|
8208
8048
|
return _context3.a(2, api.callTxMethod(finalCall));
|
|
8209
|
-
case 13:
|
|
8210
|
-
return _context3.a(2, api.callTxMethod(secondCall));
|
|
8211
8049
|
}
|
|
8212
8050
|
}, _callee3);
|
|
8213
8051
|
}));
|
|
@@ -12673,15 +12511,19 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
12673
12511
|
key: "getTransferableAmount",
|
|
12674
12512
|
value: (function () {
|
|
12675
12513
|
var _getTransferableAmount2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
12676
|
-
var _this$_options7, from, to, senderAddress, currency, feeAsset;
|
|
12514
|
+
var _this$_options7, from, to, senderAddress, currency, feeAsset, tx;
|
|
12677
12515
|
return _regenerator().w(function (_context8) {
|
|
12678
12516
|
while (1) switch (_context8.n) {
|
|
12679
12517
|
case 0:
|
|
12680
12518
|
_this$_options7 = this._options, from = _this$_options7.from, to = _this$_options7.to, senderAddress = _this$_options7.senderAddress, currency = _this$_options7.currency, feeAsset = _this$_options7.feeAsset;
|
|
12681
12519
|
assertToIsString(to);
|
|
12520
|
+
_context8.n = 1;
|
|
12521
|
+
return this.build();
|
|
12522
|
+
case 1:
|
|
12523
|
+
tx = _context8.v;
|
|
12682
12524
|
return _context8.a(2, getTransferableAmount({
|
|
12683
12525
|
api: this.api,
|
|
12684
|
-
|
|
12526
|
+
tx: tx,
|
|
12685
12527
|
origin: from,
|
|
12686
12528
|
destination: to,
|
|
12687
12529
|
senderAddress: senderAddress,
|