@cetusprotocol/aggregator-sdk 0.0.1 → 0.0.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.
package/README.md CHANGED
@@ -1,128 +0,0 @@
1
- # Cetus Aggregator Typescript SDK
2
-
3
- Cetus plus swap aggregator is a high-speed and easy-to-integrate solution designed to optimize your trading experience on the Sui blockchain. This aggregator integrates multiple mainstream decentralized exchanges (DEX) on the Sui chain, including various types of trading platforms, providing users with the best trading prices and the lowest slippage.
4
-
5
- Core Advantages:
6
-
7
- High-Speed Transactions: Thanks to advanced algorithms and efficient architecture, our aggregator can execute transactions at lightning speed, ensuring users get the best opportunities in a rapidly changing market.
8
-
9
- Easy Integration: The aggregator is designed to be simple and easy to integrate. Whether you are an individual developer or a large project team, you can quickly connect and deploy.
10
-
11
- Multi-Platform Support: Currently, we have integrated multiple mainstream DEXs on the Sui chain, including cetus, deepbook, kriya, flowx, aftermath, turbos etc, allowing users to enjoy a diversified trading experience on a single platform.
12
-
13
- By using our aggregator, you can trade more efficiently and securely on the Sui blockchain, fully leveraging the various opportunities brought by decentralized finance (DeFi).
14
-
15
- # Install
16
-
17
- The SDK is published to npm registry with experimental version. To use the SDK in your project, you can
18
-
19
- ```
20
- npm install aggregator-sdk@0.0.0-experimental-20240521171554
21
- ```
22
-
23
- # Usage
24
-
25
- ## 1. Init client with rpc and package config
26
-
27
- ```typescript
28
- // used to do simulate swap and swap
29
- const fullNodeURL = process.env.SUI_RPC!
30
-
31
- // used to do swap
32
- const secret = process.env.SUI_WALLET_SECRET!
33
-
34
- // provider by cetus
35
- const aggregatorURL = "https://api-sui.cetus.zone/router_v2"
36
-
37
- // process wallet secret
38
- const byte = Buffer.from(secret, "base64")
39
- const u8Array = new Uint8Array(byte)
40
- keypair = secret
41
- ? Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
42
- : buildTestAccount()
43
- const wallet = keypair.getPublicKey().toSuiAddress()
44
-
45
- const aggregatorPackage = {
46
- packageName: "aggregator",
47
- packageId:
48
- "0x640d44dbdc0ede165c7cc417d7f57f1b09648083109de7132c6b3fb15861f5ee",
49
- publishedAt:
50
- "0x640d44dbdc0ede165c7cc417d7f57f1b09648083109de7132c6b3fb15861f5ee",
51
- }
52
-
53
- const integratePackage = {
54
- packageName: "integrate",
55
- packageId:
56
- "0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",
57
- publishedAt:
58
- "0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
59
- }
60
-
61
- const config = new AggregatorConfig(
62
- aggregatorURL,
63
- fullNodeURL,
64
- wallet,
65
- [aggregatorPackage, integratePackage],
66
- ENV.MAINNET
67
- )
68
- const client = new AggregatorClient(config)
69
- ```
70
-
71
- ## 2. Get best router swap result from aggregator service
72
-
73
- ```typescript
74
- const amount = new BN(1000000)
75
-
76
- const from = M_SUI // 0x2::sui::SUI
77
- const target = M_CETUS // 0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS
78
-
79
- const routerRes = await client.findRouter({
80
- from,
81
- target,
82
- amount,
83
- byAmountIn: true, // true means fix input amount, false means fix output amount
84
- depth: 3, // max allow 3, means 3 hops
85
- splitAlgorithm: null, // select split algotirhm, recommended default set null
86
- splitFactor: null,
87
- splitCount: 100, // set max expect split count
88
- providers: [
89
- "AFTERMATH",
90
- "CETUS",
91
- "DEEPBOOK",
92
- "KRIYA",
93
- "FLOWX",
94
- "AFTERMATH",
95
- "TRUBOS",
96
- ], // now max support above seven platform.
97
- })
98
-
99
- if (routerRes != null) {
100
- console.log(JSON.stringify(res, null, 2))
101
- }
102
- ```
103
-
104
- ## 3. Confirm and do swap
105
-
106
- ```typescript
107
- if (routerRes != null) {
108
- const routerTx = await client.routerSwap({
109
- routers: res.routes,
110
- amountIn: res.amountIn,
111
- amountOut: res.amountOut,
112
- byAmountIn,
113
- slippage: 0.01,
114
- fromCoinType: from,
115
- targetCoinType: target,
116
- partner: undefined,
117
- isMergeTragetCoin: true,
118
- })
119
-
120
- let result = await client.devInspectTransactionBlock(routerTx, keypair)
121
-
122
- if (result.effects.status.status === "success") {
123
- console.log("Sim exec transaction success")
124
- const result = await client.signAndExecuteTransaction(routerTx, keypair)
125
- }
126
- console.log("result", result)
127
- }
128
- ```
package/dist/index.d.mts CHANGED
@@ -114,6 +114,7 @@ type RouterData = {
114
114
  amountIn: BN;
115
115
  amountOut: BN;
116
116
  routes: Router[];
117
+ insufficientLiquidity: boolean;
117
118
  };
118
119
  type AggregatorResponse = {
119
120
  code: number;
package/dist/index.d.ts CHANGED
@@ -114,6 +114,7 @@ type RouterData = {
114
114
  amountIn: BN;
115
115
  amountOut: BN;
116
116
  routes: Router[];
117
+ insufficientLiquidity: boolean;
117
118
  };
118
119
  type AggregatorResponse = {
119
120
  code: number;
package/dist/index.js CHANGED
@@ -5802,7 +5802,7 @@ function cetusRepayFlashSwapMovecall(repayParams, txb, config2) {
5802
5802
  };
5803
5803
  });
5804
5804
  }
5805
- function cetusSwapWithOutLimit(swapParams, fromCoin, txb, config2, returnPayAmount) {
5805
+ function cetusSwapWithOutLimit(swapParams, fromCoin, txb, config2) {
5806
5806
  return __async(this, null, function* () {
5807
5807
  const flashResult = cetusFlashSwapMovecall(swapParams, txb, config2);
5808
5808
  const repayCoinA = swapParams.a2b ? fromCoin : void 0;
@@ -5818,7 +5818,7 @@ function cetusSwapWithOutLimit(swapParams, fromCoin, txb, config2, returnPayAmou
5818
5818
  partner: swapParams.partner
5819
5819
  };
5820
5820
  let nextInputAmount;
5821
- if (returnPayAmount && swapParams.byAmountIn) {
5821
+ if (swapParams.byAmountIn) {
5822
5822
  nextInputAmount = flashResult.swapedAmount;
5823
5823
  } else {
5824
5824
  nextInputAmount = flashResult.payAmount;
@@ -5864,7 +5864,6 @@ function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
5864
5864
  // src/transaction/flowx.ts
5865
5865
  function flowxAmmSwapMovecall(swapParams, txb, config2) {
5866
5866
  return __async(this, null, function* () {
5867
- console.log("flowx amm swap param", swapParams);
5868
5867
  const aggregatorPackage = config2.getPackage(AGGREGATOR);
5869
5868
  if (aggregatorPackage == null) {
5870
5869
  throw new AggregateError(
@@ -5982,7 +5981,6 @@ function turbosSwapMovecall(swapParams, txb, config2) {
5982
5981
  // src/transaction/aftermath.ts
5983
5982
  function AftermathAmmSwapMovecall(swapParams, txb, config2) {
5984
5983
  return __async(this, null, function* () {
5985
- console.log("Aftermath amm swap param", swapParams);
5986
5984
  const aggregatorPackage = config2.getPackage(AGGREGATOR);
5987
5985
  if (aggregatorPackage == null) {
5988
5986
  throw new AggregateError(
@@ -6075,13 +6073,12 @@ function expectInputRouterSwap(client, params, txb, fromCoin, config2, partner)
6075
6073
  coinAType: path.a2b ? path.from : path.target,
6076
6074
  coinBType: path.a2b ? path.target : path.from
6077
6075
  };
6078
- const returnPayAmount = firstPathPool && router.path.length > 1;
6076
+ firstPathPool && router.path.length > 1;
6079
6077
  const swapResult = yield cetusSwapWithOutLimit(
6080
6078
  swapParams,
6081
6079
  nextFromCoin,
6082
6080
  txb,
6083
- config2,
6084
- returnPayAmount
6081
+ config2
6085
6082
  );
6086
6083
  transferOrDestoryCoin(
6087
6084
  txb,
@@ -6091,7 +6088,7 @@ function expectInputRouterSwap(client, params, txb, fromCoin, config2, partner)
6091
6088
  );
6092
6089
  intermediateTargetCoin = swapResult.flashTargetCoin;
6093
6090
  nextFromCoin = intermediateTargetCoin;
6094
- nextFlashAmount = returnPayAmount ? swapResult.nextInputAmount : txb.pure.u64(0);
6091
+ nextFlashAmount = swapResult.nextInputAmount;
6095
6092
  }
6096
6093
  if (path.provider === DEEPBOOK_DEX) {
6097
6094
  const coinA = path.a2b ? nextFromCoin : void 0;
@@ -6462,7 +6459,8 @@ function swapInPools(client, params, config2) {
6462
6459
  amountOut: new import_bn3.BN((_e = event.amount_out) != null ? _e : 0),
6463
6460
  initialPrice
6464
6461
  }
6465
- ]
6462
+ ],
6463
+ insufficientLiquidity: false
6466
6464
  };
6467
6465
  const result = {
6468
6466
  isExceed: event.is_exceed,
@@ -6543,6 +6541,14 @@ var AggregatorClient = class {
6543
6541
  const res = parseRouterResponse(data.data);
6544
6542
  return res;
6545
6543
  }
6544
+ if (data.msg === "liquidity is not enough") {
6545
+ return {
6546
+ amountIn: ZERO,
6547
+ amountOut: ZERO,
6548
+ routes: [],
6549
+ insufficientLiquidity: true
6550
+ };
6551
+ }
6546
6552
  return null;
6547
6553
  });
6548
6554
  }
@@ -6690,6 +6696,7 @@ function parseRouterResponse(data) {
6690
6696
  return {
6691
6697
  amountIn: new import_bn4.default(data.amount_in.toString()),
6692
6698
  amountOut: new import_bn4.default(data.amount_out.toString()),
6699
+ insufficientLiquidity: false,
6693
6700
  routes: data.routes.map((route) => {
6694
6701
  return {
6695
6702
  path: route.path.map((path) => {
package/dist/index.mjs CHANGED
@@ -5800,7 +5800,7 @@ function cetusRepayFlashSwapMovecall(repayParams, txb, config2) {
5800
5800
  };
5801
5801
  });
5802
5802
  }
5803
- function cetusSwapWithOutLimit(swapParams, fromCoin, txb, config2, returnPayAmount) {
5803
+ function cetusSwapWithOutLimit(swapParams, fromCoin, txb, config2) {
5804
5804
  return __async(this, null, function* () {
5805
5805
  const flashResult = cetusFlashSwapMovecall(swapParams, txb, config2);
5806
5806
  const repayCoinA = swapParams.a2b ? fromCoin : void 0;
@@ -5816,7 +5816,7 @@ function cetusSwapWithOutLimit(swapParams, fromCoin, txb, config2, returnPayAmou
5816
5816
  partner: swapParams.partner
5817
5817
  };
5818
5818
  let nextInputAmount;
5819
- if (returnPayAmount && swapParams.byAmountIn) {
5819
+ if (swapParams.byAmountIn) {
5820
5820
  nextInputAmount = flashResult.swapedAmount;
5821
5821
  } else {
5822
5822
  nextInputAmount = flashResult.payAmount;
@@ -5862,7 +5862,6 @@ function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
5862
5862
  // src/transaction/flowx.ts
5863
5863
  function flowxAmmSwapMovecall(swapParams, txb, config2) {
5864
5864
  return __async(this, null, function* () {
5865
- console.log("flowx amm swap param", swapParams);
5866
5865
  const aggregatorPackage = config2.getPackage(AGGREGATOR);
5867
5866
  if (aggregatorPackage == null) {
5868
5867
  throw new AggregateError(
@@ -5980,7 +5979,6 @@ function turbosSwapMovecall(swapParams, txb, config2) {
5980
5979
  // src/transaction/aftermath.ts
5981
5980
  function AftermathAmmSwapMovecall(swapParams, txb, config2) {
5982
5981
  return __async(this, null, function* () {
5983
- console.log("Aftermath amm swap param", swapParams);
5984
5982
  const aggregatorPackage = config2.getPackage(AGGREGATOR);
5985
5983
  if (aggregatorPackage == null) {
5986
5984
  throw new AggregateError(
@@ -6073,13 +6071,12 @@ function expectInputRouterSwap(client, params, txb, fromCoin, config2, partner)
6073
6071
  coinAType: path.a2b ? path.from : path.target,
6074
6072
  coinBType: path.a2b ? path.target : path.from
6075
6073
  };
6076
- const returnPayAmount = firstPathPool && router.path.length > 1;
6074
+ firstPathPool && router.path.length > 1;
6077
6075
  const swapResult = yield cetusSwapWithOutLimit(
6078
6076
  swapParams,
6079
6077
  nextFromCoin,
6080
6078
  txb,
6081
- config2,
6082
- returnPayAmount
6079
+ config2
6083
6080
  );
6084
6081
  transferOrDestoryCoin(
6085
6082
  txb,
@@ -6089,7 +6086,7 @@ function expectInputRouterSwap(client, params, txb, fromCoin, config2, partner)
6089
6086
  );
6090
6087
  intermediateTargetCoin = swapResult.flashTargetCoin;
6091
6088
  nextFromCoin = intermediateTargetCoin;
6092
- nextFlashAmount = returnPayAmount ? swapResult.nextInputAmount : txb.pure.u64(0);
6089
+ nextFlashAmount = swapResult.nextInputAmount;
6093
6090
  }
6094
6091
  if (path.provider === DEEPBOOK_DEX) {
6095
6092
  const coinA = path.a2b ? nextFromCoin : void 0;
@@ -6460,7 +6457,8 @@ function swapInPools(client, params, config2) {
6460
6457
  amountOut: new import_bn3.BN((_e = event.amount_out) != null ? _e : 0),
6461
6458
  initialPrice
6462
6459
  }
6463
- ]
6460
+ ],
6461
+ insufficientLiquidity: false
6464
6462
  };
6465
6463
  const result = {
6466
6464
  isExceed: event.is_exceed,
@@ -6541,6 +6539,14 @@ var AggregatorClient = class {
6541
6539
  const res = parseRouterResponse(data.data);
6542
6540
  return res;
6543
6541
  }
6542
+ if (data.msg === "liquidity is not enough") {
6543
+ return {
6544
+ amountIn: ZERO,
6545
+ amountOut: ZERO,
6546
+ routes: [],
6547
+ insufficientLiquidity: true
6548
+ };
6549
+ }
6544
6550
  return null;
6545
6551
  });
6546
6552
  }
@@ -6688,6 +6694,7 @@ function parseRouterResponse(data) {
6688
6694
  return {
6689
6695
  amountIn: new import_bn4.default(data.amount_in.toString()),
6690
6696
  amountOut: new import_bn4.default(data.amount_out.toString()),
6697
+ insufficientLiquidity: false,
6691
6698
  routes: data.routes.map((route) => {
6692
6699
  return {
6693
6700
  path: route.path.map((path) => {
@@ -31,6 +31,7 @@ export type RouterData = {
31
31
  amountIn: BN;
32
32
  amountOut: BN;
33
33
  routes: Router[];
34
+ insufficientLiquidity: boolean;
34
35
  };
35
36
  export type AggregatorResponse = {
36
37
  code: number;
@@ -32,8 +32,8 @@ export type repayParams = {
32
32
  };
33
33
  export type SwapResult = {
34
34
  repayTargetCoin: TransactionObjectArgument;
35
- flashTargetCoin?: TransactionObjectArgument;
36
35
  nextInputAmount?: TransactionArgument;
36
+ flashTargetCoin?: TransactionObjectArgument;
37
37
  };
38
38
  export declare function cetusRepayFlashSwapMovecall(repayParams: repayParams, txb: Transaction, config: AggregatorConfig): Promise<SwapResult>;
39
- export declare function cetusSwapWithOutLimit(swapParams: CetusSwapParams, fromCoin: TransactionObjectArgument, txb: Transaction, config: AggregatorConfig, returnPayAmount: boolean): Promise<SwapResult>;
39
+ export declare function cetusSwapWithOutLimit(swapParams: CetusSwapParams, fromCoin: TransactionObjectArgument, txb: Transaction, config: AggregatorConfig): Promise<SwapResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/client.ts CHANGED
@@ -16,7 +16,7 @@ import BN from "bn.js"
16
16
  import { swapInPools } from "./transaction/swap"
17
17
  import { completionCoin } from "./utils/coin"
18
18
  import { SUI_FRAMEWORK_ADDRESS } from "@mysten/sui/utils"
19
- import { AFTERMATH_AMM, JOIN_FUNC, PAY_MODULE, TURBOS_DEX } from "./const"
19
+ import { AFTERMATH_AMM, JOIN_FUNC, PAY_MODULE, TURBOS_DEX, ZERO } from "./const"
20
20
 
21
21
  export type ExtendedDetails = {
22
22
  aftermathPoolFlatness?: number
@@ -48,6 +48,7 @@ export type RouterData = {
48
48
  amountIn: BN
49
49
  amountOut: BN
50
50
  routes: Router[]
51
+ insufficientLiquidity: boolean
51
52
  }
52
53
 
53
54
  export type AggregatorResponse = {
@@ -190,6 +191,14 @@ export class AggregatorClient {
190
191
  return res
191
192
  }
192
193
 
194
+ if (data.msg === "liquidity is not enough") {
195
+ return {
196
+ amountIn: ZERO,
197
+ amountOut: ZERO,
198
+ routes: [],
199
+ insufficientLiquidity: true,
200
+ }
201
+ }
193
202
  return null
194
203
  }
195
204
 
@@ -343,6 +352,7 @@ function parseRouterResponse(data: any): RouterData {
343
352
  return {
344
353
  amountIn: new BN(data.amount_in.toString()),
345
354
  amountOut: new BN(data.amount_out.toString()),
355
+ insufficientLiquidity: false,
346
356
  routes: data.routes.map((route: any) => {
347
357
  return {
348
358
  path: route.path.map((path: any) => {
@@ -51,7 +51,6 @@ export async function AftermathAmmSwapMovecall(
51
51
  txb: Transaction,
52
52
  config: AggregatorConfig
53
53
  ): Promise<AftermathSwapResult> {
54
- console.log("Aftermath amm swap param", swapParams)
55
54
  const aggregatorPackage = config.getPackage(AGGREGATOR)
56
55
  if (aggregatorPackage == null) {
57
56
  throw new AggregateError(
@@ -130,8 +130,8 @@ export type repayParams = {
130
130
 
131
131
  export type SwapResult = {
132
132
  repayTargetCoin: TransactionObjectArgument
133
- flashTargetCoin?: TransactionObjectArgument
134
133
  nextInputAmount?: TransactionArgument
134
+ flashTargetCoin?: TransactionObjectArgument
135
135
  }
136
136
 
137
137
  export async function cetusRepayFlashSwapMovecall(
@@ -241,8 +241,7 @@ export async function cetusSwapWithOutLimit(
241
241
  swapParams: CetusSwapParams,
242
242
  fromCoin: TransactionObjectArgument,
243
243
  txb: Transaction,
244
- config: AggregatorConfig,
245
- returnPayAmount: boolean
244
+ config: AggregatorConfig
246
245
  ): Promise<SwapResult> {
247
246
  const flashResult = cetusFlashSwapMovecall(swapParams, txb, config)
248
247
 
@@ -262,7 +261,7 @@ export async function cetusSwapWithOutLimit(
262
261
 
263
262
  let nextInputAmount: TransactionArgument
264
263
 
265
- if (returnPayAmount && swapParams.byAmountIn) {
264
+ if (swapParams.byAmountIn) {
266
265
  nextInputAmount = flashResult.swapedAmount
267
266
  } else {
268
267
  nextInputAmount = flashResult.payAmount
@@ -39,7 +39,6 @@ export async function flowxAmmSwapMovecall(
39
39
  txb: Transaction,
40
40
  config: AggregatorConfig
41
41
  ): Promise<FlowxSwapResult> {
42
- console.log("flowx amm swap param", swapParams)
43
42
  const aggregatorPackage = config.getPackage(AGGREGATOR)
44
43
  if (aggregatorPackage == null) {
45
44
  throw new AggregateError(
@@ -26,7 +26,6 @@ import { transferOrDestoryCoin } from "./common"
26
26
  import { GetDefaultSqrtPriceLimit } from "../math"
27
27
  import { flowxAmmSwapMovecall } from "./flowx"
28
28
  import { turbosSwapMovecall } from "./turbos"
29
- import { parseAftermathFeeType, parseTurbosPoolFeeType } from "~/utils/coin"
30
29
  import { AftermathAmmSwapMovecall } from "./aftermath"
31
30
  import { TransactionErrorCode } from "~/errors"
32
31
 
@@ -73,8 +72,7 @@ export async function expectInputRouterSwap(
73
72
  swapParams,
74
73
  nextFromCoin,
75
74
  txb,
76
- config,
77
- returnPayAmount
75
+ config
78
76
  )
79
77
 
80
78
  transferOrDestoryCoin(
@@ -86,9 +84,7 @@ export async function expectInputRouterSwap(
86
84
 
87
85
  intermediateTargetCoin = swapResult.flashTargetCoin!
88
86
  nextFromCoin = intermediateTargetCoin
89
- nextFlashAmount = returnPayAmount
90
- ? swapResult.nextInputAmount!
91
- : txb.pure.u64(0)
87
+ nextFlashAmount = swapResult.nextInputAmount!
92
88
  }
93
89
 
94
90
  if (path.provider === DEEPBOOK_DEX) {
@@ -152,6 +152,7 @@ export async function swapInPools(
152
152
  initialPrice,
153
153
  },
154
154
  ],
155
+ insufficientLiquidity: false,
155
156
  }
156
157
 
157
158
  const result = {
@@ -2,18 +2,18 @@ import { Transaction } from "@mysten/sui/transactions"
2
2
 
3
3
  export async function printTransaction(tx: Transaction, isPrint = true) {
4
4
  console.log(`inputs`, tx.getData().inputs)
5
- let i = 0
5
+ let i = 0
6
6
 
7
7
  tx.getData().commands.forEach((item, index) => {
8
- if (isPrint && i < 40) {
8
+ if (isPrint && i < 15) {
9
9
  console.log(`transaction ${index}: `, JSON.stringify(item, null, 2))
10
- i ++
10
+ i++
11
11
  }
12
12
  })
13
13
  }
14
14
 
15
15
  export function checkInvalidSuiAddress(address: string): boolean {
16
- if (!address.startsWith('0x') || address.length !== 66) {
16
+ if (!address.startsWith("0x") || address.length !== 66) {
17
17
  return false
18
18
  }
19
19
  return true
@@ -14,6 +14,7 @@ import {
14
14
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
15
15
  import { printTransaction } from "~/utils/transaction"
16
16
  import BN from "bn.js"
17
+ import { fromHEX } from "@mysten/bcs"
17
18
 
18
19
  dotenv.config()
19
20
 
@@ -33,13 +34,19 @@ describe("router module", () => {
33
34
  const aggregatorURL = process.env.CETUS_AGGREGATOR!
34
35
  const secret = process.env.SUI_WALLET_SECRET!
35
36
 
37
+ // const byte = Buffer.from(secret, "hex")
36
38
  const byte = Buffer.from(secret, "base64")
37
39
  const u8Array = new Uint8Array(byte)
38
- keypair = secret
39
- ? Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
40
- : buildTestAccount()
40
+ // keypair = secret
41
+ // ? Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
42
+ // : buildTestAccount()
43
+
44
+ keypair = Ed25519Keypair.fromSecretKey(fromHEX(secret))
41
45
 
42
46
  const wallet = keypair.getPublicKey().toSuiAddress()
47
+ console.log("wallet", wallet)
48
+ // const wallet =
49
+ // "0x1d30e55c730f92a02a33dbdf6b052cd178e5d924aa58c5e2350a24852250ae58"
43
50
  // const wallet = "0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
44
51
  // const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
45
52
  // const wallet = "0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
@@ -113,13 +120,13 @@ describe("router module", () => {
113
120
  splitFactor: null,
114
121
  splitCount: 1,
115
122
  providers: [
116
- "AFTERMATH",
117
- "CETUS",
123
+ // "AFTERMATH",
124
+ // "CETUS",
118
125
  "DEEPBOOK",
119
- "KRIYA",
120
- "FLOWX",
121
- "AFTERMATH",
122
- "TRUBOS",
126
+ // "KRIYA",
127
+ // "FLOWX",
128
+ // "AFTERMATH",
129
+ // "TRUBOS",
123
130
  ],
124
131
  })
125
132
 
@@ -133,21 +140,21 @@ describe("router module", () => {
133
140
 
134
141
  test("Build router tx", async () => {
135
142
  const byAmountIn = true
136
- const amount = 10000000
143
+ const amount = 500000000
137
144
 
138
145
  const from = M_SUI
139
- const target = M_USDC
146
+ const target = M_NAVI
140
147
 
141
148
  const res = await client.findRouter({
142
149
  from,
143
150
  target,
144
151
  amount: new BN(amount),
145
152
  byAmountIn,
146
- depth: 2,
153
+ depth: 3,
147
154
  splitAlgorithm: null,
148
155
  splitFactor: null,
149
156
  splitCount: null,
150
- providers: ["AFTERMATH"],
157
+ providers: ["CETUS", "DEEPBOOK", "KRIYA", "FLOWX", "AFTERMATH", "TURBOS"],
151
158
  })
152
159
 
153
160
  if (res != null) {
@@ -174,12 +181,11 @@ describe("router module", () => {
174
181
  printTransaction(routerTx)
175
182
 
176
183
  let result = await client.devInspectTransactionBlock(routerTx, keypair)
177
- console.log("result", result)
178
184
 
179
185
  if (result.effects.status.status === "success") {
180
186
  console.log("Sim exec transaction success")
181
- const result = await client.signAndExecuteTransaction(routerTx, keypair)
182
- console.log("result", result)
187
+ // const result = await client.signAndExecuteTransaction(routerTx, keypair)
188
+ // console.log("result", result)
183
189
  } else {
184
190
  console.log("result", result)
185
191
  }
@@ -224,7 +230,7 @@ describe("router module", () => {
224
230
  fromCoinType: from,
225
231
  targetCoinType: target,
226
232
  partner: undefined,
227
- isMergeTragetCoin: true,
233
+ isMergeTragetCoin: false,
228
234
  })
229
235
 
230
236
  let result = await client.devInspectTransactionBlock(
@@ -1,17 +1,21 @@
1
- import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
1
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
2
2
 
3
- describe('router module', () => {
3
+ describe("router module", () => {
4
4
  const keystoreSecret = [
5
- ""
5
+ "0xd36441c734b1967dd4e65956d0b3e7e5dccc8c92306ad71419e6741b4a7ce6c9",
6
6
  ]
7
7
 
8
- test('Parse public key', () => {
8
+ test("Parse public key", () => {
9
9
  for (const secret of keystoreSecret) {
10
- const byte = Buffer.from(secret, 'base64')
11
- const u8Array = new Uint8Array(byte)
12
- const keypair = Ed25519Keypair.fromSecretKey(u8Array.slice(1,33))
13
- console.log("\nsecret:", secret,"\nkeypair public key: ", keypair.toSuiAddress())
10
+ const byte = Buffer.from(secret, "base64")
11
+ const u8Array = new Uint8Array(byte)
12
+ const keypair = Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
13
+ console.log(
14
+ "\nsecret:",
15
+ secret,
16
+ "\nkeypair public key: ",
17
+ keypair.toSuiAddress()
18
+ )
14
19
  }
15
20
  })
16
- });
17
-
21
+ })