@scallop-io/scallop-swap-sdk 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
1
  ### Scallop Swap Meta Aggregator SDK
2
2
 
3
3
  A unified SDK that aggregates existing swap aggregators on Sui, including Aftermath, Cetus, 7K, and FlowX and provides a generic `SwapSdkBase` class for seamless integration and extension with future swap aggregators.
4
+
5
+ #### Adding a Custom SDK Integration
6
+
7
+ Extend `SwapSdkBase` with your own SDK-specific generic types:
8
+
9
+ ```typescript
10
+ import { SwapSdkBase, SwapSdkConstructorParams } from '@scallop-io/scallop-swap-sdk';
11
+
12
+ class MyDexSwap extends SwapSdkBase<MyPoolType, MyRawRoute, MyFetchSettings, MyClient> {
13
+ constructor(params: SwapSdkConstructorParams<MyFetchSettings>) {
14
+ super('mydex', params);
15
+ this.client = new MyClient(/* ... */);
16
+ }
17
+
18
+ // Implement abstract methods: fetchRoute, buildSwapTransaction, setFetchRouteSettings, calcSlippage
19
+ }
20
+ ```
21
+
22
+ To get type-safe access via `aggregator.getAggregator('mydex')`, extend the `SdkRegistry` interface using declaration merging:
23
+
24
+ ```typescript
25
+ declare module '@scallop-io/scallop-swap-sdk' {
26
+ interface SdkRegistry {
27
+ mydex: MyDexSwap;
28
+ }
29
+ }
30
+
31
+ // Now fully typed:
32
+ const mydex = aggregator.getAggregator('mydex'); // MyDexSwap | undefined
33
+ mydex?.client; // MyClient | undefined
34
+ ```
package/dist/index.d.mts CHANGED
@@ -3,13 +3,17 @@ import { SuiClient, CoinMetadata, SuiTransactionBlockResponse, DryRunTransaction
3
3
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
4
4
  import { EventEmitter } from 'events';
5
5
  import * as _scallop_io_sui_kit from '@scallop-io/sui-kit';
6
- import { SuiKitParams, AccountManagerParams, SuiKit, Transaction as Transaction$1, TransactionObjectArgument as TransactionObjectArgument$1 } from '@scallop-io/sui-kit';
6
+ import { SuiKitParams, AccountManagerParams, Transaction as Transaction$1, TransactionObjectArgument as TransactionObjectArgument$1, SuiKit } from '@scallop-io/sui-kit';
7
7
  import * as _mysten_sui_dist_cjs_transactions from '@mysten/sui/dist/cjs/transactions';
8
8
  import { RouterDataV3, FindRouterParams, AggregatorClient, AggregatorClientParams } from '@cetusprotocol/aggregator-sdk';
9
+ export { AggregatorClient, RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
9
10
  import * as aftermath_ts_sdk from 'aftermath-ts-sdk';
10
11
  import { RouterProtocolName, RouterCompleteTradeRoute, ApiRouterPartialCompleteTradeRouteBody, Aftermath, AftermathApi, ConfigAddresses } from 'aftermath-ts-sdk';
12
+ export { Aftermath, RouterCompleteTradeRoute } from 'aftermath-ts-sdk';
11
13
  import { SourceDex, QuoteResponse, Commission } from '@7kprotocol/sdk-ts';
14
+ export { QuoteResponse } from '@7kprotocol/sdk-ts';
12
15
  import { Protocol, GetRoutesResult, Coin as Coin$1, SingleQuoteQueryParams, AggregatorQuoter, Commission as Commission$1 } from '@flowx-finance/sdk';
16
+ export { AggregatorQuoter, GetRoutesResult } from '@flowx-finance/sdk';
13
17
 
14
18
  type SecretKeyOrMnemonicsOrWalletAddress = {
15
19
  mnemonics: string;
@@ -216,9 +220,6 @@ declare abstract class SwapSdkBase<PoolType = string, RawRouteResultType = any,
216
220
  protected validateWalletAddress(): asserts this is typeof SwapSdkBase & {
217
221
  walletAddress: string;
218
222
  };
219
- protected validateRawRouteResult(): asserts this is typeof SwapSdkBase & {
220
- rawRouteResult: RawRouteResultType;
221
- };
222
223
  protected validateClient(): asserts this is typeof SwapSdkBase & {
223
224
  client: SdkClient;
224
225
  };
@@ -247,94 +248,8 @@ declare abstract class SwapSdkBase<PoolType = string, RawRouteResultType = any,
247
248
  }>;
248
249
  }
249
250
 
250
- declare class CoinMetadataRegistry {
251
- client: SuiClient;
252
- private cache;
253
- constructor(client: SuiClient, initialData?: (CoinMetadata & {
254
- coinType: string;
255
- })[]);
256
- setClient(client: SuiClient): void;
257
- getCoinMetadata(coinType: string): Promise<CoinMetadata>;
258
- }
259
-
260
- type TxExt = {
261
- initTx: Transaction;
262
- coinIn: TransactionObjectArgument;
263
- };
264
- type BuildOptionsBase = {
265
- slippage?: number;
266
- txExtensionParams?: TxExt;
267
- };
268
- declare class Aggregator {
269
- #private;
270
- readonly coinMetadata: CoinMetadataRegistry;
271
- readonly suiKit: SuiKit | undefined;
272
- readonly events: TypedEventEmitter<AggregatorEvents<string>>;
273
- protected _slippage: number;
274
- private signerMode;
275
- private aggregatorMap;
276
- private activeAggregator;
277
- private _fetchingStatus;
278
- private poolStatusForwarders;
279
- walletAddress: string;
280
- client: SuiClient;
281
- constructor(params: AggregatorConstructorParams);
282
- private forwardPoolStatusChangeEvent;
283
- addAggregator(aggregator: SwapSdkBase[]): void;
284
- getActiveAggregators(): string[];
285
- getAggregator(name: string): SwapSdkBase<string, any, any, any> | undefined;
286
- toggleAggregator(name: string, enabled: boolean): void;
287
- removeAggregator(name: string): void;
288
- get aggregators(): SwapSdkBase<string, any, any, any>[];
289
- /**
290
- * Per-aggregator fetching status. True while that aggregator's fetchRoute is in-flight.
291
- */
292
- get fetchingStatus(): Record<string, boolean>;
293
- /**
294
- * Get slippage (0.01 = 1%)
295
- */
296
- get slippage(): number;
297
- /**
298
- * Set slippage (0.01 = 1%)
299
- * @param slippageInDecimal
300
- */
301
- setSlippage(slippageInDecimal: number): void;
302
- /**
303
- * Set fetch timeout in milliseconds for all aggregators
304
- * @param timeoutInMs
305
- */
306
- setFetchTimeoutInMs(timeoutInMs: number): void;
307
- setSuiClient(client: SuiClient): void;
308
- setWalletAddress(address: string): void;
309
- getCoinMetadata(coinType: string): Promise<_mysten_sui_dist_cjs_client.CoinMetadata>;
310
- /**
311
- * Fetch swap routes from all aggregators, and sort them by best output amount
312
- * @param params FetchRouteParams
313
- * @param options FetchRoutesOptions
314
- */
315
- fetchRoutes(params: FetchRouteParams, options?: FetchRoutesOptions): Promise<{
316
- routes: FetchRouteResult<any>[];
317
- errors: {
318
- name: string;
319
- reason: unknown;
320
- }[];
321
- }>;
322
- /**
323
- * Build transaction with the selected aggregator's route
324
- * @param options Transaction building options
325
- */
326
- buildRouteTransaction(route: FetchRouteResult<any>, options?: BuildOptionsBase & {
327
- mergeResult?: true;
328
- }): Promise<SwapBuildResult<true>>;
329
- buildRouteTransaction(route: FetchRouteResult<any>, options: BuildOptionsBase & {
330
- mergeResult: false;
331
- }): Promise<SwapBuildResult<false>>;
332
- executeSwapTransaction(tx: Transaction): Promise<SuiTransactionBlockResponse>;
333
- executeSwapTransaction(tx: Transaction, dryRun: true): Promise<DryRunTransactionBlockResponse>;
334
- executeSwapTransaction(tx: Transaction, dryRun: false): Promise<SuiTransactionBlockResponse>;
335
- }
336
-
337
251
  type FetchRouteSettings$3 = Omit<FindRouterParams, 'from' | 'target' | 'amount' | 'byAmountIn' | 'providers'>;
252
+
338
253
  declare class CetusSwap extends SwapSdkBase<string, RouterDataV3, FetchRouteSettings$3, AggregatorClient> {
339
254
  constructor(params: SwapSdkConstructorParams<FetchRouteSettings$3> & Omit<AggregatorClientParams, 'client'>);
340
255
  private createRoute;
@@ -342,15 +257,19 @@ declare class CetusSwap extends SwapSdkBase<string, RouterDataV3, FetchRouteSett
342
257
  * Parse the raw route data from Cetus to the standardized FetchRouteResult format.
343
258
  * @returns FormattedRouteResult
344
259
  */
345
- private parseRawToFormattedResult;
260
+ parseRawToFormattedResult({ routerData, coinInType, coinOutType, }: {
261
+ routerData: RouterDataV3;
262
+ coinInType: string;
263
+ coinOutType: string;
264
+ }): Omit<FormattedRouteResult, 'name'>;
346
265
  setFetchRouteSettings(settings: FindRouterParams): void;
347
266
  calcSlippage(slippageInDecimal: number): number;
348
267
  fetchRoute(params: FetchRouteParams, abortSignal?: AbortSignal): Promise<{
349
268
  formattedResult: {
350
269
  name: string;
351
- coinOut: Coin;
352
270
  routes: SwapRoute[];
353
271
  coinIn: Coin;
272
+ coinOut: Coin;
354
273
  };
355
274
  rawRouteResult: RouterDataV3;
356
275
  }>;
@@ -361,6 +280,7 @@ declare class CetusSwap extends SwapSdkBase<string, RouterDataV3, FetchRouteSett
361
280
  }
362
281
 
363
282
  type FetchRouteSettings$2 = Omit<ApiRouterPartialCompleteTradeRouteBody, 'coinInType' | 'coinOutType' | 'coinInAmount' | 'protocolWhitelist' | 'protocolBlacklist'>;
283
+
364
284
  declare class AftermathSwap extends SwapSdkBase<RouterProtocolName, RouterCompleteTradeRoute, FetchRouteSettings$2, Aftermath> {
365
285
  readonly afApi: AftermathApi;
366
286
  constructor(params: SwapSdkConstructorParams<FetchRouteSettings$2> & {
@@ -397,6 +317,7 @@ interface Params {
397
317
  isSponsored?: boolean;
398
318
  }
399
319
  type FetchRouteSettings$1 = Omit<Params, 'tokenIn' | 'tokenOut' | 'amountIn' | 'sources'>;
320
+
400
321
  declare class _7kSwap extends SwapSdkBase<SourceDex, QuoteResponse, FetchRouteSettings$1> {
401
322
  commission: Commission;
402
323
  constructor(params: SwapSdkConstructorParams<FetchRouteSettings$1> & {
@@ -415,6 +336,7 @@ declare class _7kSwap extends SwapSdkBase<SourceDex, QuoteResponse, FetchRouteSe
415
336
  }
416
337
 
417
338
  type FetchRouteSettings = Omit<SingleQuoteQueryParams, 'amountIn' | 'tokenIn' | 'tokenOut' | 'excludeSources' | 'includeSources'>;
339
+
418
340
  declare class FlowXSwap extends SwapSdkBase<Protocol, GetRoutesResult<Coin$1, Coin$1>, FetchRouteSettings, AggregatorQuoter> {
419
341
  client: AggregatorQuoter;
420
342
  commission?: Commission$1;
@@ -436,9 +358,105 @@ declare class FlowXSwap extends SwapSdkBase<Protocol, GetRoutesResult<Coin$1, Co
436
358
  }>;
437
359
  }
438
360
 
361
+ interface SdkRegistry {
362
+ cetus: CetusSwap;
363
+ aftermath: AftermathSwap;
364
+ '7k': _7kSwap;
365
+ flowx: FlowXSwap;
366
+ }
367
+ type SdkName = keyof SdkRegistry;
368
+
369
+ declare class CoinMetadataRegistry {
370
+ client: SuiClient;
371
+ private cache;
372
+ constructor(client: SuiClient, initialData?: (CoinMetadata & {
373
+ coinType: string;
374
+ })[]);
375
+ setClient(client: SuiClient): void;
376
+ getCoinMetadata(coinType: string): Promise<CoinMetadata>;
377
+ }
378
+
379
+ type TxExt = {
380
+ initTx: Transaction;
381
+ coinIn: TransactionObjectArgument;
382
+ };
383
+ type BuildOptionsBase = {
384
+ slippage?: number;
385
+ txExtensionParams?: TxExt;
386
+ };
387
+ declare class Aggregator {
388
+ #private;
389
+ readonly coinMetadata: CoinMetadataRegistry;
390
+ readonly suiKit: SuiKit | undefined;
391
+ readonly events: TypedEventEmitter<AggregatorEvents<string>>;
392
+ protected _slippage: number;
393
+ private signerMode;
394
+ private aggregatorMap;
395
+ private activeAggregator;
396
+ private _fetchingStatus;
397
+ private poolStatusForwarders;
398
+ walletAddress: string;
399
+ client: SuiClient;
400
+ constructor(params: AggregatorConstructorParams);
401
+ private forwardPoolStatusChangeEvent;
402
+ addAggregator(aggregator: SwapSdkBase[]): void;
403
+ getActiveAggregators(): string[];
404
+ getAggregator<T extends SdkName>(name: T): SdkRegistry[T] | undefined;
405
+ getAggregator(name: string): SwapSdkBase | undefined;
406
+ toggleAggregator(name: string, enabled: boolean): void;
407
+ removeAggregator(name: string): void;
408
+ get aggregators(): SwapSdkBase<string, any, any, any>[];
409
+ /**
410
+ * Per-aggregator fetching status. True while that aggregator's fetchRoute is in-flight.
411
+ */
412
+ get fetchingStatus(): Record<string, boolean>;
413
+ /**
414
+ * Get slippage (0.01 = 1%)
415
+ */
416
+ get slippage(): number;
417
+ /**
418
+ * Set slippage (0.01 = 1%)
419
+ * @param slippageInDecimal
420
+ */
421
+ setSlippage(slippageInDecimal: number): void;
422
+ /**
423
+ * Set fetch timeout in milliseconds for all aggregators
424
+ * @param timeoutInMs
425
+ */
426
+ setFetchTimeoutInMs(timeoutInMs: number): void;
427
+ setSuiClient(client: SuiClient): void;
428
+ setWalletAddress(address: string): void;
429
+ getCoinMetadata(coinType: string): Promise<_mysten_sui_dist_cjs_client.CoinMetadata>;
430
+ /**
431
+ * Fetch swap routes from all aggregators, and sort them by best output amount
432
+ * @param params FetchRouteParams
433
+ * @param options FetchRoutesOptions
434
+ */
435
+ fetchRoutes(params: FetchRouteParams, options?: FetchRoutesOptions): Promise<{
436
+ routes: FetchRouteResult<any>[];
437
+ errors: {
438
+ name: string;
439
+ reason: unknown;
440
+ }[];
441
+ }>;
442
+ /**
443
+ * Build transaction with the selected aggregator's route
444
+ * @param options Transaction building options
445
+ */
446
+ buildRouteTransaction(route: FetchRouteResult<any>, options?: BuildOptionsBase & {
447
+ mergeResult?: true;
448
+ }): Promise<SwapBuildResult<true>>;
449
+ buildRouteTransaction(route: FetchRouteResult<any>, options: BuildOptionsBase & {
450
+ mergeResult: false;
451
+ }): Promise<SwapBuildResult<false>>;
452
+ executeSwapTransaction(tx: Transaction): Promise<SuiTransactionBlockResponse>;
453
+ executeSwapTransaction(tx: Transaction, dryRun: true): Promise<DryRunTransactionBlockResponse>;
454
+ executeSwapTransaction(tx: Transaction, dryRun: false): Promise<SuiTransactionBlockResponse>;
455
+ }
456
+
439
457
  declare const isSuiType: (coinType: string) => boolean;
440
458
  declare const selectCoins: (client: SuiClient, coinType: string, amount: string, owner: string) => Promise<CoinStruct[]>;
441
459
  declare const mergeWithExistingOrTransfer: (tx: Transaction, coin: TransactionObjectArgument, client: SuiClient, coinType: string, sender: string) => Promise<void>;
442
460
  declare const transformProperCase: (provider: string) => string;
443
461
 
444
- export { AftermathSwap, Aggregator, type AggregatorConstructorParams, type AggregatorEvents, type AggregatorStatusEvent, CetusSwap, type Coin, CoinMetadataRegistry, type FetchRouteParams, type FetchRouteResult, type FetchRoutesOptions, FlowXSwap, type FormattedRouteResult, type SecretKeyOrMnemonicsOrWalletAddress, type SuiClientOrFullnodeUrl, type SwapBuildResult, type SwapCoinInfo, type SwapParams, type SwapPath, type SwapRoute, SwapSdkBase, type SwapSdkBaseInterface, type SwapSdkConstructorParams, type SwapSdkEvents, type SwapSdkPoolStatusEvent, TypedEventEmitter, _7kSwap, isSuiType, mergeWithExistingOrTransfer, selectCoins, transformProperCase };
462
+ export { type FetchRouteSettings$2 as AftermathFetchRouteSettings, AftermathSwap, Aggregator, type AggregatorConstructorParams, type AggregatorEvents, type AggregatorStatusEvent, type FetchRouteSettings$3 as CetusFetchRouteSettings, CetusSwap, type Coin, CoinMetadataRegistry, type FetchRouteParams, type FetchRouteResult, type FetchRoutesOptions, type FetchRouteSettings as FlowXFetchRouteSettings, FlowXSwap, type FormattedRouteResult, type SdkName, type SdkRegistry, type SecretKeyOrMnemonicsOrWalletAddress, type SuiClientOrFullnodeUrl, type SwapBuildResult, type SwapCoinInfo, type SwapParams, type SwapPath, type SwapRoute, SwapSdkBase, type SwapSdkBaseInterface, type SwapSdkConstructorParams, type SwapSdkEvents, type SwapSdkPoolStatusEvent, TypedEventEmitter, type FetchRouteSettings$1 as _7kFetchRouteSettings, _7kSwap, isSuiType, mergeWithExistingOrTransfer, selectCoins, transformProperCase };
package/dist/index.d.ts CHANGED
@@ -3,13 +3,17 @@ import { SuiClient, CoinMetadata, SuiTransactionBlockResponse, DryRunTransaction
3
3
  import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
4
4
  import { EventEmitter } from 'events';
5
5
  import * as _scallop_io_sui_kit from '@scallop-io/sui-kit';
6
- import { SuiKitParams, AccountManagerParams, SuiKit, Transaction as Transaction$1, TransactionObjectArgument as TransactionObjectArgument$1 } from '@scallop-io/sui-kit';
6
+ import { SuiKitParams, AccountManagerParams, Transaction as Transaction$1, TransactionObjectArgument as TransactionObjectArgument$1, SuiKit } from '@scallop-io/sui-kit';
7
7
  import * as _mysten_sui_dist_cjs_transactions from '@mysten/sui/dist/cjs/transactions';
8
8
  import { RouterDataV3, FindRouterParams, AggregatorClient, AggregatorClientParams } from '@cetusprotocol/aggregator-sdk';
9
+ export { AggregatorClient, RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
9
10
  import * as aftermath_ts_sdk from 'aftermath-ts-sdk';
10
11
  import { RouterProtocolName, RouterCompleteTradeRoute, ApiRouterPartialCompleteTradeRouteBody, Aftermath, AftermathApi, ConfigAddresses } from 'aftermath-ts-sdk';
12
+ export { Aftermath, RouterCompleteTradeRoute } from 'aftermath-ts-sdk';
11
13
  import { SourceDex, QuoteResponse, Commission } from '@7kprotocol/sdk-ts';
14
+ export { QuoteResponse } from '@7kprotocol/sdk-ts';
12
15
  import { Protocol, GetRoutesResult, Coin as Coin$1, SingleQuoteQueryParams, AggregatorQuoter, Commission as Commission$1 } from '@flowx-finance/sdk';
16
+ export { AggregatorQuoter, GetRoutesResult } from '@flowx-finance/sdk';
13
17
 
14
18
  type SecretKeyOrMnemonicsOrWalletAddress = {
15
19
  mnemonics: string;
@@ -216,9 +220,6 @@ declare abstract class SwapSdkBase<PoolType = string, RawRouteResultType = any,
216
220
  protected validateWalletAddress(): asserts this is typeof SwapSdkBase & {
217
221
  walletAddress: string;
218
222
  };
219
- protected validateRawRouteResult(): asserts this is typeof SwapSdkBase & {
220
- rawRouteResult: RawRouteResultType;
221
- };
222
223
  protected validateClient(): asserts this is typeof SwapSdkBase & {
223
224
  client: SdkClient;
224
225
  };
@@ -247,94 +248,8 @@ declare abstract class SwapSdkBase<PoolType = string, RawRouteResultType = any,
247
248
  }>;
248
249
  }
249
250
 
250
- declare class CoinMetadataRegistry {
251
- client: SuiClient;
252
- private cache;
253
- constructor(client: SuiClient, initialData?: (CoinMetadata & {
254
- coinType: string;
255
- })[]);
256
- setClient(client: SuiClient): void;
257
- getCoinMetadata(coinType: string): Promise<CoinMetadata>;
258
- }
259
-
260
- type TxExt = {
261
- initTx: Transaction;
262
- coinIn: TransactionObjectArgument;
263
- };
264
- type BuildOptionsBase = {
265
- slippage?: number;
266
- txExtensionParams?: TxExt;
267
- };
268
- declare class Aggregator {
269
- #private;
270
- readonly coinMetadata: CoinMetadataRegistry;
271
- readonly suiKit: SuiKit | undefined;
272
- readonly events: TypedEventEmitter<AggregatorEvents<string>>;
273
- protected _slippage: number;
274
- private signerMode;
275
- private aggregatorMap;
276
- private activeAggregator;
277
- private _fetchingStatus;
278
- private poolStatusForwarders;
279
- walletAddress: string;
280
- client: SuiClient;
281
- constructor(params: AggregatorConstructorParams);
282
- private forwardPoolStatusChangeEvent;
283
- addAggregator(aggregator: SwapSdkBase[]): void;
284
- getActiveAggregators(): string[];
285
- getAggregator(name: string): SwapSdkBase<string, any, any, any> | undefined;
286
- toggleAggregator(name: string, enabled: boolean): void;
287
- removeAggregator(name: string): void;
288
- get aggregators(): SwapSdkBase<string, any, any, any>[];
289
- /**
290
- * Per-aggregator fetching status. True while that aggregator's fetchRoute is in-flight.
291
- */
292
- get fetchingStatus(): Record<string, boolean>;
293
- /**
294
- * Get slippage (0.01 = 1%)
295
- */
296
- get slippage(): number;
297
- /**
298
- * Set slippage (0.01 = 1%)
299
- * @param slippageInDecimal
300
- */
301
- setSlippage(slippageInDecimal: number): void;
302
- /**
303
- * Set fetch timeout in milliseconds for all aggregators
304
- * @param timeoutInMs
305
- */
306
- setFetchTimeoutInMs(timeoutInMs: number): void;
307
- setSuiClient(client: SuiClient): void;
308
- setWalletAddress(address: string): void;
309
- getCoinMetadata(coinType: string): Promise<_mysten_sui_dist_cjs_client.CoinMetadata>;
310
- /**
311
- * Fetch swap routes from all aggregators, and sort them by best output amount
312
- * @param params FetchRouteParams
313
- * @param options FetchRoutesOptions
314
- */
315
- fetchRoutes(params: FetchRouteParams, options?: FetchRoutesOptions): Promise<{
316
- routes: FetchRouteResult<any>[];
317
- errors: {
318
- name: string;
319
- reason: unknown;
320
- }[];
321
- }>;
322
- /**
323
- * Build transaction with the selected aggregator's route
324
- * @param options Transaction building options
325
- */
326
- buildRouteTransaction(route: FetchRouteResult<any>, options?: BuildOptionsBase & {
327
- mergeResult?: true;
328
- }): Promise<SwapBuildResult<true>>;
329
- buildRouteTransaction(route: FetchRouteResult<any>, options: BuildOptionsBase & {
330
- mergeResult: false;
331
- }): Promise<SwapBuildResult<false>>;
332
- executeSwapTransaction(tx: Transaction): Promise<SuiTransactionBlockResponse>;
333
- executeSwapTransaction(tx: Transaction, dryRun: true): Promise<DryRunTransactionBlockResponse>;
334
- executeSwapTransaction(tx: Transaction, dryRun: false): Promise<SuiTransactionBlockResponse>;
335
- }
336
-
337
251
  type FetchRouteSettings$3 = Omit<FindRouterParams, 'from' | 'target' | 'amount' | 'byAmountIn' | 'providers'>;
252
+
338
253
  declare class CetusSwap extends SwapSdkBase<string, RouterDataV3, FetchRouteSettings$3, AggregatorClient> {
339
254
  constructor(params: SwapSdkConstructorParams<FetchRouteSettings$3> & Omit<AggregatorClientParams, 'client'>);
340
255
  private createRoute;
@@ -342,15 +257,19 @@ declare class CetusSwap extends SwapSdkBase<string, RouterDataV3, FetchRouteSett
342
257
  * Parse the raw route data from Cetus to the standardized FetchRouteResult format.
343
258
  * @returns FormattedRouteResult
344
259
  */
345
- private parseRawToFormattedResult;
260
+ parseRawToFormattedResult({ routerData, coinInType, coinOutType, }: {
261
+ routerData: RouterDataV3;
262
+ coinInType: string;
263
+ coinOutType: string;
264
+ }): Omit<FormattedRouteResult, 'name'>;
346
265
  setFetchRouteSettings(settings: FindRouterParams): void;
347
266
  calcSlippage(slippageInDecimal: number): number;
348
267
  fetchRoute(params: FetchRouteParams, abortSignal?: AbortSignal): Promise<{
349
268
  formattedResult: {
350
269
  name: string;
351
- coinOut: Coin;
352
270
  routes: SwapRoute[];
353
271
  coinIn: Coin;
272
+ coinOut: Coin;
354
273
  };
355
274
  rawRouteResult: RouterDataV3;
356
275
  }>;
@@ -361,6 +280,7 @@ declare class CetusSwap extends SwapSdkBase<string, RouterDataV3, FetchRouteSett
361
280
  }
362
281
 
363
282
  type FetchRouteSettings$2 = Omit<ApiRouterPartialCompleteTradeRouteBody, 'coinInType' | 'coinOutType' | 'coinInAmount' | 'protocolWhitelist' | 'protocolBlacklist'>;
283
+
364
284
  declare class AftermathSwap extends SwapSdkBase<RouterProtocolName, RouterCompleteTradeRoute, FetchRouteSettings$2, Aftermath> {
365
285
  readonly afApi: AftermathApi;
366
286
  constructor(params: SwapSdkConstructorParams<FetchRouteSettings$2> & {
@@ -397,6 +317,7 @@ interface Params {
397
317
  isSponsored?: boolean;
398
318
  }
399
319
  type FetchRouteSettings$1 = Omit<Params, 'tokenIn' | 'tokenOut' | 'amountIn' | 'sources'>;
320
+
400
321
  declare class _7kSwap extends SwapSdkBase<SourceDex, QuoteResponse, FetchRouteSettings$1> {
401
322
  commission: Commission;
402
323
  constructor(params: SwapSdkConstructorParams<FetchRouteSettings$1> & {
@@ -415,6 +336,7 @@ declare class _7kSwap extends SwapSdkBase<SourceDex, QuoteResponse, FetchRouteSe
415
336
  }
416
337
 
417
338
  type FetchRouteSettings = Omit<SingleQuoteQueryParams, 'amountIn' | 'tokenIn' | 'tokenOut' | 'excludeSources' | 'includeSources'>;
339
+
418
340
  declare class FlowXSwap extends SwapSdkBase<Protocol, GetRoutesResult<Coin$1, Coin$1>, FetchRouteSettings, AggregatorQuoter> {
419
341
  client: AggregatorQuoter;
420
342
  commission?: Commission$1;
@@ -436,9 +358,105 @@ declare class FlowXSwap extends SwapSdkBase<Protocol, GetRoutesResult<Coin$1, Co
436
358
  }>;
437
359
  }
438
360
 
361
+ interface SdkRegistry {
362
+ cetus: CetusSwap;
363
+ aftermath: AftermathSwap;
364
+ '7k': _7kSwap;
365
+ flowx: FlowXSwap;
366
+ }
367
+ type SdkName = keyof SdkRegistry;
368
+
369
+ declare class CoinMetadataRegistry {
370
+ client: SuiClient;
371
+ private cache;
372
+ constructor(client: SuiClient, initialData?: (CoinMetadata & {
373
+ coinType: string;
374
+ })[]);
375
+ setClient(client: SuiClient): void;
376
+ getCoinMetadata(coinType: string): Promise<CoinMetadata>;
377
+ }
378
+
379
+ type TxExt = {
380
+ initTx: Transaction;
381
+ coinIn: TransactionObjectArgument;
382
+ };
383
+ type BuildOptionsBase = {
384
+ slippage?: number;
385
+ txExtensionParams?: TxExt;
386
+ };
387
+ declare class Aggregator {
388
+ #private;
389
+ readonly coinMetadata: CoinMetadataRegistry;
390
+ readonly suiKit: SuiKit | undefined;
391
+ readonly events: TypedEventEmitter<AggregatorEvents<string>>;
392
+ protected _slippage: number;
393
+ private signerMode;
394
+ private aggregatorMap;
395
+ private activeAggregator;
396
+ private _fetchingStatus;
397
+ private poolStatusForwarders;
398
+ walletAddress: string;
399
+ client: SuiClient;
400
+ constructor(params: AggregatorConstructorParams);
401
+ private forwardPoolStatusChangeEvent;
402
+ addAggregator(aggregator: SwapSdkBase[]): void;
403
+ getActiveAggregators(): string[];
404
+ getAggregator<T extends SdkName>(name: T): SdkRegistry[T] | undefined;
405
+ getAggregator(name: string): SwapSdkBase | undefined;
406
+ toggleAggregator(name: string, enabled: boolean): void;
407
+ removeAggregator(name: string): void;
408
+ get aggregators(): SwapSdkBase<string, any, any, any>[];
409
+ /**
410
+ * Per-aggregator fetching status. True while that aggregator's fetchRoute is in-flight.
411
+ */
412
+ get fetchingStatus(): Record<string, boolean>;
413
+ /**
414
+ * Get slippage (0.01 = 1%)
415
+ */
416
+ get slippage(): number;
417
+ /**
418
+ * Set slippage (0.01 = 1%)
419
+ * @param slippageInDecimal
420
+ */
421
+ setSlippage(slippageInDecimal: number): void;
422
+ /**
423
+ * Set fetch timeout in milliseconds for all aggregators
424
+ * @param timeoutInMs
425
+ */
426
+ setFetchTimeoutInMs(timeoutInMs: number): void;
427
+ setSuiClient(client: SuiClient): void;
428
+ setWalletAddress(address: string): void;
429
+ getCoinMetadata(coinType: string): Promise<_mysten_sui_dist_cjs_client.CoinMetadata>;
430
+ /**
431
+ * Fetch swap routes from all aggregators, and sort them by best output amount
432
+ * @param params FetchRouteParams
433
+ * @param options FetchRoutesOptions
434
+ */
435
+ fetchRoutes(params: FetchRouteParams, options?: FetchRoutesOptions): Promise<{
436
+ routes: FetchRouteResult<any>[];
437
+ errors: {
438
+ name: string;
439
+ reason: unknown;
440
+ }[];
441
+ }>;
442
+ /**
443
+ * Build transaction with the selected aggregator's route
444
+ * @param options Transaction building options
445
+ */
446
+ buildRouteTransaction(route: FetchRouteResult<any>, options?: BuildOptionsBase & {
447
+ mergeResult?: true;
448
+ }): Promise<SwapBuildResult<true>>;
449
+ buildRouteTransaction(route: FetchRouteResult<any>, options: BuildOptionsBase & {
450
+ mergeResult: false;
451
+ }): Promise<SwapBuildResult<false>>;
452
+ executeSwapTransaction(tx: Transaction): Promise<SuiTransactionBlockResponse>;
453
+ executeSwapTransaction(tx: Transaction, dryRun: true): Promise<DryRunTransactionBlockResponse>;
454
+ executeSwapTransaction(tx: Transaction, dryRun: false): Promise<SuiTransactionBlockResponse>;
455
+ }
456
+
439
457
  declare const isSuiType: (coinType: string) => boolean;
440
458
  declare const selectCoins: (client: SuiClient, coinType: string, amount: string, owner: string) => Promise<CoinStruct[]>;
441
459
  declare const mergeWithExistingOrTransfer: (tx: Transaction, coin: TransactionObjectArgument, client: SuiClient, coinType: string, sender: string) => Promise<void>;
442
460
  declare const transformProperCase: (provider: string) => string;
443
461
 
444
- export { AftermathSwap, Aggregator, type AggregatorConstructorParams, type AggregatorEvents, type AggregatorStatusEvent, CetusSwap, type Coin, CoinMetadataRegistry, type FetchRouteParams, type FetchRouteResult, type FetchRoutesOptions, FlowXSwap, type FormattedRouteResult, type SecretKeyOrMnemonicsOrWalletAddress, type SuiClientOrFullnodeUrl, type SwapBuildResult, type SwapCoinInfo, type SwapParams, type SwapPath, type SwapRoute, SwapSdkBase, type SwapSdkBaseInterface, type SwapSdkConstructorParams, type SwapSdkEvents, type SwapSdkPoolStatusEvent, TypedEventEmitter, _7kSwap, isSuiType, mergeWithExistingOrTransfer, selectCoins, transformProperCase };
462
+ export { type FetchRouteSettings$2 as AftermathFetchRouteSettings, AftermathSwap, Aggregator, type AggregatorConstructorParams, type AggregatorEvents, type AggregatorStatusEvent, type FetchRouteSettings$3 as CetusFetchRouteSettings, CetusSwap, type Coin, CoinMetadataRegistry, type FetchRouteParams, type FetchRouteResult, type FetchRoutesOptions, type FetchRouteSettings as FlowXFetchRouteSettings, FlowXSwap, type FormattedRouteResult, type SdkName, type SdkRegistry, type SecretKeyOrMnemonicsOrWalletAddress, type SuiClientOrFullnodeUrl, type SwapBuildResult, type SwapCoinInfo, type SwapParams, type SwapPath, type SwapRoute, SwapSdkBase, type SwapSdkBaseInterface, type SwapSdkConstructorParams, type SwapSdkEvents, type SwapSdkPoolStatusEvent, TypedEventEmitter, type FetchRouteSettings$1 as _7kFetchRouteSettings, _7kSwap, isSuiType, mergeWithExistingOrTransfer, selectCoins, transformProperCase };