@cetusprotocol/aggregator-sdk 0.3.28 → 0.3.30

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/src/api.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  } from "./errors"
9
9
  import { parseRouterResponse } from "./client"
10
10
 
11
- const SDK_VERSION = 1000328
11
+ const SDK_VERSION = 1000330
12
12
 
13
13
  export interface FindRouterParams {
14
14
  from: string
@@ -53,6 +53,13 @@ export type ExtendedDetails = {
53
53
  steammBCoinAType?: string
54
54
  steammBCoinBType?: string
55
55
  steammLPToken?: string
56
+ metastablePriceSeed?: string
57
+ metastableETHPriceSeed?: string
58
+ metastableWhitelistedAppId?: string
59
+ metastableCreateCapPkgId?: string
60
+ metastableCreateCapModule?: string
61
+ metastableCreateCapAllTypeParams?: boolean
62
+ metastableRegistryId?: string
56
63
  }
57
64
 
58
65
  export type Path = {
@@ -146,7 +153,6 @@ export async function getRouterResult(
146
153
  }
147
154
  }
148
155
  if (data.data != null) {
149
- console.log("data.data", JSON.stringify(data.data, null, 2))
150
156
  const res = parseRouterResponse(data.data, params.byAmountIn)
151
157
  return res
152
158
  }
package/src/client.ts CHANGED
@@ -48,6 +48,7 @@ import {
48
48
  SuiPythClient,
49
49
  } from "@pythnetwork/pyth-sui-js"
50
50
  import { Steamm } from "./transaction/steamm"
51
+ import { Metastable } from "./transaction/metastable"
51
52
 
52
53
  export const CETUS = "CETUS"
53
54
  export const DEEPBOOKV2 = "DEEPBOOK"
@@ -69,6 +70,7 @@ export const HAEDALPMM = "HAEDALPMM"
69
70
  export const ALPHAFI = "ALPHAFI"
70
71
  export const SPRINGSUI = "SPRINGSUI"
71
72
  export const STEAMM = "STEAMM"
73
+ export const METASTABLE = "METASTABLE"
72
74
  export const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2"
73
75
 
74
76
  export type BuildRouterSwapParams = {
@@ -167,7 +169,7 @@ export class AggregatorClient {
167
169
  [Env.Mainnet]: {
168
170
  connections: [
169
171
  new SuiPriceServiceConnection(
170
- "https://cetus.liquify.com/api=X9LTVPQD7Y3R5N2A/hermes",
172
+ "https://cetus-pythnet-a648.mainnet.pythnet.rpcpool.com/219cf7a8-6d75-432d-a648-d487a6dd5dc3/hermes",
171
173
  {
172
174
  timeout: 3000,
173
175
  }
@@ -224,23 +226,28 @@ export class AggregatorClient {
224
226
 
225
227
  const allCoins: CoinAsset[] = []
226
228
  while (true) {
227
- const gotCoins = await this.client.getCoins({
228
- owner: this.signer,
229
- coinType,
230
- cursor,
231
- limit,
232
- })
233
- for (const coin of gotCoins.data) {
234
- allCoins.push({
235
- coinAddress: extractStructTagFromType(coin.coinType).source_address,
236
- coinObjectId: coin.coinObjectId,
237
- balance: BigInt(coin.balance),
229
+ try {
230
+ const gotCoins = await this.client.getCoins({
231
+ owner: this.signer,
232
+ coinType,
233
+ cursor,
234
+ limit,
238
235
  })
239
- }
240
- if (gotCoins.data.length < limit) {
236
+ for (const coin of gotCoins.data) {
237
+ allCoins.push({
238
+ coinAddress: extractStructTagFromType(coin.coinType).source_address,
239
+ coinObjectId: coin.coinObjectId,
240
+ balance: BigInt(coin.balance),
241
+ })
242
+ }
243
+ if (gotCoins.data.length < limit) {
244
+ break
245
+ }
246
+ cursor = gotCoins.data[limit - 1].coinObjectId
247
+ } catch (e) {
248
+ console.error("getCoins error:", e)
241
249
  break
242
250
  }
243
- cursor = gotCoins.data[limit - 1].coinObjectId
244
251
  }
245
252
 
246
253
  this.allCoins.set(coinType, allCoins)
@@ -583,7 +590,8 @@ export class AggregatorClient {
583
590
  if (this.env === Env.Mainnet) {
584
591
  // return "0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af" // version 6
585
592
  // return "0xf9c6f78322ed667909e05f6b42b2f5a67af6297503c905335e02a15148e9440d" // version 7
586
- return "0x2485feb9d42c7c3bcb8ecde555ad40f1b073d9fb4faf354fa2d30a0b183a23ce" // version 8
593
+ // return "0x2485feb9d42c7c3bcb8ecde555ad40f1b073d9fb4faf354fa2d30a0b183a23ce" // version 8
594
+ return "0x3864c7c59a4889fec05d1aae4bc9dba5a0e0940594b424fbed44cb3f6ac4c032" // version 9
587
595
  // return "0x803db8dfcc86fc1afbc7d2212bd14ec9690978ddebea0d590e01147d6b17aa06" // pre
588
596
  } else {
589
597
  // return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637" // version 2
@@ -701,6 +709,8 @@ export class AggregatorClient {
701
709
  return new Alphafi(this.env)
702
710
  case STEAMM:
703
711
  return new Steamm(this.env)
712
+ case METASTABLE:
713
+ return new Metastable(this.env, pythPriceIDs)
704
714
  default:
705
715
  throw new Error(`Unsupported dex ${provider}`)
706
716
  }
@@ -803,6 +813,14 @@ export function findPythPriceIDs(routes: Router[]): string[] {
803
813
  priceIDs.add(path.extendedDetails.haedalPmmQuotePriceSeed)
804
814
  }
805
815
  }
816
+ if (path.provider === METASTABLE) {
817
+ if (path.extendedDetails && path.extendedDetails.metastablePriceSeed) {
818
+ priceIDs.add(path.extendedDetails.metastablePriceSeed)
819
+ }
820
+ if (path.extendedDetails && path.extendedDetails.metastableETHPriceSeed) {
821
+ priceIDs.add(path.extendedDetails.metastableETHPriceSeed)
822
+ }
823
+ }
806
824
  }
807
825
  }
808
826
  return Array.from(priceIDs)
@@ -851,7 +869,8 @@ export function parseRouterResponse(
851
869
  path.provider === DEEPBOOKV3 ||
852
870
  path.provider === SCALLOP ||
853
871
  path.provider === HAEDALPMM ||
854
- path.provider === STEAMM
872
+ path.provider === STEAMM ||
873
+ path.provider === METASTABLE
855
874
  ) {
856
875
  extendedDetails = {
857
876
  aftermathLpSupplyType:
@@ -871,7 +890,14 @@ export function parseRouterResponse(
871
890
  steammLendingMarketType: path.extended_details?.steamm_lending_market_type,
872
891
  steammBCoinAType: path.extended_details?.steamm_btoken_a_type,
873
892
  steammBCoinBType: path.extended_details?.steamm_btoken_b_type,
874
- steammLPToken: path.extended_details?.steamm_lp_token_type,
893
+ steammLPToken: path.extended_details?.steamm_lp_token_type,
894
+ metastablePriceSeed: path.extended_details?.metastable_price_seed,
895
+ metastableETHPriceSeed: path.extended_details?.metastable_eth_price_seed,
896
+ metastableWhitelistedAppId: path.extended_details?.metastable_whitelisted_app_id,
897
+ metastableCreateCapPkgId: path.extended_details?.metastable_create_cap_pkg_id,
898
+ metastableCreateCapModule: path.extended_details?.metastable_create_cap_module,
899
+ metastableCreateCapAllTypeParams: path.extended_details?.metastable_create_cap_all_type_params,
900
+ metastableRegistryId: path.extended_details?.metastable_registry_id,
875
901
  }
876
902
  }
877
903
 
@@ -0,0 +1,141 @@
1
+ import {
2
+ Transaction,
3
+ TransactionObjectArgument,
4
+ } from "@mysten/sui/transactions"
5
+ import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, getAggregatorV2ExtendPublishedAt, Path } from ".."
6
+
7
+ const SUPER_SUI_TYPE = "0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI"
8
+ const MUSD_TYPE = "0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD"
9
+ const METH_TYPE = "0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH"
10
+
11
+ export class Metastable implements Dex {
12
+ private pythPriceIDs: Map<string, string>
13
+ private versionID: string
14
+
15
+ constructor(env: Env, pythPriceIDs: Map<string, string>) {
16
+ if (env !== Env.Mainnet) {
17
+ throw new Error("Metastable only supported on mainnet")
18
+ }
19
+ this.versionID = "0x4696559327b35ff2ab26904e7426a1646312e9c836d5c6cff6709a5ccc30915c"
20
+ this.pythPriceIDs = pythPriceIDs
21
+ }
22
+
23
+ async swap(
24
+ client: AggregatorClient,
25
+ txb: Transaction,
26
+ path: Path,
27
+ inputCoin: TransactionObjectArgument,
28
+ packages?: Map<string, string>
29
+ ): Promise<TransactionObjectArgument> {
30
+ const { direction, from, target } = path
31
+
32
+ const [func, createCapFunc, coinType, metaCoinType] = direction
33
+ ? ["swap_a2b", "create_deposit_cap", from, target]
34
+ : ["swap_b2a", "create_withdraw_cap", target, from]
35
+
36
+ let createExchangePkgId = "";
37
+ let createDepositModule = "pyth";
38
+ let metaSingletonId = "";
39
+ if (path.extendedDetails == null) {
40
+ throw new Error("Extended details not supported metastable")
41
+ } else {
42
+ if (
43
+ !path.extendedDetails.metastableCreateCapPkgId ||
44
+ !path.extendedDetails.metastableCreateCapModule ||
45
+ !path.extendedDetails.metastableRegistryId ||
46
+ !path.extendedDetails.metastableWhitelistedAppId
47
+ ) {
48
+ throw new Error("CreateCapPkgId or CreateCapModule or RegistryId or WhitelistedAppId or CreateCapAllTypeParams not supported")
49
+ }
50
+ createExchangePkgId = path.extendedDetails.metastableCreateCapPkgId
51
+ createDepositModule = path.extendedDetails.metastableCreateCapModule
52
+ metaSingletonId = path.extendedDetails.metastableWhitelistedAppId
53
+ }
54
+
55
+ const createDepositCapTypeArgs = [
56
+ metaCoinType
57
+ ]
58
+ if (path.extendedDetails.metastableCreateCapAllTypeParams) {
59
+ createDepositCapTypeArgs.push(coinType);
60
+ }
61
+
62
+ const depositArgs = [
63
+ txb.object(metaSingletonId),
64
+ txb.object(path.id),
65
+ ]
66
+
67
+ switch (metaCoinType) {
68
+ case SUPER_SUI_TYPE: {
69
+ if (!path.extendedDetails.metastableRegistryId) {
70
+ throw new Error("Not found registry id for super sui")
71
+ }
72
+ depositArgs.push(txb.object(path.extendedDetails.metastableRegistryId));
73
+ break;
74
+ }
75
+ case MUSD_TYPE: {
76
+ if (path.extendedDetails.metastablePriceSeed != null) {
77
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed)
78
+ if (priceId == null) {
79
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed)
80
+ }
81
+ depositArgs.push(txb.object(priceId));
82
+ }
83
+ if (path.extendedDetails.metastableETHPriceSeed != null) {
84
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed)
85
+ if (priceId == null) {
86
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed)
87
+ }
88
+ depositArgs.push(txb.object(priceId));
89
+ }
90
+ depositArgs.push(txb.object(CLOCK_ADDRESS));
91
+ break;
92
+ }
93
+ case METH_TYPE: {
94
+ if (path.extendedDetails.metastablePriceSeed != null) {
95
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastablePriceSeed)
96
+ if (priceId == null) {
97
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastablePriceSeed)
98
+ }
99
+ depositArgs.push(txb.object(priceId));
100
+ }
101
+ if (path.extendedDetails.metastableETHPriceSeed != null) {
102
+ const priceId = this.pythPriceIDs.get(path.extendedDetails.metastableETHPriceSeed)
103
+ if (priceId == null) {
104
+ throw new Error("Invalid Pyth price feed: " + path.extendedDetails.metastableETHPriceSeed)
105
+ }
106
+ depositArgs.push(txb.object(priceId));
107
+ }
108
+ depositArgs.push(txb.object(CLOCK_ADDRESS));
109
+ break;
110
+ }
111
+
112
+ default:
113
+ throw new Error("Invalid Metacoin: " + metaCoinType);
114
+ }
115
+
116
+ const depositResult = txb.moveCall({
117
+ target: `${createExchangePkgId}::${createDepositModule}::${createCapFunc}`,
118
+ typeArguments: createDepositCapTypeArgs,
119
+ arguments: depositArgs,
120
+ }) as TransactionObjectArgument
121
+
122
+ const swapArgs = [
123
+ txb.object(path.id),
124
+ txb.object(this.versionID),
125
+ depositResult,
126
+ inputCoin,
127
+ ]
128
+
129
+ const publishedAt = getAggregatorV2ExtendPublishedAt(client.publishedAtV2Extend(), packages)
130
+ const res = txb.moveCall({
131
+ target: `${publishedAt}::metastable::${func}`,
132
+ typeArguments: [
133
+ coinType,
134
+ metaCoinType,
135
+ ],
136
+ arguments: swapArgs,
137
+ }) as TransactionObjectArgument
138
+
139
+ return res
140
+ }
141
+ }
@@ -0,0 +1,377 @@
1
+ import { describe, test } from "@jest/globals"
2
+ import dotenv from "dotenv"
3
+ import { AggregatorClient } from "~/client"
4
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
5
+ import { printTransaction } from "~/utils/transaction"
6
+ import BN from "bn.js"
7
+ import { fromB64 } from "@mysten/sui/utils"
8
+ import { SuiClient } from "@mysten/sui/client"
9
+ import { Env } from "~/index"
10
+ import { Transaction } from "@mysten/sui/transactions"
11
+
12
+ dotenv.config()
13
+
14
+ export function buildTestAccount(): Ed25519Keypair {
15
+ const mnemonics = process.env.SUI_WALLET_MNEMONICS || ""
16
+ const testAccountObject = Ed25519Keypair.deriveKeypair(mnemonics)
17
+ return testAccountObject
18
+ }
19
+
20
+ describe("Test metastable provider", () => {
21
+ let client: AggregatorClient
22
+ let keypair: Ed25519Keypair
23
+
24
+ const T_SUPER_SUI = "0x790f258062909e3a0ffc78b3c53ac2f62d7084c3bab95644bdeb05add7250001::super_sui::SUPER_SUI"
25
+ const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
26
+ const AF_SUI = "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
27
+
28
+ const WH_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
29
+ const T_USDC = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
30
+ const M_USDC = "0xe44df51c0b21a27ab915fa1fe2ca610cd3eaa6d9666fe5e62b988bf7f0bd8722::musd::MUSD"
31
+
32
+ const METH = "0xccd628c2334c5ed33e6c47d6c21bb664f8b6307b2ac32c2462a61f69a31ebcee::meth::METH"
33
+ const ETH = "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH"
34
+ const WEHT = "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
35
+
36
+ beforeAll(() => {
37
+ const fullNodeURL = process.env.SUI_RPC!
38
+ const aggregatorURL = process.env.CETUS_AGGREGATOR!
39
+ const secret = process.env.SUI_WALLET_SECRET!
40
+
41
+ if (secret) {
42
+ keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
43
+ } else {
44
+ keypair = buildTestAccount()
45
+ }
46
+
47
+ // const wallet = keypair.getPublicKey().toSuiAddress()
48
+ // const wallet =
49
+ // "0x5cade8f29891e04c5f6e5ad3a020583fda51c8267f1b0c0fa5a85158d486ac3b" // has 1 meth
50
+
51
+ const wallet = "0x80cda5d0baa1e33ad073f590f8e6dc00a8d3657663ce06ce08c18ecbb0e47031" // has 80 eth
52
+
53
+ console.log("wallet: ", wallet)
54
+
55
+ const endpoint = aggregatorURL
56
+
57
+ const suiClient = new SuiClient({
58
+ url: fullNodeURL,
59
+ })
60
+ client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
61
+ })
62
+
63
+ test("Find Routers --> SUI -> SUPER_SUI", async () => {
64
+ // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
65
+ const amounts = ["999000000", "5000000000"]
66
+
67
+ for (const amount of amounts) {
68
+ const res = await client.findRouters({
69
+ from: T_SUI,
70
+ target: T_SUPER_SUI,
71
+ amount: new BN(amount),
72
+ byAmountIn: true,
73
+ depth: 3,
74
+ splitCount: 1,
75
+ providers: ["METASTABLE"],
76
+ })
77
+
78
+ if (res != null) {
79
+ console.log(JSON.stringify(res, null, 2))
80
+ }
81
+ console.log("amount in", res?.amountIn.toString())
82
+ console.log("amount out", res?.amountOut.toString())
83
+
84
+ const txb = new Transaction()
85
+
86
+ if (res != null) {
87
+ console.log(JSON.stringify(res, null, 2))
88
+ await client.fastRouterSwap({
89
+ routers: res,
90
+ txb,
91
+ slippage: 0.01,
92
+ refreshAllCoins: true,
93
+ payDeepFeeAmount: 0,
94
+ })
95
+
96
+ txb.setSender(client.signer)
97
+ const buildTxb = await txb.build({ client: client.client })
98
+ // const buildTxb = await txb.getData()
99
+
100
+ console.log("buildTxb", buildTxb)
101
+ // printTransaction(txb)
102
+
103
+ let result = await client.devInspectTransactionBlock(txb)
104
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
105
+ for (const event of result.events) {
106
+ console.log("event", JSON.stringify(event, null, 2))
107
+ }
108
+ }
109
+ }
110
+ })
111
+
112
+ test("Find Routers --> SUPER_SUI --> SUI", async () => {
113
+ // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
114
+ const amounts = ["1000", "1000000", "900000000"]
115
+
116
+ for (const amount of amounts) {
117
+ const res = await client.findRouters({
118
+ from: T_SUPER_SUI,
119
+ target: T_SUI,
120
+ amount: new BN(amount),
121
+ byAmountIn: true,
122
+ depth: 3,
123
+ splitCount: 1,
124
+ providers: ["METASTABLE"],
125
+ })
126
+
127
+ if (res != null) {
128
+ console.log(JSON.stringify(res, null, 2))
129
+ }
130
+ console.log("amount in", res?.amountIn.toString())
131
+ console.log("amount out", res?.amountOut.toString())
132
+
133
+ const txb = new Transaction()
134
+
135
+ if (res != null) {
136
+ console.log(JSON.stringify(res, null, 2))
137
+ await client.fastRouterSwap({
138
+ routers: res,
139
+ txb,
140
+ slippage: 0.01,
141
+ refreshAllCoins: true,
142
+ payDeepFeeAmount: 0,
143
+ })
144
+
145
+ txb.setSender(client.signer)
146
+ const buildTxb = await txb.build({ client: client.client })
147
+ // const buildTxb = await txb.getData()
148
+
149
+ // printTransaction(txb)
150
+
151
+ let result = await client.devInspectTransactionBlock(txb)
152
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
153
+ for (const event of result.events) {
154
+ console.log("event", JSON.stringify(event, null, 2))
155
+ }
156
+ }
157
+ }
158
+ })
159
+
160
+ test("Find Routers --> USDC -> MUSDC", async () => {
161
+ const amounts = ["1000000", "30000000"]
162
+
163
+ for (const amount of amounts) {
164
+ const res = await client.findRouters({
165
+ from: T_USDC,
166
+ target: M_USDC,
167
+ amount: new BN(amount),
168
+ byAmountIn: true,
169
+ depth: 3,
170
+ splitCount: 1,
171
+ providers: ["METASTABLE"],
172
+ })
173
+
174
+ if (res != null) {
175
+ console.log(JSON.stringify(res, null, 2))
176
+ }
177
+ console.log("amount in", res?.amountIn.toString())
178
+ console.log("amount out", res?.amountOut.toString())
179
+
180
+ const txb = new Transaction()
181
+
182
+ if (res != null) {
183
+ console.log(JSON.stringify(res, null, 2))
184
+ await client.fastRouterSwap({
185
+ routers: res,
186
+ txb,
187
+ slippage: 0.01,
188
+ refreshAllCoins: true,
189
+ payDeepFeeAmount: 0,
190
+ })
191
+ txb.setSender(client.signer)
192
+
193
+ let result = await client.devInspectTransactionBlock(txb)
194
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
195
+ for (const event of result.events) {
196
+ console.log("event", JSON.stringify(event, null, 2))
197
+ }
198
+ }
199
+ }
200
+ })
201
+
202
+ test("Find Routers --> MUSDC -> USDC", async () => {
203
+ // const amounts = ["1000", "1000000", "100000000", "5000000000", "10000000000000"]
204
+ const amounts = ["1000000", "1000000000"]
205
+
206
+ for (const amount of amounts) {
207
+ const res = await client.findRouters({
208
+ from: M_USDC,
209
+ target: T_USDC,
210
+ amount: new BN(amount),
211
+ byAmountIn: true,
212
+ depth: 3,
213
+ splitCount: 1,
214
+ providers: ["METASTABLE"],
215
+ })
216
+
217
+ if (res != null) {
218
+ console.log(JSON.stringify(res, null, 2))
219
+ }
220
+ console.log("amount in", res?.amountIn.toString())
221
+ console.log("amount out", res?.amountOut.toString())
222
+
223
+ const txb = new Transaction()
224
+
225
+ if (res != null) {
226
+ console.log(JSON.stringify(res, null, 2))
227
+ await client.fastRouterSwap({
228
+ routers: res,
229
+ txb,
230
+ slippage: 0.01,
231
+ refreshAllCoins: true,
232
+ payDeepFeeAmount: 0,
233
+ })
234
+ txb.setSender(client.signer)
235
+
236
+ let result = await client.devInspectTransactionBlock(txb)
237
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
238
+ for (const event of result.events) {
239
+ console.log("event", JSON.stringify(event, null, 2))
240
+ }
241
+ }
242
+
243
+ }
244
+ })
245
+
246
+ test("Find Routers --> METH -> ETH", async () => {
247
+ const amounts = ["5000000", "100000000"]
248
+
249
+ for (const amount of amounts) {
250
+ const res = await client.findRouters({
251
+ from: METH,
252
+ target: ETH,
253
+ amount: new BN(amount),
254
+ byAmountIn: true,
255
+ depth: 3,
256
+ splitCount: 1,
257
+ providers: ["METASTABLE"],
258
+ })
259
+
260
+ if (res != null) {
261
+ console.log(JSON.stringify(res, null, 2))
262
+ }
263
+ console.log("amount in", res?.amountIn.toString())
264
+ console.log("amount out", res?.amountOut.toString())
265
+
266
+ const txb = new Transaction()
267
+
268
+ if (res != null) {
269
+ console.log(JSON.stringify(res, null, 2))
270
+ await client.fastRouterSwap({
271
+ routers: res,
272
+ txb,
273
+ slippage: 0.01,
274
+ refreshAllCoins: true,
275
+ payDeepFeeAmount: 0,
276
+ })
277
+ txb.setSender(client.signer)
278
+
279
+ let result = await client.devInspectTransactionBlock(txb)
280
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
281
+ for (const event of result.events) {
282
+ console.log("event", JSON.stringify(event, null, 2))
283
+ }
284
+ }
285
+ }
286
+ })
287
+
288
+ test("Find Routers --> ETH -> METH", async () => {
289
+ const amounts = ["10000000", "5000000000"]
290
+
291
+ for (const amount of amounts) {
292
+ const res = await client.findRouters({
293
+ from: ETH,
294
+ target: METH,
295
+ amount: new BN(amount),
296
+ byAmountIn: true,
297
+ depth: 3,
298
+ splitCount: 1,
299
+ providers: ["METASTABLE"],
300
+ })
301
+
302
+ if (res != null) {
303
+ console.log(JSON.stringify(res, null, 2))
304
+ }
305
+ console.log("amount in", res?.amountIn.toString())
306
+ console.log("amount out", res?.amountOut.toString())
307
+
308
+ const txb = new Transaction()
309
+ if (res != null) {
310
+ console.log(JSON.stringify(res, null, 2))
311
+ await client.fastRouterSwap({
312
+ routers: res,
313
+ txb,
314
+ slippage: 0.01,
315
+ refreshAllCoins: true,
316
+ payDeepFeeAmount: 0,
317
+ })
318
+ txb.setSender(client.signer)
319
+
320
+ let result = await client.devInspectTransactionBlock(txb)
321
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
322
+ for (const event of result.events) {
323
+ console.log("event", JSON.stringify(event, null, 2))
324
+ }
325
+ }
326
+ }
327
+ })
328
+
329
+ test("Build Router TX", async () => {
330
+ const amount = "10000000"
331
+
332
+ const res = await client.findRouters({
333
+ from: T_USDC,
334
+ target: M_USDC,
335
+ amount: new BN(amount),
336
+ byAmountIn: true,
337
+ depth: 3,
338
+ providers: ["METASTABLE"],
339
+ })
340
+
341
+ console.log("amount in", res?.amountIn.toString())
342
+ console.log("amount out", res?.amountOut.toString())
343
+
344
+ const txb = new Transaction()
345
+
346
+ if (res != null) {
347
+ console.log(JSON.stringify(res, null, 2))
348
+ await client.fastRouterSwap({
349
+ routers: res,
350
+ txb,
351
+ slippage: 0.01,
352
+ refreshAllCoins: true,
353
+ payDeepFeeAmount: 0,
354
+ })
355
+
356
+ txb.setSender(client.signer)
357
+ const buildTxb = await txb.build({ client: client.client })
358
+ // const buildTxb = await txb.getData()
359
+
360
+ console.log("buildTxb", buildTxb)
361
+ // printTransaction(txb)
362
+
363
+ let result = await client.devInspectTransactionBlock(txb)
364
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
365
+ for (const event of result.events) {
366
+ console.log("event", JSON.stringify(event, null, 2))
367
+ }
368
+
369
+ // if (result.effects.status.status === "success") {
370
+ // const result = await client.signAndExecuteTransaction(txb, keypair)
371
+ // console.log("result", result)
372
+ // } else {
373
+ // console.log("result", result)
374
+ // }
375
+ }
376
+ }, 600000)
377
+ })
@@ -33,9 +33,7 @@ describe("router module", () => {
33
33
  keypair = buildTestAccount()
34
34
  }
35
35
 
36
- // const wallet = keypair.getPublicKey().toSuiAddress()
37
- const wallet =
38
- "0x073dfdcbb5d6552efd954273f7ab9e0b918d7bf30103e3f4e632502289cd92ee"
36
+ const wallet = keypair.getPublicKey().toSuiAddress()
39
37
 
40
38
  console.log("wallet: ", wallet)
41
39
 
@@ -49,7 +47,7 @@ describe("router module", () => {
49
47
  })
50
48
 
51
49
  test("Get coins", () => {
52
- return client.getCoins(testData.M_wUSDC).then((coins) => {
50
+ return client.getCoins(testData.M_USDC).then((coins) => {
53
51
  console.log(coins)
54
52
  })
55
53
  })