@gmx-io/sdk 1.5.0-alpha-13 → 1.5.0-alpha-15

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 (61) hide show
  1. package/build/cjs/scripts/subsquid-codegen.js +1 -1
  2. package/build/cjs/src/clients/v1/modules/trades/trades.js +4 -0
  3. package/build/cjs/src/clients/v2/__tests__/decrease.spec.js +12 -12
  4. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -0
  5. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +122 -0
  6. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -0
  7. package/build/cjs/src/codegen/subsquid.js +30 -0
  8. package/build/cjs/src/configs/markets.js +14 -0
  9. package/build/cjs/src/configs/tokens.js +18 -0
  10. package/build/cjs/src/test/mock.js +1 -0
  11. package/build/cjs/src/utils/__tests__/markets.spec.js +88 -48
  12. package/build/cjs/src/utils/__tests__/positions.spec.js +93 -0
  13. package/build/cjs/src/utils/markets/utils.js +23 -14
  14. package/build/cjs/src/utils/orderTransactions/utils.js +2 -2
  15. package/build/cjs/src/utils/orderTransactions/validateTypedData.js +3 -3
  16. package/build/cjs/src/utils/positions/utils.js +34 -2
  17. package/build/cjs/src/utils/prices/utils.js +4 -4
  18. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  19. package/build/cjs/src/utils/trade/decrease.js +1 -1
  20. package/build/cjs/src/utils/trade/increase.js +1 -1
  21. package/build/cjs/src/utils/trade/trade.js +0 -7
  22. package/build/cjs/src/utils/tradeHistory/utils.js +2 -0
  23. package/build/cjs/src/utils/twap/index.js +4 -10
  24. package/build/esm/scripts/subsquid-codegen.js +1 -1
  25. package/build/esm/src/clients/v1/modules/trades/trades.js +4 -0
  26. package/build/esm/src/clients/v2/__tests__/decrease.spec.js +12 -12
  27. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -0
  28. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +122 -0
  29. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -0
  30. package/build/esm/src/codegen/subsquid.js +30 -0
  31. package/build/esm/src/configs/markets.js +14 -0
  32. package/build/esm/src/configs/tokens.js +18 -0
  33. package/build/esm/src/test/mock.js +1 -0
  34. package/build/esm/src/utils/__tests__/markets.spec.js +90 -50
  35. package/build/esm/src/utils/__tests__/positions.spec.js +94 -1
  36. package/build/esm/src/utils/markets/utils.js +21 -13
  37. package/build/esm/src/utils/orderTransactions/utils.js +2 -2
  38. package/build/esm/src/utils/orderTransactions/validateTypedData.js +3 -3
  39. package/build/esm/src/utils/positions/utils.js +32 -2
  40. package/build/esm/src/utils/prices/utils.js +4 -4
  41. package/build/esm/src/utils/subaccount/index.js +2 -2
  42. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  43. package/build/esm/src/utils/trade/decrease.js +1 -1
  44. package/build/esm/src/utils/trade/increase.js +1 -1
  45. package/build/esm/src/utils/trade/trade.js +0 -7
  46. package/build/esm/src/utils/tradeHistory/utils.js +2 -0
  47. package/build/esm/src/utils/twap/index.js +4 -10
  48. package/build/types/src/codegen/prebuilt/index.d.ts +168 -0
  49. package/build/types/src/codegen/subsquid.d.ts +77 -0
  50. package/build/types/src/utils/markets/utils.d.ts +6 -1
  51. package/build/types/src/utils/positions/types.d.ts +3 -0
  52. package/build/types/src/utils/positions/utils.d.ts +15 -0
  53. package/build/types/src/utils/prices/utils.d.ts +1 -1
  54. package/build/types/src/utils/subaccount/index.d.ts +2 -2
  55. package/build/types/src/utils/swap/types.d.ts +1 -1
  56. package/build/types/src/utils/trade/types.d.ts +4 -1
  57. package/build/types/src/utils/tradeHistory/types.d.ts +2 -0
  58. package/package.json +1 -1
  59. package/build/cjs/src/configs/marketHours.js +0 -27
  60. package/build/esm/src/configs/marketHours.js +0 -24
  61. package/build/types/src/configs/marketHours.d.ts +0 -7
@@ -1,10 +1,9 @@
1
1
  import { zeroAddress } from "viem";
2
2
  import { BASIS_POINTS_DIVISOR, BASIS_POINTS_DIVISOR_BIGINT } from "../../configs/factors";
3
- import { MARKET_HOURS_MARKETS } from "../../configs/marketHours";
4
3
  import { convertTokenAddress, getTokenVisualMultiplier, NATIVE_TOKEN_ADDRESS } from "../../configs/tokens";
5
4
  import { bigMath } from "../bigmath";
6
5
  import { getBorrowingFactorPerPeriod, getFundingFactorPerPeriod } from "../fees";
7
- import { applyFactor, PRECISION } from "../numbers";
6
+ import { applyFactor, expandDecimals, PRECISION } from "../numbers";
8
7
  import { getByKey } from "../objects";
9
8
  import { periodToSeconds } from "../time";
10
9
  import { convertToContractTokenPrices, convertToUsd, getMidPrice } from "../tokens";
@@ -85,7 +84,9 @@ export function getCappedPoolPnl(p) {
85
84
  return poolPnl > maxPnl ? maxPnl : poolPnl;
86
85
  }
87
86
  /**
88
- * Rounds to nearest .0 leverage, so that getMaxAllowedLeverageByMinCollateralFactor can get .0 or .5 leverage.
87
+ * Theoretical max leverage derived purely from minCollateralFactor. Does not account for
88
+ * fees or the liquidation safety buffer. Used by the deposit-collateral path where the
89
+ * user is not opening a new size.
89
90
  */
90
91
  const ROUNDING_VALUE = 10000;
91
92
  export function getMaxLeverageByMinCollateralFactor(minCollateralFactor) {
@@ -97,17 +98,21 @@ export function getMaxLeverageByMinCollateralFactor(minCollateralFactor) {
97
98
  const rounded = Math.round(Number(x) / ROUNDING_VALUE) * ROUNDING_VALUE;
98
99
  return rounded;
99
100
  }
100
- export function getMaxAllowedLeverageByMinCollateralFactor(minCollateralFactor, marketAddress) {
101
- if (marketAddress) {
102
- const cfg = MARKET_HOURS_MARKETS[marketAddress];
103
- if (cfg) {
104
- if (minCollateralFactor === cfg.onHoursMcf)
105
- return cfg.onHoursMaxLeverage * BASIS_POINTS_DIVISOR;
106
- if (minCollateralFactor === cfg.offHoursMcf)
107
- return cfg.offHoursMaxLeverage * BASIS_POINTS_DIVISOR;
108
- }
101
+ const MAX_ALLOWED_LEVERAGE_STEP_BP = 5 * BASIS_POINTS_DIVISOR;
102
+ export function getMaxAllowedLeverage({ minCollateralFactor, minCollateralFactorForLiquidation, positionFeeFactorForBalanceWasNotImproved, }) {
103
+ if (minCollateralFactor === undefined ||
104
+ minCollateralFactor === 0n ||
105
+ minCollateralFactorForLiquidation === undefined ||
106
+ minCollateralFactorForLiquidation === 0n ||
107
+ positionFeeFactorForBalanceWasNotImproved === undefined) {
108
+ return 100 * BASIS_POINTS_DIVISOR;
109
109
  }
110
- return getMaxLeverageByMinCollateralFactor(minCollateralFactor) / 2;
110
+ const openingDenominator = minCollateralFactor + 2n * positionFeeFactorForBalanceWasNotImproved;
111
+ const openingMaxBp = bigMath.mulDiv(PRECISION, BASIS_POINTS_DIVISOR_BIGINT, openingDenominator);
112
+ const liquidationDenominator = 2n * minCollateralFactorForLiquidation;
113
+ const liquidationMaxBp = bigMath.mulDiv(PRECISION, BASIS_POINTS_DIVISOR_BIGINT, liquidationDenominator);
114
+ const rawMaxBp = bigMath.min(openingMaxBp, liquidationMaxBp);
115
+ return Math.floor(Number(rawMaxBp) / MAX_ALLOWED_LEVERAGE_STEP_BP) * MAX_ALLOWED_LEVERAGE_STEP_BP;
111
116
  }
112
117
  export function getOppositeCollateral(marketInfo, tokenAddress) {
113
118
  const poolType = getTokenPoolType(marketInfo, tokenAddress);
@@ -205,6 +210,9 @@ export function getPriceForPnl(prices, isLong, maximize) {
205
210
  export function getIsMarketAvailableForExpressSwaps(marketInfo) {
206
211
  return [marketInfo.indexToken, marketInfo.longToken, marketInfo.shortToken].every((token) => token.hasPriceFeedProvider);
207
212
  }
213
+ export function getIsMarketDeprecated(marketInfo) {
214
+ return marketInfo.maxOpenInterestLong <= expandDecimals(1n, 30) && marketInfo.maxOpenInterestShort <= expandDecimals(1n, 30);
215
+ }
208
216
  export function getMarket24Stats(dayPriceCandle) {
209
217
  const open24h = dayPriceCandle.open;
210
218
  const high24h = dayPriceCandle.high;
@@ -158,8 +158,8 @@ export function buildDecreaseOrderPayload(p) {
158
158
  };
159
159
  }
160
160
  export function buildTwapOrdersPayloads(p, twapParams) {
161
- if (!twapParams.numberOfParts || twapParams.numberOfParts < 2) {
162
- throw new Error(`TWAP numberOfParts must be >= 2, got ${twapParams.numberOfParts}`);
161
+ if (!twapParams.numberOfParts || twapParams.numberOfParts <= 0) {
162
+ throw new Error(`TWAP numberOfParts must be > 0, got ${twapParams.numberOfParts}`);
163
163
  }
164
164
  const uiFeeReceiver = createTwapUiFeeReceiver({ numberOfParts: twapParams.numberOfParts, source: twapParams.source });
165
165
  if (isSwapOrderType(p.orderType)) {
@@ -70,7 +70,8 @@ accountAddress) {
70
70
  const cancellationReceiver = order?.addresses?.cancellationReceiver;
71
71
  if (cancellationReceiver) {
72
72
  const checksummedCancellationReceiver = getAddress(cancellationReceiver);
73
- if (checksummedCancellationReceiver !== ZERO_ADDRESS && !allowedReceivers.has(checksummedCancellationReceiver)) {
73
+ if (checksummedCancellationReceiver !== ZERO_ADDRESS &&
74
+ !allowedReceivers.has(checksummedCancellationReceiver)) {
74
75
  throw new Error(`Order cancellationReceiver "${cancellationReceiver}" does not match signer "${signerAddress}". Possible malicious typed data.`);
75
76
  }
76
77
  }
@@ -84,8 +85,7 @@ export function validateSubaccountApprovalTypedData(domain, message, chainId, si
84
85
  if (message.account && getAddress(message.account) !== checksummedSigner) {
85
86
  throw new Error(`Subaccount approval account "${message.account}" does not match signer "${signerAddress}"`);
86
87
  }
87
- if (message.subaccount &&
88
- getAddress(message.subaccount) !== getAddress(expectedSubaccountAddress)) {
88
+ if (message.subaccount && getAddress(message.subaccount) !== getAddress(expectedSubaccountAddress)) {
89
89
  throw new Error(`Subaccount address "${message.subaccount}" does not match expected "${expectedSubaccountAddress}"`);
90
90
  }
91
91
  }
@@ -1,7 +1,7 @@
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, getMarketIndexName, getMarketPnl, getMarketPoolName, getMaxAllowedLeverageByMinCollateralFactor, getOpenInterestUsd, getPoolUsdWithoutPnl, } from "../markets";
4
+ import { getCappedPoolPnl, getMarketIndexName, getMarketPnl, getMarketPoolName, getMaxAllowedLeverage, getOpenInterestUsd, getPoolUsdWithoutPnl, } from "../markets";
5
5
  import { applyFactor, expandDecimals, FLOAT_PRECISION_SQRT, getBasisPoints, PRECISION } from "../numbers";
6
6
  import { getAcceptablePriceInfo, getMarkPrice } from "../prices";
7
7
  import { convertToTokenAmount, convertToUsd, getIsEquivalentTokens } from "../tokens";
@@ -53,10 +53,17 @@ export function getPositionNetValue(p) {
53
53
  const pendingFeesUsd = getPositionPendingFeesUsd(p);
54
54
  return collateralUsd - pendingFeesUsd + pnl;
55
55
  }
56
+ export function getPositionNetValueAfterAllFees(p) {
57
+ const { collateralUsd, pnl, pendingBorrowingFeesUsd, pendingFundingFeesUsd, netPriceImpactDeltaUsd, closingFeeUsd } = p;
58
+ return collateralUsd + pnl - pendingBorrowingFeesUsd - pendingFundingFeesUsd + netPriceImpactDeltaUsd - closingFeeUsd;
59
+ }
56
60
  export function getPositionPnlAfterFees({ pnl, pendingBorrowingFeesUsd, pendingFundingFeesUsd, }) {
57
61
  const pnlAfterFees = pnl - pendingBorrowingFeesUsd - pendingFundingFeesUsd;
58
62
  return pnlAfterFees;
59
63
  }
64
+ export function getPositionPnlAfterAllFees({ pnl, pendingBorrowingFeesUsd, pendingFundingFeesUsd, netPriceImpactDeltaUsd, closingFeeUsd, }) {
65
+ return pnl - pendingBorrowingFeesUsd - pendingFundingFeesUsd + netPriceImpactDeltaUsd - closingFeeUsd;
66
+ }
60
67
  export function getLeverage(p) {
61
68
  const { pnl, sizeInUsd, collateralUsd, pendingBorrowingFeesUsd, pendingFundingFeesUsd } = p;
62
69
  const totalPendingFeesUsd = getPositionPendingFeesUsd({ pendingFundingFeesUsd, pendingBorrowingFeesUsd });
@@ -308,6 +315,22 @@ export function getPositionInfo(p) {
308
315
  pendingFundingFeesUsd,
309
316
  });
310
317
  const pnlAfterFeesPercentage = collateralUsd !== 0n ? getBasisPoints(pnlAfterFees, collateralUsd) : 0n;
318
+ const netValueAfterAllFees = getPositionNetValueAfterAllFees({
319
+ collateralUsd,
320
+ pnl,
321
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
322
+ pendingFundingFeesUsd,
323
+ netPriceImpactDeltaUsd: netPriceImpactValues.totalImpactDeltaUsd,
324
+ closingFeeUsd,
325
+ });
326
+ const pnlAfterAllFees = getPositionPnlAfterAllFees({
327
+ pnl,
328
+ pendingBorrowingFeesUsd: position.pendingBorrowingFeesUsd,
329
+ pendingFundingFeesUsd,
330
+ netPriceImpactDeltaUsd: netPriceImpactValues.totalImpactDeltaUsd,
331
+ closingFeeUsd,
332
+ });
333
+ const pnlAfterAllFeesPercentage = collateralUsd !== 0n ? getBasisPoints(pnlAfterAllFees, collateralUsd) : 0n;
311
334
  const leverage = getLeverage({
312
335
  sizeInUsd: position.sizeInUsd,
313
336
  collateralUsd,
@@ -329,7 +352,11 @@ export function getPositionInfo(p) {
329
352
  pendingFundingFeesUsd,
330
353
  pnl: undefined,
331
354
  });
332
- const maxAllowedLeverage = getMaxAllowedLeverageByMinCollateralFactor(marketInfo.minCollateralFactor, marketInfo.marketTokenAddress);
355
+ const maxAllowedLeverage = getMaxAllowedLeverage({
356
+ minCollateralFactor: marketInfo.minCollateralFactor,
357
+ minCollateralFactorForLiquidation: marketInfo.minCollateralFactorForLiquidation,
358
+ positionFeeFactorForBalanceWasNotImproved: marketInfo.positionFeeFactorForBalanceWasNotImproved,
359
+ });
333
360
  const hasLowCollateral = (leverage !== undefined && leverage > maxAllowedLeverage) || false;
334
361
  const liquidationPrice = getLiquidationPrice({
335
362
  marketInfo,
@@ -382,6 +409,9 @@ export function getPositionInfo(p) {
382
409
  pnlPercentage,
383
410
  pnlAfterFees,
384
411
  pnlAfterFeesPercentage,
412
+ netValueAfterAllFees,
413
+ pnlAfterAllFees,
414
+ pnlAfterAllFeesPercentage,
385
415
  netValue,
386
416
  netPriceImapctDeltaUsd: netPriceImpactValues.totalImpactDeltaUsd,
387
417
  priceImpactDiffUsd: netPriceImpactValues.priceImpactDiffUsd,
@@ -118,9 +118,9 @@ export function getAcceptablePriceByPriceImpact(p) {
118
118
  };
119
119
  }
120
120
  export function getDefaultAcceptablePriceImpactBps(p) {
121
- const { indexPrice, sizeDeltaUsd, priceImpactDeltaUsd, acceptablePriceImapctBuffer = DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER, } = p;
121
+ const { indexPrice, sizeDeltaUsd, priceImpactDeltaUsd, acceptablePriceImpactBuffer = DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER, } = p;
122
122
  if (priceImpactDeltaUsd > 0) {
123
- return BigInt(acceptablePriceImapctBuffer);
123
+ return BigInt(acceptablePriceImpactBuffer);
124
124
  }
125
125
  const baseAcceptablePriceValues = getAcceptablePriceByPriceImpact({
126
126
  isIncrease: p.isIncrease,
@@ -130,7 +130,7 @@ export function getDefaultAcceptablePriceImpactBps(p) {
130
130
  priceImpactDeltaUsd,
131
131
  });
132
132
  if (baseAcceptablePriceValues.acceptablePriceDeltaBps < 0) {
133
- return bigMath.abs(baseAcceptablePriceValues.acceptablePriceDeltaBps) + BigInt(acceptablePriceImapctBuffer);
133
+ return bigMath.abs(baseAcceptablePriceValues.acceptablePriceDeltaBps) + BigInt(acceptablePriceImpactBuffer);
134
134
  }
135
- return BigInt(acceptablePriceImapctBuffer);
135
+ return BigInt(acceptablePriceImpactBuffer);
136
136
  }
@@ -2,5 +2,5 @@ export * from "./types";
2
2
  export { generateSubaccount, decryptSubaccountPrivateKey, createSubaccountSignerFromConfig, } from "./generateSubaccount";
3
3
  export { hashSubaccountApproval } from "./hashSubaccountApproval";
4
4
  export { getEmptySubaccountApproval } from "./getEmptySubaccountApproval";
5
- export { getSubaccountApprovalTypedData, } from "./getSubaccountApprovalTypedData";
6
- export { fetchSubaccountStatus, prepareSubaccountApproval, signSubaccountApproval, } from "./api";
5
+ export { getSubaccountApprovalTypedData } from "./getSubaccountApprovalTypedData";
6
+ export { fetchSubaccountStatus, prepareSubaccountApproval, signSubaccountApproval } from "./api";
@@ -293,7 +293,7 @@ describe("getBestSwapPath", () => {
293
293
  it("should handle routes with zero output", () => {
294
294
  const routes = createTestRoutes();
295
295
  const result = getBestSwapPath({ routes, usdIn: 100n * dollar, estimator: () => ({ usdOut: 0n }) });
296
- expect(result).toBeUndefined();
296
+ expect(result).toEqual(routes[0]);
297
297
  });
298
298
  it("should skip routes that throw errors", () => {
299
299
  const routes = createTestRoutes();
@@ -377,7 +377,7 @@ function applyAcceptablePrice(p) {
377
377
  indexPrice: values.indexPrice,
378
378
  sizeDeltaUsd: values.sizeDeltaUsd,
379
379
  priceImpactDeltaUsd: values.closePriceImpactDeltaUsd,
380
- acceptablePriceImapctBuffer: acceptablePriceImpactBuffer || DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER,
380
+ acceptablePriceImpactBuffer: acceptablePriceImpactBuffer || DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER,
381
381
  });
382
382
  if (maxNegativePriceImpactBps === undefined) {
383
383
  maxNegativePriceImpactBps = values.recommendedAcceptablePriceDeltaBps;
@@ -271,7 +271,7 @@ export function getIncreasePositionAmounts(p) {
271
271
  indexPrice: values.indexPrice,
272
272
  sizeDeltaUsd: values.sizeDeltaUsd,
273
273
  priceImpactDeltaUsd: values.positionPriceImpactDeltaUsd,
274
- acceptablePriceImapctBuffer: acceptablePriceImpactBuffer || DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER,
274
+ acceptablePriceImpactBuffer: acceptablePriceImpactBuffer || DEFAULT_ACCEPTABLE_PRICE_IMPACT_BUFFER,
275
275
  });
276
276
  if (maxNegativePriceImpactBps === undefined) {
277
277
  maxNegativePriceImpactBps = values.recommendedAcceptablePriceDeltaBps;
@@ -3,11 +3,7 @@ import { bigMath } from "../bigmath";
3
3
  import { DecreasePositionSwapType } from "../orders/types";
4
4
  import { getShouldUseMaxPrice } from "../prices";
5
5
  import { TradeMode, TradeType, } from "./types";
6
- const MAX_ALLOWED_SLIPPAGE = 5000; // 50%
7
6
  export function applySlippageToPrice(allowedSlippage, price, isIncrease, isLong) {
8
- if (allowedSlippage < 0 || allowedSlippage > MAX_ALLOWED_SLIPPAGE) {
9
- throw new Error(`allowedSlippage must be between 0 and ${MAX_ALLOWED_SLIPPAGE} bps, got ${allowedSlippage}`);
10
- }
11
7
  const shouldIncreasePrice = getShouldUseMaxPrice(isIncrease, isLong);
12
8
  const slippageBasisPoints = shouldIncreasePrice
13
9
  ? BASIS_POINTS_DIVISOR + allowedSlippage
@@ -15,9 +11,6 @@ export function applySlippageToPrice(allowedSlippage, price, isIncrease, isLong)
15
11
  return bigMath.mulDiv(price, BigInt(slippageBasisPoints), BASIS_POINTS_DIVISOR_BIGINT);
16
12
  }
17
13
  export function applySlippageToMinOut(allowedSlippage, minOutputAmount) {
18
- if (allowedSlippage < 0 || allowedSlippage > MAX_ALLOWED_SLIPPAGE) {
19
- throw new Error(`allowedSlippage must be between 0 and ${MAX_ALLOWED_SLIPPAGE} bps, got ${allowedSlippage}`);
20
- }
21
14
  const slippageBasisPoints = BASIS_POINTS_DIVISOR - allowedSlippage;
22
15
  return bigMath.mulDiv(minOutputAmount, BigInt(slippageBasisPoints), BASIS_POINTS_DIVISOR_BIGINT);
23
16
  }
@@ -114,10 +114,12 @@ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, t
114
114
  basePnlUsd: rawAction.basePnlUsd ? BigInt(rawAction.basePnlUsd) : undefined,
115
115
  priceImpactDiffUsd: rawAction.priceImpactDiffUsd ? BigInt(rawAction.priceImpactDiffUsd) : undefined,
116
116
  priceImpactUsd: rawAction.priceImpactUsd ? BigInt(rawAction.priceImpactUsd) : undefined,
117
+ swapImpactUsd: rawAction.swapImpactUsd ? BigInt(rawAction.swapImpactUsd) : undefined,
117
118
  totalImpactUsd: rawAction.totalImpactUsd ? BigInt(rawAction.totalImpactUsd) : undefined,
118
119
  positionFeeAmount: rawAction.positionFeeAmount ? BigInt(rawAction.positionFeeAmount) : undefined,
119
120
  borrowingFeeAmount: rawAction.borrowingFeeAmount ? BigInt(rawAction.borrowingFeeAmount) : undefined,
120
121
  fundingFeeAmount: rawAction.fundingFeeAmount ? BigInt(rawAction.fundingFeeAmount) : undefined,
122
+ swapFeeUsd: rawAction.swapFeeUsd ? BigInt(rawAction.swapFeeUsd) : undefined,
121
123
  liquidationFeeAmount: rawAction.liquidationFeeAmount ? BigInt(rawAction.liquidationFeeAmount) : undefined,
122
124
  reason: rawAction.reason ?? undefined,
123
125
  reasonBytes: rawAction.reasonBytes ?? undefined,
@@ -12,13 +12,10 @@ export function getTwapDurationInSeconds(duration) {
12
12
  return duration.hours * 60 * 60 + duration.minutes * 60;
13
13
  }
14
14
  export function getTwapValidFromTime(duration, numberOfParts, partIndex) {
15
- if (numberOfParts < 2) {
16
- throw new Error(`TWAP numberOfParts must be >= 2, got ${numberOfParts}`);
17
- }
18
15
  const durationMinutes = duration.hours * 60 + duration.minutes;
19
- const durationSeconds = durationMinutes * 60;
16
+ const durationMs = durationMinutes * 60;
20
17
  const startTime = Math.ceil(Date.now() / 1000);
21
- return BigInt(Math.floor(startTime + (durationSeconds / (numberOfParts - 1)) * partIndex));
18
+ return BigInt(Math.floor(startTime + (durationMs / (numberOfParts - 1)) * partIndex));
22
19
  }
23
20
  export function changeTwapNumberOfPartsValue(value) {
24
21
  if (value < MIN_TWAP_NUMBER_OF_PARTS) {
@@ -40,13 +37,10 @@ export function getTwapOrderKey({ twapId, orderType, pool, isLong, collateralTok
40
37
  return `${twapId}-${type}-${pool}-${collateralTokenSymbol}`;
41
38
  }
42
39
  export function makeTwapValidFromTimeGetter(duration, numberOfParts) {
43
- if (numberOfParts < 2) {
44
- throw new Error(`TWAP numberOfParts must be >= 2, got ${numberOfParts}`);
45
- }
46
40
  const durationMinutes = duration.hours * 60 + duration.minutes;
47
- const durationSeconds = durationMinutes * 60;
41
+ const durationMs = durationMinutes * 60;
48
42
  const startTime = Math.ceil(Date.now() / 1000);
49
43
  return (part) => {
50
- return BigInt(Math.floor(startTime + (durationSeconds / (numberOfParts - 1)) * part));
44
+ return BigInt(Math.floor(startTime + (durationMs / (numberOfParts - 1)) * part));
51
45
  };
52
46
  }
@@ -92,6 +92,21 @@ export declare const HASHED_MARKET_VALUES_KEYS: {
92
92
  shortInterestInTokensUsingLongToken: string;
93
93
  shortInterestInTokensUsingShortToken: string;
94
94
  };
95
+ "0x1b997cb4841c4cb360E384192fFd7fb26eb10e5f": {
96
+ longPoolAmount: string;
97
+ shortPoolAmount: string;
98
+ positionImpactPoolAmount: string;
99
+ swapImpactPoolAmountLong: string;
100
+ swapImpactPoolAmountShort: string;
101
+ longInterestUsingLongToken: string;
102
+ longInterestUsingShortToken: string;
103
+ shortInterestUsingLongToken: string;
104
+ shortInterestUsingShortToken: string;
105
+ longInterestInTokensUsingLongToken: string;
106
+ longInterestInTokensUsingShortToken: string;
107
+ shortInterestInTokensUsingLongToken: string;
108
+ shortInterestInTokensUsingShortToken: string;
109
+ };
95
110
  "0xc5c9B5E23810565763De41144741477eeCB25e2e": {
96
111
  longPoolAmount: string;
97
112
  shortPoolAmount: string;
@@ -2089,6 +2104,21 @@ export declare const HASHED_MARKET_VALUES_KEYS: {
2089
2104
  shortInterestInTokensUsingLongToken: string;
2090
2105
  shortInterestInTokensUsingShortToken: string;
2091
2106
  };
2107
+ "0xE26E7b91143f367445f1c0a5dCf4f4aC8EaDcDb1": {
2108
+ longPoolAmount: string;
2109
+ shortPoolAmount: string;
2110
+ positionImpactPoolAmount: string;
2111
+ swapImpactPoolAmountLong: string;
2112
+ swapImpactPoolAmountShort: string;
2113
+ longInterestUsingLongToken: string;
2114
+ longInterestUsingShortToken: string;
2115
+ shortInterestUsingLongToken: string;
2116
+ shortInterestUsingShortToken: string;
2117
+ longInterestInTokensUsingLongToken: string;
2118
+ longInterestInTokensUsingShortToken: string;
2119
+ shortInterestInTokensUsingLongToken: string;
2120
+ shortInterestInTokensUsingShortToken: string;
2121
+ };
2092
2122
  };
2093
2123
  "43113": {
2094
2124
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {
@@ -3202,6 +3232,67 @@ export declare const HASHED_MARKET_CONFIG_KEYS: {
3202
3232
  virtualLongTokenId: string;
3203
3233
  virtualShortTokenId: string;
3204
3234
  };
3235
+ "0x1b997cb4841c4cb360E384192fFd7fb26eb10e5f": {
3236
+ isDisabled: string;
3237
+ maxLongPoolAmount: string;
3238
+ maxShortPoolAmount: string;
3239
+ maxLongPoolUsdForDeposit: string;
3240
+ maxShortPoolUsdForDeposit: string;
3241
+ reserveFactorLong: string;
3242
+ reserveFactorShort: string;
3243
+ openInterestReserveFactorLong: string;
3244
+ openInterestReserveFactorShort: string;
3245
+ maxOpenInterestLong: string;
3246
+ maxOpenInterestShort: string;
3247
+ minPositionImpactPoolAmount: string;
3248
+ positionImpactPoolDistributionRate: string;
3249
+ borrowingFactorLong: string;
3250
+ borrowingFactorShort: string;
3251
+ borrowingExponentFactorLong: string;
3252
+ borrowingExponentFactorShort: string;
3253
+ fundingFactor: string;
3254
+ fundingExponentFactor: string;
3255
+ fundingIncreaseFactorPerSecond: string;
3256
+ fundingDecreaseFactorPerSecond: string;
3257
+ thresholdForStableFunding: string;
3258
+ thresholdForDecreaseFunding: string;
3259
+ minFundingFactorPerSecond: string;
3260
+ maxFundingFactorPerSecond: string;
3261
+ maxPnlFactorForTradersLong: string;
3262
+ maxPnlFactorForTradersShort: string;
3263
+ maxPnlFactorForDepositsLong: string;
3264
+ maxPnlFactorForDepositsShort: string;
3265
+ maxPnlFactorForWithdrawalsLong: string;
3266
+ maxPnlFactorForWithdrawalsShort: string;
3267
+ positionFeeFactorForBalanceWasImproved: string;
3268
+ positionFeeFactorForBalanceWasNotImproved: string;
3269
+ positionImpactFactorPositive: string;
3270
+ positionImpactFactorNegative: string;
3271
+ maxPositionImpactFactorPositive: string;
3272
+ maxPositionImpactFactorNegative: string;
3273
+ maxPositionImpactFactorForLiquidations: string;
3274
+ maxLendableImpactFactor: string;
3275
+ maxLendableImpactFactorForWithdrawals: string;
3276
+ maxLendableImpactUsd: string;
3277
+ lentPositionImpactPoolAmount: string;
3278
+ minCollateralFactor: string;
3279
+ minCollateralFactorForLiquidation: string;
3280
+ minCollateralFactorForOpenInterestLong: string;
3281
+ minCollateralFactorForOpenInterestShort: string;
3282
+ positionImpactExponentFactorPositive: string;
3283
+ positionImpactExponentFactorNegative: string;
3284
+ swapFeeFactorForBalanceWasImproved: string;
3285
+ swapFeeFactorForBalanceWasNotImproved: string;
3286
+ atomicSwapFeeFactor: string;
3287
+ swapImpactFactorPositive: string;
3288
+ swapImpactFactorNegative: string;
3289
+ swapImpactExponentFactor: string;
3290
+ withdrawalFeeFactorBalanceWasImproved: string;
3291
+ withdrawalFeeFactorBalanceWasNotImproved: string;
3292
+ virtualMarketId: string;
3293
+ virtualLongTokenId: string;
3294
+ virtualShortTokenId: string;
3295
+ };
3205
3296
  "0xc5c9B5E23810565763De41144741477eeCB25e2e": {
3206
3297
  isDisabled: string;
3207
3298
  maxLongPoolAmount: string;
@@ -11317,6 +11408,67 @@ export declare const HASHED_MARKET_CONFIG_KEYS: {
11317
11408
  virtualLongTokenId: string;
11318
11409
  virtualShortTokenId: string;
11319
11410
  };
11411
+ "0xE26E7b91143f367445f1c0a5dCf4f4aC8EaDcDb1": {
11412
+ isDisabled: string;
11413
+ maxLongPoolAmount: string;
11414
+ maxShortPoolAmount: string;
11415
+ maxLongPoolUsdForDeposit: string;
11416
+ maxShortPoolUsdForDeposit: string;
11417
+ reserveFactorLong: string;
11418
+ reserveFactorShort: string;
11419
+ openInterestReserveFactorLong: string;
11420
+ openInterestReserveFactorShort: string;
11421
+ maxOpenInterestLong: string;
11422
+ maxOpenInterestShort: string;
11423
+ minPositionImpactPoolAmount: string;
11424
+ positionImpactPoolDistributionRate: string;
11425
+ borrowingFactorLong: string;
11426
+ borrowingFactorShort: string;
11427
+ borrowingExponentFactorLong: string;
11428
+ borrowingExponentFactorShort: string;
11429
+ fundingFactor: string;
11430
+ fundingExponentFactor: string;
11431
+ fundingIncreaseFactorPerSecond: string;
11432
+ fundingDecreaseFactorPerSecond: string;
11433
+ thresholdForStableFunding: string;
11434
+ thresholdForDecreaseFunding: string;
11435
+ minFundingFactorPerSecond: string;
11436
+ maxFundingFactorPerSecond: string;
11437
+ maxPnlFactorForTradersLong: string;
11438
+ maxPnlFactorForTradersShort: string;
11439
+ maxPnlFactorForDepositsLong: string;
11440
+ maxPnlFactorForDepositsShort: string;
11441
+ maxPnlFactorForWithdrawalsLong: string;
11442
+ maxPnlFactorForWithdrawalsShort: string;
11443
+ positionFeeFactorForBalanceWasImproved: string;
11444
+ positionFeeFactorForBalanceWasNotImproved: string;
11445
+ positionImpactFactorPositive: string;
11446
+ positionImpactFactorNegative: string;
11447
+ maxPositionImpactFactorPositive: string;
11448
+ maxPositionImpactFactorNegative: string;
11449
+ maxPositionImpactFactorForLiquidations: string;
11450
+ maxLendableImpactFactor: string;
11451
+ maxLendableImpactFactorForWithdrawals: string;
11452
+ maxLendableImpactUsd: string;
11453
+ lentPositionImpactPoolAmount: string;
11454
+ minCollateralFactor: string;
11455
+ minCollateralFactorForLiquidation: string;
11456
+ minCollateralFactorForOpenInterestLong: string;
11457
+ minCollateralFactorForOpenInterestShort: string;
11458
+ positionImpactExponentFactorPositive: string;
11459
+ positionImpactExponentFactorNegative: string;
11460
+ swapFeeFactorForBalanceWasImproved: string;
11461
+ swapFeeFactorForBalanceWasNotImproved: string;
11462
+ atomicSwapFeeFactor: string;
11463
+ swapImpactFactorPositive: string;
11464
+ swapImpactFactorNegative: string;
11465
+ swapImpactExponentFactor: string;
11466
+ withdrawalFeeFactorBalanceWasImproved: string;
11467
+ withdrawalFeeFactorBalanceWasNotImproved: string;
11468
+ virtualMarketId: string;
11469
+ virtualLongTokenId: string;
11470
+ virtualShortTokenId: string;
11471
+ };
11320
11472
  };
11321
11473
  "43113": {
11322
11474
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {
@@ -14366,6 +14518,14 @@ export declare const HASHED_KINK_MODEL_MARKET_RATES_KEYS: {
14366
14518
  aboveOptimalUsageBorrowingFactorLong: string;
14367
14519
  aboveOptimalUsageBorrowingFactorShort: string;
14368
14520
  };
14521
+ "0x1b997cb4841c4cb360E384192fFd7fb26eb10e5f": {
14522
+ optimalUsageFactorLong: string;
14523
+ optimalUsageFactorShort: string;
14524
+ baseBorrowingFactorLong: string;
14525
+ baseBorrowingFactorShort: string;
14526
+ aboveOptimalUsageBorrowingFactorLong: string;
14527
+ aboveOptimalUsageBorrowingFactorShort: string;
14528
+ };
14369
14529
  "0xc5c9B5E23810565763De41144741477eeCB25e2e": {
14370
14530
  optimalUsageFactorLong: string;
14371
14531
  optimalUsageFactorShort: string;
@@ -15432,6 +15592,14 @@ export declare const HASHED_KINK_MODEL_MARKET_RATES_KEYS: {
15432
15592
  aboveOptimalUsageBorrowingFactorLong: string;
15433
15593
  aboveOptimalUsageBorrowingFactorShort: string;
15434
15594
  };
15595
+ "0xE26E7b91143f367445f1c0a5dCf4f4aC8EaDcDb1": {
15596
+ optimalUsageFactorLong: string;
15597
+ optimalUsageFactorShort: string;
15598
+ baseBorrowingFactorLong: string;
15599
+ baseBorrowingFactorShort: string;
15600
+ aboveOptimalUsageBorrowingFactorLong: string;
15601
+ aboveOptimalUsageBorrowingFactorShort: string;
15602
+ };
15435
15603
  };
15436
15604
  "43113": {
15437
15605
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {