@gmx-io/sdk 1.5.0-alpha-1 → 1.5.0-alpha-3

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 (162) hide show
  1. package/build/cjs/scripts/generate-platform-tokens.js +200 -0
  2. package/build/cjs/scripts/subsquid-codegen.js +1 -1
  3. package/build/cjs/src/clients/v1/modules/accounts/accounts.js +1 -1
  4. package/build/cjs/src/clients/v1/modules/markets/index.js +1 -1
  5. package/build/cjs/src/clients/v1/modules/markets/markets.spec.js +2 -2
  6. package/build/cjs/src/clients/v1/modules/orders/orders.js +4 -4
  7. package/build/cjs/src/clients/v1/modules/positions/positions.js +9 -151
  8. package/build/cjs/src/clients/v1/modules/tokens/tokens.js +1 -1
  9. package/build/cjs/src/clients/v1/modules/tokens/tokens.spec.js +2 -2
  10. package/build/cjs/src/clients/v1/modules/trades/trades.js +1 -1
  11. package/build/cjs/src/clients/v1/modules/utils/utils.js +1 -1
  12. package/build/cjs/src/clients/v2/index.js +13 -1
  13. package/build/cjs/src/codegen/platformTokens.json +134 -0
  14. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
  15. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +171 -0
  16. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +45 -0
  17. package/build/cjs/src/codegen/subsquid.js +142 -22
  18. package/build/cjs/src/configs/api.js +10 -6
  19. package/build/cjs/src/configs/markets.js +21 -0
  20. package/build/cjs/src/configs/tokens.js +35 -0
  21. package/build/cjs/src/utils/__tests__/fees.spec.js +1 -1
  22. package/build/cjs/src/utils/__tests__/numbers.spec.js +1 -1
  23. package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
  24. package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
  25. package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
  26. package/build/cjs/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
  27. package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
  28. package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
  29. package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
  30. package/build/cjs/src/utils/__tests__/parseError.spec.js +40 -0
  31. package/build/cjs/src/utils/__tests__/positions.spec.js +1 -1
  32. package/build/cjs/src/utils/__tests__/prices.spec.js +1 -1
  33. package/build/cjs/src/utils/__tests__/tokens.spec.js +191 -4
  34. package/build/cjs/src/utils/errors/parseError.js +67 -25
  35. package/build/cjs/src/utils/fees/executionFee.js +1 -1
  36. package/build/cjs/src/utils/fees/priceImpact.js +6 -1
  37. package/build/cjs/src/utils/markets/__tests__/mockMarkets.js +1 -1
  38. package/build/cjs/src/utils/markets/utils.js +15 -4
  39. package/build/cjs/src/utils/numbers/utils.js +4 -2
  40. package/build/cjs/src/utils/orders/api.js +13 -0
  41. package/build/cjs/src/utils/orders/index.js +1 -0
  42. package/build/cjs/src/utils/orders/utils.js +2 -2
  43. package/build/cjs/src/utils/positions/api.js +14 -0
  44. package/build/cjs/src/utils/positions/index.js +1 -0
  45. package/build/cjs/src/utils/positions/utils.js +213 -1
  46. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +1 -1
  47. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  48. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +1 -1
  49. package/build/cjs/src/utils/swap/buildSwapStrategy.js +1 -1
  50. package/build/cjs/src/utils/swap/externalSwapQuoteByPath.js +1 -1
  51. package/build/cjs/src/utils/swap/swapPath.js +1 -1
  52. package/build/cjs/src/utils/swap/swapValues.js +1 -1
  53. package/build/cjs/src/utils/tokens/utils.js +23 -3
  54. package/build/cjs/src/utils/trade/decrease.js +1 -1
  55. package/build/cjs/src/utils/trade/increase.js +1 -1
  56. package/build/cjs/src/utils/trade/trade.js +1 -1
  57. package/build/esm/scripts/generate-platform-tokens.js +195 -0
  58. package/build/esm/scripts/subsquid-codegen.js +1 -1
  59. package/build/esm/src/clients/v1/modules/accounts/accounts.js +1 -1
  60. package/build/esm/src/clients/v1/modules/markets/index.js +1 -1
  61. package/build/esm/src/clients/v1/modules/markets/markets.spec.js +1 -1
  62. package/build/esm/src/clients/v1/modules/orders/orders.js +4 -4
  63. package/build/esm/src/clients/v1/modules/positions/positions.js +12 -154
  64. package/build/esm/src/clients/v1/modules/tokens/tokens.js +1 -1
  65. package/build/esm/src/clients/v1/modules/tokens/tokens.spec.js +1 -1
  66. package/build/esm/src/clients/v1/modules/trades/trades.js +1 -1
  67. package/build/esm/src/clients/v1/modules/utils/utils.js +1 -1
  68. package/build/esm/src/clients/v2/index.js +13 -1
  69. package/build/esm/src/codegen/platformTokens.json +134 -0
  70. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
  71. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +171 -0
  72. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +45 -0
  73. package/build/esm/src/codegen/subsquid.js +141 -21
  74. package/build/esm/src/configs/api.js +8 -5
  75. package/build/esm/src/configs/markets.js +21 -0
  76. package/build/esm/src/configs/tokens.js +35 -0
  77. package/build/esm/src/utils/__tests__/fees.spec.js +1 -1
  78. package/build/esm/src/utils/__tests__/numbers.spec.js +1 -1
  79. package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
  80. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
  81. package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
  82. package/build/esm/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
  83. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
  84. package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
  85. package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
  86. package/build/esm/src/utils/__tests__/parseError.spec.js +40 -0
  87. package/build/esm/src/utils/__tests__/positions.spec.js +1 -1
  88. package/build/esm/src/utils/__tests__/prices.spec.js +1 -1
  89. package/build/esm/src/utils/__tests__/tokens.spec.js +192 -5
  90. package/build/esm/src/utils/errors/parseError.js +64 -24
  91. package/build/esm/src/utils/fees/executionFee.js +1 -1
  92. package/build/esm/src/utils/fees/priceImpact.js +5 -1
  93. package/build/esm/src/utils/markets/__tests__/mockMarkets.js +1 -1
  94. package/build/esm/src/utils/markets/utils.js +15 -4
  95. package/build/esm/src/utils/numbers/utils.js +2 -0
  96. package/build/esm/src/utils/orders/api.js +9 -0
  97. package/build/esm/src/utils/orders/index.js +1 -0
  98. package/build/esm/src/utils/orders/utils.js +2 -2
  99. package/build/esm/src/utils/positions/api.js +10 -0
  100. package/build/esm/src/utils/positions/index.js +1 -0
  101. package/build/esm/src/utils/positions/utils.js +213 -3
  102. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +1 -1
  103. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  104. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +1 -1
  105. package/build/esm/src/utils/swap/buildSwapStrategy.js +1 -1
  106. package/build/esm/src/utils/swap/externalSwapQuoteByPath.js +1 -1
  107. package/build/esm/src/utils/swap/swapPath.js +1 -1
  108. package/build/esm/src/utils/swap/swapValues.js +1 -1
  109. package/build/esm/src/utils/tokens/utils.js +23 -3
  110. package/build/esm/src/utils/trade/decrease.js +1 -1
  111. package/build/esm/src/utils/trade/increase.js +1 -1
  112. package/build/esm/src/utils/trade/trade.js +1 -1
  113. package/build/types/scripts/generate-platform-tokens.d.ts +27 -0
  114. package/build/types/src/clients/v1/modules/markets/index.d.ts +1 -1
  115. package/build/types/src/clients/v1/modules/oracle.d.ts +1 -1
  116. package/build/types/src/clients/v1/modules/orders/helpers.d.ts +1 -1
  117. package/build/types/src/clients/v1/modules/orders/orders.d.ts +2 -2
  118. package/build/types/src/clients/v1/modules/orders/transactions/cancelOrdersTxn.d.ts +1 -1
  119. package/build/types/src/clients/v1/modules/orders/transactions/createDecreaseOrderTxn.d.ts +1 -1
  120. package/build/types/src/clients/v1/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -1
  121. package/build/types/src/clients/v1/modules/orders/transactions/createSwapOrderTxn.d.ts +1 -1
  122. package/build/types/src/clients/v1/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
  123. package/build/types/src/clients/v1/modules/orders/transactions/updateOrderTxn.d.ts +1 -1
  124. package/build/types/src/clients/v1/modules/orders/utils.d.ts +2 -2
  125. package/build/types/src/clients/v1/modules/positions/positions.d.ts +1 -1
  126. package/build/types/src/clients/v1/modules/tokens/tokens.d.ts +1 -1
  127. package/build/types/src/clients/v1/modules/trades/trades.d.ts +2 -2
  128. package/build/types/src/clients/v1/modules/utils/utils.d.ts +1 -1
  129. package/build/types/src/clients/v2/index.d.ts +7 -0
  130. package/build/types/src/codegen/prebuilt/index.d.ts +240 -0
  131. package/build/types/src/codegen/subsquid.d.ts +492 -60
  132. package/build/types/src/configs/api.d.ts +1 -0
  133. package/build/types/src/utils/errors/parseError.d.ts +13 -1
  134. package/build/types/src/utils/fees/executionFee.d.ts +1 -1
  135. package/build/types/src/utils/fees/getNaiveEstimatedGasBySwapCount.d.ts +1 -1
  136. package/build/types/src/utils/fees/index.d.ts +1 -1
  137. package/build/types/src/utils/fees/priceImpact.d.ts +1 -0
  138. package/build/types/src/utils/markets/api.d.ts +1 -1
  139. package/build/types/src/utils/markets/multicall.d.ts +1 -1
  140. package/build/types/src/utils/markets/types.d.ts +8 -2
  141. package/build/types/src/utils/markets/utils.d.ts +1 -1
  142. package/build/types/src/utils/numbers/utils.d.ts +2 -0
  143. package/build/types/src/utils/orders/api.d.ts +7 -0
  144. package/build/types/src/utils/orders/index.d.ts +1 -0
  145. package/build/types/src/utils/orders/types.d.ts +27 -0
  146. package/build/types/src/utils/orders/utils.d.ts +1 -1
  147. package/build/types/src/utils/positions/api.d.ts +8 -0
  148. package/build/types/src/utils/positions/index.d.ts +1 -0
  149. package/build/types/src/utils/positions/types.d.ts +5 -16
  150. package/build/types/src/utils/positions/utils.d.ts +42 -1
  151. package/build/types/src/utils/swap/buildSwapStrategy.d.ts +1 -1
  152. package/build/types/src/utils/swap/findSwapPathsBetweenTokens.d.ts +1 -1
  153. package/build/types/src/utils/swap/preparedSwapData.d.ts +1 -1
  154. package/build/types/src/utils/swap/swapRouting.d.ts +1 -1
  155. package/build/types/src/utils/tokens/types.d.ts +1 -1
  156. package/build/types/src/utils/trade/decrease.d.ts +1 -1
  157. package/build/types/src/utils/trade/increase.d.ts +1 -1
  158. package/build/types/src/utils/trade/trade.d.ts +1 -1
  159. package/build/types/src/utils/tradeHistory/types.d.ts +2 -2
  160. package/build/types/src/utils/tradeHistory/utils.d.ts +1 -1
  161. package/build/types/src/utils/twap/index.d.ts +1 -1
  162. package/package.json +4 -3
@@ -1,9 +1,10 @@
1
1
  import { BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
2
2
  import { bigMath } from "../bigmath";
3
3
  import { capPositionImpactUsdByMaxImpactPool, capPositionImpactUsdByMaxPriceImpactFactor, getMaxPositionImpactFactors, getPositionFee, getPriceImpactForPosition, getProportionalPendingImpactValues, } from "../fees";
4
- import { getCappedPoolPnl, getMarketPnl, getOpenInterestUsd, getPoolUsdWithoutPnl } from "../markets";
5
- import { applyFactor, expandDecimals, PRECISION } from "../numbers";
6
- import { convertToUsd, getIsEquivalentTokens } from "../tokens";
4
+ import { getCappedPoolPnl, getMarketIndexName, getMarketPnl, getMarketPoolName, getMaxAllowedLeverageByMinCollateralFactor, getOpenInterestUsd, getPoolUsdWithoutPnl, } from "../markets";
5
+ import { applyFactor, expandDecimals, FLOAT_PRECISION_SQRT, getBasisPoints, PRECISION } from "../numbers";
6
+ import { getAcceptablePriceInfo, getMarkPrice } from "../prices";
7
+ import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens } from "../tokens";
7
8
  export function getPositionKey(account, marketAddress, collateralAddress, isLong) {
8
9
  return `${account}:${marketAddress}:${collateralAddress}:${isLong}`;
9
10
  }
@@ -195,3 +196,212 @@ export function getMinCollateralFactorForPosition(position, openInterestDelta) {
195
196
  }
196
197
  return minCollateralFactor;
197
198
  }
199
+ function getFundingAmount(latestFundingAmountPerSize, positionFundingAmountPerSize, positionSizeInUsd) {
200
+ const fundingDiffFactor = latestFundingAmountPerSize - positionFundingAmountPerSize;
201
+ // fundingAmountPerSize values are stored with FLOAT_PRECISION_SQRT precision
202
+ return bigMath.mulDiv(positionSizeInUsd, fundingDiffFactor, PRECISION * FLOAT_PRECISION_SQRT);
203
+ }
204
+ export function getContractPositionDynamicFees({ position, marketInfo, marketFeeState, referralInfo, }) {
205
+ const { sizeInUsd, isLong, borrowingFactor } = position;
206
+ const isCollateralLongToken = position.collateralTokenAddress === marketInfo.longToken.address;
207
+ const collateralToken = isCollateralLongToken ? marketInfo.longToken : marketInfo.shortToken;
208
+ const collateralMinPrice = collateralToken.prices.minPrice;
209
+ const cumulativeBorrowingFactor = isLong
210
+ ? marketFeeState.cumulativeBorrowingFactorLong
211
+ : marketFeeState.cumulativeBorrowingFactorShort;
212
+ const borrowingDiffFactor = cumulativeBorrowingFactor > borrowingFactor ? cumulativeBorrowingFactor - borrowingFactor : 0n;
213
+ const pendingBorrowingFeesUsd = applyFactor(sizeInUsd, borrowingDiffFactor);
214
+ let latestFundingFeeAmountPerSize;
215
+ if (isLong) {
216
+ latestFundingFeeAmountPerSize = isCollateralLongToken
217
+ ? marketFeeState.fundingFeeAmountPerSizeLongLong
218
+ : marketFeeState.fundingFeeAmountPerSizeLongShort;
219
+ }
220
+ else {
221
+ latestFundingFeeAmountPerSize = isCollateralLongToken
222
+ ? marketFeeState.fundingFeeAmountPerSizeShortLong
223
+ : marketFeeState.fundingFeeAmountPerSizeShortShort;
224
+ }
225
+ const fundingFeeAmount = getFundingAmount(latestFundingFeeAmountPerSize, position.fundingFeeAmountPerSize, sizeInUsd);
226
+ let latestLongTokenClaimableFundingAmountPerSize;
227
+ let latestShortTokenClaimableFundingAmountPerSize;
228
+ if (isLong) {
229
+ latestLongTokenClaimableFundingAmountPerSize = marketFeeState.claimableFundingAmountPerSizeLongLong;
230
+ latestShortTokenClaimableFundingAmountPerSize = marketFeeState.claimableFundingAmountPerSizeLongShort;
231
+ }
232
+ else {
233
+ latestLongTokenClaimableFundingAmountPerSize = marketFeeState.claimableFundingAmountPerSizeShortLong;
234
+ latestShortTokenClaimableFundingAmountPerSize = marketFeeState.claimableFundingAmountPerSizeShortShort;
235
+ }
236
+ const claimableLongTokenAmount = getFundingAmount(latestLongTokenClaimableFundingAmountPerSize, position.longTokenClaimableFundingAmountPerSize, sizeInUsd);
237
+ const claimableShortTokenAmount = getFundingAmount(latestShortTokenClaimableFundingAmountPerSize, position.shortTokenClaimableFundingAmountPerSize, sizeInUsd);
238
+ const { balanceWasImproved } = getPriceImpactForPosition(marketInfo, -sizeInUsd, isLong);
239
+ const { positionFeeUsd, discountUsd, uiFeeUsd } = getPositionFee(marketInfo, sizeInUsd, balanceWasImproved, referralInfo);
240
+ const positionFeeAmount = convertToTokenAmount(positionFeeUsd, collateralToken.decimals, collateralMinPrice) ?? 0n;
241
+ const traderDiscountAmount = convertToTokenAmount(discountUsd, collateralToken.decimals, collateralMinPrice) ?? 0n;
242
+ const uiFeeAmount = convertToTokenAmount(uiFeeUsd, collateralToken.decimals, collateralMinPrice) ?? 0n;
243
+ return {
244
+ pendingBorrowingFeesUsd,
245
+ fundingFeeAmount,
246
+ claimableLongTokenAmount,
247
+ claimableShortTokenAmount,
248
+ positionFeeAmount,
249
+ traderDiscountAmount,
250
+ uiFeeAmount,
251
+ };
252
+ }
253
+ export function getPositionInfo(p) {
254
+ const { position, marketInfo, minCollateralUsd, userReferralInfo, showPnlInLeverage = true, uiFeeFactor } = p;
255
+ const { indexToken, longToken, shortToken } = marketInfo;
256
+ const isCollateralLongToken = position.collateralTokenAddress === longToken.address;
257
+ const collateralToken = isCollateralLongToken ? longToken : shortToken;
258
+ const pnlToken = position.isLong ? longToken : shortToken;
259
+ const collateralMinPrice = collateralToken.prices.minPrice;
260
+ const markPrice = getMarkPrice({ prices: indexToken.prices, isLong: position.isLong, isIncrease: false });
261
+ const entryPrice = getEntryPrice({
262
+ sizeInTokens: position.sizeInTokens,
263
+ sizeInUsd: position.sizeInUsd,
264
+ indexToken,
265
+ });
266
+ const pendingFundingFeesUsd = convertToUsd(position.fundingFeeAmount, collateralToken.decimals, collateralMinPrice);
267
+ const pendingClaimableFundingFeesLongUsd = convertToUsd(position.claimableLongTokenAmount, longToken.decimals, longToken.prices.minPrice);
268
+ const pendingClaimableFundingFeesShortUsd = convertToUsd(position.claimableShortTokenAmount, shortToken.decimals, shortToken.prices.minPrice);
269
+ const pendingClaimableFundingFeesUsd = pendingClaimableFundingFeesLongUsd + pendingClaimableFundingFeesShortUsd;
270
+ const totalPendingFeesUsd = getPositionPendingFeesUsd({
271
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
272
+ pendingFundingFeesUsd,
273
+ });
274
+ const collateralUsd = convertToUsd(position.collateralAmount, collateralToken.decimals, collateralMinPrice);
275
+ const remainingCollateralUsd = collateralUsd - totalPendingFeesUsd;
276
+ const remainingCollateralAmount = convertToTokenAmount(remainingCollateralUsd, collateralToken.decimals, collateralMinPrice);
277
+ const pnl = getPositionPnlUsd({
278
+ marketInfo,
279
+ sizeInUsd: position.sizeInUsd,
280
+ sizeInTokens: position.sizeInTokens,
281
+ markPrice,
282
+ isLong: position.isLong,
283
+ });
284
+ const pnlPercentage = collateralUsd !== 0n ? getBasisPoints(pnl, collateralUsd) : 0n;
285
+ const closeAcceptablePriceInfo = getAcceptablePriceInfo({
286
+ marketInfo,
287
+ isIncrease: false,
288
+ isLimit: false,
289
+ isLong: position.isLong,
290
+ indexPrice: markPrice,
291
+ sizeDeltaUsd: position.sizeInUsd,
292
+ });
293
+ const positionFeeInfo = getPositionFee(marketInfo, position.sizeInUsd, closeAcceptablePriceInfo.balanceWasImproved, userReferralInfo, uiFeeFactor);
294
+ const closingFeeUsd = positionFeeInfo.positionFeeUsd;
295
+ const uiFeeUsd = positionFeeInfo.uiFeeUsd ?? 0n;
296
+ const netPriceImpactValues = getNetPriceImpactDeltaUsdForDecrease({
297
+ marketInfo,
298
+ sizeInUsd: position.sizeInUsd,
299
+ pendingImpactAmount: position.pendingImpactAmount,
300
+ sizeDeltaUsd: position.sizeInUsd,
301
+ priceImpactDeltaUsd: closeAcceptablePriceInfo.priceImpactDeltaUsd,
302
+ });
303
+ const netValue = getPositionNetValue({
304
+ collateralUsd,
305
+ pnl,
306
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
307
+ pendingFundingFeesUsd,
308
+ closingFeeUsd,
309
+ uiFeeUsd,
310
+ totalPendingImpactDeltaUsd: netPriceImpactValues.totalImpactDeltaUsd,
311
+ priceImpactDiffUsd: netPriceImpactValues.priceImpactDiffUsd,
312
+ });
313
+ const pnlAfterFees = getPositionPnlAfterFees({
314
+ pnl,
315
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
316
+ pendingFundingFeesUsd,
317
+ closingFeeUsd,
318
+ uiFeeUsd,
319
+ totalPendingImpactDeltaUsd: netPriceImpactValues.totalImpactDeltaUsd,
320
+ priceImpactDiffUsd: netPriceImpactValues.priceImpactDiffUsd,
321
+ });
322
+ const pnlAfterFeesPercentage = collateralUsd !== 0n ? getBasisPoints(pnlAfterFees, collateralUsd + closingFeeUsd) : 0n;
323
+ const leverage = getLeverage({
324
+ sizeInUsd: position.sizeInUsd,
325
+ collateralUsd,
326
+ pnl: showPnlInLeverage ? pnl : undefined,
327
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
328
+ pendingFundingFeesUsd,
329
+ });
330
+ const leverageWithPnl = getLeverage({
331
+ sizeInUsd: position.sizeInUsd,
332
+ collateralUsd,
333
+ pnl,
334
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
335
+ pendingFundingFeesUsd,
336
+ });
337
+ const leverageWithoutPnl = getLeverage({
338
+ sizeInUsd: position.sizeInUsd,
339
+ collateralUsd,
340
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
341
+ pendingFundingFeesUsd,
342
+ pnl: undefined,
343
+ });
344
+ const maxAllowedLeverage = getMaxAllowedLeverageByMinCollateralFactor(marketInfo.minCollateralFactor);
345
+ const hasLowCollateral = (leverage !== undefined && leverage > maxAllowedLeverage) || false;
346
+ const liquidationPrice = getLiquidationPrice({
347
+ marketInfo,
348
+ collateralToken,
349
+ sizeInUsd: position.sizeInUsd,
350
+ sizeInTokens: position.sizeInTokens,
351
+ collateralUsd,
352
+ collateralAmount: position.collateralAmount,
353
+ pendingImpactAmount: position.pendingImpactAmount,
354
+ userReferralInfo,
355
+ minCollateralUsd,
356
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
357
+ pendingFundingFeesUsd,
358
+ isLong: position.isLong,
359
+ });
360
+ const indexName = getMarketIndexName({ indexToken, isSpotOnly: false });
361
+ const poolName = getMarketPoolName({ longToken, shortToken });
362
+ const market = {
363
+ marketTokenAddress: marketInfo.marketTokenAddress,
364
+ indexTokenAddress: marketInfo.indexTokenAddress,
365
+ longTokenAddress: marketInfo.longTokenAddress,
366
+ shortTokenAddress: marketInfo.shortTokenAddress,
367
+ isSameCollaterals: marketInfo.isSameCollaterals,
368
+ isSpotOnly: marketInfo.isSpotOnly,
369
+ name: marketInfo.name,
370
+ data: marketInfo.data,
371
+ };
372
+ return {
373
+ ...position,
374
+ market,
375
+ marketInfo,
376
+ indexName,
377
+ poolName,
378
+ indexToken,
379
+ collateralToken,
380
+ pnlToken,
381
+ longToken,
382
+ shortToken,
383
+ markPrice,
384
+ entryPrice,
385
+ liquidationPrice,
386
+ collateralUsd,
387
+ remainingCollateralUsd,
388
+ remainingCollateralAmount,
389
+ hasLowCollateral,
390
+ leverage,
391
+ leverageWithPnl,
392
+ leverageWithoutPnl,
393
+ pnl,
394
+ pnlPercentage,
395
+ pnlAfterFees,
396
+ pnlAfterFeesPercentage,
397
+ netValue,
398
+ netPriceImapctDeltaUsd: netPriceImpactValues.totalImpactDeltaUsd,
399
+ priceImpactDiffUsd: netPriceImpactValues.priceImpactDiffUsd,
400
+ pendingImpactUsd: netPriceImpactValues.proportionalPendingImpactDeltaUsd,
401
+ closePriceImpactDeltaUsd: closeAcceptablePriceInfo.priceImpactDeltaUsd,
402
+ closingFeeUsd,
403
+ uiFeeUsd,
404
+ pendingFundingFeesUsd,
405
+ pendingClaimableFundingFeesUsd,
406
+ };
407
+ }
@@ -1,13 +1,13 @@
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 { mockMarketsInfoData, mockTokensData, usdToToken } from "../../../test/mock";
4
5
  import { expandDecimals } from "../../numbers";
5
6
  import { SwapPricingType } from "../../orders/types";
6
7
  import { getSwapPathStats } from "..";
7
8
  import { buildMarketsAdjacencyGraph } from "../buildMarketsAdjacencyGraph";
8
9
  import { findSwapPathsBetweenTokens } from "../findSwapPathsBetweenTokens";
9
10
  import { createMarketEdgeLiquidityGetter, createNaiveNetworkEstimator, createNaiveSwapEstimator, getMaxLiquidityMarketSwapPathFromTokenSwapPaths, getNaiveBestMarketSwapPathsFromTokenSwapPaths, getTokenSwapPathsForTokenPair, } from "../swapRouting";
10
- import { mockMarketsInfoData, mockTokensData, usdToToken } from "../../../test/mock";
11
11
  const marketKeys = [
12
12
  "ETH-ETH-USDC",
13
13
  "BTC-BTC-USDC",
@@ -1,8 +1,8 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { USD_DECIMALS } from "../../../configs/factors";
3
+ import { mockMarketsInfoData, mockTokensData } from "../../../test/mock";
3
4
  import { bigMath } from "../../bigmath";
4
5
  import { SwapPricingType } from "../../orders/types";
5
- import { mockMarketsInfoData, mockTokensData } from "../../../test/mock";
6
6
  import { buildMarketsAdjacencyGraph } from "../buildMarketsAdjacencyGraph";
7
7
  import { createMarketEdgeLiquidityGetter, createNaiveSwapEstimator, createSwapEstimator, getBestMarketForTokenEdge, getBestSwapPath, getMaxLiquidityMarketForTokenEdge, getMaxLiquidityMarketSwapPathFromTokenSwapPaths, getNaiveBestMarketSwapPathsFromTokenSwapPaths, } from "../swapRouting";
8
8
  const dollar = 10n ** BigInt(USD_DECIMALS);
@@ -1,8 +1,8 @@
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 "../../orders/types";
5
4
  import { mockMarketsInfoData as createMockMarketsInfoData, mockTokensData, usdToToken } from "../../../test/mock";
5
+ import { SwapPricingType } from "../../orders/types";
6
6
  import { getSwapPathOutputAddresses, getSwapPathStats } from "../swapStats";
7
7
  const someWrappedToken = "0x0000000000000000000000000000000000000001";
8
8
  const someNativeToken = "0x0000000000000000000000000000000000000000";
@@ -1,9 +1,9 @@
1
1
  import { bigMath } from "../bigmath";
2
+ import { SwapPricingType } from "../orders/types";
2
3
  import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens, getIsStake, getIsUnstake, getIsUnwrap, getIsWrap, getMidPrice, } from "../tokens";
3
4
  import { getAvailableExternalSwapPaths } from "./externalSwapPath";
4
5
  import { getExternalSwapQuoteByPath } from "./externalSwapQuoteByPath";
5
6
  import { createFindSwapPath } from "./swapPath";
6
- import { SwapPricingType } from "../orders/types";
7
7
  /*
8
8
  Order/Priority of getting swap strategy:
9
9
  1. Check if it needs a swap and return noSwap if tokens are equivalent, stake or unstake [noSwap]
@@ -1,5 +1,5 @@
1
+ import { ExternalSwapAggregator, } from "../trade/types";
1
2
  import { getBotanixStakingExternalSwapQuote } from "./botanixStaking";
2
- import { ExternalSwapAggregator } from "../trade/types";
3
3
  export const getExternalSwapQuoteByPath = ({ amountIn, externalSwapPath, externalSwapQuoteParams, }) => {
4
4
  if (amountIn === undefined ||
5
5
  externalSwapQuoteParams.gasPrice === undefined ||
@@ -2,10 +2,10 @@ import { MARKETS } from "../../configs/markets";
2
2
  import { convertTokenAddress, getWrappedToken, NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
3
3
  import { LRUCache } from "../LruCache";
4
4
  import { getIsMarketAvailableForExpressSwaps } from "../markets";
5
+ import { SwapPricingType } from "../orders/types";
5
6
  import { buildMarketsAdjacencyGraph } from "./buildMarketsAdjacencyGraph";
6
7
  import { createMarketEdgeLiquidityGetter, createNaiveNetworkEstimator, createNaiveSwapEstimator, createSwapEstimator, getBestSwapPath, getMarketAdjacencyGraph, getMaxLiquidityMarketSwapPathFromTokenSwapPaths, getNaiveBestMarketSwapPathsFromTokenSwapPaths, getTokenSwapPathsForTokenPairPrebuilt, marketRouteToMarketEdges, } from "./swapRouting";
7
8
  import { getSwapPathStats } from "./swapStats";
8
- import { SwapPricingType } from "../orders/types";
9
9
  export const getWrappedAddress = (chainId, address) => {
10
10
  return address ? convertTokenAddress(chainId, address, "wrapped") : undefined;
11
11
  };
@@ -2,9 +2,9 @@ import { BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
2
2
  import { bigMath } from "../bigmath";
3
3
  import { getTotalSwapVolumeFromSwapStats } from "../fees";
4
4
  import { applyFactor } from "../numbers";
5
+ import { SwapPricingType } from "../orders/types";
5
6
  import { convertToTokenAmount, convertToUsd, getAmountByRatio, getIsEquivalentTokens, getIsStake, getIsUnstake, getIsUnwrap, getIsWrap, } from "../tokens";
6
7
  import { buildReverseSwapStrategy, buildSwapStrategy } from "./buildSwapStrategy";
7
- import { SwapPricingType } from "../orders/types";
8
8
  export function getSwapAmountsByFromValue(p) {
9
9
  const { tokenIn, tokenOut, amountIn, triggerRatio, isLimit, swapOptimizationOrder, uiFeeFactor, allowedSwapSlippageBps, marketsInfoData, chainId, externalSwapQuoteParams, allowSameTokenSwap, } = p;
10
10
  if (!externalSwapQuoteParams) {
@@ -75,6 +75,11 @@ export function getTokensRatioByAmounts(p) {
75
75
  const { fromToken, toToken, fromTokenAmount, toTokenAmount } = p;
76
76
  const adjustedFromAmount = (fromTokenAmount * PRECISION) / expandDecimals(1, fromToken.decimals);
77
77
  const adjustedToAmount = (toTokenAmount * PRECISION) / expandDecimals(1, toToken.decimals);
78
+ const areBothStablecoins = fromToken.isStable && toToken.isStable;
79
+ if (areBothStablecoins) {
80
+ const ratio = adjustedToAmount > 0 ? (adjustedFromAmount * PRECISION) / adjustedToAmount : 0n;
81
+ return { ratio, largestToken: toToken, smallestToken: fromToken };
82
+ }
78
83
  const [smallestToken, largestToken, largestAmount, smallestAmount] = adjustedFromAmount > adjustedToAmount
79
84
  ? [fromToken, toToken, adjustedFromAmount, adjustedToAmount]
80
85
  : [toToken, fromToken, adjustedToAmount, adjustedFromAmount];
@@ -93,17 +98,27 @@ export function getTokensRatioByMinOutputAmountAndTriggerPrice(p) {
93
98
  const adjustedFromAmount = (fromTokenAmount * PRECISION) / expandDecimals(1, fromToken.decimals);
94
99
  const adjustedToAmount = (minOutputAmount * PRECISION) / expandDecimals(1, toToken.decimals);
95
100
  const adjustedMinOutputAmount = (minOutputAmount * PRECISION) / expandDecimals(1, toToken.decimals);
96
- [smallestToken, largestToken, largestAmount, smallestAmount] =
97
- adjustedFromAmount > adjustedToAmount
101
+ const areBothStablecoins = fromToken.isStable && toToken.isStable;
102
+ const isFromAmountLarger = adjustedFromAmount > adjustedToAmount;
103
+ if (areBothStablecoins) {
104
+ smallestToken = fromToken;
105
+ largestToken = toToken;
106
+ largestAmount = adjustedFromAmount;
107
+ smallestAmount = adjustedToAmount;
108
+ }
109
+ else {
110
+ [smallestToken, largestToken, largestAmount, smallestAmount] = isFromAmountLarger
98
111
  ? [fromToken, toToken, adjustedFromAmount, adjustedToAmount]
99
112
  : [toToken, fromToken, adjustedToAmount, adjustedFromAmount];
113
+ }
100
114
  ratio = smallestAmount > 0 ? (largestAmount * PRECISION) / smallestAmount : 0n;
101
115
  if (triggerPrice === 0n) {
102
116
  allowedSwapSlippageBps = DEFAULT_ALLOWED_SWAP_SLIPPAGE_BPS;
103
117
  acceptablePrice = ratio;
104
118
  }
105
119
  else {
106
- const outputAtTriggerPrice = adjustedFromAmount > adjustedToAmount
120
+ const shouldDivide = areBothStablecoins ? true : isFromAmountLarger;
121
+ const outputAtTriggerPrice = shouldDivide
107
122
  ? (adjustedFromAmount * PRECISION) / triggerPrice
108
123
  : (adjustedFromAmount * triggerPrice) / PRECISION;
109
124
  allowedSwapSlippageBps =
@@ -141,6 +156,11 @@ export function getIsUnstake(token1, token2) {
141
156
  }
142
157
  export function getTokensRatioByPrice(p) {
143
158
  const { fromToken, toToken, fromPrice, toPrice } = p;
159
+ const areBothStablecoins = fromToken.isStable && toToken.isStable;
160
+ if (areBothStablecoins) {
161
+ const ratio = fromPrice > 0n ? (toPrice * PRECISION) / fromPrice : PRECISION;
162
+ return { ratio, largestToken: toToken, smallestToken: fromToken };
163
+ }
144
164
  const [largestToken, smallestToken, largestPrice, smallestPrice] = fromPrice > toPrice ? [fromToken, toToken, fromPrice, toPrice] : [toToken, fromToken, toPrice, fromPrice];
145
165
  const ratio = (largestPrice * PRECISION) / smallestPrice;
146
166
  return { ratio, largestToken, smallestToken };
@@ -2,11 +2,11 @@ import { DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER } from "../../configs/factors";
2
2
  import { bigMath } from "../bigmath";
3
3
  import { getPositionFee } from "../fees";
4
4
  import { applyFactor, BASIS_POINTS_DIVISOR_BIGINT, expandDecimals, getBasisPoints, roundUpDivision, USD_DECIMALS, MaxUint256, } from "../numbers";
5
+ import { DecreasePositionSwapType, OrderType, SwapPricingType } from "../orders/types";
5
6
  import { getLeverage, getLiquidationPrice, getMinCollateralFactorForPosition, getNetPriceImpactDeltaUsdForDecrease, getPositionPnlUsd, } from "../positions";
6
7
  import { getAcceptablePriceInfo, getDefaultAcceptablePriceImpactBps, getMarkPrice, getOrderThresholdType, } from "../prices";
7
8
  import { getSwapStats } from "../swap";
8
9
  import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens } from "../tokens";
9
- import { DecreasePositionSwapType, OrderType, SwapPricingType } from "../orders/types";
10
10
  export function getDecreasePositionAmounts(p) {
11
11
  const { marketInfo, collateralToken, isLong, position, closeSizeUsd, keepLeverage, triggerPrice, fixedAcceptablePriceImpactBps, acceptablePriceImpactBuffer, userReferralInfo, minCollateralUsd, minPositionSizeUsd, uiFeeFactor, triggerOrderType: orderType, receiveToken: receiveTokenArg, isSetAcceptablePriceImpactEnabled, } = p;
12
12
  const { indexToken } = marketInfo;
@@ -3,11 +3,11 @@ import { BASIS_POINTS_DIVISOR_BIGINT, DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER } f
3
3
  import { bigMath } from "../bigmath";
4
4
  import { capPositionImpactUsdByMaxImpactPool, capPositionImpactUsdByMaxPriceImpactFactor, getPositionFee, getPriceImpactForPosition, getTotalSwapVolumeFromSwapStats, } from "../fees";
5
5
  import { applyFactor } from "../numbers";
6
+ import { OrderType } from "../orders/types";
6
7
  import { getEntryPrice, getLeverage, getLiquidationPrice, getPositionPnlUsd, getPriceImpactDiffUsd, } from "../positions";
7
8
  import { getAcceptablePriceInfo, getDefaultAcceptablePriceImpactBps, getMarkPrice, getOrderThresholdType, } from "../prices";
8
9
  import { getSwapAmountsByFromValue, getSwapAmountsByToValue } from "../swap";
9
10
  import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens, getTokensRatioByPrice } from "../tokens";
10
- import { OrderType } from "../orders/types";
11
11
  export function getIncreasePositionAmounts(p) {
12
12
  const { marketInfo, indexToken, initialCollateralToken, collateralToken, initialCollateralAmount, indexTokenAmount, isLong, leverage, triggerPrice, limitOrderType, position, fixedAcceptablePriceImpactBps, acceptablePriceImpactBuffer, externalSwapQuote, findSwapPath, userReferralInfo, uiFeeFactor, strategy, marketsInfoData, chainId, externalSwapQuoteParams, isSetAcceptablePriceImpactEnabled, } = p;
13
13
  const swapStrategy = {
@@ -2,7 +2,7 @@ import { BASIS_POINTS_DIVISOR, BASIS_POINTS_DIVISOR_BIGINT } from "../../configs
2
2
  import { bigMath } from "../bigmath";
3
3
  import { DecreasePositionSwapType } from "../orders/types";
4
4
  import { getShouldUseMaxPrice } from "../prices";
5
- import { TradeMode, TradeType, } from "../trade/types";
5
+ import { TradeMode, TradeType, } from "./types";
6
6
  export function applySlippageToPrice(allowedSlippage, price, isIncrease, isLong) {
7
7
  const shouldIncreasePrice = getShouldUseMaxPrice(isIncrease, isLong);
8
8
  const slippageBasisPoints = shouldIncreasePrice
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Generate platform tokens JSON from gmxLayerZero deployments folder
3
+ *
4
+ * Prerequisites:
5
+ * Cloned https://github.com/gmx-io/layer-zero repository
6
+ *
7
+ * Usage:
8
+ * yarn tsx sdk/scripts/generate-platform-tokens.ts <layer-zero-path>
9
+ *
10
+ * Example:
11
+ * # Relative to monorepo root
12
+ * yarn tsx sdk/scripts/generate-platform-tokens.ts ../layer-zero
13
+ * yarn tsx sdk/scripts/generate-platform-tokens.ts /path/to/layer-zero
14
+ *
15
+ *
16
+ * Expected folder structure:
17
+ * layer-zero/
18
+ * deployments/
19
+ * arbitrum-mainnet/
20
+ * .chainId
21
+ * TokenName.json
22
+ * base-mainnet/
23
+ * .chainId
24
+ * TokenName.json
25
+ * ...
26
+ */
27
+ export {};
@@ -1,6 +1,6 @@
1
+ import { Module } from "../base";
1
2
  import { MarketsData, MarketsInfoData } from "../../../../utils/markets/types";
2
3
  import { TokensData } from "../../../../utils/tokens/types";
3
- import { Module } from "../base";
4
4
  export declare class Markets extends Module {
5
5
  private getClaimableFundingData;
6
6
  private getMarketsValues;
@@ -1,5 +1,5 @@
1
+ import type { GmxSdk } from "..";
1
2
  import { MarketSdkConfig } from "../../../utils/markets/types";
2
- import type { GmxSdk } from "../index";
3
3
  export type TickersResponse = {
4
4
  minPrice: string;
5
5
  maxPrice: string;
@@ -1,7 +1,7 @@
1
+ import type { GmxSdk } from "../..";
1
2
  import type { GasLimitsConfig } from "../../../../utils/fees/types";
2
3
  import { MarketsInfoData } from "../../../../utils/markets/types";
3
4
  import { TokensData } from "../../../../utils/tokens/types";
4
- import type { GmxSdk } from "../..";
5
5
  /** Base Optional params for helpers, allows to avoid calling markets, tokens and uiFeeFactor methods if they are already passed */
6
6
  interface BaseOptionalParams {
7
7
  marketsInfoData?: MarketsInfoData;
@@ -1,12 +1,12 @@
1
+ import { Module } from "../base";
1
2
  import { MarketFilterLongShortItemData } from "../trades/trades";
2
3
  import { MarketInfo, MarketsInfoData } from "../../../../utils/markets/types";
3
4
  import { OrdersInfoData, OrderType } from "../../../../utils/orders/types";
5
+ import { SidecarLimitOrderEntryValid, SidecarSlTpOrderEntryValid } from "../../../../utils/sidecarOrders/types";
4
6
  import { TokenData, TokensData } from "../../../../utils/tokens/types";
5
7
  import { DecreasePositionAmounts, IncreasePositionAmounts, SwapAmounts } from "../../../../utils/trade/types";
6
- import { Module } from "../base";
7
8
  import { PositionIncreaseParams, SwapParams } from "./helpers";
8
9
  import { WrapOrUnwrapParams } from "./transactions/createWrapOrUnwrapTxn";
9
- import { SidecarLimitOrderEntryValid, SidecarSlTpOrderEntryValid } from "../../../../utils/sidecarOrders/types";
10
10
  export declare class Orders extends Module {
11
11
  getOrders({ account: _account, marketsInfoData, tokensData, orderTypesFilter, marketsDirectionsFilter, }: {
12
12
  account?: string;
@@ -1,4 +1,4 @@
1
- import type { GmxSdk } from "../../../index";
1
+ import type { GmxSdk } from "../../..";
2
2
  export type CancelOrderParams = {
3
3
  orderKeys: string[];
4
4
  };
@@ -1,6 +1,6 @@
1
+ import type { GmxSdk } from "../../..";
1
2
  import type { DecreasePositionSwapType, OrderType } from "../../../../../utils/orders/types";
2
3
  import type { Token, TokensData } from "../../../../../utils/tokens/types";
3
- import type { GmxSdk } from "../../../index";
4
4
  export type DecreaseOrderParams = {
5
5
  account: string;
6
6
  marketAddress: string;
@@ -1,7 +1,7 @@
1
+ import type { GmxSdk } from "../../..";
1
2
  import { OrderTxnType, OrderType } from "../../../../../utils/orders/types";
2
3
  import { TokenData, TokenPrices, TokensData } from "../../../../../utils/tokens/types";
3
4
  import { DecreaseOrderParams } from "./createDecreaseOrderTxn";
4
- import type { GmxSdk } from "../../../index";
5
5
  export type PriceOverrides = {
6
6
  [address: string]: TokenPrices | undefined;
7
7
  };
@@ -1,6 +1,6 @@
1
+ import type { GmxSdk } from "../../..";
1
2
  import { OrderType } from "../../../../../utils/orders/types";
2
3
  import { TokensData } from "../../../../../utils/tokens/types";
3
- import type { GmxSdk } from "../../..";
4
4
  export type SwapOrderParams = {
5
5
  fromTokenAddress: string;
6
6
  fromTokenAmount: bigint;
@@ -1,4 +1,4 @@
1
- import type { GmxSdk } from "../../../index";
1
+ import type { GmxSdk } from "../../..";
2
2
  export type WrapOrUnwrapParams = {
3
3
  amount: bigint;
4
4
  isWrap: boolean;
@@ -1,6 +1,6 @@
1
1
  import { Address } from "viem";
2
+ import type { GmxSdk } from "../../..";
2
3
  import { Token } from "../../../../../utils/tokens/types";
3
- import type { GmxSdk } from "../../../index";
4
4
  export type UpdateOrderParams = {
5
5
  orderKey: string;
6
6
  indexToken?: Token;
@@ -1,13 +1,13 @@
1
1
  import { Address } from "viem";
2
+ import type { GmxSdk } from "../..";
2
3
  import type { MarketFilterLongShortDirection, MarketFilterLongShortItemData } from "../trades/trades";
3
4
  import type { MulticallResult } from "../../multicall";
4
5
  import type { ContractsChainId } from "../../../../configs/chains";
5
6
  import type { GasLimitsConfig } from "../../../../utils/fees/types";
6
7
  import type { MarketsInfoData } from "../../../../utils/markets/types";
7
8
  import { DecreasePositionSwapType, Order } from "../../../../utils/orders/types";
8
- import type { TokensData } from "../../../../utils/tokens/types";
9
9
  import { SidecarLimitOrderEntry, SidecarSlTpOrderEntry } from "../../../../utils/sidecarOrders/types";
10
- import type { GmxSdk } from "../../index";
10
+ import type { TokensData } from "../../../../utils/tokens/types";
11
11
  export declare const getOrderExecutionFee: (sdk: GmxSdk, swapsCount: number, decreasePositionSwapType: DecreasePositionSwapType | undefined, gasLimits: GasLimitsConfig | undefined, tokensData: TokensData | undefined, gasPrice: bigint | undefined) => import("../../../../utils/fees/types").ExecutionFee | undefined;
12
12
  export declare const getExecutionFeeAmountForEntry: (sdk: GmxSdk, entry: SidecarSlTpOrderEntry | SidecarLimitOrderEntry, gasLimits: GasLimitsConfig, tokensData: TokensData, gasPrice: bigint | undefined) => bigint | undefined;
13
13
  export declare function matchByMarket({ order, nonSwapRelevantDefinedFiltersLowercased, hasNonSwapRelevantDefinedMarkets, pureDirectionFilters, hasPureDirectionFilters, swapRelevantDefinedMarketsLowercased, hasSwapRelevantDefinedMarkets, marketsInfoData, chainId, }: {
@@ -1,8 +1,8 @@
1
+ import { Module } from "../base";
1
2
  import { MarketsData, MarketsInfoData } from "../../../../utils/markets/types";
2
3
  import { OrderInfo } from "../../../../utils/orders/types";
3
4
  import { PositionsData, PositionsInfoData } from "../../../../utils/positions/types";
4
5
  import { TokensData } from "../../../../utils/tokens/types";
5
- import { Module } from "../base";
6
6
  type PositionsResult = {
7
7
  positionsData?: PositionsData;
8
8
  allPossiblePositionsKeys?: string[];
@@ -1,5 +1,5 @@
1
- import { TokensData, Token as TToken } from "../../../../utils/tokens/types";
2
1
  import { Module } from "../base";
2
+ import { TokensData, Token as TToken } from "../../../../utils/tokens/types";
3
3
  type TokensDataResult = {
4
4
  tokensData?: TokensData;
5
5
  pricesUpdatedAt?: number;
@@ -1,10 +1,10 @@
1
1
  import type { Address } from "viem";
2
+ import type { GmxSdk } from "../..";
3
+ import { Module } from "../base";
2
4
  import { MarketsInfoData } from "../../../../utils/markets/types";
3
5
  import { OrderType } from "../../../../utils/orders/types";
4
6
  import { TokensData } from "../../../../utils/tokens/types";
5
7
  import { TradeAction, TradeActionType } from "../../../../utils/tradeHistory/types";
6
- import type { GmxSdk } from "../..";
7
- import { Module } from "../base";
8
8
  export type MarketFilterLongShortDirection = "long" | "short" | "swap" | "any";
9
9
  export type MarketFilterLongShortItemData = {
10
10
  marketAddress: Address | "any";
@@ -1,7 +1,7 @@
1
+ import { Module } from "../base";
1
2
  import type { GasLimitsConfig } from "../../../../utils/fees/types";
2
3
  import { TokensData } from "../../../../utils/tokens/types";
3
4
  import type { DecreasePositionAmounts, IncreasePositionAmounts, SwapAmounts, TradeFeesType } from "../../../../utils/trade/types";
4
- import { Module } from "../base";
5
5
  export declare class Utils extends Module {
6
6
  private _gasLimits;
7
7
  getGasLimits(): Promise<GasLimitsConfig>;
@@ -10,4 +10,11 @@ export declare class GmxApiSdk {
10
10
  });
11
11
  fetchMarketsInfo(): Promise<import("../../utils/markets").RawMarketInfo[]>;
12
12
  fetchTokensData(): Promise<import("../../utils/tokens").TokenData[]>;
13
+ fetchPositionsInfo(params: {
14
+ account: string;
15
+ includeRelatedOrders?: boolean;
16
+ }): Promise<import("../../utils/positions").ApiPositionInfo[]>;
17
+ fetchOrders(params: {
18
+ account: string;
19
+ }): Promise<import("../../utils/orders").ApiOrderInfo[]>;
13
20
  }