@cetusprotocol/aggregator-sdk 0.4.1 → 0.4.3
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.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/.env.example +0 -4
- package/bun.lockb +0 -0
- package/dist/src/api.d.ts +0 -104
- package/dist/src/client.d.ts +0 -118
- package/dist/src/const.d.ts +0 -8
- package/dist/src/errors.d.ts +0 -40
- package/dist/src/index.d.ts +0 -9
- package/dist/src/math.d.ts +0 -6
- package/dist/src/transaction/afsui.d.ts +0 -10
- package/dist/src/transaction/aftermath.d.ts +0 -13
- package/dist/src/transaction/alphafi.d.ts +0 -7
- package/dist/src/transaction/bluefin.d.ts +0 -7
- package/dist/src/transaction/bluemove.d.ts +0 -7
- package/dist/src/transaction/cetus.d.ts +0 -15
- package/dist/src/transaction/deepbook_v2.d.ts +0 -14
- package/dist/src/transaction/deepbook_v3.d.ts +0 -12
- package/dist/src/transaction/flowx_v2.d.ts +0 -7
- package/dist/src/transaction/flowx_v3.d.ts +0 -8
- package/dist/src/transaction/haedal.d.ts +0 -6
- package/dist/src/transaction/haedal_pmm.d.ts +0 -7
- package/dist/src/transaction/index.d.ts +0 -10
- package/dist/src/transaction/kriya_v2.d.ts +0 -6
- package/dist/src/transaction/kriya_v3.d.ts +0 -7
- package/dist/src/transaction/metastable.d.ts +0 -8
- package/dist/src/transaction/obric.d.ts +0 -8
- package/dist/src/transaction/scallop.d.ts +0 -8
- package/dist/src/transaction/steamm.d.ts +0 -6
- package/dist/src/transaction/suilend.d.ts +0 -7
- package/dist/src/transaction/swap.d.ts +0 -4
- package/dist/src/transaction/turbos.d.ts +0 -7
- package/dist/src/transaction/volo.d.ts +0 -8
- package/dist/src/types/CoinAssist.d.ts +0 -122
- package/dist/src/types/sui.d.ts +0 -112
- package/dist/src/utils/api.d.ts +0 -1
- package/dist/src/utils/coin.d.ts +0 -11
- package/dist/src/utils/contracts.d.ts +0 -16
- package/dist/src/utils/index.d.ts +0 -5
- package/dist/src/utils/msafe.d.ts +0 -2
- package/dist/src/utils/transaction.d.ts +0 -3
- package/dist/tests/math.test.d.ts +0 -1
- package/dist/tests/router/alphafi.test.d.ts +0 -2
- package/dist/tests/router/metastable.test.d.ts +0 -2
- package/dist/tests/router/obric.test.d.ts +0 -2
- package/dist/tests/router/scallop.test.d.ts +0 -2
- package/dist/tests/router/steamm.test.d.ts +0 -2
- package/dist/tests/router.test.d.ts +0 -2
- package/dist/tests/test_data.test.d.ts +0 -18
- package/dist/tests/wallet.test.d.ts +0 -1
- package/example/package.json +0 -17
- package/example/swap.ts +0 -21
- package/example/tsconfig.json +0 -12
- package/jest.config.mjs +0 -13
- package/src/api.ts +0 -325
- package/src/client.ts +0 -1081
- package/src/const.ts +0 -15
- package/src/errors.ts +0 -77
- package/src/index.ts +0 -10
- package/src/math.ts +0 -66
- package/src/transaction/afsui.ts +0 -62
- package/src/transaction/aftermath.ts +0 -88
- package/src/transaction/alphafi.ts +0 -50
- package/src/transaction/bluefin.ts +0 -46
- package/src/transaction/bluemove.ts +0 -42
- package/src/transaction/cetus.ts +0 -118
- package/src/transaction/deepbook_v2.ts +0 -122
- package/src/transaction/deepbook_v3.ts +0 -60
- package/src/transaction/flowx_v2.ts +0 -42
- package/src/transaction/flowx_v3.ts +0 -52
- package/src/transaction/haedal.ts +0 -33
- package/src/transaction/haedal_pmm.ts +0 -80
- package/src/transaction/index.ts +0 -42
- package/src/transaction/kriya_v2.ts +0 -37
- package/src/transaction/kriya_v3.ts +0 -47
- package/src/transaction/metastable.ts +0 -141
- package/src/transaction/obric.ts +0 -90
- package/src/transaction/scallop.ts +0 -64
- package/src/transaction/steamm.ts +0 -77
- package/src/transaction/suilend.ts +0 -48
- package/src/transaction/swap.ts +0 -162
- package/src/transaction/turbos.ts +0 -56
- package/src/transaction/volo.ts +0 -53
- package/src/types/CoinAssist.ts +0 -217
- package/src/types/sui.ts +0 -148
- package/src/utils/api.ts +0 -6
- package/src/utils/coin.ts +0 -136
- package/src/utils/contracts.ts +0 -136
- package/src/utils/index.ts +0 -5
- package/src/utils/msafe.ts +0 -40
- package/src/utils/transaction.ts +0 -20
- package/tests/math.test.ts +0 -21
- package/tests/router/alphafi.test.ts +0 -132
- package/tests/router/metastable.test.ts +0 -383
- package/tests/router/obric.test.ts +0 -203
- package/tests/router/scallop.test.ts +0 -133
- package/tests/router/steamm.test.ts +0 -130
- package/tests/router.test.ts +0 -379
- package/tests/test_data.test.ts +0 -28
- package/tests/wallet.test.ts +0 -21
- package/tsup.config.ts +0 -23
- package/version.mjs +0 -28
|
@@ -1,133 +0,0 @@
|
|
|
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 scallop provider", () => {
|
|
21
|
-
let client: AggregatorClient
|
|
22
|
-
let keypair: Ed25519Keypair
|
|
23
|
-
|
|
24
|
-
const T_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
25
|
-
const T_SHASUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI"
|
|
26
|
-
|
|
27
|
-
const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
|
|
28
|
-
const T_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
|
|
29
|
-
|
|
30
|
-
beforeAll(() => {
|
|
31
|
-
const fullNodeURL = process.env.SUI_RPC!
|
|
32
|
-
const aggregatorURL = process.env.CETUS_AGGREGATOR!
|
|
33
|
-
const secret = process.env.SUI_WALLET_SECRET!
|
|
34
|
-
|
|
35
|
-
if (secret) {
|
|
36
|
-
keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
|
|
37
|
-
} else {
|
|
38
|
-
keypair = buildTestAccount()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// const wallet = keypair.getPublicKey().toSuiAddress()
|
|
42
|
-
const wallet =
|
|
43
|
-
"0xf077fa7f67b1f2d417bbe977b3cbc113b078907f74e04120f623b87b23e93963"
|
|
44
|
-
|
|
45
|
-
console.log("wallet: ", wallet)
|
|
46
|
-
|
|
47
|
-
const endpoint = aggregatorURL
|
|
48
|
-
|
|
49
|
-
const suiClient = new SuiClient({
|
|
50
|
-
url: fullNodeURL,
|
|
51
|
-
})
|
|
52
|
-
|
|
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
|
-
})
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test("Find Routers", async () => {
|
|
63
|
-
const amounts = ["1000", "1000000", "100000000", "5000000000", "1000000000000000000000000000"]
|
|
64
|
-
|
|
65
|
-
while (true) {
|
|
66
|
-
const res = await client.findRouters({
|
|
67
|
-
from: T_SUI,
|
|
68
|
-
target: T_SSUI,
|
|
69
|
-
amount: new BN("1000000000000000000000000000"),
|
|
70
|
-
byAmountIn: true,
|
|
71
|
-
depth: 3,
|
|
72
|
-
splitCount: 1,
|
|
73
|
-
providers: ["SCALLOP"],
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
if (res != null) {
|
|
77
|
-
console.log(JSON.stringify(res, null, 2))
|
|
78
|
-
}
|
|
79
|
-
console.log("amount in", res?.amountIn.toString())
|
|
80
|
-
console.log("amount out", res?.amountOut.toString())
|
|
81
|
-
}
|
|
82
|
-
}, 6000000)
|
|
83
|
-
|
|
84
|
-
test("Build Router TX", async () => {
|
|
85
|
-
const amount = "10000000"
|
|
86
|
-
|
|
87
|
-
const res = await client.findRouters({
|
|
88
|
-
from: T_HASUI,
|
|
89
|
-
target: T_SHASUI,
|
|
90
|
-
amount: new BN(amount),
|
|
91
|
-
byAmountIn: true,
|
|
92
|
-
depth: 3,
|
|
93
|
-
providers: ["SCALLOP"],
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
console.log("amount in", res?.amountIn.toString())
|
|
97
|
-
console.log("amount out", res?.amountOut.toString())
|
|
98
|
-
|
|
99
|
-
const txb = new Transaction()
|
|
100
|
-
|
|
101
|
-
if (res != null) {
|
|
102
|
-
console.log(JSON.stringify(res, null, 2))
|
|
103
|
-
await client.fastRouterSwap({
|
|
104
|
-
routers: res,
|
|
105
|
-
txb,
|
|
106
|
-
slippage: 0.01,
|
|
107
|
-
refreshAllCoins: true,
|
|
108
|
-
payDeepFeeAmount: 0,
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
txb.setSender(client.signer)
|
|
112
|
-
const buildTxb = await txb.build({ client: client.client })
|
|
113
|
-
// const buildTxb = await txb.getData()
|
|
114
|
-
|
|
115
|
-
console.log("buildTxb", buildTxb)
|
|
116
|
-
|
|
117
|
-
printTransaction(txb)
|
|
118
|
-
|
|
119
|
-
let result = await client.devInspectTransactionBlock(txb)
|
|
120
|
-
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
121
|
-
for (const event of result.events) {
|
|
122
|
-
console.log("event", JSON.stringify(event, null, 2))
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (result.effects.status.status === "success") {
|
|
126
|
-
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
127
|
-
console.log("result", result)
|
|
128
|
-
} else {
|
|
129
|
-
console.log("result", result)
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}, 600000)
|
|
133
|
-
})
|
|
@@ -1,130 +0,0 @@
|
|
|
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 steammfe module", () => {
|
|
21
|
-
let client: AggregatorClient
|
|
22
|
-
let keypair: Ed25519Keypair
|
|
23
|
-
|
|
24
|
-
const T_SUI = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
25
|
-
const T_USDC = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
|
|
26
|
-
|
|
27
|
-
beforeAll(() => {
|
|
28
|
-
const fullNodeURL = process.env.SUI_RPC!
|
|
29
|
-
const aggregatorURL = process.env.CETUS_AGGREGATOR!
|
|
30
|
-
const secret = process.env.SUI_WALLET_SECRET!
|
|
31
|
-
|
|
32
|
-
if (secret) {
|
|
33
|
-
keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
|
|
34
|
-
} else {
|
|
35
|
-
keypair = buildTestAccount()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
39
|
-
// const wallet =
|
|
40
|
-
// "0xb0deeb083fb5738e2d76820a3e59a284adbd56ab1b1d71d606cda8ea71cffe90"
|
|
41
|
-
|
|
42
|
-
console.log("wallet: ", wallet)
|
|
43
|
-
|
|
44
|
-
const endpoint = aggregatorURL
|
|
45
|
-
|
|
46
|
-
const suiClient = new SuiClient({
|
|
47
|
-
url: fullNodeURL,
|
|
48
|
-
})
|
|
49
|
-
|
|
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
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
test("Find Routers", async () => {
|
|
60
|
-
const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
|
|
61
|
-
|
|
62
|
-
for (const amount of amounts) {
|
|
63
|
-
const res = await client.findRouters({
|
|
64
|
-
from: T_USDC,
|
|
65
|
-
target: T_SUI,
|
|
66
|
-
amount: new BN(amount),
|
|
67
|
-
byAmountIn: true,
|
|
68
|
-
depth: 3,
|
|
69
|
-
splitCount: 1,
|
|
70
|
-
providers: ["STEAMMFE"],
|
|
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
|
-
})
|
|
80
|
-
|
|
81
|
-
test("Build Router TX", async () => {
|
|
82
|
-
const amount = "10000000"
|
|
83
|
-
|
|
84
|
-
const res = await client.findRouters({
|
|
85
|
-
from: T_USDC,
|
|
86
|
-
target: T_SUI,
|
|
87
|
-
amount: new BN(amount),
|
|
88
|
-
byAmountIn: true,
|
|
89
|
-
depth: 3,
|
|
90
|
-
providers: ["STEAMM"],
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
console.log("amount in", res?.amountIn.toString())
|
|
94
|
-
console.log("amount out", res?.amountOut.toString())
|
|
95
|
-
|
|
96
|
-
const txb = new Transaction()
|
|
97
|
-
|
|
98
|
-
if (res != null) {
|
|
99
|
-
console.log(JSON.stringify(res, null, 2))
|
|
100
|
-
await client.fastRouterSwap({
|
|
101
|
-
routers: res,
|
|
102
|
-
txb,
|
|
103
|
-
slippage: 0.01,
|
|
104
|
-
refreshAllCoins: true,
|
|
105
|
-
payDeepFeeAmount: 0,
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
txb.setSender(client.signer)
|
|
109
|
-
const buildTxb = await txb.build({ client: client.client })
|
|
110
|
-
// const buildTxb = await txb.getData()
|
|
111
|
-
|
|
112
|
-
console.log("buildTxb", buildTxb)
|
|
113
|
-
|
|
114
|
-
printTransaction(txb)
|
|
115
|
-
|
|
116
|
-
let result = await client.devInspectTransactionBlock(txb)
|
|
117
|
-
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
118
|
-
for (const event of result.events) {
|
|
119
|
-
console.log("event", JSON.stringify(event, null, 2))
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (result.effects.status.status === "success") {
|
|
123
|
-
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
124
|
-
console.log("result", result)
|
|
125
|
-
} else {
|
|
126
|
-
console.log("result", result)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, 600000)
|
|
130
|
-
})
|
package/tests/router.test.ts
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
import { describe, test } from "@jest/globals"
|
|
2
|
-
import dotenv from "dotenv"
|
|
3
|
-
import { AggregatorClient } from "~/client"
|
|
4
|
-
import * as testData from "./test_data.test"
|
|
5
|
-
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
6
|
-
import { printTransaction } from "~/utils/transaction"
|
|
7
|
-
import BN from "bn.js"
|
|
8
|
-
import { fromB64 } from "@mysten/sui/utils"
|
|
9
|
-
import { SuiClient } from "@mysten/sui/client"
|
|
10
|
-
import { Env } from "~/index"
|
|
11
|
-
import { Transaction } from "@mysten/sui/transactions"
|
|
12
|
-
|
|
13
|
-
dotenv.config()
|
|
14
|
-
|
|
15
|
-
export function buildTestAccount(): Ed25519Keypair {
|
|
16
|
-
const mnemonics = process.env.SUI_WALLET_MNEMONICS || ""
|
|
17
|
-
const testAccountObject = Ed25519Keypair.deriveKeypair(mnemonics)
|
|
18
|
-
return testAccountObject
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe("router module", () => {
|
|
22
|
-
let client: AggregatorClient
|
|
23
|
-
let keypair: Ed25519Keypair
|
|
24
|
-
|
|
25
|
-
beforeAll(() => {
|
|
26
|
-
const fullNodeURL = process.env.SUI_RPC!
|
|
27
|
-
const aggregatorURL = process.env.CETUS_AGGREGATOR!
|
|
28
|
-
const secret = process.env.SUI_WALLET_SECRET!
|
|
29
|
-
|
|
30
|
-
if (secret) {
|
|
31
|
-
keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
|
|
32
|
-
} else {
|
|
33
|
-
keypair = buildTestAccount()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
37
|
-
|
|
38
|
-
console.log("wallet: ", wallet)
|
|
39
|
-
|
|
40
|
-
const endpoint = aggregatorURL
|
|
41
|
-
|
|
42
|
-
const suiClient = new SuiClient({
|
|
43
|
-
url: fullNodeURL,
|
|
44
|
-
})
|
|
45
|
-
|
|
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
|
-
})
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
test("Get coins", () => {
|
|
56
|
-
return client.getCoins(testData.M_USDC).then((coins) => {
|
|
57
|
-
console.log(coins)
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test("Downgrade swap in route", async () => {
|
|
62
|
-
const amount = 1000000
|
|
63
|
-
const byAmountIn = true
|
|
64
|
-
|
|
65
|
-
const res: any = await client.swapInPools({
|
|
66
|
-
from: testData.M_SUI,
|
|
67
|
-
target: testData.M_USDC,
|
|
68
|
-
amount: new BN(amount),
|
|
69
|
-
byAmountIn,
|
|
70
|
-
pools: [
|
|
71
|
-
"0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105",
|
|
72
|
-
],
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
if (res != null) {
|
|
76
|
-
console.log(JSON.stringify(res, null, 2))
|
|
77
|
-
|
|
78
|
-
console.log("amount in", res.routeData.amountIn.toString())
|
|
79
|
-
console.log("amount out", res.routeData.amountOut.toString())
|
|
80
|
-
|
|
81
|
-
const txb = new Transaction()
|
|
82
|
-
await client.fastRouterSwap({
|
|
83
|
-
routers: res.routeData.routes,
|
|
84
|
-
byAmountIn,
|
|
85
|
-
txb,
|
|
86
|
-
slippage: 0.01,
|
|
87
|
-
refreshAllCoins: true,
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
printTransaction(txb)
|
|
91
|
-
|
|
92
|
-
let result = await client.devInspectTransactionBlock(txb)
|
|
93
|
-
console.log("🚀 ~ file: router.test.ts:114 ~ test ~ result:", result)
|
|
94
|
-
}
|
|
95
|
-
}, 60000)
|
|
96
|
-
|
|
97
|
-
test("Find router", async () => {
|
|
98
|
-
const amount = "4239267610000000000"
|
|
99
|
-
const res = await client.findRouters({
|
|
100
|
-
from: testData.M_SUI,
|
|
101
|
-
target: testData.M_USDC,
|
|
102
|
-
amount: new BN(amount),
|
|
103
|
-
byAmountIn: true,
|
|
104
|
-
depth: 3,
|
|
105
|
-
splitCount: 1,
|
|
106
|
-
providers: ["CETUS"],
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
if (res != null) {
|
|
110
|
-
console.log(JSON.stringify(res, null, 2))
|
|
111
|
-
}
|
|
112
|
-
console.log("amount in", res?.amountIn.toString())
|
|
113
|
-
console.log("amount out", res?.amountOut.toString())
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
test("Build router tx", async () => {
|
|
117
|
-
const byAmountIn = true
|
|
118
|
-
const amount = "100000"
|
|
119
|
-
const from =
|
|
120
|
-
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
121
|
-
const target = "0x2::sui::SUI"
|
|
122
|
-
|
|
123
|
-
const res = await client.findRouters({
|
|
124
|
-
from,
|
|
125
|
-
target,
|
|
126
|
-
amount: new BN(amount),
|
|
127
|
-
byAmountIn,
|
|
128
|
-
depth: 3,
|
|
129
|
-
providers: ["CETUS"],
|
|
130
|
-
splitCount: 1,
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
if (res != null) {
|
|
134
|
-
console.log(JSON.stringify(res, null, 2))
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
console.log("amount in", res?.amountIn.toString())
|
|
138
|
-
console.log("amount out", res?.amountOut.toString())
|
|
139
|
-
|
|
140
|
-
const txb = new Transaction()
|
|
141
|
-
|
|
142
|
-
if (res != null) {
|
|
143
|
-
console.log(JSON.stringify(res, null, 2))
|
|
144
|
-
await client.fastRouterSwap({
|
|
145
|
-
routers: res,
|
|
146
|
-
txb,
|
|
147
|
-
slippage: 0.01,
|
|
148
|
-
refreshAllCoins: true,
|
|
149
|
-
payDeepFeeAmount: 0,
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
printTransaction(txb)
|
|
153
|
-
|
|
154
|
-
let result = await client.devInspectTransactionBlock(txb)
|
|
155
|
-
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
156
|
-
for (const event of result.events) {
|
|
157
|
-
console.log("event", JSON.stringify(event, null, 2))
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (result.effects.status.status === "success") {
|
|
161
|
-
// console.log("Sim exec transaction success")
|
|
162
|
-
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
163
|
-
console.log("result", result)
|
|
164
|
-
} else {
|
|
165
|
-
console.log("result", result)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}, 600000)
|
|
169
|
-
|
|
170
|
-
test("By amount out", async () => {
|
|
171
|
-
const byAmountIn = false
|
|
172
|
-
const amount = "10000000000"
|
|
173
|
-
|
|
174
|
-
const from = testData.M_USDC
|
|
175
|
-
const target = testData.M_SSWP
|
|
176
|
-
|
|
177
|
-
const res = await client.findRouters({
|
|
178
|
-
from,
|
|
179
|
-
target,
|
|
180
|
-
amount: new BN(amount),
|
|
181
|
-
byAmountIn,
|
|
182
|
-
depth: 3,
|
|
183
|
-
providers: ["CETUS"],
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
console.log("amount in", res?.amountIn.toString())
|
|
187
|
-
console.log("amount out", res?.amountOut.toString())
|
|
188
|
-
|
|
189
|
-
const txb = new Transaction()
|
|
190
|
-
if (res != null) {
|
|
191
|
-
console.log(JSON.stringify(res, null, 2))
|
|
192
|
-
await client.fastRouterSwap({
|
|
193
|
-
routers: res.routes,
|
|
194
|
-
byAmountIn,
|
|
195
|
-
txb,
|
|
196
|
-
slippage: 0.02,
|
|
197
|
-
refreshAllCoins: true,
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
printTransaction(txb)
|
|
201
|
-
|
|
202
|
-
let result = await client.devInspectTransactionBlock(txb)
|
|
203
|
-
|
|
204
|
-
if (result.effects.status.status === "success") {
|
|
205
|
-
console.log("Sim exec transaction success")
|
|
206
|
-
// const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
207
|
-
// console.log("result", result)
|
|
208
|
-
} else {
|
|
209
|
-
console.log("result", result)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}, 600000)
|
|
213
|
-
|
|
214
|
-
test("Test Multi Input", async () => {
|
|
215
|
-
const amounts = [1000000000, 2000000000, 10000000000000]
|
|
216
|
-
const froms = [
|
|
217
|
-
testData.M_USDC,
|
|
218
|
-
testData.M_SUI,
|
|
219
|
-
testData.M_CETUS,
|
|
220
|
-
testData.M_NAVI,
|
|
221
|
-
]
|
|
222
|
-
const tos = [
|
|
223
|
-
testData.M_SUI,
|
|
224
|
-
testData.M_USDC,
|
|
225
|
-
testData.M_USDC,
|
|
226
|
-
testData.M_SUI,
|
|
227
|
-
]
|
|
228
|
-
|
|
229
|
-
for (let i = 0; i < froms.length; i++) {
|
|
230
|
-
const from = froms[i]
|
|
231
|
-
const target = tos[i]
|
|
232
|
-
for (const amount of amounts) {
|
|
233
|
-
for (const byAmountIn of [true, false]) {
|
|
234
|
-
console.log({
|
|
235
|
-
from,
|
|
236
|
-
target,
|
|
237
|
-
amount,
|
|
238
|
-
byAmountIn,
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
const res = await client.findRouters({
|
|
242
|
-
from,
|
|
243
|
-
target,
|
|
244
|
-
amount: new BN(amount),
|
|
245
|
-
byAmountIn,
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
const txb = new Transaction()
|
|
249
|
-
|
|
250
|
-
if (res != null) {
|
|
251
|
-
await client.fastRouterSwap({
|
|
252
|
-
routers: res.routes,
|
|
253
|
-
byAmountIn,
|
|
254
|
-
slippage: 0.01,
|
|
255
|
-
txb,
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
let result = await client.devInspectTransactionBlock(txb)
|
|
259
|
-
// console.log('result', result)
|
|
260
|
-
|
|
261
|
-
if (result.effects.status.status === "success") {
|
|
262
|
-
console.log("Sim exec transaction success")
|
|
263
|
-
// const result = await client.signAndExecuteTransaction(routerTx, keypair)
|
|
264
|
-
// console.log('result', result)
|
|
265
|
-
} else {
|
|
266
|
-
console.log("Sim exec transaction failed")
|
|
267
|
-
// console.log('result', result)
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}, 60000000)
|
|
274
|
-
|
|
275
|
-
test("Build router with liquidity changes", async () => {
|
|
276
|
-
const byAmountIn = true
|
|
277
|
-
const amount = "1000000000"
|
|
278
|
-
|
|
279
|
-
// const from = M_USDC
|
|
280
|
-
// const target = M_SUI
|
|
281
|
-
|
|
282
|
-
const from = testData.M_SUI
|
|
283
|
-
// const target =
|
|
284
|
-
// "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
285
|
-
// const target =
|
|
286
|
-
// "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
287
|
-
|
|
288
|
-
const target = testData.M_HASUI
|
|
289
|
-
|
|
290
|
-
const res = await client.findRouters({
|
|
291
|
-
from,
|
|
292
|
-
target,
|
|
293
|
-
amount: new BN(amount),
|
|
294
|
-
byAmountIn,
|
|
295
|
-
depth: 2,
|
|
296
|
-
providers: [
|
|
297
|
-
"CETUS",
|
|
298
|
-
// "DEEPBOOK",
|
|
299
|
-
// "AFTERMATH",
|
|
300
|
-
// "FLOWX",
|
|
301
|
-
// "KRIYA",
|
|
302
|
-
// "KRIYAV3",
|
|
303
|
-
// "TURBOS",
|
|
304
|
-
// "FLOWXV3",
|
|
305
|
-
],
|
|
306
|
-
liquidityChanges: [
|
|
307
|
-
{
|
|
308
|
-
poolID:
|
|
309
|
-
"0x871d8a227114f375170f149f7e9d45be822dd003eba225e83c05ac80828596bc",
|
|
310
|
-
ticklower: 100,
|
|
311
|
-
tickUpper: 394,
|
|
312
|
-
deltaLiquidity: -5498684,
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
poolID:
|
|
316
|
-
"0x871d8a227114f375170f149f7e9d45be822dd003eba225e83c05ac80828596bc",
|
|
317
|
-
ticklower: 100,
|
|
318
|
-
tickUpper: 394,
|
|
319
|
-
deltaLiquidity: 986489,
|
|
320
|
-
},
|
|
321
|
-
],
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
if (res != null) {
|
|
325
|
-
console.log(JSON.stringify(res, null, 2))
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const txb = new Transaction()
|
|
329
|
-
|
|
330
|
-
if (res != null) {
|
|
331
|
-
console.log(JSON.stringify(res, null, 2))
|
|
332
|
-
await client.fastRouterSwap({
|
|
333
|
-
routers: res.routes,
|
|
334
|
-
byAmountIn,
|
|
335
|
-
txb,
|
|
336
|
-
slippage: 0.01,
|
|
337
|
-
refreshAllCoins: true,
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
printTransaction(txb)
|
|
341
|
-
|
|
342
|
-
let result = await client.devInspectTransactionBlock(txb)
|
|
343
|
-
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
344
|
-
|
|
345
|
-
// if (result.effects.status.status === "success") {
|
|
346
|
-
// console.log("Sim exec transaction success")
|
|
347
|
-
// const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
348
|
-
// // console.log("result", result)
|
|
349
|
-
// } else {
|
|
350
|
-
// console.log("result", result)
|
|
351
|
-
// }
|
|
352
|
-
}
|
|
353
|
-
}, 600000)
|
|
354
|
-
|
|
355
|
-
test("Get deepbook v3 config", async () => {
|
|
356
|
-
const config = await client.getDeepbookV3Config()
|
|
357
|
-
console.log("config", config)
|
|
358
|
-
}, 60000)
|
|
359
|
-
|
|
360
|
-
test("Find router", async () => {
|
|
361
|
-
const amount = "4239267610000000000"
|
|
362
|
-
const res = await client.findRouters({
|
|
363
|
-
from: "0x2::sui::SUI",
|
|
364
|
-
target:
|
|
365
|
-
"0x188c6239bda71ba5751990cc0271e91b6362c67bccf7aa381e018db7fe39c6d7::BUILD::BUILD",
|
|
366
|
-
amount: new BN(amount),
|
|
367
|
-
byAmountIn: true,
|
|
368
|
-
depth: 3,
|
|
369
|
-
splitCount: 1,
|
|
370
|
-
providers: ["CETUS"],
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
if (res != null) {
|
|
374
|
-
console.log(JSON.stringify(res, null, 2))
|
|
375
|
-
}
|
|
376
|
-
console.log("amount in", res?.amountIn.toString())
|
|
377
|
-
console.log("amount out", res?.amountOut.toString())
|
|
378
|
-
})
|
|
379
|
-
})
|
package/tests/test_data.test.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// Testnet
|
|
2
|
-
export const T_USDC = "0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::usdc::USDC"
|
|
3
|
-
export const T_USDT = "0x26b3bc67befc214058ca78ea9a2690298d731a2d4309485ec3d40198063c4abc::usdt::USDT"
|
|
4
|
-
export const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
|
|
5
|
-
export const T_DBUSDC = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDC::DBUSDC"
|
|
6
|
-
export const T_DBUSDT = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDT::DBUSDT"
|
|
7
|
-
|
|
8
|
-
// Mainnet
|
|
9
|
-
export const M_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
10
|
-
export const M_wUSDC =
|
|
11
|
-
"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
|
|
12
|
-
export const M_CETUS =
|
|
13
|
-
"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
|
|
14
|
-
export const M_NAVI =
|
|
15
|
-
"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX"
|
|
16
|
-
export const M_SUI = "0x2::sui::SUI"
|
|
17
|
-
export const M_VSUI =
|
|
18
|
-
"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
19
|
-
export const M_VAPOR =
|
|
20
|
-
"0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094024b32ab7b76d14d30::vapor::VAPOR"
|
|
21
|
-
export const M_HASUI =
|
|
22
|
-
"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
23
|
-
export const M_SSWP =
|
|
24
|
-
"0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN"
|
|
25
|
-
export const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI"
|
|
26
|
-
export const M_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
|
|
27
|
-
export const M_SHaSUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI"
|
|
28
|
-
export const M_ETH = "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH"
|
package/tests/wallet.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
2
|
-
|
|
3
|
-
describe("router module", () => {
|
|
4
|
-
const keystoreSecret = [
|
|
5
|
-
"0xd36441c734b1967dd4e65956d0b3e7e5dccc8c92306ad71419e6741b4a7ce6c9",
|
|
6
|
-
]
|
|
7
|
-
|
|
8
|
-
test("Parse public key", () => {
|
|
9
|
-
for (const secret of keystoreSecret) {
|
|
10
|
-
const byte = Buffer.from(secret, "base64")
|
|
11
|
-
const u8Array = new Uint8Array(byte)
|
|
12
|
-
const keypair = Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
|
|
13
|
-
console.log(
|
|
14
|
-
"\nsecret:",
|
|
15
|
-
secret,
|
|
16
|
-
"\nkeypair public key: ",
|
|
17
|
-
keypair.toSuiAddress()
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
})
|