@paraspell/sdk-core 10.0.0 → 10.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +267 -187
- package/dist/index.d.ts +27 -7
- package/dist/index.mjs +268 -188
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -2591,12 +2591,15 @@ var getMultiLocationTokenId = function getMultiLocationTokenId(location, node) {
|
|
|
2591
2591
|
};
|
|
2592
2592
|
|
|
2593
2593
|
var computeFeeFromDryRun = function computeFeeFromDryRun(dryRun, node, executionFee) {
|
|
2594
|
+
var isFeeAsset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
2594
2595
|
// Extract delivery fees from emitted events
|
|
2595
2596
|
var deliveryFees = [];
|
|
2597
|
+
var assetConversionFee = 0n;
|
|
2596
2598
|
var _iterator = _createForOfIteratorHelper(dryRun.value.emitted_events),
|
|
2597
2599
|
_step;
|
|
2598
2600
|
try {
|
|
2599
2601
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2602
|
+
var _e$value, _e$value2;
|
|
2600
2603
|
var e = _step.value;
|
|
2601
2604
|
var isXcmEvent = e.type === 'XcmPallet' || e.type === 'PolkadotXcm' || e.type === 'CumulusXcm';
|
|
2602
2605
|
var isFeesPaid = e.value.type === 'FeesPaid';
|
|
@@ -2621,20 +2624,26 @@ var computeFeeFromDryRun = function computeFeeFromDryRun(dryRun, node, execution
|
|
|
2621
2624
|
_iterator2.f();
|
|
2622
2625
|
}
|
|
2623
2626
|
}
|
|
2627
|
+
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) {
|
|
2628
|
+
assetConversionFee += e.value.value.amount_in;
|
|
2629
|
+
}
|
|
2624
2630
|
}
|
|
2625
2631
|
} catch (err) {
|
|
2626
2632
|
_iterator.e(err);
|
|
2627
2633
|
} finally {
|
|
2628
2634
|
_iterator.f();
|
|
2629
2635
|
}
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2636
|
+
if (isFeeAsset && assetConversionFee > 0n) {
|
|
2637
|
+
return assetConversionFee;
|
|
2638
|
+
} else {
|
|
2639
|
+
var nativeAssetSymbol = assets.getNativeAssetSymbol(node);
|
|
2640
|
+
var totalDeliveryFees = deliveryFees.filter(function (df) {
|
|
2641
|
+
return df.tokenSymbol === nativeAssetSymbol;
|
|
2642
|
+
}).reduce(function (acc, df) {
|
|
2643
|
+
return acc + df.plancks;
|
|
2644
|
+
}, 0n);
|
|
2645
|
+
return totalDeliveryFees + executionFee;
|
|
2646
|
+
}
|
|
2638
2647
|
};
|
|
2639
2648
|
|
|
2640
2649
|
var getMultiLocationTokenIdPjs = function getMultiLocationTokenIdPjs(location, node) {
|
|
@@ -2951,6 +2960,15 @@ var getTNode = function getTNode(paraId, ecosystem) {
|
|
|
2951
2960
|
})) !== null && _NODE_NAMES_DOT_KSM$f !== void 0 ? _NODE_NAMES_DOT_KSM$f : null;
|
|
2952
2961
|
};
|
|
2953
2962
|
|
|
2963
|
+
var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
|
|
2964
|
+
var asset = assets.findAsset(origin, feeAsset, !sdkCommon.isTMultiLocation(destination) ? destination : null);
|
|
2965
|
+
var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(assets.isTMultiAsset);
|
|
2966
|
+
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
2967
|
+
throwUnsupportedCurrency(feeAsset, origin);
|
|
2968
|
+
}
|
|
2969
|
+
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
2970
|
+
};
|
|
2971
|
+
|
|
2954
2972
|
var isAssetHub = function isAssetHub(chain) {
|
|
2955
2973
|
return chain === 'AssetHubPolkadot' || chain === 'AssetHubKusama';
|
|
2956
2974
|
};
|
|
@@ -3030,11 +3048,12 @@ var createOriginLocation = function createOriginLocation(origin, destination) {
|
|
|
3030
3048
|
};
|
|
3031
3049
|
var getDestXcmFee = /*#__PURE__*/function () {
|
|
3032
3050
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
3033
|
-
var api, origin, destination, currency, forwardedXcms, disableFallback, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
|
|
3051
|
+
var api, origin, destination, currency, forwardedXcms, asset, feeAsset, originFee, disableFallback, resolvedFeeAsset, calcPaymentInfoFee, dryRunResult, fee, newForwardedXcms, destParaId;
|
|
3034
3052
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
3035
3053
|
while (1) switch (_context2.prev = _context2.next) {
|
|
3036
3054
|
case 0:
|
|
3037
|
-
api = options.api, origin = options.origin, destination = options.destination, currency = options.currency, forwardedXcms = options.forwardedXcms, disableFallback = options.disableFallback;
|
|
3055
|
+
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;
|
|
3056
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
3038
3057
|
calcPaymentInfoFee = /*#__PURE__*/function () {
|
|
3039
3058
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
3040
3059
|
var originAsset;
|
|
@@ -3092,42 +3111,46 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
3092
3111
|
};
|
|
3093
3112
|
}();
|
|
3094
3113
|
if (!(!assets.hasDryRunSupport(destination) || !forwardedXcms)) {
|
|
3095
|
-
_context2.next =
|
|
3114
|
+
_context2.next = 8;
|
|
3096
3115
|
break;
|
|
3097
3116
|
}
|
|
3098
|
-
_context2.next =
|
|
3117
|
+
_context2.next = 6;
|
|
3099
3118
|
return calcPaymentInfoFee();
|
|
3100
|
-
case
|
|
3119
|
+
case 6:
|
|
3101
3120
|
_context2.t0 = _context2.sent;
|
|
3102
3121
|
return _context2.abrupt("return", {
|
|
3103
3122
|
fee: _context2.t0,
|
|
3104
3123
|
feeType: 'paymentInfo'
|
|
3105
3124
|
});
|
|
3106
|
-
case
|
|
3107
|
-
_context2.next =
|
|
3125
|
+
case 8:
|
|
3126
|
+
_context2.next = 10;
|
|
3108
3127
|
return api.getDryRunXcm({
|
|
3109
3128
|
originLocation: addXcmVersionHeader(createOriginLocation(origin, destination), exports.Version.V4),
|
|
3110
3129
|
xcm: forwardedXcms[1][0],
|
|
3111
3130
|
node: destination,
|
|
3112
|
-
origin: origin
|
|
3131
|
+
origin: origin,
|
|
3132
|
+
asset: asset,
|
|
3133
|
+
originFee: originFee,
|
|
3134
|
+
feeAsset: resolvedFeeAsset,
|
|
3135
|
+
amount: BigInt(currency.amount)
|
|
3113
3136
|
});
|
|
3114
|
-
case
|
|
3137
|
+
case 10:
|
|
3115
3138
|
dryRunResult = _context2.sent;
|
|
3116
3139
|
if (dryRunResult.success) {
|
|
3117
|
-
_context2.next =
|
|
3140
|
+
_context2.next = 19;
|
|
3118
3141
|
break;
|
|
3119
3142
|
}
|
|
3120
3143
|
if (!disableFallback) {
|
|
3121
|
-
_context2.next =
|
|
3144
|
+
_context2.next = 14;
|
|
3122
3145
|
break;
|
|
3123
3146
|
}
|
|
3124
3147
|
return _context2.abrupt("return", {
|
|
3125
3148
|
dryRunError: dryRunResult.failureReason
|
|
3126
3149
|
});
|
|
3127
|
-
case
|
|
3128
|
-
_context2.next =
|
|
3150
|
+
case 14:
|
|
3151
|
+
_context2.next = 16;
|
|
3129
3152
|
return calcPaymentInfoFee();
|
|
3130
|
-
case
|
|
3153
|
+
case 16:
|
|
3131
3154
|
_context2.t1 = _context2.sent;
|
|
3132
3155
|
_context2.t2 = dryRunResult.failureReason;
|
|
3133
3156
|
return _context2.abrupt("return", {
|
|
@@ -3135,7 +3158,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
3135
3158
|
feeType: 'paymentInfo',
|
|
3136
3159
|
dryRunError: _context2.t2
|
|
3137
3160
|
});
|
|
3138
|
-
case
|
|
3161
|
+
case 19:
|
|
3139
3162
|
fee = dryRunResult.fee, newForwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
3140
3163
|
return _context2.abrupt("return", {
|
|
3141
3164
|
fee: fee,
|
|
@@ -3143,7 +3166,7 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
3143
3166
|
forwardedXcms: newForwardedXcms,
|
|
3144
3167
|
destParaId: destParaId
|
|
3145
3168
|
});
|
|
3146
|
-
case
|
|
3169
|
+
case 21:
|
|
3147
3170
|
case "end":
|
|
3148
3171
|
return _context2.stop();
|
|
3149
3172
|
}
|
|
@@ -3157,49 +3180,51 @@ var getDestXcmFee = /*#__PURE__*/function () {
|
|
|
3157
3180
|
var dryRunInternal = /*#__PURE__*/function () {
|
|
3158
3181
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
3159
3182
|
var _intermediateFees$ass, _intermediateFees$bri, _destinationDryRun;
|
|
3160
|
-
var origin, destination, currency, api, tx, senderAddress, asset, originDryRun, initialForwardedXcms, initialDestParaId, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId;
|
|
3183
|
+
var origin, destination, currency, api, tx, senderAddress, feeAsset, resolvedFeeAsset, asset, originDryRun, initialForwardedXcms, initialDestParaId, currentOrigin, forwardedXcms, nextParaId, intermediateFees, destinationDryRun, nextChain, hopApi, hopDryRun, newXcms, destParaId;
|
|
3161
3184
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3162
3185
|
while (1) switch (_context.prev = _context.next) {
|
|
3163
3186
|
case 0:
|
|
3164
|
-
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress;
|
|
3187
|
+
origin = options.origin, destination = options.destination, currency = options.currency, api = options.api, tx = options.tx, senderAddress = options.senderAddress, feeAsset = options.feeAsset;
|
|
3188
|
+
resolvedFeeAsset = feeAsset && origin === 'AssetHubPolkadot' ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
3165
3189
|
asset = assets.findAssetForNodeOrThrow(origin, currency, destination);
|
|
3166
|
-
_context.next =
|
|
3190
|
+
_context.next = 5;
|
|
3167
3191
|
return api.getDryRunCall({
|
|
3168
3192
|
tx: tx,
|
|
3169
3193
|
node: origin,
|
|
3170
|
-
address: senderAddress
|
|
3194
|
+
address: senderAddress,
|
|
3195
|
+
isFeeAsset: !!resolvedFeeAsset
|
|
3171
3196
|
});
|
|
3172
|
-
case
|
|
3197
|
+
case 5:
|
|
3173
3198
|
originDryRun = _context.sent;
|
|
3174
3199
|
if (originDryRun.success) {
|
|
3175
|
-
_context.next =
|
|
3200
|
+
_context.next = 8;
|
|
3176
3201
|
break;
|
|
3177
3202
|
}
|
|
3178
3203
|
return _context.abrupt("return", {
|
|
3179
3204
|
origin: originDryRun
|
|
3180
3205
|
});
|
|
3181
|
-
case
|
|
3206
|
+
case 8:
|
|
3182
3207
|
initialForwardedXcms = originDryRun.forwardedXcms, initialDestParaId = originDryRun.destParaId;
|
|
3183
3208
|
currentOrigin = origin;
|
|
3184
3209
|
forwardedXcms = initialForwardedXcms;
|
|
3185
3210
|
nextParaId = initialDestParaId;
|
|
3186
3211
|
intermediateFees = {};
|
|
3187
|
-
case
|
|
3212
|
+
case 13:
|
|
3188
3213
|
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)) {
|
|
3189
|
-
_context.next =
|
|
3214
|
+
_context.next = 40;
|
|
3190
3215
|
break;
|
|
3191
3216
|
}
|
|
3192
3217
|
nextChain = getTNode(nextParaId, determineRelayChain(origin) === 'Polkadot' ? 'polkadot' : 'kusama');
|
|
3193
3218
|
if (nextChain) {
|
|
3194
|
-
_context.next =
|
|
3219
|
+
_context.next = 17;
|
|
3195
3220
|
break;
|
|
3196
3221
|
}
|
|
3197
3222
|
throw new Error("Unable to find TNode for paraId ".concat(nextParaId));
|
|
3198
|
-
case
|
|
3223
|
+
case 17:
|
|
3199
3224
|
hopApi = api.clone();
|
|
3200
|
-
_context.prev =
|
|
3225
|
+
_context.prev = 18;
|
|
3201
3226
|
if (assets.hasDryRunSupport(nextChain)) {
|
|
3202
|
-
_context.next =
|
|
3227
|
+
_context.next = 22;
|
|
3203
3228
|
break;
|
|
3204
3229
|
}
|
|
3205
3230
|
if (nextChain === destination) {
|
|
@@ -3208,19 +3233,23 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
3208
3233
|
failureReason: "DryRunApi is not available on node ".concat(nextChain)
|
|
3209
3234
|
};
|
|
3210
3235
|
}
|
|
3211
|
-
return _context.abrupt("break",
|
|
3212
|
-
case
|
|
3213
|
-
_context.next =
|
|
3236
|
+
return _context.abrupt("break", 40);
|
|
3237
|
+
case 22:
|
|
3238
|
+
_context.next = 24;
|
|
3214
3239
|
return hopApi.init(nextChain, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
3215
|
-
case
|
|
3216
|
-
_context.next =
|
|
3240
|
+
case 24:
|
|
3241
|
+
_context.next = 26;
|
|
3217
3242
|
return hopApi.getDryRunXcm({
|
|
3218
3243
|
originLocation: addXcmVersionHeader(createOriginLocation(currentOrigin, nextChain), exports.Version.V4),
|
|
3219
3244
|
xcm: forwardedXcms[1][0],
|
|
3220
3245
|
node: nextChain,
|
|
3221
|
-
origin: currentOrigin
|
|
3246
|
+
origin: currentOrigin,
|
|
3247
|
+
asset: asset,
|
|
3248
|
+
feeAsset: resolvedFeeAsset,
|
|
3249
|
+
originFee: originDryRun.fee,
|
|
3250
|
+
amount: BigInt(currency.amount)
|
|
3222
3251
|
});
|
|
3223
|
-
case
|
|
3252
|
+
case 26:
|
|
3224
3253
|
hopDryRun = _context.sent;
|
|
3225
3254
|
if (nextChain === destination || sdkCommon.isRelayChain(nextChain) && !sdkCommon.isRelayChain(destination)) {
|
|
3226
3255
|
destinationDryRun = hopDryRun;
|
|
@@ -3230,28 +3259,28 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
3230
3259
|
intermediateFees.bridgeHub = hopDryRun;
|
|
3231
3260
|
}
|
|
3232
3261
|
if (hopDryRun.success) {
|
|
3233
|
-
_context.next =
|
|
3262
|
+
_context.next = 30;
|
|
3234
3263
|
break;
|
|
3235
3264
|
}
|
|
3236
|
-
return _context.abrupt("break",
|
|
3237
|
-
case
|
|
3265
|
+
return _context.abrupt("break", 40);
|
|
3266
|
+
case 30:
|
|
3238
3267
|
newXcms = hopDryRun.forwardedXcms, destParaId = hopDryRun.destParaId;
|
|
3239
3268
|
forwardedXcms = newXcms;
|
|
3240
3269
|
nextParaId = destParaId;
|
|
3241
3270
|
currentOrigin = nextChain;
|
|
3242
|
-
case
|
|
3243
|
-
_context.prev =
|
|
3244
|
-
_context.next =
|
|
3271
|
+
case 34:
|
|
3272
|
+
_context.prev = 34;
|
|
3273
|
+
_context.next = 37;
|
|
3245
3274
|
return hopApi.disconnect();
|
|
3246
|
-
case 36:
|
|
3247
|
-
return _context.finish(33);
|
|
3248
3275
|
case 37:
|
|
3249
|
-
_context.
|
|
3276
|
+
return _context.finish(34);
|
|
3277
|
+
case 38:
|
|
3278
|
+
_context.next = 13;
|
|
3250
3279
|
break;
|
|
3251
|
-
case
|
|
3280
|
+
case 40:
|
|
3252
3281
|
return _context.abrupt("return", {
|
|
3253
3282
|
origin: originDryRun.success ? _objectSpread2(_objectSpread2({}, originDryRun), {}, {
|
|
3254
|
-
currency: assets.getNativeAssetSymbol(origin)
|
|
3283
|
+
currency: resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(origin)
|
|
3255
3284
|
}) : originDryRun,
|
|
3256
3285
|
assetHub: (_intermediateFees$ass = intermediateFees.assetHub) !== null && _intermediateFees$ass !== void 0 && _intermediateFees$ass.success ? _objectSpread2(_objectSpread2({}, intermediateFees.assetHub), {}, {
|
|
3257
3286
|
currency: assets.getNativeAssetSymbol('AssetHubPolkadot')
|
|
@@ -3263,11 +3292,11 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
3263
3292
|
currency: asset.symbol
|
|
3264
3293
|
}) : destinationDryRun
|
|
3265
3294
|
});
|
|
3266
|
-
case
|
|
3295
|
+
case 41:
|
|
3267
3296
|
case "end":
|
|
3268
3297
|
return _context.stop();
|
|
3269
3298
|
}
|
|
3270
|
-
}, _callee, null, [[
|
|
3299
|
+
}, _callee, null, [[18,, 34, 38]]);
|
|
3271
3300
|
}));
|
|
3272
3301
|
return function dryRunInternal(_x) {
|
|
3273
3302
|
return _ref.apply(this, arguments);
|
|
@@ -4384,69 +4413,71 @@ var transferMoonbeamToEth = /*#__PURE__*/function () {
|
|
|
4384
4413
|
|
|
4385
4414
|
var getOriginXcmFee = /*#__PURE__*/function () {
|
|
4386
4415
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
4387
|
-
var api, tx, origin, destination, senderAddress, disableFallback, currency, rawFee, dryRunResult, _rawFee, fee, forwardedXcms, destParaId;
|
|
4416
|
+
var api, tx, origin, destination, senderAddress, disableFallback, feeAsset, currency, resolvedFeeAsset, currencySymbol, rawFee, dryRunResult, _rawFee, fee, forwardedXcms, destParaId;
|
|
4388
4417
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4389
4418
|
while (1) switch (_context.prev = _context.next) {
|
|
4390
4419
|
case 0:
|
|
4391
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback;
|
|
4392
|
-
|
|
4420
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, disableFallback = _ref.disableFallback, feeAsset = _ref.feeAsset, currency = _ref.currency;
|
|
4421
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
4422
|
+
_context.next = 4;
|
|
4393
4423
|
return api.init(origin, DRY_RUN_CLIENT_TIMEOUT_MS);
|
|
4394
|
-
case
|
|
4395
|
-
|
|
4424
|
+
case 4:
|
|
4425
|
+
currencySymbol = resolvedFeeAsset ? resolvedFeeAsset.symbol : assets.getNativeAssetSymbol(origin);
|
|
4396
4426
|
if (assets.hasDryRunSupport(origin)) {
|
|
4397
|
-
_context.next =
|
|
4427
|
+
_context.next = 10;
|
|
4398
4428
|
break;
|
|
4399
4429
|
}
|
|
4400
|
-
_context.next =
|
|
4430
|
+
_context.next = 8;
|
|
4401
4431
|
return api.calculateTransactionFee(tx, senderAddress);
|
|
4402
|
-
case
|
|
4432
|
+
case 8:
|
|
4403
4433
|
rawFee = _context.sent;
|
|
4404
4434
|
return _context.abrupt("return", {
|
|
4405
4435
|
fee: padFee(rawFee, origin, destination, 'origin'),
|
|
4406
|
-
currency:
|
|
4436
|
+
currency: currencySymbol,
|
|
4407
4437
|
feeType: 'paymentInfo'
|
|
4408
4438
|
});
|
|
4409
|
-
case
|
|
4410
|
-
_context.next =
|
|
4439
|
+
case 10:
|
|
4440
|
+
_context.next = 12;
|
|
4411
4441
|
return api.getDryRunCall({
|
|
4412
4442
|
tx: tx,
|
|
4413
4443
|
node: origin,
|
|
4414
|
-
address: senderAddress
|
|
4444
|
+
address: senderAddress,
|
|
4445
|
+
isFeeAsset: !!resolvedFeeAsset
|
|
4415
4446
|
});
|
|
4416
|
-
case
|
|
4447
|
+
case 12:
|
|
4417
4448
|
dryRunResult = _context.sent;
|
|
4418
4449
|
if (dryRunResult.success) {
|
|
4419
|
-
_context.next =
|
|
4450
|
+
_context.next = 20;
|
|
4420
4451
|
break;
|
|
4421
4452
|
}
|
|
4422
4453
|
if (!disableFallback) {
|
|
4423
|
-
_context.next =
|
|
4454
|
+
_context.next = 16;
|
|
4424
4455
|
break;
|
|
4425
4456
|
}
|
|
4426
4457
|
return _context.abrupt("return", {
|
|
4427
4458
|
dryRunError: dryRunResult.failureReason
|
|
4428
4459
|
});
|
|
4429
|
-
case
|
|
4430
|
-
_context.next =
|
|
4460
|
+
case 16:
|
|
4461
|
+
_context.next = 18;
|
|
4431
4462
|
return api.calculateTransactionFee(tx, senderAddress);
|
|
4432
|
-
case
|
|
4463
|
+
case 18:
|
|
4433
4464
|
_rawFee = _context.sent;
|
|
4434
4465
|
return _context.abrupt("return", {
|
|
4435
4466
|
fee: padFee(_rawFee, origin, destination, 'origin'),
|
|
4436
|
-
currency:
|
|
4467
|
+
currency: currencySymbol,
|
|
4437
4468
|
feeType: 'paymentInfo',
|
|
4438
4469
|
dryRunError: dryRunResult.failureReason
|
|
4439
4470
|
});
|
|
4440
|
-
case
|
|
4471
|
+
case 20:
|
|
4441
4472
|
fee = dryRunResult.fee, forwardedXcms = dryRunResult.forwardedXcms, destParaId = dryRunResult.destParaId;
|
|
4442
4473
|
return _context.abrupt("return", {
|
|
4443
4474
|
fee: fee,
|
|
4444
4475
|
feeType: 'dryRun',
|
|
4445
|
-
currency:
|
|
4476
|
+
currency: currencySymbol,
|
|
4446
4477
|
forwardedXcms: forwardedXcms,
|
|
4447
4478
|
destParaId: destParaId
|
|
4448
4479
|
});
|
|
4449
|
-
case
|
|
4480
|
+
case 22:
|
|
4450
4481
|
case "end":
|
|
4451
4482
|
return _context.stop();
|
|
4452
4483
|
}
|
|
@@ -4486,11 +4517,11 @@ var getOriginXcmFeeEstimate = /*#__PURE__*/function () {
|
|
|
4486
4517
|
|
|
4487
4518
|
var getXcmFee = /*#__PURE__*/function () {
|
|
4488
4519
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
4489
|
-
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;
|
|
4520
|
+
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;
|
|
4490
4521
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4491
4522
|
while (1) switch (_context.prev = _context.next) {
|
|
4492
4523
|
case 0:
|
|
4493
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, disableFallback = _ref.disableFallback;
|
|
4524
|
+
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;
|
|
4494
4525
|
asset = assets.findAssetForNodeOrThrow(origin, currency, destination); // Origin fee = execution fee + delivery fees
|
|
4495
4526
|
_context.next = 4;
|
|
4496
4527
|
return getOriginXcmFee({
|
|
@@ -4499,6 +4530,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4499
4530
|
origin: origin,
|
|
4500
4531
|
destination: destination,
|
|
4501
4532
|
senderAddress: senderAddress,
|
|
4533
|
+
feeAsset: feeAsset,
|
|
4534
|
+
currency: currency,
|
|
4502
4535
|
disableFallback: disableFallback
|
|
4503
4536
|
});
|
|
4504
4537
|
case 4:
|
|
@@ -4532,6 +4565,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4532
4565
|
destination: destination,
|
|
4533
4566
|
currency: currency,
|
|
4534
4567
|
address: address,
|
|
4568
|
+
asset: asset,
|
|
4569
|
+
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
4535
4570
|
senderAddress: senderAddress,
|
|
4536
4571
|
disableFallback: disableFallback
|
|
4537
4572
|
});
|
|
@@ -4595,6 +4630,9 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4595
4630
|
currency: currency,
|
|
4596
4631
|
address: address,
|
|
4597
4632
|
senderAddress: senderAddress,
|
|
4633
|
+
asset: asset,
|
|
4634
|
+
feeAsset: feeAsset,
|
|
4635
|
+
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
4598
4636
|
disableFallback: disableFallback
|
|
4599
4637
|
});
|
|
4600
4638
|
case 45:
|
|
@@ -4632,6 +4670,8 @@ var getXcmFee = /*#__PURE__*/function () {
|
|
|
4632
4670
|
destination: destination,
|
|
4633
4671
|
currency: currency,
|
|
4634
4672
|
address: address,
|
|
4673
|
+
asset: asset,
|
|
4674
|
+
originFee: originFee !== null && originFee !== void 0 ? originFee : 0n,
|
|
4635
4675
|
senderAddress: senderAddress,
|
|
4636
4676
|
disableFallback: disableFallback
|
|
4637
4677
|
});
|
|
@@ -4846,15 +4886,6 @@ var resolveAsset = function resolveAsset(currency, origin, destination, assetChe
|
|
|
4846
4886
|
return assetCheckEnabled ? assets.findAsset(origin, currency, !sdkCommon.isTMultiLocation(destination) ? destination : null) : null;
|
|
4847
4887
|
};
|
|
4848
4888
|
|
|
4849
|
-
var resolveFeeAsset = function resolveFeeAsset(feeAsset, origin, destination, currency) {
|
|
4850
|
-
var asset = assets.findAsset(origin, feeAsset, !sdkCommon.isTMultiLocation(destination) ? destination : null);
|
|
4851
|
-
var usesRawOverriddenMultiAssets = 'multiasset' in currency && currency.multiasset.every(assets.isTMultiAsset);
|
|
4852
|
-
if (!asset && !usesRawOverriddenMultiAssets) {
|
|
4853
|
-
throwUnsupportedCurrency(feeAsset, origin);
|
|
4854
|
-
}
|
|
4855
|
-
return asset !== null && asset !== void 0 ? asset : undefined;
|
|
4856
|
-
};
|
|
4857
|
-
|
|
4858
4889
|
var validateAssetSupport = function validateAssetSupport(_ref, assetCheckEnabled, isBridge, asset) {
|
|
4859
4890
|
var origin = _ref.from,
|
|
4860
4891
|
destination = _ref.to,
|
|
@@ -6345,7 +6376,7 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
6345
6376
|
key: "handleExecuteTransfer",
|
|
6346
6377
|
value: function () {
|
|
6347
6378
|
var _handleExecuteTransfer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(input) {
|
|
6348
|
-
var api, senderAddress, asset, MIN_FEE, maxU64, dummyTx, dryRunResult, feeDotShifted, toMl, feeConverted, feeConvertedPadded;
|
|
6379
|
+
var api, senderAddress, asset, decimals, multiplier, base, scaledMultiplier, MIN_FEE, maxU64, dummyTx, dryRunResult, feeDotShifted, toMl, feeConverted, feeConvertedPadded;
|
|
6349
6380
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
6350
6381
|
while (1) switch (_context3.prev = _context3.next) {
|
|
6351
6382
|
case 0:
|
|
@@ -6357,53 +6388,58 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
6357
6388
|
throw new Error('Please provide senderAddress');
|
|
6358
6389
|
case 3:
|
|
6359
6390
|
validateAddress(senderAddress, this.node, false);
|
|
6360
|
-
|
|
6391
|
+
decimals = asset.decimals;
|
|
6392
|
+
multiplier = decimals > 10 ? 0.4 : 0.15;
|
|
6393
|
+
base = BigInt(Math.pow(10, decimals));
|
|
6394
|
+
scaledMultiplier = BigInt(Math.floor(multiplier * Math.pow(10, decimals)));
|
|
6395
|
+
MIN_FEE = base * scaledMultiplier / BigInt(Math.pow(10, decimals));
|
|
6361
6396
|
maxU64 = (1n << 64n) - 1n;
|
|
6362
6397
|
dummyTx = createExecuteXcm(input, {
|
|
6363
6398
|
refTime: maxU64,
|
|
6364
6399
|
proofSize: maxU64
|
|
6365
6400
|
}, MIN_FEE);
|
|
6366
|
-
_context3.next =
|
|
6401
|
+
_context3.next = 13;
|
|
6367
6402
|
return api.getDryRunCall({
|
|
6368
6403
|
node: this.node,
|
|
6369
6404
|
tx: dummyTx,
|
|
6370
|
-
address: senderAddress
|
|
6405
|
+
address: senderAddress,
|
|
6406
|
+
isFeeAsset: false
|
|
6371
6407
|
});
|
|
6372
|
-
case
|
|
6408
|
+
case 13:
|
|
6373
6409
|
dryRunResult = _context3.sent;
|
|
6374
6410
|
if (dryRunResult.success) {
|
|
6375
|
-
_context3.next =
|
|
6411
|
+
_context3.next = 16;
|
|
6376
6412
|
break;
|
|
6377
6413
|
}
|
|
6378
6414
|
throw new Error("Dry run failed: ".concat(dryRunResult.failureReason));
|
|
6379
|
-
case
|
|
6415
|
+
case 16:
|
|
6380
6416
|
if (dryRunResult.weight) {
|
|
6381
|
-
_context3.next =
|
|
6417
|
+
_context3.next = 18;
|
|
6382
6418
|
break;
|
|
6383
6419
|
}
|
|
6384
6420
|
throw new Error('Dry run failed: weight not found');
|
|
6385
|
-
case
|
|
6421
|
+
case 18:
|
|
6386
6422
|
feeDotShifted = dryRunResult.fee / 10n;
|
|
6387
6423
|
toMl = transformMultiLocation(asset.multiLocation);
|
|
6388
|
-
_context3.next =
|
|
6424
|
+
_context3.next = 22;
|
|
6389
6425
|
return api.quoteAhPrice(DOT_MULTILOCATION, toMl, feeDotShifted);
|
|
6390
|
-
case
|
|
6426
|
+
case 22:
|
|
6391
6427
|
feeConverted = _context3.sent;
|
|
6392
6428
|
if (feeConverted) {
|
|
6393
|
-
_context3.next =
|
|
6429
|
+
_context3.next = 25;
|
|
6394
6430
|
break;
|
|
6395
6431
|
}
|
|
6396
6432
|
throw new Error("Pool DOT -> ".concat(asset.symbol, " not found."));
|
|
6397
|
-
case
|
|
6433
|
+
case 25:
|
|
6398
6434
|
if (!(BigInt(asset.amount) - feeConverted < 0)) {
|
|
6399
|
-
_context3.next =
|
|
6435
|
+
_context3.next = 27;
|
|
6400
6436
|
break;
|
|
6401
6437
|
}
|
|
6402
6438
|
throw new Error("Insufficient balance. Fee: ".concat(feeConverted, ", Amount: ").concat(asset.amount));
|
|
6403
|
-
case
|
|
6439
|
+
case 27:
|
|
6404
6440
|
feeConvertedPadded = feeConverted * 3n / 2n; // increases fee by 50%
|
|
6405
6441
|
return _context3.abrupt("return", createExecuteXcm(input, dryRunResult.weight, feeConvertedPadded));
|
|
6406
|
-
case
|
|
6442
|
+
case 29:
|
|
6407
6443
|
case "end":
|
|
6408
6444
|
return _context3.stop();
|
|
6409
6445
|
}
|
|
@@ -6429,7 +6465,10 @@ var AssetHubPolkadot = /*#__PURE__*/function (_ParachainNode) {
|
|
|
6429
6465
|
if (!assets.isAssetEqual(feeAsset, asset)) {
|
|
6430
6466
|
throw new assets.InvalidCurrencyError("Fee asset does not match transfer asset.");
|
|
6431
6467
|
}
|
|
6432
|
-
|
|
6468
|
+
var isNativeAsset = asset.symbol === this.getNativeAssetSymbol();
|
|
6469
|
+
if (!isNativeAsset) {
|
|
6470
|
+
return Promise.resolve(this.handleExecuteTransfer(input));
|
|
6471
|
+
}
|
|
6433
6472
|
}
|
|
6434
6473
|
if (destination === 'AssetHubKusama') {
|
|
6435
6474
|
return Promise.resolve(this.handleBridgeTransfer(input, 'Kusama'));
|
|
@@ -8740,59 +8779,63 @@ var getOriginFeeDetails = /*#__PURE__*/function () {
|
|
|
8740
8779
|
|
|
8741
8780
|
var getTransferableAmountInternal = /*#__PURE__*/function () {
|
|
8742
8781
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
8743
|
-
var api, senderAddress, node, currency, tx, asset, balance, ed, edBN, isNativeAsset, feeToSubtract, _yield$getOriginXcmFe, fee, transferable;
|
|
8782
|
+
var api, senderAddress, node, destination, currency, tx, feeAsset, resolvedFeeAsset, asset, balance, ed, edBN, isNativeAsset, shouldSubstractFee, feeToSubtract, _yield$getOriginXcmFe, fee, transferable;
|
|
8744
8783
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
8745
8784
|
while (1) switch (_context.prev = _context.next) {
|
|
8746
8785
|
case 0:
|
|
8747
|
-
api = _ref.api, senderAddress = _ref.senderAddress, node = _ref.
|
|
8786
|
+
api = _ref.api, senderAddress = _ref.senderAddress, node = _ref.origin, destination = _ref.destination, currency = _ref.currency, tx = _ref.tx, feeAsset = _ref.feeAsset;
|
|
8748
8787
|
validateAddress(senderAddress, node, false);
|
|
8788
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, node, destination, currency) : undefined;
|
|
8749
8789
|
asset = assets.findAssetForNodeOrThrow(node, currency, null);
|
|
8750
|
-
_context.next =
|
|
8790
|
+
_context.next = 6;
|
|
8751
8791
|
return getAssetBalanceInternal({
|
|
8752
8792
|
api: api,
|
|
8753
8793
|
address: senderAddress,
|
|
8754
8794
|
node: node,
|
|
8755
8795
|
currency: currency
|
|
8756
8796
|
});
|
|
8757
|
-
case
|
|
8797
|
+
case 6:
|
|
8758
8798
|
balance = _context.sent;
|
|
8759
8799
|
ed = assets.getExistentialDeposit(node, currency);
|
|
8760
8800
|
if (!(ed === null)) {
|
|
8761
|
-
_context.next =
|
|
8801
|
+
_context.next = 10;
|
|
8762
8802
|
break;
|
|
8763
8803
|
}
|
|
8764
8804
|
throw new Error("Cannot get existential deposit for currency ".concat(JSON.stringify(currency), "."));
|
|
8765
|
-
case
|
|
8805
|
+
case 10:
|
|
8766
8806
|
edBN = BigInt(ed);
|
|
8767
8807
|
isNativeAsset = assets.getNativeAssetSymbol(node) === asset.symbol;
|
|
8808
|
+
shouldSubstractFee = isNativeAsset || node === 'AssetHubPolkadot' && resolvedFeeAsset && assets.isAssetEqual(resolvedFeeAsset, asset);
|
|
8768
8809
|
feeToSubtract = 0n;
|
|
8769
|
-
if (!
|
|
8770
|
-
_context.next =
|
|
8810
|
+
if (!shouldSubstractFee) {
|
|
8811
|
+
_context.next = 22;
|
|
8771
8812
|
break;
|
|
8772
8813
|
}
|
|
8773
|
-
_context.next =
|
|
8814
|
+
_context.next = 17;
|
|
8774
8815
|
return getOriginXcmFee({
|
|
8775
8816
|
api: api,
|
|
8776
8817
|
tx: tx,
|
|
8777
8818
|
origin: node,
|
|
8778
8819
|
destination: node,
|
|
8779
8820
|
senderAddress: senderAddress,
|
|
8821
|
+
feeAsset: feeAsset,
|
|
8822
|
+
currency: currency,
|
|
8780
8823
|
disableFallback: false
|
|
8781
8824
|
});
|
|
8782
|
-
case
|
|
8825
|
+
case 17:
|
|
8783
8826
|
_yield$getOriginXcmFe = _context.sent;
|
|
8784
8827
|
fee = _yield$getOriginXcmFe.fee;
|
|
8785
8828
|
if (!(fee === undefined)) {
|
|
8786
|
-
_context.next =
|
|
8829
|
+
_context.next = 21;
|
|
8787
8830
|
break;
|
|
8788
8831
|
}
|
|
8789
8832
|
throw new Error("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(node, "."));
|
|
8790
|
-
case
|
|
8833
|
+
case 21:
|
|
8791
8834
|
feeToSubtract = fee;
|
|
8792
|
-
case
|
|
8835
|
+
case 22:
|
|
8793
8836
|
transferable = balance - edBN - feeToSubtract;
|
|
8794
8837
|
return _context.abrupt("return", transferable > 0n ? transferable : 0n);
|
|
8795
|
-
case
|
|
8838
|
+
case 24:
|
|
8796
8839
|
case "end":
|
|
8797
8840
|
return _context.stop();
|
|
8798
8841
|
}
|
|
@@ -8835,70 +8878,89 @@ var getTransferableAmount = /*#__PURE__*/function () {
|
|
|
8835
8878
|
|
|
8836
8879
|
var getTransferInfo = /*#__PURE__*/function () {
|
|
8837
8880
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
8838
|
-
var api, tx, origin, destination, senderAddress, address, currency, destApi, destAsset, destCurrency,
|
|
8881
|
+
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;
|
|
8839
8882
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
8840
8883
|
while (1) switch (_context.prev = _context.next) {
|
|
8841
8884
|
case 0:
|
|
8842
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency;
|
|
8843
|
-
|
|
8885
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, senderAddress = _ref.senderAddress, address = _ref.address, currency = _ref.currency, feeAsset = _ref.feeAsset;
|
|
8886
|
+
resolvedFeeAsset = feeAsset ? resolveFeeAsset(feeAsset, origin, destination, currency) : undefined;
|
|
8887
|
+
_context.next = 4;
|
|
8844
8888
|
return api.init(origin);
|
|
8845
|
-
case
|
|
8889
|
+
case 4:
|
|
8846
8890
|
api.setDisconnectAllowed(false);
|
|
8847
8891
|
destApi = api.clone();
|
|
8848
|
-
_context.next =
|
|
8892
|
+
_context.next = 8;
|
|
8849
8893
|
return destApi.init(destination);
|
|
8850
|
-
case
|
|
8894
|
+
case 8:
|
|
8851
8895
|
destApi.setDisconnectAllowed(false);
|
|
8852
|
-
_context.prev =
|
|
8896
|
+
_context.prev = 9;
|
|
8853
8897
|
destAsset = assets.findAssetOnDestOrThrow(origin, destination, currency);
|
|
8854
8898
|
destCurrency = destAsset.multiLocation ? {
|
|
8855
8899
|
multilocation: destAsset.multiLocation
|
|
8856
8900
|
} : {
|
|
8857
8901
|
symbol: destAsset.symbol
|
|
8858
8902
|
};
|
|
8859
|
-
|
|
8860
|
-
|
|
8903
|
+
if (!(feeAsset && resolvedFeeAsset)) {
|
|
8904
|
+
_context.next = 18;
|
|
8905
|
+
break;
|
|
8906
|
+
}
|
|
8907
|
+
_context.next = 15;
|
|
8908
|
+
return getAssetBalanceInternal({
|
|
8909
|
+
api: api,
|
|
8861
8910
|
address: senderAddress,
|
|
8862
8911
|
node: origin,
|
|
8863
|
-
|
|
8912
|
+
currency: feeAsset
|
|
8864
8913
|
});
|
|
8865
|
-
case
|
|
8866
|
-
|
|
8867
|
-
_context.next =
|
|
8914
|
+
case 15:
|
|
8915
|
+
_context.t0 = _context.sent;
|
|
8916
|
+
_context.next = 21;
|
|
8917
|
+
break;
|
|
8918
|
+
case 18:
|
|
8919
|
+
_context.next = 20;
|
|
8920
|
+
return getBalanceNativeInternal({
|
|
8921
|
+
api: api,
|
|
8922
|
+
address: senderAddress,
|
|
8923
|
+
node: origin
|
|
8924
|
+
});
|
|
8925
|
+
case 20:
|
|
8926
|
+
_context.t0 = _context.sent;
|
|
8927
|
+
case 21:
|
|
8928
|
+
originBalanceFee = _context.t0;
|
|
8929
|
+
_context.next = 24;
|
|
8868
8930
|
return getAssetBalanceInternal({
|
|
8869
8931
|
api: api,
|
|
8870
8932
|
address: senderAddress,
|
|
8871
8933
|
node: origin,
|
|
8872
8934
|
currency: currency
|
|
8873
8935
|
});
|
|
8874
|
-
case
|
|
8936
|
+
case 24:
|
|
8875
8937
|
originBalance = _context.sent;
|
|
8876
|
-
_context.next =
|
|
8938
|
+
_context.next = 27;
|
|
8877
8939
|
return getAssetBalanceInternal({
|
|
8878
8940
|
api: destApi,
|
|
8879
8941
|
address: address,
|
|
8880
8942
|
node: destination,
|
|
8881
8943
|
currency: destCurrency
|
|
8882
8944
|
});
|
|
8883
|
-
case
|
|
8945
|
+
case 27:
|
|
8884
8946
|
destBalance = _context.sent;
|
|
8885
8947
|
edOrigin = assets.getExistentialDeposit(origin, currency);
|
|
8886
8948
|
if (edOrigin) {
|
|
8887
|
-
_context.next =
|
|
8949
|
+
_context.next = 31;
|
|
8888
8950
|
break;
|
|
8889
8951
|
}
|
|
8890
8952
|
throw new InvalidParameterError("Existential deposit not found for ".concat(origin, " with currency ").concat(JSON.stringify(currency)));
|
|
8891
|
-
case
|
|
8953
|
+
case 31:
|
|
8892
8954
|
edOriginBn = BigInt(edOrigin);
|
|
8893
8955
|
edDest = assets.getExistentialDeposit(destination, destCurrency);
|
|
8894
8956
|
if (edDest) {
|
|
8895
|
-
_context.next =
|
|
8957
|
+
_context.next = 35;
|
|
8896
8958
|
break;
|
|
8897
8959
|
}
|
|
8898
8960
|
throw new InvalidParameterError("Existential deposit not found for ".concat(destination, " with currency ").concat(JSON.stringify(currency)));
|
|
8899
|
-
case
|
|
8961
|
+
case 35:
|
|
8900
8962
|
edDestBn = BigInt(edDest);
|
|
8901
|
-
_context.next =
|
|
8963
|
+
_context.next = 38;
|
|
8902
8964
|
return getXcmFee({
|
|
8903
8965
|
api: api,
|
|
8904
8966
|
tx: tx,
|
|
@@ -8907,9 +8969,10 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8907
8969
|
senderAddress: senderAddress,
|
|
8908
8970
|
address: address,
|
|
8909
8971
|
currency: currency,
|
|
8972
|
+
feeAsset: feeAsset,
|
|
8910
8973
|
disableFallback: false
|
|
8911
8974
|
});
|
|
8912
|
-
case
|
|
8975
|
+
case 38:
|
|
8913
8976
|
_yield$getXcmFee = _context.sent;
|
|
8914
8977
|
_yield$getXcmFee$orig = _yield$getXcmFee.origin;
|
|
8915
8978
|
originFee = _yield$getXcmFee$orig.fee;
|
|
@@ -8918,39 +8981,42 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8918
8981
|
destFee = _yield$getXcmFee$dest.fee;
|
|
8919
8982
|
destFeeCurrency = _yield$getXcmFee$dest.currency;
|
|
8920
8983
|
if (!(originFee === undefined)) {
|
|
8921
|
-
_context.next =
|
|
8984
|
+
_context.next = 47;
|
|
8922
8985
|
break;
|
|
8923
8986
|
}
|
|
8924
8987
|
throw new Error("Cannot get origin xcm fee for currency ".concat(JSON.stringify(currency), " on node ").concat(origin, "."));
|
|
8925
|
-
case
|
|
8988
|
+
case 47:
|
|
8926
8989
|
isDestFeeInNativeCurrency = destFeeCurrency === assets.getNativeAssetSymbol(destination);
|
|
8927
8990
|
if (!isDestFeeInNativeCurrency) {
|
|
8928
|
-
_context.next =
|
|
8991
|
+
_context.next = 55;
|
|
8929
8992
|
break;
|
|
8930
8993
|
}
|
|
8931
|
-
_context.next =
|
|
8994
|
+
_context.next = 51;
|
|
8932
8995
|
return getBalanceNativeInternal({
|
|
8933
8996
|
address: address,
|
|
8934
8997
|
node: destination,
|
|
8935
8998
|
api: destApi
|
|
8936
8999
|
});
|
|
8937
|
-
case
|
|
9000
|
+
case 51:
|
|
8938
9001
|
destRecipientNativeBalance = _context.sent;
|
|
8939
9002
|
destXcmFeeBalance = destRecipientNativeBalance;
|
|
8940
|
-
_context.next =
|
|
9003
|
+
_context.next = 56;
|
|
8941
9004
|
break;
|
|
8942
|
-
case
|
|
9005
|
+
case 55:
|
|
8943
9006
|
destXcmFeeBalance = destBalance;
|
|
8944
|
-
case
|
|
9007
|
+
case 56:
|
|
9008
|
+
isFeeAssetAh = origin === 'AssetHubPolkadot' && resolvedFeeAsset && assets.isAssetEqual(resolvedFeeAsset, destAsset);
|
|
8945
9009
|
originBalanceAfter = originBalance - BigInt(currency.amount);
|
|
8946
|
-
|
|
8947
|
-
originBalanceNativeSufficient =
|
|
9010
|
+
originBalanceFeeAfter = isFeeAssetAh ? originBalanceFee - BigInt(currency.amount) : originBalanceFee - originFee;
|
|
9011
|
+
originBalanceNativeSufficient = originBalanceFee >= originFee;
|
|
8948
9012
|
originBalanceSufficient = originBalanceAfter >= edOriginBn;
|
|
8949
|
-
|
|
9013
|
+
destAmount = isFeeAssetAh ? BigInt(currency.amount) - originFee : BigInt(currency.amount);
|
|
9014
|
+
destBalanceSufficient = destAmount - destFee > (destBalance < edDestBn ? edDestBn : 0);
|
|
8950
9015
|
destBalanceSufficientResult = destFeeCurrency !== destAsset.symbol ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceSufficient;
|
|
8951
|
-
destBalanceAfter = destBalance - (destFeeCurrency === destAsset.symbol ? destFee : 0n) +
|
|
9016
|
+
destBalanceAfter = destBalance - (destFeeCurrency === destAsset.symbol ? destFee : 0n) + destAmount;
|
|
8952
9017
|
destbalanceAfterResult = destFeeCurrency !== destAsset.symbol ? new UnableToComputeError('Unable to compute if dest balance will be sufficient. Fee currency is not the same') : destBalanceAfter;
|
|
8953
|
-
|
|
9018
|
+
receivedAmount = destbalanceAfterResult instanceof UnableToComputeError ? destbalanceAfterResult : destbalanceAfterResult - destBalance;
|
|
9019
|
+
destXcmFeeBalanceAfter = isFeeAssetAh ? destBalanceAfter : destXcmFeeBalance - destFee + (destFeeCurrency === destAsset.symbol ? BigInt(currency.amount) : 0n);
|
|
8954
9020
|
return _context.abrupt("return", {
|
|
8955
9021
|
chain: {
|
|
8956
9022
|
origin: origin,
|
|
@@ -8968,14 +9034,15 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8968
9034
|
xcmFee: {
|
|
8969
9035
|
sufficient: originBalanceNativeSufficient,
|
|
8970
9036
|
fee: originFee,
|
|
8971
|
-
balance:
|
|
8972
|
-
balanceAfter:
|
|
9037
|
+
balance: originBalanceFee,
|
|
9038
|
+
balanceAfter: originBalanceFeeAfter,
|
|
8973
9039
|
currencySymbol: originFeeCurrency
|
|
8974
9040
|
}
|
|
8975
9041
|
},
|
|
8976
9042
|
destination: {
|
|
8977
9043
|
receivedCurrency: {
|
|
8978
9044
|
sufficient: destBalanceSufficientResult,
|
|
9045
|
+
receivedAmount: receivedAmount,
|
|
8979
9046
|
balance: destBalance,
|
|
8980
9047
|
balanceAfter: destbalanceAfterResult,
|
|
8981
9048
|
currencySymbol: destAsset.symbol,
|
|
@@ -8989,22 +9056,22 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
8989
9056
|
}
|
|
8990
9057
|
}
|
|
8991
9058
|
});
|
|
8992
|
-
case
|
|
8993
|
-
_context.prev =
|
|
9059
|
+
case 69:
|
|
9060
|
+
_context.prev = 69;
|
|
8994
9061
|
api.setDisconnectAllowed(true);
|
|
8995
9062
|
destApi.setDisconnectAllowed(true);
|
|
8996
|
-
_context.next =
|
|
9063
|
+
_context.next = 74;
|
|
8997
9064
|
return api.disconnect();
|
|
8998
|
-
case
|
|
8999
|
-
_context.next =
|
|
9065
|
+
case 74:
|
|
9066
|
+
_context.next = 76;
|
|
9000
9067
|
return destApi.disconnect();
|
|
9001
|
-
case
|
|
9002
|
-
return _context.finish(
|
|
9003
|
-
case
|
|
9068
|
+
case 76:
|
|
9069
|
+
return _context.finish(69);
|
|
9070
|
+
case 77:
|
|
9004
9071
|
case "end":
|
|
9005
9072
|
return _context.stop();
|
|
9006
9073
|
}
|
|
9007
|
-
}, _callee, null, [[
|
|
9074
|
+
}, _callee, null, [[9,, 69, 77]]);
|
|
9008
9075
|
}));
|
|
9009
9076
|
return function getTransferInfo(_x) {
|
|
9010
9077
|
return _ref2.apply(this, arguments);
|
|
@@ -9013,11 +9080,11 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
9013
9080
|
|
|
9014
9081
|
var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
9015
9082
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
9016
|
-
var api, tx, origin, destination, address, senderAddress, currency, destApi, asset, destCurrency, ed, edBN, balance, _yield$getXcmFee, dryRunError, _yield$getXcmFee$dest, destFee, destFeeCurrency, destDryRunError;
|
|
9083
|
+
var api, tx, origin, destination, address, senderAddress, feeAsset, currency, destApi, asset, destCurrency, ed, edBN, balance, _yield$getXcmFee, dryRunError, _yield$getXcmFee$dest, destFee, destFeeCurrency, destDryRunError;
|
|
9017
9084
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
9018
9085
|
while (1) switch (_context.prev = _context.next) {
|
|
9019
9086
|
case 0:
|
|
9020
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, currency = _ref.currency;
|
|
9087
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, address = _ref.address, senderAddress = _ref.senderAddress, feeAsset = _ref.feeAsset, currency = _ref.currency;
|
|
9021
9088
|
validateAddress(address, destination);
|
|
9022
9089
|
destApi = api.clone();
|
|
9023
9090
|
_context.next = 5;
|
|
@@ -9055,6 +9122,7 @@ var verifyEdOnDestinationInternal = /*#__PURE__*/function () {
|
|
|
9055
9122
|
senderAddress: senderAddress,
|
|
9056
9123
|
address: address,
|
|
9057
9124
|
currency: currency,
|
|
9125
|
+
feeAsset: feeAsset,
|
|
9058
9126
|
disableFallback: false
|
|
9059
9127
|
});
|
|
9060
9128
|
case 16:
|
|
@@ -9446,11 +9514,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9446
9514
|
key: "dryRun",
|
|
9447
9515
|
value: function () {
|
|
9448
9516
|
var _dryRun2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
9449
|
-
var _this$_options2, to, address, senderAddress, tx;
|
|
9517
|
+
var _this$_options2, to, address, senderAddress, feeAsset, tx;
|
|
9450
9518
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
9451
9519
|
while (1) switch (_context3.prev = _context3.next) {
|
|
9452
9520
|
case 0:
|
|
9453
|
-
_this$_options2 = this._options, to = _this$_options2.to, address = _this$_options2.address, senderAddress = _this$_options2.senderAddress;
|
|
9521
|
+
_this$_options2 = this._options, to = _this$_options2.to, address = _this$_options2.address, senderAddress = _this$_options2.senderAddress, feeAsset = _this$_options2.feeAsset;
|
|
9454
9522
|
_context3.next = 3;
|
|
9455
9523
|
return this.build();
|
|
9456
9524
|
case 3:
|
|
@@ -9480,7 +9548,8 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9480
9548
|
origin: this._options.from,
|
|
9481
9549
|
destination: to,
|
|
9482
9550
|
currency: this._options.currency,
|
|
9483
|
-
senderAddress: this._options.senderAddress
|
|
9551
|
+
senderAddress: this._options.senderAddress,
|
|
9552
|
+
feeAsset: feeAsset
|
|
9484
9553
|
}));
|
|
9485
9554
|
case 11:
|
|
9486
9555
|
case "end":
|
|
@@ -9509,6 +9578,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9509
9578
|
to,
|
|
9510
9579
|
address,
|
|
9511
9580
|
senderAddress,
|
|
9581
|
+
feeAsset,
|
|
9512
9582
|
tx,
|
|
9513
9583
|
_args4 = arguments;
|
|
9514
9584
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
@@ -9517,7 +9587,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9517
9587
|
_ref = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {
|
|
9518
9588
|
disableFallback: false
|
|
9519
9589
|
}, disableFallback = _ref.disableFallback;
|
|
9520
|
-
_this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress;
|
|
9590
|
+
_this$_options3 = this._options, from = _this$_options3.from, to = _this$_options3.to, address = _this$_options3.address, senderAddress = _this$_options3.senderAddress, feeAsset = _this$_options3.feeAsset;
|
|
9521
9591
|
assertToIsStringAndNoEthereum(to);
|
|
9522
9592
|
assertAddressIsString(address);
|
|
9523
9593
|
_context4.next = 6;
|
|
@@ -9534,6 +9604,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9534
9604
|
senderAddress: senderAddress,
|
|
9535
9605
|
address: address,
|
|
9536
9606
|
currency: this._options.currency,
|
|
9607
|
+
feeAsset: feeAsset,
|
|
9537
9608
|
disableFallback: disableFallback
|
|
9538
9609
|
});
|
|
9539
9610
|
case 10:
|
|
@@ -9571,6 +9642,8 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9571
9642
|
from,
|
|
9572
9643
|
to,
|
|
9573
9644
|
senderAddress,
|
|
9645
|
+
currency,
|
|
9646
|
+
feeAsset,
|
|
9574
9647
|
tx,
|
|
9575
9648
|
_args5 = arguments;
|
|
9576
9649
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
@@ -9579,7 +9652,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9579
9652
|
_ref2 = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {
|
|
9580
9653
|
disableFallback: false
|
|
9581
9654
|
}, disableFallback = _ref2.disableFallback;
|
|
9582
|
-
_this$_options4 = this._options, from = _this$_options4.from, to = _this$_options4.to, senderAddress = _this$_options4.senderAddress;
|
|
9655
|
+
_this$_options4 = this._options, from = _this$_options4.from, to = _this$_options4.to, senderAddress = _this$_options4.senderAddress, currency = _this$_options4.currency, feeAsset = _this$_options4.feeAsset;
|
|
9583
9656
|
assertToIsStringAndNoEthereum(to);
|
|
9584
9657
|
_context5.next = 5;
|
|
9585
9658
|
return this.build();
|
|
@@ -9593,6 +9666,8 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9593
9666
|
origin: from,
|
|
9594
9667
|
destination: to,
|
|
9595
9668
|
senderAddress: senderAddress,
|
|
9669
|
+
currency: currency,
|
|
9670
|
+
feeAsset: feeAsset,
|
|
9596
9671
|
disableFallback: disableFallback
|
|
9597
9672
|
});
|
|
9598
9673
|
case 9:
|
|
@@ -9723,26 +9798,29 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9723
9798
|
key: "getTransferableAmount",
|
|
9724
9799
|
value: (function () {
|
|
9725
9800
|
var _getTransferableAmount2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
9726
|
-
var _this$_options7, from, senderAddress, currency, tx;
|
|
9801
|
+
var _this$_options7, from, to, senderAddress, currency, feeAsset, tx;
|
|
9727
9802
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
9728
9803
|
while (1) switch (_context8.prev = _context8.next) {
|
|
9729
9804
|
case 0:
|
|
9730
|
-
_this$_options7 = this._options, from = _this$_options7.from, senderAddress = _this$_options7.senderAddress, currency = _this$_options7.currency;
|
|
9731
|
-
|
|
9805
|
+
_this$_options7 = this._options, from = _this$_options7.from, to = _this$_options7.to, senderAddress = _this$_options7.senderAddress, currency = _this$_options7.currency, feeAsset = _this$_options7.feeAsset;
|
|
9806
|
+
assertToIsStringAndNoEthereum(to);
|
|
9807
|
+
_context8.next = 4;
|
|
9732
9808
|
return this.build();
|
|
9733
|
-
case
|
|
9809
|
+
case 4:
|
|
9734
9810
|
tx = _context8.sent;
|
|
9735
|
-
_context8.next =
|
|
9811
|
+
_context8.next = 7;
|
|
9736
9812
|
return getTransferableAmount({
|
|
9737
9813
|
api: this.api,
|
|
9738
9814
|
tx: tx,
|
|
9739
|
-
|
|
9815
|
+
origin: from,
|
|
9816
|
+
destination: to,
|
|
9740
9817
|
senderAddress: senderAddress,
|
|
9818
|
+
feeAsset: feeAsset,
|
|
9741
9819
|
currency: currency
|
|
9742
9820
|
});
|
|
9743
|
-
case 6:
|
|
9744
|
-
return _context8.abrupt("return", _context8.sent);
|
|
9745
9821
|
case 7:
|
|
9822
|
+
return _context8.abrupt("return", _context8.sent);
|
|
9823
|
+
case 8:
|
|
9746
9824
|
case "end":
|
|
9747
9825
|
return _context8.stop();
|
|
9748
9826
|
}
|
|
@@ -9763,11 +9841,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9763
9841
|
key: "verifyEdOnDestination",
|
|
9764
9842
|
value: (function () {
|
|
9765
9843
|
var _verifyEdOnDestination2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
9766
|
-
var _this$_options8, from, to, address, currency, senderAddress, tx;
|
|
9844
|
+
var _this$_options8, from, to, address, currency, senderAddress, feeAsset, tx;
|
|
9767
9845
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
9768
9846
|
while (1) switch (_context9.prev = _context9.next) {
|
|
9769
9847
|
case 0:
|
|
9770
|
-
_this$_options8 = this._options, from = _this$_options8.from, to = _this$_options8.to, address = _this$_options8.address, currency = _this$_options8.currency, senderAddress = _this$_options8.senderAddress;
|
|
9848
|
+
_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;
|
|
9771
9849
|
assertToIsStringAndNoEthereum(to);
|
|
9772
9850
|
assertAddressIsString(address);
|
|
9773
9851
|
_context9.next = 5;
|
|
@@ -9781,6 +9859,7 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9781
9859
|
destination: to,
|
|
9782
9860
|
address: address,
|
|
9783
9861
|
senderAddress: senderAddress,
|
|
9862
|
+
feeAsset: feeAsset,
|
|
9784
9863
|
currency: currency
|
|
9785
9864
|
}));
|
|
9786
9865
|
case 7:
|
|
@@ -9804,11 +9883,11 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9804
9883
|
key: "getTransferInfo",
|
|
9805
9884
|
value: (function () {
|
|
9806
9885
|
var _getTransferInfo2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0() {
|
|
9807
|
-
var _this$_options9, from, to, address, currency, senderAddress, tx;
|
|
9886
|
+
var _this$_options9, from, to, address, currency, senderAddress, feeAsset, tx;
|
|
9808
9887
|
return _regeneratorRuntime().wrap(function _callee0$(_context0) {
|
|
9809
9888
|
while (1) switch (_context0.prev = _context0.next) {
|
|
9810
9889
|
case 0:
|
|
9811
|
-
_this$_options9 = this._options, from = _this$_options9.from, to = _this$_options9.to, address = _this$_options9.address, currency = _this$_options9.currency, senderAddress = _this$_options9.senderAddress;
|
|
9890
|
+
_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;
|
|
9812
9891
|
assertToIsStringAndNoEthereum(to);
|
|
9813
9892
|
assertAddressIsString(address);
|
|
9814
9893
|
_context0.next = 5;
|
|
@@ -9822,7 +9901,8 @@ var GeneralBuilder = /*#__PURE__*/function () {
|
|
|
9822
9901
|
destination: to,
|
|
9823
9902
|
address: address,
|
|
9824
9903
|
senderAddress: senderAddress,
|
|
9825
|
-
currency: currency
|
|
9904
|
+
currency: currency,
|
|
9905
|
+
feeAsset: feeAsset
|
|
9826
9906
|
}));
|
|
9827
9907
|
case 7:
|
|
9828
9908
|
case "end":
|