@cetusprotocol/aggregator-sdk 1.4.3 → 1.4.5
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 +46 -302
- package/bun.lock +83 -663
- package/dist/index.js +3 -2
- package/dist/index.mjs +3 -2
- package/package.json +8 -14
- package/tsconfig.json +1 -0
- package/vitest.config.ts +16 -0
- package/examples/mergeSwapExample.ts +0 -142
package/dist/index.js
CHANGED
|
@@ -3452,7 +3452,7 @@ var AGGREGATOR_V3_CONFIG = {
|
|
|
3452
3452
|
};
|
|
3453
3453
|
|
|
3454
3454
|
// src/api.ts
|
|
3455
|
-
var SDK_VERSION =
|
|
3455
|
+
var SDK_VERSION = 1010405;
|
|
3456
3456
|
function parseRouterResponse(data, byAmountIn) {
|
|
3457
3457
|
let packages = /* @__PURE__ */ new Map();
|
|
3458
3458
|
if (data.packages) {
|
|
@@ -3860,6 +3860,7 @@ function processErrorStatusCode(status) {
|
|
|
3860
3860
|
case 5e3:
|
|
3861
3861
|
return 1002 /* InsufficientLiquidity */;
|
|
3862
3862
|
case 5001:
|
|
3863
|
+
case 5010:
|
|
3863
3864
|
return 1007 /* NotFoundRoute */;
|
|
3864
3865
|
case 5030:
|
|
3865
3866
|
return 1008 /* ServiceUnavailable */;
|
|
@@ -6661,7 +6662,7 @@ var DeepbookV3Router = class {
|
|
|
6661
6662
|
}
|
|
6662
6663
|
addDeepPricePoint(txb, swapData) {
|
|
6663
6664
|
txb.moveCall({
|
|
6664
|
-
target: `${swapData.publishedAt}::deepbookv3::
|
|
6665
|
+
target: `${swapData.publishedAt}::deepbookv3::add_deep_price_point_v2`,
|
|
6665
6666
|
typeArguments: [
|
|
6666
6667
|
swapData.coinAType,
|
|
6667
6668
|
swapData.coinBType,
|
package/dist/index.mjs
CHANGED
|
@@ -3446,7 +3446,7 @@ var AGGREGATOR_V3_CONFIG = {
|
|
|
3446
3446
|
};
|
|
3447
3447
|
|
|
3448
3448
|
// src/api.ts
|
|
3449
|
-
var SDK_VERSION =
|
|
3449
|
+
var SDK_VERSION = 1010405;
|
|
3450
3450
|
function parseRouterResponse(data, byAmountIn) {
|
|
3451
3451
|
let packages = /* @__PURE__ */ new Map();
|
|
3452
3452
|
if (data.packages) {
|
|
@@ -3854,6 +3854,7 @@ function processErrorStatusCode(status) {
|
|
|
3854
3854
|
case 5e3:
|
|
3855
3855
|
return 1002 /* InsufficientLiquidity */;
|
|
3856
3856
|
case 5001:
|
|
3857
|
+
case 5010:
|
|
3857
3858
|
return 1007 /* NotFoundRoute */;
|
|
3858
3859
|
case 5030:
|
|
3859
3860
|
return 1008 /* ServiceUnavailable */;
|
|
@@ -6655,7 +6656,7 @@ var DeepbookV3Router = class {
|
|
|
6655
6656
|
}
|
|
6656
6657
|
addDeepPricePoint(txb, swapData) {
|
|
6657
6658
|
txb.moveCall({
|
|
6658
|
-
target: `${swapData.publishedAt}::deepbookv3::
|
|
6659
|
+
target: `${swapData.publishedAt}::deepbookv3::add_deep_price_point_v2`,
|
|
6659
6660
|
typeArguments: [
|
|
6660
6661
|
swapData.coinAType,
|
|
6661
6662
|
swapData.coinBType,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cetusprotocol/aggregator-sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsup --format cjs,esm --dts",
|
|
10
10
|
"dev": "tsup --watch",
|
|
11
|
-
"test": "
|
|
12
|
-
"test:
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"test:watch": "vitest",
|
|
13
|
+
"test:gas": "vitest run tests/benchmarks/gas-benchmark.ts",
|
|
13
14
|
"benchmark": "bun tests/benchmarks/run-benchmark.ts",
|
|
14
15
|
"benchmark:quick": "bun tests/benchmarks/run-benchmark.ts --max-tests 10",
|
|
15
16
|
"benchmark:cetus": "bun tests/benchmarks/run-benchmark.ts --providers CETUS",
|
|
@@ -28,22 +29,15 @@
|
|
|
28
29
|
"node-fetch": "^3.3.2"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "^7.24.5",
|
|
32
|
-
"@babel/preset-env": "^7.24.5",
|
|
33
|
-
"@babel/preset-typescript": "^7.24.1",
|
|
34
|
-
"@jest/globals": "^29.7.0",
|
|
35
|
-
"@types/jest": "^29.5.12",
|
|
36
|
-
"@types/node": "^20.12.12",
|
|
37
|
-
"babel-jest": "^29.7.0",
|
|
38
|
-
"jest": "^29.7.0",
|
|
39
|
-
"ts-jest": "^29.1.3",
|
|
40
|
-
"typescript": "^5.0.0",
|
|
41
32
|
"@types/bn.js": "^5.1.5",
|
|
42
33
|
"@types/bun": "latest",
|
|
43
34
|
"@types/json-bigint": "^1.0.4",
|
|
35
|
+
"@types/node": "^20.12.12",
|
|
44
36
|
"bn.js": "^5.2.1",
|
|
45
37
|
"decimal.js": "^10.4.3",
|
|
46
|
-
"tsup": "^8.0.2"
|
|
38
|
+
"tsup": "^8.0.2",
|
|
39
|
+
"typescript": "^5.0.0",
|
|
40
|
+
"vitest": "^4.0.18"
|
|
47
41
|
},
|
|
48
42
|
"overrides": {
|
|
49
43
|
"chalk": "5.3.0",
|
package/tsconfig.json
CHANGED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config"
|
|
2
|
+
import path from "path"
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
environment: "node",
|
|
7
|
+
globals: true,
|
|
8
|
+
testTimeout: 60000,
|
|
9
|
+
hookTimeout: 30000,
|
|
10
|
+
},
|
|
11
|
+
resolve: {
|
|
12
|
+
alias: {
|
|
13
|
+
"~": path.resolve(__dirname, "./src"),
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
})
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { AggregatorClient, MergeSwapParams, Env } from "../src"
|
|
2
|
-
import { Transaction } from "@mysten/sui/transactions"
|
|
3
|
-
import { SuiClient } from "@mysten/sui/client"
|
|
4
|
-
import BN from "bn.js"
|
|
5
|
-
|
|
6
|
-
async function mergeSwapExample() {
|
|
7
|
-
// Initialize client
|
|
8
|
-
const client = new AggregatorClient({
|
|
9
|
-
endpoint: "https://api-sui-cloudfront.cetus.zone/router_v3",
|
|
10
|
-
env: Env.Mainnet,
|
|
11
|
-
signer: "0xYourWalletAddress", // Replace with your wallet address
|
|
12
|
-
client: new SuiClient({ url: "https://fullnode.mainnet.sui.io" })
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
// 1. First, find merge swap routes
|
|
16
|
-
const mergeSwapParams: MergeSwapParams = {
|
|
17
|
-
target: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", // USDC
|
|
18
|
-
byAmountIn: true,
|
|
19
|
-
depth: 3,
|
|
20
|
-
providers: ["CETUS"],
|
|
21
|
-
froms: [
|
|
22
|
-
{
|
|
23
|
-
coinType: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
|
|
24
|
-
amount: new BN("100000000")
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
coinType: "0xce7ff77a83ea0cb6fd39bd8748e2ec89a3f41e8efdc3f4eb123e0ca37b184db2::buck::BUCK",
|
|
28
|
-
amount: new BN("1000000000")
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
coinType: "0x002::sui::SUI",
|
|
32
|
-
amount: new BN("3000000000")
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
console.log("Finding merge swap routes...")
|
|
38
|
-
const routerResult = await client.findMergeSwapRouters(mergeSwapParams)
|
|
39
|
-
|
|
40
|
-
if (!routerResult || routerResult.error) {
|
|
41
|
-
console.error("Failed to find routes:", routerResult?.error)
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
console.log("Routes found!")
|
|
46
|
-
console.log("Total amount in:", routerResult.amountIn.toString())
|
|
47
|
-
console.log("Total amount out:", routerResult.amountOut.toString())
|
|
48
|
-
console.log("Number of paths:", routerResult.paths.length)
|
|
49
|
-
|
|
50
|
-
// 2. Execute merge swap with manual input coins
|
|
51
|
-
const txb = new Transaction()
|
|
52
|
-
|
|
53
|
-
// Prepare input coins (you need to have these coins in your wallet)
|
|
54
|
-
const inputCoins = [
|
|
55
|
-
{
|
|
56
|
-
coinType: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
|
|
57
|
-
coin: txb.object("0xDeepCoinObjectId") // Replace with actual coin object ID
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
coinType: "0xce7ff77a83ea0cb6fd39bd8748e2ec89a3f41e8efdc3f4eb123e0ca37b184db2::buck::BUCK",
|
|
61
|
-
coin: txb.object("0xBuckCoinObjectId") // Replace with actual coin object ID
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
coinType: "0x002::sui::SUI",
|
|
65
|
-
coin: txb.splitCoins(txb.gas, [3000000000])[0] // Use gas coin for SUI
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
|
|
69
|
-
// Execute merge swap
|
|
70
|
-
const outputCoin = await client.mergeSwap({
|
|
71
|
-
router: routerResult,
|
|
72
|
-
inputCoins,
|
|
73
|
-
slippage: 0.01, // 1% slippage
|
|
74
|
-
txb,
|
|
75
|
-
partner: "YourPartnerName" // Optional
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
console.log("Merge swap transaction built successfully!")
|
|
79
|
-
|
|
80
|
-
// Transfer output to sender (optional)
|
|
81
|
-
txb.transferObjects([outputCoin], client.signer)
|
|
82
|
-
|
|
83
|
-
// Sign and execute transaction (implementation depends on your wallet integration)
|
|
84
|
-
// const result = await signAndExecuteTransaction(txb)
|
|
85
|
-
// console.log("Transaction executed:", result.digest)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function fastMergeSwapExample() {
|
|
89
|
-
// Initialize client
|
|
90
|
-
const client = new AggregatorClient({
|
|
91
|
-
endpoint: "https://api-sui-cloudfront.cetus.zone/router_v3",
|
|
92
|
-
env: Env.Mainnet,
|
|
93
|
-
signer: "0xYourWalletAddress", // Replace with your wallet address
|
|
94
|
-
client: new SuiClient({ url: "https://fullnode.mainnet.sui.io" })
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
// 1. Find merge swap routes
|
|
98
|
-
const mergeSwapParams: MergeSwapParams = {
|
|
99
|
-
target: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
100
|
-
byAmountIn: true,
|
|
101
|
-
depth: 3,
|
|
102
|
-
froms: [
|
|
103
|
-
{
|
|
104
|
-
coinType: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
|
|
105
|
-
amount: new BN("100000000")
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
coinType: "0x002::sui::SUI",
|
|
109
|
-
amount: new BN("2000000000")
|
|
110
|
-
}
|
|
111
|
-
]
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const routerResult = await client.findMergeSwapRouters(mergeSwapParams)
|
|
115
|
-
|
|
116
|
-
if (!routerResult || routerResult.error) {
|
|
117
|
-
console.error("Failed to find routes:", routerResult?.error)
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 2. Execute fast merge swap (automatically builds input coins)
|
|
122
|
-
const txb = new Transaction()
|
|
123
|
-
|
|
124
|
-
await client.fastMergeSwap({
|
|
125
|
-
router: routerResult,
|
|
126
|
-
slippage: 0.01, // 1% slippage
|
|
127
|
-
txb,
|
|
128
|
-
partner: "YourPartnerName", // Optional
|
|
129
|
-
payDeepFeeAmount: 1000000 // Optional: DeepBook fee if needed
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
console.log("Fast merge swap transaction built successfully!")
|
|
133
|
-
console.log("Input coins are automatically created and output is auto-merged/transferred")
|
|
134
|
-
|
|
135
|
-
// Sign and execute transaction
|
|
136
|
-
// const result = await signAndExecuteTransaction(txb)
|
|
137
|
-
// console.log("Transaction executed:", result.digest)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Run examples
|
|
141
|
-
mergeSwapExample().catch(console.error)
|
|
142
|
-
// fastMergeSwapExample().catch(console.error)
|