@paraspell/sdk-core 14.5.3 → 14.5.4
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.d.ts +3 -5
- package/dist/index.mjs +185 -150
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -157,7 +157,6 @@ declare abstract class SubstrateChain<TApi, TRes, TSigner, TCustomChain extends
|
|
|
157
157
|
canReceiveFrom<TCustomChain extends string = never>(_origin: TChain | TCustomChain): boolean;
|
|
158
158
|
shouldUseNativeAssetTeleport({ api, assetInfo: asset, to }: TTransferInternalOptions<TApi, TRes, TSigner, TCustomChain>): boolean;
|
|
159
159
|
shouldUseExecuteTransfer(_options: TPolkadotXCMTransferOptions<TApi, TRes, TSigner, TCustomChain>): boolean;
|
|
160
|
-
protected shouldUseReserveTransfer(): boolean;
|
|
161
160
|
createAsset(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>, asset: WithAmount<TAssetInfo>, version: Version): TAsset;
|
|
162
161
|
getNativeAssetSymbol(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>): string;
|
|
163
162
|
transferLocal(options: TTransferInternalOptions<TApi, TRes, TSigner, TCustomChain>): Promise<TRes>;
|
|
@@ -216,7 +215,6 @@ declare class AssetHubWestend<TApi, TRes, TSigner, TCustomChain extends string =
|
|
|
216
215
|
declare class Astar<TApi, TRes, TSigner, TCustomChain extends string = never> extends SubstrateChain<TApi, TRes, TSigner, TCustomChain> implements IPolkadotXCMTransfer<TApi, TRes, TSigner, TCustomChain> {
|
|
217
216
|
constructor(chain?: TParachain, info?: string, ecosystem?: TRelaychain, version?: Version);
|
|
218
217
|
protected getMintConfig(): TMintConfig;
|
|
219
|
-
protected shouldUseReserveTransfer(): boolean;
|
|
220
218
|
isSendingTempDisabled(assetInfo: TAssetInfo): boolean;
|
|
221
219
|
transferPolkadotXCM(input: TPolkadotXCMTransferOptions<TApi, TRes, TSigner, TCustomChain>): Promise<TRes>;
|
|
222
220
|
isRelayToParaEnabled(): boolean;
|
|
@@ -364,7 +362,6 @@ declare class EnergyWebX<TApi, TRes, TSigner, TCustomChain extends string = neve
|
|
|
364
362
|
constructor(chain?: TParachain, info?: string, ecosystem?: TRelaychain, version?: Version);
|
|
365
363
|
transferPolkadotXCM(input: TPolkadotXCMTransferOptions<TApi, TRes, TSigner, TCustomChain>): Promise<TRes>;
|
|
366
364
|
isRelayToParaEnabled(): boolean;
|
|
367
|
-
protected shouldUseReserveTransfer(): boolean;
|
|
368
365
|
protected getMintConfig(): TMintConfig;
|
|
369
366
|
transferLocalNonNativeAsset(options: TTransferLocalOptions<TApi, TRes, TSigner, TCustomChain>): TRes;
|
|
370
367
|
getBalanceForeign(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>, address: string, asset: TAssetInfo): Promise<bigint>;
|
|
@@ -1528,6 +1525,7 @@ type TGetXcmFeeBaseOptions<TRes, TDisableFallback extends boolean = boolean, TCu
|
|
|
1528
1525
|
disableFallback: TDisableFallback;
|
|
1529
1526
|
swapConfig?: TXcmFeeSwapConfig;
|
|
1530
1527
|
skipReverseFeeCalculation?: boolean;
|
|
1528
|
+
skipEdDeposit?: boolean;
|
|
1531
1529
|
};
|
|
1532
1530
|
type TGetXcmFeeOptions<TApi, TRes, TSigner, TDisableFallback extends boolean = boolean, TCustomChain extends string = never> = WithApi<TGetXcmFeeBaseOptions<TRes, TDisableFallback, TCustomChain>, TApi, TRes, TSigner, TCustomChain>;
|
|
1533
1531
|
type TGetXcmFeeInternalOptions<TApi, TRes, TSigner, TDisableFallback extends boolean = boolean, TCustomChain extends string = never> = Omit<TGetXcmFeeOptions<TApi, TRes, TSigner, TDisableFallback, TCustomChain>, 'buildTx'> & {
|
|
@@ -2151,7 +2149,7 @@ type TCreateBaseSwapXcmOptions = {
|
|
|
2151
2149
|
feeAssetInfo?: TAssetInfo;
|
|
2152
2150
|
sender: string;
|
|
2153
2151
|
recipient: string;
|
|
2154
|
-
calculateMinAmountOut: (amountIn: bigint, assetTo?: TAssetInfo) => Promise<bigint>;
|
|
2152
|
+
calculateMinAmountOut: (amountIn: bigint, assetTo?: TAssetInfo, slippagePct?: string) => Promise<bigint>;
|
|
2155
2153
|
};
|
|
2156
2154
|
type TCreateSwapXcmOptions<TApi, TRes, TSigner, TCustomChain extends string = never> = WithApi<TCreateBaseSwapXcmOptions, TApi, TRes, TSigner, TCustomChain>;
|
|
2157
2155
|
type TSwapFeeEstimates = {
|
|
@@ -2382,7 +2380,7 @@ declare const getOriginXcmFeeInternal: <TApi, TRes, TSigner, TCustomChain extend
|
|
|
2382
2380
|
declare const getXcmFeeInternal: <TApi, TRes, TSigner, TDisableFallback extends boolean, TCustomChain extends string = never>(options: TGetXcmFeeOptions<TApi, TRes, TSigner, TDisableFallback, TCustomChain>) => Promise<TGetXcmFeeResult<TDisableFallback, TCustomChain>>;
|
|
2383
2381
|
declare const getXcmFee: <TApi, TRes, TSigner, TDisableFallback extends boolean, TCustomChain extends string = never>(options: TGetXcmFeeOptions<TApi, TRes, TSigner, TDisableFallback, TCustomChain>) => Promise<TGetXcmFeeResult<TDisableFallback, TCustomChain>>;
|
|
2384
2382
|
|
|
2385
|
-
declare const getXcmFeeOnce: <TApi, TRes, TSigner, TDisableFallback extends boolean, TCustomChain extends string = never>({ api, tx, origin, destination, sender, recipient, currency, feeAsset, version, disableFallback, swapConfig, useRootOrigin, skipReverseFeeCalculation }: TGetXcmFeeInternalOptions<TApi, TRes, TSigner, TDisableFallback, TCustomChain>) => Promise<TGetXcmFeeResult<TDisableFallback, TCustomChain>>;
|
|
2383
|
+
declare const getXcmFeeOnce: <TApi, TRes, TSigner, TDisableFallback extends boolean, TCustomChain extends string = never>({ api, tx, origin, destination, sender, recipient, currency, feeAsset, version, disableFallback, swapConfig, useRootOrigin, skipReverseFeeCalculation, skipEdDeposit }: TGetXcmFeeInternalOptions<TApi, TRes, TSigner, TDisableFallback, TCustomChain>) => Promise<TGetXcmFeeResult<TDisableFallback, TCustomChain>>;
|
|
2386
2384
|
|
|
2387
2385
|
declare const getBridgeStatus: <TApi, TRes, TSigner, TCustomChain extends string = never>(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>) => Promise<TBridgeStatus>;
|
|
2388
2386
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blake2b } from '@noble/hashes/blake2.js';
|
|
2
|
-
import { isChainEvm, getAssetsObject, InvalidCurrencyError, isAssetEqual, isSymbolMatch, isStableCoinAsset, isAdditionalSubstrateBridgeAsset, isBridgedSystemAsset, STABLECOIN_IDS, isSymbolSpecifier, normalizeLocation, getNativeAssetSymbol, extractAssetLocation, normalizeSymbol, findNativeAssetInfoOrThrow,
|
|
2
|
+
import { isChainEvm, getAssetsObject, InvalidCurrencyError, isAssetEqual, isSymbolMatch, isStableCoinAsset, isAdditionalSubstrateBridgeAsset, isBridgedSystemAsset, STABLECOIN_IDS, isSymbolSpecifier, normalizeLocation, getNativeAssetSymbol, extractAssetLocation, normalizeSymbol, findNativeAssetInfoOrThrow, getOtherAssets, canonicalizeLocation, getAssetsObjectImpl, getAssetsImpl, getNativeAssetsImpl, getOtherAssetsImpl, findAssetInfoImpl, findAssetInfoOrThrowImpl, findAssetInfoOnDestImpl, findAssetOnDestOrThrowImpl, findNativeAssetInfoImpl, findNativeAssetInfoOrThrowImpl, isChainEvmImpl, getNativeAssetSymbolImpl, getRelayChainSymbolImpl, hasDryRunSupportImpl, hasXcmPaymentApiSupportImpl, getExistentialDepositImpl, normalizeCustomAssets } from '@paraspell/assets';
|
|
3
3
|
export * from '@paraspell/assets';
|
|
4
4
|
import { base58 } from '@scure/base';
|
|
5
5
|
import { isAddress, isHex, createPublicClient, http, formatUnits as formatUnits$1, parseUnits as parseUnits$1, stringToHex, numberToBytes } from 'viem';
|
|
@@ -2661,7 +2661,7 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2661
2661
|
key: "transfer",
|
|
2662
2662
|
value: function () {
|
|
2663
2663
|
var _transfer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(transferOptions) {
|
|
2664
|
-
var api, asset, currency, feeAsset, feeCurrency, recipient, destination, paraIdTo, overriddenAsset, version, sender, ahAddress, pallet, method, keepAlive, transactOptions, scenario, paraId, destChain, isLocalTransfer, isRelayAsset,
|
|
2664
|
+
var api, asset, currency, feeAsset, feeCurrency, recipient, destination, paraIdTo, overriddenAsset, version, sender, ahAddress, pallet, method, keepAlive, transactOptions, scenario, paraId, destChain, isLocalTransfer, isRelayAsset, supportsTypeAndThen, options, promise, isSubBridge, isAHOrigin, isExternalAsset, isEthDest, isExternalAssetViaAh, input, _t, _t2;
|
|
2665
2665
|
return _regenerator().w(function (_context) {
|
|
2666
2666
|
while (1) switch (_context.n) {
|
|
2667
2667
|
case 0:
|
|
@@ -2687,26 +2687,20 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2687
2687
|
this.throwIfTempDisabled(transferOptions, destChain);
|
|
2688
2688
|
this.throwIfCantReceive(destChain);
|
|
2689
2689
|
isRelayAsset = deepEqual(asset.location, RELAY_LOCATION) && isSymbolMatch(api.getRelayChainSymbol(this.chain), asset.symbol);
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2690
|
+
if (!(supportsPolkadotXCM(this) || isRelayAsset)) {
|
|
2691
|
+
_context.n = 11;
|
|
2692
|
+
break;
|
|
2693
|
+
}
|
|
2694
2694
|
_context.n = 3;
|
|
2695
|
-
return api.hasMethod(api.
|
|
2695
|
+
return api.hasMethod(api.getXcmPallet(this.chain), 'transfer_assets_using_type_and_then');
|
|
2696
2696
|
case 3:
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
if (!(assetNeedsTypeThen && !supportsTypeThen && (!shouldUseReserveTransfer || isSubBridge))) {
|
|
2697
|
+
supportsTypeAndThen = _context.v;
|
|
2698
|
+
if (supportsTypeAndThen) {
|
|
2700
2699
|
_context.n = 4;
|
|
2701
2700
|
break;
|
|
2702
2701
|
}
|
|
2703
|
-
throw new TypeAndThenUnavailableError(
|
|
2702
|
+
throw new TypeAndThenUnavailableError("Chain ".concat(this.chain, " does not support the type-and-then method required for this transfer."));
|
|
2704
2703
|
case 4:
|
|
2705
|
-
useTypeAndThen = !shouldUseReserveTransfer && assetNeedsTypeThen && supportsTypeThen && destChain && !isExternalChain(destChain) && (!isTrustedChain(this.chain) || !isTrustedChain(destChain)) || isSubBridge;
|
|
2706
|
-
if (!(supportsPolkadotXCM(this) || useTypeAndThen)) {
|
|
2707
|
-
_context.n = 14;
|
|
2708
|
-
break;
|
|
2709
|
-
}
|
|
2710
2704
|
options = {
|
|
2711
2705
|
api: api,
|
|
2712
2706
|
chain: this.chain,
|
|
@@ -2751,53 +2745,31 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2751
2745
|
case 6:
|
|
2752
2746
|
return _context.a(2, _t.deserializeExtrinsics.call(_t, _context.v));
|
|
2753
2747
|
case 7:
|
|
2748
|
+
isSubBridge = !isTLocation(destination) && isSubstrateBridge(this.chain, destination);
|
|
2754
2749
|
isAHOrigin = this.chain.includes('AssetHub');
|
|
2755
|
-
isAHDest = !isTLocation(destination) && destination.includes('AssetHub'); // Handle common cases
|
|
2756
2750
|
isExternalAsset = asset.location.parents === Parents.TWO;
|
|
2757
|
-
isEthDest = _typeof(destination) !== 'object' && isExternalChain(destination);
|
|
2758
|
-
isExternalAssetViaAh = isExternalAsset && !isAHOrigin && !
|
|
2759
|
-
|
|
2760
|
-
if (!(isExternalAssetViaAh || isExternalAssetToAh || useTypeAndThen)) {
|
|
2761
|
-
_context.n = 11;
|
|
2762
|
-
break;
|
|
2763
|
-
}
|
|
2764
|
-
if (!(useTypeAndThen && supportsPolkadotXCM(this) && !isSubBridge)) {
|
|
2751
|
+
isEthDest = _typeof(destination) !== 'object' && isExternalChain(destination);
|
|
2752
|
+
isExternalAssetViaAh = isExternalAsset && !isAHOrigin && !isEthDest;
|
|
2753
|
+
if (!(!supportsPolkadotXCM(this) || isSubBridge || isExternalAssetViaAh)) {
|
|
2765
2754
|
_context.n = 9;
|
|
2766
2755
|
break;
|
|
2767
2756
|
}
|
|
2757
|
+
_t2 = api;
|
|
2768
2758
|
_context.n = 8;
|
|
2769
|
-
return
|
|
2759
|
+
return createTypeAndThenCall(options);
|
|
2770
2760
|
case 8:
|
|
2771
|
-
|
|
2772
|
-
if (!this.shouldUseExecuteTransfer(options)) {
|
|
2773
|
-
_context.n = 9;
|
|
2774
|
-
break;
|
|
2775
|
-
}
|
|
2776
|
-
return _context.a(2, tx);
|
|
2761
|
+
return _context.a(2, _t2.deserializeExtrinsics.call(_t2, _context.v));
|
|
2777
2762
|
case 9:
|
|
2778
|
-
_context.n = 10;
|
|
2779
|
-
return createTypeAndThenCall(options);
|
|
2780
|
-
case 10:
|
|
2781
|
-
call = _context.v;
|
|
2782
|
-
return _context.a(2, api.deserializeExtrinsics(call));
|
|
2783
|
-
case 11:
|
|
2784
|
-
if (!supportsPolkadotXCM(this)) {
|
|
2785
|
-
_context.n = 13;
|
|
2786
|
-
break;
|
|
2787
|
-
}
|
|
2788
2763
|
if (!(this.shouldUseNativeAssetTeleport(transferOptions) && !getFeeAssetInfo(asset, feeAsset) && !this.shouldUseExecuteTransfer(options))) {
|
|
2789
|
-
_context.n =
|
|
2764
|
+
_context.n = 10;
|
|
2790
2765
|
break;
|
|
2791
2766
|
}
|
|
2792
2767
|
return _context.a(2, transferPolkadotXcm(options, 'limited_teleport_assets', 'Unlimited'));
|
|
2793
|
-
case
|
|
2768
|
+
case 10:
|
|
2794
2769
|
return _context.a(2, this.transferPolkadotXCM(options));
|
|
2795
|
-
case
|
|
2796
|
-
_context.n = 15;
|
|
2797
|
-
break;
|
|
2798
|
-
case 14:
|
|
2770
|
+
case 11:
|
|
2799
2771
|
if (!supportsXTokens(this)) {
|
|
2800
|
-
_context.n =
|
|
2772
|
+
_context.n = 12;
|
|
2801
2773
|
break;
|
|
2802
2774
|
}
|
|
2803
2775
|
validateFeeAssetSupport(asset, feeAsset, overriddenAsset, 'XTokens');
|
|
@@ -2815,9 +2787,9 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2815
2787
|
method: method
|
|
2816
2788
|
};
|
|
2817
2789
|
return _context.a(2, this.transferXTokens(input));
|
|
2818
|
-
case
|
|
2790
|
+
case 12:
|
|
2819
2791
|
throw new NoXCMSupportImplementedError(this.chain);
|
|
2820
|
-
case
|
|
2792
|
+
case 13:
|
|
2821
2793
|
return _context.a(2);
|
|
2822
2794
|
}
|
|
2823
2795
|
}, _callee, this);
|
|
@@ -2885,11 +2857,6 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2885
2857
|
value: function shouldUseExecuteTransfer(_options) {
|
|
2886
2858
|
return false;
|
|
2887
2859
|
}
|
|
2888
|
-
}, {
|
|
2889
|
-
key: "shouldUseReserveTransfer",
|
|
2890
|
-
value: function shouldUseReserveTransfer() {
|
|
2891
|
-
return false;
|
|
2892
|
-
}
|
|
2893
2860
|
}, {
|
|
2894
2861
|
key: "createAsset",
|
|
2895
2862
|
value: function createAsset$1(api, asset, version) {
|
|
@@ -3048,7 +3015,7 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
3048
3015
|
key: "getBalanceForeign",
|
|
3049
3016
|
value: function () {
|
|
3050
3017
|
var _getBalanceForeign = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(api, address, asset) {
|
|
3051
|
-
var pallets, lastError, customCurrencyId, _iterator, _step, pallet, instance,
|
|
3018
|
+
var pallets, lastError, customCurrencyId, _iterator, _step, pallet, instance, _t3, _t4;
|
|
3052
3019
|
return _regenerator().w(function (_context3) {
|
|
3053
3020
|
while (1) switch (_context3.p = _context3.n) {
|
|
3054
3021
|
case 0:
|
|
@@ -3077,8 +3044,8 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
3077
3044
|
return _context3.a(2, _context3.v);
|
|
3078
3045
|
case 6:
|
|
3079
3046
|
_context3.p = 6;
|
|
3080
|
-
|
|
3081
|
-
lastError =
|
|
3047
|
+
_t3 = _context3.v;
|
|
3048
|
+
lastError = _t3;
|
|
3082
3049
|
case 7:
|
|
3083
3050
|
_context3.n = 3;
|
|
3084
3051
|
break;
|
|
@@ -3087,8 +3054,8 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
3087
3054
|
break;
|
|
3088
3055
|
case 9:
|
|
3089
3056
|
_context3.p = 9;
|
|
3090
|
-
|
|
3091
|
-
_iterator.e(
|
|
3057
|
+
_t4 = _context3.v;
|
|
3058
|
+
_iterator.e(_t4);
|
|
3092
3059
|
case 10:
|
|
3093
3060
|
_context3.p = 10;
|
|
3094
3061
|
_iterator.f();
|
|
@@ -3545,7 +3512,7 @@ var createTransfer = /*#__PURE__*/function () {
|
|
|
3545
3512
|
return api.init(origin, TX_CLIENT_TIMEOUT_MS, destination);
|
|
3546
3513
|
case 1:
|
|
3547
3514
|
_resolveTransferParam = resolveTransferParams(options), resolvedFeeAsset = _resolveTransferParam.resolvedFeeAsset, resolvedVersion = _resolveTransferParam.resolvedVersion, overriddenAsset = _resolveTransferParam.overriddenAsset, normalizedAsset = _resolveTransferParam.normalizedAsset;
|
|
3548
|
-
customCtx = api
|
|
3515
|
+
customCtx = api._customCtx;
|
|
3549
3516
|
chainInstance = getSubstrateChainImpl(origin, customCtx);
|
|
3550
3517
|
return _context.a(2, chainInstance.transfer({
|
|
3551
3518
|
api: api,
|
|
@@ -5974,7 +5941,7 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
5974
5941
|
break;
|
|
5975
5942
|
}
|
|
5976
5943
|
_context2.n = 8;
|
|
5977
|
-
return addEthereumBridgeFees(api, bridgeHubHop
|
|
5944
|
+
return addEthereumBridgeFees(api, bridgeHubHop.result, destination, assetHubChain);
|
|
5978
5945
|
case 8:
|
|
5979
5946
|
_t9 = _context2.v;
|
|
5980
5947
|
_context2.n = 10;
|
|
@@ -6248,7 +6215,7 @@ var localizeLocationInner = function localizeLocationInner(chain, location, orig
|
|
|
6248
6215
|
if (locationRelay && targetRelay && locationRelay !== targetRelay && (!origin || !ecosystemDiffers && isConsensusAnchored)) {
|
|
6249
6216
|
return location;
|
|
6250
6217
|
}
|
|
6251
|
-
if (origin && ecosystemDiffers && location.parents === Parents.TWO &&
|
|
6218
|
+
if (origin && ecosystemDiffers && location.parents === Parents.TWO && deepEqual(getJunctionValue(location, 'GlobalConsensus'), _defineProperty({}, targetRelay, null)) && junctionCount === 1) {
|
|
6252
6219
|
return RELAY_LOCATION;
|
|
6253
6220
|
}
|
|
6254
6221
|
var newInterior = location.interior === 'Here' ? {
|
|
@@ -6297,7 +6264,7 @@ var localizeLocationInner = function localizeLocationInner(chain, location, orig
|
|
|
6297
6264
|
parents: Parents.ONE
|
|
6298
6265
|
});
|
|
6299
6266
|
}
|
|
6300
|
-
if (origin && ecosystemDiffers && isOriginRelayHere && !hasGlobalConsensus
|
|
6267
|
+
if (origin && ecosystemDiffers && isOriginRelayHere && !hasGlobalConsensus) {
|
|
6301
6268
|
return {
|
|
6302
6269
|
parents: Parents.TWO,
|
|
6303
6270
|
interior: {
|
|
@@ -6307,7 +6274,7 @@ var localizeLocationInner = function localizeLocationInner(chain, location, orig
|
|
|
6307
6274
|
}
|
|
6308
6275
|
};
|
|
6309
6276
|
}
|
|
6310
|
-
if (origin && ecosystemDiffers && newInterior.Here === undefined && !hasGlobalConsensus
|
|
6277
|
+
if (origin && ecosystemDiffers && newInterior.Here === undefined && !hasGlobalConsensus) {
|
|
6311
6278
|
var _junctions = flattenJunctions(newInterior);
|
|
6312
6279
|
var updatedJunctions = [{
|
|
6313
6280
|
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
@@ -6598,7 +6565,7 @@ var wrapTxBypass = /*#__PURE__*/function () {
|
|
|
6598
6565
|
case 1:
|
|
6599
6566
|
balance = _context.v;
|
|
6600
6567
|
bonus = mintBonusForSent(chain, sentAsset, feeAsset, !!mintFeeAssets, api);
|
|
6601
|
-
if (
|
|
6568
|
+
if (options.sentAssetMintMode === 'bypass') {
|
|
6602
6569
|
mintAmount = parseUnits(bypassMintAmount, sentAsset.decimals) + sentAsset.amount + BigInt(sentAsset.existentialDeposit);
|
|
6603
6570
|
} else {
|
|
6604
6571
|
missing = calcSentAssetPreviewMint(sentAsset, balance, dryRunOptions.keepAlive);
|
|
@@ -7040,7 +7007,8 @@ var computeAllFees = /*#__PURE__*/function () {
|
|
|
7040
7007
|
currency: currency,
|
|
7041
7008
|
feeAsset: feeCurrency,
|
|
7042
7009
|
disableFallback: false,
|
|
7043
|
-
skipReverseFeeCalculation: true
|
|
7010
|
+
skipReverseFeeCalculation: true,
|
|
7011
|
+
skipEdDeposit: true
|
|
7044
7012
|
});
|
|
7045
7013
|
case 3:
|
|
7046
7014
|
result = _context.v;
|
|
@@ -7173,11 +7141,11 @@ var resolveEdDeposit = /*#__PURE__*/function () {
|
|
|
7173
7141
|
|
|
7174
7142
|
var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
7175
7143
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
7176
|
-
var api, tx, origin, destination, sender, recipient, currency, feeAsset, version, disableFallback, swapConfig, useRootOrigin, skipReverseFeeCalculation, resolvedFeeAsset, _resolveCurrency, asset, assets, resolvedVersion, _yield$getOriginXcmFe, originFeeRaw, originAsset, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, isMythosToEthereum, originFee, destApi, destFeeRes, _result, _dryRunError, processHop, traversalResult, destFee, destAsset, destFeeType, destDryRunError, destSufficient, destResult, _destApi, destFallback, relayChain, bridgeHubChain, assetHubChain, bridgeHubHop, processedBridgeHub, bridgeHubHopIndex, convertToFeeDetail, result, dryRunError, _t, _t2, _t3, _t4;
|
|
7144
|
+
var api, tx, origin, destination, sender, recipient, currency, feeAsset, version, disableFallback, swapConfig, useRootOrigin, skipReverseFeeCalculation, skipEdDeposit, resolvedFeeAsset, _resolveCurrency, asset, assets, resolvedVersion, _yield$getOriginXcmFe, originFeeRaw, originAsset, originFeeType, originDryRunError, initialForwardedXcm, initialDestParaId, originWeight, sufficientOriginFee, isMythosToEthereum, originFee, destApi, destFeeRes, _result, _dryRunError, processHop, traversalResult, destFee, destAsset, destFeeType, destDryRunError, destSufficient, destResult, _destApi, destFallback, relayChain, bridgeHubChain, assetHubChain, bridgeHubHop, processedBridgeHub, bridgeHubHopIndex, convertToFeeDetail, result, dryRunError, _t, _t2, _t3, _t4;
|
|
7177
7145
|
return _regenerator().w(function (_context2) {
|
|
7178
7146
|
while (1) switch (_context2.p = _context2.n) {
|
|
7179
7147
|
case 0:
|
|
7180
|
-
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, sender = _ref.sender, recipient = _ref.recipient, currency = _ref.currency, feeAsset = _ref.feeAsset, version = _ref.version, disableFallback = _ref.disableFallback, swapConfig = _ref.swapConfig, useRootOrigin = _ref.useRootOrigin, skipReverseFeeCalculation = _ref.skipReverseFeeCalculation;
|
|
7148
|
+
api = _ref.api, tx = _ref.tx, origin = _ref.origin, destination = _ref.destination, sender = _ref.sender, recipient = _ref.recipient, currency = _ref.currency, feeAsset = _ref.feeAsset, version = _ref.version, disableFallback = _ref.disableFallback, swapConfig = _ref.swapConfig, useRootOrigin = _ref.useRootOrigin, skipReverseFeeCalculation = _ref.skipReverseFeeCalculation, skipEdDeposit = _ref.skipEdDeposit;
|
|
7181
7149
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(api, feeAsset, origin, destination, currency) : undefined;
|
|
7182
7150
|
_resolveCurrency = resolveCurrency(api, currency, resolvedFeeAsset, origin, destination), asset = _resolveCurrency.asset, assets = _resolveCurrency.assets;
|
|
7183
7151
|
resolvedVersion = pickCompatibleXcmVersion(api, origin, destination, version);
|
|
@@ -7346,7 +7314,7 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
7346
7314
|
});
|
|
7347
7315
|
case 1:
|
|
7348
7316
|
hopResult = _context.v;
|
|
7349
|
-
if (!(!isDestination || hopResult.fee === undefined || hopResult.dryRunError || isAssetEqual(hopResult.asset, hopApi.findNativeAssetInfoOrThrow(currentChain)))) {
|
|
7317
|
+
if (!(skipEdDeposit || !isDestination || hopResult.fee === undefined || hopResult.dryRunError || isAssetEqual(hopResult.asset, hopApi.findNativeAssetInfoOrThrow(currentChain)))) {
|
|
7350
7318
|
_context.n = 2;
|
|
7351
7319
|
break;
|
|
7352
7320
|
}
|
|
@@ -7988,7 +7956,7 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
7988
7956
|
selectedCurrency = _yield$buildOriginInf.selectedCurrency;
|
|
7989
7957
|
originXcmFee = _yield$buildOriginInf.xcmFee;
|
|
7990
7958
|
builtHops = [];
|
|
7991
|
-
if (!(hops
|
|
7959
|
+
if (!(hops.length > 0)) {
|
|
7992
7960
|
_context2.n = 7;
|
|
7993
7961
|
break;
|
|
7994
7962
|
}
|
|
@@ -9561,13 +9529,13 @@ var prepareExecuteContext = function prepareExecuteContext(_ref) {
|
|
|
9561
9529
|
var asset = createAsset(version, amount, assetInfo.location);
|
|
9562
9530
|
var assetLocalized = createAsset(version, amount, api.localizeLocation(chain, assetInfo.location));
|
|
9563
9531
|
var assetLocalizedToDest = createAsset(version, amount, localizeLocation(destChain, assetInfo.location));
|
|
9564
|
-
var assetLocalizedToReserve = createAsset(version, amount, api.localizeLocation(reserveChain
|
|
9532
|
+
var assetLocalizedToReserve = createAsset(version, amount, api.localizeLocation(reserveChain, assetInfo.location));
|
|
9565
9533
|
var resolvedFeeAssetInfo = getFeeAssetInfo(assetInfo, feeAssetInfo);
|
|
9566
9534
|
var feeAssetTotal = originFee + reserveFee + destFee;
|
|
9567
9535
|
var feeAsset = resolvedFeeAssetInfo && createAsset(version, feeAssetTotal, resolvedFeeAssetInfo.location);
|
|
9568
9536
|
var feeAssetLocalized = resolvedFeeAssetInfo && createAsset(version, feeAssetTotal, api.localizeLocation(chain, resolvedFeeAssetInfo.location));
|
|
9569
9537
|
var feeAssetLocalizedToDest = resolvedFeeAssetInfo && createAsset(version, destFee, localizeLocation(destChain, resolvedFeeAssetInfo.location));
|
|
9570
|
-
var feeAssetLocalizedToReserve = resolvedFeeAssetInfo && createAsset(version, reserveFee, api.localizeLocation(reserveChain
|
|
9538
|
+
var feeAssetLocalizedToReserve = resolvedFeeAssetInfo && createAsset(version, reserveFee, api.localizeLocation(reserveChain, resolvedFeeAssetInfo.location));
|
|
9571
9539
|
var feeReserveChain = resolvedFeeAssetInfo && api.getAssetReserveChain(chain, resolvedFeeAssetInfo.location);
|
|
9572
9540
|
return {
|
|
9573
9541
|
amount: amount,
|
|
@@ -9653,13 +9621,11 @@ var createBaseExecuteXcm = function createBaseExecuteXcm(options) {
|
|
|
9653
9621
|
// currency and must not be subtracted from the transfer amount.
|
|
9654
9622
|
var originFeeDeduction = feeAssetInfo && !feeAsset ? originFee : 0n;
|
|
9655
9623
|
var destLocation = createDestination(api, version, chain, destChain, paraIdTo);
|
|
9656
|
-
if (chain !== 'AssetHubPolkadot' && reserveChain === undefined) {
|
|
9657
|
-
throw new UnsupportedOperationError('Sending local reserve assets with custom fee asset is not yet supported for this chain.');
|
|
9658
|
-
}
|
|
9659
9624
|
if (feeReserveChain !== undefined && feeReserveChain !== reserveChain) {
|
|
9660
9625
|
throw new ScenarioNotSupportedError("Fee asset cannot pay fees on hops and destination because its reserve chain (".concat(feeReserveChain, ") differs from the reserve chain of the transferred asset (").concat(reserveChain, ")."));
|
|
9661
9626
|
}
|
|
9662
9627
|
var transferType = getInstructionType(api, version, chain, destChain, assetInfo, reserveChain, transactOptions);
|
|
9628
|
+
var hasReserveHop = transferType !== 'DepositAsset';
|
|
9663
9629
|
var createRoutingFilter = function createRoutingFilter(asset) {
|
|
9664
9630
|
return feeAsset ? createAllCountedFilter(2) : createAssetsFilter(asset, version);
|
|
9665
9631
|
};
|
|
@@ -9669,16 +9635,16 @@ var createBaseExecuteXcm = function createBaseExecuteXcm(options) {
|
|
|
9669
9635
|
throw new ScenarioNotSupportedError("Fee asset ".concat(feeAssetInfo.symbol, " cannot be teleported from ").concat(from, " to ").concat(to, ", so it cannot pay fees there."));
|
|
9670
9636
|
}
|
|
9671
9637
|
};
|
|
9672
|
-
var reserveToDestInstruction = isTeleportLeg(api, reserveChain
|
|
9638
|
+
var reserveToDestInstruction = isTeleportLeg(api, reserveChain, destChain, assetInfo) ? 'InitiateTeleport' : 'DepositReserveAsset';
|
|
9673
9639
|
var createReserveToDestXcm = function createReserveToDestXcm() {
|
|
9674
9640
|
if (isReserveDest) return suffixXcm;
|
|
9675
9641
|
if (reserveToDestInstruction === 'InitiateTeleport') {
|
|
9676
|
-
assertFeeAssetTeleportable(reserveChain
|
|
9642
|
+
assertFeeAssetTeleportable(reserveChain, destChain);
|
|
9677
9643
|
}
|
|
9678
9644
|
return [_defineProperty({}, reserveToDestInstruction, {
|
|
9679
9645
|
assets: createRoutingFilter(assetLocalizedToReserve),
|
|
9680
|
-
dest: createDestination(api, version, reserveChain
|
|
9681
|
-
xcm: [].concat(_toConsumableArray(createBuyExecution(feeAssetLocalizedToDest !== null && feeAssetLocalizedToDest !== void 0 ? feeAssetLocalizedToDest : updateAsset(assetLocalizedToDest, reserveFee === 1000n ? amount / 2n : amount - originFeeDeduction - reserveFee))), _toConsumableArray(suffixXcm))
|
|
9646
|
+
dest: createDestination(api, version, reserveChain, destChain, paraIdTo),
|
|
9647
|
+
xcm: [].concat(_toConsumableArray(createBuyExecution(feeAssetLocalizedToDest !== null && feeAssetLocalizedToDest !== void 0 ? feeAssetLocalizedToDest : updateAsset(assetLocalizedToDest, reserveFee === 1000n && hasReserveHop ? amount / 2n : amount - originFeeDeduction - reserveFee))), _toConsumableArray(suffixXcm))
|
|
9682
9648
|
})];
|
|
9683
9649
|
};
|
|
9684
9650
|
var mainInstructions;
|
|
@@ -10137,71 +10103,75 @@ var isMultiHopSwap = function isMultiHopSwap(exchangeChain, assetFrom, assetTo)
|
|
|
10137
10103
|
return isAssetHub && !isAssetEqual(assetFrom, nativeAsset) && !isAssetEqual(assetTo, nativeAsset);
|
|
10138
10104
|
};
|
|
10139
10105
|
|
|
10106
|
+
var createExchangeAsset = function createExchangeAsset(give, want) {
|
|
10107
|
+
return {
|
|
10108
|
+
ExchangeAsset: {
|
|
10109
|
+
give: give,
|
|
10110
|
+
want: want,
|
|
10111
|
+
maximal: true
|
|
10112
|
+
}
|
|
10113
|
+
};
|
|
10114
|
+
};
|
|
10140
10115
|
var createExchangeInstructions = /*#__PURE__*/function () {
|
|
10141
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options,
|
|
10142
|
-
var api, chain, exchangeChain, assetInfoFrom, assetInfoTo, version, calculateMinAmountOut, _options$fees, originReserveFee, exchangeFee, hasSeparateFeeAsset,
|
|
10116
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, separateFeeAssetInfo) {
|
|
10117
|
+
var api, chain, exchangeChain, assetInfoFrom, assetInfoTo, version, calculateMinAmountOut, _options$fees, originReserveFee, exchangeFee, hasSeparateFeeAsset, needsMultiHop, isDummyRun, halveOnDummyFees, createWant, amountIn, give, assetTo, nativeAsset, isNativeFeeAsset, nativeAmountOut, assetNative;
|
|
10143
10118
|
return _regenerator().w(function (_context) {
|
|
10144
10119
|
while (1) switch (_context.n) {
|
|
10145
10120
|
case 0:
|
|
10146
10121
|
api = options.api, chain = options.chain, exchangeChain = options.exchangeChain, assetInfoFrom = options.assetInfoFrom, assetInfoTo = options.assetInfoTo, version = options.version, calculateMinAmountOut = options.calculateMinAmountOut, _options$fees = options.fees, originReserveFee = _options$fees.originReserveFee, exchangeFee = _options$fees.exchangeFee;
|
|
10147
10122
|
hasSeparateFeeAsset = separateFeeAssetInfo !== undefined;
|
|
10148
|
-
nativeSymbol = getNativeAssetSymbol(exchangeChain);
|
|
10149
10123
|
needsMultiHop = isMultiHopSwap(exchangeChain, assetInfoFrom, assetInfoTo);
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10124
|
+
isDummyRun = exchangeFee === 0n;
|
|
10125
|
+
halveOnDummyFees = function halveOnDummyFees(amount) {
|
|
10126
|
+
return chain && isDummyRun ? (amount + 1n) / 2n : amount;
|
|
10127
|
+
};
|
|
10128
|
+
createWant = function createWant(asset) {
|
|
10129
|
+
return [isDummyRun ? _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
10130
|
+
fun: {
|
|
10131
|
+
Fungible: 1n
|
|
10132
|
+
}
|
|
10133
|
+
}) : asset];
|
|
10134
|
+
};
|
|
10135
|
+
amountIn = assetInfoFrom.amount - (chain && !hasSeparateFeeAsset ? originReserveFee + exchangeFee : 0n);
|
|
10136
|
+
give = {
|
|
10137
|
+
Definite: [createAsset(version, halveOnDummyFees(amountIn), localizeLocation(exchangeChain, assetInfoFrom.location))]
|
|
10138
|
+
};
|
|
10139
|
+
assetTo = createAsset(version, assetInfoTo.amount, localizeLocation(exchangeChain, assetInfoTo.location));
|
|
10153
10140
|
if (needsMultiHop) {
|
|
10154
10141
|
_context.n = 1;
|
|
10155
10142
|
break;
|
|
10156
10143
|
}
|
|
10157
|
-
return _context.a(2, [
|
|
10158
|
-
ExchangeAsset: {
|
|
10159
|
-
give: createAssetsFilter(assetFrom, version),
|
|
10160
|
-
want: [assetTo],
|
|
10161
|
-
maximal: hasSeparateFeeAsset
|
|
10162
|
-
}
|
|
10163
|
-
}]);
|
|
10144
|
+
return _context.a(2, [createExchangeAsset(give, createWant(assetTo))]);
|
|
10164
10145
|
case 1:
|
|
10146
|
+
// Multi-hop through native asset
|
|
10147
|
+
nativeAsset = api.findNativeAssetInfoOrThrow(exchangeChain);
|
|
10148
|
+
isNativeFeeAsset = hasSeparateFeeAsset && isAssetEqual(separateFeeAssetInfo, nativeAsset);
|
|
10165
10149
|
_context.n = 2;
|
|
10166
|
-
return calculateMinAmountOut(
|
|
10150
|
+
return calculateMinAmountOut(amountIn, nativeAsset, isNativeFeeAsset ? '0' : undefined);
|
|
10167
10151
|
case 2:
|
|
10168
10152
|
nativeAmountOut = _context.v;
|
|
10169
|
-
assetNative = createAsset(version,
|
|
10170
|
-
return _context.a(2, [{
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
want: [assetNative],
|
|
10174
|
-
maximal: hasSeparateFeeAsset
|
|
10175
|
-
}
|
|
10176
|
-
}, {
|
|
10177
|
-
ExchangeAsset: {
|
|
10178
|
-
give: separateFeeAssetInfo && isAssetEqual(separateFeeAssetInfo, nativeAsset) ? {
|
|
10179
|
-
Definite: [assetNative]
|
|
10180
|
-
} : createAssetsFilter(assetNative, version),
|
|
10181
|
-
want: [assetTo],
|
|
10182
|
-
maximal: true
|
|
10183
|
-
}
|
|
10184
|
-
}]);
|
|
10153
|
+
assetNative = createAsset(version, halveOnDummyFees(nativeAmountOut), localizeLocation(exchangeChain, nativeAsset.location));
|
|
10154
|
+
return _context.a(2, [createExchangeAsset(give, createWant(assetNative)), createExchangeAsset(isNativeFeeAsset ? {
|
|
10155
|
+
Definite: [assetNative]
|
|
10156
|
+
} : createAssetsFilter(assetNative, version), createWant(assetTo))]);
|
|
10185
10157
|
}
|
|
10186
10158
|
}, _callee);
|
|
10187
10159
|
}));
|
|
10188
|
-
return function createExchangeInstructions(_x, _x2
|
|
10160
|
+
return function createExchangeInstructions(_x, _x2) {
|
|
10189
10161
|
return _ref.apply(this, arguments);
|
|
10190
10162
|
};
|
|
10191
10163
|
}();
|
|
10192
10164
|
var createSwapExecuteXcm = /*#__PURE__*/function () {
|
|
10193
10165
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
10194
10166
|
var _ref3, _ref4;
|
|
10195
|
-
var api, chain, exchangeChain, destChain, assetInfoFrom, assetInfoTo, feeAssetInfo, _options$fees2, originFee, originReserveFee, exchangeFee, destReserveFee, destFee, sender, recipient, version, paraIdTo, isEthereumDest, resolvedDestChain,
|
|
10167
|
+
var api, chain, exchangeChain, destChain, assetInfoFrom, assetInfoTo, feeAssetInfo, _options$fees2, originFee, originReserveFee, exchangeFee, destReserveFee, destFee, sender, recipient, version, paraIdTo, isEthereumDest, resolvedDestChain, amountOut, assetToLocalizedToDest, ethFeeAssetInfo, ethBridgeFee, nativeFeeAssetInfo, ahApi, _yield$getParaEthTran, _yield$getParaEthTran2, bridgeFee, executionFee, resolvedFeeAssetInfo, hasSeparateFeeAsset, createLegFees, feeAssetBudget, isFeeLeftoverAboveEd, _prepareCommonExecute, prefix, depositInstruction, exchangeInstructions, exchangeToDestXcm, ethAsset, messageId, snowbridgeInstructions, finalXcm, fullXcm;
|
|
10196
10168
|
return _regenerator().w(function (_context2) {
|
|
10197
10169
|
while (1) switch (_context2.n) {
|
|
10198
10170
|
case 0:
|
|
10199
10171
|
api = options.api, chain = options.chain, exchangeChain = options.exchangeChain, destChain = options.destChain, assetInfoFrom = options.assetInfoFrom, assetInfoTo = options.assetInfoTo, feeAssetInfo = options.feeAssetInfo, _options$fees2 = options.fees, originFee = _options$fees2.originFee, originReserveFee = _options$fees2.originReserveFee, exchangeFee = _options$fees2.exchangeFee, destReserveFee = _options$fees2.destReserveFee, destFee = _options$fees2.destFee, sender = options.sender, recipient = options.recipient, version = options.version, paraIdTo = options.paraIdTo;
|
|
10200
10172
|
isEthereumDest = destChain !== undefined && isExternalChain(destChain); // For Ethereum destination, the actual hop target is AssetHub (bridge hub)
|
|
10201
10173
|
resolvedDestChain = isEthereumDest ? "AssetHub".concat(getRelayChainOf(chain !== null && chain !== void 0 ? chain : exchangeChain)) : undefined;
|
|
10202
|
-
|
|
10203
|
-
amountOut = assetInfoTo.amount;
|
|
10204
|
-
assetTo = createAsset(version, amountOut, localizeLocation(exchangeChain, assetInfoTo.location)); // For Ethereum, localize to AssetHub since that's where instructions execute
|
|
10174
|
+
amountOut = assetInfoTo.amount; // For Ethereum, localize to AssetHub since that's where instructions execute
|
|
10205
10175
|
assetToLocalizedToDest = createAsset(version, amountOut, localizeLocation((_ref3 = resolvedDestChain !== null && resolvedDestChain !== void 0 ? resolvedDestChain : destChain) !== null && _ref3 !== void 0 ? _ref3 : exchangeChain, assetInfoTo.location)); // For Ethereum destination, use DOT as feeAsset for bridge fees
|
|
10206
10176
|
ethBridgeFee = 0n;
|
|
10207
10177
|
if (!isEthereumDest) {
|
|
@@ -10259,7 +10229,7 @@ var createSwapExecuteXcm = /*#__PURE__*/function () {
|
|
|
10259
10229
|
version: version
|
|
10260
10230
|
}, assetToLocalizedToDest, isFeeLeftoverAboveEd()), prefix = _prepareCommonExecute.prefix, depositInstruction = _prepareCommonExecute.depositInstruction;
|
|
10261
10231
|
_context2.n = 4;
|
|
10262
|
-
return createExchangeInstructions(options,
|
|
10232
|
+
return createExchangeInstructions(options, resolvedFeeAssetInfo);
|
|
10263
10233
|
case 4:
|
|
10264
10234
|
exchangeInstructions = _context2.v;
|
|
10265
10235
|
if (!isEthereumDest) {
|
|
@@ -10327,22 +10297,86 @@ var createSwapExecuteXcm = /*#__PURE__*/function () {
|
|
|
10327
10297
|
}
|
|
10328
10298
|
}, _callee2);
|
|
10329
10299
|
}));
|
|
10330
|
-
return function createSwapExecuteXcm(
|
|
10300
|
+
return function createSwapExecuteXcm(_x3) {
|
|
10331
10301
|
return _ref2.apply(this, arguments);
|
|
10332
10302
|
};
|
|
10333
10303
|
}();
|
|
10334
10304
|
|
|
10305
|
+
var scaleFeeToPostTradePrice = function scaleFeeToPostTradePrice(fee, soldAmount, nativeForFee, nativeForSoldAmount) {
|
|
10306
|
+
var spotToAverageNumerator = nativeForFee * soldAmount;
|
|
10307
|
+
var spotToAverageDenominator = fee * nativeForSoldAmount;
|
|
10308
|
+
var postTradeFee = fee * spotToAverageNumerator * spotToAverageNumerator / (spotToAverageDenominator * spotToAverageDenominator);
|
|
10309
|
+
return postTradeFee > fee ? postTradeFee : fee;
|
|
10310
|
+
};
|
|
10311
|
+
/**
|
|
10312
|
+
* AssetHub pays the onward delivery fee from the sold asset after the swap moved the pool price,
|
|
10313
|
+
* so the pre-trade fee estimate is scaled to the post-trade price to avoid NotHoldingFees.
|
|
10314
|
+
*/
|
|
10315
|
+
var getExchangeFeeAtPostTradePrice = /*#__PURE__*/function () {
|
|
10316
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, _ref2, hasSeparateFeeAsset) {
|
|
10317
|
+
var api, chain, exchangeChain, destChain, assetInfoFrom, calculateMinAmountOut, originReserveFee, exchangeFee, nativeAsset, isOnwardFeeTakenFromSoldAsset, soldAmount, _yield$Promise$all, _yield$Promise$all2, nativeForFee, nativeForSoldAmount;
|
|
10318
|
+
return _regenerator().w(function (_context) {
|
|
10319
|
+
while (1) switch (_context.n) {
|
|
10320
|
+
case 0:
|
|
10321
|
+
api = _ref.api, chain = _ref.chain, exchangeChain = _ref.exchangeChain, destChain = _ref.destChain, assetInfoFrom = _ref.assetInfoFrom, calculateMinAmountOut = _ref.calculateMinAmountOut;
|
|
10322
|
+
originReserveFee = _ref2.originReserveFee, exchangeFee = _ref2.exchangeFee;
|
|
10323
|
+
nativeAsset = api.findNativeAssetInfoOrThrow(exchangeChain);
|
|
10324
|
+
isOnwardFeeTakenFromSoldAsset = chain !== undefined && destChain !== undefined && !hasSeparateFeeAsset && exchangeChain.includes('AssetHub') && !isAssetEqual(assetInfoFrom, nativeAsset);
|
|
10325
|
+
if (isOnwardFeeTakenFromSoldAsset) {
|
|
10326
|
+
_context.n = 1;
|
|
10327
|
+
break;
|
|
10328
|
+
}
|
|
10329
|
+
return _context.a(2, exchangeFee);
|
|
10330
|
+
case 1:
|
|
10331
|
+
soldAmount = assetInfoFrom.amount - originReserveFee - exchangeFee;
|
|
10332
|
+
_context.n = 2;
|
|
10333
|
+
return Promise.all([calculateMinAmountOut(exchangeFee, nativeAsset, '0'), calculateMinAmountOut(soldAmount, nativeAsset, '0')]);
|
|
10334
|
+
case 2:
|
|
10335
|
+
_yield$Promise$all = _context.v;
|
|
10336
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
10337
|
+
nativeForFee = _yield$Promise$all2[0];
|
|
10338
|
+
nativeForSoldAmount = _yield$Promise$all2[1];
|
|
10339
|
+
if (!(nativeForSoldAmount === 0n)) {
|
|
10340
|
+
_context.n = 3;
|
|
10341
|
+
break;
|
|
10342
|
+
}
|
|
10343
|
+
return _context.a(2, exchangeFee);
|
|
10344
|
+
case 3:
|
|
10345
|
+
return _context.a(2, scaleFeeToPostTradePrice(exchangeFee, soldAmount, nativeForFee, nativeForSoldAmount));
|
|
10346
|
+
}
|
|
10347
|
+
}, _callee);
|
|
10348
|
+
}));
|
|
10349
|
+
return function getExchangeFeeAtPostTradePrice(_x, _x2, _x3) {
|
|
10350
|
+
return _ref3.apply(this, arguments);
|
|
10351
|
+
};
|
|
10352
|
+
}();
|
|
10353
|
+
|
|
10335
10354
|
var FEE_PADDING_PERCENTAGE = 20;
|
|
10355
|
+
var FEE_SHORTFALL_REASONS = ['NotHoldingFees', 'TooExpensive'];
|
|
10336
10356
|
var validateAmount = function validateAmount(amount, requiredFee) {
|
|
10337
10357
|
if (amount <= requiredFee) {
|
|
10338
10358
|
throw new AmountTooLowError("Asset amount is too low, please increase the amount or use a different fee asset.");
|
|
10339
10359
|
}
|
|
10340
10360
|
};
|
|
10361
|
+
var hasRealFeeShortfall = function hasRealFeeShortfall(_ref, exchangeChain, destChain) {
|
|
10362
|
+
var hops = _ref.hops,
|
|
10363
|
+
destination = _ref.destination;
|
|
10364
|
+
var exchangeIndex = hops.findIndex(function (hop) {
|
|
10365
|
+
return hop.chain === exchangeChain;
|
|
10366
|
+
});
|
|
10367
|
+
var checkedHops = exchangeIndex === -1 ? hops : hops.slice(0, exchangeIndex + 1);
|
|
10368
|
+
var results = [].concat(_toConsumableArray(checkedHops.map(function (hop) {
|
|
10369
|
+
return hop.result;
|
|
10370
|
+
})), _toConsumableArray(destChain ? [] : [destination]));
|
|
10371
|
+
return results.some(function (result) {
|
|
10372
|
+
return (result === null || result === void 0 ? void 0 : result.success) === false && FEE_SHORTFALL_REASONS.includes(result.dryRunError.reason);
|
|
10373
|
+
});
|
|
10374
|
+
};
|
|
10341
10375
|
var calculateTotalFees = function calculateTotalFees(chain, fees) {
|
|
10342
10376
|
return chain ? fees.originReserveFee + fees.exchangeFee : 0n;
|
|
10343
10377
|
};
|
|
10344
10378
|
var executeDryRun = /*#__PURE__*/function () {
|
|
10345
|
-
var
|
|
10379
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
10346
10380
|
var result;
|
|
10347
10381
|
return _regenerator().w(function (_context) {
|
|
10348
10382
|
while (1) switch (_context.n) {
|
|
@@ -10365,7 +10399,7 @@ var executeDryRun = /*#__PURE__*/function () {
|
|
|
10365
10399
|
}, _callee);
|
|
10366
10400
|
}));
|
|
10367
10401
|
return function executeDryRun(_x) {
|
|
10368
|
-
return
|
|
10402
|
+
return _ref2.apply(this, arguments);
|
|
10369
10403
|
};
|
|
10370
10404
|
}();
|
|
10371
10405
|
var findExchangeHopIndex = function findExchangeHopIndex(chain, dryRunResult, exchangeChain, destChain) {
|
|
@@ -10478,7 +10512,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, exchangeChain,
|
|
|
10478
10512
|
return fees;
|
|
10479
10513
|
};
|
|
10480
10514
|
var createXcmAndCall = /*#__PURE__*/function () {
|
|
10481
|
-
var
|
|
10515
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options, dryRunWeight) {
|
|
10482
10516
|
var xcm, api, chain, exchangeChain, hasApiSupport, weight, call, _t;
|
|
10483
10517
|
return _regenerator().w(function (_context2) {
|
|
10484
10518
|
while (1) switch (_context2.n) {
|
|
@@ -10513,13 +10547,13 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
10513
10547
|
}, _callee2);
|
|
10514
10548
|
}));
|
|
10515
10549
|
return function createXcmAndCall(_x2, _x3) {
|
|
10516
|
-
return
|
|
10550
|
+
return _ref3.apply(this, arguments);
|
|
10517
10551
|
};
|
|
10518
10552
|
}();
|
|
10519
10553
|
var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
10520
|
-
var
|
|
10521
|
-
var
|
|
10522
|
-
var api, chain, exchangeChain, destChain, assetFrom, assetTo, currencyTo, feeAssetInfo, sender, recipient, calculateMinAmountOut, version, isEthereumDest, separateFeeAssetInfo, hasSeparateFeeAsset, internalOptions, dryRunParams, FEE_ASSET_AMOUNT, dummyFeeAssetAmount, dummyDestFee, fees, totalFeesPre, _yield$createXcmAndCa, initialCall, firstDryRunResult, exchangeHopIndex, extractedFees, totalFees, updatedAssetTo, amountAvailableForSwap, recalculatedMinAmountOut, _yield$createXcmAndCa2, finalCall;
|
|
10554
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
10555
|
+
var _ref5;
|
|
10556
|
+
var api, chain, exchangeChain, destChain, assetFrom, assetTo, currencyTo, feeAssetInfo, sender, recipient, calculateMinAmountOut, version, isEthereumDest, separateFeeAssetInfo, hasSeparateFeeAsset, internalOptions, dryRunParams, FEE_ASSET_AMOUNT, dummyFeeAssetAmount, dummyDestFee, fees, totalFeesPre, _yield$createXcmAndCa, initialCall, firstDryRunResult, dryRunError, exchangeHopIndex, extractedFees, totalFees, updatedAssetTo, amountAvailableForSwap, recalculatedMinAmountOut, _yield$createXcmAndCa2, finalCall;
|
|
10523
10557
|
return _regenerator().w(function (_context3) {
|
|
10524
10558
|
while (1) switch (_context3.n) {
|
|
10525
10559
|
case 0:
|
|
@@ -10561,7 +10595,7 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10561
10595
|
};
|
|
10562
10596
|
FEE_ASSET_AMOUNT = 100;
|
|
10563
10597
|
dummyFeeAssetAmount = separateFeeAssetInfo ? parseUnits(FEE_ASSET_AMOUNT.toString(), separateFeeAssetInfo.decimals) : undefined;
|
|
10564
|
-
dummyDestFee = (
|
|
10598
|
+
dummyDestFee = (_ref5 = separateFeeAssetInfo && getFeeAssetInfo(assetTo, separateFeeAssetInfo) && dummyFeeAssetAmount) !== null && _ref5 !== void 0 ? _ref5 : MIN_FEE;
|
|
10565
10599
|
fees = {
|
|
10566
10600
|
originFee: dummyFeeAssetAmount !== null && dummyFeeAssetAmount !== void 0 ? dummyFeeAssetAmount : 0n,
|
|
10567
10601
|
originReserveFee: dummyFeeAssetAmount !== null && dummyFeeAssetAmount !== void 0 ? dummyFeeAssetAmount : MIN_FEE,
|
|
@@ -10591,18 +10625,26 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10591
10625
|
}));
|
|
10592
10626
|
case 3:
|
|
10593
10627
|
firstDryRunResult = _context3.v;
|
|
10594
|
-
|
|
10628
|
+
dryRunError = firstDryRunResult.dryRunError;
|
|
10629
|
+
if (!separateFeeAssetInfo) {
|
|
10595
10630
|
_context3.n = 5;
|
|
10596
10631
|
break;
|
|
10597
10632
|
}
|
|
10598
|
-
if (!
|
|
10633
|
+
if (!((dryRunError === null || dryRunError === void 0 ? void 0 : dryRunError.reason) === 'NotHoldingFees')) {
|
|
10599
10634
|
_context3.n = 4;
|
|
10600
10635
|
break;
|
|
10601
10636
|
}
|
|
10602
|
-
throw new DryRunFailedError(
|
|
10637
|
+
throw new DryRunFailedError(dryRunError);
|
|
10603
10638
|
case 4:
|
|
10604
|
-
|
|
10639
|
+
_context3.n = 6;
|
|
10640
|
+
break;
|
|
10605
10641
|
case 5:
|
|
10642
|
+
if (!hasRealFeeShortfall(firstDryRunResult, exchangeChain, destChain)) {
|
|
10643
|
+
_context3.n = 6;
|
|
10644
|
+
break;
|
|
10645
|
+
}
|
|
10646
|
+
throw new AmountTooLowError('Asset amount is too low to cover the fees, please increase the amount.');
|
|
10647
|
+
case 6:
|
|
10606
10648
|
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult, exchangeChain, destChain);
|
|
10607
10649
|
extractedFees = extractFeesFromDryRun(chain, exchangeChain, firstDryRunResult, exchangeHopIndex, destChain, false); // Set originFee from dry run origin fee (padded), same as handleExecuteTransfer
|
|
10608
10650
|
extractedFees.originFee = separateFeeAssetInfo && firstDryRunResult.origin.success ? padValueBy(firstDryRunResult.origin.fee, FEE_PADDING_PERCENTAGE) : 0n;
|
|
@@ -10610,32 +10652,36 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10610
10652
|
// We set the exchange fee to non-zero value to prevent creating dummy tx
|
|
10611
10653
|
extractedFees.exchangeFee = MIN_FEE;
|
|
10612
10654
|
}
|
|
10655
|
+
_context3.n = 7;
|
|
10656
|
+
return getExchangeFeeAtPostTradePrice(options, extractedFees, hasSeparateFeeAsset);
|
|
10657
|
+
case 7:
|
|
10658
|
+
extractedFees.exchangeFee = _context3.v;
|
|
10613
10659
|
totalFees = calculateTotalFees(chain, extractedFees);
|
|
10614
10660
|
if (!hasSeparateFeeAsset) {
|
|
10615
10661
|
validateAmount(assetFrom.amount, totalFees);
|
|
10616
10662
|
}
|
|
10617
10663
|
updatedAssetTo = assetTo;
|
|
10618
10664
|
if (!chain) {
|
|
10619
|
-
_context3.n =
|
|
10665
|
+
_context3.n = 9;
|
|
10620
10666
|
break;
|
|
10621
10667
|
}
|
|
10622
10668
|
// When fees are paid from a separate asset (e.g. DOT for Ethereum),
|
|
10623
10669
|
// the full main asset amount is available for the swap
|
|
10624
10670
|
amountAvailableForSwap = hasSeparateFeeAsset ? assetFrom.amount : assetFrom.amount - totalFees;
|
|
10625
|
-
_context3.n =
|
|
10671
|
+
_context3.n = 8;
|
|
10626
10672
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
10627
|
-
case
|
|
10673
|
+
case 8:
|
|
10628
10674
|
recalculatedMinAmountOut = _context3.v;
|
|
10629
10675
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
10630
10676
|
amount: recalculatedMinAmountOut
|
|
10631
10677
|
});
|
|
10632
|
-
case
|
|
10633
|
-
_context3.n =
|
|
10678
|
+
case 9:
|
|
10679
|
+
_context3.n = 10;
|
|
10634
10680
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
10635
10681
|
assetInfoTo: updatedAssetTo,
|
|
10636
10682
|
fees: extractedFees
|
|
10637
10683
|
}), firstDryRunResult.origin.success ? firstDryRunResult.origin.weight : undefined);
|
|
10638
|
-
case
|
|
10684
|
+
case 10:
|
|
10639
10685
|
_yield$createXcmAndCa2 = _context3.v;
|
|
10640
10686
|
finalCall = _yield$createXcmAndCa2.call;
|
|
10641
10687
|
return _context3.a(2, api.deserializeExtrinsics(finalCall));
|
|
@@ -10643,7 +10689,7 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10643
10689
|
}, _callee3);
|
|
10644
10690
|
}));
|
|
10645
10691
|
return function handleSwapExecuteTransfer(_x4) {
|
|
10646
|
-
return
|
|
10692
|
+
return _ref4.apply(this, arguments);
|
|
10647
10693
|
};
|
|
10648
10694
|
}();
|
|
10649
10695
|
|
|
@@ -10993,11 +11039,6 @@ var Astar = /*#__PURE__*/function (_SubstrateChain) {
|
|
|
10993
11039
|
useBigIntId: true
|
|
10994
11040
|
};
|
|
10995
11041
|
}
|
|
10996
|
-
}, {
|
|
10997
|
-
key: "shouldUseReserveTransfer",
|
|
10998
|
-
value: function shouldUseReserveTransfer() {
|
|
10999
|
-
return true;
|
|
11000
|
-
}
|
|
11001
11042
|
}, {
|
|
11002
11043
|
key: "isSendingTempDisabled",
|
|
11003
11044
|
value: function isSendingTempDisabled(assetInfo) {
|
|
@@ -11228,7 +11269,7 @@ var BifrostPolkadot = /*#__PURE__*/function (_SubstrateChain) {
|
|
|
11228
11269
|
}
|
|
11229
11270
|
var isVToken = asset.symbol && asset.symbol.startsWith('v');
|
|
11230
11271
|
var isVSToken = asset.symbol && asset.symbol.startsWith('vs');
|
|
11231
|
-
if (asset.isNative || !asset.
|
|
11272
|
+
if (asset.isNative || !asset.assetId) {
|
|
11232
11273
|
return isVToken ? {
|
|
11233
11274
|
VToken: asset.symbol.substring(1)
|
|
11234
11275
|
} : {
|
|
@@ -11359,8 +11400,7 @@ var resolveLocationFromDest = function resolveLocationFromDest(destination, asse
|
|
|
11359
11400
|
if (isRelayChain(destination)) return DOT_LOCATION;
|
|
11360
11401
|
// If it is a native asset, search by symbol on AssetHub and use the location from there
|
|
11361
11402
|
var assetHubAsset = getOtherAssets(destination).find(function (ahAsset) {
|
|
11362
|
-
|
|
11363
|
-
return ((_ahAsset$symbol = ahAsset.symbol) === null || _ahAsset$symbol === void 0 ? void 0 : _ahAsset$symbol.toLowerCase()) === ((_asset$symbol = asset.symbol) === null || _asset$symbol === void 0 ? void 0 : _asset$symbol.toLowerCase());
|
|
11403
|
+
return ahAsset.symbol.toLowerCase() === asset.symbol.toLowerCase();
|
|
11364
11404
|
});
|
|
11365
11405
|
if (!assetHubAsset) {
|
|
11366
11406
|
throw new InvalidCurrencyError("Asset ".concat(asset.symbol, " not found"));
|
|
@@ -11760,11 +11800,6 @@ var EnergyWebX = /*#__PURE__*/function (_SubstrateChain) {
|
|
|
11760
11800
|
value: function isRelayToParaEnabled() {
|
|
11761
11801
|
return false;
|
|
11762
11802
|
}
|
|
11763
|
-
}, {
|
|
11764
|
-
key: "shouldUseReserveTransfer",
|
|
11765
|
-
value: function shouldUseReserveTransfer() {
|
|
11766
|
-
return true;
|
|
11767
|
-
}
|
|
11768
11803
|
}, {
|
|
11769
11804
|
key: "getMintConfig",
|
|
11770
11805
|
value: function getMintConfig() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paraspell/sdk-core",
|
|
3
|
-
"version": "14.5.
|
|
3
|
+
"version": "14.5.4",
|
|
4
4
|
"description": "SDK core for ParaSpell XCM/XCMP tool for developers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@noble/hashes": "^2.4.0",
|
|
26
|
-
"@paraspell/assets": "14.5.
|
|
27
|
-
"@paraspell/pallets": "14.5.
|
|
28
|
-
"@paraspell/sdk-common": "14.5.
|
|
26
|
+
"@paraspell/assets": "14.5.4",
|
|
27
|
+
"@paraspell/pallets": "14.5.4",
|
|
28
|
+
"@paraspell/sdk-common": "14.5.4",
|
|
29
29
|
"@scure/base": "^2.4.0",
|
|
30
30
|
"viem": "^2.57.13"
|
|
31
31
|
},
|