Prerequisites

1. NPM install

npm install @cetusprotocol/aggregator-sdk

2. Setting Up Configuration

Initialize mainnet Aggregator client. There are two ways to initialize the aggregator client. One is straightforward, using the default mainnet client, while the other supports a high level of customization.

Example

  1. Fast create mainnet aggregator client default.

import { AggregatorClient } from "@cetusprotocol/aggregator-sdk"

const client = new AggregatorClient({})
  1. (Enhance) Customer create aggregator client by your self rpc node.

import { AggregatorClient } from "@cetusprotocol/aggregator-sdk"
import type { SuiClient } from '@mysten/sui/client';
import dotenv from 'dotenv'

dotenv.config()

// used to do simulate swap and swap
// https://fullnode.mainnet.sui.io:443
const fullNodeURL = process.env.SUI_RPC!

const suiClient = new SuiClient({
    url: fullNodeURL,
})

// provider by cetus
const aggregatorURL = "https://api-sui.cetus.zone/router_v2/find_routes"

// set your wallet address, used to do simulate
const wallet = "0x..."

// import { Env } from "@cetusprotocol/aggregator-sdk"
// Currently, we provide full support for Mainnet, 
// while Testnet is only supported for Cetus and DeepBook providers.
const client = new AggregatorClient({
  // endpoint, // If you do not have a exclusive aggregator api domain,just use cetus default aggregator endpoints.
  signer: wallet,
  client: suiClient,
  env: Env.Mainnet,
  pythUrls: ["YOUR_PYTH_URL", "ANOTHER_PYTH_URL"],
  partner: "YOUR_PARTNER_ID" /// Partner ID for fee sharing. Set once during initialization instead of per swap.
  overlayFeeRate: 0.01, // Overlay fee rate (0.01 represents 1%).
  overlayFeeReceiver: "0x..", // Address to receive the overlay fees
})

Notes: Some providers, such as HaedalHMM and Metastable, rely on Pyth oracle prices when build transactions. Currently, we have a default configuration that connects to Pyth's publicly available node. However, if you frequently build transactions, we recommend setting up a private Pyth node interface as an additional backup. This will ensure uninterrupted access to HaedalHMM and Metastable, even if the public node experiences occasional downtime.

Last updated