@paraspell/swap 13.2.1 → 13.3.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/README.md +3 -3
- package/dist/index.d.ts +41 -134
- package/dist/index.mjs +290 -340
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<img alt="build" src="https://github.com/paraspell/xcm-tools/actions/workflows/ci.yml/badge.svg" />
|
|
15
15
|
</a>
|
|
16
16
|
</p>
|
|
17
|
-
<p>How to swap <a href = "https://paraspell.github.io/docs/sdk/
|
|
17
|
+
<p>How to swap <a href = "https://paraspell.github.io/docs/xcm-sdk/send-xcm.html#swap" \>[here]</p>
|
|
18
18
|
<p>XCM SDK starter template project <a href = "https://github.com/paraspell/xcm-sdk-template" \>[here]</p>
|
|
19
19
|
</div>
|
|
20
20
|
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
# Installation
|
|
25
25
|
|
|
26
|
-
Please reffer to [SDK documentation](https://paraspell.github.io/docs/sdk/getting-started.html#install-swap-extension)
|
|
26
|
+
Please reffer to [SDK documentation](https://paraspell.github.io/docs/xcm-sdk/getting-started.html#install-swap-extension)
|
|
27
27
|
|
|
28
28
|
## 💻 Testing
|
|
29
29
|
|
|
@@ -38,7 +38,7 @@ Please reffer to [SDK documentation](https://paraspell.github.io/docs/sdk/gettin
|
|
|
38
38
|
|
|
39
39
|
## Contribute to XCM Tools and earn rewards 💰
|
|
40
40
|
|
|
41
|
-
We run an open Bug Bounty Program that rewards contributors for reporting and fixing bugs in the project. More information on bug bounty can be found in the [official documentation](https://paraspell.github.io/docs/contribution.html).
|
|
41
|
+
We run an open Bug Bounty Program that rewards contributors for reporting and fixing bugs in the project. More information on bug bounty can be found in the [official documentation](https://paraspell.github.io/docs/contribution-guidelines.html).
|
|
42
42
|
|
|
43
43
|
## Get Support 🚑
|
|
44
44
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { TSubstrateChain, TExchangeInput, TChain, TCurrencyInput, TAmount, TStatusChangeCallback,
|
|
2
|
-
import { TPapiApi
|
|
1
|
+
import { TSubstrateChain, TExchangeInput, TChain, TCurrencyInput, TAmount, TStatusChangeCallback, TAssetInfo, PolkadotApi, TExchangeChain, TLocation, WithApi, TSwapBuilder, TGetXcmFeeBuilderOptions, TGetXcmFeeResult, TTransactionContext, TDryRunResult } from '@paraspell/sdk-core';
|
|
2
|
+
import { TPapiApi } from '@paraspell/sdk';
|
|
3
3
|
import { TPjsApi, Extrinsic } from '@paraspell/sdk-pjs';
|
|
4
|
+
import { ApiPromise } from '@polkadot/api';
|
|
4
5
|
|
|
5
|
-
type TSwapOptions<TApi> = {
|
|
6
|
-
|
|
6
|
+
type TSwapOptions<TApi, TRes, TSigner> = {
|
|
7
|
+
apiPjs: ApiPromise;
|
|
8
|
+
api: PolkadotApi<TApi, TRes, TSigner>;
|
|
7
9
|
assetFrom: TAssetInfo;
|
|
8
10
|
assetTo: TAssetInfo;
|
|
9
11
|
amount: bigint;
|
|
@@ -13,21 +15,22 @@ type TSwapOptions<TApi> = {
|
|
|
13
15
|
origin?: TOriginInfo<TApi>;
|
|
14
16
|
isForFeeEstimation?: boolean;
|
|
15
17
|
};
|
|
16
|
-
type TGetAmountOutOptions<TApi> = {
|
|
17
|
-
|
|
18
|
+
type TGetAmountOutOptions<TApi, TRes, TSigner> = {
|
|
19
|
+
apiPjs: ApiPromise;
|
|
20
|
+
api: PolkadotApi<TApi, TRes, TSigner>;
|
|
18
21
|
origin?: TOriginInfo<TApi>;
|
|
19
22
|
assetFrom: TAssetInfo;
|
|
20
23
|
assetTo: TAssetInfo;
|
|
21
24
|
amount: bigint;
|
|
22
25
|
slippagePct?: string;
|
|
23
26
|
};
|
|
24
|
-
type TExtrinsic = Extrinsic |
|
|
25
|
-
type TSingleSwapResult = {
|
|
26
|
-
tx: TExtrinsic
|
|
27
|
+
type TExtrinsic<TRes> = Extrinsic | TRes;
|
|
28
|
+
type TSingleSwapResult<TRes> = {
|
|
29
|
+
tx: TExtrinsic<TRes>;
|
|
27
30
|
amountOut: bigint;
|
|
28
31
|
};
|
|
29
|
-
type TMultiSwapResult = {
|
|
30
|
-
txs: TExtrinsic[];
|
|
32
|
+
type TMultiSwapResult<TRes> = {
|
|
33
|
+
txs: TExtrinsic<TRes>[];
|
|
31
34
|
amountOut: bigint;
|
|
32
35
|
};
|
|
33
36
|
/**
|
|
@@ -225,167 +228,71 @@ declare const getSupportedAssetsTo: (exchangeInput: TExchangeInput, to: TChain |
|
|
|
225
228
|
*/
|
|
226
229
|
declare const getSupportedFeeAssets: (from: TChain | undefined, exchangeInput: TExchangeInput) => TAssetInfo[];
|
|
227
230
|
|
|
228
|
-
declare class
|
|
231
|
+
declare class SwapBuilderCore<TApi, TRes, TSigner, T extends Partial<TTransferBaseOptions<TApi, TRes, TSigner>> = object> {
|
|
229
232
|
readonly _api: PolkadotApi<TApi, TRes, TSigner>;
|
|
230
233
|
readonly _options: T;
|
|
231
|
-
readonly _builderOptions?: TTransferBaseOptions<TApi, TRes, TSigner>;
|
|
232
234
|
constructor(api: PolkadotApi<TApi, TRes, TSigner>, options?: T);
|
|
233
|
-
|
|
234
|
-
* Specifies the origin chain of the transfer.
|
|
235
|
-
*
|
|
236
|
-
* @param chain - The origin chain.
|
|
237
|
-
* @returns The current builder instance.
|
|
238
|
-
*/
|
|
239
|
-
from(chain: TSubstrateChain | undefined): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
235
|
+
from(chain: TSubstrateChain | undefined): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
240
236
|
from: TSubstrateChain | undefined;
|
|
241
237
|
}>;
|
|
242
|
-
|
|
243
|
-
* Specifies the exchange chain to use.
|
|
244
|
-
*
|
|
245
|
-
* @param chain - The exchange chain, or `undefined` to auto-select.
|
|
246
|
-
* @returns The current builder instance.
|
|
247
|
-
*/
|
|
248
|
-
exchange(chain: TExchangeInput): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
238
|
+
exchange(chain: TExchangeInput): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
249
239
|
exchange: TExchangeInput;
|
|
250
240
|
}>;
|
|
251
|
-
|
|
252
|
-
* Specifies the destination chain of the transfer.
|
|
253
|
-
*
|
|
254
|
-
* @param chain - The destination chain.
|
|
255
|
-
* @returns The current builder instance.
|
|
256
|
-
*/
|
|
257
|
-
to(chain: TChain | undefined): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
241
|
+
to(chain: TChain | undefined): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
258
242
|
to: TChain | undefined;
|
|
259
243
|
}>;
|
|
260
|
-
|
|
261
|
-
* Specifies the currency to send from the origin chain.
|
|
262
|
-
*
|
|
263
|
-
* @param currencyFrom - The currency to send.
|
|
264
|
-
* @returns The current builder instance.
|
|
265
|
-
*/
|
|
266
|
-
currencyFrom(currency: TCurrencyInput): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
244
|
+
currencyFrom(currency: TCurrencyInput): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
267
245
|
currencyFrom: TCurrencyInput;
|
|
268
246
|
}>;
|
|
269
|
-
|
|
270
|
-
* Specifies the currency that the origin currency will be exchanged to and received on the destination chain.
|
|
271
|
-
*
|
|
272
|
-
* @param currencyTo - The currency to receive.
|
|
273
|
-
* @returns The current builder instance.
|
|
274
|
-
*/
|
|
275
|
-
currencyTo(currency: TCurrencyInput): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
247
|
+
currencyTo(currency: TCurrencyInput): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
276
248
|
currencyTo: TCurrencyInput;
|
|
277
249
|
}>;
|
|
278
|
-
|
|
279
|
-
* Specifies the asset used to pay XCM fees.
|
|
280
|
-
*
|
|
281
|
-
* @param currency - The fee asset currency, or `undefined` to use the default.
|
|
282
|
-
* @returns The current builder instance.
|
|
283
|
-
*/
|
|
284
|
-
feeAsset(currency: TCurrencyInput | undefined): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
250
|
+
feeAsset(currency: TCurrencyInput | undefined): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
285
251
|
feeAsset: TCurrencyInput | undefined;
|
|
286
252
|
}>;
|
|
287
|
-
|
|
288
|
-
* Specifies the amount to transfer.
|
|
289
|
-
*
|
|
290
|
-
* @param amount - The amount to transfer.
|
|
291
|
-
* @returns The current builder instance.
|
|
292
|
-
*/
|
|
293
|
-
amount(amount: TAmount): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
253
|
+
amount(amount: TAmount): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
294
254
|
amount: TAmount;
|
|
295
255
|
}>;
|
|
296
|
-
|
|
297
|
-
* Specifies the recipient address on the destination chain.
|
|
298
|
-
*
|
|
299
|
-
* @param recipient - The recipient address.
|
|
300
|
-
* @returns The current builder instance.
|
|
301
|
-
*/
|
|
302
|
-
recipient(address: string | undefined): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
256
|
+
recipient(address: string | undefined): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
303
257
|
recipient: string | undefined;
|
|
304
258
|
}>;
|
|
305
|
-
|
|
306
|
-
* Specifies the sender address initiating the transfer.
|
|
307
|
-
*
|
|
308
|
-
* @param senderAddress - The sender address.
|
|
309
|
-
* @returns The current builder instance.
|
|
310
|
-
*/
|
|
311
|
-
sender(address: string): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
259
|
+
sender(address: string): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
312
260
|
sender: string;
|
|
313
261
|
}>;
|
|
314
|
-
|
|
315
|
-
* Specifies the signer for the transaction.
|
|
316
|
-
*
|
|
317
|
-
* @param signer - The signer instance.
|
|
318
|
-
* @returns The current builder instance.
|
|
319
|
-
*/
|
|
320
|
-
signer(signer: TSigner): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
262
|
+
signer(signer: TSigner): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
321
263
|
signer: TSigner;
|
|
322
264
|
}>;
|
|
323
|
-
|
|
324
|
-
* Specifies the EVM sender address, required if `evmSigner` is provided. Used when dealing with EVM chains.
|
|
325
|
-
*
|
|
326
|
-
* @param evmSenderAddress - The EVM sender address.
|
|
327
|
-
* @returns The current builder instance.
|
|
328
|
-
*/
|
|
329
|
-
evmSenderAddress(address: string | undefined): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
265
|
+
evmSenderAddress(address: string | undefined): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
330
266
|
evmSenderAddress: string | undefined;
|
|
331
267
|
}>;
|
|
332
|
-
|
|
333
|
-
* Specifies the EVM signer, required if `evmSenderAddress` is provided.
|
|
334
|
-
*
|
|
335
|
-
* @param evmSigner - The EVM signer.
|
|
336
|
-
* @returns The current builder instance.
|
|
337
|
-
*/
|
|
338
|
-
evmSigner(signer: TSigner | undefined): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
268
|
+
evmSigner(signer: TSigner | undefined): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
339
269
|
evmSigner: TSigner | undefined;
|
|
340
270
|
}>;
|
|
341
|
-
|
|
342
|
-
* Specifies the maximum slippage percentage for swaps.
|
|
343
|
-
*
|
|
344
|
-
* @param slippagePct - The slippage percentage.
|
|
345
|
-
* @returns The current builder instance.
|
|
346
|
-
*/
|
|
347
|
-
slippagePct(pct: string): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
271
|
+
slippagePct(pct: string): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
348
272
|
slippagePct: string;
|
|
349
273
|
}>;
|
|
350
|
-
|
|
351
|
-
* Sets a callback to receive status updates during the transfer.
|
|
352
|
-
*
|
|
353
|
-
* @param callback - The status change callback.
|
|
354
|
-
* @returns The current builder instance.
|
|
355
|
-
*/
|
|
356
|
-
onStatusChange(callback: TStatusChangeCallback<TApi, TRes>): RouterBuilderCore<TApi, TRes, TSigner, T & {
|
|
274
|
+
onStatusChange(callback: TStatusChangeCallback<TApi, TRes>): SwapBuilderCore<TApi, TRes, TSigner, T & {
|
|
357
275
|
onStatusChange: TStatusChangeCallback<TApi, TRes>;
|
|
358
276
|
}>;
|
|
359
|
-
|
|
360
|
-
* Returns the XCM fee for origin, exchange, and destination.
|
|
361
|
-
*
|
|
362
|
-
* @returns The XCM fee result.
|
|
363
|
-
*/
|
|
364
|
-
getXcmFees<TDisableFallback extends boolean = false>(this: RouterBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>>, options?: TGetXcmFeeBuilderOptions & {
|
|
277
|
+
getXcmFees<TDisableFallback extends boolean = false>(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>>, options?: TGetXcmFeeBuilderOptions & {
|
|
365
278
|
disableFallback: TDisableFallback;
|
|
366
279
|
}): Promise<TGetXcmFeeResult<TDisableFallback>>;
|
|
367
|
-
getTransferableAmount(this:
|
|
368
|
-
getMinTransferableAmount(this:
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Builds the transactions for the transfer with the provided parameters.
|
|
378
|
-
*/
|
|
379
|
-
build(this: RouterBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>>): Promise<TRouterPlan<TApi, TRes>>;
|
|
380
|
-
dryRun(this: RouterBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>>): Promise<TDryRunResult>;
|
|
381
|
-
getBestAmountOut(this: RouterBuilderCore<TApi, TRes, TSigner, TGetBestAmountOutBaseOptions<TApi, TRes, TSigner>>): Promise<TGetBestAmountOutResult>;
|
|
280
|
+
getTransferableAmount(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>>): Promise<bigint>;
|
|
281
|
+
getMinTransferableAmount(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>>): Promise<bigint>;
|
|
282
|
+
signAndSubmit(this: SwapBuilderCore<TApi, TRes, TSigner, TTransferBaseOptions<TApi, TRes, TSigner>>): Promise<string[]>;
|
|
283
|
+
build(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>>): Promise<TTransactionContext<TApi, TRes>[]>;
|
|
284
|
+
dryRun(this: SwapBuilderCore<TApi, TRes, TSigner, TBuildTransactionsBaseOptions<TApi, TRes, TSigner>>): Promise<TDryRunResult>;
|
|
285
|
+
getBestAmountOut(this: SwapBuilderCore<TApi, TRes, TSigner, TGetBestAmountOutBaseOptions<TApi, TRes, TSigner>>): Promise<{
|
|
286
|
+
exchange: TExchangeChain;
|
|
287
|
+
amountOut: bigint;
|
|
288
|
+
}>;
|
|
382
289
|
}
|
|
383
|
-
declare const
|
|
290
|
+
declare const SwapBuilder: <TApi, TRes, TSigner>(api: PolkadotApi<TApi, TRes, TSigner>) => TSwapBuilder<TApi, TRes, TSigner>;
|
|
384
291
|
|
|
385
292
|
declare const FEE_BUFFER_PCT = 10;
|
|
386
293
|
declare const DEST_FEE_BUFFER_PCT = -1;
|
|
387
294
|
declare const FALLBACK_FEE_CALC_ADDRESS = "5EtHZF4E8QagNCz6naobCkCAUT52SbcEqaXiDUu2PjUHxZid";
|
|
388
295
|
declare const FALLBACK_FEE_CALC_EVM_ADDRESS = "0x1501C1413e4178c38567Ada8945A80351F7B8496";
|
|
389
296
|
|
|
390
|
-
export { DEST_FEE_BUFFER_PCT, FALLBACK_FEE_CALC_ADDRESS, FALLBACK_FEE_CALC_EVM_ADDRESS, FEE_BUFFER_PCT,
|
|
297
|
+
export { DEST_FEE_BUFFER_PCT, FALLBACK_FEE_CALC_ADDRESS, FALLBACK_FEE_CALC_EVM_ADDRESS, FEE_BUFFER_PCT, SwapBuilder, SwapBuilderCore, getExchangeAssets, getExchangeConfig, getExchangePairs, getSupportedAssetsFrom, getSupportedAssetsTo, getSupportedFeeAssets };
|
|
391
298
|
export type { TAdditionalTransferOptions, TAssetsRecord, TBuildFromExchangeTxOptions, TBuildToExchangeTxOptions, TBuildTransactionsBaseOptions, TBuildTransactionsOptions, TCommonRouterOptions, TDestinationInfo, TDexConfig, TDexConfigBase, TDexConfigStored, TExchangeInfo, TExecuteRouterPlanOptions, TExtrinsic, TGetAmountOutOptions, TGetBestAmountOutBaseOptions, TGetBestAmountOutOptions, TGetBestAmountOutResult, TMultiSwapResult, TOriginInfo, TPairs, TPreparedExtrinsics, TRouterPlan, TSingleSwapResult, TSwapAndTransferTransaction, TSwapOptions, TSwapTransaction, TTransaction, TTransferBaseOptions, TTransferOptions, TTransformedOptions };
|