@7kprotocol/sdk-ts 2.4.0 → 2.4.2-beta.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 (207) hide show
  1. package/README.md +30 -3
  2. package/lib/cjs/config/fetchClient.js +11 -19
  3. package/lib/cjs/config/index.js +22 -0
  4. package/lib/cjs/constants/_7k.js +6 -3
  5. package/lib/cjs/features/limitDca/cancelDcaOrder.js +7 -18
  6. package/lib/cjs/features/limitDca/cancelLimitOrder.js +7 -18
  7. package/lib/cjs/features/limitDca/claimExpiredLimitOrder.js +7 -18
  8. package/lib/cjs/features/limitDca/constants.js +1 -5
  9. package/lib/cjs/features/limitDca/getClosedDcaOrders.js +16 -27
  10. package/lib/cjs/features/limitDca/getClosedLimitOrders.js +15 -26
  11. package/lib/cjs/features/limitDca/getDcaOrderExecutions.js +16 -27
  12. package/lib/cjs/features/limitDca/getOpenDcaOrders.js +15 -26
  13. package/lib/cjs/features/limitDca/getOpenLimitOrders.js +15 -26
  14. package/lib/cjs/features/limitDca/placeDcaOrder.js +25 -36
  15. package/lib/cjs/features/limitDca/placeLimitOrder.js +14 -25
  16. package/lib/cjs/features/prices/index.js +47 -64
  17. package/lib/cjs/features/swap/buildTx.js +88 -39
  18. package/lib/cjs/features/swap/config.js +32 -32
  19. package/lib/cjs/features/swap/estimateGasFee.js +36 -46
  20. package/lib/cjs/features/swap/executeTx.js +52 -0
  21. package/lib/cjs/features/swap/getQuote.js +41 -31
  22. package/lib/cjs/features/swap/getSwapHistory.js +14 -25
  23. package/lib/cjs/features/swap/index.js +1 -0
  24. package/lib/cjs/index.js +16 -9
  25. package/lib/cjs/libs/getCoinOjectIdsByAmount.js +15 -24
  26. package/lib/cjs/libs/getSplitCoinForTx.js +8 -15
  27. package/lib/cjs/libs/groupSwapRoutes.js +10 -12
  28. package/lib/cjs/libs/protocols/aftermath/index.js +25 -36
  29. package/lib/cjs/libs/protocols/base.js +10 -3
  30. package/lib/cjs/libs/protocols/bluefin/index.js +26 -43
  31. package/lib/cjs/libs/protocols/bluefinx/client.js +35 -0
  32. package/lib/cjs/libs/protocols/bluefinx/index.js +48 -0
  33. package/lib/cjs/libs/protocols/bluefinx/types.js +10 -0
  34. package/lib/cjs/libs/protocols/bluemove/index.js +14 -25
  35. package/lib/cjs/libs/protocols/cetus/index.js +32 -43
  36. package/lib/cjs/libs/protocols/deepbookV3/sponsored.js +19 -30
  37. package/lib/cjs/libs/protocols/flowx/index.js +9 -20
  38. package/lib/cjs/libs/protocols/flowxV3/index.js +25 -39
  39. package/lib/cjs/libs/protocols/haedal_pmm/index.js +33 -0
  40. package/lib/cjs/libs/protocols/index.js +7 -2
  41. package/lib/cjs/libs/protocols/kriya/index.js +20 -31
  42. package/lib/cjs/libs/protocols/kriyaV3/index.js +54 -65
  43. package/lib/cjs/libs/protocols/magma/index.js +28 -40
  44. package/lib/cjs/libs/protocols/momentum/index.js +49 -0
  45. package/lib/cjs/libs/protocols/obric/index.js +20 -31
  46. package/lib/cjs/libs/protocols/springsui/index.js +14 -25
  47. package/lib/cjs/libs/protocols/steamm/index.js +57 -58
  48. package/lib/cjs/libs/protocols/stsui/index.js +14 -25
  49. package/lib/cjs/libs/protocols/suiswap/index.js +23 -34
  50. package/lib/cjs/libs/protocols/turbos/index.js +23 -38
  51. package/lib/cjs/libs/protocols/utils.js +1 -5
  52. package/lib/cjs/libs/swapWithRoute.js +17 -27
  53. package/lib/cjs/types/aggregator.js +17 -0
  54. package/lib/cjs/types/config/index.d.ts +9 -0
  55. package/lib/cjs/types/config/index.d.ts.map +1 -1
  56. package/lib/cjs/types/constants/_7k.d.ts +3 -3
  57. package/lib/cjs/types/constants/_7k.d.ts.map +1 -1
  58. package/lib/cjs/types/features/limitDca/constants.d.ts +1 -2
  59. package/lib/cjs/types/features/limitDca/constants.d.ts.map +1 -1
  60. package/lib/cjs/types/features/swap/buildTx.d.ts +2 -5
  61. package/lib/cjs/types/features/swap/buildTx.d.ts.map +1 -1
  62. package/lib/cjs/types/features/swap/config.d.ts.map +1 -1
  63. package/lib/cjs/types/features/swap/estimateGasFee.d.ts.map +1 -1
  64. package/lib/cjs/types/features/swap/executeTx.d.ts +24 -0
  65. package/lib/cjs/types/features/swap/executeTx.d.ts.map +1 -0
  66. package/lib/cjs/types/features/swap/getQuote.d.ts +8 -1
  67. package/lib/cjs/types/features/swap/getQuote.d.ts.map +1 -1
  68. package/lib/cjs/types/features/swap/index.d.ts +1 -0
  69. package/lib/cjs/types/features/swap/index.d.ts.map +1 -1
  70. package/lib/cjs/types/index.d.ts +13 -8
  71. package/lib/cjs/types/index.d.ts.map +1 -1
  72. package/lib/cjs/types/libs/getCoinOjectIdsByAmount.d.ts.map +1 -1
  73. package/lib/cjs/types/libs/getSplitCoinForTx.d.ts +1 -1
  74. package/lib/cjs/types/libs/getSplitCoinForTx.d.ts.map +1 -1
  75. package/lib/cjs/types/libs/groupSwapRoutes.d.ts.map +1 -1
  76. package/lib/cjs/types/libs/protocols/base.d.ts +6 -2
  77. package/lib/cjs/types/libs/protocols/base.d.ts.map +1 -1
  78. package/lib/cjs/types/libs/protocols/bluefin/index.d.ts.map +1 -1
  79. package/lib/cjs/types/libs/protocols/bluefinx/client.d.ts +13 -0
  80. package/lib/cjs/types/libs/protocols/bluefinx/client.d.ts.map +1 -0
  81. package/lib/cjs/types/libs/protocols/bluefinx/index.d.ts +17 -0
  82. package/lib/cjs/types/libs/protocols/bluefinx/index.d.ts.map +1 -0
  83. package/lib/cjs/types/libs/protocols/bluefinx/types.d.ts +34 -0
  84. package/lib/cjs/types/libs/protocols/bluefinx/types.d.ts.map +1 -0
  85. package/lib/cjs/types/libs/protocols/cetus/index.d.ts.map +1 -1
  86. package/lib/cjs/types/libs/protocols/deepbookV3/sponsored.d.ts.map +1 -1
  87. package/lib/cjs/types/libs/protocols/flowxV3/index.d.ts.map +1 -1
  88. package/lib/{esm/types/libs/protocols/deepbook → cjs/types/libs/protocols/haedal_pmm}/index.d.ts +1 -3
  89. package/lib/cjs/types/libs/protocols/haedal_pmm/index.d.ts.map +1 -0
  90. package/lib/cjs/types/libs/protocols/index.d.ts +7 -2
  91. package/lib/cjs/types/libs/protocols/index.d.ts.map +1 -1
  92. package/lib/cjs/types/libs/protocols/magma/index.d.ts.map +1 -1
  93. package/lib/cjs/types/libs/protocols/{deepbook → momentum}/index.d.ts +1 -3
  94. package/lib/cjs/types/libs/protocols/momentum/index.d.ts.map +1 -0
  95. package/lib/cjs/types/libs/protocols/steamm/index.d.ts +13 -2
  96. package/lib/cjs/types/libs/protocols/steamm/index.d.ts.map +1 -1
  97. package/lib/cjs/types/libs/protocols/suiswap/index.d.ts.map +1 -1
  98. package/lib/cjs/types/libs/protocols/turbos/index.d.ts.map +1 -1
  99. package/lib/cjs/types/libs/protocols/utils.d.ts +1 -2
  100. package/lib/cjs/types/libs/protocols/utils.d.ts.map +1 -1
  101. package/lib/cjs/types/libs/swapWithRoute.d.ts +3 -1
  102. package/lib/cjs/types/libs/swapWithRoute.d.ts.map +1 -1
  103. package/lib/cjs/types/types/aggregator.d.ts +36 -2
  104. package/lib/cjs/types/types/aggregator.d.ts.map +1 -1
  105. package/lib/cjs/types/types/tx.d.ts +36 -2
  106. package/lib/cjs/types/types/tx.d.ts.map +1 -1
  107. package/lib/cjs/types/utils/number.d.ts +1 -3
  108. package/lib/cjs/types/utils/number.d.ts.map +1 -1
  109. package/lib/cjs/types/utils/sui.d.ts +1 -1
  110. package/lib/cjs/types/utils/sui.d.ts.map +1 -1
  111. package/lib/cjs/utils/number.js +4 -10
  112. package/lib/cjs/utils/sui.js +71 -80
  113. package/lib/esm/config/index.js +22 -0
  114. package/lib/esm/constants/_7k.js +6 -3
  115. package/lib/esm/features/limitDca/constants.js +1 -2
  116. package/lib/esm/features/swap/buildTx.js +81 -20
  117. package/lib/esm/features/swap/config.js +19 -8
  118. package/lib/esm/features/swap/estimateGasFee.js +13 -9
  119. package/lib/esm/features/swap/executeTx.js +48 -0
  120. package/lib/esm/features/swap/getQuote.js +24 -3
  121. package/lib/esm/features/swap/index.js +1 -0
  122. package/lib/esm/index.mjs +8 -4
  123. package/lib/esm/libs/getCoinOjectIdsByAmount.js +7 -7
  124. package/lib/esm/libs/getSplitCoinForTx.js +5 -3
  125. package/lib/esm/libs/groupSwapRoutes.js +1 -2
  126. package/lib/esm/libs/protocols/base.js +10 -1
  127. package/lib/esm/libs/protocols/bluefin/index.js +2 -5
  128. package/lib/esm/libs/protocols/bluefinx/client.js +30 -0
  129. package/lib/esm/libs/protocols/bluefinx/index.js +44 -0
  130. package/lib/esm/libs/protocols/bluefinx/types.js +8 -0
  131. package/lib/esm/libs/protocols/cetus/index.js +1 -1
  132. package/lib/esm/libs/protocols/deepbookV3/sponsored.js +1 -1
  133. package/lib/esm/libs/protocols/flowxV3/index.js +1 -4
  134. package/lib/esm/libs/protocols/haedal_pmm/index.js +29 -0
  135. package/lib/esm/libs/protocols/index.js +7 -2
  136. package/lib/esm/libs/protocols/magma/index.js +1 -2
  137. package/lib/esm/libs/protocols/momentum/index.js +45 -0
  138. package/lib/esm/libs/protocols/steamm/index.js +58 -48
  139. package/lib/esm/libs/protocols/suiswap/index.js +1 -1
  140. package/lib/esm/libs/protocols/turbos/index.js +2 -6
  141. package/lib/esm/libs/protocols/utils.js +1 -2
  142. package/lib/esm/libs/swapWithRoute.js +2 -1
  143. package/lib/esm/types/aggregator.js +14 -1
  144. package/lib/esm/types/config/index.d.ts +9 -0
  145. package/lib/esm/types/config/index.d.ts.map +1 -1
  146. package/lib/esm/types/constants/_7k.d.ts +3 -3
  147. package/lib/esm/types/constants/_7k.d.ts.map +1 -1
  148. package/lib/esm/types/features/limitDca/constants.d.ts +1 -2
  149. package/lib/esm/types/features/limitDca/constants.d.ts.map +1 -1
  150. package/lib/esm/types/features/swap/buildTx.d.ts +2 -5
  151. package/lib/esm/types/features/swap/buildTx.d.ts.map +1 -1
  152. package/lib/esm/types/features/swap/config.d.ts.map +1 -1
  153. package/lib/esm/types/features/swap/estimateGasFee.d.ts.map +1 -1
  154. package/lib/esm/types/features/swap/executeTx.d.ts +24 -0
  155. package/lib/esm/types/features/swap/executeTx.d.ts.map +1 -0
  156. package/lib/esm/types/features/swap/getQuote.d.ts +8 -1
  157. package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
  158. package/lib/esm/types/features/swap/index.d.ts +1 -0
  159. package/lib/esm/types/features/swap/index.d.ts.map +1 -1
  160. package/lib/esm/types/index.d.ts +13 -8
  161. package/lib/esm/types/index.d.ts.map +1 -1
  162. package/lib/esm/types/libs/getCoinOjectIdsByAmount.d.ts.map +1 -1
  163. package/lib/esm/types/libs/getSplitCoinForTx.d.ts +1 -1
  164. package/lib/esm/types/libs/getSplitCoinForTx.d.ts.map +1 -1
  165. package/lib/esm/types/libs/groupSwapRoutes.d.ts.map +1 -1
  166. package/lib/esm/types/libs/protocols/base.d.ts +6 -2
  167. package/lib/esm/types/libs/protocols/base.d.ts.map +1 -1
  168. package/lib/esm/types/libs/protocols/bluefin/index.d.ts.map +1 -1
  169. package/lib/esm/types/libs/protocols/bluefinx/client.d.ts +13 -0
  170. package/lib/esm/types/libs/protocols/bluefinx/client.d.ts.map +1 -0
  171. package/lib/esm/types/libs/protocols/bluefinx/index.d.ts +17 -0
  172. package/lib/esm/types/libs/protocols/bluefinx/index.d.ts.map +1 -0
  173. package/lib/esm/types/libs/protocols/bluefinx/types.d.ts +34 -0
  174. package/lib/esm/types/libs/protocols/bluefinx/types.d.ts.map +1 -0
  175. package/lib/esm/types/libs/protocols/cetus/index.d.ts.map +1 -1
  176. package/lib/esm/types/libs/protocols/deepbookV3/sponsored.d.ts.map +1 -1
  177. package/lib/esm/types/libs/protocols/flowxV3/index.d.ts.map +1 -1
  178. package/lib/esm/types/libs/protocols/haedal_pmm/index.d.ts +9 -0
  179. package/lib/esm/types/libs/protocols/haedal_pmm/index.d.ts.map +1 -0
  180. package/lib/esm/types/libs/protocols/index.d.ts +7 -2
  181. package/lib/esm/types/libs/protocols/index.d.ts.map +1 -1
  182. package/lib/esm/types/libs/protocols/magma/index.d.ts.map +1 -1
  183. package/lib/esm/types/libs/protocols/momentum/index.d.ts +9 -0
  184. package/lib/esm/types/libs/protocols/momentum/index.d.ts.map +1 -0
  185. package/lib/esm/types/libs/protocols/steamm/index.d.ts +13 -2
  186. package/lib/esm/types/libs/protocols/steamm/index.d.ts.map +1 -1
  187. package/lib/esm/types/libs/protocols/suiswap/index.d.ts.map +1 -1
  188. package/lib/esm/types/libs/protocols/turbos/index.d.ts.map +1 -1
  189. package/lib/esm/types/libs/protocols/utils.d.ts +1 -2
  190. package/lib/esm/types/libs/protocols/utils.d.ts.map +1 -1
  191. package/lib/esm/types/libs/swapWithRoute.d.ts +3 -1
  192. package/lib/esm/types/libs/swapWithRoute.d.ts.map +1 -1
  193. package/lib/esm/types/types/aggregator.d.ts +36 -2
  194. package/lib/esm/types/types/aggregator.d.ts.map +1 -1
  195. package/lib/esm/types/types/tx.d.ts +36 -2
  196. package/lib/esm/types/types/tx.d.ts.map +1 -1
  197. package/lib/esm/types/utils/number.d.ts +1 -3
  198. package/lib/esm/types/utils/number.d.ts.map +1 -1
  199. package/lib/esm/types/utils/sui.d.ts +1 -1
  200. package/lib/esm/types/utils/sui.d.ts.map +1 -1
  201. package/lib/esm/utils/number.js +4 -6
  202. package/lib/esm/utils/sui.js +4 -3
  203. package/package.json +14 -15
  204. package/lib/cjs/libs/protocols/deepbook/index.js +0 -96
  205. package/lib/cjs/types/libs/protocols/deepbook/index.d.ts.map +0 -1
  206. package/lib/esm/libs/protocols/deepbook/index.js +0 -80
  207. package/lib/esm/types/libs/protocols/deepbook/index.d.ts.map +0 -1
@@ -1,16 +1,28 @@
1
1
  import { Transaction, } from "@mysten/sui/transactions";
2
- import BigNumber from "bignumber.js";
2
+ import { isValidSuiAddress, toBase64, toHex } from "@mysten/sui/utils";
3
+ import { Config } from "../../config";
4
+ import { _7K_CONFIG, _7K_PACKAGE_ID, _7K_VAULT } from "../../constants/_7k";
3
5
  import { getSplitCoinForTx } from "../../libs/getSplitCoinForTx";
4
6
  import { groupSwapRoutes } from "../../libs/groupSwapRoutes";
7
+ import { sponsorBluefinX } from "../../libs/protocols/bluefinx/client";
8
+ import { BluefinXTx } from "../../libs/protocols/bluefinx/types";
5
9
  import { swapWithRoute } from "../../libs/swapWithRoute";
6
- import { denormalizeTokenType } from "../../utils/token";
10
+ import { isBluefinXRouting, } from "../../types/aggregator";
7
11
  import { SuiUtils } from "../../utils/sui";
8
- import { _7K_CONFIG, _7K_PACKAGE_ID, _7K_VAULT } from "../../constants/_7k";
9
- import { isValidSuiAddress } from "@mysten/sui/utils";
12
+ import { denormalizeTokenType } from "../../utils/token";
10
13
  import { getConfig } from "./config";
11
- export const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: _commission, devInspect, extendTx, }) => {
14
+ export const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }) => {
15
+ const isBluefinX = isBluefinXRouting(quoteResponse);
16
+ const _commission = {
17
+ ...__commission,
18
+ // commission is ignored for bluefinx
19
+ commissionBps: isBluefinX ? 0 : __commission.commissionBps,
20
+ };
12
21
  const { tx: _tx, coinIn } = extendTx || {};
13
22
  let coinOut;
23
+ if (isBluefinX && devInspect) {
24
+ throw new Error("BluefinX tx is sponsored, skip devInspect");
25
+ }
14
26
  if (!accountAddress) {
15
27
  throw new Error("Sender address is required");
16
28
  }
@@ -26,12 +38,13 @@ export const buildTx = async ({ quoteResponse, accountAddress, slippage, commiss
26
38
  let coinData;
27
39
  if (coinIn) {
28
40
  coinData = tx.splitCoins(coinIn, splits);
29
- SuiUtils.transferOrDestroyZeroCoin(tx, quoteResponse.tokenIn, coinIn, accountAddress);
41
+ SuiUtils.collectDust(tx, quoteResponse.tokenIn, coinIn);
30
42
  }
31
43
  else {
32
- const { coinData: _data } = await getSplitCoinForTx(accountAddress, quoteResponse.swapAmountWithDecimal, splits, denormalizeTokenType(quoteResponse.tokenIn), tx, devInspect);
44
+ const { coinData: _data } = await getSplitCoinForTx(accountAddress, quoteResponse.swapAmountWithDecimal, splits, denormalizeTokenType(quoteResponse.tokenIn), tx, devInspect, isSponsored || isBluefinX);
33
45
  coinData = _data;
34
46
  }
47
+ const pythMap = await updatePythPriceFeedsIfAny(tx, quoteResponse);
35
48
  const coinObjects = [];
36
49
  const config = await getConfig();
37
50
  await Promise.all(routes.map(async (route, index) => {
@@ -42,6 +55,7 @@ export const buildTx = async ({ quoteResponse, accountAddress, slippage, commiss
42
55
  currentAccount: accountAddress,
43
56
  tx,
44
57
  config,
58
+ pythMap,
45
59
  });
46
60
  if (coinRes) {
47
61
  coinObjects.push(coinRes);
@@ -51,16 +65,11 @@ export const buildTx = async ({ quoteResponse, accountAddress, slippage, commiss
51
65
  const mergeCoin = coinObjects.length > 1
52
66
  ? SuiUtils.mergeCoins(coinObjects, tx)
53
67
  : coinObjects[0];
54
- coinOut = mergeCoin;
55
- const minReceived = new BigNumber(1)
56
- .minus(slippage)
57
- .multipliedBy(quoteResponse.returnAmountWithDecimal)
58
- .toFixed(0);
59
- const [partner] = tx.moveCall({
60
- target: "0x1::option::some",
61
- typeArguments: [`address`],
62
- arguments: [tx.pure.address(_commission.partner)],
63
- });
68
+ const returnAmountAfterCommission = (BigInt(10000 - _commission.commissionBps) *
69
+ BigInt(quoteResponse.returnAmountWithDecimal)) /
70
+ BigInt(10000);
71
+ const minReceived = (BigInt(1e9 - +slippage * 1e9) * BigInt(returnAmountAfterCommission)) /
72
+ BigInt(1e9);
64
73
  tx.moveCall({
65
74
  target: `${_7K_PACKAGE_ID}::settle::settle`,
66
75
  typeArguments: [quoteResponse.tokenIn, quoteResponse.tokenOut],
@@ -69,15 +78,67 @@ export const buildTx = async ({ quoteResponse, accountAddress, slippage, commiss
69
78
  tx.object(_7K_VAULT),
70
79
  tx.pure.u64(quoteResponse.swapAmountWithDecimal),
71
80
  mergeCoin,
72
- tx.pure.u64(minReceived),
73
- tx.pure.u64(quoteResponse.returnAmountWithDecimal),
74
- partner,
81
+ tx.pure.u64(minReceived), // minimum received
82
+ tx.pure.u64(returnAmountAfterCommission), // expected amount out
83
+ tx.pure.option("address", isValidSuiAddress(_commission.partner) ? _commission.partner : null),
75
84
  tx.pure.u64(_commission.commissionBps),
85
+ tx.pure.u64(0),
76
86
  ],
77
87
  });
78
88
  if (!extendTx) {
79
89
  tx.transferObjects([mergeCoin], tx.pure.address(accountAddress));
80
90
  }
91
+ else {
92
+ coinOut = mergeCoin;
93
+ }
94
+ }
95
+ if (isBluefinX) {
96
+ const extra = quoteResponse.swaps[0].extra;
97
+ if (extra.quoteExpiresAtUtcMillis < Date.now()) {
98
+ throw new Error("Quote expired");
99
+ }
100
+ tx.setSenderIfNotSet(accountAddress);
101
+ const bytes = await tx.build({
102
+ client: Config.getSuiClient(),
103
+ onlyTransactionKind: true,
104
+ });
105
+ const res = await sponsorBluefinX({
106
+ quoteId: extra.quoteId,
107
+ txBytes: toBase64(bytes),
108
+ sender: accountAddress,
109
+ });
110
+ if (!res.success) {
111
+ throw new Error("Sponsor failed");
112
+ }
113
+ return {
114
+ tx: new BluefinXTx(res.quoteId, res.data.txBytes),
115
+ coinOut,
116
+ };
81
117
  }
82
118
  return { tx, coinOut };
83
119
  };
120
+ const getPythPriceFeeds = (res) => {
121
+ const ids = [];
122
+ for (const s of res.swaps) {
123
+ for (const o of s.extra?.oracles || []) {
124
+ const bytes = o.Pyth?.price_identifier?.bytes;
125
+ if (bytes) {
126
+ ids.push("0x" + toHex(Uint8Array.from(bytes)));
127
+ }
128
+ }
129
+ }
130
+ return ids;
131
+ };
132
+ const updatePythPriceFeedsIfAny = async (tx, quoteResponse) => {
133
+ // update oracles price if any
134
+ const pythMap = {};
135
+ const pythIds = getPythPriceFeeds(quoteResponse);
136
+ if (pythIds.length > 0) {
137
+ const prices = await Config.getPythConnection().getPriceFeedsUpdateData(pythIds);
138
+ const ids = await Config.getPythClient().updatePriceFeeds(tx, prices, pythIds);
139
+ pythIds.map((id, index) => {
140
+ pythMap[id] = ids[index];
141
+ });
142
+ }
143
+ return pythMap;
144
+ };
@@ -1,7 +1,5 @@
1
1
  import { fetchClient } from "../../config/fetchClient";
2
2
  import { API_ENDPOINTS } from "../../constants/apiEndpoints";
3
- let config = null;
4
- let configTs = 0;
5
3
  export const DEFAULT_CONFIG = {
6
4
  aftermath: {
7
5
  name: "Aftermath",
@@ -17,6 +15,11 @@ export const DEFAULT_CONFIG = {
17
15
  package: "0x6c796c3ab3421a68158e0df18e4657b2827b1f8fed5ed4b82dba9c935988711b",
18
16
  globalConfig: "0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
19
17
  },
18
+ bluefinx: {
19
+ name: "BluefinX",
20
+ package: "0xf8870f988ab09be7c5820a856bd5e9da84fc7192e095a7a8829919293b00a36c",
21
+ globalConfig: "0xc6b29a60c3924776bedc78df72c127ea52b86aeb655432979a38f13d742dedaa",
22
+ },
20
23
  bluemove: {
21
24
  name: "Bluemove",
22
25
  package: "0x08cd33481587d4c4612865b164796d937df13747d8c763b8a178c87e3244498f",
@@ -27,10 +30,6 @@ export const DEFAULT_CONFIG = {
27
30
  package: "0x6f5e582ede61fe5395b50c4a449ec11479a54d7ff8e0158247adfda60d98970b",
28
31
  globalConfig: "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",
29
32
  },
30
- deepbook: {
31
- name: "Deepbook",
32
- package: "0xdee9",
33
- },
34
33
  deepbook_v3: {
35
34
  name: "Deepbook V3",
36
35
  package: "",
@@ -83,13 +82,25 @@ export const DEFAULT_CONFIG = {
83
82
  name: "Steamm",
84
83
  package: "0x4fb1cf45dffd6230305f1d269dd1816678cc8e3ba0b747a813a556921219f261",
85
84
  script: "0x13bfc09cfc1bd922d3aa53fcf7b2cd510727ee65068ce136e2ebd5f3b213fdd2",
85
+ oracle: "0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b",
86
86
  },
87
87
  magma: {
88
88
  name: "Magma",
89
89
  package: "0x951d48bece7f6c2a3f4ba0b5791ba823c491e504feb4136497ee51331208ac33",
90
90
  globalConfig: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
91
91
  },
92
+ haedal_pmm: {
93
+ name: "Haedal PMM",
94
+ package: "0xa0e3b011012b80af4957afa30e556486eb3da0a7d96eeb733cf16ccd3aec32e0",
95
+ },
96
+ momentum: {
97
+ name: "Momentum",
98
+ package: "0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860",
99
+ version: "0x2375a0b1ec12010aaea3b2545acfa2ad34cfbba03ce4b59f4c39e1e25eed1b2a",
100
+ },
92
101
  };
102
+ let config = DEFAULT_CONFIG;
103
+ let configTs = 0;
93
104
  export async function getConfig() {
94
105
  const ttl = 60;
95
106
  if (config && Date.now() - configTs < ttl * 1000) {
@@ -98,9 +109,9 @@ export async function getConfig() {
98
109
  try {
99
110
  const response = await fetchClient(`${API_ENDPOINTS.MAIN}/config`);
100
111
  const quoteResponse = (await response.json());
101
- config = quoteResponse;
112
+ config = { ...config, ...quoteResponse };
102
113
  configTs = Date.now();
103
- return quoteResponse;
114
+ return config;
104
115
  }
105
116
  catch (_) {
106
117
  return DEFAULT_CONFIG;
@@ -1,12 +1,16 @@
1
- import BigNumber from "bignumber.js";
2
1
  import { SUI_DECIMALS } from "@mysten/sui/utils";
3
- import { buildTx } from "./buildTx";
2
+ import { Config } from "../../config";
3
+ import { isBluefinXRouting } from "../../types/aggregator";
4
4
  import { formatBalance } from "../../utils/number";
5
5
  import { getSuiPrice } from "../prices";
6
- import { Config } from "../../config";
6
+ import { buildTx } from "./buildTx";
7
+ import { BluefinXTx } from "../../libs/protocols/bluefinx/types";
7
8
  export async function estimateGasFee({ quoteResponse, accountAddress, slippage, suiPrice: _suiPrice, extendTx, commission, }) {
8
9
  if (!accountAddress)
9
10
  return 0;
11
+ // BluefinX is sponsored, no need to estimate gas fee
12
+ if (!accountAddress || isBluefinXRouting(quoteResponse))
13
+ return 0;
10
14
  const result = await buildTx({
11
15
  extendTx,
12
16
  quoteResponse,
@@ -19,7 +23,7 @@ export async function estimateGasFee({ quoteResponse, accountAddress, slippage,
19
23
  return undefined;
20
24
  });
21
25
  const { tx } = result || {};
22
- if (!tx)
26
+ if (!tx || tx instanceof BluefinXTx)
23
27
  return 0;
24
28
  const suiPrice = _suiPrice || (await getSuiPrice());
25
29
  const suiDecimals = SUI_DECIMALS;
@@ -29,9 +33,9 @@ export async function estimateGasFee({ quoteResponse, accountAddress, slippage,
29
33
  });
30
34
  if (status.status !== "success")
31
35
  return 0;
32
- const fee = new BigNumber(gasUsed.computationCost)
33
- .plus(gasUsed.storageCost)
34
- .minus(gasUsed.storageRebate);
35
- const feeUsd = new BigNumber(suiPrice).multipliedBy(formatBalance(fee, suiDecimals));
36
- return feeUsd.toNumber();
36
+ const fee = BigInt(gasUsed.computationCost) +
37
+ BigInt(gasUsed.storageCost) -
38
+ BigInt(gasUsed.storageRebate);
39
+ const feeUsd = Number(suiPrice) * Number(formatBalance(fee, suiDecimals));
40
+ return feeUsd;
37
41
  }
@@ -0,0 +1,48 @@
1
+ import { Config } from "../../config";
2
+ import { executeBluefinTx } from "../../libs/protocols/bluefinx/client";
3
+ import { BluefinXTx } from "../../libs/protocols/bluefinx/types";
4
+ /**
5
+ * Execute a transaction after it is signed
6
+ *
7
+ * Automatically handle BluefinX transaction execution if needed
8
+ * @example
9
+ * ```ts
10
+ * const { mutateAsync: signTransaction } = useSignTransaction();
11
+ * const quoteResponse = await getQuote(...quoteParams);
12
+ * const { tx } = await buildTx(...buildTxParams);
13
+ * const {signature, bytes} = await signTransaction({
14
+ * transaction: tx instanceof BluefinXTx ? tx.txBytes : tx,
15
+ * });
16
+ * const res = await executeTx(tx, signature, bytes);
17
+ * ```
18
+ * @param tx - AggregatorTx - received from `buildTx`
19
+ * @param signature - User signature after signing the transaction
20
+ * @param signedTxBytes - Signed transaction bytes after signing the transaction
21
+ * @param options - Options for the transaction
22
+ * @returns `SuiTransactionBlockResponse`
23
+ */
24
+ export const executeTx = async (tx, signature, signedTxBytes, options) => {
25
+ const isBluefinTx = tx instanceof BluefinXTx;
26
+ const client = Config.getSuiClient();
27
+ let res;
28
+ if (isBluefinTx) {
29
+ try {
30
+ const result = await executeBluefinTx(tx, signature);
31
+ res = await client.waitForTransaction({
32
+ digest: result.txDigest,
33
+ options,
34
+ });
35
+ }
36
+ catch (e) {
37
+ throw Error(`Could not retrieve BluefinX transaction with quoteId: ${tx.quoteId} ${e}`);
38
+ }
39
+ }
40
+ else {
41
+ res = await client.executeTransactionBlock({
42
+ transactionBlock: signedTxBytes,
43
+ signature,
44
+ options,
45
+ });
46
+ }
47
+ return res;
48
+ };
@@ -1,6 +1,7 @@
1
1
  import { normalizeStructTag, normalizeSuiObjectId } from "@mysten/sui/utils";
2
- import { API_ENDPOINTS } from "../../constants/apiEndpoints";
3
2
  import { fetchClient } from "../../config/fetchClient";
3
+ import { API_ENDPOINTS } from "../../constants/apiEndpoints";
4
+ import { isBluefinXRouting } from "../../types/aggregator";
4
5
  export const DEFAULT_SOURCES = [
5
6
  "suiswap",
6
7
  "turbos",
@@ -9,7 +10,6 @@ export const DEFAULT_SOURCES = [
9
10
  "kriya",
10
11
  "kriya_v3",
11
12
  "aftermath",
12
- "deepbook",
13
13
  "deepbook_v3",
14
14
  "flowx",
15
15
  "flowx_v3",
@@ -18,9 +18,12 @@ export const DEFAULT_SOURCES = [
18
18
  "obric",
19
19
  "stsui",
20
20
  "steamm",
21
+ "steamm_oracle_quoter",
21
22
  "magma",
23
+ "haedal_pmm",
24
+ "momentum",
22
25
  ];
23
- export async function getQuote({ tokenIn, tokenOut, amountIn, sources = DEFAULT_SOURCES, targetPools, excludedPools, }) {
26
+ export async function getQuote({ tokenIn, tokenOut, amountIn, sources = DEFAULT_SOURCES, commissionBps, targetPools, excludedPools, taker, }) {
24
27
  const params = new URLSearchParams({
25
28
  amount: amountIn,
26
29
  from: normalizeStructTag(tokenIn),
@@ -33,10 +36,28 @@ export async function getQuote({ tokenIn, tokenOut, amountIn, sources = DEFAULT_
33
36
  if (excludedPools?.length) {
34
37
  params.append("excluded_pools", excludedPools.map((v) => normalizeSuiObjectId(v)).join(","));
35
38
  }
39
+ if (taker) {
40
+ params.append("taker", taker);
41
+ }
36
42
  const response = await fetchClient(`${API_ENDPOINTS.MAIN}/quote?${params}`);
37
43
  if (!response.ok) {
38
44
  throw new Error("Failed to fetch aggregator quote");
39
45
  }
40
46
  const quoteResponse = (await response.json());
47
+ computeReturnAmountAfterCommission(quoteResponse, commissionBps);
41
48
  return quoteResponse;
42
49
  }
50
+ const computeReturnAmountAfterCommission = (quoteResponse, commissionBps) => {
51
+ const _commissionBps = isBluefinXRouting(quoteResponse) ? 0 : commissionBps;
52
+ if (quoteResponse.returnAmount && +quoteResponse.returnAmount > 0) {
53
+ quoteResponse.returnAmountAfterCommissionWithDecimal = ((BigInt(quoteResponse.returnAmountWithDecimal || 0) *
54
+ BigInt(10_000 - (_commissionBps ?? 0))) /
55
+ BigInt(10_000)).toString(10);
56
+ const exp = Math.round(+quoteResponse.returnAmountWithDecimal / +quoteResponse.returnAmount);
57
+ quoteResponse.returnAmountAfterCommission = (+quoteResponse.returnAmountAfterCommissionWithDecimal / exp).toString(10);
58
+ }
59
+ else {
60
+ quoteResponse.returnAmountAfterCommission = "";
61
+ quoteResponse.returnAmountAfterCommissionWithDecimal = "";
62
+ }
63
+ };
@@ -1,4 +1,5 @@
1
1
  export * from "./buildTx";
2
2
  export * from "./estimateGasFee";
3
+ export * from "./executeTx";
3
4
  export * from "./getQuote";
4
5
  export * from "./getSwapHistory";
package/lib/esm/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  export * from "./types/aggregator";
2
2
  import { Config } from "./config";
3
- import { getTokenPrice, getTokenPrices, getSuiPrice } from "./features/prices";
4
- import { buildTx, getQuote, estimateGasFee, getSwapHistory, } from "./features/swap";
5
- import { placeLimitOrder, getOpenLimitOrders, cancelLimitOrder, claimExpiredLimitOrder, getClosedLimitOrders, placeDcaOrder, getOpenDcaOrders, cancelDcaOrder, getClosedDcaOrders, getDcaOrderExecutions, } from "./features/limitDca";
3
+ import { getSuiPrice, getTokenPrice, getTokenPrices } from "./features/prices";
4
+ import { executeBluefinTx } from "./libs/protocols/bluefinx/client";
5
+ import { buildTx, estimateGasFee, executeTx, getQuote, getSwapHistory, DEFAULT_SOURCES, } from "./features/swap";
6
+ import { cancelDcaOrder, cancelLimitOrder, claimExpiredLimitOrder, getClosedDcaOrders, getClosedLimitOrders, getDcaOrderExecutions, getOpenDcaOrders, getOpenLimitOrders, placeDcaOrder, placeLimitOrder, } from "./features/limitDca";
6
7
  // avoid breaking changes
7
8
  const getSuiClient = Config.getSuiClient;
8
9
  const setSuiClient = Config.setSuiClient;
@@ -14,7 +15,7 @@ getSuiClient, setSuiClient,
14
15
  // prices
15
16
  getTokenPrice, getTokenPrices, getSuiPrice,
16
17
  // swap
17
- getQuote, estimateGasFee, buildTx, getSwapHistory,
18
+ getQuote, estimateGasFee, buildTx, getSwapHistory, executeTx, executeBluefinTx, DEFAULT_SOURCES,
18
19
  // limit order
19
20
  placeLimitOrder, getOpenLimitOrders, cancelLimitOrder, claimExpiredLimitOrder, getClosedLimitOrders,
20
21
  // dca
@@ -34,6 +35,9 @@ export default {
34
35
  estimateGasFee,
35
36
  buildTx,
36
37
  getSwapHistory,
38
+ executeTx,
39
+ executeBluefinTx,
40
+ DEFAULT_SOURCES,
37
41
  // limit order
38
42
  placeLimitOrder,
39
43
  getOpenLimitOrders,
@@ -1,15 +1,15 @@
1
- import BigNumber from "bignumber.js";
2
1
  import { Config } from "../config";
3
2
  const orderByKey = (array, key, sortBy) => {
4
3
  if (!array?.length) {
5
4
  return;
6
5
  }
7
6
  let swapped;
8
- const compareFunctionName = sortBy === "desc" ? "isLessThan" : "isGreaterThan";
9
7
  do {
10
8
  swapped = false;
11
9
  for (let i = 0; i < array.length - 1; i++) {
12
- if (new BigNumber(array[i][key])[compareFunctionName](array[i + 1][key])) {
10
+ const a = BigInt(array[i][key]);
11
+ const b = BigInt(array[i + 1][key]);
12
+ if (sortBy === "desc" ? a < b : a > b) {
13
13
  const temp = array[i];
14
14
  array[i] = array[i + 1];
15
15
  array[i + 1] = temp;
@@ -45,15 +45,15 @@ export const getCoinOjectIdsByAmount = async (address, amount, coinType) => {
45
45
  ...item,
46
46
  balance: item.balance,
47
47
  };
48
- }), "balance", "desc");
48
+ }), "balance", "desc") ?? [];
49
49
  let balance = "0";
50
50
  const objectIds = [];
51
51
  const objectCoins = [];
52
- for (const coin of coinObj ?? []) {
53
- balance = new BigNumber(coin.balance).plus(balance).toFixed();
52
+ for (const coin of coinObj) {
53
+ balance = (BigInt(coin.balance) + BigInt(balance)).toString(10);
54
54
  objectIds.push(coin.coinObjectId);
55
55
  objectCoins.push(coin);
56
- if (new BigNumber(balance).isGreaterThanOrEqualTo(amount)) {
56
+ if (BigInt(balance) >= BigInt(amount)) {
57
57
  break;
58
58
  }
59
59
  }
@@ -1,11 +1,13 @@
1
1
  import { Transaction } from "@mysten/sui/transactions";
2
- import { getCoinOjectIdsByAmount } from "./getCoinOjectIdsByAmount";
2
+ import { normalizeStructTag } from "@mysten/sui/utils";
3
3
  import { SUI_TYPE } from "../constants/tokens";
4
- export const getSplitCoinForTx = async (account, amount, splits, coinType, inheritTx, inspecTransaction) => {
4
+ import { getCoinOjectIdsByAmount } from "./getCoinOjectIdsByAmount";
5
+ export const getSplitCoinForTx = async (account, amount, splits, coinType, inheritTx, inspecTransaction, isSponsored = false) => {
5
6
  const tx = inheritTx ?? new Transaction();
6
7
  const { objectIds } = await getCoinOjectIdsByAmount(account, amount, coinType);
7
8
  const coinObjectId = objectIds[0];
8
- if (coinType === SUI_TYPE) {
9
+ if (normalizeStructTag(coinType) === normalizeStructTag(SUI_TYPE) &&
10
+ !isSponsored) {
9
11
  let coin;
10
12
  if (inspecTransaction) {
11
13
  if (objectIds.length > 1) {
@@ -1,4 +1,3 @@
1
- import BigNumber from "bignumber.js";
2
1
  import { denormalizeTokenType } from "../utils/token";
3
2
  export function groupSwapRoutes(quoteResponse) {
4
3
  if (!quoteResponse.routes || !quoteResponse.swaps) {
@@ -12,7 +11,7 @@ export function groupSwapRoutes(quoteResponse) {
12
11
  const item = items[i];
13
12
  currentGroup.push(item);
14
13
  const nextItem = items[i + 1];
15
- if (!nextItem || new BigNumber(nextItem.amount).gt(0)) {
14
+ if (!nextItem || BigInt(nextItem.amount) > 0n) {
16
15
  groupedItems.push(currentGroup);
17
16
  currentGroup = [];
18
17
  }
@@ -5,11 +5,13 @@ export class BaseContract {
5
5
  inputCoinObject;
6
6
  currentAccount;
7
7
  config;
8
- constructor({ swapInfo, inputCoinObject, currentAccount, config, }) {
8
+ pythMap;
9
+ constructor({ swapInfo, inputCoinObject, currentAccount, config, pythMap, }) {
9
10
  this.swapInfo = swapInfo;
10
11
  this.inputCoinObject = inputCoinObject;
11
12
  this.currentAccount = currentAccount;
12
13
  this.config = config;
14
+ this.pythMap = pythMap;
13
15
  }
14
16
  getInputCoinValue(tx) {
15
17
  return SuiUtils.getCoinValue(this.swapInfo.assetIn, this.inputCoinObject, tx);
@@ -17,4 +19,11 @@ export class BaseContract {
17
19
  getTypeParams() {
18
20
  return parseStructTag(this.swapInfo.extra?.poolStructTag || "").typeParams.map(normalizeStructTag);
19
21
  }
22
+ get extra() {
23
+ const extra = this.swapInfo.extra;
24
+ if (!extra) {
25
+ throw new Error(`Invalid extra info for getExtra`);
26
+ }
27
+ return extra;
28
+ }
20
29
  }
@@ -1,7 +1,6 @@
1
1
  import { BaseContract } from "../base";
2
2
  import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
3
3
  import { getDefaultSqrtPriceLimit } from "../utils";
4
- import BN from "bn.js";
5
4
  import { SuiUtils } from "../../../utils/sui";
6
5
  export class BluefinContract extends BaseContract {
7
6
  async swap(tx) {
@@ -24,14 +23,12 @@ export class BluefinContract extends BaseContract {
24
23
  tx.pure.bool(true),
25
24
  amountIn,
26
25
  tx.pure.u64(0),
27
- tx.pure.u128(getDefaultSqrtPriceLimit(swapXtoY)
28
- .add(swapXtoY ? new BN(1) : new BN(-1))
29
- .toString(10)),
26
+ tx.pure.u128(getDefaultSqrtPriceLimit(swapXtoY) + (swapXtoY ? 1n : -1n)),
30
27
  ],
31
28
  });
32
29
  const coinOutX = SuiUtils.coinFromBalance(tx, coinX.address, balanceOutX);
33
30
  const coinOutY = SuiUtils.coinFromBalance(tx, coinY.address, balanceOutY);
34
- SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, swapXtoY ? coinOutX : coinOutY, this.currentAccount);
31
+ SuiUtils.collectDust(tx, this.swapInfo.assetIn, swapXtoY ? coinOutX : coinOutY);
35
32
  return swapXtoY ? coinOutY : coinOutX;
36
33
  }
37
34
  }
@@ -0,0 +1,30 @@
1
+ import { API_ENDPOINTS } from "../../../constants/apiEndpoints";
2
+ const request = async (path, body) => {
3
+ const res = await fetch(`${API_ENDPOINTS.MAIN}/${path}`, {
4
+ method: "POST",
5
+ body: JSON.stringify(body),
6
+ headers: {
7
+ "Content-Type": "application/json",
8
+ },
9
+ });
10
+ return res.json();
11
+ };
12
+ export const sponsorBluefinX = async (body) => {
13
+ return await request("bluefinx/sponsor", body);
14
+ };
15
+ /**
16
+ * Request BluefinX for signing sponsored tx and execute it
17
+ *
18
+ * @Warning
19
+ * User must use this function to execute BluefinX tx, otherwise the tx will be rejected by BluefinX contract
20
+ * @param tx - BluefinX tx which is generated by `buildTx`
21
+ * @param signature - user signature after signing the transaction
22
+ * @returns `SwapResponse`
23
+ */
24
+ export const executeBluefinTx = async (tx, signature) => {
25
+ return await request("bluefinx/swap", {
26
+ quoteId: tx.quoteId,
27
+ txBytes: tx.txBytes,
28
+ signature,
29
+ });
30
+ };
@@ -0,0 +1,44 @@
1
+ import { bcs } from "@mysten/sui/bcs";
2
+ import { fromBase64, normalizeStructTag, SUI_CLOCK_OBJECT_ID, } from "@mysten/sui/utils";
3
+ import { SuiUtils } from "../../../utils/sui";
4
+ import { BaseContract } from "../base";
5
+ const BcsQuote = bcs.struct("Quote", {
6
+ vault: bcs.Address,
7
+ id: bcs.string(),
8
+ taker: bcs.Address,
9
+ token_in_amount: bcs.u64(),
10
+ token_out_amount: bcs.u64(),
11
+ token_in_type: bcs.string(),
12
+ token_out_type: bcs.string(),
13
+ expires_at: bcs.u64(),
14
+ created_at: bcs.u64(),
15
+ });
16
+ export class BluefinXContract extends BaseContract {
17
+ async swap(tx) {
18
+ const extra = this.extra;
19
+ const quoteBytes = BcsQuote.serialize({
20
+ vault: extra.vault,
21
+ id: extra.quoteId,
22
+ taker: extra.taker,
23
+ token_in_amount: this.swapInfo.amount,
24
+ token_out_amount: this.swapInfo.returnAmount,
25
+ token_in_type: normalizeStructTag(this.swapInfo.assetIn).slice(2),
26
+ token_out_type: normalizeStructTag(this.swapInfo.assetOut).slice(2),
27
+ expires_at: extra.quoteExpiresAtUtcMillis,
28
+ created_at: extra.createdAtUtcMillis,
29
+ }).toBytes();
30
+ const [out] = tx.moveCall({
31
+ arguments: [
32
+ tx.object(SUI_CLOCK_OBJECT_ID),
33
+ tx.object(extra.vault),
34
+ tx.object(this.config.bluefinx.globalConfig),
35
+ tx.pure.vector("u8", Array.from(quoteBytes)),
36
+ tx.pure.vector("u8", Array.from(fromBase64(extra.signature))),
37
+ SuiUtils.coinIntoBalance(tx, this.swapInfo.assetIn, this.inputCoinObject),
38
+ ],
39
+ target: `${this.config.bluefinx.package}::vault::swap`,
40
+ typeArguments: [this.swapInfo.assetIn, this.swapInfo.assetOut],
41
+ });
42
+ return SuiUtils.coinFromBalance(tx, this.swapInfo.assetOut, out);
43
+ }
44
+ }
@@ -0,0 +1,8 @@
1
+ export class BluefinXTx {
2
+ quoteId;
3
+ txBytes;
4
+ constructor(quoteId, txBytes) {
5
+ this.quoteId = quoteId;
6
+ this.txBytes = txBytes;
7
+ }
8
+ }
@@ -34,7 +34,7 @@ export class CetusContract extends BaseContract {
34
34
  tx.object(SUI_CLOCK_OBJECT_ID),
35
35
  ],
36
36
  });
37
- SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, this.swapInfo.swapXtoY ? receiveA : receiveB, this.currentAccount);
37
+ SuiUtils.collectDust(tx, this.swapInfo.assetIn, this.swapInfo.swapXtoY ? receiveA : receiveB);
38
38
  return this.swapInfo.swapXtoY ? receiveB : receiveA;
39
39
  }
40
40
  }
@@ -20,7 +20,7 @@ export class SponsoredDeepBookV3Contract extends BaseContract {
20
20
  });
21
21
  const coinIn = swapXtoY ? base : quote;
22
22
  const coinOut = swapXtoY ? quote : base;
23
- SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, coinIn, this.currentAccount);
23
+ SuiUtils.collectDust(tx, this.swapInfo.assetIn, coinIn);
24
24
  return coinOut;
25
25
  }
26
26
  }
@@ -1,7 +1,6 @@
1
1
  import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
2
2
  import { BaseContract } from "../base";
3
3
  import { getDefaultSqrtPriceLimit } from "../utils";
4
- import { BN } from "bn.js";
5
4
  export class FlowxV3Contract extends BaseContract {
6
5
  async swap(tx) {
7
6
  const [coinX, coinY] = this.swapInfo.pool.allTokens;
@@ -22,9 +21,7 @@ export class FlowxV3Contract extends BaseContract {
22
21
  tx.pure.u64(swapFeeRate), // swap fee rate to lookup pool in the registry
23
22
  this.inputCoinObject,
24
23
  tx.pure.u64(0), // min amount out
25
- tx.pure.u128(getDefaultSqrtPriceLimit(swapXtoY)
26
- .add(swapXtoY ? new BN(1) : new BN(-1))
27
- .toString(10)), // sqrt price limit
24
+ tx.pure.u128(getDefaultSqrtPriceLimit(swapXtoY) + (swapXtoY ? 1n : -1n)), // sqrt price limit
28
25
  tx.pure.u64("18446744073709551615"), // u64 max value
29
26
  tx.object(config.version),
30
27
  tx.object(SUI_CLOCK_OBJECT_ID),