@paraspell/sdk-core 10.0.0 → 10.0.2
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 +318 -238
- package/dist/index.d.ts +27 -7
- package/dist/index.mjs +319 -239
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blake2b } from '@noble/hashes/blake2';
|
|
2
|
-
import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, getRelayChainSymbol, isForeignAsset,
|
|
2
|
+
import { isNodeEvm, getAssetsObject, InvalidCurrencyError, getNativeAssetSymbol, getOtherAssets, getRelayChainSymbol, isForeignAsset, findAsset, isTMultiAsset, hasDryRunSupport, findAssetForNodeOrThrow, isOverrideMultiLocationSpecifier, findAssetByMultiLocation, hasSupportForAsset, extractMultiAssetLoc, isAssetEqual, isSymbolSpecifier, getAssetId, getExistentialDeposit, findAssetOnDestOrThrow, normalizeSymbol } from '@paraspell/assets';
|
|
3
3
|
export * from '@paraspell/assets';
|
|
4
4
|
import { base58 } from '@scure/base';
|
|
5
5
|
import { ethers, Contract } from 'ethers';
|
|
@@ -786,7 +786,7 @@ var blake2b512 = function blake2b512(msg) {
|
|
|
786
786
|
var ALLOWED_PUBKEY_BYTES = new Set([32, 33]);
|
|
787
787
|
var deriveAccountId = function deriveAccountId(raw) {
|
|
788
788
|
if (!ALLOWED_PUBKEY_BYTES.has(raw.length)) {
|
|
789
|
-
throw new
|
|
789
|
+
throw new InvalidParameterError('public key length is invalid');
|
|
790
790
|
}
|
|
791
791
|
return raw.length === 33 ? blake2b256(raw) : raw;
|
|
792
792
|
};
|
|
@@ -804,7 +804,7 @@ var networkToBytes = function networkToBytes(net) {
|
|
|
804
804
|
};
|
|
805
805
|
var encodeSs58 = function encodeSs58(payload, network) {
|
|
806
806
|
if (!VALID_ADDR_PAYLOAD.has(payload.length)) {
|
|
807
|
-
throw new
|
|
807
|
+
throw new InvalidParameterError('unexpected payload length for SS58 address');
|
|
808
808
|
}
|
|
809
809
|
var netBytes = networkToBytes(network);
|
|
810
810
|
var chkInput = new Uint8Array(SS58_HARD_PREFIX.length + netBytes.length + payload.length);
|
|
@@ -2171,7 +2171,7 @@ var getNodeProviders = function getNodeProviders(node) {
|
|
|
2171
2171
|
var _getNodeConfig = getNodeConfig(node),
|
|
2172
2172
|
providers = _getNodeConfig.providers;
|
|
2173
2173
|
if (providers.length === 0) {
|
|
2174
|
-
throw new
|
|
2174
|
+
throw new InvalidParameterError("No providers found for node ".concat(node));
|
|
2175
2175
|
}
|
|
2176
2176
|
// Prefer Dwellir provider
|
|
2177
2177
|
providers.sort(function (a, b) {
|
|
@@ -2384,12 +2384,12 @@ var addXcmVersionHeader = function addXcmVersionHeader(obj, version) {
|
|
|
2384
2384
|
var extractVersionFromHeader = function extractVersionFromHeader(versionHeader) {
|
|
2385
2385
|
var keys = Object.keys(versionHeader);
|
|
2386
2386
|
if (keys.length !== 1) {
|
|
2387
|
-
throw new
|
|
2387
|
+
throw new InvalidParameterError('Invalid version header: expected exactly one key.');
|
|
2388
2388
|
}
|
|
2389
2389
|
var version = keys[0];
|
|
2390
2390
|
var value = versionHeader[version];
|
|
2391
2391
|
if (value === undefined) {
|
|
2392
|
-
throw new
|
|
2392
|
+
throw new InvalidParameterError('Invalid version header: value is undefined.');
|
|
2393
2393
|
}
|
|
2394
2394
|
return [version, value];
|
|
2395
2395
|
};
|
|
@@ -2432,13 +2432,13 @@ var resolveTNodeFromMultiLocation = function resolveTNodeFromMultiLocation(relay
|
|
|
2432
2432
|
var _NODE_NAMES_DOT_KSM$f;
|
|
2433
2433
|
var parachainId = findParachainJunction(multiLocation);
|
|
2434
2434
|
if (parachainId === null) {
|
|
2435
|
-
throw new
|
|
2435
|
+
throw new InvalidParameterError('Parachain ID not found in destination multi location.');
|
|
2436
2436
|
}
|
|
2437
2437
|
var node = (_NODE_NAMES_DOT_KSM$f = NODE_NAMES_DOT_KSM.find(function (nodeName) {
|
|
2438
2438
|
return getParaId(nodeName) === parachainId && determineRelayChain(nodeName) === relayChain;
|
|
2439
2439
|
})) !== null && _NODE_NAMES_DOT_KSM$f !== void 0 ? _NODE_NAMES_DOT_KSM$f : null;
|
|
2440
2440
|
if (node === null) {
|
|
2441
|
-
throw new
|
|
2441
|
+
throw new InvalidParameterError('Node with specified paraId not found in destination multi location.');
|
|
2442
2442
|
}
|
|
2443
2443
|
return node;
|
|
2444
2444
|
};
|
|
@@ -2592,12 +2592,15 @@ var getMultiLocationTokenId = function getMultiLocationTokenId(location, node) {
|
|
|
2592
2592
|
};
|
|
2593
2593
|
|
|
2594
2594
|
var computeFeeFromDryRun = function computeFeeFromDryRun(dryRun, node, executionFee) {
|
|
2595
|
+
var isFeeAsset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
2595
2596
|
// Extract delivery fees from emitted events
|
|
2596
2597
|
var deliveryFees = [];
|
|
2598
|
+
var assetConversionFee = 0n;
|
|
2597
2599
|
var _iterator = _createForOfIteratorHelper(dryRun.value.emitted_events),
|
|
2598
2600
|
_step;
|
|
2599
2601
|
try {
|
|
2600
2602
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2603
|
+
var _e$value, _e$value2;
|
|
2601
2604
|
var e = _step.value;
|
|
2602
2605
|
var isXcmEvent = e.type === 'XcmPallet' || e.type === 'PolkadotXcm' || e.type === 'CumulusXcm';
|
|
2603
2606
|
var isFeesPaid = e.value.type === 'FeesPaid';
|
|
@@ -2622,20 +2625,26 @@ var computeFeeFromDryRun = function computeFeeFromDryRun(dryRun, node, execution
|
|
|
2622
2625
|
_iterator2.f();
|
|
2623
2626
|
}
|
|
2624
2627
|
}
|
|
2628
|
+
if (isFeeAsset && e.type === 'AssetConversion' && ((_e$value = e.value) === null || _e$value === void 0 ? void 0 : _e$value.type) === 'SwapCreditExecuted' && (_e$value2 = e.value) !== null && _e$value2 !== void 0 && _e$value2.value && e.value.value.amount_in !== undefined && e.value.value.amount_in !== null) {
|
|
2629
|
+
assetConversionFee += e.value.value.amount_in;
|
|
2630
|
+
}
|
|
2625
2631
|
}
|
|
2626
2632
|
} catch (err) {
|
|
2627
2633
|
_iterator.e(err);
|
|
2628
2634
|
} finally {
|
|
2629
2635
|
_iterator.f();
|
|
2630
2636
|
}
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2637
|
+
if (isFeeAsset && assetConversionFee > 0n) {
|
|
2638
|
+
return assetConversionFee;
|
|
2639
|
+
} else {
|
|
2640
|
+
var nativeAssetSymbol = getNativeAssetSymbol(node);
|
|
2641
|
+
var totalDeliveryFees = deliveryFees.filter(function (df) {
|
|
2642
|
+
return df.tokenSymbol === nativeAssetSymbol;
|
|
2643
|
+
}).reduce(function (acc, df) {
|
|
2644
|
+
return acc + df.plancks;
|
|
2645
|
+
}, 0n);
|
|
2646
|
+
return totalDeliveryFees + executionFee;
|
|
2647
|
+
}
|
|
2639
2648
|
};
|
|
2640
2649
|
|
|
2641
2650
|
var getMultiLocationTokenIdPjs = function getMultiLocationTokenIdPjs(location, node) {
|
|
@@ -2709,17 +2718,17 @@ var resolveModuleError = function resolveModuleError(node, error) {
|
|
|
2709
2718
|
return p.index === Number(error.index);
|
|
2710
2719
|
});
|
|
2711
2720
|
if (!palletDetails) {
|
|
2712
|
-
throw new
|
|
2721
|
+
throw new InvalidParameterError("Pallet with index ".concat(error.index, " not found"));
|
|
2713
2722
|
}
|
|
2714
2723
|
// Use only the first byte of the error to get the error index
|
|
2715
2724
|
var errorIndex = Number(error.error.slice(0, 4));
|
|
2716
2725
|
var name = palletDetails.name;
|
|
2717
2726
|
if (name !== 'XTokens' && name !== 'PolkadotXcm' && name !== 'XcmPallet') {
|
|
2718
|
-
throw new
|
|
2727
|
+
throw new InvalidParameterError("Pallet ".concat(name, " is not supported"));
|
|
2719
2728
|
}
|
|
2720
2729
|
var failureReason = name === 'XTokens' ? Object.values(XTokensError)[errorIndex] : Object.values(PolkadotXcmError)[errorIndex];
|
|
2721
2730
|
if (!failureReason) {
|
|
2722
|
-
throw new
|
|
2731
|
+
throw new InvalidParameterError("Error index ".concat(errorIndex, " not found in ").concat(name, " pallet"));
|
|
2723
2732
|
}
|
|
2724
2733
|
return failureReason;
|
|
2725
2734
|
};
|
|
@@ -2753,7 +2762,7 @@ var getFees = function getFees(scenario) {
|
|
|
2753
2762
|
} else if (scenario === 'ParaToPara') {
|
|
2754
2763
|
return 399600000000;
|
|
2755
2764
|
}
|
|
2756
|
-
throw new
|
|
2765
|
+
throw new InvalidParameterError("Fees for scenario ".concat(scenario, " are not defined."));
|
|
2757
2766
|
};
|
|
2758
2767
|
|
|
2759
2768
|
/**
|
|
@@ -2913,7 +2922,7 @@ var XTokensTransferImpl = /*#__PURE__*/function () {
|
|
|
2913
2922
|
useMultiAssetTransfer = _input$useMultiAssetT === void 0 ? false : _input$useMultiAssetT;
|
|
2914
2923
|
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
2915
2924
|
if (isMultiLocationDestination) {
|
|
2916
|
-
throw new
|
|
2925
|
+
throw new InvalidParameterError('Multilocation destinations are not supported for specific transfer you are trying to create. In special cases such as xTokens or xTransfer pallet try using address multilocation instead (for both destination and address in same multilocation set (eg. X2 - Parachain, Address). For further assistance please open issue in our repository.');
|
|
2917
2926
|
}
|
|
2918
2927
|
var isBifrostOrigin = origin === 'BifrostPolkadot' || origin === 'BifrostKusama';
|
|
2919
2928
|
var isAssetHubDest = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama';
|
|
@@ -2952,6 +2961,15 @@ var getTNode = function getTNode(paraId, ecosystem) {
|
|
|
2952
2961
|
})) !== null && _NODE_NAMES_DOT_KSM$f !== void 0 ? _NODE_NAMES_DOT_KSM$f : null;
|
|
2953
2962
|
};
|
|
2954
2963
|
|
|
2964
|
+
var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
|
|
2965
|
+
var asset = findAsset(origin, feeAsset, !isTMultiLocation(destination) ? destination : null);
|
|
2966
|
+
var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(isTMultiAsset);
|
|
2967
|
+
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
2968
|
+
throwUnsupportedCurrency(feeAsset, origin);
|
|
2969
|
+
}
|
|
2970
|
+
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
2971
|
+
};
|
|
2972
|
+
|
|
2955
2973
|
var isAssetHub = function isAssetHub(chain) {
|
|
2956
2974
|
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
2957
2975
|
};
|
|
@@ -3031,11 +3049,12 @@ var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
|
3031
3049
|
};
|
|
3032
3050
|
var getDestXcmFee = /*#__PURE__*/function () {
|
|
3033
3051
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
3034
|
-
var api, origin, destination, currency, forwardedXcms, disableFallback, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
|
|
3052
|
+
var api, origin, destination, currency, forwardedXcms, asset, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
|
|
3035
3053
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
3036
3054
|
while (1) switch (_context2.prev = _context2.next) {
|
|
3037
3055
|
case 0:
|
|
3038
|
-
api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, disableFallback = options.disableFallback;
|
|
3056
|
+
api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, asset = options.asset, feeAsset = options.feeAsset, originFee = options.originFee, disableFallback = options.disableFallback;
|
|
3057
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
3039
3058
|
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
3040
3059
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
3041
3060
|
var originAsset;
|
|
@@ -3093,42 +3112,46 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
3093
3112
|
};
|
|
3094
3113
|
}();
|
|
3095
3114
|
if (!(!hasDryRunSupport(destination) || !forwardedXcms)) {
|
|
3096
|
-
_context2.next =
|
|
3115
|
+
_context2.next = 8;
|
|
3097
3116
|
break;
|
|
3098
3117
|
}
|
|
3099
|
-
_context2.next =
|
|
3118
|
+
_context2.next = 6;
|
|
3100
3119
|
return calcPaymentInfoFee();
|
|
3101
|
-
case
|
|
3120
|
+
case 6:
|
|
3102
3121
|
_context2.t0 = _context2.sent;
|
|
3103
3122
|
return _context2.abrupt("return", {
|
|
3104
3123
|
fee: _context2.t0,
|
|
3105
3124
|
feeType: 'paymentInfo'
|
|
3106
3125
|
});
|
|
3107
|
-
case
|
|
3108
|
-
_context2.next =
|
|
3126
|
+
case 8:
|
|
3127
|
+
_context2.next = 10;
|
|
3109
3128
|
return api.getDryRunXcm({
|
|
3110
3129
|
originLocation: addXcmVersionHeader(createOriginLocation(origin, destination), Version.V4),
|
|
3111
3130
|
xcm: forwardedXcms[1][0],
|
|
3112
3131
|
node: destination,
|
|
3113
|
-
origin: origin
|
|
3132
|
+
origin: origin,
|
|
3133
|
+
asset: asset,
|
|
3134
|
+
originFee: originFee,
|
|
3135
|
+
feeAsset: resolvedFeeAsset,
|
|
3136
|
+
amount: BigInt(currency.amount)
|
|
3114
3137
|
});
|
|
3115
|
-
case
|
|
3138
|
+
case 10:
|
|
3116
3139
|
dryRunResult = _context2.sent;
|
|
3117
3140
|
if (dryRunResult.success) {
|
|
3118
|
-
_context2.next =
|
|
3141
|
+
_context2.next = 19;
|
|
3119
3142
|
break;
|
|
3120
3143
|
}
|
|
3121
3144
|
if (!disableFallback) {
|
|
3122
|
-
_context2.next =
|
|
3145
|
+
_context2.next = 14;
|
|
3123
3146
|
break;
|
|
3124
3147
|
}
|
|
3125
3148
|
return _context2.abrupt("return", {
|
|
3126
3149
|
dryRunError: dryRunResult.failureReason
|
|
3127
3150
|
});
|
|
3128
|
-
case
|
|
3129
|
-
_context2.next =
|
|
3151
|
+
case 14:
|
|
3152
|
+
_context2.next = 16;
|
|
3130
3153
|
return calcPaymentInfoFee();
|
|
3131
|
-
case
|
|
3154
|
+
case 16:
|
|
3132
3155
|
_context2.t1 = _context2.sent;
|
|
3133
3156
|
_context2.t2 = dryRunResult.failureReason;
|
|
3134
3157
|
return _context2.abrupt("return", {
|
|
@@ -3136,7 +3159,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
3136
3159
|
feeType: 'paymentInfo',
|
|
3137
3160
|
dryRunError: _context2.t2
|
|
3138
3161
|
});
|
|
3139
|
-
case
|
|
3162
|
+
case 19:
|
|
3140
3163
|
fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
3141
3164
|
return _context2.abrupt("return", {
|
|
3142
3165
|
fee: fee,
|
|
@@ -3144,7 +3167,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
3144
3167
|
forwardedXcms: newForwardedXcms,
|
|
3145
3168
|
destParaId: destParaId
|
|
3146
3169
|
});
|
|
3147
|
-
case
|
|
3170
|
+
case 21:
|
|
3148
3171
|
case "end":
|
|
3149
3172
|
return _context2.stop();
|
|
3150
3173
|
}
|
|
@@ -3158,49 +3181,51 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
3158
3181
|
var dryRunInternal = /*#__PURE__*/function () {
|
|
3159
3182
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
3160
3183
|
var _intermediateFees$ass, _intermediateFees$bri, _destinationDryRun;
|
|
3161
|
-
var origin, destination, currency, api, tx, senderAddress, asset, originDryRun, initialForwardedXcms, initialDestParaId, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId;
|
|
3184
|
+
var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId;
|
|
3162
3185
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3163
3186
|
while (1) switch (_context.prev = _context.next) {
|
|
3164
3187
|
case 0:
|
|
3165
|
-
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress;
|
|
3188
|
+
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
|
|
3189
|
+
resolvedFeeAsset = feeAsset && origin === 'AssetHubPolkadot' ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
3166
3190
|
asset = findAssetForNodeOrThrow(origin, currency, destination);
|
|
3167
|
-
_context.next =
|
|
3191
|
+
_context.next = 5;
|
|
3168
3192
|
return api.getDryRunCall({
|
|
3169
3193
|
tx: tx,
|
|
3170
3194
|
node: origin,
|
|
3171
|
-
address: senderAddress
|
|
3195
|
+
address: senderAddress,
|
|
3196
|
+
isFeeAsset: !!resolvedFeeAsset
|
|
3172
3197
|
});
|
|
3173
|
-
case
|
|
3198
|
+
case 5:
|
|
3174
3199
|
originDryRun = _context.sent;
|
|
3175
3200
|
if (originDryRun.success) {
|
|
3176
|
-
_context.next =
|
|
3201
|
+
_context.next = 8;
|
|
3177
3202
|
break;
|
|
3178
3203
|
}
|
|
3179
3204
|
return _context.abrupt("return", {
|
|
3180
3205
|
origin: originDryRun
|
|
3181
3206
|
});
|
|
3182
|
-
case
|
|
3207
|
+
case 8:
|
|
3183
3208
|
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
3184
3209
|
currentOrigin = origin;
|
|
3185
3210
|
forwardedXcms = initialForwardedXcms;
|
|
3186
3211
|
nextParaId = initialDestParaId;
|
|
3187
3212
|
intermediateFees = {};
|
|
3188
|
-
case
|
|
3213
|
+
case 13:
|
|
3189
3214
|
if (!(Array.isArray(forwardedXcms) && forwardedXcms.length && forwardedXcms[1].length && ('disconnect' in api.getApi() ? Object.values(forwardedXcms[1][0]).length : forwardedXcms[1][0].value.length) > 0 && nextParaId !== undefined)) {
|
|
3190
|
-
_context.next =
|
|
3215
|
+
_context.next = 40;
|
|
3191
3216
|
break;
|
|
3192
3217
|
}
|
|
3193
3218
|
nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
|
|
3194
3219
|
if (nextChain) {
|
|
3195
|
-
_context.next =
|
|
3220
|
+
_context.next = 17;
|
|
3196
3221
|
break;
|
|
3197
3222
|
}
|
|
3198
|
-
throw new
|
|
3199
|
-
case
|
|
3223
|
+
throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
|
|
3224
|
+
case 17:
|
|
3200
3225
|
hopApi = api.clone();
|
|
3201
|
-
_context.prev =
|
|
3226
|
+
_context.prev = 18;
|
|
3202
3227
|
if (hasDryRunSupport(nextChain)) {
|
|
3203
|
-
_context.next =
|
|
3228
|
+
_context.next = 22;
|
|
3204
3229
|
break;
|
|
3205
3230
|
}
|
|
3206
3231
|
if (nextChain === destination) {
|
|
@@ -3209,19 +3234,23 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
3209
3234
|
failureReason: "DryRunApi is not available on node ".concat(nextChain)
|
|
3210
3235
|
};
|
|
3211
3236
|
}
|
|
3212
|
-
return _context.abrupt("break",
|
|
3213
|
-
case
|
|
3214
|
-
_context.next =
|
|
3237
|
+
return _context.abrupt("break", 40);
|
|
3238
|
+
case 22:
|
|
3239
|
+
_context.next = 24;
|
|
3215
3240
|
return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
3216
|
-
case
|
|
3217
|
-
_context.next =
|
|
3241
|
+
case 24:
|
|
3242
|
+
_context.next = 26;
|
|
3218
3243
|
return hopApi.getDryRunXcm({
|
|
3219
3244
|
originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, nextChain), Version.V4),
|
|
3220
3245
|
xcm: forwardedXcms[1][0],
|
|
3221
3246
|
node: nextChain,
|
|
3222
|
-
origin: currentOrigin
|
|
3247
|
+
origin: currentOrigin,
|
|
3248
|
+
asset: asset,
|
|
3249
|
+
feeAsset: resolvedFeeAsset,
|
|
3250
|
+
originFee: originDryRun.fee,
|
|
3251
|
+
amount: BigInt(currency.amount)
|
|
3223
3252
|
});
|
|
3224
|
-
case
|
|
3253
|
+
case 26:
|
|
3225
3254
|
hopDryRun = _context.sent;
|
|
3226
3255
|
if (nextChain === destination || isRelayChain(nextChain) && !isRelayChain(destination)) {
|
|
3227
3256
|
destinationDryRun = hopDryRun;
|
|
@@ -3231,28 +3260,28 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
3231
3260
|
intermediateFees.bridgeHub = hopDryRun;
|
|
3232
3261
|
}
|
|
3233
3262
|
if (hopDryRun.success) {
|
|
3234
|
-
_context.next =
|
|
3263
|
+
_context.next = 30;
|
|
3235
3264
|
break;
|
|
3236
3265
|
}
|
|
3237
|
-
return _context.abrupt("break",
|
|
3238
|
-
case
|
|
3266
|
+
return _context.abrupt("break", 40);
|
|
3267
|
+
case 30:
|
|
3239
3268
|
newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
|
|
3240
3269
|
forwardedXcms = newXcms;
|
|
3241
3270
|
nextParaId = destParaId;
|
|
3242
3271
|
currentOrigin = nextChain;
|
|
3243
|
-
case
|
|
3244
|
-
_context.prev =
|
|
3245
|
-
_context.next =
|
|
3272
|
+
case 34:
|
|
3273
|
+
_context.prev = 34;
|
|
3274
|
+
_context.next = 37;
|
|
3246
3275
|
return hopApi.disconnect();
|
|
3247
|
-
case 36:
|
|
3248
|
-
return _context.finish(33);
|
|
3249
3276
|
case 37:
|
|
3250
|
-
_context.
|
|
3277
|
+
return _context.finish(34);
|
|
3278
|
+
case 38:
|
|
3279
|
+
_context.next = 13;
|
|
3251
3280
|
break;
|
|
3252
|
-
case
|
|
3281
|
+
case 40:
|
|
3253
3282
|
return _context.abrupt("return", {
|
|
3254
3283
|
origin: originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
|
|
3255
|
-
currency: getNativeAssetSymbol(origin)
|
|
3284
|
+
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(origin)
|
|
3256
3285
|
}) : originDryRun,
|
|
3257
3286
|
assetHub: (_intermediateFees$ass = intermediateFees.assetHub) !== null && _intermediateFees$ass !== void 0 && _intermediateFees$ass.success ? _objectSpread2(_objectSpread2({}, intermediateFees.assetHub), {}, {
|
|
3258
3287
|
currency: getNativeAssetSymbol('AssetHubPolkadot')
|
|
@@ -3264,11 +3293,11 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
3264
3293
|
currency: asset.symbol
|
|
3265
3294
|
}) : destinationDryRun
|
|
3266
3295
|
});
|
|
3267
|
-
case
|
|
3296
|
+
case 41:
|
|
3268
3297
|
case "end":
|
|
3269
3298
|
return _context.stop();
|
|
3270
3299
|
}
|
|
3271
|
-
}, _callee, null, [[
|
|
3300
|
+
}, _callee, null, [[18,, 34, 38]]);
|
|
3272
3301
|
}));
|
|
3273
3302
|
return function dryRunInternal(_x) {
|
|
3274
3303
|
return _ref.apply(this, arguments);
|
|
@@ -3391,7 +3420,7 @@ var formatAssetIdToERC20 = function formatAssetIdToERC20(id) {
|
|
|
3391
3420
|
return id;
|
|
3392
3421
|
}
|
|
3393
3422
|
if (!(/^\d{38,39}$/.test(id) || /^\d{4}$/.test(id))) {
|
|
3394
|
-
throw new
|
|
3423
|
+
throw new InvalidParameterError("Asset id: ".concat(id, " must be a string and have either 4 digits or 38-39 digits"));
|
|
3395
3424
|
}
|
|
3396
3425
|
return "0xffffffff".concat(BigInt(id).toString(16).padStart(32, '0'));
|
|
3397
3426
|
};
|
|
@@ -3566,7 +3595,7 @@ var getBalanceForeignInternal = /*#__PURE__*/function () {
|
|
|
3566
3595
|
}
|
|
3567
3596
|
return _context.abrupt("return", getBalanceForeignPolkadotXcm(api, node, address, asset));
|
|
3568
3597
|
case 11:
|
|
3569
|
-
throw new
|
|
3598
|
+
throw new InvalidParameterError('Unsupported pallet');
|
|
3570
3599
|
case 12:
|
|
3571
3600
|
case "end":
|
|
3572
3601
|
return _context.stop();
|
|
@@ -3911,13 +3940,13 @@ var transferMoonbeamEvm = /*#__PURE__*/function () {
|
|
|
3911
3940
|
_context.next = 3;
|
|
3912
3941
|
break;
|
|
3913
3942
|
}
|
|
3914
|
-
throw new
|
|
3943
|
+
throw new InvalidParameterError('Multiassets syntax is not supported for Evm transfers');
|
|
3915
3944
|
case 3:
|
|
3916
3945
|
if (!('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation))) {
|
|
3917
3946
|
_context.next = 5;
|
|
3918
3947
|
break;
|
|
3919
3948
|
}
|
|
3920
|
-
throw new
|
|
3949
|
+
throw new InvalidParameterError('Override multilocation is not supported for Evm transfers');
|
|
3921
3950
|
case 5:
|
|
3922
3951
|
contract = isEthersSigner(signer) ? new Contract(CONTRACT_ADDRESS, abi$1, signer) : getContract({
|
|
3923
3952
|
abi: abi$1,
|
|
@@ -4238,7 +4267,7 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
|
|
|
4238
4267
|
_context.next = 3;
|
|
4239
4268
|
break;
|
|
4240
4269
|
}
|
|
4241
|
-
throw new
|
|
4270
|
+
throw new InvalidParameterError('AssetHub address is required');
|
|
4242
4271
|
case 3:
|
|
4243
4272
|
_context.next = 5;
|
|
4244
4273
|
return getBridgeStatus(api.clone());
|
|
@@ -4254,13 +4283,13 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
|
|
|
4254
4283
|
_context.next = 10;
|
|
4255
4284
|
break;
|
|
4256
4285
|
}
|
|
4257
|
-
throw new
|
|
4286
|
+
throw new InvalidParameterError('Multiassets syntax is not supported for Evm transfers');
|
|
4258
4287
|
case 10:
|
|
4259
4288
|
if (!('multilocation' in currency && isOverrideMultiLocationSpecifier(currency.multilocation))) {
|
|
4260
4289
|
_context.next = 12;
|
|
4261
4290
|
break;
|
|
4262
4291
|
}
|
|
4263
|
-
throw new
|
|
4292
|
+
throw new InvalidParameterError('Override multilocation is not supported for Evm transfers');
|
|
4264
4293
|
case 12:
|
|
4265
4294
|
foundAsset = findAsset(from, currency, to);
|
|
4266
4295
|
if (!(foundAsset === null)) {
|
|
@@ -4311,7 +4340,7 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
|
|
|
4311
4340
|
_context.next = 31;
|
|
4312
4341
|
break;
|
|
4313
4342
|
}
|
|
4314
|
-
throw new
|
|
4343
|
+
throw new InvalidParameterError('Unable to get sender address');
|
|
4315
4344
|
case 31:
|
|
4316
4345
|
_context.next = 33;
|
|
4317
4346
|
return api.init(from, TX_CLIENT_TIMEOUT_MS);
|
|
@@ -4354,7 +4383,7 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
|
|
|
4354
4383
|
};
|
|
4355
4384
|
numberToHex32 = function numberToHex32(num) {
|
|
4356
4385
|
return typeof num !== 'number' || isNaN(num) ? function () {
|
|
4357
|
-
throw new
|
|
4386
|
+
throw new InvalidParameterError('Input must be a valid number');
|
|
4358
4387
|
}() : "0x".concat((num >>> 0).toString(16).padStart(8, '0'));
|
|
4359
4388
|
}; // Execute the custom XCM message with the precompile
|
|
4360
4389
|
_context.next = 54;
|
|
@@ -4385,69 +4414,71 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
|
|
|
4385
4414
|
|
|
4386
4415
|
var getOriginXcmFee = /*#__PURE__*/function () {
|
|
4387
4416
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
4388
|
-
var api, tx, origin, destination, senderAddress, disableFallback, currency, rawFee, dryRunResult, _rawFee, fee, forwardedXcms, destParaId;
|
|
4417
|
+
var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, resolvedFeeAsset, currencySymbol, rawFee, dryRunResult, _rawFee, fee, forwardedXcms, destParaId;
|
|
4389
4418
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4390
4419
|
while (1) switch (_context.prev = _context.next) {
|
|
4391
4420
|
case 0:
|
|
4392
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback;
|
|
4393
|
-
|
|
4421
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback, feeAsset = _ref.feeAsset, currency = _ref.currency;
|
|
4422
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4423
|
+
_context.next = 4;
|
|
4394
4424
|
return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4395
|
-
case
|
|
4396
|
-
|
|
4425
|
+
case 4:
|
|
4426
|
+
currencySymbol = resolvedFeeAsset ? resolvedFeeAsset.symbol : getNativeAssetSymbol(origin);
|
|
4397
4427
|
if (hasDryRunSupport(origin)) {
|
|
4398
|
-
_context.next =
|
|
4428
|
+
_context.next = 10;
|
|
4399
4429
|
break;
|
|
4400
4430
|
}
|
|
4401
|
-
_context.next =
|
|
4431
|
+
_context.next = 8;
|
|
4402
4432
|
return api.calculateTransactionFee(tx, senderAddress);
|
|
4403
|
-
case
|
|
4433
|
+
case 8:
|
|
4404
4434
|
rawFee = _context.sent;
|
|
4405
4435
|
return _context.abrupt("return", {
|
|
4406
4436
|
fee: padFee(rawFee, origin, destination, 'origin'),
|
|
4407
|
-
currency:
|
|
4437
|
+
currency: currencySymbol,
|
|
4408
4438
|
feeType: 'paymentInfo'
|
|
4409
4439
|
});
|
|
4410
|
-
case
|
|
4411
|
-
_context.next =
|
|
4440
|
+
case 10:
|
|
4441
|
+
_context.next = 12;
|
|
4412
4442
|
return api.getDryRunCall({
|
|
4413
4443
|
tx: tx,
|
|
4414
4444
|
node: origin,
|
|
4415
|
-
address: senderAddress
|
|
4445
|
+
address: senderAddress,
|
|
4446
|
+
isFeeAsset: !!resolvedFeeAsset
|
|
4416
4447
|
});
|
|
4417
|
-
case
|
|
4448
|
+
case 12:
|
|
4418
4449
|
dryRunResult = _context.sent;
|
|
4419
4450
|
if (dryRunResult.success) {
|
|
4420
|
-
_context.next =
|
|
4451
|
+
_context.next = 20;
|
|
4421
4452
|
break;
|
|
4422
4453
|
}
|
|
4423
4454
|
if (!disableFallback) {
|
|
4424
|
-
_context.next =
|
|
4455
|
+
_context.next = 16;
|
|
4425
4456
|
break;
|
|
4426
4457
|
}
|
|
4427
4458
|
return _context.abrupt("return", {
|
|
4428
4459
|
dryRunError: dryRunResult.failureReason
|
|
4429
4460
|
});
|
|
4430
|
-
case
|
|
4431
|
-
_context.next =
|
|
4461
|
+
case 16:
|
|
4462
|
+
_context.next = 18;
|
|
4432
4463
|
return api.calculateTransactionFee(tx, senderAddress);
|
|
4433
|
-
case
|
|
4464
|
+
case 18:
|
|
4434
4465
|
_rawFee = _context.sent;
|
|
4435
4466
|
return _context.abrupt("return", {
|
|
4436
4467
|
fee: padFee(_rawFee, origin, destination, 'origin'),
|
|
4437
|
-
currency:
|
|
4468
|
+
currency: currencySymbol,
|
|
4438
4469
|
feeType: 'paymentInfo',
|
|
4439
4470
|
dryRunError: dryRunResult.failureReason
|
|
4440
4471
|
});
|
|
4441
|
-
case
|
|
4472
|
+
case 20:
|
|
4442
4473
|
fee = dryRunResult.fee, forwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
4443
4474
|
return _context.abrupt("return", {
|
|
4444
4475
|
fee: fee,
|
|
4445
4476
|
feeType: 'dryRun',
|
|
4446
|
-
currency:
|
|
4477
|
+
currency: currencySymbol,
|
|
4447
4478
|
forwardedXcms: forwardedXcms,
|
|
4448
4479
|
destParaId: destParaId
|
|
4449
4480
|
});
|
|
4450
|
-
case
|
|
4481
|
+
case 22:
|
|
4451
4482
|
case "end":
|
|
4452
4483
|
return _context.stop();
|
|
4453
4484
|
}
|
|
@@ -4487,11 +4518,11 @@ var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
|
|
|
4487
4518
|
|
|
4488
4519
|
var getXcmFee = /*#__PURE__*/function () {
|
|
4489
4520
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
4490
|
-
var api, tx, origin, destination, senderAddress, address, currency, disableFallback, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, destApi, destFeeRes, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, nextChain, hopApi, hopResult, failingRecord, hopIsDestination, destFallback;
|
|
4521
|
+
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, disableFallback, asset, _yield$getOriginXcmFe, originFee, originCurrency, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, destApi, destFeeRes, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationFee, destinationFeeType, destinationDryRunError, nextChain, hopApi, hopResult, failingRecord, hopIsDestination, destFallback;
|
|
4491
4522
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4492
4523
|
while (1) switch (_context.prev = _context.next) {
|
|
4493
4524
|
case 0:
|
|
4494
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, disableFallback = _ref.disableFallback;
|
|
4525
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset, disableFallback = _ref.disableFallback;
|
|
4495
4526
|
asset = findAssetForNodeOrThrow(origin, currency, destination); // Origin fee = execution fee + delivery fees
|
|
4496
4527
|
_context.next = 4;
|
|
4497
4528
|
return getOriginXcmFee({
|
|
@@ -4500,6 +4531,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4500
4531
|
origin: origin,
|
|
4501
4532
|
destination: destination,
|
|
4502
4533
|
senderAddress: senderAddress,
|
|
4534
|
+
feeAsset: feeAsset,
|
|
4535
|
+
currency: currency,
|
|
4503
4536
|
disableFallback: disableFallback
|
|
4504
4537
|
});
|
|
4505
4538
|
case 4:
|
|
@@ -4533,6 +4566,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4533
4566
|
destination: destination,
|
|
4534
4567
|
currency: currency,
|
|
4535
4568
|
address: address,
|
|
4569
|
+
asset: asset,
|
|
4570
|
+
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
4536
4571
|
senderAddress: senderAddress,
|
|
4537
4572
|
disableFallback: disableFallback
|
|
4538
4573
|
});
|
|
@@ -4580,7 +4615,7 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4580
4615
|
_context.next = 39;
|
|
4581
4616
|
break;
|
|
4582
4617
|
}
|
|
4583
|
-
throw new
|
|
4618
|
+
throw new InvalidParameterError("Unable to find TNode for paraId ".concat(nextParaId));
|
|
4584
4619
|
case 39:
|
|
4585
4620
|
hopApi = api.clone();
|
|
4586
4621
|
_context.prev = 40;
|
|
@@ -4596,6 +4631,9 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4596
4631
|
currency: currency,
|
|
4597
4632
|
address: address,
|
|
4598
4633
|
senderAddress: senderAddress,
|
|
4634
|
+
asset: asset,
|
|
4635
|
+
feeAsset: feeAsset,
|
|
4636
|
+
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
4599
4637
|
disableFallback: disableFallback
|
|
4600
4638
|
});
|
|
4601
4639
|
case 45:
|
|
@@ -4633,6 +4671,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4633
4671
|
destination: destination,
|
|
4634
4672
|
currency: currency,
|
|
4635
4673
|
address: address,
|
|
4674
|
+
asset: asset,
|
|
4675
|
+
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
4636
4676
|
senderAddress: senderAddress,
|
|
4637
4677
|
disableFallback: disableFallback
|
|
4638
4678
|
});
|
|
@@ -4805,7 +4845,7 @@ var transferRelayToPara = /*#__PURE__*/function () {
|
|
|
4805
4845
|
_context.next = 4;
|
|
4806
4846
|
break;
|
|
4807
4847
|
}
|
|
4808
|
-
throw new
|
|
4848
|
+
throw new InvalidParameterError('API is required when using MultiLocation as destination.');
|
|
4809
4849
|
case 4:
|
|
4810
4850
|
_context.next = 6;
|
|
4811
4851
|
return api.init(origin, TX_CLIENT_TIMEOUT_MS);
|
|
@@ -4847,15 +4887,6 @@ var resolveAsset = function resolveAsset(currency, origin, destination, assetChe
|
|
|
4847
4887
|
return assetCheckEnabled ? findAsset(origin, currency, !isTMultiLocation(destination) ? destination : null) : null;
|
|
4848
4888
|
};
|
|
4849
4889
|
|
|
4850
|
-
var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
|
|
4851
|
-
var asset = findAsset(origin, feeAsset, !isTMultiLocation(destination) ? destination : null);
|
|
4852
|
-
var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(isTMultiAsset);
|
|
4853
|
-
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
4854
|
-
throwUnsupportedCurrency(feeAsset, origin);
|
|
4855
|
-
}
|
|
4856
|
-
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
4857
|
-
};
|
|
4858
|
-
|
|
4859
4890
|
var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
|
|
4860
4891
|
var origin = _ref.from,
|
|
4861
4892
|
destination = _ref.to,
|
|
@@ -5014,13 +5045,13 @@ var send = /*#__PURE__*/function () {
|
|
|
5014
5045
|
_context.next = 14;
|
|
5015
5046
|
break;
|
|
5016
5047
|
}
|
|
5017
|
-
throw new
|
|
5048
|
+
throw new InvalidParameterError('Transfers from relay chain to Ethereum are not supported.');
|
|
5018
5049
|
case 14:
|
|
5019
5050
|
if (asset) {
|
|
5020
5051
|
_context.next = 16;
|
|
5021
5052
|
break;
|
|
5022
5053
|
}
|
|
5023
|
-
throw new
|
|
5054
|
+
throw new InvalidParameterError('Asset is required for relay chain to relay chain transfers.');
|
|
5024
5055
|
case 16:
|
|
5025
5056
|
isLocalTransfer = origin === destination;
|
|
5026
5057
|
if (!isLocalTransfer) {
|
|
@@ -5163,7 +5194,7 @@ var ParachainNode = /*#__PURE__*/function () {
|
|
|
5163
5194
|
_context.next = 6;
|
|
5164
5195
|
break;
|
|
5165
5196
|
}
|
|
5166
|
-
throw new
|
|
5197
|
+
throw new InvalidParameterError('Sending assets to Polimec is supported only from AssetHubPolkadot and Hydration');
|
|
5167
5198
|
case 6:
|
|
5168
5199
|
versionOrDefault = version !== null && version !== void 0 ? version : this.version;
|
|
5169
5200
|
isLocalTransfer = this.node === destination;
|
|
@@ -5406,13 +5437,13 @@ var ParachainNode = /*#__PURE__*/function () {
|
|
|
5406
5437
|
_context2.next = 5;
|
|
5407
5438
|
break;
|
|
5408
5439
|
}
|
|
5409
|
-
throw new
|
|
5440
|
+
throw new InvalidParameterError('Sender address is required for transfers to Ethereum');
|
|
5410
5441
|
case 5:
|
|
5411
5442
|
if (!isTMultiLocation(address)) {
|
|
5412
5443
|
_context2.next = 7;
|
|
5413
5444
|
break;
|
|
5414
5445
|
}
|
|
5415
|
-
throw new
|
|
5446
|
+
throw new InvalidParameterError('Multi-location address is not supported for Ethereum transfers');
|
|
5416
5447
|
case 7:
|
|
5417
5448
|
ethMultiAsset = createMultiAsset(version, asset.amount, asset.multiLocation);
|
|
5418
5449
|
PARA_TO_PARA_FEE_DOT = 500000000n; // 0.5 DOT
|
|
@@ -5559,13 +5590,13 @@ var ParachainNode = /*#__PURE__*/function () {
|
|
|
5559
5590
|
_context3.next = 11;
|
|
5560
5591
|
break;
|
|
5561
5592
|
}
|
|
5562
|
-
throw new
|
|
5593
|
+
throw new InvalidParameterError('Sender address is required for transfers to Ethereum');
|
|
5563
5594
|
case 11:
|
|
5564
5595
|
if (!isTMultiLocation(address)) {
|
|
5565
5596
|
_context3.next = 13;
|
|
5566
5597
|
break;
|
|
5567
5598
|
}
|
|
5568
|
-
throw new
|
|
5599
|
+
throw new InvalidParameterError('Multi-location address is not supported for Ethereum transfers');
|
|
5569
5600
|
case 13:
|
|
5570
5601
|
ethMultiAsset = createMultiAsset(version, asset.amount, asset.multiLocation);
|
|
5571
5602
|
_context3.next = 16;
|
|
@@ -5950,7 +5981,7 @@ var createExecuteXcm = function createExecuteXcm(input, weight, executionFee) {
|
|
|
5950
5981
|
_extractVersionFromHe4[0];
|
|
5951
5982
|
var beneficiary = _extractVersionFromHe4[1];
|
|
5952
5983
|
if (!asset.multiLocation) {
|
|
5953
|
-
throw new
|
|
5984
|
+
throw new InvalidParameterError("Asset ".concat(JSON.stringify(asset), " has no multiLocation"));
|
|
5954
5985
|
}
|
|
5955
5986
|
var transformedMultiLocation = transformMultiLocation(asset.multiLocation);
|
|
5956
5987
|
var amountWithoutFee = BigInt(asset.amount) - executionFee;
|
|
@@ -6133,13 +6164,13 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
6133
6164
|
_context.next = 8;
|
|
6134
6165
|
break;
|
|
6135
6166
|
}
|
|
6136
|
-
throw new
|
|
6167
|
+
throw new InvalidParameterError('Sender address is required for transfers to Ethereum');
|
|
6137
6168
|
case 8:
|
|
6138
6169
|
if (!isTMultiLocation(address)) {
|
|
6139
6170
|
_context.next = 10;
|
|
6140
6171
|
break;
|
|
6141
6172
|
}
|
|
6142
|
-
throw new
|
|
6173
|
+
throw new InvalidParameterError('Multi-location address is not supported for Ethereum transfers');
|
|
6143
6174
|
case 10:
|
|
6144
6175
|
if (isForeignAsset(asset)) {
|
|
6145
6176
|
_context.next = 12;
|
|
@@ -6223,7 +6254,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
6223
6254
|
_context2.next = 8;
|
|
6224
6255
|
break;
|
|
6225
6256
|
}
|
|
6226
|
-
throw new
|
|
6257
|
+
throw new InvalidParameterError('Only Ethereum addresses are supported for Ethereum transfers');
|
|
6227
6258
|
case 8:
|
|
6228
6259
|
if (isForeignAsset(asset)) {
|
|
6229
6260
|
_context2.next = 10;
|
|
@@ -6346,7 +6377,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
6346
6377
|
key: "handleExecuteTransfer",
|
|
6347
6378
|
value: function () {
|
|
6348
6379
|
var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(input) {
|
|
6349
|
-
var api, senderAddress, asset, MIN_FEE, maxU64, dummyTx, dryRunResult, feeDotShifted, toMl, feeConverted, feeConvertedPadded;
|
|
6380
|
+
var api, senderAddress, asset, decimals, multiplier, base, scaledMultiplier, MIN_FEE, maxU64, dummyTx, dryRunResult, feeDotShifted, toMl, feeConverted, feeConvertedPadded;
|
|
6350
6381
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
6351
6382
|
while (1) switch (_context3.prev = _context3.next) {
|
|
6352
6383
|
case 0:
|
|
@@ -6355,56 +6386,61 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
6355
6386
|
_context3.next = 3;
|
|
6356
6387
|
break;
|
|
6357
6388
|
}
|
|
6358
|
-
throw new
|
|
6389
|
+
throw new InvalidParameterError('Please provide senderAddress');
|
|
6359
6390
|
case 3:
|
|
6360
6391
|
validateAddress(senderAddress, this.node, false);
|
|
6361
|
-
|
|
6392
|
+
decimals = asset.decimals;
|
|
6393
|
+
multiplier = decimals > 10 ? 0.4 : 0.15;
|
|
6394
|
+
base = BigInt(Math.pow(10, decimals));
|
|
6395
|
+
scaledMultiplier = BigInt(Math.floor(multiplier * Math.pow(10, decimals)));
|
|
6396
|
+
MIN_FEE = base * scaledMultiplier / BigInt(Math.pow(10, decimals));
|
|
6362
6397
|
maxU64 = (1n << 64n) - 1n;
|
|
6363
6398
|
dummyTx = createExecuteXcm(input, {
|
|
6364
6399
|
refTime: maxU64,
|
|
6365
6400
|
proofSize: maxU64
|
|
6366
6401
|
}, MIN_FEE);
|
|
6367
|
-
_context3.next =
|
|
6402
|
+
_context3.next = 13;
|
|
6368
6403
|
return api.getDryRunCall({
|
|
6369
6404
|
node: this.node,
|
|
6370
6405
|
tx: dummyTx,
|
|
6371
|
-
address: senderAddress
|
|
6406
|
+
address: senderAddress,
|
|
6407
|
+
isFeeAsset: false
|
|
6372
6408
|
});
|
|
6373
|
-
case
|
|
6409
|
+
case 13:
|
|
6374
6410
|
dryRunResult = _context3.sent;
|
|
6375
6411
|
if (dryRunResult.success) {
|
|
6376
|
-
_context3.next =
|
|
6412
|
+
_context3.next = 16;
|
|
6377
6413
|
break;
|
|
6378
6414
|
}
|
|
6379
|
-
throw new
|
|
6380
|
-
case
|
|
6415
|
+
throw new DryRunFailedError("Dry run failed: ".concat(dryRunResult.failureReason));
|
|
6416
|
+
case 16:
|
|
6381
6417
|
if (dryRunResult.weight) {
|
|
6382
|
-
_context3.next =
|
|
6418
|
+
_context3.next = 18;
|
|
6383
6419
|
break;
|
|
6384
6420
|
}
|
|
6385
|
-
throw new
|
|
6386
|
-
case
|
|
6421
|
+
throw new DryRunFailedError('Dry run failed: weight not found');
|
|
6422
|
+
case 18:
|
|
6387
6423
|
feeDotShifted = dryRunResult.fee / 10n;
|
|
6388
6424
|
toMl = transformMultiLocation(asset.multiLocation);
|
|
6389
|
-
_context3.next =
|
|
6425
|
+
_context3.next = 22;
|
|
6390
6426
|
return api.quoteAhPrice(DOT_MULTILOCATION, toMl, feeDotShifted);
|
|
6391
|
-
case
|
|
6427
|
+
case 22:
|
|
6392
6428
|
feeConverted = _context3.sent;
|
|
6393
6429
|
if (feeConverted) {
|
|
6394
|
-
_context3.next =
|
|
6430
|
+
_context3.next = 25;
|
|
6395
6431
|
break;
|
|
6396
6432
|
}
|
|
6397
|
-
throw new
|
|
6398
|
-
case
|
|
6433
|
+
throw new InvalidParameterError("Pool DOT -> ".concat(asset.symbol, " not found."));
|
|
6434
|
+
case 25:
|
|
6399
6435
|
if (!(BigInt(asset.amount) - feeConverted < 0)) {
|
|
6400
|
-
_context3.next =
|
|
6436
|
+
_context3.next = 27;
|
|
6401
6437
|
break;
|
|
6402
6438
|
}
|
|
6403
|
-
throw new
|
|
6404
|
-
case
|
|
6439
|
+
throw new InvalidParameterError("Insufficient balance. Fee: ".concat(feeConverted, ", Amount: ").concat(asset.amount));
|
|
6440
|
+
case 27:
|
|
6405
6441
|
feeConvertedPadded = feeConverted * 3n / 2n; // increases fee by 50%
|
|
6406
6442
|
return _context3.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
|
|
6407
|
-
case
|
|
6443
|
+
case 29:
|
|
6408
6444
|
case "end":
|
|
6409
6445
|
return _context3.stop();
|
|
6410
6446
|
}
|
|
@@ -6430,7 +6466,10 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
6430
6466
|
if (!isAssetEqual(feeAsset, asset)) {
|
|
6431
6467
|
throw new InvalidCurrencyError("Fee asset does not match transfer asset.");
|
|
6432
6468
|
}
|
|
6433
|
-
|
|
6469
|
+
var isNativeAsset = asset.symbol === this.getNativeAssetSymbol();
|
|
6470
|
+
if (!isNativeAsset) {
|
|
6471
|
+
return Promise.resolve(this.handleExecuteTransfer(input));
|
|
6472
|
+
}
|
|
6434
6473
|
}
|
|
6435
6474
|
if (destination === 'AssetHubKusama') {
|
|
6436
6475
|
return Promise.resolve(this.handleBridgeTransfer(input, 'Kusama'));
|
|
@@ -8141,7 +8180,7 @@ var XTransferTransferImpl = /*#__PURE__*/function () {
|
|
|
8141
8180
|
method = input.method;
|
|
8142
8181
|
var isMultiLocationDestination = _typeof(destination) === 'object';
|
|
8143
8182
|
if (isMultiLocationDestination) {
|
|
8144
|
-
throw new
|
|
8183
|
+
throw new InvalidParameterError('Multilocation destinations are not supported for specific transfer you are trying to create. In special cases such as xTokens or xTransfer pallet try using address multilocation instead (for both destination and address in same multilocation set (eg. X2 - Parachain, Address). For further assistance please open issue in our repository.');
|
|
8145
8184
|
}
|
|
8146
8185
|
var version = Version.V1;
|
|
8147
8186
|
var multiAssets = [createMultiAsset(version, asset.amount, {
|
|
@@ -8741,59 +8780,63 @@ var getOriginFeeDetails = /*#__PURE__*/function () {
|
|
|
8741
8780
|
|
|
8742
8781
|
var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
8743
8782
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
8744
|
-
var api, senderAddress, node, currency, tx, asset, balance, ed, edBN, isNativeAsset, feeToSubtract, _yield$getOriginXcmFe, fee, transferable;
|
|
8783
|
+
var api, senderAddress, node, destination, currency, tx, feeAsset, resolvedFeeAsset, asset, balance, ed, edBN, isNativeAsset, shouldSubstractFee, feeToSubtract, _yield$getOriginXcmFe, fee, transferable;
|
|
8745
8784
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
8746
8785
|
while (1) switch (_context.prev = _context.next) {
|
|
8747
8786
|
case 0:
|
|
8748
|
-
api = _ref.api, senderAddress = _ref.senderAddress, node = _ref.
|
|
8787
|
+
api = _ref.api, senderAddress = _ref.senderAddress, node = _ref.origin, destination = _ref.destination, currency = _ref.currency, tx = _ref.tx, feeAsset = _ref.feeAsset;
|
|
8749
8788
|
validateAddress(senderAddress, node, false);
|
|
8789
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, node, destination, currency) : undefined;
|
|
8750
8790
|
asset = findAssetForNodeOrThrow(node, currency, null);
|
|
8751
|
-
_context.next =
|
|
8791
|
+
_context.next = 6;
|
|
8752
8792
|
return getAssetBalanceInternal({
|
|
8753
8793
|
api: api,
|
|
8754
8794
|
address: senderAddress,
|
|
8755
8795
|
node: node,
|
|
8756
8796
|
currency: currency
|
|
8757
8797
|
});
|
|
8758
|
-
case
|
|
8798
|
+
case 6:
|
|
8759
8799
|
balance = _context.sent;
|
|
8760
8800
|
ed = getExistentialDeposit(node, currency);
|
|
8761
8801
|
if (!(ed === null)) {
|
|
8762
|
-
_context.next =
|
|
8802
|
+
_context.next = 10;
|
|
8763
8803
|
break;
|
|
8764
8804
|
}
|
|
8765
|
-
throw new
|
|
8766
|
-
case
|
|
8805
|
+
throw new InvalidParameterError("Cannot get existential deposit for currency ".concat(JSON.stringify(currency), "."));
|
|
8806
|
+
case 10:
|
|
8767
8807
|
edBN = BigInt(ed);
|
|
8768
8808
|
isNativeAsset = getNativeAssetSymbol(node) === asset.symbol;
|
|
8809
|
+
shouldSubstractFee = isNativeAsset || node === 'AssetHubPolkadot' && resolvedFeeAsset && isAssetEqual(resolvedFeeAsset, asset);
|
|
8769
8810
|
feeToSubtract = 0n;
|
|
8770
|
-
if (!
|
|
8771
|
-
_context.next =
|
|
8811
|
+
if (!shouldSubstractFee) {
|
|
8812
|
+
_context.next = 22;
|
|
8772
8813
|
break;
|
|
8773
8814
|
}
|
|
8774
|
-
_context.next =
|
|
8815
|
+
_context.next = 17;
|
|
8775
8816
|
return getOriginXcmFee({
|
|
8776
8817
|
api: api,
|
|
8777
8818
|
tx: tx,
|
|
8778
8819
|
origin: node,
|
|
8779
8820
|
destination: node,
|
|
8780
8821
|
senderAddress: senderAddress,
|
|
8822
|
+
feeAsset: feeAsset,
|
|
8823
|
+
currency: currency,
|
|
8781
8824
|
disableFallback: false
|
|
8782
8825
|
});
|
|
8783
|
-
case
|
|
8826
|
+
case 17:
|
|
8784
8827
|
_yield$getOriginXcmFe = _context.sent;
|
|
8785
8828
|
fee = _yield$getOriginXcmFe.fee;
|
|
8786
8829
|
if (!(fee === undefined)) {
|
|
8787
|
-
_context.next =
|
|
8830
|
+
_context.next = 21;
|
|
8788
8831
|
break;
|
|
8789
8832
|
}
|
|
8790
|
-
throw new
|
|
8791
|
-
case
|
|
8833
|
+
throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(node, "."));
|
|
8834
|
+
case 21:
|
|
8792
8835
|
feeToSubtract = fee;
|
|
8793
|
-
case
|
|
8836
|
+
case 22:
|
|
8794
8837
|
transferable = balance - edBN - feeToSubtract;
|
|
8795
8838
|
return _context.abrupt("return", transferable > 0n ? transferable : 0n);
|
|
8796
|
-
case
|
|
8839
|
+
case 24:
|
|
8797
8840
|
case "end":
|
|
8798
8841
|
return _context.stop();
|
|
8799
8842
|
}
|
|
@@ -8836,70 +8879,89 @@ var getTransferableAmount = /*#__PURE__*/function () {
|
|
|
8836
8879
|
|
|
8837
8880
|
var getTransferInfo = /*#__PURE__*/function () {
|
|
8838
8881
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
8839
|
-
var api, tx, origin, destination, senderAddress, address, currency, destApi, destAsset, destCurrency,
|
|
8882
|
+
var api, tx, origin, destination, senderAddress, address, currency, feeAsset, resolvedFeeAsset, destApi, destAsset, destCurrency, originBalanceFee, originBalance, destBalance, edOrigin, edOriginBn, edDest, edDestBn, _yield$getXcmFee, _yield$getXcmFee$orig, originFee, originFeeCurrency, _yield$getXcmFee$dest, destFee, destFeeCurrency, destXcmFeeBalance, isDestFeeInNativeCurrency, destRecipientNativeBalance, isFeeAssetAh, originBalanceAfter, originBalanceFeeAfter, originBalanceNativeSufficient, originBalanceSufficient, destAmount, destBalanceSufficient, destBalanceSufficientResult, destBalanceAfter, destbalanceAfterResult, receivedAmount, destXcmFeeBalanceAfter;
|
|
8840
8883
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
8841
8884
|
while (1) switch (_context.prev = _context.next) {
|
|
8842
8885
|
case 0:
|
|
8843
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
|
|
8844
|
-
|
|
8886
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset;
|
|
8887
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
8888
|
+
_context.next = 4;
|
|
8845
8889
|
return api.init(origin);
|
|
8846
|
-
case
|
|
8890
|
+
case 4:
|
|
8847
8891
|
api.setDisconnectAllowed(false);
|
|
8848
8892
|
destApi = api.clone();
|
|
8849
|
-
_context.next =
|
|
8893
|
+
_context.next = 8;
|
|
8850
8894
|
return destApi.init(destination);
|
|
8851
|
-
case
|
|
8895
|
+
case 8:
|
|
8852
8896
|
destApi.setDisconnectAllowed(false);
|
|
8853
|
-
_context.prev =
|
|
8897
|
+
_context.prev = 9;
|
|
8854
8898
|
destAsset = findAssetOnDestOrThrow(origin, destination, currency);
|
|
8855
8899
|
destCurrency = destAsset.multiLocation ? {
|
|
8856
8900
|
multilocation: destAsset.multiLocation
|
|
8857
8901
|
} : {
|
|
8858
8902
|
symbol: destAsset.symbol
|
|
8859
8903
|
};
|
|
8860
|
-
|
|
8861
|
-
|
|
8904
|
+
if (!(feeAsset && resolvedFeeAsset)) {
|
|
8905
|
+
_context.next = 18;
|
|
8906
|
+
break;
|
|
8907
|
+
}
|
|
8908
|
+
_context.next = 15;
|
|
8909
|
+
return getAssetBalanceInternal({
|
|
8910
|
+
api: api,
|
|
8862
8911
|
address: senderAddress,
|
|
8863
8912
|
node: origin,
|
|
8864
|
-
|
|
8913
|
+
currency: feeAsset
|
|
8865
8914
|
});
|
|
8866
|
-
case
|
|
8867
|
-
|
|
8868
|
-
_context.next =
|
|
8915
|
+
case 15:
|
|
8916
|
+
_context.t0 = _context.sent;
|
|
8917
|
+
_context.next = 21;
|
|
8918
|
+
break;
|
|
8919
|
+
case 18:
|
|
8920
|
+
_context.next = 20;
|
|
8921
|
+
return getBalanceNativeInternal({
|
|
8922
|
+
api: api,
|
|
8923
|
+
address: senderAddress,
|
|
8924
|
+
node: origin
|
|
8925
|
+
});
|
|
8926
|
+
case 20:
|
|
8927
|
+
_context.t0 = _context.sent;
|
|
8928
|
+
case 21:
|
|
8929
|
+
originBalanceFee = _context.t0;
|
|
8930
|
+
_context.next = 24;
|
|
8869
8931
|
return getAssetBalanceInternal({
|
|
8870
8932
|
api: api,
|
|
8871
8933
|
address: senderAddress,
|
|
8872
8934
|
node: origin,
|
|
8873
8935
|
currency: currency
|
|
8874
8936
|
});
|
|
8875
|
-
case
|
|
8937
|
+
case 24:
|
|
8876
8938
|
originBalance = _context.sent;
|
|
8877
|
-
_context.next =
|
|
8939
|
+
_context.next = 27;
|
|
8878
8940
|
return getAssetBalanceInternal({
|
|
8879
8941
|
api: destApi,
|
|
8880
8942
|
address: address,
|
|
8881
8943
|
node: destination,
|
|
8882
8944
|
currency: destCurrency
|
|
8883
8945
|
});
|
|
8884
|
-
case
|
|
8946
|
+
case 27:
|
|
8885
8947
|
destBalance = _context.sent;
|
|
8886
8948
|
edOrigin = getExistentialDeposit(origin, currency);
|
|
8887
8949
|
if (edOrigin) {
|
|
8888
|
-
_context.next =
|
|
8950
|
+
_context.next = 31;
|
|
8889
8951
|
break;
|
|
8890
8952
|
}
|
|
8891
8953
|
throw new InvalidParameterError("Existential deposit not found for ".concat(origin, " with currency ").concat(JSON.stringify(currency)));
|
|
8892
|
-
case
|
|
8954
|
+
case 31:
|
|
8893
8955
|
edOriginBn = BigInt(edOrigin);
|
|
8894
8956
|
edDest = getExistentialDeposit(destination, destCurrency);
|
|
8895
8957
|
if (edDest) {
|
|
8896
|
-
_context.next =
|
|
8958
|
+
_context.next = 35;
|
|
8897
8959
|
break;
|
|
8898
8960
|
}
|
|
8899
8961
|
throw new InvalidParameterError("Existential deposit not found for ".concat(destination, " with currency ").concat(JSON.stringify(currency)));
|
|
8900
|
-
case
|
|
8962
|
+
case 35:
|
|
8901
8963
|
edDestBn = BigInt(edDest);
|
|
8902
|
-
_context.next =
|
|
8964
|
+
_context.next = 38;
|
|
8903
8965
|
return getXcmFee({
|
|
8904
8966
|
api: api,
|
|
8905
8967
|
tx: tx,
|
|
@@ -8908,9 +8970,10 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8908
8970
|
senderAddress: senderAddress,
|
|
8909
8971
|
address: address,
|
|
8910
8972
|
currency: currency,
|
|
8973
|
+
feeAsset: feeAsset,
|
|
8911
8974
|
disableFallback: false
|
|
8912
8975
|
});
|
|
8913
|
-
case
|
|
8976
|
+
case 38:
|
|
8914
8977
|
_yield$getXcmFee = _context.sent;
|
|
8915
8978
|
_yield$getXcmFee$orig = _yield$getXcmFee.origin;
|
|
8916
8979
|
originFee = _yield$getXcmFee$orig.fee;
|
|
@@ -8919,39 +8982,42 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8919
8982
|
destFee = _yield$getXcmFee$dest.fee;
|
|
8920
8983
|
destFeeCurrency = _yield$getXcmFee$dest.currency;
|
|
8921
8984
|
if (!(originFee === undefined)) {
|
|
8922
|
-
_context.next =
|
|
8985
|
+
_context.next = 47;
|
|
8923
8986
|
break;
|
|
8924
8987
|
}
|
|
8925
|
-
throw new
|
|
8926
|
-
case
|
|
8988
|
+
throw new InvalidParameterError("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(origin, "."));
|
|
8989
|
+
case 47:
|
|
8927
8990
|
isDestFeeInNativeCurrency = destFeeCurrency === getNativeAssetSymbol(destination);
|
|
8928
8991
|
if (!isDestFeeInNativeCurrency) {
|
|
8929
|
-
_context.next =
|
|
8992
|
+
_context.next = 55;
|
|
8930
8993
|
break;
|
|
8931
8994
|
}
|
|
8932
|
-
_context.next =
|
|
8995
|
+
_context.next = 51;
|
|
8933
8996
|
return getBalanceNativeInternal({
|
|
8934
8997
|
address: address,
|
|
8935
8998
|
node: destination,
|
|
8936
8999
|
api: destApi
|
|
8937
9000
|
});
|
|
8938
|
-
case
|
|
9001
|
+
case 51:
|
|
8939
9002
|
destRecipientNativeBalance = _context.sent;
|
|
8940
9003
|
destXcmFeeBalance = destRecipientNativeBalance;
|
|
8941
|
-
_context.next =
|
|
9004
|
+
_context.next = 56;
|
|
8942
9005
|
break;
|
|
8943
|
-
case
|
|
9006
|
+
case 55:
|
|
8944
9007
|
destXcmFeeBalance = destBalance;
|
|
8945
|
-
case
|
|
9008
|
+
case 56:
|
|
9009
|
+
isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && isAssetEqual(resolvedFeeAsset, destAsset);
|
|
8946
9010
|
originBalanceAfter = originBalance - BigInt(currency.amount);
|
|
8947
|
-
|
|
8948
|
-
originBalanceNativeSufficient =
|
|
9011
|
+
originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - BigInt(currency.amount) : originBalanceFee - originFee;
|
|
9012
|
+
originBalanceNativeSufficient = originBalanceFee >= originFee;
|
|
8949
9013
|
originBalanceSufficient = originBalanceAfter >= edOriginBn;
|
|
8950
|
-
|
|
9014
|
+
destAmount = isFeeAssetAh ? BigInt(currency.amount) - originFee : BigInt(currency.amount);
|
|
9015
|
+
destBalanceSufficient = destAmount - destFee > (destBalance < edDestBn ? edDestBn : 0);
|
|
8951
9016
|
destBalanceSufficientResult = destFeeCurrency !== destAsset.symbol ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceSufficient;
|
|
8952
|
-
destBalanceAfter = destBalance - (destFeeCurrency === destAsset.symbol ? destFee : 0n) +
|
|
9017
|
+
destBalanceAfter = destBalance - (destFeeCurrency === destAsset.symbol ? destFee : 0n) + destAmount;
|
|
8953
9018
|
destbalanceAfterResult = destFeeCurrency !== destAsset.symbol ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceAfter;
|
|
8954
|
-
|
|
9019
|
+
receivedAmount = destbalanceAfterResult instanceof UnableToComputeError ? destbalanceAfterResult : destbalanceAfterResult - destBalance;
|
|
9020
|
+
destXcmFeeBalanceAfter = isFeeAssetAh ? destBalanceAfter : destXcmFeeBalance - destFee + (destFeeCurrency === destAsset.symbol ? BigInt(currency.amount) : 0n);
|
|
8955
9021
|
return _context.abrupt("return", {
|
|
8956
9022
|
chain: {
|
|
8957
9023
|
origin: origin,
|
|
@@ -8969,14 +9035,15 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8969
9035
|
xcmFee: {
|
|
8970
9036
|
sufficient: originBalanceNativeSufficient,
|
|
8971
9037
|
fee: originFee,
|
|
8972
|
-
balance:
|
|
8973
|
-
balanceAfter:
|
|
9038
|
+
balance: originBalanceFee,
|
|
9039
|
+
balanceAfter: originBalanceFeeAfter,
|
|
8974
9040
|
currencySymbol: originFeeCurrency
|
|
8975
9041
|
}
|
|
8976
9042
|
},
|
|
8977
9043
|
destination: {
|
|
8978
9044
|
receivedCurrency: {
|
|
8979
9045
|
sufficient: destBalanceSufficientResult,
|
|
9046
|
+
receivedAmount: receivedAmount,
|
|
8980
9047
|
balance: destBalance,
|
|
8981
9048
|
balanceAfter: destbalanceAfterResult,
|
|
8982
9049
|
currencySymbol: destAsset.symbol,
|
|
@@ -8990,22 +9057,22 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8990
9057
|
}
|
|
8991
9058
|
}
|
|
8992
9059
|
});
|
|
8993
|
-
case
|
|
8994
|
-
_context.prev =
|
|
9060
|
+
case 69:
|
|
9061
|
+
_context.prev = 69;
|
|
8995
9062
|
api.setDisconnectAllowed(true);
|
|
8996
9063
|
destApi.setDisconnectAllowed(true);
|
|
8997
|
-
_context.next =
|
|
9064
|
+
_context.next = 74;
|
|
8998
9065
|
return api.disconnect();
|
|
8999
|
-
case
|
|
9000
|
-
_context.next =
|
|
9066
|
+
case 74:
|
|
9067
|
+
_context.next = 76;
|
|
9001
9068
|
return destApi.disconnect();
|
|
9002
|
-
case
|
|
9003
|
-
return _context.finish(
|
|
9004
|
-
case
|
|
9069
|
+
case 76:
|
|
9070
|
+
return _context.finish(69);
|
|
9071
|
+
case 77:
|
|
9005
9072
|
case "end":
|
|
9006
9073
|
return _context.stop();
|
|
9007
9074
|
}
|
|
9008
|
-
}, _callee, null, [[
|
|
9075
|
+
}, _callee, null, [[9,, 69, 77]]);
|
|
9009
9076
|
}));
|
|
9010
9077
|
return function getTransferInfo(_x) {
|
|
9011
9078
|
return _ref2.apply(this, arguments);
|
|
@@ -9014,11 +9081,11 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
9014
9081
|
|
|
9015
9082
|
var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
9016
9083
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
9017
|
-
var api, tx, origin, destination, address, senderAddress, currency, destApi, asset, destCurrency, ed, edBN, balance, _yield$getXcmFee, dryRunError, _yield$getXcmFee$dest, destFee, destFeeCurrency, destDryRunError;
|
|
9084
|
+
var api, tx, origin, destination, address, senderAddress, feeAsset, currency, destApi, asset, destCurrency, ed, edBN, balance, _yield$getXcmFee, dryRunError, _yield$getXcmFee$dest, destFee, destFeeCurrency, destDryRunError;
|
|
9018
9085
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
9019
9086
|
while (1) switch (_context.prev = _context.next) {
|
|
9020
9087
|
case 0:
|
|
9021
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, currency = _ref.currency;
|
|
9088
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, feeAsset = _ref.feeAsset, currency = _ref.currency;
|
|
9022
9089
|
validateAddress(address, destination);
|
|
9023
9090
|
destApi = api.clone();
|
|
9024
9091
|
_context.next = 5;
|
|
@@ -9035,7 +9102,7 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
|
9035
9102
|
_context.next = 10;
|
|
9036
9103
|
break;
|
|
9037
9104
|
}
|
|
9038
|
-
throw new
|
|
9105
|
+
throw new InvalidParameterError("Cannot get existential deposit for currency ".concat(JSON.stringify(currency)));
|
|
9039
9106
|
case 10:
|
|
9040
9107
|
edBN = BigInt(ed);
|
|
9041
9108
|
_context.next = 13;
|
|
@@ -9056,6 +9123,7 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
|
9056
9123
|
senderAddress: senderAddress,
|
|
9057
9124
|
address: address,
|
|
9058
9125
|
currency: currency,
|
|
9126
|
+
feeAsset: feeAsset,
|
|
9059
9127
|
disableFallback: false
|
|
9060
9128
|
});
|
|
9061
9129
|
case 16:
|
|
@@ -9069,7 +9137,7 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
|
9069
9137
|
_context.next = 24;
|
|
9070
9138
|
break;
|
|
9071
9139
|
}
|
|
9072
|
-
throw new
|
|
9140
|
+
throw new InvalidParameterError("Cannot get destination xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(destination, "."));
|
|
9073
9141
|
case 24:
|
|
9074
9142
|
if (!dryRunError) {
|
|
9075
9143
|
_context.next = 26;
|
|
@@ -9183,7 +9251,7 @@ var BatchTransactionManager = /*#__PURE__*/function () {
|
|
|
9183
9251
|
_context.next = 6;
|
|
9184
9252
|
break;
|
|
9185
9253
|
}
|
|
9186
|
-
throw new
|
|
9254
|
+
throw new InvalidParameterError('No transactions to batch.');
|
|
9187
9255
|
case 6:
|
|
9188
9256
|
sameFrom = this.transactionOptions.every(function (tx) {
|
|
9189
9257
|
return tx.from === from;
|
|
@@ -9192,7 +9260,7 @@ var BatchTransactionManager = /*#__PURE__*/function () {
|
|
|
9192
9260
|
_context.next = 9;
|
|
9193
9261
|
break;
|
|
9194
9262
|
}
|
|
9195
|
-
throw new
|
|
9263
|
+
throw new InvalidParameterError('All transactions must have the same origin.');
|
|
9196
9264
|
case 9:
|
|
9197
9265
|
results = this.transactionOptions.map(function (options) {
|
|
9198
9266
|
return send(options);
|
|
@@ -9250,7 +9318,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9250
9318
|
key: "to",
|
|
9251
9319
|
value: function to(node, paraIdTo) {
|
|
9252
9320
|
if (this._options.from && isRelayChain(this._options.from) && node === 'Ethereum') {
|
|
9253
|
-
throw new
|
|
9321
|
+
throw new InvalidParameterError('Transfers from Relay chain to Ethereum are not yet supported.');
|
|
9254
9322
|
}
|
|
9255
9323
|
return new GeneralBuilder(this.api, this.batchManager, _objectSpread2(_objectSpread2({}, this._options), {}, {
|
|
9256
9324
|
to: node,
|
|
@@ -9420,14 +9488,14 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9420
9488
|
_context2.next = 2;
|
|
9421
9489
|
break;
|
|
9422
9490
|
}
|
|
9423
|
-
throw new
|
|
9491
|
+
throw new InvalidParameterError('Transaction manager contains batched items. Use buildBatch() to process them.');
|
|
9424
9492
|
case 2:
|
|
9425
9493
|
_this$_options = this._options, from = _this$_options.from, to = _this$_options.to;
|
|
9426
9494
|
if (!(!isTMultiLocation(to) && isRelayChain(from) && isRelayChain(to) && from !== to)) {
|
|
9427
9495
|
_context2.next = 5;
|
|
9428
9496
|
break;
|
|
9429
9497
|
}
|
|
9430
|
-
throw new
|
|
9498
|
+
throw new InvalidParameterError('Transfers between relay chains are not yet supported.');
|
|
9431
9499
|
case 5:
|
|
9432
9500
|
return _context2.abrupt("return", send(_objectSpread2({
|
|
9433
9501
|
api: this.api
|
|
@@ -9447,11 +9515,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9447
9515
|
key: "dryRun",
|
|
9448
9516
|
value: function () {
|
|
9449
9517
|
var _dryRun2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
9450
|
-
var _this$_options2, to, address, senderAddress, tx;
|
|
9518
|
+
var _this$_options2, to, address, senderAddress, feeAsset, tx;
|
|
9451
9519
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
9452
9520
|
while (1) switch (_context3.prev = _context3.next) {
|
|
9453
9521
|
case 0:
|
|
9454
|
-
_this$_options2 = this._options, to = _this$_options2.to, address = _this$_options2.address, senderAddress = _this$_options2.senderAddress;
|
|
9522
|
+
_this$_options2 = this._options, to = _this$_options2.to, address = _this$_options2.address, senderAddress = _this$_options2.senderAddress, feeAsset = _this$_options2.feeAsset;
|
|
9455
9523
|
_context3.next = 3;
|
|
9456
9524
|
return this.build();
|
|
9457
9525
|
case 3:
|
|
@@ -9481,7 +9549,8 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9481
9549
|
origin: this._options.from,
|
|
9482
9550
|
destination: to,
|
|
9483
9551
|
currency: this._options.currency,
|
|
9484
|
-
senderAddress: this._options.senderAddress
|
|
9552
|
+
senderAddress: this._options.senderAddress,
|
|
9553
|
+
feeAsset: feeAsset
|
|
9485
9554
|
}));
|
|
9486
9555
|
case 11:
|
|
9487
9556
|
case "end":
|
|
@@ -9510,6 +9579,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9510
9579
|
to,
|
|
9511
9580
|
address,
|
|
9512
9581
|
senderAddress,
|
|
9582
|
+
feeAsset,
|
|
9513
9583
|
tx,
|
|
9514
9584
|
_args4 = arguments;
|
|
9515
9585
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
@@ -9518,7 +9588,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9518
9588
|
_ref = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {
|
|
9519
9589
|
disableFallback: false
|
|
9520
9590
|
}, disableFallback = _ref.disableFallback;
|
|
9521
|
-
_this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress;
|
|
9591
|
+
_this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress, feeAsset = _this$_options3.feeAsset;
|
|
9522
9592
|
assertToIsStringAndNoEthereum(to);
|
|
9523
9593
|
assertAddressIsString(address);
|
|
9524
9594
|
_context4.next = 6;
|
|
@@ -9535,6 +9605,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9535
9605
|
senderAddress: senderAddress,
|
|
9536
9606
|
address: address,
|
|
9537
9607
|
currency: this._options.currency,
|
|
9608
|
+
feeAsset: feeAsset,
|
|
9538
9609
|
disableFallback: disableFallback
|
|
9539
9610
|
});
|
|
9540
9611
|
case 10:
|
|
@@ -9572,6 +9643,8 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9572
9643
|
from,
|
|
9573
9644
|
to,
|
|
9574
9645
|
senderAddress,
|
|
9646
|
+
currency,
|
|
9647
|
+
feeAsset,
|
|
9575
9648
|
tx,
|
|
9576
9649
|
_args5 = arguments;
|
|
9577
9650
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
@@ -9580,7 +9653,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9580
9653
|
_ref2 = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {
|
|
9581
9654
|
disableFallback: false
|
|
9582
9655
|
}, disableFallback = _ref2.disableFallback;
|
|
9583
|
-
_this$_options4 = this._options, from = _this$_options4.from, to = _this$_options4.to, senderAddress = _this$_options4.senderAddress;
|
|
9656
|
+
_this$_options4 = this._options, from = _this$_options4.from, to = _this$_options4.to, senderAddress = _this$_options4.senderAddress, currency = _this$_options4.currency, feeAsset = _this$_options4.feeAsset;
|
|
9584
9657
|
assertToIsStringAndNoEthereum(to);
|
|
9585
9658
|
_context5.next = 5;
|
|
9586
9659
|
return this.build();
|
|
@@ -9594,6 +9667,8 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9594
9667
|
origin: from,
|
|
9595
9668
|
destination: to,
|
|
9596
9669
|
senderAddress: senderAddress,
|
|
9670
|
+
currency: currency,
|
|
9671
|
+
feeAsset: feeAsset,
|
|
9597
9672
|
disableFallback: disableFallback
|
|
9598
9673
|
});
|
|
9599
9674
|
case 9:
|
|
@@ -9724,26 +9799,29 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9724
9799
|
key: "getTransferableAmount",
|
|
9725
9800
|
value: (function () {
|
|
9726
9801
|
var _getTransferableAmount2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
9727
|
-
var _this$_options7, from, senderAddress, currency, tx;
|
|
9802
|
+
var _this$_options7, from, to, senderAddress, currency, feeAsset, tx;
|
|
9728
9803
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
9729
9804
|
while (1) switch (_context8.prev = _context8.next) {
|
|
9730
9805
|
case 0:
|
|
9731
|
-
_this$_options7 = this._options, from = _this$_options7.from, senderAddress = _this$_options7.senderAddress, currency = _this$_options7.currency;
|
|
9732
|
-
|
|
9806
|
+
_this$_options7 = this._options, from = _this$_options7.from, to = _this$_options7.to, senderAddress = _this$_options7.senderAddress, currency = _this$_options7.currency, feeAsset = _this$_options7.feeAsset;
|
|
9807
|
+
assertToIsStringAndNoEthereum(to);
|
|
9808
|
+
_context8.next = 4;
|
|
9733
9809
|
return this.build();
|
|
9734
|
-
case
|
|
9810
|
+
case 4:
|
|
9735
9811
|
tx = _context8.sent;
|
|
9736
|
-
_context8.next =
|
|
9812
|
+
_context8.next = 7;
|
|
9737
9813
|
return getTransferableAmount({
|
|
9738
9814
|
api: this.api,
|
|
9739
9815
|
tx: tx,
|
|
9740
|
-
|
|
9816
|
+
origin: from,
|
|
9817
|
+
destination: to,
|
|
9741
9818
|
senderAddress: senderAddress,
|
|
9819
|
+
feeAsset: feeAsset,
|
|
9742
9820
|
currency: currency
|
|
9743
9821
|
});
|
|
9744
|
-
case 6:
|
|
9745
|
-
return _context8.abrupt("return", _context8.sent);
|
|
9746
9822
|
case 7:
|
|
9823
|
+
return _context8.abrupt("return", _context8.sent);
|
|
9824
|
+
case 8:
|
|
9747
9825
|
case "end":
|
|
9748
9826
|
return _context8.stop();
|
|
9749
9827
|
}
|
|
@@ -9764,11 +9842,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9764
9842
|
key: "verifyEdOnDestination",
|
|
9765
9843
|
value: (function () {
|
|
9766
9844
|
var _verifyEdOnDestination2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
9767
|
-
var _this$_options8, from, to, address, currency, senderAddress, tx;
|
|
9845
|
+
var _this$_options8, from, to, address, currency, senderAddress, feeAsset, tx;
|
|
9768
9846
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
9769
9847
|
while (1) switch (_context9.prev = _context9.next) {
|
|
9770
9848
|
case 0:
|
|
9771
|
-
_this$_options8 = this._options, from = _this$_options8.from, to = _this$_options8.to, address = _this$_options8.address, currency = _this$_options8.currency, senderAddress = _this$_options8.senderAddress;
|
|
9849
|
+
_this$_options8 = this._options, from = _this$_options8.from, to = _this$_options8.to, address = _this$_options8.address, currency = _this$_options8.currency, senderAddress = _this$_options8.senderAddress, feeAsset = _this$_options8.feeAsset;
|
|
9772
9850
|
assertToIsStringAndNoEthereum(to);
|
|
9773
9851
|
assertAddressIsString(address);
|
|
9774
9852
|
_context9.next = 5;
|
|
@@ -9782,6 +9860,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9782
9860
|
destination: to,
|
|
9783
9861
|
address: address,
|
|
9784
9862
|
senderAddress: senderAddress,
|
|
9863
|
+
feeAsset: feeAsset,
|
|
9785
9864
|
currency: currency
|
|
9786
9865
|
}));
|
|
9787
9866
|
case 7:
|
|
@@ -9805,11 +9884,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9805
9884
|
key: "getTransferInfo",
|
|
9806
9885
|
value: (function () {
|
|
9807
9886
|
var _getTransferInfo2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0() {
|
|
9808
|
-
var _this$_options9, from, to, address, currency, senderAddress, tx;
|
|
9887
|
+
var _this$_options9, from, to, address, currency, senderAddress, feeAsset, tx;
|
|
9809
9888
|
return _regeneratorRuntime().wrap(function _callee0$(_context0) {
|
|
9810
9889
|
while (1) switch (_context0.prev = _context0.next) {
|
|
9811
9890
|
case 0:
|
|
9812
|
-
_this$_options9 = this._options, from = _this$_options9.from, to = _this$_options9.to, address = _this$_options9.address, currency = _this$_options9.currency, senderAddress = _this$_options9.senderAddress;
|
|
9891
|
+
_this$_options9 = this._options, from = _this$_options9.from, to = _this$_options9.to, address = _this$_options9.address, currency = _this$_options9.currency, senderAddress = _this$_options9.senderAddress, feeAsset = _this$_options9.feeAsset;
|
|
9813
9892
|
assertToIsStringAndNoEthereum(to);
|
|
9814
9893
|
assertAddressIsString(address);
|
|
9815
9894
|
_context0.next = 5;
|
|
@@ -9823,7 +9902,8 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9823
9902
|
destination: to,
|
|
9824
9903
|
address: address,
|
|
9825
9904
|
senderAddress: senderAddress,
|
|
9826
|
-
currency: currency
|
|
9905
|
+
currency: currency,
|
|
9906
|
+
feeAsset: feeAsset
|
|
9827
9907
|
}));
|
|
9828
9908
|
case 7:
|
|
9829
9909
|
case "end":
|