Skip to content

CetusProtocol/aggregator

Repository files navigation


Logo

Cetus Plus Swap Aggregator

Integrating Cetus-Aggregator-SDK: A Comprehensive Guide, Please see details in document.
Explore the document »

Welcome to Cetus Plus Swap Aggregator

Cetus plus swap aggregator is a high-speed and easy-to-integrate solution designed to optimize your trading experience on the Sui blockchain. This aggregator integrates multiple mainstream decentralized exchanges (DEX) on the Sui chain, including various types of trading platforms, providing users with the best trading prices and the lowest slippage.

Core Advantages:

High-Speed Transactions: Thanks to advanced algorithms and efficient architecture, our aggregator can execute transactions at lightning speed, ensuring users get the best opportunities in a rapidly changing market.

Easy Integration: The aggregator is designed to be simple and easy to integrate. Whether you are an individual developer or a large project team, you can quickly connect and deploy.

Multi-Platform Support: Currently, we have integrated multiple mainstream DEXs on the Sui chain, including cetus, deepbook, kriya, flowx, aftermath, afsui, haedal, volo, turbos etc, allowing users to enjoy a diversified trading experience on a single platform.

By using our aggregator, you can trade more efficiently and securely on the Sui blockchain, fully leveraging the various opportunities brought by decentralized finance (DeFi).

Install

The SDK is published to npm registry. To use the SDK in your project, you can run npm install @cetusprotocol/aggregator-sdk

Usage

1. Init client with rpc and package config

  1. Create aggregator client default.

    const client = new AggregatorClient()
  2. Customer create aggregator client by your self rpc node.

    // 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(
      aggregatorURL,
      wallet,
      suiClient,
      Env.Mainnet
    )

2. Get best router swap result from aggregator service

const amount = new BN(1000000)
const from = "0x2::sui::SUI"
const target =
  "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"

const routerRes = await client.findRouters({
  from,
  target,
  amount,
  byAmountIn: true, // true means fix input amount, false means fix output amount
})

3. Confirm and do fast swap

const routerTx = new Transaction()

await client.fastRouterSwap({
  routers: routerRes.routes,
  byAmountIn,
  txb: routerTx,
  slippage: 0.01,
  isMergeTragetCoin: true,
  refreshAllCoins: true,
})

4. Build PTB and return target coin

const routerTx = new Transaction()

const targetCoin = await client.routerSwap({
  routers: routerRes.routes,
  byAmountIn: true,
  txb: routerTx,
  inputCoin,
  slippage: 0.01,
})

// you can use this target coin object argument to build your ptb.
const client.transferOrDestoryCoin(
    txb,
    targetCoinRes.targetCoin,
    targetCoinType
)

More About Cetus

Use the following links to learn more about Cetus:

Learn more about working with Cetus in the Cetus Documentation.

Join the Cetus community on Cetus Discord.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published