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
55class 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 ;
0 commit comments