For the complete documentation index, see llms.txt. This page is also available as Markdown.

Features Available

1. Find router

Func client.findRouters()

Params

Required parameters

Name
Type
Details

from

String

The coin type of input coin.

target

String

The coin type of output coin.

amount

BN | string | number| bigint

The amount of input or output,determined byAmountIn

byAmountIn

Boolean

true means fixed the amount of input, false means fixed the amount of output.

Optional parameters

Name
Type
Details

providers

String Array

Optional list of liquidity providers to include when finding routes. If omitted, the Aggregator automatically selects all providers supported by the current SDK version. Use getAllProviders(), getProvidersIncluding(), or getProvidersExcluding() to construct this list. Refer to Getting Started for the provider list supported by each SDK version.

depth

Number

now depths support betweent 1 and 3, default setting is 3, it means you can get 3 hops path.

splitAlgorithm

String

devide_equally or geometric, recommand just use default devide_equally.

splitFactor

Number

used to contral geometric split width.

splitCount

Number

this field represents the maximum number of splits for a transaction. If you do not want to split, set it to 1. The default value is 20.

ResponseV3

When using Aggregator SDK v3 (version 1.0.0 or higher), the findRouter method will return data in the RouterV3 structure.

Name
Type
Details

quoteID

string

A randomly generated ID from the aggregator service for tracking index transactions and quotes.

amountIn

BN

Total amount in.

amountOut

BN

Total amount out.

byAmountIn

Boolean

true means fixed the amount of input, false means fixed the amount of output. This is the same as request parameters.

paths

Path[]

All liquidity paths data.

insufficientLiquidity

Boolean

true means liquidity insufficient, false means liquidity enough.

deviationRatio

Number

Price deviation ratio, (0.01 means 1%), indicating the degree of difference between the aggregator result and market price. When the price deviation ratio is undefined (no reference market price available) or relatively large (significant deviation from existing market prices), provide users with a reference option on whether to execute the trade at the current price to avoid potential asset losses.

packages

Map<string, string>

When user pass new version parameters, it will return newest aggregator packages data.

overlayFee

Number

The amount for overlay fee.

totalDeepFee

Number

Calculated need deep fee for deep pools.

error

RouterError

Error code and msg for aggregator.

ResponseV2

Name
Type
Details

quoteID

string

A randomly generated ID from the aggregator service for tracking index transactions and quotes.

amountIn

BN

Total amount in.

amountOut

BN

Total amount out.

byAmountIn

Boolean

true means fixed the amount of input, false means fixed the amount of output. This is the same as request parameters.

routes

Router[]

All liquidity routes data.

insufficientLiquidity

Boolean

true means liquidity insufficient, false means liquidity enough.

deviationRatio

Number

Price deviation ratio, (0.01 means 1%), indicating the degree of difference between the aggregator result and market price. When the price deviation ratio is undefined (no reference market price available) or relatively large (significant deviation from existing market prices), provide users with a reference option on whether to execute the trade at the current price to avoid potential asset losses.

packages

Map<string, string>

When user pass new version parameters, it will return newest aggregator packages data.

overlayFee

Number

The amount for overlay fee.

totalDeepFee

Number

Calculated need deep fee for deep pools.

error

RouterError

Error code and msg for aggregator.

Example

2. Build swap transaction

Comparison of Swap Methods

Feature

fastRouterSwap

routerSwapWithMaxAmountIn

routerSwap

Input Coin

Prepared automatically

Provided by caller

Provided by caller

Input Limit

Managed automatically

Enforced by maxAmountIn

No explicit limit

Output

Delivered automatically

Returns target coin object

Returns target coin object

Recommended Use

Best for simple swaps where the SDK manages input coin construction automatically through coinWithBalance.

Best for composable PTBs requiring external input coins with a maximum input protection.

Best for composable PTBs where the full input coin balance should be used in the swap.

2.1 Build fast swap transaction

Automatically prepares the input coin, builds the swap, and delivers the output coin to the transaction sender.

BuildFastRouterSwapParamsV3

Required Params

Name
Type
Details

router

RouterDataV3 Object

returned by find router method in latest aggregator sdk version

slippage

Number

A decimal value in the range 0 <= slippage < 1. For example, 0.01 allows up to 1% slippage during swap execution.

txb

Transaction

The programmable transaction builder.

Optional parameters

Name
Type
Details

partner

String

The partner address. Details about partner can be found here. You can now set the partner directly during client initialization. This parameter will soon be deprecated; please migrate your configuration.

cetusDlmmPartner

String

The partner address. Details about partner can be found here. You can now set the partner directly during client initialization. This parameter will soon be deprecated; please migrate your configuration.

refreshAllCoins

Boolean

If true, retrieves all coin types when setting up the swap; if false, uses the existing coins.

payDeepFeeAmount

Number

The deep amount for pay deep fee in deepbookv3 path. Currently, all pools that charge a swap fee are covered by Cetus.

sponsored

Boolean

Set to true when a separate sponsor or gas station pays the transaction gas. In sponsored mode, the swap does not use txb.gas as its input or output. Default: false.

Sponsored transactions

Set sponsored: true when a separate sponsor or gas station pays the transaction gas. In this mode, the swap does not use txb.gas as its input or output because the gas coin belongs to the sponsor.

For the complete flow—including buildTransactionKind, attaching the sponsor's gas data, and collecting signatures from both parties—see Sponsored transaction: sponsor pays gas.

Example

2.2. Build a swap with maximum input validation

Builds a swap using a caller-provided input coin, validates it against maxAmountIn, and returns the target coin object for use in the same PTB.

Use routerSwapWithMaxAmountIn when the output coin needs to be reused in the same PTB and the provided input coin must be validated against an explicit maximum amount.

BuildRouterSwapParamsV3 (with maxAmountIn)

Extension of BuildRouterSwapParamsV3 with additional maximum amount validation.

Required Params

Name
Type
Details

router

RouterDataV3 Object

Returned by findRouters method. Must include the packages field with aggregator v3 package address.

inputCoin

TransactionObjectArgument

The input coin object to be swapped.Important: Unlike routerSwap, this methods comes with a maxAmountIn input and the final executed amount won't exceed this cap

slippage

Number

A decimal value in the range 0 <= slippage < 1. For example, 0.01 allows up to 1% slippage during swap execution.

txb

Transaction

The programmable transaction builder.

maxAmountIn

BN

The maximum allowed amount of the provided input coin. The transaction aborts if the input coin amount exceeds this value.

Optional Parameters

Name
Type
Details

partner

String

The partner address. Details about partner can be found here.You can now set the partner directly during client initialization. This parameter will soon be deprecated; please migrate your configuration.

deepbookv3DeepFee

TransactionObjectArgument

The DEEP token object for paying fees in DeepBook V3 pools. Currently, all pools that charge a swap fee are covered by Cetus, so you typically don't need to provide this.

fixable

Boolean

Advanced parameter for fixable router swap. Used in special swap scenarios. Default: false

Examples

2.3. Build swap transaction and return target coin object(use the whole input coin)

Uses a caller-provided input coin and returns the target coin object for use in the same PTB.

⚠️ Critical Difference: inputCoin Behavior

routerSwap - Full Consumption

Important: If you provide a coin with 1000 SUI, the entire 1000 SUI will be used in the swap, regardless of the router's amountIn. This method does not support partial coin usage.

routerSwapWithMaxAmountIn - Protected Consumption

Important: This method adds on-chain validation to ensure the swap does not exceed maxAmountIn. The transaction will abort if the required amount exceeds this limit, protecting your assets from unexpected large swaps.

slippage and maxAmountIn provide different protections. slippage limits deterioration of the execution rate relative to the quote. maxAmountIn sets an absolute upper bound on the input coin amount. When either validation fails, the transaction aborts on-chain.

BuildRouterSwapParamsV3

Required Params

Name
Type
Details

router

RouterData Object

Returned by find router method

inputCoin

TransactionObjectArgument

The input coin object to be swapped. Important: This method will completely consume the input coin amount. If you need to set a maximum limit on how much of the input coin can be used (for example, to implement slippage protection on the input side), you should use routerSwapWithMaxAmountIn method.

slippage

Number

A decimal value in the range 0 <= slippage < 1. For example, 0.01 allows up to 1% slippage during swap execution.

txb

Transaction

The programmable transaction builder.

Optional parameters

Name
Type
Details

partner

String

The partner address. Details about partner can be found here. You can now set the partner directly during client initialization. This parameter will soon be deprecated; please migrate your configuration.

deepbookv3DeepFee

TransactionObjectArgument

The deep fee obejct argument for pay deep fee in deepbookv3 path. Currently, all pools that charge a swap fee are covered by Cetus.

Example

3. FAQ

5.1. Why use v3 swap params?

1. Automatically merges duplicate paths

By combining the latest path merging and sorting algorithms, duplicate pools are consolidated, resulting in significant gas savings when dealing with multiple split paths.

2. Support dynamic use latest package version

The new parameters will pass the entire result from find router, which includes the latest contract address. However, this feature is only effective in SDK versions greater than 0.3.18.

In the future, we will continue to support the old version of swap parameters in both swap methods. However, upgrading to the new version will allow you to avoid mandatory SDK version updates.

3. Remove duplicate parameter byAmountIn

Now, the find router result will return the value based on the amount in, allowing you to directly obtain it from the find router result in the new swap parameters.

5.2. How to Migrate to Aggregator V3?

No code changes needed for basic usage:

  • Use the latest sdk version. (version >= v1.1.1)

  • Client initialization stays the same

  • findRouter now returns V3 structure automatically

  • fastRouterSwap and routerSwap accept the new format transparently

  • Update display logic only if showing detailed RouterDataV3 to users

5.3. How to set providers?

  1. You can ignore the providers parameters; the aggregator server will automatically set all usable providers based on the SDK version.

  2. You can use the getAllProviders() method to retrieve all providers. Additionally, you can use the getProvidersIncluding() and getProvidersExcluding() methods to filter out specific providers or select only certain ones from the complete list.

  1. While you can manually specify the providers you want to use, as the number of providers increases, manual configuration may lead to the omission of some providers, which could affect your price advantage."

5.4. How to fix error "All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes. Detailed error: aborted"?

Reason: Some providers, such as Headalpmm and Metastable, rely on Pyth oracle prices when building transactions. Currently, we have a default configuration that connects to Pyth's publicly available node. However, if you frequently build transactions, you may encounter limitations with the Pyth public nodes(https://hermes.pyth.network).

Solutions: We recommend setting up a private Pyth node interface as an additional backup. This will ensure uninterrupted access to SteammOmmV2 and Metastable, even if the public node experiences occasional downtime.

Another way, you can opt not to use Headalpmm and Metastable, but this will require you to manually configure the provider when find router.

Last updated