@cetusprotocol/aggregator-sdk 0.0.0-experimental-20240929164543 → 0.0.0-experimental-20241010160019

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.
@@ -0,0 +1,68 @@
1
+ import {
2
+ Transaction,
3
+ TransactionArgument,
4
+ TransactionObjectArgument,
5
+ } from "@mysten/sui/transactions"
6
+ import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
7
+ import { mintZeroCoin } from "~/utils/coin"
8
+
9
+ export type CetusFlashSwapResult = {
10
+ targetCoin: TransactionObjectArgument
11
+ flashReceipt: TransactionObjectArgument
12
+ payAmount: TransactionArgument
13
+ }
14
+
15
+ export class DeepbookV3 implements Dex {
16
+ private deepbookV3Config: string
17
+ private deepCoinType: string
18
+
19
+ constructor(env: Env) {
20
+ this.deepbookV3Config =
21
+ env === Env.Mainnet
22
+ ? "0x0"
23
+ : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
24
+ this.deepCoinType =
25
+ env === Env.Mainnet
26
+ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
27
+ : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
28
+ }
29
+
30
+ async swap(
31
+ client: AggregatorClient,
32
+ txb: Transaction,
33
+ path: Path,
34
+ inputCoin: TransactionObjectArgument,
35
+ deepbookv3DeepFee?: TransactionObjectArgument
36
+ ): Promise<TransactionObjectArgument> {
37
+ const { direction, from, target } = path
38
+ const [func, coinAType, coinBType] = direction
39
+ ? ["swap_a2b", from, target]
40
+ : ["swap_b2a", target, from]
41
+
42
+ let deepFee
43
+ if (deepbookv3DeepFee) {
44
+ if (path.extendedDetails?.deepbookv3DeepFee && path.extendedDetails?.deepbookv3DeepFee > 0) {
45
+ const splitAmounts = [path.extendedDetails?.deepbookv3DeepFee]
46
+ deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0] as TransactionObjectArgument
47
+ } else {
48
+ deepFee = mintZeroCoin(txb, this.deepCoinType)
49
+ }
50
+ } else {
51
+ deepFee = mintZeroCoin(txb, this.deepCoinType)
52
+ }
53
+
54
+ const args = [
55
+ txb.object(this.deepbookV3Config),
56
+ txb.object(path.id),
57
+ inputCoin,
58
+ deepFee,
59
+ txb.object(CLOCK_ADDRESS),
60
+ ]
61
+ const res = txb.moveCall({
62
+ target: `${client.publishedAt()}::deepbookv3::${func}`,
63
+ typeArguments: [coinAType, coinBType],
64
+ arguments: args,
65
+ }) as TransactionArgument
66
+ return res
67
+ }
68
+ }
@@ -12,6 +12,7 @@ export interface Dex {
12
12
  client: AggregatorClient,
13
13
  ptb: Transaction,
14
14
  path: Path,
15
- inputCoin: TransactionObjectArgument
15
+ inputCoin: TransactionObjectArgument,
16
+ deepbookv3DeepFee?: TransactionObjectArgument
16
17
  ): Promise<TransactionObjectArgument>
17
18
  }
@@ -0,0 +1,6 @@
1
+ export function processEndpoint(endpoint: string) {
2
+ if (endpoint.endsWith("/find_routes")) {
3
+ return endpoint.replace("/find_routes", "")
4
+ }
5
+ return endpoint
6
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './contracts'
2
2
  export * from './msafe'
3
+ export * from './api'
package/test.json ADDED
@@ -0,0 +1,5 @@
1
+ [
2
+ [Path { id: "0x0d1b1746d220bd5ebac5231c7685480a16f1c707a46306095a4c67dc7ce4dcae", edge_id: "0x0d1b1746d220bd5ebac5231c7685480a16f1c707a46306095a4c67dc7ce4dcae", provider: "DEEPBOOKV3", from: "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP", target: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI", direction: true, fee_rate: Decimal(0), lot_size: 1000000, amount_in: 0, amount_out: 0, max_depth: 3, extended_details: None, allow_bidirection: true
3
+ }
4
+ ]
5
+ ]
@@ -8,6 +8,7 @@ import {
8
8
  M_SSWP,
9
9
  M_SUI,
10
10
  M_USDC,
11
+ T_DEEP,
11
12
  } from "./test_data.test"
12
13
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
13
14
  import { printTransaction } from "~/utils/transaction"
@@ -40,12 +41,12 @@ describe("router module", () => {
40
41
  keypair = buildTestAccount()
41
42
  }
42
43
 
43
- // const wallet = keypair.getPublicKey().toSuiAddress()
44
+ const wallet = keypair.getPublicKey().toSuiAddress()
44
45
 
45
46
  // console.log("wallet", wallet, "\n", wallet.toString())
46
47
 
47
- const wallet =
48
- "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
48
+ // const wallet =
49
+ // "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
49
50
  // const wallet =
50
51
  // "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
51
52
  // const wallet =
@@ -69,12 +70,15 @@ describe("router module", () => {
69
70
  publishedAt:
70
71
  "0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
71
72
  }
73
+ // const endpoint =
74
+ // "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
72
75
  const endpoint =
73
- "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
76
+ "http://localhost:8080/router_v2/find_routes"
77
+
74
78
  const suiClient = new SuiClient({
75
- url: "https://fullnode.mainnet.sui.io:443",
79
+ url: "https://fullnode.testnet.sui.io:443",
76
80
  })
77
- client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
81
+ client = new AggregatorClient(endpoint, wallet, suiClient, Env.Testnet)
78
82
  })
79
83
 
80
84
  test("Get all coins", () => {
@@ -135,15 +139,9 @@ describe("router module", () => {
135
139
 
136
140
  test("Build router tx", async () => {
137
141
  const byAmountIn = true
138
- const amount = "1000000000"
139
-
142
+ const amount = "20000000000"
140
143
  const from = M_SUI
141
- // const target =
142
- // "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
143
- // const target =
144
- // "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
145
-
146
- const target = M_USDC
144
+ const target = T_DEEP
147
145
 
148
146
  const res = await client.findRouters({
149
147
  from,
@@ -152,14 +150,14 @@ describe("router module", () => {
152
150
  byAmountIn,
153
151
  depth: 3,
154
152
  providers: [
155
- // "CETUS",
153
+ "CETUS",
156
154
  // "DEEPBOOK",
157
155
  // "AFTERMATH",
158
156
  // "FLOWX",
159
157
  // "KRIYA",
160
158
  // "KRIYAV3",
161
159
  // "TURBOS",
162
- "BLUEMOVE",
160
+ "DEEPBOOKV3",
163
161
  ],
164
162
  })
165
163
 
@@ -188,13 +186,13 @@ describe("router module", () => {
188
186
  let result = await client.devInspectTransactionBlock(txb)
189
187
  console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
190
188
 
191
- // if (result.effects.status.status === "success") {
192
- // console.log("Sim exec transaction success")
193
- // const result = await client.signAndExecuteTransaction(txb, keypair)
194
- // // console.log("result", result)
195
- // } else {
196
- // console.log("result", result)
197
- // }
189
+ if (result.effects.status.status === "success") {
190
+ // console.log("Sim exec transaction success")
191
+ const result = await client.signAndExecuteTransaction(txb, keypair)
192
+ console.log("result", result)
193
+ } else {
194
+ console.log("result", result)
195
+ }
198
196
  }
199
197
  }, 600000)
200
198
 
@@ -348,9 +346,6 @@ describe("router module", () => {
348
346
  console.log(JSON.stringify(res, null, 2))
349
347
  }
350
348
 
351
- console.log("amount in", res?.amountIn.toString())
352
- console.log("amount out", res?.amountOut.toString())
353
-
354
349
  const txb = new Transaction()
355
350
 
356
351
  if (res != null) {
@@ -378,4 +373,9 @@ describe("router module", () => {
378
373
  // }
379
374
  }
380
375
  }, 600000)
376
+
377
+ test("Get deepbook v3 config", async () => {
378
+ const config = await client.getDeepbookV3Config()
379
+ console.log("config", config)
380
+ }, 60000)
381
381
  })
@@ -1,5 +1,6 @@
1
1
  // Testnet
2
2
  export const T_USDC = ""
3
+ export const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
3
4
 
4
5
  // Mainnet
5
6
  export const M_USDC =