@gmx-io/sdk 1.0.4 → 1.1.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 (190) hide show
  1. package/build/cjs/src/abis/ArbitrumNodeInterface.json +105 -0
  2. package/build/cjs/src/abis/CustomErrors.json +613 -16
  3. package/build/cjs/src/abis/ERC20PermitInterface.json +118 -0
  4. package/build/cjs/src/abis/GelatoRelayRouter.json +1426 -0
  5. package/build/cjs/src/abis/RelayParams.json +110 -0
  6. package/build/cjs/src/abis/SubaccountApproval.json +17 -0
  7. package/build/cjs/src/abis/SubaccountGelatoRelayRouter.json +1885 -0
  8. package/build/cjs/src/abis/SyntheticsReader.json +1 -131
  9. package/build/cjs/src/abis/__tests__/abis.spec.js +40 -0
  10. package/build/cjs/src/abis/index.js +8 -0
  11. package/build/cjs/src/configs/__tests__/permits.spec.js +109 -0
  12. package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -1
  13. package/build/cjs/src/configs/chains.js +36 -5
  14. package/build/cjs/src/configs/contracts.js +15 -3
  15. package/build/cjs/src/configs/dataStore.js +26 -4
  16. package/build/cjs/src/configs/express.js +35 -0
  17. package/build/cjs/src/configs/factors.js +4 -3
  18. package/build/cjs/src/configs/markets.js +28 -0
  19. package/build/cjs/src/configs/tokens.js +90 -0
  20. package/build/cjs/src/configs/twap.js +10 -0
  21. package/build/cjs/src/index.js +3 -3
  22. package/build/cjs/src/modules/markets/index.js +1 -0
  23. package/build/cjs/src/modules/markets/query-builders.js +4 -0
  24. package/build/cjs/src/modules/orders/helpers.js +2 -0
  25. package/build/cjs/src/modules/orders/orders.js +4 -3
  26. package/build/cjs/src/modules/utils/utils.js +11 -1
  27. package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +32 -0
  28. package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +323 -0
  29. package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +60 -0
  30. package/build/cjs/src/test/mock.js +30 -1
  31. package/build/cjs/src/types/twap.js +2 -0
  32. package/build/cjs/src/utils/__tests__/numbers.spec.js +217 -0
  33. package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +241 -0
  34. package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +595 -0
  35. package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +296 -0
  36. package/build/cjs/src/utils/__tests__/orderTransactions/externalCalls.spec.js +118 -0
  37. package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +762 -0
  38. package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +469 -0
  39. package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +80 -0
  40. package/build/cjs/src/utils/__tests__/parseError.spec.js +263 -0
  41. package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +45 -0
  42. package/build/cjs/src/utils/bigmath.js +3 -0
  43. package/build/cjs/src/utils/callContract.js +2 -2
  44. package/build/cjs/src/utils/errors/index.js +18 -0
  45. package/build/cjs/src/utils/errors/parseError.js +150 -0
  46. package/build/cjs/src/utils/{contracts.js → errors/transactionsErrors.js} +35 -3
  47. package/build/cjs/src/utils/fees/executionFee.js +52 -1
  48. package/build/cjs/src/utils/fees/index.js +8 -4
  49. package/build/cjs/src/utils/gelatoRelay.js +5 -0
  50. package/build/cjs/src/utils/hash.js +6 -1
  51. package/build/cjs/src/utils/marketKeysAndConfigs.js +4 -0
  52. package/build/cjs/src/utils/markets.js +5 -1
  53. package/build/cjs/src/utils/numbers.js +559 -5
  54. package/build/cjs/src/utils/orderTransactions.js +638 -0
  55. package/build/cjs/src/utils/orders.js +7 -1
  56. package/build/cjs/src/utils/simulateExecuteOrder.js +6 -2
  57. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +11 -6
  58. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +4 -4
  59. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +9 -0
  60. package/build/cjs/src/utils/swap/swapPath.js +30 -13
  61. package/build/cjs/src/utils/swap/swapRouting.js +4 -2
  62. package/build/cjs/src/utils/swap/swapStats.js +6 -5
  63. package/build/cjs/src/utils/testUtil.js +1 -1
  64. package/build/cjs/src/utils/time.js +30 -0
  65. package/build/cjs/src/utils/tokens.js +16 -2
  66. package/build/cjs/src/utils/twap/index.js +53 -0
  67. package/build/cjs/src/utils/twap/uiFeeReceiver.js +31 -0
  68. package/build/cjs/src/utils/types.js +13 -0
  69. package/build/esm/src/abis/ArbitrumNodeInterface.json +105 -0
  70. package/build/esm/src/abis/CustomErrors.json +613 -16
  71. package/build/esm/src/abis/ERC20PermitInterface.json +118 -0
  72. package/build/esm/src/abis/GelatoRelayRouter.json +1426 -0
  73. package/build/esm/src/abis/RelayParams.json +110 -0
  74. package/build/esm/src/abis/SubaccountApproval.json +17 -0
  75. package/build/esm/src/abis/SubaccountGelatoRelayRouter.json +1885 -0
  76. package/build/esm/src/abis/SyntheticsReader.json +1 -131
  77. package/build/esm/src/abis/__tests__/abis.spec.js +35 -0
  78. package/build/esm/src/abis/index.js +8 -0
  79. package/build/esm/src/configs/__tests__/permits.spec.js +107 -0
  80. package/build/esm/src/configs/__tests__/tokens.spec.js +3 -3
  81. package/build/esm/src/configs/chains.js +33 -3
  82. package/build/esm/src/configs/contracts.js +15 -3
  83. package/build/esm/src/configs/dataStore.js +19 -1
  84. package/build/esm/src/configs/express.js +29 -0
  85. package/build/esm/src/configs/factors.js +1 -3
  86. package/build/esm/src/configs/markets.js +28 -0
  87. package/build/esm/src/configs/tokens.js +90 -0
  88. package/build/esm/src/configs/twap.js +7 -0
  89. package/build/esm/src/index.js +4 -4
  90. package/build/esm/src/modules/markets/index.js +1 -0
  91. package/build/esm/src/modules/markets/query-builders.js +4 -0
  92. package/build/esm/src/modules/orders/helpers.js +2 -0
  93. package/build/esm/src/modules/orders/orders.js +4 -3
  94. package/build/esm/src/modules/utils/utils.js +13 -3
  95. package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +32 -0
  96. package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +323 -0
  97. package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +60 -0
  98. package/build/esm/src/test/mock.js +28 -0
  99. package/build/esm/src/types/twap.js +1 -0
  100. package/build/esm/src/utils/__tests__/numbers.spec.js +219 -2
  101. package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +239 -0
  102. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +593 -0
  103. package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +294 -0
  104. package/build/esm/src/utils/__tests__/orderTransactions/externalCalls.spec.js +116 -0
  105. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +760 -0
  106. package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +467 -0
  107. package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +78 -0
  108. package/build/esm/src/utils/__tests__/parseError.spec.js +261 -0
  109. package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +43 -0
  110. package/build/esm/src/utils/bigmath.js +3 -0
  111. package/build/esm/src/utils/callContract.js +3 -3
  112. package/build/esm/src/utils/errors/index.js +2 -0
  113. package/build/esm/src/utils/errors/parseError.js +141 -0
  114. package/build/esm/src/utils/{contracts.js → errors/transactionsErrors.js} +30 -1
  115. package/build/esm/src/utils/fees/executionFee.js +48 -1
  116. package/build/esm/src/utils/fees/index.js +8 -4
  117. package/build/esm/src/utils/gelatoRelay.js +2 -0
  118. package/build/esm/src/utils/hash.js +5 -1
  119. package/build/esm/src/utils/marketKeysAndConfigs.js +5 -1
  120. package/build/esm/src/utils/markets.js +3 -0
  121. package/build/esm/src/utils/numbers.js +516 -1
  122. package/build/esm/src/utils/orderTransactions.js +607 -0
  123. package/build/esm/src/utils/orders.js +5 -0
  124. package/build/esm/src/utils/simulateExecuteOrder.js +6 -2
  125. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +11 -6
  126. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +4 -4
  127. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +9 -0
  128. package/build/esm/src/utils/swap/swapPath.js +30 -13
  129. package/build/esm/src/utils/swap/swapRouting.js +4 -2
  130. package/build/esm/src/utils/swap/swapStats.js +6 -5
  131. package/build/esm/src/utils/testUtil.js +2 -2
  132. package/build/esm/src/utils/time.js +23 -0
  133. package/build/esm/src/utils/tokens.js +14 -1
  134. package/build/esm/src/utils/twap/index.js +44 -0
  135. package/build/esm/src/utils/twap/uiFeeReceiver.js +24 -0
  136. package/build/esm/src/utils/types.js +8 -0
  137. package/build/types/src/abis/__tests__/abis.spec.d.ts +1 -0
  138. package/build/types/src/abis/index.d.ts +1 -1
  139. package/build/types/src/configs/__tests__/permits.spec.d.ts +1 -0
  140. package/build/types/src/configs/chains.d.ts +29 -1
  141. package/build/types/src/configs/contracts.d.ts +238 -1
  142. package/build/types/src/configs/dataStore.d.ts +10 -0
  143. package/build/types/src/configs/express.d.ts +12 -0
  144. package/build/types/src/configs/factors.d.ts +1 -3
  145. package/build/types/src/configs/tokens.d.ts +2 -2
  146. package/build/types/src/configs/twap.d.ts +7 -0
  147. package/build/types/src/modules/markets/query-builders.d.ts +1 -1
  148. package/build/types/src/modules/markets/types.d.ts +2 -2
  149. package/build/types/src/modules/orders/orders.d.ts +2 -1
  150. package/build/types/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -1
  151. package/build/types/src/test/mock.d.ts +16 -1
  152. package/build/types/src/types/fees.d.ts +9 -0
  153. package/build/types/src/types/markets.d.ts +1 -0
  154. package/build/types/src/types/orders.d.ts +3 -0
  155. package/build/types/src/types/tokens.d.ts +27 -0
  156. package/build/types/src/types/trade.d.ts +2 -19
  157. package/build/types/src/types/twap.d.ts +11 -0
  158. package/build/types/src/utils/__tests__/orderTransactions/batchUtils.spec.d.ts +1 -0
  159. package/build/types/src/utils/__tests__/orderTransactions/decreaseOrders.spec.d.ts +1 -0
  160. package/build/types/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.d.ts +1 -0
  161. package/build/types/src/utils/__tests__/orderTransactions/externalCalls.spec.d.ts +1 -0
  162. package/build/types/src/utils/__tests__/orderTransactions/increaseOrders.spec.d.ts +1 -0
  163. package/build/types/src/utils/__tests__/orderTransactions/swapOrders.spec.d.ts +1 -0
  164. package/build/types/src/utils/__tests__/orderTransactions/updateOrder.spec.d.ts +1 -0
  165. package/build/types/src/utils/__tests__/parseError.spec.d.ts +1 -0
  166. package/build/types/src/utils/__tests__/uiFeeReceiver.spec.d.ts +1 -0
  167. package/build/types/src/utils/bigmath.d.ts +1 -0
  168. package/build/types/src/utils/errors/index.d.ts +2 -0
  169. package/build/types/src/utils/errors/parseError.d.ts +50 -0
  170. package/build/types/src/utils/errors/transactionsErrors.d.ts +34 -0
  171. package/build/types/src/utils/fees/executionFee.d.ts +35 -2
  172. package/build/types/src/utils/fees/index.d.ts +1 -1
  173. package/build/types/src/utils/gelatoRelay.d.ts +2 -0
  174. package/build/types/src/utils/hash.d.ts +2 -0
  175. package/build/types/src/utils/marketKeysAndConfigs.d.ts +1 -0
  176. package/build/types/src/utils/markets.d.ts +1 -0
  177. package/build/types/src/utils/numbers.d.ts +110 -1
  178. package/build/types/src/utils/orderTransactions.d.ts +231 -0
  179. package/build/types/src/utils/orders.d.ts +2 -1
  180. package/build/types/src/utils/simulateExecuteOrder.d.ts +4 -0
  181. package/build/types/src/utils/swap/swapPath.d.ts +5 -5
  182. package/build/types/src/utils/swap/swapRouting.d.ts +2 -2
  183. package/build/types/src/utils/swap/swapStats.d.ts +2 -0
  184. package/build/types/src/utils/time.d.ts +14 -0
  185. package/build/types/src/utils/tokens.d.ts +6 -5
  186. package/build/types/src/utils/twap/index.d.ts +17 -0
  187. package/build/types/src/utils/twap/uiFeeReceiver.d.ts +9 -0
  188. package/build/types/src/utils/types.d.ts +5 -0
  189. package/package.json +3 -1
  190. package/build/types/src/utils/contracts.d.ts +0 -19
@@ -0,0 +1,261 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { parseError } from "../errors";
3
+ import { TxErrorType } from "../errors/transactionsErrors";
4
+ describe("parseError", () => {
5
+ describe("general errors", () => {
6
+ it("should handle basic Error objects", () => {
7
+ const error = new Error("Something went wrong");
8
+ const result = parseError(error);
9
+ expect(result).toEqual(expect.objectContaining({
10
+ errorMessage: "Something went wrong",
11
+ errorName: "Error",
12
+ errorGroup: "Something went wrong",
13
+ errorStack: error.stack,
14
+ errorStackHash: expect.any(String),
15
+ errorDepth: 0,
16
+ }));
17
+ });
18
+ it("should handle string errors", () => {
19
+ const result = parseError("API request failed");
20
+ expect(result).toEqual(expect.objectContaining({
21
+ errorMessage: "API request failed",
22
+ errorGroup: "API request failed",
23
+ errorStackGroup: "Unknown stack group",
24
+ errorDepth: 0,
25
+ }));
26
+ });
27
+ it("should handle nested errors with context", () => {
28
+ const error = {
29
+ message: "Order execution failed",
30
+ errorContext: "simulation",
31
+ info: {
32
+ error: {
33
+ message: "Price impact too high",
34
+ name: "ValidationError",
35
+ },
36
+ },
37
+ };
38
+ const result = parseError(error);
39
+ expect(result).toEqual(expect.objectContaining({
40
+ errorMessage: "Price impact too high",
41
+ errorName: "ValidationError",
42
+ errorContext: "simulation",
43
+ errorDepth: 0,
44
+ }));
45
+ });
46
+ it("should handle undefined errors", () => {
47
+ const result = parseError(undefined);
48
+ expect(result).toEqual(expect.objectContaining({
49
+ errorMessage: "undefined",
50
+ errorGroup: "undefined",
51
+ errorDepth: 0,
52
+ }));
53
+ });
54
+ describe("error masking", () => {
55
+ it("should mask URLs in error groups", () => {
56
+ const error = new Error("Failed to fetch data from https://api.example.com:8080/v1/data?param=123");
57
+ const result = parseError(error);
58
+ expect(result).toEqual(expect.objectContaining({
59
+ errorMessage: "Failed to fetch data from https://api.example.com:8080/v1/data?param=123",
60
+ errorGroup: "Failed to fetch data from https://api.example.com:",
61
+ errorDepth: 0,
62
+ }));
63
+ });
64
+ it("should mask numbers in error groups", () => {
65
+ const error = new Error("Transaction failed with gas 123456 at block 789012");
66
+ const result = parseError(error);
67
+ expect(result).toEqual(expect.objectContaining({
68
+ errorMessage: "Transaction failed with gas 123456 at block 789012",
69
+ errorGroup: "Transaction failed with gas XXX at block XXX",
70
+ errorDepth: 0,
71
+ }));
72
+ });
73
+ it("should mask both URLs and numbers in error groups", () => {
74
+ const error = new Error("Failed https://api.example.com/v1/tx/123456 with status 404 and error code E123");
75
+ const result = parseError(error);
76
+ expect(result).toEqual(expect.objectContaining({
77
+ errorMessage: "Failed https://api.example.com/v1/tx/123456 with status 404 and error code E123",
78
+ errorGroup: "Failed https://api.example.com with status XXX an",
79
+ errorDepth: 0,
80
+ }));
81
+ });
82
+ it("should mask URLs in stack traces", () => {
83
+ const error = new Error("Processing failed");
84
+ // Simulate a stack trace with URLs
85
+ error.stack = `Error: Processing failed
86
+ at processData (https://app.example.com/static/js/main.123456.js:12:34)
87
+ at handleRequest (https://app.example.com/static/js/vendor.789012.js:56:78)`;
88
+ const result = parseError(error);
89
+ expect(result?.errorStackGroup).toBe(`Error: Processing failed
90
+ at processData (https://app.example.com)
91
+ at handleRequest (https://app.example.com)`);
92
+ });
93
+ });
94
+ });
95
+ describe("transaction errors", () => {
96
+ it("should handle ethers v6 user rejected error", () => {
97
+ const error = {
98
+ info: {
99
+ error: {
100
+ code: "ACTION_REJECTED",
101
+ message: "User denied transaction signature",
102
+ },
103
+ },
104
+ };
105
+ const result = parseError(error);
106
+ expect(result).toEqual(expect.objectContaining({
107
+ errorMessage: "User denied transaction signature",
108
+ txErrorType: TxErrorType.UserDenied,
109
+ isUserError: true,
110
+ isUserRejectedError: true,
111
+ errorGroup: "Txn Error: USER_DENIED",
112
+ }));
113
+ });
114
+ it("should handle ethers v6 insufficient funds error", () => {
115
+ const error = {
116
+ info: {
117
+ error: {
118
+ message: "insufficient funds for gas",
119
+ },
120
+ },
121
+ };
122
+ const result = parseError(error);
123
+ expect(result).toEqual(expect.objectContaining({
124
+ errorMessage: "insufficient funds for gas",
125
+ txErrorType: TxErrorType.NotEnoughFunds,
126
+ isUserError: true,
127
+ isUserRejectedError: false,
128
+ errorGroup: "Txn Error: NOT_ENOUGH_FUNDS",
129
+ }));
130
+ });
131
+ it("should handle RPC errors with code", () => {
132
+ const error = {
133
+ info: {
134
+ error: {
135
+ code: -32603,
136
+ message: "Internal JSON-RPC error",
137
+ },
138
+ },
139
+ };
140
+ const result = parseError(error);
141
+ expect(result).toEqual(expect.objectContaining({
142
+ errorMessage: "Internal JSON-RPC error",
143
+ txErrorType: TxErrorType.RpcError,
144
+ isUserError: false,
145
+ isUserRejectedError: false,
146
+ errorGroup: "Txn Error: RPC_ERROR",
147
+ }));
148
+ });
149
+ it("should handle nested error in error.body", () => {
150
+ const error = {
151
+ info: {
152
+ error: {
153
+ message: JSON.stringify({
154
+ error: {
155
+ code: -32000,
156
+ message: "Invalid input parameters",
157
+ },
158
+ }),
159
+ },
160
+ },
161
+ };
162
+ const result = parseError(error);
163
+ expect(result).toEqual(expect.objectContaining({
164
+ errorMessage: JSON.stringify({
165
+ error: {
166
+ code: -32000,
167
+ message: "Invalid input parameters",
168
+ },
169
+ }),
170
+ errorGroup: '{"error":{"code":-XXX,"message":"Invalid input par',
171
+ errorStackGroup: "Unknown stack group",
172
+ errorDepth: 0,
173
+ isUserError: false,
174
+ isUserRejectedError: false,
175
+ }));
176
+ });
177
+ it("should handle contract errors with data", () => {
178
+ const error = {
179
+ message: "execution reverted",
180
+ data: "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001a4f726465724e6f7446756c66696c6c61626c6541744c696d697400000000000000",
181
+ };
182
+ const result = parseError(error);
183
+ expect(result).toEqual(expect.objectContaining({
184
+ errorMessage: "execution reverted",
185
+ errorGroup: "execution reverted",
186
+ errorStackGroup: "Unknown stack group",
187
+ txErrorData: "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001a4f726465724e6f7446756c66696c6c61626c6541744c696d697400000000000000",
188
+ isUserError: false,
189
+ isUserRejectedError: false,
190
+ }));
191
+ });
192
+ it("should handle parent errors", () => {
193
+ const error = {
194
+ message: "Failed to execute transaction",
195
+ parentError: {
196
+ message: "User denied transaction signature",
197
+ info: {
198
+ error: {
199
+ code: "ACTION_REJECTED",
200
+ },
201
+ },
202
+ },
203
+ };
204
+ const result = parseError(error);
205
+ expect(result).toEqual(expect.objectContaining({
206
+ errorMessage: "Failed to execute transaction",
207
+ errorGroup: "Failed to execute transaction",
208
+ errorStackGroup: "Unknown stack group",
209
+ isUserError: false,
210
+ isUserRejectedError: false,
211
+ parentError: expect.objectContaining({
212
+ errorMessage: undefined,
213
+ errorGroup: "Unknown group",
214
+ errorStackGroup: "Unknown stack group",
215
+ errorDepth: 1,
216
+ isUserError: false,
217
+ isUserRejectedError: false,
218
+ }),
219
+ }));
220
+ });
221
+ it("should handle slippage errors", () => {
222
+ const error = {
223
+ message: "Router: mark price lower than limit",
224
+ };
225
+ const result = parseError(error);
226
+ expect(result).toEqual(expect.objectContaining({
227
+ errorMessage: "Router: mark price lower than limit",
228
+ txErrorType: TxErrorType.Slippage,
229
+ isUserError: false,
230
+ errorGroup: "Txn Error: SLIPPAGE",
231
+ }));
232
+ });
233
+ it("should handle network change errors", () => {
234
+ const error = {
235
+ message: "network changed",
236
+ };
237
+ const result = parseError(error);
238
+ expect(result).toEqual(expect.objectContaining({
239
+ errorMessage: "network changed",
240
+ txErrorType: TxErrorType.NetworkChanged,
241
+ isUserError: true,
242
+ errorGroup: "Txn Error: NETWORK_CHANGED",
243
+ }));
244
+ });
245
+ it("should handle additional validation info", () => {
246
+ const error = {
247
+ message: "Transaction failed",
248
+ errorSource: "getCallStaticError",
249
+ isAdditionalValidationPassed: false,
250
+ additionalValidationType: "tryCallStatic",
251
+ };
252
+ const result = parseError(error);
253
+ expect(result).toEqual(expect.objectContaining({
254
+ errorMessage: "Transaction failed",
255
+ errorSource: "getCallStaticError",
256
+ isAdditionalValidationPassed: false,
257
+ additionalValidationType: "tryCallStatic",
258
+ }));
259
+ });
260
+ });
261
+ });
@@ -0,0 +1,43 @@
1
+ import { isAddress } from "viem";
2
+ import { describe, it, expect } from "vitest";
3
+ import { createTwapUiFeeReceiver, decodeTwapUiFeeReceiver } from "../twap/uiFeeReceiver";
4
+ describe("uiFeeReceiver", () => {
5
+ describe("decodeTwapUiFeeReceiver", () => {
6
+ it("should return undefined if the address is not a valid address", () => {
7
+ expect(decodeTwapUiFeeReceiver("0x1234567890123456789012345678901234567890")).toBeUndefined();
8
+ expect(decodeTwapUiFeeReceiver("0xffffff")).toBeUndefined();
9
+ expect(decodeTwapUiFeeReceiver("")).toBeUndefined();
10
+ });
11
+ it("should return undefined if twapId inside is 0000", () => {
12
+ expect(decodeTwapUiFeeReceiver("0xff00000000000000000000000000000000000001")).toBeUndefined();
13
+ });
14
+ it("should return the twapId and numberOfParts if the uiFeeReceiver is valid twap", () => {
15
+ expect(decodeTwapUiFeeReceiver("0xff0000000000000000000000000000000a123401")).toEqual({
16
+ twapId: "1234",
17
+ numberOfParts: 10,
18
+ });
19
+ expect(decodeTwapUiFeeReceiver("0xff000000000000000000000000000000153a4f01")).toEqual({
20
+ twapId: "3a4f",
21
+ numberOfParts: 21,
22
+ });
23
+ });
24
+ });
25
+ describe("createTwapUiFeeReceiver", () => {
26
+ it("should create a valid address", () => {
27
+ expect(isAddress(createTwapUiFeeReceiver({ numberOfParts: 10 }))).toBeTruthy();
28
+ });
29
+ it("should correctly encode numberOfParts", () => {
30
+ expect(decodeTwapUiFeeReceiver(createTwapUiFeeReceiver({ numberOfParts: 10 }))?.numberOfParts).toEqual(10);
31
+ expect(decodeTwapUiFeeReceiver(createTwapUiFeeReceiver({ numberOfParts: 21 }))?.numberOfParts).toEqual(21);
32
+ });
33
+ it("should correctly encode twapId with length 4", () => {
34
+ expect(decodeTwapUiFeeReceiver(createTwapUiFeeReceiver({ numberOfParts: 10 }))?.twapId).toHaveLength(4);
35
+ expect(decodeTwapUiFeeReceiver(createTwapUiFeeReceiver({ numberOfParts: 10 }))?.twapId).toHaveLength(4);
36
+ expect(decodeTwapUiFeeReceiver(createTwapUiFeeReceiver({ numberOfParts: 21 }))?.twapId).toHaveLength(4);
37
+ });
38
+ it("should correctly encode twapId as hex", () => {
39
+ expect(parseInt(decodeTwapUiFeeReceiver(createTwapUiFeeReceiver({ numberOfParts: 10 }))?.twapId ?? "", 16)).not.toBeNaN();
40
+ expect(parseInt(decodeTwapUiFeeReceiver(createTwapUiFeeReceiver({ numberOfParts: 21 }))?.twapId ?? "", 16)).not.toBeNaN();
41
+ });
42
+ });
43
+ });
@@ -28,4 +28,7 @@ export const bigMath = {
28
28
  divRound(x, y) {
29
29
  return x / y + ((x % y) * 2n > y ? 1n : 0n);
30
30
  },
31
+ divRoundUp(x, y) {
32
+ return (x + y - 1n) / y;
33
+ },
31
34
  };
@@ -1,5 +1,5 @@
1
1
  import { encodeFunctionData, withRetry } from "viem";
2
- import { GAS_PRICE_BUFFER_MAP, GAS_PRICE_PREMIUM_MAP, getChain, MAX_FEE_PER_GAS_MAP, MAX_PRIORITY_FEE_PER_GAS_MAP, } from "../configs/chains";
2
+ import { GAS_PRICE_BUFFER_MAP, GAS_PRICE_PREMIUM_MAP, getViemChain, MAX_FEE_PER_GAS_MAP, MAX_PRIORITY_FEE_PER_GAS_MAP, } from "../configs/chains";
3
3
  import { BASIS_POINTS_DIVISOR_BIGINT } from "../configs/factors";
4
4
  import { bigMath } from "./bigmath";
5
5
  export async function getGasPrice(client, chainId) {
@@ -7,7 +7,7 @@ export async function getGasPrice(client, chainId) {
7
7
  const premium = GAS_PRICE_PREMIUM_MAP[chainId] || 0n;
8
8
  const feeData = await withRetry(() => client.estimateFeesPerGas({
9
9
  type: "legacy",
10
- chain: getChain(chainId),
10
+ chain: getViemChain(chainId),
11
11
  }), {
12
12
  delay: 200,
13
13
  retryCount: 2,
@@ -85,7 +85,7 @@ export async function getGasLimit(client, account, contractAddress, abi, method,
85
85
  }
86
86
  export async function callContract(sdk, contractAddress, abi, method, params, opts = {}) {
87
87
  const txnOpts = {};
88
- const chain = getChain(sdk.chainId);
88
+ const chain = getViemChain(sdk.chainId);
89
89
  if (opts.value) {
90
90
  txnOpts.value = BigInt(opts.value);
91
91
  }
@@ -0,0 +1,2 @@
1
+ export * from "./parseError";
2
+ export * from "./transactionsErrors";
@@ -0,0 +1,141 @@
1
+ import cryptoJs from "crypto-js";
2
+ import { decodeErrorResult } from "viem";
3
+ import { abis } from "../../abis";
4
+ import { extractDataFromError, extractTxnError, getIsUserError, getIsUserRejectedError, } from "./transactionsErrors";
5
+ const URL_REGEXP = /((?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\\+~#=]{2,256}\.[a-z]{2,6}\b(?::\d+)?)(?:[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]*)/gi;
6
+ const MAX_ERRORS_DEPTH = 1;
7
+ export function extendError(error, params) {
8
+ error.errorContext = params.errorContext;
9
+ error.errorSource = params.errorSource;
10
+ error.isAdditionalValidationPassed = params.isAdditionalValidationPassed;
11
+ error.additionalValidationType = params.additionalValidationType;
12
+ error.data = params.data;
13
+ return error;
14
+ }
15
+ export function parseError(error, errorDepth = 0) {
16
+ if (errorDepth > MAX_ERRORS_DEPTH) {
17
+ return undefined;
18
+ }
19
+ // all human readable details are in info field
20
+ const errorInfo = typeof error === "string" ? undefined : error?.info?.error;
21
+ const errorSource = typeof error === "string" ? undefined : error?.errorSource;
22
+ const errorContext = typeof error === "string" ? undefined : error?.errorContext;
23
+ const isAdditionalValidationPassed = typeof error === "string" ? undefined : error?.isAdditionalValidationPassed;
24
+ const additionalValidationType = typeof error === "string" ? undefined : error?.additionalValidationType;
25
+ const data = typeof error === "string" ? undefined : error?.data;
26
+ let errorMessage = "Unknown error";
27
+ let errorStack = undefined;
28
+ let errorStackHash = undefined;
29
+ let errorName = undefined;
30
+ let contractError = undefined;
31
+ let contractErrorArgs = undefined;
32
+ let txErrorType = undefined;
33
+ let errorGroup = "Unknown group";
34
+ let errorStackGroup = "Unknown stack group";
35
+ let txErrorData = undefined;
36
+ let isUserError = undefined;
37
+ let isUserRejectedError = undefined;
38
+ let parentError = undefined;
39
+ try {
40
+ errorMessage = hasMessage(errorInfo)
41
+ ? errorInfo.message ?? (hasMessage(error) ? error.message : String(error))
42
+ : String(error);
43
+ errorStack = hasStack(error) ? error.stack : undefined;
44
+ if (hasName(errorInfo)) {
45
+ errorName = errorInfo.name;
46
+ }
47
+ else if (hasName(error)) {
48
+ errorName = error.name;
49
+ }
50
+ try {
51
+ let txError;
52
+ if (errorInfo) {
53
+ txError = extractTxnError(errorInfo);
54
+ }
55
+ else if (error && typeof error === "object") {
56
+ txError = extractTxnError(error);
57
+ }
58
+ if (txError && txError.length) {
59
+ const [message, type, errorData] = txError;
60
+ errorMessage = message;
61
+ txErrorType = type || undefined;
62
+ txErrorData = errorData;
63
+ isUserError = type ? getIsUserError(type) : false;
64
+ isUserRejectedError = type ? getIsUserRejectedError(type) : false;
65
+ }
66
+ }
67
+ catch (e) {
68
+ //
69
+ }
70
+ if (errorMessage) {
71
+ const errorData = extractDataFromError(errorMessage) ?? extractDataFromError(error?.message);
72
+ if (errorData) {
73
+ const parsedError = decodeErrorResult({
74
+ abi: abis.CustomErrors,
75
+ data: errorData,
76
+ });
77
+ if (parsedError) {
78
+ contractError = parsedError.errorName;
79
+ contractErrorArgs = parsedError.args;
80
+ }
81
+ }
82
+ }
83
+ if (typeof error !== "string" && error?.parentError) {
84
+ parentError = parseError(error.parentError, errorDepth + 1);
85
+ }
86
+ }
87
+ catch (e) {
88
+ //
89
+ }
90
+ if (errorStack) {
91
+ errorStackHash = cryptoJs.SHA256(errorStack).toString(cryptoJs.enc.Hex);
92
+ errorStackGroup = errorStack.slice(0, 300);
93
+ errorStackGroup = errorStackGroup.replace(URL_REGEXP, "$1");
94
+ errorStackGroup = errorStackGroup.replace(/\d+/g, "XXX");
95
+ }
96
+ if (txErrorType) {
97
+ errorGroup = `Txn Error: ${txErrorType}`;
98
+ }
99
+ else if (errorMessage) {
100
+ errorGroup = errorMessage.slice(0, 300);
101
+ errorGroup = errorGroup.replace(URL_REGEXP, "$1");
102
+ errorGroup = errorGroup.replace(/\d+/g, "XXX");
103
+ errorGroup = errorGroup.slice(0, 50);
104
+ }
105
+ else if (errorName) {
106
+ errorGroup = errorName;
107
+ }
108
+ return {
109
+ errorMessage,
110
+ errorGroup,
111
+ errorStackGroup,
112
+ errorStack,
113
+ errorStackHash,
114
+ errorName,
115
+ contractError,
116
+ contractErrorArgs,
117
+ errorContext,
118
+ isUserError,
119
+ data,
120
+ isUserRejectedError,
121
+ txErrorType,
122
+ txErrorData,
123
+ errorSource,
124
+ parentError,
125
+ isAdditionalValidationPassed,
126
+ additionalValidationType,
127
+ errorDepth,
128
+ };
129
+ }
130
+ export function isContractError(error, errorType) {
131
+ return error.contractError === errorType;
132
+ }
133
+ function hasMessage(error) {
134
+ return !!error && typeof error === "object" && typeof error.message === "string";
135
+ }
136
+ function hasStack(error) {
137
+ return !!error && typeof error === "object" && typeof error.stack === "string";
138
+ }
139
+ function hasName(error) {
140
+ return !!error && typeof error === "object" && typeof error.name === "string";
141
+ }
@@ -49,7 +49,23 @@ const TX_ERROR_PATTERNS = {
49
49
  { msg: "couldn't connect to the network" },
50
50
  ],
51
51
  };
52
- export function extractError(ex) {
52
+ export var CustomErrorName;
53
+ (function (CustomErrorName) {
54
+ CustomErrorName["EndOfOracleSimulation"] = "EndOfOracleSimulation";
55
+ CustomErrorName["InsufficientExecutionFee"] = "InsufficientExecutionFee";
56
+ CustomErrorName["OrderNotFulfillableAtAcceptablePrice"] = "OrderNotFulfillableAtAcceptablePrice";
57
+ CustomErrorName["InsufficientSwapOutputAmount"] = "InsufficientSwapOutputAmount";
58
+ })(CustomErrorName || (CustomErrorName = {}));
59
+ export function getIsUserRejectedError(errorType) {
60
+ return errorType === TxErrorType.UserDenied;
61
+ }
62
+ export function getIsUserError(errorType) {
63
+ return [TxErrorType.UserDenied, TxErrorType.NetworkChanged, TxErrorType.Expired, TxErrorType.NotEnoughFunds].includes(errorType);
64
+ }
65
+ /**
66
+ * @deprecated Use `parseError` instead.
67
+ */
68
+ export function extractTxnError(ex) {
53
69
  if (!ex) {
54
70
  return [];
55
71
  }
@@ -87,3 +103,16 @@ export function extractError(ex) {
87
103
  }
88
104
  return [message, null, ex.data];
89
105
  }
106
+ /**
107
+ * @deprecated Use `parseError` instead.
108
+ */
109
+ export function extractDataFromError(errorMessage) {
110
+ if (typeof errorMessage !== "string")
111
+ return null;
112
+ const pattern = /data="([^"]+)"/;
113
+ const match = errorMessage.match(pattern);
114
+ if (match && match[1]) {
115
+ return match[1];
116
+ }
117
+ return null;
118
+ }
@@ -3,7 +3,7 @@ import { USD_DECIMALS } from "../../configs/factors";
3
3
  import { NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
4
4
  import { DecreasePositionSwapType } from "../../types/orders";
5
5
  import { applyFactor, expandDecimals } from "../numbers";
6
- import { convertToUsd, getTokenData } from "../tokens";
6
+ import { convertBetweenTokens, convertToUsd, getTokenData } from "../tokens";
7
7
  export function getExecutionFee(chainId, gasLimits,
8
8
  // TODO optimize we only need the native token data
9
9
  tokensData, estimatedGasLimit, gasPrice, oraclePriceCount, numberOfParts) {
@@ -29,6 +29,53 @@ tokensData, estimatedGasLimit, gasPrice, oraclePriceCount, numberOfParts) {
29
29
  isFeeVeryHigh,
30
30
  };
31
31
  }
32
+ export function estimateRelayerGasLimit({ gasLimits, tokenPermitsCount, feeSwapsCount, feeExternalCallsGasLimit, oraclePriceCount, transactionPayloadGasLimit, l1GasLimit, }) {
33
+ const feeSwapsGasLimit = gasLimits.singleSwap * BigInt(feeSwapsCount);
34
+ const oraclePricesGasLimit = gasLimits.estimatedGasFeePerOraclePrice * BigInt(oraclePriceCount);
35
+ const tokenPermitsGasLimit = gasLimits.tokenPermitGasLimit * BigInt(tokenPermitsCount);
36
+ const relayParamsGasLimit = feeSwapsGasLimit + oraclePricesGasLimit + tokenPermitsGasLimit + feeExternalCallsGasLimit;
37
+ return relayParamsGasLimit + transactionPayloadGasLimit + l1GasLimit;
38
+ }
39
+ export function approximateL1GasBuffer({ l1Reference, sizeOfData, }) {
40
+ const evaluated = Math.round((Number(l1Reference.gasLimit) * Math.log(Number(sizeOfData))) / Math.log(Number(l1Reference.sizeOfData)));
41
+ const l1GasLimit = Math.abs(evaluated) < Infinity ? BigInt(evaluated) : l1Reference.gasLimit;
42
+ return l1GasLimit;
43
+ }
44
+ export function estimateBatchGasLimit({ gasLimits, createOrdersCount, updateOrdersCount, cancelOrdersCount, externalCallsGasLimit, }) {
45
+ const createOrdersGasLimit = gasLimits.createOrderGasLimit * BigInt(createOrdersCount);
46
+ const updateOrdersGasLimit = gasLimits.updateOrderGasLimit * BigInt(updateOrdersCount);
47
+ const cancelOrdersGasLimit = gasLimits.cancelOrderGasLimit * BigInt(cancelOrdersCount);
48
+ return createOrdersGasLimit + updateOrdersGasLimit + cancelOrdersGasLimit + externalCallsGasLimit;
49
+ }
50
+ export function estimateBatchMinGasPaymentTokenAmount({ chainId, gasPaymentToken, relayFeeToken, gasPrice, gasLimits, l1Reference, tokensData, createOrdersCount = 1, updateOrdersCount = 0, cancelOrdersCount = 0, executionFeeAmount, }) {
51
+ const batchGasLimit = estimateBatchGasLimit({
52
+ gasLimits,
53
+ createOrdersCount,
54
+ updateOrdersCount,
55
+ cancelOrdersCount,
56
+ externalCallsGasLimit: 0n,
57
+ });
58
+ const relayerGasLimit = estimateRelayerGasLimit({
59
+ gasLimits,
60
+ tokenPermitsCount: 0,
61
+ feeSwapsCount: relayFeeToken.address === gasPaymentToken.address ? 0 : 1,
62
+ feeExternalCallsGasLimit: 0n,
63
+ oraclePriceCount: 2,
64
+ transactionPayloadGasLimit: batchGasLimit,
65
+ l1GasLimit: l1Reference?.gasLimit ?? 0n,
66
+ });
67
+ const gasLimit = relayerGasLimit + batchGasLimit;
68
+ const feeAmount = gasLimit * gasPrice;
69
+ const executionGasLimit = estimateExecuteIncreaseOrderGasLimit(gasLimits, {
70
+ swapsCount: 2,
71
+ callbackGasLimit: 0n,
72
+ });
73
+ const executionFee = executionFeeAmount ??
74
+ getExecutionFee(chainId, gasLimits, tokensData, executionGasLimit, gasPrice, 4n)?.feeTokenAmount;
75
+ let totalFee = feeAmount + (executionFee ?? 0n);
76
+ const minGasPaymentTokenBalance = convertBetweenTokens(totalFee, relayFeeToken, gasPaymentToken, false);
77
+ return minGasPaymentTokenBalance;
78
+ }
32
79
  /**
33
80
  * Copy from contract: `estimateExecuteIncreaseOrderGasLimit`
34
81
  */
@@ -4,10 +4,14 @@ import { applyFactor, getBasisPoints, PRECISION } from "../numbers";
4
4
  export * from "./estimateOraclePriceCount";
5
5
  export * from "./executionFee";
6
6
  export * from "./priceImpact";
7
- export function getSwapFee(marketInfo, swapAmount, forPositiveImpact) {
8
- const factor = forPositiveImpact
9
- ? marketInfo.swapFeeFactorForPositiveImpact
10
- : marketInfo.swapFeeFactorForNegativeImpact;
7
+ export function getSwapFee(marketInfo, swapAmount, forPositiveImpact, isAtomicSwap) {
8
+ let factor;
9
+ if (isAtomicSwap) {
10
+ factor = marketInfo.atomicSwapFeeFactor;
11
+ }
12
+ else {
13
+ factor = forPositiveImpact ? marketInfo.swapFeeFactorForPositiveImpact : marketInfo.swapFeeFactorForNegativeImpact;
14
+ }
11
15
  return applyFactor(swapAmount, factor);
12
16
  }
13
17
  export function getPositionFee(marketInfo, sizeDeltaUsd, forPositiveImpact, referralInfo, uiFeeFactor) {
@@ -0,0 +1,2 @@
1
+ import { GelatoRelay } from "@gelatonetwork/relay-sdk";
2
+ export const gelatoRelay = new GelatoRelay();
@@ -1,5 +1,6 @@
1
- import { encodeAbiParameters, keccak256 } from "viem";
1
+ import { encodeAbiParameters, keccak256, stringToBytes } from "viem";
2
2
  import { LRUCache } from "./LruCache";
3
+ export const ZERO_DATA = "0x";
3
4
  const dataCache = new LRUCache(10000);
4
5
  export function hashData(dataTypes, dataValues) {
5
6
  const key = JSON.stringify({ dataTypes, dataValues }, (_, val) => (typeof val === "bigint" ? String(val) : val));
@@ -33,3 +34,6 @@ export function hashDataMap(map) {
33
34
  }
34
35
  return result;
35
36
  }
37
+ export function keccakString(string) {
38
+ return keccak256(stringToBytes(string));
39
+ }
@@ -1,4 +1,4 @@
1
- import { BORROWING_EXPONENT_FACTOR_KEY, BORROWING_FACTOR_KEY, FUNDING_DECREASE_FACTOR_PER_SECOND, FUNDING_EXPONENT_FACTOR_KEY, FUNDING_FACTOR_KEY, FUNDING_INCREASE_FACTOR_PER_SECOND, IS_MARKET_DISABLED_KEY, MAX_FUNDING_FACTOR_PER_SECOND, MAX_OPEN_INTEREST_KEY, MAX_PNL_FACTOR_FOR_TRADERS_KEY, MAX_PNL_FACTOR_KEY, MAX_POOL_AMOUNT_KEY, MAX_POOL_USD_FOR_DEPOSIT_KEY, MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS_KEY, MAX_POSITION_IMPACT_FACTOR_KEY, MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER_KEY, MIN_COLLATERAL_FACTOR_KEY, MIN_FUNDING_FACTOR_PER_SECOND, MIN_POSITION_IMPACT_POOL_AMOUNT_KEY, OPEN_INTEREST_IN_TOKENS_KEY, OPEN_INTEREST_KEY, OPEN_INTEREST_RESERVE_FACTOR_KEY, POOL_AMOUNT_ADJUSTMENT_KEY, POOL_AMOUNT_KEY, POSITION_FEE_FACTOR_KEY, POSITION_IMPACT_EXPONENT_FACTOR_KEY, POSITION_IMPACT_FACTOR_KEY, POSITION_IMPACT_POOL_AMOUNT_KEY, POSITION_IMPACT_POOL_DISTRIBUTION_RATE_KEY, RESERVE_FACTOR_KEY, SWAP_FEE_FACTOR_KEY, SWAP_IMPACT_EXPONENT_FACTOR_KEY, SWAP_IMPACT_FACTOR_KEY, SWAP_IMPACT_POOL_AMOUNT_KEY, THRESHOLD_FOR_DECREASE_FUNDING, THRESHOLD_FOR_STABLE_FUNDING, VIRTUAL_MARKET_ID_KEY, VIRTUAL_TOKEN_ID_KEY, } from "../configs/dataStore";
1
+ import { ATOMIC_SWAP_FEE_FACTOR_KEY, BORROWING_EXPONENT_FACTOR_KEY, BORROWING_FACTOR_KEY, FUNDING_DECREASE_FACTOR_PER_SECOND, FUNDING_EXPONENT_FACTOR_KEY, FUNDING_FACTOR_KEY, FUNDING_INCREASE_FACTOR_PER_SECOND, IS_MARKET_DISABLED_KEY, MAX_FUNDING_FACTOR_PER_SECOND, MAX_OPEN_INTEREST_KEY, MAX_PNL_FACTOR_FOR_TRADERS_KEY, MAX_PNL_FACTOR_KEY, MAX_POOL_AMOUNT_KEY, MAX_POOL_USD_FOR_DEPOSIT_KEY, MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS_KEY, MAX_POSITION_IMPACT_FACTOR_KEY, MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER_KEY, MIN_COLLATERAL_FACTOR_KEY, MIN_FUNDING_FACTOR_PER_SECOND, MIN_POSITION_IMPACT_POOL_AMOUNT_KEY, OPEN_INTEREST_IN_TOKENS_KEY, OPEN_INTEREST_KEY, OPEN_INTEREST_RESERVE_FACTOR_KEY, POOL_AMOUNT_ADJUSTMENT_KEY, POOL_AMOUNT_KEY, POSITION_FEE_FACTOR_KEY, POSITION_IMPACT_EXPONENT_FACTOR_KEY, POSITION_IMPACT_FACTOR_KEY, POSITION_IMPACT_POOL_AMOUNT_KEY, POSITION_IMPACT_POOL_DISTRIBUTION_RATE_KEY, RESERVE_FACTOR_KEY, SWAP_FEE_FACTOR_KEY, SWAP_IMPACT_EXPONENT_FACTOR_KEY, SWAP_IMPACT_FACTOR_KEY, SWAP_IMPACT_POOL_AMOUNT_KEY, THRESHOLD_FOR_DECREASE_FUNDING, THRESHOLD_FOR_STABLE_FUNDING, VIRTUAL_MARKET_ID_KEY, VIRTUAL_TOKEN_ID_KEY, } from "../configs/dataStore";
2
2
  import { hashDataMap } from "./hash";
3
3
  export function hashMarketConfigKeys(market) {
4
4
  const marketAddress = market.marketTokenAddress;
@@ -171,6 +171,10 @@ export function hashMarketConfigKeys(market) {
171
171
  ["bytes32", "address", "bool"],
172
172
  [SWAP_FEE_FACTOR_KEY, marketAddress, false],
173
173
  ],
174
+ atomicSwapFeeFactor: [
175
+ ["bytes32", "address"],
176
+ [ATOMIC_SWAP_FEE_FACTOR_KEY, marketAddress],
177
+ ],
174
178
  swapImpactFactorPositive: [
175
179
  ["bytes32", "address", "bool"],
176
180
  [SWAP_IMPACT_FACTOR_KEY, marketAddress, true],
@@ -147,3 +147,6 @@ export function getPriceForPnl(prices, isLong, maximize) {
147
147
  }
148
148
  return maximize ? prices.minPrice : prices.maxPrice;
149
149
  }
150
+ export function getIsMarketAvailableForExpressSwaps(marketInfo) {
151
+ return [marketInfo.indexToken, marketInfo.longToken, marketInfo.shortToken].every((token) => token.hasPriceFeedProvider);
152
+ }