@cetusprotocol/aggregator-sdk 0.0.8 → 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 -1552
  4. package/dist/index.mjs +1215 -1539
  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 -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
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,14 +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 { M_CETUS, M_HASUI, M_NAVI, M_SUI, M_USDC } from "../src/test_data.test"
4
+ import { M_CETUS, M_NAVI, M_SSWP, M_SUI, M_USDC } from "./test_data.test"
6
5
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
7
6
  import { printTransaction } from "~/utils/transaction"
8
7
  import BN from "bn.js"
9
- import { fromHEX } from "@mysten/bcs"
10
8
  import { fromB64 } from "@mysten/sui/utils"
11
- 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"
12
12
 
13
13
  dotenv.config()
14
14
 
@@ -19,7 +19,6 @@ export function buildTestAccount(): Ed25519Keypair {
19
19
  }
20
20
 
21
21
  describe("router module", () => {
22
- let config: AggregatorConfig
23
22
  let client: AggregatorClient
24
23
  let keypair: Ed25519Keypair
25
24
 
@@ -28,28 +27,25 @@ describe("router module", () => {
28
27
  const aggregatorURL = process.env.CETUS_AGGREGATOR!
29
28
  const secret = process.env.SUI_WALLET_SECRET!
30
29
 
31
- // const byte = Buffer.from(secret, "hex")
32
- // keypair = secret
33
- // ? Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
34
- // : buildTestAccount()
35
- const byte = Buffer.from(secret, "base64")
36
- const u8Array = new Uint8Array(byte)
37
- const secretKey = fromB64(secret)
38
- console.log("secret key", secretKey.toString())
39
-
40
- keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
30
+ if (secret) {
31
+ keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
32
+ } else {
33
+ keypair = buildTestAccount()
34
+ }
41
35
 
42
- // const wallet = keypair.getPublicKey().toSuiAddress()
36
+ const wallet = keypair.getPublicKey().toSuiAddress()
43
37
 
44
38
  // console.log("wallet", wallet, "\n", wallet.toString())
45
39
 
46
40
  // const wallet =
47
41
  // "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
48
- const wallet =
49
- "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
42
+ // const wallet =
43
+ // "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
44
+ // const wallet =
45
+ // "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
50
46
  // const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
51
47
  // const wallet = "0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
52
- // console.log("wallet: ", wallet)
48
+ console.log("wallet: ", wallet)
53
49
 
54
50
  const aggregatorPackage = {
55
51
  packageName: "aggregator",
@@ -66,20 +62,12 @@ describe("router module", () => {
66
62
  publishedAt:
67
63
  "0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
68
64
  }
69
-
70
- config = new AggregatorConfig(
71
- aggregatorURL,
72
- fullNodeURL,
73
- wallet,
74
- [aggregatorPackage, integratePackage],
75
- ENV.MAINNET
76
- )
77
- client = new AggregatorClient(config)
78
- })
79
-
80
- test("Init aggregator client", () => {
81
- expect(config.getAggregatorUrl().length > 0).toBe(true)
82
- 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)
83
71
  })
84
72
 
85
73
  test("Get all coins", () => {
@@ -90,12 +78,13 @@ describe("router module", () => {
90
78
 
91
79
  test("Downgrade swap in route", async () => {
92
80
  const amount = 1000000
81
+ const byAmountIn = false
93
82
 
94
- const res = await client.swapInPools({
83
+ const res: any = await client.swapInPools({
95
84
  from: M_USDC,
96
85
  target: M_SUI,
97
86
  amount: new BN(amount),
98
- byAmountIn: true,
87
+ byAmountIn,
99
88
  pools: [
100
89
  "0xcf994611fd4c48e277ce3ffd4d4364c914af2c3cbb05f7bf6facd371de688630",
101
90
  ],
@@ -103,49 +92,72 @@ describe("router module", () => {
103
92
 
104
93
  if (res != null) {
105
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)
106
107
  }
107
- })
108
+ }, 10000)
108
109
 
109
110
  test("Find router", async () => {
110
- const amount = "423926761000000000000000000000"
111
-
112
- const res = await client.findRouter({
111
+ const amount = "4239267610000000000"
112
+ const res = await client.findRouters({
113
113
  from: M_SUI,
114
114
  target: M_USDC,
115
115
  amount: new BN(amount),
116
116
  byAmountIn: true,
117
117
  depth: 3,
118
- splitAlgorithm: null,
119
- splitFactor: null,
120
118
  splitCount: 1,
121
- providers: ["CETUS"],
119
+ // providers: ["CETUS"],
122
120
  })
123
121
 
124
122
  if (res != null) {
125
123
  console.log(JSON.stringify(res, null, 2))
126
124
  }
127
-
128
125
  console.log("amount in", res?.amountIn.toString())
129
126
  console.log("amount out", res?.amountOut.toString())
130
127
  })
131
128
 
132
129
  test("Build router tx", async () => {
133
130
  const byAmountIn = true
134
- const amount = "3000000000000"
131
+ const amount = "1000000000"
132
+
133
+ // const from = M_USDC
134
+ // const target = M_SUI
135
135
 
136
136
  const from = M_SUI
137
- const target = M_USDC
137
+ // const target =
138
+ // "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
139
+ // const target =
140
+ // "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
141
+
142
+ const target =
143
+ "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
138
144
 
139
- const res = await client.findRouter({
145
+ const res = await client.findRouters({
140
146
  from,
141
147
  target,
142
148
  amount: new BN(amount),
143
149
  byAmountIn,
144
150
  depth: 3,
145
- splitAlgorithm: null,
146
- splitFactor: null,
147
- splitCount: null,
148
- 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
+ ],
149
161
  })
150
162
 
151
163
  if (res != null) {
@@ -155,28 +167,72 @@ describe("router module", () => {
155
167
  console.log("amount in", res?.amountIn.toString())
156
168
  console.log("amount out", res?.amountOut.toString())
157
169
 
170
+ const txb = new Transaction()
171
+
158
172
  if (res != null) {
159
173
  console.log(JSON.stringify(res, null, 2))
160
- const routerTx = await client.routerSwap({
174
+ await client.fastRouterSwap({
161
175
  routers: res.routes,
162
- amountIn: res.amountIn,
163
- amountOut: res.amountOut,
164
176
  byAmountIn,
177
+ txb,
165
178
  slippage: 0.01,
166
- fromCoinType: from,
167
- targetCoinType: target,
168
- partner: undefined,
169
179
  isMergeTragetCoin: false,
170
180
  refreshAllCoins: true,
171
181
  })
172
182
 
173
- 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)
197
+
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)
174
230
 
175
- let result = await client.devInspectTransactionBlock(routerTx)
231
+ let result = await client.devInspectTransactionBlock(txb)
176
232
 
177
233
  if (result.effects.status.status === "success") {
178
234
  console.log("Sim exec transaction success")
179
- // const result = await client.signAndExecuteTransaction(routerTx, keypair)
235
+ // const result = await client.signAndExecuteTransaction(txb, keypair)
180
236
  // console.log("result", result)
181
237
  } else {
182
238
  console.log("result", result)
@@ -200,32 +256,26 @@ describe("router module", () => {
200
256
  amount,
201
257
  byAmountIn,
202
258
  })
203
- const res = await client.findRouter({
259
+
260
+ const res = await client.findRouters({
204
261
  from,
205
262
  target,
206
263
  amount: new BN(amount),
207
264
  byAmountIn,
208
- depth: null,
209
- splitAlgorithm: null,
210
- splitFactor: null,
211
- splitCount: null,
212
- providers: null,
213
265
  })
214
266
 
267
+ const txb = new Transaction()
268
+
215
269
  if (res != null) {
216
- const routerTx = await client.routerSwap({
270
+ await client.fastRouterSwap({
217
271
  routers: res.routes,
218
- amountIn: res.amountIn,
219
- amountOut: res.amountOut,
220
272
  byAmountIn,
221
273
  slippage: 0.01,
222
- fromCoinType: from,
223
- targetCoinType: target,
224
- partner: undefined,
274
+ txb,
225
275
  isMergeTragetCoin: false,
226
276
  })
227
277
 
228
- let result = await client.devInspectTransactionBlock(routerTx)
278
+ let result = await client.devInspectTransactionBlock(txb)
229
279
  // console.log('result', result)
230
280
 
231
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
- }