@gmx-io/sdk 1.5.0-alpha-7 → 1.5.0-alpha-9

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 (113) hide show
  1. package/build/cjs/src/clients/v1/testUtil.js +1 -1
  2. package/build/cjs/src/clients/v2/index.js +42 -9
  3. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +34 -0
  4. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +230 -0
  5. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +62 -0
  6. package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -0
  7. package/build/cjs/src/configs/api.js +4 -3
  8. package/build/cjs/src/configs/batch.js +13 -0
  9. package/build/cjs/src/configs/chainIds.js +2 -1
  10. package/build/cjs/src/configs/chains.js +48 -2
  11. package/build/cjs/src/configs/contracts.js +67 -0
  12. package/build/cjs/src/configs/express.js +3 -6
  13. package/build/cjs/src/configs/fees.js +9 -0
  14. package/build/cjs/src/configs/gasLimits.js +7 -0
  15. package/build/cjs/src/configs/markets.js +30 -0
  16. package/build/cjs/src/configs/oracleKeeper.js +2 -0
  17. package/build/cjs/src/configs/tokens.js +89 -1
  18. package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
  19. package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
  20. package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
  21. package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +24 -0
  22. package/build/cjs/src/utils/apy/api.js +11 -0
  23. package/build/cjs/src/utils/apy/types.js +2 -0
  24. package/build/cjs/src/utils/errors/parseError.js +3 -0
  25. package/build/cjs/src/utils/fees/executionFee.js +11 -3
  26. package/build/cjs/src/utils/markets/api.js +16 -1
  27. package/build/cjs/src/utils/numbers/utils.js +4 -0
  28. package/build/cjs/src/utils/orderTransactions/utils.js +2 -2
  29. package/build/cjs/src/utils/pairs/api.js +7 -0
  30. package/build/cjs/src/utils/pairs/types.js +2 -0
  31. package/build/cjs/src/utils/performance/api.js +21 -0
  32. package/build/cjs/src/utils/performance/types.js +2 -0
  33. package/build/cjs/src/utils/rates/api.js +13 -0
  34. package/build/cjs/src/utils/rates/types.js +2 -0
  35. package/build/cjs/src/utils/staking/api.js +11 -0
  36. package/build/cjs/src/utils/staking/types.js +2 -0
  37. package/build/cjs/src/utils/swap/swapValues.js +3 -3
  38. package/build/cjs/src/utils/tokens/api.js +7 -0
  39. package/build/cjs/src/utils/trade/decrease.js +131 -6
  40. package/build/cjs/src/utils/trade/increase.js +2 -6
  41. package/build/cjs/src/utils/twap/uiFeeReceiver.js +29 -13
  42. package/build/esm/src/clients/v1/testUtil.js +1 -1
  43. package/build/esm/src/clients/v2/index.js +34 -1
  44. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +34 -0
  45. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +230 -0
  46. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +62 -0
  47. package/build/esm/src/configs/__tests__/tokens.spec.js +2 -1
  48. package/build/esm/src/configs/api.js +5 -4
  49. package/build/esm/src/configs/batch.js +14 -1
  50. package/build/esm/src/configs/chainIds.js +1 -0
  51. package/build/esm/src/configs/chains.js +48 -3
  52. package/build/esm/src/configs/contracts.js +68 -1
  53. package/build/esm/src/configs/express.js +4 -7
  54. package/build/esm/src/configs/fees.js +6 -0
  55. package/build/esm/src/configs/gasLimits.js +8 -1
  56. package/build/esm/src/configs/markets.js +31 -1
  57. package/build/esm/src/configs/oracleKeeper.js +3 -1
  58. package/build/esm/src/configs/tokens.js +90 -2
  59. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
  60. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
  61. package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
  62. package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +25 -1
  63. package/build/esm/src/utils/apy/api.js +7 -0
  64. package/build/esm/src/utils/apy/types.js +1 -0
  65. package/build/esm/src/utils/errors/parseError.js +3 -0
  66. package/build/esm/src/utils/fees/executionFee.js +8 -2
  67. package/build/esm/src/utils/markets/api.js +13 -0
  68. package/build/esm/src/utils/numbers/utils.js +4 -0
  69. package/build/esm/src/utils/orderTransactions/utils.js +2 -2
  70. package/build/esm/src/utils/pairs/api.js +3 -0
  71. package/build/esm/src/utils/pairs/types.js +1 -0
  72. package/build/esm/src/utils/performance/api.js +16 -0
  73. package/build/esm/src/utils/performance/types.js +1 -0
  74. package/build/esm/src/utils/rates/api.js +9 -0
  75. package/build/esm/src/utils/rates/types.js +1 -0
  76. package/build/esm/src/utils/staking/api.js +7 -0
  77. package/build/esm/src/utils/staking/types.js +1 -0
  78. package/build/esm/src/utils/swap/swapValues.js +3 -3
  79. package/build/esm/src/utils/tokens/api.js +3 -0
  80. package/build/esm/src/utils/trade/decrease.js +127 -7
  81. package/build/esm/src/utils/trade/increase.js +3 -7
  82. package/build/esm/src/utils/twap/uiFeeReceiver.js +27 -12
  83. package/build/types/src/clients/v1/index.d.ts +1 -1
  84. package/build/types/src/clients/v1/modules/base.d.ts +1 -1
  85. package/build/types/src/clients/v1/multicall.d.ts +1 -1
  86. package/build/types/src/clients/v2/index.d.ts +26 -1
  87. package/build/types/src/codegen/prebuilt/index.d.ts +326 -0
  88. package/build/types/src/configs/chainIds.d.ts +1 -0
  89. package/build/types/src/configs/chains.d.ts +26 -6
  90. package/build/types/src/configs/contracts.d.ts +64 -0
  91. package/build/types/src/configs/express.d.ts +0 -4
  92. package/build/types/src/configs/fees.d.ts +4 -0
  93. package/build/types/src/utils/apy/api.d.ts +5 -0
  94. package/build/types/src/utils/apy/types.d.ts +13 -0
  95. package/build/types/src/utils/errors/parseError.d.ts +3 -0
  96. package/build/types/src/utils/fees/executionFee.d.ts +2 -0
  97. package/build/types/src/utils/markets/api.d.ts +10 -1
  98. package/build/types/src/utils/numbers/utils.d.ts +1 -0
  99. package/build/types/src/utils/orderTransactions/utils.d.ts +2 -1
  100. package/build/types/src/utils/pairs/api.d.ts +5 -0
  101. package/build/types/src/utils/pairs/types.d.ts +20 -0
  102. package/build/types/src/utils/performance/api.d.ts +8 -0
  103. package/build/types/src/utils/performance/types.d.ts +19 -0
  104. package/build/types/src/utils/rates/api.d.ts +5 -0
  105. package/build/types/src/utils/rates/types.d.ts +19 -0
  106. package/build/types/src/utils/staking/api.d.ts +7 -0
  107. package/build/types/src/utils/staking/types.d.ts +14 -0
  108. package/build/types/src/utils/swap/swapValues.d.ts +2 -0
  109. package/build/types/src/utils/tokens/api.d.ts +5 -0
  110. package/build/types/src/utils/trade/decrease.d.ts +41 -2
  111. package/build/types/src/utils/trade/types.d.ts +8 -0
  112. package/build/types/src/utils/twap/uiFeeReceiver.d.ts +9 -6
  113. package/package.json +1 -1
@@ -5,10 +5,10 @@ import { applyFactor, BASIS_POINTS_DIVISOR_BIGINT, expandDecimals, getBasisPoint
5
5
  import { DecreasePositionSwapType, OrderType, SwapPricingType } from "../orders/types";
6
6
  import { getLeverage, getLiquidationPrice, getMinCollateralFactorForPosition, getNetPriceImpactDeltaUsdForDecrease, getPositionPnlUsd, } from "../positions";
7
7
  import { getAcceptablePriceInfo, getDefaultAcceptablePriceImpactBps, getMarkPrice, getOrderThresholdType, } from "../prices";
8
- import { getSwapStats } from "../swap";
8
+ import { getSwapAmountsByFromValue, getSwapStats } from "../swap";
9
9
  import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens } from "../tokens";
10
10
  export function getDecreasePositionAmounts(p) {
11
- const { marketInfo, collateralToken, isLong, position, closeSizeUsd, keepLeverage, triggerPrice, fixedAcceptablePriceImpactBps, acceptablePriceImpactBuffer, userReferralInfo, minCollateralUsd, minPositionSizeUsd, uiFeeFactor, triggerOrderType: orderType, receiveToken: receiveTokenArg, isSetAcceptablePriceImpactEnabled, } = p;
11
+ const { marketInfo, collateralToken, isLong, position, closeSizeUsd, keepLeverage, triggerPrice, fixedAcceptablePriceImpactBps, acceptablePriceImpactBuffer, userReferralInfo, minCollateralUsd, minPositionSizeUsd, uiFeeFactor, triggerOrderType: orderType, receiveToken: receiveTokenArg, isSetAcceptablePriceImpactEnabled, forceDecreaseSwapType, } = p;
12
12
  const { indexToken } = marketInfo;
13
13
  const receiveToken = receiveTokenArg ?? collateralToken;
14
14
  const values = {
@@ -39,17 +39,20 @@ export function getDecreasePositionAmounts(p) {
39
39
  fundingFeeUsd: 0n,
40
40
  feeDiscountUsd: 0n,
41
41
  swapProfitFeeUsd: 0n,
42
+ swapProfitUsdIn: 0n,
42
43
  payedOutputUsd: 0n,
43
44
  payedRemainingCollateralUsd: 0n,
44
45
  payedRemainingCollateralAmount: 0n,
45
46
  receiveTokenAmount: 0n,
46
47
  receiveUsd: 0n,
48
+ primaryOutput: { tokenAddress: "", amount: 0n, usd: 0n },
49
+ secondaryOutput: { tokenAddress: "", amount: 0n, usd: 0n },
47
50
  triggerOrderType: orderType,
48
51
  triggerThresholdType: undefined,
49
52
  decreaseSwapType: DecreasePositionSwapType.NoSwap,
50
53
  };
51
54
  const pnlToken = isLong ? marketInfo.longToken : marketInfo.shortToken;
52
- values.decreaseSwapType = getDecreaseSwapType(pnlToken, collateralToken, receiveToken);
55
+ values.decreaseSwapType = forceDecreaseSwapType ?? getDecreaseSwapType(pnlToken, collateralToken, receiveToken);
53
56
  const markPrice = getMarkPrice({ prices: indexToken.prices, isIncrease: false, isLong });
54
57
  const isTrigger = orderType !== undefined;
55
58
  if (orderType) {
@@ -164,20 +167,25 @@ export function getDecreasePositionAmounts(p) {
164
167
  values.borrowingFeeUsd = borrowFeeCost.usd;
165
168
  const fundingFeeCost = estimateCollateralCost(position.pendingFundingFeesUsd, collateralToken, values.collateralPrice);
166
169
  values.fundingFeeUsd = fundingFeeCost.usd;
167
- if (profitUsd > 0 && values.decreaseSwapType === DecreasePositionSwapType.SwapPnlTokenToCollateralToken) {
170
+ if (profitUsd > 0 &&
171
+ (values.decreaseSwapType === DecreasePositionSwapType.SwapPnlTokenToCollateralToken ||
172
+ values.decreaseSwapType === DecreasePositionSwapType.SwapCollateralTokenToPnlToken)) {
173
+ const isSwapToCollateral = values.decreaseSwapType === DecreasePositionSwapType.SwapPnlTokenToCollateralToken;
168
174
  const swapProfitStats = getSwapStats({
169
175
  marketInfo,
170
- tokenInAddress: pnlToken.address,
171
- tokenOutAddress: collateralToken.address,
176
+ tokenInAddress: isSwapToCollateral ? pnlToken.address : collateralToken.address,
177
+ tokenOutAddress: isSwapToCollateral ? collateralToken.address : pnlToken.address,
172
178
  usdIn: profitUsd,
173
179
  shouldApplyPriceImpact: true,
174
180
  swapPricingType: SwapPricingType.Swap,
175
181
  });
176
182
  values.swapProfitFeeUsd = swapProfitStats.swapFeeUsd - swapProfitStats.priceImpactDeltaUsd;
183
+ values.swapProfitUsdIn = swapProfitStats.usdIn;
177
184
  values.swapUiFeeUsd = applyFactor(swapProfitStats.usdIn, uiFeeFactor);
178
185
  }
179
186
  else {
180
187
  values.swapProfitFeeUsd = 0n;
188
+ values.swapProfitUsdIn = 0n;
181
189
  }
182
190
  const totalFeesUsd = getTotalFeesUsdForDecrease({
183
191
  positionFeeUsd: values.positionFeeUsd,
@@ -235,6 +243,24 @@ export function getDecreasePositionAmounts(p) {
235
243
  values.receiveTokenAmount = payedInfo.outputAmount;
236
244
  }
237
245
  values.receiveUsd = convertToUsd(values.receiveTokenAmount, collateralToken.decimals, values.collateralPrice);
246
+ // SwapCollateralTokenToPnlToken → primaryOutput (pnl token), otherwise → secondaryOutput (collateral token)
247
+ const pnlTokenPrice = pnlToken.prices.minPrice;
248
+ if (values.decreaseSwapType === DecreasePositionSwapType.SwapCollateralTokenToPnlToken) {
249
+ values.primaryOutput = {
250
+ tokenAddress: pnlToken.address,
251
+ amount: convertToTokenAmount(values.receiveUsd, pnlToken.decimals, pnlTokenPrice) ?? 0n,
252
+ usd: values.receiveUsd,
253
+ };
254
+ values.secondaryOutput = { tokenAddress: collateralToken.address, amount: 0n, usd: 0n };
255
+ }
256
+ else {
257
+ values.primaryOutput = { tokenAddress: pnlToken.address, amount: 0n, usd: 0n };
258
+ values.secondaryOutput = {
259
+ tokenAddress: collateralToken.address,
260
+ amount: values.receiveTokenAmount,
261
+ usd: values.receiveUsd,
262
+ };
263
+ }
238
264
  return values;
239
265
  }
240
266
  export function getIsFullClose(p) {
@@ -444,7 +470,7 @@ export function getNextPositionValuesForDecreaseTrade(p) {
444
470
  nextPendingImpactDeltaUsd,
445
471
  };
446
472
  }
447
- function getDecreaseSwapType(pnlToken, collateralToken, receiveToken) {
473
+ export function getDecreaseSwapType(pnlToken, collateralToken, receiveToken) {
448
474
  if (getIsEquivalentTokens(pnlToken, collateralToken)) {
449
475
  return DecreasePositionSwapType.NoSwap;
450
476
  }
@@ -455,3 +481,97 @@ function getDecreaseSwapType(pnlToken, collateralToken, receiveToken) {
455
481
  return DecreasePositionSwapType.SwapPnlTokenToCollateralToken;
456
482
  }
457
483
  }
484
+ export function isThirdTokenDecreaseSwap(pnlToken, collateralToken, receiveToken) {
485
+ return (!getIsEquivalentTokens(receiveToken, pnlToken) &&
486
+ !getIsEquivalentTokens(receiveToken, collateralToken) &&
487
+ !getIsEquivalentTokens(pnlToken, collateralToken));
488
+ }
489
+ export function getCollateralToPnlInternalSwapStats(p) {
490
+ const { pnlToken, receiveUsd } = p;
491
+ // Fees already deducted in getDecreasePositionAmounts — convert at oracle price to avoid double-counting
492
+ const amountOut = convertToTokenAmount(receiveUsd, pnlToken.decimals, pnlToken.prices.minPrice) ?? 0n;
493
+ return { amountOut };
494
+ }
495
+ export function selectBetterDecreaseSwapType(p) {
496
+ return p.pathBUsdOut > p.pathAUsdOut ? "pathB" : "pathA";
497
+ }
498
+ export function getOptimalDecreaseAndSwapAmounts(p) {
499
+ const { marketInfo, collateralToken, isLong, position, closeSizeUsd, keepLeverage, triggerPrice, fixedAcceptablePriceImpactBps, acceptablePriceImpactBuffer, userReferralInfo, minCollateralUsd, minPositionSizeUsd, uiFeeFactor, triggerOrderType, isSetAcceptablePriceImpactEnabled, receiveToken, findSwapPath, findSwapPathFromPnl, marketsInfoData, chainId, } = p;
500
+ const decreaseBaseParams = {
501
+ marketInfo,
502
+ collateralToken,
503
+ isLong,
504
+ position,
505
+ closeSizeUsd,
506
+ keepLeverage,
507
+ triggerPrice,
508
+ fixedAcceptablePriceImpactBps,
509
+ acceptablePriceImpactBuffer,
510
+ userReferralInfo,
511
+ minCollateralUsd,
512
+ minPositionSizeUsd,
513
+ uiFeeFactor,
514
+ triggerOrderType,
515
+ isSetAcceptablePriceImpactEnabled,
516
+ receiveToken,
517
+ };
518
+ const pathADecrease = getDecreasePositionAmounts(decreaseBaseParams);
519
+ const pnlToken = isLong ? marketInfo.longToken : marketInfo.shortToken;
520
+ const shouldSwap = !getIsEquivalentTokens(collateralToken, receiveToken);
521
+ if (!shouldSwap) {
522
+ return { decreaseAmounts: pathADecrease, swapAmounts: undefined };
523
+ }
524
+ const isThirdToken = isThirdTokenDecreaseSwap(pnlToken, collateralToken, receiveToken);
525
+ const pathASwap = pathADecrease.receiveTokenAmount > 0n
526
+ ? getSwapAmountsByFromValue({
527
+ tokenIn: collateralToken,
528
+ tokenOut: receiveToken,
529
+ amountIn: pathADecrease.receiveTokenAmount,
530
+ isLimit: false,
531
+ findSwapPath,
532
+ uiFeeFactor,
533
+ marketsInfoData,
534
+ chainId,
535
+ externalSwapQuoteParams: undefined,
536
+ allowSameTokenSwap: false,
537
+ })
538
+ : undefined;
539
+ if (!isThirdToken) {
540
+ return { decreaseAmounts: pathADecrease, swapAmounts: pathASwap };
541
+ }
542
+ // Path B: force internal collateral→pnl swap, then external pnl→receive
543
+ const pathBDecrease = getDecreasePositionAmounts({
544
+ ...decreaseBaseParams,
545
+ forceDecreaseSwapType: DecreasePositionSwapType.SwapCollateralTokenToPnlToken,
546
+ });
547
+ if (pathBDecrease.primaryOutput.usd <= 0n) {
548
+ return { decreaseAmounts: pathADecrease, swapAmounts: pathASwap };
549
+ }
550
+ const internalSwapStats = getCollateralToPnlInternalSwapStats({
551
+ pnlToken,
552
+ receiveUsd: pathBDecrease.primaryOutput.usd,
553
+ });
554
+ if (internalSwapStats.amountOut <= 0n) {
555
+ return { decreaseAmounts: pathADecrease, swapAmounts: pathASwap };
556
+ }
557
+ const pathBSwap = getSwapAmountsByFromValue({
558
+ tokenIn: pnlToken,
559
+ tokenOut: receiveToken,
560
+ amountIn: internalSwapStats.amountOut,
561
+ isLimit: false,
562
+ findSwapPath: findSwapPathFromPnl,
563
+ uiFeeFactor,
564
+ marketsInfoData,
565
+ chainId,
566
+ externalSwapQuoteParams: undefined,
567
+ allowSameTokenSwap: false,
568
+ });
569
+ const winner = selectBetterDecreaseSwapType({
570
+ pathAUsdOut: pathASwap?.usdOut ?? 0n,
571
+ pathBUsdOut: pathBSwap.usdOut,
572
+ });
573
+ if (winner === "pathB") {
574
+ return { decreaseAmounts: pathBDecrease, swapAmounts: pathBSwap };
575
+ }
576
+ return { decreaseAmounts: pathADecrease, swapAmounts: pathASwap };
577
+ }
@@ -7,7 +7,7 @@ import { OrderType } from "../orders/types";
7
7
  import { getEntryPrice, getLeverage, getLiquidationPrice, getPositionPnlUsd, getPriceImpactDiffUsd, } from "../positions";
8
8
  import { getAcceptablePriceInfo, getDefaultAcceptablePriceImpactBps, getMarkPrice, getOrderThresholdType, } from "../prices";
9
9
  import { getSwapAmountsByFromValue, getSwapAmountsByToValue } from "../swap";
10
- import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens, getTokensRatioByPrice } from "../tokens";
10
+ import { convertToTokenAmount, convertToUsd, getTokensRatioByPrice } from "../tokens";
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 = {
@@ -328,12 +328,8 @@ export function getIncreasePositionPrices({ triggerPrice, indexToken, initialCol
328
328
  let collateralPrice;
329
329
  if (triggerPrice !== undefined && triggerPrice > 0 && limitOrderType !== undefined) {
330
330
  indexPrice = triggerPrice;
331
- initialCollateralPrice = getIsEquivalentTokens(indexToken, initialCollateralToken)
332
- ? triggerPrice
333
- : initialCollateralToken.prices.minPrice;
334
- collateralPrice = getIsEquivalentTokens(indexToken, collateralToken)
335
- ? triggerPrice
336
- : collateralToken.prices.minPrice;
331
+ initialCollateralPrice = initialCollateralToken.prices.minPrice;
332
+ collateralPrice = collateralToken.prices.minPrice;
337
333
  triggerThresholdType = getOrderThresholdType(limitOrderType, isLong);
338
334
  }
339
335
  else {
@@ -1,14 +1,19 @@
1
1
  import { isAddress } from "viem";
2
2
  const VERSION = "01";
3
3
  const PREFIX = "0xff0000";
4
+ const JIT_BYTE_START = 15 * 2;
5
+ const JIT_BYTE_END = 16 * 2;
6
+ const EXPRESS_BYTE_START = 16 * 2;
7
+ const EXPRESS_BYTE_END = 17 * 2;
4
8
  /**
5
9
  * Ui fee receiver structure:
6
- * 0-3 (4) bytes (0-7 chars) - PREFIX
7
- * 4-15 (12) bytes (8-32 chars) - 12 bytes buffer
8
- * 16 (1) byte (33-34 chars) - isExpress flag
9
- * 17 (1) byte (35-36 chars) - numberOfParts (hex encoded)
10
- * 18-19 (2) bytes (37-40 chars) - twapId
11
- * 20 (1) byte (41-42 chars) - VERSION
10
+ * 0-2 (3) bytes (0-5 chars) - PREFIX
11
+ * 3-13 (11) bytes (6-27 chars) - free buffer
12
+ * 14 (1) byte (28-29 chars) - isJit flag
13
+ * 15 (1) byte (30-31 chars) - isExpress flag
14
+ * 16 (1) byte (32-33 chars) - numberOfParts (hex encoded)
15
+ * 17-18 (2) bytes (34-37 chars) - twapId
16
+ * 19 (1) byte (38-39 chars) - VERSION
12
17
  *
13
18
  * Total: 0x + 20 bytes (41 hex characters)
14
19
  */
@@ -21,23 +26,33 @@ export function createTwapUiFeeReceiver({ numberOfParts }) {
21
26
  const twapId = generateTwapId();
22
27
  const numberOfPartsInHex = numberOfParts.toString(16).padStart(2, "0");
23
28
  const buffer = "00".repeat(12);
24
- const isExpressHex = "00";
25
- return `${PREFIX}${buffer}${isExpressHex}${numberOfPartsInHex}${twapId}${VERSION}`;
29
+ const flagsHex = "00";
30
+ return `${PREFIX}${buffer}${flagsHex}${numberOfPartsInHex}${twapId}${VERSION}`;
26
31
  }
27
32
  export function decodeTwapUiFeeReceiver(address) {
28
33
  const byteString = address.slice(2);
29
34
  const twapId = byteString.slice(34, 38);
30
- const isExpress = byteString.slice(30, 32) === "01";
35
+ const isExpress = getUiFeeReceiverByte(address, EXPRESS_BYTE_START, EXPRESS_BYTE_END) === "01";
36
+ const isJit = getUiFeeReceiverByte(address, JIT_BYTE_START, JIT_BYTE_END) === "01";
31
37
  if (!isValidTwapUiFeeReceiver(address) || twapId === "0000") {
32
38
  return;
33
39
  }
34
40
  const numberOfParts = parseInt(byteString.slice(32, 34), 16);
35
- return { twapId, numberOfParts, isExpress };
41
+ return { twapId, numberOfParts, isExpress, isJit };
36
42
  }
37
43
  export function isValidTwapUiFeeReceiver(address) {
38
44
  return isAddress(address) && address.toLowerCase().startsWith(PREFIX.toLowerCase());
39
45
  }
40
46
  export function setUiFeeReceiverIsExpress(uiFeeReceiver, isExpress) {
41
- const isExpressInHex = isExpress ? "01" : "00";
42
- return `${uiFeeReceiver.slice(0, 16 * 2)}${isExpressInHex}${uiFeeReceiver.slice(17 * 2)}`;
47
+ return setUiFeeReceiverByte(uiFeeReceiver, EXPRESS_BYTE_START, EXPRESS_BYTE_END, isExpress);
48
+ }
49
+ export function setUiFeeReceiverIsJit(uiFeeReceiver, isJit) {
50
+ return setUiFeeReceiverByte(uiFeeReceiver, JIT_BYTE_START, JIT_BYTE_END, isJit);
51
+ }
52
+ function getUiFeeReceiverByte(uiFeeReceiver, start, end) {
53
+ return uiFeeReceiver.slice(start, end);
54
+ }
55
+ function setUiFeeReceiverByte(uiFeeReceiver, start, end, enabled) {
56
+ const value = enabled ? "01" : "00";
57
+ return `${uiFeeReceiver.slice(0, start)}${value}${uiFeeReceiver.slice(end)}`;
43
58
  }
@@ -26,7 +26,7 @@ export declare class GmxSdk {
26
26
  setAccount(account: Address): void;
27
27
  executeMulticall<T = any>(request: MulticallRequestConfig<any>): Promise<T>;
28
28
  callContract(address: Address, abi: Abi, method: string, params: any[], opts?: CallContractOpts): Promise<string>;
29
- get chainId(): 43114 | 42161 | 3637 | 43113 | 421614;
29
+ get chainId(): 43114 | 42161 | 3637 | 4326 | 43113 | 421614;
30
30
  get chain(): import("viem").Chain;
31
31
  get account(): string;
32
32
  }
@@ -3,6 +3,6 @@ export declare class Module {
3
3
  sdk: GmxSdk;
4
4
  constructor(sdk: GmxSdk);
5
5
  get oracle(): import("./oracle").Oracle;
6
- get chainId(): 43114 | 42161 | 3637 | 43113 | 421614;
6
+ get chainId(): 43114 | 42161 | 3637 | 4326 | 43113 | 421614;
7
7
  get account(): string;
8
8
  }
@@ -14,7 +14,7 @@ export declare class Multicall {
14
14
  };
15
15
  static getInstance(sdk: GmxSdk): Promise<Multicall>;
16
16
  constructor(sdk: GmxSdk);
17
- get chainId(): 43114 | 42161 | 3637 | 43113 | 421614;
17
+ get chainId(): 43114 | 42161 | 3637 | 4326 | 43113 | 421614;
18
18
  call(request: MulticallRequestConfig<any>, maxTimeout: number): Promise<MulticallResult<any>>;
19
19
  }
20
20
  export type SkipKey = null | undefined | false;
@@ -1,7 +1,18 @@
1
1
  import { ContractsChainId } from "../../configs/chains";
2
+ import { ApyParams, ApyResponse } from "../../utils/apy/types";
2
3
  import { IHttp } from "../../utils/http/types";
4
+ import { MarketTicker, MarketWithTiers } from "../../utils/markets/types";
5
+ import { PerformanceAnnualized, PerformanceParams, PerformanceSnapshots } from "../../utils/performance/types";
3
6
  import type { OhlcvParams } from "../../utils/prices/types";
7
+ import { MarketRates, RatesParams } from "../../utils/rates/types";
8
+ import { StakingPowerResponse } from "../../utils/staking/types";
9
+ export type { ApyEntry, ApyParams, ApyResponse } from "../../utils/apy/types";
10
+ export type { MarketTicker, MarketWithTiers } from "../../utils/markets/types";
11
+ export type { Pair } from "../../utils/pairs/types";
12
+ export type { PerformanceAnnualized, PerformanceParams, PerformanceSnapshot, PerformanceSnapshots, } from "../../utils/performance/types";
4
13
  export type { OhlcvCandle, OhlcvParams } from "../../utils/prices/types";
14
+ export type { ApiParameterPeriod, MarketRates, RatesParams, RatesSnapshot } from "../../utils/rates/types";
15
+ export type { StakingPowerResponse } from "../../utils/staking/types";
5
16
  export declare class GmxApiSdk {
6
17
  ctx: {
7
18
  chainId: ContractsChainId;
@@ -10,8 +21,14 @@ export declare class GmxApiSdk {
10
21
  constructor({ chainId }: {
11
22
  chainId: ContractsChainId;
12
23
  });
13
- fetchMarketsInfo(): Promise<import("../../utils/markets").RawMarketInfo[]>;
24
+ fetchMarketsInfo(): Promise<import("../../utils/markets/types").RawMarketInfo[]>;
25
+ fetchMarkets(): Promise<MarketWithTiers[]>;
26
+ fetchMarketsTickers(params?: {
27
+ addresses?: string[];
28
+ symbols?: string[];
29
+ }): Promise<MarketTicker[]>;
14
30
  fetchTokensData(): Promise<import("../../utils/tokens").TokenData[]>;
31
+ fetchTokens(): Promise<import("../../utils/tokens").Token[]>;
15
32
  fetchPositionsInfo(params: {
16
33
  address: string;
17
34
  includeRelatedOrders?: boolean;
@@ -20,4 +37,12 @@ export declare class GmxApiSdk {
20
37
  address: string;
21
38
  }): Promise<import("../../utils/orders").ApiOrderInfo[]>;
22
39
  fetchOhlcv(params: OhlcvParams): Promise<import("../../utils/prices/types").OhlcvCandle[]>;
40
+ fetchPairs(): Promise<import("../../utils/pairs/types").Pair[]>;
41
+ fetchRates(params?: RatesParams): Promise<MarketRates[]>;
42
+ fetchApy(params?: ApyParams): Promise<ApyResponse>;
43
+ fetchPerformanceAnnualized(params?: PerformanceParams): Promise<PerformanceAnnualized[]>;
44
+ fetchPerformanceSnapshots(params?: PerformanceParams): Promise<PerformanceSnapshots[]>;
45
+ fetchStakingPower(params: {
46
+ address: string;
47
+ }): Promise<StakingPowerResponse>;
23
48
  }