@paraspell/sdk-core 14.5.3 → 14.6.0
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 +4 -16
- package/dist/index.mjs +291 -332
- package/package.json +10 -10
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;
|
|
@@ -307,15 +305,6 @@ declare class BridgeHubWestend<TApi, TRes, TSigner, TCustomChain extends string
|
|
|
307
305
|
constructor();
|
|
308
306
|
}
|
|
309
307
|
|
|
310
|
-
declare class Centrifuge<TApi, TRes, TSigner, TCustomChain extends string = never> extends SubstrateChain<TApi, TRes, TSigner, TCustomChain> implements IXTokensTransfer<TApi, TRes, TSigner, TCustomChain> {
|
|
311
|
-
constructor();
|
|
312
|
-
getCustomCurrencyId(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>, asset: TAssetInfo): "Native" | {
|
|
313
|
-
ForeignAsset: number;
|
|
314
|
-
};
|
|
315
|
-
transferXTokens(input: TXTokensTransferOptions<TApi, TRes, TSigner, TCustomChain>): TRes;
|
|
316
|
-
transferLocalNonNativeAsset(options: TTransferLocalOptions<TApi, TRes, TSigner, TCustomChain>): TRes;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
308
|
declare class Collectives<TApi, TRes, TSigner, TCustomChain extends string = never> extends SubstrateChain<TApi, TRes, TSigner, TCustomChain> implements IPolkadotXCMTransfer<TApi, TRes, TSigner, TCustomChain> {
|
|
320
309
|
constructor(chain?: TParachain, info?: string, ecosystem?: TRelaychain, version?: Version);
|
|
321
310
|
transferPolkadotXCM(input: TPolkadotXCMTransferOptions<TApi, TRes, TSigner, TCustomChain>): Promise<TRes>;
|
|
@@ -364,7 +353,6 @@ declare class EnergyWebX<TApi, TRes, TSigner, TCustomChain extends string = neve
|
|
|
364
353
|
constructor(chain?: TParachain, info?: string, ecosystem?: TRelaychain, version?: Version);
|
|
365
354
|
transferPolkadotXCM(input: TPolkadotXCMTransferOptions<TApi, TRes, TSigner, TCustomChain>): Promise<TRes>;
|
|
366
355
|
isRelayToParaEnabled(): boolean;
|
|
367
|
-
protected shouldUseReserveTransfer(): boolean;
|
|
368
356
|
protected getMintConfig(): TMintConfig;
|
|
369
357
|
transferLocalNonNativeAsset(options: TTransferLocalOptions<TApi, TRes, TSigner, TCustomChain>): TRes;
|
|
370
358
|
getBalanceForeign(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>, address: string, asset: TAssetInfo): Promise<bigint>;
|
|
@@ -538,7 +526,6 @@ declare const chains: <TApi, TRes, TSigner>() => {
|
|
|
538
526
|
Unique: Unique<TApi, TRes, TSigner, never>;
|
|
539
527
|
BifrostPolkadot: BifrostPolkadot<TApi, TRes, TSigner, never>;
|
|
540
528
|
BridgeHubPolkadot: BridgeHubPolkadot<TApi, TRes, TSigner, never>;
|
|
541
|
-
Centrifuge: Centrifuge<TApi, TRes, TSigner, never>;
|
|
542
529
|
Darwinia: Darwinia<TApi, TRes, TSigner, never>;
|
|
543
530
|
EnergyWebX: EnergyWebX<TApi, TRes, TSigner, never>;
|
|
544
531
|
Hydration: Hydration<TApi, TRes, TSigner, never>;
|
|
@@ -1528,6 +1515,7 @@ type TGetXcmFeeBaseOptions<TRes, TDisableFallback extends boolean = boolean, TCu
|
|
|
1528
1515
|
disableFallback: TDisableFallback;
|
|
1529
1516
|
swapConfig?: TXcmFeeSwapConfig;
|
|
1530
1517
|
skipReverseFeeCalculation?: boolean;
|
|
1518
|
+
skipEdDeposit?: boolean;
|
|
1531
1519
|
};
|
|
1532
1520
|
type TGetXcmFeeOptions<TApi, TRes, TSigner, TDisableFallback extends boolean = boolean, TCustomChain extends string = never> = WithApi<TGetXcmFeeBaseOptions<TRes, TDisableFallback, TCustomChain>, TApi, TRes, TSigner, TCustomChain>;
|
|
1533
1521
|
type TGetXcmFeeInternalOptions<TApi, TRes, TSigner, TDisableFallback extends boolean = boolean, TCustomChain extends string = never> = Omit<TGetXcmFeeOptions<TApi, TRes, TSigner, TDisableFallback, TCustomChain>, 'buildTx'> & {
|
|
@@ -2151,7 +2139,7 @@ type TCreateBaseSwapXcmOptions = {
|
|
|
2151
2139
|
feeAssetInfo?: TAssetInfo;
|
|
2152
2140
|
sender: string;
|
|
2153
2141
|
recipient: string;
|
|
2154
|
-
calculateMinAmountOut: (amountIn: bigint, assetTo?: TAssetInfo) => Promise<bigint>;
|
|
2142
|
+
calculateMinAmountOut: (amountIn: bigint, assetTo?: TAssetInfo, slippagePct?: string) => Promise<bigint>;
|
|
2155
2143
|
};
|
|
2156
2144
|
type TCreateSwapXcmOptions<TApi, TRes, TSigner, TCustomChain extends string = never> = WithApi<TCreateBaseSwapXcmOptions, TApi, TRes, TSigner, TCustomChain>;
|
|
2157
2145
|
type TSwapFeeEstimates = {
|
|
@@ -2382,7 +2370,7 @@ declare const getOriginXcmFeeInternal: <TApi, TRes, TSigner, TCustomChain extend
|
|
|
2382
2370
|
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
2371
|
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
2372
|
|
|
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>>;
|
|
2373
|
+
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
2374
|
|
|
2387
2375
|
declare const getBridgeStatus: <TApi, TRes, TSigner, TCustomChain extends string = never>(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>) => Promise<TBridgeStatus>;
|
|
2388
2376
|
|
|
@@ -2573,7 +2561,7 @@ declare const reverseTransformLocation: (location: TLocation) => TLocation;
|
|
|
2573
2561
|
|
|
2574
2562
|
declare const normalizeAmount: (amount: bigint) => bigint;
|
|
2575
2563
|
|
|
2576
|
-
declare const resolveDestChain: <TApi, TRes, TSigner, TCustomChain extends string = never>(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>, originChain: TSubstrateChain | TCustomChain, paraId: number | undefined) => "AssetHubPolkadot" | "Acala" | "Ajuna" | "Astar" | "BifrostPolkadot" | "BridgeHubPolkadot" | "
|
|
2564
|
+
declare const resolveDestChain: <TApi, TRes, TSigner, TCustomChain extends string = never>(api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>, originChain: TSubstrateChain | TCustomChain, paraId: number | undefined) => "AssetHubPolkadot" | "Acala" | "Ajuna" | "Astar" | "BifrostPolkadot" | "BridgeHubPolkadot" | "Darwinia" | "EnergyWebX" | "Hydration" | "Heima" | "Jamton" | "CoretimePolkadot" | "Collectives" | "NeuroWeb" | "Pendulum" | "Mythos" | "Peaq" | "PeoplePolkadot" | "Unique" | "Xode" | "AssetHubKusama" | "BridgeHubKusama" | "Karura" | "CoretimeKusama" | "Encointer" | "Basilisk" | "BifrostKusama" | "Curio" | "RobonomicsPolkadot" | "PeopleKusama" | "Shiden" | "AssetHubWestend" | "BridgeHubWestend" | "CollectivesWestend" | "CoretimeWestend" | "Penpal" | "PeopleWestend" | "AssetHubPaseo" | "EnergyWebXPaseo" | "HeimaPaseo" | "HydrationPaseo" | "PeoplePaseo" | "Shibuya" | undefined;
|
|
2577
2565
|
|
|
2578
2566
|
declare const resolveParaId: <TApi, TRes, TSigner, TCustomChain extends string = never>(paraId: number | undefined, destination: TDestination, api: PolkadotApi<TApi, TRes, TSigner, TCustomChain>) => number | undefined;
|
|
2579
2567
|
|
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';
|
|
@@ -377,7 +377,7 @@ function _toPrimitive(t, r) {
|
|
|
377
377
|
if ("object" != typeof i) return i;
|
|
378
378
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
379
379
|
}
|
|
380
|
-
return (String )(t);
|
|
380
|
+
return ("string" === r ? String : Number)(t);
|
|
381
381
|
}
|
|
382
382
|
function _toPropertyKey(t) {
|
|
383
383
|
var i = _toPrimitive(t, "string");
|
|
@@ -1036,21 +1036,6 @@ var BridgeHubPolkadot$1 = {
|
|
|
1036
1036
|
}
|
|
1037
1037
|
]
|
|
1038
1038
|
};
|
|
1039
|
-
var Centrifuge$1 = {
|
|
1040
|
-
name: "Centrifuge",
|
|
1041
|
-
info: "centrifuge",
|
|
1042
|
-
paraId: 2031,
|
|
1043
|
-
providers: [
|
|
1044
|
-
{
|
|
1045
|
-
name: "OnFinality",
|
|
1046
|
-
endpoint: "wss://centrifuge-parachain.api.onfinality.io/public-ws"
|
|
1047
|
-
},
|
|
1048
|
-
{
|
|
1049
|
-
name: "Centrifuge",
|
|
1050
|
-
endpoint: "wss://fullnode.centrifuge.io"
|
|
1051
|
-
}
|
|
1052
|
-
]
|
|
1053
|
-
};
|
|
1054
1039
|
var Darwinia$1 = {
|
|
1055
1040
|
name: "Darwinia",
|
|
1056
1041
|
info: "darwinia",
|
|
@@ -1817,7 +1802,6 @@ var configs = {
|
|
|
1817
1802
|
Astar: Astar$1,
|
|
1818
1803
|
BifrostPolkadot: BifrostPolkadot$1,
|
|
1819
1804
|
BridgeHubPolkadot: BridgeHubPolkadot$1,
|
|
1820
|
-
Centrifuge: Centrifuge$1,
|
|
1821
1805
|
Darwinia: Darwinia$1,
|
|
1822
1806
|
EnergyWebX: EnergyWebX$1,
|
|
1823
1807
|
Hydration: Hydration$1,
|
|
@@ -2661,7 +2645,7 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2661
2645
|
key: "transfer",
|
|
2662
2646
|
value: function () {
|
|
2663
2647
|
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,
|
|
2648
|
+
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
2649
|
return _regenerator().w(function (_context) {
|
|
2666
2650
|
while (1) switch (_context.n) {
|
|
2667
2651
|
case 0:
|
|
@@ -2687,26 +2671,20 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2687
2671
|
this.throwIfTempDisabled(transferOptions, destChain);
|
|
2688
2672
|
this.throwIfCantReceive(destChain);
|
|
2689
2673
|
isRelayAsset = deepEqual(asset.location, RELAY_LOCATION) && isSymbolMatch(api.getRelayChainSymbol(this.chain), asset.symbol);
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2674
|
+
if (!(supportsPolkadotXCM(this) || isRelayAsset)) {
|
|
2675
|
+
_context.n = 11;
|
|
2676
|
+
break;
|
|
2677
|
+
}
|
|
2694
2678
|
_context.n = 3;
|
|
2695
|
-
return api.hasMethod(api.
|
|
2679
|
+
return api.hasMethod(api.getXcmPallet(this.chain), 'transfer_assets_using_type_and_then');
|
|
2696
2680
|
case 3:
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
if (!(assetNeedsTypeThen && !supportsTypeThen && (!shouldUseReserveTransfer || isSubBridge))) {
|
|
2681
|
+
supportsTypeAndThen = _context.v;
|
|
2682
|
+
if (supportsTypeAndThen) {
|
|
2700
2683
|
_context.n = 4;
|
|
2701
2684
|
break;
|
|
2702
2685
|
}
|
|
2703
|
-
throw new TypeAndThenUnavailableError(
|
|
2686
|
+
throw new TypeAndThenUnavailableError("Chain ".concat(this.chain, " does not support the type-and-then method required for this transfer."));
|
|
2704
2687
|
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
2688
|
options = {
|
|
2711
2689
|
api: api,
|
|
2712
2690
|
chain: this.chain,
|
|
@@ -2751,53 +2729,31 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2751
2729
|
case 6:
|
|
2752
2730
|
return _context.a(2, _t.deserializeExtrinsics.call(_t, _context.v));
|
|
2753
2731
|
case 7:
|
|
2732
|
+
isSubBridge = !isTLocation(destination) && isSubstrateBridge(this.chain, destination);
|
|
2754
2733
|
isAHOrigin = this.chain.includes('AssetHub');
|
|
2755
|
-
isAHDest = !isTLocation(destination) && destination.includes('AssetHub'); // Handle common cases
|
|
2756
2734
|
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)) {
|
|
2735
|
+
isEthDest = _typeof(destination) !== 'object' && isExternalChain(destination);
|
|
2736
|
+
isExternalAssetViaAh = isExternalAsset && !isAHOrigin && !isEthDest;
|
|
2737
|
+
if (!(!supportsPolkadotXCM(this) || isSubBridge || isExternalAssetViaAh)) {
|
|
2765
2738
|
_context.n = 9;
|
|
2766
2739
|
break;
|
|
2767
2740
|
}
|
|
2741
|
+
_t2 = api;
|
|
2768
2742
|
_context.n = 8;
|
|
2769
|
-
return
|
|
2743
|
+
return createTypeAndThenCall(options);
|
|
2770
2744
|
case 8:
|
|
2771
|
-
|
|
2772
|
-
if (!this.shouldUseExecuteTransfer(options)) {
|
|
2773
|
-
_context.n = 9;
|
|
2774
|
-
break;
|
|
2775
|
-
}
|
|
2776
|
-
return _context.a(2, tx);
|
|
2745
|
+
return _context.a(2, _t2.deserializeExtrinsics.call(_t2, _context.v));
|
|
2777
2746
|
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
2747
|
if (!(this.shouldUseNativeAssetTeleport(transferOptions) && !getFeeAssetInfo(asset, feeAsset) && !this.shouldUseExecuteTransfer(options))) {
|
|
2789
|
-
_context.n =
|
|
2748
|
+
_context.n = 10;
|
|
2790
2749
|
break;
|
|
2791
2750
|
}
|
|
2792
2751
|
return _context.a(2, transferPolkadotXcm(options, 'limited_teleport_assets', 'Unlimited'));
|
|
2793
|
-
case
|
|
2752
|
+
case 10:
|
|
2794
2753
|
return _context.a(2, this.transferPolkadotXCM(options));
|
|
2795
|
-
case
|
|
2796
|
-
_context.n = 15;
|
|
2797
|
-
break;
|
|
2798
|
-
case 14:
|
|
2754
|
+
case 11:
|
|
2799
2755
|
if (!supportsXTokens(this)) {
|
|
2800
|
-
_context.n =
|
|
2756
|
+
_context.n = 12;
|
|
2801
2757
|
break;
|
|
2802
2758
|
}
|
|
2803
2759
|
validateFeeAssetSupport(asset, feeAsset, overriddenAsset, 'XTokens');
|
|
@@ -2815,9 +2771,9 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2815
2771
|
method: method
|
|
2816
2772
|
};
|
|
2817
2773
|
return _context.a(2, this.transferXTokens(input));
|
|
2818
|
-
case
|
|
2774
|
+
case 12:
|
|
2819
2775
|
throw new NoXCMSupportImplementedError(this.chain);
|
|
2820
|
-
case
|
|
2776
|
+
case 13:
|
|
2821
2777
|
return _context.a(2);
|
|
2822
2778
|
}
|
|
2823
2779
|
}, _callee, this);
|
|
@@ -2885,11 +2841,6 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
2885
2841
|
value: function shouldUseExecuteTransfer(_options) {
|
|
2886
2842
|
return false;
|
|
2887
2843
|
}
|
|
2888
|
-
}, {
|
|
2889
|
-
key: "shouldUseReserveTransfer",
|
|
2890
|
-
value: function shouldUseReserveTransfer() {
|
|
2891
|
-
return false;
|
|
2892
|
-
}
|
|
2893
2844
|
}, {
|
|
2894
2845
|
key: "createAsset",
|
|
2895
2846
|
value: function createAsset$1(api, asset, version) {
|
|
@@ -3048,7 +2999,7 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
3048
2999
|
key: "getBalanceForeign",
|
|
3049
3000
|
value: function () {
|
|
3050
3001
|
var _getBalanceForeign = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(api, address, asset) {
|
|
3051
|
-
var pallets, lastError, customCurrencyId, _iterator, _step, pallet, instance,
|
|
3002
|
+
var pallets, lastError, customCurrencyId, _iterator, _step, pallet, instance, _t3, _t4;
|
|
3052
3003
|
return _regenerator().w(function (_context3) {
|
|
3053
3004
|
while (1) switch (_context3.p = _context3.n) {
|
|
3054
3005
|
case 0:
|
|
@@ -3077,8 +3028,8 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
3077
3028
|
return _context3.a(2, _context3.v);
|
|
3078
3029
|
case 6:
|
|
3079
3030
|
_context3.p = 6;
|
|
3080
|
-
|
|
3081
|
-
lastError =
|
|
3031
|
+
_t3 = _context3.v;
|
|
3032
|
+
lastError = _t3;
|
|
3082
3033
|
case 7:
|
|
3083
3034
|
_context3.n = 3;
|
|
3084
3035
|
break;
|
|
@@ -3087,8 +3038,8 @@ var SubstrateChain = /*#__PURE__*/function (_Chain) {
|
|
|
3087
3038
|
break;
|
|
3088
3039
|
case 9:
|
|
3089
3040
|
_context3.p = 9;
|
|
3090
|
-
|
|
3091
|
-
_iterator.e(
|
|
3041
|
+
_t4 = _context3.v;
|
|
3042
|
+
_iterator.e(_t4);
|
|
3092
3043
|
case 10:
|
|
3093
3044
|
_context3.p = 10;
|
|
3094
3045
|
_iterator.f();
|
|
@@ -3545,7 +3496,7 @@ var createTransfer = /*#__PURE__*/function () {
|
|
|
3545
3496
|
return api.init(origin, TX_CLIENT_TIMEOUT_MS, destination);
|
|
3546
3497
|
case 1:
|
|
3547
3498
|
_resolveTransferParam = resolveTransferParams(options), resolvedFeeAsset = _resolveTransferParam.resolvedFeeAsset, resolvedVersion = _resolveTransferParam.resolvedVersion, overriddenAsset = _resolveTransferParam.overriddenAsset, normalizedAsset = _resolveTransferParam.normalizedAsset;
|
|
3548
|
-
customCtx = api
|
|
3499
|
+
customCtx = api._customCtx;
|
|
3549
3500
|
chainInstance = getSubstrateChainImpl(origin, customCtx);
|
|
3550
3501
|
return _context.a(2, chainInstance.transfer({
|
|
3551
3502
|
api: api,
|
|
@@ -5974,7 +5925,7 @@ var dryRunInternal = /*#__PURE__*/function () {
|
|
|
5974
5925
|
break;
|
|
5975
5926
|
}
|
|
5976
5927
|
_context2.n = 8;
|
|
5977
|
-
return addEthereumBridgeFees(api, bridgeHubHop
|
|
5928
|
+
return addEthereumBridgeFees(api, bridgeHubHop.result, destination, assetHubChain);
|
|
5978
5929
|
case 8:
|
|
5979
5930
|
_t9 = _context2.v;
|
|
5980
5931
|
_context2.n = 10;
|
|
@@ -6248,7 +6199,7 @@ var localizeLocationInner = function localizeLocationInner(chain, location, orig
|
|
|
6248
6199
|
if (locationRelay && targetRelay && locationRelay !== targetRelay && (!origin || !ecosystemDiffers && isConsensusAnchored)) {
|
|
6249
6200
|
return location;
|
|
6250
6201
|
}
|
|
6251
|
-
if (origin && ecosystemDiffers && location.parents === Parents.TWO &&
|
|
6202
|
+
if (origin && ecosystemDiffers && location.parents === Parents.TWO && deepEqual(getJunctionValue(location, 'GlobalConsensus'), _defineProperty({}, targetRelay, null)) && junctionCount === 1) {
|
|
6252
6203
|
return RELAY_LOCATION;
|
|
6253
6204
|
}
|
|
6254
6205
|
var newInterior = location.interior === 'Here' ? {
|
|
@@ -6297,7 +6248,7 @@ var localizeLocationInner = function localizeLocationInner(chain, location, orig
|
|
|
6297
6248
|
parents: Parents.ONE
|
|
6298
6249
|
});
|
|
6299
6250
|
}
|
|
6300
|
-
if (origin && ecosystemDiffers && isOriginRelayHere && !hasGlobalConsensus
|
|
6251
|
+
if (origin && ecosystemDiffers && isOriginRelayHere && !hasGlobalConsensus) {
|
|
6301
6252
|
return {
|
|
6302
6253
|
parents: Parents.TWO,
|
|
6303
6254
|
interior: {
|
|
@@ -6307,7 +6258,7 @@ var localizeLocationInner = function localizeLocationInner(chain, location, orig
|
|
|
6307
6258
|
}
|
|
6308
6259
|
};
|
|
6309
6260
|
}
|
|
6310
|
-
if (origin && ecosystemDiffers && newInterior.Here === undefined && !hasGlobalConsensus
|
|
6261
|
+
if (origin && ecosystemDiffers && newInterior.Here === undefined && !hasGlobalConsensus) {
|
|
6311
6262
|
var _junctions = flattenJunctions(newInterior);
|
|
6312
6263
|
var updatedJunctions = [{
|
|
6313
6264
|
GlobalConsensus: _defineProperty({}, originRelay, null)
|
|
@@ -6598,7 +6549,7 @@ var wrapTxBypass = /*#__PURE__*/function () {
|
|
|
6598
6549
|
case 1:
|
|
6599
6550
|
balance = _context.v;
|
|
6600
6551
|
bonus = mintBonusForSent(chain, sentAsset, feeAsset, !!mintFeeAssets, api);
|
|
6601
|
-
if (
|
|
6552
|
+
if (options.sentAssetMintMode === 'bypass') {
|
|
6602
6553
|
mintAmount = parseUnits(bypassMintAmount, sentAsset.decimals) + sentAsset.amount + BigInt(sentAsset.existentialDeposit);
|
|
6603
6554
|
} else {
|
|
6604
6555
|
missing = calcSentAssetPreviewMint(sentAsset, balance, dryRunOptions.keepAlive);
|
|
@@ -7040,7 +6991,8 @@ var computeAllFees = /*#__PURE__*/function () {
|
|
|
7040
6991
|
currency: currency,
|
|
7041
6992
|
feeAsset: feeCurrency,
|
|
7042
6993
|
disableFallback: false,
|
|
7043
|
-
skipReverseFeeCalculation: true
|
|
6994
|
+
skipReverseFeeCalculation: true,
|
|
6995
|
+
skipEdDeposit: true
|
|
7044
6996
|
});
|
|
7045
6997
|
case 3:
|
|
7046
6998
|
result = _context.v;
|
|
@@ -7173,11 +7125,11 @@ var resolveEdDeposit = /*#__PURE__*/function () {
|
|
|
7173
7125
|
|
|
7174
7126
|
var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
7175
7127
|
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;
|
|
7128
|
+
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
7129
|
return _regenerator().w(function (_context2) {
|
|
7178
7130
|
while (1) switch (_context2.p = _context2.n) {
|
|
7179
7131
|
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;
|
|
7132
|
+
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
7133
|
resolvedFeeAsset = feeAsset ? resolveFeeAsset(api, feeAsset, origin, destination, currency) : undefined;
|
|
7182
7134
|
_resolveCurrency = resolveCurrency(api, currency, resolvedFeeAsset, origin, destination), asset = _resolveCurrency.asset, assets = _resolveCurrency.assets;
|
|
7183
7135
|
resolvedVersion = pickCompatibleXcmVersion(api, origin, destination, version);
|
|
@@ -7346,7 +7298,7 @@ var getXcmFeeOnce = /*#__PURE__*/function () {
|
|
|
7346
7298
|
});
|
|
7347
7299
|
case 1:
|
|
7348
7300
|
hopResult = _context.v;
|
|
7349
|
-
if (!(!isDestination || hopResult.fee === undefined || hopResult.dryRunError || isAssetEqual(hopResult.asset, hopApi.findNativeAssetInfoOrThrow(currentChain)))) {
|
|
7301
|
+
if (!(skipEdDeposit || !isDestination || hopResult.fee === undefined || hopResult.dryRunError || isAssetEqual(hopResult.asset, hopApi.findNativeAssetInfoOrThrow(currentChain)))) {
|
|
7350
7302
|
_context.n = 2;
|
|
7351
7303
|
break;
|
|
7352
7304
|
}
|
|
@@ -7988,7 +7940,7 @@ var getTransferInfo = /*#__PURE__*/function () {
|
|
|
7988
7940
|
selectedCurrency = _yield$buildOriginInf.selectedCurrency;
|
|
7989
7941
|
originXcmFee = _yield$buildOriginInf.xcmFee;
|
|
7990
7942
|
builtHops = [];
|
|
7991
|
-
if (!(hops
|
|
7943
|
+
if (!(hops.length > 0)) {
|
|
7992
7944
|
_context2.n = 7;
|
|
7993
7945
|
break;
|
|
7994
7946
|
}
|
|
@@ -9561,13 +9513,13 @@ var prepareExecuteContext = function prepareExecuteContext(_ref) {
|
|
|
9561
9513
|
var asset = createAsset(version, amount, assetInfo.location);
|
|
9562
9514
|
var assetLocalized = createAsset(version, amount, api.localizeLocation(chain, assetInfo.location));
|
|
9563
9515
|
var assetLocalizedToDest = createAsset(version, amount, localizeLocation(destChain, assetInfo.location));
|
|
9564
|
-
var assetLocalizedToReserve = createAsset(version, amount, api.localizeLocation(reserveChain
|
|
9516
|
+
var assetLocalizedToReserve = createAsset(version, amount, api.localizeLocation(reserveChain, assetInfo.location));
|
|
9565
9517
|
var resolvedFeeAssetInfo = getFeeAssetInfo(assetInfo, feeAssetInfo);
|
|
9566
9518
|
var feeAssetTotal = originFee + reserveFee + destFee;
|
|
9567
9519
|
var feeAsset = resolvedFeeAssetInfo && createAsset(version, feeAssetTotal, resolvedFeeAssetInfo.location);
|
|
9568
9520
|
var feeAssetLocalized = resolvedFeeAssetInfo && createAsset(version, feeAssetTotal, api.localizeLocation(chain, resolvedFeeAssetInfo.location));
|
|
9569
9521
|
var feeAssetLocalizedToDest = resolvedFeeAssetInfo && createAsset(version, destFee, localizeLocation(destChain, resolvedFeeAssetInfo.location));
|
|
9570
|
-
var feeAssetLocalizedToReserve = resolvedFeeAssetInfo && createAsset(version, reserveFee, api.localizeLocation(reserveChain
|
|
9522
|
+
var feeAssetLocalizedToReserve = resolvedFeeAssetInfo && createAsset(version, reserveFee, api.localizeLocation(reserveChain, resolvedFeeAssetInfo.location));
|
|
9571
9523
|
var feeReserveChain = resolvedFeeAssetInfo && api.getAssetReserveChain(chain, resolvedFeeAssetInfo.location);
|
|
9572
9524
|
return {
|
|
9573
9525
|
amount: amount,
|
|
@@ -9653,13 +9605,11 @@ var createBaseExecuteXcm = function createBaseExecuteXcm(options) {
|
|
|
9653
9605
|
// currency and must not be subtracted from the transfer amount.
|
|
9654
9606
|
var originFeeDeduction = feeAssetInfo && !feeAsset ? originFee : 0n;
|
|
9655
9607
|
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
9608
|
if (feeReserveChain !== undefined && feeReserveChain !== reserveChain) {
|
|
9660
9609
|
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
9610
|
}
|
|
9662
9611
|
var transferType = getInstructionType(api, version, chain, destChain, assetInfo, reserveChain, transactOptions);
|
|
9612
|
+
var hasReserveHop = transferType !== 'DepositAsset';
|
|
9663
9613
|
var createRoutingFilter = function createRoutingFilter(asset) {
|
|
9664
9614
|
return feeAsset ? createAllCountedFilter(2) : createAssetsFilter(asset, version);
|
|
9665
9615
|
};
|
|
@@ -9669,16 +9619,16 @@ var createBaseExecuteXcm = function createBaseExecuteXcm(options) {
|
|
|
9669
9619
|
throw new ScenarioNotSupportedError("Fee asset ".concat(feeAssetInfo.symbol, " cannot be teleported from ").concat(from, " to ").concat(to, ", so it cannot pay fees there."));
|
|
9670
9620
|
}
|
|
9671
9621
|
};
|
|
9672
|
-
var reserveToDestInstruction = isTeleportLeg(api, reserveChain
|
|
9622
|
+
var reserveToDestInstruction = isTeleportLeg(api, reserveChain, destChain, assetInfo) ? 'InitiateTeleport' : 'DepositReserveAsset';
|
|
9673
9623
|
var createReserveToDestXcm = function createReserveToDestXcm() {
|
|
9674
9624
|
if (isReserveDest) return suffixXcm;
|
|
9675
9625
|
if (reserveToDestInstruction === 'InitiateTeleport') {
|
|
9676
|
-
assertFeeAssetTeleportable(reserveChain
|
|
9626
|
+
assertFeeAssetTeleportable(reserveChain, destChain);
|
|
9677
9627
|
}
|
|
9678
9628
|
return [_defineProperty({}, reserveToDestInstruction, {
|
|
9679
9629
|
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))
|
|
9630
|
+
dest: createDestination(api, version, reserveChain, destChain, paraIdTo),
|
|
9631
|
+
xcm: [].concat(_toConsumableArray(createBuyExecution(feeAssetLocalizedToDest !== null && feeAssetLocalizedToDest !== void 0 ? feeAssetLocalizedToDest : updateAsset(assetLocalizedToDest, reserveFee === 1000n && hasReserveHop ? amount / 2n : amount - originFeeDeduction - reserveFee))), _toConsumableArray(suffixXcm))
|
|
9682
9632
|
})];
|
|
9683
9633
|
};
|
|
9684
9634
|
var mainInstructions;
|
|
@@ -10137,71 +10087,75 @@ var isMultiHopSwap = function isMultiHopSwap(exchangeChain, assetFrom, assetTo)
|
|
|
10137
10087
|
return isAssetHub && !isAssetEqual(assetFrom, nativeAsset) && !isAssetEqual(assetTo, nativeAsset);
|
|
10138
10088
|
};
|
|
10139
10089
|
|
|
10090
|
+
var createExchangeAsset = function createExchangeAsset(give, want) {
|
|
10091
|
+
return {
|
|
10092
|
+
ExchangeAsset: {
|
|
10093
|
+
give: give,
|
|
10094
|
+
want: want,
|
|
10095
|
+
maximal: true
|
|
10096
|
+
}
|
|
10097
|
+
};
|
|
10098
|
+
};
|
|
10140
10099
|
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,
|
|
10100
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options, separateFeeAssetInfo) {
|
|
10101
|
+
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
10102
|
return _regenerator().w(function (_context) {
|
|
10144
10103
|
while (1) switch (_context.n) {
|
|
10145
10104
|
case 0:
|
|
10146
10105
|
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
10106
|
hasSeparateFeeAsset = separateFeeAssetInfo !== undefined;
|
|
10148
|
-
nativeSymbol = getNativeAssetSymbol(exchangeChain);
|
|
10149
10107
|
needsMultiHop = isMultiHopSwap(exchangeChain, assetInfoFrom, assetInfoTo);
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10108
|
+
isDummyRun = exchangeFee === 0n;
|
|
10109
|
+
halveOnDummyFees = function halveOnDummyFees(amount) {
|
|
10110
|
+
return chain && isDummyRun ? (amount + 1n) / 2n : amount;
|
|
10111
|
+
};
|
|
10112
|
+
createWant = function createWant(asset) {
|
|
10113
|
+
return [isDummyRun ? _objectSpread2(_objectSpread2({}, asset), {}, {
|
|
10114
|
+
fun: {
|
|
10115
|
+
Fungible: 1n
|
|
10116
|
+
}
|
|
10117
|
+
}) : asset];
|
|
10118
|
+
};
|
|
10119
|
+
amountIn = assetInfoFrom.amount - (chain && !hasSeparateFeeAsset ? originReserveFee + exchangeFee : 0n);
|
|
10120
|
+
give = {
|
|
10121
|
+
Definite: [createAsset(version, halveOnDummyFees(amountIn), localizeLocation(exchangeChain, assetInfoFrom.location))]
|
|
10122
|
+
};
|
|
10123
|
+
assetTo = createAsset(version, assetInfoTo.amount, localizeLocation(exchangeChain, assetInfoTo.location));
|
|
10153
10124
|
if (needsMultiHop) {
|
|
10154
10125
|
_context.n = 1;
|
|
10155
10126
|
break;
|
|
10156
10127
|
}
|
|
10157
|
-
return _context.a(2, [
|
|
10158
|
-
ExchangeAsset: {
|
|
10159
|
-
give: createAssetsFilter(assetFrom, version),
|
|
10160
|
-
want: [assetTo],
|
|
10161
|
-
maximal: hasSeparateFeeAsset
|
|
10162
|
-
}
|
|
10163
|
-
}]);
|
|
10128
|
+
return _context.a(2, [createExchangeAsset(give, createWant(assetTo))]);
|
|
10164
10129
|
case 1:
|
|
10130
|
+
// Multi-hop through native asset
|
|
10131
|
+
nativeAsset = api.findNativeAssetInfoOrThrow(exchangeChain);
|
|
10132
|
+
isNativeFeeAsset = hasSeparateFeeAsset && isAssetEqual(separateFeeAssetInfo, nativeAsset);
|
|
10165
10133
|
_context.n = 2;
|
|
10166
|
-
return calculateMinAmountOut(
|
|
10134
|
+
return calculateMinAmountOut(amountIn, nativeAsset, isNativeFeeAsset ? '0' : undefined);
|
|
10167
10135
|
case 2:
|
|
10168
10136
|
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
|
-
}]);
|
|
10137
|
+
assetNative = createAsset(version, halveOnDummyFees(nativeAmountOut), localizeLocation(exchangeChain, nativeAsset.location));
|
|
10138
|
+
return _context.a(2, [createExchangeAsset(give, createWant(assetNative)), createExchangeAsset(isNativeFeeAsset ? {
|
|
10139
|
+
Definite: [assetNative]
|
|
10140
|
+
} : createAssetsFilter(assetNative, version), createWant(assetTo))]);
|
|
10185
10141
|
}
|
|
10186
10142
|
}, _callee);
|
|
10187
10143
|
}));
|
|
10188
|
-
return function createExchangeInstructions(_x, _x2
|
|
10144
|
+
return function createExchangeInstructions(_x, _x2) {
|
|
10189
10145
|
return _ref.apply(this, arguments);
|
|
10190
10146
|
};
|
|
10191
10147
|
}();
|
|
10192
10148
|
var createSwapExecuteXcm = /*#__PURE__*/function () {
|
|
10193
10149
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
|
|
10194
10150
|
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,
|
|
10151
|
+
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
10152
|
return _regenerator().w(function (_context2) {
|
|
10197
10153
|
while (1) switch (_context2.n) {
|
|
10198
10154
|
case 0:
|
|
10199
10155
|
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
10156
|
isEthereumDest = destChain !== undefined && isExternalChain(destChain); // For Ethereum destination, the actual hop target is AssetHub (bridge hub)
|
|
10201
10157
|
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
|
|
10158
|
+
amountOut = assetInfoTo.amount; // For Ethereum, localize to AssetHub since that's where instructions execute
|
|
10205
10159
|
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
10160
|
ethBridgeFee = 0n;
|
|
10207
10161
|
if (!isEthereumDest) {
|
|
@@ -10259,7 +10213,7 @@ var createSwapExecuteXcm = /*#__PURE__*/function () {
|
|
|
10259
10213
|
version: version
|
|
10260
10214
|
}, assetToLocalizedToDest, isFeeLeftoverAboveEd()), prefix = _prepareCommonExecute.prefix, depositInstruction = _prepareCommonExecute.depositInstruction;
|
|
10261
10215
|
_context2.n = 4;
|
|
10262
|
-
return createExchangeInstructions(options,
|
|
10216
|
+
return createExchangeInstructions(options, resolvedFeeAssetInfo);
|
|
10263
10217
|
case 4:
|
|
10264
10218
|
exchangeInstructions = _context2.v;
|
|
10265
10219
|
if (!isEthereumDest) {
|
|
@@ -10327,22 +10281,86 @@ var createSwapExecuteXcm = /*#__PURE__*/function () {
|
|
|
10327
10281
|
}
|
|
10328
10282
|
}, _callee2);
|
|
10329
10283
|
}));
|
|
10330
|
-
return function createSwapExecuteXcm(
|
|
10284
|
+
return function createSwapExecuteXcm(_x3) {
|
|
10331
10285
|
return _ref2.apply(this, arguments);
|
|
10332
10286
|
};
|
|
10333
10287
|
}();
|
|
10334
10288
|
|
|
10289
|
+
var scaleFeeToPostTradePrice = function scaleFeeToPostTradePrice(fee, soldAmount, nativeForFee, nativeForSoldAmount) {
|
|
10290
|
+
var spotToAverageNumerator = nativeForFee * soldAmount;
|
|
10291
|
+
var spotToAverageDenominator = fee * nativeForSoldAmount;
|
|
10292
|
+
var postTradeFee = fee * spotToAverageNumerator * spotToAverageNumerator / (spotToAverageDenominator * spotToAverageDenominator);
|
|
10293
|
+
return postTradeFee > fee ? postTradeFee : fee;
|
|
10294
|
+
};
|
|
10295
|
+
/**
|
|
10296
|
+
* AssetHub pays the onward delivery fee from the sold asset after the swap moved the pool price,
|
|
10297
|
+
* so the pre-trade fee estimate is scaled to the post-trade price to avoid NotHoldingFees.
|
|
10298
|
+
*/
|
|
10299
|
+
var getExchangeFeeAtPostTradePrice = /*#__PURE__*/function () {
|
|
10300
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref, _ref2, hasSeparateFeeAsset) {
|
|
10301
|
+
var api, chain, exchangeChain, destChain, assetInfoFrom, calculateMinAmountOut, originReserveFee, exchangeFee, nativeAsset, isOnwardFeeTakenFromSoldAsset, soldAmount, _yield$Promise$all, _yield$Promise$all2, nativeForFee, nativeForSoldAmount;
|
|
10302
|
+
return _regenerator().w(function (_context) {
|
|
10303
|
+
while (1) switch (_context.n) {
|
|
10304
|
+
case 0:
|
|
10305
|
+
api = _ref.api, chain = _ref.chain, exchangeChain = _ref.exchangeChain, destChain = _ref.destChain, assetInfoFrom = _ref.assetInfoFrom, calculateMinAmountOut = _ref.calculateMinAmountOut;
|
|
10306
|
+
originReserveFee = _ref2.originReserveFee, exchangeFee = _ref2.exchangeFee;
|
|
10307
|
+
nativeAsset = api.findNativeAssetInfoOrThrow(exchangeChain);
|
|
10308
|
+
isOnwardFeeTakenFromSoldAsset = chain !== undefined && destChain !== undefined && !hasSeparateFeeAsset && exchangeChain.includes('AssetHub') && !isAssetEqual(assetInfoFrom, nativeAsset);
|
|
10309
|
+
if (isOnwardFeeTakenFromSoldAsset) {
|
|
10310
|
+
_context.n = 1;
|
|
10311
|
+
break;
|
|
10312
|
+
}
|
|
10313
|
+
return _context.a(2, exchangeFee);
|
|
10314
|
+
case 1:
|
|
10315
|
+
soldAmount = assetInfoFrom.amount - originReserveFee - exchangeFee;
|
|
10316
|
+
_context.n = 2;
|
|
10317
|
+
return Promise.all([calculateMinAmountOut(exchangeFee, nativeAsset, '0'), calculateMinAmountOut(soldAmount, nativeAsset, '0')]);
|
|
10318
|
+
case 2:
|
|
10319
|
+
_yield$Promise$all = _context.v;
|
|
10320
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
10321
|
+
nativeForFee = _yield$Promise$all2[0];
|
|
10322
|
+
nativeForSoldAmount = _yield$Promise$all2[1];
|
|
10323
|
+
if (!(nativeForSoldAmount === 0n)) {
|
|
10324
|
+
_context.n = 3;
|
|
10325
|
+
break;
|
|
10326
|
+
}
|
|
10327
|
+
return _context.a(2, exchangeFee);
|
|
10328
|
+
case 3:
|
|
10329
|
+
return _context.a(2, scaleFeeToPostTradePrice(exchangeFee, soldAmount, nativeForFee, nativeForSoldAmount));
|
|
10330
|
+
}
|
|
10331
|
+
}, _callee);
|
|
10332
|
+
}));
|
|
10333
|
+
return function getExchangeFeeAtPostTradePrice(_x, _x2, _x3) {
|
|
10334
|
+
return _ref3.apply(this, arguments);
|
|
10335
|
+
};
|
|
10336
|
+
}();
|
|
10337
|
+
|
|
10335
10338
|
var FEE_PADDING_PERCENTAGE = 20;
|
|
10339
|
+
var FEE_SHORTFALL_REASONS = ['NotHoldingFees', 'TooExpensive'];
|
|
10336
10340
|
var validateAmount = function validateAmount(amount, requiredFee) {
|
|
10337
10341
|
if (amount <= requiredFee) {
|
|
10338
10342
|
throw new AmountTooLowError("Asset amount is too low, please increase the amount or use a different fee asset.");
|
|
10339
10343
|
}
|
|
10340
10344
|
};
|
|
10345
|
+
var hasRealFeeShortfall = function hasRealFeeShortfall(_ref, exchangeChain, destChain) {
|
|
10346
|
+
var hops = _ref.hops,
|
|
10347
|
+
destination = _ref.destination;
|
|
10348
|
+
var exchangeIndex = hops.findIndex(function (hop) {
|
|
10349
|
+
return hop.chain === exchangeChain;
|
|
10350
|
+
});
|
|
10351
|
+
var checkedHops = exchangeIndex === -1 ? hops : hops.slice(0, exchangeIndex + 1);
|
|
10352
|
+
var results = [].concat(_toConsumableArray(checkedHops.map(function (hop) {
|
|
10353
|
+
return hop.result;
|
|
10354
|
+
})), _toConsumableArray(destChain ? [] : [destination]));
|
|
10355
|
+
return results.some(function (result) {
|
|
10356
|
+
return (result === null || result === void 0 ? void 0 : result.success) === false && FEE_SHORTFALL_REASONS.includes(result.dryRunError.reason);
|
|
10357
|
+
});
|
|
10358
|
+
};
|
|
10341
10359
|
var calculateTotalFees = function calculateTotalFees(chain, fees) {
|
|
10342
10360
|
return chain ? fees.originReserveFee + fees.exchangeFee : 0n;
|
|
10343
10361
|
};
|
|
10344
10362
|
var executeDryRun = /*#__PURE__*/function () {
|
|
10345
|
-
var
|
|
10363
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
|
|
10346
10364
|
var result;
|
|
10347
10365
|
return _regenerator().w(function (_context) {
|
|
10348
10366
|
while (1) switch (_context.n) {
|
|
@@ -10365,7 +10383,7 @@ var executeDryRun = /*#__PURE__*/function () {
|
|
|
10365
10383
|
}, _callee);
|
|
10366
10384
|
}));
|
|
10367
10385
|
return function executeDryRun(_x) {
|
|
10368
|
-
return
|
|
10386
|
+
return _ref2.apply(this, arguments);
|
|
10369
10387
|
};
|
|
10370
10388
|
}();
|
|
10371
10389
|
var findExchangeHopIndex = function findExchangeHopIndex(chain, dryRunResult, exchangeChain, destChain) {
|
|
@@ -10478,7 +10496,7 @@ var extractFeesFromDryRun = function extractFeesFromDryRun(chain, exchangeChain,
|
|
|
10478
10496
|
return fees;
|
|
10479
10497
|
};
|
|
10480
10498
|
var createXcmAndCall = /*#__PURE__*/function () {
|
|
10481
|
-
var
|
|
10499
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options, dryRunWeight) {
|
|
10482
10500
|
var xcm, api, chain, exchangeChain, hasApiSupport, weight, call, _t;
|
|
10483
10501
|
return _regenerator().w(function (_context2) {
|
|
10484
10502
|
while (1) switch (_context2.n) {
|
|
@@ -10513,13 +10531,13 @@ var createXcmAndCall = /*#__PURE__*/function () {
|
|
|
10513
10531
|
}, _callee2);
|
|
10514
10532
|
}));
|
|
10515
10533
|
return function createXcmAndCall(_x2, _x3) {
|
|
10516
|
-
return
|
|
10534
|
+
return _ref3.apply(this, arguments);
|
|
10517
10535
|
};
|
|
10518
10536
|
}();
|
|
10519
10537
|
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;
|
|
10538
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
|
|
10539
|
+
var _ref5;
|
|
10540
|
+
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
10541
|
return _regenerator().w(function (_context3) {
|
|
10524
10542
|
while (1) switch (_context3.n) {
|
|
10525
10543
|
case 0:
|
|
@@ -10561,7 +10579,7 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10561
10579
|
};
|
|
10562
10580
|
FEE_ASSET_AMOUNT = 100;
|
|
10563
10581
|
dummyFeeAssetAmount = separateFeeAssetInfo ? parseUnits(FEE_ASSET_AMOUNT.toString(), separateFeeAssetInfo.decimals) : undefined;
|
|
10564
|
-
dummyDestFee = (
|
|
10582
|
+
dummyDestFee = (_ref5 = separateFeeAssetInfo && getFeeAssetInfo(assetTo, separateFeeAssetInfo) && dummyFeeAssetAmount) !== null && _ref5 !== void 0 ? _ref5 : MIN_FEE;
|
|
10565
10583
|
fees = {
|
|
10566
10584
|
originFee: dummyFeeAssetAmount !== null && dummyFeeAssetAmount !== void 0 ? dummyFeeAssetAmount : 0n,
|
|
10567
10585
|
originReserveFee: dummyFeeAssetAmount !== null && dummyFeeAssetAmount !== void 0 ? dummyFeeAssetAmount : MIN_FEE,
|
|
@@ -10591,18 +10609,26 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10591
10609
|
}));
|
|
10592
10610
|
case 3:
|
|
10593
10611
|
firstDryRunResult = _context3.v;
|
|
10594
|
-
|
|
10612
|
+
dryRunError = firstDryRunResult.dryRunError;
|
|
10613
|
+
if (!separateFeeAssetInfo) {
|
|
10595
10614
|
_context3.n = 5;
|
|
10596
10615
|
break;
|
|
10597
10616
|
}
|
|
10598
|
-
if (!
|
|
10617
|
+
if (!((dryRunError === null || dryRunError === void 0 ? void 0 : dryRunError.reason) === 'NotHoldingFees')) {
|
|
10599
10618
|
_context3.n = 4;
|
|
10600
10619
|
break;
|
|
10601
10620
|
}
|
|
10602
|
-
throw new DryRunFailedError(
|
|
10621
|
+
throw new DryRunFailedError(dryRunError);
|
|
10603
10622
|
case 4:
|
|
10604
|
-
|
|
10623
|
+
_context3.n = 6;
|
|
10624
|
+
break;
|
|
10605
10625
|
case 5:
|
|
10626
|
+
if (!hasRealFeeShortfall(firstDryRunResult, exchangeChain, destChain)) {
|
|
10627
|
+
_context3.n = 6;
|
|
10628
|
+
break;
|
|
10629
|
+
}
|
|
10630
|
+
throw new AmountTooLowError('Asset amount is too low to cover the fees, please increase the amount.');
|
|
10631
|
+
case 6:
|
|
10606
10632
|
exchangeHopIndex = findExchangeHopIndex(chain, firstDryRunResult, exchangeChain, destChain);
|
|
10607
10633
|
extractedFees = extractFeesFromDryRun(chain, exchangeChain, firstDryRunResult, exchangeHopIndex, destChain, false); // Set originFee from dry run origin fee (padded), same as handleExecuteTransfer
|
|
10608
10634
|
extractedFees.originFee = separateFeeAssetInfo && firstDryRunResult.origin.success ? padValueBy(firstDryRunResult.origin.fee, FEE_PADDING_PERCENTAGE) : 0n;
|
|
@@ -10610,32 +10636,36 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10610
10636
|
// We set the exchange fee to non-zero value to prevent creating dummy tx
|
|
10611
10637
|
extractedFees.exchangeFee = MIN_FEE;
|
|
10612
10638
|
}
|
|
10639
|
+
_context3.n = 7;
|
|
10640
|
+
return getExchangeFeeAtPostTradePrice(options, extractedFees, hasSeparateFeeAsset);
|
|
10641
|
+
case 7:
|
|
10642
|
+
extractedFees.exchangeFee = _context3.v;
|
|
10613
10643
|
totalFees = calculateTotalFees(chain, extractedFees);
|
|
10614
10644
|
if (!hasSeparateFeeAsset) {
|
|
10615
10645
|
validateAmount(assetFrom.amount, totalFees);
|
|
10616
10646
|
}
|
|
10617
10647
|
updatedAssetTo = assetTo;
|
|
10618
10648
|
if (!chain) {
|
|
10619
|
-
_context3.n =
|
|
10649
|
+
_context3.n = 9;
|
|
10620
10650
|
break;
|
|
10621
10651
|
}
|
|
10622
10652
|
// When fees are paid from a separate asset (e.g. DOT for Ethereum),
|
|
10623
10653
|
// the full main asset amount is available for the swap
|
|
10624
10654
|
amountAvailableForSwap = hasSeparateFeeAsset ? assetFrom.amount : assetFrom.amount - totalFees;
|
|
10625
|
-
_context3.n =
|
|
10655
|
+
_context3.n = 8;
|
|
10626
10656
|
return calculateMinAmountOut(amountAvailableForSwap);
|
|
10627
|
-
case
|
|
10657
|
+
case 8:
|
|
10628
10658
|
recalculatedMinAmountOut = _context3.v;
|
|
10629
10659
|
updatedAssetTo = _objectSpread2(_objectSpread2({}, assetTo), {}, {
|
|
10630
10660
|
amount: recalculatedMinAmountOut
|
|
10631
10661
|
});
|
|
10632
|
-
case
|
|
10633
|
-
_context3.n =
|
|
10662
|
+
case 9:
|
|
10663
|
+
_context3.n = 10;
|
|
10634
10664
|
return createXcmAndCall(_objectSpread2(_objectSpread2({}, internalOptions), {}, {
|
|
10635
10665
|
assetInfoTo: updatedAssetTo,
|
|
10636
10666
|
fees: extractedFees
|
|
10637
10667
|
}), firstDryRunResult.origin.success ? firstDryRunResult.origin.weight : undefined);
|
|
10638
|
-
case
|
|
10668
|
+
case 10:
|
|
10639
10669
|
_yield$createXcmAndCa2 = _context3.v;
|
|
10640
10670
|
finalCall = _yield$createXcmAndCa2.call;
|
|
10641
10671
|
return _context3.a(2, api.deserializeExtrinsics(finalCall));
|
|
@@ -10643,7 +10673,7 @@ var handleSwapExecuteTransfer = /*#__PURE__*/function () {
|
|
|
10643
10673
|
}, _callee3);
|
|
10644
10674
|
}));
|
|
10645
10675
|
return function handleSwapExecuteTransfer(_x4) {
|
|
10646
|
-
return
|
|
10676
|
+
return _ref4.apply(this, arguments);
|
|
10647
10677
|
};
|
|
10648
10678
|
}();
|
|
10649
10679
|
|
|
@@ -10993,11 +11023,6 @@ var Astar = /*#__PURE__*/function (_SubstrateChain) {
|
|
|
10993
11023
|
useBigIntId: true
|
|
10994
11024
|
};
|
|
10995
11025
|
}
|
|
10996
|
-
}, {
|
|
10997
|
-
key: "shouldUseReserveTransfer",
|
|
10998
|
-
value: function shouldUseReserveTransfer() {
|
|
10999
|
-
return true;
|
|
11000
|
-
}
|
|
11001
11026
|
}, {
|
|
11002
11027
|
key: "isSendingTempDisabled",
|
|
11003
11028
|
value: function isSendingTempDisabled(assetInfo) {
|
|
@@ -11228,7 +11253,7 @@ var BifrostPolkadot = /*#__PURE__*/function (_SubstrateChain) {
|
|
|
11228
11253
|
}
|
|
11229
11254
|
var isVToken = asset.symbol && asset.symbol.startsWith('v');
|
|
11230
11255
|
var isVSToken = asset.symbol && asset.symbol.startsWith('vs');
|
|
11231
|
-
if (asset.isNative || !asset.
|
|
11256
|
+
if (asset.isNative || !asset.assetId) {
|
|
11232
11257
|
return isVToken ? {
|
|
11233
11258
|
VToken: asset.symbol.substring(1)
|
|
11234
11259
|
} : {
|
|
@@ -11354,172 +11379,6 @@ var BridgeHubWestend = /*#__PURE__*/function (_BridgeHubPolkadot) {
|
|
|
11354
11379
|
return _createClass(BridgeHubWestend);
|
|
11355
11380
|
}(BridgeHubPolkadot);
|
|
11356
11381
|
|
|
11357
|
-
var resolveLocationFromDest = function resolveLocationFromDest(destination, asset) {
|
|
11358
|
-
if (_typeof(destination) === 'object') return destination;
|
|
11359
|
-
if (isRelayChain(destination)) return DOT_LOCATION;
|
|
11360
|
-
// If it is a native asset, search by symbol on AssetHub and use the location from there
|
|
11361
|
-
var assetHubAsset = getOtherAssets(destination).find(function (ahAsset) {
|
|
11362
|
-
var _ahAsset$symbol, _asset$symbol;
|
|
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());
|
|
11364
|
-
});
|
|
11365
|
-
if (!assetHubAsset) {
|
|
11366
|
-
throw new InvalidCurrencyError("Asset ".concat(asset.symbol, " not found"));
|
|
11367
|
-
}
|
|
11368
|
-
return assetHubAsset.location;
|
|
11369
|
-
};
|
|
11370
|
-
var buildLocation = function buildLocation(_ref) {
|
|
11371
|
-
var asset = _ref.asset,
|
|
11372
|
-
destination = _ref.destination;
|
|
11373
|
-
if (asset.isNative) {
|
|
11374
|
-
return resolveLocationFromDest(destination, asset);
|
|
11375
|
-
}
|
|
11376
|
-
return asset.location;
|
|
11377
|
-
};
|
|
11378
|
-
|
|
11379
|
-
var createDefaultCurrencySelection = function createDefaultCurrencySelection(input) {
|
|
11380
|
-
var asset = input.asset,
|
|
11381
|
-
version = input.version;
|
|
11382
|
-
var location = buildLocation(input);
|
|
11383
|
-
var multiAsset = createAsset(version, asset.amount, location);
|
|
11384
|
-
return addXcmVersionHeader(multiAsset, version);
|
|
11385
|
-
};
|
|
11386
|
-
var getModifiedCurrencySelection = function getModifiedCurrencySelection(input) {
|
|
11387
|
-
var version = input.version,
|
|
11388
|
-
asset = input.asset,
|
|
11389
|
-
overriddenAsset = input.overriddenAsset;
|
|
11390
|
-
if (overriddenAsset) {
|
|
11391
|
-
return addXcmVersionHeader(maybeOverrideAssets(version, asset.amount, [], overriddenAsset), version);
|
|
11392
|
-
}
|
|
11393
|
-
return createDefaultCurrencySelection(input);
|
|
11394
|
-
};
|
|
11395
|
-
|
|
11396
|
-
var getXTokensParams = function getXTokensParams(isMultiAssetTransfer, currencySelection, destLocation, amount, weightLimit, version, overriddenAsset) {
|
|
11397
|
-
var versionedDestLocation = addXcmVersionHeader(destLocation, version);
|
|
11398
|
-
if (!isMultiAssetTransfer) {
|
|
11399
|
-
return {
|
|
11400
|
-
currency_id: currencySelection,
|
|
11401
|
-
amount: BigInt(amount),
|
|
11402
|
-
dest: versionedDestLocation,
|
|
11403
|
-
dest_weight_limit: weightLimit
|
|
11404
|
-
};
|
|
11405
|
-
}
|
|
11406
|
-
var assetKey = overriddenAsset ? 'assets' : 'asset';
|
|
11407
|
-
var feeAssetIndex = overriddenAsset ? overriddenAsset.findIndex(function (asset) {
|
|
11408
|
-
return asset.isFeeAsset;
|
|
11409
|
-
}) : undefined;
|
|
11410
|
-
var feeIndexWithFallback = feeAssetIndex === -1 ? 0 : feeAssetIndex;
|
|
11411
|
-
return _objectSpread2(_objectSpread2(_defineProperty({}, assetKey, currencySelection), overriddenAsset && {
|
|
11412
|
-
fee_item: feeIndexWithFallback
|
|
11413
|
-
}), {}, {
|
|
11414
|
-
dest: versionedDestLocation,
|
|
11415
|
-
dest_weight_limit: weightLimit
|
|
11416
|
-
});
|
|
11417
|
-
};
|
|
11418
|
-
|
|
11419
|
-
var getXTokensMethod = function getXTokensMethod(useMultiAsset, overriddenAsset) {
|
|
11420
|
-
if (!useMultiAsset) return 'transfer';
|
|
11421
|
-
return overriddenAsset ? 'transfer_multiassets' : 'transfer_multiasset';
|
|
11422
|
-
};
|
|
11423
|
-
var buildXTokensCall = function buildXTokensCall(input, currencySelection, fees) {
|
|
11424
|
-
var api = input.api,
|
|
11425
|
-
origin = input.origin,
|
|
11426
|
-
destination = input.destination,
|
|
11427
|
-
overriddenAsset = input.overriddenAsset,
|
|
11428
|
-
useMultiAssetTransfer = input.useMultiAssetTransfer,
|
|
11429
|
-
recipient = input.recipient,
|
|
11430
|
-
asset = input.asset,
|
|
11431
|
-
pallet = input.pallet,
|
|
11432
|
-
version = input.version,
|
|
11433
|
-
paraIdTo = input.paraIdTo,
|
|
11434
|
-
methodOverride = input.method;
|
|
11435
|
-
var useMultiAsset = useMultiAssetTransfer || !!overriddenAsset;
|
|
11436
|
-
var modifiedCurrencySelection = useMultiAsset ? getModifiedCurrencySelection(input) : currencySelection;
|
|
11437
|
-
var method = getXTokensMethod(useMultiAsset, overriddenAsset);
|
|
11438
|
-
var destLocation = createBeneficiaryLocXTokens({
|
|
11439
|
-
api: api,
|
|
11440
|
-
origin: origin,
|
|
11441
|
-
destination: destination,
|
|
11442
|
-
recipient: recipient,
|
|
11443
|
-
version: version,
|
|
11444
|
-
paraId: paraIdTo
|
|
11445
|
-
});
|
|
11446
|
-
var params = getXTokensParams(useMultiAsset, modifiedCurrencySelection, destLocation, asset.amount, fees, version, overriddenAsset);
|
|
11447
|
-
return {
|
|
11448
|
-
module: pallet !== null && pallet !== void 0 ? pallet : 'XTokens',
|
|
11449
|
-
method: methodOverride !== null && methodOverride !== void 0 ? methodOverride : method,
|
|
11450
|
-
params: params
|
|
11451
|
-
};
|
|
11452
|
-
};
|
|
11453
|
-
|
|
11454
|
-
// Contains basic structure of xTokens call
|
|
11455
|
-
var transferXTokens = function transferXTokens(input, currencySelection) {
|
|
11456
|
-
var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_FEE;
|
|
11457
|
-
var api = input.api,
|
|
11458
|
-
destination = input.destination;
|
|
11459
|
-
assertToIsString(destination, ERR_LOCATION_DEST_NOT_SUPPORTED);
|
|
11460
|
-
var call = buildXTokensCall(input, currencySelection, fees);
|
|
11461
|
-
return api.deserializeExtrinsics(call);
|
|
11462
|
-
};
|
|
11463
|
-
|
|
11464
|
-
var Centrifuge = /*#__PURE__*/function (_SubstrateChain) {
|
|
11465
|
-
function Centrifuge() {
|
|
11466
|
-
_classCallCheck(this, Centrifuge);
|
|
11467
|
-
return _callSuper(this, Centrifuge, ['Centrifuge', 'centrifuge', 'Polkadot', Version.V4]);
|
|
11468
|
-
}
|
|
11469
|
-
_inherits(Centrifuge, _SubstrateChain);
|
|
11470
|
-
return _createClass(Centrifuge, [{
|
|
11471
|
-
key: "getCustomCurrencyId",
|
|
11472
|
-
value: function getCustomCurrencyId(api, asset) {
|
|
11473
|
-
if (asset.symbol === this.getNativeAssetSymbol(api)) return 'Native';
|
|
11474
|
-
assertHasId(asset);
|
|
11475
|
-
return {
|
|
11476
|
-
ForeignAsset: Number(asset.assetId)
|
|
11477
|
-
};
|
|
11478
|
-
}
|
|
11479
|
-
}, {
|
|
11480
|
-
key: "transferXTokens",
|
|
11481
|
-
value: function transferXTokens$1(input) {
|
|
11482
|
-
var asset = input.asset,
|
|
11483
|
-
api = input.api;
|
|
11484
|
-
var currencySelection = this.getCustomCurrencyId(api, asset);
|
|
11485
|
-
return transferXTokens(input, currencySelection);
|
|
11486
|
-
}
|
|
11487
|
-
}, {
|
|
11488
|
-
key: "transferLocalNonNativeAsset",
|
|
11489
|
-
value: function transferLocalNonNativeAsset(options) {
|
|
11490
|
-
var api = options.api,
|
|
11491
|
-
asset = options.assetInfo,
|
|
11492
|
-
recipient = options.recipient,
|
|
11493
|
-
isAmountAll = options.isAmountAll,
|
|
11494
|
-
keepAlive = options.keepAlive;
|
|
11495
|
-
var dest = {
|
|
11496
|
-
Id: recipient
|
|
11497
|
-
};
|
|
11498
|
-
var currencyId = this.getCustomCurrencyId(api, asset);
|
|
11499
|
-
if (isAmountAll) {
|
|
11500
|
-
return api.deserializeExtrinsics({
|
|
11501
|
-
module: 'Tokens',
|
|
11502
|
-
method: 'transfer_all',
|
|
11503
|
-
params: {
|
|
11504
|
-
dest: dest,
|
|
11505
|
-
currency_id: currencyId,
|
|
11506
|
-
keep_alive: keepAlive
|
|
11507
|
-
}
|
|
11508
|
-
});
|
|
11509
|
-
}
|
|
11510
|
-
return api.deserializeExtrinsics({
|
|
11511
|
-
module: 'Tokens',
|
|
11512
|
-
method: keepAlive ? 'transfer_keep_alive' : 'transfer',
|
|
11513
|
-
params: {
|
|
11514
|
-
dest: dest,
|
|
11515
|
-
currency_id: currencyId,
|
|
11516
|
-
amount: asset.amount
|
|
11517
|
-
}
|
|
11518
|
-
});
|
|
11519
|
-
}
|
|
11520
|
-
}]);
|
|
11521
|
-
}(SubstrateChain);
|
|
11522
|
-
|
|
11523
11382
|
var Collectives = /*#__PURE__*/function (_SubstrateChain) {
|
|
11524
11383
|
function Collectives() {
|
|
11525
11384
|
var chain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Collectives';
|
|
@@ -11760,11 +11619,6 @@ var EnergyWebX = /*#__PURE__*/function (_SubstrateChain) {
|
|
|
11760
11619
|
value: function isRelayToParaEnabled() {
|
|
11761
11620
|
return false;
|
|
11762
11621
|
}
|
|
11763
|
-
}, {
|
|
11764
|
-
key: "shouldUseReserveTransfer",
|
|
11765
|
-
value: function shouldUseReserveTransfer() {
|
|
11766
|
-
return true;
|
|
11767
|
-
}
|
|
11768
11622
|
}, {
|
|
11769
11623
|
key: "getMintConfig",
|
|
11770
11624
|
value: function getMintConfig() {
|
|
@@ -12285,6 +12139,112 @@ var Paseo = /*#__PURE__*/function (_Polkadot) {
|
|
|
12285
12139
|
return _createClass(Paseo);
|
|
12286
12140
|
}(Polkadot);
|
|
12287
12141
|
|
|
12142
|
+
var resolveLocationFromDest = function resolveLocationFromDest(destination, asset) {
|
|
12143
|
+
if (_typeof(destination) === 'object') return destination;
|
|
12144
|
+
if (isRelayChain(destination)) return DOT_LOCATION;
|
|
12145
|
+
// If it is a native asset, search by symbol on AssetHub and use the location from there
|
|
12146
|
+
var assetHubAsset = getOtherAssets(destination).find(function (ahAsset) {
|
|
12147
|
+
return ahAsset.symbol.toLowerCase() === asset.symbol.toLowerCase();
|
|
12148
|
+
});
|
|
12149
|
+
if (!assetHubAsset) {
|
|
12150
|
+
throw new InvalidCurrencyError("Asset ".concat(asset.symbol, " not found"));
|
|
12151
|
+
}
|
|
12152
|
+
return assetHubAsset.location;
|
|
12153
|
+
};
|
|
12154
|
+
var buildLocation = function buildLocation(_ref) {
|
|
12155
|
+
var asset = _ref.asset,
|
|
12156
|
+
destination = _ref.destination;
|
|
12157
|
+
if (asset.isNative) {
|
|
12158
|
+
return resolveLocationFromDest(destination, asset);
|
|
12159
|
+
}
|
|
12160
|
+
return asset.location;
|
|
12161
|
+
};
|
|
12162
|
+
|
|
12163
|
+
var createDefaultCurrencySelection = function createDefaultCurrencySelection(input) {
|
|
12164
|
+
var asset = input.asset,
|
|
12165
|
+
version = input.version;
|
|
12166
|
+
var location = buildLocation(input);
|
|
12167
|
+
var multiAsset = createAsset(version, asset.amount, location);
|
|
12168
|
+
return addXcmVersionHeader(multiAsset, version);
|
|
12169
|
+
};
|
|
12170
|
+
var getModifiedCurrencySelection = function getModifiedCurrencySelection(input) {
|
|
12171
|
+
var version = input.version,
|
|
12172
|
+
asset = input.asset,
|
|
12173
|
+
overriddenAsset = input.overriddenAsset;
|
|
12174
|
+
if (overriddenAsset) {
|
|
12175
|
+
return addXcmVersionHeader(maybeOverrideAssets(version, asset.amount, [], overriddenAsset), version);
|
|
12176
|
+
}
|
|
12177
|
+
return createDefaultCurrencySelection(input);
|
|
12178
|
+
};
|
|
12179
|
+
|
|
12180
|
+
var getXTokensParams = function getXTokensParams(isMultiAssetTransfer, currencySelection, destLocation, amount, weightLimit, version, overriddenAsset) {
|
|
12181
|
+
var versionedDestLocation = addXcmVersionHeader(destLocation, version);
|
|
12182
|
+
if (!isMultiAssetTransfer) {
|
|
12183
|
+
return {
|
|
12184
|
+
currency_id: currencySelection,
|
|
12185
|
+
amount: BigInt(amount),
|
|
12186
|
+
dest: versionedDestLocation,
|
|
12187
|
+
dest_weight_limit: weightLimit
|
|
12188
|
+
};
|
|
12189
|
+
}
|
|
12190
|
+
var assetKey = overriddenAsset ? 'assets' : 'asset';
|
|
12191
|
+
var feeAssetIndex = overriddenAsset ? overriddenAsset.findIndex(function (asset) {
|
|
12192
|
+
return asset.isFeeAsset;
|
|
12193
|
+
}) : undefined;
|
|
12194
|
+
var feeIndexWithFallback = feeAssetIndex === -1 ? 0 : feeAssetIndex;
|
|
12195
|
+
return _objectSpread2(_objectSpread2(_defineProperty({}, assetKey, currencySelection), overriddenAsset && {
|
|
12196
|
+
fee_item: feeIndexWithFallback
|
|
12197
|
+
}), {}, {
|
|
12198
|
+
dest: versionedDestLocation,
|
|
12199
|
+
dest_weight_limit: weightLimit
|
|
12200
|
+
});
|
|
12201
|
+
};
|
|
12202
|
+
|
|
12203
|
+
var getXTokensMethod = function getXTokensMethod(useMultiAsset, overriddenAsset) {
|
|
12204
|
+
if (!useMultiAsset) return 'transfer';
|
|
12205
|
+
return overriddenAsset ? 'transfer_multiassets' : 'transfer_multiasset';
|
|
12206
|
+
};
|
|
12207
|
+
var buildXTokensCall = function buildXTokensCall(input, currencySelection, fees) {
|
|
12208
|
+
var api = input.api,
|
|
12209
|
+
origin = input.origin,
|
|
12210
|
+
destination = input.destination,
|
|
12211
|
+
overriddenAsset = input.overriddenAsset,
|
|
12212
|
+
useMultiAssetTransfer = input.useMultiAssetTransfer,
|
|
12213
|
+
recipient = input.recipient,
|
|
12214
|
+
asset = input.asset,
|
|
12215
|
+
pallet = input.pallet,
|
|
12216
|
+
version = input.version,
|
|
12217
|
+
paraIdTo = input.paraIdTo,
|
|
12218
|
+
methodOverride = input.method;
|
|
12219
|
+
var useMultiAsset = useMultiAssetTransfer || !!overriddenAsset;
|
|
12220
|
+
var modifiedCurrencySelection = useMultiAsset ? getModifiedCurrencySelection(input) : currencySelection;
|
|
12221
|
+
var method = getXTokensMethod(useMultiAsset, overriddenAsset);
|
|
12222
|
+
var destLocation = createBeneficiaryLocXTokens({
|
|
12223
|
+
api: api,
|
|
12224
|
+
origin: origin,
|
|
12225
|
+
destination: destination,
|
|
12226
|
+
recipient: recipient,
|
|
12227
|
+
version: version,
|
|
12228
|
+
paraId: paraIdTo
|
|
12229
|
+
});
|
|
12230
|
+
var params = getXTokensParams(useMultiAsset, modifiedCurrencySelection, destLocation, asset.amount, fees, version, overriddenAsset);
|
|
12231
|
+
return {
|
|
12232
|
+
module: pallet !== null && pallet !== void 0 ? pallet : 'XTokens',
|
|
12233
|
+
method: methodOverride !== null && methodOverride !== void 0 ? methodOverride : method,
|
|
12234
|
+
params: params
|
|
12235
|
+
};
|
|
12236
|
+
};
|
|
12237
|
+
|
|
12238
|
+
// Contains basic structure of xTokens call
|
|
12239
|
+
var transferXTokens = function transferXTokens(input, currencySelection) {
|
|
12240
|
+
var fees = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_FEE;
|
|
12241
|
+
var api = input.api,
|
|
12242
|
+
destination = input.destination;
|
|
12243
|
+
assertToIsString(destination, ERR_LOCATION_DEST_NOT_SUPPORTED);
|
|
12244
|
+
var call = buildXTokensCall(input, currencySelection, fees);
|
|
12245
|
+
return api.deserializeExtrinsics(call);
|
|
12246
|
+
};
|
|
12247
|
+
|
|
12288
12248
|
var Peaq = /*#__PURE__*/function (_SubstrateChain) {
|
|
12289
12249
|
function Peaq() {
|
|
12290
12250
|
_classCallCheck(this, Peaq);
|
|
@@ -12708,7 +12668,6 @@ var chains = function chains() {
|
|
|
12708
12668
|
Unique: new Unique(),
|
|
12709
12669
|
BifrostPolkadot: new BifrostPolkadot(),
|
|
12710
12670
|
BridgeHubPolkadot: new BridgeHubPolkadot(),
|
|
12711
|
-
Centrifuge: new Centrifuge(),
|
|
12712
12671
|
Darwinia: new Darwinia(),
|
|
12713
12672
|
EnergyWebX: new EnergyWebX(),
|
|
12714
12673
|
Hydration: new Hydration(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paraspell/sdk-core",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.6.0",
|
|
4
4
|
"description": "SDK core for ParaSpell XCM/XCMP tool for developers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,23 +23,23 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@noble/hashes": "^2.4.0",
|
|
26
|
-
"@paraspell/assets": "14.
|
|
27
|
-
"@paraspell/pallets": "14.
|
|
28
|
-
"@paraspell/sdk-common": "14.
|
|
26
|
+
"@paraspell/assets": "14.6.0",
|
|
27
|
+
"@paraspell/pallets": "14.6.0",
|
|
28
|
+
"@paraspell/sdk-common": "14.6.0",
|
|
29
29
|
"@scure/base": "^2.4.0",
|
|
30
|
-
"viem": "^2.
|
|
30
|
+
"viem": "^2.58.8"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@babel/plugin-syntax-import-attributes": "^7.29.7",
|
|
34
|
-
"@babel/preset-env": "^7.29.
|
|
34
|
+
"@babel/preset-env": "^7.29.14",
|
|
35
35
|
"@codecov/rollup-plugin": "^2.0.1",
|
|
36
36
|
"@rollup/plugin-babel": "^7.1.0",
|
|
37
37
|
"@rollup/plugin-json": "^6.1.0",
|
|
38
38
|
"@rollup/plugin-typescript": "^12.3.1",
|
|
39
|
-
"@vitest/coverage-v8": "^5.
|
|
40
|
-
"axios": "^1.21.
|
|
41
|
-
"dotenv": "^18.0.
|
|
42
|
-
"rollup": "^4.
|
|
39
|
+
"@vitest/coverage-v8": "^5.1.2",
|
|
40
|
+
"axios": "^1.21.1",
|
|
41
|
+
"dotenv": "^18.0.10",
|
|
42
|
+
"rollup": "^4.68.8",
|
|
43
43
|
"rollup-plugin-dts": "^6.5.1",
|
|
44
44
|
"ts-morph": "^28.0.0",
|
|
45
45
|
"tsx": "^4.23.15"
|