KMP Cetus Aggregator
AndroidiOSJVMmacOS
Use the KMP Aggregator to perform swaps on the Cetus DEX (and other aggregators) on Sui with a simple, type-safe DSL. It is built on top of ksui and automatically handles routing, coin splitting, and PTB construction.
Key Features
- Initialize a simple
Aggregatorand use a Kotlin DSL to describe swaps. - Get smart routing across multiple liquidity sources.
- Benefit from automatic gas coin handling for SUI inputs.
- Write once and run on Android, iOS, JVM, and macOS.
- Compose the resulting
ProgrammableTransactiondirectly with ksui.
Installation
Add the dependency to your KMP project. You also need ksui and bcs.
Code
// In commonMain
implementation("xyz.mcxross.agg.cetus:kmp:0.1.5-SNAPSHOT")
implementation("xyz.mcxross.ksui:ksui:2.2.8-SNAPSHOT")
implementation("xyz.mcxross.ksui:ksui-core:2.2.8-SNAPSHOT")
implementation("xyz.mcxross.bcs:bcs:0.1.3")For snapshots, include the repository:
Code
repositories {
mavenCentral()
maven("https://central.sonatype.com/repository/maven-snapshots")
}Quick Start
Set up a Sui client (from ksui) and the aggregator, then build and execute a swap.
Code
import xyz.mcxross.ksui.Sui
import xyz.mcxross.ksui.core.model.Network
import xyz.mcxross.ksui.core.model.SuiConfig
import xyz.mcxross.ksui.core.model.SuiSettings
import xyz.mcxross.agg.cetus.dsl.*
suspend fun main() {
val sui = Sui(SuiConfig(SuiSettings(network = Network.MAINNET)))
val aggregator = Aggregator()
val tx = aggregator.swap {
from = Tokens.SUI
to = Tokens.CETUS
amount = 1.sui
slippage = 0.5.percent
recipient = "0xYourAddress..."
}
val signer = Account.import("suiprivkey...")
val response = sui.signAndExecuteTransactionBlock(signer, tx)
println("Swap executed: ${response.digest}")
}Available Tokens
The Tokens object provides common coin types:
Code
Tokens.SUI
Tokens.CETUS
Tokens.DEEP
Tokens.USDCUse any valid coin type string.
Swap Scope Options
Inside the swap { } block you can set:
from,to: coin typesamount: ULong (use.suiextension for convenience)slippage: Double (use.percent)recipient: destination addresspartner,providers,inputObject,pythPriceIds,deepbookV3DeepFeefor advanced routing.