@paraspell/sdk-core 11.12.1 → 11.12.3
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 +385 -331
- package/dist/index.d.ts +211 -207
- package/dist/index.mjs +387 -333
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { blake2b } from '@noble/hashes/blake2';
|
|
2
|
-
import { isChainEvm, getAssetsObject, InvalidCurrencyError, isForeignAsset, extractAssetLocation, findAssetInfoOrThrow, getNativeAssetSymbol, getOtherAssets, isAssetEqual, findNativeAssetInfoOrThrow, findAssetInfo, isTAsset, getExistentialDepositOrThrow, isSymbolMatch, hasDryRunSupport, isOverrideLocationSpecifier,
|
|
2
|
+
import { isChainEvm, getAssetsObject, InvalidCurrencyError, isForeignAsset, extractAssetLocation, findAssetInfoOrThrow, getNativeAssetSymbol, getOtherAssets, isAssetEqual, findNativeAssetInfoOrThrow, findAssetInfo, isTAsset, getExistentialDepositOrThrow, isSymbolMatch, hasDryRunSupport, findAssetOnDestOrThrow, findAssetInfoOnDest, hasSupportForAsset, isOverrideLocationSpecifier, getRelayChainSymbol, isSymbolSpecifier, findAssetInfoByLoc, Native, hasXcmPaymentApiSupport, getExistentialDeposit, findNativeAssetInfo, isAssetXcEqual, normalizeLocation, getEdFromAssetOrThrow, normalizeSymbol } from '@paraspell/assets';
|
|
3
3
|
export * from '@paraspell/assets';
|
|
4
4
|
import { base58 } from '@scure/base';
|
|
5
5
|
import { isAddress, parseUnits as parseUnits$1, formatUnits as formatUnits$1, createPublicClient, http, getContract, pad, toHex, getAddress, concat, keccak256 } from 'viem';
|
|
6
6
|
import { getSupportedPalletsDetails, getDefaultPallet, getSupportedPallets, getNativeAssetsPallet, getOtherAssetsPallets } from '@paraspell/pallets';
|
|
7
7
|
export * from '@paraspell/pallets';
|
|
8
|
-
import { replaceBigInt, isTLocation, Version, hasJunction, getJunctionValue, isRelayChain, Parents,
|
|
8
|
+
import { replaceBigInt, isTLocation, Version, hasJunction, getJunctionValue, isRelayChain, Parents, isExternalChain, deepEqual, PARACHAINS, isSubstrateBridge, isTrustedChain, isSystemChain } from '@paraspell/sdk-common';
|
|
9
9
|
export * from '@paraspell/sdk-common';
|
|
10
10
|
import { moonbeam, moonriver, mainnet } from 'viem/chains';
|
|
11
11
|
|
|
@@ -3091,7 +3091,13 @@ var getChainLocation = function getChainLocation(chain, destChain) {
|
|
|
3091
3091
|
* @param location - The location to localize
|
|
3092
3092
|
* @returns The localized location
|
|
3093
3093
|
*/
|
|
3094
|
-
var localizeLocation = function localizeLocation(chain, location) {
|
|
3094
|
+
var localizeLocation = function localizeLocation(chain, location, origin) {
|
|
3095
|
+
var targetRelay = isExternalChain(chain) ? undefined : getRelayChainOf(chain).toLowerCase();
|
|
3096
|
+
var originRelay = origin && !isExternalChain(origin) ? getRelayChainOf(origin).toLowerCase() : undefined;
|
|
3097
|
+
var ecosystemDiffers = originRelay !== targetRelay;
|
|
3098
|
+
if (origin && ecosystemDiffers && location.parents === Parents.TWO && originRelay !== undefined && targetRelay !== undefined && deepEqual(getJunctionValue(location, 'GlobalConsensus'), _defineProperty({}, targetRelay, null))) {
|
|
3099
|
+
return RELAY_LOCATION;
|
|
3100
|
+
}
|
|
3095
3101
|
var newInterior = location.interior;
|
|
3096
3102
|
var parachainRemoved = false;
|
|
3097
3103
|
if (location.interior !== 'Here') {
|
|
@@ -3115,6 +3121,20 @@ var localizeLocation = function localizeLocation(chain, location) {
|
|
|
3115
3121
|
newInterior = _defineProperty({}, "X".concat(filteredJunctions.length), filteredJunctions);
|
|
3116
3122
|
}
|
|
3117
3123
|
}
|
|
3124
|
+
var isOriginRelayHere = deepEqual(location, RELAY_LOCATION);
|
|
3125
|
+
var hasGlobalConsensus = hasJunction(location, 'GlobalConsensus');
|
|
3126
|
+
if (origin && ecosystemDiffers && isOriginRelayHere && !hasGlobalConsensus && originRelay !== undefined) {
|
|
3127
|
+
return {
|
|
3128
|
+
parents: Parents.TWO,
|
|
3129
|
+
interior: {
|
|
3130
|
+
X2: [{
|
|
3131
|
+
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
3132
|
+
}, {
|
|
3133
|
+
Parachain: getParaId(origin)
|
|
3134
|
+
}]
|
|
3135
|
+
}
|
|
3136
|
+
};
|
|
3137
|
+
}
|
|
3118
3138
|
var shouldSetParentsToZero = parachainRemoved || newInterior === 'Here' && isRelayChain(chain);
|
|
3119
3139
|
return {
|
|
3120
3140
|
parents: shouldSetParentsToZero ? Parents.ZERO : location.parents,
|
|
@@ -3243,13 +3263,26 @@ var constructRelayToParaParameters = function constructRelayToParaParameters(_re
|
|
|
3243
3263
|
};
|
|
3244
3264
|
|
|
3245
3265
|
var createDestination = function createDestination(version, origin, destination, chainId, junction, parents) {
|
|
3266
|
+
var isLocDestination = isTLocation(destination);
|
|
3267
|
+
var isSubBridge = !isLocDestination && !isExternalChain(destination) && isSubstrateBridge(origin, destination);
|
|
3268
|
+
if (isSubBridge) {
|
|
3269
|
+
return {
|
|
3270
|
+
parents: Parents.TWO,
|
|
3271
|
+
interior: {
|
|
3272
|
+
X2: [{
|
|
3273
|
+
GlobalConsensus: getRelayChainOf(destination)
|
|
3274
|
+
}, {
|
|
3275
|
+
Parachain: chainId
|
|
3276
|
+
}]
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
}
|
|
3246
3280
|
var scenario = resolveScenario(origin, destination);
|
|
3247
3281
|
var parentsResolved = parents !== null && parents !== void 0 ? parents : scenario === 'RelayToPara' ? Parents.ZERO : Parents.ONE;
|
|
3248
3282
|
var interior = scenario === 'ParaToRelay' ? 'Here' : createX1Payload(version, junction !== null && junction !== void 0 ? junction : {
|
|
3249
3283
|
Parachain: chainId
|
|
3250
3284
|
});
|
|
3251
|
-
|
|
3252
|
-
return isLocationDestination ? destination : {
|
|
3285
|
+
return isLocDestination ? destination : {
|
|
3253
3286
|
parents: parentsResolved,
|
|
3254
3287
|
interior: interior
|
|
3255
3288
|
};
|
|
@@ -3258,19 +3291,6 @@ var createVersionedDestination = function createVersionedDestination(version, or
|
|
|
3258
3291
|
var plainDestination = createDestination(version, origin, destination, chainId, junction, parents);
|
|
3259
3292
|
return addXcmVersionHeader(plainDestination, version);
|
|
3260
3293
|
};
|
|
3261
|
-
var createBridgeDestination = function createBridgeDestination(ecosystem, destination, chainId) {
|
|
3262
|
-
var location = {
|
|
3263
|
-
parents: Parents.TWO,
|
|
3264
|
-
interior: {
|
|
3265
|
-
X2: [{
|
|
3266
|
-
GlobalConsensus: ecosystem
|
|
3267
|
-
}, {
|
|
3268
|
-
Parachain: chainId
|
|
3269
|
-
}]
|
|
3270
|
-
}
|
|
3271
|
-
};
|
|
3272
|
-
return isTLocation(destination) ? destination : location;
|
|
3273
|
-
};
|
|
3274
3294
|
var resolveTChainFromLocation = function resolveTChainFromLocation(relaychain, location) {
|
|
3275
3295
|
var _PARACHAINS$find;
|
|
3276
3296
|
var parachainId = getJunctionValue(location, 'Parachain');
|
|
@@ -3650,9 +3670,7 @@ var handleExecuteTransfer = /*#__PURE__*/function () {
|
|
|
3650
3670
|
assertSenderAddress(senderAddress);
|
|
3651
3671
|
assertAddressIsString(address);
|
|
3652
3672
|
checkAmount = function checkAmount(fee) {
|
|
3653
|
-
if (assetInfo.amount <= fee)
|
|
3654
|
-
throw new InvalidParameterError("Asset amount is too low, please increase the amount or use a different fee asset.");
|
|
3655
|
-
}
|
|
3673
|
+
if (assetInfo.amount <= fee) throw new AmountTooLowError();
|
|
3656
3674
|
};
|
|
3657
3675
|
checkAmount(MIN_FEE);
|
|
3658
3676
|
destChain = getTChain(paraIdTo, getRelayChainOf(chain));
|
|
@@ -4501,6 +4519,204 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
4501
4519
|
};
|
|
4502
4520
|
}();
|
|
4503
4521
|
|
|
4522
|
+
var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
|
|
4523
|
+
return assetCheckEnabled ? findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null) : null;
|
|
4524
|
+
};
|
|
4525
|
+
|
|
4526
|
+
var resolveHopAsset = function resolveHopAsset(_ref) {
|
|
4527
|
+
var _asset$location, _findAssetInfoOnDest;
|
|
4528
|
+
var originChain = _ref.originChain,
|
|
4529
|
+
currentChain = _ref.currentChain,
|
|
4530
|
+
swapConfig = _ref.swapConfig,
|
|
4531
|
+
asset = _ref.asset,
|
|
4532
|
+
hasPassedExchange = _ref.hasPassedExchange,
|
|
4533
|
+
currency = _ref.currency;
|
|
4534
|
+
var isExternalAsset = ((_asset$location = asset.location) === null || _asset$location === void 0 ? void 0 : _asset$location.parents) === Parents.TWO;
|
|
4535
|
+
if (isExternalAsset) {
|
|
4536
|
+
return findNativeAssetInfoOrThrow(getRelayChainOf(currentChain));
|
|
4537
|
+
}
|
|
4538
|
+
if (hasPassedExchange && swapConfig && currentChain !== swapConfig.exchangeChain) {
|
|
4539
|
+
return findAssetOnDestOrThrow(swapConfig.exchangeChain, currentChain, swapConfig.currencyTo);
|
|
4540
|
+
}
|
|
4541
|
+
return (_findAssetInfoOnDest = findAssetInfoOnDest(originChain, currentChain, currency)) !== null && _findAssetInfoOnDest !== void 0 ? _findAssetInfoOnDest : asset;
|
|
4542
|
+
};
|
|
4543
|
+
|
|
4544
|
+
var validateBridgeAsset = function validateBridgeAsset(origin, destination, asset, currency, isBridge) {
|
|
4545
|
+
var _asset$location;
|
|
4546
|
+
if (!asset || isTLocation(destination) || isExternalChain(destination) || !isBridge) {
|
|
4547
|
+
return;
|
|
4548
|
+
}
|
|
4549
|
+
var nativeAsset = findNativeAssetInfoOrThrow(origin);
|
|
4550
|
+
var isNativeAsset = isAssetEqual(asset, nativeAsset);
|
|
4551
|
+
var ecosystem = getRelayChainOf(destination).toLowerCase();
|
|
4552
|
+
var isBridgedAsset = ((_asset$location = asset.location) === null || _asset$location === void 0 ? void 0 : _asset$location.parents) === Parents.TWO && deepEqual(getJunctionValue(asset.location, 'GlobalConsensus'), _defineProperty({}, ecosystem, null));
|
|
4553
|
+
if (!(isNativeAsset || isBridgedAsset)) {
|
|
4554
|
+
throw new InvalidCurrencyError("Substrate bridge does not support currency ".concat(JSON.stringify(currency, replaceBigInt), "."));
|
|
4555
|
+
}
|
|
4556
|
+
};
|
|
4557
|
+
var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
|
|
4558
|
+
var origin = _ref.from,
|
|
4559
|
+
destination = _ref.to,
|
|
4560
|
+
currency = _ref.currency;
|
|
4561
|
+
var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
|
|
4562
|
+
var isLocationDestination = _typeof(destination) === 'object';
|
|
4563
|
+
if (!isBridge && !isRelayDestination && !isLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !hasSupportForAsset(destination, asset.symbol)) {
|
|
4564
|
+
throw new InvalidCurrencyError("Destination chain ".concat(destination, " does not support currency ").concat(JSON.stringify(currency, replaceBigInt), "."));
|
|
4565
|
+
}
|
|
4566
|
+
if (asset === null && assetCheckEnabled) {
|
|
4567
|
+
throwUnsupportedCurrency(currency, origin);
|
|
4568
|
+
}
|
|
4569
|
+
validateBridgeAsset(origin, destination, asset, currency, isBridge);
|
|
4570
|
+
};
|
|
4571
|
+
|
|
4572
|
+
var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset) {
|
|
4573
|
+
var api = options.api,
|
|
4574
|
+
currency = options.currency,
|
|
4575
|
+
feeAsset = options.feeAsset,
|
|
4576
|
+
origin = options.from,
|
|
4577
|
+
destination = options.to;
|
|
4578
|
+
if ('location' in currency && isOverrideLocationSpecifier(currency.location)) {
|
|
4579
|
+
return currency.location.value;
|
|
4580
|
+
}
|
|
4581
|
+
if (Array.isArray(currency)) {
|
|
4582
|
+
if (!feeAsset) {
|
|
4583
|
+
throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
|
|
4584
|
+
}
|
|
4585
|
+
if ('location' in feeAsset && isOverrideLocationSpecifier(feeAsset.location)) {
|
|
4586
|
+
throw new InvalidCurrencyError('Fee asset cannot be an overridden location specifier');
|
|
4587
|
+
}
|
|
4588
|
+
if (currency.every(function (asset) {
|
|
4589
|
+
return isTAsset(asset);
|
|
4590
|
+
})) {
|
|
4591
|
+
if (!feeAsset) {
|
|
4592
|
+
throw new InvalidCurrencyError('Fee asset not provided');
|
|
4593
|
+
}
|
|
4594
|
+
if (!('location' in feeAsset)) {
|
|
4595
|
+
throw new InvalidCurrencyError('Fee asset must be specified by location when using raw overridden multi assets');
|
|
4596
|
+
}
|
|
4597
|
+
return currency.map(function (asset) {
|
|
4598
|
+
var ml = extractAssetLocation(asset);
|
|
4599
|
+
return _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
4600
|
+
fun: {
|
|
4601
|
+
Fungible: BigInt(asset.fun.Fungible)
|
|
4602
|
+
},
|
|
4603
|
+
isFeeAsset: deepEqual(ml, feeAsset.location)
|
|
4604
|
+
});
|
|
4605
|
+
});
|
|
4606
|
+
}
|
|
4607
|
+
// MultiAsset is an array of TCurrencyCore, search for assets
|
|
4608
|
+
var assets = currency.map(function (currency) {
|
|
4609
|
+
if (currency.amount === AMOUNT_ALL) {
|
|
4610
|
+
throw new InvalidCurrencyError('Multi assets cannot use amount all. Please specify amount.');
|
|
4611
|
+
}
|
|
4612
|
+
var asset = findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null);
|
|
4613
|
+
if (!asset) {
|
|
4614
|
+
throw new InvalidCurrencyError("Origin chain ".concat(origin, " does not support currency ").concat(JSON.stringify(currency)));
|
|
4615
|
+
}
|
|
4616
|
+
assertHasLocation(asset);
|
|
4617
|
+
if (!resolvedFeeAsset) {
|
|
4618
|
+
throw new InvalidCurrencyError('Fee asset not found');
|
|
4619
|
+
}
|
|
4620
|
+
validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
|
|
4621
|
+
var version = getChainVersion(origin);
|
|
4622
|
+
var abstractedAmount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
4623
|
+
return _objectSpread2({
|
|
4624
|
+
isFeeAsset: isAssetEqual(resolvedFeeAsset, asset)
|
|
4625
|
+
}, createAsset(version, abstractedAmount, asset.location));
|
|
4626
|
+
});
|
|
4627
|
+
if (assets.filter(function (asset) {
|
|
4628
|
+
return asset.isFeeAsset;
|
|
4629
|
+
}).length > 1) {
|
|
4630
|
+
throw new InvalidCurrencyError("Fee asset matches multiple assets in multiassets");
|
|
4631
|
+
}
|
|
4632
|
+
if (assets.filter(function (asset) {
|
|
4633
|
+
return asset.isFeeAsset;
|
|
4634
|
+
}).length === 0) {
|
|
4635
|
+
throw new InvalidCurrencyError("Fee asset not found in multiassets");
|
|
4636
|
+
}
|
|
4637
|
+
return assets;
|
|
4638
|
+
}
|
|
4639
|
+
return undefined;
|
|
4640
|
+
};
|
|
4641
|
+
|
|
4642
|
+
var selectXcmVersion = function selectXcmVersion(forcedVersion, originVersion, destMaxVersion) {
|
|
4643
|
+
if (forcedVersion) return forcedVersion;
|
|
4644
|
+
var destVersion = destMaxVersion !== null && destMaxVersion !== void 0 ? destMaxVersion : originVersion;
|
|
4645
|
+
return destVersion < originVersion ? destVersion : originVersion;
|
|
4646
|
+
};
|
|
4647
|
+
|
|
4648
|
+
var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency) {
|
|
4649
|
+
if (isRelayChain(origin)) return true;
|
|
4650
|
+
var isMultipleAssets = Array.isArray(currency);
|
|
4651
|
+
var hasOverriddenLocation = 'location' in currency && isOverrideLocationSpecifier(currency.location);
|
|
4652
|
+
return !(isMultipleAssets || hasOverriddenLocation);
|
|
4653
|
+
};
|
|
4654
|
+
|
|
4655
|
+
var validateAddress = function validateAddress(address, chain) {
|
|
4656
|
+
var isDestination = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
4657
|
+
if (isTLocation(address)) return;
|
|
4658
|
+
var isEvm = isChainEvm(chain);
|
|
4659
|
+
var isEthereumAddress = isAddress(address);
|
|
4660
|
+
if (isEvm) {
|
|
4661
|
+
if (!isEthereumAddress) {
|
|
4662
|
+
throw new InvalidAddressError("".concat(isDestination ? 'Destination chain' : 'Chain', " is an EVM chain, but the address provided is not a valid Ethereum address."));
|
|
4663
|
+
}
|
|
4664
|
+
} else {
|
|
4665
|
+
if (isEthereumAddress) {
|
|
4666
|
+
throw new InvalidAddressError("EVM address provided but ".concat(isDestination ? 'destination ' : '', "chain is not an EVM chain."));
|
|
4667
|
+
}
|
|
4668
|
+
}
|
|
4669
|
+
};
|
|
4670
|
+
|
|
4671
|
+
var validateDestinationAddress = function validateDestinationAddress(address, destination) {
|
|
4672
|
+
if (typeof address === 'string' && !isTLocation(destination)) {
|
|
4673
|
+
validateAddress(address, destination);
|
|
4674
|
+
}
|
|
4675
|
+
};
|
|
4676
|
+
|
|
4677
|
+
var validateCurrency = function validateCurrency(currency, feeAsset) {
|
|
4678
|
+
if (Array.isArray(currency)) {
|
|
4679
|
+
if (currency.length === 0) {
|
|
4680
|
+
throw new InvalidCurrencyError('Overridden assets cannot be empty');
|
|
4681
|
+
}
|
|
4682
|
+
if (currency.length === 1) {
|
|
4683
|
+
throw new InvalidCurrencyError('Please provide more than one asset');
|
|
4684
|
+
}
|
|
4685
|
+
if (currency.length > 1 && !currency.every(function (asset) {
|
|
4686
|
+
return isTAsset(asset);
|
|
4687
|
+
}) && !feeAsset) {
|
|
4688
|
+
throw new InvalidCurrencyError('Overridden assets cannot be used without specifying fee asset');
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
4691
|
+
};
|
|
4692
|
+
var validateDestination = function validateDestination(origin, destination) {
|
|
4693
|
+
if (isRelayChain(origin) && !isTLocation(destination) && isRelayChain(destination) && origin !== destination) {
|
|
4694
|
+
throw new IncompatibleChainsError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
|
|
4695
|
+
}
|
|
4696
|
+
var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam', 'Mythos'];
|
|
4697
|
+
if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
|
|
4698
|
+
throw new IncompatibleChainsError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
|
|
4699
|
+
}
|
|
4700
|
+
var isLocationDestination = _typeof(destination) === 'object';
|
|
4701
|
+
var isBridge = !isTLocation(destination) && isSubstrateBridge(origin, destination);
|
|
4702
|
+
var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
|
|
4703
|
+
if (!isRelayDestination && !isLocationDestination) {
|
|
4704
|
+
var originRelayChainSymbol = getRelayChainSymbol(origin);
|
|
4705
|
+
var destinationRelayChainSymbol = getRelayChainSymbol(destination);
|
|
4706
|
+
if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
|
|
4707
|
+
throw new IncompatibleChainsError();
|
|
4708
|
+
}
|
|
4709
|
+
}
|
|
4710
|
+
};
|
|
4711
|
+
var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
|
|
4712
|
+
if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
|
|
4713
|
+
throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
|
|
4714
|
+
}
|
|
4715
|
+
if (!assetCheckEnabled && 'id' in currency) {
|
|
4716
|
+
throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
|
|
4717
|
+
}
|
|
4718
|
+
};
|
|
4719
|
+
|
|
4504
4720
|
var getFailureInfo$1 = function getFailureInfo(result) {
|
|
4505
4721
|
var orderedChecks = [{
|
|
4506
4722
|
chain: 'origin',
|
|
@@ -5333,19 +5549,19 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
5333
5549
|
initialForwardedXcms = originDryModified.forwardedXcms, initialDestParaId = originDryModified.destParaId;
|
|
5334
5550
|
processHop = /*#__PURE__*/function () {
|
|
5335
5551
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
5336
|
-
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopAsset,
|
|
5552
|
+
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopAsset, hopDryRun;
|
|
5337
5553
|
return _regenerator().w(function (_context) {
|
|
5338
5554
|
while (1) switch (_context.n) {
|
|
5339
5555
|
case 0:
|
|
5340
5556
|
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange;
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
}
|
|
5557
|
+
hopAsset = resolveHopAsset({
|
|
5558
|
+
originChain: origin,
|
|
5559
|
+
currentChain: currentChain,
|
|
5560
|
+
asset: currentAsset,
|
|
5561
|
+
currency: currency,
|
|
5562
|
+
swapConfig: swapConfig,
|
|
5563
|
+
hasPassedExchange: hasPassedExchange
|
|
5564
|
+
});
|
|
5349
5565
|
if (hasDryRunSupport(currentChain)) {
|
|
5350
5566
|
_context.n = 1;
|
|
5351
5567
|
break;
|
|
@@ -5909,22 +6125,6 @@ var handleToAhTeleport = /*#__PURE__*/function () {
|
|
|
5909
6125
|
};
|
|
5910
6126
|
}();
|
|
5911
6127
|
|
|
5912
|
-
var validateAddress = function validateAddress(address, chain) {
|
|
5913
|
-
var isDestination = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
5914
|
-
if (isTLocation(address)) return;
|
|
5915
|
-
var isEvm = isChainEvm(chain);
|
|
5916
|
-
var isEthereumAddress = isAddress(address);
|
|
5917
|
-
if (isEvm) {
|
|
5918
|
-
if (!isEthereumAddress) {
|
|
5919
|
-
throw new InvalidAddressError("".concat(isDestination ? 'Destination chain' : 'Chain', " is an EVM chain, but the address provided is not a valid Ethereum address."));
|
|
5920
|
-
}
|
|
5921
|
-
} else {
|
|
5922
|
-
if (isEthereumAddress) {
|
|
5923
|
-
throw new InvalidAddressError("EVM address provided but ".concat(isDestination ? 'destination ' : '', "chain is not an EVM chain."));
|
|
5924
|
-
}
|
|
5925
|
-
}
|
|
5926
|
-
};
|
|
5927
|
-
|
|
5928
6128
|
var resolveLocationFromDest = function resolveLocationFromDest(destination, asset) {
|
|
5929
6129
|
if (_typeof(destination) === 'object') return destination;
|
|
5930
6130
|
if (isRelayChain(destination)) return DOT_LOCATION;
|
|
@@ -6231,15 +6431,16 @@ var Parachain = /*#__PURE__*/function () {
|
|
|
6231
6431
|
}, {
|
|
6232
6432
|
key: "canUseXTokens",
|
|
6233
6433
|
value: function canUseXTokens(options) {
|
|
6434
|
+
var _asset$location;
|
|
6234
6435
|
var asset = options.assetInfo;
|
|
6235
|
-
var isExternalAsset =
|
|
6436
|
+
var isExternalAsset = ((_asset$location = asset.location) === null || _asset$location === void 0 ? void 0 : _asset$location.parents) === Parents.TWO;
|
|
6236
6437
|
return !isExternalAsset && !this.shouldUseNativeAssetTeleport(options);
|
|
6237
6438
|
}
|
|
6238
6439
|
}, {
|
|
6239
6440
|
key: "transfer",
|
|
6240
6441
|
value: function () {
|
|
6241
6442
|
var _transfer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(sendOptions) {
|
|
6242
|
-
var api, asset, currency, feeAsset, feeCurrency, address, destination, paraIdTo, overriddenAsset, version, senderAddress, ahAddress, pallet, method, scenario, paraId, destChain, isLocalTransfer, isRelayAsset, supportsTypeThen, useTypeAndThen, isBifrostOrigin, isJamtonOrigin, isAssetHubDest, useMultiAssets, input, options, shouldUseTeleport, isAhToOtherPara, isOtherParaToAh, isAllowedAhTransfer,
|
|
6443
|
+
var api, asset, currency, feeAsset, feeCurrency, address, destination, paraIdTo, overriddenAsset, version, senderAddress, ahAddress, pallet, method, scenario, paraId, destChain, isLocalTransfer, isRelayAsset, supportsTypeThen, isSubBridge, useTypeAndThen, isBifrostOrigin, isJamtonOrigin, isAssetHubDest, useMultiAssets, input, _asset$location2, options, shouldUseTeleport, isAhToOtherPara, isOtherParaToAh, isAllowedAhTransfer, isAHOrigin, isAHDest, isExternalAsset, isEthDest, isExternalAssetViaAh, isExternalAssetToAh, call, _t;
|
|
6243
6444
|
return _regenerator().w(function (_context) {
|
|
6244
6445
|
while (1) switch (_context.n) {
|
|
6245
6446
|
case 0:
|
|
@@ -6273,7 +6474,8 @@ var Parachain = /*#__PURE__*/function () {
|
|
|
6273
6474
|
}
|
|
6274
6475
|
throw new InvalidParameterError('Relaychain assets can only be transferred using the type-and-then method which is not supported by this chain');
|
|
6275
6476
|
case 4:
|
|
6276
|
-
|
|
6477
|
+
isSubBridge = !isTLocation(destination) && isSubstrateBridge(this.chain, destination);
|
|
6478
|
+
useTypeAndThen = isRelayAsset && supportsTypeThen && destChain && !feeAsset && (!isTrustedChain(this.chain) || !isTrustedChain(destChain)) || isSubBridge;
|
|
6277
6479
|
if (!(supportsXTokens(this) && this.canUseXTokens(sendOptions) && !useTypeAndThen)) {
|
|
6278
6480
|
_context.n = 6;
|
|
6279
6481
|
break;
|
|
@@ -6366,17 +6568,17 @@ var Parachain = /*#__PURE__*/function () {
|
|
|
6366
6568
|
}
|
|
6367
6569
|
throw new InvalidParameterError('Astar system asset transfers are temporarily disabled');
|
|
6368
6570
|
case 9:
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
isExternalAsset = asset.location
|
|
6571
|
+
isAHOrigin = this.chain.includes('AssetHub');
|
|
6572
|
+
isAHDest = !isTLocation(destination) && destination.includes('AssetHub'); // Handle common cases
|
|
6573
|
+
isExternalAsset = ((_asset$location2 = asset.location) === null || _asset$location2 === void 0 ? void 0 : _asset$location2.parents) === Parents.TWO;
|
|
6372
6574
|
isEthDest = destination === 'Ethereum'; // External asset - Any origin to any dest via AH - DestinationReserve - multiple instructions
|
|
6373
|
-
isExternalAssetViaAh = isExternalAsset && !
|
|
6374
|
-
isExternalAssetToAh = isExternalAsset &&
|
|
6575
|
+
isExternalAssetViaAh = isExternalAsset && !isAHOrigin && !isAHDest && !isEthDest && !feeAsset; // External asset - Any origin to AHP - DestinationReserve - one DepositAsset instruction
|
|
6576
|
+
isExternalAssetToAh = isExternalAsset && isAHDest && !isAHOrigin && !isEthDest && !feeAsset;
|
|
6375
6577
|
if (!(isExternalAssetViaAh || isExternalAssetToAh || useTypeAndThen)) {
|
|
6376
6578
|
_context.n = 15;
|
|
6377
6579
|
break;
|
|
6378
6580
|
}
|
|
6379
|
-
if (!(useTypeAndThen && supportsPolkadotXCM(this))) {
|
|
6581
|
+
if (!(useTypeAndThen && supportsPolkadotXCM(this) && !isSubBridge)) {
|
|
6380
6582
|
_context.n = 10;
|
|
6381
6583
|
break;
|
|
6382
6584
|
}
|
|
@@ -6463,7 +6665,7 @@ var Parachain = /*#__PURE__*/function () {
|
|
|
6463
6665
|
value: function shouldUseNativeAssetTeleport(_ref) {
|
|
6464
6666
|
var asset = _ref.assetInfo,
|
|
6465
6667
|
to = _ref.to;
|
|
6466
|
-
if (isTLocation(to) ||
|
|
6668
|
+
if (isTLocation(to) || isSubstrateBridge(this.chain, to) || to === 'Ethereum') return false;
|
|
6467
6669
|
var isAHPOrigin = this.chain.includes('AssetHub');
|
|
6468
6670
|
var isAHPDest = !isTLocation(to) && to.includes('AssetHub');
|
|
6469
6671
|
var isNativeAsset = !isTLocation(to) && (isAHPOrigin && isForeignAsset(asset) && isSymbolMatch(asset.symbol, getNativeAssetSymbol(to)) || isAHPDest && !isForeignAsset(asset) && isSymbolMatch(asset.symbol, getNativeAssetSymbol(this.chain)));
|
|
@@ -6559,51 +6761,57 @@ var Parachain = /*#__PURE__*/function () {
|
|
|
6559
6761
|
key: "transferLocal",
|
|
6560
6762
|
value: function () {
|
|
6561
6763
|
var _transferLocal = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
6562
|
-
var api, asset, address, senderAddress, currency, isAmountAll, validatedOptions, isNativeAsset, balance, localOptions;
|
|
6764
|
+
var api, asset, feeAsset, address, senderAddress, currency, isAmountAll, validatedOptions, isNativeAsset, balance, localOptions;
|
|
6563
6765
|
return _regenerator().w(function (_context3) {
|
|
6564
6766
|
while (1) switch (_context3.n) {
|
|
6565
6767
|
case 0:
|
|
6566
|
-
api = options.api, asset = options.assetInfo, address = options.address, senderAddress = options.senderAddress, currency = options.currency, isAmountAll = options.isAmountAll;
|
|
6768
|
+
api = options.api, asset = options.assetInfo, feeAsset = options.feeAsset, address = options.address, senderAddress = options.senderAddress, currency = options.currency, isAmountAll = options.isAmountAll;
|
|
6567
6769
|
if (!isTLocation(address)) {
|
|
6568
6770
|
_context3.n = 1;
|
|
6569
6771
|
break;
|
|
6570
6772
|
}
|
|
6571
6773
|
throw new InvalidAddressError('Location address is not supported for local transfers');
|
|
6572
6774
|
case 1:
|
|
6775
|
+
if (!feeAsset) {
|
|
6776
|
+
_context3.n = 2;
|
|
6777
|
+
break;
|
|
6778
|
+
}
|
|
6779
|
+
throw new InvalidParameterError('Fee asset is not supported for local transfers');
|
|
6780
|
+
case 2:
|
|
6573
6781
|
validatedOptions = _objectSpread2(_objectSpread2({}, options), {}, {
|
|
6574
6782
|
address: address
|
|
6575
6783
|
});
|
|
6576
6784
|
isNativeAsset = asset.symbol === this.getNativeAssetSymbol() && !isForeignAsset(asset);
|
|
6577
6785
|
if (!isAmountAll) {
|
|
6578
|
-
_context3.n =
|
|
6786
|
+
_context3.n = 4;
|
|
6579
6787
|
break;
|
|
6580
6788
|
}
|
|
6581
6789
|
assertSenderAddress(senderAddress);
|
|
6582
|
-
_context3.n =
|
|
6790
|
+
_context3.n = 3;
|
|
6583
6791
|
return getAssetBalanceInternal({
|
|
6584
6792
|
api: api,
|
|
6585
6793
|
chain: this.chain,
|
|
6586
6794
|
address: senderAddress,
|
|
6587
6795
|
currency: currency
|
|
6588
6796
|
});
|
|
6589
|
-
case
|
|
6797
|
+
case 3:
|
|
6590
6798
|
balance = _context3.v;
|
|
6591
|
-
_context3.n =
|
|
6799
|
+
_context3.n = 5;
|
|
6592
6800
|
break;
|
|
6593
|
-
case 3:
|
|
6594
|
-
balance = MIN_AMOUNT;
|
|
6595
6801
|
case 4:
|
|
6802
|
+
balance = MIN_AMOUNT;
|
|
6803
|
+
case 5:
|
|
6596
6804
|
localOptions = _objectSpread2(_objectSpread2({}, validatedOptions), {}, {
|
|
6597
6805
|
balance: balance
|
|
6598
6806
|
});
|
|
6599
6807
|
if (!isNativeAsset) {
|
|
6600
|
-
_context3.n =
|
|
6808
|
+
_context3.n = 6;
|
|
6601
6809
|
break;
|
|
6602
6810
|
}
|
|
6603
6811
|
return _context3.a(2, this.transferLocalNativeAsset(localOptions));
|
|
6604
|
-
case 5:
|
|
6605
|
-
return _context3.a(2, this.transferLocalNonNativeAsset(localOptions));
|
|
6606
6812
|
case 6:
|
|
6813
|
+
return _context3.a(2, this.transferLocalNonNativeAsset(localOptions));
|
|
6814
|
+
case 7:
|
|
6607
6815
|
return _context3.a(2);
|
|
6608
6816
|
}
|
|
6609
6817
|
}, _callee3, this);
|
|
@@ -7104,9 +7312,6 @@ var AssetHubKusama = /*#__PURE__*/function (_Parachain) {
|
|
|
7104
7312
|
scenario = input.scenario;
|
|
7105
7313
|
// TESTED https://kusama.subscan.io/xcm_message/kusama-ddc2a48f0d8e0337832d7aae26f6c3053e1f4ffd
|
|
7106
7314
|
// TESTED https://kusama.subscan.io/xcm_message/kusama-8e423130a4d8b61679af95dbea18a55124f99672
|
|
7107
|
-
if (destination === 'AssetHubPolkadot') {
|
|
7108
|
-
return getChain('AssetHubPolkadot').handleBridgeTransfer(input, 'Polkadot');
|
|
7109
|
-
}
|
|
7110
7315
|
if (scenario === 'ParaToPara' && asset.symbol === 'DOT' && !isForeignAsset(asset)) {
|
|
7111
7316
|
throw new ScenarioNotSupportedError(this.chain, scenario, 'Bridged DOT cannot currently be transfered from AssetHubKusama, if you are sending different DOT asset, please specify {id: <DOTID>}.');
|
|
7112
7317
|
}
|
|
@@ -7152,36 +7357,6 @@ var AssetHubPolkadot = /*#__PURE__*/function (_Parachain) {
|
|
|
7152
7357
|
}
|
|
7153
7358
|
_inherits(AssetHubPolkadot, _Parachain);
|
|
7154
7359
|
return _createClass(AssetHubPolkadot, [{
|
|
7155
|
-
key: "handleBridgeTransfer",
|
|
7156
|
-
value: function handleBridgeTransfer(input, targetChain) {
|
|
7157
|
-
var _asset$symbol, _asset$symbol2, _asset$symbol3;
|
|
7158
|
-
var api = input.api,
|
|
7159
|
-
asset = input.assetInfo,
|
|
7160
|
-
destination = input.destination,
|
|
7161
|
-
address = input.address,
|
|
7162
|
-
version = input.version,
|
|
7163
|
-
paraIdTo = input.paraIdTo;
|
|
7164
|
-
if (targetChain === 'Kusama' && ((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toUpperCase()) === 'KSM' || targetChain === 'Polkadot' && ((_asset$symbol2 = asset.symbol) === null || _asset$symbol2 === void 0 ? void 0 : _asset$symbol2.toUpperCase()) === 'DOT') {
|
|
7165
|
-
var modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
|
|
7166
|
-
destLocation: createBridgeDestination(targetChain, destination, paraIdTo),
|
|
7167
|
-
beneficiaryLocation: createBeneficiaryLocation({
|
|
7168
|
-
api: api,
|
|
7169
|
-
address: address,
|
|
7170
|
-
version: version
|
|
7171
|
-
}),
|
|
7172
|
-
asset: createAsset(version, asset.amount, asset.location)
|
|
7173
|
-
});
|
|
7174
|
-
return transferPolkadotXcm(modifiedInput, 'transfer_assets', 'Unlimited');
|
|
7175
|
-
} else if (targetChain === 'Polkadot' && ((_asset$symbol3 = asset.symbol) === null || _asset$symbol3 === void 0 ? void 0 : _asset$symbol3.toUpperCase()) === 'KSM' || targetChain === 'Kusama' && 'DOT') {
|
|
7176
|
-
var _modifiedInput = _objectSpread2(_objectSpread2({}, input), {}, {
|
|
7177
|
-
destLocation: createBridgeDestination(targetChain, destination, paraIdTo),
|
|
7178
|
-
asset: createAsset(version, asset.amount, DOT_LOCATION)
|
|
7179
|
-
});
|
|
7180
|
-
return transferPolkadotXcm(_modifiedInput, 'limited_reserve_transfer_assets', 'Unlimited');
|
|
7181
|
-
}
|
|
7182
|
-
throw new InvalidCurrencyError("Polkadot <-> Kusama bridge does not support currency ".concat(asset.symbol));
|
|
7183
|
-
}
|
|
7184
|
-
}, {
|
|
7185
7360
|
key: "handleEthBridgeNativeTransfer",
|
|
7186
7361
|
value: function () {
|
|
7187
7362
|
var _handleEthBridgeNativeTransfer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
|
|
@@ -7386,52 +7561,46 @@ var AssetHubPolkadot = /*#__PURE__*/function (_Parachain) {
|
|
|
7386
7561
|
case 4:
|
|
7387
7562
|
return _context3.a(2, _t.callTxMethod.call(_t, _context3.v));
|
|
7388
7563
|
case 5:
|
|
7389
|
-
if (!(destination === 'AssetHubKusama')) {
|
|
7390
|
-
_context3.n = 6;
|
|
7391
|
-
break;
|
|
7392
|
-
}
|
|
7393
|
-
return _context3.a(2, this.handleBridgeTransfer(options, 'Kusama'));
|
|
7394
|
-
case 6:
|
|
7395
7564
|
if (!(destination === 'Ethereum')) {
|
|
7396
|
-
_context3.n =
|
|
7565
|
+
_context3.n = 6;
|
|
7397
7566
|
break;
|
|
7398
7567
|
}
|
|
7399
7568
|
return _context3.a(2, this.handleEthBridgeTransfer(options));
|
|
7400
|
-
case
|
|
7569
|
+
case 6:
|
|
7401
7570
|
if (!(destination === 'Mythos')) {
|
|
7402
|
-
_context3.n =
|
|
7571
|
+
_context3.n = 7;
|
|
7403
7572
|
break;
|
|
7404
7573
|
}
|
|
7405
7574
|
return _context3.a(2, this.handleMythosTransfer(options));
|
|
7406
|
-
case
|
|
7575
|
+
case 7:
|
|
7407
7576
|
isExternalAsset = assetInfo.location && assetInfo.location.parents === Parents.TWO;
|
|
7408
7577
|
if (!isExternalAsset) {
|
|
7409
|
-
_context3.n =
|
|
7578
|
+
_context3.n = 9;
|
|
7410
7579
|
break;
|
|
7411
7580
|
}
|
|
7412
|
-
_context3.n =
|
|
7581
|
+
_context3.n = 8;
|
|
7413
7582
|
return createTypeAndThenCall(this.chain, options);
|
|
7414
|
-
case
|
|
7583
|
+
case 8:
|
|
7415
7584
|
_call = _context3.v;
|
|
7416
7585
|
return _context3.a(2, api.callTxMethod(_call));
|
|
7417
|
-
case
|
|
7586
|
+
case 9:
|
|
7418
7587
|
if (!(scenario === 'ParaToPara' && assetInfo.symbol === 'KSM' && !isForeignAsset(assetInfo))) {
|
|
7419
|
-
_context3.n =
|
|
7588
|
+
_context3.n = 10;
|
|
7420
7589
|
break;
|
|
7421
7590
|
}
|
|
7422
7591
|
throw new ScenarioNotSupportedError(this.chain, scenario, 'Bridged KSM cannot currently be transfered from AssetHubPolkadot, if you are sending different KSM asset, please specify {id: <KSMID>}.');
|
|
7423
|
-
case
|
|
7592
|
+
case 10:
|
|
7424
7593
|
method = this.getMethod(scenario, destination); // Patch transfer_assets to use type_and_then transfer
|
|
7425
7594
|
if (!(method === 'transfer_assets' && isSymbolMatch(assetInfo.symbol, getRelayChainSymbol(this.chain)))) {
|
|
7426
|
-
_context3.n =
|
|
7595
|
+
_context3.n = 12;
|
|
7427
7596
|
break;
|
|
7428
7597
|
}
|
|
7429
7598
|
_t2 = api;
|
|
7430
|
-
_context3.n =
|
|
7599
|
+
_context3.n = 11;
|
|
7431
7600
|
return createTypeAndThenCall(this.chain, options);
|
|
7432
|
-
case
|
|
7601
|
+
case 11:
|
|
7433
7602
|
return _context3.a(2, _t2.callTxMethod.call(_t2, _context3.v));
|
|
7434
|
-
case
|
|
7603
|
+
case 12:
|
|
7435
7604
|
modifiedInput = this.patchInput(options);
|
|
7436
7605
|
return _context3.a(2, transferPolkadotXcm(modifiedInput, method, 'Unlimited'));
|
|
7437
7606
|
}
|
|
@@ -11129,156 +11298,6 @@ var getOriginXcmFee = /*#__PURE__*/function () {
|
|
|
11129
11298
|
};
|
|
11130
11299
|
}();
|
|
11131
11300
|
|
|
11132
|
-
var resolveAsset = function resolveAsset(currency, origin, destination, assetCheckEnabled) {
|
|
11133
|
-
return assetCheckEnabled ? findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null) : null;
|
|
11134
|
-
};
|
|
11135
|
-
|
|
11136
|
-
var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
|
|
11137
|
-
var origin = _ref.from,
|
|
11138
|
-
destination = _ref.to,
|
|
11139
|
-
currency = _ref.currency;
|
|
11140
|
-
var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
|
|
11141
|
-
var isLocationDestination = _typeof(destination) === 'object';
|
|
11142
|
-
if (!isBridge && !isRelayDestination && !isLocationDestination && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== undefined && assetCheckEnabled && !('id' in currency) && !hasSupportForAsset(destination, asset.symbol)) {
|
|
11143
|
-
throw new InvalidCurrencyError("Destination chain ".concat(destination, " does not support currency ").concat(JSON.stringify(currency, replaceBigInt), "."));
|
|
11144
|
-
}
|
|
11145
|
-
if (!isBridge && asset === null && assetCheckEnabled) {
|
|
11146
|
-
throwUnsupportedCurrency(currency, origin);
|
|
11147
|
-
}
|
|
11148
|
-
};
|
|
11149
|
-
|
|
11150
|
-
var resolveOverriddenAsset = function resolveOverriddenAsset(options, isBridge, assetCheckEnabled, resolvedFeeAsset) {
|
|
11151
|
-
var api = options.api,
|
|
11152
|
-
currency = options.currency,
|
|
11153
|
-
feeAsset = options.feeAsset,
|
|
11154
|
-
origin = options.from,
|
|
11155
|
-
destination = options.to;
|
|
11156
|
-
if ('location' in currency && isOverrideLocationSpecifier(currency.location)) {
|
|
11157
|
-
return currency.location.value;
|
|
11158
|
-
}
|
|
11159
|
-
if (Array.isArray(currency)) {
|
|
11160
|
-
if (!feeAsset) {
|
|
11161
|
-
throw new InvalidCurrencyError('Overridden multi assets cannot be used without specifying fee asset');
|
|
11162
|
-
}
|
|
11163
|
-
if ('location' in feeAsset && isOverrideLocationSpecifier(feeAsset.location)) {
|
|
11164
|
-
throw new InvalidCurrencyError('Fee asset cannot be an overridden location specifier');
|
|
11165
|
-
}
|
|
11166
|
-
if (currency.every(function (asset) {
|
|
11167
|
-
return isTAsset(asset);
|
|
11168
|
-
})) {
|
|
11169
|
-
if (!feeAsset) {
|
|
11170
|
-
throw new InvalidCurrencyError('Fee asset not provided');
|
|
11171
|
-
}
|
|
11172
|
-
if (!('location' in feeAsset)) {
|
|
11173
|
-
throw new InvalidCurrencyError('Fee asset must be specified by location when using raw overridden multi assets');
|
|
11174
|
-
}
|
|
11175
|
-
return currency.map(function (asset) {
|
|
11176
|
-
var ml = extractAssetLocation(asset);
|
|
11177
|
-
return _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
11178
|
-
fun: {
|
|
11179
|
-
Fungible: BigInt(asset.fun.Fungible)
|
|
11180
|
-
},
|
|
11181
|
-
isFeeAsset: deepEqual(ml, feeAsset.location)
|
|
11182
|
-
});
|
|
11183
|
-
});
|
|
11184
|
-
}
|
|
11185
|
-
// MultiAsset is an array of TCurrencyCore, search for assets
|
|
11186
|
-
var assets = currency.map(function (currency) {
|
|
11187
|
-
if (currency.amount === AMOUNT_ALL) {
|
|
11188
|
-
throw new InvalidCurrencyError('Multi assets cannot use amount all. Please specify amount.');
|
|
11189
|
-
}
|
|
11190
|
-
var asset = findAssetInfo(origin, currency, !isTLocation(destination) ? destination : null);
|
|
11191
|
-
if (!asset) {
|
|
11192
|
-
throw new InvalidCurrencyError("Origin chain ".concat(origin, " does not support currency ").concat(JSON.stringify(currency)));
|
|
11193
|
-
}
|
|
11194
|
-
assertHasLocation(asset);
|
|
11195
|
-
if (!resolvedFeeAsset) {
|
|
11196
|
-
throw new InvalidCurrencyError('Fee asset not found');
|
|
11197
|
-
}
|
|
11198
|
-
validateAssetSupport(options, assetCheckEnabled, isBridge, asset);
|
|
11199
|
-
var version = getChainVersion(origin);
|
|
11200
|
-
var abstractedAmount = abstractDecimals(currency.amount, asset.decimals, api);
|
|
11201
|
-
return _objectSpread2({
|
|
11202
|
-
isFeeAsset: isAssetEqual(resolvedFeeAsset, asset)
|
|
11203
|
-
}, createAsset(version, abstractedAmount, asset.location));
|
|
11204
|
-
});
|
|
11205
|
-
if (assets.filter(function (asset) {
|
|
11206
|
-
return asset.isFeeAsset;
|
|
11207
|
-
}).length > 1) {
|
|
11208
|
-
throw new InvalidCurrencyError("Fee asset matches multiple assets in multiassets");
|
|
11209
|
-
}
|
|
11210
|
-
if (assets.filter(function (asset) {
|
|
11211
|
-
return asset.isFeeAsset;
|
|
11212
|
-
}).length === 0) {
|
|
11213
|
-
throw new InvalidCurrencyError("Fee asset not found in multiassets");
|
|
11214
|
-
}
|
|
11215
|
-
return assets;
|
|
11216
|
-
}
|
|
11217
|
-
return undefined;
|
|
11218
|
-
};
|
|
11219
|
-
|
|
11220
|
-
var selectXcmVersion = function selectXcmVersion(forcedVersion, originVersion, destMaxVersion) {
|
|
11221
|
-
if (forcedVersion) return forcedVersion;
|
|
11222
|
-
var destVersion = destMaxVersion !== null && destMaxVersion !== void 0 ? destMaxVersion : originVersion;
|
|
11223
|
-
return destVersion < originVersion ? destVersion : originVersion;
|
|
11224
|
-
};
|
|
11225
|
-
|
|
11226
|
-
var shouldPerformAssetCheck = function shouldPerformAssetCheck(origin, currency) {
|
|
11227
|
-
if (isRelayChain(origin)) return true;
|
|
11228
|
-
var isMultipleAssets = Array.isArray(currency);
|
|
11229
|
-
var hasOverriddenLocation = 'location' in currency && isOverrideLocationSpecifier(currency.location);
|
|
11230
|
-
return !(isMultipleAssets || hasOverriddenLocation);
|
|
11231
|
-
};
|
|
11232
|
-
|
|
11233
|
-
var validateDestinationAddress = function validateDestinationAddress(address, destination) {
|
|
11234
|
-
if (typeof address === 'string' && !isTLocation(destination)) {
|
|
11235
|
-
validateAddress(address, destination);
|
|
11236
|
-
}
|
|
11237
|
-
};
|
|
11238
|
-
|
|
11239
|
-
var validateCurrency = function validateCurrency(currency, feeAsset) {
|
|
11240
|
-
if (Array.isArray(currency)) {
|
|
11241
|
-
if (currency.length === 0) {
|
|
11242
|
-
throw new InvalidCurrencyError('Overridden assets cannot be empty');
|
|
11243
|
-
}
|
|
11244
|
-
if (currency.length === 1) {
|
|
11245
|
-
throw new InvalidCurrencyError('Please provide more than one asset');
|
|
11246
|
-
}
|
|
11247
|
-
if (currency.length > 1 && !currency.every(function (asset) {
|
|
11248
|
-
return isTAsset(asset);
|
|
11249
|
-
}) && !feeAsset) {
|
|
11250
|
-
throw new InvalidCurrencyError('Overridden assets cannot be used without specifying fee asset');
|
|
11251
|
-
}
|
|
11252
|
-
}
|
|
11253
|
-
};
|
|
11254
|
-
var validateDestination = function validateDestination(origin, destination) {
|
|
11255
|
-
if (isRelayChain(origin) && !isTLocation(destination) && isRelayChain(destination) && origin !== destination) {
|
|
11256
|
-
throw new IncompatibleChainsError('Direct relay chain to relay chain transfers are not supported. Please use Polkadot <-> Kusama bridge through AssetHub.');
|
|
11257
|
-
}
|
|
11258
|
-
var allowedChainsToEthereum = ['AssetHubPolkadot', 'Hydration', 'BifrostPolkadot', 'Moonbeam', 'Mythos'];
|
|
11259
|
-
if (destination === 'Ethereum' && !allowedChainsToEthereum.includes(origin)) {
|
|
11260
|
-
throw new IncompatibleChainsError("Transfers to Ethereum are only supported from: ".concat(allowedChainsToEthereum.join(', ')));
|
|
11261
|
-
}
|
|
11262
|
-
var isLocationDestination = _typeof(destination) === 'object';
|
|
11263
|
-
var isBridge = !isTLocation(destination) && isDotKsmBridge(origin, destination);
|
|
11264
|
-
var isRelayDestination = !isTLocation(destination) && isRelayChain(destination);
|
|
11265
|
-
if (!isRelayDestination && !isLocationDestination) {
|
|
11266
|
-
var originRelayChainSymbol = getRelayChainSymbol(origin);
|
|
11267
|
-
var destinationRelayChainSymbol = getRelayChainSymbol(destination);
|
|
11268
|
-
if (!isBridge && originRelayChainSymbol !== destinationRelayChainSymbol) {
|
|
11269
|
-
throw new IncompatibleChainsError();
|
|
11270
|
-
}
|
|
11271
|
-
}
|
|
11272
|
-
};
|
|
11273
|
-
var validateAssetSpecifiers = function validateAssetSpecifiers(assetCheckEnabled, currency) {
|
|
11274
|
-
if (!assetCheckEnabled && 'symbol' in currency && isSymbolSpecifier(currency.symbol)) {
|
|
11275
|
-
throw new InvalidCurrencyError('Symbol specifier is not supported when asset check is disabled. Please use normal symbol instead.');
|
|
11276
|
-
}
|
|
11277
|
-
if (!assetCheckEnabled && 'id' in currency) {
|
|
11278
|
-
throw new InvalidCurrencyError('Asset ID is not supported when asset check is disabled. Please use normal symbol instead');
|
|
11279
|
-
}
|
|
11280
|
-
};
|
|
11281
|
-
|
|
11282
11301
|
var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
|
|
11283
11302
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
11284
11303
|
var api, tx, origin, destination, currency, senderAddress, feeAsset, originAsset, amount, rawOriginFee, originFee, resolvedFeeAsset, sufficient, asset;
|
|
@@ -11478,20 +11497,19 @@ var getXcmFeeInternal = /*#__PURE__*/function () {
|
|
|
11478
11497
|
case 10:
|
|
11479
11498
|
processHop = /*#__PURE__*/function () {
|
|
11480
11499
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
11481
|
-
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopAsset,
|
|
11500
|
+
var hopApi, currentChain, currentOrigin, currentAsset, forwardedXcms, hasPassedExchange, hopAsset, hopResult;
|
|
11482
11501
|
return _regenerator().w(function (_context) {
|
|
11483
11502
|
while (1) switch (_context.n) {
|
|
11484
11503
|
case 0:
|
|
11485
11504
|
hopApi = params.api, currentChain = params.currentChain, currentOrigin = params.currentOrigin, currentAsset = params.currentAsset, forwardedXcms = params.forwardedXcms, hasPassedExchange = params.hasPassedExchange;
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
}
|
|
11505
|
+
hopAsset = resolveHopAsset({
|
|
11506
|
+
originChain: origin,
|
|
11507
|
+
currentChain: currentChain,
|
|
11508
|
+
asset: currentAsset,
|
|
11509
|
+
currency: currency,
|
|
11510
|
+
swapConfig: swapConfig,
|
|
11511
|
+
hasPassedExchange: hasPassedExchange
|
|
11512
|
+
});
|
|
11495
11513
|
_context.n = 1;
|
|
11496
11514
|
return getDestXcmFee({
|
|
11497
11515
|
api: hopApi,
|
|
@@ -11945,7 +11963,7 @@ var send = /*#__PURE__*/function () {
|
|
|
11945
11963
|
validateDestination(origin, destination);
|
|
11946
11964
|
validateDestinationAddress(address, destination);
|
|
11947
11965
|
if (senderAddress) validateAddress(senderAddress, origin, false);
|
|
11948
|
-
isBridge = !isTLocation(destination) &&
|
|
11966
|
+
isBridge = !isTLocation(destination) && isSubstrateBridge(origin, destination);
|
|
11949
11967
|
assetCheckEnabled = shouldPerformAssetCheck(origin, currency);
|
|
11950
11968
|
validateAssetSpecifiers(assetCheckEnabled, currency);
|
|
11951
11969
|
asset = resolveAsset(currency, origin, destination, assetCheckEnabled);
|
|
@@ -12719,18 +12737,19 @@ var computeInstructionFee = /*#__PURE__*/function () {
|
|
|
12719
12737
|
}();
|
|
12720
12738
|
var computeAllFees = /*#__PURE__*/function () {
|
|
12721
12739
|
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref3, customXcm, isDotAsset, refundInstruction) {
|
|
12722
|
-
var _customXcm$DepositRes;
|
|
12723
12740
|
var reserve, dest, version, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0;
|
|
12724
12741
|
return _regenerator().w(function (_context2) {
|
|
12725
12742
|
while (1) switch (_context2.n) {
|
|
12726
12743
|
case 0:
|
|
12727
12744
|
reserve = _ref3.reserve, dest = _ref3.dest, version = _ref3.options.version;
|
|
12728
|
-
if (!(
|
|
12745
|
+
if (!customXcm.some(function (x) {
|
|
12746
|
+
return 'DepositReserveAsset' in x || 'InitiateTeleport' in x;
|
|
12747
|
+
})) {
|
|
12729
12748
|
_context2.n = 6;
|
|
12730
12749
|
break;
|
|
12731
12750
|
}
|
|
12732
12751
|
_context2.n = 1;
|
|
12733
|
-
return computeInstructionFee(reserve, version,
|
|
12752
|
+
return computeInstructionFee(reserve, version, customXcm);
|
|
12734
12753
|
case 1:
|
|
12735
12754
|
_t3 = _context2.v;
|
|
12736
12755
|
if (!refundInstruction) {
|
|
@@ -12748,7 +12767,12 @@ var computeAllFees = /*#__PURE__*/function () {
|
|
|
12748
12767
|
case 4:
|
|
12749
12768
|
_t5 = _t4;
|
|
12750
12769
|
_context2.n = 5;
|
|
12751
|
-
return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, (
|
|
12770
|
+
return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, function () {
|
|
12771
|
+
var instr = customXcm.find(function (j) {
|
|
12772
|
+
return 'DepositReserveAsset' in j || 'InitiateTeleport' in j;
|
|
12773
|
+
});
|
|
12774
|
+
return instr ? 'DepositReserveAsset' in instr ? instr.DepositReserveAsset.xcm : instr.InitiateTeleport.xcm : undefined;
|
|
12775
|
+
}());
|
|
12752
12776
|
case 5:
|
|
12753
12777
|
_t6 = _context2.v;
|
|
12754
12778
|
_t2 = {
|
|
@@ -12764,7 +12788,7 @@ var computeAllFees = /*#__PURE__*/function () {
|
|
|
12764
12788
|
break;
|
|
12765
12789
|
}
|
|
12766
12790
|
_context2.n = 7;
|
|
12767
|
-
return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version,
|
|
12791
|
+
return computeInstructionFee(hasXcmPaymentApiSupport(dest.chain) ? dest : reserve, version, customXcm);
|
|
12768
12792
|
case 7:
|
|
12769
12793
|
_t7 = _context2.v;
|
|
12770
12794
|
_context2.n = 9;
|
|
@@ -12802,28 +12826,49 @@ var computeAllFees = /*#__PURE__*/function () {
|
|
|
12802
12826
|
};
|
|
12803
12827
|
}();
|
|
12804
12828
|
|
|
12829
|
+
var getSubBridgeReserve = function getSubBridgeReserve(chain, destination, location) {
|
|
12830
|
+
if (deepEqual(location, RELAY_LOCATION)) return chain;
|
|
12831
|
+
return destination;
|
|
12832
|
+
};
|
|
12833
|
+
var resolveReserveChain = function resolveReserveChain(chain, destination, assetLocation, isSubBridge, overrideReserve) {
|
|
12834
|
+
if (isSubBridge) {
|
|
12835
|
+
return getSubBridgeReserve(chain, destination, assetLocation);
|
|
12836
|
+
}
|
|
12837
|
+
if (overrideReserve !== undefined) {
|
|
12838
|
+
return overrideReserve;
|
|
12839
|
+
}
|
|
12840
|
+
var relayChain = getRelayChainOf(chain);
|
|
12841
|
+
if (relayChain === 'Paseo' || relayChain === 'Kusama') {
|
|
12842
|
+
// Paseo and Kusama ecosystems migrate reserves to AssetHub
|
|
12843
|
+
return getAssetReserveChain(chain, chain, assetLocation);
|
|
12844
|
+
}
|
|
12845
|
+
if (isRelayChain(destination)) {
|
|
12846
|
+
return destination;
|
|
12847
|
+
}
|
|
12848
|
+
return getAssetReserveChain(chain, chain, assetLocation);
|
|
12849
|
+
};
|
|
12805
12850
|
var createTypeAndThenCallContext = /*#__PURE__*/function () {
|
|
12806
12851
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
|
|
12807
|
-
var api,
|
|
12852
|
+
var api, destination, assetInfo, destinationChain, isSubBridge, reserveChain, destApi, reserveApi;
|
|
12808
12853
|
return _regenerator().w(function (_context) {
|
|
12809
12854
|
while (1) switch (_context.n) {
|
|
12810
12855
|
case 0:
|
|
12811
|
-
api = options.api,
|
|
12856
|
+
api = options.api, destination = options.destination, assetInfo = options.assetInfo;
|
|
12812
12857
|
assertHasLocation(assetInfo);
|
|
12813
|
-
if (
|
|
12858
|
+
if (!isTLocation(destination)) {
|
|
12814
12859
|
_context.n = 1;
|
|
12815
12860
|
break;
|
|
12816
12861
|
}
|
|
12817
12862
|
throw new InvalidParameterError('Cannot override destination when using type and then transfer.');
|
|
12818
12863
|
case 1:
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12864
|
+
destinationChain = destination;
|
|
12865
|
+
isSubBridge = isSubstrateBridge(chain, destinationChain);
|
|
12866
|
+
reserveChain = resolveReserveChain(chain, destinationChain, assetInfo.location, isSubBridge, overrideReserve);
|
|
12822
12867
|
destApi = api.clone();
|
|
12823
12868
|
_context.n = 2;
|
|
12824
|
-
return destApi.init(
|
|
12869
|
+
return destApi.init(destinationChain);
|
|
12825
12870
|
case 2:
|
|
12826
|
-
reserveApi = reserveChain === chain ? api : reserveChain ===
|
|
12871
|
+
reserveApi = reserveChain === chain ? api : reserveChain === destinationChain ? destApi : api.clone();
|
|
12827
12872
|
_context.n = 3;
|
|
12828
12873
|
return reserveApi.init(reserveChain);
|
|
12829
12874
|
case 3:
|
|
@@ -12834,12 +12879,13 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
|
|
|
12834
12879
|
},
|
|
12835
12880
|
dest: {
|
|
12836
12881
|
api: destApi,
|
|
12837
|
-
chain:
|
|
12882
|
+
chain: destinationChain
|
|
12838
12883
|
},
|
|
12839
12884
|
reserve: {
|
|
12840
12885
|
api: reserveApi,
|
|
12841
12886
|
chain: reserveChain
|
|
12842
12887
|
},
|
|
12888
|
+
isSubBridge: isSubBridge,
|
|
12843
12889
|
assetInfo: assetInfo,
|
|
12844
12890
|
options: options
|
|
12845
12891
|
});
|
|
@@ -12851,13 +12897,14 @@ var createTypeAndThenCallContext = /*#__PURE__*/function () {
|
|
|
12851
12897
|
};
|
|
12852
12898
|
}();
|
|
12853
12899
|
|
|
12854
|
-
var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
|
|
12900
|
+
var createCustomXcm = function createCustomXcm(_ref, isDotAsset, assetCount) {
|
|
12855
12901
|
var origin = _ref.origin,
|
|
12856
12902
|
dest = _ref.dest,
|
|
12857
12903
|
reserve = _ref.reserve,
|
|
12904
|
+
isSubBridge = _ref.isSubBridge,
|
|
12858
12905
|
assetInfo = _ref.assetInfo,
|
|
12859
12906
|
options = _ref.options;
|
|
12860
|
-
var fees = arguments.length >
|
|
12907
|
+
var fees = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
12861
12908
|
reserveFee: MIN_FEE,
|
|
12862
12909
|
refundFee: 0n,
|
|
12863
12910
|
destFee: MIN_FEE
|
|
@@ -12870,20 +12917,22 @@ var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
|
|
|
12870
12917
|
refundFee = fees.refundFee,
|
|
12871
12918
|
destFee = fees.destFee;
|
|
12872
12919
|
var feeAssetLocation = !isDotAsset ? RELAY_LOCATION : assetInfo.location;
|
|
12873
|
-
var feeLocLocalized = localizeLocation(dest.chain, feeAssetLocation);
|
|
12874
|
-
var asset = createAsset(version, assetInfo.amount, localizeLocation(dest.chain, assetInfo.location));
|
|
12920
|
+
var feeLocLocalized = localizeLocation(dest.chain, feeAssetLocation, origin.chain);
|
|
12921
|
+
var asset = createAsset(version, assetInfo.amount, localizeLocation(dest.chain, assetInfo.location, origin.chain));
|
|
12875
12922
|
var depositInstruction = {
|
|
12876
12923
|
DepositAsset: {
|
|
12877
12924
|
assets: {
|
|
12878
|
-
Wild: {
|
|
12925
|
+
Wild: assetCount > 1 ? {
|
|
12879
12926
|
AllOf: {
|
|
12880
12927
|
id: asset.id,
|
|
12881
12928
|
fun: 'Fungible'
|
|
12882
12929
|
}
|
|
12930
|
+
} : {
|
|
12931
|
+
AllCounted: 1
|
|
12883
12932
|
}
|
|
12884
12933
|
},
|
|
12885
12934
|
beneficiary: createBeneficiaryLocation({
|
|
12886
|
-
api: origin.api,
|
|
12935
|
+
api: isSubBridge ? dest.api : origin.api,
|
|
12887
12936
|
address: address,
|
|
12888
12937
|
version: version
|
|
12889
12938
|
})
|
|
@@ -12892,7 +12941,7 @@ var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
|
|
|
12892
12941
|
var assetsFilter = [];
|
|
12893
12942
|
if (!isDotAsset) assetsFilter.push(createAsset(version, reserveFee + destFee, localizeLocation(reserve.chain, RELAY_LOCATION)));
|
|
12894
12943
|
assetsFilter.push(createAsset(version, assetInfo.amount, localizeLocation(reserve.chain, assetInfo.location)));
|
|
12895
|
-
if (origin.chain !== reserve.chain && dest.chain !== reserve.chain) {
|
|
12944
|
+
if (isSubBridge || origin.chain !== reserve.chain && dest.chain !== reserve.chain) {
|
|
12896
12945
|
var buyExecutionAmount = !isDotAsset ? destFee : assetInfo.amount - reserveFee - refundFee;
|
|
12897
12946
|
if (buyExecutionAmount < 0n) throw new AmountTooLowError();
|
|
12898
12947
|
var filter = fees.destFee === MIN_FEE ? {
|
|
@@ -12906,26 +12955,29 @@ var createCustomXcm = function createCustomXcm(_ref, isDotAsset) {
|
|
|
12906
12955
|
weight_limit: 'Unlimited'
|
|
12907
12956
|
}
|
|
12908
12957
|
};
|
|
12958
|
+
if (isSubBridge) {
|
|
12959
|
+
return [buyExecution, depositInstruction];
|
|
12960
|
+
}
|
|
12909
12961
|
var destLoc = createDestination(version, origin.chain, destination, paraIdTo);
|
|
12910
12962
|
// If destination is a system chain, use teleport instead of reserve deposit
|
|
12911
12963
|
if (isSystemChain(dest.chain)) {
|
|
12912
|
-
return {
|
|
12964
|
+
return [{
|
|
12913
12965
|
InitiateTeleport: {
|
|
12914
12966
|
assets: filter,
|
|
12915
12967
|
dest: destLoc,
|
|
12916
12968
|
xcm: [buyExecution, depositInstruction]
|
|
12917
12969
|
}
|
|
12918
|
-
};
|
|
12970
|
+
}];
|
|
12919
12971
|
}
|
|
12920
|
-
return {
|
|
12972
|
+
return [{
|
|
12921
12973
|
DepositReserveAsset: {
|
|
12922
12974
|
assets: filter,
|
|
12923
12975
|
dest: destLoc,
|
|
12924
12976
|
xcm: [buyExecution, depositInstruction]
|
|
12925
12977
|
}
|
|
12926
|
-
};
|
|
12978
|
+
}];
|
|
12927
12979
|
}
|
|
12928
|
-
return depositInstruction;
|
|
12980
|
+
return [depositInstruction];
|
|
12929
12981
|
};
|
|
12930
12982
|
|
|
12931
12983
|
var createRefundInstruction = function createRefundInstruction(api, senderAddress, version, assetCount) {
|
|
@@ -12960,7 +13012,7 @@ var buildAssets = function buildAssets(chain, asset, feeAmount, isDotAsset, vers
|
|
|
12960
13012
|
*/
|
|
12961
13013
|
var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
12962
13014
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(chain, options, overrideReserve) {
|
|
12963
|
-
var api, senderAddress, version, context, assetInfo,
|
|
13015
|
+
var api, senderAddress, version, context, assetInfo, isSubBridge, LOCATIONS, isRelayAsset, assetCount, customXcm, refundInstruction, fees, finalCustomXcm, totalFee, assets;
|
|
12964
13016
|
return _regenerator().w(function (_context) {
|
|
12965
13017
|
while (1) switch (_context.n) {
|
|
12966
13018
|
case 0:
|
|
@@ -12969,8 +13021,8 @@ var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
|
12969
13021
|
return createTypeAndThenCallContext(chain, options, overrideReserve);
|
|
12970
13022
|
case 1:
|
|
12971
13023
|
context = _context.v;
|
|
12972
|
-
assetInfo = context.assetInfo;
|
|
12973
|
-
|
|
13024
|
+
assetInfo = context.assetInfo, isSubBridge = context.isSubBridge;
|
|
13025
|
+
LOCATIONS = [RELAY_LOCATION, {
|
|
12974
13026
|
parents: 2,
|
|
12975
13027
|
interior: {
|
|
12976
13028
|
X1: [{
|
|
@@ -12979,20 +13031,32 @@ var createTypeAndThenCall = /*#__PURE__*/function () {
|
|
|
12979
13031
|
}
|
|
12980
13032
|
}]
|
|
12981
13033
|
}
|
|
13034
|
+
}, {
|
|
13035
|
+
parents: 2,
|
|
13036
|
+
interior: {
|
|
13037
|
+
X1: [{
|
|
13038
|
+
GlobalConsensus: {
|
|
13039
|
+
Polkadot: null
|
|
13040
|
+
}
|
|
13041
|
+
}]
|
|
13042
|
+
}
|
|
13043
|
+
}];
|
|
13044
|
+
isRelayAsset = LOCATIONS.some(function (loc) {
|
|
13045
|
+
return deepEqual(assetInfo.location, loc);
|
|
12982
13046
|
});
|
|
12983
|
-
|
|
12984
|
-
|
|
13047
|
+
assetCount = isRelayAsset ? 1 : 2;
|
|
13048
|
+
customXcm = createCustomXcm(context, isRelayAsset, assetCount);
|
|
12985
13049
|
refundInstruction = senderAddress ? createRefundInstruction(api, senderAddress, version, assetCount) : null;
|
|
12986
13050
|
_context.n = 2;
|
|
12987
|
-
return computeAllFees(context, customXcm,
|
|
13051
|
+
return computeAllFees(context, customXcm, isRelayAsset, refundInstruction);
|
|
12988
13052
|
case 2:
|
|
12989
13053
|
fees = _context.v;
|
|
12990
13054
|
finalCustomXcm = [];
|
|
12991
|
-
if (refundInstruction) finalCustomXcm.push(refundInstruction);
|
|
12992
|
-
finalCustomXcm.push(createCustomXcm(context,
|
|
13055
|
+
if (refundInstruction && !isSubBridge) finalCustomXcm.push(refundInstruction);
|
|
13056
|
+
finalCustomXcm.push.apply(finalCustomXcm, _toConsumableArray(createCustomXcm(context, isRelayAsset, assetCount, fees)));
|
|
12993
13057
|
totalFee = fees.reserveFee + fees.destFee + fees.refundFee;
|
|
12994
|
-
assets = buildAssets(chain, assetInfo, totalFee,
|
|
12995
|
-
return _context.a(2, buildTypeAndThenCall(context,
|
|
13058
|
+
assets = buildAssets(chain, assetInfo, totalFee, isRelayAsset, version);
|
|
13059
|
+
return _context.a(2, buildTypeAndThenCall(context, isRelayAsset, finalCustomXcm, assets));
|
|
12996
13060
|
}
|
|
12997
13061
|
}, _callee);
|
|
12998
13062
|
}));
|
|
@@ -13819,9 +13883,6 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
13819
13883
|
value: function () {
|
|
13820
13884
|
var _buildCommon = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
13821
13885
|
var isCalledInternally,
|
|
13822
|
-
_this$_options,
|
|
13823
|
-
from,
|
|
13824
|
-
to,
|
|
13825
13886
|
_yield$this$prepareNo,
|
|
13826
13887
|
normalizedOptions,
|
|
13827
13888
|
tx,
|
|
@@ -13836,25 +13897,18 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
13836
13897
|
}
|
|
13837
13898
|
throw new InvalidParameterError('Transaction manager contains batched items. Use buildBatch() to process them.');
|
|
13838
13899
|
case 1:
|
|
13839
|
-
|
|
13840
|
-
if (!(!isTLocation(to) && isRelayChain(from) && isRelayChain(to) && from !== to)) {
|
|
13841
|
-
_context4.n = 2;
|
|
13842
|
-
break;
|
|
13843
|
-
}
|
|
13844
|
-
throw new InvalidParameterError('Transfers between relay chains are not yet supported.');
|
|
13845
|
-
case 2:
|
|
13846
|
-
_context4.n = 3;
|
|
13900
|
+
_context4.n = 2;
|
|
13847
13901
|
return this.prepareNormalizedOptions(this._options);
|
|
13848
|
-
case
|
|
13902
|
+
case 2:
|
|
13849
13903
|
_yield$this$prepareNo = _context4.v;
|
|
13850
13904
|
normalizedOptions = _yield$this$prepareNo.normalizedOptions;
|
|
13851
|
-
_context4.n =
|
|
13905
|
+
_context4.n = 3;
|
|
13852
13906
|
return send(normalizedOptions);
|
|
13853
|
-
case
|
|
13907
|
+
case 3:
|
|
13854
13908
|
tx = _context4.v;
|
|
13855
|
-
_context4.n =
|
|
13909
|
+
_context4.n = 4;
|
|
13856
13910
|
return this.maybePerformXcmFormatCheck(tx, normalizedOptions, isCalledInternally);
|
|
13857
|
-
case
|
|
13911
|
+
case 4:
|
|
13858
13912
|
return _context4.a(2, {
|
|
13859
13913
|
tx: tx,
|
|
13860
13914
|
options: normalizedOptions
|