@gmx-io/sdk 1.1.1 → 1.2.0

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 (100) hide show
  1. package/build/cjs/src/abis/StBTC.json +1225 -0
  2. package/build/cjs/src/abis/SyntheticsReader.json +480 -19
  3. package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -0
  4. package/build/cjs/src/configs/chains.js +57 -6
  5. package/build/cjs/src/configs/contracts.js +64 -68
  6. package/build/cjs/src/configs/dataStore.js +4 -3
  7. package/build/cjs/src/configs/express.js +2 -1
  8. package/build/cjs/src/configs/factors.js +2 -1
  9. package/build/cjs/src/configs/markets.js +37 -0
  10. package/build/cjs/src/configs/oracleKeeper.js +1 -0
  11. package/build/cjs/src/configs/tokens.js +130 -1
  12. package/build/cjs/src/modules/orders/helpers.js +13 -14
  13. package/build/cjs/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -1
  14. package/build/cjs/src/modules/orders/transactions/createIncreaseOrderTxn.js +6 -3
  15. package/build/cjs/src/modules/orders/transactions/createSwapOrderTxn.js +1 -1
  16. package/build/cjs/src/modules/positions/positions.js +9 -0
  17. package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +42 -0
  18. package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +257 -0
  19. package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +77 -0
  20. package/build/cjs/src/types/subsquid.js +2405 -0
  21. package/build/cjs/src/utils/__tests__/numbers.spec.js +17 -9
  22. package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
  23. package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
  24. package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
  25. package/build/cjs/src/utils/__tests__/prices.spec.js +3 -2
  26. package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +9 -0
  27. package/build/cjs/src/utils/errors/transactionsErrors.js +2 -1
  28. package/build/cjs/src/utils/fees/executionFee.js +9 -1
  29. package/build/cjs/src/utils/markets.js +2 -2
  30. package/build/cjs/src/utils/numbers.js +52 -33
  31. package/build/cjs/src/utils/orderTransactions.js +3 -0
  32. package/build/cjs/src/utils/orders.js +8 -2
  33. package/build/cjs/src/utils/prices.js +1 -1
  34. package/build/cjs/src/utils/swap/swapValues.js +40 -0
  35. package/build/cjs/src/utils/tokens.js +10 -1
  36. package/build/cjs/src/utils/tradeHistory.js +4 -4
  37. package/build/cjs/src/utils/twap/uiFeeReceiver.js +26 -6
  38. package/build/esm/src/abis/StBTC.json +1225 -0
  39. package/build/esm/src/abis/SyntheticsReader.json +480 -19
  40. package/build/esm/src/configs/__tests__/tokens.spec.js +2 -1
  41. package/build/esm/src/configs/chains.js +56 -5
  42. package/build/esm/src/configs/contracts.js +65 -69
  43. package/build/esm/src/configs/dataStore.js +1 -0
  44. package/build/esm/src/configs/express.js +4 -3
  45. package/build/esm/src/configs/factors.js +1 -1
  46. package/build/esm/src/configs/markets.js +38 -1
  47. package/build/esm/src/configs/oracleKeeper.js +2 -1
  48. package/build/esm/src/configs/tokens.js +131 -2
  49. package/build/esm/src/modules/orders/helpers.js +13 -14
  50. package/build/esm/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -1
  51. package/build/esm/src/modules/orders/transactions/createIncreaseOrderTxn.js +6 -3
  52. package/build/esm/src/modules/orders/transactions/createSwapOrderTxn.js +1 -1
  53. package/build/esm/src/modules/positions/positions.js +9 -0
  54. package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +42 -0
  55. package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +257 -0
  56. package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +77 -0
  57. package/build/esm/src/types/subsquid.js +2402 -0
  58. package/build/esm/src/utils/__tests__/numbers.spec.js +18 -10
  59. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
  60. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
  61. package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
  62. package/build/esm/src/utils/__tests__/prices.spec.js +3 -2
  63. package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +9 -0
  64. package/build/esm/src/utils/errors/transactionsErrors.js +2 -1
  65. package/build/esm/src/utils/fees/executionFee.js +11 -3
  66. package/build/esm/src/utils/markets.js +2 -2
  67. package/build/esm/src/utils/numbers.js +51 -31
  68. package/build/esm/src/utils/orderTransactions.js +3 -0
  69. package/build/esm/src/utils/orders.js +8 -2
  70. package/build/esm/src/utils/prices.js +1 -1
  71. package/build/esm/src/utils/swap/swapValues.js +41 -1
  72. package/build/esm/src/utils/tokens.js +7 -0
  73. package/build/esm/src/utils/tradeHistory.js +4 -4
  74. package/build/esm/src/utils/twap/uiFeeReceiver.js +24 -5
  75. package/build/types/src/configs/chains.d.ts +20 -37
  76. package/build/types/src/configs/contracts.d.ts +60 -63
  77. package/build/types/src/configs/dataStore.d.ts +1 -0
  78. package/build/types/src/configs/factors.d.ts +1 -1
  79. package/build/types/src/configs/markets.d.ts +2 -1
  80. package/build/types/src/configs/oracleKeeper.d.ts +1 -1
  81. package/build/types/src/configs/tokens.d.ts +1 -0
  82. package/build/types/src/index.d.ts +1 -1
  83. package/build/types/src/modules/base.d.ts +1 -1
  84. package/build/types/src/modules/orders/helpers.d.ts +10 -2
  85. package/build/types/src/modules/orders/orders.d.ts +10 -1
  86. package/build/types/src/types/orders.d.ts +1 -1
  87. package/build/types/src/types/sdk.d.ts +2 -1
  88. package/build/types/src/types/subsquid.d.ts +7304 -0
  89. package/build/types/src/types/tokens.d.ts +1 -0
  90. package/build/types/src/types/trade.d.ts +1 -0
  91. package/build/types/src/types/tradeHistory.d.ts +0 -40
  92. package/build/types/src/utils/markets.d.ts +1 -1
  93. package/build/types/src/utils/multicall.d.ts +1 -1
  94. package/build/types/src/utils/numbers.d.ts +9 -3
  95. package/build/types/src/utils/orderTransactions.d.ts +2 -3
  96. package/build/types/src/utils/prices.d.ts +1 -1
  97. package/build/types/src/utils/tokens.d.ts +2 -0
  98. package/build/types/src/utils/tradeHistory.d.ts +2 -2
  99. package/build/types/src/utils/twap/uiFeeReceiver.d.ts +13 -0
  100. package/package.json +7 -2
@@ -45,6 +45,7 @@ export type Token = {
45
45
  isV1Available?: boolean;
46
46
  isPlatformToken?: boolean;
47
47
  isPlatformTradingToken?: boolean;
48
+ isStaking?: boolean;
48
49
  shouldResetAllowance?: boolean;
49
50
  };
50
51
  export type TokenInfo = Token & {
@@ -280,5 +280,6 @@ export type TradeSearchParams = {
280
280
  pool?: string;
281
281
  collateral?: string;
282
282
  market?: string;
283
+ chainId?: string;
283
284
  };
284
285
  export {};
@@ -1,4 +1,3 @@
1
- import { BytesLike } from "./common";
2
1
  import { MarketInfo } from "./markets";
3
2
  import { OrderType } from "./orders";
4
3
  import { TokenData } from "./tokens";
@@ -9,45 +8,6 @@ export declare enum TradeActionType {
9
8
  OrderUpdated = "OrderUpdated",
10
9
  OrderFrozen = "OrderFrozen"
11
10
  }
12
- export type RawTradeAction = {
13
- id: string;
14
- eventName: TradeActionType;
15
- account: string;
16
- marketAddress?: string;
17
- swapPath?: string[];
18
- initialCollateralTokenAddress?: string;
19
- initialCollateralDeltaAmount?: string;
20
- sizeDeltaUsd?: string;
21
- triggerPrice?: string;
22
- acceptablePrice?: string;
23
- executionPrice?: string;
24
- minOutputAmount?: string;
25
- executionAmountOut?: string;
26
- priceImpactDiffUsd?: string;
27
- priceImpactUsd?: string;
28
- positionFeeAmount?: string;
29
- borrowingFeeAmount?: string;
30
- fundingFeeAmount?: string;
31
- liquidationFeeAmount?: string;
32
- pnlUsd?: string;
33
- basePnlUsd?: string;
34
- collateralTokenPriceMax?: string;
35
- collateralTokenPriceMin?: string;
36
- indexTokenPriceMin?: string;
37
- indexTokenPriceMax?: string;
38
- orderType: OrderType;
39
- orderKey: string;
40
- isLong?: boolean;
41
- shouldUnwrapNativeToken?: boolean;
42
- twapGroupId?: string;
43
- numberOfParts?: number;
44
- reason?: string;
45
- reasonBytes?: BytesLike;
46
- timestamp: number;
47
- transaction: {
48
- hash: string;
49
- };
50
- };
51
11
  export type PositionTradeAction = {
52
12
  id: string;
53
13
  eventName: TradeActionType;
@@ -16,7 +16,7 @@ export declare function getMarketIndexName(p: ({
16
16
  export declare function getMarketPoolName(p: {
17
17
  longToken: Token;
18
18
  shortToken: Token;
19
- }): string;
19
+ }, separator?: string): string;
20
20
  export declare function getContractMarketPrices(tokensData: TokensData, market: Market): ContractMarketPrices | undefined;
21
21
  /**
22
22
  * Apart from usual cases, returns `long` for single token backed markets.
@@ -12,7 +12,7 @@ export declare class Multicall {
12
12
  };
13
13
  static getInstance(sdk: GmxSdk): Promise<Multicall>;
14
14
  constructor(sdk: GmxSdk);
15
- get chainId(): number;
15
+ get chainId(): import("../configs/chains").UiContractsChain;
16
16
  call(request: MulticallRequestConfig<any>, maxTimeout: number): Promise<MulticallResult<any>>;
17
17
  }
18
18
  export type SkipKey = null | undefined | false;
@@ -3,6 +3,7 @@ export type BigNumberish = string | Numeric;
3
3
  export declare const USD_DECIMALS = 30;
4
4
  export declare const BASIS_POINTS_DIVISOR = 10000;
5
5
  export declare const BASIS_POINTS_DIVISOR_BIGINT = 10000n;
6
+ export declare const BASIS_POINTS_DECIMALS = 4;
6
7
  export declare const PRECISION_DECIMALS = 30;
7
8
  export declare const PRECISION: bigint;
8
9
  export declare const BN_ZERO = 0n;
@@ -47,11 +48,13 @@ export declare function formatTokenAmount(amount?: bigint, tokenDecimals?: numbe
47
48
  minThreshold?: string;
48
49
  maxThreshold?: string;
49
50
  displayPlus?: boolean;
51
+ isStable?: boolean;
50
52
  }): string | undefined;
51
53
  export declare function formatTokenAmountWithUsd(tokenAmount?: bigint, usdAmount?: bigint, tokenSymbol?: string, tokenDecimals?: number, opts?: {
52
54
  fallbackToZero?: boolean;
53
55
  displayDecimals?: number;
54
56
  displayPlus?: boolean;
57
+ isStable?: boolean;
55
58
  }): string | undefined;
56
59
  /**
57
60
  *
@@ -64,8 +67,11 @@ export declare function formatRatePercentage(rate?: bigint, opts?: {
64
67
  export declare function formatUsdPrice(price?: bigint, opts?: Parameters<typeof formatUsd>[1]): string | undefined;
65
68
  export declare function formatPercentageDisplay(percentage: number, hideThreshold?: number): string;
66
69
  export declare function formatAmountHuman(amount: BigNumberish | undefined, tokenDecimals: number, showDollar?: boolean, displayDecimals?: number): string;
67
- export declare function formatBalanceAmount(amount: bigint, tokenDecimals: number, tokenSymbol?: string, showZero?: boolean, toExponential?: boolean): string;
68
- export declare function formatBalanceAmountWithUsd(amount: bigint, amountUsd: bigint, tokenDecimals: number, tokenSymbol?: string, showZero?: boolean): string;
70
+ export declare function formatBalanceAmount(amount: bigint, tokenDecimals: number, tokenSymbol?: string, { showZero, toExponential, isStable, }?: {
71
+ showZero?: boolean;
72
+ toExponential?: boolean;
73
+ isStable?: boolean;
74
+ }): string;
69
75
  export declare function formatFactor(factor: bigint): string;
70
76
  export declare function numberWithCommas(x: BigNumberish): string;
71
77
  export declare const formatAmount: (amount: BigNumberish | undefined, tokenDecimals: number, displayDecimals?: number, useCommas?: boolean, defaultValue?: string, visualMultiplier?: number) => string;
@@ -116,7 +122,7 @@ type DeserializeBigIntInObject<T> = {
116
122
  };
117
123
  export declare function serializeBigIntsInObject<T extends object>(obj: T): SerializedBigIntsInObject<T>;
118
124
  export declare function deserializeBigIntsInObject<T extends object>(obj: T): DeserializeBigIntInObject<T>;
119
- export declare function calculateDisplayDecimals(price?: bigint, decimals?: number, visualMultiplier?: number): 5 | 2 | 3 | 4 | 6 | 7 | 8 | 9;
125
+ export declare function calculateDisplayDecimals(price?: bigint, decimals?: number, visualMultiplier?: number, isStable?: boolean): 5 | 2 | 3 | 4 | 6 | 7 | 8 | 9;
120
126
  export declare function clamp(value: number, min: number, max: number): number;
121
127
  export declare function absDiffBps(value: bigint, base: bigint): bigint;
122
128
  export {};
@@ -3,7 +3,7 @@ import { DecreasePositionSwapType, OrderType } from "../types/orders";
3
3
  import { ContractPrice, ERC20Address, TokensData } from "../types/tokens";
4
4
  import { ExternalSwapQuote } from "../types/trade";
5
5
  import { TwapOrderParams } from "../types/twap";
6
- type ExchangeRouterCall = {
6
+ export type ExchangeRouterCall = {
7
7
  method: string;
8
8
  params: any[];
9
9
  };
@@ -131,6 +131,7 @@ export type SwapOrderParams = CommonOrderParams & {
131
131
  swapPath: string[];
132
132
  externalSwapQuote: ExternalSwapQuote | undefined;
133
133
  minOutputAmount: bigint;
134
+ expectedOutputAmount?: bigint;
134
135
  orderType: OrderType.MarketSwap | OrderType.LimitSwap;
135
136
  triggerRatio: bigint | undefined;
136
137
  };
@@ -187,7 +188,6 @@ export declare function buildTokenTransfersParamsForIncreaseOrSwap({ chainId, re
187
188
  externalSwapQuote: ExternalSwapQuote | undefined;
188
189
  minOutputAmount: bigint;
189
190
  swapPath: string[];
190
- orderType: OrderType;
191
191
  }): TokenTransfersParams;
192
192
  export declare function getBatchExternalCalls(batchParams: BatchOrderTxnParams): ExternalCallsPayload;
193
193
  export declare function combineExternalCalls(externalCalls: ExternalCallsPayload[]): ExternalCallsPayload;
@@ -228,4 +228,3 @@ export declare function getBatchSwapsCount(orderParams: BatchOrderTxnParams | un
228
228
  export declare function getIsEmptyBatch(orderParams: BatchOrderTxnParams | undefined): boolean;
229
229
  export declare function getBatchIsNativePayment(orderParams: BatchOrderTxnParams): boolean;
230
230
  export declare function getIsInvalidBatchReceiver(batchParams: BatchOrderTxnParams, signerAddress: string): boolean;
231
- export {};
@@ -8,7 +8,7 @@ export declare function getMarkPrice(p: {
8
8
  isLong: boolean;
9
9
  }): bigint;
10
10
  export declare function getShouldUseMaxPrice(isIncrease: boolean, isLong: boolean): boolean;
11
- export declare function getOrderThresholdType(orderType: OrderType, isLong: boolean): TriggerThresholdType;
11
+ export declare function getOrderThresholdType(orderType: OrderType, isLong: boolean): TriggerThresholdType | undefined;
12
12
  export declare function getAcceptablePriceInfo(p: {
13
13
  marketInfo: MarketInfo;
14
14
  isIncrease: boolean;
@@ -39,6 +39,8 @@ export declare function getAmountByRatio(p: {
39
39
  }): bigint;
40
40
  export declare function getIsWrap(token1: Token, token2: Token): boolean | undefined;
41
41
  export declare function getIsUnwrap(token1: Token, token2: Token): boolean | undefined;
42
+ export declare function getIsStake(token1: Token, token2: Token): boolean | undefined;
43
+ export declare function getIsUnstake(token1: Token, token2: Token): boolean | undefined;
42
44
  export declare function getTokensRatioByPrice(p: {
43
45
  fromToken: Token;
44
46
  toToken: Token;
@@ -1,7 +1,7 @@
1
1
  import type { MarketsInfoData } from "../types/markets";
2
+ import type { TradeAction as SubsquidTradeAction } from "../types/subsquid";
2
3
  import { Token, TokensData } from "../types/tokens";
3
4
  import type { PositionTradeAction } from "../types/tradeHistory";
4
- import type { RawTradeAction } from "../types/tradeHistory";
5
5
  import type { SwapTradeAction } from "../types/tradeHistory";
6
- export declare function createRawTradeActionTransformer(marketsInfoData: MarketsInfoData, wrappedToken: Token, tokensData: TokensData): (value: RawTradeAction, index: number, array: RawTradeAction[]) => SwapTradeAction | PositionTradeAction | undefined;
6
+ export declare function createRawTradeActionTransformer(marketsInfoData: MarketsInfoData, wrappedToken: Token, tokensData: TokensData): (value: SubsquidTradeAction, index: number, array: SubsquidTradeAction[]) => SwapTradeAction | PositionTradeAction | undefined;
7
7
  export declare function bigNumberify(n?: bigint | string | null | undefined): bigint | undefined;
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Ui fee receiver structure:
3
+ * 0..3 bytes (0..7 chars) - PREFIX
4
+ * 4..16 bytes (8..27 chars) - 12 bytes buffer
5
+ * 17 byte (27..29 chars) - isExpress flag
6
+ * 18 byte (30..32 chars) - numberOfParts (hex encoded)
7
+ * 19..20 bytes (34..38 chars) - twapId
8
+ * 20 byte (38..40 chars) - VERSION
9
+ *
10
+ * Total: 20 bytes (40 hex characters)
11
+ */
1
12
  export declare function generateTwapId(): string;
2
13
  export declare function createTwapUiFeeReceiver({ numberOfParts }: {
3
14
  numberOfParts: number;
@@ -5,5 +16,7 @@ export declare function createTwapUiFeeReceiver({ numberOfParts }: {
5
16
  export declare function decodeTwapUiFeeReceiver(address: string): {
6
17
  twapId: string;
7
18
  numberOfParts: number;
19
+ isExpress: boolean;
8
20
  } | void;
9
21
  export declare function isValidTwapUiFeeReceiver(address: string): boolean;
22
+ export declare function setUiFeeReceiverIsExpress(uiFeeReceiver: string, isExpress: boolean): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmx-io/sdk",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "main": "./build/cjs/src/index.js",
6
6
  "module": "./build/esm/src/index.js",
@@ -51,9 +51,10 @@
51
51
  "build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > build/cjs/src/package.json",
52
52
  "build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > build/esm/src/package.json",
53
53
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
54
+ "build:subsquid": "./node_modules/@graphql-codegen/cli/cjs/bin.js -c subsquid-codegen.ts",
54
55
  "tscheck": "tsc -p tsconfig.json --noEmit",
55
56
  "clean": "rm -rf build/**/*.tsbuildinfo",
56
- "build": "rm -rf build && yarn build:types && yarn build:cjs && yarn build:esm && yarn clean"
57
+ "build": "rm -rf build && yarn build:subsquid && yarn build:types && yarn build:cjs && yarn build:esm && yarn clean"
57
58
  },
58
59
  "publishConfig": {
59
60
  "access": "public"
@@ -75,6 +76,10 @@
75
76
  },
76
77
  "devDependencies": {
77
78
  "@babel/plugin-proposal-private-property-in-object": "7.21.11",
79
+ "@graphql-codegen/cli": "5.0.6",
80
+ "@graphql-codegen/client-preset": "4.8.1",
81
+ "@graphql-codegen/typescript": "4.1.6",
82
+ "@graphql-codegen/typescript-operations": "4.6.1",
78
83
  "@types/lodash": "4.14.198",
79
84
  "@types/node": "18.7.13",
80
85
  "lint-staged": "12.3.4",