@cetusprotocol/aggregator-sdk 0.3.32 → 0.4.1
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/README.md +19 -8
- package/dist/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +211 -33
- package/dist/index.mjs +211 -34
- package/dist/src/api.d.ts +5 -1
- package/dist/src/client.d.ts +15 -1
- package/dist/src/transaction/obric.d.ts +8 -0
- package/dist/tests/router/alphafi.test.d.ts +2 -0
- package/dist/tests/router/obric.test.d.ts +2 -0
- package/package.json +1 -1
- package/src/api.ts +12 -3
- package/src/client.ts +184 -31
- package/src/transaction/obric.ts +90 -0
- package/tests/router/alphafi.test.ts +132 -0
- package/tests/router/metastable.test.ts +7 -1
- package/tests/router/obric.test.ts +203 -0
- package/tests/router/scallop.test.ts +7 -1
- package/tests/router/steamm.test.ts +7 -1
- package/tests/router.test.ts +7 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { describe, test } from "@jest/globals"
|
|
2
|
+
import dotenv from "dotenv"
|
|
3
|
+
import { AggregatorClient } from "~/client"
|
|
4
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
5
|
+
import { printTransaction } from "~/utils/transaction"
|
|
6
|
+
import BN from "bn.js"
|
|
7
|
+
import { fromB64 } from "@mysten/sui/utils"
|
|
8
|
+
import { SuiClient } from "@mysten/sui/client"
|
|
9
|
+
import { Env } from "~/index"
|
|
10
|
+
import { Transaction } from "@mysten/sui/transactions"
|
|
11
|
+
|
|
12
|
+
dotenv.config()
|
|
13
|
+
|
|
14
|
+
export function buildTestAccount(): Ed25519Keypair {
|
|
15
|
+
const mnemonics = process.env.SUI_WALLET_MNEMONICS || ""
|
|
16
|
+
const testAccountObject = Ed25519Keypair.deriveKeypair(mnemonics)
|
|
17
|
+
return testAccountObject
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("Test obric provider", () => {
|
|
21
|
+
let client: AggregatorClient
|
|
22
|
+
let keypair: Ed25519Keypair
|
|
23
|
+
|
|
24
|
+
const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
|
|
25
|
+
const WH_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
|
|
26
|
+
const T_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
27
|
+
|
|
28
|
+
beforeAll(() => {
|
|
29
|
+
const fullNodeURL = process.env.SUI_RPC!
|
|
30
|
+
const aggregatorURL = process.env.CETUS_AGGREGATOR!
|
|
31
|
+
const secret = process.env.SUI_WALLET_SECRET!
|
|
32
|
+
|
|
33
|
+
if (secret) {
|
|
34
|
+
keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
|
|
35
|
+
} else {
|
|
36
|
+
keypair = buildTestAccount()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// const wallet = keypair.getPublicKey().toSuiAddress()
|
|
40
|
+
|
|
41
|
+
const wallet = "0x935029ca5219502a47ac9b69f556ccf6e2198b5e7815cf50f68846f723739cbd" // has 80 eth
|
|
42
|
+
console.log("wallet: ", wallet)
|
|
43
|
+
|
|
44
|
+
const endpoint = aggregatorURL
|
|
45
|
+
|
|
46
|
+
const suiClient = new SuiClient({
|
|
47
|
+
url: fullNodeURL,
|
|
48
|
+
})
|
|
49
|
+
client = new AggregatorClient({
|
|
50
|
+
endpoint,
|
|
51
|
+
signer: wallet,
|
|
52
|
+
client: suiClient,
|
|
53
|
+
env: Env.Mainnet,
|
|
54
|
+
pythUrls: ["https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes"],
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test("Find Routers --> SUI -> USDC, locked", async () => {
|
|
59
|
+
// const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
|
|
60
|
+
const amounts = ["9990", "5000000000"]
|
|
61
|
+
|
|
62
|
+
for (const amount of amounts) {
|
|
63
|
+
const res = await client.findRouters({
|
|
64
|
+
from: T_SUI,
|
|
65
|
+
target: WH_USDC,
|
|
66
|
+
amount: new BN(amount),
|
|
67
|
+
byAmountIn: true,
|
|
68
|
+
depth: 3,
|
|
69
|
+
splitCount: 1,
|
|
70
|
+
providers: ["OBRIC"],
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
if (res != null) {
|
|
74
|
+
console.log(JSON.stringify(res, null, 2))
|
|
75
|
+
}
|
|
76
|
+
console.log("amount in", res?.amountIn.toString())
|
|
77
|
+
console.log("amount out", res?.amountOut.toString())
|
|
78
|
+
|
|
79
|
+
const txb = new Transaction()
|
|
80
|
+
|
|
81
|
+
if (res != null) {
|
|
82
|
+
console.log(JSON.stringify(res, null, 2))
|
|
83
|
+
await client.fastRouterSwap({
|
|
84
|
+
routers: res,
|
|
85
|
+
txb,
|
|
86
|
+
slippage: 0.01,
|
|
87
|
+
refreshAllCoins: true,
|
|
88
|
+
payDeepFeeAmount: 0,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
txb.setSender(client.signer)
|
|
92
|
+
const buildTxb = await txb.build({ client: client.client })
|
|
93
|
+
// const buildTxb = await txb.getData()
|
|
94
|
+
|
|
95
|
+
console.log("buildTxb", buildTxb)
|
|
96
|
+
printTransaction(txb)
|
|
97
|
+
|
|
98
|
+
let result = await client.devInspectTransactionBlock(txb)
|
|
99
|
+
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
100
|
+
for (const event of result.events) {
|
|
101
|
+
console.log("event", JSON.stringify(event, null, 2))
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, 50000)
|
|
106
|
+
|
|
107
|
+
test("Find Routers --> WUSDC --> SUI, no pyth mode", async () => {
|
|
108
|
+
// const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
|
|
109
|
+
// const amounts = ["1000", "1000000", "900000000"]
|
|
110
|
+
const amounts = ["90000000"]
|
|
111
|
+
|
|
112
|
+
for (const amount of amounts) {
|
|
113
|
+
const res = await client.findRouters({
|
|
114
|
+
from: T_USDC,
|
|
115
|
+
target: T_SUI,
|
|
116
|
+
amount: new BN(amount),
|
|
117
|
+
byAmountIn: true,
|
|
118
|
+
depth: 3,
|
|
119
|
+
splitCount: 1,
|
|
120
|
+
providers: ["OBRIC"],
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
if (res != null) {
|
|
124
|
+
console.log(JSON.stringify(res, null, 2))
|
|
125
|
+
}
|
|
126
|
+
console.log("amount in", res?.amountIn.toString())
|
|
127
|
+
console.log("amount out", res?.amountOut.toString())
|
|
128
|
+
|
|
129
|
+
const txb = new Transaction()
|
|
130
|
+
|
|
131
|
+
if (res != null) {
|
|
132
|
+
await client.fastRouterSwap({
|
|
133
|
+
routers: res,
|
|
134
|
+
txb,
|
|
135
|
+
slippage: 0.001,
|
|
136
|
+
refreshAllCoins: true,
|
|
137
|
+
payDeepFeeAmount: 0,
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
txb.setSender(client.signer)
|
|
141
|
+
const buildTxb = await txb.build({ client: client.client })
|
|
142
|
+
// const buildTxb = await txb.getData()
|
|
143
|
+
|
|
144
|
+
// printTransaction(txb)
|
|
145
|
+
|
|
146
|
+
let result = await client.devInspectTransactionBlock(txb)
|
|
147
|
+
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
148
|
+
for (const event of result.events) {
|
|
149
|
+
console.log("event", JSON.stringify(event, null, 2))
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test("Build Router TX", async () => {
|
|
156
|
+
const amount = "1000000"
|
|
157
|
+
|
|
158
|
+
const res = await client.findRouters({
|
|
159
|
+
from: T_USDC,
|
|
160
|
+
target: T_SUI,
|
|
161
|
+
amount: new BN(amount),
|
|
162
|
+
byAmountIn: true,
|
|
163
|
+
depth: 3,
|
|
164
|
+
providers: ["OBRIC"],
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
console.log("amount in", res?.amountIn.toString())
|
|
168
|
+
console.log("amount out", res?.amountOut.toString())
|
|
169
|
+
|
|
170
|
+
const txb = new Transaction()
|
|
171
|
+
|
|
172
|
+
if (res != null) {
|
|
173
|
+
console.log(JSON.stringify(res, null, 2))
|
|
174
|
+
await client.fastRouterSwap({
|
|
175
|
+
routers: res,
|
|
176
|
+
txb,
|
|
177
|
+
slippage: 0.01,
|
|
178
|
+
refreshAllCoins: true,
|
|
179
|
+
payDeepFeeAmount: 0,
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
txb.setSender(client.signer)
|
|
183
|
+
const buildTxb = await txb.build({ client: client.client })
|
|
184
|
+
// const buildTxb = await txb.getData()
|
|
185
|
+
|
|
186
|
+
console.log("buildTxb", buildTxb)
|
|
187
|
+
// printTransaction(txb)
|
|
188
|
+
|
|
189
|
+
let result = await client.devInspectTransactionBlock(txb)
|
|
190
|
+
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
191
|
+
for (const event of result.events) {
|
|
192
|
+
console.log("event", JSON.stringify(event, null, 2))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// if (result.effects.status.status === "success") {
|
|
196
|
+
// const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
197
|
+
// console.log("result", result)
|
|
198
|
+
// } else {
|
|
199
|
+
// console.log("result", result)
|
|
200
|
+
// }
|
|
201
|
+
}
|
|
202
|
+
}, 600000)
|
|
203
|
+
})
|
|
@@ -50,7 +50,13 @@ describe("Test scallop provider", () => {
|
|
|
50
50
|
url: fullNodeURL,
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
client = new AggregatorClient(
|
|
53
|
+
client = new AggregatorClient({
|
|
54
|
+
endpoint,
|
|
55
|
+
signer: wallet,
|
|
56
|
+
client: suiClient,
|
|
57
|
+
env: Env.Mainnet,
|
|
58
|
+
pythUrls: ["https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes"],
|
|
59
|
+
})
|
|
54
60
|
})
|
|
55
61
|
|
|
56
62
|
test("Find Routers", async () => {
|
|
@@ -47,7 +47,13 @@ describe("Test steammfe module", () => {
|
|
|
47
47
|
url: fullNodeURL,
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
client = new AggregatorClient(
|
|
50
|
+
client = new AggregatorClient({
|
|
51
|
+
endpoint,
|
|
52
|
+
signer: wallet,
|
|
53
|
+
client: suiClient,
|
|
54
|
+
env: Env.Mainnet,
|
|
55
|
+
pythUrls: ["https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes"],
|
|
56
|
+
})
|
|
51
57
|
})
|
|
52
58
|
|
|
53
59
|
test("Find Routers", async () => {
|
package/tests/router.test.ts
CHANGED
|
@@ -43,7 +43,13 @@ describe("router module", () => {
|
|
|
43
43
|
url: fullNodeURL,
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
client = new AggregatorClient(
|
|
46
|
+
client = new AggregatorClient({
|
|
47
|
+
endpoint,
|
|
48
|
+
signer: wallet,
|
|
49
|
+
client: suiClient,
|
|
50
|
+
env: Env.Mainnet,
|
|
51
|
+
pythUrls: ["https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes"],
|
|
52
|
+
})
|
|
47
53
|
})
|
|
48
54
|
|
|
49
55
|
test("Get coins", () => {
|