@7kprotocol/sdk-ts 2.4.1 → 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 (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,33 +1,22 @@
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.placeLimitOrder = placeLimitOrder;
13
4
  const getSplitCoinForTx_1 = require("../../libs/getSplitCoinForTx");
14
5
  const token_1 = require("../../utils/token");
15
6
  const constants_1 = require("./constants");
16
- function placeLimitOrder(_a) {
17
- return __awaiter(this, arguments, void 0, function* ({ accountAddress, payCoinType, targetCoinType, payCoinAmount, rate, slippage, expireTs, devInspect, }) {
18
- const { tx, coinData: payCoin } = yield (0, getSplitCoinForTx_1.getSplitCoinForTx)(accountAddress, payCoinAmount.toString(), [payCoinAmount.toString()], (0, token_1.denormalizeTokenType)(payCoinType), undefined, devInspect);
19
- tx.moveCall({
20
- target: `${constants_1.LIMIT_ORDER_MODULE_ID}::place_limit_order`,
21
- arguments: [
22
- tx.object(constants_1.GLOBAL_CONFIG_ID),
23
- payCoin,
24
- tx.pure.u64(rate),
25
- tx.pure.u64(slippage),
26
- tx.pure.u64(expireTs),
27
- tx.object.clock(),
28
- ],
29
- typeArguments: [payCoinType, targetCoinType],
30
- });
31
- return tx;
7
+ async function placeLimitOrder({ accountAddress, payCoinType, targetCoinType, payCoinAmount, rate, slippage, expireTs, devInspect, }) {
8
+ const { tx, coinData: payCoin } = await (0, getSplitCoinForTx_1.getSplitCoinForTx)(accountAddress, payCoinAmount.toString(), [payCoinAmount.toString()], (0, token_1.denormalizeTokenType)(payCoinType), undefined, devInspect);
9
+ tx.moveCall({
10
+ target: `${constants_1.LIMIT_ORDER_MODULE_ID}::place_limit_order`,
11
+ arguments: [
12
+ tx.object(constants_1.GLOBAL_CONFIG_ID),
13
+ payCoin,
14
+ tx.pure.u64(rate),
15
+ tx.pure.u64(slippage),
16
+ tx.pure.u64(expireTs),
17
+ tx.object.clock(),
18
+ ],
19
+ typeArguments: [payCoinType, targetCoinType],
32
20
  });
21
+ return tx;
33
22
  }
@@ -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.getTokenPrice = getTokenPrice;
13
4
  exports.getTokenPrices = getTokenPrices;
@@ -16,18 +7,15 @@ const fetchClient_1 = require("../../config/fetchClient");
16
7
  const apiEndpoints_1 = require("../../constants/apiEndpoints");
17
8
  const tokens_1 = require("../../constants/tokens");
18
9
  const token_1 = require("../../utils/token");
19
- function getTokenPrice(id_1) {
20
- return __awaiter(this, arguments, void 0, function* (id, vsCoin = tokens_1.NATIVE_USDC_TOKEN_TYPE) {
21
- var _a;
22
- try {
23
- const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.PRICES}/price?ids=${(0, token_1.normalizeTokenType)(id)}&vsCoin=${vsCoin}`);
24
- const pricesRes = (yield response.json());
25
- return Number(((_a = pricesRes === null || pricesRes === void 0 ? void 0 : pricesRes[id]) === null || _a === void 0 ? void 0 : _a.price) || 0);
26
- }
27
- catch (_) {
28
- return 0;
29
- }
30
- });
10
+ async function getTokenPrice(id, vsCoin = tokens_1.NATIVE_USDC_TOKEN_TYPE) {
11
+ try {
12
+ const response = await (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.PRICES}/price?ids=${(0, token_1.normalizeTokenType)(id)}&vsCoin=${vsCoin}`);
13
+ const pricesRes = (await response.json());
14
+ return Number(pricesRes?.[id]?.price || 0);
15
+ }
16
+ catch (_) {
17
+ return 0;
18
+ }
31
19
  }
32
20
  const chunkArray = (array, chunkSize) => {
33
21
  const chunks = [];
@@ -38,48 +26,43 @@ const chunkArray = (array, chunkSize) => {
38
26
  };
39
27
  const MAX_TOTAL_IDS = 500;
40
28
  const MAX_IDS_PER_REQUEST = 100;
41
- function getTokenPrices(ids_1) {
42
- return __awaiter(this, arguments, void 0, function* (ids, vsCoin = tokens_1.NATIVE_USDC_TOKEN_TYPE) {
43
- try {
44
- const limitedIds = ids.slice(0, MAX_TOTAL_IDS).map(token_1.normalizeTokenType);
45
- const idChunks = chunkArray(limitedIds, MAX_IDS_PER_REQUEST);
46
- const responses = yield Promise.all(idChunks.map((chunk) => __awaiter(this, void 0, void 0, function* () {
47
- const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.PRICES}/price`, {
48
- method: "POST",
49
- headers: {
50
- "Content-Type": "application/json",
51
- },
52
- body: JSON.stringify({
53
- ids: chunk,
54
- vsCoin,
55
- }),
56
- });
57
- const pricesRes = (yield response.json());
58
- return pricesRes;
59
- })));
60
- const combinedPrices = responses.reduce((acc, pricesRes) => {
61
- Object.keys(pricesRes).forEach((id) => {
62
- var _a;
63
- acc[id] = Number(((_a = pricesRes[id]) === null || _a === void 0 ? void 0 : _a.price) || 0);
64
- });
65
- return acc;
66
- }, {});
67
- const finalPrices = limitedIds.reduce((acc, id) => {
68
- acc[id] = combinedPrices[id] || 0;
69
- return acc;
70
- }, {});
71
- return finalPrices;
72
- }
73
- catch (_) {
74
- return ids.slice(0, MAX_TOTAL_IDS).reduce((acc, id) => {
75
- acc[id] = 0;
76
- return acc;
77
- }, {});
78
- }
79
- });
29
+ async function getTokenPrices(ids, vsCoin = tokens_1.NATIVE_USDC_TOKEN_TYPE) {
30
+ try {
31
+ const limitedIds = ids.slice(0, MAX_TOTAL_IDS).map(token_1.normalizeTokenType);
32
+ const idChunks = chunkArray(limitedIds, MAX_IDS_PER_REQUEST);
33
+ const responses = await Promise.all(idChunks.map(async (chunk) => {
34
+ const response = await (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.PRICES}/price`, {
35
+ method: "POST",
36
+ headers: {
37
+ "Content-Type": "application/json",
38
+ },
39
+ body: JSON.stringify({
40
+ ids: chunk,
41
+ vsCoin,
42
+ }),
43
+ });
44
+ const pricesRes = (await response.json());
45
+ return pricesRes;
46
+ }));
47
+ const combinedPrices = responses.reduce((acc, pricesRes) => {
48
+ Object.keys(pricesRes).forEach((id) => {
49
+ acc[id] = Number(pricesRes[id]?.price || 0);
50
+ });
51
+ return acc;
52
+ }, {});
53
+ const finalPrices = limitedIds.reduce((acc, id) => {
54
+ acc[id] = combinedPrices[id] || 0;
55
+ return acc;
56
+ }, {});
57
+ return finalPrices;
58
+ }
59
+ catch (_) {
60
+ return ids.slice(0, MAX_TOTAL_IDS).reduce((acc, id) => {
61
+ acc[id] = 0;
62
+ return acc;
63
+ }, {});
64
+ }
80
65
  }
81
- function getSuiPrice() {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- return yield getTokenPrice(tokens_1.SUI_FULL_TYPE);
84
- });
66
+ async function getSuiPrice() {
67
+ return await getTokenPrice(tokens_1.SUI_FULL_TYPE);
85
68
  }
@@ -1,31 +1,31 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.buildTx = void 0;
16
4
  const transactions_1 = require("@mysten/sui/transactions");
17
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
5
+ const utils_1 = require("@mysten/sui/utils");
6
+ const config_1 = require("../../config");
7
+ const _7k_1 = require("../../constants/_7k");
18
8
  const getSplitCoinForTx_1 = require("../../libs/getSplitCoinForTx");
19
9
  const groupSwapRoutes_1 = require("../../libs/groupSwapRoutes");
10
+ const client_1 = require("../../libs/protocols/bluefinx/client");
11
+ const types_1 = require("../../libs/protocols/bluefinx/types");
20
12
  const swapWithRoute_1 = require("../../libs/swapWithRoute");
21
- const token_1 = require("../../utils/token");
13
+ const aggregator_1 = require("../../types/aggregator");
22
14
  const sui_1 = require("../../utils/sui");
23
- const _7k_1 = require("../../constants/_7k");
24
- const utils_1 = require("@mysten/sui/utils");
25
- const config_1 = require("./config");
26
- const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteResponse, accountAddress, slippage, commission: _commission, devInspect, extendTx, isSponsored }) {
15
+ const token_1 = require("../../utils/token");
16
+ const config_2 = require("./config");
17
+ const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }) => {
18
+ const isBluefinX = (0, aggregator_1.isBluefinXRouting)(quoteResponse);
19
+ const _commission = {
20
+ ...__commission,
21
+ // commission is ignored for bluefinx
22
+ commissionBps: isBluefinX ? 0 : __commission.commissionBps,
23
+ };
27
24
  const { tx: _tx, coinIn } = extendTx || {};
28
25
  let coinOut;
26
+ if (isBluefinX && devInspect) {
27
+ throw new Error("BluefinX tx is sponsored, skip devInspect");
28
+ }
29
29
  if (!accountAddress) {
30
30
  throw new Error("Sender address is required");
31
31
  }
@@ -37,45 +37,42 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteRespon
37
37
  }
38
38
  const tx = _tx || new transactions_1.Transaction();
39
39
  const routes = (0, groupSwapRoutes_1.groupSwapRoutes)(quoteResponse);
40
- const splits = routes.map((group) => { var _a, _b; return (_b = (_a = group[0]) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : "0"; });
40
+ const splits = routes.map((group) => group[0]?.amount ?? "0");
41
41
  let coinData;
42
42
  if (coinIn) {
43
43
  coinData = tx.splitCoins(coinIn, splits);
44
- sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, quoteResponse.tokenIn, coinIn, accountAddress);
44
+ sui_1.SuiUtils.collectDust(tx, quoteResponse.tokenIn, coinIn);
45
45
  }
46
46
  else {
47
- const { coinData: _data } = yield (0, getSplitCoinForTx_1.getSplitCoinForTx)(accountAddress, quoteResponse.swapAmountWithDecimal, splits, (0, token_1.denormalizeTokenType)(quoteResponse.tokenIn), tx, devInspect, isSponsored);
47
+ const { coinData: _data } = await (0, getSplitCoinForTx_1.getSplitCoinForTx)(accountAddress, quoteResponse.swapAmountWithDecimal, splits, (0, token_1.denormalizeTokenType)(quoteResponse.tokenIn), tx, devInspect, isSponsored || isBluefinX);
48
48
  coinData = _data;
49
49
  }
50
+ const pythMap = await updatePythPriceFeedsIfAny(tx, quoteResponse);
50
51
  const coinObjects = [];
51
- const config = yield (0, config_1.getConfig)();
52
- yield Promise.all(routes.map((route, index) => __awaiter(void 0, void 0, void 0, function* () {
52
+ const config = await (0, config_2.getConfig)();
53
+ await Promise.all(routes.map(async (route, index) => {
53
54
  const inputCoinObject = coinData[index];
54
- const coinRes = yield (0, swapWithRoute_1.swapWithRoute)({
55
+ const coinRes = await (0, swapWithRoute_1.swapWithRoute)({
55
56
  route,
56
57
  inputCoinObject,
57
58
  currentAccount: accountAddress,
58
59
  tx,
59
60
  config,
61
+ pythMap,
60
62
  });
61
63
  if (coinRes) {
62
64
  coinObjects.push(coinRes);
63
65
  }
64
- })));
66
+ }));
65
67
  if (coinObjects.length > 0) {
66
68
  const mergeCoin = coinObjects.length > 1
67
69
  ? sui_1.SuiUtils.mergeCoins(coinObjects, tx)
68
70
  : coinObjects[0];
69
- coinOut = mergeCoin;
70
- const minReceived = new bignumber_js_1.default(1)
71
- .minus(slippage)
72
- .multipliedBy(quoteResponse.returnAmountWithDecimal)
73
- .toFixed(0);
74
- const [partner] = tx.moveCall({
75
- target: "0x1::option::some",
76
- typeArguments: [`address`],
77
- arguments: [tx.pure.address(_commission.partner)],
78
- });
71
+ const returnAmountAfterCommission = (BigInt(10000 - _commission.commissionBps) *
72
+ BigInt(quoteResponse.returnAmountWithDecimal)) /
73
+ BigInt(10000);
74
+ const minReceived = (BigInt(1e9 - +slippage * 1e9) * BigInt(returnAmountAfterCommission)) /
75
+ BigInt(1e9);
79
76
  tx.moveCall({
80
77
  target: `${_7k_1._7K_PACKAGE_ID}::settle::settle`,
81
78
  typeArguments: [quoteResponse.tokenIn, quoteResponse.tokenOut],
@@ -84,16 +81,68 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteRespon
84
81
  tx.object(_7k_1._7K_VAULT),
85
82
  tx.pure.u64(quoteResponse.swapAmountWithDecimal),
86
83
  mergeCoin,
87
- tx.pure.u64(minReceived),
88
- tx.pure.u64(quoteResponse.returnAmountWithDecimal),
89
- partner,
84
+ tx.pure.u64(minReceived), // minimum received
85
+ tx.pure.u64(returnAmountAfterCommission), // expected amount out
86
+ tx.pure.option("address", (0, utils_1.isValidSuiAddress)(_commission.partner) ? _commission.partner : null),
90
87
  tx.pure.u64(_commission.commissionBps),
88
+ tx.pure.u64(0),
91
89
  ],
92
90
  });
93
91
  if (!extendTx) {
94
92
  tx.transferObjects([mergeCoin], tx.pure.address(accountAddress));
95
93
  }
94
+ else {
95
+ coinOut = mergeCoin;
96
+ }
97
+ }
98
+ if (isBluefinX) {
99
+ const extra = quoteResponse.swaps[0].extra;
100
+ if (extra.quoteExpiresAtUtcMillis < Date.now()) {
101
+ throw new Error("Quote expired");
102
+ }
103
+ tx.setSenderIfNotSet(accountAddress);
104
+ const bytes = await tx.build({
105
+ client: config_1.Config.getSuiClient(),
106
+ onlyTransactionKind: true,
107
+ });
108
+ const res = await (0, client_1.sponsorBluefinX)({
109
+ quoteId: extra.quoteId,
110
+ txBytes: (0, utils_1.toBase64)(bytes),
111
+ sender: accountAddress,
112
+ });
113
+ if (!res.success) {
114
+ throw new Error("Sponsor failed");
115
+ }
116
+ return {
117
+ tx: new types_1.BluefinXTx(res.quoteId, res.data.txBytes),
118
+ coinOut,
119
+ };
96
120
  }
97
121
  return { tx, coinOut };
98
- });
122
+ };
99
123
  exports.buildTx = buildTx;
124
+ const getPythPriceFeeds = (res) => {
125
+ const ids = [];
126
+ for (const s of res.swaps) {
127
+ for (const o of s.extra?.oracles || []) {
128
+ const bytes = o.Pyth?.price_identifier?.bytes;
129
+ if (bytes) {
130
+ ids.push("0x" + (0, utils_1.toHex)(Uint8Array.from(bytes)));
131
+ }
132
+ }
133
+ }
134
+ return ids;
135
+ };
136
+ const updatePythPriceFeedsIfAny = async (tx, quoteResponse) => {
137
+ // update oracles price if any
138
+ const pythMap = {};
139
+ const pythIds = getPythPriceFeeds(quoteResponse);
140
+ if (pythIds.length > 0) {
141
+ const prices = await config_1.Config.getPythConnection().getPriceFeedsUpdateData(pythIds);
142
+ const ids = await config_1.Config.getPythClient().updatePriceFeeds(tx, prices, pythIds);
143
+ pythIds.map((id, index) => {
144
+ pythMap[id] = ids[index];
145
+ });
146
+ }
147
+ return pythMap;
148
+ };
@@ -1,20 +1,9 @@
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.DEFAULT_CONFIG = void 0;
13
4
  exports.getConfig = getConfig;
14
5
  const fetchClient_1 = require("../../config/fetchClient");
15
6
  const apiEndpoints_1 = require("../../constants/apiEndpoints");
16
- let config = null;
17
- let configTs = 0;
18
7
  exports.DEFAULT_CONFIG = {
19
8
  aftermath: {
20
9
  name: "Aftermath",
@@ -30,6 +19,11 @@ exports.DEFAULT_CONFIG = {
30
19
  package: "0x6c796c3ab3421a68158e0df18e4657b2827b1f8fed5ed4b82dba9c935988711b",
31
20
  globalConfig: "0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
32
21
  },
22
+ bluefinx: {
23
+ name: "BluefinX",
24
+ package: "0xf8870f988ab09be7c5820a856bd5e9da84fc7192e095a7a8829919293b00a36c",
25
+ globalConfig: "0xc6b29a60c3924776bedc78df72c127ea52b86aeb655432979a38f13d742dedaa",
26
+ },
33
27
  bluemove: {
34
28
  name: "Bluemove",
35
29
  package: "0x08cd33481587d4c4612865b164796d937df13747d8c763b8a178c87e3244498f",
@@ -40,10 +34,6 @@ exports.DEFAULT_CONFIG = {
40
34
  package: "0x6f5e582ede61fe5395b50c4a449ec11479a54d7ff8e0158247adfda60d98970b",
41
35
  globalConfig: "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",
42
36
  },
43
- deepbook: {
44
- name: "Deepbook",
45
- package: "0xdee9",
46
- },
47
37
  deepbook_v3: {
48
38
  name: "Deepbook V3",
49
39
  package: "",
@@ -96,28 +86,38 @@ exports.DEFAULT_CONFIG = {
96
86
  name: "Steamm",
97
87
  package: "0x4fb1cf45dffd6230305f1d269dd1816678cc8e3ba0b747a813a556921219f261",
98
88
  script: "0x13bfc09cfc1bd922d3aa53fcf7b2cd510727ee65068ce136e2ebd5f3b213fdd2",
89
+ oracle: "0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b",
99
90
  },
100
91
  magma: {
101
92
  name: "Magma",
102
93
  package: "0x951d48bece7f6c2a3f4ba0b5791ba823c491e504feb4136497ee51331208ac33",
103
94
  globalConfig: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
104
95
  },
96
+ haedal_pmm: {
97
+ name: "Haedal PMM",
98
+ package: "0xa0e3b011012b80af4957afa30e556486eb3da0a7d96eeb733cf16ccd3aec32e0",
99
+ },
100
+ momentum: {
101
+ name: "Momentum",
102
+ package: "0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860",
103
+ version: "0x2375a0b1ec12010aaea3b2545acfa2ad34cfbba03ce4b59f4c39e1e25eed1b2a",
104
+ },
105
105
  };
106
- function getConfig() {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const ttl = 60;
109
- if (config && Date.now() - configTs < ttl * 1000) {
110
- return config;
111
- }
112
- try {
113
- const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.MAIN}/config`);
114
- const quoteResponse = (yield response.json());
115
- config = quoteResponse;
116
- configTs = Date.now();
117
- return quoteResponse;
118
- }
119
- catch (_) {
120
- return exports.DEFAULT_CONFIG;
121
- }
122
- });
106
+ let config = exports.DEFAULT_CONFIG;
107
+ let configTs = 0;
108
+ async function getConfig() {
109
+ const ttl = 60;
110
+ if (config && Date.now() - configTs < ttl * 1000) {
111
+ return config;
112
+ }
113
+ try {
114
+ const response = await (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.MAIN}/config`);
115
+ const quoteResponse = (await response.json());
116
+ config = { ...config, ...quoteResponse };
117
+ configTs = Date.now();
118
+ return config;
119
+ }
120
+ catch (_) {
121
+ return exports.DEFAULT_CONFIG;
122
+ }
123
123
  }
@@ -1,54 +1,44 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.estimateGasFee = estimateGasFee;
16
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
17
4
  const utils_1 = require("@mysten/sui/utils");
18
- const buildTx_1 = require("./buildTx");
5
+ const config_1 = require("../../config");
6
+ const aggregator_1 = require("../../types/aggregator");
19
7
  const number_1 = require("../../utils/number");
20
8
  const prices_1 = require("../prices");
21
- const config_1 = require("../../config");
22
- function estimateGasFee(_a) {
23
- return __awaiter(this, arguments, void 0, function* ({ quoteResponse, accountAddress, slippage, suiPrice: _suiPrice, extendTx, commission, }) {
24
- if (!accountAddress)
25
- return 0;
26
- const result = yield (0, buildTx_1.buildTx)({
27
- extendTx,
28
- quoteResponse,
29
- accountAddress,
30
- slippage,
31
- commission,
32
- devInspect: true,
33
- }).catch((err) => {
34
- console.log("build tx error: ", err);
35
- return undefined;
36
- });
37
- const { tx } = result || {};
38
- if (!tx)
39
- return 0;
40
- const suiPrice = _suiPrice || (yield (0, prices_1.getSuiPrice)());
41
- const suiDecimals = utils_1.SUI_DECIMALS;
42
- const { effects: { gasUsed, status }, } = yield config_1.Config.getSuiClient().devInspectTransactionBlock({
43
- sender: accountAddress,
44
- transactionBlock: tx,
45
- });
46
- if (status.status !== "success")
47
- return 0;
48
- const fee = new bignumber_js_1.default(gasUsed.computationCost)
49
- .plus(gasUsed.storageCost)
50
- .minus(gasUsed.storageRebate);
51
- const feeUsd = new bignumber_js_1.default(suiPrice).multipliedBy((0, number_1.formatBalance)(fee, suiDecimals));
52
- return feeUsd.toNumber();
9
+ const buildTx_1 = require("./buildTx");
10
+ const types_1 = require("../../libs/protocols/bluefinx/types");
11
+ async function estimateGasFee({ quoteResponse, accountAddress, slippage, suiPrice: _suiPrice, extendTx, commission, }) {
12
+ if (!accountAddress)
13
+ return 0;
14
+ // BluefinX is sponsored, no need to estimate gas fee
15
+ if (!accountAddress || (0, aggregator_1.isBluefinXRouting)(quoteResponse))
16
+ return 0;
17
+ const result = await (0, buildTx_1.buildTx)({
18
+ extendTx,
19
+ quoteResponse,
20
+ accountAddress,
21
+ slippage,
22
+ commission,
23
+ devInspect: true,
24
+ }).catch((err) => {
25
+ console.log("build tx error: ", err);
26
+ return undefined;
27
+ });
28
+ const { tx } = result || {};
29
+ if (!tx || tx instanceof types_1.BluefinXTx)
30
+ return 0;
31
+ const suiPrice = _suiPrice || (await (0, prices_1.getSuiPrice)());
32
+ const suiDecimals = utils_1.SUI_DECIMALS;
33
+ const { effects: { gasUsed, status }, } = await config_1.Config.getSuiClient().devInspectTransactionBlock({
34
+ sender: accountAddress,
35
+ transactionBlock: tx,
53
36
  });
37
+ if (status.status !== "success")
38
+ return 0;
39
+ const fee = BigInt(gasUsed.computationCost) +
40
+ BigInt(gasUsed.storageCost) -
41
+ BigInt(gasUsed.storageRebate);
42
+ const feeUsd = Number(suiPrice) * Number((0, number_1.formatBalance)(fee, suiDecimals));
43
+ return feeUsd;
54
44
  }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeTx = void 0;
4
+ const config_1 = require("../../config");
5
+ const client_1 = require("../../libs/protocols/bluefinx/client");
6
+ const types_1 = require("../../libs/protocols/bluefinx/types");
7
+ /**
8
+ * Execute a transaction after it is signed
9
+ *
10
+ * Automatically handle BluefinX transaction execution if needed
11
+ * @example
12
+ * ```ts
13
+ * const { mutateAsync: signTransaction } = useSignTransaction();
14
+ * const quoteResponse = await getQuote(...quoteParams);
15
+ * const { tx } = await buildTx(...buildTxParams);
16
+ * const {signature, bytes} = await signTransaction({
17
+ * transaction: tx instanceof BluefinXTx ? tx.txBytes : tx,
18
+ * });
19
+ * const res = await executeTx(tx, signature, bytes);
20
+ * ```
21
+ * @param tx - AggregatorTx - received from `buildTx`
22
+ * @param signature - User signature after signing the transaction
23
+ * @param signedTxBytes - Signed transaction bytes after signing the transaction
24
+ * @param options - Options for the transaction
25
+ * @returns `SuiTransactionBlockResponse`
26
+ */
27
+ const executeTx = async (tx, signature, signedTxBytes, options) => {
28
+ const isBluefinTx = tx instanceof types_1.BluefinXTx;
29
+ const client = config_1.Config.getSuiClient();
30
+ let res;
31
+ if (isBluefinTx) {
32
+ try {
33
+ const result = await (0, client_1.executeBluefinTx)(tx, signature);
34
+ res = await client.waitForTransaction({
35
+ digest: result.txDigest,
36
+ options,
37
+ });
38
+ }
39
+ catch (e) {
40
+ throw Error(`Could not retrieve BluefinX transaction with quoteId: ${tx.quoteId} ${e}`);
41
+ }
42
+ }
43
+ else {
44
+ res = await client.executeTransactionBlock({
45
+ transactionBlock: signedTxBytes,
46
+ signature,
47
+ options,
48
+ });
49
+ }
50
+ return res;
51
+ };
52
+ exports.executeTx = executeTx;