@cetusprotocol/sui-clmm-sdk 1.0.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.
Files changed (64) hide show
  1. package/.turbo/turbo-build.log +11100 -0
  2. package/README.md +108 -0
  3. package/dist/index.d.mts +2251 -0
  4. package/dist/index.d.ts +2251 -0
  5. package/dist/index.js +13 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +13 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/docs/add_liquidity.md +145 -0
  10. package/docs/close_position.md +57 -0
  11. package/docs/collect_fees.md +37 -0
  12. package/docs/create_clmm_pool.md +228 -0
  13. package/docs/error_code.md +69 -0
  14. package/docs/get_clmm_pools.md +92 -0
  15. package/docs/get_positions.md +70 -0
  16. package/docs/get_reward.md +53 -0
  17. package/docs/get_ticks.md +39 -0
  18. package/docs/migrate_to_version_6.0.md +143 -0
  19. package/docs/open_position.md +224 -0
  20. package/docs/partner_swap.md +60 -0
  21. package/docs/pre_swap.md +136 -0
  22. package/docs/remove_liquidity.md +124 -0
  23. package/docs/swap.md +153 -0
  24. package/docs/utils.md +85 -0
  25. package/package.json +37 -0
  26. package/src/config/index.ts +2 -0
  27. package/src/config/mainnet.ts +41 -0
  28. package/src/config/testnet.ts +40 -0
  29. package/src/errors/errors.ts +93 -0
  30. package/src/errors/index.ts +1 -0
  31. package/src/index.ts +10 -0
  32. package/src/math/apr.ts +167 -0
  33. package/src/math/index.ts +1 -0
  34. package/src/modules/configModule.ts +540 -0
  35. package/src/modules/index.ts +5 -0
  36. package/src/modules/poolModule.ts +1066 -0
  37. package/src/modules/positionModule.ts +932 -0
  38. package/src/modules/rewarderModule.ts +430 -0
  39. package/src/modules/swapModule.ts +389 -0
  40. package/src/sdk.ts +131 -0
  41. package/src/types/clmm_type.ts +1002 -0
  42. package/src/types/clmmpool.ts +366 -0
  43. package/src/types/config_type.ts +241 -0
  44. package/src/types/index.ts +8 -0
  45. package/src/types/sui.ts +124 -0
  46. package/src/types/token_type.ts +189 -0
  47. package/src/utils/common.ts +426 -0
  48. package/src/utils/index.ts +3 -0
  49. package/src/utils/positionUtils.ts +434 -0
  50. package/src/utils/swapUtils.ts +499 -0
  51. package/tests/add_liquidity.test.ts +121 -0
  52. package/tests/add_liquidity_fix_token.test.ts +182 -0
  53. package/tests/apr.test.ts +71 -0
  54. package/tests/cetus_config.test.ts +26 -0
  55. package/tests/collect_fees.test.ts +11 -0
  56. package/tests/pool.test.ts +267 -0
  57. package/tests/position.test.ts +145 -0
  58. package/tests/remove_liquidity.test.ts +119 -0
  59. package/tests/rewarder.test.ts +60 -0
  60. package/tests/sdk_config.test.ts +49 -0
  61. package/tests/swap.test.ts +254 -0
  62. package/tests/tsconfig.json +26 -0
  63. package/tsconfig.json +5 -0
  64. package/tsup.config.ts +10 -0
@@ -0,0 +1,124 @@
1
+ import type { TransactionArgument } from '@mysten/sui/transactions'
2
+ import type { SuiAddressType } from '@cetusprotocol/common-sdk'
3
+ import { ClmmError, TypesErrorCode } from '../errors/errors'
4
+
5
+ /**
6
+ * Constants for different modules in the CLMM (Cryptocurrency Liquidity Mining Module).
7
+ */
8
+ export const ClmmPartnerModule = 'partner'
9
+ export const ClmmIntegratePoolModule = 'pool_script'
10
+ export const ClmmIntegratePoolV2Module = 'pool_script_v2'
11
+ export const ClmmIntegratePoolV3Module = 'pool_script_v3'
12
+ export const ClmmIntegrateRouterModule = 'router'
13
+ export const ClmmIntegrateRouterWithPartnerModule = 'router_with_partner'
14
+ export const ClmmFetcherModule = 'fetcher_script'
15
+ export const ClmmExpectSwapModule = 'expect_swap'
16
+ export const ClmmIntegrateUtilsModule = 'utils'
17
+
18
+ export const DeepbookCustodianV2Module = 'custodian_v2'
19
+ export const DeepbookClobV2Module = 'clob_v2'
20
+ export const DeepbookEndpointsV2Module = 'endpoints_v2'
21
+
22
+ /**
23
+ * Represents a Non-Fungible Token (NFT) with associated metadata.
24
+ */
25
+ export type NFT = {
26
+ /**
27
+ * The address or identifier of the creator of the NFT.
28
+ */
29
+ creator: string
30
+
31
+ /**
32
+ * A description providing additional information about the NFT.
33
+ */
34
+ description: string
35
+
36
+ /**
37
+ * The URL to the image representing the NFT visually.
38
+ */
39
+ image_url: string
40
+
41
+ /**
42
+ * A link associated with the NFT, providing more details or interactions.
43
+ */
44
+ link: string
45
+
46
+ /**
47
+ * The name or title of the NFT.
48
+ */
49
+ name: string
50
+
51
+ /**
52
+ * The URL to the project or collection associated with the NFT.
53
+ */
54
+ project_url: string
55
+ }
56
+
57
+ /**
58
+ * Represents a SUI struct tag.
59
+ */
60
+ export type SuiStructTag = {
61
+ /**
62
+ * The full address of the struct.
63
+ */
64
+ full_address: string
65
+
66
+ /**
67
+ * The source address of the struct.
68
+ */
69
+ source_address: string
70
+
71
+ /**
72
+ * The address of the struct.
73
+ */
74
+ address: SuiAddressType
75
+
76
+ /**
77
+ * The module to which the struct belongs.
78
+ */
79
+ module: string
80
+
81
+ /**
82
+ * The name of the struct.
83
+ */
84
+ name: string
85
+
86
+ /**
87
+ * An array of type arguments (SUI addresses) for the struct.
88
+ */
89
+ type_arguments: SuiAddressType[]
90
+ }
91
+
92
+ /**
93
+ * Represents basic SUI data types.
94
+ */
95
+ export type SuiBasicTypes = 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256'
96
+
97
+ /**
98
+ * Represents a SUI transaction argument, which can be of various types.
99
+ */
100
+ export type SuiTxArg = TransactionArgument | string | number | bigint | boolean
101
+
102
+ /**
103
+ * Represents input types for SUI data.
104
+ */
105
+ export type SuiInputTypes = 'object' | SuiBasicTypes
106
+
107
+ /**
108
+ * Gets the default SUI input type based on the provided value.
109
+ * @param value - The value to determine the default input type for.
110
+ * @returns The default SUI input type.
111
+ * @throws Error if the type of the value is unknown.
112
+ */
113
+ export const getDefaultSuiInputType = (value: any): SuiInputTypes => {
114
+ if (typeof value === 'string' && value.startsWith('0x')) {
115
+ return 'object' // Treat value as an object if it starts with '0x'.
116
+ }
117
+ if (typeof value === 'number' || typeof value === 'bigint') {
118
+ return 'u64' // Treat number or bigint values as 'u64' type.
119
+ }
120
+ if (typeof value === 'boolean') {
121
+ return 'bool' // Treat boolean values as 'bool' type.
122
+ }
123
+ throw new ClmmError(`Unknown type for value: ${value}`, TypesErrorCode.InvalidType)
124
+ }
@@ -0,0 +1,189 @@
1
+ import type { SuiObjectIdType } from '@cetusprotocol/common-sdk'
2
+
3
+ /**
4
+ * Represents configuration for tokens.
5
+ */
6
+ export type TokenConfig = {
7
+ /**
8
+ * The object identifier of the coin registry.
9
+ */
10
+ coin_registry_id: SuiObjectIdType
11
+
12
+ /**
13
+ * The object identifier of the coin list owner.
14
+ */
15
+ coin_list_owner: SuiObjectIdType
16
+
17
+ /**
18
+ * The object identifier of the pool registry.
19
+ */
20
+ pool_registry_id: SuiObjectIdType
21
+
22
+ /**
23
+ * The object identifier of the pool list owner.
24
+ */
25
+ pool_list_owner: SuiObjectIdType
26
+ }
27
+
28
+ /**
29
+ * Represents information about a token.
30
+ */
31
+ export type TokenInfo = {
32
+ /**
33
+ * The name of the token.
34
+ */
35
+ name: string
36
+
37
+ /**
38
+ * The symbol of the token.
39
+ */
40
+ symbol: string
41
+
42
+ /**
43
+ * The official symbol of the token.
44
+ */
45
+ official_symbol: string
46
+
47
+ /**
48
+ * The Coingecko ID of the token.
49
+ */
50
+ coingecko_id: string
51
+
52
+ /**
53
+ * The number of decimal places for the token.
54
+ */
55
+ decimals: number
56
+
57
+ /**
58
+ * The project URL for the token.
59
+ */
60
+ project_url: string
61
+
62
+ /**
63
+ * The URL to the logo image of the token.
64
+ */
65
+ logo_url: string
66
+
67
+ /**
68
+ * The address of the token.
69
+ */
70
+ address: string
71
+
72
+ /**
73
+ * Additional properties for the token information.
74
+ */
75
+ } & Record<string, any>
76
+
77
+ /**
78
+ * Represents information about a liquidity pool.
79
+ */
80
+ export type PoolInfo = {
81
+ /**
82
+ * The symbol of the pool.
83
+ */
84
+ symbol: string
85
+
86
+ /**
87
+ * The name of the pool.
88
+ */
89
+ name: string
90
+
91
+ /**
92
+ * The number of decimal places for the pool.
93
+ */
94
+ decimals: number
95
+
96
+ /**
97
+ * The fee for the pool.
98
+ */
99
+ fee: string
100
+
101
+ /**
102
+ * The tick spacing for the pool.
103
+ */
104
+ tick_spacing: number
105
+
106
+ /**
107
+ * The type of the pool.
108
+ */
109
+ type: string
110
+
111
+ /**
112
+ * The address of the pool.
113
+ */
114
+ address: string
115
+
116
+ /**
117
+ * The address of coin A for the pool.
118
+ */
119
+ coin_a_address: string
120
+
121
+ /**
122
+ * The address of coin B for the pool.
123
+ */
124
+ coin_b_address: string
125
+
126
+ /**
127
+ * The project URL for the pool.
128
+ */
129
+ project_url: string
130
+
131
+ /**
132
+ * The sort order for the pool.
133
+ */
134
+ sort: number
135
+
136
+ /**
137
+ * Indicates if the rewarder is displayed for the pool.
138
+ */
139
+ is_display_rewarder: boolean
140
+
141
+ /**
142
+ * Indicates if rewarder 1 is displayed for the pool.
143
+ */
144
+ rewarder_display1: boolean
145
+
146
+ /**
147
+ * Indicates if rewarder 2 is displayed for the pool.
148
+ */
149
+ rewarder_display2: boolean
150
+
151
+ /**
152
+ * Indicates if rewarder 3 is displayed for the pool.
153
+ */
154
+ rewarder_display3: boolean
155
+
156
+ /**
157
+ * Indicates if the pool is stable.
158
+ */
159
+ is_stable: boolean
160
+
161
+ /**
162
+ * Additional properties for the pool information.
163
+ */
164
+ } & Record<string, any>
165
+
166
+ /**
167
+ * Represents an event related to token configuration.
168
+ */
169
+ export type TokenConfigEvent = {
170
+ /**
171
+ * The object identifier of the coin registry.
172
+ */
173
+ coin_registry_id: SuiObjectIdType
174
+
175
+ /**
176
+ * The object identifier of the coin list owner.
177
+ */
178
+ coin_list_owner: SuiObjectIdType
179
+
180
+ /**
181
+ * The object identifier of the pool registry.
182
+ */
183
+ pool_registry_id: SuiObjectIdType
184
+
185
+ /**
186
+ * The object identifier of the pool list owner.
187
+ */
188
+ pool_list_owner: SuiObjectIdType
189
+ }