@cetusprotocol/aggregator-sdk 0.4.1 → 0.4.3

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 (103) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.mjs +1 -1
  3. package/package.json +1 -1
  4. package/.env.example +0 -4
  5. package/bun.lockb +0 -0
  6. package/dist/src/api.d.ts +0 -104
  7. package/dist/src/client.d.ts +0 -118
  8. package/dist/src/const.d.ts +0 -8
  9. package/dist/src/errors.d.ts +0 -40
  10. package/dist/src/index.d.ts +0 -9
  11. package/dist/src/math.d.ts +0 -6
  12. package/dist/src/transaction/afsui.d.ts +0 -10
  13. package/dist/src/transaction/aftermath.d.ts +0 -13
  14. package/dist/src/transaction/alphafi.d.ts +0 -7
  15. package/dist/src/transaction/bluefin.d.ts +0 -7
  16. package/dist/src/transaction/bluemove.d.ts +0 -7
  17. package/dist/src/transaction/cetus.d.ts +0 -15
  18. package/dist/src/transaction/deepbook_v2.d.ts +0 -14
  19. package/dist/src/transaction/deepbook_v3.d.ts +0 -12
  20. package/dist/src/transaction/flowx_v2.d.ts +0 -7
  21. package/dist/src/transaction/flowx_v3.d.ts +0 -8
  22. package/dist/src/transaction/haedal.d.ts +0 -6
  23. package/dist/src/transaction/haedal_pmm.d.ts +0 -7
  24. package/dist/src/transaction/index.d.ts +0 -10
  25. package/dist/src/transaction/kriya_v2.d.ts +0 -6
  26. package/dist/src/transaction/kriya_v3.d.ts +0 -7
  27. package/dist/src/transaction/metastable.d.ts +0 -8
  28. package/dist/src/transaction/obric.d.ts +0 -8
  29. package/dist/src/transaction/scallop.d.ts +0 -8
  30. package/dist/src/transaction/steamm.d.ts +0 -6
  31. package/dist/src/transaction/suilend.d.ts +0 -7
  32. package/dist/src/transaction/swap.d.ts +0 -4
  33. package/dist/src/transaction/turbos.d.ts +0 -7
  34. package/dist/src/transaction/volo.d.ts +0 -8
  35. package/dist/src/types/CoinAssist.d.ts +0 -122
  36. package/dist/src/types/sui.d.ts +0 -112
  37. package/dist/src/utils/api.d.ts +0 -1
  38. package/dist/src/utils/coin.d.ts +0 -11
  39. package/dist/src/utils/contracts.d.ts +0 -16
  40. package/dist/src/utils/index.d.ts +0 -5
  41. package/dist/src/utils/msafe.d.ts +0 -2
  42. package/dist/src/utils/transaction.d.ts +0 -3
  43. package/dist/tests/math.test.d.ts +0 -1
  44. package/dist/tests/router/alphafi.test.d.ts +0 -2
  45. package/dist/tests/router/metastable.test.d.ts +0 -2
  46. package/dist/tests/router/obric.test.d.ts +0 -2
  47. package/dist/tests/router/scallop.test.d.ts +0 -2
  48. package/dist/tests/router/steamm.test.d.ts +0 -2
  49. package/dist/tests/router.test.d.ts +0 -2
  50. package/dist/tests/test_data.test.d.ts +0 -18
  51. package/dist/tests/wallet.test.d.ts +0 -1
  52. package/example/package.json +0 -17
  53. package/example/swap.ts +0 -21
  54. package/example/tsconfig.json +0 -12
  55. package/jest.config.mjs +0 -13
  56. package/src/api.ts +0 -325
  57. package/src/client.ts +0 -1081
  58. package/src/const.ts +0 -15
  59. package/src/errors.ts +0 -77
  60. package/src/index.ts +0 -10
  61. package/src/math.ts +0 -66
  62. package/src/transaction/afsui.ts +0 -62
  63. package/src/transaction/aftermath.ts +0 -88
  64. package/src/transaction/alphafi.ts +0 -50
  65. package/src/transaction/bluefin.ts +0 -46
  66. package/src/transaction/bluemove.ts +0 -42
  67. package/src/transaction/cetus.ts +0 -118
  68. package/src/transaction/deepbook_v2.ts +0 -122
  69. package/src/transaction/deepbook_v3.ts +0 -60
  70. package/src/transaction/flowx_v2.ts +0 -42
  71. package/src/transaction/flowx_v3.ts +0 -52
  72. package/src/transaction/haedal.ts +0 -33
  73. package/src/transaction/haedal_pmm.ts +0 -80
  74. package/src/transaction/index.ts +0 -42
  75. package/src/transaction/kriya_v2.ts +0 -37
  76. package/src/transaction/kriya_v3.ts +0 -47
  77. package/src/transaction/metastable.ts +0 -141
  78. package/src/transaction/obric.ts +0 -90
  79. package/src/transaction/scallop.ts +0 -64
  80. package/src/transaction/steamm.ts +0 -77
  81. package/src/transaction/suilend.ts +0 -48
  82. package/src/transaction/swap.ts +0 -162
  83. package/src/transaction/turbos.ts +0 -56
  84. package/src/transaction/volo.ts +0 -53
  85. package/src/types/CoinAssist.ts +0 -217
  86. package/src/types/sui.ts +0 -148
  87. package/src/utils/api.ts +0 -6
  88. package/src/utils/coin.ts +0 -136
  89. package/src/utils/contracts.ts +0 -136
  90. package/src/utils/index.ts +0 -5
  91. package/src/utils/msafe.ts +0 -40
  92. package/src/utils/transaction.ts +0 -20
  93. package/tests/math.test.ts +0 -21
  94. package/tests/router/alphafi.test.ts +0 -132
  95. package/tests/router/metastable.test.ts +0 -383
  96. package/tests/router/obric.test.ts +0 -203
  97. package/tests/router/scallop.test.ts +0 -133
  98. package/tests/router/steamm.test.ts +0 -130
  99. package/tests/router.test.ts +0 -379
  100. package/tests/test_data.test.ts +0 -28
  101. package/tests/wallet.test.ts +0 -21
  102. package/tsup.config.ts +0 -23
  103. package/version.mjs +0 -28
package/src/api.ts DELETED
@@ -1,325 +0,0 @@
1
- import BN from "bn.js"
2
- import Decimal from "decimal.js"
3
- import { completionCoin } from "~/utils/coin"
4
- import { ZERO } from "./const"
5
- import {
6
- AggregatorServerErrorCode,
7
- getAggregatorServerErrorMessage,
8
- } from "./errors"
9
- import { parseRouterResponse } from "./client"
10
-
11
- const SDK_VERSION = 1000401
12
-
13
- export interface FindRouterParams {
14
- from: string
15
- target: string
16
- amount: BN
17
- byAmountIn: boolean
18
- depth?: number
19
- splitAlgorithm?: string
20
- splitFactor?: number
21
- splitCount?: number
22
- providers?: string[]
23
- liquidityChanges?: PreSwapLpChangeParams[]
24
- }
25
-
26
- export interface PreSwapLpChangeParams {
27
- poolID: string
28
- ticklower: number
29
- tickUpper: number
30
- deltaLiquidity: number
31
- }
32
-
33
- export type ExtendedDetails = {
34
- // aftermath
35
- aftermathPoolFlatness?: number
36
- aftermathLpSupplyType?: string
37
- // turbos
38
- turbosFeeType?: string
39
- // cetus
40
- afterSqrtPrice?: string
41
- // deepbookv3
42
- deepbookv3DeepFee?: number
43
- // scallop
44
- scallopScoinTreasury?: string
45
- // haedal
46
- haedalPmmBasePriceSeed?: string
47
- haedalPmmQuotePriceSeed?: string
48
- // steamm
49
- steammBankA?: string
50
- steammBankB?: string
51
- steammLendingMarket?: string
52
- steammLendingMarketType?: string
53
- steammBCoinAType?: string
54
- steammBCoinBType?: string
55
- steammLPToken?: string
56
- metastablePriceSeed?: string
57
- metastableETHPriceSeed?: string
58
- metastableWhitelistedAppId?: string
59
- metastableCreateCapPkgId?: string
60
- metastableCreateCapModule?: string
61
- metastableCreateCapAllTypeParams?: boolean
62
- metastableRegistryId?: string
63
- obricCoinAPriceSeed?: string
64
- obricCoinBPriceSeed?: string
65
- obricCoinAPriceId?: string
66
- obricCoinBPriceId?: string
67
- }
68
-
69
- export type Path = {
70
- id: string
71
- direction: boolean
72
- provider: string
73
- from: string
74
- target: string
75
- feeRate: number
76
- amountIn: string
77
- amountOut: string
78
- version?: string
79
- extendedDetails?: ExtendedDetails
80
- }
81
-
82
- export type Router = {
83
- path: Path[]
84
- amountIn: BN
85
- amountOut: BN
86
- initialPrice: Decimal
87
- }
88
-
89
- export type RouterError = {
90
- code: number
91
- msg: string
92
- }
93
-
94
- export type RouterData = {
95
- amountIn: BN
96
- amountOut: BN
97
- byAmountIn: boolean
98
- routes: Router[]
99
- insufficientLiquidity: boolean
100
- packages?: Map<string, string>
101
- totalDeepFee?: number
102
- error?: RouterError
103
- }
104
-
105
- export type AggregatorResponse = {
106
- code: number
107
- msg: string
108
- data: RouterData
109
- }
110
-
111
- export async function getRouterResult(
112
- endpoint: string,
113
- apiKey: string,
114
- params: FindRouterParams
115
- ): Promise<RouterData | null> {
116
- let response
117
- if (params.liquidityChanges && params.liquidityChanges.length > 0) {
118
- response = await postRouterWithLiquidityChanges(endpoint, params)
119
- } else {
120
- response = await getRouter(endpoint, apiKey, params)
121
- }
122
-
123
- if (!response) {
124
- return null
125
- }
126
-
127
- if (!response.ok) {
128
- let errorCode = AggregatorServerErrorCode.NumberTooLarge
129
- if (response.status === 429) {
130
- errorCode = AggregatorServerErrorCode.RateLimitExceeded
131
- }
132
-
133
- return {
134
- amountIn: ZERO,
135
- amountOut: ZERO,
136
- routes: [],
137
- byAmountIn: params.byAmountIn,
138
- insufficientLiquidity: false,
139
- error: {
140
- code: errorCode,
141
- msg: getAggregatorServerErrorMessage(errorCode),
142
- },
143
- }
144
- }
145
- const data = await response.json()
146
- const insufficientLiquidity = data.msg === "liquidity is not enough"
147
-
148
- if (data.msg && data.msg.indexOf("HoneyPot scam") > -1) {
149
- return {
150
- amountIn: ZERO,
151
- amountOut: ZERO,
152
- routes: [],
153
- byAmountIn: params.byAmountIn,
154
- insufficientLiquidity,
155
- error: {
156
- code: AggregatorServerErrorCode.HoneyPot,
157
- msg: getAggregatorServerErrorMessage(
158
- AggregatorServerErrorCode.HoneyPot
159
- ),
160
- },
161
- }
162
- }
163
- if (data.data != null) {
164
- const res = parseRouterResponse(data.data, params.byAmountIn)
165
- return res
166
- }
167
-
168
- return {
169
- amountIn: ZERO,
170
- amountOut: ZERO,
171
- routes: [],
172
- insufficientLiquidity,
173
- byAmountIn: params.byAmountIn,
174
- error: {
175
- code: AggregatorServerErrorCode.InsufficientLiquidity,
176
- msg: getAggregatorServerErrorMessage(
177
- AggregatorServerErrorCode.InsufficientLiquidity
178
- ),
179
- },
180
- }
181
- }
182
-
183
- async function getRouter(endpoint: string, apiKey: string, params: FindRouterParams) {
184
- try {
185
- const {
186
- from,
187
- target,
188
- amount,
189
- byAmountIn,
190
- depth,
191
- splitAlgorithm,
192
- splitFactor,
193
- splitCount,
194
- providers,
195
- } = params
196
- const fromCoin = completionCoin(from)
197
- const targetCoin = completionCoin(target)
198
-
199
- let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
200
-
201
- if (depth) {
202
- url += `&depth=${depth}`
203
- }
204
-
205
- if (splitAlgorithm) {
206
- url += `&split_algorithm=${splitAlgorithm}`
207
- }
208
-
209
- if (splitFactor) {
210
- url += `&split_factor=${splitFactor}`
211
- }
212
-
213
- if (splitCount) {
214
- url += `&split_count=${splitCount}`
215
- }
216
-
217
- if (providers) {
218
- if (providers.length > 0) {
219
- url += `&providers=${providers.join(",")}`
220
- }
221
- }
222
-
223
- if (apiKey.length > 0) {
224
- url += `&apiKey=${apiKey}`
225
- }
226
-
227
- // set newest sdk version
228
- url += `&v=${SDK_VERSION}`
229
-
230
- const response = await fetch(url)
231
- return response
232
- } catch (error) {
233
- console.error(error)
234
- return null
235
- }
236
- }
237
-
238
- async function postRouterWithLiquidityChanges(
239
- endpoint: string,
240
- params: FindRouterParams
241
- ) {
242
- const {
243
- from,
244
- target,
245
- amount,
246
- byAmountIn,
247
- depth,
248
- splitAlgorithm,
249
- splitFactor,
250
- splitCount,
251
- providers,
252
- liquidityChanges,
253
- } = params
254
-
255
- const fromCoin = completionCoin(from)
256
- const targetCoin = completionCoin(target)
257
- const url = `${endpoint}/find_routes`
258
- const providersStr = providers?.join(",")
259
- const requestData = {
260
- from: fromCoin,
261
- target: targetCoin,
262
- amount: Number(amount.toString()),
263
- by_amount_in: byAmountIn,
264
- depth,
265
- split_algorithm: splitAlgorithm,
266
- split_factor: splitFactor,
267
- split_count: splitCount,
268
- providers: providersStr,
269
- liquidity_changes: liquidityChanges!.map((change) => ({
270
- pool: change.poolID,
271
- tick_lower: change.ticklower,
272
- tick_upper: change.tickUpper,
273
- delta_liquidity: change.deltaLiquidity,
274
- })),
275
- v: SDK_VERSION,
276
- }
277
-
278
- try {
279
- const response = await fetch(url, {
280
- method: "POST",
281
- headers: {
282
- "Content-Type": "application/json",
283
- },
284
- body: JSON.stringify(requestData),
285
- })
286
-
287
- return response
288
- } catch (error) {
289
- console.error("Error:", error)
290
- return null
291
- }
292
- }
293
-
294
- export type DeepbookV3Config = {
295
- id: string
296
- is_alternative_payment: boolean
297
- alternative_payment_amount: number
298
- trade_cap: string
299
- balance_manager: string
300
- deep_fee_vault: number
301
- whitelist: number
302
- package_version: 0
303
- // unix timestamp in seconds
304
- last_updated_time: number
305
- whitelist_pools: string[]
306
- }
307
-
308
- export type DeepbookV3ConfigResponse = {
309
- code: number
310
- msg: string
311
- data: DeepbookV3Config
312
- }
313
-
314
- export async function getDeepbookV3Config(
315
- endpoint: string
316
- ): Promise<DeepbookV3ConfigResponse | null> {
317
- const url = `${endpoint}/deepbookv3_config`
318
- try {
319
- const response = await fetch(url)
320
- return response.json() as Promise<DeepbookV3ConfigResponse>
321
- } catch (error) {
322
- console.error("Error:", error)
323
- return null
324
- }
325
- }