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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/build/cjs/scripts/generate-platform-tokens.js +200 -0
  2. package/build/cjs/scripts/subsquid-codegen.js +1 -1
  3. package/build/cjs/src/clients/v1/modules/accounts/accounts.js +1 -1
  4. package/build/cjs/src/clients/v1/modules/markets/index.js +1 -1
  5. package/build/cjs/src/clients/v1/modules/markets/markets.spec.js +2 -2
  6. package/build/cjs/src/clients/v1/modules/orders/orders.js +4 -4
  7. package/build/cjs/src/clients/v1/modules/positions/positions.js +9 -151
  8. package/build/cjs/src/clients/v1/modules/tokens/tokens.js +1 -1
  9. package/build/cjs/src/clients/v1/modules/tokens/tokens.spec.js +2 -2
  10. package/build/cjs/src/clients/v1/modules/trades/trades.js +1 -1
  11. package/build/cjs/src/clients/v1/modules/utils/utils.js +1 -1
  12. package/build/cjs/src/clients/v2/index.js +13 -1
  13. package/build/cjs/src/codegen/platformTokens.json +134 -0
  14. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
  15. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +171 -0
  16. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +45 -0
  17. package/build/cjs/src/codegen/subsquid.js +142 -22
  18. package/build/cjs/src/configs/api.js +10 -6
  19. package/build/cjs/src/configs/markets.js +21 -0
  20. package/build/cjs/src/configs/tokens.js +35 -0
  21. package/build/cjs/src/utils/__tests__/fees.spec.js +1 -1
  22. package/build/cjs/src/utils/__tests__/numbers.spec.js +1 -1
  23. package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
  24. package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
  25. package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
  26. package/build/cjs/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
  27. package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
  28. package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
  29. package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
  30. package/build/cjs/src/utils/__tests__/parseError.spec.js +40 -0
  31. package/build/cjs/src/utils/__tests__/positions.spec.js +1 -1
  32. package/build/cjs/src/utils/__tests__/prices.spec.js +1 -1
  33. package/build/cjs/src/utils/__tests__/tokens.spec.js +191 -4
  34. package/build/cjs/src/utils/errors/parseError.js +67 -25
  35. package/build/cjs/src/utils/fees/executionFee.js +1 -1
  36. package/build/cjs/src/utils/fees/priceImpact.js +6 -1
  37. package/build/cjs/src/utils/markets/__tests__/mockMarkets.js +1 -1
  38. package/build/cjs/src/utils/markets/utils.js +15 -4
  39. package/build/cjs/src/utils/numbers/utils.js +4 -2
  40. package/build/cjs/src/utils/orders/api.js +13 -0
  41. package/build/cjs/src/utils/orders/index.js +1 -0
  42. package/build/cjs/src/utils/orders/utils.js +2 -2
  43. package/build/cjs/src/utils/positions/api.js +14 -0
  44. package/build/cjs/src/utils/positions/index.js +1 -0
  45. package/build/cjs/src/utils/positions/utils.js +213 -1
  46. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +1 -1
  47. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  48. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +1 -1
  49. package/build/cjs/src/utils/swap/buildSwapStrategy.js +1 -1
  50. package/build/cjs/src/utils/swap/externalSwapQuoteByPath.js +1 -1
  51. package/build/cjs/src/utils/swap/swapPath.js +1 -1
  52. package/build/cjs/src/utils/swap/swapValues.js +1 -1
  53. package/build/cjs/src/utils/tokens/utils.js +23 -3
  54. package/build/cjs/src/utils/trade/decrease.js +1 -1
  55. package/build/cjs/src/utils/trade/increase.js +1 -1
  56. package/build/cjs/src/utils/trade/trade.js +1 -1
  57. package/build/esm/scripts/generate-platform-tokens.js +195 -0
  58. package/build/esm/scripts/subsquid-codegen.js +1 -1
  59. package/build/esm/src/clients/v1/modules/accounts/accounts.js +1 -1
  60. package/build/esm/src/clients/v1/modules/markets/index.js +1 -1
  61. package/build/esm/src/clients/v1/modules/markets/markets.spec.js +1 -1
  62. package/build/esm/src/clients/v1/modules/orders/orders.js +4 -4
  63. package/build/esm/src/clients/v1/modules/positions/positions.js +12 -154
  64. package/build/esm/src/clients/v1/modules/tokens/tokens.js +1 -1
  65. package/build/esm/src/clients/v1/modules/tokens/tokens.spec.js +1 -1
  66. package/build/esm/src/clients/v1/modules/trades/trades.js +1 -1
  67. package/build/esm/src/clients/v1/modules/utils/utils.js +1 -1
  68. package/build/esm/src/clients/v2/index.js +13 -1
  69. package/build/esm/src/codegen/platformTokens.json +134 -0
  70. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +24 -0
  71. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +171 -0
  72. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +45 -0
  73. package/build/esm/src/codegen/subsquid.js +141 -21
  74. package/build/esm/src/configs/api.js +8 -5
  75. package/build/esm/src/configs/markets.js +21 -0
  76. package/build/esm/src/configs/tokens.js +35 -0
  77. package/build/esm/src/utils/__tests__/fees.spec.js +1 -1
  78. package/build/esm/src/utils/__tests__/numbers.spec.js +1 -1
  79. package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +1 -1
  80. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +1 -1
  81. package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +1 -1
  82. package/build/esm/src/utils/__tests__/orderTransactions/externalCalls.spec.js +1 -1
  83. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +1 -1
  84. package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -1
  85. package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +1 -1
  86. package/build/esm/src/utils/__tests__/parseError.spec.js +40 -0
  87. package/build/esm/src/utils/__tests__/positions.spec.js +1 -1
  88. package/build/esm/src/utils/__tests__/prices.spec.js +1 -1
  89. package/build/esm/src/utils/__tests__/tokens.spec.js +192 -5
  90. package/build/esm/src/utils/errors/parseError.js +64 -24
  91. package/build/esm/src/utils/fees/executionFee.js +1 -1
  92. package/build/esm/src/utils/fees/priceImpact.js +5 -1
  93. package/build/esm/src/utils/markets/__tests__/mockMarkets.js +1 -1
  94. package/build/esm/src/utils/markets/utils.js +15 -4
  95. package/build/esm/src/utils/numbers/utils.js +2 -0
  96. package/build/esm/src/utils/orders/api.js +9 -0
  97. package/build/esm/src/utils/orders/index.js +1 -0
  98. package/build/esm/src/utils/orders/utils.js +2 -2
  99. package/build/esm/src/utils/positions/api.js +10 -0
  100. package/build/esm/src/utils/positions/index.js +1 -0
  101. package/build/esm/src/utils/positions/utils.js +213 -3
  102. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +1 -1
  103. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +1 -1
  104. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +1 -1
  105. package/build/esm/src/utils/swap/buildSwapStrategy.js +1 -1
  106. package/build/esm/src/utils/swap/externalSwapQuoteByPath.js +1 -1
  107. package/build/esm/src/utils/swap/swapPath.js +1 -1
  108. package/build/esm/src/utils/swap/swapValues.js +1 -1
  109. package/build/esm/src/utils/tokens/utils.js +23 -3
  110. package/build/esm/src/utils/trade/decrease.js +1 -1
  111. package/build/esm/src/utils/trade/increase.js +1 -1
  112. package/build/esm/src/utils/trade/trade.js +1 -1
  113. package/build/types/scripts/generate-platform-tokens.d.ts +27 -0
  114. package/build/types/src/clients/v1/modules/markets/index.d.ts +1 -1
  115. package/build/types/src/clients/v1/modules/oracle.d.ts +1 -1
  116. package/build/types/src/clients/v1/modules/orders/helpers.d.ts +1 -1
  117. package/build/types/src/clients/v1/modules/orders/orders.d.ts +2 -2
  118. package/build/types/src/clients/v1/modules/orders/transactions/cancelOrdersTxn.d.ts +1 -1
  119. package/build/types/src/clients/v1/modules/orders/transactions/createDecreaseOrderTxn.d.ts +1 -1
  120. package/build/types/src/clients/v1/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -1
  121. package/build/types/src/clients/v1/modules/orders/transactions/createSwapOrderTxn.d.ts +1 -1
  122. package/build/types/src/clients/v1/modules/orders/transactions/createWrapOrUnwrapTxn.d.ts +1 -1
  123. package/build/types/src/clients/v1/modules/orders/transactions/updateOrderTxn.d.ts +1 -1
  124. package/build/types/src/clients/v1/modules/orders/utils.d.ts +2 -2
  125. package/build/types/src/clients/v1/modules/positions/positions.d.ts +1 -1
  126. package/build/types/src/clients/v1/modules/tokens/tokens.d.ts +1 -1
  127. package/build/types/src/clients/v1/modules/trades/trades.d.ts +2 -2
  128. package/build/types/src/clients/v1/modules/utils/utils.d.ts +1 -1
  129. package/build/types/src/clients/v2/index.d.ts +7 -0
  130. package/build/types/src/codegen/prebuilt/index.d.ts +240 -0
  131. package/build/types/src/codegen/subsquid.d.ts +492 -60
  132. package/build/types/src/configs/api.d.ts +1 -0
  133. package/build/types/src/utils/errors/parseError.d.ts +13 -1
  134. package/build/types/src/utils/fees/executionFee.d.ts +1 -1
  135. package/build/types/src/utils/fees/getNaiveEstimatedGasBySwapCount.d.ts +1 -1
  136. package/build/types/src/utils/fees/index.d.ts +1 -1
  137. package/build/types/src/utils/fees/priceImpact.d.ts +1 -0
  138. package/build/types/src/utils/markets/api.d.ts +1 -1
  139. package/build/types/src/utils/markets/multicall.d.ts +1 -1
  140. package/build/types/src/utils/markets/types.d.ts +8 -2
  141. package/build/types/src/utils/markets/utils.d.ts +1 -1
  142. package/build/types/src/utils/numbers/utils.d.ts +2 -0
  143. package/build/types/src/utils/orders/api.d.ts +7 -0
  144. package/build/types/src/utils/orders/index.d.ts +1 -0
  145. package/build/types/src/utils/orders/types.d.ts +27 -0
  146. package/build/types/src/utils/orders/utils.d.ts +1 -1
  147. package/build/types/src/utils/positions/api.d.ts +8 -0
  148. package/build/types/src/utils/positions/index.d.ts +1 -0
  149. package/build/types/src/utils/positions/types.d.ts +5 -16
  150. package/build/types/src/utils/positions/utils.d.ts +42 -1
  151. package/build/types/src/utils/swap/buildSwapStrategy.d.ts +1 -1
  152. package/build/types/src/utils/swap/findSwapPathsBetweenTokens.d.ts +1 -1
  153. package/build/types/src/utils/swap/preparedSwapData.d.ts +1 -1
  154. package/build/types/src/utils/swap/swapRouting.d.ts +1 -1
  155. package/build/types/src/utils/tokens/types.d.ts +1 -1
  156. package/build/types/src/utils/trade/decrease.d.ts +1 -1
  157. package/build/types/src/utils/trade/increase.d.ts +1 -1
  158. package/build/types/src/utils/trade/trade.d.ts +1 -1
  159. package/build/types/src/utils/tradeHistory/types.d.ts +2 -2
  160. package/build/types/src/utils/tradeHistory/utils.d.ts +1 -1
  161. package/build/types/src/utils/twap/index.d.ts +1 -1
  162. package/package.json +4 -3
@@ -1 +1,2 @@
1
1
  export declare function getApiUrl(chainId: number): any;
2
+ export declare function isApiSupported(chainId: number): boolean;
@@ -1,4 +1,7 @@
1
+ import { AbiParameterToPrimitiveType, ContractErrorName, ExtractAbiItem } from "viem";
2
+ import { abis } from "../../abis";
1
3
  import { CustomErrorName, TxErrorType } from "./transactionsErrors";
4
+ export declare function extractErrorDataFromViemError(error: any): string | undefined;
2
5
  export type OrderErrorContext = "simulation" | "gasLimit" | "gasPrice" | "bestNonce" | "sending" | "pending" | "relayer" | "minting" | "execution" | "unknown";
3
6
  export type ErrorLike = {
4
7
  message?: string;
@@ -58,4 +61,13 @@ export declare class CustomError extends Error {
58
61
  });
59
62
  }
60
63
  export declare function isCustomError(error: Error | undefined): error is CustomError;
61
- export declare function getCustomError(error: Error): CustomError | Error;
64
+ export type ParsedCustomError = {
65
+ name: string;
66
+ args?: {
67
+ [key in ExtractAbiItem<typeof abis.CustomErrors, ContractErrorName<typeof abis.CustomErrors>>["inputs"][number]["name"]]: AbiParameterToPrimitiveType<Extract<ExtractAbiItem<typeof abis.CustomErrors, ContractErrorName<typeof abis.CustomErrors>>["inputs"][number], {
68
+ name: key;
69
+ }>, "inputs">;
70
+ };
71
+ };
72
+ export declare function tryDecodeCustomError(reasonBytes: string): ParsedCustomError | undefined;
73
+ export declare function decodeErrorFromViemError(error: any): ParsedCustomError | undefined;
@@ -1,5 +1,5 @@
1
1
  import { ContractsChainId } from "../../configs/chains";
2
- import { ExecutionFee, GasLimitsConfig, L1ExpressOrderGasReference } from "../fees/types";
2
+ import { ExecutionFee, GasLimitsConfig, L1ExpressOrderGasReference } from "./types";
3
3
  import { DecreasePositionSwapType } from "../orders/types";
4
4
  import { TokenData, TokensData } from "../tokens/types";
5
5
  export declare function getExecutionFee(chainId: number, gasLimits: GasLimitsConfig, tokensData: TokensData, estimatedGasLimit: bigint, gasPrice: bigint, oraclePriceCount: bigint, numberOfParts?: number): ExecutionFee | undefined;
@@ -1,2 +1,2 @@
1
- import type { GasLimitsConfig } from "../fees/types";
1
+ import type { GasLimitsConfig } from "./types";
2
2
  export declare function getNaiveEstimatedGasBySwapCount(singleSwap: GasLimitsConfig["singleSwap"], swapsCount: number): bigint;
@@ -1,7 +1,7 @@
1
- import { FeeItem } from "./types";
2
1
  import { MarketInfo } from "../markets/types";
3
2
  import { SwapPricingType } from "../orders/types";
4
3
  import { SwapStats } from "../trade/types";
4
+ import { FeeItem } from "./types";
5
5
  export * from "./types";
6
6
  export * from "./estimateOraclePriceCount";
7
7
  export * from "./executionFee";
@@ -107,3 +107,4 @@ export declare function getCappedPriceImpactPercentageFromFees({ fees, isSwap, }
107
107
  fees: TradeFees | undefined;
108
108
  isSwap: boolean;
109
109
  }): bigint | undefined;
110
+ export declare function getMaxNegativeImpactBps(marketInfo: MarketInfo): bigint;
@@ -1,6 +1,6 @@
1
1
  import { IHttp } from "../http/types";
2
- import { RawMarketInfo } from "./types";
3
2
  import { TokenData } from "../tokens/types";
3
+ import { RawMarketInfo } from "./types";
4
4
  export declare function fetchApiMarketsInfo(ctx: {
5
5
  api: IHttp;
6
6
  }): Promise<RawMarketInfo[]>;
@@ -1,7 +1,7 @@
1
1
  import type { ContractCallsConfig } from "../../clients/v1/multicall";
2
2
  import { ContractsChainId } from "../../configs/chains";
3
- import type { MarketConfig, MarketValues, MarketsData } from "./types";
4
3
  import type { TokensData } from "../tokens/types";
4
+ import type { MarketConfig, MarketValues, MarketsData } from "./types";
5
5
  type MulticallResponse = {
6
6
  data: Record<string, any>;
7
7
  errors: Record<string, any>;
@@ -169,6 +169,8 @@ export type ClaimableFundingData = {
169
169
  export type MarketTicker = {
170
170
  symbol: string;
171
171
  marketTokenAddress: string;
172
+ minPrice: bigint;
173
+ maxPrice: bigint;
172
174
  markPrice: bigint;
173
175
  high24h: bigint;
174
176
  low24h: bigint;
@@ -176,8 +178,12 @@ export type MarketTicker = {
176
178
  close24h: bigint;
177
179
  priceChange24h: bigint;
178
180
  priceChangePercent24hBps: bigint;
179
- openInterestLong: bigint;
180
- openInterestShort: bigint;
181
+ longInterestInTokens: bigint;
182
+ shortInterestInTokens: bigint;
183
+ longInterestUsd: bigint;
184
+ shortInterestUsd: bigint;
185
+ longInterestUsdMark: bigint;
186
+ shortInterestUsdMark: bigint;
181
187
  availableLiquidityLong: bigint;
182
188
  availableLiquidityShort: bigint;
183
189
  poolAmountLongUsd: bigint;
@@ -1,8 +1,8 @@
1
1
  import type { ContractsChainId } from "../../configs/chains";
2
2
  import type { MarketConfig as ConfigMarketConfig } from "../../configs/markets";
3
- import type { ClaimableFundingData, ContractMarketPrices, Market, MarketConfig, MarketInfo, MarketsData, MarketsInfoData, MarketTicker, MarketValues, MarketWithTiers, RawMarketInfo, RawMarketsInfoData } from "./types";
4
3
  import type { DayPriceCandle } from "../24h/types";
5
4
  import type { Token, TokenPrices, TokensData } from "../tokens/types";
5
+ import type { ClaimableFundingData, ContractMarketPrices, Market, MarketConfig, MarketInfo, MarketsData, MarketsInfoData, MarketTicker, MarketValues, MarketWithTiers, RawMarketInfo, RawMarketsInfoData } from "./types";
6
6
  export declare function getMarketFullName(p: {
7
7
  longToken: Token;
8
8
  shortToken: Token;
@@ -6,6 +6,8 @@ export declare const BASIS_POINTS_DIVISOR_BIGINT = 10000n;
6
6
  export declare const BASIS_POINTS_DECIMALS = 4;
7
7
  export declare const PRECISION_DECIMALS = 30;
8
8
  export declare const PRECISION: bigint;
9
+ export declare const FLOAT_PRECISION_SQRT_DECIMALS = 15;
10
+ export declare const FLOAT_PRECISION_SQRT: bigint;
9
11
  export declare const BN_ZERO = 0n;
10
12
  export declare const BN_ONE = 1n;
11
13
  export declare const BN_NEGATIVE_ONE = -1n;
@@ -0,0 +1,7 @@
1
+ import { IHttp } from "../http/types";
2
+ import { ApiOrderInfo } from "./types";
3
+ export declare function fetchApiOrders(ctx: {
4
+ api: IHttp;
5
+ }, params: {
6
+ account: string;
7
+ }): Promise<ApiOrderInfo[]>;
@@ -1,2 +1,3 @@
1
+ export * from "./api";
1
2
  export * from "./types";
2
3
  export * from "./utils";
@@ -104,4 +104,31 @@ type TwapOrderParams<T extends SingleOrderParams = SingleOrderParams> = {
104
104
  numberOfParts: number;
105
105
  };
106
106
  export type OrderParams = SingleOrderParams | TwapOrderParams;
107
+ export type ApiOrderInfo = {
108
+ key: string;
109
+ account: string;
110
+ receiver: string;
111
+ cancellationReceiver: string;
112
+ callbackContract: string;
113
+ uiFeeReceiver: string;
114
+ marketAddress: string;
115
+ initialCollateralTokenAddress: string;
116
+ swapPath: string[];
117
+ orderType: number;
118
+ decreasePositionSwapType: number;
119
+ sizeDeltaUsd: bigint;
120
+ initialCollateralDeltaAmount: bigint;
121
+ triggerPrice: bigint;
122
+ acceptablePrice: bigint;
123
+ executionFee: bigint;
124
+ callbackGasLimit: bigint;
125
+ minOutputAmount: bigint;
126
+ updatedAtTime: bigint;
127
+ validFromTime: bigint;
128
+ srcChainId: bigint;
129
+ isLong: boolean;
130
+ shouldUnwrapNativeToken: boolean;
131
+ isFrozen: boolean;
132
+ autoCancel: boolean;
133
+ };
107
134
  export {};
@@ -1,6 +1,6 @@
1
1
  import { MarketsInfoData } from "../markets/types";
2
- import { Order, OrderInfo, OrderParams, OrderType, PositionOrderInfo, SwapOrderInfo, TwapOrderInfo } from "./types";
3
2
  import { Token, TokensData } from "../tokens/types";
3
+ import { Order, OrderInfo, OrderParams, OrderType, PositionOrderInfo, SwapOrderInfo, TwapOrderInfo } from "./types";
4
4
  export declare function isMarketOrderType(orderType: OrderType): boolean;
5
5
  export declare function isLimitOrderType(orderType: OrderType): boolean;
6
6
  export declare function isTriggerDecreaseOrderType(orderType: OrderType): boolean;
@@ -0,0 +1,8 @@
1
+ import { IHttp } from "../http/types";
2
+ import { ApiPositionInfo } from "./types";
3
+ export declare function fetchApiPositionsInfo(ctx: {
4
+ api: IHttp;
5
+ }, params: {
6
+ account: string;
7
+ includeRelatedOrders?: boolean;
8
+ }): Promise<ApiPositionInfo[]>;
@@ -1,2 +1,3 @@
1
+ export * from "./api";
1
2
  export * from "./types";
2
3
  export * from "./utils";
@@ -1,4 +1,5 @@
1
1
  import type { Market, MarketInfo } from "../markets/types";
2
+ import type { ApiOrderInfo } from "../orders/types";
2
3
  import type { TokenData } from "../tokens/types";
3
4
  export type Position = {
4
5
  key: string;
@@ -22,22 +23,6 @@ export type Position = {
22
23
  traderDiscountAmount: bigint;
23
24
  uiFeeAmount: bigint;
24
25
  pendingImpactAmount: bigint;
25
- /**
26
- * Not implemented in parsing
27
- */
28
- borrowingFactor?: bigint;
29
- /**
30
- * Not implemented in parsing
31
- */
32
- fundingFeeAmountPerSize?: bigint;
33
- /**
34
- * Not implemented in parsing
35
- */
36
- longTokenClaimableFundingAmountPerSize?: bigint;
37
- /**
38
- * Not implemented in parsing
39
- */
40
- shortTokenClaimableFundingAmountPerSize?: bigint;
41
26
  data: string;
42
27
  };
43
28
  export type PositionInfo = Position & {
@@ -77,9 +62,13 @@ export type PositionInfo = Position & {
77
62
  export type PositionInfoLoaded = PositionInfo & {
78
63
  marketInfo: MarketInfo;
79
64
  };
65
+ export type RawPositionInfo = Omit<PositionInfo, "marketInfo" | "market" | "indexToken" | "longToken" | "shortToken" | "collateralToken" | "pnlToken">;
80
66
  export type PositionsData = {
81
67
  [positionKey: string]: Position;
82
68
  };
83
69
  export type PositionsInfoData = {
84
70
  [positionKey: string]: PositionInfo;
85
71
  };
72
+ export type ApiPositionInfo = RawPositionInfo & {
73
+ relatedOrders?: ApiOrderInfo[];
74
+ };
@@ -1,7 +1,7 @@
1
1
  import { MarketInfo } from "../markets/types";
2
- import { PositionInfoLoaded } from "./types";
3
2
  import { UserReferralInfo } from "../referrals/types";
4
3
  import { Token, TokenData } from "../tokens/types";
4
+ import { Position, PositionInfo, PositionInfoLoaded } from "./types";
5
5
  export declare function getPositionKey(account: string, marketAddress: string, collateralAddress: string, isLong: boolean): string;
6
6
  export declare function parsePositionKey(positionKey: string): {
7
7
  account: string;
@@ -88,3 +88,44 @@ export declare function getPriceImpactDiffUsd({ totalImpactDeltaUsd, marketInfo,
88
88
  sizeDeltaUsd: bigint;
89
89
  }): bigint;
90
90
  export declare function getMinCollateralFactorForPosition(position: PositionInfoLoaded, openInterestDelta: bigint): bigint;
91
+ export declare function getContractPositionDynamicFees({ position, marketInfo, marketFeeState, referralInfo, }: {
92
+ position: {
93
+ sizeInUsd: bigint;
94
+ collateralTokenAddress: string;
95
+ isLong: boolean;
96
+ borrowingFactor: bigint;
97
+ fundingFeeAmountPerSize: bigint;
98
+ longTokenClaimableFundingAmountPerSize: bigint;
99
+ shortTokenClaimableFundingAmountPerSize: bigint;
100
+ };
101
+ marketInfo: MarketInfo;
102
+ marketFeeState: {
103
+ cumulativeBorrowingFactorLong: bigint;
104
+ cumulativeBorrowingFactorShort: bigint;
105
+ fundingFeeAmountPerSizeLongLong: bigint;
106
+ fundingFeeAmountPerSizeLongShort: bigint;
107
+ fundingFeeAmountPerSizeShortLong: bigint;
108
+ fundingFeeAmountPerSizeShortShort: bigint;
109
+ claimableFundingAmountPerSizeLongLong: bigint;
110
+ claimableFundingAmountPerSizeLongShort: bigint;
111
+ claimableFundingAmountPerSizeShortLong: bigint;
112
+ claimableFundingAmountPerSizeShortShort: bigint;
113
+ };
114
+ referralInfo?: UserReferralInfo;
115
+ }): {
116
+ pendingBorrowingFeesUsd: bigint;
117
+ fundingFeeAmount: bigint;
118
+ claimableLongTokenAmount: bigint;
119
+ claimableShortTokenAmount: bigint;
120
+ positionFeeAmount: bigint;
121
+ traderDiscountAmount: bigint;
122
+ uiFeeAmount: bigint;
123
+ };
124
+ export declare function getPositionInfo(p: {
125
+ position: Position;
126
+ marketInfo: MarketInfo;
127
+ minCollateralUsd: bigint;
128
+ userReferralInfo?: UserReferralInfo;
129
+ showPnlInLeverage?: boolean;
130
+ uiFeeFactor?: bigint;
131
+ }): PositionInfo;
@@ -1,6 +1,6 @@
1
1
  import { MarketsInfoData } from "../markets/types";
2
2
  import { SwapPricingType } from "../orders/types";
3
- import { SwapStrategyForSwapOrders } from "../swap/types";
3
+ import { SwapStrategyForSwapOrders } from "./types";
4
4
  import { TokenData } from "../tokens/types";
5
5
  import { ExternalSwapQuoteParams, SwapOptimizationOrderArray } from "../trade/types";
6
6
  export declare function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType, allowSameTokenSwap, }: {
@@ -1,3 +1,3 @@
1
- import type { MarketsGraph } from "./buildMarketsAdjacencyGraph";
2
1
  import type { SwapPaths } from "../trade/types";
2
+ import type { MarketsGraph } from "./buildMarketsAdjacencyGraph";
3
3
  export declare function findSwapPathsBetweenTokens(graph: MarketsGraph): SwapPaths;
@@ -1,5 +1,5 @@
1
- import { MarketsGraph } from "./buildMarketsAdjacencyGraph";
2
1
  import { SwapPaths } from "../trade/types";
2
+ import { MarketsGraph } from "./buildMarketsAdjacencyGraph";
3
3
  declare const MARKETS_ADJACENCY_GRAPH: {
4
4
  [chainId: number]: MarketsGraph;
5
5
  };
@@ -1,7 +1,7 @@
1
- import { MarketsGraph } from "./buildMarketsAdjacencyGraph";
2
1
  import { GasLimitsConfig } from "../fees/types";
3
2
  import { MarketsInfoData } from "../markets/types";
4
3
  import { SwapPricingType } from "../orders/types";
4
+ import { MarketsGraph } from "./buildMarketsAdjacencyGraph";
5
5
  import { TokensData } from "../tokens/types";
6
6
  import { MarketEdge, MarketEdgeLiquidityGetter, NaiveNetworkEstimator, NaiveSwapEstimator, SwapEstimator, SwapPaths } from "../trade/types";
7
7
  export declare const createSwapEstimator: (marketsInfoData: MarketsInfoData, swapPricingType: SwapPricingType) => SwapEstimator;
@@ -11,7 +11,7 @@ export type TokenAddressTypesMap = {
11
11
  export type ContractPrice = bigint & {
12
12
  __brand: "contractPrice";
13
13
  };
14
- export type TokenCategory = "meme" | "layer1" | "layer2" | "defi";
14
+ export type TokenCategory = "meme" | "layer1" | "layer2" | "defi" | "rwa";
15
15
  export type Token = {
16
16
  name: string;
17
17
  symbol: string;
@@ -1,8 +1,8 @@
1
- import { DecreasePositionAmounts, NextPositionValues } from "./types";
2
1
  import { MarketInfo } from "../markets/types";
3
2
  import { PositionInfo, PositionInfoLoaded } from "../positions/types";
4
3
  import { UserReferralInfo } from "../referrals/types";
5
4
  import { TokenData } from "../tokens/types";
5
+ import { DecreasePositionAmounts, NextPositionValues } from "./types";
6
6
  export declare function getDecreasePositionAmounts(p: {
7
7
  marketInfo: MarketInfo;
8
8
  collateralToken: TokenData;
@@ -1,8 +1,8 @@
1
- import { ExternalSwapQuote, ExternalSwapQuoteParams, FindSwapPath, IncreasePositionAmounts, NextPositionValues, TriggerThresholdType } from "./types";
2
1
  import { MarketInfo, MarketsInfoData } from "../markets/types";
3
2
  import { PositionInfo } from "../positions/types";
4
3
  import { UserReferralInfo } from "../referrals/types";
5
4
  import { TokenData, TokensRatio } from "../tokens/types";
5
+ import { ExternalSwapQuote, ExternalSwapQuoteParams, FindSwapPath, IncreasePositionAmounts, NextPositionValues, TriggerThresholdType } from "./types";
6
6
  type IncreasePositionParams = {
7
7
  marketInfo: MarketInfo;
8
8
  indexToken: TokenData;
@@ -1,4 +1,4 @@
1
- import { DecreasePositionAmounts, IncreasePositionAmounts, SwapAmounts, TradeFlags, TradeMode, TradeType } from "../trade/types";
1
+ import { DecreasePositionAmounts, IncreasePositionAmounts, SwapAmounts, TradeFlags, TradeMode, TradeType } from "./types";
2
2
  export declare function applySlippageToPrice(allowedSlippage: number, price: bigint, isIncrease: boolean, isLong: boolean): bigint;
3
3
  export declare function applySlippageToMinOut(allowedSlippage: number, minOutputAmount: bigint): bigint;
4
4
  export declare function getSwapCount({ isSwap, isIncrease, increaseAmounts, decreaseAmounts, swapAmounts, }: {
@@ -43,7 +43,7 @@ export type PositionTradeAction = {
43
43
  orderKey: string;
44
44
  isLong: boolean;
45
45
  reason?: string;
46
- reasonBytes?: string | Uint8Array;
46
+ reasonBytes?: string;
47
47
  shouldUnwrapNativeToken: boolean;
48
48
  totalImpactUsd?: bigint;
49
49
  liquidationFeeAmount?: bigint;
@@ -73,7 +73,7 @@ export type SwapTradeAction = {
73
73
  orderType: OrderType;
74
74
  orderKey: string;
75
75
  reason?: string;
76
- reasonBytes?: string | Uint8Array;
76
+ reasonBytes?: string;
77
77
  twapParams: {
78
78
  twapGroupId: string;
79
79
  numberOfParts: number;
@@ -1,6 +1,6 @@
1
1
  import type { TradeAction as SubsquidTradeAction } from "../../codegen/subsquid";
2
2
  import type { MarketsInfoData } from "../markets/types";
3
- import type { PositionTradeAction, SwapTradeAction } from "./types";
4
3
  import { Token, TokensData } from "../tokens/types";
4
+ import type { PositionTradeAction, SwapTradeAction } from "./types";
5
5
  export declare function createRawTradeActionTransformer(marketsInfoData: MarketsInfoData, wrappedToken: Token, tokensData: TokensData): (value: SubsquidTradeAction, index: number, array: SubsquidTradeAction[]) => SwapTradeAction | PositionTradeAction | undefined;
6
6
  export declare function bigNumberify(n?: bigint | string | null | undefined): bigint | undefined;
@@ -1,5 +1,5 @@
1
- import { TwapDuration } from "./types";
2
1
  import { OrderType } from "../orders/types";
2
+ import { TwapDuration } from "./types";
3
3
  export * from "./types";
4
4
  export declare function getIsValidTwapParams(duration: TwapDuration, numberOfParts: number): boolean;
5
5
  export declare function getTwapDurationInSeconds(duration: TwapDuration): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmx-io/sdk",
3
- "version": "1.5.0-alpha-1",
3
+ "version": "1.5.0-alpha-3",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -328,7 +328,7 @@
328
328
  "crypto-js": "4.2.0",
329
329
  "graphql": "15.8.0",
330
330
  "isomorphic-performance": "5.1.1",
331
- "lodash": "4.17.21",
331
+ "lodash": "4.17.23",
332
332
  "query-string": "7.1.1",
333
333
  "typescript": "5.4.2",
334
334
  "universal-perf-hooks": "1.0.1",
@@ -354,6 +354,7 @@
354
354
  ],
355
355
  "packageManager": "yarn@4.12.0",
356
356
  "resolutions": {
357
- "viem@2.39.0": "patch:viem@npm:2.39.0#../.yarn/patches/viem-npm-2.39.0-c113f391fd"
357
+ "viem@2.39.0": "patch:viem@npm:2.39.0#../.yarn/patches/viem-npm-2.39.0-c113f391fd",
358
+ "lodash": "4.17.23"
358
359
  }
359
360
  }