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

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 (47) hide show
  1. package/build/cjs/scripts/subsquid-codegen.js +1 -1
  2. package/build/cjs/src/clients/v1/modules/trades/trades.js +2 -5
  3. package/build/cjs/src/clients/v1/testUtil.js +1 -1
  4. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -0
  5. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +114 -0
  6. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -0
  7. package/build/cjs/src/codegen/subsquid.js +94 -424
  8. package/build/cjs/src/configs/express.js +7 -2
  9. package/build/cjs/src/configs/markets.js +14 -0
  10. package/build/cjs/src/configs/tokens.js +22 -0
  11. package/build/cjs/src/utils/__tests__/numbers.spec.js +19 -0
  12. package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +45 -0
  13. package/build/cjs/src/utils/errors/transactionsErrors.js +32 -0
  14. package/build/cjs/src/utils/fees/priceImpact.js +5 -1
  15. package/build/cjs/src/utils/gelatoRelay/utils.js +14 -8
  16. package/build/cjs/src/utils/numbers/utils.js +45 -8
  17. package/build/cjs/src/utils/orderTransactions/utils.js +6 -3
  18. package/build/cjs/src/utils/positions/utils.js +3 -1
  19. package/build/cjs/src/utils/tradeHistory/utils.js +2 -2
  20. package/build/esm/scripts/subsquid-codegen.js +1 -1
  21. package/build/esm/src/clients/v1/modules/trades/trades.js +2 -5
  22. package/build/esm/src/clients/v1/testUtil.js +1 -1
  23. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +16 -0
  24. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +114 -0
  25. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +30 -0
  26. package/build/esm/src/codegen/subsquid.js +93 -423
  27. package/build/esm/src/configs/express.js +6 -1
  28. package/build/esm/src/configs/markets.js +14 -0
  29. package/build/esm/src/configs/tokens.js +22 -0
  30. package/build/esm/src/utils/__tests__/numbers.spec.js +20 -1
  31. package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +45 -0
  32. package/build/esm/src/utils/errors/transactionsErrors.js +32 -0
  33. package/build/esm/src/utils/fees/priceImpact.js +5 -1
  34. package/build/esm/src/utils/gelatoRelay/utils.js +11 -4
  35. package/build/esm/src/utils/numbers/utils.js +45 -8
  36. package/build/esm/src/utils/orderTransactions/utils.js +6 -3
  37. package/build/esm/src/utils/positions/utils.js +3 -1
  38. package/build/esm/src/utils/tradeHistory/utils.js +2 -2
  39. package/build/types/src/codegen/prebuilt/index.d.ts +160 -0
  40. package/build/types/src/codegen/subsquid.d.ts +392 -587
  41. package/build/types/src/configs/express.d.ts +2 -1
  42. package/build/types/src/utils/errors/transactionsErrors.d.ts +33 -1
  43. package/build/types/src/utils/gelatoRelay/utils.d.ts +4 -2
  44. package/build/types/src/utils/numbers/utils.d.ts +2 -1
  45. package/build/types/src/utils/orderTransactions/utils.d.ts +2 -2
  46. package/build/types/src/utils/tradeHistory/types.d.ts +2 -6
  47. package/package.json +2 -2
@@ -8,8 +8,13 @@ export const DEFAULT_SUBACCOUNT_EXPIRY_DURATION = periodToSeconds(7, "1d"); // 1
8
8
  export const DEFAULT_SUBACCOUNT_MAX_ALLOWED_COUNT = 90;
9
9
  export const DEFAULT_PERMIT_DEADLINE_DURATION = periodToSeconds(1, "1h");
10
10
  export const DEFAULT_EXPRESS_ORDER_DEADLINE_DURATION = periodToSeconds(1, "1h");
11
- export const MIN_GELATO_USD_BALANCE_FOR_SPONSORED_CALL = expandDecimals(100, USD_DECIMALS); // 100$
12
11
  export const MIN_RELAYER_FEE_USD = 5n ** BigInt(USD_DECIMALS - 1); // 0.5$
12
+ export const GELATO_API_KEYS = {
13
+ [ARBITRUM]: "6dE6kOa9pc1ap4dQQC2iaK9i6nBFp8eYxQlm00VreWc_",
14
+ [AVALANCHE]: "FalsQh9loL6V0rwPy4gWgnQPR6uTHfWjSVT2qlTzUq4_",
15
+ [BOTANIX]: "s5GgkfX7dvd_2uYqsRSCjzMekUrXh0dibUvfLab1Anc_",
16
+ [ARBITRUM_SEPOLIA]: "nx5nyAg4h2kI_64YtOuPt7LSPDEXo4u8eJY_idF9xDw_",
17
+ };
13
18
  export const EXPRESS_EXTRA_EXECUTION_FEE_BUFFER_BPS = 1000;
14
19
  export const EXPRESS_DEFAULT_MIN_RESIDUAL_USD_NUMBER = 20;
15
20
  export const EXPRESS_DEFAULT_MIN_RESIDUAL_USD = expandDecimals(EXPRESS_DEFAULT_MIN_RESIDUAL_USD_NUMBER, USD_DECIMALS);
@@ -887,6 +887,20 @@ export const MARKETS = {
887
887
  longTokenAddress: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
888
888
  shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
889
889
  },
890
+ // CC/USD [WBTC-USDC]
891
+ "0x45F0331a6e175B556Bc7d28E0A1c349525006d4E": {
892
+ marketTokenAddress: "0x45F0331a6e175B556Bc7d28E0A1c349525006d4E",
893
+ indexTokenAddress: "0x7F2A3967bd0999A860E13Ab8DC34aF98675CC208",
894
+ longTokenAddress: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
895
+ shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
896
+ },
897
+ // MET/USD [WBTC-USDC]
898
+ "0xbA30e198CFFeBEf0A84D6943cC8B2e356E324112": {
899
+ marketTokenAddress: "0xbA30e198CFFeBEf0A84D6943cC8B2e356E324112",
900
+ indexTokenAddress: "0x84D523493Aac127025AC770981a54C9601326A41",
901
+ longTokenAddress: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
902
+ shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
903
+ },
890
904
  },
891
905
  [AVALANCHE]: {
892
906
  // BTC/USD [BTC-USDC]
@@ -1250,6 +1250,28 @@ export const TOKENS = {
1250
1250
  categories: ["layer1"],
1251
1251
  imageUrl: "https://assets.coingecko.com/coins/images/54035/standard/Transparent_bg.png?1738075331",
1252
1252
  },
1253
+ {
1254
+ name: "Canton",
1255
+ symbol: "CC",
1256
+ address: "0x7F2A3967bd0999A860E13Ab8DC34aF98675CC208",
1257
+ isSynthetic: true,
1258
+ decimals: 18,
1259
+ priceDecimals: 5,
1260
+ categories: ["layer1"],
1261
+ imageUrl: "https://assets.coingecko.com/coins/images/70468/standard/Canton-Ticker_%281%29.png?1762826299",
1262
+ explorerUrl: "https://arbiscan.io/token/0x7F2A3967bd0999A860E13Ab8DC34aF98675CC208",
1263
+ },
1264
+ {
1265
+ name: "Meteora",
1266
+ symbol: "MET",
1267
+ address: "0x84D523493Aac127025AC770981a54C9601326A41",
1268
+ isSynthetic: true,
1269
+ decimals: 18,
1270
+ priceDecimals: 5,
1271
+ categories: ["defi"],
1272
+ imageUrl: "https://assets.coingecko.com/coins/images/69110/standard/meteora.png?1757517561",
1273
+ explorerUrl: "https://arbiscan.io/token/0x84D523493Aac127025AC770981a54C9601326A41",
1274
+ },
1253
1275
  ],
1254
1276
  [AVALANCHE]: [
1255
1277
  {
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { BASIS_POINTS_DIVISOR_BIGINT, USD_DECIMALS } from "../../configs/factors";
3
- import { applyFactor, basisPointsToFloat, bigintToNumber, BN_NEGATIVE_ONE, BN_ONE, BN_ZERO, expandDecimals, formatAmount, formatAmountHuman, formatBalanceAmount, formatFactor, formatPercentage, formatTokenAmount, formatUsdPrice, getBasisPoints, numberToBigint, PERCENT_PRECISION_DECIMALS, PRECISION, PRECISION_DECIMALS, roundWithDecimals, roundUpMagnitudeDivision, toBigNumberWithDecimals, } from "../numbers";
3
+ import { applyFactor, basisPointsToFloat, bigintToNumber, BN_NEGATIVE_ONE, BN_ONE, BN_ZERO, expandDecimals, formatAmount, formatAmountHuman, formatBalanceAmount, formatFactor, formatPercentage, formatTokenAmount, formatUsdPrice, getBasisPoints, numberToBigint, PERCENT_PRECISION_DECIMALS, PRECISION, PRECISION_DECIMALS, trimZeroDecimals, roundWithDecimals, roundUpMagnitudeDivision, toBigNumberWithDecimals, } from "../numbers";
4
4
  const ONE_USD = 1000000000000000000000000000000n;
5
5
  describe("numbers utils", () => {
6
6
  it("constants", () => {
@@ -80,6 +80,25 @@ describe("numbers utils", () => {
80
80
  expect(numberToBigint(-1.123456789, 6)).toEqual(-1123456n);
81
81
  });
82
82
  });
83
+ describe("trimZeroDecimals", () => {
84
+ it("large integer stays as plain string (no scientific)", () => {
85
+ const large = "1" + "0".repeat(31);
86
+ expect(trimZeroDecimals(large)).toBe(large);
87
+ });
88
+ it("negative large integer", () => {
89
+ const largeNeg = "-" + "1" + "0".repeat(31);
90
+ expect(trimZeroDecimals(largeNeg)).toBe(largeNeg);
91
+ });
92
+ it("fraction with only zero decimals trims to int", () => {
93
+ expect(trimZeroDecimals("123.000")).toBe("123");
94
+ });
95
+ it("leading zeros on integer are removed", () => {
96
+ expect(trimZeroDecimals("0000123")).toBe("123");
97
+ });
98
+ it("leading zeros with trailing zero decimals trims to int", () => {
99
+ expect(trimZeroDecimals("0000123.000")).toBe("123");
100
+ });
101
+ });
83
102
  describe("toBigNumberWithDecimals", () => {
84
103
  it("should convert string to big number with decimals", () => {
85
104
  expect(toBigNumberWithDecimals("0", PRECISION_DECIMALS)).toBe(0n);
@@ -175,6 +175,51 @@ describe("Batch Utils", () => {
175
175
  });
176
176
  });
177
177
  describe("getBatchTotalExecutionFee", () => {
178
+ it("returns undefined for empty batch", () => {
179
+ const tokensData = {
180
+ [WETH.address]: {
181
+ ...WETH,
182
+ prices: {
183
+ minPrice: expandDecimals(2000, USD_DECIMALS),
184
+ maxPrice: expandDecimals(2000, USD_DECIMALS),
185
+ },
186
+ },
187
+ };
188
+ const result = getBatchTotalExecutionFee({
189
+ batchParams: { createOrderParams: [], updateOrderParams: [], cancelOrderParams: [] },
190
+ tokensData,
191
+ chainId: CHAIN_ID,
192
+ });
193
+ expect(result).toBeUndefined();
194
+ });
195
+ it("returns valid ExecutionFee with zero amounts for cancel-only batch", () => {
196
+ const tokensData = {
197
+ [WETH.address]: {
198
+ ...WETH,
199
+ prices: {
200
+ minPrice: expandDecimals(2000, USD_DECIMALS),
201
+ maxPrice: expandDecimals(2000, USD_DECIMALS),
202
+ },
203
+ },
204
+ };
205
+ const result = getBatchTotalExecutionFee({
206
+ batchParams: {
207
+ createOrderParams: [],
208
+ updateOrderParams: [],
209
+ cancelOrderParams: [{ orderKey: "0x123" }],
210
+ },
211
+ tokensData,
212
+ chainId: CHAIN_ID,
213
+ });
214
+ expect(result).toEqual({
215
+ feeTokenAmount: 0n,
216
+ gasLimit: 0n,
217
+ feeUsd: 0n,
218
+ feeToken: tokensData[WETH.address],
219
+ isFeeHigh: false,
220
+ isFeeVeryHigh: false,
221
+ });
222
+ });
178
223
  it("calculates total execution fee including top-ups", () => {
179
224
  const params5 = {
180
225
  ...commonMarketIncreaseParams,
@@ -59,10 +59,42 @@ const TX_ERROR_PATTERNS = {
59
59
  };
60
60
  export var CustomErrorName;
61
61
  (function (CustomErrorName) {
62
+ CustomErrorName["DisabledMarket"] = "DisabledMarket";
62
63
  CustomErrorName["EndOfOracleSimulation"] = "EndOfOracleSimulation";
64
+ CustomErrorName["ExternalCallFailed"] = "ExternalCallFailed";
65
+ CustomErrorName["InsufficientCollateralAmount"] = "InsufficientCollateralAmount";
66
+ CustomErrorName["InsufficientCollateralUsd"] = "InsufficientCollateralUsd";
67
+ CustomErrorName["InsufficientExecutionGas"] = "InsufficientExecutionGas";
63
68
  CustomErrorName["InsufficientExecutionFee"] = "InsufficientExecutionFee";
69
+ CustomErrorName["InsufficientFundsToPayForCosts"] = "InsufficientFundsToPayForCosts";
70
+ CustomErrorName["InsufficientOutputAmount"] = "InsufficientOutputAmount";
71
+ CustomErrorName["InsufficientPoolAmount"] = "InsufficientPoolAmount";
72
+ CustomErrorName["InsufficientReserve"] = "InsufficientReserve";
73
+ CustomErrorName["InsufficientReserveForOpenInterest"] = "InsufficientReserveForOpenInterest";
64
74
  CustomErrorName["OrderNotFulfillableAtAcceptablePrice"] = "OrderNotFulfillableAtAcceptablePrice";
65
75
  CustomErrorName["InsufficientSwapOutputAmount"] = "InsufficientSwapOutputAmount";
76
+ CustomErrorName["InvalidCollateralTokenForMarket"] = "InvalidCollateralTokenForMarket";
77
+ CustomErrorName["InvalidDecreaseOrderSize"] = "InvalidDecreaseOrderSize";
78
+ CustomErrorName["InvalidOraclePrice"] = "InvalidOraclePrice";
79
+ CustomErrorName["LiquidatablePosition"] = "LiquidatablePosition";
80
+ CustomErrorName["MarketNotFound"] = "MarketNotFound";
81
+ CustomErrorName["MaxOpenInterestExceeded"] = "MaxOpenInterestExceeded";
82
+ CustomErrorName["MaxPoolAmountExceeded"] = "MaxPoolAmountExceeded";
83
+ CustomErrorName["MaxPoolUsdForDepositExceeded"] = "MaxPoolUsdForDepositExceeded";
84
+ CustomErrorName["MaxPriceAgeExceeded"] = "MaxPriceAgeExceeded";
85
+ CustomErrorName["MinPositionSize"] = "MinPositionSize";
86
+ CustomErrorName["NegativeExecutionPrice"] = "NegativeExecutionPrice";
87
+ CustomErrorName["OrderNotFound"] = "OrderNotFound";
88
+ CustomErrorName["OrderNotUpdatable"] = "OrderNotUpdatable";
89
+ CustomErrorName["OrderTypeCannotBeCreated"] = "OrderTypeCannotBeCreated";
90
+ CustomErrorName["PnlFactorExceededForLongs"] = "PnlFactorExceededForLongs";
91
+ CustomErrorName["PnlFactorExceededForShorts"] = "PnlFactorExceededForShorts";
92
+ CustomErrorName["PriceImpactLargerThanOrderSize"] = "PriceImpactLargerThanOrderSize";
93
+ CustomErrorName["SwapPriceImpactExceedsAmountIn"] = "SwapPriceImpactExceedsAmountIn";
94
+ CustomErrorName["UnableToWithdrawCollateral"] = "UnableToWithdrawCollateral";
95
+ CustomErrorName["UsdDeltaExceedsLongOpenInterest"] = "UsdDeltaExceedsLongOpenInterest";
96
+ CustomErrorName["UsdDeltaExceedsPoolValue"] = "UsdDeltaExceedsPoolValue";
97
+ CustomErrorName["UsdDeltaExceedsShortOpenInterest"] = "UsdDeltaExceedsShortOpenInterest";
66
98
  })(CustomErrorName || (CustomErrorName = {}));
67
99
  export function getIsUserRejectedError(errorType) {
68
100
  return errorType === TxErrorType.UserDenied;
@@ -342,7 +342,11 @@ export function applyImpactFactor(diff, factor, exponent) {
342
342
  const _diff = Number(diff) / 10 ** 30;
343
343
  const _exponent = Number(exponent) / 10 ** 30;
344
344
  // Pow and convert back to BigInt with 30 decimals
345
- let result = bigNumberify(BigInt(Math.round(_diff ** _exponent * 10 ** 30)));
345
+ const powered = _diff ** _exponent * 10 ** 30;
346
+ if (!isFinite(powered) || isNaN(powered)) {
347
+ return 0n;
348
+ }
349
+ let result = bigNumberify(BigInt(Math.round(powered)));
346
350
  result = (result * factor) / expandDecimals(1, 30);
347
351
  return result;
348
352
  }
@@ -1,4 +1,11 @@
1
- import { GelatoRelay } from "@gelatonetwork/relay-sdk";
2
- import noop from "lodash/noop";
3
- export const gelatoRelay = new GelatoRelay();
4
- gelatoRelay.onError(noop);
1
+ import { createGelatoEvmRelayerClient } from "@gelatocloud/gasless";
2
+ export { StatusCode } from "@gelatocloud/gasless";
3
+ let _relayerClients = new Map();
4
+ export function getGelatoRelayerClient(apiKey) {
5
+ let client = _relayerClients.get(apiKey);
6
+ if (!client) {
7
+ client = createGelatoEvmRelayerClient({ apiKey });
8
+ _relayerClients.set(apiKey, client);
9
+ }
10
+ return client;
11
+ }
@@ -68,16 +68,39 @@ export function numberToBigint(value, decimals) {
68
68
  return negative ? -res : res;
69
69
  }
70
70
  export const trimZeroDecimals = (amount) => {
71
- if (parseFloat(amount) === parseInt(amount)) {
72
- return parseInt(amount).toString();
71
+ if (amount === "") {
72
+ return amount;
73
+ }
74
+ if (!amount.includes(".")) {
75
+ return normalizeInteger(amount);
76
+ }
77
+ const isNegative = amount.startsWith("-");
78
+ const unsignedAmount = isNegative ? amount.slice(1) : amount;
79
+ const [integerPartRaw, fractionPartRaw = ""] = unsignedAmount.split(".");
80
+ if (/^0*$/.test(fractionPartRaw)) {
81
+ const integerWithSign = isNegative ? `-${integerPartRaw}` : integerPartRaw;
82
+ return normalizeInteger(integerWithSign);
73
83
  }
74
84
  return amount;
75
85
  };
86
+ function normalizeInteger(value) {
87
+ if (!value) {
88
+ return "0";
89
+ }
90
+ const isNegative = value.startsWith("-");
91
+ const hasPlus = value.startsWith("+");
92
+ const unsigned = isNegative || hasPlus ? value.slice(1) : value;
93
+ const stripped = unsigned.replace(/^0+/, "") || "0";
94
+ if (stripped === "0") {
95
+ return "0";
96
+ }
97
+ return isNegative ? `-${stripped}` : stripped;
98
+ }
76
99
  export function bigintToNumber(value, decimals) {
77
100
  const negative = value < 0;
78
101
  if (negative)
79
102
  value *= -1n;
80
- const precision = 10n ** BigInt(decimals);
103
+ const precision = expandDecimals(1, decimals);
81
104
  const int = value / precision;
82
105
  const frac = value % precision;
83
106
  const num = parseFloat(`${int}.${frac.toString().padStart(decimals, "0")}`);
@@ -122,7 +145,7 @@ export function formatDeltaUsd(deltaUsd, percentage, opts = {}) {
122
145
  }
123
146
  const sign = getPlusOrMinusSymbol(deltaUsd, { showPlusForZero: opts.showPlusForZero });
124
147
  const exceedingInfo = getLimitedDisplay(deltaUsd, USD_DECIMALS);
125
- const percentageStr = percentage !== undefined ? ` (${sign}${formatPercentage(bigMath.abs(percentage))})` : "";
148
+ const percentageStr = percentage !== undefined && !opts.hidePercentage ? ` (${sign}${formatPercentage(bigMath.abs(percentage))})` : "";
126
149
  const deltaUsdStr = formatAmount(exceedingInfo.value, USD_DECIMALS, 2, true);
127
150
  const symbol = exceedingInfo.symbol ? `${exceedingInfo.symbol} ` : "";
128
151
  return `${symbol}${sign}$\u200a${deltaUsdStr}${percentageStr}`;
@@ -345,12 +368,15 @@ export const formatArrayAmount = (arr, index, tokenDecimals, displayDecimals, us
345
368
  }
346
369
  return formatAmount(arr[index], tokenDecimals, displayDecimals, useCommas);
347
370
  };
348
- export const formatAmountFree = (amount, tokenDecimals, displayDecimals) => {
371
+ export const formatAmountFree = (amount, tokenDecimals, displayDecimals, visualMultiplier) => {
349
372
  if (amount === undefined || amount === null) {
350
373
  return "...";
351
374
  }
352
- amount = BigInt(amount);
353
- let amountStr = formatUnits(amount, tokenDecimals);
375
+ let amountBigInt = BigInt(amount);
376
+ if (visualMultiplier) {
377
+ amountBigInt = amountBigInt / BigInt(visualMultiplier);
378
+ }
379
+ let amountStr = formatUnits(amountBigInt, tokenDecimals);
354
380
  amountStr = limitDecimals(amountStr, displayDecimals);
355
381
  return trimZeroDecimals(amountStr);
356
382
  };
@@ -374,6 +400,12 @@ export function getLimitedDisplay(amount, tokenDecimals, opts = {}) {
374
400
  }
375
401
  export const limitDecimals = (amount, maxDecimals) => {
376
402
  let amountStr = amount.toString();
403
+ if (amountStr.includes("e") || amountStr.includes("E")) {
404
+ const num = Number(amountStr);
405
+ if (!isNaN(num)) {
406
+ amountStr = num.toFixed(20).replace(/\.?0+$/, "");
407
+ }
408
+ }
377
409
  if (maxDecimals === undefined) {
378
410
  return amountStr;
379
411
  }
@@ -472,11 +504,16 @@ export function bigNumberify(n) {
472
504
  }
473
505
  export const parseValue = (value, tokenDecimals) => {
474
506
  const pValue = parseFloat(value);
475
- if (isNaN(pValue)) {
507
+ if (isNaN(pValue) || !isFinite(pValue)) {
476
508
  return undefined;
477
509
  }
478
510
  value = limitDecimals(value, tokenDecimals);
479
511
  const amount = parseUnits(value, tokenDecimals);
512
+ // Cap at a safe maximum to prevent downstream BigInt overflow errors
513
+ const MAX_ALLOWED = expandDecimals(1, 62);
514
+ if (amount > MAX_ALLOWED || amount < -MAX_ALLOWED) {
515
+ return undefined;
516
+ }
480
517
  return bigNumberify(amount);
481
518
  };
482
519
  export function roundUpDivision(a, b) {
@@ -271,18 +271,21 @@ export function buildUpdateOrderPayload(p) {
271
271
  },
272
272
  };
273
273
  }
274
- export function getBatchTotalExecutionFee({ batchParams: { createOrderParams, updateOrderParams }, tokensData, chainId, }) {
274
+ export function getBatchTotalExecutionFee({ batchParams, tokensData, chainId, }) {
275
+ if (getIsEmptyBatch(batchParams)) {
276
+ return undefined;
277
+ }
275
278
  let feeTokenAmount = 0n;
276
279
  let gasLimit = 0n;
277
280
  const wnt = getByKey(tokensData, getWrappedToken(chainId).address);
278
281
  if (!wnt) {
279
282
  return undefined;
280
283
  }
281
- for (const co of createOrderParams) {
284
+ for (const co of batchParams.createOrderParams) {
282
285
  feeTokenAmount += co.orderPayload.numbers.executionFee;
283
286
  gasLimit += co.params.executionGasLimit;
284
287
  }
285
- for (const uo of updateOrderParams) {
288
+ for (const uo of batchParams.updateOrderParams) {
286
289
  feeTokenAmount += uo.updatePayload.executionFeeTopUp;
287
290
  }
288
291
  const feeUsd = convertToUsd(feeTokenAmount, wnt.decimals, wnt.prices.maxPrice);
@@ -235,7 +235,9 @@ export function getContractPositionDynamicFees({ position, marketInfo, marketFee
235
235
  }
236
236
  const claimableLongTokenAmount = getFundingAmount(latestLongTokenClaimableFundingAmountPerSize, position.longTokenClaimableFundingAmountPerSize, sizeInUsd);
237
237
  const claimableShortTokenAmount = getFundingAmount(latestShortTokenClaimableFundingAmountPerSize, position.shortTokenClaimableFundingAmountPerSize, sizeInUsd);
238
- const { balanceWasImproved } = getPriceImpactForPosition(marketInfo, -sizeInUsd, isLong);
238
+ const { balanceWasImproved } = getPriceImpactForPosition(marketInfo, -sizeInUsd, isLong, {
239
+ fallbackToZero: true,
240
+ });
239
241
  const { positionFeeUsd, discountUsd, uiFeeUsd } = getPositionFee(marketInfo, sizeInUsd, balanceWasImproved, referralInfo);
240
242
  const positionFeeAmount = convertToTokenAmount(positionFeeUsd, collateralToken.decimals, collateralMinPrice) ?? 0n;
241
243
  const traderDiscountAmount = convertToTokenAmount(discountUsd, collateralToken.decimals, collateralMinPrice) ?? 0n;
@@ -39,7 +39,7 @@ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, t
39
39
  targetCollateralToken,
40
40
  initialCollateralToken,
41
41
  timestamp: rawAction.timestamp,
42
- transaction: rawAction.transaction,
42
+ transactionHash: rawAction.transactionHash,
43
43
  reason: rawAction.reason ?? undefined,
44
44
  reasonBytes: rawAction.reasonBytes ?? undefined,
45
45
  twapParams: rawAction.twapGroupId && rawAction.numberOfParts
@@ -120,7 +120,7 @@ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, t
120
120
  liquidationFeeAmount: rawAction.liquidationFeeAmount ? BigInt(rawAction.liquidationFeeAmount) : undefined,
121
121
  reason: rawAction.reason ?? undefined,
122
122
  reasonBytes: rawAction.reasonBytes ?? undefined,
123
- transaction: rawAction.transaction,
123
+ transactionHash: rawAction.transactionHash,
124
124
  timestamp: rawAction.timestamp,
125
125
  shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
126
126
  twapParams: rawAction.twapGroupId && rawAction.numberOfParts
@@ -1922,6 +1922,36 @@ export declare const HASHED_MARKET_VALUES_KEYS: {
1922
1922
  shortInterestInTokensUsingLongToken: string;
1923
1923
  shortInterestInTokensUsingShortToken: string;
1924
1924
  };
1925
+ "0x45F0331a6e175B556Bc7d28E0A1c349525006d4E": {
1926
+ longPoolAmount: string;
1927
+ shortPoolAmount: string;
1928
+ positionImpactPoolAmount: string;
1929
+ swapImpactPoolAmountLong: string;
1930
+ swapImpactPoolAmountShort: string;
1931
+ longInterestUsingLongToken: string;
1932
+ longInterestUsingShortToken: string;
1933
+ shortInterestUsingLongToken: string;
1934
+ shortInterestUsingShortToken: string;
1935
+ longInterestInTokensUsingLongToken: string;
1936
+ longInterestInTokensUsingShortToken: string;
1937
+ shortInterestInTokensUsingLongToken: string;
1938
+ shortInterestInTokensUsingShortToken: string;
1939
+ };
1940
+ "0xbA30e198CFFeBEf0A84D6943cC8B2e356E324112": {
1941
+ longPoolAmount: string;
1942
+ shortPoolAmount: string;
1943
+ positionImpactPoolAmount: string;
1944
+ swapImpactPoolAmountLong: string;
1945
+ swapImpactPoolAmountShort: string;
1946
+ longInterestUsingLongToken: string;
1947
+ longInterestUsingShortToken: string;
1948
+ shortInterestUsingLongToken: string;
1949
+ shortInterestUsingShortToken: string;
1950
+ longInterestInTokensUsingLongToken: string;
1951
+ longInterestInTokensUsingShortToken: string;
1952
+ shortInterestInTokensUsingLongToken: string;
1953
+ shortInterestInTokensUsingShortToken: string;
1954
+ };
1925
1955
  };
1926
1956
  "43113": {
1927
1957
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {
@@ -9905,6 +9935,120 @@ export declare const HASHED_MARKET_CONFIG_KEYS: {
9905
9935
  virtualLongTokenId: string;
9906
9936
  virtualShortTokenId: string;
9907
9937
  };
9938
+ "0x45F0331a6e175B556Bc7d28E0A1c349525006d4E": {
9939
+ isDisabled: string;
9940
+ maxLongPoolAmount: string;
9941
+ maxShortPoolAmount: string;
9942
+ maxLongPoolUsdForDeposit: string;
9943
+ maxShortPoolUsdForDeposit: string;
9944
+ reserveFactorLong: string;
9945
+ reserveFactorShort: string;
9946
+ openInterestReserveFactorLong: string;
9947
+ openInterestReserveFactorShort: string;
9948
+ maxOpenInterestLong: string;
9949
+ maxOpenInterestShort: string;
9950
+ minPositionImpactPoolAmount: string;
9951
+ positionImpactPoolDistributionRate: string;
9952
+ borrowingFactorLong: string;
9953
+ borrowingFactorShort: string;
9954
+ borrowingExponentFactorLong: string;
9955
+ borrowingExponentFactorShort: string;
9956
+ fundingFactor: string;
9957
+ fundingExponentFactor: string;
9958
+ fundingIncreaseFactorPerSecond: string;
9959
+ fundingDecreaseFactorPerSecond: string;
9960
+ thresholdForStableFunding: string;
9961
+ thresholdForDecreaseFunding: string;
9962
+ minFundingFactorPerSecond: string;
9963
+ maxFundingFactorPerSecond: string;
9964
+ maxPnlFactorForTradersLong: string;
9965
+ maxPnlFactorForTradersShort: string;
9966
+ positionFeeFactorForBalanceWasImproved: string;
9967
+ positionFeeFactorForBalanceWasNotImproved: string;
9968
+ positionImpactFactorPositive: string;
9969
+ positionImpactFactorNegative: string;
9970
+ maxPositionImpactFactorPositive: string;
9971
+ maxPositionImpactFactorNegative: string;
9972
+ maxPositionImpactFactorForLiquidations: string;
9973
+ maxLendableImpactFactor: string;
9974
+ maxLendableImpactFactorForWithdrawals: string;
9975
+ maxLendableImpactUsd: string;
9976
+ lentPositionImpactPoolAmount: string;
9977
+ minCollateralFactor: string;
9978
+ minCollateralFactorForLiquidation: string;
9979
+ minCollateralFactorForOpenInterestLong: string;
9980
+ minCollateralFactorForOpenInterestShort: string;
9981
+ positionImpactExponentFactorPositive: string;
9982
+ positionImpactExponentFactorNegative: string;
9983
+ swapFeeFactorForBalanceWasImproved: string;
9984
+ swapFeeFactorForBalanceWasNotImproved: string;
9985
+ atomicSwapFeeFactor: string;
9986
+ swapImpactFactorPositive: string;
9987
+ swapImpactFactorNegative: string;
9988
+ swapImpactExponentFactor: string;
9989
+ withdrawalFeeFactorBalanceWasImproved: string;
9990
+ withdrawalFeeFactorBalanceWasNotImproved: string;
9991
+ virtualMarketId: string;
9992
+ virtualLongTokenId: string;
9993
+ virtualShortTokenId: string;
9994
+ };
9995
+ "0xbA30e198CFFeBEf0A84D6943cC8B2e356E324112": {
9996
+ isDisabled: string;
9997
+ maxLongPoolAmount: string;
9998
+ maxShortPoolAmount: string;
9999
+ maxLongPoolUsdForDeposit: string;
10000
+ maxShortPoolUsdForDeposit: string;
10001
+ reserveFactorLong: string;
10002
+ reserveFactorShort: string;
10003
+ openInterestReserveFactorLong: string;
10004
+ openInterestReserveFactorShort: string;
10005
+ maxOpenInterestLong: string;
10006
+ maxOpenInterestShort: string;
10007
+ minPositionImpactPoolAmount: string;
10008
+ positionImpactPoolDistributionRate: string;
10009
+ borrowingFactorLong: string;
10010
+ borrowingFactorShort: string;
10011
+ borrowingExponentFactorLong: string;
10012
+ borrowingExponentFactorShort: string;
10013
+ fundingFactor: string;
10014
+ fundingExponentFactor: string;
10015
+ fundingIncreaseFactorPerSecond: string;
10016
+ fundingDecreaseFactorPerSecond: string;
10017
+ thresholdForStableFunding: string;
10018
+ thresholdForDecreaseFunding: string;
10019
+ minFundingFactorPerSecond: string;
10020
+ maxFundingFactorPerSecond: string;
10021
+ maxPnlFactorForTradersLong: string;
10022
+ maxPnlFactorForTradersShort: string;
10023
+ positionFeeFactorForBalanceWasImproved: string;
10024
+ positionFeeFactorForBalanceWasNotImproved: string;
10025
+ positionImpactFactorPositive: string;
10026
+ positionImpactFactorNegative: string;
10027
+ maxPositionImpactFactorPositive: string;
10028
+ maxPositionImpactFactorNegative: string;
10029
+ maxPositionImpactFactorForLiquidations: string;
10030
+ maxLendableImpactFactor: string;
10031
+ maxLendableImpactFactorForWithdrawals: string;
10032
+ maxLendableImpactUsd: string;
10033
+ lentPositionImpactPoolAmount: string;
10034
+ minCollateralFactor: string;
10035
+ minCollateralFactorForLiquidation: string;
10036
+ minCollateralFactorForOpenInterestLong: string;
10037
+ minCollateralFactorForOpenInterestShort: string;
10038
+ positionImpactExponentFactorPositive: string;
10039
+ positionImpactExponentFactorNegative: string;
10040
+ swapFeeFactorForBalanceWasImproved: string;
10041
+ swapFeeFactorForBalanceWasNotImproved: string;
10042
+ atomicSwapFeeFactor: string;
10043
+ swapImpactFactorPositive: string;
10044
+ swapImpactFactorNegative: string;
10045
+ swapImpactExponentFactor: string;
10046
+ withdrawalFeeFactorBalanceWasImproved: string;
10047
+ withdrawalFeeFactorBalanceWasNotImproved: string;
10048
+ virtualMarketId: string;
10049
+ virtualLongTokenId: string;
10050
+ virtualShortTokenId: string;
10051
+ };
9908
10052
  };
9909
10053
  "43113": {
9910
10054
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {
@@ -13506,6 +13650,22 @@ export declare const HASHED_KINK_MODEL_MARKET_RATES_KEYS: {
13506
13650
  aboveOptimalUsageBorrowingFactorLong: string;
13507
13651
  aboveOptimalUsageBorrowingFactorShort: string;
13508
13652
  };
13653
+ "0x45F0331a6e175B556Bc7d28E0A1c349525006d4E": {
13654
+ optimalUsageFactorLong: string;
13655
+ optimalUsageFactorShort: string;
13656
+ baseBorrowingFactorLong: string;
13657
+ baseBorrowingFactorShort: string;
13658
+ aboveOptimalUsageBorrowingFactorLong: string;
13659
+ aboveOptimalUsageBorrowingFactorShort: string;
13660
+ };
13661
+ "0xbA30e198CFFeBEf0A84D6943cC8B2e356E324112": {
13662
+ optimalUsageFactorLong: string;
13663
+ optimalUsageFactorShort: string;
13664
+ baseBorrowingFactorLong: string;
13665
+ baseBorrowingFactorShort: string;
13666
+ aboveOptimalUsageBorrowingFactorLong: string;
13667
+ aboveOptimalUsageBorrowingFactorShort: string;
13668
+ };
13509
13669
  };
13510
13670
  "43113": {
13511
13671
  "0xD996ff47A1F763E1e55415BC4437c59292D1F415": {