@cetusprotocol/aggregator-sdk 0.3.9 → 0.3.10

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
@@ -5758,6 +5758,15 @@ function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
5758
5758
  }
5759
5759
  return Number(amountLimit.toString());
5760
5760
  }
5761
+ function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
5762
+ let amountLimit = ZERO;
5763
+ if (byAmountIn) {
5764
+ amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE - slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
5765
+ } else {
5766
+ amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE + slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
5767
+ }
5768
+ return amountLimit;
5769
+ }
5761
5770
  function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
5762
5771
  const sqrtPriceX64 = new decimal_default(sqrtPriceStr).mul(decimal_default.pow(2, -64));
5763
5772
  return sqrtPriceX64.pow(2).mul(decimal_default.pow(10, decimalsA - decimalsB));
@@ -6279,7 +6288,7 @@ var AggregatorClient8 = class {
6279
6288
  (acc, router) => acc.add(router.amountOut),
6280
6289
  new import_bn5.default(0)
6281
6290
  );
6282
- const amountLimit = CalculateAmountLimit(
6291
+ const amountLimit = CalculateAmountLimitBN(
6283
6292
  byAmountIn ? amountOut : amountIn,
6284
6293
  byAmountIn,
6285
6294
  slippage
@@ -6289,7 +6298,7 @@ var AggregatorClient8 = class {
6289
6298
  txb,
6290
6299
  inputCoin,
6291
6300
  routers,
6292
- new import_bn5.default(amountLimit),
6301
+ amountLimit,
6293
6302
  partner,
6294
6303
  deepbookv3DeepFee
6295
6304
  );
package/dist/index.mjs CHANGED
@@ -5756,6 +5756,15 @@ function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
5756
5756
  }
5757
5757
  return Number(amountLimit.toString());
5758
5758
  }
5759
+ function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
5760
+ let amountLimit = ZERO;
5761
+ if (byAmountIn) {
5762
+ amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE - slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
5763
+ } else {
5764
+ amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE + slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
5765
+ }
5766
+ return amountLimit;
5767
+ }
5759
5768
  function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
5760
5769
  const sqrtPriceX64 = new decimal_default(sqrtPriceStr).mul(decimal_default.pow(2, -64));
5761
5770
  return sqrtPriceX64.pow(2).mul(decimal_default.pow(10, decimalsA - decimalsB));
@@ -6277,7 +6286,7 @@ var AggregatorClient8 = class {
6277
6286
  (acc, router) => acc.add(router.amountOut),
6278
6287
  new import_bn5.default(0)
6279
6288
  );
6280
- const amountLimit = CalculateAmountLimit(
6289
+ const amountLimit = CalculateAmountLimitBN(
6281
6290
  byAmountIn ? amountOut : amountIn,
6282
6291
  byAmountIn,
6283
6292
  slippage
@@ -6287,7 +6296,7 @@ var AggregatorClient8 = class {
6287
6296
  txb,
6288
6297
  inputCoin,
6289
6298
  routers,
6290
- new import_bn5.default(amountLimit),
6299
+ amountLimit,
6291
6300
  partner,
6292
6301
  deepbookv3DeepFee
6293
6302
  );
@@ -1,5 +1,6 @@
1
1
  import BN from "bn.js";
2
2
  import Decimal from "decimal.js";
3
3
  export declare function CalculateAmountLimit(expectAmount: BN, byAmountIn: boolean, slippage: number): number;
4
+ export declare function CalculateAmountLimitBN(expectAmount: BN, byAmountIn: boolean, slippage: number): BN;
4
5
  export declare function GetDefaultSqrtPriceLimit(a2b: boolean): BN;
5
6
  export declare function sqrtPriceX64ToPrice(sqrtPriceStr: string, decimalsA: number, decimalsB: number): Decimal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/client.ts CHANGED
@@ -28,7 +28,7 @@ import { FlowxV3 } from "./transaction/flowx_v3"
28
28
  import { Turbos } from "./transaction/turbos"
29
29
  import { Cetus } from "./transaction/cetus"
30
30
  import { swapInPools } from "./transaction/swap"
31
- import { CalculateAmountLimit } from "./math"
31
+ import { CalculateAmountLimit, CalculateAmountLimitBN } from "./math"
32
32
  import { Haedal } from "./transaction/haedal"
33
33
  import { Afsui } from "./transaction/afsui"
34
34
  import { Volo } from "./transaction/volo"
@@ -284,7 +284,7 @@ export class AggregatorClient {
284
284
  (acc, router) => acc.add(router.amountOut),
285
285
  new BN(0)
286
286
  )
287
- const amountLimit = CalculateAmountLimit(
287
+ const amountLimit = CalculateAmountLimitBN(
288
288
  byAmountIn ? amountOut : amountIn,
289
289
  byAmountIn,
290
290
  slippage
@@ -295,7 +295,7 @@ export class AggregatorClient {
295
295
  txb,
296
296
  inputCoin,
297
297
  routers,
298
- new BN(amountLimit),
298
+ amountLimit,
299
299
  partner,
300
300
  deepbookv3DeepFee
301
301
  )
package/src/math.ts CHANGED
@@ -26,6 +26,25 @@ export function CalculateAmountLimit(
26
26
  return Number(amountLimit.toString())
27
27
  }
28
28
 
29
+ export function CalculateAmountLimitBN(
30
+ expectAmount: BN,
31
+ byAmountIn: boolean,
32
+ slippage: number
33
+ ): BN {
34
+ let amountLimit = ZERO
35
+ if (byAmountIn) {
36
+ amountLimit = expectAmount
37
+ .mul(new BN(TEN_POW_NINE - slippage * TEN_POW_NINE))
38
+ .div(new BN(TEN_POW_NINE))
39
+ } else {
40
+ amountLimit = expectAmount
41
+ .mul(new BN(TEN_POW_NINE + slippage * TEN_POW_NINE))
42
+ .div(new BN(TEN_POW_NINE))
43
+ }
44
+
45
+ return amountLimit
46
+ }
47
+
29
48
  const MAX_SQER_PRICE_X64 = "79226673515401279992447579055"
30
49
  const MIN_SQER_PRICE_X64 = "4295048016"
31
50
 
@@ -112,9 +112,9 @@ describe("router module", () => {
112
112
 
113
113
  test("Build router tx", async () => {
114
114
  const byAmountIn = true
115
- const amount = "320000"
115
+ const amount = "400000000000"
116
116
  const from = "0x2::sui::SUI"
117
- const target = "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI"
117
+ const target = "0xaf3aae4940a248739ce4964857381fc3f3149a6d05375bfbb2118592907e3bbb::dam::DAM"
118
118
 
119
119
  const res = await client.findRouters({
120
120
  from,
@@ -122,17 +122,6 @@ describe("router module", () => {
122
122
  amount: new BN(amount),
123
123
  byAmountIn,
124
124
  depth: 3,
125
- providers: [
126
- "SUILEND",
127
- // "CETUS",
128
- // "DEEPBOOKV3",
129
- // "DEEPBOOK",
130
- // "AFTERMATH",
131
- // "FLOWX",
132
- // "KRIYA",
133
- // "KRIYAV3",
134
- // "TURBOS",
135
- ],
136
125
  })
137
126
 
138
127
  if (res != null) {
@@ -152,7 +141,7 @@ describe("router module", () => {
152
141
  txb,
153
142
  slippage: 0.01,
154
143
  isMergeTragetCoin: false,
155
- partner: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5",
144
+ // partner: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5",
156
145
  refreshAllCoins: true,
157
146
  payDeepFeeAmount: 0,
158
147
  })
@@ -161,14 +150,18 @@ describe("router module", () => {
161
150
 
162
151
  let result = await client.devInspectTransactionBlock(txb)
163
152
  console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
164
-
165
- if (result.effects.status.status === "success") {
166
- // console.log("Sim exec transaction success")
167
- const result = await client.signAndExecuteTransaction(txb, keypair)
168
- console.log("result", result)
169
- } else {
170
- console.log("result", result)
153
+ for (const event of result.events) {
154
+ console.log("event", JSON.stringify(event, null, 2))
171
155
  }
156
+ console.log("txb", )
157
+
158
+ // if (result.effects.status.status === "success") {
159
+ // // console.log("Sim exec transaction success")
160
+ // const result = await client.signAndExecuteTransaction(txb, keypair)
161
+ // console.log("result", result)
162
+ // } else {
163
+ // console.log("result", result)
164
+ // }
172
165
  }
173
166
  }, 600000)
174
167