@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.cjs
CHANGED
|
@@ -3473,6 +3473,129 @@ var createDirectExecuteXcm = function createDirectExecuteXcm(options) {
|
|
|
3473
3473
|
return addXcmVersionHeader(fullXcm, version);
|
|
3474
3474
|
};
|
|
3475
3475
|
|
|
3476
|
+
var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
|
|
3477
|
+
var asset = assets.findAssetInfo(origin, feeAsset, !sdkCommon.isTLocation(destination) ? destination : null);
|
|
3478
|
+
var usesRawOverriddenMultiAssets = Array.isArray(currency) && currency.every(assets.isTAsset);
|
|
3479
|
+
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
3480
|
+
throwUnsupportedCurrency(feeAsset, origin);
|
|
3481
|
+
}
|
|
3482
|
+
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
3483
|
+
};
|
|
3484
|
+
|
|
3485
|
+
var isAssetHub = function isAssetHub(chain) {
|
|
3486
|
+
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
3487
|
+
};
|
|
3488
|
+
var isBridgeHub = function isBridgeHub(chain) {
|
|
3489
|
+
return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
|
|
3490
|
+
};
|
|
3491
|
+
var isPeople = function isPeople(chain) {
|
|
3492
|
+
return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
|
|
3493
|
+
};
|
|
3494
|
+
var isSystemPara = function isSystemPara(chain) {
|
|
3495
|
+
return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
|
|
3496
|
+
};
|
|
3497
|
+
var mul = function mul(v, num) {
|
|
3498
|
+
var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
|
|
3499
|
+
return v * num / den;
|
|
3500
|
+
};
|
|
3501
|
+
var padFee = function padFee(raw, origin, dest, side) {
|
|
3502
|
+
var relayOrigin = sdkCommon.isRelayChain(origin);
|
|
3503
|
+
var relayDest = sdkCommon.isRelayChain(dest);
|
|
3504
|
+
var sysParaOrigin = isSystemPara(origin);
|
|
3505
|
+
var sysParaDest = isSystemPara(dest);
|
|
3506
|
+
var relayToPara = relayOrigin && !relayDest;
|
|
3507
|
+
var sysParaToPara = sysParaOrigin && !sysParaDest;
|
|
3508
|
+
var paraToPara = !relayOrigin && !sysParaOrigin;
|
|
3509
|
+
if (sysParaToPara) return raw * 40n;
|
|
3510
|
+
if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
|
|
3511
|
+
if (paraToPara && side == 'origin' && origin === 'Mythos' && dest !== 'Ethereum') {
|
|
3512
|
+
return 150000000000000000n;
|
|
3513
|
+
}
|
|
3514
|
+
if (paraToPara) return mul(raw, 130n, 100n);
|
|
3515
|
+
// apply default 30% padding
|
|
3516
|
+
return mul(raw, 130n, 100n);
|
|
3517
|
+
};
|
|
3518
|
+
var padFeeBy = function padFeeBy(amount, percent) {
|
|
3519
|
+
return mul(amount, BigInt(100 + percent), 100n);
|
|
3520
|
+
};
|
|
3521
|
+
|
|
3522
|
+
var determineAddress = function determineAddress(chain, address, senderAddress) {
|
|
3523
|
+
if (assets.isChainEvm(chain)) {
|
|
3524
|
+
return viem.isAddress(address) ? address : senderAddress;
|
|
3525
|
+
}
|
|
3526
|
+
return viem.isAddress(address) ? senderAddress : address;
|
|
3527
|
+
};
|
|
3528
|
+
var getReverseTxFee = /*#__PURE__*/function () {
|
|
3529
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
|
|
3530
|
+
var api, origin, destination, senderAddress, address, currency, toAddress, fromAddress, tx, rawFee;
|
|
3531
|
+
return _regenerator().w(function (_context) {
|
|
3532
|
+
while (1) switch (_context.n) {
|
|
3533
|
+
case 0:
|
|
3534
|
+
api = _ref.api, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
|
|
3535
|
+
toAddress = determineAddress(origin, address, senderAddress);
|
|
3536
|
+
fromAddress = determineAddress(destination, address, senderAddress);
|
|
3537
|
+
_context.n = 1;
|
|
3538
|
+
return Builder(api).from(destination).to(origin).address(toAddress).senderAddress(fromAddress).currency(_objectSpread2(_objectSpread2({}, currencyInput), {}, {
|
|
3539
|
+
amount: currency.amount
|
|
3540
|
+
})).build();
|
|
3541
|
+
case 1:
|
|
3542
|
+
tx = _context.v;
|
|
3543
|
+
_context.n = 2;
|
|
3544
|
+
return api.calculateTransactionFee(tx, fromAddress);
|
|
3545
|
+
case 2:
|
|
3546
|
+
rawFee = _context.v;
|
|
3547
|
+
return _context.a(2, padFee(rawFee, origin, destination, 'destination'));
|
|
3548
|
+
}
|
|
3549
|
+
}, _callee);
|
|
3550
|
+
}));
|
|
3551
|
+
return function getReverseTxFee(_x, _x2) {
|
|
3552
|
+
return _ref2.apply(this, arguments);
|
|
3553
|
+
};
|
|
3554
|
+
}();
|
|
3555
|
+
|
|
3556
|
+
var AssetsPallet = /*#__PURE__*/function () {
|
|
3557
|
+
function AssetsPallet() {
|
|
3558
|
+
_classCallCheck(this, AssetsPallet);
|
|
3559
|
+
}
|
|
3560
|
+
return _createClass(AssetsPallet, [{
|
|
3561
|
+
key: "setBalance",
|
|
3562
|
+
value: function setBalance(address, asset, chain) {
|
|
3563
|
+
assertHasId(asset);
|
|
3564
|
+
var assetId = asset.assetId,
|
|
3565
|
+
amount = asset.amount;
|
|
3566
|
+
var id = chain === 'Astar' || chain === 'Shiden' || chain === 'Moonbeam' ? BigInt(assetId) : Number(assetId);
|
|
3567
|
+
var addr = assets.isChainEvm(chain) ? address : {
|
|
3568
|
+
Id: address
|
|
3569
|
+
};
|
|
3570
|
+
return Promise.resolve({
|
|
3571
|
+
assetStatusTx: {
|
|
3572
|
+
module: 'Assets',
|
|
3573
|
+
method: 'force_asset_status',
|
|
3574
|
+
parameters: {
|
|
3575
|
+
id: id,
|
|
3576
|
+
owner: addr,
|
|
3577
|
+
issuer: addr,
|
|
3578
|
+
admin: addr,
|
|
3579
|
+
freezer: addr,
|
|
3580
|
+
min_balance: 0n,
|
|
3581
|
+
is_sufficient: true,
|
|
3582
|
+
is_frozen: false
|
|
3583
|
+
}
|
|
3584
|
+
},
|
|
3585
|
+
balanceTx: {
|
|
3586
|
+
module: 'Assets',
|
|
3587
|
+
method: 'mint',
|
|
3588
|
+
parameters: {
|
|
3589
|
+
id: id,
|
|
3590
|
+
beneficiary: addr,
|
|
3591
|
+
amount: amount
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
});
|
|
3595
|
+
}
|
|
3596
|
+
}]);
|
|
3597
|
+
}();
|
|
3598
|
+
|
|
3476
3599
|
// Inspired by Moonbeam XCM-SDK
|
|
3477
3600
|
// https://github.com/moonbeam-foundation/xcm-sdk/blob/ab835c15bf41612604b1c858d956a9f07705ed65/packages/utils/src/format/asset.ts#L1
|
|
3478
3601
|
var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
|
|
@@ -3966,322 +4089,75 @@ var getOriginFeeDetails = /*#__PURE__*/function () {
|
|
|
3966
4089
|
};
|
|
3967
4090
|
}();
|
|
3968
4091
|
|
|
3969
|
-
var
|
|
3970
|
-
var
|
|
3971
|
-
|
|
3972
|
-
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
3973
|
-
throwUnsupportedCurrency(feeAsset, origin);
|
|
3974
|
-
}
|
|
3975
|
-
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
3976
|
-
};
|
|
3977
|
-
|
|
3978
|
-
var isAssetHub = function isAssetHub(chain) {
|
|
3979
|
-
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
3980
|
-
};
|
|
3981
|
-
var isBridgeHub = function isBridgeHub(chain) {
|
|
3982
|
-
return chain === 'BridgeHubPolkadot' || chain === 'BridgeHubKusama';
|
|
3983
|
-
};
|
|
3984
|
-
var isPeople = function isPeople(chain) {
|
|
3985
|
-
return chain === 'PeoplePolkadot' || chain === 'PeopleKusama';
|
|
3986
|
-
};
|
|
3987
|
-
var isSystemPara = function isSystemPara(chain) {
|
|
3988
|
-
return isAssetHub(chain) || isBridgeHub(chain) || isPeople(chain);
|
|
3989
|
-
};
|
|
3990
|
-
var mul = function mul(v, num) {
|
|
3991
|
-
var den = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1n;
|
|
3992
|
-
return v * num / den;
|
|
3993
|
-
};
|
|
3994
|
-
var padFee = function padFee(raw, origin, dest, side) {
|
|
3995
|
-
var relayOrigin = sdkCommon.isRelayChain(origin);
|
|
3996
|
-
var relayDest = sdkCommon.isRelayChain(dest);
|
|
3997
|
-
var sysParaOrigin = isSystemPara(origin);
|
|
3998
|
-
var sysParaDest = isSystemPara(dest);
|
|
3999
|
-
var relayToPara = relayOrigin && !relayDest;
|
|
4000
|
-
var sysParaToPara = sysParaOrigin && !sysParaDest;
|
|
4001
|
-
var paraToPara = !relayOrigin && !sysParaOrigin;
|
|
4002
|
-
if (sysParaToPara) return raw * 40n;
|
|
4003
|
-
if (relayToPara) return side === 'origin' ? mul(raw, 320n, 100n) : mul(raw, 3000n, 100n);
|
|
4004
|
-
if (paraToPara && side == 'origin' && origin === 'Mythos' && dest !== 'Ethereum') {
|
|
4005
|
-
return 150000000000000000n;
|
|
4006
|
-
}
|
|
4007
|
-
if (paraToPara) return mul(raw, 130n, 100n);
|
|
4008
|
-
// apply default 30% padding
|
|
4009
|
-
return mul(raw, 130n, 100n);
|
|
4010
|
-
};
|
|
4011
|
-
var padFeeBy = function padFeeBy(amount, percent) {
|
|
4012
|
-
return mul(amount, BigInt(100 + percent), 100n);
|
|
4013
|
-
};
|
|
4014
|
-
|
|
4015
|
-
var determineAddress = function determineAddress(chain, address, senderAddress) {
|
|
4016
|
-
if (assets.isChainEvm(chain)) {
|
|
4017
|
-
return viem.isAddress(address) ? address : senderAddress;
|
|
4018
|
-
}
|
|
4019
|
-
return viem.isAddress(address) ? senderAddress : address;
|
|
4020
|
-
};
|
|
4021
|
-
var getReverseTxFee = /*#__PURE__*/function () {
|
|
4022
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, currencyInput) {
|
|
4023
|
-
var api, origin, destination, senderAddress, address, currency, toAddress, fromAddress, tx, rawFee;
|
|
4092
|
+
var dryRun = /*#__PURE__*/function () {
|
|
4093
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
4094
|
+
var api, senderAddress, origin;
|
|
4024
4095
|
return _regenerator().w(function (_context) {
|
|
4025
|
-
while (1) switch (_context.n) {
|
|
4096
|
+
while (1) switch (_context.p = _context.n) {
|
|
4026
4097
|
case 0:
|
|
4027
|
-
api =
|
|
4028
|
-
|
|
4029
|
-
fromAddress = determineAddress(destination, address, senderAddress);
|
|
4098
|
+
api = options.api, senderAddress = options.senderAddress, origin = options.origin;
|
|
4099
|
+
validateAddress(senderAddress, origin, false);
|
|
4030
4100
|
_context.n = 1;
|
|
4031
|
-
return
|
|
4032
|
-
amount: currency.amount
|
|
4033
|
-
})).build();
|
|
4101
|
+
return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4034
4102
|
case 1:
|
|
4035
|
-
|
|
4103
|
+
_context.p = 1;
|
|
4036
4104
|
_context.n = 2;
|
|
4037
|
-
return
|
|
4105
|
+
return dryRunInternal(options);
|
|
4038
4106
|
case 2:
|
|
4039
|
-
|
|
4040
|
-
|
|
4107
|
+
return _context.a(2, _context.v);
|
|
4108
|
+
case 3:
|
|
4109
|
+
_context.p = 3;
|
|
4110
|
+
_context.n = 4;
|
|
4111
|
+
return api.disconnect();
|
|
4112
|
+
case 4:
|
|
4113
|
+
return _context.f(3);
|
|
4114
|
+
case 5:
|
|
4115
|
+
return _context.a(2);
|
|
4041
4116
|
}
|
|
4042
|
-
}, _callee);
|
|
4117
|
+
}, _callee, null, [[1,, 3, 5]]);
|
|
4043
4118
|
}));
|
|
4044
|
-
return function
|
|
4045
|
-
return
|
|
4119
|
+
return function dryRun(_x) {
|
|
4120
|
+
return _ref.apply(this, arguments);
|
|
4046
4121
|
};
|
|
4047
4122
|
}();
|
|
4048
4123
|
|
|
4049
|
-
var
|
|
4050
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(
|
|
4051
|
-
var
|
|
4124
|
+
var dryRunOrigin = /*#__PURE__*/function () {
|
|
4125
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
4126
|
+
var api, chain, address, result;
|
|
4052
4127
|
return _regenerator().w(function (_context) {
|
|
4053
|
-
while (1) switch (_context.n) {
|
|
4128
|
+
while (1) switch (_context.p = _context.n) {
|
|
4054
4129
|
case 0:
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
return _context.a(2, undefined);
|
|
4130
|
+
api = options.api, chain = options.chain, address = options.address;
|
|
4131
|
+
validateAddress(address, chain, false);
|
|
4132
|
+
_context.n = 1;
|
|
4133
|
+
return api.init(chain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4060
4134
|
case 1:
|
|
4061
|
-
|
|
4135
|
+
_context.p = 1;
|
|
4062
4136
|
_context.n = 2;
|
|
4063
|
-
return
|
|
4064
|
-
api: api,
|
|
4065
|
-
chain: origin,
|
|
4066
|
-
address: senderAddress
|
|
4067
|
-
});
|
|
4137
|
+
return api.getDryRunCall(options);
|
|
4068
4138
|
case 2:
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
isNativeAssetToDest = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(destination));
|
|
4072
|
-
if (!(isNativeAssetToOrigin && isNativeAssetToDest)) {
|
|
4139
|
+
result = _context.v;
|
|
4140
|
+
if (!result.success) {
|
|
4073
4141
|
_context.n = 3;
|
|
4074
4142
|
break;
|
|
4075
4143
|
}
|
|
4076
|
-
return _context.a(2,
|
|
4144
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, result), {}, {
|
|
4145
|
+
currency: assets.getNativeAssetSymbol(chain)
|
|
4146
|
+
}));
|
|
4077
4147
|
case 3:
|
|
4078
|
-
|
|
4079
|
-
_context.n = 5;
|
|
4080
|
-
break;
|
|
4081
|
-
}
|
|
4082
|
-
isSufficientNative = balanceNative - edNative - feeNative > 0n;
|
|
4083
|
-
_context.n = 4;
|
|
4084
|
-
return getAssetBalance({
|
|
4085
|
-
api: api,
|
|
4086
|
-
chain: origin,
|
|
4087
|
-
address: senderAddress,
|
|
4088
|
-
currency: currency
|
|
4089
|
-
});
|
|
4148
|
+
return _context.a(2, result);
|
|
4090
4149
|
case 4:
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
return _context.a(2, isSufficientNative && isSufficientAsset);
|
|
4150
|
+
_context.p = 4;
|
|
4151
|
+
_context.n = 5;
|
|
4152
|
+
return api.disconnect();
|
|
4095
4153
|
case 5:
|
|
4096
|
-
return _context.
|
|
4154
|
+
return _context.f(4);
|
|
4097
4155
|
case 6:
|
|
4098
4156
|
return _context.a(2);
|
|
4099
4157
|
}
|
|
4100
|
-
}, _callee);
|
|
4158
|
+
}, _callee, null, [[1,, 4, 6]]);
|
|
4101
4159
|
}));
|
|
4102
|
-
return function
|
|
4103
|
-
return _ref.apply(this, arguments);
|
|
4104
|
-
};
|
|
4105
|
-
}();
|
|
4106
|
-
var isSufficientDestination = /*#__PURE__*/function () {
|
|
4107
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, destination, address, amount, asset, feeNative) {
|
|
4108
|
-
var isNativeAsset, existentialDeposit, nativeBalance;
|
|
4109
|
-
return _regenerator().w(function (_context2) {
|
|
4110
|
-
while (1) switch (_context2.n) {
|
|
4111
|
-
case 0:
|
|
4112
|
-
isNativeAsset = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(destination));
|
|
4113
|
-
if (isNativeAsset) {
|
|
4114
|
-
_context2.n = 1;
|
|
4115
|
-
break;
|
|
4116
|
-
}
|
|
4117
|
-
return _context2.a(2, undefined);
|
|
4118
|
-
case 1:
|
|
4119
|
-
existentialDeposit = assets.getExistentialDepositOrThrow(destination);
|
|
4120
|
-
_context2.n = 2;
|
|
4121
|
-
return getBalanceNativeInternal({
|
|
4122
|
-
api: api,
|
|
4123
|
-
chain: destination,
|
|
4124
|
-
address: address
|
|
4125
|
-
});
|
|
4126
|
-
case 2:
|
|
4127
|
-
nativeBalance = _context2.v;
|
|
4128
|
-
return _context2.a(2, nativeBalance + amount - existentialDeposit - feeNative > 0n);
|
|
4129
|
-
}
|
|
4130
|
-
}, _callee2);
|
|
4131
|
-
}));
|
|
4132
|
-
return function isSufficientDestination(_x9, _x0, _x1, _x10, _x11, _x12) {
|
|
4133
|
-
return _ref2.apply(this, arguments);
|
|
4134
|
-
};
|
|
4135
|
-
}();
|
|
4136
|
-
|
|
4137
|
-
var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
4138
|
-
if (sdkCommon.isRelayChain(origin)) return DOT_LOCATION;
|
|
4139
|
-
return {
|
|
4140
|
-
parents: sdkCommon.isRelayChain(destination) ? sdkCommon.Parents.ZERO : sdkCommon.Parents.ONE,
|
|
4141
|
-
interior: {
|
|
4142
|
-
X1: [{
|
|
4143
|
-
Parachain: getParaId(origin)
|
|
4144
|
-
}]
|
|
4145
|
-
}
|
|
4146
|
-
};
|
|
4147
|
-
};
|
|
4148
|
-
var getDestXcmFee = /*#__PURE__*/function () {
|
|
4149
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
4150
|
-
var api, origin, hopChain, destination, currency, forwardedXcms, asset, address, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, _fee, sufficient, dryRunResult, _fee2, _sufficient, fee, newForwardedXcms, destParaId;
|
|
4151
|
-
return _regenerator().w(function (_context2) {
|
|
4152
|
-
while (1) switch (_context2.n) {
|
|
4153
|
-
case 0:
|
|
4154
|
-
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;
|
|
4155
|
-
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4156
|
-
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
4157
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
4158
|
-
var originAsset, _t;
|
|
4159
|
-
return _regenerator().w(function (_context) {
|
|
4160
|
-
while (1) switch (_context.p = _context.n) {
|
|
4161
|
-
case 0:
|
|
4162
|
-
if (!(destination === 'Ethereum')) {
|
|
4163
|
-
_context.n = 1;
|
|
4164
|
-
break;
|
|
4165
|
-
}
|
|
4166
|
-
return _context.a(2, 0n);
|
|
4167
|
-
case 1:
|
|
4168
|
-
originAsset = assets.findAssetInfoOrThrow(origin, currency, destination);
|
|
4169
|
-
if (!originAsset.location) {
|
|
4170
|
-
_context.n = 7;
|
|
4171
|
-
break;
|
|
4172
|
-
}
|
|
4173
|
-
_context.p = 2;
|
|
4174
|
-
_context.n = 3;
|
|
4175
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4176
|
-
destination: destination
|
|
4177
|
-
}), {
|
|
4178
|
-
location: originAsset.location
|
|
4179
|
-
});
|
|
4180
|
-
case 3:
|
|
4181
|
-
return _context.a(2, _context.v);
|
|
4182
|
-
case 4:
|
|
4183
|
-
_context.p = 4;
|
|
4184
|
-
_t = _context.v;
|
|
4185
|
-
if (!(_t instanceof assets.InvalidCurrencyError)) {
|
|
4186
|
-
_context.n = 6;
|
|
4187
|
-
break;
|
|
4188
|
-
}
|
|
4189
|
-
_context.n = 5;
|
|
4190
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4191
|
-
destination: destination
|
|
4192
|
-
}), {
|
|
4193
|
-
symbol: originAsset.symbol
|
|
4194
|
-
});
|
|
4195
|
-
case 5:
|
|
4196
|
-
return _context.a(2, _context.v);
|
|
4197
|
-
case 6:
|
|
4198
|
-
throw _t;
|
|
4199
|
-
case 7:
|
|
4200
|
-
_context.n = 8;
|
|
4201
|
-
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
4202
|
-
destination: destination
|
|
4203
|
-
}), {
|
|
4204
|
-
symbol: originAsset.symbol
|
|
4205
|
-
});
|
|
4206
|
-
case 8:
|
|
4207
|
-
return _context.a(2, _context.v);
|
|
4208
|
-
}
|
|
4209
|
-
}, _callee, null, [[2, 4]]);
|
|
4210
|
-
}));
|
|
4211
|
-
return function calcPaymentInfoFee() {
|
|
4212
|
-
return _ref2.apply(this, arguments);
|
|
4213
|
-
};
|
|
4214
|
-
}();
|
|
4215
|
-
if (!(!assets.hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
|
|
4216
|
-
_context2.n = 3;
|
|
4217
|
-
break;
|
|
4218
|
-
}
|
|
4219
|
-
_context2.n = 1;
|
|
4220
|
-
return calcPaymentInfoFee();
|
|
4221
|
-
case 1:
|
|
4222
|
-
_fee = _context2.v;
|
|
4223
|
-
_context2.n = 2;
|
|
4224
|
-
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee);
|
|
4225
|
-
case 2:
|
|
4226
|
-
sufficient = _context2.v;
|
|
4227
|
-
return _context2.a(2, {
|
|
4228
|
-
fee: _fee,
|
|
4229
|
-
feeType: 'paymentInfo',
|
|
4230
|
-
sufficient: sufficient
|
|
4231
|
-
});
|
|
4232
|
-
case 3:
|
|
4233
|
-
_context2.n = 4;
|
|
4234
|
-
return api.getDryRunXcm({
|
|
4235
|
-
originLocation: addXcmVersionHeader(createOriginLocation(hopChain, destination), sdkCommon.Version.V4),
|
|
4236
|
-
xcm: forwardedXcms[1][0],
|
|
4237
|
-
chain: destination,
|
|
4238
|
-
origin: origin,
|
|
4239
|
-
asset: asset,
|
|
4240
|
-
originFee: originFee,
|
|
4241
|
-
feeAsset: resolvedFeeAsset,
|
|
4242
|
-
amount: BigInt(currency.amount) < 2n ? 2n : BigInt(currency.amount)
|
|
4243
|
-
});
|
|
4244
|
-
case 4:
|
|
4245
|
-
dryRunResult = _context2.v;
|
|
4246
|
-
if (dryRunResult.success) {
|
|
4247
|
-
_context2.n = 8;
|
|
4248
|
-
break;
|
|
4249
|
-
}
|
|
4250
|
-
if (!disableFallback) {
|
|
4251
|
-
_context2.n = 5;
|
|
4252
|
-
break;
|
|
4253
|
-
}
|
|
4254
|
-
return _context2.a(2, {
|
|
4255
|
-
dryRunError: dryRunResult.failureReason
|
|
4256
|
-
});
|
|
4257
|
-
case 5:
|
|
4258
|
-
_context2.n = 6;
|
|
4259
|
-
return calcPaymentInfoFee();
|
|
4260
|
-
case 6:
|
|
4261
|
-
_fee2 = _context2.v;
|
|
4262
|
-
_context2.n = 7;
|
|
4263
|
-
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee2);
|
|
4264
|
-
case 7:
|
|
4265
|
-
_sufficient = _context2.v;
|
|
4266
|
-
return _context2.a(2, {
|
|
4267
|
-
fee: _fee2,
|
|
4268
|
-
feeType: 'paymentInfo',
|
|
4269
|
-
dryRunError: dryRunResult.failureReason,
|
|
4270
|
-
sufficient: _sufficient
|
|
4271
|
-
});
|
|
4272
|
-
case 8:
|
|
4273
|
-
fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
4274
|
-
return _context2.a(2, {
|
|
4275
|
-
fee: fee,
|
|
4276
|
-
feeType: 'dryRun',
|
|
4277
|
-
sufficient: true,
|
|
4278
|
-
forwardedXcms: newForwardedXcms,
|
|
4279
|
-
destParaId: destParaId
|
|
4280
|
-
});
|
|
4281
|
-
}
|
|
4282
|
-
}, _callee2);
|
|
4283
|
-
}));
|
|
4284
|
-
return function getDestXcmFee(_x) {
|
|
4160
|
+
return function dryRunOrigin(_x) {
|
|
4285
4161
|
return _ref.apply(this, arguments);
|
|
4286
4162
|
};
|
|
4287
4163
|
}();
|
|
@@ -5016,287 +4892,332 @@ var addEthereumBridgeFees = /*#__PURE__*/function () {
|
|
|
5016
4892
|
};
|
|
5017
4893
|
}();
|
|
5018
4894
|
|
|
5019
|
-
var
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
4895
|
+
var AssetManagerPallet = /*#__PURE__*/function () {
|
|
4896
|
+
function AssetManagerPallet() {
|
|
4897
|
+
_classCallCheck(this, AssetManagerPallet);
|
|
4898
|
+
}
|
|
4899
|
+
return _createClass(AssetManagerPallet, [{
|
|
4900
|
+
key: "setBalance",
|
|
4901
|
+
value: function setBalance(address, asset) {
|
|
4902
|
+
assertHasId(asset);
|
|
4903
|
+
var assetId = asset.assetId,
|
|
4904
|
+
amount = asset.amount;
|
|
4905
|
+
return Promise.resolve({
|
|
4906
|
+
balanceTx: {
|
|
4907
|
+
module: 'AssetManager',
|
|
4908
|
+
method: 'updateBalance',
|
|
4909
|
+
parameters: {
|
|
4910
|
+
who: {
|
|
4911
|
+
Id: address
|
|
4912
|
+
},
|
|
4913
|
+
currency_id: {
|
|
4914
|
+
ForeignAsset: assetId
|
|
4915
|
+
},
|
|
4916
|
+
amount: amount
|
|
4917
|
+
}
|
|
4918
|
+
}
|
|
4919
|
+
});
|
|
4920
|
+
}
|
|
4921
|
+
}]);
|
|
4922
|
+
}();
|
|
4923
|
+
|
|
4924
|
+
var BalancesPallet = /*#__PURE__*/function () {
|
|
4925
|
+
function BalancesPallet() {
|
|
4926
|
+
_classCallCheck(this, BalancesPallet);
|
|
4927
|
+
}
|
|
4928
|
+
return _createClass(BalancesPallet, [{
|
|
4929
|
+
key: "setBalance",
|
|
4930
|
+
value: function setBalance(address, assetInfo, chain) {
|
|
4931
|
+
var amount = assetInfo.amount;
|
|
4932
|
+
var notUseId = chain.startsWith('Hydration') || chain === 'Basilisk' || assets.isChainEvm(chain);
|
|
4933
|
+
return Promise.resolve({
|
|
4934
|
+
balanceTx: {
|
|
4935
|
+
module: 'Balances',
|
|
4936
|
+
method: 'force_set_balance',
|
|
4937
|
+
parameters: {
|
|
4938
|
+
who: notUseId ? address : {
|
|
4939
|
+
Id: address
|
|
4940
|
+
},
|
|
4941
|
+
new_free: amount
|
|
4942
|
+
}
|
|
4943
|
+
}
|
|
4944
|
+
});
|
|
5029
4945
|
}
|
|
4946
|
+
}]);
|
|
4947
|
+
}();
|
|
4948
|
+
|
|
4949
|
+
var CurrenciesPallet = /*#__PURE__*/function () {
|
|
4950
|
+
function CurrenciesPallet() {
|
|
4951
|
+
_classCallCheck(this, CurrenciesPallet);
|
|
5030
4952
|
}
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
var
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
4953
|
+
return _createClass(CurrenciesPallet, [{
|
|
4954
|
+
key: "setBalance",
|
|
4955
|
+
value: function setBalance(address, assetInfo) {
|
|
4956
|
+
assertHasId(assetInfo);
|
|
4957
|
+
var assetId = assetInfo.assetId,
|
|
4958
|
+
amount = assetInfo.amount;
|
|
4959
|
+
return Promise.resolve({
|
|
4960
|
+
balanceTx: {
|
|
4961
|
+
module: 'Currencies',
|
|
4962
|
+
method: 'update_balance',
|
|
4963
|
+
parameters: {
|
|
4964
|
+
who: address,
|
|
4965
|
+
currency_id: Number(assetId),
|
|
4966
|
+
amount: amount
|
|
4967
|
+
}
|
|
4968
|
+
}
|
|
4969
|
+
});
|
|
5042
4970
|
}
|
|
5043
|
-
}
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
4971
|
+
}]);
|
|
4972
|
+
}();
|
|
4973
|
+
|
|
4974
|
+
var ForeignAssetsPallet = /*#__PURE__*/function () {
|
|
4975
|
+
function ForeignAssetsPallet() {
|
|
4976
|
+
_classCallCheck(this, ForeignAssetsPallet);
|
|
5047
4977
|
}
|
|
5048
|
-
return {
|
|
4978
|
+
return _createClass(ForeignAssetsPallet, [{
|
|
4979
|
+
key: "setBalance",
|
|
4980
|
+
value: function setBalance(address, asset) {
|
|
4981
|
+
assertHasLocation(asset);
|
|
4982
|
+
var location = asset.location,
|
|
4983
|
+
amount = asset.amount;
|
|
4984
|
+
return Promise.resolve({
|
|
4985
|
+
assetStatusTx: {
|
|
4986
|
+
module: 'ForeignAssets',
|
|
4987
|
+
method: 'force_asset_status',
|
|
4988
|
+
parameters: {
|
|
4989
|
+
id: location,
|
|
4990
|
+
owner: {
|
|
4991
|
+
Id: address
|
|
4992
|
+
},
|
|
4993
|
+
issuer: {
|
|
4994
|
+
Id: address
|
|
4995
|
+
},
|
|
4996
|
+
admin: {
|
|
4997
|
+
Id: address
|
|
4998
|
+
},
|
|
4999
|
+
freezer: {
|
|
5000
|
+
Id: address
|
|
5001
|
+
},
|
|
5002
|
+
min_balance: 0n,
|
|
5003
|
+
is_sufficient: true,
|
|
5004
|
+
is_frozen: false
|
|
5005
|
+
}
|
|
5006
|
+
},
|
|
5007
|
+
balanceTx: {
|
|
5008
|
+
module: 'ForeignAssets',
|
|
5009
|
+
method: 'mint',
|
|
5010
|
+
parameters: {
|
|
5011
|
+
id: location,
|
|
5012
|
+
beneficiary: {
|
|
5013
|
+
Id: address
|
|
5014
|
+
},
|
|
5015
|
+
amount: amount
|
|
5016
|
+
}
|
|
5017
|
+
}
|
|
5018
|
+
});
|
|
5019
|
+
}
|
|
5020
|
+
}]);
|
|
5021
|
+
}();
|
|
5022
|
+
|
|
5023
|
+
var SIZE = 32;
|
|
5024
|
+
var BALANCE_SLOT = 0;
|
|
5025
|
+
var calculateMappingSlot = function calculateMappingSlot(key) {
|
|
5026
|
+
var normalizedKey = viem.getAddress(key);
|
|
5027
|
+
var keyPadded = viem.pad(normalizedKey, {
|
|
5028
|
+
size: SIZE
|
|
5029
|
+
});
|
|
5030
|
+
var slotHex = viem.pad(viem.toHex(BALANCE_SLOT), {
|
|
5031
|
+
size: SIZE
|
|
5032
|
+
});
|
|
5033
|
+
var encoded = viem.concat([keyPadded, slotHex]);
|
|
5034
|
+
return viem.keccak256(encoded);
|
|
5049
5035
|
};
|
|
5050
|
-
var
|
|
5051
|
-
|
|
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
|
-
case 2:
|
|
5081
|
-
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
5082
|
-
processHop = /*#__PURE__*/function () {
|
|
5083
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
5084
|
-
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, isDestination, hopDryRun, hopCurrency;
|
|
5085
|
-
return _regenerator().w(function (_context) {
|
|
5086
|
-
while (1) switch (_context.n) {
|
|
5087
|
-
case 0:
|
|
5088
|
-
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange, isDestination = params.isDestination;
|
|
5089
|
-
if (assets.hasDryRunSupport(currentChain)) {
|
|
5090
|
-
_context.n = 1;
|
|
5091
|
-
break;
|
|
5092
|
-
}
|
|
5093
|
-
return _context.a(2, {
|
|
5094
|
-
success: false,
|
|
5095
|
-
failureReason: "DryRunApi is not available on chain ".concat(currentChain)
|
|
5096
|
-
});
|
|
5097
|
-
case 1:
|
|
5098
|
-
_context.n = 2;
|
|
5099
|
-
return hopApi.getDryRunXcm({
|
|
5100
|
-
originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain), sdkCommon.Version.V4),
|
|
5101
|
-
xcm: forwardedXcms[1][0],
|
|
5102
|
-
chain: currentChain,
|
|
5103
|
-
origin: currentOrigin,
|
|
5104
|
-
asset: currentAsset,
|
|
5105
|
-
feeAsset: resolvedFeeAsset,
|
|
5106
|
-
originFee: originDryRun.fee,
|
|
5107
|
-
amount: amount
|
|
5108
|
-
});
|
|
5109
|
-
case 2:
|
|
5110
|
-
hopDryRun = _context.v;
|
|
5111
|
-
if (!hopDryRun.success) {
|
|
5112
|
-
_context.n = 3;
|
|
5113
|
-
break;
|
|
5114
|
-
}
|
|
5115
|
-
if (destination === 'Ethereum' && (currentChain.includes('AssetHub') || currentChain.includes('BridgeHub'))) {
|
|
5116
|
-
hopCurrency = assets.getNativeAssetSymbol(currentChain);
|
|
5117
|
-
} else if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
|
|
5118
|
-
hopCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo).symbol;
|
|
5119
|
-
} else if (isDestination) {
|
|
5120
|
-
hopCurrency = assets.findAssetOnDestOrThrow(origin, currentChain, currency).symbol;
|
|
5121
|
-
} else {
|
|
5122
|
-
hopCurrency = asset.symbol;
|
|
5123
|
-
}
|
|
5124
|
-
return _context.a(2, _objectSpread2(_objectSpread2({}, hopDryRun), {}, {
|
|
5125
|
-
currency: hopCurrency
|
|
5126
|
-
}));
|
|
5127
|
-
case 3:
|
|
5128
|
-
return _context.a(2, hopDryRun);
|
|
5036
|
+
var SystemPallet = /*#__PURE__*/function () {
|
|
5037
|
+
function SystemPallet() {
|
|
5038
|
+
_classCallCheck(this, SystemPallet);
|
|
5039
|
+
}
|
|
5040
|
+
return _createClass(SystemPallet, [{
|
|
5041
|
+
key: "setBalance",
|
|
5042
|
+
value: function () {
|
|
5043
|
+
var _setBalance = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(address, assetInfo, _chain, api) {
|
|
5044
|
+
var contractAddr, slot, amountEncoded, storageKey;
|
|
5045
|
+
return _regenerator().w(function (_context) {
|
|
5046
|
+
while (1) switch (_context.n) {
|
|
5047
|
+
case 0:
|
|
5048
|
+
assertHasId(assetInfo);
|
|
5049
|
+
contractAddr = formatAssetIdToERC20(assetInfo.assetId);
|
|
5050
|
+
slot = calculateMappingSlot(address);
|
|
5051
|
+
amountEncoded = viem.pad(viem.toHex(assetInfo.amount), {
|
|
5052
|
+
size: SIZE
|
|
5053
|
+
});
|
|
5054
|
+
_context.n = 1;
|
|
5055
|
+
return api.getEvmStorage(contractAddr, slot);
|
|
5056
|
+
case 1:
|
|
5057
|
+
storageKey = _context.v;
|
|
5058
|
+
return _context.a(2, {
|
|
5059
|
+
balanceTx: {
|
|
5060
|
+
module: 'System',
|
|
5061
|
+
method: 'set_storage',
|
|
5062
|
+
parameters: {
|
|
5063
|
+
items: [[storageKey, amountEncoded]]
|
|
5064
|
+
}
|
|
5129
5065
|
}
|
|
5130
|
-
}, _callee);
|
|
5131
|
-
}));
|
|
5132
|
-
return function processHop(_x2) {
|
|
5133
|
-
return _ref2.apply(this, arguments);
|
|
5134
|
-
};
|
|
5135
|
-
}();
|
|
5136
|
-
_context2.n = 3;
|
|
5137
|
-
return traverseXcmHops({
|
|
5138
|
-
api: api,
|
|
5139
|
-
origin: origin,
|
|
5140
|
-
destination: destination,
|
|
5141
|
-
currency: currency,
|
|
5142
|
-
initialForwardedXcms: initialForwardedXcms,
|
|
5143
|
-
initialDestParaId: initialDestParaId,
|
|
5144
|
-
swapConfig: swapConfig,
|
|
5145
|
-
processHop: processHop,
|
|
5146
|
-
shouldContinue: function shouldContinue(hopResult) {
|
|
5147
|
-
return hopResult.success;
|
|
5148
|
-
},
|
|
5149
|
-
extractNextHopData: function extractNextHopData(hopResult) {
|
|
5150
|
-
return {
|
|
5151
|
-
forwardedXcms: hopResult.success ? hopResult.forwardedXcms : undefined,
|
|
5152
|
-
destParaId: hopResult.success ? hopResult.destParaId : undefined
|
|
5153
|
-
};
|
|
5154
|
-
}
|
|
5155
|
-
});
|
|
5156
|
-
case 3:
|
|
5157
|
-
traversalResult = _context2.v;
|
|
5158
|
-
// Process Ethereum bridge fees
|
|
5159
|
-
assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
|
|
5160
|
-
bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
|
|
5161
|
-
if (!((_traversalResult$brid = traversalResult.bridgeHub) !== null && _traversalResult$brid !== void 0 && _traversalResult$brid.success)) {
|
|
5162
|
-
_context2.n = 5;
|
|
5163
|
-
break;
|
|
5164
|
-
}
|
|
5165
|
-
_context2.n = 4;
|
|
5166
|
-
return addEthereumBridgeFees(api, traversalResult.bridgeHub, destination, assetHubChain);
|
|
5167
|
-
case 4:
|
|
5168
|
-
_t = _context2.v;
|
|
5169
|
-
_context2.n = 6;
|
|
5170
|
-
break;
|
|
5171
|
-
case 5:
|
|
5172
|
-
_t = traversalResult.bridgeHub;
|
|
5173
|
-
case 6:
|
|
5174
|
-
processedBridgeHub = _t;
|
|
5175
|
-
// Update bridge hub in hops if needed
|
|
5176
|
-
if (processedBridgeHub && processedBridgeHub.success && traversalResult.bridgeHub && traversalResult.bridgeHub.success && processedBridgeHub.fee !== traversalResult.bridgeHub.fee) {
|
|
5177
|
-
bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
|
|
5178
|
-
return hop.chain === bridgeHubChain;
|
|
5179
|
-
});
|
|
5180
|
-
if (bridgeHubHopIndex !== -1 && traversalResult.hops[bridgeHubHopIndex].result.success) {
|
|
5181
|
-
traversalResult.hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, traversalResult.hops[bridgeHubHopIndex].result), {}, {
|
|
5182
|
-
fee: processedBridgeHub.fee
|
|
5183
5066
|
});
|
|
5184
|
-
}
|
|
5185
5067
|
}
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(assetHubChain)
|
|
5191
|
-
}) : traversalResult.assetHub;
|
|
5192
|
-
bridgeHubWithCurrency = processedBridgeHub !== null && processedBridgeHub !== void 0 && processedBridgeHub.success ? _objectSpread2(_objectSpread2({}, processedBridgeHub), {}, {
|
|
5193
|
-
currency: assets.getNativeAssetSymbol(bridgeHubChain)
|
|
5194
|
-
}) : processedBridgeHub;
|
|
5195
|
-
destinationWithCurrency = (_traversalResult$dest = traversalResult.destination) !== null && _traversalResult$dest !== void 0 && _traversalResult$dest.success ? _objectSpread2(_objectSpread2({}, traversalResult.destination), {}, {
|
|
5196
|
-
currency: asset === null || asset === void 0 ? void 0 : asset.symbol
|
|
5197
|
-
}) : traversalResult.destination;
|
|
5198
|
-
_getFailureInfo = getFailureInfo$1({
|
|
5199
|
-
destination: destinationWithCurrency,
|
|
5200
|
-
assetHub: assetHubWithCurrency,
|
|
5201
|
-
bridgeHub: bridgeHubWithCurrency
|
|
5202
|
-
}, traversalResult.hops), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
|
|
5203
|
-
return _context2.a(2, {
|
|
5204
|
-
failureReason: failureReason,
|
|
5205
|
-
failureChain: failureChain,
|
|
5206
|
-
origin: originWithCurrency,
|
|
5207
|
-
assetHub: assetHubWithCurrency,
|
|
5208
|
-
bridgeHub: bridgeHubWithCurrency,
|
|
5209
|
-
destination: destinationWithCurrency,
|
|
5210
|
-
hops: traversalResult.hops
|
|
5211
|
-
});
|
|
5068
|
+
}, _callee);
|
|
5069
|
+
}));
|
|
5070
|
+
function setBalance(_x, _x2, _x3, _x4) {
|
|
5071
|
+
return _setBalance.apply(this, arguments);
|
|
5212
5072
|
}
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
return _ref.apply(this, arguments);
|
|
5217
|
-
};
|
|
5073
|
+
return setBalance;
|
|
5074
|
+
}()
|
|
5075
|
+
}]);
|
|
5218
5076
|
}();
|
|
5219
5077
|
|
|
5220
|
-
var
|
|
5221
|
-
|
|
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
|
-
return function dryRun(_x) {
|
|
5248
|
-
return _ref.apply(this, arguments);
|
|
5249
|
-
};
|
|
5078
|
+
var TokensPallet = /*#__PURE__*/function () {
|
|
5079
|
+
function TokensPallet() {
|
|
5080
|
+
_classCallCheck(this, TokensPallet);
|
|
5081
|
+
}
|
|
5082
|
+
return _createClass(TokensPallet, [{
|
|
5083
|
+
key: "setBalance",
|
|
5084
|
+
value: function setBalance(address, asset, chain) {
|
|
5085
|
+
var isBifrost = chain.startsWith('Bifrost');
|
|
5086
|
+
if (!isBifrost) assertHasId(asset);
|
|
5087
|
+
var id = isBifrost ? getChain('BifrostPolkadot').getCurrencySelection(asset) : (assertHasId(asset), asset.assetId);
|
|
5088
|
+
var amount = asset.amount;
|
|
5089
|
+
return Promise.resolve({
|
|
5090
|
+
balanceTx: {
|
|
5091
|
+
module: 'Tokens',
|
|
5092
|
+
method: 'set_balance',
|
|
5093
|
+
parameters: {
|
|
5094
|
+
who: {
|
|
5095
|
+
Id: address
|
|
5096
|
+
},
|
|
5097
|
+
currency_id: id,
|
|
5098
|
+
new_free: amount,
|
|
5099
|
+
new_reserved: 0n
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
});
|
|
5103
|
+
}
|
|
5104
|
+
}]);
|
|
5250
5105
|
}();
|
|
5251
5106
|
|
|
5252
|
-
var
|
|
5253
|
-
|
|
5254
|
-
|
|
5107
|
+
var palletRegistry = {
|
|
5108
|
+
Balances: BalancesPallet,
|
|
5109
|
+
Tokens: TokensPallet,
|
|
5110
|
+
Currencies: CurrenciesPallet,
|
|
5111
|
+
Assets: AssetsPallet,
|
|
5112
|
+
ForeignAssets: ForeignAssetsPallet,
|
|
5113
|
+
AssetManager: AssetManagerPallet,
|
|
5114
|
+
System: SystemPallet
|
|
5115
|
+
};
|
|
5116
|
+
var getPalletInstance = function getPalletInstance(type) {
|
|
5117
|
+
var HandlerClass = palletRegistry[type];
|
|
5118
|
+
return new HandlerClass();
|
|
5119
|
+
};
|
|
5120
|
+
|
|
5121
|
+
var MINT_AMOUNT = 1000n; // Mint 1000 units of asset
|
|
5122
|
+
var pickOtherPallet = function pickOtherPallet(asset, pallets) {
|
|
5123
|
+
if (assets.isForeignAsset(asset) && asset.assetId === undefined) {
|
|
5124
|
+
var _pallets$find;
|
|
5125
|
+
// No assetId means it's probably a ForeignAssets pallet asset
|
|
5126
|
+
return (_pallets$find = pallets.find(function (pallet) {
|
|
5127
|
+
return pallet.startsWith('Foreign');
|
|
5128
|
+
})) !== null && _pallets$find !== void 0 ? _pallets$find : pallets[0];
|
|
5129
|
+
}
|
|
5130
|
+
return pallets[0];
|
|
5131
|
+
};
|
|
5132
|
+
var createMintTxs = function createMintTxs(chain, asset, address, api) {
|
|
5133
|
+
var nativePallet = pallets.getNativeAssetsPallet(chain);
|
|
5134
|
+
var otherPallets = pallets.getOtherAssetsPallets(chain);
|
|
5135
|
+
var isMainNativeAsset = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(chain));
|
|
5136
|
+
var pallet = assets.isForeignAsset(asset) || !isMainNativeAsset ? pickOtherPallet(asset, otherPallets) : nativePallet;
|
|
5137
|
+
var palletInstance = getPalletInstance(pallet);
|
|
5138
|
+
return palletInstance.setBalance(address, asset, chain, api);
|
|
5139
|
+
};
|
|
5140
|
+
var createRequiredMintTxs = function createRequiredMintTxs(chain, currency, amountHuman, address, api) {
|
|
5141
|
+
var asset = assets.findAssetInfoOrThrow(chain, currency, null);
|
|
5142
|
+
var amount = viem.parseUnits(amountHuman.toString(), asset.decimals);
|
|
5143
|
+
return createMintTxs(chain, _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5144
|
+
amount: amount
|
|
5145
|
+
}), address, api);
|
|
5146
|
+
};
|
|
5147
|
+
var createOptionalMintTxs = function createOptionalMintTxs(chain, currency, amountHuman, address, api) {
|
|
5148
|
+
var asset = assets.findAssetInfo(chain, currency, null);
|
|
5149
|
+
if (!asset) return null;
|
|
5150
|
+
var amount = viem.parseUnits(amountHuman.toString(), asset.decimals);
|
|
5151
|
+
return createMintTxs(chain, _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5152
|
+
amount: amount
|
|
5153
|
+
}), address, api);
|
|
5154
|
+
};
|
|
5155
|
+
var resultToExtrinsics = function resultToExtrinsics(api, address, _ref) {
|
|
5156
|
+
var assetStatusTx = _ref.assetStatusTx,
|
|
5157
|
+
balanceTx = _ref.balanceTx;
|
|
5158
|
+
return [].concat(_toConsumableArray(assetStatusTx ? [api.callTxMethod(assetStatusTx)] : []), _toConsumableArray(assetStatusTx ? [api.callDispatchAsMethod(api.callTxMethod(balanceTx), address)] : [api.callTxMethod(balanceTx)]));
|
|
5159
|
+
};
|
|
5160
|
+
var wrapTxBypass = /*#__PURE__*/function () {
|
|
5161
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, chain, asset, feeAsset, address, tx) {
|
|
5162
|
+
var mintNativeAssetRes, mintRelayAssetRes, mintFeeAssetRes, amount, mintAmount, mintAssetRes;
|
|
5255
5163
|
return _regenerator().w(function (_context) {
|
|
5256
|
-
while (1) switch (_context.
|
|
5164
|
+
while (1) switch (_context.n) {
|
|
5257
5165
|
case 0:
|
|
5258
|
-
api = options.api, chain = options.chain, address = options.address;
|
|
5259
|
-
validateAddress(address, chain, false);
|
|
5260
5166
|
_context.n = 1;
|
|
5261
|
-
return
|
|
5167
|
+
return createRequiredMintTxs(chain, {
|
|
5168
|
+
symbol: assets.Native(assets.getNativeAssetSymbol(chain))
|
|
5169
|
+
}, MINT_AMOUNT, address, api);
|
|
5262
5170
|
case 1:
|
|
5263
|
-
|
|
5171
|
+
mintNativeAssetRes = _context.v;
|
|
5264
5172
|
_context.n = 2;
|
|
5265
|
-
return
|
|
5173
|
+
return createOptionalMintTxs(chain, {
|
|
5174
|
+
location: {
|
|
5175
|
+
parents: sdkCommon.Parents.ONE,
|
|
5176
|
+
interior: {
|
|
5177
|
+
Here: null
|
|
5178
|
+
}
|
|
5179
|
+
}
|
|
5180
|
+
}, MINT_AMOUNT, address, api);
|
|
5266
5181
|
case 2:
|
|
5267
|
-
|
|
5268
|
-
if (!
|
|
5269
|
-
_context.n =
|
|
5182
|
+
mintRelayAssetRes = _context.v;
|
|
5183
|
+
if (!feeAsset) {
|
|
5184
|
+
_context.n = 4;
|
|
5270
5185
|
break;
|
|
5271
5186
|
}
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
})
|
|
5187
|
+
amount = viem.parseUnits(MINT_AMOUNT.toString(), feeAsset.decimals);
|
|
5188
|
+
_context.n = 3;
|
|
5189
|
+
return createMintTxs(chain, _objectSpread2(_objectSpread2({}, feeAsset), {}, {
|
|
5190
|
+
amount: amount
|
|
5191
|
+
}), address, api);
|
|
5275
5192
|
case 3:
|
|
5276
|
-
|
|
5193
|
+
mintFeeAssetRes = _context.v;
|
|
5277
5194
|
case 4:
|
|
5278
|
-
|
|
5195
|
+
// mint asset that is being sent
|
|
5196
|
+
mintAmount = viem.parseUnits(MINT_AMOUNT.toString(), asset.decimals);
|
|
5279
5197
|
_context.n = 5;
|
|
5280
|
-
return
|
|
5198
|
+
return createMintTxs(chain, _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5199
|
+
amount: asset.amount + mintAmount
|
|
5200
|
+
}), address, api);
|
|
5281
5201
|
case 5:
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5202
|
+
mintAssetRes = _context.v;
|
|
5203
|
+
return _context.a(2, api.callBatchMethod([].concat(_toConsumableArray([mintNativeAssetRes, mintRelayAssetRes, mintFeeAssetRes, mintAssetRes].flatMap(function (tx) {
|
|
5204
|
+
return tx ? resultToExtrinsics(api, address, tx) : [];
|
|
5205
|
+
})), [api.callDispatchAsMethod(tx, address)]), exports.BatchMode.BATCH_ALL));
|
|
5285
5206
|
}
|
|
5286
|
-
}, _callee
|
|
5207
|
+
}, _callee);
|
|
5287
5208
|
}));
|
|
5288
|
-
return function
|
|
5289
|
-
return
|
|
5209
|
+
return function wrapTxBypass(_x, _x2, _x3, _x4, _x5, _x6) {
|
|
5210
|
+
return _ref2.apply(this, arguments);
|
|
5290
5211
|
};
|
|
5291
5212
|
}();
|
|
5292
5213
|
|
|
5293
|
-
var
|
|
5214
|
+
var getOriginXcmFeeInternal = /*#__PURE__*/function () {
|
|
5294
5215
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
5295
|
-
var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, asset, amount, resolvedFeeAsset, nativeAssetSymbol, rawFee, paddedFee, sufficient, dryRunResult, _rawFee, _paddedFee,
|
|
5216
|
+
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;
|
|
5296
5217
|
return _regenerator().w(function (_context) {
|
|
5297
5218
|
while (1) switch (_context.n) {
|
|
5298
5219
|
case 0:
|
|
5299
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback, feeAsset = _ref.feeAsset, currency = _ref.currency;
|
|
5220
|
+
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;
|
|
5300
5221
|
asset = assets.findAssetInfoOrThrow(origin, currency, destination);
|
|
5301
5222
|
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
5302
5223
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
@@ -5331,12 +5252,17 @@ var getOriginXcmFee = /*#__PURE__*/function () {
|
|
|
5331
5252
|
tx: tx,
|
|
5332
5253
|
chain: origin,
|
|
5333
5254
|
address: senderAddress,
|
|
5334
|
-
|
|
5255
|
+
asset: _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
5256
|
+
amount: amount
|
|
5257
|
+
}),
|
|
5258
|
+
feeAsset: resolvedFeeAsset,
|
|
5259
|
+
// Force dryRun pass
|
|
5260
|
+
useRootOrigin: useRootOrigin
|
|
5335
5261
|
});
|
|
5336
5262
|
case 5:
|
|
5337
5263
|
dryRunResult = _context.v;
|
|
5338
5264
|
if (dryRunResult.success) {
|
|
5339
|
-
_context.n =
|
|
5265
|
+
_context.n = 8;
|
|
5340
5266
|
break;
|
|
5341
5267
|
}
|
|
5342
5268
|
if (!disableFallback) {
|
|
@@ -5352,20 +5278,14 @@ var getOriginXcmFee = /*#__PURE__*/function () {
|
|
|
5352
5278
|
case 7:
|
|
5353
5279
|
_rawFee = _context.v;
|
|
5354
5280
|
_paddedFee = padFee(_rawFee, origin, destination, 'origin');
|
|
5355
|
-
_context.n = 8;
|
|
5356
|
-
return isSufficientOrigin(api, origin, destination, senderAddress, _paddedFee, _objectSpread2(_objectSpread2({}, currency), {}, {
|
|
5357
|
-
amount: amount
|
|
5358
|
-
}), asset, resolvedFeeAsset);
|
|
5359
|
-
case 8:
|
|
5360
|
-
_sufficient = _context.v;
|
|
5361
5281
|
return _context.a(2, {
|
|
5362
5282
|
fee: _paddedFee,
|
|
5363
5283
|
currency: nativeAssetSymbol,
|
|
5364
5284
|
feeType: 'paymentInfo',
|
|
5365
5285
|
dryRunError: dryRunResult.failureReason,
|
|
5366
|
-
sufficient:
|
|
5286
|
+
sufficient: false
|
|
5367
5287
|
});
|
|
5368
|
-
case
|
|
5288
|
+
case 8:
|
|
5369
5289
|
fee = dryRunResult.fee, forwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId, weight = dryRunResult.weight;
|
|
5370
5290
|
currencySymbol = resolvedFeeAsset ? resolvedFeeAsset.symbol : nativeAssetSymbol;
|
|
5371
5291
|
return _context.a(2, {
|
|
@@ -5380,11 +5300,40 @@ var getOriginXcmFee = /*#__PURE__*/function () {
|
|
|
5380
5300
|
}
|
|
5381
5301
|
}, _callee);
|
|
5382
5302
|
}));
|
|
5383
|
-
return function
|
|
5303
|
+
return function getOriginXcmFeeInternal(_x) {
|
|
5384
5304
|
return _ref2.apply(this, arguments);
|
|
5385
5305
|
};
|
|
5386
5306
|
}();
|
|
5387
5307
|
|
|
5308
|
+
var getOriginXcmFee = /*#__PURE__*/function () {
|
|
5309
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
5310
|
+
var forced, real;
|
|
5311
|
+
return _regenerator().w(function (_context) {
|
|
5312
|
+
while (1) switch (_context.n) {
|
|
5313
|
+
case 0:
|
|
5314
|
+
_context.n = 1;
|
|
5315
|
+
return getOriginXcmFeeInternal(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
5316
|
+
useRootOrigin: true
|
|
5317
|
+
}));
|
|
5318
|
+
case 1:
|
|
5319
|
+
forced = _context.v;
|
|
5320
|
+
_context.n = 2;
|
|
5321
|
+
return getOriginXcmFeeInternal(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
5322
|
+
useRootOrigin: false
|
|
5323
|
+
}));
|
|
5324
|
+
case 2:
|
|
5325
|
+
real = _context.v;
|
|
5326
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, forced), {}, {
|
|
5327
|
+
sufficient: real.sufficient
|
|
5328
|
+
}));
|
|
5329
|
+
}
|
|
5330
|
+
}, _callee);
|
|
5331
|
+
}));
|
|
5332
|
+
return function getOriginXcmFee(_x) {
|
|
5333
|
+
return _ref.apply(this, arguments);
|
|
5334
|
+
};
|
|
5335
|
+
}();
|
|
5336
|
+
|
|
5388
5337
|
var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
|
|
5389
5338
|
return assetCheckEnabled ? assets.findAssetInfo(origin, currency, !sdkCommon.isTLocation(destination) ? destination : null) : null;
|
|
5390
5339
|
};
|
|
@@ -5587,7 +5536,7 @@ var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
|
|
|
5587
5536
|
};
|
|
5588
5537
|
}();
|
|
5589
5538
|
|
|
5590
|
-
var getFailureInfo = function getFailureInfo(chains, hops) {
|
|
5539
|
+
var getFailureInfo$1 = function getFailureInfo(chains, hops) {
|
|
5591
5540
|
var _chains$origin, _chains$assetHub, _chains$bridgeHub, _chains$destination;
|
|
5592
5541
|
// Check standard chains first for backwards compatibility
|
|
5593
5542
|
if ((_chains$origin = chains.origin) !== null && _chains$origin !== void 0 && _chains$origin.dryRunError) return {
|
|
@@ -5626,8 +5575,8 @@ var getFailureInfo = function getFailureInfo(chains, hops) {
|
|
|
5626
5575
|
}
|
|
5627
5576
|
return {};
|
|
5628
5577
|
};
|
|
5629
|
-
var
|
|
5630
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
5578
|
+
var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
5579
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref, useRootOrigin) {
|
|
5631
5580
|
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;
|
|
5632
5581
|
return _regenerator().w(function (_context2) {
|
|
5633
5582
|
while (1) switch (_context2.p = _context2.n) {
|
|
@@ -5636,7 +5585,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5636
5585
|
asset = assets.findAssetInfoOrThrow(origin, currency, destination);
|
|
5637
5586
|
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
5638
5587
|
_context2.n = 1;
|
|
5639
|
-
return
|
|
5588
|
+
return getOriginXcmFeeInternal({
|
|
5640
5589
|
api: api,
|
|
5641
5590
|
tx: tx,
|
|
5642
5591
|
origin: origin,
|
|
@@ -5644,7 +5593,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5644
5593
|
senderAddress: senderAddress,
|
|
5645
5594
|
feeAsset: feeAsset,
|
|
5646
5595
|
currency: currency,
|
|
5647
|
-
disableFallback: disableFallback
|
|
5596
|
+
disableFallback: disableFallback,
|
|
5597
|
+
useRootOrigin: useRootOrigin
|
|
5648
5598
|
});
|
|
5649
5599
|
case 1:
|
|
5650
5600
|
_yield$getOriginXcmFe = _context2.v;
|
|
@@ -5690,13 +5640,12 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5690
5640
|
case 5:
|
|
5691
5641
|
destFeeRes = _context2.v;
|
|
5692
5642
|
_result = {
|
|
5693
|
-
origin: _objectSpread2(_objectSpread2(_objectSpread2(
|
|
5643
|
+
origin: _objectSpread2(_objectSpread2(_objectSpread2({}, originFee && {
|
|
5694
5644
|
fee: originFee
|
|
5695
5645
|
}), originFeeType && {
|
|
5696
5646
|
feeType: originFeeType
|
|
5697
|
-
}), sufficientOriginFee !== undefined && {
|
|
5698
|
-
sufficient: sufficientOriginFee
|
|
5699
5647
|
}), {}, {
|
|
5648
|
+
sufficient: sufficientOriginFee,
|
|
5700
5649
|
currency: originCurrency
|
|
5701
5650
|
}, originDryRunError && {
|
|
5702
5651
|
dryRunError: originDryRunError
|
|
@@ -5714,7 +5663,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5714
5663
|
}),
|
|
5715
5664
|
hops: []
|
|
5716
5665
|
};
|
|
5717
|
-
_getFailureInfo = getFailureInfo({
|
|
5666
|
+
_getFailureInfo = getFailureInfo$1({
|
|
5718
5667
|
origin: _result.origin,
|
|
5719
5668
|
destination: _result.destination
|
|
5720
5669
|
}, []), _failureChain = _getFailureInfo.failureChain, _failureReason = _getFailureInfo.failureReason;
|
|
@@ -5773,7 +5722,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5773
5722
|
}
|
|
5774
5723
|
}, _callee);
|
|
5775
5724
|
}));
|
|
5776
|
-
return function processHop(
|
|
5725
|
+
return function processHop(_x3) {
|
|
5777
5726
|
return _ref3.apply(this, arguments);
|
|
5778
5727
|
};
|
|
5779
5728
|
}();
|
|
@@ -5926,7 +5875,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5926
5875
|
};
|
|
5927
5876
|
})
|
|
5928
5877
|
});
|
|
5929
|
-
_getFailureInfo2 = getFailureInfo({
|
|
5878
|
+
_getFailureInfo2 = getFailureInfo$1({
|
|
5930
5879
|
origin: result.origin,
|
|
5931
5880
|
assetHub: result.assetHub,
|
|
5932
5881
|
bridgeHub: result.bridgeHub,
|
|
@@ -5939,11 +5888,59 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
5939
5888
|
}
|
|
5940
5889
|
}, _callee2, null, [[3,, 6, 8]]);
|
|
5941
5890
|
}));
|
|
5942
|
-
return function
|
|
5891
|
+
return function getXcmFeeInternal(_x, _x2) {
|
|
5943
5892
|
return _ref2.apply(this, arguments);
|
|
5944
5893
|
};
|
|
5945
5894
|
}();
|
|
5946
5895
|
|
|
5896
|
+
var getXcmFee = /*#__PURE__*/function () {
|
|
5897
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
5898
|
+
var _real$assetHub, _real$bridgeHub;
|
|
5899
|
+
var forced, real;
|
|
5900
|
+
return _regenerator().w(function (_context) {
|
|
5901
|
+
while (1) switch (_context.n) {
|
|
5902
|
+
case 0:
|
|
5903
|
+
_context.n = 1;
|
|
5904
|
+
return getXcmFeeInternal(options, true);
|
|
5905
|
+
case 1:
|
|
5906
|
+
forced = _context.v;
|
|
5907
|
+
_context.n = 2;
|
|
5908
|
+
return getXcmFeeInternal(options, false);
|
|
5909
|
+
case 2:
|
|
5910
|
+
real = _context.v;
|
|
5911
|
+
return _context.a(2, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, forced), {}, {
|
|
5912
|
+
origin: _objectSpread2(_objectSpread2({}, forced.origin), {}, {
|
|
5913
|
+
sufficient: real.origin.sufficient
|
|
5914
|
+
}),
|
|
5915
|
+
destination: _objectSpread2(_objectSpread2({}, forced.destination), {}, {
|
|
5916
|
+
sufficient: real.destination.sufficient
|
|
5917
|
+
})
|
|
5918
|
+
}, forced.assetHub ? {
|
|
5919
|
+
assetHub: _objectSpread2(_objectSpread2({}, forced.assetHub), {}, {
|
|
5920
|
+
sufficient: (_real$assetHub = real.assetHub) === null || _real$assetHub === void 0 ? void 0 : _real$assetHub.sufficient
|
|
5921
|
+
})
|
|
5922
|
+
} : {}), forced.bridgeHub ? {
|
|
5923
|
+
bridgeHub: _objectSpread2(_objectSpread2({}, forced.bridgeHub), {}, {
|
|
5924
|
+
sufficient: (_real$bridgeHub = real.bridgeHub) === null || _real$bridgeHub === void 0 ? void 0 : _real$bridgeHub.sufficient
|
|
5925
|
+
})
|
|
5926
|
+
} : {}), {}, {
|
|
5927
|
+
hops: forced.hops.map(function (hop, index) {
|
|
5928
|
+
var _real$hops$index;
|
|
5929
|
+
return _objectSpread2(_objectSpread2({}, hop), {}, {
|
|
5930
|
+
result: _objectSpread2(_objectSpread2({}, hop.result), {}, {
|
|
5931
|
+
sufficient: (_real$hops$index = real.hops[index]) === null || _real$hops$index === void 0 ? void 0 : _real$hops$index.result.sufficient
|
|
5932
|
+
})
|
|
5933
|
+
});
|
|
5934
|
+
})
|
|
5935
|
+
}));
|
|
5936
|
+
}
|
|
5937
|
+
}, _callee);
|
|
5938
|
+
}));
|
|
5939
|
+
return function getXcmFee(_x) {
|
|
5940
|
+
return _ref.apply(this, arguments);
|
|
5941
|
+
};
|
|
5942
|
+
}();
|
|
5943
|
+
|
|
5947
5944
|
var BRIDGE_FEE_DOT = 682395810n; // 0.068239581 DOT
|
|
5948
5945
|
var BRIDGE_FEE_KSM = 12016807000n; // 0.012016807 KSM
|
|
5949
5946
|
var getXcmFeeEstimate = /*#__PURE__*/function () {
|
|
@@ -6499,68 +6496,13 @@ var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
|
6499
6496
|
};
|
|
6500
6497
|
}();
|
|
6501
6498
|
|
|
6502
|
-
var attemptDryRunFee = /*#__PURE__*/function () {
|
|
6503
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
|
|
6504
|
-
var origin, currency, builder, reductionPcts, lastReduction, result, _i, _reductionPcts, percentage, modifiedBuilder, _t, _t2, _t3, _t4, _t5, _t6, _t7;
|
|
6505
|
-
return _regenerator().w(function (_context) {
|
|
6506
|
-
while (1) switch (_context.n) {
|
|
6507
|
-
case 0:
|
|
6508
|
-
origin = options.origin, currency = options.currency, builder = options.builder;
|
|
6509
|
-
reductionPcts = [0, 10, 20, 30, 40, 50];
|
|
6510
|
-
lastReduction = reductionPcts[reductionPcts.length - 1];
|
|
6511
|
-
result = null;
|
|
6512
|
-
_i = 0, _reductionPcts = reductionPcts;
|
|
6513
|
-
case 1:
|
|
6514
|
-
if (!(_i < _reductionPcts.length)) {
|
|
6515
|
-
_context.n = 5;
|
|
6516
|
-
break;
|
|
6517
|
-
}
|
|
6518
|
-
percentage = _reductionPcts[_i];
|
|
6519
|
-
modifiedBuilder = builder.currency(_objectSpread2(_objectSpread2({}, currency), {}, {
|
|
6520
|
-
amount: padFeeBy(BigInt(currency.amount), -percentage)
|
|
6521
|
-
}));
|
|
6522
|
-
_t = getOriginXcmFee;
|
|
6523
|
-
_t2 = _objectSpread2;
|
|
6524
|
-
_t3 = _objectSpread2({}, options);
|
|
6525
|
-
_t4 = {};
|
|
6526
|
-
_context.n = 2;
|
|
6527
|
-
return modifiedBuilder.build();
|
|
6528
|
-
case 2:
|
|
6529
|
-
_t5 = _context.v;
|
|
6530
|
-
_t6 = {
|
|
6531
|
-
tx: _t5
|
|
6532
|
-
};
|
|
6533
|
-
_t7 = _t2(_t3, _t4, _t6);
|
|
6534
|
-
_context.n = 3;
|
|
6535
|
-
return _t(_t7);
|
|
6536
|
-
case 3:
|
|
6537
|
-
result = _context.v;
|
|
6538
|
-
if (!(result.feeType === 'dryRun' || percentage === lastReduction || !assets.hasDryRunSupport(origin))) {
|
|
6539
|
-
_context.n = 4;
|
|
6540
|
-
break;
|
|
6541
|
-
}
|
|
6542
|
-
return _context.a(2, result);
|
|
6543
|
-
case 4:
|
|
6544
|
-
_i++;
|
|
6545
|
-
_context.n = 1;
|
|
6546
|
-
break;
|
|
6547
|
-
case 5:
|
|
6548
|
-
return _context.a(2, result);
|
|
6549
|
-
}
|
|
6550
|
-
}, _callee);
|
|
6551
|
-
}));
|
|
6552
|
-
return function attemptDryRunFee(_x) {
|
|
6553
|
-
return _ref.apply(this, arguments);
|
|
6554
|
-
};
|
|
6555
|
-
}();
|
|
6556
|
-
|
|
6557
6499
|
var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
6558
6500
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
6559
|
-
var api, senderAddress, chain, destination, currency,
|
|
6501
|
+
var api, senderAddress, chain, destination, currency, tx, feeAsset, resolvedFeeAsset, asset, amount, balance, ed, isNativeAsset, shouldSubstractFee, feeToSubtract, _yield$getOriginXcmFe, fee, transferable;
|
|
6560
6502
|
return _regenerator().w(function (_context) {
|
|
6561
6503
|
while (1) switch (_context.n) {
|
|
6562
6504
|
case 0:
|
|
6563
|
-
api = _ref.api, senderAddress = _ref.senderAddress, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency,
|
|
6505
|
+
api = _ref.api, senderAddress = _ref.senderAddress, chain = _ref.origin, destination = _ref.destination, currency = _ref.currency, tx = _ref.tx, feeAsset = _ref.feeAsset;
|
|
6564
6506
|
validateAddress(senderAddress, chain, false);
|
|
6565
6507
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, chain, destination, currency) : undefined;
|
|
6566
6508
|
asset = assets.findAssetInfoOrThrow(chain, currency, null);
|
|
@@ -6583,9 +6525,9 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
|
6583
6525
|
break;
|
|
6584
6526
|
}
|
|
6585
6527
|
_context.n = 2;
|
|
6586
|
-
return
|
|
6528
|
+
return getOriginXcmFee({
|
|
6587
6529
|
api: api,
|
|
6588
|
-
|
|
6530
|
+
tx: tx,
|
|
6589
6531
|
origin: chain,
|
|
6590
6532
|
destination: chain,
|
|
6591
6533
|
senderAddress: senderAddress,
|
|
@@ -6596,8 +6538,8 @@ var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
|
6596
6538
|
disableFallback: false
|
|
6597
6539
|
});
|
|
6598
6540
|
case 2:
|
|
6599
|
-
_yield$
|
|
6600
|
-
fee = _yield$
|
|
6541
|
+
_yield$getOriginXcmFe = _context.v;
|
|
6542
|
+
fee = _yield$getOriginXcmFe.fee;
|
|
6601
6543
|
if (!(fee === undefined)) {
|
|
6602
6544
|
_context.n = 3;
|
|
6603
6545
|
break;
|
|
@@ -6920,22 +6862,16 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
6920
6862
|
bridgeHubFeeResult = _yield$getXcmFee.bridgeHub;
|
|
6921
6863
|
destFeeDetail = _yield$getXcmFee.destination;
|
|
6922
6864
|
hops = _yield$getXcmFee.hops;
|
|
6923
|
-
if (!(originFee === undefined)) {
|
|
6924
|
-
_context2.n = 10;
|
|
6925
|
-
break;
|
|
6926
|
-
}
|
|
6927
|
-
throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency, sdkCommon.replaceBigInt), " on chain ").concat(origin, "."));
|
|
6928
|
-
case 10:
|
|
6929
6865
|
isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && assets.isAssetEqual(resolvedFeeAsset, originAsset);
|
|
6930
6866
|
originBalanceAfter = originBalance - amount;
|
|
6931
6867
|
originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - amount : originBalanceFee - originFee;
|
|
6932
6868
|
originBalanceNativeSufficient = originBalanceFee >= originFee;
|
|
6933
6869
|
originBalanceSufficient = originBalanceAfter >= edOrigin;
|
|
6934
6870
|
if (!assetHubFeeResult) {
|
|
6935
|
-
_context2.n =
|
|
6871
|
+
_context2.n = 11;
|
|
6936
6872
|
break;
|
|
6937
6873
|
}
|
|
6938
|
-
_context2.n =
|
|
6874
|
+
_context2.n = 10;
|
|
6939
6875
|
return buildHopInfo({
|
|
6940
6876
|
api: api,
|
|
6941
6877
|
chain: "AssetHub".concat(getRelayChainOf(origin)),
|
|
@@ -6945,15 +6881,15 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
6945
6881
|
senderAddress: senderAddress,
|
|
6946
6882
|
ahAddress: ahAddress
|
|
6947
6883
|
});
|
|
6948
|
-
case
|
|
6884
|
+
case 10:
|
|
6949
6885
|
assetHub = _context2.v;
|
|
6950
|
-
case
|
|
6886
|
+
case 11:
|
|
6951
6887
|
if (!bridgeHubFeeResult) {
|
|
6952
|
-
_context2.n =
|
|
6888
|
+
_context2.n = 13;
|
|
6953
6889
|
break;
|
|
6954
6890
|
}
|
|
6955
6891
|
bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
|
|
6956
|
-
_context2.n =
|
|
6892
|
+
_context2.n = 12;
|
|
6957
6893
|
return buildHopInfo({
|
|
6958
6894
|
api: api,
|
|
6959
6895
|
chain: bridgeHubChain,
|
|
@@ -6963,15 +6899,15 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
6963
6899
|
senderAddress: senderAddress,
|
|
6964
6900
|
ahAddress: ahAddress
|
|
6965
6901
|
});
|
|
6966
|
-
case
|
|
6902
|
+
case 12:
|
|
6967
6903
|
bridgeHub = _context2.v;
|
|
6968
|
-
case
|
|
6904
|
+
case 13:
|
|
6969
6905
|
builtHops = [];
|
|
6970
6906
|
if (!(hops && hops.length > 0)) {
|
|
6971
|
-
_context2.n =
|
|
6907
|
+
_context2.n = 15;
|
|
6972
6908
|
break;
|
|
6973
6909
|
}
|
|
6974
|
-
_context2.n =
|
|
6910
|
+
_context2.n = 14;
|
|
6975
6911
|
return Promise.all(hops.map(/*#__PURE__*/function () {
|
|
6976
6912
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(hop) {
|
|
6977
6913
|
var result;
|
|
@@ -7001,10 +6937,10 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
7001
6937
|
return _ref3.apply(this, arguments);
|
|
7002
6938
|
};
|
|
7003
6939
|
}()));
|
|
7004
|
-
case
|
|
6940
|
+
case 14:
|
|
7005
6941
|
builtHops = _context2.v;
|
|
7006
|
-
case
|
|
7007
|
-
_context2.n =
|
|
6942
|
+
case 15:
|
|
6943
|
+
_context2.n = 16;
|
|
7008
6944
|
return buildDestInfo({
|
|
7009
6945
|
api: api,
|
|
7010
6946
|
origin: origin,
|
|
@@ -7019,7 +6955,7 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
7019
6955
|
assetHubFee: assetHubFeeResult === null || assetHubFeeResult === void 0 ? void 0 : assetHubFeeResult.fee,
|
|
7020
6956
|
bridgeFee: bridgeHubFeeResult === null || bridgeHubFeeResult === void 0 ? void 0 : bridgeHubFeeResult.fee
|
|
7021
6957
|
});
|
|
7022
|
-
case
|
|
6958
|
+
case 16:
|
|
7023
6959
|
destinationInfo = _context2.v;
|
|
7024
6960
|
return _context2.a(2, {
|
|
7025
6961
|
chain: {
|
|
@@ -7048,17 +6984,17 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
7048
6984
|
hops: builtHops,
|
|
7049
6985
|
destination: destinationInfo
|
|
7050
6986
|
});
|
|
7051
|
-
case
|
|
7052
|
-
_context2.p =
|
|
6987
|
+
case 17:
|
|
6988
|
+
_context2.p = 17;
|
|
7053
6989
|
api.setDisconnectAllowed(true);
|
|
7054
|
-
_context2.n =
|
|
6990
|
+
_context2.n = 18;
|
|
7055
6991
|
return api.disconnect();
|
|
6992
|
+
case 18:
|
|
6993
|
+
return _context2.f(17);
|
|
7056
6994
|
case 19:
|
|
7057
|
-
return _context2.f(18);
|
|
7058
|
-
case 20:
|
|
7059
6995
|
return _context2.a(2);
|
|
7060
6996
|
}
|
|
7061
|
-
}, _callee2, null, [[3,,
|
|
6997
|
+
}, _callee2, null, [[3,, 17, 19]]);
|
|
7062
6998
|
}));
|
|
7063
6999
|
return function getTransferInfo(_x) {
|
|
7064
7000
|
return _ref2.apply(this, arguments);
|
|
@@ -7215,14 +7151,264 @@ var verifyEdOnDestination = /*#__PURE__*/function () {
|
|
|
7215
7151
|
};
|
|
7216
7152
|
}();
|
|
7217
7153
|
|
|
7218
|
-
var
|
|
7154
|
+
var isSufficientOrigin = /*#__PURE__*/function () {
|
|
7155
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(api, origin, destination, senderAddress, feeNative, currency, asset, feeAsset) {
|
|
7156
|
+
var edNative, balanceNative, isNativeAssetToOrigin, isNativeAssetToDest, isSufficientNative, balanceAsset, edAsset, isSufficientAsset;
|
|
7157
|
+
return _regenerator().w(function (_context) {
|
|
7158
|
+
while (1) switch (_context.n) {
|
|
7159
|
+
case 0:
|
|
7160
|
+
if (!feeAsset) {
|
|
7161
|
+
_context.n = 1;
|
|
7162
|
+
break;
|
|
7163
|
+
}
|
|
7164
|
+
return _context.a(2, undefined);
|
|
7165
|
+
case 1:
|
|
7166
|
+
edNative = assets.getExistentialDepositOrThrow(origin);
|
|
7167
|
+
_context.n = 2;
|
|
7168
|
+
return getBalanceNativeInternal({
|
|
7169
|
+
api: api,
|
|
7170
|
+
chain: origin,
|
|
7171
|
+
address: senderAddress
|
|
7172
|
+
});
|
|
7173
|
+
case 2:
|
|
7174
|
+
balanceNative = _context.v;
|
|
7175
|
+
isNativeAssetToOrigin = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(origin));
|
|
7176
|
+
isNativeAssetToDest = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(destination));
|
|
7177
|
+
if (!(isNativeAssetToOrigin && isNativeAssetToDest)) {
|
|
7178
|
+
_context.n = 3;
|
|
7179
|
+
break;
|
|
7180
|
+
}
|
|
7181
|
+
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
7182
|
+
case 3:
|
|
7183
|
+
if (isNativeAssetToOrigin) {
|
|
7184
|
+
_context.n = 5;
|
|
7185
|
+
break;
|
|
7186
|
+
}
|
|
7187
|
+
isSufficientNative = balanceNative - edNative - feeNative > 0n;
|
|
7188
|
+
_context.n = 4;
|
|
7189
|
+
return getAssetBalance({
|
|
7190
|
+
api: api,
|
|
7191
|
+
chain: origin,
|
|
7192
|
+
address: senderAddress,
|
|
7193
|
+
currency: currency
|
|
7194
|
+
});
|
|
7195
|
+
case 4:
|
|
7196
|
+
balanceAsset = _context.v;
|
|
7197
|
+
edAsset = assets.getExistentialDepositOrThrow(origin, currency);
|
|
7198
|
+
isSufficientAsset = balanceAsset - edAsset > 0n;
|
|
7199
|
+
return _context.a(2, isSufficientNative && isSufficientAsset);
|
|
7200
|
+
case 5:
|
|
7201
|
+
return _context.a(2, balanceNative - edNative - feeNative - BigInt(currency.amount) > 0n);
|
|
7202
|
+
case 6:
|
|
7203
|
+
return _context.a(2);
|
|
7204
|
+
}
|
|
7205
|
+
}, _callee);
|
|
7206
|
+
}));
|
|
7207
|
+
return function isSufficientOrigin(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) {
|
|
7208
|
+
return _ref.apply(this, arguments);
|
|
7209
|
+
};
|
|
7210
|
+
}();
|
|
7211
|
+
var isSufficientDestination = /*#__PURE__*/function () {
|
|
7212
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(api, destination, address, amount, asset, feeNative) {
|
|
7213
|
+
var isNativeAsset, existentialDeposit, nativeBalance;
|
|
7214
|
+
return _regenerator().w(function (_context2) {
|
|
7215
|
+
while (1) switch (_context2.n) {
|
|
7216
|
+
case 0:
|
|
7217
|
+
isNativeAsset = assets.isSymbolMatch(asset.symbol, assets.getNativeAssetSymbol(destination));
|
|
7218
|
+
if (isNativeAsset) {
|
|
7219
|
+
_context2.n = 1;
|
|
7220
|
+
break;
|
|
7221
|
+
}
|
|
7222
|
+
return _context2.a(2, undefined);
|
|
7223
|
+
case 1:
|
|
7224
|
+
existentialDeposit = assets.getExistentialDepositOrThrow(destination);
|
|
7225
|
+
_context2.n = 2;
|
|
7226
|
+
return getBalanceNativeInternal({
|
|
7227
|
+
api: api,
|
|
7228
|
+
chain: destination,
|
|
7229
|
+
address: address
|
|
7230
|
+
});
|
|
7231
|
+
case 2:
|
|
7232
|
+
nativeBalance = _context2.v;
|
|
7233
|
+
return _context2.a(2, nativeBalance + amount - existentialDeposit - feeNative > 0n);
|
|
7234
|
+
}
|
|
7235
|
+
}, _callee2);
|
|
7236
|
+
}));
|
|
7237
|
+
return function isSufficientDestination(_x9, _x0, _x1, _x10, _x11, _x12) {
|
|
7238
|
+
return _ref2.apply(this, arguments);
|
|
7239
|
+
};
|
|
7240
|
+
}();
|
|
7241
|
+
|
|
7242
|
+
var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
7243
|
+
if (sdkCommon.isRelayChain(origin)) return DOT_LOCATION;
|
|
7244
|
+
return {
|
|
7245
|
+
parents: sdkCommon.isRelayChain(destination) ? sdkCommon.Parents.ZERO : sdkCommon.Parents.ONE,
|
|
7246
|
+
interior: {
|
|
7247
|
+
X1: [{
|
|
7248
|
+
Parachain: getParaId(origin)
|
|
7249
|
+
}]
|
|
7250
|
+
}
|
|
7251
|
+
};
|
|
7252
|
+
};
|
|
7253
|
+
var getDestXcmFee = /*#__PURE__*/function () {
|
|
7254
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
7255
|
+
var api, origin, hopChain, destination, currency, forwardedXcms, asset, address, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, _fee, sufficient, dryRunResult, _fee2, fee, newForwardedXcms, destParaId;
|
|
7256
|
+
return _regenerator().w(function (_context2) {
|
|
7257
|
+
while (1) switch (_context2.n) {
|
|
7258
|
+
case 0:
|
|
7259
|
+
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;
|
|
7260
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
7261
|
+
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
7262
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
7263
|
+
var originAsset, _t;
|
|
7264
|
+
return _regenerator().w(function (_context) {
|
|
7265
|
+
while (1) switch (_context.p = _context.n) {
|
|
7266
|
+
case 0:
|
|
7267
|
+
if (!(destination === 'Ethereum')) {
|
|
7268
|
+
_context.n = 1;
|
|
7269
|
+
break;
|
|
7270
|
+
}
|
|
7271
|
+
return _context.a(2, 0n);
|
|
7272
|
+
case 1:
|
|
7273
|
+
originAsset = assets.findAssetInfoOrThrow(origin, currency, destination);
|
|
7274
|
+
if (!originAsset.location) {
|
|
7275
|
+
_context.n = 7;
|
|
7276
|
+
break;
|
|
7277
|
+
}
|
|
7278
|
+
_context.p = 2;
|
|
7279
|
+
_context.n = 3;
|
|
7280
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
7281
|
+
destination: destination
|
|
7282
|
+
}), {
|
|
7283
|
+
location: originAsset.location
|
|
7284
|
+
});
|
|
7285
|
+
case 3:
|
|
7286
|
+
return _context.a(2, _context.v);
|
|
7287
|
+
case 4:
|
|
7288
|
+
_context.p = 4;
|
|
7289
|
+
_t = _context.v;
|
|
7290
|
+
if (!(_t instanceof assets.InvalidCurrencyError)) {
|
|
7291
|
+
_context.n = 6;
|
|
7292
|
+
break;
|
|
7293
|
+
}
|
|
7294
|
+
_context.n = 5;
|
|
7295
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
7296
|
+
destination: destination
|
|
7297
|
+
}), {
|
|
7298
|
+
symbol: originAsset.symbol
|
|
7299
|
+
});
|
|
7300
|
+
case 5:
|
|
7301
|
+
return _context.a(2, _context.v);
|
|
7302
|
+
case 6:
|
|
7303
|
+
throw _t;
|
|
7304
|
+
case 7:
|
|
7305
|
+
_context.n = 8;
|
|
7306
|
+
return getReverseTxFee(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
7307
|
+
destination: destination
|
|
7308
|
+
}), {
|
|
7309
|
+
symbol: originAsset.symbol
|
|
7310
|
+
});
|
|
7311
|
+
case 8:
|
|
7312
|
+
return _context.a(2, _context.v);
|
|
7313
|
+
}
|
|
7314
|
+
}, _callee, null, [[2, 4]]);
|
|
7315
|
+
}));
|
|
7316
|
+
return function calcPaymentInfoFee() {
|
|
7317
|
+
return _ref2.apply(this, arguments);
|
|
7318
|
+
};
|
|
7319
|
+
}();
|
|
7320
|
+
if (!(!assets.hasDryRunSupport(destination) || !forwardedXcms || destination === 'Ethereum')) {
|
|
7321
|
+
_context2.n = 3;
|
|
7322
|
+
break;
|
|
7323
|
+
}
|
|
7324
|
+
_context2.n = 1;
|
|
7325
|
+
return calcPaymentInfoFee();
|
|
7326
|
+
case 1:
|
|
7327
|
+
_fee = _context2.v;
|
|
7328
|
+
_context2.n = 2;
|
|
7329
|
+
return isSufficientDestination(api, destination, address, BigInt(currency.amount), asset, _fee);
|
|
7330
|
+
case 2:
|
|
7331
|
+
sufficient = _context2.v;
|
|
7332
|
+
return _context2.a(2, {
|
|
7333
|
+
fee: _fee,
|
|
7334
|
+
feeType: 'paymentInfo',
|
|
7335
|
+
sufficient: !assets.hasDryRunSupport(destination) ? sufficient : false
|
|
7336
|
+
});
|
|
7337
|
+
case 3:
|
|
7338
|
+
_context2.n = 4;
|
|
7339
|
+
return api.getDryRunXcm({
|
|
7340
|
+
originLocation: addXcmVersionHeader(createOriginLocation(hopChain, destination), sdkCommon.Version.V4),
|
|
7341
|
+
xcm: forwardedXcms[1][0],
|
|
7342
|
+
chain: destination,
|
|
7343
|
+
origin: origin,
|
|
7344
|
+
asset: asset,
|
|
7345
|
+
originFee: originFee,
|
|
7346
|
+
feeAsset: resolvedFeeAsset,
|
|
7347
|
+
amount: BigInt(currency.amount) < 2n ? 2n : BigInt(currency.amount)
|
|
7348
|
+
});
|
|
7349
|
+
case 4:
|
|
7350
|
+
dryRunResult = _context2.v;
|
|
7351
|
+
if (dryRunResult.success) {
|
|
7352
|
+
_context2.n = 7;
|
|
7353
|
+
break;
|
|
7354
|
+
}
|
|
7355
|
+
if (!disableFallback) {
|
|
7356
|
+
_context2.n = 5;
|
|
7357
|
+
break;
|
|
7358
|
+
}
|
|
7359
|
+
return _context2.a(2, {
|
|
7360
|
+
dryRunError: dryRunResult.failureReason
|
|
7361
|
+
});
|
|
7362
|
+
case 5:
|
|
7363
|
+
_context2.n = 6;
|
|
7364
|
+
return calcPaymentInfoFee();
|
|
7365
|
+
case 6:
|
|
7366
|
+
_fee2 = _context2.v;
|
|
7367
|
+
return _context2.a(2, {
|
|
7368
|
+
fee: _fee2,
|
|
7369
|
+
feeType: 'paymentInfo',
|
|
7370
|
+
dryRunError: dryRunResult.failureReason,
|
|
7371
|
+
sufficient: false
|
|
7372
|
+
});
|
|
7373
|
+
case 7:
|
|
7374
|
+
fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
7375
|
+
return _context2.a(2, {
|
|
7376
|
+
fee: fee,
|
|
7377
|
+
feeType: 'dryRun',
|
|
7378
|
+
sufficient: true,
|
|
7379
|
+
forwardedXcms: newForwardedXcms,
|
|
7380
|
+
destParaId: destParaId
|
|
7381
|
+
});
|
|
7382
|
+
}
|
|
7383
|
+
}, _callee2);
|
|
7384
|
+
}));
|
|
7385
|
+
return function getDestXcmFee(_x) {
|
|
7386
|
+
return _ref.apply(this, arguments);
|
|
7387
|
+
};
|
|
7388
|
+
}();
|
|
7389
|
+
|
|
7390
|
+
var getFailureInfo = function getFailureInfo(results, hops) {
|
|
7391
|
+
// Check standard chains first for backwards compatibility
|
|
7392
|
+
for (var _i = 0, _arr = ['destination', 'assetHub', 'bridgeHub']; _i < _arr.length; _i++) {
|
|
7393
|
+
var chain = _arr[_i];
|
|
7394
|
+
var res = results[chain];
|
|
7395
|
+
if (res && !res.success && res.failureReason) {
|
|
7396
|
+
return {
|
|
7397
|
+
failureReason: res.failureReason,
|
|
7398
|
+
failureChain: chain
|
|
7399
|
+
};
|
|
7400
|
+
}
|
|
7401
|
+
}
|
|
7219
7402
|
var _iterator = _createForOfIteratorHelper(hops),
|
|
7220
7403
|
_step;
|
|
7221
7404
|
try {
|
|
7222
7405
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
7223
7406
|
var hop = _step.value;
|
|
7224
|
-
if (!hop.result.success) {
|
|
7225
|
-
|
|
7407
|
+
if (!hop.result.success && hop.result.failureReason) {
|
|
7408
|
+
return {
|
|
7409
|
+
failureReason: hop.result.failureReason,
|
|
7410
|
+
failureChain: hop.chain
|
|
7411
|
+
};
|
|
7226
7412
|
}
|
|
7227
7413
|
}
|
|
7228
7414
|
} catch (err) {
|
|
@@ -7230,7 +7416,182 @@ var validateHops = function validateHops(hops) {
|
|
|
7230
7416
|
} finally {
|
|
7231
7417
|
_iterator.f();
|
|
7232
7418
|
}
|
|
7419
|
+
return {};
|
|
7233
7420
|
};
|
|
7421
|
+
var dryRunInternal = /*#__PURE__*/function () {
|
|
7422
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
7423
|
+
var _traversalResult$brid, _traversalResult$asse, _traversalResult$dest;
|
|
7424
|
+
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;
|
|
7425
|
+
return _regenerator().w(function (_context2) {
|
|
7426
|
+
while (1) switch (_context2.n) {
|
|
7427
|
+
case 0:
|
|
7428
|
+
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;
|
|
7429
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
7430
|
+
asset = assets.findAssetInfoOrThrow(origin, currency, destination);
|
|
7431
|
+
amount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
7432
|
+
_context2.n = 1;
|
|
7433
|
+
return api.getDryRunCall({
|
|
7434
|
+
tx: tx,
|
|
7435
|
+
chain: origin,
|
|
7436
|
+
address: senderAddress,
|
|
7437
|
+
asset: _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
7438
|
+
amount: amount
|
|
7439
|
+
}),
|
|
7440
|
+
feeAsset: resolvedFeeAsset,
|
|
7441
|
+
useRootOrigin: useRootOrigin
|
|
7442
|
+
});
|
|
7443
|
+
case 1:
|
|
7444
|
+
originDryRun = _context2.v;
|
|
7445
|
+
if (originDryRun.success) {
|
|
7446
|
+
_context2.n = 2;
|
|
7447
|
+
break;
|
|
7448
|
+
}
|
|
7449
|
+
return _context2.a(2, {
|
|
7450
|
+
failureReason: originDryRun.failureReason,
|
|
7451
|
+
failureChain: 'origin',
|
|
7452
|
+
origin: originDryRun,
|
|
7453
|
+
hops: []
|
|
7454
|
+
});
|
|
7455
|
+
case 2:
|
|
7456
|
+
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
7457
|
+
processHop = /*#__PURE__*/function () {
|
|
7458
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
7459
|
+
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, isDestination, hopDryRun, hopCurrency;
|
|
7460
|
+
return _regenerator().w(function (_context) {
|
|
7461
|
+
while (1) switch (_context.n) {
|
|
7462
|
+
case 0:
|
|
7463
|
+
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange, isDestination = params.isDestination;
|
|
7464
|
+
if (assets.hasDryRunSupport(currentChain)) {
|
|
7465
|
+
_context.n = 1;
|
|
7466
|
+
break;
|
|
7467
|
+
}
|
|
7468
|
+
return _context.a(2, {
|
|
7469
|
+
success: false,
|
|
7470
|
+
failureReason: "DryRunApi is not available on chain ".concat(currentChain)
|
|
7471
|
+
});
|
|
7472
|
+
case 1:
|
|
7473
|
+
_context.n = 2;
|
|
7474
|
+
return hopApi.getDryRunXcm({
|
|
7475
|
+
originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, currentChain), sdkCommon.Version.V4),
|
|
7476
|
+
xcm: forwardedXcms[1][0],
|
|
7477
|
+
chain: currentChain,
|
|
7478
|
+
origin: currentOrigin,
|
|
7479
|
+
asset: currentAsset,
|
|
7480
|
+
feeAsset: resolvedFeeAsset,
|
|
7481
|
+
originFee: originDryRun.fee,
|
|
7482
|
+
amount: amount
|
|
7483
|
+
});
|
|
7484
|
+
case 2:
|
|
7485
|
+
hopDryRun = _context.v;
|
|
7486
|
+
if (!hopDryRun.success) {
|
|
7487
|
+
_context.n = 3;
|
|
7488
|
+
break;
|
|
7489
|
+
}
|
|
7490
|
+
if (destination === 'Ethereum' && (currentChain.includes('AssetHub') || currentChain.includes('BridgeHub'))) {
|
|
7491
|
+
hopCurrency = assets.getNativeAssetSymbol(currentChain);
|
|
7492
|
+
} else if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
|
|
7493
|
+
hopCurrency = assets.findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo).symbol;
|
|
7494
|
+
} else if (isDestination) {
|
|
7495
|
+
hopCurrency = assets.findAssetOnDestOrThrow(origin, currentChain, currency).symbol;
|
|
7496
|
+
} else {
|
|
7497
|
+
hopCurrency = asset.symbol;
|
|
7498
|
+
}
|
|
7499
|
+
return _context.a(2, _objectSpread2(_objectSpread2({}, hopDryRun), {}, {
|
|
7500
|
+
currency: hopCurrency
|
|
7501
|
+
}));
|
|
7502
|
+
case 3:
|
|
7503
|
+
return _context.a(2, hopDryRun);
|
|
7504
|
+
}
|
|
7505
|
+
}, _callee);
|
|
7506
|
+
}));
|
|
7507
|
+
return function processHop(_x2) {
|
|
7508
|
+
return _ref2.apply(this, arguments);
|
|
7509
|
+
};
|
|
7510
|
+
}();
|
|
7511
|
+
_context2.n = 3;
|
|
7512
|
+
return traverseXcmHops({
|
|
7513
|
+
api: api,
|
|
7514
|
+
origin: origin,
|
|
7515
|
+
destination: destination,
|
|
7516
|
+
currency: currency,
|
|
7517
|
+
initialForwardedXcms: initialForwardedXcms,
|
|
7518
|
+
initialDestParaId: initialDestParaId,
|
|
7519
|
+
swapConfig: swapConfig,
|
|
7520
|
+
processHop: processHop,
|
|
7521
|
+
shouldContinue: function shouldContinue(hopResult) {
|
|
7522
|
+
return hopResult.success;
|
|
7523
|
+
},
|
|
7524
|
+
extractNextHopData: function extractNextHopData(hopResult) {
|
|
7525
|
+
return {
|
|
7526
|
+
forwardedXcms: hopResult.success ? hopResult.forwardedXcms : undefined,
|
|
7527
|
+
destParaId: hopResult.success ? hopResult.destParaId : undefined
|
|
7528
|
+
};
|
|
7529
|
+
}
|
|
7530
|
+
});
|
|
7531
|
+
case 3:
|
|
7532
|
+
traversalResult = _context2.v;
|
|
7533
|
+
// Process Ethereum bridge fees
|
|
7534
|
+
assetHubChain = "AssetHub".concat(getRelayChainOf(origin));
|
|
7535
|
+
bridgeHubChain = "BridgeHub".concat(getRelayChainOf(origin));
|
|
7536
|
+
if (!((_traversalResult$brid = traversalResult.bridgeHub) !== null && _traversalResult$brid !== void 0 && _traversalResult$brid.success)) {
|
|
7537
|
+
_context2.n = 5;
|
|
7538
|
+
break;
|
|
7539
|
+
}
|
|
7540
|
+
_context2.n = 4;
|
|
7541
|
+
return addEthereumBridgeFees(api, traversalResult.bridgeHub, destination, assetHubChain);
|
|
7542
|
+
case 4:
|
|
7543
|
+
_t = _context2.v;
|
|
7544
|
+
_context2.n = 6;
|
|
7545
|
+
break;
|
|
7546
|
+
case 5:
|
|
7547
|
+
_t = traversalResult.bridgeHub;
|
|
7548
|
+
case 6:
|
|
7549
|
+
processedBridgeHub = _t;
|
|
7550
|
+
// Update bridge hub in hops if needed
|
|
7551
|
+
if (processedBridgeHub && processedBridgeHub.success && traversalResult.bridgeHub && traversalResult.bridgeHub.success && processedBridgeHub.fee !== traversalResult.bridgeHub.fee) {
|
|
7552
|
+
bridgeHubHopIndex = traversalResult.hops.findIndex(function (hop) {
|
|
7553
|
+
return hop.chain === bridgeHubChain;
|
|
7554
|
+
});
|
|
7555
|
+
if (bridgeHubHopIndex !== -1 && traversalResult.hops[bridgeHubHopIndex].result.success) {
|
|
7556
|
+
traversalResult.hops[bridgeHubHopIndex].result = _objectSpread2(_objectSpread2({}, traversalResult.hops[bridgeHubHopIndex].result), {}, {
|
|
7557
|
+
fee: processedBridgeHub.fee
|
|
7558
|
+
});
|
|
7559
|
+
}
|
|
7560
|
+
}
|
|
7561
|
+
originWithCurrency = originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
|
|
7562
|
+
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(origin)
|
|
7563
|
+
}) : originDryRun;
|
|
7564
|
+
assetHubWithCurrency = (_traversalResult$asse = traversalResult.assetHub) !== null && _traversalResult$asse !== void 0 && _traversalResult$asse.success ? _objectSpread2(_objectSpread2({}, traversalResult.assetHub), {}, {
|
|
7565
|
+
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(assetHubChain)
|
|
7566
|
+
}) : traversalResult.assetHub;
|
|
7567
|
+
bridgeHubWithCurrency = processedBridgeHub !== null && processedBridgeHub !== void 0 && processedBridgeHub.success ? _objectSpread2(_objectSpread2({}, processedBridgeHub), {}, {
|
|
7568
|
+
currency: assets.getNativeAssetSymbol(bridgeHubChain)
|
|
7569
|
+
}) : processedBridgeHub;
|
|
7570
|
+
destinationWithCurrency = (_traversalResult$dest = traversalResult.destination) !== null && _traversalResult$dest !== void 0 && _traversalResult$dest.success ? _objectSpread2(_objectSpread2({}, traversalResult.destination), {}, {
|
|
7571
|
+
currency: asset === null || asset === void 0 ? void 0 : asset.symbol
|
|
7572
|
+
}) : traversalResult.destination;
|
|
7573
|
+
_getFailureInfo = getFailureInfo({
|
|
7574
|
+
destination: destinationWithCurrency,
|
|
7575
|
+
assetHub: assetHubWithCurrency,
|
|
7576
|
+
bridgeHub: bridgeHubWithCurrency
|
|
7577
|
+
}, traversalResult.hops), failureReason = _getFailureInfo.failureReason, failureChain = _getFailureInfo.failureChain;
|
|
7578
|
+
return _context2.a(2, {
|
|
7579
|
+
failureReason: failureReason,
|
|
7580
|
+
failureChain: failureChain,
|
|
7581
|
+
origin: originWithCurrency,
|
|
7582
|
+
assetHub: assetHubWithCurrency,
|
|
7583
|
+
bridgeHub: bridgeHubWithCurrency,
|
|
7584
|
+
destination: destinationWithCurrency,
|
|
7585
|
+
hops: traversalResult.hops
|
|
7586
|
+
});
|
|
7587
|
+
}
|
|
7588
|
+
}, _callee2);
|
|
7589
|
+
}));
|
|
7590
|
+
return function dryRunInternal(_x) {
|
|
7591
|
+
return _ref.apply(this, arguments);
|
|
7592
|
+
};
|
|
7593
|
+
}();
|
|
7594
|
+
|
|
7234
7595
|
var getReserveFeeFromHops = function getReserveFeeFromHops(hops) {
|
|
7235
7596
|
if (!hops || hops.length === 0 || !hops[0].result.success) {
|
|
7236
7597
|
return MIN_FEE;
|
|
@@ -7240,7 +7601,7 @@ var getReserveFeeFromHops = function getReserveFeeFromHops(hops) {
|
|
|
7240
7601
|
var FEE_PADDING_PERCENTAGE$1 = 40;
|
|
7241
7602
|
var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
7242
7603
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options) {
|
|
7243
|
-
var api, senderAddress, paraIdTo, assetInfo, currency, feeCurrency, address, feeAssetInfo, version,
|
|
7604
|
+
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;
|
|
7244
7605
|
return _regenerator().w(function (_context) {
|
|
7245
7606
|
while (1) switch (_context.n) {
|
|
7246
7607
|
case 0:
|
|
@@ -7252,25 +7613,6 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7252
7613
|
throw new InvalidParameterError('Please provide senderAddress');
|
|
7253
7614
|
case 1:
|
|
7254
7615
|
assertAddressIsString(address);
|
|
7255
|
-
if (!(feeCurrency && feeAssetInfo && !assets.isAssetEqual(assetInfo, feeAssetInfo))) {
|
|
7256
|
-
_context.n = 3;
|
|
7257
|
-
break;
|
|
7258
|
-
}
|
|
7259
|
-
_context.n = 2;
|
|
7260
|
-
return getAssetBalanceInternal({
|
|
7261
|
-
api: api,
|
|
7262
|
-
address: senderAddress,
|
|
7263
|
-
chain: chain,
|
|
7264
|
-
currency: feeCurrency
|
|
7265
|
-
});
|
|
7266
|
-
case 2:
|
|
7267
|
-
_t = _context.v;
|
|
7268
|
-
_context.n = 4;
|
|
7269
|
-
break;
|
|
7270
|
-
case 3:
|
|
7271
|
-
_t = undefined;
|
|
7272
|
-
case 4:
|
|
7273
|
-
feeAssetBalance = _t;
|
|
7274
7616
|
checkAmount = function checkAmount(fee) {
|
|
7275
7617
|
if (assetInfo.amount <= fee) {
|
|
7276
7618
|
throw new InvalidParameterError("Asset amount is too low, please increase the amount or use a different fee asset.");
|
|
@@ -7291,14 +7633,16 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7291
7633
|
senderAddress: senderAddress,
|
|
7292
7634
|
version: version,
|
|
7293
7635
|
paraIdTo: paraIdTo
|
|
7294
|
-
};
|
|
7636
|
+
}; // We mint 1000 units of feeAsset and use 100
|
|
7637
|
+
FEE_ASSET_AMOUNT = 100;
|
|
7638
|
+
feeAssetAmount = feeAssetInfo ? viem.parseUnits(FEE_ASSET_AMOUNT.toString(), feeAssetInfo.decimals) : MIN_FEE;
|
|
7295
7639
|
call = createExecuteCall(chain, createDirectExecuteXcm(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7296
7640
|
fees: {
|
|
7297
|
-
originFee:
|
|
7641
|
+
originFee: feeAssetAmount,
|
|
7298
7642
|
reserveFee: MIN_FEE
|
|
7299
7643
|
}
|
|
7300
7644
|
})), MAX_WEIGHT);
|
|
7301
|
-
_context.n =
|
|
7645
|
+
_context.n = 2;
|
|
7302
7646
|
return dryRunInternal({
|
|
7303
7647
|
api: api,
|
|
7304
7648
|
tx: api.callTxMethod(call),
|
|
@@ -7307,17 +7651,17 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7307
7651
|
senderAddress: senderAddress,
|
|
7308
7652
|
address: address,
|
|
7309
7653
|
currency: currency,
|
|
7310
|
-
feeAsset: feeCurrency
|
|
7654
|
+
feeAsset: feeCurrency,
|
|
7655
|
+
useRootOrigin: true
|
|
7311
7656
|
});
|
|
7312
|
-
case
|
|
7657
|
+
case 2:
|
|
7313
7658
|
dryRunResult = _context.v;
|
|
7314
7659
|
if (dryRunResult.origin.success) {
|
|
7315
|
-
_context.n =
|
|
7660
|
+
_context.n = 3;
|
|
7316
7661
|
break;
|
|
7317
7662
|
}
|
|
7318
7663
|
throw new DryRunFailedError(dryRunResult.failureReason);
|
|
7319
|
-
case
|
|
7320
|
-
validateHops(dryRunResult.hops);
|
|
7664
|
+
case 3:
|
|
7321
7665
|
originFeeEstimate = dryRunResult.origin.fee;
|
|
7322
7666
|
originFee = padFeeBy(originFeeEstimate, FEE_PADDING_PERCENTAGE$1);
|
|
7323
7667
|
reserveFeeEstimate = getReserveFeeFromHops(dryRunResult.hops);
|
|
@@ -7329,9 +7673,9 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7329
7673
|
reserveFee: reserveFee
|
|
7330
7674
|
}
|
|
7331
7675
|
}));
|
|
7332
|
-
_context.n =
|
|
7676
|
+
_context.n = 4;
|
|
7333
7677
|
return api.getXcmWeight(xcm);
|
|
7334
|
-
case
|
|
7678
|
+
case 4:
|
|
7335
7679
|
weight = _context.v;
|
|
7336
7680
|
return _context.a(2, createExecuteCall(chain, xcm, weight));
|
|
7337
7681
|
}
|
|
@@ -7622,7 +7966,7 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
7622
7966
|
}();
|
|
7623
7967
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
7624
7968
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
7625
|
-
var api, chain, exchangeChain, destChain, assetFrom, assetTo, currencyTo, senderAddress, recipientAddress, calculateMinAmountOut, version, internalOptions, dryRunParams, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex,
|
|
7969
|
+
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;
|
|
7626
7970
|
return _regenerator().w(function (_context3) {
|
|
7627
7971
|
while (1) switch (_context3.n) {
|
|
7628
7972
|
case 0:
|
|
@@ -7649,7 +7993,8 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7649
7993
|
swapConfig: {
|
|
7650
7994
|
currencyTo: currencyTo,
|
|
7651
7995
|
exchangeChain: exchangeChain
|
|
7652
|
-
}
|
|
7996
|
+
},
|
|
7997
|
+
useRootOrigin: true
|
|
7653
7998
|
}; // First dry run with dummy fees to extract actual fees
|
|
7654
7999
|
_context3.n = 2;
|
|
7655
8000
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
@@ -7668,38 +8013,8 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7668
8013
|
}));
|
|
7669
8014
|
case 3:
|
|
7670
8015
|
firstDryRunResult = _context3.v;
|
|
7671
|
-
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult.hops, exchangeChain, destChain);
|
|
7672
|
-
|
|
7673
|
-
requireExchangeSuccess = !hasOriginReserveHop;
|
|
7674
|
-
extractedFees = extractFeesFromDryRun(chain, firstDryRunResult, exchangeHopIndex, destChain, false); // If we need exchange to succeed but it failed, throw error
|
|
7675
|
-
if (!(requireExchangeSuccess && extractedFees.exchangeFee === 0n)) {
|
|
7676
|
-
_context3.n = 6;
|
|
7677
|
-
break;
|
|
7678
|
-
}
|
|
7679
|
-
if (!destChain) {
|
|
7680
|
-
_context3.n = 5;
|
|
7681
|
-
break;
|
|
7682
|
-
}
|
|
7683
|
-
if (!chain) {
|
|
7684
|
-
_context3.n = 4;
|
|
7685
|
-
break;
|
|
7686
|
-
}
|
|
7687
|
-
exchangeHop = firstDryRunResult.hops[exchangeHopIndex];
|
|
7688
|
-
if (exchangeHop.result.success) {
|
|
7689
|
-
_context3.n = 4;
|
|
7690
|
-
break;
|
|
7691
|
-
}
|
|
7692
|
-
throw new DryRunFailedError("Exchange hop failed when no origin reserve exists: ".concat(exchangeHop.result.failureReason || 'Unknown reason'));
|
|
7693
|
-
case 4:
|
|
7694
|
-
_context3.n = 6;
|
|
7695
|
-
break;
|
|
7696
|
-
case 5:
|
|
7697
|
-
if (!(firstDryRunResult.destination && !firstDryRunResult.destination.success)) {
|
|
7698
|
-
_context3.n = 6;
|
|
7699
|
-
break;
|
|
7700
|
-
}
|
|
7701
|
-
throw new DryRunFailedError("Exchange (destination) failed when no origin reserve exists: ".concat(firstDryRunResult.destination.failureReason || 'Unknown reason'));
|
|
7702
|
-
case 6:
|
|
8016
|
+
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult.hops, exchangeChain, destChain);
|
|
8017
|
+
extractedFees = extractFeesFromDryRun(chain, firstDryRunResult, exchangeHopIndex, destChain, false);
|
|
7703
8018
|
if (extractedFees.exchangeFee === 0n) {
|
|
7704
8019
|
// We set the exchange fee to non-zero value to prevent creating dummy tx
|
|
7705
8020
|
extractedFees.exchangeFee = MIN_FEE;
|
|
@@ -7709,67 +8024,27 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
7709
8024
|
validateAmount(BigInt(assetFrom.amount), totalFeesInFromAsset);
|
|
7710
8025
|
updatedAssetTo = assetTo;
|
|
7711
8026
|
if (!chain) {
|
|
7712
|
-
_context3.n =
|
|
8027
|
+
_context3.n = 5;
|
|
7713
8028
|
break;
|
|
7714
8029
|
}
|
|
7715
8030
|
amountAvailableForSwap = BigInt(assetFrom.amount) - totalFeesInFromAsset;
|
|
7716
|
-
_context3.n =
|
|
8031
|
+
_context3.n = 4;
|
|
7717
8032
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
7718
|
-
case
|
|
8033
|
+
case 4:
|
|
7719
8034
|
recalculatedMinAmountOut = _context3.v;
|
|
7720
8035
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7721
8036
|
amount: recalculatedMinAmountOut
|
|
7722
8037
|
});
|
|
7723
|
-
case
|
|
7724
|
-
_context3.n =
|
|
8038
|
+
case 5:
|
|
8039
|
+
_context3.n = 6;
|
|
7725
8040
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7726
8041
|
assetInfoTo: updatedAssetTo,
|
|
7727
8042
|
fees: extractedFees
|
|
7728
8043
|
}), firstDryRunResult.origin.success ? firstDryRunResult.origin.weight : undefined);
|
|
7729
|
-
case
|
|
8044
|
+
case 6:
|
|
7730
8045
|
_yield$createXcmAndCa2 = _context3.v;
|
|
7731
|
-
|
|
7732
|
-
_context3.n = 10;
|
|
7733
|
-
return executeDryRun(_objectSpread2(_objectSpread2({}, dryRunParams), {}, {
|
|
7734
|
-
tx: api.callTxMethod(secondCall)
|
|
7735
|
-
}));
|
|
7736
|
-
case 10:
|
|
7737
|
-
secondDryRunResult = _context3.v;
|
|
7738
|
-
hasHopsInSecondRun = secondDryRunResult.hops && secondDryRunResult.hops.length > 0;
|
|
7739
|
-
isOnExchangeChain = chain === exchangeChain;
|
|
7740
|
-
if (hasHopsInSecondRun && !isOnExchangeChain) {
|
|
7741
|
-
finalExchangeHopIndex = findExchangeHopIndex(chain, secondDryRunResult.hops, exchangeChain, destChain);
|
|
7742
|
-
finalFees = extractFeesFromDryRun(chain, secondDryRunResult, finalExchangeHopIndex, destChain, true);
|
|
7743
|
-
} else {
|
|
7744
|
-
finalFees = extractFeesFromDryRun(chain, secondDryRunResult, 0, destChain, true);
|
|
7745
|
-
}
|
|
7746
|
-
// Validate that we have enough after accounting for final fees
|
|
7747
|
-
finalTotalFeesInFromAsset = chain ? finalFees.originReserveFee + finalFees.exchangeFee : 0n;
|
|
7748
|
-
validateAmount(BigInt(assetFrom.amount), finalTotalFeesInFromAsset);
|
|
7749
|
-
// If the final fees are different, we might need one more iteration
|
|
7750
|
-
if (!(finalFees.exchangeFee !== extractedFees.exchangeFee || finalFees.originReserveFee !== extractedFees.originReserveFee)) {
|
|
7751
|
-
_context3.n = 13;
|
|
7752
|
-
break;
|
|
7753
|
-
}
|
|
7754
|
-
finalAmountAvailableForSwap = BigInt(assetFrom.amount) - finalTotalFeesInFromAsset;
|
|
7755
|
-
_context3.n = 11;
|
|
7756
|
-
return calculateMinAmountOut(finalAmountAvailableForSwap);
|
|
7757
|
-
case 11:
|
|
7758
|
-
finalMinAmountOut = _context3.v;
|
|
7759
|
-
finalAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
7760
|
-
amount: finalMinAmountOut
|
|
7761
|
-
});
|
|
7762
|
-
_context3.n = 12;
|
|
7763
|
-
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
7764
|
-
assetInfoTo: finalAssetTo,
|
|
7765
|
-
fees: finalFees
|
|
7766
|
-
}), secondDryRunResult.origin.success ? secondDryRunResult.origin.weight : undefined);
|
|
7767
|
-
case 12:
|
|
7768
|
-
_yield$createXcmAndCa3 = _context3.v;
|
|
7769
|
-
finalCall = _yield$createXcmAndCa3.call;
|
|
8046
|
+
finalCall = _yield$createXcmAndCa2.call;
|
|
7770
8047
|
return _context3.a(2, api.callTxMethod(finalCall));
|
|
7771
|
-
case 13:
|
|
7772
|
-
return _context3.a(2, api.callTxMethod(secondCall));
|
|
7773
8048
|
}
|
|
7774
8049
|
}, _callee3);
|
|
7775
8050
|
}));
|
|
@@ -10636,7 +10911,7 @@ var Moonbeam = /*#__PURE__*/function (_Parachain) {
|
|
|
10636
10911
|
case 3:
|
|
10637
10912
|
location = this.getLocation(assetInfo, scenario);
|
|
10638
10913
|
return _context.a(2, transferPolkadotXcm(_objectSpread2(_objectSpread2({}, input), {}, {
|
|
10639
|
-
asset: createAsset(version, assetInfo.amount, location)
|
|
10914
|
+
asset: createAsset(version, assetInfo.amount, localizeLocation(this.chain, location))
|
|
10640
10915
|
}), 'transfer_assets', 'Unlimited'));
|
|
10641
10916
|
}
|
|
10642
10917
|
}, _callee, this);
|
|
@@ -12235,15 +12510,19 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
12235
12510
|
key: "getTransferableAmount",
|
|
12236
12511
|
value: (function () {
|
|
12237
12512
|
var _getTransferableAmount2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
12238
|
-
var _this$_options7, from, to, senderAddress, currency, feeAsset;
|
|
12513
|
+
var _this$_options7, from, to, senderAddress, currency, feeAsset, tx;
|
|
12239
12514
|
return _regenerator().w(function (_context8) {
|
|
12240
12515
|
while (1) switch (_context8.n) {
|
|
12241
12516
|
case 0:
|
|
12242
12517
|
_this$_options7 = this._options, from = _this$_options7.from, to = _this$_options7.to, senderAddress = _this$_options7.senderAddress, currency = _this$_options7.currency, feeAsset = _this$_options7.feeAsset;
|
|
12243
12518
|
assertToIsString(to);
|
|
12519
|
+
_context8.n = 1;
|
|
12520
|
+
return this.build();
|
|
12521
|
+
case 1:
|
|
12522
|
+
tx = _context8.v;
|
|
12244
12523
|
return _context8.a(2, getTransferableAmount({
|
|
12245
12524
|
api: this.api,
|
|
12246
|
-
|
|
12525
|
+
tx: tx,
|
|
12247
12526
|
origin: from,
|
|
12248
12527
|
destination: to,
|
|
12249
12528
|
senderAddress: senderAddress,
|
|
@@ -12371,6 +12650,7 @@ var Builder = function Builder(api) {
|
|
|
12371
12650
|
};
|
|
12372
12651
|
|
|
12373
12652
|
exports.AssetClaimBuilder = AssetClaimBuilder;
|
|
12653
|
+
exports.AssetsPallet = AssetsPallet;
|
|
12374
12654
|
exports.BridgeHaltedError = BridgeHaltedError;
|
|
12375
12655
|
exports.Builder = Builder;
|
|
12376
12656
|
exports.ChainNotSupportedError = ChainNotSupportedError;
|
|
@@ -12436,6 +12716,7 @@ exports.getOriginFeeDetails = getOriginFeeDetails;
|
|
|
12436
12716
|
exports.getOriginFeeDetailsInternal = getOriginFeeDetailsInternal;
|
|
12437
12717
|
exports.getOriginXcmFee = getOriginXcmFee;
|
|
12438
12718
|
exports.getOriginXcmFeeEstimate = getOriginXcmFeeEstimate;
|
|
12719
|
+
exports.getOriginXcmFeeInternal = getOriginXcmFeeInternal;
|
|
12439
12720
|
exports.getParaEthTransferFees = getParaEthTransferFees;
|
|
12440
12721
|
exports.getParaId = getParaId;
|
|
12441
12722
|
exports.getRelayChainOf = getRelayChainOf;
|
|
@@ -12465,6 +12746,7 @@ exports.transferRelayToPara = transferRelayToPara;
|
|
|
12465
12746
|
exports.traverseXcmHops = traverseXcmHops;
|
|
12466
12747
|
exports.validateAddress = validateAddress;
|
|
12467
12748
|
exports.verifyEdOnDestination = verifyEdOnDestination;
|
|
12749
|
+
exports.wrapTxBypass = wrapTxBypass;
|
|
12468
12750
|
Object.keys(assets).forEach(function (k) {
|
|
12469
12751
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
12470
12752
|
enumerable: true,
|