@cetusprotocol/aggregator-sdk 0.0.7 → 0.1.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 (57) hide show
  1. package/dist/index.d.mts +98 -102
  2. package/dist/index.d.ts +98 -102
  3. package/dist/index.js +1228 -1556
  4. package/dist/index.mjs +1215 -1543
  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 -9
  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 -13
  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 -31
  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 +127 -81
  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 -174
  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 -341
  57. package/src/utils/account_cap.ts +0 -62
package/src/utils/coin.ts CHANGED
@@ -1,24 +1,27 @@
1
+ import { SuiZeroCoinFn } from "../const"
2
+ import { CoinAsset } from "../types/sui"
3
+ import { CoinUtils } from "../types/CoinAssist"
4
+ import { TransactionErrorCode } from "../errors"
5
+ import {
6
+ Transaction,
7
+ TransactionObjectArgument,
8
+ } from "@mysten/sui/transactions"
9
+
1
10
  export function completionCoin(s: string): string {
2
11
  const index = s.indexOf("::")
3
12
  if (index === -1) {
4
13
  return s
5
14
  }
6
-
7
15
  const prefix = s.substring(0, index)
8
16
  const rest = s.substring(index)
9
-
10
17
  if (!prefix.startsWith("0x")) {
11
18
  return s
12
19
  }
13
-
14
20
  const hexStr = prefix.substring(2)
15
-
16
21
  if (hexStr.length > 64) {
17
22
  return s
18
23
  }
19
-
20
24
  const paddedHexStr = hexStr.padStart(64, "0")
21
-
22
25
  return `0x${paddedHexStr}${rest}`
23
26
  }
24
27
 
@@ -38,3 +41,85 @@ export function compareCoins(coinA: string, coinB: string): boolean {
38
41
  // If both strings are the same length and all characters are equal
39
42
  return true // or coinB, they are equal
40
43
  }
44
+
45
+ export function mintZeroCoin(
46
+ txb: Transaction,
47
+ coinType: string
48
+ ): TransactionObjectArgument {
49
+ return txb.moveCall({
50
+ target: SuiZeroCoinFn,
51
+ typeArguments: [coinType],
52
+ })
53
+ }
54
+
55
+ export type BuildCoinResult = {
56
+ targetCoin: TransactionObjectArgument
57
+ isMintZeroCoin: boolean
58
+ targetCoinAmount: number
59
+ }
60
+
61
+ export function buildInputCoin(
62
+ txb: Transaction,
63
+ allCoins: CoinAsset[],
64
+ amount: bigint,
65
+ coinType: string
66
+ ): BuildCoinResult {
67
+ const usedCoinAsests = CoinUtils.getCoinAssets(coinType, allCoins)
68
+ if (amount === BigInt(0) && usedCoinAsests.length === 0) {
69
+ const zeroCoin = mintZeroCoin(txb, coinType)
70
+ return {
71
+ targetCoin: zeroCoin,
72
+ isMintZeroCoin: true,
73
+ targetCoinAmount: 0,
74
+ }
75
+ }
76
+
77
+ let totalCoinBalance = CoinUtils.calculateTotalBalance(usedCoinAsests)
78
+ if (totalCoinBalance < amount) {
79
+ throw new AggregateError(
80
+ "Insufficient balance when build merge coin",
81
+ TransactionErrorCode.InsufficientBalance
82
+ )
83
+ }
84
+
85
+ if (CoinUtils.isSuiCoin(coinType)) {
86
+ const resultCoin = txb.splitCoins(txb.gas, [
87
+ txb.pure.u64(amount.toString()),
88
+ ])
89
+ return {
90
+ targetCoin: resultCoin,
91
+ isMintZeroCoin: true,
92
+ targetCoinAmount: Number(amount.toString()),
93
+ }
94
+ }
95
+
96
+ // sort used coin by amount, asc
97
+ let sortCoinAssets = CoinUtils.sortByBalance(usedCoinAsests)
98
+
99
+ // find first three coin if greater than amount
100
+ let totalThreeCoinBalance = sortCoinAssets
101
+ .slice(0, 3)
102
+ .reduce((acc, coin) => acc + coin.balance, BigInt(0))
103
+ if (totalThreeCoinBalance < BigInt(amount)) {
104
+ sortCoinAssets = CoinUtils.sortByBalanceDes(usedCoinAsests)
105
+ }
106
+
107
+ let selectedCoinResult = CoinUtils.selectCoinObjectIdGreaterThanOrEqual(
108
+ sortCoinAssets,
109
+ amount
110
+ )
111
+ const [masterCoin, ...mergedCoin] = selectedCoinResult.objectArray
112
+
113
+ if (mergedCoin.length > 0) {
114
+ txb.mergeCoins(
115
+ masterCoin,
116
+ mergedCoin.map((coin) => txb.object(coin))
117
+ )
118
+ }
119
+
120
+ return {
121
+ targetCoin: txb.object(masterCoin),
122
+ isMintZeroCoin: false,
123
+ targetCoinAmount: Number(amount.toString()),
124
+ }
125
+ }
@@ -5,7 +5,7 @@ export async function printTransaction(tx: Transaction, isPrint = true) {
5
5
  let i = 0
6
6
 
7
7
  tx.getData().commands.forEach((item, index) => {
8
- if (isPrint && i < 15) {
8
+ if (isPrint) {
9
9
  console.log(`transaction ${index}: `, JSON.stringify(item, null, 2))
10
10
  i++
11
11
  }
@@ -1,22 +1,14 @@
1
- import { describe, expect, test } from "@jest/globals"
1
+ import { describe, test } from "@jest/globals"
2
2
  import dotenv from "dotenv"
3
3
  import { AggregatorClient } from "~/client"
4
- import { AggregatorConfig, ENV } from "~/config"
5
- import {
6
- M_CETUS,
7
- M_HASUI,
8
- M_NAVI,
9
- M_SUI,
10
- M_USDC,
11
- M_VAPOR,
12
- M_VSUI,
13
- } from "../src/test_data.test"
4
+ import { M_CETUS, M_NAVI, M_SSWP, M_SUI, M_USDC } from "./test_data.test"
14
5
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
15
6
  import { printTransaction } from "~/utils/transaction"
16
7
  import BN from "bn.js"
17
- import { fromHEX } from "@mysten/bcs"
18
8
  import { fromB64 } from "@mysten/sui/utils"
19
- import { getFullnodeUrl } from "@mysten/sui/dist/cjs/client"
9
+ import { SuiClient } from "@mysten/sui/client"
10
+ import { Env } from "~/index"
11
+ import { Transaction } from "@mysten/sui/transactions"
20
12
 
21
13
  dotenv.config()
22
14
 
@@ -27,7 +19,6 @@ export function buildTestAccount(): Ed25519Keypair {
27
19
  }
28
20
 
29
21
  describe("router module", () => {
30
- let config: AggregatorConfig
31
22
  let client: AggregatorClient
32
23
  let keypair: Ed25519Keypair
33
24
 
@@ -36,24 +27,25 @@ describe("router module", () => {
36
27
  const aggregatorURL = process.env.CETUS_AGGREGATOR!
37
28
  const secret = process.env.SUI_WALLET_SECRET!
38
29
 
39
- // const byte = Buffer.from(secret, "hex")
40
- // keypair = secret
41
- // ? Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
42
- // : buildTestAccount()
43
- const byte = Buffer.from(secret, "base64")
44
- const u8Array = new Uint8Array(byte)
30
+ if (secret) {
31
+ keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
32
+ } else {
33
+ keypair = buildTestAccount()
34
+ }
45
35
 
46
- // keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
36
+ const wallet = keypair.getPublicKey().toSuiAddress()
47
37
 
48
- // const wallet = keypair.getPublicKey().toSuiAddress()
49
- // console.log("wallet", wallet)
38
+ // console.log("wallet", wallet, "\n", wallet.toString())
50
39
 
51
- const wallet =
52
- "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
53
- // const wallet = "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
40
+ // const wallet =
41
+ // "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
42
+ // const wallet =
43
+ // "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
44
+ // const wallet =
45
+ // "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
54
46
  // const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
55
47
  // const wallet = "0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
56
- // console.log("wallet: ", wallet)
48
+ console.log("wallet: ", wallet)
57
49
 
58
50
  const aggregatorPackage = {
59
51
  packageName: "aggregator",
@@ -70,20 +62,12 @@ describe("router module", () => {
70
62
  publishedAt:
71
63
  "0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
72
64
  }
73
-
74
- config = new AggregatorConfig(
75
- aggregatorURL,
76
- fullNodeURL,
77
- wallet,
78
- [aggregatorPackage, integratePackage],
79
- ENV.MAINNET
80
- )
81
- client = new AggregatorClient(config)
82
- })
83
-
84
- test("Init aggregator client", () => {
85
- expect(config.getAggregatorUrl().length > 0).toBe(true)
86
- expect(config.getWallet().length > 0).toBe(true)
65
+ const endpoint =
66
+ "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
67
+ const suiClient = new SuiClient({
68
+ url: "https://fullnode.mainnet.sui.io:443",
69
+ })
70
+ client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
87
71
  })
88
72
 
89
73
  test("Get all coins", () => {
@@ -94,12 +78,13 @@ describe("router module", () => {
94
78
 
95
79
  test("Downgrade swap in route", async () => {
96
80
  const amount = 1000000
81
+ const byAmountIn = false
97
82
 
98
- const res = await client.swapInPools({
83
+ const res: any = await client.swapInPools({
99
84
  from: M_USDC,
100
85
  target: M_SUI,
101
86
  amount: new BN(amount),
102
- byAmountIn: true,
87
+ byAmountIn,
103
88
  pools: [
104
89
  "0xcf994611fd4c48e277ce3ffd4d4364c914af2c3cbb05f7bf6facd371de688630",
105
90
  ],
@@ -107,49 +92,72 @@ describe("router module", () => {
107
92
 
108
93
  if (res != null) {
109
94
  console.log(JSON.stringify(res, null, 2))
95
+ const txb = new Transaction()
96
+ await client.fastRouterSwap({
97
+ routers: res.routeData.routes,
98
+ byAmountIn,
99
+ txb,
100
+ slippage: 0.01,
101
+ isMergeTragetCoin: false,
102
+ refreshAllCoins: true,
103
+ })
104
+
105
+ let result = await client.devInspectTransactionBlock(txb)
106
+ console.log("🚀 ~ file: router.test.ts:114 ~ test ~ result:", result)
110
107
  }
111
- })
108
+ }, 10000)
112
109
 
113
110
  test("Find router", async () => {
114
- const amount = "423926761000000000000000000000"
115
-
116
- const res = await client.findRouter({
111
+ const amount = "4239267610000000000"
112
+ const res = await client.findRouters({
117
113
  from: M_SUI,
118
114
  target: M_USDC,
119
115
  amount: new BN(amount),
120
116
  byAmountIn: true,
121
117
  depth: 3,
122
- splitAlgorithm: null,
123
- splitFactor: null,
124
118
  splitCount: 1,
125
- providers: ["CETUS"],
119
+ // providers: ["CETUS"],
126
120
  })
127
121
 
128
122
  if (res != null) {
129
123
  console.log(JSON.stringify(res, null, 2))
130
124
  }
131
-
132
125
  console.log("amount in", res?.amountIn.toString())
133
126
  console.log("amount out", res?.amountOut.toString())
134
127
  })
135
128
 
136
129
  test("Build router tx", async () => {
137
130
  const byAmountIn = true
138
- const amount = "1000000"
131
+ const amount = "1000000000"
139
132
 
140
- const from = M_USDC
141
- const target = M_SUI
133
+ // const from = M_USDC
134
+ // const target = M_SUI
135
+
136
+ const from = M_SUI
137
+ // const target =
138
+ // "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
139
+ // const target =
140
+ // "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
141
+
142
+ const target =
143
+ "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
142
144
 
143
- const res = await client.findRouter({
145
+ const res = await client.findRouters({
144
146
  from,
145
147
  target,
146
148
  amount: new BN(amount),
147
149
  byAmountIn,
148
150
  depth: 3,
149
- splitAlgorithm: null,
150
- splitFactor: null,
151
- splitCount: null,
152
- providers: ["CETUS", "DEEPBOOK", "AFTERMATH", "FLOWX", "KRIYA", "TURBOS"],
151
+ providers: [
152
+ // "CETUS",
153
+ // "DEEPBOOK",
154
+ // "AFTERMATH",
155
+ // "FLOWX",
156
+ // "KRIYA",
157
+ // "KRIYAV3",
158
+ // "TURBOS",
159
+ "VOLO",
160
+ ],
153
161
  })
154
162
 
155
163
  if (res != null) {
@@ -159,28 +167,72 @@ describe("router module", () => {
159
167
  console.log("amount in", res?.amountIn.toString())
160
168
  console.log("amount out", res?.amountOut.toString())
161
169
 
170
+ const txb = new Transaction()
171
+
162
172
  if (res != null) {
163
173
  console.log(JSON.stringify(res, null, 2))
164
- const routerTx = await client.routerSwap({
174
+ await client.fastRouterSwap({
165
175
  routers: res.routes,
166
- amountIn: res.amountIn,
167
- amountOut: res.amountOut,
168
176
  byAmountIn,
177
+ txb,
169
178
  slippage: 0.01,
170
- fromCoinType: from,
171
- targetCoinType: target,
172
- partner: undefined,
173
179
  isMergeTragetCoin: false,
174
180
  refreshAllCoins: true,
175
181
  })
176
182
 
177
- printTransaction(routerTx)
183
+ printTransaction(txb)
184
+
185
+ let result = await client.devInspectTransactionBlock(txb)
186
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
187
+
188
+ // if (result.effects.status.status === "success") {
189
+ // console.log("Sim exec transaction success")
190
+ // const result = await client.signAndExecuteTransaction(txb, keypair)
191
+ // // console.log("result", result)
192
+ // } else {
193
+ // console.log("result", result)
194
+ // }
195
+ }
196
+ }, 600000)
178
197
 
179
- let result = await client.devInspectTransactionBlock(routerTx)
198
+ test("By amount out", async () => {
199
+ const byAmountIn = false
200
+ const amount = "10000000000"
201
+
202
+ const from = M_USDC
203
+ const target = M_SSWP
204
+
205
+ const res = await client.findRouters({
206
+ from,
207
+ target,
208
+ amount: new BN(amount),
209
+ byAmountIn,
210
+ depth: 3,
211
+ providers: ["CETUS"],
212
+ })
213
+
214
+ console.log("amount in", res?.amountIn.toString())
215
+ console.log("amount out", res?.amountOut.toString())
216
+
217
+ const txb = new Transaction()
218
+ if (res != null) {
219
+ console.log(JSON.stringify(res, null, 2))
220
+ await client.fastRouterSwap({
221
+ routers: res.routes,
222
+ byAmountIn,
223
+ txb,
224
+ slippage: 0.02,
225
+ isMergeTragetCoin: false,
226
+ refreshAllCoins: true,
227
+ })
228
+
229
+ printTransaction(txb)
230
+
231
+ let result = await client.devInspectTransactionBlock(txb)
180
232
 
181
233
  if (result.effects.status.status === "success") {
182
234
  console.log("Sim exec transaction success")
183
- // const result = await client.signAndExecuteTransaction(routerTx, keypair)
235
+ // const result = await client.signAndExecuteTransaction(txb, keypair)
184
236
  // console.log("result", result)
185
237
  } else {
186
238
  console.log("result", result)
@@ -204,32 +256,26 @@ describe("router module", () => {
204
256
  amount,
205
257
  byAmountIn,
206
258
  })
207
- const res = await client.findRouter({
259
+
260
+ const res = await client.findRouters({
208
261
  from,
209
262
  target,
210
263
  amount: new BN(amount),
211
264
  byAmountIn,
212
- depth: null,
213
- splitAlgorithm: null,
214
- splitFactor: null,
215
- splitCount: null,
216
- providers: null,
217
265
  })
218
266
 
267
+ const txb = new Transaction()
268
+
219
269
  if (res != null) {
220
- const routerTx = await client.routerSwap({
270
+ await client.fastRouterSwap({
221
271
  routers: res.routes,
222
- amountIn: res.amountIn,
223
- amountOut: res.amountOut,
224
272
  byAmountIn,
225
273
  slippage: 0.01,
226
- fromCoinType: from,
227
- targetCoinType: target,
228
- partner: undefined,
274
+ txb,
229
275
  isMergeTragetCoin: false,
230
276
  })
231
277
 
232
- let result = await client.devInspectTransactionBlock(routerTx)
278
+ let result = await client.devInspectTransactionBlock(txb)
233
279
  // console.log('result', result)
234
280
 
235
281
  if (result.effects.status.status === "success") {
@@ -15,3 +15,5 @@ export const M_VAPOR =
15
15
  "0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094024b32ab7b76d14d30::vapor::VAPOR"
16
16
  export const M_HASUI =
17
17
  "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
18
+ export const M_SSWP =
19
+ "0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN"
@@ -1,26 +0,0 @@
1
- export type Package = {
2
- packageName: string;
3
- packageId: string;
4
- publishedAt: string;
5
- };
6
- export declare enum ENV {
7
- MAINNET = 0,
8
- TESTNET = 1
9
- }
10
- export declare class AggregatorConfig {
11
- private aggregatorUrl;
12
- private fullNodeUrl;
13
- private wallet;
14
- private packages;
15
- private env;
16
- constructor(aggregatorUrl: string, fullNodeUrl: string, wallet: string, packages: Package[], env: ENV);
17
- getAggregatorUrl(): string;
18
- getFullNodeUrl(): string;
19
- getWallet(): string;
20
- getENV(): ENV;
21
- getPackages(): Package[];
22
- getPackage(packageName: string): Package | undefined;
23
- addPackage(newPackage: Package): void;
24
- removePackageById(packageId: string): void;
25
- findPackageById(packageId: string): Package | undefined;
26
- }
@@ -1,12 +0,0 @@
1
- import { CoinAsset } from "../types/sui";
2
- import { AggregatorConfig } from "../config";
3
- import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
4
- export declare function mintZeroCoin(txb: Transaction, coinType: string): TransactionObjectArgument;
5
- export type BuildCoinResult = {
6
- targetCoin: TransactionObjectArgument;
7
- isMintZeroCoin: boolean;
8
- targetCoinAmount: number;
9
- };
10
- export declare function buildInputCoin(txb: Transaction, allCoins: CoinAsset[], amount: bigint, coinType: string): BuildCoinResult;
11
- export declare function transferOrDestoryCoin(txb: Transaction, coinObject: TransactionObjectArgument, coinType: string, config: AggregatorConfig): void;
12
- export declare function checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: number, config: AggregatorConfig): TransactionArgument;
@@ -1,21 +0,0 @@
1
- import { TransactionArgument, Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
- import { AggregatorConfig } from "../config";
3
- import { SuiClient } from "@mysten/sui/client";
4
- export type DeepbookSwapParams = {
5
- poolId: string;
6
- a2b: boolean;
7
- amount: TransactionArgument;
8
- amountLimit: number;
9
- coinA?: TransactionObjectArgument;
10
- coinB?: TransactionObjectArgument;
11
- useFullInputCoinAmount: boolean;
12
- coinAType: string;
13
- coinBType: string;
14
- };
15
- export type DeepbookSwapResult = {
16
- targetCoin: TransactionObjectArgument;
17
- amountIn: TransactionArgument;
18
- amountOut: TransactionArgument;
19
- txb: Transaction;
20
- };
21
- export declare function deepbookSwapMovecall(swapParams: DeepbookSwapParams, client: SuiClient, txb: Transaction, config: AggregatorConfig): Promise<DeepbookSwapResult>;
@@ -1,20 +0,0 @@
1
- import { TransactionArgument, Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
- import { AggregatorConfig } from "../config";
3
- export type FlowxSwapParams = {
4
- amount: TransactionArgument;
5
- amountLimit: number;
6
- a2b: boolean;
7
- byAmountIn: boolean;
8
- coinA?: TransactionObjectArgument;
9
- coinB?: TransactionObjectArgument;
10
- useFullInputCoinAmount: boolean;
11
- coinAType: string;
12
- coinBType: string;
13
- };
14
- export type FlowxSwapResult = {
15
- targetCoin: TransactionObjectArgument;
16
- amountIn: TransactionArgument;
17
- amountOut: TransactionArgument;
18
- txb: Transaction;
19
- };
20
- export declare function flowxAmmSwapMovecall(swapParams: FlowxSwapParams, txb: Transaction, config: AggregatorConfig): Promise<FlowxSwapResult>;
@@ -1,21 +0,0 @@
1
- import { TransactionArgument, Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
- import { AggregatorConfig } from "../config";
3
- export type KriyaSwapParams = {
4
- poolId: string;
5
- amount: TransactionArgument;
6
- amountLimit: number;
7
- a2b: boolean;
8
- byAmountIn: boolean;
9
- coinA?: TransactionObjectArgument;
10
- coinB?: TransactionObjectArgument;
11
- useFullInputCoinAmount: boolean;
12
- coinAType: string;
13
- coinBType: string;
14
- };
15
- export type KriyaSwapResult = {
16
- targetCoin: TransactionObjectArgument;
17
- amountIn: TransactionArgument;
18
- amountOut: TransactionArgument;
19
- txb: Transaction;
20
- };
21
- export declare function kriyaSwapMovecall(swapParams: KriyaSwapParams, txb: Transaction, config: AggregatorConfig): Promise<KriyaSwapResult>;
@@ -1,6 +0,0 @@
1
- import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
2
- import type { BuildRouterSwapParams } from "../client";
3
- import { AggregatorConfig } from "../config";
4
- import { SuiClient } from "@mysten/sui/client";
5
- export declare function expectInputRouterSwap(client: SuiClient, params: BuildRouterSwapParams, txb: Transaction, fromCoin: TransactionObjectArgument, config: AggregatorConfig, partner?: string): Promise<TransactionObjectArgument[]>;
6
- export declare function expectOutputRouterSwap(params: BuildRouterSwapParams, txb: Transaction, fromCoin: TransactionObjectArgument, config: AggregatorConfig, partner?: string): Promise<TransactionObjectArgument[]>;
@@ -1,7 +0,0 @@
1
- import { SuiClient } from "@mysten/sui/client";
2
- import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
3
- export type GetOrCreateAccountCapResult = {
4
- accountCap: TransactionObjectArgument;
5
- isCreate: boolean;
6
- };
7
- export declare function getOrCreateAccountCap(txb: Transaction, client: SuiClient, owner: string): Promise<GetOrCreateAccountCapResult>;
package/src/config.ts DELETED
@@ -1,65 +0,0 @@
1
- export type Package = {
2
- packageName: string
3
- packageId: string
4
- publishedAt: string
5
- }
6
-
7
- export enum ENV {
8
- MAINNET,
9
- TESTNET,
10
- }
11
-
12
- export class AggregatorConfig {
13
- private aggregatorUrl: string;
14
- private fullNodeUrl: string;
15
- private wallet: string;
16
- private packages: Package[];
17
- private env: ENV;
18
-
19
- constructor(aggregatorUrl: string, fullNodeUrl: string, wallet: string, packages: Package[], env: ENV) {
20
- this.aggregatorUrl = aggregatorUrl;
21
- this.fullNodeUrl = fullNodeUrl;
22
- this.wallet = wallet;
23
- this.packages = packages;
24
- this.env = env;
25
- }
26
-
27
- getAggregatorUrl(): string {
28
- return this.aggregatorUrl;
29
- }
30
-
31
- getFullNodeUrl(): string {
32
- return this.fullNodeUrl;
33
- }
34
-
35
- getWallet(): string {
36
- return this.wallet;
37
- }
38
-
39
- getENV(): ENV {
40
- return this.env
41
- }
42
-
43
- getPackages(): Package[] {
44
- return this.packages;
45
- }
46
-
47
- getPackage(packageName: string) {
48
- return this.packages.find(pkg => pkg.packageName === packageName);
49
- }
50
-
51
- addPackage(newPackage: Package): void {
52
- if (!newPackage.packageName || !newPackage.packageId || !newPackage.publishedAt) {
53
- throw new Error("Invalid package data");
54
- }
55
- this.packages.push(newPackage);
56
- }
57
-
58
- removePackageById(packageId: string): void {
59
- this.packages = this.packages.filter(pkg => pkg.packageId !== packageId);
60
- }
61
-
62
- findPackageById(packageId: string): Package | undefined {
63
- return this.packages.find(pkg => pkg.packageId === packageId);
64
- }
65
- }