@cetusprotocol/aggregator-sdk 0.3.30 → 0.3.32

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/dist/index.js CHANGED
@@ -5633,6 +5633,8 @@ function getAggregatorServerErrorMessage(code) {
5633
5633
  return "Insufficient Liquidity";
5634
5634
  case 10004 /* HoneyPot */:
5635
5635
  return "Target token is detected as a HoneyPot scam";
5636
+ case 10005 /* RateLimitExceeded */:
5637
+ return "Too many requests. Please try again later";
5636
5638
  default:
5637
5639
  return "Unknown error";
5638
5640
  }
@@ -6792,7 +6794,7 @@ var _AggregatorClient = class _AggregatorClient {
6792
6794
  // Include deepbookv3, scallop, bluefin
6793
6795
  publishedAtV2Extend() {
6794
6796
  if (this.env === 0 /* Mainnet */) {
6795
- return "0x34ef25b60b51f9d07cd9b7dc5b08dfdf26c7b0ff00c57bb17454c161fa6b6b83";
6797
+ return "0xf57be4b9f9036034b1c5484d299d8fb68d5f43862d6afe8886d67db293dfc4bc";
6796
6798
  } else {
6797
6799
  return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
6798
6800
  }
@@ -7143,7 +7145,7 @@ function processEndpoint(endpoint) {
7143
7145
  }
7144
7146
 
7145
7147
  // src/api.ts
7146
- var SDK_VERSION = 1000330;
7148
+ var SDK_VERSION = 1000332;
7147
7149
  function getRouterResult(endpoint, params) {
7148
7150
  return __async(this, null, function* () {
7149
7151
  let response;
@@ -7156,6 +7158,10 @@ function getRouterResult(endpoint, params) {
7156
7158
  return null;
7157
7159
  }
7158
7160
  if (!response.ok) {
7161
+ let errorCode = 10001 /* NumberTooLarge */;
7162
+ if (response.status === 429) {
7163
+ errorCode = 10005 /* RateLimitExceeded */;
7164
+ }
7159
7165
  return {
7160
7166
  amountIn: ZERO,
7161
7167
  amountOut: ZERO,
@@ -7163,10 +7169,8 @@ function getRouterResult(endpoint, params) {
7163
7169
  byAmountIn: params.byAmountIn,
7164
7170
  insufficientLiquidity: false,
7165
7171
  error: {
7166
- code: 10001 /* NumberTooLarge */,
7167
- msg: getAggregatorServerErrorMessage(
7168
- 10001 /* NumberTooLarge */
7169
- )
7172
+ code: errorCode,
7173
+ msg: getAggregatorServerErrorMessage(errorCode)
7170
7174
  }
7171
7175
  };
7172
7176
  }
package/dist/index.mjs CHANGED
@@ -5631,6 +5631,8 @@ function getAggregatorServerErrorMessage(code) {
5631
5631
  return "Insufficient Liquidity";
5632
5632
  case 10004 /* HoneyPot */:
5633
5633
  return "Target token is detected as a HoneyPot scam";
5634
+ case 10005 /* RateLimitExceeded */:
5635
+ return "Too many requests. Please try again later";
5634
5636
  default:
5635
5637
  return "Unknown error";
5636
5638
  }
@@ -6790,7 +6792,7 @@ var _AggregatorClient = class _AggregatorClient {
6790
6792
  // Include deepbookv3, scallop, bluefin
6791
6793
  publishedAtV2Extend() {
6792
6794
  if (this.env === 0 /* Mainnet */) {
6793
- return "0x34ef25b60b51f9d07cd9b7dc5b08dfdf26c7b0ff00c57bb17454c161fa6b6b83";
6795
+ return "0xf57be4b9f9036034b1c5484d299d8fb68d5f43862d6afe8886d67db293dfc4bc";
6794
6796
  } else {
6795
6797
  return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78";
6796
6798
  }
@@ -7141,7 +7143,7 @@ function processEndpoint(endpoint) {
7141
7143
  }
7142
7144
 
7143
7145
  // src/api.ts
7144
- var SDK_VERSION = 1000330;
7146
+ var SDK_VERSION = 1000332;
7145
7147
  function getRouterResult(endpoint, params) {
7146
7148
  return __async(this, null, function* () {
7147
7149
  let response;
@@ -7154,6 +7156,10 @@ function getRouterResult(endpoint, params) {
7154
7156
  return null;
7155
7157
  }
7156
7158
  if (!response.ok) {
7159
+ let errorCode = 10001 /* NumberTooLarge */;
7160
+ if (response.status === 429) {
7161
+ errorCode = 10005 /* RateLimitExceeded */;
7162
+ }
7157
7163
  return {
7158
7164
  amountIn: ZERO,
7159
7165
  amountOut: ZERO,
@@ -7161,10 +7167,8 @@ function getRouterResult(endpoint, params) {
7161
7167
  byAmountIn: params.byAmountIn,
7162
7168
  insufficientLiquidity: false,
7163
7169
  error: {
7164
- code: 10001 /* NumberTooLarge */,
7165
- msg: getAggregatorServerErrorMessage(
7166
- 10001 /* NumberTooLarge */
7167
- )
7170
+ code: errorCode,
7171
+ msg: getAggregatorServerErrorMessage(errorCode)
7168
7172
  }
7169
7173
  };
7170
7174
  }
@@ -34,6 +34,7 @@ export declare enum AggregatorServerErrorCode {
34
34
  NumberTooLarge = 10001,
35
35
  NoRouter = 10002,
36
36
  InsufficientLiquidity = 10003,
37
- HoneyPot = 10004
37
+ HoneyPot = 10004,
38
+ RateLimitExceeded = 10005
38
39
  }
39
40
  export declare function getAggregatorServerErrorMessage(code: AggregatorServerErrorCode): string;
@@ -0,0 +1,2 @@
1
+ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
2
+ export declare function buildTestAccount(): Ed25519Keypair;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.3.30",
3
+ "version": "0.3.32",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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 = 1000330
11
+ const SDK_VERSION = 1000332
12
12
 
13
13
  export interface FindRouterParams {
14
14
  from: string
@@ -120,6 +120,11 @@ export async function getRouterResult(
120
120
  }
121
121
 
122
122
  if (!response.ok) {
123
+ let errorCode = AggregatorServerErrorCode.NumberTooLarge
124
+ if (response.status === 429) {
125
+ errorCode = AggregatorServerErrorCode.RateLimitExceeded
126
+ }
127
+
123
128
  return {
124
129
  amountIn: ZERO,
125
130
  amountOut: ZERO,
@@ -127,10 +132,8 @@ export async function getRouterResult(
127
132
  byAmountIn: params.byAmountIn,
128
133
  insufficientLiquidity: false,
129
134
  error: {
130
- code: AggregatorServerErrorCode.NumberTooLarge,
131
- msg: getAggregatorServerErrorMessage(
132
- AggregatorServerErrorCode.NumberTooLarge
133
- ),
135
+ code: errorCode,
136
+ msg: getAggregatorServerErrorMessage(errorCode),
134
137
  },
135
138
  }
136
139
  }
package/src/client.ts CHANGED
@@ -610,7 +610,8 @@ export class AggregatorClient {
610
610
  // return "0x347dd58bbd11cd82c8b386b344729717c04a998da73386e82a239cc196d5706b" // version 7
611
611
  // return "0xf2fcea41dc217385019828375764fa06d9bd25e8e4726ba1962680849fb8d613" // version 8
612
612
  // return "0xa2d8a4279d69d8fec04b2fea8852d0d467d3cc0d39c5890180d439ae7a9953ed" // version 9
613
- return "0x34ef25b60b51f9d07cd9b7dc5b08dfdf26c7b0ff00c57bb17454c161fa6b6b83" // version 10
613
+ // return "0x34ef25b60b51f9d07cd9b7dc5b08dfdf26c7b0ff00c57bb17454c161fa6b6b83" // version 10
614
+ return "0xf57be4b9f9036034b1c5484d299d8fb68d5f43862d6afe8886d67db293dfc4bc" // version 11
614
615
  } else {
615
616
  return "0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"
616
617
  }
package/src/errors.ts CHANGED
@@ -51,7 +51,8 @@ export enum AggregatorServerErrorCode {
51
51
  NumberTooLarge = 10001,
52
52
  NoRouter = 10002,
53
53
  InsufficientLiquidity = 10003,
54
- HoneyPot = 10004
54
+ HoneyPot = 10004,
55
+ RateLimitExceeded = 10005,
55
56
  }
56
57
 
57
58
  export function getAggregatorServerErrorMessage(
@@ -68,6 +69,8 @@ export function getAggregatorServerErrorMessage(
68
69
  return "Insufficient Liquidity"
69
70
  case AggregatorServerErrorCode.HoneyPot:
70
71
  return "Target token is detected as a HoneyPot scam"
72
+ case AggregatorServerErrorCode.RateLimitExceeded:
73
+ return "Too many requests. Please try again later"
71
74
  default:
72
75
  return "Unknown error"
73
76
  }
@@ -37,4 +37,4 @@ export const restituteMsafeFastRouterSwapParams = (data: any) => {
37
37
  }
38
38
 
39
39
  return result
40
- }
40
+ }
@@ -0,0 +1,127 @@
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 scallop provider", () => {
21
+ let client: AggregatorClient
22
+ let keypair: Ed25519Keypair
23
+
24
+ const T_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
25
+ const T_SHASUI = "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI"
26
+
27
+ const T_SUI = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
28
+ const T_SSUI = "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI"
29
+
30
+ beforeAll(() => {
31
+ const fullNodeURL = process.env.SUI_RPC!
32
+ const aggregatorURL = process.env.CETUS_AGGREGATOR!
33
+ const secret = process.env.SUI_WALLET_SECRET!
34
+
35
+ if (secret) {
36
+ keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
37
+ } else {
38
+ keypair = buildTestAccount()
39
+ }
40
+
41
+ // const wallet = keypair.getPublicKey().toSuiAddress()
42
+ const wallet =
43
+ "0xf077fa7f67b1f2d417bbe977b3cbc113b078907f74e04120f623b87b23e93963"
44
+
45
+ console.log("wallet: ", wallet)
46
+
47
+ const endpoint = aggregatorURL
48
+
49
+ const suiClient = new SuiClient({
50
+ url: fullNodeURL,
51
+ })
52
+
53
+ client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
54
+ })
55
+
56
+ test("Find Routers", async () => {
57
+ const amounts = ["1000", "1000000", "100000000", "5000000000", "1000000000000000000000000000"]
58
+
59
+ while (true) {
60
+ const res = await client.findRouters({
61
+ from: T_SUI,
62
+ target: T_SSUI,
63
+ amount: new BN("1000000000000000000000000000"),
64
+ byAmountIn: true,
65
+ depth: 3,
66
+ splitCount: 1,
67
+ providers: ["SCALLOP"],
68
+ })
69
+
70
+ if (res != null) {
71
+ console.log(JSON.stringify(res, null, 2))
72
+ }
73
+ console.log("amount in", res?.amountIn.toString())
74
+ console.log("amount out", res?.amountOut.toString())
75
+ }
76
+ }, 6000000)
77
+
78
+ test("Build Router TX", async () => {
79
+ const amount = "10000000"
80
+
81
+ const res = await client.findRouters({
82
+ from: T_HASUI,
83
+ target: T_SHASUI,
84
+ amount: new BN(amount),
85
+ byAmountIn: true,
86
+ depth: 3,
87
+ providers: ["SCALLOP"],
88
+ })
89
+
90
+ console.log("amount in", res?.amountIn.toString())
91
+ console.log("amount out", res?.amountOut.toString())
92
+
93
+ const txb = new Transaction()
94
+
95
+ if (res != null) {
96
+ console.log(JSON.stringify(res, null, 2))
97
+ await client.fastRouterSwap({
98
+ routers: res,
99
+ txb,
100
+ slippage: 0.01,
101
+ refreshAllCoins: true,
102
+ payDeepFeeAmount: 0,
103
+ })
104
+
105
+ txb.setSender(client.signer)
106
+ const buildTxb = await txb.build({ client: client.client })
107
+ // const buildTxb = await txb.getData()
108
+
109
+ console.log("buildTxb", buildTxb)
110
+
111
+ printTransaction(txb)
112
+
113
+ let result = await client.devInspectTransactionBlock(txb)
114
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
115
+ for (const event of result.events) {
116
+ console.log("event", JSON.stringify(event, null, 2))
117
+ }
118
+
119
+ if (result.effects.status.status === "success") {
120
+ const result = await client.signAndExecuteTransaction(txb, keypair)
121
+ console.log("result", result)
122
+ } else {
123
+ console.log("result", result)
124
+ }
125
+ }
126
+ }, 600000)
127
+ })