@cetusprotocol/aggregator-sdk 0.0.8 → 0.1.1

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 (57) hide show
  1. package/dist/index.d.mts +98 -161
  2. package/dist/index.d.ts +98 -161
  3. package/dist/index.js +1128 -1550
  4. package/dist/index.mjs +1116 -1488
  5. package/dist/src/api.d.ts +53 -0
  6. package/dist/src/client.d.ts +38 -65
  7. package/dist/src/const.d.ts +0 -68
  8. package/dist/src/index.d.ts +9 -5
  9. package/dist/src/transaction/afsui.d.ts +10 -0
  10. package/dist/src/transaction/aftermath.d.ts +13 -24
  11. package/dist/src/transaction/cetus.d.ts +9 -33
  12. package/dist/src/transaction/deepbook_v2.d.ts +14 -0
  13. package/dist/src/transaction/flowx_v2.d.ts +7 -0
  14. package/dist/src/transaction/haedal.d.ts +6 -0
  15. package/dist/src/transaction/index.d.ts +6 -1
  16. package/dist/src/transaction/kriya_v2.d.ts +6 -0
  17. package/dist/src/transaction/kriya_v3.d.ts +7 -0
  18. package/dist/src/transaction/swap.d.ts +1 -2
  19. package/dist/src/transaction/turbos.d.ts +7 -22
  20. package/dist/src/transaction/volo.d.ts +8 -0
  21. package/dist/src/utils/coin.d.ts +9 -0
  22. package/dist/{src → tests}/test_data.test.d.ts +1 -0
  23. package/package.json +2 -2
  24. package/src/api.ts +144 -0
  25. package/src/client.ts +295 -239
  26. package/src/const.ts +0 -113
  27. package/src/index.ts +10 -5
  28. package/src/transaction/afsui.ts +60 -0
  29. package/src/transaction/aftermath.ts +71 -124
  30. package/src/transaction/cetus.ts +87 -258
  31. package/src/transaction/deepbook_v2.ts +122 -0
  32. package/src/transaction/flowx_v2.ts +42 -0
  33. package/src/transaction/haedal.ts +41 -0
  34. package/src/transaction/index.ts +17 -1
  35. package/src/transaction/kriya_v2.ts +38 -0
  36. package/src/transaction/kriya_v3.ts +46 -0
  37. package/src/transaction/swap.ts +17 -24
  38. package/src/transaction/turbos.ts +40 -99
  39. package/src/transaction/volo.ts +52 -0
  40. package/src/utils/coin.ts +91 -6
  41. package/src/utils/transaction.ts +1 -1
  42. package/tests/router.test.ts +123 -73
  43. package/{src → tests}/test_data.test.ts +2 -0
  44. package/dist/src/config.d.ts +0 -26
  45. package/dist/src/transaction/common.d.ts +0 -12
  46. package/dist/src/transaction/deepbook.d.ts +0 -21
  47. package/dist/src/transaction/flowx.d.ts +0 -20
  48. package/dist/src/transaction/kriya.d.ts +0 -21
  49. package/dist/src/transaction/router.d.ts +0 -6
  50. package/dist/src/utils/account_cap.d.ts +0 -7
  51. package/src/config.ts +0 -65
  52. package/src/transaction/common.ts +0 -169
  53. package/src/transaction/deepbook.ts +0 -126
  54. package/src/transaction/flowx.ts +0 -97
  55. package/src/transaction/kriya.ts +0 -77
  56. package/src/transaction/router.ts +0 -339
  57. package/src/utils/account_cap.ts +0 -62
@@ -3,279 +3,108 @@ import {
3
3
  TransactionArgument,
4
4
  TransactionObjectArgument,
5
5
  } from "@mysten/sui/transactions"
6
- import { AggregatorConfig, ENV } from "../config"
7
- import {
8
- AGGREGATOR,
9
- CLOCK_ADDRESS,
10
- CETUS_MODULE,
11
- FlashSwapA2BFunc,
12
- MAINNET_CETUS_GLOBAL_CONFIG_ID,
13
- TESTNET_CETUS_GLOBAL_CONFIG_ID,
14
- FlashSwapWithPartnerA2BFunc,
15
- FlashSwapWithPartnerB2AFunc,
16
- FlashSwapB2AFunc,
17
- REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC,
18
- REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC,
19
- REPAY_FLASH_SWAP_A2B_FUNC,
20
- REPAY_FLASH_SWAP_B2A_FUNC,
21
- } from "../const"
22
- import { ConfigErrorCode, TransactionErrorCode } from "../errors"
23
- import BN from "bn.js"
24
- import { createTarget } from "../utils"
25
-
26
- export type CetusSwapParams = {
27
- poolId: string
28
- amount: TransactionArgument
29
- amountLimit: string
30
- a2b: boolean
31
- byAmountIn: boolean
32
- sqrtPriceLimit: BN
33
- partner?: string
34
- coinAType: string
35
- coinBType: string
36
- }
6
+ import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
37
7
 
38
8
  export type CetusFlashSwapResult = {
39
9
  targetCoin: TransactionObjectArgument
40
10
  flashReceipt: TransactionObjectArgument
41
11
  payAmount: TransactionArgument
42
- swapedAmount: TransactionArgument
43
- txb: Transaction
44
12
  }
45
13
 
46
- export function cetusFlashSwapMovecall(
47
- swapParams: CetusSwapParams,
48
- txb: Transaction,
49
- config: AggregatorConfig
50
- ): CetusFlashSwapResult {
51
- const aggregatorPackage = config.getPackage(AGGREGATOR)
52
- if (aggregatorPackage == null) {
53
- throw new AggregateError(
54
- "Aggregator package not set",
55
- ConfigErrorCode.MissAggregatorPackage
56
- )
57
- }
58
- const aggregatorPublishedAt = aggregatorPackage.publishedAt
59
-
60
- const globalConfigId =
61
- config.getENV() === ENV.MAINNET
62
- ? MAINNET_CETUS_GLOBAL_CONFIG_ID
63
- : TESTNET_CETUS_GLOBAL_CONFIG_ID
64
-
65
- const hasPartner = swapParams.partner != null && swapParams.partner.length > 0
14
+ export class Cetus implements Dex {
15
+ private globalConfig: string
16
+ private partner: string
66
17
 
67
- const args = hasPartner
68
- ? [
69
- txb.object(globalConfigId),
70
- txb.object(swapParams.poolId),
71
- swapParams.amount,
72
- txb.pure.u64(swapParams.amountLimit),
73
- txb.pure.bool(swapParams.byAmountIn),
74
- txb.pure.u128(swapParams.sqrtPriceLimit.toString()),
75
- txb.object(swapParams.partner!.toString()),
76
- txb.object(CLOCK_ADDRESS),
77
- ]
78
- : [
79
- txb.object(globalConfigId),
80
- txb.object(swapParams.poolId),
81
- swapParams.amount,
82
- txb.pure.u64(swapParams.amountLimit),
83
- txb.pure.bool(swapParams.byAmountIn),
84
- txb.pure.u128(swapParams.sqrtPriceLimit.toString()),
85
- txb.object(CLOCK_ADDRESS),
86
- ]
18
+ constructor(env: Env, partner?: string) {
19
+ this.globalConfig =
20
+ env === Env.Mainnet
21
+ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f"
22
+ : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a"
87
23
 
88
- let func
89
- if (hasPartner) {
90
- if (swapParams.a2b) {
91
- func = FlashSwapWithPartnerA2BFunc
92
- } else {
93
- func = FlashSwapWithPartnerB2AFunc
94
- }
95
- } else {
96
- if (swapParams.a2b) {
97
- func = FlashSwapA2BFunc
98
- } else {
99
- func = FlashSwapB2AFunc
100
- }
24
+ this.partner =
25
+ partner ??
26
+ "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b"
101
27
  }
102
28
 
103
- const target = createTarget(aggregatorPublishedAt, CETUS_MODULE, func)
104
-
105
- const moveCallRes = txb.moveCall({
106
- target,
107
- typeArguments: [swapParams.coinAType, swapParams.coinBType],
108
- arguments: args,
109
- })
110
-
111
- return {
112
- targetCoin: moveCallRes[0],
113
- flashReceipt: moveCallRes[1],
114
- payAmount: moveCallRes[2],
115
- swapedAmount: moveCallRes[3],
116
- txb,
117
- }
118
- }
119
-
120
- export type repayParams = {
121
- poolId: string
122
- a2b: boolean
123
- coinA?: TransactionObjectArgument
124
- coinB?: TransactionObjectArgument
125
- receipt: TransactionObjectArgument
126
- coinAType: string
127
- coinBType: string
128
- partner?: string
129
- }
130
-
131
- export type SwapResult = {
132
- repayTargetCoin: TransactionObjectArgument
133
- nextInputAmount?: TransactionArgument
134
- flashTargetCoin?: TransactionObjectArgument
135
- }
136
-
137
- export async function cetusRepayFlashSwapMovecall(
138
- repayParams: repayParams,
139
- txb: Transaction,
140
- config: AggregatorConfig
141
- ): Promise<SwapResult> {
142
- const aggregatorPackage = config.getPackage(AGGREGATOR)
143
- if (aggregatorPackage == null) {
144
- throw new AggregateError(
145
- "Aggregator package not set",
146
- ConfigErrorCode.MissAggregatorPackage
147
- )
148
- }
149
- const aggregatorPublishedAt = aggregatorPackage.publishedAt
150
-
151
- const globalConfigId =
152
- config.getENV() === ENV.MAINNET
153
- ? MAINNET_CETUS_GLOBAL_CONFIG_ID
154
- : TESTNET_CETUS_GLOBAL_CONFIG_ID
155
-
156
- const hasPartner =
157
- repayParams.partner != null && repayParams.partner.length > 0
158
-
159
- if (repayParams.a2b) {
160
- if (repayParams.coinA == null) {
161
- throw new AggregateError(
162
- "coinA is required",
163
- TransactionErrorCode.MissCoinA
164
- )
29
+ flash_swap(
30
+ client: AggregatorClient,
31
+ txb: Transaction,
32
+ path: Path,
33
+ by_amount_in: boolean
34
+ ): CetusFlashSwapResult {
35
+ const { direction, from, target } = path
36
+ const [func, coinAType, coinBType] = direction
37
+ ? ["flash_swap_a2b", from, target]
38
+ : ["flash_swap_b2a", target, from]
39
+ let amount = by_amount_in ? path.amountIn : path.amountOut
40
+ const args = [
41
+ txb.object(this.globalConfig),
42
+ txb.object(path.id),
43
+ txb.object(this.partner),
44
+ txb.pure.u64(amount),
45
+ txb.pure.bool(by_amount_in),
46
+ txb.object(CLOCK_ADDRESS),
47
+ ]
48
+ const res: TransactionObjectArgument[] = txb.moveCall({
49
+ target: `${client.publishedAt()}::cetus::${func}`,
50
+ typeArguments: [coinAType, coinBType],
51
+ arguments: args,
52
+ })
53
+ return {
54
+ targetCoin: res[0],
55
+ flashReceipt: res[1],
56
+ payAmount: res[2],
165
57
  }
166
- } else {
167
- if (repayParams.coinB == null) {
168
- throw new AggregateError(
169
- "coinB is required",
170
- TransactionErrorCode.MissCoinB
171
- )
172
- }
173
- }
174
-
175
- let args
176
- if (hasPartner) {
177
- if (repayParams.a2b) {
178
- args = [
179
- txb.object(globalConfigId),
180
- txb.object(repayParams.poolId),
181
- repayParams.coinA!,
182
- repayParams.receipt,
183
- txb.object(repayParams.partner!),
184
- ]
185
- } else {
186
- args = [
187
- txb.object(globalConfigId),
188
- txb.object(repayParams.poolId),
189
- repayParams.coinB!,
190
- repayParams.receipt,
191
- txb.object(repayParams.partner!),
192
- ]
193
- }
194
- } else {
195
- if (repayParams.a2b) {
196
- args = [
197
- txb.object(globalConfigId),
198
- txb.object(repayParams.poolId),
199
- repayParams.coinA!,
200
- repayParams.receipt,
201
- ]
202
- } else {
203
- args = [
204
- txb.object(globalConfigId),
205
- txb.object(repayParams.poolId),
206
- repayParams.coinB!,
207
- repayParams.receipt,
208
- ]
209
- }
210
- }
211
-
212
- let func
213
- if (hasPartner) {
214
- if (repayParams.a2b) {
215
- func = REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC
216
- } else {
217
- func = REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC
218
- }
219
- } else {
220
- if (repayParams.a2b) {
221
- func = REPAY_FLASH_SWAP_A2B_FUNC
222
- } else {
223
- func = REPAY_FLASH_SWAP_B2A_FUNC
224
- }
225
- }
226
-
227
- const target = createTarget(aggregatorPublishedAt, CETUS_MODULE, func)
228
-
229
- const res: TransactionObjectArgument[] = txb.moveCall({
230
- target,
231
- typeArguments: [repayParams.coinAType, repayParams.coinBType],
232
- arguments: args,
233
- })
234
-
235
- return {
236
- repayTargetCoin: res[0],
237
- }
238
- }
239
-
240
- export async function cetusSwapWithOutLimit(
241
- swapParams: CetusSwapParams,
242
- fromCoin: TransactionObjectArgument,
243
- txb: Transaction,
244
- config: AggregatorConfig
245
- ): Promise<SwapResult> {
246
- const flashResult = cetusFlashSwapMovecall(swapParams, txb, config)
247
-
248
- const repayCoinA = swapParams.a2b ? fromCoin : undefined
249
- const repayCoinB = swapParams.a2b ? undefined : fromCoin
250
-
251
- const repayParams = {
252
- poolId: swapParams.poolId,
253
- a2b: swapParams.a2b,
254
- coinA: repayCoinA,
255
- coinB: repayCoinB,
256
- receipt: flashResult.flashReceipt,
257
- coinAType: swapParams.coinAType,
258
- coinBType: swapParams.coinBType,
259
- partner: swapParams.partner,
260
58
  }
261
59
 
262
- let nextInputAmount: TransactionArgument
263
-
264
- if (swapParams.byAmountIn) {
265
- nextInputAmount = flashResult.swapedAmount
266
- } else {
267
- nextInputAmount = flashResult.payAmount
60
+ repay_flash_swap(
61
+ client: AggregatorClient,
62
+ txb: Transaction,
63
+ path: Path,
64
+ inputCoin: TransactionObjectArgument,
65
+ receipt: TransactionArgument
66
+ ): TransactionObjectArgument {
67
+ const { direction, from, target } = path
68
+ const [func, coinAType, coinBType] = direction
69
+ ? ["repay_flash_swap_a2b", from, target]
70
+ : ["repay_flash_swap_b2a", target, from]
71
+ const args = [
72
+ txb.object(this.globalConfig),
73
+ txb.object(path.id),
74
+ txb.object(this.partner),
75
+ inputCoin,
76
+ receipt,
77
+ ]
78
+ const res = txb.moveCall({
79
+ target: `${client.publishedAt()}::cetus::${func}`,
80
+ typeArguments: [coinAType, coinBType],
81
+ arguments: args,
82
+ })
83
+ return res[0] as TransactionObjectArgument
268
84
  }
269
85
 
270
- const repayResult = await cetusRepayFlashSwapMovecall(
271
- repayParams,
272
- txb,
273
- config
274
- )
275
-
276
- return {
277
- flashTargetCoin: flashResult.targetCoin,
278
- repayTargetCoin: repayResult.repayTargetCoin,
279
- nextInputAmount,
86
+ async swap(
87
+ client: AggregatorClient,
88
+ txb: Transaction,
89
+ path: Path,
90
+ inputCoin: TransactionObjectArgument
91
+ ): Promise<TransactionObjectArgument> {
92
+ const { direction, from, target } = path
93
+ const [func, coinAType, coinBType] = direction
94
+ ? ["swap_a2b", from, target]
95
+ : ["swap_b2a", target, from]
96
+ const args = [
97
+ txb.object(this.globalConfig),
98
+ txb.object(path.id),
99
+ txb.object(this.partner),
100
+ inputCoin,
101
+ txb.object(CLOCK_ADDRESS),
102
+ ]
103
+ const res = txb.moveCall({
104
+ target: `${client.publishedAt()}::cetus::${func}`,
105
+ typeArguments: [coinAType, coinBType],
106
+ arguments: args,
107
+ }) as TransactionArgument
108
+ return res
280
109
  }
281
110
  }
@@ -0,0 +1,122 @@
1
+ import {
2
+ Transaction,
3
+ TransactionArgument,
4
+ TransactionObjectArgument,
5
+ } from "@mysten/sui/transactions"
6
+ import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
7
+ import { SuiClient } from "@mysten/sui/client"
8
+
9
+ const DEEPBOOK_PACKAGE_ID =
10
+ "0x000000000000000000000000000000000000000000000000000000000000dee9"
11
+
12
+ type GetOrCreateAccountCapResult = {
13
+ accountCap: TransactionObjectArgument
14
+ isCreate: boolean
15
+ }
16
+
17
+ export class DeepbookV2 implements Dex {
18
+ constructor(env: Env) {
19
+ if (env !== Env.Mainnet) {
20
+ throw new Error("Aftermath only supported on mainnet")
21
+ }
22
+ }
23
+
24
+ async getAccountCap(
25
+ client: SuiClient,
26
+ owner: string
27
+ ): Promise<string | null> {
28
+ let limit = 50
29
+ let cursor = null
30
+
31
+ while (true) {
32
+ const ownedObjects: any = client.getOwnedObjects({
33
+ owner,
34
+ cursor,
35
+ limit,
36
+ filter: {
37
+ MoveModule: {
38
+ package: DEEPBOOK_PACKAGE_ID,
39
+ module: "custodian_v2",
40
+ },
41
+ },
42
+ })
43
+
44
+ if (ownedObjects != null && ownedObjects.data != null) {
45
+ if (ownedObjects.data.length !== 0) {
46
+ return ownedObjects.data[0].data.objectId
47
+ }
48
+
49
+ if (ownedObjects.data.length < 50) {
50
+ break
51
+ }
52
+ } else {
53
+ break
54
+ }
55
+ }
56
+
57
+ return null
58
+ }
59
+
60
+ async getOrCreateAccountCap(
61
+ txb: Transaction,
62
+ client: SuiClient,
63
+ owner: string
64
+ ): Promise<GetOrCreateAccountCapResult> {
65
+ let accountCapStr = await this.getAccountCap(client, owner)
66
+ if (accountCapStr !== null) {
67
+ return {
68
+ accountCap: txb.object(accountCapStr),
69
+ isCreate: false,
70
+ }
71
+ }
72
+
73
+ const accountCap = txb.moveCall({
74
+ target: `${DEEPBOOK_PACKAGE_ID}::clob_v2::create_account`,
75
+ typeArguments: [],
76
+ arguments: [],
77
+ })
78
+
79
+ return {
80
+ accountCap,
81
+ isCreate: true,
82
+ }
83
+ }
84
+
85
+ async swap(
86
+ client: AggregatorClient,
87
+ txb: Transaction,
88
+ path: Path,
89
+ inputCoin: TransactionObjectArgument
90
+ ): Promise<TransactionObjectArgument> {
91
+ const { direction, from, target } = path
92
+
93
+ const [func, coinAType, coinBType] = direction
94
+ ? ["swap_a2b", from, target]
95
+ : ["swap_b2a", target, from]
96
+
97
+ const accountCapRes = await this.getOrCreateAccountCap(
98
+ txb,
99
+ client.client,
100
+ client.signer
101
+ )
102
+
103
+ const args = [
104
+ txb.object(path.id),
105
+ inputCoin,
106
+ accountCapRes.accountCap,
107
+ txb.object(CLOCK_ADDRESS),
108
+ ]
109
+
110
+ const res = txb.moveCall({
111
+ target: `${client.publishedAt()}::deepbook::${func}`,
112
+ typeArguments: [coinAType, coinBType],
113
+ arguments: args,
114
+ }) as TransactionObjectArgument
115
+
116
+ if (accountCapRes.isCreate) {
117
+ txb.transferObjects([accountCapRes.accountCap], client.signer)
118
+ }
119
+
120
+ return res
121
+ }
122
+ }
@@ -0,0 +1,42 @@
1
+ import {
2
+ Transaction,
3
+ TransactionArgument,
4
+ TransactionObjectArgument,
5
+ } from "@mysten/sui/transactions"
6
+ import { AggregatorClient, Dex, Env, Path } from ".."
7
+
8
+ export class FlowxV2 implements Dex {
9
+ private container: string
10
+
11
+ constructor(env: Env) {
12
+ if (env !== Env.Mainnet) {
13
+ throw new Error("Flowx only supported on mainnet")
14
+ }
15
+
16
+ this.container =
17
+ "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511"
18
+ }
19
+
20
+ async swap(
21
+ client: AggregatorClient,
22
+ txb: Transaction,
23
+ path: Path,
24
+ inputCoin: TransactionObjectArgument
25
+ ): Promise<TransactionObjectArgument> {
26
+ const { direction, from, target } = path
27
+
28
+ const [func, coinAType, coinBType] = direction
29
+ ? ["swap_a2b", from, target]
30
+ : ["swap_b2a", target, from]
31
+
32
+ const args = [txb.object(this.container), inputCoin]
33
+
34
+ const res = txb.moveCall({
35
+ target: `${client.publishedAt()}::flowx_amm::${func}`,
36
+ typeArguments: [coinAType, coinBType],
37
+ arguments: args,
38
+ }) as TransactionObjectArgument
39
+
40
+ return res
41
+ }
42
+ }
@@ -0,0 +1,41 @@
1
+ import {
2
+ Transaction,
3
+ TransactionObjectArgument,
4
+ } from "@mysten/sui/transactions"
5
+ import { AggregatorClient, Dex, Env, Path } from ".."
6
+ import { SUI_SYSTEM_ADDRESS } from "@mysten/sui/utils"
7
+
8
+ export class Haedal implements Dex {
9
+ constructor(env: Env) {
10
+ if (env !== Env.Mainnet) {
11
+ throw new Error("Haedal only supported on mainnet")
12
+ }
13
+ }
14
+
15
+ async swap(
16
+ client: AggregatorClient,
17
+ txb: Transaction,
18
+ path: Path,
19
+ inputCoin: TransactionObjectArgument
20
+ ): Promise<TransactionObjectArgument> {
21
+ const { direction } = path
22
+
23
+ if (!direction) {
24
+ throw new Error("Haedal not support b2a swap")
25
+ }
26
+
27
+ const func = "swap_a2b"
28
+
29
+ console.log("haedal path id", path.id)
30
+
31
+ const args = [txb.object(path.id), txb.object("0x5"), inputCoin]
32
+
33
+ const res = txb.moveCall({
34
+ target: `${client.publishedAt()}::haedal::${func}`,
35
+ typeArguments: [],
36
+ arguments: args,
37
+ }) as TransactionObjectArgument
38
+
39
+ return res
40
+ }
41
+ }
@@ -1 +1,17 @@
1
- export * from "./router"
1
+ import {
2
+ Transaction,
3
+ TransactionObjectArgument,
4
+ } from "@mysten/sui/transactions"
5
+ import { AggregatorClient, Path } from ".."
6
+
7
+ export const CLOCK_ADDRESS =
8
+ "0x0000000000000000000000000000000000000000000000000000000000000006"
9
+
10
+ export interface Dex {
11
+ swap(
12
+ client: AggregatorClient,
13
+ ptb: Transaction,
14
+ path: Path,
15
+ inputCoin: TransactionObjectArgument
16
+ ): Promise<TransactionObjectArgument>
17
+ }
@@ -0,0 +1,38 @@
1
+ import {
2
+ Transaction,
3
+ TransactionArgument,
4
+ TransactionObjectArgument,
5
+ TransactionResult,
6
+ } from "@mysten/sui/transactions"
7
+ import { AggregatorClient, Dex, Env, Path } from ".."
8
+
9
+ export class KriyaV2 implements Dex {
10
+ constructor(env: Env) {
11
+ if (env !== Env.Mainnet) {
12
+ throw new Error("Kriya amm only supported on mainnet")
13
+ }
14
+ }
15
+
16
+ async swap(
17
+ client: AggregatorClient,
18
+ txb: Transaction,
19
+ path: Path,
20
+ inputCoin: TransactionObjectArgument
21
+ ): Promise<TransactionObjectArgument> {
22
+ const { direction, from, target } = path
23
+
24
+ const [func, coinAType, coinBType] = direction
25
+ ? ["swap_a2b", from, target]
26
+ : ["swap_b2a", target, from]
27
+
28
+ const args = [txb.object(path.id), inputCoin]
29
+
30
+ const res = txb.moveCall({
31
+ target: `${client.publishedAt()}::kriya_amm::${func}`,
32
+ typeArguments: [coinAType, coinBType],
33
+ arguments: args,
34
+ }) as TransactionObjectArgument
35
+
36
+ return res
37
+ }
38
+ }
@@ -0,0 +1,46 @@
1
+ import {
2
+ Transaction,
3
+ TransactionObjectArgument,
4
+ } from "@mysten/sui/transactions"
5
+ import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."
6
+
7
+ export class KriyaV3 implements Dex {
8
+ private version: string
9
+
10
+ constructor(env: Env) {
11
+ if (env !== Env.Mainnet) {
12
+ throw new Error("Kriya clmm only supported on mainnet")
13
+ }
14
+
15
+ this.version =
16
+ "0xf5145a7ac345ca8736cf8c76047d00d6d378f30e81be6f6eb557184d9de93c78"
17
+ }
18
+
19
+ async swap(
20
+ client: AggregatorClient,
21
+ txb: Transaction,
22
+ path: Path,
23
+ inputCoin: TransactionObjectArgument
24
+ ): Promise<TransactionObjectArgument> {
25
+ const { direction, from, target } = path
26
+
27
+ const [func, coinAType, coinBType] = direction
28
+ ? ["swap_a2b", from, target]
29
+ : ["swap_b2a", target, from]
30
+
31
+ const args = [
32
+ txb.object(path.id),
33
+ inputCoin,
34
+ txb.object(this.version),
35
+ txb.object(CLOCK_ADDRESS),
36
+ ]
37
+
38
+ const res = txb.moveCall({
39
+ target: `${client.publishedAt()}::kriya_clmm::${func}`,
40
+ typeArguments: [coinAType, coinBType],
41
+ arguments: args,
42
+ }) as TransactionObjectArgument
43
+
44
+ return res
45
+ }
46
+ }