@cetusprotocol/aggregator-sdk 0.0.0-experimental-20250829185106 → 0.0.0-experimental-20250903203111

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.
@@ -1,142 +0,0 @@
1
- import { AggregatorClient, MergeSwapParams, Env } from "../src"
2
- import { Transaction } from "@mysten/sui/transactions"
3
- import { SuiClient } from "@mysten/sui/client"
4
- import BN from "bn.js"
5
-
6
- async function mergeSwapExample() {
7
- // Initialize client
8
- const client = new AggregatorClient({
9
- endpoint: "https://api-sui-cloudfront.cetus.zone/router_v3",
10
- env: Env.Mainnet,
11
- signer: "0xYourWalletAddress", // Replace with your wallet address
12
- client: new SuiClient({ url: "https://fullnode.mainnet.sui.io" })
13
- })
14
-
15
- // 1. First, find merge swap routes
16
- const mergeSwapParams: MergeSwapParams = {
17
- target: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", // USDC
18
- byAmountIn: true,
19
- depth: 3,
20
- providers: ["CETUS"],
21
- froms: [
22
- {
23
- coinType: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
24
- amount: new BN("100000000")
25
- },
26
- {
27
- coinType: "0xce7ff77a83ea0cb6fd39bd8748e2ec89a3f41e8efdc3f4eb123e0ca37b184db2::buck::BUCK",
28
- amount: new BN("1000000000")
29
- },
30
- {
31
- coinType: "0x002::sui::SUI",
32
- amount: new BN("3000000000")
33
- }
34
- ]
35
- }
36
-
37
- console.log("Finding merge swap routes...")
38
- const routerResult = await client.findMergeSwapRouters(mergeSwapParams)
39
-
40
- if (!routerResult || routerResult.error) {
41
- console.error("Failed to find routes:", routerResult?.error)
42
- return
43
- }
44
-
45
- console.log("Routes found!")
46
- console.log("Total amount in:", routerResult.amountIn.toString())
47
- console.log("Total amount out:", routerResult.amountOut.toString())
48
- console.log("Number of paths:", routerResult.paths.length)
49
-
50
- // 2. Execute merge swap with manual input coins
51
- const txb = new Transaction()
52
-
53
- // Prepare input coins (you need to have these coins in your wallet)
54
- const inputCoins = [
55
- {
56
- coinType: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
57
- coin: txb.object("0xDeepCoinObjectId") // Replace with actual coin object ID
58
- },
59
- {
60
- coinType: "0xce7ff77a83ea0cb6fd39bd8748e2ec89a3f41e8efdc3f4eb123e0ca37b184db2::buck::BUCK",
61
- coin: txb.object("0xBuckCoinObjectId") // Replace with actual coin object ID
62
- },
63
- {
64
- coinType: "0x002::sui::SUI",
65
- coin: txb.splitCoins(txb.gas, [3000000000])[0] // Use gas coin for SUI
66
- }
67
- ]
68
-
69
- // Execute merge swap
70
- const outputCoin = await client.mergeSwap({
71
- router: routerResult,
72
- inputCoins,
73
- slippage: 0.01, // 1% slippage
74
- txb,
75
- partner: "YourPartnerName" // Optional
76
- })
77
-
78
- console.log("Merge swap transaction built successfully!")
79
-
80
- // Transfer output to sender (optional)
81
- txb.transferObjects([outputCoin], client.signer)
82
-
83
- // Sign and execute transaction (implementation depends on your wallet integration)
84
- // const result = await signAndExecuteTransaction(txb)
85
- // console.log("Transaction executed:", result.digest)
86
- }
87
-
88
- async function fastMergeSwapExample() {
89
- // Initialize client
90
- const client = new AggregatorClient({
91
- endpoint: "https://api-sui-cloudfront.cetus.zone/router_v3",
92
- env: Env.Mainnet,
93
- signer: "0xYourWalletAddress", // Replace with your wallet address
94
- client: new SuiClient({ url: "https://fullnode.mainnet.sui.io" })
95
- })
96
-
97
- // 1. Find merge swap routes
98
- const mergeSwapParams: MergeSwapParams = {
99
- target: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
100
- byAmountIn: true,
101
- depth: 3,
102
- froms: [
103
- {
104
- coinType: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
105
- amount: new BN("100000000")
106
- },
107
- {
108
- coinType: "0x002::sui::SUI",
109
- amount: new BN("2000000000")
110
- }
111
- ]
112
- }
113
-
114
- const routerResult = await client.findMergeSwapRouters(mergeSwapParams)
115
-
116
- if (!routerResult || routerResult.error) {
117
- console.error("Failed to find routes:", routerResult?.error)
118
- return
119
- }
120
-
121
- // 2. Execute fast merge swap (automatically builds input coins)
122
- const txb = new Transaction()
123
-
124
- await client.fastMergeSwap({
125
- router: routerResult,
126
- slippage: 0.01, // 1% slippage
127
- txb,
128
- partner: "YourPartnerName", // Optional
129
- payDeepFeeAmount: 1000000 // Optional: DeepBook fee if needed
130
- })
131
-
132
- console.log("Fast merge swap transaction built successfully!")
133
- console.log("Input coins are automatically created and output is auto-merged/transferred")
134
-
135
- // Sign and execute transaction
136
- // const result = await signAndExecuteTransaction(txb)
137
- // console.log("Transaction executed:", result.digest)
138
- }
139
-
140
- // Run examples
141
- mergeSwapExample().catch(console.error)
142
- // fastMergeSwapExample().catch(console.error)