@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241009201249 → 0.0.0-experimental-20241011180351
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.
- package/dist/index.d.mts +38 -3
- package/dist/index.d.ts +38 -3
- package/dist/index.js +117 -20
- package/dist/index.mjs +110 -21
- package/dist/src/api.d.ts +16 -0
- package/dist/src/client.d.ts +6 -2
- package/dist/src/transaction/deepbook_v3.d.ts +1 -1
- package/dist/src/transaction/index.d.ts +1 -1
- package/dist/src/utils/api.d.ts +1 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/tests/test_data.test.d.ts +3 -0
- package/package.json +1 -1
- package/src/api.ts +33 -7
- package/src/client.ts +73 -8
- package/src/transaction/afsui.ts +0 -1
- package/src/transaction/aftermath.ts +0 -2
- package/src/transaction/deepbook_v3.ts +16 -4
- package/src/transaction/index.ts +2 -1
- package/src/utils/api.ts +6 -0
- package/src/utils/index.ts +3 -0
- package/tests/router.test.ts +29 -27
- package/tests/test_data.test.ts +3 -0
package/src/transaction/afsui.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class DeepbookV3 implements Dex {
|
|
|
20
20
|
this.deepbookV3Config =
|
|
21
21
|
env === Env.Mainnet
|
|
22
22
|
? "0x0"
|
|
23
|
-
: "
|
|
23
|
+
: "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
|
|
24
24
|
this.deepCoinType =
|
|
25
25
|
env === Env.Mainnet
|
|
26
26
|
? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
|
|
@@ -31,19 +31,31 @@ export class DeepbookV3 implements Dex {
|
|
|
31
31
|
client: AggregatorClient,
|
|
32
32
|
txb: Transaction,
|
|
33
33
|
path: Path,
|
|
34
|
-
inputCoin: TransactionObjectArgument
|
|
34
|
+
inputCoin: TransactionObjectArgument,
|
|
35
|
+
deepbookv3DeepFee?: TransactionObjectArgument
|
|
35
36
|
): Promise<TransactionObjectArgument> {
|
|
36
37
|
const { direction, from, target } = path
|
|
37
38
|
const [func, coinAType, coinBType] = direction
|
|
38
39
|
? ["swap_a2b", from, target]
|
|
39
40
|
: ["swap_b2a", target, from]
|
|
40
41
|
|
|
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
|
+
|
|
42
54
|
const args = [
|
|
43
55
|
txb.object(this.deepbookV3Config),
|
|
44
56
|
txb.object(path.id),
|
|
45
57
|
inputCoin,
|
|
46
|
-
|
|
58
|
+
deepFee,
|
|
47
59
|
txb.object(CLOCK_ADDRESS),
|
|
48
60
|
]
|
|
49
61
|
const res = txb.moveCall({
|
package/src/transaction/index.ts
CHANGED
|
@@ -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
|
}
|
package/src/utils/api.ts
ADDED
package/src/utils/index.ts
CHANGED
package/tests/router.test.ts
CHANGED
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
M_SSWP,
|
|
9
9
|
M_SUI,
|
|
10
10
|
M_USDC,
|
|
11
|
+
T_DBUSDC,
|
|
12
|
+
T_DBUSDT,
|
|
13
|
+
T_DEEP,
|
|
11
14
|
} from "./test_data.test"
|
|
12
15
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
13
16
|
import { printTransaction } from "~/utils/transaction"
|
|
@@ -40,12 +43,12 @@ describe("router module", () => {
|
|
|
40
43
|
keypair = buildTestAccount()
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
44
47
|
|
|
45
48
|
// console.log("wallet", wallet, "\n", wallet.toString())
|
|
46
49
|
|
|
47
|
-
const wallet =
|
|
48
|
-
|
|
50
|
+
// const wallet =
|
|
51
|
+
// "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
|
|
49
52
|
// const wallet =
|
|
50
53
|
// "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
|
|
51
54
|
// const wallet =
|
|
@@ -69,12 +72,15 @@ describe("router module", () => {
|
|
|
69
72
|
publishedAt:
|
|
70
73
|
"0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
|
|
71
74
|
}
|
|
75
|
+
// const endpoint =
|
|
76
|
+
// "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
72
77
|
const endpoint =
|
|
73
|
-
"https://api-sui
|
|
78
|
+
"https://api-sui.devcetus.com/router_v2/find_routes"
|
|
79
|
+
|
|
74
80
|
const suiClient = new SuiClient({
|
|
75
|
-
url: "https://fullnode.
|
|
81
|
+
url: "https://fullnode.testnet.sui.io:443",
|
|
76
82
|
})
|
|
77
|
-
client = new AggregatorClient(endpoint, wallet, suiClient, Env.
|
|
83
|
+
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Testnet)
|
|
78
84
|
})
|
|
79
85
|
|
|
80
86
|
test("Get all coins", () => {
|
|
@@ -135,15 +141,9 @@ describe("router module", () => {
|
|
|
135
141
|
|
|
136
142
|
test("Build router tx", async () => {
|
|
137
143
|
const byAmountIn = true
|
|
138
|
-
const amount = "
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
// const target =
|
|
142
|
-
// "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
143
|
-
// const target =
|
|
144
|
-
// "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
145
|
-
|
|
146
|
-
const target = M_USDC
|
|
144
|
+
const amount = "20000000000"
|
|
145
|
+
const from = T_DBUSDC
|
|
146
|
+
const target = T_DBUSDT
|
|
147
147
|
|
|
148
148
|
const res = await client.findRouters({
|
|
149
149
|
from,
|
|
@@ -152,14 +152,14 @@ describe("router module", () => {
|
|
|
152
152
|
byAmountIn,
|
|
153
153
|
depth: 3,
|
|
154
154
|
providers: [
|
|
155
|
-
|
|
155
|
+
"CETUS",
|
|
156
|
+
"DEEPBOOKV3",
|
|
156
157
|
// "DEEPBOOK",
|
|
157
158
|
// "AFTERMATH",
|
|
158
159
|
// "FLOWX",
|
|
159
160
|
// "KRIYA",
|
|
160
161
|
// "KRIYAV3",
|
|
161
162
|
// "TURBOS",
|
|
162
|
-
"BLUEMOVE",
|
|
163
163
|
],
|
|
164
164
|
})
|
|
165
165
|
|
|
@@ -188,13 +188,13 @@ describe("router module", () => {
|
|
|
188
188
|
let result = await client.devInspectTransactionBlock(txb)
|
|
189
189
|
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
190
190
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
+
}
|
|
198
198
|
}
|
|
199
199
|
}, 600000)
|
|
200
200
|
|
|
@@ -348,9 +348,6 @@ describe("router module", () => {
|
|
|
348
348
|
console.log(JSON.stringify(res, null, 2))
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
console.log("amount in", res?.amountIn.toString())
|
|
352
|
-
console.log("amount out", res?.amountOut.toString())
|
|
353
|
-
|
|
354
351
|
const txb = new Transaction()
|
|
355
352
|
|
|
356
353
|
if (res != null) {
|
|
@@ -378,4 +375,9 @@ describe("router module", () => {
|
|
|
378
375
|
// }
|
|
379
376
|
}
|
|
380
377
|
}, 600000)
|
|
378
|
+
|
|
379
|
+
test("Get deepbook v3 config", async () => {
|
|
380
|
+
const config = await client.getDeepbookV3Config()
|
|
381
|
+
console.log("config", config)
|
|
382
|
+
}, 60000)
|
|
381
383
|
})
|
package/tests/test_data.test.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// Testnet
|
|
2
2
|
export const T_USDC = ""
|
|
3
|
+
export const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
4
|
+
export const T_DBUSDC = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDC::DBUSDC"
|
|
5
|
+
export const T_DBUSDT = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDT::DBUSDT"
|
|
3
6
|
|
|
4
7
|
// Mainnet
|
|
5
8
|
export const M_USDC =
|