@7kprotocol/sdk-ts 2.4.1 → 2.4.2-beta.1

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 (205) 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.map +1 -1
  74. package/lib/cjs/types/libs/groupSwapRoutes.d.ts.map +1 -1
  75. package/lib/cjs/types/libs/protocols/base.d.ts +6 -2
  76. package/lib/cjs/types/libs/protocols/base.d.ts.map +1 -1
  77. package/lib/cjs/types/libs/protocols/bluefin/index.d.ts.map +1 -1
  78. package/lib/cjs/types/libs/protocols/bluefinx/client.d.ts +13 -0
  79. package/lib/cjs/types/libs/protocols/bluefinx/client.d.ts.map +1 -0
  80. package/lib/cjs/types/libs/protocols/bluefinx/index.d.ts +17 -0
  81. package/lib/cjs/types/libs/protocols/bluefinx/index.d.ts.map +1 -0
  82. package/lib/cjs/types/libs/protocols/bluefinx/types.d.ts +34 -0
  83. package/lib/cjs/types/libs/protocols/bluefinx/types.d.ts.map +1 -0
  84. package/lib/cjs/types/libs/protocols/cetus/index.d.ts.map +1 -1
  85. package/lib/cjs/types/libs/protocols/deepbookV3/sponsored.d.ts.map +1 -1
  86. package/lib/cjs/types/libs/protocols/flowxV3/index.d.ts.map +1 -1
  87. package/lib/{esm/types/libs/protocols/deepbook → cjs/types/libs/protocols/haedal_pmm}/index.d.ts +1 -3
  88. package/lib/cjs/types/libs/protocols/haedal_pmm/index.d.ts.map +1 -0
  89. package/lib/cjs/types/libs/protocols/index.d.ts +7 -2
  90. package/lib/cjs/types/libs/protocols/index.d.ts.map +1 -1
  91. package/lib/cjs/types/libs/protocols/magma/index.d.ts.map +1 -1
  92. package/lib/cjs/types/libs/protocols/{deepbook → momentum}/index.d.ts +1 -3
  93. package/lib/cjs/types/libs/protocols/momentum/index.d.ts.map +1 -0
  94. package/lib/cjs/types/libs/protocols/steamm/index.d.ts +13 -2
  95. package/lib/cjs/types/libs/protocols/steamm/index.d.ts.map +1 -1
  96. package/lib/cjs/types/libs/protocols/suiswap/index.d.ts.map +1 -1
  97. package/lib/cjs/types/libs/protocols/turbos/index.d.ts.map +1 -1
  98. package/lib/cjs/types/libs/protocols/utils.d.ts +1 -2
  99. package/lib/cjs/types/libs/protocols/utils.d.ts.map +1 -1
  100. package/lib/cjs/types/libs/swapWithRoute.d.ts +3 -1
  101. package/lib/cjs/types/libs/swapWithRoute.d.ts.map +1 -1
  102. package/lib/cjs/types/types/aggregator.d.ts +36 -2
  103. package/lib/cjs/types/types/aggregator.d.ts.map +1 -1
  104. package/lib/cjs/types/types/tx.d.ts +1 -2
  105. package/lib/cjs/types/types/tx.d.ts.map +1 -1
  106. package/lib/cjs/types/utils/number.d.ts +1 -3
  107. package/lib/cjs/types/utils/number.d.ts.map +1 -1
  108. package/lib/cjs/types/utils/sui.d.ts +1 -1
  109. package/lib/cjs/types/utils/sui.d.ts.map +1 -1
  110. package/lib/cjs/utils/number.js +4 -10
  111. package/lib/cjs/utils/sui.js +71 -80
  112. package/lib/esm/config/index.js +22 -0
  113. package/lib/esm/constants/_7k.js +6 -3
  114. package/lib/esm/features/limitDca/constants.js +1 -2
  115. package/lib/esm/features/swap/buildTx.js +81 -20
  116. package/lib/esm/features/swap/config.js +19 -8
  117. package/lib/esm/features/swap/estimateGasFee.js +13 -9
  118. package/lib/esm/features/swap/executeTx.js +48 -0
  119. package/lib/esm/features/swap/getQuote.js +24 -3
  120. package/lib/esm/features/swap/index.js +1 -0
  121. package/lib/esm/index.mjs +8 -4
  122. package/lib/esm/libs/getCoinOjectIdsByAmount.js +7 -7
  123. package/lib/esm/libs/getSplitCoinForTx.js +4 -2
  124. package/lib/esm/libs/groupSwapRoutes.js +1 -2
  125. package/lib/esm/libs/protocols/base.js +10 -1
  126. package/lib/esm/libs/protocols/bluefin/index.js +2 -5
  127. package/lib/esm/libs/protocols/bluefinx/client.js +30 -0
  128. package/lib/esm/libs/protocols/bluefinx/index.js +44 -0
  129. package/lib/esm/libs/protocols/bluefinx/types.js +8 -0
  130. package/lib/esm/libs/protocols/cetus/index.js +1 -1
  131. package/lib/esm/libs/protocols/deepbookV3/sponsored.js +1 -1
  132. package/lib/esm/libs/protocols/flowxV3/index.js +1 -4
  133. package/lib/esm/libs/protocols/haedal_pmm/index.js +29 -0
  134. package/lib/esm/libs/protocols/index.js +7 -2
  135. package/lib/esm/libs/protocols/magma/index.js +1 -2
  136. package/lib/esm/libs/protocols/momentum/index.js +45 -0
  137. package/lib/esm/libs/protocols/steamm/index.js +58 -48
  138. package/lib/esm/libs/protocols/suiswap/index.js +1 -1
  139. package/lib/esm/libs/protocols/turbos/index.js +2 -6
  140. package/lib/esm/libs/protocols/utils.js +1 -2
  141. package/lib/esm/libs/swapWithRoute.js +2 -1
  142. package/lib/esm/types/aggregator.js +14 -1
  143. package/lib/esm/types/config/index.d.ts +9 -0
  144. package/lib/esm/types/config/index.d.ts.map +1 -1
  145. package/lib/esm/types/constants/_7k.d.ts +3 -3
  146. package/lib/esm/types/constants/_7k.d.ts.map +1 -1
  147. package/lib/esm/types/features/limitDca/constants.d.ts +1 -2
  148. package/lib/esm/types/features/limitDca/constants.d.ts.map +1 -1
  149. package/lib/esm/types/features/swap/buildTx.d.ts +2 -5
  150. package/lib/esm/types/features/swap/buildTx.d.ts.map +1 -1
  151. package/lib/esm/types/features/swap/config.d.ts.map +1 -1
  152. package/lib/esm/types/features/swap/estimateGasFee.d.ts.map +1 -1
  153. package/lib/esm/types/features/swap/executeTx.d.ts +24 -0
  154. package/lib/esm/types/features/swap/executeTx.d.ts.map +1 -0
  155. package/lib/esm/types/features/swap/getQuote.d.ts +8 -1
  156. package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
  157. package/lib/esm/types/features/swap/index.d.ts +1 -0
  158. package/lib/esm/types/features/swap/index.d.ts.map +1 -1
  159. package/lib/esm/types/index.d.ts +13 -8
  160. package/lib/esm/types/index.d.ts.map +1 -1
  161. package/lib/esm/types/libs/getCoinOjectIdsByAmount.d.ts.map +1 -1
  162. package/lib/esm/types/libs/getSplitCoinForTx.d.ts.map +1 -1
  163. package/lib/esm/types/libs/groupSwapRoutes.d.ts.map +1 -1
  164. package/lib/esm/types/libs/protocols/base.d.ts +6 -2
  165. package/lib/esm/types/libs/protocols/base.d.ts.map +1 -1
  166. package/lib/esm/types/libs/protocols/bluefin/index.d.ts.map +1 -1
  167. package/lib/esm/types/libs/protocols/bluefinx/client.d.ts +13 -0
  168. package/lib/esm/types/libs/protocols/bluefinx/client.d.ts.map +1 -0
  169. package/lib/esm/types/libs/protocols/bluefinx/index.d.ts +17 -0
  170. package/lib/esm/types/libs/protocols/bluefinx/index.d.ts.map +1 -0
  171. package/lib/esm/types/libs/protocols/bluefinx/types.d.ts +34 -0
  172. package/lib/esm/types/libs/protocols/bluefinx/types.d.ts.map +1 -0
  173. package/lib/esm/types/libs/protocols/cetus/index.d.ts.map +1 -1
  174. package/lib/esm/types/libs/protocols/deepbookV3/sponsored.d.ts.map +1 -1
  175. package/lib/esm/types/libs/protocols/flowxV3/index.d.ts.map +1 -1
  176. package/lib/esm/types/libs/protocols/haedal_pmm/index.d.ts +9 -0
  177. package/lib/esm/types/libs/protocols/haedal_pmm/index.d.ts.map +1 -0
  178. package/lib/esm/types/libs/protocols/index.d.ts +7 -2
  179. package/lib/esm/types/libs/protocols/index.d.ts.map +1 -1
  180. package/lib/esm/types/libs/protocols/magma/index.d.ts.map +1 -1
  181. package/lib/esm/types/libs/protocols/momentum/index.d.ts +9 -0
  182. package/lib/esm/types/libs/protocols/momentum/index.d.ts.map +1 -0
  183. package/lib/esm/types/libs/protocols/steamm/index.d.ts +13 -2
  184. package/lib/esm/types/libs/protocols/steamm/index.d.ts.map +1 -1
  185. package/lib/esm/types/libs/protocols/suiswap/index.d.ts.map +1 -1
  186. package/lib/esm/types/libs/protocols/turbos/index.d.ts.map +1 -1
  187. package/lib/esm/types/libs/protocols/utils.d.ts +1 -2
  188. package/lib/esm/types/libs/protocols/utils.d.ts.map +1 -1
  189. package/lib/esm/types/libs/swapWithRoute.d.ts +3 -1
  190. package/lib/esm/types/libs/swapWithRoute.d.ts.map +1 -1
  191. package/lib/esm/types/types/aggregator.d.ts +36 -2
  192. package/lib/esm/types/types/aggregator.d.ts.map +1 -1
  193. package/lib/esm/types/types/tx.d.ts +1 -2
  194. package/lib/esm/types/types/tx.d.ts.map +1 -1
  195. package/lib/esm/types/utils/number.d.ts +1 -3
  196. package/lib/esm/types/utils/number.d.ts.map +1 -1
  197. package/lib/esm/types/utils/sui.d.ts +1 -1
  198. package/lib/esm/types/utils/sui.d.ts.map +1 -1
  199. package/lib/esm/utils/number.js +4 -6
  200. package/lib/esm/utils/sui.js +4 -3
  201. package/package.json +14 -15
  202. package/lib/cjs/libs/protocols/deepbook/index.js +0 -96
  203. package/lib/cjs/types/libs/protocols/deepbook/index.d.ts.map +0 -1
  204. package/lib/esm/libs/protocols/deepbook/index.js +0 -80
  205. package/lib/esm/types/libs/protocols/deepbook/index.d.ts.map +0 -1
@@ -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
+ import { getCoinOjectIdsByAmount } from "./getCoinOjectIdsByAmount";
4
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 && !isSponsored) {
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),
@@ -0,0 +1,29 @@
1
+ import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
2
+ import { BaseContract } from "../base";
3
+ import { SuiUtils } from "../../../utils/sui";
4
+ export class HaedalPMMContract extends BaseContract {
5
+ async swap(tx) {
6
+ const [coinX, coinY] = this.swapInfo.pool.allTokens;
7
+ const xToY = this.swapInfo.swapXtoY;
8
+ const { x_price_id, y_price_id } = this.swapInfo.extra || {};
9
+ if (!x_price_id || !y_price_id) {
10
+ throw new Error("x_price_id and y_price_id are required");
11
+ }
12
+ const config = this.config.haedal_pmm;
13
+ const [coinOut] = tx.moveCall({
14
+ target: `${config.package}::trader::${xToY ? "sell_base_coin" : "sell_quote_coin"}`,
15
+ typeArguments: [coinX.address, coinY.address],
16
+ arguments: [
17
+ tx.object(this.swapInfo.poolId),
18
+ tx.object(SUI_CLOCK_OBJECT_ID),
19
+ tx.object(x_price_id), // pyth pricefeed for x
20
+ tx.object(y_price_id), // pyth pricefeed for y
21
+ this.inputCoinObject, // mutable coin
22
+ this.getInputCoinValue(tx), // swap amount
23
+ tx.pure.u64(0), // min output amount
24
+ ],
25
+ });
26
+ SuiUtils.collectDust(tx, this.swapInfo.assetIn, this.inputCoinObject);
27
+ return coinOut;
28
+ }
29
+ }
@@ -1,7 +1,6 @@
1
1
  import { FlowXContract } from "./flowx";
2
2
  import { AfterMathContract } from "./aftermath";
3
3
  import { CetusContract } from "./cetus";
4
- import { DeepBookContract } from "./deepbook";
5
4
  import { KriyaContract } from "./kriya";
6
5
  import { TurbosContract } from "./turbos";
7
6
  import { SuiswapContract } from "./suiswap";
@@ -15,6 +14,9 @@ import { StSuiContract } from "./stsui";
15
14
  import { FlowxV3Contract } from "./flowxV3";
16
15
  import { SteammContract } from "./steamm";
17
16
  import { MagmaContract } from "./magma";
17
+ import { HaedalPMMContract } from "./haedal_pmm";
18
+ import { MomentumContract } from "./momentum";
19
+ import { BluefinXContract } from "./bluefinx";
18
20
  export const ProtocolContract = {
19
21
  cetus: CetusContract,
20
22
  turbos: TurbosContract,
@@ -22,7 +24,6 @@ export const ProtocolContract = {
22
24
  kriya: KriyaContract,
23
25
  suiswap: SuiswapContract,
24
26
  aftermath: AfterMathContract,
25
- deepbook: DeepBookContract,
26
27
  deepbook_v3: SponsoredDeepBookV3Contract,
27
28
  flowx: FlowXContract,
28
29
  flowx_v3: FlowxV3Contract,
@@ -32,5 +33,9 @@ export const ProtocolContract = {
32
33
  obric: ObricContract,
33
34
  stsui: StSuiContract,
34
35
  steamm: SteammContract,
36
+ steamm_oracle_quoter: SteammContract,
35
37
  magma: MagmaContract,
38
+ haedal_pmm: HaedalPMMContract,
39
+ momentum: MomentumContract,
40
+ bluefinx: BluefinXContract,
36
41
  };
@@ -30,8 +30,7 @@ export class MagmaContract extends BaseContract {
30
30
  tx.object(SUI_CLOCK_OBJECT_ID),
31
31
  ],
32
32
  });
33
- SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, swapXtoY ? receiveA : receiveB, this.currentAccount);
34
- console.log(tx);
33
+ SuiUtils.collectDust(tx, this.swapInfo.assetIn, swapXtoY ? receiveA : receiveB);
35
34
  return swapXtoY ? receiveB : receiveA;
36
35
  }
37
36
  }
@@ -0,0 +1,45 @@
1
+ import { BaseContract } from "../base";
2
+ import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
3
+ import { getDefaultSqrtPriceLimit } from "../utils";
4
+ import { SuiUtils } from "../../../utils/sui";
5
+ export class MomentumContract extends BaseContract {
6
+ async swap(tx) {
7
+ const [coinX, coinY] = this.swapInfo.pool.allTokens;
8
+ const swapXtoY = this.swapInfo.swapXtoY;
9
+ const sqrtPriceLimit = getDefaultSqrtPriceLimit(swapXtoY);
10
+ const typeArguments = [coinX.address, coinY.address];
11
+ const { package: packageId, version } = this.config.momentum;
12
+ const [receiveA, receiveB, debt] = tx.moveCall({
13
+ target: `${packageId}::trade::flash_swap`,
14
+ typeArguments,
15
+ arguments: [
16
+ tx.object(this.swapInfo.poolId),
17
+ tx.pure.bool(swapXtoY), // a2b
18
+ tx.pure.bool(true), // exact in
19
+ this.getInputCoinValue(tx),
20
+ tx.pure.u128(sqrtPriceLimit.toString()), // sqrt price limit
21
+ tx.object(SUI_CLOCK_OBJECT_ID),
22
+ tx.object(version),
23
+ ],
24
+ });
25
+ tx.moveCall({
26
+ target: `${packageId}::trade::repay_flash_swap`,
27
+ typeArguments,
28
+ arguments: [
29
+ tx.object(this.swapInfo.poolId),
30
+ debt,
31
+ swapXtoY
32
+ ? SuiUtils.coinIntoBalance(tx, coinX.address, this.inputCoinObject)
33
+ : SuiUtils.zeroBalance(tx, coinX.address),
34
+ swapXtoY
35
+ ? SuiUtils.zeroBalance(tx, coinY.address)
36
+ : SuiUtils.coinIntoBalance(tx, coinY.address, this.inputCoinObject),
37
+ tx.object(version),
38
+ ],
39
+ });
40
+ const receiveACoin = SuiUtils.coinFromBalance(tx, coinX.address, receiveA);
41
+ const receiveBCoin = SuiUtils.coinFromBalance(tx, coinY.address, receiveB);
42
+ SuiUtils.collectDust(tx, this.swapInfo.assetIn, swapXtoY ? receiveACoin : receiveBCoin);
43
+ return swapXtoY ? receiveBCoin : receiveACoin;
44
+ }
45
+ }