@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
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { USD_DECIMALS } from "../../../configs/factors";
3
3
  import { NATIVE_TOKEN_ADDRESS } from "../../../configs/tokens";
4
+ import { SwapPricingType } from "../../../types/orders";
4
5
  import { mockMarketsInfoData as createMockMarketsInfoData, mockTokensData, usdToToken } from "../../../test/mock";
5
6
  import { getSwapPathOutputAddresses, getSwapPathStats } from "../swapStats";
6
7
  const someWrappedToken = "0x0000000000000000000000000000000000000001";
@@ -253,7 +254,7 @@ describe("getSwapPathStats", () => {
253
254
  usdIn: 100n * dollar,
254
255
  shouldUnwrapNativeToken: false,
255
256
  shouldApplyPriceImpact: true,
256
- isAtomicSwap: false,
257
+ swapPricingType: SwapPricingType.Swap,
257
258
  });
258
259
  expect(result).toBeUndefined();
259
260
  });
@@ -266,7 +267,7 @@ describe("getSwapPathStats", () => {
266
267
  usdIn: 100n * dollar,
267
268
  shouldUnwrapNativeToken: false,
268
269
  shouldApplyPriceImpact: true,
269
- isAtomicSwap: false,
270
+ swapPricingType: SwapPricingType.Swap,
270
271
  });
271
272
  expect(result).toBeDefined();
272
273
  expect(result?.swapPath).toEqual(["ETH-WETH-USDC"]);
@@ -288,7 +289,7 @@ describe("getSwapPathStats", () => {
288
289
  usdIn: 100n * dollar,
289
290
  shouldUnwrapNativeToken: false,
290
291
  shouldApplyPriceImpact: true,
291
- isAtomicSwap: false,
292
+ swapPricingType: SwapPricingType.Swap,
292
293
  });
293
294
  expect(result).toBeDefined();
294
295
  expect(result?.swapPath).toEqual(["BTC-BTC-WETH", "BTC-BTC-USDC"]);
@@ -310,7 +311,7 @@ describe("getSwapPathStats", () => {
310
311
  usdIn: 100n * dollar,
311
312
  shouldUnwrapNativeToken: true,
312
313
  shouldApplyPriceImpact: true,
313
- isAtomicSwap: false,
314
+ swapPricingType: SwapPricingType.Swap,
314
315
  });
315
316
  expect(result).toBeDefined();
316
317
  expect(result?.tokenOutAddress).toBe(NATIVE_TOKEN_ADDRESS);
@@ -324,7 +325,7 @@ describe("getSwapPathStats", () => {
324
325
  usdIn: 100n * dollar,
325
326
  shouldUnwrapNativeToken: false,
326
327
  shouldApplyPriceImpact: true,
327
- isAtomicSwap: false,
328
+ swapPricingType: SwapPricingType.Swap,
328
329
  });
329
330
  expect(result).toBeUndefined();
330
331
  });
@@ -337,7 +338,7 @@ describe("getSwapPathStats", () => {
337
338
  usdIn: 100n * dollar,
338
339
  shouldUnwrapNativeToken: false,
339
340
  shouldApplyPriceImpact: true,
340
- isAtomicSwap: false,
341
+ swapPricingType: SwapPricingType.Swap,
341
342
  });
342
343
  const resultWithoutImpact = getSwapPathStats({
343
344
  marketsInfoData: testMarketsInfoData,
@@ -347,7 +348,7 @@ describe("getSwapPathStats", () => {
347
348
  usdIn: 100n * dollar,
348
349
  shouldUnwrapNativeToken: false,
349
350
  shouldApplyPriceImpact: false,
350
- isAtomicSwap: false,
351
+ swapPricingType: SwapPricingType.Swap,
351
352
  });
352
353
  if (!resultWithImpact || !resultWithoutImpact) {
353
354
  throw new Error("Results should be defined");
@@ -363,7 +364,7 @@ describe("getSwapPathStats", () => {
363
364
  usdIn: 100n * dollar,
364
365
  shouldUnwrapNativeToken: false,
365
366
  shouldApplyPriceImpact: true,
366
- isAtomicSwap: false,
367
+ swapPricingType: SwapPricingType.Swap,
367
368
  });
368
369
  expect(result).toBeDefined();
369
370
  expect(result?.swapSteps).toHaveLength(2);
@@ -388,7 +389,7 @@ describe("getSwapPathStats", () => {
388
389
  usdIn: 100n * dollar,
389
390
  shouldUnwrapNativeToken: false,
390
391
  shouldApplyPriceImpact: true,
391
- isAtomicSwap: false,
392
+ swapPricingType: SwapPricingType.Swap,
392
393
  });
393
394
  expect(result).toBeUndefined();
394
395
  });
@@ -1,3 +1,4 @@
1
+ import { SwapPricingType } from "../../types/orders";
1
2
  import { bigMath } from "../bigmath";
2
3
  import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens, getIsStake, getIsUnstake, getMidPrice, } from "../tokens";
3
4
  import { getAvailableExternalSwapPaths } from "./externalSwapPath";
@@ -10,7 +11,7 @@ import { createFindSwapPath } from "./swapPath";
10
11
  3. Check if there is a combined swap strategy and return combinedSwap if there is [combinedSwap]
11
12
  4. Return defaultSwapStrategy (noSwap) if there is no other swap strategy [noSwap]
12
13
  */
13
- export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, }) {
14
+ export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType = SwapPricingType.Swap, }) {
14
15
  const priceIn = tokenIn.prices.minPrice;
15
16
  const usdIn = convertToUsd(amountIn, tokenIn.decimals, priceIn);
16
17
  if (amountIn < 0n) {
@@ -36,7 +37,7 @@ export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData
36
37
  fromTokenAddress: tokenIn.address,
37
38
  toTokenAddress: tokenOut.address,
38
39
  marketsInfoData,
39
- isExpressFeeSwap: false,
40
+ swapPricingType,
40
41
  });
41
42
  const swapPathStats = findSwapPath(usdIn, { order: swapOptimizationOrder });
42
43
  if (swapPathStats) {
@@ -60,7 +61,7 @@ export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData
60
61
  fromTokenAddress: path.outTokenAddress,
61
62
  toTokenAddress: tokenOut.address,
62
63
  marketsInfoData,
63
- isExpressFeeSwap: false,
64
+ swapPricingType,
64
65
  });
65
66
  const swapPathStats = findSwapPath(usdIn);
66
67
  return Boolean(swapPathStats);
@@ -76,7 +77,7 @@ export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData
76
77
  fromTokenAddress: suitableSwapPath.outTokenAddress,
77
78
  toTokenAddress: tokenOut.address,
78
79
  marketsInfoData,
79
- isExpressFeeSwap: false,
80
+ swapPricingType,
80
81
  });
81
82
  const swapPathStatsForCombinedSwap = externalSwapQuoteForCombinedSwap
82
83
  ? findSwapPathForSuitableSwapPath(externalSwapQuoteForCombinedSwap.usdOut)
@@ -99,7 +100,7 @@ export function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData
99
100
  return defaultSwapStrategy;
100
101
  }
101
102
  // Used for getting swap amounts by to value
102
- export function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, }) {
103
+ export function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, swapPricingType, }) {
103
104
  const priceIn = getMidPrice(tokenIn.prices);
104
105
  const priceOut = getMidPrice(tokenOut.prices);
105
106
  const preferredUsdOut = convertToUsd(amountOut, tokenOut.decimals, getMidPrice(tokenOut.prices));
@@ -125,7 +126,7 @@ export function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, markets
125
126
  fromTokenAddress: tokenIn.address,
126
127
  toTokenAddress: tokenOut.address,
127
128
  marketsInfoData,
128
- isExpressFeeSwap: false,
129
+ swapPricingType,
129
130
  });
130
131
  const approximateSwapPathStats = findSwapPath(approximateUsdIn, { order: swapOptimizationOrder });
131
132
  if (approximateSwapPathStats) {
@@ -161,12 +162,12 @@ export function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, markets
161
162
  fromTokenAddress: tokenIn.address,
162
163
  toTokenAddress: path.inTokenAddress,
163
164
  marketsInfoData,
164
- isExpressFeeSwap: false,
165
+ swapPricingType,
165
166
  });
166
167
  const swapPathStats = findSwapPath(approximateUsdIn);
167
168
  return Boolean(swapPathStats);
168
169
  });
169
- if (suitableSwapPath) {
170
+ if (suitableSwapPath && externalSwapQuoteParams) {
170
171
  const approximateExternalSwapQuoteForCombinedSwap = getExternalSwapQuoteByPath({
171
172
  amountIn: approximateAmountIn,
172
173
  externalSwapPath: suitableSwapPath,
@@ -180,7 +181,7 @@ export function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, markets
180
181
  fromTokenAddress: tokenIn.address,
181
182
  toTokenAddress: suitableSwapPath.inTokenAddress,
182
183
  marketsInfoData,
183
- isExpressFeeSwap: false,
184
+ swapPricingType,
184
185
  });
185
186
  const approximateSwapPathStatsForCombinedSwap = findSwapPathForSuitableSwapPath(approximateExternalSwapQuoteForCombinedSwap.usdOut);
186
187
  if (!approximateSwapPathStatsForCombinedSwap) {
@@ -1,5 +1,6 @@
1
1
  import { MARKETS } from "../../configs/markets";
2
2
  import { convertTokenAddress, getWrappedToken, NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
3
+ import { SwapPricingType } from "../../types/orders";
3
4
  import { LRUCache } from "../LruCache";
4
5
  import { getIsMarketAvailableForExpressSwaps } from "../markets";
5
6
  import { buildMarketsAdjacencyGraph } from "./buildMarketsAdjacencyGraph";
@@ -26,7 +27,7 @@ function buildMarketAdjacencyGraph(chainId, disabledMarkets) {
26
27
  }
27
28
  const FALLBACK_FIND_SWAP_PATH = () => undefined;
28
29
  export const createFindSwapPath = (params) => {
29
- const { chainId, fromTokenAddress, toTokenAddress, marketsInfoData, disabledMarkets, manualPath, gasEstimationParams, isExpressFeeSwap, } = params;
30
+ const { chainId, fromTokenAddress, toTokenAddress, marketsInfoData, disabledMarkets, manualPath, gasEstimationParams, swapPricingType = SwapPricingType.Swap, } = params;
30
31
  const wrappedFromAddress = getWrappedAddress(chainId, fromTokenAddress);
31
32
  const wrappedToAddress = getWrappedAddress(chainId, toTokenAddress);
32
33
  const wrappedToken = getWrappedToken(chainId);
@@ -34,20 +35,19 @@ export const createFindSwapPath = (params) => {
34
35
  ? getTokenSwapPathsForTokenPairPrebuilt(chainId, wrappedFromAddress, wrappedToAddress)
35
36
  : [];
36
37
  const finalDisabledMarkets = [...(disabledMarkets ?? [])];
37
- if (isExpressFeeSwap) {
38
+ if (swapPricingType === SwapPricingType.AtomicSwap) {
38
39
  const expressSwapUnavailableMarkets = Object.values(marketsInfoData ?? {})
39
40
  .filter((market) => !getIsMarketAvailableForExpressSwaps(market))
40
41
  .map((market) => market.marketTokenAddress);
41
42
  finalDisabledMarkets.push(...expressSwapUnavailableMarkets);
42
43
  }
43
- const isAtomicSwap = Boolean(isExpressFeeSwap);
44
44
  const marketAdjacencyGraph = buildMarketAdjacencyGraph(chainId, finalDisabledMarkets);
45
45
  const cache = {};
46
46
  if (!marketsInfoData) {
47
47
  return FALLBACK_FIND_SWAP_PATH;
48
48
  }
49
49
  const marketEdgeLiquidityGetter = createMarketEdgeLiquidityGetter(marketsInfoData);
50
- const naiveEstimator = createNaiveSwapEstimator(marketsInfoData, isAtomicSwap);
50
+ const naiveEstimator = createNaiveSwapEstimator(marketsInfoData, swapPricingType);
51
51
  const naiveNetworkEstimator = gasEstimationParams
52
52
  ? createNaiveNetworkEstimator({
53
53
  gasLimits: gasEstimationParams.gasLimits,
@@ -56,7 +56,7 @@ export const createFindSwapPath = (params) => {
56
56
  chainId,
57
57
  })
58
58
  : undefined;
59
- const estimator = createSwapEstimator(marketsInfoData, isAtomicSwap);
59
+ const estimator = createSwapEstimator(marketsInfoData, swapPricingType);
60
60
  const findSwapPath = (usdIn, opts) => {
61
61
  if (tokenSwapPaths.length === 0 || !fromTokenAddress || !wrappedFromAddress || !wrappedToAddress) {
62
62
  return undefined;
@@ -126,7 +126,7 @@ export const createFindSwapPath = (params) => {
126
126
  shouldUnwrapNativeToken: toTokenAddress === NATIVE_TOKEN_ADDRESS,
127
127
  shouldApplyPriceImpact: true,
128
128
  usdIn,
129
- isAtomicSwap,
129
+ swapPricingType,
130
130
  });
131
131
  cache[cacheKey] = result;
132
132
  return result;
@@ -8,7 +8,7 @@ import { getByKey } from "../objects";
8
8
  import { DEFAULT_NAIVE_TOP_PATHS_COUNT } from "./constants";
9
9
  import { MARKETS_ADJACENCY_GRAPH, REACHABLE_TOKENS, TOKEN_SWAP_PATHS } from "./preparedSwapData";
10
10
  import { getSwapStats } from "./swapStats";
11
- export const createSwapEstimator = (marketsInfoData, isAtomicSwap) => {
11
+ export const createSwapEstimator = (marketsInfoData, swapPricingType) => {
12
12
  return (e, usdIn) => {
13
13
  const marketInfo = marketsInfoData[e.marketAddress];
14
14
  if (!marketInfo || marketInfo.isDisabled) {
@@ -22,7 +22,7 @@ export const createSwapEstimator = (marketsInfoData, isAtomicSwap) => {
22
22
  tokenInAddress: e.from,
23
23
  tokenOutAddress: e.to,
24
24
  shouldApplyPriceImpact: true,
25
- isAtomicSwap,
25
+ swapPricingType,
26
26
  });
27
27
  const isOutLiquidity = swapStats?.isOutLiquidity;
28
28
  const isOutCapacity = swapStats?.isOutCapacity;
@@ -48,7 +48,11 @@ export const createMarketEdgeLiquidityGetter = (marketsInfoData) => {
48
48
  return liquidity;
49
49
  };
50
50
  };
51
- export const createNaiveSwapEstimator = (marketsInfoData, isAtomicSwap) => {
51
+ /**
52
+ TODO MLTCH does naive estimator need to know about swap pricing type?
53
+ Its naive for a reason and i think it would work the same without knowing about it
54
+ */
55
+ export const createNaiveSwapEstimator = (marketsInfoData, swapPricingType) => {
52
56
  return (e, usdIn) => {
53
57
  let marketInfo = marketsInfoData[e.marketAddress];
54
58
  if (marketInfo === undefined || marketInfo.isDisabled) {
@@ -60,7 +64,7 @@ export const createNaiveSwapEstimator = (marketsInfoData, isAtomicSwap) => {
60
64
  tokenInAddress: e.from,
61
65
  tokenOutAddress: e.to,
62
66
  shouldApplyPriceImpact: true,
63
- isAtomicSwap,
67
+ swapPricingType,
64
68
  });
65
69
  const usdOut = swapStats?.usdOut;
66
70
  if (usdOut === undefined || usdOut === 0n || swapStats.isOutCapacity || swapStats.isOutLiquidity) {
@@ -78,7 +78,7 @@ export function getSwapPathOutputAddresses(p) {
78
78
  };
79
79
  }
80
80
  export function getSwapPathStats(p) {
81
- const { marketsInfoData, swapPath, initialCollateralAddress, usdIn, shouldUnwrapNativeToken, shouldApplyPriceImpact, wrappedNativeTokenAddress, isAtomicSwap, } = p;
81
+ const { marketsInfoData, swapPath, initialCollateralAddress, usdIn, shouldUnwrapNativeToken, shouldApplyPriceImpact, wrappedNativeTokenAddress, swapPricingType, } = p;
82
82
  if (swapPath.length === 0) {
83
83
  return undefined;
84
84
  }
@@ -108,7 +108,7 @@ export function getSwapPathStats(p) {
108
108
  tokenOutAddress,
109
109
  usdIn: usdOut,
110
110
  shouldApplyPriceImpact,
111
- isAtomicSwap,
111
+ swapPricingType,
112
112
  });
113
113
  tokenInAddress = swapStep.tokenOutAddress;
114
114
  usdOut = swapStep.usdOut;
@@ -134,7 +134,7 @@ export function getSwapPathStats(p) {
134
134
  };
135
135
  }
136
136
  export function getSwapStats(p) {
137
- const { marketInfo, tokenInAddress, tokenOutAddress, usdIn, shouldApplyPriceImpact, isAtomicSwap } = p;
137
+ const { marketInfo, tokenInAddress, tokenOutAddress, usdIn, shouldApplyPriceImpact, swapPricingType } = p;
138
138
  const isWrap = tokenInAddress === NATIVE_TOKEN_ADDRESS;
139
139
  const isUnwrap = tokenOutAddress === NATIVE_TOKEN_ADDRESS;
140
140
  const tokenIn = getTokenPoolType(marketInfo, tokenInAddress) === "long" ? marketInfo.longToken : marketInfo.shortToken;
@@ -152,7 +152,7 @@ export function getSwapStats(p) {
152
152
  catch (e) {
153
153
  // Approximate if the market would be out of capacity
154
154
  const capacityUsd = getSwapCapacityUsd(marketInfo, getTokenPoolType(marketInfo, tokenInAddress) === "long");
155
- const swapFeeUsd = getSwapFee(marketInfo, usdIn, false, isAtomicSwap);
155
+ const swapFeeUsd = getSwapFee(marketInfo, usdIn, false, swapPricingType);
156
156
  const usdInAfterFees = usdIn - swapFeeUsd;
157
157
  const isOutCapacity = capacityUsd < usdInAfterFees;
158
158
  return {
@@ -173,8 +173,8 @@ export function getSwapStats(p) {
173
173
  isOutCapacity,
174
174
  };
175
175
  }
176
- const swapFeeAmount = getSwapFee(marketInfo, amountIn, balanceWasImproved, isAtomicSwap);
177
- const swapFeeUsd = getSwapFee(marketInfo, usdIn, balanceWasImproved, isAtomicSwap);
176
+ const swapFeeAmount = getSwapFee(marketInfo, amountIn, balanceWasImproved, swapPricingType);
177
+ const swapFeeUsd = getSwapFee(marketInfo, usdIn, balanceWasImproved, swapPricingType);
178
178
  const amountInAfterFees = amountIn - swapFeeAmount;
179
179
  const usdInAfterFees = usdIn - swapFeeUsd;
180
180
  let usdOut = usdInAfterFees;
@@ -1,4 +1,5 @@
1
1
  import { BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
2
+ import { SwapPricingType } from "../../types/orders";
2
3
  import { bigMath } from "../bigmath";
3
4
  import { getTotalSwapVolumeFromSwapStats } from "../fees";
4
5
  import { applyFactor } from "../numbers";
@@ -17,6 +18,7 @@ export function getSwapAmountsByFromValue(p) {
17
18
  chainId,
18
19
  swapOptimizationOrder,
19
20
  externalSwapQuoteParams,
21
+ swapPricingType: SwapPricingType.Swap,
20
22
  });
21
23
  const swapPathStats = swapStrategy.swapPathStats;
22
24
  const totalSwapVolume = getTotalSwapVolumeFromSwapStats(swapPathStats?.swapSteps);
@@ -85,6 +87,7 @@ export function getSwapAmountsByToValue(p) {
85
87
  chainId,
86
88
  externalSwapQuoteParams,
87
89
  swapOptimizationOrder,
90
+ swapPricingType: SwapPricingType.Swap,
88
91
  });
89
92
  const swapStrategy = buildSwapStrategy({
90
93
  amountIn: swapStrategyReverse.amountIn,
@@ -94,6 +97,7 @@ export function getSwapAmountsByToValue(p) {
94
97
  chainId,
95
98
  swapOptimizationOrder,
96
99
  externalSwapQuoteParams,
100
+ swapPricingType: SwapPricingType.Swap,
97
101
  });
98
102
  const uiFeeUsd = applyFactor(swapStrategy.usdIn, uiFeeFactor);
99
103
  const defaultAmounts = {
@@ -1,5 +1,5 @@
1
1
  import { BASIS_POINTS_DIVISOR_BIGINT, DEFAULT_ALLOWED_SWAP_SLIPPAGE_BPS } from "../configs/factors";
2
- import { NATIVE_TOKEN_ADDRESS } from "../configs/tokens";
2
+ import { GLV_STUB_ADDRESS, getToken, NATIVE_TOKEN_ADDRESS, GM_STUB_ADDRESS } from "../configs/tokens";
3
3
  import { bigMath } from "./bigmath";
4
4
  import { adjustForDecimals, expandDecimals, PRECISION } from "./numbers";
5
5
  export function parseContractPrice(price, tokenDecimals) {
@@ -145,3 +145,17 @@ export function getTokensRatioByPrice(p) {
145
145
  const ratio = (largestPrice * PRECISION) / smallestPrice;
146
146
  return { ratio, largestToken, smallestToken };
147
147
  }
148
+ export function getGmToken(chainId, marketTokenAddress) {
149
+ const stubToken = getToken(chainId, GM_STUB_ADDRESS);
150
+ return {
151
+ ...stubToken,
152
+ address: marketTokenAddress,
153
+ };
154
+ }
155
+ export function getGlvToken(chainId, glvTokenAddress) {
156
+ const stubToken = getToken(chainId, GLV_STUB_ADDRESS);
157
+ return {
158
+ ...stubToken,
159
+ address: glvTokenAddress,
160
+ };
161
+ }
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER } from "../../configs/factors";
2
- import { DecreasePositionSwapType, OrderType } from "../../types/orders";
2
+ import { DecreasePositionSwapType, OrderType, SwapPricingType } from "../../types/orders";
3
3
  import { bigMath } from "../bigmath";
4
4
  import { getPositionFee } from "../fees";
5
5
  import { applyFactor, BASIS_POINTS_DIVISOR_BIGINT, expandDecimals, getBasisPoints, roundUpDivision, USD_DECIMALS, MaxUint256, } from "../numbers";
@@ -171,7 +171,7 @@ export function getDecreasePositionAmounts(p) {
171
171
  tokenOutAddress: collateralToken.address,
172
172
  usdIn: profitUsd,
173
173
  shouldApplyPriceImpact: true,
174
- isAtomicSwap: false,
174
+ swapPricingType: SwapPricingType.Swap,
175
175
  });
176
176
  values.swapProfitFeeUsd = swapProfitStats.swapFeeUsd - swapProfitStats.priceImpactDeltaUsd;
177
177
  values.swapUiFeeUsd = applyFactor(swapProfitStats.usdIn, uiFeeFactor);