@paraspell/sdk-core 11.1.1 → 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 +1046 -764
- package/dist/index.d.ts +480 -452
- package/dist/index.mjs +1047 -768
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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
|
-
import { isAddress, parseUnits, createPublicClient, http, getContract } from 'viem';
|
|
6
|
-
import { getSupportedPalletsDetails, getDefaultPallet, getSupportedPallets } from '@paraspell/pallets';
|
|
5
|
+
import { isAddress, parseUnits, createPublicClient, http, getContract, pad, toHex, getAddress, concat, keccak256 } from 'viem';
|
|
6
|
+
import { getSupportedPalletsDetails, getDefaultPallet, getNativeAssetsPallet, getOtherAssetsPallets, getSupportedPallets } from '@paraspell/pallets';
|
|
7
7
|
export * from '@paraspell/pallets';
|
|
8
8
|
import { replaceBigInt, isTLocation, Version, hasJunction, getJunctionValue, isRelayChain, Parents, PARACHAINS, deepEqual, isSystemChain, isDotKsmBridge } from '@paraspell/sdk-common';
|
|
9
9
|
export * from '@paraspell/sdk-common';
|
|
@@ -3474,6 +3474,129 @@ 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
|
+
|
|
3557
|
+
var AssetsPallet = /*#__PURE__*/function () {
|
|
3558
|
+
function AssetsPallet() {
|
|
3559
|
+
_classCallCheck(this, AssetsPallet);
|
|
3560
|
+
}
|
|
3561
|
+
return _createClass(AssetsPallet, [{
|
|
3562
|
+
key: "setBalance",
|
|
3563
|
+
value: function setBalance(address, asset, chain) {
|
|
3564
|
+
assertHasId(asset);
|
|
3565
|
+
var assetId = asset.assetId,
|
|
3566
|
+
amount = asset.amount;
|
|
3567
|
+
var id = chain === 'Astar' || chain === 'Shiden' || chain === 'Moonbeam' ? BigInt(assetId) : Number(assetId);
|
|
3568
|
+
var addr = isChainEvm(chain) ? address : {
|
|
3569
|
+
Id: address
|
|
3570
|
+
};
|
|
3571
|
+
return Promise.resolve({
|
|
3572
|
+
assetStatusTx: {
|
|
3573
|
+
module: 'Assets',
|
|
3574
|
+
method: 'force_asset_status',
|
|
3575
|
+
parameters: {
|
|
3576
|
+
id: id,
|
|
3577
|
+
owner: addr,
|
|
3578
|
+
issuer: addr,
|
|
3579
|
+
admin: addr,
|
|
3580
|
+
freezer: addr,
|
|
3581
|
+
min_balance: 0n,
|
|
3582
|
+
is_sufficient: true,
|
|
3583
|
+
is_frozen: false
|
|
3584
|
+
}
|
|
3585
|
+
},
|
|
3586
|
+
balanceTx: {
|
|
3587
|
+
module: 'Assets',
|
|
3588
|
+
method: 'mint',
|
|
3589
|
+
parameters: {
|
|
3590
|
+
id: id,
|
|
3591
|
+
beneficiary: addr,
|
|
3592
|
+
amount: amount
|
|
3593
|
+
}
|
|
3594
|
+
}
|
|
3595
|
+
});
|
|
3596
|
+
}
|
|
3597
|
+
}]);
|
|
3598
|
+
}();
|
|
3599
|
+
|
|
3477
3600
|
// Inspired by Moonbeam XCM-SDK
|
|
3478
3601
|
// https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
|
|
3479
3602
|
var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
|
|
@@ -3967,322 +4090,75 @@ var getOriginFeeDetails = /*#__PURE__*/function () {
|
|
|
3967
4090
|
};
|
|
3968
4091
|
}();
|
|
3969
4092
|
|
|
3970
|
-
var
|
|
3971
|
-
var
|
|
3972
|
-
|
|
3973
|
-
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
3974
|
-
throwUnsupportedCurrency(feeAsset, origin);
|
|
3975
|
-
}
|
|
3976
|
-
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
3977
|
-
};
|
|
3978
|
-
|
|
3979
|
-
var isAssetHub = function isAssetHub(chain) {
|
|
3980
|
-
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
3981
|
-
};
|
|
3982
|
-
var isBridgeHub = function isBridgeHub(chain) {
|
|
3983
|
-
return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
|
|
3984
|
-
};
|
|
3985
|
-
var isPeople = function isPeople(chain) {
|
|
3986
|
-
return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
|
|
3987
|
-
};
|
|
3988
|
-
var isSystemPara = function isSystemPara(chain) {
|
|
3989
|
-
return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
|
|
3990
|
-
};
|
|
3991
|
-
var mul = function mul(v, num) {
|
|
3992
|
-
var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
|
|
3993
|
-
return v * num / den;
|
|
3994
|
-
};
|
|
3995
|
-
var padFee = function padFee(raw, origin, dest, side) {
|
|
3996
|
-
var relayOrigin = isRelayChain(origin);
|
|
3997
|
-
var relayDest = isRelayChain(dest);
|
|
3998
|
-
var sysParaOrigin = isSystemPara(origin);
|
|
3999
|
-
var sysParaDest = isSystemPara(dest);
|
|
4000
|
-
var relayToPara = relayOrigin && !relayDest;
|
|
4001
|
-
var sysParaToPara = sysParaOrigin && !sysParaDest;
|
|
4002
|
-
var paraToPara = !relayOrigin && !sysParaOrigin;
|
|
4003
|
-
if (sysParaToPara) return raw * 40n;
|
|
4004
|
-
if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
|
|
4005
|
-
if (paraToPara && side == 'origin' && origin === 'Mythos' && dest !== 'Ethereum') {
|
|
4006
|
-
return 150000000000000000n;
|
|
4007
|
-
}
|
|
4008
|
-
if (paraToPara) return mul(raw, 130n, 100n);
|
|
4009
|
-
// apply default 30% padding
|
|
4010
|
-
return mul(raw, 130n, 100n);
|
|
4011
|
-
};
|
|
4012
|
-
var padFeeBy = function padFeeBy(amount, percent) {
|
|
4013
|
-
return mul(amount, BigInt(100 + percent), 100n);
|
|
4014
|
-
};
|
|
4015
|
-
|
|
4016
|
-
var determineAddress = function determineAddress(chain, address, senderAddress) {
|
|
4017
|
-
if (isChainEvm(chain)) {
|
|
4018
|
-
return isAddress(address) ? address : senderAddress;
|
|
4019
|
-
}
|
|
4020
|
-
return isAddress(address) ? senderAddress : address;
|
|
4021
|
-
};
|
|
4022
|
-
var getReverseTxFee = /*#__PURE__*/function () {
|
|
4023
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
|
|
4024
|
-
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;
|
|
4025
4096
|
return _regenerator().w(function (_context) {
|
|
4026
|
-
while (1) switch (_context.n) {
|
|
4097
|
+
while (1) switch (_context.p = _context.n) {
|
|
4027
4098
|
case 0:
|
|
4028
|
-
api =
|
|
4029
|
-
|
|
4030
|
-
fromAddress = determineAddress(destination, address, senderAddress);
|
|
4099
|
+
api = options.api, senderAddress = options.senderAddress, origin = options.origin;
|
|
4100
|
+
validateAddress(senderAddress, origin, false);
|
|
4031
4101
|
_context.n = 1;
|
|
4032
|
-
return
|
|
4033
|
-
amount: currency.amount
|
|
4034
|
-
})).build();
|
|
4102
|
+
return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4035
4103
|
case 1:
|
|
4036
|
-
|
|
4104
|
+
_context.p = 1;
|
|
4037
4105
|
_context.n = 2;
|
|
4038
|
-
return
|
|
4106
|
+
return dryRunInternal(options);
|
|
4039
4107
|
case 2:
|
|
4040
|
-
|
|
4041
|
-
|
|
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);
|
|
4042
4117
|
}
|
|
4043
|
-
}, _callee);
|
|
4118
|
+
}, _callee, null, [[1,, 3, 5]]);
|
|
4044
4119
|
}));
|
|
4045
|
-
return function
|
|
4046
|
-
return
|
|
4120
|
+
return function dryRun(_x) {
|
|
4121
|
+
return _ref.apply(this, arguments);
|
|
4047
4122
|
};
|
|
4048
4123
|
}();
|
|
4049
4124
|
|
|
4050
|
-
var
|
|
4051
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(
|
|
4052
|
-
var
|
|
4125
|
+
var dryRunOrigin = /*#__PURE__*/function () {
|
|
4126
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
4127
|
+
var api, chain, address, result;
|
|
4053
4128
|
return _regenerator().w(function (_context) {
|
|
4054
|
-
while (1) switch (_context.n) {
|
|
4129
|
+
while (1) switch (_context.p = _context.n) {
|
|
4055
4130
|
case 0:
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
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);
|
|
4061
4135
|
case 1:
|
|
4062
|
-
|
|
4136
|
+
_context.p = 1;
|
|
4063
4137
|
_context.n = 2;
|
|
4064
|
-
return
|
|
4065
|
-
api: api,
|
|
4066
|
-
chain: origin,
|
|
4067
|
-
address: senderAddress
|
|
4068
|
-
});
|
|
4138
|
+
return api.getDryRunCall(options);
|
|
4069
4139
|
case 2:
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
isNativeAssetToDest = isSymbolMatch(asset.symbol, getNativeAssetSymbol(destination));
|
|
4073
|
-
if (!(isNativeAssetToOrigin && isNativeAssetToDest)) {
|
|
4140
|
+
result = _context.v;
|
|
4141
|
+
if (!result.success) {
|
|
4074
4142
|
_context.n = 3;
|
|
4075
4143
|
break;
|
|
4076
4144
|
}
|
|
4077
|
-
return _context.a(2,
|
|
4145
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, result), {}, {
|
|
4146
|
+
currency: getNativeAssetSymbol(chain)
|
|
4147
|
+
}));
|
|
4078
4148
|
case 3:
|
|
4079
|
-
|
|
4080
|
-
_context.n = 5;
|
|
4081
|
-
break;
|
|
4082
|
-
}
|
|
4083
|
-
isSufficientNative = balanceNative - edNative - feeNative > 0n;
|
|
4084
|
-
_context.n = 4;
|
|
4085
|
-
return getAssetBalance({
|
|
4086
|
-
api: api,
|
|
4087
|
-
chain: origin,
|
|
4088
|
-
address: senderAddress,
|
|
4089
|
-
currency: currency
|
|
4090
|
-
});
|
|
4149
|
+
return _context.a(2, result);
|
|
4091
4150
|
case 4:
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
return _context.a(2, isSufficientNative && isSufficientAsset);
|
|
4151
|
+
_context.p = 4;
|
|
4152
|
+
_context.n = 5;
|
|
4153
|
+
return api.disconnect();
|
|
4096
4154
|
case 5:
|
|
4097
|
-
return _context.
|
|
4155
|
+
return _context.f(4);
|
|
4098
4156
|
case 6:
|
|
4099
4157
|
return _context.a(2);
|
|
4100
4158
|
}
|
|
4101
|
-
}, _callee);
|
|
4159
|
+
}, _callee, null, [[1,, 4, 6]]);
|
|
4102
4160
|
}));
|
|
4103
|
-
return function
|
|
4104
|
-
return _ref.apply(this, arguments);
|
|
4105
|
-
};
|
|
4106
|
-
}();
|
|
4107
|
-
var isSufficientDestination = /*#__PURE__*/function () {
|
|
4108
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, destination, address, amount, asset, feeNative) {
|
|
4109
|
-
var isNativeAsset, existentialDeposit, nativeBalance;
|
|
4110
|
-
return _regenerator().w(function (_context2) {
|
|
4111
|
-
while (1) switch (_context2.n) {
|
|
4112
|
-
case 0:
|
|
4113
|
-
isNativeAsset = isSymbolMatch(asset.symbol, getNativeAssetSymbol(destination));
|
|
4114
|
-
if (isNativeAsset) {
|
|
4115
|
-
_context2.n = 1;
|
|
4116
|
-
break;
|
|
4117
|
-
}
|
|
4118
|
-
return _context2.a(2, undefined);
|
|
4119
|
-
case 1:
|
|
4120
|
-
existentialDeposit = getExistentialDepositOrThrow(destination);
|
|
4121
|
-
_context2.n = 2;
|
|
4122
|
-
return getBalanceNativeInternal({
|
|
4123
|
-
api: api,
|
|
4124
|
-
chain: destination,
|
|
4125
|
-
address: address
|
|
4126
|
-
});
|
|
4127
|
-
case 2:
|
|
4128
|
-
nativeBalance = _context2.v;
|
|
4129
|
-
return _context2.a(2, nativeBalance + amount - existentialDeposit - feeNative > 0n);
|
|
4130
|
-
}
|
|
4131
|
-
}, _callee2);
|
|
4132
|
-
}));
|
|
4133
|
-
return function isSufficientDestination(_x9, _x0, _x1, _x10, _x11, _x12) {
|
|
4134
|
-
return _ref2.apply(this, arguments);
|
|
4135
|
-
};
|
|
4136
|
-
}();
|
|
4137
|
-
|
|
4138
|
-
var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
4139
|
-
if (isRelayChain(origin)) return DOT_LOCATION;
|
|
4140
|
-
return {
|
|
4141
|
-
parents: isRelayChain(destination) ? Parents.ZERO : Parents.ONE,
|
|
4142
|
-
interior: {
|
|
4143
|
-
X1: [{
|
|
4144
|
-
Parachain: getParaId(origin)
|
|
4145
|
-
}]
|
|
4146
|
-
}
|
|
4147
|
-
};
|
|
4148
|
-
};
|
|
4149
|
-
var getDestXcmFee = /*#__PURE__*/function () {
|
|
4150
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
4151
|
-
var api, origin, hopChain, destination, currency, forwardedXcms, asset, address, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, _fee, sufficient, dryRunResult, _fee2, _sufficient, fee, newForwardedXcms, destParaId;
|
|
4152
|
-
return _regenerator().w(function (_context2) {
|
|
4153
|
-
while (1) switch (_context2.n) {
|
|
4154
|
-
case 0:
|
|
4155
|
-
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;
|
|
4156
|
-
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4157
|
-
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
4158
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
4159
|
-
var originAsset, _t;
|
|
4160
|
-
return _regenerator().w(function (_context) {
|
|
4161
|
-
while (1) switch (_context.p = _context.n) {
|
|
4162
|
-
case 0:
|
|
4163
|
-
if (!(destination === 'Ethereum')) {
|
|
4164
|
-
_context.n = 1;
|
|
4165
|
-
break;
|
|
4166
|
-
}
|
|
4167
|
-
return _context.a(2, 0n);
|
|
4168
|
-
case 1:
|
|
4169
|
-
originAsset = findAssetInfoOrThrow(origin, currency, destination);
|
|
4170
|
-
if (!originAsset.location) {
|
|
4171
|
-
_context.n = 7;
|
|
4172
|
-
break;
|
|
4173
|
-
}
|
|
4174
|
-
_context.p = 2;
|
|
4175
|
-
_context.n = 3;
|
|
4176
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4177
|
-
destination: destination
|
|
4178
|
-
}), {
|
|
4179
|
-
location: originAsset.location
|
|
4180
|
-
});
|
|
4181
|
-
case 3:
|
|
4182
|
-
return _context.a(2, _context.v);
|
|
4183
|
-
case 4:
|
|
4184
|
-
_context.p = 4;
|
|
4185
|
-
_t = _context.v;
|
|
4186
|
-
if (!(_t instanceof InvalidCurrencyError)) {
|
|
4187
|
-
_context.n = 6;
|
|
4188
|
-
break;
|
|
4189
|
-
}
|
|
4190
|
-
_context.n = 5;
|
|
4191
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4192
|
-
destination: destination
|
|
4193
|
-
}), {
|
|
4194
|
-
symbol: originAsset.symbol
|
|
4195
|
-
});
|
|
4196
|
-
case 5:
|
|
4197
|
-
return _context.a(2, _context.v);
|
|
4198
|
-
case 6:
|
|
4199
|
-
throw _t;
|
|
4200
|
-
case 7:
|
|
4201
|
-
_context.n = 8;
|
|
4202
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4203
|
-
destination: destination
|
|
4204
|
-
}), {
|
|
4205
|
-
symbol: originAsset.symbol
|
|
4206
|
-
});
|
|
4207
|
-
case 8:
|
|
4208
|
-
return _context.a(2, _context.v);
|
|
4209
|
-
}
|
|
4210
|
-
}, _callee, null, [[2, 4]]);
|
|
4211
|
-
}));
|
|
4212
|
-
return function calcPaymentInfoFee() {
|
|
4213
|
-
return _ref2.apply(this, arguments);
|
|
4214
|
-
};
|
|
4215
|
-
}();
|
|
4216
|
-
if (!(!hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
|
|
4217
|
-
_context2.n = 3;
|
|
4218
|
-
break;
|
|
4219
|
-
}
|
|
4220
|
-
_context2.n = 1;
|
|
4221
|
-
return calcPaymentInfoFee();
|
|
4222
|
-
case 1:
|
|
4223
|
-
_fee = _context2.v;
|
|
4224
|
-
_context2.n = 2;
|
|
4225
|
-
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee);
|
|
4226
|
-
case 2:
|
|
4227
|
-
sufficient = _context2.v;
|
|
4228
|
-
return _context2.a(2, {
|
|
4229
|
-
fee: _fee,
|
|
4230
|
-
feeType: 'paymentInfo',
|
|
4231
|
-
sufficient: sufficient
|
|
4232
|
-
});
|
|
4233
|
-
case 3:
|
|
4234
|
-
_context2.n = 4;
|
|
4235
|
-
return api.getDryRunXcm({
|
|
4236
|
-
originLocation: addXcmVersionHeader(createOriginLocation(hopChain, destination), Version.V4),
|
|
4237
|
-
xcm: forwardedXcms[1][0],
|
|
4238
|
-
chain: destination,
|
|
4239
|
-
origin: origin,
|
|
4240
|
-
asset: asset,
|
|
4241
|
-
originFee: originFee,
|
|
4242
|
-
feeAsset: resolvedFeeAsset,
|
|
4243
|
-
amount: BigInt(currency.amount) < 2n ? 2n : BigInt(currency.amount)
|
|
4244
|
-
});
|
|
4245
|
-
case 4:
|
|
4246
|
-
dryRunResult = _context2.v;
|
|
4247
|
-
if (dryRunResult.success) {
|
|
4248
|
-
_context2.n = 8;
|
|
4249
|
-
break;
|
|
4250
|
-
}
|
|
4251
|
-
if (!disableFallback) {
|
|
4252
|
-
_context2.n = 5;
|
|
4253
|
-
break;
|
|
4254
|
-
}
|
|
4255
|
-
return _context2.a(2, {
|
|
4256
|
-
dryRunError: dryRunResult.failureReason
|
|
4257
|
-
});
|
|
4258
|
-
case 5:
|
|
4259
|
-
_context2.n = 6;
|
|
4260
|
-
return calcPaymentInfoFee();
|
|
4261
|
-
case 6:
|
|
4262
|
-
_fee2 = _context2.v;
|
|
4263
|
-
_context2.n = 7;
|
|
4264
|
-
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee2);
|
|
4265
|
-
case 7:
|
|
4266
|
-
_sufficient = _context2.v;
|
|
4267
|
-
return _context2.a(2, {
|
|
4268
|
-
fee: _fee2,
|
|
4269
|
-
feeType: 'paymentInfo',
|
|
4270
|
-
dryRunError: dryRunResult.failureReason,
|
|
4271
|
-
sufficient: _sufficient
|
|
4272
|
-
});
|
|
4273
|
-
case 8:
|
|
4274
|
-
fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
4275
|
-
return _context2.a(2, {
|
|
4276
|
-
fee: fee,
|
|
4277
|
-
feeType: 'dryRun',
|
|
4278
|
-
sufficient: true,
|
|
4279
|
-
forwardedXcms: newForwardedXcms,
|
|
4280
|
-
destParaId: destParaId
|
|
4281
|
-
});
|
|
4282
|
-
}
|
|
4283
|
-
}, _callee2);
|
|
4284
|
-
}));
|
|
4285
|
-
return function getDestXcmFee(_x) {
|
|
4161
|
+
return function dryRunOrigin(_x) {
|
|
4286
4162
|
return _ref.apply(this, arguments);
|
|
4287
4163
|
};
|
|
4288
4164
|
}();
|
|
@@ -5017,287 +4893,332 @@ var addEthereumBridgeFees = /*#__PURE__*/function () {
|
|
|
5017
4893
|
};
|
|
5018
4894
|
}();
|
|
5019
4895
|
|
|
5020
|
-
var
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
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
|
+
});
|
|
4921
|
+
}
|
|
4922
|
+
}]);
|
|
4923
|
+
}();
|
|
4924
|
+
|
|
4925
|
+
var BalancesPallet = /*#__PURE__*/function () {
|
|
4926
|
+
function BalancesPallet() {
|
|
4927
|
+
_classCallCheck(this, BalancesPallet);
|
|
4928
|
+
}
|
|
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
|
+
});
|
|
5030
4946
|
}
|
|
4947
|
+
}]);
|
|
4948
|
+
}();
|
|
4949
|
+
|
|
4950
|
+
var CurrenciesPallet = /*#__PURE__*/function () {
|
|
4951
|
+
function CurrenciesPallet() {
|
|
4952
|
+
_classCallCheck(this, CurrenciesPallet);
|
|
5031
4953
|
}
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
var
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
4954
|
+
return _createClass(CurrenciesPallet, [{
|
|
4955
|
+
key: "setBalance",
|
|
4956
|
+
value: function setBalance(address, assetInfo) {
|
|
4957
|
+
assertHasId(assetInfo);
|
|
4958
|
+
var assetId = assetInfo.assetId,
|
|
4959
|
+
amount = assetInfo.amount;
|
|
4960
|
+
return Promise.resolve({
|
|
4961
|
+
balanceTx: {
|
|
4962
|
+
module: 'Currencies',
|
|
4963
|
+
method: 'update_balance',
|
|
4964
|
+
parameters: {
|
|
4965
|
+
who: address,
|
|
4966
|
+
currency_id: Number(assetId),
|
|
4967
|
+
amount: amount
|
|
4968
|
+
}
|
|
4969
|
+
}
|
|
4970
|
+
});
|
|
5043
4971
|
}
|
|
5044
|
-
}
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
4972
|
+
}]);
|
|
4973
|
+
}();
|
|
4974
|
+
|
|
4975
|
+
var ForeignAssetsPallet = /*#__PURE__*/function () {
|
|
4976
|
+
function ForeignAssetsPallet() {
|
|
4977
|
+
_classCallCheck(this, ForeignAssetsPallet);
|
|
5048
4978
|
}
|
|
5049
|
-
return {
|
|
4979
|
+
return _createClass(ForeignAssetsPallet, [{
|
|
4980
|
+
key: "setBalance",
|
|
4981
|
+
value: function setBalance(address, asset) {
|
|
4982
|
+
assertHasLocation(asset);
|
|
4983
|
+
var location = asset.location,
|
|
4984
|
+
amount = asset.amount;
|
|
4985
|
+
return Promise.resolve({
|
|
4986
|
+
assetStatusTx: {
|
|
4987
|
+
module: 'ForeignAssets',
|
|
4988
|
+
method: 'force_asset_status',
|
|
4989
|
+
parameters: {
|
|
4990
|
+
id: location,
|
|
4991
|
+
owner: {
|
|
4992
|
+
Id: address
|
|
4993
|
+
},
|
|
4994
|
+
issuer: {
|
|
4995
|
+
Id: address
|
|
4996
|
+
},
|
|
4997
|
+
admin: {
|
|
4998
|
+
Id: address
|
|
4999
|
+
},
|
|
5000
|
+
freezer: {
|
|
5001
|
+
Id: address
|
|
5002
|
+
},
|
|
5003
|
+
min_balance: 0n,
|
|
5004
|
+
is_sufficient: true,
|
|
5005
|
+
is_frozen: false
|
|
5006
|
+
}
|
|
5007
|
+
},
|
|
5008
|
+
balanceTx: {
|
|
5009
|
+
module: 'ForeignAssets',
|
|
5010
|
+
method: 'mint',
|
|
5011
|
+
parameters: {
|
|
5012
|
+
id: location,
|
|
5013
|
+
beneficiary: {
|
|
5014
|
+
Id: address
|
|
5015
|
+
},
|
|
5016
|
+
amount: amount
|
|
5017
|
+
}
|
|
5018
|
+
}
|
|
5019
|
+
});
|
|
5020
|
+
}
|
|
5021
|
+
}]);
|
|
5022
|
+
}();
|
|
5023
|
+
|
|
5024
|
+
var SIZE = 32;
|
|
5025
|
+
var BALANCE_SLOT = 0;
|
|
5026
|
+
var calculateMappingSlot = function calculateMappingSlot(key) {
|
|
5027
|
+
var normalizedKey = getAddress(key);
|
|
5028
|
+
var keyPadded = pad(normalizedKey, {
|
|
5029
|
+
size: SIZE
|
|
5030
|
+
});
|
|
5031
|
+
var slotHex = pad(toHex(BALANCE_SLOT), {
|
|
5032
|
+
size: SIZE
|
|
5033
|
+
});
|
|
5034
|
+
var encoded = concat([keyPadded, slotHex]);
|
|
5035
|
+
return keccak256(encoded);
|
|
5050
5036
|
};
|
|
5051
|
-
var
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
});
|
|
5081
|
-
case 2:
|
|
5082
|
-
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
5083
|
-
processHop = /*#__PURE__*/function () {
|
|
5084
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
5085
|
-
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, isDestination, hopDryRun, hopCurrency;
|
|
5086
|
-
return _regenerator().w(function (_context) {
|
|
5087
|
-
while (1) switch (_context.n) {
|
|
5088
|
-
case 0:
|
|
5089
|
-
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange, isDestination = params.isDestination;
|
|
5090
|
-
if (hasDryRunSupport(currentChain)) {
|
|
5091
|
-
_context.n = 1;
|
|
5092
|
-
break;
|
|
5093
|
-
}
|
|
5094
|
-
return _context.a(2, {
|
|
5095
|
-
success: false,
|
|
5096
|
-
failureReason: "DryRunApi is not available on chain ".concat(currentChain)
|
|
5097
|
-
});
|
|
5098
|
-
case 1:
|
|
5099
|
-
_context.n = 2;
|
|
5100
|
-
return hopApi.getDryRunXcm({
|
|
5101
|
-
originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain), Version.V4),
|
|
5102
|
-
xcm: forwardedXcms[1][0],
|
|
5103
|
-
chain: currentChain,
|
|
5104
|
-
origin: currentOrigin,
|
|
5105
|
-
asset: currentAsset,
|
|
5106
|
-
feeAsset: resolvedFeeAsset,
|
|
5107
|
-
originFee: originDryRun.fee,
|
|
5108
|
-
amount: amount
|
|
5109
|
-
});
|
|
5110
|
-
case 2:
|
|
5111
|
-
hopDryRun = _context.v;
|
|
5112
|
-
if (!hopDryRun.success) {
|
|
5113
|
-
_context.n = 3;
|
|
5114
|
-
break;
|
|
5115
|
-
}
|
|
5116
|
-
if (destination === 'Ethereum' && (currentChain.includes('AssetHub') || currentChain.includes('BridgeHub'))) {
|
|
5117
|
-
hopCurrency = getNativeAssetSymbol(currentChain);
|
|
5118
|
-
} else if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
|
|
5119
|
-
hopCurrency = findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo).symbol;
|
|
5120
|
-
} else if (isDestination) {
|
|
5121
|
-
hopCurrency = findAssetOnDestOrThrow(origin, currentChain, currency).symbol;
|
|
5122
|
-
} else {
|
|
5123
|
-
hopCurrency = asset.symbol;
|
|
5124
|
-
}
|
|
5125
|
-
return _context.a(2, _objectSpread2(_objectSpread2({}, hopDryRun), {}, {
|
|
5126
|
-
currency: hopCurrency
|
|
5127
|
-
}));
|
|
5128
|
-
case 3:
|
|
5129
|
-
return _context.a(2, hopDryRun);
|
|
5037
|
+
var SystemPallet = /*#__PURE__*/function () {
|
|
5038
|
+
function SystemPallet() {
|
|
5039
|
+
_classCallCheck(this, SystemPallet);
|
|
5040
|
+
}
|
|
5041
|
+
return _createClass(SystemPallet, [{
|
|
5042
|
+
key: "setBalance",
|
|
5043
|
+
value: function () {
|
|
5044
|
+
var _setBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(address, assetInfo, _chain, api) {
|
|
5045
|
+
var contractAddr, slot, amountEncoded, storageKey;
|
|
5046
|
+
return _regenerator().w(function (_context) {
|
|
5047
|
+
while (1) switch (_context.n) {
|
|
5048
|
+
case 0:
|
|
5049
|
+
assertHasId(assetInfo);
|
|
5050
|
+
contractAddr = formatAssetIdToERC20(assetInfo.assetId);
|
|
5051
|
+
slot = calculateMappingSlot(address);
|
|
5052
|
+
amountEncoded = pad(toHex(assetInfo.amount), {
|
|
5053
|
+
size: SIZE
|
|
5054
|
+
});
|
|
5055
|
+
_context.n = 1;
|
|
5056
|
+
return api.getEvmStorage(contractAddr, slot);
|
|
5057
|
+
case 1:
|
|
5058
|
+
storageKey = _context.v;
|
|
5059
|
+
return _context.a(2, {
|
|
5060
|
+
balanceTx: {
|
|
5061
|
+
module: 'System',
|
|
5062
|
+
method: 'set_storage',
|
|
5063
|
+
parameters: {
|
|
5064
|
+
items: [[storageKey, amountEncoded]]
|
|
5065
|
+
}
|
|
5130
5066
|
}
|
|
5131
|
-
}, _callee);
|
|
5132
|
-
}));
|
|
5133
|
-
return function processHop(_x2) {
|
|
5134
|
-
return _ref2.apply(this, arguments);
|
|
5135
|
-
};
|
|
5136
|
-
}();
|
|
5137
|
-
_context2.n = 3;
|
|
5138
|
-
return traverseXcmHops({
|
|
5139
|
-
api: api,
|
|
5140
|
-
origin: origin,
|
|
5141
|
-
destination: destination,
|
|
5142
|
-
currency: currency,
|
|
5143
|
-
initialForwardedXcms: initialForwardedXcms,
|
|
5144
|
-
initialDestParaId: initialDestParaId,
|
|
5145
|
-
swapConfig: swapConfig,
|
|
5146
|
-
processHop: processHop,
|
|
5147
|
-
shouldContinue: function shouldContinue(hopResult) {
|
|
5148
|
-
return hopResult.success;
|
|
5149
|
-
},
|
|
5150
|
-
extractNextHopData: function extractNextHopData(hopResult) {
|
|
5151
|
-
return {
|
|
5152
|
-
forwardedXcms: hopResult.success ? hopResult.forwardedXcms : undefined,
|
|
5153
|
-
destParaId: hopResult.success ? hopResult.destParaId : undefined
|
|
5154
|
-
};
|
|
5155
|
-
}
|
|
5156
|
-
});
|
|
5157
|
-
case 3:
|
|
5158
|
-
traversalResult = _context2.v;
|
|
5159
|
-
// Process Ethereum bridge fees
|
|
5160
|
-
assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
|
|
5161
|
-
bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
|
|
5162
|
-
if (!((_traversalResult$brid = traversalResult.bridgeHub) !== null && _traversalResult$brid !== void 0 && _traversalResult$brid.success)) {
|
|
5163
|
-
_context2.n = 5;
|
|
5164
|
-
break;
|
|
5165
|
-
}
|
|
5166
|
-
_context2.n = 4;
|
|
5167
|
-
return addEthereumBridgeFees(api, traversalResult.bridgeHub, destination, assetHubChain);
|
|
5168
|
-
case 4:
|
|
5169
|
-
_t = _context2.v;
|
|
5170
|
-
_context2.n = 6;
|
|
5171
|
-
break;
|
|
5172
|
-
case 5:
|
|
5173
|
-
_t = traversalResult.bridgeHub;
|
|
5174
|
-
case 6:
|
|
5175
|
-
processedBridgeHub = _t;
|
|
5176
|
-
// Update bridge hub in hops if needed
|
|
5177
|
-
if (processedBridgeHub && processedBridgeHub.success && traversalResult.bridgeHub && traversalResult.bridgeHub.success && processedBridgeHub.fee !== traversalResult.bridgeHub.fee) {
|
|
5178
|
-
bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
|
|
5179
|
-
return hop.chain === bridgeHubChain;
|
|
5180
|
-
});
|
|
5181
|
-
if (bridgeHubHopIndex !== -1 && traversalResult.hops[bridgeHubHopIndex].result.success) {
|
|
5182
|
-
traversalResult.hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, traversalResult.hops[bridgeHubHopIndex].result), {}, {
|
|
5183
|
-
fee: processedBridgeHub.fee
|
|
5184
5067
|
});
|
|
5185
|
-
}
|
|
5186
5068
|
}
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(assetHubChain)
|
|
5192
|
-
}) : traversalResult.assetHub;
|
|
5193
|
-
bridgeHubWithCurrency = processedBridgeHub !== null && processedBridgeHub !== void 0 && processedBridgeHub.success ? _objectSpread2(_objectSpread2({}, processedBridgeHub), {}, {
|
|
5194
|
-
currency: getNativeAssetSymbol(bridgeHubChain)
|
|
5195
|
-
}) : processedBridgeHub;
|
|
5196
|
-
destinationWithCurrency = (_traversalResult$dest = traversalResult.destination) !== null && _traversalResult$dest !== void 0 && _traversalResult$dest.success ? _objectSpread2(_objectSpread2({}, traversalResult.destination), {}, {
|
|
5197
|
-
currency: asset === null || asset === void 0 ? void 0 : asset.symbol
|
|
5198
|
-
}) : traversalResult.destination;
|
|
5199
|
-
_getFailureInfo = getFailureInfo$1({
|
|
5200
|
-
destination: destinationWithCurrency,
|
|
5201
|
-
assetHub: assetHubWithCurrency,
|
|
5202
|
-
bridgeHub: bridgeHubWithCurrency
|
|
5203
|
-
}, traversalResult.hops), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
|
|
5204
|
-
return _context2.a(2, {
|
|
5205
|
-
failureReason: failureReason,
|
|
5206
|
-
failureChain: failureChain,
|
|
5207
|
-
origin: originWithCurrency,
|
|
5208
|
-
assetHub: assetHubWithCurrency,
|
|
5209
|
-
bridgeHub: bridgeHubWithCurrency,
|
|
5210
|
-
destination: destinationWithCurrency,
|
|
5211
|
-
hops: traversalResult.hops
|
|
5212
|
-
});
|
|
5069
|
+
}, _callee);
|
|
5070
|
+
}));
|
|
5071
|
+
function setBalance(_x, _x2, _x3, _x4) {
|
|
5072
|
+
return _setBalance.apply(this, arguments);
|
|
5213
5073
|
}
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
return _ref.apply(this, arguments);
|
|
5218
|
-
};
|
|
5074
|
+
return setBalance;
|
|
5075
|
+
}()
|
|
5076
|
+
}]);
|
|
5219
5077
|
}();
|
|
5220
5078
|
|
|
5221
|
-
var
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
}
|
|
5246
|
-
}
|
|
5247
|
-
})
|
|
5248
|
-
return function dryRun(_x) {
|
|
5249
|
-
return _ref.apply(this, arguments);
|
|
5250
|
-
};
|
|
5079
|
+
var TokensPallet = /*#__PURE__*/function () {
|
|
5080
|
+
function TokensPallet() {
|
|
5081
|
+
_classCallCheck(this, TokensPallet);
|
|
5082
|
+
}
|
|
5083
|
+
return _createClass(TokensPallet, [{
|
|
5084
|
+
key: "setBalance",
|
|
5085
|
+
value: function setBalance(address, asset, chain) {
|
|
5086
|
+
var isBifrost = chain.startsWith('Bifrost');
|
|
5087
|
+
if (!isBifrost) assertHasId(asset);
|
|
5088
|
+
var id = isBifrost ? getChain('BifrostPolkadot').getCurrencySelection(asset) : (assertHasId(asset), asset.assetId);
|
|
5089
|
+
var amount = asset.amount;
|
|
5090
|
+
return Promise.resolve({
|
|
5091
|
+
balanceTx: {
|
|
5092
|
+
module: 'Tokens',
|
|
5093
|
+
method: 'set_balance',
|
|
5094
|
+
parameters: {
|
|
5095
|
+
who: {
|
|
5096
|
+
Id: address
|
|
5097
|
+
},
|
|
5098
|
+
currency_id: id,
|
|
5099
|
+
new_free: amount,
|
|
5100
|
+
new_reserved: 0n
|
|
5101
|
+
}
|
|
5102
|
+
}
|
|
5103
|
+
});
|
|
5104
|
+
}
|
|
5105
|
+
}]);
|
|
5251
5106
|
}();
|
|
5252
5107
|
|
|
5253
|
-
var
|
|
5254
|
-
|
|
5255
|
-
|
|
5108
|
+
var palletRegistry = {
|
|
5109
|
+
Balances: BalancesPallet,
|
|
5110
|
+
Tokens: TokensPallet,
|
|
5111
|
+
Currencies: CurrenciesPallet,
|
|
5112
|
+
Assets: AssetsPallet,
|
|
5113
|
+
ForeignAssets: ForeignAssetsPallet,
|
|
5114
|
+
AssetManager: AssetManagerPallet,
|
|
5115
|
+
System: SystemPallet
|
|
5116
|
+
};
|
|
5117
|
+
var getPalletInstance = function getPalletInstance(type) {
|
|
5118
|
+
var HandlerClass = palletRegistry[type];
|
|
5119
|
+
return new HandlerClass();
|
|
5120
|
+
};
|
|
5121
|
+
|
|
5122
|
+
var MINT_AMOUNT = 1000n; // Mint 1000 units of asset
|
|
5123
|
+
var pickOtherPallet = function pickOtherPallet(asset, pallets) {
|
|
5124
|
+
if (isForeignAsset(asset) && asset.assetId === undefined) {
|
|
5125
|
+
var _pallets$find;
|
|
5126
|
+
// No assetId means it's probably a ForeignAssets pallet asset
|
|
5127
|
+
return (_pallets$find = pallets.find(function (pallet) {
|
|
5128
|
+
return pallet.startsWith('Foreign');
|
|
5129
|
+
})) !== null && _pallets$find !== void 0 ? _pallets$find : pallets[0];
|
|
5130
|
+
}
|
|
5131
|
+
return pallets[0];
|
|
5132
|
+
};
|
|
5133
|
+
var createMintTxs = function createMintTxs(chain, asset, address, api) {
|
|
5134
|
+
var nativePallet = getNativeAssetsPallet(chain);
|
|
5135
|
+
var otherPallets = getOtherAssetsPallets(chain);
|
|
5136
|
+
var isMainNativeAsset = isSymbolMatch(asset.symbol, getNativeAssetSymbol(chain));
|
|
5137
|
+
var pallet = isForeignAsset(asset) || !isMainNativeAsset ? pickOtherPallet(asset, otherPallets) : nativePallet;
|
|
5138
|
+
var palletInstance = getPalletInstance(pallet);
|
|
5139
|
+
return palletInstance.setBalance(address, asset, chain, api);
|
|
5140
|
+
};
|
|
5141
|
+
var createRequiredMintTxs = function createRequiredMintTxs(chain, currency, amountHuman, address, api) {
|
|
5142
|
+
var asset = findAssetInfoOrThrow(chain, currency, null);
|
|
5143
|
+
var amount = parseUnits(amountHuman.toString(), asset.decimals);
|
|
5144
|
+
return createMintTxs(chain, _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5145
|
+
amount: amount
|
|
5146
|
+
}), address, api);
|
|
5147
|
+
};
|
|
5148
|
+
var createOptionalMintTxs = function createOptionalMintTxs(chain, currency, amountHuman, address, api) {
|
|
5149
|
+
var asset = findAssetInfo(chain, currency, null);
|
|
5150
|
+
if (!asset) return null;
|
|
5151
|
+
var amount = parseUnits(amountHuman.toString(), asset.decimals);
|
|
5152
|
+
return createMintTxs(chain, _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5153
|
+
amount: amount
|
|
5154
|
+
}), address, api);
|
|
5155
|
+
};
|
|
5156
|
+
var resultToExtrinsics = function resultToExtrinsics(api, address, _ref) {
|
|
5157
|
+
var assetStatusTx = _ref.assetStatusTx,
|
|
5158
|
+
balanceTx = _ref.balanceTx;
|
|
5159
|
+
return [].concat(_toConsumableArray(assetStatusTx ? [api.callTxMethod(assetStatusTx)] : []), _toConsumableArray(assetStatusTx ? [api.callDispatchAsMethod(api.callTxMethod(balanceTx), address)] : [api.callTxMethod(balanceTx)]));
|
|
5160
|
+
};
|
|
5161
|
+
var wrapTxBypass = /*#__PURE__*/function () {
|
|
5162
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, chain, asset, feeAsset, address, tx) {
|
|
5163
|
+
var mintNativeAssetRes, mintRelayAssetRes, mintFeeAssetRes, amount, mintAmount, mintAssetRes;
|
|
5256
5164
|
return _regenerator().w(function (_context) {
|
|
5257
|
-
while (1) switch (_context.
|
|
5165
|
+
while (1) switch (_context.n) {
|
|
5258
5166
|
case 0:
|
|
5259
|
-
api = options.api, chain = options.chain, address = options.address;
|
|
5260
|
-
validateAddress(address, chain, false);
|
|
5261
5167
|
_context.n = 1;
|
|
5262
|
-
return
|
|
5168
|
+
return createRequiredMintTxs(chain, {
|
|
5169
|
+
symbol: Native(getNativeAssetSymbol(chain))
|
|
5170
|
+
}, MINT_AMOUNT, address, api);
|
|
5263
5171
|
case 1:
|
|
5264
|
-
|
|
5172
|
+
mintNativeAssetRes = _context.v;
|
|
5265
5173
|
_context.n = 2;
|
|
5266
|
-
return
|
|
5174
|
+
return createOptionalMintTxs(chain, {
|
|
5175
|
+
location: {
|
|
5176
|
+
parents: Parents.ONE,
|
|
5177
|
+
interior: {
|
|
5178
|
+
Here: null
|
|
5179
|
+
}
|
|
5180
|
+
}
|
|
5181
|
+
}, MINT_AMOUNT, address, api);
|
|
5267
5182
|
case 2:
|
|
5268
|
-
|
|
5269
|
-
if (!
|
|
5270
|
-
_context.n =
|
|
5183
|
+
mintRelayAssetRes = _context.v;
|
|
5184
|
+
if (!feeAsset) {
|
|
5185
|
+
_context.n = 4;
|
|
5271
5186
|
break;
|
|
5272
5187
|
}
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
})
|
|
5188
|
+
amount = parseUnits(MINT_AMOUNT.toString(), feeAsset.decimals);
|
|
5189
|
+
_context.n = 3;
|
|
5190
|
+
return createMintTxs(chain, _objectSpread2(_objectSpread2({}, feeAsset), {}, {
|
|
5191
|
+
amount: amount
|
|
5192
|
+
}), address, api);
|
|
5276
5193
|
case 3:
|
|
5277
|
-
|
|
5194
|
+
mintFeeAssetRes = _context.v;
|
|
5278
5195
|
case 4:
|
|
5279
|
-
|
|
5196
|
+
// mint asset that is being sent
|
|
5197
|
+
mintAmount = parseUnits(MINT_AMOUNT.toString(), asset.decimals);
|
|
5280
5198
|
_context.n = 5;
|
|
5281
|
-
return
|
|
5199
|
+
return createMintTxs(chain, _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5200
|
+
amount: asset.amount + mintAmount
|
|
5201
|
+
}), address, api);
|
|
5282
5202
|
case 5:
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5203
|
+
mintAssetRes = _context.v;
|
|
5204
|
+
return _context.a(2, api.callBatchMethod([].concat(_toConsumableArray([mintNativeAssetRes, mintRelayAssetRes, mintFeeAssetRes, mintAssetRes].flatMap(function (tx) {
|
|
5205
|
+
return tx ? resultToExtrinsics(api, address, tx) : [];
|
|
5206
|
+
})), [api.callDispatchAsMethod(tx, address)]), BatchMode.BATCH_ALL));
|
|
5286
5207
|
}
|
|
5287
|
-
}, _callee
|
|
5208
|
+
}, _callee);
|
|
5288
5209
|
}));
|
|
5289
|
-
return function
|
|
5290
|
-
return
|
|
5210
|
+
return function wrapTxBypass(_x, _x2, _x3, _x4, _x5, _x6) {
|
|
5211
|
+
return _ref2.apply(this, arguments);
|
|
5291
5212
|
};
|
|
5292
5213
|
}();
|
|
5293
5214
|
|
|
5294
|
-
var
|
|
5215
|
+
var getOriginXcmFeeInternal = /*#__PURE__*/function () {
|
|
5295
5216
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
5296
|
-
var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, asset, amount, resolvedFeeAsset, nativeAssetSymbol, rawFee, paddedFee, sufficient, dryRunResult, _rawFee, _paddedFee,
|
|
5217
|
+
var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, _ref$useRootOrigin, useRootOrigin, asset, amount, resolvedFeeAsset, nativeAssetSymbol, rawFee, paddedFee, sufficient, dryRunResult, _rawFee, _paddedFee, fee, forwardedXcms, destParaId, weight, currencySymbol;
|
|
5297
5218
|
return _regenerator().w(function (_context) {
|
|
5298
5219
|
while (1) switch (_context.n) {
|
|
5299
5220
|
case 0:
|
|
5300
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback, feeAsset = _ref.feeAsset, currency = _ref.currency;
|
|
5221
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback, feeAsset = _ref.feeAsset, currency = _ref.currency, _ref$useRootOrigin = _ref.useRootOrigin, useRootOrigin = _ref$useRootOrigin === void 0 ? false : _ref$useRootOrigin;
|
|
5301
5222
|
asset = findAssetInfoOrThrow(origin, currency, destination);
|
|
5302
5223
|
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
5303
5224
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
@@ -5332,12 +5253,17 @@ var getOriginXcmFee = /*#__PURE__*/function () {
|
|
|
5332
5253
|
tx: tx,
|
|
5333
5254
|
chain: origin,
|
|
5334
5255
|
address: senderAddress,
|
|
5335
|
-
|
|
5256
|
+
asset: _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5257
|
+
amount: amount
|
|
5258
|
+
}),
|
|
5259
|
+
feeAsset: resolvedFeeAsset,
|
|
5260
|
+
// Force dryRun pass
|
|
5261
|
+
useRootOrigin: useRootOrigin
|
|
5336
5262
|
});
|
|
5337
5263
|
case 5:
|
|
5338
5264
|
dryRunResult = _context.v;
|
|
5339
5265
|
if (dryRunResult.success) {
|
|
5340
|
-
_context.n =
|
|
5266
|
+
_context.n = 8;
|
|
5341
5267
|
break;
|
|
5342
5268
|
}
|
|
5343
5269
|
if (!disableFallback) {
|
|
@@ -5353,20 +5279,14 @@ var getOriginXcmFee = /*#__PURE__*/function () {
|
|
|
5353
5279
|
case 7:
|
|
5354
5280
|
_rawFee = _context.v;
|
|
5355
5281
|
_paddedFee = padFee(_rawFee, origin, destination, 'origin');
|
|
5356
|
-
_context.n = 8;
|
|
5357
|
-
return isSufficientOrigin(api, origin, destination, senderAddress, _paddedFee, _objectSpread2(_objectSpread2({}, currency), {}, {
|
|
5358
|
-
amount: amount
|
|
5359
|
-
}), asset, resolvedFeeAsset);
|
|
5360
|
-
case 8:
|
|
5361
|
-
_sufficient = _context.v;
|
|
5362
5282
|
return _context.a(2, {
|
|
5363
5283
|
fee: _paddedFee,
|
|
5364
5284
|
currency: nativeAssetSymbol,
|
|
5365
5285
|
feeType: 'paymentInfo',
|
|
5366
5286
|
dryRunError: dryRunResult.failureReason,
|
|
5367
|
-
sufficient:
|
|
5287
|
+
sufficient: false
|
|
5368
5288
|
});
|
|
5369
|
-
case
|
|
5289
|
+
case 8:
|
|
5370
5290
|
fee = dryRunResult.fee, forwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId, weight = dryRunResult.weight;
|
|
5371
5291
|
currencySymbol = resolvedFeeAsset ? resolvedFeeAsset.symbol : nativeAssetSymbol;
|
|
5372
5292
|
return _context.a(2, {
|
|
@@ -5381,11 +5301,40 @@ var getOriginXcmFee = /*#__PURE__*/function () {
|
|
|
5381
5301
|
}
|
|
5382
5302
|
}, _callee);
|
|
5383
5303
|
}));
|
|
5384
|
-
return function
|
|
5304
|
+
return function getOriginXcmFeeInternal(_x) {
|
|
5385
5305
|
return _ref2.apply(this, arguments);
|
|
5386
5306
|
};
|
|
5387
5307
|
}();
|
|
5388
5308
|
|
|
5309
|
+
var getOriginXcmFee = /*#__PURE__*/function () {
|
|
5310
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
5311
|
+
var forced, real;
|
|
5312
|
+
return _regenerator().w(function (_context) {
|
|
5313
|
+
while (1) switch (_context.n) {
|
|
5314
|
+
case 0:
|
|
5315
|
+
_context.n = 1;
|
|
5316
|
+
return getOriginXcmFeeInternal(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
5317
|
+
useRootOrigin: true
|
|
5318
|
+
}));
|
|
5319
|
+
case 1:
|
|
5320
|
+
forced = _context.v;
|
|
5321
|
+
_context.n = 2;
|
|
5322
|
+
return getOriginXcmFeeInternal(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
5323
|
+
useRootOrigin: false
|
|
5324
|
+
}));
|
|
5325
|
+
case 2:
|
|
5326
|
+
real = _context.v;
|
|
5327
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, forced), {}, {
|
|
5328
|
+
sufficient: real.sufficient
|
|
5329
|
+
}));
|
|
5330
|
+
}
|
|
5331
|
+
}, _callee);
|
|
5332
|
+
}));
|
|
5333
|
+
return function getOriginXcmFee(_x) {
|
|
5334
|
+
return _ref.apply(this, arguments);
|
|
5335
|
+
};
|
|
5336
|
+
}();
|
|
5337
|
+
|
|
5389
5338
|
var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
|
|
5390
5339
|
return assetCheckEnabled ? findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null) : null;
|
|
5391
5340
|
};
|
|
@@ -5588,7 +5537,7 @@ var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
|
|
|
5588
5537
|
};
|
|
5589
5538
|
}();
|
|
5590
5539
|
|
|
5591
|
-
var getFailureInfo = function getFailureInfo(chains, hops) {
|
|
5540
|
+
var getFailureInfo$1 = function getFailureInfo(chains, hops) {
|
|
5592
5541
|
var _chains$origin, _chains$assetHub, _chains$bridgeHub, _chains$destination;
|
|
5593
5542
|
// Check standard chains first for backwards compatibility
|
|
5594
5543
|
if ((_chains$origin = chains.origin) !== null && _chains$origin !== void 0 && _chains$origin.dryRunError) return {
|
|
@@ -5627,8 +5576,8 @@ var getFailureInfo = function getFailureInfo(chains, hops) {
|
|
|
5627
5576
|
}
|
|
5628
5577
|
return {};
|
|
5629
5578
|
};
|
|
5630
|
-
var
|
|
5631
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
5579
|
+
var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
5580
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref, useRootOrigin) {
|
|
5632
5581
|
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, swapConfig, asset, amount, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, destApi, destFeeRes, _result, _getFailureInfo, _failureChain, _failureReason, processHop, traversalResult, destFee, destCurrency, destFeeType, destDryRunError, destSufficient, destResult, _destApi, destFallback, assetHubChain, processedBridgeHub, bridgeHubChain, bridgeHubHopIndex, convertToFeeDetail, result, _getFailureInfo2, failureChain, failureReason;
|
|
5633
5582
|
return _regenerator().w(function (_context2) {
|
|
5634
5583
|
while (1) switch (_context2.p = _context2.n) {
|
|
@@ -5637,7 +5586,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5637
5586
|
asset = findAssetInfoOrThrow(origin, currency, destination);
|
|
5638
5587
|
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
5639
5588
|
_context2.n = 1;
|
|
5640
|
-
return
|
|
5589
|
+
return getOriginXcmFeeInternal({
|
|
5641
5590
|
api: api,
|
|
5642
5591
|
tx: tx,
|
|
5643
5592
|
origin: origin,
|
|
@@ -5645,7 +5594,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5645
5594
|
senderAddress: senderAddress,
|
|
5646
5595
|
feeAsset: feeAsset,
|
|
5647
5596
|
currency: currency,
|
|
5648
|
-
disableFallback: disableFallback
|
|
5597
|
+
disableFallback: disableFallback,
|
|
5598
|
+
useRootOrigin: useRootOrigin
|
|
5649
5599
|
});
|
|
5650
5600
|
case 1:
|
|
5651
5601
|
_yield$getOriginXcmFe = _context2.v;
|
|
@@ -5691,13 +5641,12 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5691
5641
|
case 5:
|
|
5692
5642
|
destFeeRes = _context2.v;
|
|
5693
5643
|
_result = {
|
|
5694
|
-
origin: _objectSpread2(_objectSpread2(_objectSpread2(
|
|
5644
|
+
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
5695
5645
|
fee: originFee
|
|
5696
5646
|
}), originFeeType && {
|
|
5697
5647
|
feeType: originFeeType
|
|
5698
|
-
}), sufficientOriginFee !== undefined && {
|
|
5699
|
-
sufficient: sufficientOriginFee
|
|
5700
5648
|
}), {}, {
|
|
5649
|
+
sufficient: sufficientOriginFee,
|
|
5701
5650
|
currency: originCurrency
|
|
5702
5651
|
}, originDryRunError && {
|
|
5703
5652
|
dryRunError: originDryRunError
|
|
@@ -5715,7 +5664,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5715
5664
|
}),
|
|
5716
5665
|
hops: []
|
|
5717
5666
|
};
|
|
5718
|
-
_getFailureInfo = getFailureInfo({
|
|
5667
|
+
_getFailureInfo = getFailureInfo$1({
|
|
5719
5668
|
origin: _result.origin,
|
|
5720
5669
|
destination: _result.destination
|
|
5721
5670
|
}, []), _failureChain = _getFailureInfo.failureChain, _failureReason = _getFailureInfo.failureReason;
|
|
@@ -5774,7 +5723,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5774
5723
|
}
|
|
5775
5724
|
}, _callee);
|
|
5776
5725
|
}));
|
|
5777
|
-
return function processHop(
|
|
5726
|
+
return function processHop(_x3) {
|
|
5778
5727
|
return _ref3.apply(this, arguments);
|
|
5779
5728
|
};
|
|
5780
5729
|
}();
|
|
@@ -5927,7 +5876,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5927
5876
|
};
|
|
5928
5877
|
})
|
|
5929
5878
|
});
|
|
5930
|
-
_getFailureInfo2 = getFailureInfo({
|
|
5879
|
+
_getFailureInfo2 = getFailureInfo$1({
|
|
5931
5880
|
origin: result.origin,
|
|
5932
5881
|
assetHub: result.assetHub,
|
|
5933
5882
|
bridgeHub: result.bridgeHub,
|
|
@@ -5940,11 +5889,59 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5940
5889
|
}
|
|
5941
5890
|
}, _callee2, null, [[3,, 6, 8]]);
|
|
5942
5891
|
}));
|
|
5943
|
-
return function
|
|
5892
|
+
return function getXcmFeeInternal(_x, _x2) {
|
|
5944
5893
|
return _ref2.apply(this, arguments);
|
|
5945
5894
|
};
|
|
5946
5895
|
}();
|
|
5947
5896
|
|
|
5897
|
+
var getXcmFee = /*#__PURE__*/function () {
|
|
5898
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
5899
|
+
var _real$assetHub, _real$bridgeHub;
|
|
5900
|
+
var forced, real;
|
|
5901
|
+
return _regenerator().w(function (_context) {
|
|
5902
|
+
while (1) switch (_context.n) {
|
|
5903
|
+
case 0:
|
|
5904
|
+
_context.n = 1;
|
|
5905
|
+
return getXcmFeeInternal(options, true);
|
|
5906
|
+
case 1:
|
|
5907
|
+
forced = _context.v;
|
|
5908
|
+
_context.n = 2;
|
|
5909
|
+
return getXcmFeeInternal(options, false);
|
|
5910
|
+
case 2:
|
|
5911
|
+
real = _context.v;
|
|
5912
|
+
return _context.a(2, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, forced), {}, {
|
|
5913
|
+
origin: _objectSpread2(_objectSpread2({}, forced.origin), {}, {
|
|
5914
|
+
sufficient: real.origin.sufficient
|
|
5915
|
+
}),
|
|
5916
|
+
destination: _objectSpread2(_objectSpread2({}, forced.destination), {}, {
|
|
5917
|
+
sufficient: real.destination.sufficient
|
|
5918
|
+
})
|
|
5919
|
+
}, forced.assetHub ? {
|
|
5920
|
+
assetHub: _objectSpread2(_objectSpread2({}, forced.assetHub), {}, {
|
|
5921
|
+
sufficient: (_real$assetHub = real.assetHub) === null || _real$assetHub === void 0 ? void 0 : _real$assetHub.sufficient
|
|
5922
|
+
})
|
|
5923
|
+
} : {}), forced.bridgeHub ? {
|
|
5924
|
+
bridgeHub: _objectSpread2(_objectSpread2({}, forced.bridgeHub), {}, {
|
|
5925
|
+
sufficient: (_real$bridgeHub = real.bridgeHub) === null || _real$bridgeHub === void 0 ? void 0 : _real$bridgeHub.sufficient
|
|
5926
|
+
})
|
|
5927
|
+
} : {}), {}, {
|
|
5928
|
+
hops: forced.hops.map(function (hop, index) {
|
|
5929
|
+
var _real$hops$index;
|
|
5930
|
+
return _objectSpread2(_objectSpread2({}, hop), {}, {
|
|
5931
|
+
result: _objectSpread2(_objectSpread2({}, hop.result), {}, {
|
|
5932
|
+
sufficient: (_real$hops$index = real.hops[index]) === null || _real$hops$index === void 0 ? void 0 : _real$hops$index.result.sufficient
|
|
5933
|
+
})
|
|
5934
|
+
});
|
|
5935
|
+
})
|
|
5936
|
+
}));
|
|
5937
|
+
}
|
|
5938
|
+
}, _callee);
|
|
5939
|
+
}));
|
|
5940
|
+
return function getXcmFee(_x) {
|
|
5941
|
+
return _ref.apply(this, arguments);
|
|
5942
|
+
};
|
|
5943
|
+
}();
|
|
5944
|
+
|
|
5948
5945
|
var BRIDGE_FEE_DOT = 682395810n; // 0.068239581 DOT
|
|
5949
5946
|
var BRIDGE_FEE_KSM = 12016807000n; // 0.012016807 KSM
|
|
5950
5947
|
var getXcmFeeEstimate = /*#__PURE__*/function () {
|
|
@@ -6500,68 +6497,13 @@ var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
|
6500
6497
|
};
|
|
6501
6498
|
}();
|
|
6502
6499
|
|
|
6503
|
-
var attemptDryRunFee = /*#__PURE__*/function () {
|
|
6504
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
6505
|
-
var origin, currency, builder, reductionPcts, lastReduction, result, _i, _reductionPcts, percentage, modifiedBuilder, _t, _t2, _t3, _t4, _t5, _t6, _t7;
|
|
6506
|
-
return _regenerator().w(function (_context) {
|
|
6507
|
-
while (1) switch (_context.n) {
|
|
6508
|
-
case 0:
|
|
6509
|
-
origin = options.origin, currency = options.currency, builder = options.builder;
|
|
6510
|
-
reductionPcts = [0, 10, 20, 30, 40, 50];
|
|
6511
|
-
lastReduction = reductionPcts[reductionPcts.length - 1];
|
|
6512
|
-
result = null;
|
|
6513
|
-
_i = 0, _reductionPcts = reductionPcts;
|
|
6514
|
-
case 1:
|
|
6515
|
-
if (!(_i < _reductionPcts.length)) {
|
|
6516
|
-
_context.n = 5;
|
|
6517
|
-
break;
|
|
6518
|
-
}
|
|
6519
|
-
percentage = _reductionPcts[_i];
|
|
6520
|
-
modifiedBuilder = builder.currency(_objectSpread2(_objectSpread2({}, currency), {}, {
|
|
6521
|
-
amount: padFeeBy(BigInt(currency.amount), -percentage)
|
|
6522
|
-
}));
|
|
6523
|
-
_t = getOriginXcmFee;
|
|
6524
|
-
_t2 = _objectSpread2;
|
|
6525
|
-
_t3 = _objectSpread2({}, options);
|
|
6526
|
-
_t4 = {};
|
|
6527
|
-
_context.n = 2;
|
|
6528
|
-
return modifiedBuilder.build();
|
|
6529
|
-
case 2:
|
|
6530
|
-
_t5 = _context.v;
|
|
6531
|
-
_t6 = {
|
|
6532
|
-
tx: _t5
|
|
6533
|
-
};
|
|
6534
|
-
_t7 = _t2(_t3, _t4, _t6);
|
|
6535
|
-
_context.n = 3;
|
|
6536
|
-
return _t(_t7);
|
|
6537
|
-
case 3:
|
|
6538
|
-
result = _context.v;
|
|
6539
|
-
if (!(result.feeType === 'dryRun' || percentage === lastReduction || !hasDryRunSupport(origin))) {
|
|
6540
|
-
_context.n = 4;
|
|
6541
|
-
break;
|
|
6542
|
-
}
|
|
6543
|
-
return _context.a(2, result);
|
|
6544
|
-
case 4:
|
|
6545
|
-
_i++;
|
|
6546
|
-
_context.n = 1;
|
|
6547
|
-
break;
|
|
6548
|
-
case 5:
|
|
6549
|
-
return _context.a(2, result);
|
|
6550
|
-
}
|
|
6551
|
-
}, _callee);
|
|
6552
|
-
}));
|
|
6553
|
-
return function attemptDryRunFee(_x) {
|
|
6554
|
-
return _ref.apply(this, arguments);
|
|
6555
|
-
};
|
|
6556
|
-
}();
|
|
6557
|
-
|
|
6558
6500
|
var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
6559
6501
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
6560
|
-
var api, senderAddress, chain, destination, currency,
|
|
6502
|
+
var api, senderAddress, chain, destination, currency, tx, feeAsset, resolvedFeeAsset, asset, amount, balance, ed, isNativeAsset, shouldSubstractFee, feeToSubtract, _yield$getOriginXcmFe, fee, transferable;
|
|
6561
6503
|
return _regenerator().w(function (_context) {
|
|
6562
6504
|
while (1) switch (_context.n) {
|
|
6563
6505
|
case 0:
|
|
6564
|
-
api = _ref.api, senderAddress = _ref.senderAddress, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency,
|
|
6506
|
+
api = _ref.api, senderAddress = _ref.senderAddress, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency, tx = _ref.tx, feeAsset = _ref.feeAsset;
|
|
6565
6507
|
validateAddress(senderAddress, chain, false);
|
|
6566
6508
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, chain, destination, currency) : undefined;
|
|
6567
6509
|
asset = findAssetInfoOrThrow(chain, currency, null);
|
|
@@ -6584,9 +6526,9 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
|
6584
6526
|
break;
|
|
6585
6527
|
}
|
|
6586
6528
|
_context.n = 2;
|
|
6587
|
-
return
|
|
6529
|
+
return getOriginXcmFee({
|
|
6588
6530
|
api: api,
|
|
6589
|
-
|
|
6531
|
+
tx: tx,
|
|
6590
6532
|
origin: chain,
|
|
6591
6533
|
destination: chain,
|
|
6592
6534
|
senderAddress: senderAddress,
|
|
@@ -6597,8 +6539,8 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
|
6597
6539
|
disableFallback: false
|
|
6598
6540
|
});
|
|
6599
6541
|
case 2:
|
|
6600
|
-
_yield$
|
|
6601
|
-
fee = _yield$
|
|
6542
|
+
_yield$getOriginXcmFe = _context.v;
|
|
6543
|
+
fee = _yield$getOriginXcmFe.fee;
|
|
6602
6544
|
if (!(fee === undefined)) {
|
|
6603
6545
|
_context.n = 3;
|
|
6604
6546
|
break;
|
|
@@ -6921,22 +6863,16 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
6921
6863
|
bridgeHubFeeResult = _yield$getXcmFee.bridgeHub;
|
|
6922
6864
|
destFeeDetail = _yield$getXcmFee.destination;
|
|
6923
6865
|
hops = _yield$getXcmFee.hops;
|
|
6924
|
-
if (!(originFee === undefined)) {
|
|
6925
|
-
_context2.n = 10;
|
|
6926
|
-
break;
|
|
6927
|
-
}
|
|
6928
|
-
throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency, replaceBigInt), " on chain ").concat(origin, "."));
|
|
6929
|
-
case 10:
|
|
6930
6866
|
isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && isAssetEqual(resolvedFeeAsset, originAsset);
|
|
6931
6867
|
originBalanceAfter = originBalance - amount;
|
|
6932
6868
|
originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - amount : originBalanceFee - originFee;
|
|
6933
6869
|
originBalanceNativeSufficient = originBalanceFee >= originFee;
|
|
6934
6870
|
originBalanceSufficient = originBalanceAfter >= edOrigin;
|
|
6935
6871
|
if (!assetHubFeeResult) {
|
|
6936
|
-
_context2.n =
|
|
6872
|
+
_context2.n = 11;
|
|
6937
6873
|
break;
|
|
6938
6874
|
}
|
|
6939
|
-
_context2.n =
|
|
6875
|
+
_context2.n = 10;
|
|
6940
6876
|
return buildHopInfo({
|
|
6941
6877
|
api: api,
|
|
6942
6878
|
chain: "AssetHub".concat(getRelayChainOf(origin)),
|
|
@@ -6946,15 +6882,15 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
6946
6882
|
senderAddress: senderAddress,
|
|
6947
6883
|
ahAddress: ahAddress
|
|
6948
6884
|
});
|
|
6949
|
-
case
|
|
6885
|
+
case 10:
|
|
6950
6886
|
assetHub = _context2.v;
|
|
6951
|
-
case
|
|
6887
|
+
case 11:
|
|
6952
6888
|
if (!bridgeHubFeeResult) {
|
|
6953
|
-
_context2.n =
|
|
6889
|
+
_context2.n = 13;
|
|
6954
6890
|
break;
|
|
6955
6891
|
}
|
|
6956
6892
|
bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
|
|
6957
|
-
_context2.n =
|
|
6893
|
+
_context2.n = 12;
|
|
6958
6894
|
return buildHopInfo({
|
|
6959
6895
|
api: api,
|
|
6960
6896
|
chain: bridgeHubChain,
|
|
@@ -6964,15 +6900,15 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
6964
6900
|
senderAddress: senderAddress,
|
|
6965
6901
|
ahAddress: ahAddress
|
|
6966
6902
|
});
|
|
6967
|
-
case
|
|
6903
|
+
case 12:
|
|
6968
6904
|
bridgeHub = _context2.v;
|
|
6969
|
-
case
|
|
6905
|
+
case 13:
|
|
6970
6906
|
builtHops = [];
|
|
6971
6907
|
if (!(hops && hops.length > 0)) {
|
|
6972
|
-
_context2.n =
|
|
6908
|
+
_context2.n = 15;
|
|
6973
6909
|
break;
|
|
6974
6910
|
}
|
|
6975
|
-
_context2.n =
|
|
6911
|
+
_context2.n = 14;
|
|
6976
6912
|
return Promise.all(hops.map(/*#__PURE__*/function () {
|
|
6977
6913
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(hop) {
|
|
6978
6914
|
var result;
|
|
@@ -7002,10 +6938,10 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
7002
6938
|
return _ref3.apply(this, arguments);
|
|
7003
6939
|
};
|
|
7004
6940
|
}()));
|
|
7005
|
-
case
|
|
6941
|
+
case 14:
|
|
7006
6942
|
builtHops = _context2.v;
|
|
7007
|
-
case
|
|
7008
|
-
_context2.n =
|
|
6943
|
+
case 15:
|
|
6944
|
+
_context2.n = 16;
|
|
7009
6945
|
return buildDestInfo({
|
|
7010
6946
|
api: api,
|
|
7011
6947
|
origin: origin,
|
|
@@ -7020,7 +6956,7 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
7020
6956
|
assetHubFee: assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.fee,
|
|
7021
6957
|
bridgeFee: bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.fee
|
|
7022
6958
|
});
|
|
7023
|
-
case
|
|
6959
|
+
case 16:
|
|
7024
6960
|
destinationInfo = _context2.v;
|
|
7025
6961
|
return _context2.a(2, {
|
|
7026
6962
|
chain: {
|
|
@@ -7049,17 +6985,17 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
7049
6985
|
hops: builtHops,
|
|
7050
6986
|
destination: destinationInfo
|
|
7051
6987
|
});
|
|
7052
|
-
case
|
|
7053
|
-
_context2.p =
|
|
6988
|
+
case 17:
|
|
6989
|
+
_context2.p = 17;
|
|
7054
6990
|
api.setDisconnectAllowed(true);
|
|
7055
|
-
_context2.n =
|
|
6991
|
+
_context2.n = 18;
|
|
7056
6992
|
return api.disconnect();
|
|
6993
|
+
case 18:
|
|
6994
|
+
return _context2.f(17);
|
|
7057
6995
|
case 19:
|
|
7058
|
-
return _context2.f(18);
|
|
7059
|
-
case 20:
|
|
7060
6996
|
return _context2.a(2);
|
|
7061
6997
|
}
|
|
7062
|
-
}, _callee2, null, [[3,,
|
|
6998
|
+
}, _callee2, null, [[3,, 17, 19]]);
|
|
7063
6999
|
}));
|
|
7064
7000
|
return function getTransferInfo(_x) {
|
|
7065
7001
|
return _ref2.apply(this, arguments);
|
|
@@ -7216,14 +7152,264 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
|
|
|
7216
7152
|
};
|
|
7217
7153
|
}();
|
|
7218
7154
|
|
|
7219
|
-
var
|
|
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) {
|
|
7160
|
+
case 0:
|
|
7161
|
+
if (!feeAsset) {
|
|
7162
|
+
_context.n = 1;
|
|
7163
|
+
break;
|
|
7164
|
+
}
|
|
7165
|
+
return _context.a(2, undefined);
|
|
7166
|
+
case 1:
|
|
7167
|
+
edNative = getExistentialDepositOrThrow(origin);
|
|
7168
|
+
_context.n = 2;
|
|
7169
|
+
return getBalanceNativeInternal({
|
|
7170
|
+
api: api,
|
|
7171
|
+
chain: origin,
|
|
7172
|
+
address: senderAddress
|
|
7173
|
+
});
|
|
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;
|
|
7180
|
+
break;
|
|
7181
|
+
}
|
|
7182
|
+
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
7183
|
+
case 3:
|
|
7184
|
+
if (isNativeAssetToOrigin) {
|
|
7185
|
+
_context.n = 5;
|
|
7186
|
+
break;
|
|
7187
|
+
}
|
|
7188
|
+
isSufficientNative = balanceNative - edNative - feeNative > 0n;
|
|
7189
|
+
_context.n = 4;
|
|
7190
|
+
return getAssetBalance({
|
|
7191
|
+
api: api,
|
|
7192
|
+
chain: origin,
|
|
7193
|
+
address: senderAddress,
|
|
7194
|
+
currency: currency
|
|
7195
|
+
});
|
|
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;
|
|
7221
|
+
break;
|
|
7222
|
+
}
|
|
7223
|
+
return _context2.a(2, undefined);
|
|
7224
|
+
case 1:
|
|
7225
|
+
existentialDeposit = getExistentialDepositOrThrow(destination);
|
|
7226
|
+
_context2.n = 2;
|
|
7227
|
+
return getBalanceNativeInternal({
|
|
7228
|
+
api: api,
|
|
7229
|
+
chain: destination,
|
|
7230
|
+
address: address
|
|
7231
|
+
});
|
|
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;
|
|
7265
|
+
return _regenerator().w(function (_context) {
|
|
7266
|
+
while (1) switch (_context.p = _context.n) {
|
|
7267
|
+
case 0:
|
|
7268
|
+
if (!(destination === 'Ethereum')) {
|
|
7269
|
+
_context.n = 1;
|
|
7270
|
+
break;
|
|
7271
|
+
}
|
|
7272
|
+
return _context.a(2, 0n);
|
|
7273
|
+
case 1:
|
|
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
|
|
7311
|
+
});
|
|
7312
|
+
case 8:
|
|
7313
|
+
return _context.a(2, _context.v);
|
|
7314
|
+
}
|
|
7315
|
+
}, _callee, null, [[2, 4]]);
|
|
7316
|
+
}));
|
|
7317
|
+
return function calcPaymentInfoFee() {
|
|
7318
|
+
return _ref2.apply(this, arguments);
|
|
7319
|
+
};
|
|
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,
|
|
7344
|
+
origin: origin,
|
|
7345
|
+
asset: asset,
|
|
7346
|
+
originFee: originFee,
|
|
7347
|
+
feeAsset: resolvedFeeAsset,
|
|
7348
|
+
amount: BigInt(currency.amount) < 2n ? 2n : BigInt(currency.amount)
|
|
7349
|
+
});
|
|
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
|
+
}
|
|
7360
|
+
return _context2.a(2, {
|
|
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
|
|
7382
|
+
});
|
|
7383
|
+
}
|
|
7384
|
+
}, _callee2);
|
|
7385
|
+
}));
|
|
7386
|
+
return function getDestXcmFee(_x) {
|
|
7387
|
+
return _ref.apply(this, arguments);
|
|
7388
|
+
};
|
|
7389
|
+
}();
|
|
7390
|
+
|
|
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
|
+
}
|
|
7402
|
+
}
|
|
7220
7403
|
var _iterator = _createForOfIteratorHelper(hops),
|
|
7221
7404
|
_step;
|
|
7222
7405
|
try {
|
|
7223
7406
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
7224
7407
|
var hop = _step.value;
|
|
7225
|
-
if (!hop.result.success) {
|
|
7226
|
-
|
|
7408
|
+
if (!hop.result.success && hop.result.failureReason) {
|
|
7409
|
+
return {
|
|
7410
|
+
failureReason: hop.result.failureReason,
|
|
7411
|
+
failureChain: hop.chain
|
|
7412
|
+
};
|
|
7227
7413
|
}
|
|
7228
7414
|
}
|
|
7229
7415
|
} catch (err) {
|
|
@@ -7231,7 +7417,182 @@ var validateHops = function validateHops(hops) {
|
|
|
7231
7417
|
} finally {
|
|
7232
7418
|
_iterator.f();
|
|
7233
7419
|
}
|
|
7420
|
+
return {};
|
|
7234
7421
|
};
|
|
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) {
|
|
7428
|
+
case 0:
|
|
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
|
+
});
|
|
7444
|
+
case 1:
|
|
7445
|
+
originDryRun = _context2.v;
|
|
7446
|
+
if (originDryRun.success) {
|
|
7447
|
+
_context2.n = 2;
|
|
7448
|
+
break;
|
|
7449
|
+
}
|
|
7450
|
+
return _context2.a(2, {
|
|
7451
|
+
failureReason: originDryRun.failureReason,
|
|
7452
|
+
failureChain: 'origin',
|
|
7453
|
+
origin: originDryRun,
|
|
7454
|
+
hops: []
|
|
7455
|
+
});
|
|
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({
|
|
7514
|
+
api: api,
|
|
7515
|
+
origin: origin,
|
|
7516
|
+
destination: destination,
|
|
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
|
+
}
|
|
7531
|
+
});
|
|
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;
|
|
7539
|
+
break;
|
|
7540
|
+
}
|
|
7541
|
+
_context2.n = 4;
|
|
7542
|
+
return addEthereumBridgeFees(api, traversalResult.bridgeHub, destination, assetHubChain);
|
|
7543
|
+
case 4:
|
|
7544
|
+
_t = _context2.v;
|
|
7545
|
+
_context2.n = 6;
|
|
7546
|
+
break;
|
|
7547
|
+
case 5:
|
|
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
|
+
});
|
|
7588
|
+
}
|
|
7589
|
+
}, _callee2);
|
|
7590
|
+
}));
|
|
7591
|
+
return function dryRunInternal(_x) {
|
|
7592
|
+
return _ref.apply(this, arguments);
|
|
7593
|
+
};
|
|
7594
|
+
}();
|
|
7595
|
+
|
|
7235
7596
|
var getReserveFeeFromHops = function getReserveFeeFromHops(hops) {
|
|
7236
7597
|
if (!hops || hops.length === 0 || !hops[0].result.success) {
|
|
7237
7598
|
return MIN_FEE;
|
|
@@ -7241,7 +7602,7 @@ var getReserveFeeFromHops = function getReserveFeeFromHops(hops) {
|
|
|
7241
7602
|
var FEE_PADDING_PERCENTAGE$1 = 40;
|
|
7242
7603
|
var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
7243
7604
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options) {
|
|
7244
|
-
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;
|
|
7245
7606
|
return _regenerator().w(function (_context) {
|
|
7246
7607
|
while (1) switch (_context.n) {
|
|
7247
7608
|
case 0:
|
|
@@ -7253,25 +7614,6 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7253
7614
|
throw new InvalidParameterError('Please provide senderAddress');
|
|
7254
7615
|
case 1:
|
|
7255
7616
|
assertAddressIsString(address);
|
|
7256
|
-
if (!(feeCurrency && feeAssetInfo && !isAssetEqual(assetInfo, feeAssetInfo))) {
|
|
7257
|
-
_context.n = 3;
|
|
7258
|
-
break;
|
|
7259
|
-
}
|
|
7260
|
-
_context.n = 2;
|
|
7261
|
-
return getAssetBalanceInternal({
|
|
7262
|
-
api: api,
|
|
7263
|
-
address: senderAddress,
|
|
7264
|
-
chain: chain,
|
|
7265
|
-
currency: feeCurrency
|
|
7266
|
-
});
|
|
7267
|
-
case 2:
|
|
7268
|
-
_t = _context.v;
|
|
7269
|
-
_context.n = 4;
|
|
7270
|
-
break;
|
|
7271
|
-
case 3:
|
|
7272
|
-
_t = undefined;
|
|
7273
|
-
case 4:
|
|
7274
|
-
feeAssetBalance = _t;
|
|
7275
7617
|
checkAmount = function checkAmount(fee) {
|
|
7276
7618
|
if (assetInfo.amount <= fee) {
|
|
7277
7619
|
throw new InvalidParameterError("Asset amount is too low, please increase the amount or use a different fee asset.");
|
|
@@ -7292,14 +7634,16 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7292
7634
|
senderAddress: senderAddress,
|
|
7293
7635
|
version: version,
|
|
7294
7636
|
paraIdTo: paraIdTo
|
|
7295
|
-
};
|
|
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;
|
|
7296
7640
|
call = createExecuteCall(chain, createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7297
7641
|
fees: {
|
|
7298
|
-
originFee:
|
|
7642
|
+
originFee: feeAssetAmount,
|
|
7299
7643
|
reserveFee: MIN_FEE
|
|
7300
7644
|
}
|
|
7301
7645
|
})), MAX_WEIGHT);
|
|
7302
|
-
_context.n =
|
|
7646
|
+
_context.n = 2;
|
|
7303
7647
|
return dryRunInternal({
|
|
7304
7648
|
api: api,
|
|
7305
7649
|
tx: api.callTxMethod(call),
|
|
@@ -7308,17 +7652,17 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7308
7652
|
senderAddress: senderAddress,
|
|
7309
7653
|
address: address,
|
|
7310
7654
|
currency: currency,
|
|
7311
|
-
feeAsset: feeCurrency
|
|
7655
|
+
feeAsset: feeCurrency,
|
|
7656
|
+
useRootOrigin: true
|
|
7312
7657
|
});
|
|
7313
|
-
case
|
|
7658
|
+
case 2:
|
|
7314
7659
|
dryRunResult = _context.v;
|
|
7315
7660
|
if (dryRunResult.origin.success) {
|
|
7316
|
-
_context.n =
|
|
7661
|
+
_context.n = 3;
|
|
7317
7662
|
break;
|
|
7318
7663
|
}
|
|
7319
7664
|
throw new DryRunFailedError(dryRunResult.failureReason);
|
|
7320
|
-
case
|
|
7321
|
-
validateHops(dryRunResult.hops);
|
|
7665
|
+
case 3:
|
|
7322
7666
|
originFeeEstimate = dryRunResult.origin.fee;
|
|
7323
7667
|
originFee = padFeeBy(originFeeEstimate, FEE_PADDING_PERCENTAGE$1);
|
|
7324
7668
|
reserveFeeEstimate = getReserveFeeFromHops(dryRunResult.hops);
|
|
@@ -7330,9 +7674,9 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7330
7674
|
reserveFee: reserveFee
|
|
7331
7675
|
}
|
|
7332
7676
|
}));
|
|
7333
|
-
_context.n =
|
|
7677
|
+
_context.n = 4;
|
|
7334
7678
|
return api.getXcmWeight(xcm);
|
|
7335
|
-
case
|
|
7679
|
+
case 4:
|
|
7336
7680
|
weight = _context.v;
|
|
7337
7681
|
return _context.a(2, createExecuteCall(chain, xcm, weight));
|
|
7338
7682
|
}
|
|
@@ -7623,7 +7967,7 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
7623
7967
|
}();
|
|
7624
7968
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
7625
7969
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
7626
|
-
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;
|
|
7627
7971
|
return _regenerator().w(function (_context3) {
|
|
7628
7972
|
while (1) switch (_context3.n) {
|
|
7629
7973
|
case 0:
|
|
@@ -7650,7 +7994,8 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7650
7994
|
swapConfig: {
|
|
7651
7995
|
currencyTo: currencyTo,
|
|
7652
7996
|
exchangeChain: exchangeChain
|
|
7653
|
-
}
|
|
7997
|
+
},
|
|
7998
|
+
useRootOrigin: true
|
|
7654
7999
|
}; // First dry run with dummy fees to extract actual fees
|
|
7655
8000
|
_context3.n = 2;
|
|
7656
8001
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
@@ -7669,38 +8014,8 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7669
8014
|
}));
|
|
7670
8015
|
case 3:
|
|
7671
8016
|
firstDryRunResult = _context3.v;
|
|
7672
|
-
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult.hops, exchangeChain, destChain);
|
|
7673
|
-
|
|
7674
|
-
requireExchangeSuccess = !hasOriginReserveHop;
|
|
7675
|
-
extractedFees = extractFeesFromDryRun(chain, firstDryRunResult, exchangeHopIndex, destChain, false); // If we need exchange to succeed but it failed, throw error
|
|
7676
|
-
if (!(requireExchangeSuccess && extractedFees.exchangeFee === 0n)) {
|
|
7677
|
-
_context3.n = 6;
|
|
7678
|
-
break;
|
|
7679
|
-
}
|
|
7680
|
-
if (!destChain) {
|
|
7681
|
-
_context3.n = 5;
|
|
7682
|
-
break;
|
|
7683
|
-
}
|
|
7684
|
-
if (!chain) {
|
|
7685
|
-
_context3.n = 4;
|
|
7686
|
-
break;
|
|
7687
|
-
}
|
|
7688
|
-
exchangeHop = firstDryRunResult.hops[exchangeHopIndex];
|
|
7689
|
-
if (exchangeHop.result.success) {
|
|
7690
|
-
_context3.n = 4;
|
|
7691
|
-
break;
|
|
7692
|
-
}
|
|
7693
|
-
throw new DryRunFailedError("Exchange hop failed when no origin reserve exists: ".concat(exchangeHop.result.failureReason || 'Unknown reason'));
|
|
7694
|
-
case 4:
|
|
7695
|
-
_context3.n = 6;
|
|
7696
|
-
break;
|
|
7697
|
-
case 5:
|
|
7698
|
-
if (!(firstDryRunResult.destination && !firstDryRunResult.destination.success)) {
|
|
7699
|
-
_context3.n = 6;
|
|
7700
|
-
break;
|
|
7701
|
-
}
|
|
7702
|
-
throw new DryRunFailedError("Exchange (destination) failed when no origin reserve exists: ".concat(firstDryRunResult.destination.failureReason || 'Unknown reason'));
|
|
7703
|
-
case 6:
|
|
8017
|
+
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult.hops, exchangeChain, destChain);
|
|
8018
|
+
extractedFees = extractFeesFromDryRun(chain, firstDryRunResult, exchangeHopIndex, destChain, false);
|
|
7704
8019
|
if (extractedFees.exchangeFee === 0n) {
|
|
7705
8020
|
// We set the exchange fee to non-zero value to prevent creating dummy tx
|
|
7706
8021
|
extractedFees.exchangeFee = MIN_FEE;
|
|
@@ -7710,67 +8025,27 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7710
8025
|
validateAmount(BigInt(assetFrom.amount), totalFeesInFromAsset);
|
|
7711
8026
|
updatedAssetTo = assetTo;
|
|
7712
8027
|
if (!chain) {
|
|
7713
|
-
_context3.n =
|
|
8028
|
+
_context3.n = 5;
|
|
7714
8029
|
break;
|
|
7715
8030
|
}
|
|
7716
8031
|
amountAvailableForSwap = BigInt(assetFrom.amount) - totalFeesInFromAsset;
|
|
7717
|
-
_context3.n =
|
|
8032
|
+
_context3.n = 4;
|
|
7718
8033
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
7719
|
-
case
|
|
8034
|
+
case 4:
|
|
7720
8035
|
recalculatedMinAmountOut = _context3.v;
|
|
7721
8036
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7722
8037
|
amount: recalculatedMinAmountOut
|
|
7723
8038
|
});
|
|
7724
|
-
case
|
|
7725
|
-
_context3.n =
|
|
8039
|
+
case 5:
|
|
8040
|
+
_context3.n = 6;
|
|
7726
8041
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7727
8042
|
assetInfoTo: updatedAssetTo,
|
|
7728
8043
|
fees: extractedFees
|
|
7729
8044
|
}), firstDryRunResult.origin.success ? firstDryRunResult.origin.weight : undefined);
|
|
7730
|
-
case
|
|
8045
|
+
case 6:
|
|
7731
8046
|
_yield$createXcmAndCa2 = _context3.v;
|
|
7732
|
-
|
|
7733
|
-
_context3.n = 10;
|
|
7734
|
-
return executeDryRun(_objectSpread2(_objectSpread2({}, dryRunParams), {}, {
|
|
7735
|
-
tx: api.callTxMethod(secondCall)
|
|
7736
|
-
}));
|
|
7737
|
-
case 10:
|
|
7738
|
-
secondDryRunResult = _context3.v;
|
|
7739
|
-
hasHopsInSecondRun = secondDryRunResult.hops && secondDryRunResult.hops.length > 0;
|
|
7740
|
-
isOnExchangeChain = chain === exchangeChain;
|
|
7741
|
-
if (hasHopsInSecondRun && !isOnExchangeChain) {
|
|
7742
|
-
finalExchangeHopIndex = findExchangeHopIndex(chain, secondDryRunResult.hops, exchangeChain, destChain);
|
|
7743
|
-
finalFees = extractFeesFromDryRun(chain, secondDryRunResult, finalExchangeHopIndex, destChain, true);
|
|
7744
|
-
} else {
|
|
7745
|
-
finalFees = extractFeesFromDryRun(chain, secondDryRunResult, 0, destChain, true);
|
|
7746
|
-
}
|
|
7747
|
-
// Validate that we have enough after accounting for final fees
|
|
7748
|
-
finalTotalFeesInFromAsset = chain ? finalFees.originReserveFee + finalFees.exchangeFee : 0n;
|
|
7749
|
-
validateAmount(BigInt(assetFrom.amount), finalTotalFeesInFromAsset);
|
|
7750
|
-
// If the final fees are different, we might need one more iteration
|
|
7751
|
-
if (!(finalFees.exchangeFee !== extractedFees.exchangeFee || finalFees.originReserveFee !== extractedFees.originReserveFee)) {
|
|
7752
|
-
_context3.n = 13;
|
|
7753
|
-
break;
|
|
7754
|
-
}
|
|
7755
|
-
finalAmountAvailableForSwap = BigInt(assetFrom.amount) - finalTotalFeesInFromAsset;
|
|
7756
|
-
_context3.n = 11;
|
|
7757
|
-
return calculateMinAmountOut(finalAmountAvailableForSwap);
|
|
7758
|
-
case 11:
|
|
7759
|
-
finalMinAmountOut = _context3.v;
|
|
7760
|
-
finalAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7761
|
-
amount: finalMinAmountOut
|
|
7762
|
-
});
|
|
7763
|
-
_context3.n = 12;
|
|
7764
|
-
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7765
|
-
assetInfoTo: finalAssetTo,
|
|
7766
|
-
fees: finalFees
|
|
7767
|
-
}), secondDryRunResult.origin.success ? secondDryRunResult.origin.weight : undefined);
|
|
7768
|
-
case 12:
|
|
7769
|
-
_yield$createXcmAndCa3 = _context3.v;
|
|
7770
|
-
finalCall = _yield$createXcmAndCa3.call;
|
|
8047
|
+
finalCall = _yield$createXcmAndCa2.call;
|
|
7771
8048
|
return _context3.a(2, api.callTxMethod(finalCall));
|
|
7772
|
-
case 13:
|
|
7773
|
-
return _context3.a(2, api.callTxMethod(secondCall));
|
|
7774
8049
|
}
|
|
7775
8050
|
}, _callee3);
|
|
7776
8051
|
}));
|
|
@@ -10637,7 +10912,7 @@ var Moonbeam = /*#__PURE__*/function (_Parachain) {
|
|
|
10637
10912
|
case 3:
|
|
10638
10913
|
location = this.getLocation(assetInfo, scenario);
|
|
10639
10914
|
return _context.a(2, transferPolkadotXcm(_objectSpread2(_objectSpread2({}, input), {}, {
|
|
10640
|
-
asset: createAsset(version, assetInfo.amount, location)
|
|
10915
|
+
asset: createAsset(version, assetInfo.amount, localizeLocation(this.chain, location))
|
|
10641
10916
|
}), 'transfer_assets', 'Unlimited'));
|
|
10642
10917
|
}
|
|
10643
10918
|
}, _callee, this);
|
|
@@ -12236,15 +12511,19 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
12236
12511
|
key: "getTransferableAmount",
|
|
12237
12512
|
value: (function () {
|
|
12238
12513
|
var _getTransferableAmount2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
12239
|
-
var _this$_options7, from, to, senderAddress, currency, feeAsset;
|
|
12514
|
+
var _this$_options7, from, to, senderAddress, currency, feeAsset, tx;
|
|
12240
12515
|
return _regenerator().w(function (_context8) {
|
|
12241
12516
|
while (1) switch (_context8.n) {
|
|
12242
12517
|
case 0:
|
|
12243
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;
|
|
12244
12519
|
assertToIsString(to);
|
|
12520
|
+
_context8.n = 1;
|
|
12521
|
+
return this.build();
|
|
12522
|
+
case 1:
|
|
12523
|
+
tx = _context8.v;
|
|
12245
12524
|
return _context8.a(2, getTransferableAmount({
|
|
12246
12525
|
api: this.api,
|
|
12247
|
-
|
|
12526
|
+
tx: tx,
|
|
12248
12527
|
origin: from,
|
|
12249
12528
|
destination: to,
|
|
12250
12529
|
senderAddress: senderAddress,
|
|
@@ -12371,4 +12650,4 @@ var Builder = function Builder(api) {
|
|
|
12371
12650
|
return new GeneralBuilder(api, new BatchTransactionManager());
|
|
12372
12651
|
};
|
|
12373
12652
|
|
|
12374
|
-
export { AssetClaimBuilder, BatchMode, BridgeHaltedError, Builder, ChainNotSupportedError, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleChainsError, InvalidAddressError, InvalidParameterError, MissingChainApiError, NoXCMSupportImplementedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, UnableToComputeError, XTokensError, abstractDecimals, addEthereumBridgeFees, addXcmVersionHeader, applyDecimalAbstraction, assertAddressIsString, assertHasId, assertHasLocation, assertIsForeign, assertToIsString, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createAsset, createAssetsFilter, createBaseExecuteXcm, createBeneficiaryLocXTokens, createBeneficiaryLocation, createChainClient, createDirectExecuteXcm, createExecuteCall, createExecuteExchangeXcm, createTypeAndThenCall, createVersionedAssets, createX1Payload, deriveAccountId, dryRun, dryRunOrigin, encodeSs58, getAssetBalance, getAssetBalanceInternal, getAssetReserveChain, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getChain, getChainConfig, getChainLocation, getChainProviders, getChainVersion, getOriginFeeDetails, getOriginFeeDetailsInternal, getOriginXcmFee, getOriginXcmFeeEstimate, getParaEthTransferFees, getParaId, getRelayChainOf, getTChain, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, handleExecuteTransfer, handleSwapExecuteTransfer, handleToAhTeleport, isConfig, localizeLocation, maybeOverrideAsset, maybeOverrideAssets, padFee, padFeeBy, resolveModuleError, resolveParaId, reverseTransformLocation, send, sortAssets, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, traverseXcmHops, validateAddress, verifyEdOnDestination };
|
|
12653
|
+
export { AssetClaimBuilder, AssetsPallet, BatchMode, BridgeHaltedError, Builder, ChainNotSupportedError, DRY_RUN_CLIENT_TIMEOUT_MS, DryRunFailedError, ETHEREUM_JUNCTION, ETH_CHAIN_ID, GeneralBuilder, IncompatibleChainsError, InvalidAddressError, InvalidParameterError, MissingChainApiError, NoXCMSupportImplementedError, PolkadotXcmError, ScenarioNotSupportedError, TX_CLIENT_TIMEOUT_MS, TransferToAhNotSupported, UnableToComputeError, XTokensError, abstractDecimals, addEthereumBridgeFees, addXcmVersionHeader, applyDecimalAbstraction, assertAddressIsString, assertHasId, assertHasLocation, assertIsForeign, assertToIsString, blake2b256, blake2b512, claimAssets, computeFeeFromDryRun, computeFeeFromDryRunPjs, convertSs58, createAsset, createAssetsFilter, createBaseExecuteXcm, createBeneficiaryLocXTokens, createBeneficiaryLocation, createChainClient, createDirectExecuteXcm, createExecuteCall, createExecuteExchangeXcm, createTypeAndThenCall, createVersionedAssets, createX1Payload, deriveAccountId, dryRun, dryRunOrigin, encodeSs58, getAssetBalance, getAssetBalanceInternal, getAssetReserveChain, getBalanceForeign, getBalanceForeignInternal, getBalanceNative, getBalanceNativeInternal, getBridgeStatus, getChain, getChainConfig, getChainLocation, getChainProviders, getChainVersion, getOriginFeeDetails, getOriginFeeDetailsInternal, getOriginXcmFee, getOriginXcmFeeEstimate, getOriginXcmFeeInternal, getParaEthTransferFees, getParaId, getRelayChainOf, getTChain, getTransferInfo, getTransferableAmount, getTransferableAmountInternal, getXcmFee, getXcmFeeEstimate, handleExecuteTransfer, handleSwapExecuteTransfer, handleToAhTeleport, isConfig, localizeLocation, maybeOverrideAsset, maybeOverrideAssets, padFee, padFeeBy, resolveModuleError, resolveParaId, reverseTransformLocation, send, sortAssets, transferMoonbeamEvm, transferMoonbeamToEth, transferRelayToPara, traverseXcmHops, validateAddress, verifyEdOnDestination, wrapTxBypass };
|