@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,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.MagmaContract = void 0;
13
4
  const base_1 = require("../base");
@@ -15,38 +6,35 @@ const utils_1 = require("@mysten/sui/utils");
15
6
  const utils_2 = require("../utils");
16
7
  const sui_1 = require("../../../utils/sui");
17
8
  class MagmaContract extends base_1.BaseContract {
18
- swap(tx) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const [coinX, coinY] = this.swapInfo.pool.allTokens;
21
- const swapXtoY = this.swapInfo.swapXtoY;
22
- const sqrtPriceLimit = (0, utils_2.getDefaultSqrtPriceLimit)(swapXtoY);
23
- const typeArguments = [coinX.address, coinY.address];
24
- const [zeroOut] = tx.moveCall({
25
- target: "0x2::coin::zero",
26
- typeArguments: [swapXtoY ? coinY.address : coinX.address],
27
- });
28
- const amountIn = sui_1.SuiUtils.getCoinValue(swapXtoY ? coinX.address : coinY.address, this.inputCoinObject, tx);
29
- const config = this.config.magma;
30
- const [receiveA, receiveB] = tx.moveCall({
31
- target: `${config.package}::router::swap`,
32
- typeArguments,
33
- arguments: [
34
- tx.object(config.globalConfig),
35
- tx.object(this.swapInfo.poolId),
36
- swapXtoY ? this.inputCoinObject : zeroOut, // coin A
37
- swapXtoY ? zeroOut : this.inputCoinObject, // coin B
38
- tx.pure.bool(swapXtoY), // a to b or b to a
39
- tx.pure.bool(true), // exact in or out
40
- amountIn, // swap amount
41
- tx.pure.u128(sqrtPriceLimit.toString()), // sqrt price limit
42
- tx.pure.bool(false),
43
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
44
- ],
45
- });
46
- sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, swapXtoY ? receiveA : receiveB, this.currentAccount);
47
- console.log(tx);
48
- return swapXtoY ? receiveB : receiveA;
9
+ async swap(tx) {
10
+ const [coinX, coinY] = this.swapInfo.pool.allTokens;
11
+ const swapXtoY = this.swapInfo.swapXtoY;
12
+ const sqrtPriceLimit = (0, utils_2.getDefaultSqrtPriceLimit)(swapXtoY);
13
+ const typeArguments = [coinX.address, coinY.address];
14
+ const [zeroOut] = tx.moveCall({
15
+ target: "0x2::coin::zero",
16
+ typeArguments: [swapXtoY ? coinY.address : coinX.address],
49
17
  });
18
+ const amountIn = sui_1.SuiUtils.getCoinValue(swapXtoY ? coinX.address : coinY.address, this.inputCoinObject, tx);
19
+ const config = this.config.magma;
20
+ const [receiveA, receiveB] = tx.moveCall({
21
+ target: `${config.package}::router::swap`,
22
+ typeArguments,
23
+ arguments: [
24
+ tx.object(config.globalConfig),
25
+ tx.object(this.swapInfo.poolId),
26
+ swapXtoY ? this.inputCoinObject : zeroOut, // coin A
27
+ swapXtoY ? zeroOut : this.inputCoinObject, // coin B
28
+ tx.pure.bool(swapXtoY), // a to b or b to a
29
+ tx.pure.bool(true), // exact in or out
30
+ amountIn, // swap amount
31
+ tx.pure.u128(sqrtPriceLimit.toString()), // sqrt price limit
32
+ tx.pure.bool(false),
33
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
34
+ ],
35
+ });
36
+ sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, swapXtoY ? receiveA : receiveB);
37
+ return swapXtoY ? receiveB : receiveA;
50
38
  }
51
39
  }
52
40
  exports.MagmaContract = MagmaContract;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MomentumContract = void 0;
4
+ const base_1 = require("../base");
5
+ const utils_1 = require("@mysten/sui/utils");
6
+ const utils_2 = require("../utils");
7
+ const sui_1 = require("../../../utils/sui");
8
+ class MomentumContract extends base_1.BaseContract {
9
+ async swap(tx) {
10
+ const [coinX, coinY] = this.swapInfo.pool.allTokens;
11
+ const swapXtoY = this.swapInfo.swapXtoY;
12
+ const sqrtPriceLimit = (0, utils_2.getDefaultSqrtPriceLimit)(swapXtoY);
13
+ const typeArguments = [coinX.address, coinY.address];
14
+ const { package: packageId, version } = this.config.momentum;
15
+ const [receiveA, receiveB, debt] = tx.moveCall({
16
+ target: `${packageId}::trade::flash_swap`,
17
+ typeArguments,
18
+ arguments: [
19
+ tx.object(this.swapInfo.poolId),
20
+ tx.pure.bool(swapXtoY), // a2b
21
+ tx.pure.bool(true), // exact in
22
+ this.getInputCoinValue(tx),
23
+ tx.pure.u128(sqrtPriceLimit.toString()), // sqrt price limit
24
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
25
+ tx.object(version),
26
+ ],
27
+ });
28
+ tx.moveCall({
29
+ target: `${packageId}::trade::repay_flash_swap`,
30
+ typeArguments,
31
+ arguments: [
32
+ tx.object(this.swapInfo.poolId),
33
+ debt,
34
+ swapXtoY
35
+ ? sui_1.SuiUtils.coinIntoBalance(tx, coinX.address, this.inputCoinObject)
36
+ : sui_1.SuiUtils.zeroBalance(tx, coinX.address),
37
+ swapXtoY
38
+ ? sui_1.SuiUtils.zeroBalance(tx, coinY.address)
39
+ : sui_1.SuiUtils.coinIntoBalance(tx, coinY.address, this.inputCoinObject),
40
+ tx.object(version),
41
+ ],
42
+ });
43
+ const receiveACoin = sui_1.SuiUtils.coinFromBalance(tx, coinX.address, receiveA);
44
+ const receiveBCoin = sui_1.SuiUtils.coinFromBalance(tx, coinY.address, receiveB);
45
+ sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, swapXtoY ? receiveACoin : receiveBCoin);
46
+ return swapXtoY ? receiveBCoin : receiveACoin;
47
+ }
48
+ }
49
+ exports.MomentumContract = MomentumContract;
@@ -1,41 +1,30 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ObricContract = void 0;
13
4
  const utils_1 = require("@mysten/sui/utils");
14
5
  const base_1 = require("../base");
15
6
  class ObricContract extends base_1.BaseContract {
16
- swap(tx) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const [coinX, coinY] = this.swapInfo.pool.allTokens;
19
- const xToY = this.swapInfo.swapXtoY;
20
- const { x_price_id, y_price_id } = this.swapInfo.extra || {};
21
- if (!x_price_id || !y_price_id) {
22
- throw new Error("x_price_id and y_price_id are required");
23
- }
24
- const { package: PACKAGE_ID, pythState: PYTH_STATE } = this.config.obric;
25
- const [coinOut] = tx.moveCall({
26
- target: `${PACKAGE_ID}::v2::${xToY ? "swap_x_to_y" : "swap_y_to_x"}`,
27
- typeArguments: [coinX.address, coinY.address],
28
- arguments: [
29
- tx.object(this.swapInfo.poolId),
30
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
31
- tx.object(PYTH_STATE),
32
- tx.object(x_price_id), // pyth pricefeed for x
33
- tx.object(y_price_id), // pyth pricefeed for y
34
- this.inputCoinObject,
35
- ],
36
- });
37
- return coinOut;
7
+ async swap(tx) {
8
+ const [coinX, coinY] = this.swapInfo.pool.allTokens;
9
+ const xToY = this.swapInfo.swapXtoY;
10
+ const { x_price_id, y_price_id } = this.swapInfo.extra || {};
11
+ if (!x_price_id || !y_price_id) {
12
+ throw new Error("x_price_id and y_price_id are required");
13
+ }
14
+ const { package: PACKAGE_ID, pythState: PYTH_STATE } = this.config.obric;
15
+ const [coinOut] = tx.moveCall({
16
+ target: `${PACKAGE_ID}::v2::${xToY ? "swap_x_to_y" : "swap_y_to_x"}`,
17
+ typeArguments: [coinX.address, coinY.address],
18
+ arguments: [
19
+ tx.object(this.swapInfo.poolId),
20
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
21
+ tx.object(PYTH_STATE),
22
+ tx.object(x_price_id), // pyth pricefeed for x
23
+ tx.object(y_price_id), // pyth pricefeed for y
24
+ this.inputCoinObject,
25
+ ],
38
26
  });
27
+ return coinOut;
39
28
  }
40
29
  }
41
30
  exports.ObricContract = ObricContract;
@@ -1,35 +1,24 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SpringSuiContract = void 0;
13
4
  const utils_1 = require("@mysten/sui/utils");
14
5
  const base_1 = require("../base");
15
6
  class SpringSuiContract extends base_1.BaseContract {
16
- swap(tx) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- // coinX is always SUI
19
- const coinY = this.swapInfo.pool.allTokens[1];
20
- const isStake = this.swapInfo.swapXtoY;
21
- const { package: PACKAGE_ID } = this.config.springsui;
22
- const [coinOut] = tx.moveCall({
23
- target: `${PACKAGE_ID}::liquid_staking::${isStake ? "mint" : "redeem"}`,
24
- typeArguments: [coinY.address],
25
- arguments: [
26
- tx.object(this.swapInfo.poolId),
27
- isStake ? tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID) : this.inputCoinObject,
28
- isStake ? this.inputCoinObject : tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID),
29
- ],
30
- });
31
- return coinOut;
7
+ async swap(tx) {
8
+ // coinX is always SUI
9
+ const coinY = this.swapInfo.pool.allTokens[1];
10
+ const isStake = this.swapInfo.swapXtoY;
11
+ const { package: PACKAGE_ID } = this.config.springsui;
12
+ const [coinOut] = tx.moveCall({
13
+ target: `${PACKAGE_ID}::liquid_staking::${isStake ? "mint" : "redeem"}`,
14
+ typeArguments: [coinY.address],
15
+ arguments: [
16
+ tx.object(this.swapInfo.poolId),
17
+ isStake ? tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID) : this.inputCoinObject,
18
+ isStake ? this.inputCoinObject : tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID),
19
+ ],
32
20
  });
21
+ return coinOut;
33
22
  }
34
23
  }
35
24
  exports.SpringSuiContract = SpringSuiContract;
@@ -1,26 +1,21 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SteammContract = void 0;
13
4
  const base_1 = require("../base");
14
5
  const utils_1 = require("@mysten/sui/utils");
15
6
  const sui_1 = require("../../../utils/sui");
16
7
  class SteammContract extends base_1.BaseContract {
17
- swap(tx) {
18
- return __awaiter(this, void 0, void 0, function* () {
8
+ async swap(tx) {
9
+ if (this.extra.poolStructTag.includes("omm::OracleQuoter")) {
10
+ return this.ommSwap(tx);
11
+ }
12
+ else if (this.extra.poolStructTag.includes("cpmm::CpQuoter")) {
19
13
  return this.cpmmSwap(tx);
20
- });
14
+ }
15
+ throw new Error(`Unsupported pool type: ${this.extra.poolStructTag}`);
21
16
  }
22
17
  cpmmSwap(tx) {
23
- const extra = this.swapInfo.extra;
18
+ const extra = this.extra;
24
19
  if (!extra ||
25
20
  !extra.bankAStructTag ||
26
21
  !extra.bankBStructTag ||
@@ -70,10 +65,10 @@ class SteammContract extends base_1.BaseContract {
70
65
  });
71
66
  const coinIn = xToY ? coinA : coinB;
72
67
  const coinOut = xToY ? coinB : coinA;
73
- sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, coinIn, this.currentAccount);
68
+ sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, coinIn);
74
69
  return coinOut;
75
70
  }
76
- cpmmSwapV2(tx) {
71
+ ommSwap(tx) {
77
72
  const extra = this.swapInfo.extra;
78
73
  if (!extra ||
79
74
  !extra.bankAStructTag ||
@@ -87,72 +82,76 @@ class SteammContract extends base_1.BaseContract {
87
82
  }
88
83
  // the pool script v1 only support same lending market
89
84
  if (extra.lendingMarketA !== extra.lendingMarketB) {
90
- throw new Error(`Invalid lending market for cpmmSwap`);
85
+ throw new Error(`Invalid lending market for ommSwap`);
91
86
  }
92
87
  const [btokenA, bTokenB, _quoter, lp] = (0, utils_1.parseStructTag)(extra.poolStructTag).typeParams;
93
88
  const [lendingMarket, coinTypeA, _bTokenA] = (0, utils_1.parseStructTag)(extra.bankAStructTag).typeParams;
94
89
  const [_lendingMarket, coinTypeB, _bTokenB] = (0, utils_1.parseStructTag)(extra.bankBStructTag).typeParams;
95
- const [coinX, _coinY] = this.swapInfo.pool.allTokens;
96
- const xToY = coinX.address === this.swapInfo.assetIn;
90
+ const xToY = this.swapInfo.swapXtoY;
97
91
  const coinA = xToY
98
92
  ? this.inputCoinObject
99
93
  : sui_1.SuiUtils.zeroCoin(tx, (0, utils_1.normalizeStructTag)(coinTypeA));
100
94
  const coinB = !xToY
101
95
  ? this.inputCoinObject
102
96
  : sui_1.SuiUtils.zeroCoin(tx, (0, utils_1.normalizeStructTag)(coinTypeB));
103
- const bankATypeArgs = [lendingMarket, coinTypeA, btokenA].map(utils_1.normalizeStructTag);
104
- const bankBTypeArgs = [lendingMarket, coinTypeB, bTokenB].map(utils_1.normalizeStructTag);
105
- const bankInTypeArgs = xToY ? bankATypeArgs : bankBTypeArgs;
106
- const bankOutTypeArgs = xToY ? bankBTypeArgs : bankATypeArgs;
107
- // mint btoken from both coins
108
- const bTokenIn = tx.moveCall({
109
- target: `${this.config.steamm.package}::bank::mint_btokens`,
110
- typeArguments: bankInTypeArgs,
97
+ const [priceA, priceB] = this.getOraclePriceUpdate(tx);
98
+ tx.moveCall({
99
+ target: `${this.config.steamm.script}::pool_script_v2::omm_swap`,
100
+ typeArguments: [
101
+ lendingMarket,
102
+ coinTypeA,
103
+ coinTypeB,
104
+ btokenA,
105
+ bTokenB,
106
+ lp,
107
+ ].map(utils_1.normalizeStructTag),
111
108
  arguments: [
112
- tx.object(xToY ? extra.bankA : extra.bankB),
109
+ tx.object(this.swapInfo.poolId),
110
+ tx.object(extra.bankA),
111
+ tx.object(extra.bankB),
113
112
  tx.object(extra.lendingMarketA),
114
- xToY ? coinA : coinB,
113
+ priceA,
114
+ priceB,
115
+ coinA,
116
+ coinB,
117
+ tx.pure.bool(xToY),
115
118
  this.getInputCoinValue(tx),
119
+ tx.pure.u64(0),
116
120
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
117
121
  ],
118
122
  });
119
- const bTokenOut = sui_1.SuiUtils.zeroCoin(tx, (0, utils_1.normalizeStructTag)(xToY ? bTokenB : btokenA));
120
- // call swap on btoken
121
- tx.moveCall({
122
- target: `${this.config.steamm.package}::cpmm::swap`,
123
- typeArguments: [btokenA, bTokenB, lp].map(utils_1.normalizeStructTag),
123
+ const coinIn = xToY ? coinA : coinB;
124
+ const coinOut = xToY ? coinB : coinA;
125
+ sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, coinIn);
126
+ return coinOut;
127
+ }
128
+ getOraclePriceUpdate(tx) {
129
+ const oracleA = this.extra.oracles?.[0]?.Pyth?.price_identifier?.bytes;
130
+ const oracleB = this.extra.oracles?.[1]?.Pyth?.price_identifier?.bytes;
131
+ const registry = this.extra.oracleRegistry;
132
+ const indexes = this.extra.oracleIndexes;
133
+ if (!oracleA || !oracleB || !registry || indexes?.length !== 2) {
134
+ throw new Error(`Invalid oracle info for getOraclePriceUpdate`);
135
+ }
136
+ const [a] = tx.moveCall({
137
+ target: `${this.config.steamm.oracle}::oracles::get_pyth_price`,
124
138
  arguments: [
125
- tx.object(this.swapInfo.poolId),
126
- xToY ? bTokenIn : bTokenOut,
127
- xToY ? bTokenOut : bTokenIn,
128
- tx.pure.bool(xToY),
129
- sui_1.SuiUtils.getCoinValue((0, utils_1.normalizeStructTag)(xToY ? btokenA : bTokenB), bTokenIn, tx),
130
- tx.pure.u64(0), // min output
139
+ tx.object(registry),
140
+ tx.object(this.pythMap["0x" + (0, utils_1.toHex)(Uint8Array.from(oracleA))]),
141
+ tx.pure.u64(indexes[0]),
142
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
131
143
  ],
132
144
  });
133
- // burn btoken to get out coin
134
- const [outCoin] = tx.moveCall({
135
- target: `${this.config.steamm.package}::bank::burn_btokens`,
136
- typeArguments: bankOutTypeArgs,
145
+ const [b] = tx.moveCall({
146
+ target: `${this.config.steamm.oracle}::oracles::get_pyth_price`,
137
147
  arguments: [
138
- tx.object(xToY ? extra.bankB : extra.bankA),
139
- tx.object(extra.lendingMarketA),
140
- bTokenOut,
141
- sui_1.SuiUtils.getCoinValue((0, utils_1.normalizeStructTag)(xToY ? bTokenB : btokenA), bTokenOut, tx),
148
+ tx.object(registry),
149
+ tx.object(this.pythMap["0x" + (0, utils_1.toHex)(Uint8Array.from(oracleB))]),
150
+ tx.pure.u64(indexes[1]),
142
151
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
143
152
  ],
144
153
  });
145
- const coinIn = xToY ? coinA : coinB;
146
- const coinOut = xToY ? coinB : coinA;
147
- // the coinIn was mutated by mint_btokens above, but not consumed, so we need to transfer or destroy it
148
- sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, coinIn, this.currentAccount);
149
- // bTokenIn was mutated by cpmm::swap above, but not consumed, so we need to transfer or destroy it
150
- sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, (0, utils_1.normalizeStructTag)(xToY ? btokenA : bTokenB), bTokenIn, this.currentAccount);
151
- // bTokenOut was burned by burn_btokens above, but not consumed, so we need to transfer or destroy it
152
- sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, (0, utils_1.normalizeStructTag)(xToY ? bTokenB : btokenA), bTokenOut, this.currentAccount);
153
- // after all we need to merge the placeholder output coin (zero) with actual output coin from swap burn
154
- tx.mergeCoins(coinOut, [outCoin]);
155
- return coinOut;
154
+ return [a, b];
156
155
  }
157
156
  }
158
157
  exports.SteammContract = SteammContract;
@@ -1,35 +1,24 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.StSuiContract = void 0;
13
4
  const utils_1 = require("@mysten/sui/utils");
14
5
  const base_1 = require("../base");
15
6
  class StSuiContract extends base_1.BaseContract {
16
- swap(tx) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- // coinX is always SUI
19
- const coinY = this.swapInfo.pool.allTokens[1];
20
- const isStake = this.swapInfo.swapXtoY;
21
- const { package: PACKAGE_ID } = this.config.stsui;
22
- const [coinOut] = tx.moveCall({
23
- target: `${PACKAGE_ID}::liquid_staking::${isStake ? "mint" : "redeem"}`,
24
- typeArguments: [coinY.address],
25
- arguments: [
26
- tx.object(this.swapInfo.poolId),
27
- isStake ? tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID) : this.inputCoinObject,
28
- isStake ? this.inputCoinObject : tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID),
29
- ],
30
- });
31
- return coinOut;
7
+ async swap(tx) {
8
+ // coinX is always SUI
9
+ const coinY = this.swapInfo.pool.allTokens[1];
10
+ const isStake = this.swapInfo.swapXtoY;
11
+ const { package: PACKAGE_ID } = this.config.stsui;
12
+ const [coinOut] = tx.moveCall({
13
+ target: `${PACKAGE_ID}::liquid_staking::${isStake ? "mint" : "redeem"}`,
14
+ typeArguments: [coinY.address],
15
+ arguments: [
16
+ tx.object(this.swapInfo.poolId),
17
+ isStake ? tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID) : this.inputCoinObject,
18
+ isStake ? this.inputCoinObject : tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID),
19
+ ],
32
20
  });
21
+ return coinOut;
33
22
  }
34
23
  }
35
24
  exports.StSuiContract = StSuiContract;
@@ -1,45 +1,34 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SuiswapContract = void 0;
13
4
  const utils_1 = require("@mysten/sui/utils");
14
5
  const base_1 = require("../base");
15
6
  const sui_1 = require("../../../utils/sui");
16
7
  class SuiswapContract extends base_1.BaseContract {
17
- swap(tx) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const poolId = this.swapInfo.poolId;
20
- const swapXtoY = this.swapInfo.swapXtoY;
21
- const inputCoin = this.inputCoinObject;
22
- const typeArguments = [this.swapInfo.coinX.type, this.swapInfo.coinY.type];
23
- const callFunc = swapXtoY
24
- ? "do_swap_x_to_y_direct"
25
- : "do_swap_y_to_x_direct";
26
- const { package: PACKAGE_ID } = this.config.suiswap;
27
- const inputAmount = this.getInputCoinValue(tx);
28
- const [tokenIn, tokenOut] = tx.moveCall({
29
- target: `${PACKAGE_ID}::pool::${callFunc}`,
30
- typeArguments,
31
- arguments: [
32
- tx.object(poolId),
33
- tx.makeMoveVec({
34
- elements: [inputCoin],
35
- }),
36
- inputAmount,
37
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
38
- ],
39
- });
40
- sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, tokenIn, this.currentAccount);
41
- return tokenOut;
8
+ async swap(tx) {
9
+ const poolId = this.swapInfo.poolId;
10
+ const swapXtoY = this.swapInfo.swapXtoY;
11
+ const inputCoin = this.inputCoinObject;
12
+ const typeArguments = [this.swapInfo.coinX.type, this.swapInfo.coinY.type];
13
+ const callFunc = swapXtoY
14
+ ? "do_swap_x_to_y_direct"
15
+ : "do_swap_y_to_x_direct";
16
+ const { package: PACKAGE_ID } = this.config.suiswap;
17
+ const inputAmount = this.getInputCoinValue(tx);
18
+ const [tokenIn, tokenOut] = tx.moveCall({
19
+ target: `${PACKAGE_ID}::pool::${callFunc}`,
20
+ typeArguments,
21
+ arguments: [
22
+ tx.object(poolId),
23
+ tx.makeMoveVec({
24
+ elements: [inputCoin],
25
+ }),
26
+ inputAmount,
27
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
28
+ ],
42
29
  });
30
+ sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, tokenIn);
31
+ return tokenOut;
43
32
  }
44
33
  }
45
34
  exports.SuiswapContract = SuiswapContract;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.TurbosContract = void 0;
13
4
  const utils_1 = require("@mysten/sui/utils");
@@ -16,36 +7,30 @@ const utils_2 = require("../utils");
16
7
  const sui_1 = require("../../../utils/sui");
17
8
  const ONE_MINUTE = 60 * 1000;
18
9
  class TurbosContract extends base_1.BaseContract {
19
- swap(tx) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const a2b = this.swapInfo.swapXtoY;
22
- const { poolId, address } = {
23
- poolId: this.swapInfo.poolId,
24
- address: this.currentAccount,
25
- };
26
- const { package: PACKAGE_ID, version: VERSION } = this.config.turbos;
27
- const inputAmount = this.getInputCoinValue(tx);
28
- const [tokenOut, tokenIn] = tx.moveCall({
29
- target: `${PACKAGE_ID}::swap_router::swap_${a2b ? "a_b" : "b_a"}_with_return_`,
30
- typeArguments: this.getTypeParams(),
31
- arguments: [
32
- tx.object(poolId),
33
- tx.makeMoveVec({
34
- elements: [this.inputCoinObject],
35
- }),
36
- inputAmount,
37
- tx.pure.u64(0),
38
- tx.pure.u128((0, utils_2.getDefaultSqrtPriceLimit)(this.swapInfo.swapXtoY).toString()),
39
- tx.pure.bool(true),
40
- tx.pure.address(this.currentAccount),
41
- tx.pure.u64(Date.now() + ONE_MINUTE * 3),
42
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
43
- tx.object(VERSION),
44
- ],
45
- });
46
- sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, tokenIn, address);
47
- return tokenOut;
10
+ async swap(tx) {
11
+ const a2b = this.swapInfo.swapXtoY;
12
+ const { package: PACKAGE_ID, version: VERSION } = this.config.turbos;
13
+ const inputAmount = this.getInputCoinValue(tx);
14
+ const [tokenOut, tokenIn] = tx.moveCall({
15
+ target: `${PACKAGE_ID}::swap_router::swap_${a2b ? "a_b" : "b_a"}_with_return_`,
16
+ typeArguments: this.getTypeParams(),
17
+ arguments: [
18
+ tx.object(this.swapInfo.poolId),
19
+ tx.makeMoveVec({
20
+ elements: [this.inputCoinObject],
21
+ }),
22
+ inputAmount,
23
+ tx.pure.u64(0),
24
+ tx.pure.u128((0, utils_2.getDefaultSqrtPriceLimit)(this.swapInfo.swapXtoY).toString()),
25
+ tx.pure.bool(true),
26
+ tx.pure.address(this.currentAccount),
27
+ tx.pure.u64(Date.now() + ONE_MINUTE * 3),
28
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
29
+ tx.object(VERSION),
30
+ ],
48
31
  });
32
+ sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, tokenIn);
33
+ return tokenOut;
49
34
  }
50
35
  }
51
36
  exports.TurbosContract = TurbosContract;
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getDefaultSqrtPriceLimit = getDefaultSqrtPriceLimit;
7
- const bn_js_1 = __importDefault(require("bn.js"));
8
4
  const constants_1 = require("./constants");
9
5
  function getDefaultSqrtPriceLimit(a2b) {
10
- return new bn_js_1.default(a2b ? constants_1.MIN_SQRT_PRICE : constants_1.MAX_SQRT_PRICE);
6
+ return BigInt(a2b ? constants_1.MIN_SQRT_PRICE : constants_1.MAX_SQRT_PRICE);
11
7
  }