@gmx-io/sdk 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/build/cjs/src/abis/GlvReader.js +940 -940
  2. package/build/cjs/src/abis/IStargate.js +603 -0
  3. package/build/cjs/src/abis/LayerZeroProvider.js +273 -46
  4. package/build/cjs/src/abis/index.js +2 -2
  5. package/build/cjs/src/configs/batch.js +29 -103
  6. package/build/cjs/src/configs/chainIds.js +2 -2
  7. package/build/cjs/src/configs/chains.js +230 -151
  8. package/build/cjs/src/configs/contracts.js +1 -5
  9. package/build/cjs/src/configs/dataStore.js +5 -4
  10. package/build/cjs/src/configs/express.js +1 -1
  11. package/build/cjs/src/configs/gasLimits.js +41 -0
  12. package/build/cjs/src/configs/markets.js +67 -1
  13. package/build/cjs/src/configs/multichain.js +1 -0
  14. package/build/cjs/src/configs/oracleKeeper.js +18 -20
  15. package/build/cjs/src/configs/tokens.js +53 -14
  16. package/build/cjs/src/modules/markets/index.js +6 -2
  17. package/build/cjs/src/modules/markets/markets.spec.js +5 -5
  18. package/build/cjs/src/modules/markets/query-builders.js +8 -0
  19. package/build/cjs/src/modules/orders/helpers.js +2 -2
  20. package/build/cjs/src/modules/orders/helpers.spec.js +1 -1
  21. package/build/cjs/src/modules/orders/orders.spec.js +1 -1
  22. package/build/cjs/src/modules/positions/positions.spec.js +2 -2
  23. package/build/cjs/src/modules/tokens/tokens.spec.js +2 -2
  24. package/build/cjs/src/modules/trades/trades.spec.js +1 -1
  25. package/build/cjs/src/modules/utils/utils.js +7 -6
  26. package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
  27. package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +495 -0
  28. package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +45 -0
  29. package/build/cjs/src/test/mock.js +2 -0
  30. package/build/cjs/src/types/chains.js +2 -0
  31. package/build/cjs/src/types/orders.js +8 -2
  32. package/build/cjs/src/types/subsquid.js +241 -1
  33. package/build/cjs/src/types/tokens.js +7 -0
  34. package/build/cjs/src/utils/__tests__/abort.spec.js +122 -0
  35. package/build/cjs/src/utils/__tests__/numbers.spec.js +94 -14
  36. package/build/cjs/src/utils/abort.js +31 -0
  37. package/build/cjs/src/utils/callContract.js +4 -4
  38. package/build/cjs/src/utils/fees/executionFee.js +14 -11
  39. package/build/cjs/src/utils/fees/index.js +8 -2
  40. package/build/cjs/src/utils/marketKeysAndConfigs.js +8 -0
  41. package/build/cjs/src/utils/markets.js +7 -1
  42. package/build/cjs/src/utils/multicall.js +54 -17
  43. package/build/cjs/src/utils/numbers.js +25 -14
  44. package/build/cjs/src/utils/orders.js +2 -2
  45. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +7 -6
  46. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +5 -4
  47. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +10 -9
  48. package/build/cjs/src/utils/swap/buildSwapStrategy.js +10 -9
  49. package/build/cjs/src/utils/swap/swapPath.js +6 -6
  50. package/build/cjs/src/utils/swap/swapRouting.js +8 -4
  51. package/build/cjs/src/utils/swap/swapStats.js +6 -6
  52. package/build/cjs/src/utils/swap/swapValues.js +4 -0
  53. package/build/cjs/src/utils/tokens.js +17 -1
  54. package/build/cjs/src/utils/trade/decrease.js +1 -1
  55. package/build/esm/src/abis/GlvReader.js +940 -940
  56. package/build/esm/src/abis/IStargate.js +601 -0
  57. package/build/esm/src/abis/LayerZeroProvider.js +273 -46
  58. package/build/esm/src/abis/index.js +2 -2
  59. package/build/esm/src/configs/batch.js +30 -104
  60. package/build/esm/src/configs/chainIds.js +1 -1
  61. package/build/esm/src/configs/chains.js +212 -147
  62. package/build/esm/src/configs/contracts.js +1 -5
  63. package/build/esm/src/configs/dataStore.js +1 -0
  64. package/build/esm/src/configs/express.js +1 -1
  65. package/build/esm/src/configs/gasLimits.js +38 -0
  66. package/build/esm/src/configs/markets.js +60 -1
  67. package/build/esm/src/configs/multichain.js +2 -1
  68. package/build/esm/src/configs/oracleKeeper.js +17 -19
  69. package/build/esm/src/configs/tokens.js +52 -13
  70. package/build/esm/src/modules/markets/index.js +6 -2
  71. package/build/esm/src/modules/markets/markets.spec.js +5 -5
  72. package/build/esm/src/modules/markets/query-builders.js +8 -0
  73. package/build/esm/src/modules/orders/helpers.js +3 -3
  74. package/build/esm/src/modules/orders/helpers.spec.js +1 -1
  75. package/build/esm/src/modules/orders/orders.spec.js +1 -1
  76. package/build/esm/src/modules/positions/positions.spec.js +2 -2
  77. package/build/esm/src/modules/tokens/tokens.spec.js +2 -2
  78. package/build/esm/src/modules/trades/trades.spec.js +1 -1
  79. package/build/esm/src/modules/utils/utils.js +7 -6
  80. package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
  81. package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +495 -0
  82. package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +45 -0
  83. package/build/esm/src/test/mock.js +2 -0
  84. package/build/esm/src/types/chains.js +1 -0
  85. package/build/esm/src/types/orders.js +8 -2
  86. package/build/esm/src/types/subsquid.js +240 -0
  87. package/build/esm/src/types/tokens.js +6 -1
  88. package/build/esm/src/utils/__tests__/abort.spec.js +120 -0
  89. package/build/esm/src/utils/__tests__/numbers.spec.js +95 -15
  90. package/build/esm/src/utils/abort.js +27 -0
  91. package/build/esm/src/utils/callContract.js +5 -5
  92. package/build/esm/src/utils/fees/executionFee.js +15 -12
  93. package/build/esm/src/utils/fees/index.js +8 -2
  94. package/build/esm/src/utils/marketKeysAndConfigs.js +9 -1
  95. package/build/esm/src/utils/markets.js +5 -0
  96. package/build/esm/src/utils/multicall.js +53 -16
  97. package/build/esm/src/utils/numbers.js +21 -12
  98. package/build/esm/src/utils/orders.js +3 -3
  99. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +7 -6
  100. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +5 -4
  101. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +10 -9
  102. package/build/esm/src/utils/swap/buildSwapStrategy.js +10 -9
  103. package/build/esm/src/utils/swap/swapPath.js +6 -6
  104. package/build/esm/src/utils/swap/swapRouting.js +8 -4
  105. package/build/esm/src/utils/swap/swapStats.js +6 -6
  106. package/build/esm/src/utils/swap/swapValues.js +4 -0
  107. package/build/esm/src/utils/tokens.js +15 -1
  108. package/build/esm/src/utils/trade/decrease.js +2 -2
  109. package/build/types/src/abis/IStargate.d.ts +464 -0
  110. package/build/types/src/abis/LayerZeroProvider.d.ts +12 -0
  111. package/build/types/src/abis/index.d.ts +475 -99
  112. package/build/types/src/configs/chainIds.d.ts +1 -1
  113. package/build/types/src/configs/chains.d.ts +170 -27
  114. package/build/types/src/configs/contracts.d.ts +0 -4
  115. package/build/types/src/configs/dataStore.d.ts +1 -0
  116. package/build/types/src/configs/express.d.ts +1 -1
  117. package/build/types/src/configs/gasLimits.d.ts +4 -0
  118. package/build/types/src/configs/markets.d.ts +10 -1
  119. package/build/types/src/configs/oracleKeeper.d.ts +13 -0
  120. package/build/types/src/configs/tokens.d.ts +3 -0
  121. package/build/types/src/index.d.ts +1 -1
  122. package/build/types/src/modules/base.d.ts +1 -1
  123. package/build/types/src/modules/markets/index.d.ts +2 -0
  124. package/build/types/src/modules/markets/query-builders.d.ts +1 -1
  125. package/build/types/src/modules/markets/types.d.ts +2 -2
  126. package/build/types/src/modules/utils/utils.d.ts +2 -3
  127. package/build/types/src/types/chains.d.ts +57 -0
  128. package/build/types/src/types/markets.d.ts +2 -0
  129. package/build/types/src/types/orders.d.ts +8 -2
  130. package/build/types/src/types/subsquid.d.ts +5987 -5172
  131. package/build/types/src/types/tokens.d.ts +11 -3
  132. package/build/types/src/types/trade.d.ts +5 -0
  133. package/build/types/src/utils/__tests__/abort.spec.d.ts +1 -0
  134. package/build/types/src/utils/abort.d.ts +1 -0
  135. package/build/types/src/utils/fees/estimateOraclePriceCount.d.ts +2 -2
  136. package/build/types/src/utils/fees/executionFee.d.ts +6 -6
  137. package/build/types/src/utils/fees/index.d.ts +2 -1
  138. package/build/types/src/utils/marketKeysAndConfigs.d.ts +2 -0
  139. package/build/types/src/utils/markets.d.ts +4 -2
  140. package/build/types/src/utils/multicall.d.ts +4 -2
  141. package/build/types/src/utils/numbers.d.ts +8 -1
  142. package/build/types/src/utils/swap/buildSwapStrategy.d.ts +6 -3
  143. package/build/types/src/utils/swap/swapPath.d.ts +2 -1
  144. package/build/types/src/utils/swap/swapRouting.d.ts +7 -2
  145. package/build/types/src/utils/swap/swapStats.d.ts +3 -2
  146. package/build/types/src/utils/swap/swapValues.d.ts +1 -1
  147. package/build/types/src/utils/tokens.d.ts +3 -0
  148. package/package.json +8 -2
  149. package/build/cjs/src/abis/MultichainUtils.js +0 -133
  150. package/build/esm/src/abis/MultichainUtils.js +0 -131
  151. package/build/types/src/abis/MultichainUtils.d.ts +0 -100
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const vitest_1 = require("vitest");
4
4
  const factors_1 = require("../../../configs/factors");
5
5
  const tokens_1 = require("../../../configs/tokens");
6
+ const orders_1 = require("../../../types/orders");
6
7
  const mock_1 = require("../../../test/mock");
7
8
  const swapStats_1 = require("../swapStats");
8
9
  const someWrappedToken = "0x0000000000000000000000000000000000000001";
@@ -255,7 +256,7 @@ const mockMarketsInfoData = {
255
256
  usdIn: 100n * dollar,
256
257
  shouldUnwrapNativeToken: false,
257
258
  shouldApplyPriceImpact: true,
258
- isAtomicSwap: false,
259
+ swapPricingType: orders_1.SwapPricingType.Swap,
259
260
  });
260
261
  (0, vitest_1.expect)(result).toBeUndefined();
261
262
  });
@@ -268,7 +269,7 @@ const mockMarketsInfoData = {
268
269
  usdIn: 100n * dollar,
269
270
  shouldUnwrapNativeToken: false,
270
271
  shouldApplyPriceImpact: true,
271
- isAtomicSwap: false,
272
+ swapPricingType: orders_1.SwapPricingType.Swap,
272
273
  });
273
274
  (0, vitest_1.expect)(result).toBeDefined();
274
275
  (0, vitest_1.expect)(result?.swapPath).toEqual(["ETH-WETH-USDC"]);
@@ -290,7 +291,7 @@ const mockMarketsInfoData = {
290
291
  usdIn: 100n * dollar,
291
292
  shouldUnwrapNativeToken: false,
292
293
  shouldApplyPriceImpact: true,
293
- isAtomicSwap: false,
294
+ swapPricingType: orders_1.SwapPricingType.Swap,
294
295
  });
295
296
  (0, vitest_1.expect)(result).toBeDefined();
296
297
  (0, vitest_1.expect)(result?.swapPath).toEqual(["BTC-BTC-WETH", "BTC-BTC-USDC"]);
@@ -312,7 +313,7 @@ const mockMarketsInfoData = {
312
313
  usdIn: 100n * dollar,
313
314
  shouldUnwrapNativeToken: true,
314
315
  shouldApplyPriceImpact: true,
315
- isAtomicSwap: false,
316
+ swapPricingType: orders_1.SwapPricingType.Swap,
316
317
  });
317
318
  (0, vitest_1.expect)(result).toBeDefined();
318
319
  (0, vitest_1.expect)(result?.tokenOutAddress).toBe(tokens_1.NATIVE_TOKEN_ADDRESS);
@@ -326,7 +327,7 @@ const mockMarketsInfoData = {
326
327
  usdIn: 100n * dollar,
327
328
  shouldUnwrapNativeToken: false,
328
329
  shouldApplyPriceImpact: true,
329
- isAtomicSwap: false,
330
+ swapPricingType: orders_1.SwapPricingType.Swap,
330
331
  });
331
332
  (0, vitest_1.expect)(result).toBeUndefined();
332
333
  });
@@ -339,7 +340,7 @@ const mockMarketsInfoData = {
339
340
  usdIn: 100n * dollar,
340
341
  shouldUnwrapNativeToken: false,
341
342
  shouldApplyPriceImpact: true,
342
- isAtomicSwap: false,
343
+ swapPricingType: orders_1.SwapPricingType.Swap,
343
344
  });
344
345
  const resultWithoutImpact = (0, swapStats_1.getSwapPathStats)({
345
346
  marketsInfoData: testMarketsInfoData,
@@ -349,7 +350,7 @@ const mockMarketsInfoData = {
349
350
  usdIn: 100n * dollar,
350
351
  shouldUnwrapNativeToken: false,
351
352
  shouldApplyPriceImpact: false,
352
- isAtomicSwap: false,
353
+ swapPricingType: orders_1.SwapPricingType.Swap,
353
354
  });
354
355
  if (!resultWithImpact || !resultWithoutImpact) {
355
356
  throw new Error("Results should be defined");
@@ -365,7 +366,7 @@ const mockMarketsInfoData = {
365
366
  usdIn: 100n * dollar,
366
367
  shouldUnwrapNativeToken: false,
367
368
  shouldApplyPriceImpact: true,
368
- isAtomicSwap: false,
369
+ swapPricingType: orders_1.SwapPricingType.Swap,
369
370
  });
370
371
  (0, vitest_1.expect)(result).toBeDefined();
371
372
  (0, vitest_1.expect)(result?.swapSteps).toHaveLength(2);
@@ -390,7 +391,7 @@ const mockMarketsInfoData = {
390
391
  usdIn: 100n * dollar,
391
392
  shouldUnwrapNativeToken: false,
392
393
  shouldApplyPriceImpact: true,
393
- isAtomicSwap: false,
394
+ swapPricingType: orders_1.SwapPricingType.Swap,
394
395
  });
395
396
  (0, vitest_1.expect)(result).toBeUndefined();
396
397
  });
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildReverseSwapStrategy = exports.buildSwapStrategy = void 0;
4
+ const orders_1 = require("../../types/orders");
4
5
  const bigmath_1 = require("../bigmath");
5
6
  const tokens_1 = require("../tokens");
6
7
  const externalSwapPath_1 = require("./externalSwapPath");
@@ -13,7 +14,7 @@ const swapPath_1 = require("./swapPath");
13
14
  3. Check if there is a combined swap strategy and return combinedSwap if there is [combinedSwap]
14
15
  4. Return defaultSwapStrategy (noSwap) if there is no other swap strategy [noSwap]
15
16
  */
16
- function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, }) {
17
+ function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType = orders_1.SwapPricingType.Swap, }) {
17
18
  const priceIn = tokenIn.prices.minPrice;
18
19
  const usdIn = (0, tokens_1.convertToUsd)(amountIn, tokenIn.decimals, priceIn);
19
20
  if (amountIn < 0n) {
@@ -39,7 +40,7 @@ function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chain
39
40
  fromTokenAddress: tokenIn.address,
40
41
  toTokenAddress: tokenOut.address,
41
42
  marketsInfoData,
42
- isExpressFeeSwap: false,
43
+ swapPricingType,
43
44
  });
44
45
  const swapPathStats = findSwapPath(usdIn, { order: swapOptimizationOrder });
45
46
  if (swapPathStats) {
@@ -63,7 +64,7 @@ function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chain
63
64
  fromTokenAddress: path.outTokenAddress,
64
65
  toTokenAddress: tokenOut.address,
65
66
  marketsInfoData,
66
- isExpressFeeSwap: false,
67
+ swapPricingType,
67
68
  });
68
69
  const swapPathStats = findSwapPath(usdIn);
69
70
  return Boolean(swapPathStats);
@@ -79,7 +80,7 @@ function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chain
79
80
  fromTokenAddress: suitableSwapPath.outTokenAddress,
80
81
  toTokenAddress: tokenOut.address,
81
82
  marketsInfoData,
82
- isExpressFeeSwap: false,
83
+ swapPricingType,
83
84
  });
84
85
  const swapPathStatsForCombinedSwap = externalSwapQuoteForCombinedSwap
85
86
  ? findSwapPathForSuitableSwapPath(externalSwapQuoteForCombinedSwap.usdOut)
@@ -103,7 +104,7 @@ function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chain
103
104
  }
104
105
  exports.buildSwapStrategy = buildSwapStrategy;
105
106
  // Used for getting swap amounts by to value
106
- function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, }) {
107
+ function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, swapPricingType, }) {
107
108
  const priceIn = (0, tokens_1.getMidPrice)(tokenIn.prices);
108
109
  const priceOut = (0, tokens_1.getMidPrice)(tokenOut.prices);
109
110
  const preferredUsdOut = (0, tokens_1.convertToUsd)(amountOut, tokenOut.decimals, (0, tokens_1.getMidPrice)(tokenOut.prices));
@@ -129,7 +130,7 @@ function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoDat
129
130
  fromTokenAddress: tokenIn.address,
130
131
  toTokenAddress: tokenOut.address,
131
132
  marketsInfoData,
132
- isExpressFeeSwap: false,
133
+ swapPricingType,
133
134
  });
134
135
  const approximateSwapPathStats = findSwapPath(approximateUsdIn, { order: swapOptimizationOrder });
135
136
  if (approximateSwapPathStats) {
@@ -165,12 +166,12 @@ function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoDat
165
166
  fromTokenAddress: tokenIn.address,
166
167
  toTokenAddress: path.inTokenAddress,
167
168
  marketsInfoData,
168
- isExpressFeeSwap: false,
169
+ swapPricingType,
169
170
  });
170
171
  const swapPathStats = findSwapPath(approximateUsdIn);
171
172
  return Boolean(swapPathStats);
172
173
  });
173
- if (suitableSwapPath) {
174
+ if (suitableSwapPath && externalSwapQuoteParams) {
174
175
  const approximateExternalSwapQuoteForCombinedSwap = (0, externalSwapQuoteByPath_1.getExternalSwapQuoteByPath)({
175
176
  amountIn: approximateAmountIn,
176
177
  externalSwapPath: suitableSwapPath,
@@ -184,7 +185,7 @@ function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoDat
184
185
  fromTokenAddress: tokenIn.address,
185
186
  toTokenAddress: suitableSwapPath.inTokenAddress,
186
187
  marketsInfoData,
187
- isExpressFeeSwap: false,
188
+ swapPricingType,
188
189
  });
189
190
  const approximateSwapPathStatsForCombinedSwap = findSwapPathForSuitableSwapPath(approximateExternalSwapQuoteForCombinedSwap.usdOut);
190
191
  if (!approximateSwapPathStatsForCombinedSwap) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createFindSwapPath = exports.getWrappedAddress = void 0;
4
4
  const markets_1 = require("../../configs/markets");
5
5
  const tokens_1 = require("../../configs/tokens");
6
+ const orders_1 = require("../../types/orders");
6
7
  const LruCache_1 = require("../LruCache");
7
8
  const markets_2 = require("../markets");
8
9
  const buildMarketsAdjacencyGraph_1 = require("./buildMarketsAdjacencyGraph");
@@ -30,7 +31,7 @@ function buildMarketAdjacencyGraph(chainId, disabledMarkets) {
30
31
  }
31
32
  const FALLBACK_FIND_SWAP_PATH = () => undefined;
32
33
  const createFindSwapPath = (params) => {
33
- const { chainId, fromTokenAddress, toTokenAddress, marketsInfoData, disabledMarkets, manualPath, gasEstimationParams, isExpressFeeSwap, } = params;
34
+ const { chainId, fromTokenAddress, toTokenAddress, marketsInfoData, disabledMarkets, manualPath, gasEstimationParams, swapPricingType = orders_1.SwapPricingType.Swap, } = params;
34
35
  const wrappedFromAddress = (0, exports.getWrappedAddress)(chainId, fromTokenAddress);
35
36
  const wrappedToAddress = (0, exports.getWrappedAddress)(chainId, toTokenAddress);
36
37
  const wrappedToken = (0, tokens_1.getWrappedToken)(chainId);
@@ -38,20 +39,19 @@ const createFindSwapPath = (params) => {
38
39
  ? (0, swapRouting_1.getTokenSwapPathsForTokenPairPrebuilt)(chainId, wrappedFromAddress, wrappedToAddress)
39
40
  : [];
40
41
  const finalDisabledMarkets = [...(disabledMarkets ?? [])];
41
- if (isExpressFeeSwap) {
42
+ if (swapPricingType === orders_1.SwapPricingType.AtomicSwap) {
42
43
  const expressSwapUnavailableMarkets = Object.values(marketsInfoData ?? {})
43
44
  .filter((market) => !(0, markets_2.getIsMarketAvailableForExpressSwaps)(market))
44
45
  .map((market) => market.marketTokenAddress);
45
46
  finalDisabledMarkets.push(...expressSwapUnavailableMarkets);
46
47
  }
47
- const isAtomicSwap = Boolean(isExpressFeeSwap);
48
48
  const marketAdjacencyGraph = buildMarketAdjacencyGraph(chainId, finalDisabledMarkets);
49
49
  const cache = {};
50
50
  if (!marketsInfoData) {
51
51
  return FALLBACK_FIND_SWAP_PATH;
52
52
  }
53
53
  const marketEdgeLiquidityGetter = (0, swapRouting_1.createMarketEdgeLiquidityGetter)(marketsInfoData);
54
- const naiveEstimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, isAtomicSwap);
54
+ const naiveEstimator = (0, swapRouting_1.createNaiveSwapEstimator)(marketsInfoData, swapPricingType);
55
55
  const naiveNetworkEstimator = gasEstimationParams
56
56
  ? (0, swapRouting_1.createNaiveNetworkEstimator)({
57
57
  gasLimits: gasEstimationParams.gasLimits,
@@ -60,7 +60,7 @@ const createFindSwapPath = (params) => {
60
60
  chainId,
61
61
  })
62
62
  : undefined;
63
- const estimator = (0, swapRouting_1.createSwapEstimator)(marketsInfoData, isAtomicSwap);
63
+ const estimator = (0, swapRouting_1.createSwapEstimator)(marketsInfoData, swapPricingType);
64
64
  const findSwapPath = (usdIn, opts) => {
65
65
  if (tokenSwapPaths.length === 0 || !fromTokenAddress || !wrappedFromAddress || !wrappedToAddress) {
66
66
  return undefined;
@@ -130,7 +130,7 @@ const createFindSwapPath = (params) => {
130
130
  shouldUnwrapNativeToken: toTokenAddress === tokens_1.NATIVE_TOKEN_ADDRESS,
131
131
  shouldApplyPriceImpact: true,
132
132
  usdIn,
133
- isAtomicSwap,
133
+ swapPricingType,
134
134
  });
135
135
  cache[cacheKey] = result;
136
136
  return result;
@@ -11,7 +11,7 @@ const objects_1 = require("../objects");
11
11
  const constants_1 = require("./constants");
12
12
  const preparedSwapData_1 = require("./preparedSwapData");
13
13
  const swapStats_1 = require("./swapStats");
14
- const createSwapEstimator = (marketsInfoData, isAtomicSwap) => {
14
+ const createSwapEstimator = (marketsInfoData, swapPricingType) => {
15
15
  return (e, usdIn) => {
16
16
  const marketInfo = marketsInfoData[e.marketAddress];
17
17
  if (!marketInfo || marketInfo.isDisabled) {
@@ -25,7 +25,7 @@ const createSwapEstimator = (marketsInfoData, isAtomicSwap) => {
25
25
  tokenInAddress: e.from,
26
26
  tokenOutAddress: e.to,
27
27
  shouldApplyPriceImpact: true,
28
- isAtomicSwap,
28
+ swapPricingType,
29
29
  });
30
30
  const isOutLiquidity = swapStats?.isOutLiquidity;
31
31
  const isOutCapacity = swapStats?.isOutCapacity;
@@ -53,7 +53,11 @@ const createMarketEdgeLiquidityGetter = (marketsInfoData) => {
53
53
  };
54
54
  };
55
55
  exports.createMarketEdgeLiquidityGetter = createMarketEdgeLiquidityGetter;
56
- const createNaiveSwapEstimator = (marketsInfoData, isAtomicSwap) => {
56
+ /**
57
+ TODO MLTCH does naive estimator need to know about swap pricing type?
58
+ Its naive for a reason and i think it would work the same without knowing about it
59
+ */
60
+ const createNaiveSwapEstimator = (marketsInfoData, swapPricingType) => {
57
61
  return (e, usdIn) => {
58
62
  let marketInfo = marketsInfoData[e.marketAddress];
59
63
  if (marketInfo === undefined || marketInfo.isDisabled) {
@@ -65,7 +69,7 @@ const createNaiveSwapEstimator = (marketsInfoData, isAtomicSwap) => {
65
69
  tokenInAddress: e.from,
66
70
  tokenOutAddress: e.to,
67
71
  shouldApplyPriceImpact: true,
68
- isAtomicSwap,
72
+ swapPricingType,
69
73
  });
70
74
  const usdOut = swapStats?.usdOut;
71
75
  if (usdOut === undefined || usdOut === 0n || swapStats.isOutCapacity || swapStats.isOutLiquidity) {
@@ -83,7 +83,7 @@ function getSwapPathOutputAddresses(p) {
83
83
  }
84
84
  exports.getSwapPathOutputAddresses = getSwapPathOutputAddresses;
85
85
  function getSwapPathStats(p) {
86
- const { marketsInfoData, swapPath, initialCollateralAddress, usdIn, shouldUnwrapNativeToken, shouldApplyPriceImpact, wrappedNativeTokenAddress, isAtomicSwap, } = p;
86
+ const { marketsInfoData, swapPath, initialCollateralAddress, usdIn, shouldUnwrapNativeToken, shouldApplyPriceImpact, wrappedNativeTokenAddress, swapPricingType, } = p;
87
87
  if (swapPath.length === 0) {
88
88
  return undefined;
89
89
  }
@@ -113,7 +113,7 @@ function getSwapPathStats(p) {
113
113
  tokenOutAddress,
114
114
  usdIn: usdOut,
115
115
  shouldApplyPriceImpact,
116
- isAtomicSwap,
116
+ swapPricingType,
117
117
  });
118
118
  tokenInAddress = swapStep.tokenOutAddress;
119
119
  usdOut = swapStep.usdOut;
@@ -140,7 +140,7 @@ function getSwapPathStats(p) {
140
140
  }
141
141
  exports.getSwapPathStats = getSwapPathStats;
142
142
  function getSwapStats(p) {
143
- const { marketInfo, tokenInAddress, tokenOutAddress, usdIn, shouldApplyPriceImpact, isAtomicSwap } = p;
143
+ const { marketInfo, tokenInAddress, tokenOutAddress, usdIn, shouldApplyPriceImpact, swapPricingType } = p;
144
144
  const isWrap = tokenInAddress === tokens_1.NATIVE_TOKEN_ADDRESS;
145
145
  const isUnwrap = tokenOutAddress === tokens_1.NATIVE_TOKEN_ADDRESS;
146
146
  const tokenIn = (0, markets_1.getTokenPoolType)(marketInfo, tokenInAddress) === "long" ? marketInfo.longToken : marketInfo.shortToken;
@@ -158,7 +158,7 @@ function getSwapStats(p) {
158
158
  catch (e) {
159
159
  // Approximate if the market would be out of capacity
160
160
  const capacityUsd = getSwapCapacityUsd(marketInfo, (0, markets_1.getTokenPoolType)(marketInfo, tokenInAddress) === "long");
161
- const swapFeeUsd = (0, fees_1.getSwapFee)(marketInfo, usdIn, false, isAtomicSwap);
161
+ const swapFeeUsd = (0, fees_1.getSwapFee)(marketInfo, usdIn, false, swapPricingType);
162
162
  const usdInAfterFees = usdIn - swapFeeUsd;
163
163
  const isOutCapacity = capacityUsd < usdInAfterFees;
164
164
  return {
@@ -179,8 +179,8 @@ function getSwapStats(p) {
179
179
  isOutCapacity,
180
180
  };
181
181
  }
182
- const swapFeeAmount = (0, fees_1.getSwapFee)(marketInfo, amountIn, balanceWasImproved, isAtomicSwap);
183
- const swapFeeUsd = (0, fees_1.getSwapFee)(marketInfo, usdIn, balanceWasImproved, isAtomicSwap);
182
+ const swapFeeAmount = (0, fees_1.getSwapFee)(marketInfo, amountIn, balanceWasImproved, swapPricingType);
183
+ const swapFeeUsd = (0, fees_1.getSwapFee)(marketInfo, usdIn, balanceWasImproved, swapPricingType);
184
184
  const amountInAfterFees = amountIn - swapFeeAmount;
185
185
  const usdInAfterFees = usdIn - swapFeeUsd;
186
186
  let usdOut = usdInAfterFees;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSwapPathComparator = exports.getSwapAmountsByToValue = exports.getSwapAmountsByFromValue = void 0;
4
4
  const factors_1 = require("../../configs/factors");
5
+ const orders_1 = require("../../types/orders");
5
6
  const bigmath_1 = require("../bigmath");
6
7
  const fees_1 = require("../fees");
7
8
  const numbers_1 = require("../numbers");
@@ -20,6 +21,7 @@ function getSwapAmountsByFromValue(p) {
20
21
  chainId,
21
22
  swapOptimizationOrder,
22
23
  externalSwapQuoteParams,
24
+ swapPricingType: orders_1.SwapPricingType.Swap,
23
25
  });
24
26
  const swapPathStats = swapStrategy.swapPathStats;
25
27
  const totalSwapVolume = (0, fees_1.getTotalSwapVolumeFromSwapStats)(swapPathStats?.swapSteps);
@@ -89,6 +91,7 @@ function getSwapAmountsByToValue(p) {
89
91
  chainId,
90
92
  externalSwapQuoteParams,
91
93
  swapOptimizationOrder,
94
+ swapPricingType: orders_1.SwapPricingType.Swap,
92
95
  });
93
96
  const swapStrategy = (0, buildSwapStrategy_1.buildSwapStrategy)({
94
97
  amountIn: swapStrategyReverse.amountIn,
@@ -98,6 +101,7 @@ function getSwapAmountsByToValue(p) {
98
101
  chainId,
99
102
  swapOptimizationOrder,
100
103
  externalSwapQuoteParams,
104
+ swapPricingType: orders_1.SwapPricingType.Swap,
101
105
  });
102
106
  const uiFeeUsd = (0, numbers_1.applyFactor)(swapStrategy.usdIn, uiFeeFactor);
103
107
  const defaultAmounts = {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTokensRatioByPrice = exports.getIsUnstake = exports.getIsStake = exports.getIsUnwrap = exports.getIsWrap = exports.getAmountByRatio = exports.getTokensRatioByMinOutputAmountAndTriggerPrice = exports.getTokensRatioByAmounts = exports.getTokenData = exports.getIsEquivalentTokens = exports.getMidPrice = exports.convertBetweenTokens = exports.convertToUsd = exports.convertToTokenAmount = exports.convertToContractTokenPrices = exports.convertToContractPrice = exports.parseContractPrice = void 0;
3
+ exports.getGlvToken = exports.getGmToken = exports.getTokensRatioByPrice = exports.getIsUnstake = exports.getIsStake = exports.getIsUnwrap = exports.getIsWrap = exports.getAmountByRatio = exports.getTokensRatioByMinOutputAmountAndTriggerPrice = exports.getTokensRatioByAmounts = exports.getTokenData = exports.getIsEquivalentTokens = exports.getMidPrice = exports.convertBetweenTokens = exports.convertToUsd = exports.convertToTokenAmount = exports.convertToContractTokenPrices = exports.convertToContractPrice = exports.parseContractPrice = void 0;
4
4
  const factors_1 = require("../configs/factors");
5
5
  const tokens_1 = require("../configs/tokens");
6
6
  const bigmath_1 = require("./bigmath");
@@ -165,3 +165,19 @@ function getTokensRatioByPrice(p) {
165
165
  return { ratio, largestToken, smallestToken };
166
166
  }
167
167
  exports.getTokensRatioByPrice = getTokensRatioByPrice;
168
+ function getGmToken(chainId, marketTokenAddress) {
169
+ const stubToken = (0, tokens_1.getToken)(chainId, tokens_1.GM_STUB_ADDRESS);
170
+ return {
171
+ ...stubToken,
172
+ address: marketTokenAddress,
173
+ };
174
+ }
175
+ exports.getGmToken = getGmToken;
176
+ function getGlvToken(chainId, glvTokenAddress) {
177
+ const stubToken = (0, tokens_1.getToken)(chainId, tokens_1.GLV_STUB_ADDRESS);
178
+ return {
179
+ ...stubToken,
180
+ address: glvTokenAddress,
181
+ };
182
+ }
183
+ exports.getGlvToken = getGlvToken;
@@ -174,7 +174,7 @@ function getDecreasePositionAmounts(p) {
174
174
  tokenOutAddress: collateralToken.address,
175
175
  usdIn: profitUsd,
176
176
  shouldApplyPriceImpact: true,
177
- isAtomicSwap: false,
177
+ swapPricingType: orders_1.SwapPricingType.Swap,
178
178
  });
179
179
  values.swapProfitFeeUsd = swapProfitStats.swapFeeUsd - swapProfitStats.priceImpactDeltaUsd;
180
180
  values.swapUiFeeUsd = (0, numbers_1.applyFactor)(swapProfitStats.usdIn, uiFeeFactor);