Skip to content

Commit 12d6c52

Browse files
committed
fix workflow
1 parent c564740 commit 12d6c52

File tree

8 files changed

+541
-324
lines changed

8 files changed

+541
-324
lines changed

packages/sui-agent/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@
1919
"license": "ISC",
2020
"description": "",
2121
"dependencies": {
22+
"@cetusprotocol/cetus-sui-clmm-sdk": "^5.2.0",
2223
"@mysten/sui": "1.1.0",
2324
"aftermath-ts-sdk": "^1.2.49",
2425
"atoma-sdk": "github:atoma-network/atoma-sdk-typescript",
2526
"axios": "^1.7.9",
27+
"bn.js": "^5.2.1",
2628
"dotenv": "^16.4.7",
2729
"mongoose": "^8.10.0",
2830
"navi-sdk": "^1.4.24",
29-
"typescript": "^5.7.3",
30-
"@cetusprotocol/cetus-sui-clmm-sdk": "^5.2.0"
31+
"typescript": "^5.7.3"
3132
},
3233
"devDependencies": {
34+
"@types/bn.js": "^5.1.6",
3335
"@types/dotenv": "^8.2.0",
3436
"@types/jest": "^29.5.12",
3537
"@types/node": "^20.11.19",
Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import CetusClmmSDK, { initCetusSDK } from '@cetusprotocol/cetus-sui-clmm-sdk'
2-
import { handleError } from '../../utils'
3-
import { CetusPool } from './types'
1+
import CetusClmmSDK, { initCetusSDK } from '@cetusprotocol/cetus-sui-clmm-sdk';
2+
import { handleError } from '../../utils';
3+
import { CetusPool } from './types';
44

55
class PoolTool {
6-
private static sdk: CetusClmmSDK
6+
private static sdk: CetusClmmSDK;
77

88
private static initSDK() {
99
if (!this.sdk) {
1010
this.sdk = initCetusSDK({
1111
network: 'mainnet',
12-
fullNodeUrl: process.env.SUI_RPC_URL || 'https://fullnode.mainnet.sui.io',
12+
fullNodeUrl:
13+
process.env.SUI_RPC_URL || 'https://fullnode.mainnet.sui.io',
1314
simulationAccount: process.env.SUI_WALLET_ADDRESS || '',
14-
})
15+
});
1516
}
16-
return this.sdk
17+
return this.sdk;
1718
}
1819

1920
/**
@@ -23,22 +24,24 @@ class PoolTool {
2324
*/
2425
public static async getPool(poolId: string): Promise<string> {
2526
try {
26-
const sdk = this.initSDK()
27-
const pool = await sdk.Pool.getPool(poolId)
28-
return JSON.stringify([{
29-
reasoning: 'Successfully retrieved pool information',
30-
response: pool,
31-
status: 'success',
32-
query: `Get pool ${poolId}`,
33-
errors: []
34-
}])
27+
const sdk = this.initSDK();
28+
const pool = await sdk.Pool.getPool(poolId);
29+
return JSON.stringify([
30+
{
31+
reasoning: 'Successfully retrieved pool information',
32+
response: pool,
33+
status: 'success',
34+
query: `Get pool ${poolId}`,
35+
errors: [],
36+
},
37+
]);
3538
} catch (error) {
3639
return JSON.stringify([
3740
handleError(error, {
3841
reasoning: 'Failed to retrieve pool information',
39-
query: `Attempted to get pool ${poolId}`
40-
})
41-
])
42+
query: `Attempted to get pool ${poolId}`,
43+
}),
44+
]);
4245
}
4346
}
4447

@@ -48,22 +51,24 @@ class PoolTool {
4851
*/
4952
public static async getAllPools(): Promise<string> {
5053
try {
51-
const sdk = this.initSDK()
52-
const pools = await sdk.Pool.getPools()
53-
return JSON.stringify([{
54-
reasoning: 'Successfully retrieved all pools',
55-
response: pools,
56-
status: 'success',
57-
query: 'Get all pools',
58-
errors: []
59-
}])
54+
const sdk = this.initSDK();
55+
const pools = await sdk.Pool.getPools();
56+
return JSON.stringify([
57+
{
58+
reasoning: 'Successfully retrieved all pools',
59+
response: pools,
60+
status: 'success',
61+
query: 'Get all pools',
62+
errors: [],
63+
},
64+
]);
6065
} catch (error) {
6166
return JSON.stringify([
6267
handleError(error, {
6368
reasoning: 'Failed to retrieve pools',
64-
query: 'Attempted to get all pools'
65-
})
66-
])
69+
query: 'Attempted to get all pools',
70+
}),
71+
]);
6772
}
6873
}
6974

@@ -74,22 +79,24 @@ class PoolTool {
7479
*/
7580
public static async getPoolStats(poolId: string): Promise<string> {
7681
try {
77-
const sdk = this.initSDK()
78-
const stats = await sdk.Pool.getPoolImmutables([poolId])
79-
return JSON.stringify([{
80-
reasoning: 'Successfully retrieved pool statistics',
81-
response: stats,
82-
status: 'success',
83-
query: `Get stats for pool ${poolId}`,
84-
errors: []
85-
}])
82+
const sdk = this.initSDK();
83+
const stats = await sdk.Pool.getPoolImmutables([poolId]);
84+
return JSON.stringify([
85+
{
86+
reasoning: 'Successfully retrieved pool statistics',
87+
response: stats,
88+
status: 'success',
89+
query: `Get stats for pool ${poolId}`,
90+
errors: [],
91+
},
92+
]);
8693
} catch (error) {
8794
return JSON.stringify([
8895
handleError(error, {
8996
reasoning: 'Failed to retrieve pool statistics',
90-
query: `Attempted to get stats for pool ${poolId}`
91-
})
92-
])
97+
query: `Attempted to get stats for pool ${poolId}`,
98+
}),
99+
]);
93100
}
94101
}
95102

@@ -100,25 +107,29 @@ class PoolTool {
100107
*/
101108
public static async getPoolPositions(poolId: string): Promise<string> {
102109
try {
103-
const sdk = this.initSDK()
104-
const pool = await sdk.Pool.getPool(poolId) as unknown as CetusPool
105-
const positions = await sdk.Pool.getPositionList(pool.position_manager.positions_handle)
106-
return JSON.stringify([{
107-
reasoning: 'Successfully retrieved pool positions',
108-
response: positions,
109-
status: 'success',
110-
query: `Get positions for pool ${poolId}`,
111-
errors: []
112-
}])
110+
const sdk = this.initSDK();
111+
const pool = (await sdk.Pool.getPool(poolId)) as unknown as CetusPool;
112+
const positions = await sdk.Pool.getPositionList(
113+
pool.position_manager.positions_handle,
114+
);
115+
return JSON.stringify([
116+
{
117+
reasoning: 'Successfully retrieved pool positions',
118+
response: positions,
119+
status: 'success',
120+
query: `Get positions for pool ${poolId}`,
121+
errors: [],
122+
},
123+
]);
113124
} catch (error) {
114125
return JSON.stringify([
115126
handleError(error, {
116127
reasoning: 'Failed to retrieve pool positions',
117-
query: `Attempted to get positions for pool ${poolId}`
118-
})
119-
])
128+
query: `Attempted to get positions for pool ${poolId}`,
129+
}),
130+
]);
120131
}
121132
}
122133
}
123134

124-
export default PoolTool
135+
export default PoolTool;

packages/sui-agent/src/protocols/cetus/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ The Sui Agent includes comprehensive integration with the Cetus Protocol, provid
55
### Features
66

77
#### Pool Management
8+
89
- Get pool information and statistics
910
- Create new pools with custom parameters
1011
- Monitor pool metrics (TVL, volume, etc.)
1112
- View all positions in a pool
1213

1314
#### Position Management
15+
1416
- View positions for any address
1517
- Add liquidity with customizable parameters
1618
- Remove liquidity with slippage protection
1719
- Collect fees and rewards
1820

1921
#### Trading
22+
2023
- Execute swaps with slippage protection
2124
- Calculate swap quotes and price impact
2225
- Support for both exact input and exact output swaps
@@ -29,33 +32,35 @@ const agent = new Agents(YOUR_BEARER_TOKEN);
2932

3033
// Get pool information
3134
const poolInfo = await agent.SuperVisorAgent(
32-
'Get information about Cetus pool 0x123...abc'
35+
'Get information about Cetus pool 0x123...abc',
3336
);
3437

3538
// Get positions for an address
3639
const positions = await agent.SuperVisorAgent(
37-
'Get all Cetus positions for address 0x456...def'
40+
'Get all Cetus positions for address 0x456...def',
3841
);
3942

4043
// Calculate and execute a swap
4144
const swap = await agent.SuperVisorAgent(
42-
'Swap 1 SUI for USDC on Cetus pool 0x123...abc with 1% slippage'
45+
'Swap 1 SUI for USDC on Cetus pool 0x123...abc with 1% slippage',
4346
);
4447

4548
// Add liquidity
4649
const addLiquidity = await agent.SuperVisorAgent(
47-
'Add 100 USDC as liquidity to Cetus pool 0x123...abc with 0.5% slippage'
50+
'Add 100 USDC as liquidity to Cetus pool 0x123...abc with 0.5% slippage',
4851
);
4952
```
5053

5154
### Supported Operations
5255

5356
1. Pool Operations
57+
5458
- `get_cetus_pool`: Get details about a specific pool
5559
- `create_cetus_pool`: Create a new pool with custom parameters
5660
- Get pool statistics and metrics
5761

5862
2. Position Operations
63+
5964
- `get_cetus_positions`: Get all positions for an address
6065
- `add_cetus_liquidity`: Add liquidity to a pool
6166
- `remove_cetus_liquidity`: Remove liquidity from a position
@@ -68,12 +73,14 @@ const addLiquidity = await agent.SuperVisorAgent(
6873
### Configuration
6974

7075
The Cetus integration uses the following environment variables:
76+
7177
- `SUI_RPC_URL`: The Sui network RPC URL (defaults to mainnet)
7278
- `SUI_WALLET_ADDRESS`: The simulation account address
7379

7480
### Error Handling
7581

7682
All operations include comprehensive error handling and return standardized responses:
83+
7784
```typescript
7885
{
7986
reasoning: string;

0 commit comments

Comments
 (0)