@cetusprotocol/aggregator-sdk 0.4.0 → 0.4.2
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 +19 -8
- package/dist/index.d.mts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +25 -27
- package/dist/index.mjs +26 -28
- package/package.json +1 -1
- package/dist/src/api.d.ts +0 -104
- package/dist/src/client.d.ts +0 -107
- package/dist/src/const.d.ts +0 -8
- package/dist/src/errors.d.ts +0 -40
- package/dist/src/index.d.ts +0 -9
- package/dist/src/math.d.ts +0 -6
- package/dist/src/transaction/afsui.d.ts +0 -10
- package/dist/src/transaction/aftermath.d.ts +0 -13
- package/dist/src/transaction/alphafi.d.ts +0 -7
- package/dist/src/transaction/bluefin.d.ts +0 -7
- package/dist/src/transaction/bluemove.d.ts +0 -7
- package/dist/src/transaction/cetus.d.ts +0 -15
- package/dist/src/transaction/deepbook_v2.d.ts +0 -14
- package/dist/src/transaction/deepbook_v3.d.ts +0 -12
- package/dist/src/transaction/flowx_v2.d.ts +0 -7
- package/dist/src/transaction/flowx_v3.d.ts +0 -8
- package/dist/src/transaction/haedal.d.ts +0 -6
- package/dist/src/transaction/haedal_pmm.d.ts +0 -7
- package/dist/src/transaction/index.d.ts +0 -10
- package/dist/src/transaction/kriya_v2.d.ts +0 -6
- package/dist/src/transaction/kriya_v3.d.ts +0 -7
- package/dist/src/transaction/metastable.d.ts +0 -8
- package/dist/src/transaction/obric.d.ts +0 -8
- package/dist/src/transaction/scallop.d.ts +0 -8
- package/dist/src/transaction/steamm.d.ts +0 -6
- package/dist/src/transaction/suilend.d.ts +0 -7
- package/dist/src/transaction/swap.d.ts +0 -4
- package/dist/src/transaction/turbos.d.ts +0 -7
- package/dist/src/transaction/volo.d.ts +0 -8
- package/dist/src/types/CoinAssist.d.ts +0 -122
- package/dist/src/types/sui.d.ts +0 -112
- package/dist/src/utils/api.d.ts +0 -1
- package/dist/src/utils/coin.d.ts +0 -11
- package/dist/src/utils/contracts.d.ts +0 -16
- package/dist/src/utils/index.d.ts +0 -5
- package/dist/src/utils/msafe.d.ts +0 -2
- package/dist/src/utils/transaction.d.ts +0 -3
- package/dist/tests/math.test.d.ts +0 -1
- package/dist/tests/router/metastable.test.d.ts +0 -2
- package/dist/tests/router/obric.test.d.ts +0 -2
- package/dist/tests/router/scallop.test.d.ts +0 -2
- package/dist/tests/router/steamm.test.d.ts +0 -2
- package/dist/tests/router.test.d.ts +0 -2
- package/dist/tests/test_data.test.d.ts +0 -18
- package/dist/tests/wallet.test.d.ts +0 -1
- package/example/package.json +0 -17
- package/example/swap.ts +0 -21
- package/example/tsconfig.json +0 -12
- package/jest.config.mjs +0 -13
- package/src/api.ts +0 -320
- package/src/client.ts +0 -1081
- package/src/const.ts +0 -15
- package/src/errors.ts +0 -77
- package/src/index.ts +0 -10
- package/src/math.ts +0 -66
- package/src/transaction/afsui.ts +0 -62
- package/src/transaction/aftermath.ts +0 -88
- package/src/transaction/alphafi.ts +0 -50
- package/src/transaction/bluefin.ts +0 -46
- package/src/transaction/bluemove.ts +0 -42
- package/src/transaction/cetus.ts +0 -118
- package/src/transaction/deepbook_v2.ts +0 -122
- package/src/transaction/deepbook_v3.ts +0 -60
- package/src/transaction/flowx_v2.ts +0 -42
- package/src/transaction/flowx_v3.ts +0 -52
- package/src/transaction/haedal.ts +0 -33
- package/src/transaction/haedal_pmm.ts +0 -80
- package/src/transaction/index.ts +0 -42
- package/src/transaction/kriya_v2.ts +0 -37
- package/src/transaction/kriya_v3.ts +0 -47
- package/src/transaction/metastable.ts +0 -141
- package/src/transaction/obric.ts +0 -90
- package/src/transaction/scallop.ts +0 -64
- package/src/transaction/steamm.ts +0 -77
- package/src/transaction/suilend.ts +0 -48
- package/src/transaction/swap.ts +0 -162
- package/src/transaction/turbos.ts +0 -56
- package/src/transaction/volo.ts +0 -53
- package/src/types/CoinAssist.ts +0 -217
- package/src/types/sui.ts +0 -148
- package/src/utils/api.ts +0 -6
- package/src/utils/coin.ts +0 -136
- package/src/utils/contracts.ts +0 -136
- package/src/utils/index.ts +0 -5
- package/src/utils/msafe.ts +0 -40
- package/src/utils/transaction.ts +0 -20
- package/tests/math.test.ts +0 -21
- package/tests/router/metastable.test.ts +0 -377
- package/tests/router/obric.test.ts +0 -197
- package/tests/router/scallop.test.ts +0 -127
- package/tests/router/steamm.test.ts +0 -124
- package/tests/router.test.ts +0 -373
- package/tests/test_data.test.ts +0 -28
- package/tests/wallet.test.ts +0 -21
- package/tsup.config.ts +0 -23
- package/version.mjs +0 -28
package/example/package.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "aggregator-example",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Cetus Aggregator SDK usage example",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"swap": "ts-node swap.ts"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"@cetusprotocol/aggregator-sdk": "^0.3.18",
|
|
11
|
-
"@mysten/sui.js": "^0.49.1"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"typescript": "^5.0.0",
|
|
15
|
-
"ts-node": "^10.9.1"
|
|
16
|
-
}
|
|
17
|
-
}
|
package/example/swap.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AggregatorClient } from "@cetusprotocol/aggregator-sdk"
|
|
2
|
-
import BN from "bn.js"
|
|
3
|
-
|
|
4
|
-
async function main() {
|
|
5
|
-
// default to mainnet
|
|
6
|
-
const client = new AggregatorClient()
|
|
7
|
-
|
|
8
|
-
const from = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
|
|
9
|
-
const target = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
|
|
10
|
-
|
|
11
|
-
const routers = await client.findRouters({
|
|
12
|
-
from,
|
|
13
|
-
target,
|
|
14
|
-
amount: new BN(1000000000),
|
|
15
|
-
byAmountIn: true,
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
console.log(routers)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
main()
|
package/example/tsconfig.json
DELETED
package/jest.config.mjs
DELETED
package/src/api.ts
DELETED
|
@@ -1,320 +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 = 1000400
|
|
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
|
-
params: FindRouterParams
|
|
114
|
-
): Promise<RouterData | null> {
|
|
115
|
-
let response
|
|
116
|
-
if (params.liquidityChanges && params.liquidityChanges.length > 0) {
|
|
117
|
-
response = await postRouterWithLiquidityChanges(endpoint, params)
|
|
118
|
-
} else {
|
|
119
|
-
response = await getRouter(endpoint, params)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!response) {
|
|
123
|
-
return null
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (!response.ok) {
|
|
127
|
-
let errorCode = AggregatorServerErrorCode.NumberTooLarge
|
|
128
|
-
if (response.status === 429) {
|
|
129
|
-
errorCode = AggregatorServerErrorCode.RateLimitExceeded
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
amountIn: ZERO,
|
|
134
|
-
amountOut: ZERO,
|
|
135
|
-
routes: [],
|
|
136
|
-
byAmountIn: params.byAmountIn,
|
|
137
|
-
insufficientLiquidity: false,
|
|
138
|
-
error: {
|
|
139
|
-
code: errorCode,
|
|
140
|
-
msg: getAggregatorServerErrorMessage(errorCode),
|
|
141
|
-
},
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
const data = await response.json()
|
|
145
|
-
const insufficientLiquidity = data.msg === "liquidity is not enough"
|
|
146
|
-
|
|
147
|
-
if (data.msg && data.msg.indexOf("HoneyPot scam") > -1) {
|
|
148
|
-
return {
|
|
149
|
-
amountIn: ZERO,
|
|
150
|
-
amountOut: ZERO,
|
|
151
|
-
routes: [],
|
|
152
|
-
byAmountIn: params.byAmountIn,
|
|
153
|
-
insufficientLiquidity,
|
|
154
|
-
error: {
|
|
155
|
-
code: AggregatorServerErrorCode.HoneyPot,
|
|
156
|
-
msg: getAggregatorServerErrorMessage(
|
|
157
|
-
AggregatorServerErrorCode.HoneyPot
|
|
158
|
-
),
|
|
159
|
-
},
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (data.data != null) {
|
|
163
|
-
const res = parseRouterResponse(data.data, params.byAmountIn)
|
|
164
|
-
return res
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
amountIn: ZERO,
|
|
169
|
-
amountOut: ZERO,
|
|
170
|
-
routes: [],
|
|
171
|
-
insufficientLiquidity,
|
|
172
|
-
byAmountIn: params.byAmountIn,
|
|
173
|
-
error: {
|
|
174
|
-
code: AggregatorServerErrorCode.InsufficientLiquidity,
|
|
175
|
-
msg: getAggregatorServerErrorMessage(
|
|
176
|
-
AggregatorServerErrorCode.InsufficientLiquidity
|
|
177
|
-
),
|
|
178
|
-
},
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async function getRouter(endpoint: string, params: FindRouterParams) {
|
|
183
|
-
try {
|
|
184
|
-
const {
|
|
185
|
-
from,
|
|
186
|
-
target,
|
|
187
|
-
amount,
|
|
188
|
-
byAmountIn,
|
|
189
|
-
depth,
|
|
190
|
-
splitAlgorithm,
|
|
191
|
-
splitFactor,
|
|
192
|
-
splitCount,
|
|
193
|
-
providers,
|
|
194
|
-
} = params
|
|
195
|
-
const fromCoin = completionCoin(from)
|
|
196
|
-
const targetCoin = completionCoin(target)
|
|
197
|
-
|
|
198
|
-
let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
|
|
199
|
-
|
|
200
|
-
if (depth) {
|
|
201
|
-
url += `&depth=${depth}`
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (splitAlgorithm) {
|
|
205
|
-
url += `&split_algorithm=${splitAlgorithm}`
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (splitFactor) {
|
|
209
|
-
url += `&split_factor=${splitFactor}`
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (splitCount) {
|
|
213
|
-
url += `&split_count=${splitCount}`
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (providers) {
|
|
217
|
-
if (providers.length > 0) {
|
|
218
|
-
url += `&providers=${providers.join(",")}`
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// set newest sdk version
|
|
223
|
-
url += `&v=${SDK_VERSION}`
|
|
224
|
-
|
|
225
|
-
const response = await fetch(url)
|
|
226
|
-
return response
|
|
227
|
-
} catch (error) {
|
|
228
|
-
console.error(error)
|
|
229
|
-
return null
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async function postRouterWithLiquidityChanges(
|
|
234
|
-
endpoint: string,
|
|
235
|
-
params: FindRouterParams
|
|
236
|
-
) {
|
|
237
|
-
const {
|
|
238
|
-
from,
|
|
239
|
-
target,
|
|
240
|
-
amount,
|
|
241
|
-
byAmountIn,
|
|
242
|
-
depth,
|
|
243
|
-
splitAlgorithm,
|
|
244
|
-
splitFactor,
|
|
245
|
-
splitCount,
|
|
246
|
-
providers,
|
|
247
|
-
liquidityChanges,
|
|
248
|
-
} = params
|
|
249
|
-
|
|
250
|
-
const fromCoin = completionCoin(from)
|
|
251
|
-
const targetCoin = completionCoin(target)
|
|
252
|
-
const url = `${endpoint}/find_routes`
|
|
253
|
-
const providersStr = providers?.join(",")
|
|
254
|
-
const requestData = {
|
|
255
|
-
from: fromCoin,
|
|
256
|
-
target: targetCoin,
|
|
257
|
-
amount: Number(amount.toString()),
|
|
258
|
-
by_amount_in: byAmountIn,
|
|
259
|
-
depth,
|
|
260
|
-
split_algorithm: splitAlgorithm,
|
|
261
|
-
split_factor: splitFactor,
|
|
262
|
-
split_count: splitCount,
|
|
263
|
-
providers: providersStr,
|
|
264
|
-
liquidity_changes: liquidityChanges!.map((change) => ({
|
|
265
|
-
pool: change.poolID,
|
|
266
|
-
tick_lower: change.ticklower,
|
|
267
|
-
tick_upper: change.tickUpper,
|
|
268
|
-
delta_liquidity: change.deltaLiquidity,
|
|
269
|
-
})),
|
|
270
|
-
v: SDK_VERSION,
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
try {
|
|
274
|
-
const response = await fetch(url, {
|
|
275
|
-
method: "POST",
|
|
276
|
-
headers: {
|
|
277
|
-
"Content-Type": "application/json",
|
|
278
|
-
},
|
|
279
|
-
body: JSON.stringify(requestData),
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
return response
|
|
283
|
-
} catch (error) {
|
|
284
|
-
console.error("Error:", error)
|
|
285
|
-
return null
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export type DeepbookV3Config = {
|
|
290
|
-
id: string
|
|
291
|
-
is_alternative_payment: boolean
|
|
292
|
-
alternative_payment_amount: number
|
|
293
|
-
trade_cap: string
|
|
294
|
-
balance_manager: string
|
|
295
|
-
deep_fee_vault: number
|
|
296
|
-
whitelist: number
|
|
297
|
-
package_version: 0
|
|
298
|
-
// unix timestamp in seconds
|
|
299
|
-
last_updated_time: number
|
|
300
|
-
whitelist_pools: string[]
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export type DeepbookV3ConfigResponse = {
|
|
304
|
-
code: number
|
|
305
|
-
msg: string
|
|
306
|
-
data: DeepbookV3Config
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export async function getDeepbookV3Config(
|
|
310
|
-
endpoint: string
|
|
311
|
-
): Promise<DeepbookV3ConfigResponse | null> {
|
|
312
|
-
const url = `${endpoint}/deepbookv3_config`
|
|
313
|
-
try {
|
|
314
|
-
const response = await fetch(url)
|
|
315
|
-
return response.json() as Promise<DeepbookV3ConfigResponse>
|
|
316
|
-
} catch (error) {
|
|
317
|
-
console.error("Error:", error)
|
|
318
|
-
return null
|
|
319
|
-
}
|
|
320
|
-
}
|