@cetusprotocol/aggregator-sdk 0.11.1 → 0.12.0
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 +68 -59
- package/dist/index.js +5 -5
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
- package/script/copy-to-sui-aggregator.sh +85 -0
package/README.md
CHANGED
|
@@ -29,7 +29,9 @@ Multi-Platform Support: Currently, we have integrated multiple mainstream DEXs o
|
|
|
29
29
|
|
|
30
30
|
By using our aggregator, you can trade more efficiently and securely on the Sui blockchain, fully leveraging the various opportunities brought by decentralized finance (DeFi).
|
|
31
31
|
|
|
32
|
-
#
|
|
32
|
+
# Aggregator SDK
|
|
33
|
+
|
|
34
|
+
## Install
|
|
33
35
|
|
|
34
36
|
The SDK is published to npm registry. To use the SDK in your project, you can
|
|
35
37
|
|
|
@@ -37,33 +39,15 @@ The SDK is published to npm registry. To use the SDK in your project, you can
|
|
|
37
39
|
npm install @cetusprotocol/aggregator-sdk
|
|
38
40
|
```
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## 1. Init client with rpc and package config
|
|
42
|
+
## Usage
|
|
43
43
|
|
|
44
|
-
1.
|
|
45
|
-
```typescript
|
|
46
|
-
const client = new AggregatorClient({})
|
|
47
|
-
```
|
|
44
|
+
### 1. Init client with rpc and package config
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
const client = new AggregatorClient({
|
|
54
|
-
// endpoint, // If you do not have a exclusive aggregator api domain,just use cetus default aggregator endpoints.
|
|
55
|
-
signer: wallet,
|
|
56
|
-
client: suiClient,
|
|
57
|
-
env: Env.Mainnet,
|
|
58
|
-
pythUrls: ["YOUR_PYTH_URL", "ANOTHER_PYTH_URL"],
|
|
59
|
-
partner: "YOUR_PARTNER_ID", // Partner ID for fee sharing. Set once during initialization instead of per swap.
|
|
60
|
-
overlayFeeRate: 0.01, // Overlay fee rate (0.01 represents 1%). The denominator is 1000000, so 0.01% = 100
|
|
61
|
-
overlayFeeReceiver: "0x..", // Address to receive the overlay fees
|
|
62
|
-
})
|
|
63
|
-
```
|
|
64
|
-
**Notes**: Some providers, such as HaedalHMM and Metastable, rely on Pyth oracle prices when build transactions. Currently, we have a default configuration that connects to Pyth's publicly available node. However, if you frequently build transactions, we recommend setting up a private Pyth node interface as an additional backup. This will ensure uninterrupted access to HaedalHMM and Metastable, even if the public node experiences occasional downtime.
|
|
46
|
+
```typescript
|
|
47
|
+
const client = new AggregatorClient({})
|
|
48
|
+
```
|
|
65
49
|
|
|
66
|
-
|
|
50
|
+
### 2. Get best router swap result from aggregator service
|
|
67
51
|
|
|
68
52
|
```typescript
|
|
69
53
|
const amount = new BN(1000000)
|
|
@@ -79,72 +63,97 @@ const routers = await client.findRouters({
|
|
|
79
63
|
})
|
|
80
64
|
```
|
|
81
65
|
|
|
82
|
-
|
|
66
|
+
### 3. Confirm and do fast swap
|
|
67
|
+
|
|
83
68
|
```typescript
|
|
84
|
-
const
|
|
69
|
+
const txb = new Transaction()
|
|
85
70
|
|
|
86
71
|
if (routerRes != null) {
|
|
87
72
|
await client.fastRouterSwap({
|
|
88
73
|
routers,
|
|
89
|
-
txb
|
|
74
|
+
txb,
|
|
90
75
|
slippage: 0.01,
|
|
91
|
-
isMergeTragetCoin: true,
|
|
92
|
-
refreshAllCoins: true
|
|
93
76
|
})
|
|
94
77
|
|
|
95
|
-
|
|
78
|
+
const result = await client.devInspectTransactionBlock(txb, keypair)
|
|
96
79
|
|
|
97
80
|
if (result.effects.status.status === "success") {
|
|
98
|
-
console.log("
|
|
99
|
-
const result = await client.signAndExecuteTransaction(
|
|
100
|
-
console.log("[Cetus] Transaction executed successfully:", {
|
|
101
|
-
digest: result.digest,
|
|
102
|
-
status: result.effects?.status,
|
|
103
|
-
gasUsed: result.effects?.gasUsed
|
|
104
|
-
})
|
|
105
|
-
} else {
|
|
106
|
-
console.error("[Cetus] Transaction simulation failed:", result.effects?.status)
|
|
81
|
+
console.log("Sim exec transaction success")
|
|
82
|
+
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
107
83
|
}
|
|
84
|
+
console.log("result", result)
|
|
108
85
|
}
|
|
109
86
|
```
|
|
110
87
|
|
|
111
|
-
|
|
88
|
+
### 4. Build PTB and return target coin
|
|
112
89
|
|
|
113
90
|
```typescript
|
|
114
|
-
const
|
|
115
|
-
const byAmountIn = true
|
|
91
|
+
const txb = new Transaction()
|
|
92
|
+
const byAmountIn = true
|
|
116
93
|
|
|
117
94
|
if (routerRes != null) {
|
|
118
95
|
const targetCoin = await client.routerSwap({
|
|
119
96
|
routers,
|
|
120
|
-
txb
|
|
97
|
+
txb,
|
|
121
98
|
inputCoin,
|
|
122
99
|
slippage: 0.01,
|
|
123
100
|
})
|
|
124
101
|
|
|
125
102
|
// you can use this target coin object argument to build your ptb.
|
|
126
|
-
client.
|
|
127
|
-
txb,
|
|
128
|
-
targetCoin,
|
|
129
|
-
targetCoinType
|
|
130
|
-
)
|
|
103
|
+
client.transferOrDestoryCoin(txb, targetCoin, targetCoinType)
|
|
131
104
|
|
|
132
|
-
|
|
105
|
+
const result = await client.devInspectTransactionBlock(txb, keypair)
|
|
133
106
|
|
|
134
107
|
if (result.effects.status.status === "success") {
|
|
135
|
-
console.log("
|
|
136
|
-
const result = await client.signAndExecuteTransaction(
|
|
137
|
-
console.log("[Cetus] Transaction executed successfully:", {
|
|
138
|
-
digest: result.digest,
|
|
139
|
-
status: result.effects?.status,
|
|
140
|
-
gasUsed: result.effects?.gasUsed
|
|
141
|
-
})
|
|
142
|
-
} else {
|
|
143
|
-
console.error("[Cetus] Transaction simulation failed:", result.effects?.status)
|
|
108
|
+
console.log("Sim exec transaction success")
|
|
109
|
+
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
144
110
|
}
|
|
111
|
+
console.log("result", result)
|
|
145
112
|
}
|
|
146
113
|
```
|
|
147
114
|
|
|
115
|
+
# Aggregator Contract Interface
|
|
116
|
+
|
|
117
|
+
## Tags corresponding to different networks
|
|
118
|
+
|
|
119
|
+
| Contract | Tag of Repo | Latest published at address |
|
|
120
|
+
| ------------------------- | ----------- | ------------------------------------------------------------------ |
|
|
121
|
+
| CetusAggregatorV2 | mainnet | 0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032 |
|
|
122
|
+
| CetusAggregatorV2ExtendV1 | mainnet | 0x39402d188b7231036e52266ebafad14413b4bf3daea4ac17115989444e6cd516 |
|
|
123
|
+
| CetusAggregatorV2ExtendV2 | mainnet | 0x368d13376443a8051b22b42a9125f6a3bc836422bb2d9c4a53984b8d6624c326 |
|
|
124
|
+
|
|
125
|
+
## Example
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
CetusAggregatorV2 = { git = "https://github.com/CetusProtocol/aggregator.git", subdir = "packages/cetus-aggregator-v2/mainnet", rev = "mainnet", override = true }
|
|
129
|
+
|
|
130
|
+
CetusAggregatorV2ExtendV1 = { git = "https://github.com/CetusProtocol/aggregator.git", subdir = "packages/cetus-aggregator-v2-extend-v1", rev = "mainnet", override = true }
|
|
131
|
+
|
|
132
|
+
CetusAggregatorV2ExtendV2 = { git = "https://github.com/CetusProtocol/aggregator.git", subdir = "packages/cetus-aggregator-v2-extend-v2", rev = "mainnet", override = true }
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
# Simple Aggregator Contract Interface(include cetus, flowxv3, turbos, bluefin)
|
|
136
|
+
|
|
137
|
+
## Tags corresponding to different networks
|
|
138
|
+
|
|
139
|
+
| Contract | Tag of Repo | Latest published at address |
|
|
140
|
+
| --------------------- | ----------- | ------------------------------------------------------------------ |
|
|
141
|
+
| CetusAggregatorSimple | mainnet | 0x594d67abc0778023ac852800578271dd7e18698ad06e6298034858c77612333d |
|
|
142
|
+
|
|
143
|
+
## Example
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
CetusAggregatorSimple = { git = "https://github.com/CetusProtocol/aggregator.git", subdir = "packages/cetus-aggregator-v2/simple-mainnet", rev = "mainnet-v1.49.1", override = true }
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Usage
|
|
150
|
+
|
|
151
|
+
Cetus clmm interface is not complete(just have function definition), so it will fails when sui client check the code version. However, this does not affect its actual functionality. Therefore, we need to add a --dependencies-are-root during the build.
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
sui move build --dependencies-are-root && sui client publish --dependencies-are-root
|
|
155
|
+
```
|
|
156
|
+
|
|
148
157
|
# More About Cetus
|
|
149
158
|
|
|
150
159
|
Use the following links to learn more about Cetus:
|
package/dist/index.js
CHANGED
|
@@ -5805,7 +5805,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5805
5805
|
const targetCoin = completionCoin(target);
|
|
5806
5806
|
const tx = new transactions.Transaction();
|
|
5807
5807
|
const direction = compareCoins(fromCoin, targetCoin);
|
|
5808
|
-
const integratePublishedAt = env === 0 /* Mainnet */ ? "
|
|
5808
|
+
const integratePublishedAt = env === 0 /* Mainnet */ ? "0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d" : "0x4f920e1ef6318cfba77e20a0538a419a5a504c14230169438b99aba485db40a6";
|
|
5809
5809
|
const coinA = direction ? fromCoin : targetCoin;
|
|
5810
5810
|
const coinB = direction ? targetCoin : fromCoin;
|
|
5811
5811
|
const typeArguments = [coinA, coinB];
|
|
@@ -7344,7 +7344,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
7344
7344
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
7345
7345
|
publishedAtV2() {
|
|
7346
7346
|
if (this.env === 0 /* Mainnet */) {
|
|
7347
|
-
return "
|
|
7347
|
+
return "0x47a7b90756fba96fe649c2aaa10ec60dec6b8cb8545573d621310072721133aa";
|
|
7348
7348
|
} else {
|
|
7349
7349
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
7350
7350
|
}
|
|
@@ -7352,14 +7352,14 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
7352
7352
|
// Include deepbookv3, scallop, bluefin
|
|
7353
7353
|
publishedAtV2Extend() {
|
|
7354
7354
|
if (this.env === 0 /* Mainnet */) {
|
|
7355
|
-
return "
|
|
7355
|
+
return "0x8093d002bba575f1378b0da206a8df1fc55c4b5b3718752304f1b67a505d2be4";
|
|
7356
7356
|
} else {
|
|
7357
7357
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
7358
7358
|
}
|
|
7359
7359
|
}
|
|
7360
7360
|
publishedAtV2Extend2() {
|
|
7361
7361
|
if (this.env === 0 /* Mainnet */) {
|
|
7362
|
-
return "
|
|
7362
|
+
return "0x96356d1cfc7a4dec5bc0171f085ddaf1f650b1c6c412f209518d496c8ffed212";
|
|
7363
7363
|
} else {
|
|
7364
7364
|
return "0x0";
|
|
7365
7365
|
}
|
|
@@ -7760,7 +7760,7 @@ function processEndpoint(endpoint) {
|
|
|
7760
7760
|
|
|
7761
7761
|
// src/api.ts
|
|
7762
7762
|
var import_bn7 = __toESM(require_bn());
|
|
7763
|
-
var SDK_VERSION =
|
|
7763
|
+
var SDK_VERSION = 1001200;
|
|
7764
7764
|
function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
7765
7765
|
return __async(this, null, function* () {
|
|
7766
7766
|
let response;
|
package/dist/index.mjs
CHANGED
|
@@ -5803,7 +5803,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5803
5803
|
const targetCoin = completionCoin(target);
|
|
5804
5804
|
const tx = new Transaction();
|
|
5805
5805
|
const direction = compareCoins(fromCoin, targetCoin);
|
|
5806
|
-
const integratePublishedAt = env === 0 /* Mainnet */ ? "
|
|
5806
|
+
const integratePublishedAt = env === 0 /* Mainnet */ ? "0xb2db7142fa83210a7d78d9c12ac49c043b3cbbd482224fea6e3da00aa5a5ae2d" : "0x4f920e1ef6318cfba77e20a0538a419a5a504c14230169438b99aba485db40a6";
|
|
5807
5807
|
const coinA = direction ? fromCoin : targetCoin;
|
|
5808
5808
|
const coinB = direction ? targetCoin : fromCoin;
|
|
5809
5809
|
const typeArguments = [coinA, coinB];
|
|
@@ -7342,7 +7342,7 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
7342
7342
|
// Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
|
|
7343
7343
|
publishedAtV2() {
|
|
7344
7344
|
if (this.env === 0 /* Mainnet */) {
|
|
7345
|
-
return "
|
|
7345
|
+
return "0x47a7b90756fba96fe649c2aaa10ec60dec6b8cb8545573d621310072721133aa";
|
|
7346
7346
|
} else {
|
|
7347
7347
|
return "0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934";
|
|
7348
7348
|
}
|
|
@@ -7350,14 +7350,14 @@ var _AggregatorClient = class _AggregatorClient {
|
|
|
7350
7350
|
// Include deepbookv3, scallop, bluefin
|
|
7351
7351
|
publishedAtV2Extend() {
|
|
7352
7352
|
if (this.env === 0 /* Mainnet */) {
|
|
7353
|
-
return "
|
|
7353
|
+
return "0x8093d002bba575f1378b0da206a8df1fc55c4b5b3718752304f1b67a505d2be4";
|
|
7354
7354
|
} else {
|
|
7355
7355
|
return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
|
|
7356
7356
|
}
|
|
7357
7357
|
}
|
|
7358
7358
|
publishedAtV2Extend2() {
|
|
7359
7359
|
if (this.env === 0 /* Mainnet */) {
|
|
7360
|
-
return "
|
|
7360
|
+
return "0x96356d1cfc7a4dec5bc0171f085ddaf1f650b1c6c412f209518d496c8ffed212";
|
|
7361
7361
|
} else {
|
|
7362
7362
|
return "0x0";
|
|
7363
7363
|
}
|
|
@@ -7758,7 +7758,7 @@ function processEndpoint(endpoint) {
|
|
|
7758
7758
|
|
|
7759
7759
|
// src/api.ts
|
|
7760
7760
|
var import_bn7 = __toESM(require_bn());
|
|
7761
|
-
var SDK_VERSION =
|
|
7761
|
+
var SDK_VERSION = 1001200;
|
|
7762
7762
|
function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
|
|
7763
7763
|
return __async(this, null, function* () {
|
|
7764
7764
|
let response;
|
package/package.json
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 复制 aggregator-sdk 文件到 sui/aggregator 目录的脚本
|
|
4
|
+
# 作者: Auto Generated Script
|
|
5
|
+
# 日期: $(date)
|
|
6
|
+
|
|
7
|
+
set -e # 遇到错误时退出
|
|
8
|
+
|
|
9
|
+
# 定义源目录和目标目录
|
|
10
|
+
SOURCE_DIR="/home/ccbond/github/cetus/aggregator-sdk"
|
|
11
|
+
TARGET_DIR="/home/ccbond/github/sui/aggregator"
|
|
12
|
+
|
|
13
|
+
# 颜色定义
|
|
14
|
+
RED='\033[0;31m'
|
|
15
|
+
GREEN='\033[0;32m'
|
|
16
|
+
YELLOW='\033[1;33m'
|
|
17
|
+
NC='\033[0m' # No Color
|
|
18
|
+
|
|
19
|
+
# 打印带颜色的消息
|
|
20
|
+
print_message() {
|
|
21
|
+
local color=$1
|
|
22
|
+
local message=$2
|
|
23
|
+
echo -e "${color}${message}${NC}"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# 检查源目录是否存在
|
|
27
|
+
if [ ! -d "$SOURCE_DIR" ]; then
|
|
28
|
+
print_message $RED "错误: 源目录 $SOURCE_DIR 不存在!"
|
|
29
|
+
exit 1
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
# 创建目标目录(如果不存在)
|
|
33
|
+
if [ ! -d "$TARGET_DIR" ]; then
|
|
34
|
+
print_message $YELLOW "目标目录 $TARGET_DIR 不存在,正在创建..."
|
|
35
|
+
mkdir -p "$TARGET_DIR"
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
print_message $GREEN "开始复制文件..."
|
|
39
|
+
print_message $YELLOW "源目录: $SOURCE_DIR"
|
|
40
|
+
print_message $YELLOW "目标目录: $TARGET_DIR"
|
|
41
|
+
echo
|
|
42
|
+
|
|
43
|
+
# 复制 src 目录
|
|
44
|
+
if [ -d "$SOURCE_DIR/src" ]; then
|
|
45
|
+
print_message $GREEN "复制 src 目录..."
|
|
46
|
+
cp -r "$SOURCE_DIR/src" "$TARGET_DIR/"
|
|
47
|
+
else
|
|
48
|
+
print_message $RED "警告: src 目录不存在于源路径中"
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
# 复制 package.json
|
|
52
|
+
if [ -f "$SOURCE_DIR/package.json" ]; then
|
|
53
|
+
print_message $GREEN "复制 package.json..."
|
|
54
|
+
cp "$SOURCE_DIR/package.json" "$TARGET_DIR/"
|
|
55
|
+
else
|
|
56
|
+
print_message $RED "警告: package.json 不存在于源路径中"
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
# 复制 README.md (假设是 README.md)
|
|
60
|
+
if [ -f "$SOURCE_DIR/README.md" ]; then
|
|
61
|
+
print_message $GREEN "复制 README.md..."
|
|
62
|
+
cp "$SOURCE_DIR/README.md" "$TARGET_DIR/"
|
|
63
|
+
elif [ -f "$SOURCE_DIR/README" ]; then
|
|
64
|
+
print_message $GREEN "复制 README..."
|
|
65
|
+
cp "$SOURCE_DIR/README" "$TARGET_DIR/"
|
|
66
|
+
else
|
|
67
|
+
print_message $RED "警告: README 或 README.md 不存在于源路径中"
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
# 复制 tests 目录
|
|
71
|
+
if [ -d "$SOURCE_DIR/tests" ]; then
|
|
72
|
+
print_message $GREEN "复制 tests 目录..."
|
|
73
|
+
cp -r "$SOURCE_DIR/tests" "$TARGET_DIR/"
|
|
74
|
+
else
|
|
75
|
+
print_message $RED "警告: tests 目录不存在于源路径中"
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
echo
|
|
79
|
+
print_message $GREEN "复制完成!"
|
|
80
|
+
print_message $YELLOW "复制的文件和目录位于: $TARGET_DIR"
|
|
81
|
+
|
|
82
|
+
# 显示目标目录内容
|
|
83
|
+
echo
|
|
84
|
+
print_message $YELLOW "目标目录内容:"
|
|
85
|
+
ls -la "$TARGET_DIR"
|