@gmx-io/sdk 1.0.0-alpha.1 → 1.0.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 (34) hide show
  1. package/README.md +5 -3
  2. package/build/cjs/src/configs/markets.js +7 -0
  3. package/build/cjs/src/configs/tokens.js +11 -0
  4. package/build/cjs/src/modules/trades/trades.js +27 -156
  5. package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +8 -0
  6. package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +50 -0
  7. package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +15 -0
  8. package/build/cjs/src/utils/__tests__/subgraph.spec.js +0 -4
  9. package/build/cjs/src/utils/fees/priceImpact.js +2 -2
  10. package/build/cjs/src/utils/subgraph.js +16 -6
  11. package/build/cjs/src/utils/testUtil.js +1 -2
  12. package/build/cjs/src/utils/tradeHistory.js +137 -0
  13. package/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  14. package/build/esm/src/configs/markets.js +7 -0
  15. package/build/esm/src/configs/tokens.js +11 -0
  16. package/build/esm/src/modules/trades/trades.js +25 -153
  17. package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +8 -0
  18. package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +50 -0
  19. package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +15 -0
  20. package/build/esm/src/utils/__tests__/subgraph.spec.js +0 -4
  21. package/build/esm/src/utils/fees/priceImpact.js +1 -1
  22. package/build/esm/src/utils/subgraph.js +16 -6
  23. package/build/esm/src/utils/testUtil.js +1 -2
  24. package/build/esm/src/utils/tradeHistory.js +132 -0
  25. package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
  26. package/build/src/abis/index.d.ts +20 -1
  27. package/build/src/modules/markets/query-builders.d.ts +1 -1
  28. package/build/src/modules/tokens/tokens.d.ts +2 -2
  29. package/build/src/modules/trades/trades.d.ts +2 -3
  30. package/build/src/types/sdk.d.ts +0 -2
  31. package/build/src/types/tradeHistory.d.ts +3 -3
  32. package/build/src/utils/subgraph.d.ts +7 -5
  33. package/build/src/utils/tradeHistory.d.ts +7 -0
  34. package/package.json +7 -7
@@ -577,6 +577,13 @@ export const MARKETS = {
577
577
  longTokenAddress: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
578
578
  shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
579
579
  },
580
+ // DOLO/USD [WETH-USDC]
581
+ "0x4D3Eb91efd36C2b74181F34B111bc1E91a0d0cb4": {
582
+ marketTokenAddress: "0x4D3Eb91efd36C2b74181F34B111bc1E91a0d0cb4",
583
+ indexTokenAddress: "0x97Ce1F309B949f7FBC4f58c5cb6aa417A5ff8964",
584
+ longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
585
+ shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
586
+ },
580
587
  },
581
588
  [AVALANCHE]: {
582
589
  // BTC/USD [BTC-USDC]
@@ -876,6 +876,17 @@ export const TOKENS = {
876
876
  coingeckoUrl: "https://www.coingecko.com/en/coins/mantra",
877
877
  isSynthetic: true,
878
878
  },
879
+ {
880
+ name: "Dolomite",
881
+ symbol: "DOLO",
882
+ address: "0x97Ce1F309B949f7FBC4f58c5cb6aa417A5ff8964",
883
+ decimals: 18,
884
+ priceDecimals: 6,
885
+ categories: ["defi"],
886
+ imageUrl: "https://assets.coingecko.com/coins/images/54710/standard/DOLO-small.png?1745398535",
887
+ coingeckoUrl: "https://www.coingecko.com/en/coins/dolomite",
888
+ isSynthetic: true,
889
+ },
879
890
  {
880
891
  name: "GMX LP",
881
892
  symbol: "GLP",
@@ -1,14 +1,12 @@
1
1
  import merge from "lodash/merge";
2
- import { getAddress } from "viem";
3
2
  import { getWrappedToken } from "../../configs/tokens";
4
3
  import { OrderType } from "../../types/orders";
5
4
  import { TradeActionType } from "../../types/tradeHistory";
6
5
  import graphqlFetcher from "../../utils/graphqlFetcher";
7
- import { getByKey } from "../../utils/objects";
8
6
  import { isIncreaseOrderType, isLimitOrderType, isSwapOrderType, isTriggerDecreaseOrderType } from "../../utils/orders";
9
7
  import { buildFiltersBody } from "../../utils/subgraph";
10
8
  import { getSwapPathOutputAddresses } from "../../utils/swap/swapStats";
11
- import { parseContractPrice } from "../../utils/tokens";
9
+ import { createRawTradeActionTransformer } from "../../utils/tradeHistory";
12
10
  import { Module } from "../base";
13
11
  export class Trades extends Module {
14
12
  async getTradeHistory(p) {
@@ -31,13 +29,13 @@ export class Trades extends Module {
31
29
  }
32
30
  }
33
31
  export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirectionsFilter = [], forAllAccounts, account, fromTxTimestamp, toTxTimestamp, orderEventCombinations, marketsInfoData, tokensData, }) {
34
- const endpoint = sdk.config.subgraphUrl;
32
+ const endpoint = sdk.config.subsquidUrl;
35
33
  const chainId = sdk.chainId;
36
34
  if (!endpoint) {
37
35
  return [];
38
36
  }
39
- const skip = pageIndex * pageSize;
40
- const first = pageSize;
37
+ const offset = pageIndex * pageSize;
38
+ const limit = pageSize;
41
39
  const nonSwapRelevantDefinedFiltersLowercased = marketsDirectionsFilter
42
40
  .filter((filter) => filter.direction !== "swap" && filter.marketAddress !== "any")
43
41
  .map((filter) => ({
@@ -58,40 +56,38 @@ export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirec
58
56
  .map((filter) => filter.marketAddress.toLowerCase());
59
57
  const hasSwapRelevantDefinedMarkets = swapRelevantDefinedMarketsLowercased.length > 0;
60
58
  const filtersStr = buildFiltersBody({
61
- and: [
59
+ AND: [
62
60
  {
63
- account: forAllAccounts ? undefined : account.toLowerCase(),
64
- transaction: {
65
- timestamp_gte: fromTxTimestamp,
66
- timestamp_lte: toTxTimestamp,
67
- },
61
+ account_eq: forAllAccounts ? undefined : account,
62
+ timestamp_gte: fromTxTimestamp,
63
+ timestamp_lte: toTxTimestamp,
68
64
  },
69
65
  {
70
- or: !hasPureDirectionFilters
66
+ OR: !hasPureDirectionFilters
71
67
  ? undefined
72
68
  : pureDirectionFilters.map((filter) => filter.direction === "swap"
73
69
  ? {
74
70
  orderType_in: [OrderType.LimitSwap, OrderType.MarketSwap],
75
71
  }
76
72
  : {
77
- isLong: filter.direction === "long",
73
+ isLong_eq: filter.direction === "long",
78
74
  orderType_not_in: [OrderType.LimitSwap, OrderType.MarketSwap],
79
75
  }),
80
76
  },
81
77
  {
82
- or: [
78
+ OR: [
83
79
  // For non-swap orders
84
80
  {
85
- and: !hasNonSwapRelevantDefinedMarkets
81
+ AND: !hasNonSwapRelevantDefinedMarkets
86
82
  ? undefined
87
83
  : [
88
84
  {
89
85
  orderType_not_in: [OrderType.LimitSwap, OrderType.MarketSwap],
90
86
  },
91
87
  {
92
- or: nonSwapRelevantDefinedFiltersLowercased.map((filter) => ({
93
- marketAddress: filter.marketAddress === "any" ? undefined : filter.marketAddress,
94
- isLong: filter.direction === "any" ? undefined : filter.direction === "long",
88
+ OR: nonSwapRelevantDefinedFiltersLowercased.map((filter) => ({
89
+ marketAddress_eq: filter.marketAddress === "any" ? undefined : filter.marketAddress,
90
+ isLong_eq: filter.direction === "any" ? undefined : filter.direction === "long",
95
91
  // Collateral filtering is done outside of graphql on the client
96
92
  })),
97
93
  },
@@ -99,14 +95,14 @@ export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirec
99
95
  },
100
96
  // For defined markets on swap orders
101
97
  {
102
- and: !hasSwapRelevantDefinedMarkets
98
+ AND: !hasSwapRelevantDefinedMarkets
103
99
  ? undefined
104
100
  : [
105
101
  {
106
102
  orderType_in: [OrderType.LimitSwap, OrderType.MarketSwap],
107
103
  },
108
104
  {
109
- or: [
105
+ OR: [
110
106
  // Source token is not in swap path so we add it to the or filter
111
107
  {
112
108
  marketAddress_in: swapRelevantDefinedMarketsLowercased,
@@ -120,7 +116,7 @@ export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirec
120
116
  ],
121
117
  },
122
118
  {
123
- or: orderEventCombinations?.map((combination) => {
119
+ OR: orderEventCombinations?.map((combination) => {
124
120
  let sizeDeltaUsdCondition = {};
125
121
  if (combination.orderType !== undefined &&
126
122
  [OrderType.MarketDecrease, OrderType.MarketIncrease].includes(combination.orderType)) {
@@ -132,25 +128,24 @@ export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirec
132
128
  }
133
129
  }
134
130
  return merge({
135
- eventName: combination.eventName,
136
- orderType: combination.orderType,
131
+ eventName_eq: combination.eventName,
132
+ orderType_eq: combination.orderType,
137
133
  }, sizeDeltaUsdCondition);
138
134
  }),
139
135
  },
140
136
  {
141
137
  // We do not show create liquidation orders in the trade history, thus we filter it out
142
138
  // ... && not (liquidation && orderCreated) === ... && (not liquidation || not orderCreated)
143
- or: [{ orderType_not: OrderType.Liquidation }, { eventName_not: TradeActionType.OrderCreated }],
139
+ OR: [{ orderType_not_eq: OrderType.Liquidation }, { eventName_not_eq: TradeActionType.OrderCreated }],
144
140
  },
145
141
  ],
146
142
  });
147
143
  const whereClause = `where: ${filtersStr}`;
148
144
  const query = `{
149
145
  tradeActions(
150
- skip: ${skip},
151
- first: ${first},
152
- orderBy: transaction__timestamp,
153
- orderDirection: desc,
146
+ offset: ${offset},
147
+ limit: ${limit},
148
+ orderBy: transaction_timestamp_DESC,
154
149
  ${whereClause}
155
150
  ) {
156
151
  id
@@ -190,6 +185,7 @@ export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirec
190
185
 
191
186
  reason
192
187
  reasonBytes
188
+ timestamp
193
189
 
194
190
  transaction {
195
191
  timestamp
@@ -260,127 +256,3 @@ export async function fetchTradeActions({ sdk, pageIndex, pageSize, marketsDirec
260
256
  }
261
257
  return tradeActions;
262
258
  }
263
- function createRawTradeActionTransformer(marketsInfoData, wrappedToken, tokensData) {
264
- return (rawAction) => {
265
- const orderType = Number(rawAction.orderType);
266
- if (isSwapOrderType(orderType)) {
267
- const initialCollateralTokenAddress = getAddress(rawAction.initialCollateralTokenAddress);
268
- const swapPath = rawAction.swapPath.map((address) => getAddress(address));
269
- const swapPathOutputAddresses = getSwapPathOutputAddresses({
270
- marketsInfoData,
271
- swapPath,
272
- initialCollateralAddress: initialCollateralTokenAddress,
273
- wrappedNativeTokenAddress: wrappedToken.address,
274
- shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
275
- isIncrease: false,
276
- });
277
- const initialCollateralToken = getByKey(tokensData, initialCollateralTokenAddress);
278
- const targetCollateralToken = getByKey(tokensData, swapPathOutputAddresses.outTokenAddress);
279
- if (!initialCollateralToken || !targetCollateralToken) {
280
- return undefined;
281
- }
282
- const tradeAction = {
283
- id: rawAction.id,
284
- eventName: rawAction.eventName,
285
- account: rawAction.account,
286
- swapPath,
287
- orderType,
288
- orderKey: rawAction.orderKey,
289
- initialCollateralTokenAddress: rawAction.initialCollateralTokenAddress,
290
- initialCollateralDeltaAmount: bigNumberify(rawAction.initialCollateralDeltaAmount),
291
- minOutputAmount: bigNumberify(rawAction.minOutputAmount),
292
- executionAmountOut: rawAction.executionAmountOut ? bigNumberify(rawAction.executionAmountOut) : undefined,
293
- shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
294
- targetCollateralToken,
295
- initialCollateralToken,
296
- transaction: rawAction.transaction,
297
- reason: rawAction.reason,
298
- reasonBytes: rawAction.reasonBytes,
299
- };
300
- return tradeAction;
301
- }
302
- else {
303
- const marketAddress = getAddress(rawAction.marketAddress);
304
- const marketInfo = getByKey(marketsInfoData, marketAddress);
305
- const indexToken = marketInfo?.indexToken;
306
- const initialCollateralTokenAddress = getAddress(rawAction.initialCollateralTokenAddress);
307
- const swapPath = rawAction.swapPath.map((address) => getAddress(address));
308
- const swapPathOutputAddresses = getSwapPathOutputAddresses({
309
- marketsInfoData,
310
- swapPath,
311
- initialCollateralAddress: initialCollateralTokenAddress,
312
- wrappedNativeTokenAddress: wrappedToken.address,
313
- shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
314
- isIncrease: isIncreaseOrderType(rawAction.orderType),
315
- });
316
- const initialCollateralToken = getByKey(tokensData, initialCollateralTokenAddress);
317
- const targetCollateralToken = getByKey(tokensData, swapPathOutputAddresses.outTokenAddress);
318
- if (!marketInfo || !indexToken || !initialCollateralToken || !targetCollateralToken) {
319
- return undefined;
320
- }
321
- const tradeAction = {
322
- id: rawAction.id,
323
- eventName: rawAction.eventName,
324
- account: rawAction.account,
325
- marketAddress,
326
- marketInfo,
327
- indexToken,
328
- swapPath,
329
- initialCollateralTokenAddress,
330
- initialCollateralToken,
331
- targetCollateralToken,
332
- initialCollateralDeltaAmount: bigNumberify(rawAction.initialCollateralDeltaAmount),
333
- sizeDeltaUsd: bigNumberify(rawAction.sizeDeltaUsd),
334
- triggerPrice: rawAction.triggerPrice
335
- ? parseContractPrice(bigNumberify(rawAction.triggerPrice), indexToken.decimals)
336
- : undefined,
337
- acceptablePrice: parseContractPrice(bigNumberify(rawAction.acceptablePrice), indexToken.decimals),
338
- executionPrice: rawAction.executionPrice
339
- ? parseContractPrice(bigNumberify(rawAction.executionPrice), indexToken.decimals)
340
- : undefined,
341
- minOutputAmount: bigNumberify(rawAction.minOutputAmount),
342
- collateralTokenPriceMax: rawAction.collateralTokenPriceMax
343
- ? parseContractPrice(bigNumberify(rawAction.collateralTokenPriceMax), initialCollateralToken.decimals)
344
- : undefined,
345
- collateralTokenPriceMin: rawAction.collateralTokenPriceMin
346
- ? parseContractPrice(bigNumberify(rawAction.collateralTokenPriceMin), initialCollateralToken.decimals)
347
- : undefined,
348
- indexTokenPriceMin: rawAction.indexTokenPriceMin
349
- ? parseContractPrice(BigInt(rawAction.indexTokenPriceMin), indexToken.decimals)
350
- : undefined,
351
- indexTokenPriceMax: rawAction.indexTokenPriceMax
352
- ? parseContractPrice(BigInt(rawAction.indexTokenPriceMax), indexToken.decimals)
353
- : undefined,
354
- orderType,
355
- orderKey: rawAction.orderKey,
356
- isLong: rawAction.isLong,
357
- pnlUsd: rawAction.pnlUsd ? BigInt(rawAction.pnlUsd) : undefined,
358
- basePnlUsd: rawAction.basePnlUsd ? BigInt(rawAction.basePnlUsd) : undefined,
359
- priceImpactDiffUsd: rawAction.priceImpactDiffUsd ? BigInt(rawAction.priceImpactDiffUsd) : undefined,
360
- priceImpactUsd: rawAction.priceImpactUsd ? BigInt(rawAction.priceImpactUsd) : undefined,
361
- positionFeeAmount: rawAction.positionFeeAmount ? BigInt(rawAction.positionFeeAmount) : undefined,
362
- borrowingFeeAmount: rawAction.borrowingFeeAmount ? BigInt(rawAction.borrowingFeeAmount) : undefined,
363
- fundingFeeAmount: rawAction.fundingFeeAmount ? BigInt(rawAction.fundingFeeAmount) : undefined,
364
- reason: rawAction.reason,
365
- reasonBytes: rawAction.reasonBytes,
366
- transaction: rawAction.transaction,
367
- shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
368
- };
369
- return tradeAction;
370
- }
371
- };
372
- }
373
- export function bigNumberify(n) {
374
- try {
375
- if (n === undefined)
376
- throw new Error("n is undefined");
377
- if (n === null)
378
- throw new Error("n is null");
379
- return BigInt(n);
380
- }
381
- catch (e) {
382
- // eslint-disable-next-line no-console
383
- console.error("bigNumberify error", e);
384
- return undefined;
385
- }
386
- }
@@ -647,6 +647,14 @@
647
647
  "baseBorrowingFactorShort": "0x4385c8e191a978b34824ae41b408ba588e261054e5945d0e99068ad10b4905ed",
648
648
  "aboveOptimalUsageBorrowingFactorLong": "0x2914e46a2e627cc733a945a8eb44ab2ef758f9a6fc35821bec5e340d7e0239b4",
649
649
  "aboveOptimalUsageBorrowingFactorShort": "0xe09312ebfcc03606ed101a23c5fe2e9883e431d2787ba65c5a0ae9526b58ce1b"
650
+ },
651
+ "0x4D3Eb91efd36C2b74181F34B111bc1E91a0d0cb4": {
652
+ "optimalUsageFactorLong": "0x2e3f861626c4e7e577efc24e5c1bf68664f67cca423736be0c5cc5bfd2d51490",
653
+ "optimalUsageFactorShort": "0x6140b20bd94e328307faca8fbb6fcead2c2104a2ef78c533383f36379298cbd2",
654
+ "baseBorrowingFactorLong": "0xb1a5d5b89f2457ae28d85c819b41f35391063c1f32c19406bf0d5f3697d44af7",
655
+ "baseBorrowingFactorShort": "0x6b2efc5c2a51a2cb3b50b9a474a578272ceac9dacd7f8a495246541658b004c4",
656
+ "aboveOptimalUsageBorrowingFactorLong": "0x0364a6542f02b0cf5de96a3f0a0566ee9ac777fdac6302691a0b1296c29edca6",
657
+ "aboveOptimalUsageBorrowingFactorShort": "0x825303f6ce78aa93bacadc5a8603f840a7e0f0bfdd480164fd9b0f3dfefaf00e"
650
658
  }
651
659
  },
652
660
  "43113": {
@@ -4049,6 +4049,56 @@
4049
4049
  "virtualMarketId": "0x9bfab2b19467f690a2c7d7a2ff79f023153dbf5544a93501c14c5936fcd75632",
4050
4050
  "virtualLongTokenId": "0xa59040b7efb6b7122a74cb318a192ebc6732849dff5332ee3ba40b90dfa0a04f",
4051
4051
  "virtualShortTokenId": "0xd5258cb84f0039be58306488e8df941c05f3cf4f219e92aacb6561c736bbb960"
4052
+ },
4053
+ "0x4D3Eb91efd36C2b74181F34B111bc1E91a0d0cb4": {
4054
+ "isDisabled": "0xe83e0ec1c1ac7b6988e49213d58bd11bbf6b5afd77c2181f70861e2d01a511d2",
4055
+ "maxLongPoolAmount": "0xa097b6493cd049189f95eb24b10ee6bba633ffc345ca5368f002508e0710de5c",
4056
+ "maxShortPoolAmount": "0x3a62c3ecc3bd77bc6ac9cd711f02b737a57957fd92f4ff4991e344a3cc2d9e90",
4057
+ "maxLongPoolUsdForDeposit": "0x5b8f631e61e2c150cbc7216f1294708b77f7ffb5ac0ddc77e49e39d90973cd04",
4058
+ "maxShortPoolUsdForDeposit": "0xcec2e1dfcff690b41a286cb908f8ec7e8d477eb0c5a4137df3ffa03d6b8bc1d0",
4059
+ "longPoolAmountAdjustment": "0x4828e328562b81a0de9c9c1643b8d78dc00b3f1aeebf9bc2ac063913b360869b",
4060
+ "shortPoolAmountAdjustment": "0xc59ca141127bbc1e0c05ca53f0a693b7753f2eb40e82e4a46091f5c6822ceabb",
4061
+ "reserveFactorLong": "0x04b4bf4124bc2c435a8322257b69201f3faca69b4b41528b66c3ece775ec7599",
4062
+ "reserveFactorShort": "0x3a6c9a54cb408352534a7cc18c5d7609255660fc230a8986f083a4aefd03e685",
4063
+ "openInterestReserveFactorLong": "0x1b0e072734b61aafae0aa4477d30d3142dff83557526128e52921aa980795fc7",
4064
+ "openInterestReserveFactorShort": "0x861a873250c1c87b0d3fcfe8a8bd868d5805edb4344b93c8b8c3c21d38a23f08",
4065
+ "maxOpenInterestLong": "0x36306db41065a9ff0b80796d65c397fdb82feb0478876df11243ce8441c80442",
4066
+ "maxOpenInterestShort": "0x0e76c80c44accb13dff368ae386a5f7ea4431453231552223b06d54e4436c2a9",
4067
+ "minPositionImpactPoolAmount": "0xf532ebf558f007c799e40efcf925d5c8b0a54d20fa5a5827b98651c8fbc0d6a1",
4068
+ "positionImpactPoolDistributionRate": "0xdfb096f793983ae1287c615cab10b12b9b78aac824cdf75f4555aaaa6c126c8b",
4069
+ "borrowingFactorLong": "0x6bcb1c43b78a3699cc620c81d1913eab8fa38bdbd0ab09f278b1ffa3cf3fdbf5",
4070
+ "borrowingFactorShort": "0x5c74aae37330a55a343662dfa6e90aa5eb8436337a24bc5ef6bdbb0184382746",
4071
+ "borrowingExponentFactorLong": "0x0ffd6ce396e5ecd7bf6eb7f72c1904098a749d5778697b228d864900c43a085d",
4072
+ "borrowingExponentFactorShort": "0x7a83fda1755ae48adc568c095c433b60a5fa8e185d2c0d048a7da5aa9c58fb37",
4073
+ "fundingFactor": "0x6553e6ae127cfe5faac7b998815419cd3ff538d7f5119095ba608c1e06fd3c48",
4074
+ "fundingExponentFactor": "0x4279f11a70c0e464b3f4ac316332f50c7c39433e7e8415f5d3507be3f9206254",
4075
+ "fundingIncreaseFactorPerSecond": "0x15baa5f7d714f06984bab3b1a6e277e6afb0a48bc6d111c4bdaaf481945d4b33",
4076
+ "fundingDecreaseFactorPerSecond": "0x255bb64b67c537678593fb60a785fff37eb4434e26dd8bf832dd2814733dda8b",
4077
+ "thresholdForStableFunding": "0x54dd03fb88b75dc954f40a355526e9c8482cc98fc0f3968474c014fe1facee40",
4078
+ "thresholdForDecreaseFunding": "0xfa037a22ec153bc6db4a99a10da601c82c9501e6df9e62291ba5564a97e5aa78",
4079
+ "minFundingFactorPerSecond": "0x19da90413997cebefe8f8ea7272d94f356a7b8a4e8c79c08ce1752e02fb1a5df",
4080
+ "maxFundingFactorPerSecond": "0x84b82ffe4834b4f94641d9a3e2a60fbc0ff1d7e4937d430ee80a014b13175f04",
4081
+ "maxPnlFactorForTradersLong": "0x5c42ebcdd5cc73bbf367156af70735b25897a6accb5699e2dd442a3e7aec32a8",
4082
+ "maxPnlFactorForTradersShort": "0x4845b537832a8b591e75676444faad0887e9747c7624c43298a64ef95d1c2d9a",
4083
+ "positionFeeFactorForPositiveImpact": "0x379014e598d8d0024d508ff729cf9a31eaa22b3554e89bce3ed00e48534e7c5e",
4084
+ "positionFeeFactorForNegativeImpact": "0x62a50f7f748ef2572aa3c3f6f486616ea33a0067bab4b7269610a1cacde6300e",
4085
+ "positionImpactFactorPositive": "0xf181edeb1432f629bf14e39df272865fcc52c85bc89c06fe329eead795328349",
4086
+ "positionImpactFactorNegative": "0xb409ce5f332ad37f5a8f1dd25badc32e20e7526c80ac6cba8faa43afd32f748f",
4087
+ "maxPositionImpactFactorPositive": "0x9acf59a110f586200c0fc1906a2b18a23d3033df529808b6dcf746e8a235e46c",
4088
+ "maxPositionImpactFactorNegative": "0xcf04d976c885aa14b78007f6e63a843f74393edd54f99f8d0c8f9878a33f87aa",
4089
+ "maxPositionImpactFactorForLiquidations": "0x78534eabae34614434e9cbca171a7f3521bb40e26621d621fe9f1280a9eeea7a",
4090
+ "minCollateralFactor": "0x9286a24a3b626cd4b440c9ebc31ce5a5b709c22f2f4acc917c3135cac6b26ef6",
4091
+ "minCollateralFactorForOpenInterestLong": "0x8c69704d7ad8d47b8fc79dd9f203c622ac43de9aaa60e25de14b70468e2d9b25",
4092
+ "minCollateralFactorForOpenInterestShort": "0xfb46f190074aa0025c421e05d226229b80b32da2a638dc566c0ee9b31a62b25e",
4093
+ "positionImpactExponentFactor": "0xfa76ae24b59f8ccb8233c444e1d247e8e7dd78cdb2a7e1ba29dfbb782c4d00da",
4094
+ "swapFeeFactorForPositiveImpact": "0x9108de9102344a53cfaba2ef2d276e027bb6b4051c3e818d7ecbddfc291f9e1f",
4095
+ "swapFeeFactorForNegativeImpact": "0xac6ef53ecc38b138b10d39e00eeabffd9e05f54cc9903fe59702b86960bef8c5",
4096
+ "swapImpactFactorPositive": "0xd6c74362814ea6fd65d9379cfd8fe06f850ac287b75940fd77e0bdc45264edcf",
4097
+ "swapImpactFactorNegative": "0x1db488bdc1bc0726b938a5242b366c388f4ee2152ebfa088e8e35bec3646688d",
4098
+ "swapImpactExponentFactor": "0xcc4807baa2417c31f1cb6b99b84cfa7be11077af4704aa12415f80c2ee7c50b8",
4099
+ "virtualMarketId": "0x646b9cbcf92ff6e208db3b2e7267e1a70f08248b5233dca10c246d857ca6be9f",
4100
+ "virtualLongTokenId": "0xaab37f889b9680dda34f58a689de3023cb22f7ae14d32a3c1d45798a973db1f5",
4101
+ "virtualShortTokenId": "0xd5258cb84f0039be58306488e8df941c05f3cf4f219e92aacb6561c736bbb960"
4052
4102
  }
4053
4103
  },
4054
4104
  "43113": {
@@ -1214,6 +1214,21 @@
1214
1214
  "longInterestInTokensUsingShortToken": "0x6f542fdc6addee4e75891c4bfb8860c6232b10e35d2cf34d56a31f6e37a073a4",
1215
1215
  "shortInterestInTokensUsingLongToken": "0xbe1d49d8de9f15dd608c0ec6671808b8204838b14e8d31769b30489ee71e6e8e",
1216
1216
  "shortInterestInTokensUsingShortToken": "0xb19e3d111bcebca624cd2077e9c21d2f53f98e22648b3625c51cdcaf1ca09ddd"
1217
+ },
1218
+ "0x4D3Eb91efd36C2b74181F34B111bc1E91a0d0cb4": {
1219
+ "longPoolAmount": "0xcfdeeee75cef8de81f3e98bc2ee46390b1ebb489016a64e945f8df208913cd15",
1220
+ "shortPoolAmount": "0x819197d0e2f89533aaf9f8f682459b4a9632d54904ec9e5a550c76963ae99f8b",
1221
+ "positionImpactPoolAmount": "0x744ca86ca9666aad1339f04e710e921b3d1ebc7c56ed244640e5088fa98d6757",
1222
+ "swapImpactPoolAmountLong": "0x762b06f45ebc57521994d8ebf527c46abf5058816c792501f0bf625506e82d35",
1223
+ "swapImpactPoolAmountShort": "0x58950f4dfb0a69cfd67091901b12864103bb9cad22c497d86b4d4d258cf85687",
1224
+ "longInterestUsingLongToken": "0xa31015cdcb4172aaed407c2d933b627f7a8e46999aa67ae98973a8fe9b8c6a15",
1225
+ "longInterestUsingShortToken": "0x139a84e762d9799d19c51f6fb7241c93ea222cd11cfe52aae1306d8825cc6e42",
1226
+ "shortInterestUsingLongToken": "0x3d6d99fcb9adf2d5dcfe04612a0c670605275b61a237d5a077d2eb3044ad8f6a",
1227
+ "shortInterestUsingShortToken": "0xe0e0724df520d9ed9306b7611305b3d4ee8a7b7c48296c8a1bb7df9ad33a4807",
1228
+ "longInterestInTokensUsingLongToken": "0xe992d65208bb38ea6097352425d679b71a75429322dc6b4c872c9451cadd26a6",
1229
+ "longInterestInTokensUsingShortToken": "0xdf1bda8a83a0560547c25e3e4ca770baecbd6a61efb81b6d5e8e4e912f054329",
1230
+ "shortInterestInTokensUsingLongToken": "0x0d9c0848acc691d704ebb980a19c1661d77056a084d0147232952666d6d7780c",
1231
+ "shortInterestInTokensUsingShortToken": "0x41d05cc1bd601fe40bf8e5a838e9e832eb3bd6d9a56dabcf470e99d5e52c3de9"
1217
1232
  }
1218
1233
  },
1219
1234
  "43113": {
@@ -94,7 +94,6 @@ describe("buildFiltersBody", () => {
94
94
  foo: "bar",
95
95
  },
96
96
  ],
97
- // @ts-expect-error
98
97
  baz: "qux",
99
98
  };
100
99
  const getResult = () => buildFiltersBody(input);
@@ -107,7 +106,6 @@ describe("buildFiltersBody", () => {
107
106
  foo: "bar",
108
107
  },
109
108
  ],
110
- // @ts-expect-error
111
109
  baz: "qux",
112
110
  };
113
111
  const getResult = () => buildFiltersBody(input);
@@ -116,7 +114,6 @@ describe("buildFiltersBody", () => {
116
114
  it("should throw not error if empty or is mixed with other filters", () => {
117
115
  const input = {
118
116
  or: [],
119
- // @ts-expect-error
120
117
  baz: "qux",
121
118
  };
122
119
  const getResult = () => buildFiltersBody(input);
@@ -125,7 +122,6 @@ describe("buildFiltersBody", () => {
125
122
  it("should throw not error if empty and is mixed with other filters", () => {
126
123
  const input = {
127
124
  and: [],
128
- // @ts-expect-error
129
125
  baz: "qux",
130
126
  };
131
127
  const getResult = () => buildFiltersBody(input);
@@ -1,8 +1,8 @@
1
- import { bigNumberify } from "../../modules/trades/trades";
2
1
  import { bigMath } from "../bigmath";
3
2
  import { getTokenPoolType } from "../markets";
4
3
  import { applyFactor, expandDecimals, getBasisPoints, roundUpMagnitudeDivision } from "../numbers";
5
4
  import { convertToTokenAmount, convertToUsd, getMidPrice } from "../tokens";
5
+ import { bigNumberify } from "../tradeHistory";
6
6
  export function getPriceImpactByAcceptablePrice(p) {
7
7
  const { sizeDeltaUsd, acceptablePrice, indexPrice: markPrice, isLong, isIncrease } = p;
8
8
  const shouldFlipPriceDiff = isIncrease ? !isLong : isLong;
@@ -1,4 +1,4 @@
1
- export function buildFiltersBody(filters) {
1
+ export function buildFiltersBody(filters, options) {
2
2
  const res = {};
3
3
  let hadOr = false;
4
4
  let hadAnd = false;
@@ -7,7 +7,12 @@ export function buildFiltersBody(filters) {
7
7
  continue;
8
8
  }
9
9
  if (typeof value === "string") {
10
- res[key] = `"${value}"`;
10
+ if (options?.enums?.[value]) {
11
+ res[key] = value;
12
+ }
13
+ else {
14
+ res[key] = `"${value}"`;
15
+ }
11
16
  }
12
17
  else if (typeof value === "number") {
13
18
  res[key] = `${value}`;
@@ -20,13 +25,18 @@ export function buildFiltersBody(filters) {
20
25
  value
21
26
  .map((el) => {
22
27
  if (typeof el === "string") {
23
- return `"${el}"`;
28
+ if (options?.enums?.[el]) {
29
+ return el;
30
+ }
31
+ else {
32
+ return `"${el}"`;
33
+ }
24
34
  }
25
35
  else if (typeof el === "number") {
26
36
  return `${el}`;
27
37
  }
28
38
  else {
29
- const elemStr = buildFiltersBody(el);
39
+ const elemStr = buildFiltersBody(el, options);
30
40
  if (elemStr === "{}") {
31
41
  return "";
32
42
  }
@@ -46,9 +56,9 @@ export function buildFiltersBody(filters) {
46
56
  res[key] = null;
47
57
  }
48
58
  else {
49
- const valueStr = buildFiltersBody(value);
59
+ const valueStr = buildFiltersBody(value, options);
50
60
  if (valueStr !== "{}") {
51
- res[key + "_"] = buildFiltersBody(value);
61
+ res[key + "_"] = buildFiltersBody(value, options);
52
62
  }
53
63
  }
54
64
  if (hadOr) {
@@ -14,7 +14,6 @@ export const arbitrumSdkConfig = {
14
14
  oracleUrl: "https://arbitrum-api.gmxinfra.io",
15
15
  rpcUrl: "https://arb1.arbitrum.io/rpc",
16
16
  walletClient: client,
17
- subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:live/api/graphql",
18
- subgraphUrl: "https://subgraph.satsuma-prod.com/3b2ced13c8d9/gmx/synthetics-arbitrum-stats/api",
17
+ subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum@e27d93/api/graphql",
19
18
  };
20
19
  export const arbitrumSdk = new GmxSdk(arbitrumSdkConfig);
@@ -0,0 +1,132 @@
1
+ import { getAddress } from "viem";
2
+ import { getByKey } from "./objects";
3
+ import { isIncreaseOrderType, isSwapOrderType } from "./orders";
4
+ import { getSwapPathOutputAddresses } from "./swap/swapStats";
5
+ import { parseContractPrice } from "./tokens";
6
+ export function createRawTradeActionTransformer(marketsInfoData, wrappedToken, tokensData) {
7
+ return (rawAction) => {
8
+ const orderType = Number(rawAction.orderType);
9
+ if (isSwapOrderType(orderType)) {
10
+ const initialCollateralTokenAddress = getAddress(rawAction.initialCollateralTokenAddress);
11
+ const swapPath = rawAction.swapPath.map((address) => getAddress(address));
12
+ const swapPathOutputAddresses = getSwapPathOutputAddresses({
13
+ marketsInfoData,
14
+ swapPath,
15
+ initialCollateralAddress: initialCollateralTokenAddress,
16
+ wrappedNativeTokenAddress: wrappedToken.address,
17
+ shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
18
+ isIncrease: false,
19
+ });
20
+ const initialCollateralToken = getByKey(tokensData, initialCollateralTokenAddress);
21
+ const targetCollateralToken = getByKey(tokensData, swapPathOutputAddresses.outTokenAddress);
22
+ if (!initialCollateralToken || !targetCollateralToken) {
23
+ return undefined;
24
+ }
25
+ const tradeAction = {
26
+ id: rawAction.id,
27
+ eventName: rawAction.eventName,
28
+ account: rawAction.account,
29
+ swapPath,
30
+ orderType,
31
+ orderKey: rawAction.orderKey,
32
+ initialCollateralTokenAddress: rawAction.initialCollateralTokenAddress,
33
+ initialCollateralDeltaAmount: bigNumberify(rawAction.initialCollateralDeltaAmount),
34
+ minOutputAmount: bigNumberify(rawAction.minOutputAmount),
35
+ executionAmountOut: rawAction.executionAmountOut ? bigNumberify(rawAction.executionAmountOut) : undefined,
36
+ shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
37
+ targetCollateralToken,
38
+ initialCollateralToken,
39
+ timestamp: rawAction.timestamp,
40
+ transaction: rawAction.transaction,
41
+ reason: rawAction.reason,
42
+ reasonBytes: rawAction.reasonBytes,
43
+ };
44
+ return tradeAction;
45
+ }
46
+ else {
47
+ const marketAddress = getAddress(rawAction.marketAddress);
48
+ const marketInfo = getByKey(marketsInfoData, marketAddress);
49
+ const indexToken = marketInfo?.indexToken;
50
+ const initialCollateralTokenAddress = getAddress(rawAction.initialCollateralTokenAddress);
51
+ const swapPath = rawAction.swapPath.map((address) => getAddress(address));
52
+ const swapPathOutputAddresses = getSwapPathOutputAddresses({
53
+ marketsInfoData,
54
+ swapPath,
55
+ initialCollateralAddress: initialCollateralTokenAddress,
56
+ wrappedNativeTokenAddress: wrappedToken.address,
57
+ shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
58
+ isIncrease: isIncreaseOrderType(rawAction.orderType),
59
+ });
60
+ const initialCollateralToken = getByKey(tokensData, initialCollateralTokenAddress);
61
+ const targetCollateralToken = getByKey(tokensData, swapPathOutputAddresses.outTokenAddress);
62
+ if (!marketInfo || !indexToken || !initialCollateralToken || !targetCollateralToken) {
63
+ return undefined;
64
+ }
65
+ const tradeAction = {
66
+ id: rawAction.id,
67
+ eventName: rawAction.eventName,
68
+ account: rawAction.account,
69
+ marketAddress,
70
+ marketInfo,
71
+ indexToken,
72
+ swapPath,
73
+ initialCollateralTokenAddress,
74
+ initialCollateralToken,
75
+ targetCollateralToken,
76
+ initialCollateralDeltaAmount: bigNumberify(rawAction.initialCollateralDeltaAmount),
77
+ sizeDeltaUsd: bigNumberify(rawAction.sizeDeltaUsd),
78
+ triggerPrice: rawAction.triggerPrice
79
+ ? parseContractPrice(bigNumberify(rawAction.triggerPrice), indexToken.decimals)
80
+ : undefined,
81
+ acceptablePrice: parseContractPrice(bigNumberify(rawAction.acceptablePrice), indexToken.decimals),
82
+ executionPrice: rawAction.executionPrice
83
+ ? parseContractPrice(bigNumberify(rawAction.executionPrice), indexToken.decimals)
84
+ : undefined,
85
+ minOutputAmount: bigNumberify(rawAction.minOutputAmount),
86
+ collateralTokenPriceMax: rawAction.collateralTokenPriceMax
87
+ ? parseContractPrice(bigNumberify(rawAction.collateralTokenPriceMax), initialCollateralToken.decimals)
88
+ : undefined,
89
+ collateralTokenPriceMin: rawAction.collateralTokenPriceMin
90
+ ? parseContractPrice(bigNumberify(rawAction.collateralTokenPriceMin), initialCollateralToken.decimals)
91
+ : undefined,
92
+ indexTokenPriceMin: rawAction.indexTokenPriceMin
93
+ ? parseContractPrice(BigInt(rawAction.indexTokenPriceMin), indexToken.decimals)
94
+ : undefined,
95
+ indexTokenPriceMax: rawAction.indexTokenPriceMax
96
+ ? parseContractPrice(BigInt(rawAction.indexTokenPriceMax), indexToken.decimals)
97
+ : undefined,
98
+ orderType,
99
+ orderKey: rawAction.orderKey,
100
+ isLong: rawAction.isLong,
101
+ pnlUsd: rawAction.pnlUsd ? BigInt(rawAction.pnlUsd) : undefined,
102
+ basePnlUsd: rawAction.basePnlUsd ? BigInt(rawAction.basePnlUsd) : undefined,
103
+ priceImpactDiffUsd: rawAction.priceImpactDiffUsd ? BigInt(rawAction.priceImpactDiffUsd) : undefined,
104
+ priceImpactUsd: rawAction.priceImpactUsd ? BigInt(rawAction.priceImpactUsd) : undefined,
105
+ positionFeeAmount: rawAction.positionFeeAmount ? BigInt(rawAction.positionFeeAmount) : undefined,
106
+ borrowingFeeAmount: rawAction.borrowingFeeAmount ? BigInt(rawAction.borrowingFeeAmount) : undefined,
107
+ fundingFeeAmount: rawAction.fundingFeeAmount ? BigInt(rawAction.fundingFeeAmount) : undefined,
108
+ liquidationFeeAmount: rawAction.liquidationFeeAmount ? BigInt(rawAction.liquidationFeeAmount) : undefined,
109
+ reason: rawAction.reason,
110
+ reasonBytes: rawAction.reasonBytes,
111
+ transaction: rawAction.transaction,
112
+ timestamp: rawAction.timestamp,
113
+ shouldUnwrapNativeToken: rawAction.shouldUnwrapNativeToken,
114
+ };
115
+ return tradeAction;
116
+ }
117
+ };
118
+ }
119
+ export function bigNumberify(n) {
120
+ try {
121
+ if (n === undefined)
122
+ throw new Error("n is undefined");
123
+ if (n === null)
124
+ throw new Error("n is null");
125
+ return BigInt(n);
126
+ }
127
+ catch (e) {
128
+ // eslint-disable-next-line no-console
129
+ console.error("bigNumberify error", e);
130
+ return undefined;
131
+ }
132
+ }