@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241010160019 → 0.0.0-experimental-20241011205228
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 +3 -25
- package/dist/index.d.ts +3 -25
- package/dist/index.js +17 -104
- package/dist/index.mjs +17 -101
- package/dist/src/api.d.ts +0 -15
- package/dist/src/client.d.ts +2 -7
- package/dist/src/transaction/index.d.ts +1 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/tests/test_data.test.d.ts +0 -1
- package/package.json +1 -1
- package/src/api.ts +7 -32
- package/src/client.ts +10 -44
- package/src/transaction/afsui.ts +1 -0
- package/src/transaction/aftermath.ts +2 -0
- package/src/transaction/deepbook_v2.ts +1 -0
- package/src/transaction/index.ts +1 -2
- package/src/utils/index.ts +0 -1
- package/tests/router.test.ts +26 -26
- package/tests/test_data.test.ts +0 -1
- package/dist/src/transaction/deepbook_v3.d.ts +0 -13
- package/dist/src/utils/api.d.ts +0 -1
- package/src/transaction/deepbook_v3.ts +0 -68
- package/src/utils/api.ts +0 -6
- package/test.json +0 -5
package/tests/router.test.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
M_SSWP,
|
|
9
9
|
M_SUI,
|
|
10
10
|
M_USDC,
|
|
11
|
-
T_DEEP,
|
|
12
11
|
} from "./test_data.test"
|
|
13
12
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
14
13
|
import { printTransaction } from "~/utils/transaction"
|
|
@@ -41,12 +40,12 @@ describe("router module", () => {
|
|
|
41
40
|
keypair = buildTestAccount()
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
43
|
+
// const wallet = keypair.getPublicKey().toSuiAddress()
|
|
45
44
|
|
|
46
45
|
// console.log("wallet", wallet, "\n", wallet.toString())
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const wallet =
|
|
48
|
+
"0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
|
|
50
49
|
// const wallet =
|
|
51
50
|
// "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
|
|
52
51
|
// const wallet =
|
|
@@ -70,15 +69,12 @@ describe("router module", () => {
|
|
|
70
69
|
publishedAt:
|
|
71
70
|
"0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
|
|
72
71
|
}
|
|
73
|
-
// const endpoint =
|
|
74
|
-
// "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
75
72
|
const endpoint =
|
|
76
|
-
"
|
|
77
|
-
|
|
73
|
+
"https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
|
|
78
74
|
const suiClient = new SuiClient({
|
|
79
|
-
url: "https://fullnode.
|
|
75
|
+
url: "https://fullnode.mainnet.sui.io:443",
|
|
80
76
|
})
|
|
81
|
-
client = new AggregatorClient(endpoint, wallet, suiClient, Env.
|
|
77
|
+
client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
|
|
82
78
|
})
|
|
83
79
|
|
|
84
80
|
test("Get all coins", () => {
|
|
@@ -139,9 +135,15 @@ describe("router module", () => {
|
|
|
139
135
|
|
|
140
136
|
test("Build router tx", async () => {
|
|
141
137
|
const byAmountIn = true
|
|
142
|
-
const amount = "
|
|
138
|
+
const amount = "1000000000"
|
|
139
|
+
|
|
143
140
|
const from = M_SUI
|
|
144
|
-
const target =
|
|
141
|
+
// const target =
|
|
142
|
+
// "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
143
|
+
// const target =
|
|
144
|
+
// "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
145
|
+
|
|
146
|
+
const target = M_USDC
|
|
145
147
|
|
|
146
148
|
const res = await client.findRouters({
|
|
147
149
|
from,
|
|
@@ -150,14 +152,14 @@ describe("router module", () => {
|
|
|
150
152
|
byAmountIn,
|
|
151
153
|
depth: 3,
|
|
152
154
|
providers: [
|
|
153
|
-
"CETUS",
|
|
155
|
+
// "CETUS",
|
|
154
156
|
// "DEEPBOOK",
|
|
155
157
|
// "AFTERMATH",
|
|
156
158
|
// "FLOWX",
|
|
157
159
|
// "KRIYA",
|
|
158
160
|
// "KRIYAV3",
|
|
159
161
|
// "TURBOS",
|
|
160
|
-
"
|
|
162
|
+
"BLUEMOVE",
|
|
161
163
|
],
|
|
162
164
|
})
|
|
163
165
|
|
|
@@ -186,13 +188,13 @@ describe("router module", () => {
|
|
|
186
188
|
let result = await client.devInspectTransactionBlock(txb)
|
|
187
189
|
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
188
190
|
|
|
189
|
-
if (result.effects.status.status === "success") {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
} else {
|
|
194
|
-
|
|
195
|
-
}
|
|
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
|
+
// }
|
|
196
198
|
}
|
|
197
199
|
}, 600000)
|
|
198
200
|
|
|
@@ -346,6 +348,9 @@ describe("router module", () => {
|
|
|
346
348
|
console.log(JSON.stringify(res, null, 2))
|
|
347
349
|
}
|
|
348
350
|
|
|
351
|
+
console.log("amount in", res?.amountIn.toString())
|
|
352
|
+
console.log("amount out", res?.amountOut.toString())
|
|
353
|
+
|
|
349
354
|
const txb = new Transaction()
|
|
350
355
|
|
|
351
356
|
if (res != null) {
|
|
@@ -373,9 +378,4 @@ describe("router module", () => {
|
|
|
373
378
|
// }
|
|
374
379
|
}
|
|
375
380
|
}, 600000)
|
|
376
|
-
|
|
377
|
-
test("Get deepbook v3 config", async () => {
|
|
378
|
-
const config = await client.getDeepbookV3Config()
|
|
379
|
-
console.log("config", config)
|
|
380
|
-
}, 60000)
|
|
381
381
|
})
|
package/tests/test_data.test.ts
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
-
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
-
export type CetusFlashSwapResult = {
|
|
4
|
-
targetCoin: TransactionObjectArgument;
|
|
5
|
-
flashReceipt: TransactionObjectArgument;
|
|
6
|
-
payAmount: TransactionArgument;
|
|
7
|
-
};
|
|
8
|
-
export declare class DeepbookV3 implements Dex {
|
|
9
|
-
private deepbookV3Config;
|
|
10
|
-
private deepCoinType;
|
|
11
|
-
constructor(env: Env);
|
|
12
|
-
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
13
|
-
}
|
package/dist/src/utils/api.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function processEndpoint(endpoint: string): string;
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
}
|
package/src/utils/api.ts
DELETED
package/test.json
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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
|
-
]
|