@gmx-io/sdk 1.4.0 → 1.4.2

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 (157) hide show
  1. package/build/cjs/src/abis/GlvReader.js +940 -940
  2. package/build/cjs/src/abis/IStargate.js +603 -0
  3. package/build/cjs/src/abis/LayerZeroProvider.js +273 -46
  4. package/build/cjs/src/abis/index.js +2 -2
  5. package/build/cjs/src/configs/batch.js +29 -103
  6. package/build/cjs/src/configs/chainIds.js +2 -2
  7. package/build/cjs/src/configs/chains.js +230 -151
  8. package/build/cjs/src/configs/contracts.js +1 -5
  9. package/build/cjs/src/configs/dataStore.js +5 -4
  10. package/build/cjs/src/configs/express.js +1 -1
  11. package/build/cjs/src/configs/gasLimits.js +41 -0
  12. package/build/cjs/src/configs/markets.js +102 -1
  13. package/build/cjs/src/configs/multichain.js +1 -0
  14. package/build/cjs/src/configs/oracleKeeper.js +18 -20
  15. package/build/cjs/src/configs/tokens.js +98 -180
  16. package/build/cjs/src/modules/markets/index.js +6 -2
  17. package/build/cjs/src/modules/markets/markets.spec.js +5 -5
  18. package/build/cjs/src/modules/markets/query-builders.js +8 -0
  19. package/build/cjs/src/modules/orders/helpers.js +4 -2
  20. package/build/cjs/src/modules/orders/helpers.spec.js +1 -1
  21. package/build/cjs/src/modules/orders/orders.spec.js +1 -1
  22. package/build/cjs/src/modules/positions/positions.spec.js +2 -2
  23. package/build/cjs/src/modules/tokens/tokens.spec.js +2 -2
  24. package/build/cjs/src/modules/trades/trades.spec.js +1 -1
  25. package/build/cjs/src/modules/utils/utils.js +7 -6
  26. package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +64 -0
  27. package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +780 -0
  28. package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +120 -0
  29. package/build/cjs/src/test/mock.js +2 -0
  30. package/build/cjs/src/types/chains.js +2 -0
  31. package/build/cjs/src/types/orders.js +8 -2
  32. package/build/cjs/src/types/subsquid.js +241 -1
  33. package/build/cjs/src/types/tokens.js +7 -0
  34. package/build/cjs/src/utils/__tests__/abort.spec.js +122 -0
  35. package/build/cjs/src/utils/__tests__/numbers.spec.js +94 -14
  36. package/build/cjs/src/utils/abort.js +31 -0
  37. package/build/cjs/src/utils/callContract.js +4 -4
  38. package/build/cjs/src/utils/fees/executionFee.js +14 -11
  39. package/build/cjs/src/utils/fees/index.js +8 -2
  40. package/build/cjs/src/utils/marketKeysAndConfigs.js +8 -0
  41. package/build/cjs/src/utils/markets.js +7 -1
  42. package/build/cjs/src/utils/multicall.js +54 -17
  43. package/build/cjs/src/utils/numbers.js +25 -14
  44. package/build/cjs/src/utils/orders.js +2 -2
  45. package/build/cjs/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.js +22 -0
  46. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +264 -6
  47. package/build/cjs/src/utils/swap/__tests__/swapRouting.spec.js +5 -4
  48. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +10 -9
  49. package/build/cjs/src/utils/swap/buildSwapStrategy.js +20 -11
  50. package/build/cjs/src/utils/swap/findSwapPathsBetweenTokens.js +8 -4
  51. package/build/cjs/src/utils/swap/swapPath.js +6 -6
  52. package/build/cjs/src/utils/swap/swapRouting.js +8 -4
  53. package/build/cjs/src/utils/swap/swapStats.js +6 -6
  54. package/build/cjs/src/utils/swap/swapValues.js +17 -6
  55. package/build/cjs/src/utils/tokens.js +17 -1
  56. package/build/cjs/src/utils/trade/decrease.js +1 -1
  57. package/build/cjs/src/utils/trade/increase.js +3 -0
  58. package/build/esm/src/abis/GlvReader.js +940 -940
  59. package/build/esm/src/abis/IStargate.js +601 -0
  60. package/build/esm/src/abis/LayerZeroProvider.js +273 -46
  61. package/build/esm/src/abis/index.js +2 -2
  62. package/build/esm/src/configs/batch.js +30 -104
  63. package/build/esm/src/configs/chainIds.js +1 -1
  64. package/build/esm/src/configs/chains.js +212 -147
  65. package/build/esm/src/configs/contracts.js +1 -5
  66. package/build/esm/src/configs/dataStore.js +1 -0
  67. package/build/esm/src/configs/express.js +1 -1
  68. package/build/esm/src/configs/gasLimits.js +38 -0
  69. package/build/esm/src/configs/markets.js +95 -1
  70. package/build/esm/src/configs/multichain.js +2 -1
  71. package/build/esm/src/configs/oracleKeeper.js +17 -19
  72. package/build/esm/src/configs/tokens.js +97 -179
  73. package/build/esm/src/modules/markets/index.js +6 -2
  74. package/build/esm/src/modules/markets/markets.spec.js +5 -5
  75. package/build/esm/src/modules/markets/query-builders.js +8 -0
  76. package/build/esm/src/modules/orders/helpers.js +5 -3
  77. package/build/esm/src/modules/orders/helpers.spec.js +1 -1
  78. package/build/esm/src/modules/orders/orders.spec.js +1 -1
  79. package/build/esm/src/modules/positions/positions.spec.js +2 -2
  80. package/build/esm/src/modules/tokens/tokens.spec.js +2 -2
  81. package/build/esm/src/modules/trades/trades.spec.js +1 -1
  82. package/build/esm/src/modules/utils/utils.js +7 -6
  83. package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +64 -0
  84. package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +780 -0
  85. package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +120 -0
  86. package/build/esm/src/test/mock.js +2 -0
  87. package/build/esm/src/types/chains.js +1 -0
  88. package/build/esm/src/types/orders.js +8 -2
  89. package/build/esm/src/types/subsquid.js +240 -0
  90. package/build/esm/src/types/tokens.js +6 -1
  91. package/build/esm/src/utils/__tests__/abort.spec.js +120 -0
  92. package/build/esm/src/utils/__tests__/numbers.spec.js +95 -15
  93. package/build/esm/src/utils/abort.js +27 -0
  94. package/build/esm/src/utils/callContract.js +5 -5
  95. package/build/esm/src/utils/fees/executionFee.js +15 -12
  96. package/build/esm/src/utils/fees/index.js +8 -2
  97. package/build/esm/src/utils/marketKeysAndConfigs.js +9 -1
  98. package/build/esm/src/utils/markets.js +5 -0
  99. package/build/esm/src/utils/multicall.js +53 -16
  100. package/build/esm/src/utils/numbers.js +21 -12
  101. package/build/esm/src/utils/orders.js +3 -3
  102. package/build/esm/src/utils/swap/__tests__/findSwapPathsBetweenTokens.spec.js +22 -0
  103. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +264 -6
  104. package/build/esm/src/utils/swap/__tests__/swapRouting.spec.js +5 -4
  105. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +10 -9
  106. package/build/esm/src/utils/swap/buildSwapStrategy.js +21 -12
  107. package/build/esm/src/utils/swap/findSwapPathsBetweenTokens.js +8 -4
  108. package/build/esm/src/utils/swap/swapPath.js +6 -6
  109. package/build/esm/src/utils/swap/swapRouting.js +8 -4
  110. package/build/esm/src/utils/swap/swapStats.js +6 -6
  111. package/build/esm/src/utils/swap/swapValues.js +18 -7
  112. package/build/esm/src/utils/tokens.js +15 -1
  113. package/build/esm/src/utils/trade/decrease.js +2 -2
  114. package/build/esm/src/utils/trade/increase.js +3 -0
  115. package/build/types/src/abis/IStargate.d.ts +464 -0
  116. package/build/types/src/abis/LayerZeroProvider.d.ts +12 -0
  117. package/build/types/src/abis/index.d.ts +475 -99
  118. package/build/types/src/configs/chainIds.d.ts +1 -1
  119. package/build/types/src/configs/chains.d.ts +170 -27
  120. package/build/types/src/configs/contracts.d.ts +0 -4
  121. package/build/types/src/configs/dataStore.d.ts +1 -0
  122. package/build/types/src/configs/express.d.ts +1 -1
  123. package/build/types/src/configs/gasLimits.d.ts +4 -0
  124. package/build/types/src/configs/markets.d.ts +10 -1
  125. package/build/types/src/configs/oracleKeeper.d.ts +13 -0
  126. package/build/types/src/configs/tokens.d.ts +3 -0
  127. package/build/types/src/index.d.ts +1 -1
  128. package/build/types/src/modules/base.d.ts +1 -1
  129. package/build/types/src/modules/markets/index.d.ts +2 -0
  130. package/build/types/src/modules/markets/query-builders.d.ts +1 -1
  131. package/build/types/src/modules/markets/types.d.ts +2 -2
  132. package/build/types/src/modules/utils/utils.d.ts +2 -3
  133. package/build/types/src/types/chains.d.ts +57 -0
  134. package/build/types/src/types/markets.d.ts +2 -0
  135. package/build/types/src/types/orders.d.ts +8 -2
  136. package/build/types/src/types/subsquid.d.ts +5987 -5172
  137. package/build/types/src/types/tokens.d.ts +11 -6
  138. package/build/types/src/types/trade.d.ts +5 -0
  139. package/build/types/src/utils/__tests__/abort.spec.d.ts +1 -0
  140. package/build/types/src/utils/abort.d.ts +1 -0
  141. package/build/types/src/utils/fees/estimateOraclePriceCount.d.ts +2 -2
  142. package/build/types/src/utils/fees/executionFee.d.ts +6 -6
  143. package/build/types/src/utils/fees/index.d.ts +2 -1
  144. package/build/types/src/utils/marketKeysAndConfigs.d.ts +2 -0
  145. package/build/types/src/utils/markets.d.ts +4 -2
  146. package/build/types/src/utils/multicall.d.ts +4 -2
  147. package/build/types/src/utils/numbers.d.ts +8 -1
  148. package/build/types/src/utils/swap/buildSwapStrategy.d.ts +8 -3
  149. package/build/types/src/utils/swap/swapPath.d.ts +2 -1
  150. package/build/types/src/utils/swap/swapRouting.d.ts +7 -2
  151. package/build/types/src/utils/swap/swapStats.d.ts +3 -2
  152. package/build/types/src/utils/swap/swapValues.d.ts +3 -1
  153. package/build/types/src/utils/tokens.d.ts +3 -0
  154. package/package.json +17 -5
  155. package/build/cjs/src/abis/MultichainUtils.js +0 -133
  156. package/build/esm/src/abis/MultichainUtils.js +0 -131
  157. package/build/types/src/abis/MultichainUtils.d.ts +0 -100
@@ -23,8 +23,6 @@ export type Token = {
23
23
  visualMultiplier?: number;
24
24
  visualPrefix?: string;
25
25
  wrappedAddress?: string;
26
- coingeckoUrl?: string;
27
- coingeckoSymbol?: string;
28
26
  metamaskSymbol?: string;
29
27
  explorerSymbol?: string;
30
28
  explorerUrl?: string;
@@ -46,7 +44,6 @@ export type Token = {
46
44
  isPlatformToken?: boolean;
47
45
  isPlatformTradingToken?: boolean;
48
46
  isStaking?: boolean;
49
- shouldResetAllowance?: boolean;
50
47
  };
51
48
  /**
52
49
  * @deprecated V1 TokenInfo struct
@@ -102,14 +99,22 @@ export type TokenPrices = {
102
99
  minPrice: bigint;
103
100
  maxPrice: bigint;
104
101
  };
102
+ export declare enum TokenBalanceType {
103
+ Wallet = 0,
104
+ GmxAccount = 1,
105
+ SourceChain = 2
106
+ }
105
107
  export type TokenAsyncData = {
106
108
  prices: TokenPrices;
107
- isGmxAccount?: boolean;
108
109
  walletBalance?: bigint;
109
110
  gmxAccountBalance?: bigint;
110
111
  /**
111
- * If isGmxAccount is true, then this is the gmx account balance
112
- * If isGmxAccount is false, then this is the wallet balance
112
+ * In source chain decimals, use `getMappedTokenId` to get the decimals
113
+ */
114
+ sourceChainBalance?: bigint;
115
+ balanceType?: TokenBalanceType;
116
+ /**
117
+ * Balance according to the balanceType
113
118
  */
114
119
  balance?: bigint;
115
120
  totalSupply?: bigint;
@@ -126,10 +126,14 @@ export type DepositAmounts = {
126
126
  export type WithdrawalAmounts = {
127
127
  marketTokenAmount: bigint;
128
128
  marketTokenUsd: bigint;
129
+ longTokenBeforeSwapAmount: bigint;
129
130
  longTokenAmount: bigint;
131
+ longTokenSwapPathStats: SwapPathStats | undefined;
130
132
  shortTokenAmount: bigint;
133
+ shortTokenBeforeSwapAmount: bigint;
131
134
  longTokenUsd: bigint;
132
135
  shortTokenUsd: bigint;
136
+ shortTokenSwapPathStats: SwapPathStats | undefined;
133
137
  glvTokenAmount: bigint;
134
138
  glvTokenUsd: bigint;
135
139
  swapFeeUsd: bigint;
@@ -298,6 +302,7 @@ export type GmSwapFees = {
298
302
  swapPriceImpact?: FeeItem;
299
303
  uiFee?: FeeItem;
300
304
  shiftFee?: FeeItem;
305
+ logicalNetworkFee?: FeeItem;
301
306
  };
302
307
  export type TradeSearchParams = {
303
308
  from?: string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function combineAbortSignals(...signals: AbortSignal[]): AbortController;
@@ -1,5 +1,5 @@
1
- export declare function estimateDepositOraclePriceCount(swapsCount: number): bigint;
2
- export declare function estimateWithdrawalOraclePriceCount(swapsCount: number): bigint;
1
+ export declare function estimateDepositOraclePriceCount(swapsCount: number | bigint): bigint;
2
+ export declare function estimateWithdrawalOraclePriceCount(swapsCount: bigint): bigint;
3
3
  export declare function estimateOrderOraclePriceCount(swapsCount: number): bigint;
4
4
  export declare function estimateShiftOraclePriceCount(): bigint;
5
5
  export declare function estimateGlvDepositOraclePriceCount(marketCount: bigint, swapsCount?: bigint): bigint;
@@ -63,18 +63,17 @@ export declare function estimateExecuteSwapOrderGasLimit(gasLimits: GasLimitsCon
63
63
  * Copy from contract: `estimateExecuteDepositGasLimit`
64
64
  */
65
65
  export declare function estimateExecuteDepositGasLimit(gasLimits: GasLimitsConfig, deposit: {
66
- longTokenSwapsCount?: number;
67
- shortTokenSwapsCount?: number;
66
+ swapsCount?: number | bigint;
68
67
  callbackGasLimit?: bigint;
69
68
  }): bigint;
70
- export declare function estimateExecuteGlvDepositGasLimit(gasLimits: GasLimitsConfig, { marketsCount, isMarketTokenDeposit, }: {
69
+ export declare function estimateExecuteGlvDepositGasLimit(gasLimits: GasLimitsConfig, { marketsCount, isMarketTokenDeposit, swapsCount, }: {
71
70
  isMarketTokenDeposit: boolean;
72
71
  marketsCount: bigint;
73
- initialLongTokenAmount: bigint;
74
- initialShortTokenAmount: bigint;
72
+ swapsCount: bigint;
75
73
  }): bigint;
76
- export declare function estimateExecuteGlvWithdrawalGasLimit(gasLimits: GasLimitsConfig, { marketsCount, }: {
74
+ export declare function estimateExecuteGlvWithdrawalGasLimit(gasLimits: GasLimitsConfig, { marketsCount, swapsCount, }: {
77
75
  marketsCount: bigint;
76
+ swapsCount: bigint;
78
77
  }): bigint;
79
78
  /**
80
79
  * Only GM withdrawals. Do not confuse with decrease with zero delta size.
@@ -83,6 +82,7 @@ export declare function estimateExecuteGlvWithdrawalGasLimit(gasLimits: GasLimit
83
82
  */
84
83
  export declare function estimateExecuteWithdrawalGasLimit(gasLimits: GasLimitsConfig, withdrawal: {
85
84
  callbackGasLimit?: bigint;
85
+ swapsCount?: bigint;
86
86
  }): bigint;
87
87
  /**
88
88
  * Copy from contract: `estimateExecuteShiftGasLimit`
@@ -1,10 +1,11 @@
1
1
  import { FeeItem } from "../../types/fees";
2
2
  import { MarketInfo } from "../../types/markets";
3
+ import { SwapPricingType } from "../../types/orders";
3
4
  import { SwapStats } from "../../types/trade";
4
5
  export * from "./estimateOraclePriceCount";
5
6
  export * from "./executionFee";
6
7
  export * from "./priceImpact";
7
- export declare function getSwapFee(marketInfo: MarketInfo, swapAmount: bigint, balanceWasImproved: boolean, isAtomicSwap: boolean): bigint;
8
+ export declare function getSwapFee(marketInfo: MarketInfo, swapAmount: bigint, balanceWasImproved: boolean, swapPricingType: SwapPricingType): bigint;
8
9
  export declare function getPositionFee(marketInfo: MarketInfo, sizeDeltaUsd: bigint, balanceWasImproved: boolean, referralInfo: {
9
10
  totalRebateFactor: bigint;
10
11
  discountFactor: bigint;
@@ -50,6 +50,8 @@ export declare function hashMarketConfigKeys(market: MarketConfig): {
50
50
  swapImpactFactorPositive: string;
51
51
  swapImpactFactorNegative: string;
52
52
  swapImpactExponentFactor: string;
53
+ withdrawalFeeFactorBalanceWasImproved: string;
54
+ withdrawalFeeFactorBalanceWasNotImproved: string;
53
55
  virtualMarketId: string;
54
56
  virtualLongTokenId: string;
55
57
  virtualShortTokenId: string;
@@ -1,5 +1,6 @@
1
- import { ContractMarketPrices, Market, MarketInfo } from "../types/markets";
2
- import { Token, TokenPrices, TokensData } from "../types/tokens";
1
+ import type { MarketConfig } from "../configs/markets";
2
+ import type { ContractMarketPrices, Market, MarketInfo } from "../types/markets";
3
+ import type { Token, TokenPrices, TokensData } from "../types/tokens";
3
4
  export declare function getMarketFullName(p: {
4
5
  longToken: Token;
5
6
  shortToken: Token;
@@ -42,6 +43,7 @@ export declare function getCappedPoolPnl(p: {
42
43
  export declare function getMaxLeverageByMinCollateralFactor(minCollateralFactor: bigint | undefined): number;
43
44
  export declare function getMaxAllowedLeverageByMinCollateralFactor(minCollateralFactor: bigint | undefined): number;
44
45
  export declare function getOppositeCollateral(marketInfo: MarketInfo, tokenAddress: string): import("../types/tokens").TokenData | undefined;
46
+ export declare function getOppositeCollateralFromConfig(marketConfig: MarketConfig, tokenAddress: string): string;
45
47
  export declare function getAvailableUsdLiquidityForCollateral(marketInfo: MarketInfo, isLong: boolean): bigint;
46
48
  export declare function getReservedUsd(marketInfo: MarketInfo, isLong: boolean): bigint;
47
49
  export declare function getMarketDivisor({ longTokenAddress, shortTokenAddress, }: {
@@ -1,6 +1,8 @@
1
1
  import { AbiId } from "../abis";
2
2
  import type { GmxSdk } from "index";
3
- export declare const MAX_TIMEOUT = 20000;
3
+ export declare const MAX_TIMEOUT = 40000;
4
+ export declare const MAX_CALLS_PER_BATCH = 1000;
5
+ export declare const MAX_CONCURRENT_BATCHES = 1;
4
6
  export type MulticallProviderUrls = {
5
7
  primary: string;
6
8
  secondary: string;
@@ -12,7 +14,7 @@ export declare class Multicall {
12
14
  };
13
15
  static getInstance(sdk: GmxSdk): Promise<Multicall>;
14
16
  constructor(sdk: GmxSdk);
15
- get chainId(): import("../configs/chains").ContractsChainId;
17
+ get chainId(): 43114 | 42161 | 3637 | 43113 | 421614;
16
18
  call(request: MulticallRequestConfig<any>, maxTimeout: number): Promise<MulticallResult<any>>;
17
19
  }
18
20
  export type SkipKey = null | undefined | false;
@@ -10,9 +10,16 @@ export declare const BN_ZERO = 0n;
10
10
  export declare const BN_ONE = 1n;
11
11
  export declare const BN_NEGATIVE_ONE = -1n;
12
12
  export declare const MaxUint256: bigint;
13
+ export declare const MaxInt256: bigint;
13
14
  export declare const PERCENT_PRECISION_DECIMALS: number;
14
15
  export declare const TRIGGER_PREFIX_ABOVE = ">";
15
16
  export declare const TRIGGER_PREFIX_BELOW = "<";
17
+ declare const __nonZero: unique symbol;
18
+ export type NonZero<T extends number | bigint> = T & {
19
+ readonly [__nonZero]: true;
20
+ };
21
+ export declare function isNonZero<T extends number | bigint>(value: T): value is NonZero<T>;
22
+ export declare function safeDivide<T extends number | bigint>(a: T, b: NonZero<T>): T;
16
23
  export declare function expandDecimals(n: BigNumberish, decimals: number): bigint;
17
24
  export declare function basisPointsToFloat(basisPoints: bigint): bigint;
18
25
  export declare function getBasisPoints(numerator: bigint, denominator: bigint, shouldRoundUp?: boolean): bigint;
@@ -129,7 +136,7 @@ type DeserializeBigIntInObject<T> = {
129
136
  };
130
137
  export declare function serializeBigIntsInObject<T extends object>(obj: T): SerializedBigIntsInObject<T>;
131
138
  export declare function deserializeBigIntsInObject<T extends object>(obj: T): DeserializeBigIntInObject<T>;
132
- export declare function calculateDisplayDecimals(price?: bigint, decimals?: number, visualMultiplier?: number, isStable?: boolean): 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
139
+ export declare function calculateDisplayDecimals(price?: bigint, decimals?: number, visualMultiplier?: number, isStable?: boolean): 5 | 2 | 3 | 4 | 6 | 7 | 8 | 9;
133
140
  export declare function clamp(value: number, min: number, max: number): number;
134
141
  export declare function absDiffBps(value: bigint, base: bigint): bigint;
135
142
  export {};
@@ -1,8 +1,9 @@
1
1
  import { MarketsInfoData } from "../../types/markets";
2
+ import { SwapPricingType } from "../../types/orders";
2
3
  import { SwapStrategyForSwapOrders } from "../../types/swapStrategy";
3
4
  import { TokenData } from "../../types/tokens";
4
5
  import { ExternalSwapQuoteParams, SwapOptimizationOrderArray } from "../../types/trade";
5
- export declare function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, }: {
6
+ export declare function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType, allowSameTokenSwap, }: {
6
7
  chainId: number;
7
8
  amountIn: bigint;
8
9
  tokenIn: TokenData;
@@ -10,13 +11,17 @@ export declare function buildSwapStrategy({ amountIn, tokenIn, tokenOut, markets
10
11
  marketsInfoData: MarketsInfoData | undefined;
11
12
  swapOptimizationOrder: SwapOptimizationOrderArray | undefined;
12
13
  externalSwapQuoteParams: ExternalSwapQuoteParams;
14
+ swapPricingType: SwapPricingType;
15
+ allowSameTokenSwap: boolean;
13
16
  }): SwapStrategyForSwapOrders;
14
- export declare function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, }: {
17
+ export declare function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, swapPricingType, allowSameTokenSwap, }: {
15
18
  chainId: number;
16
19
  amountOut: bigint;
17
20
  tokenIn: TokenData;
18
21
  tokenOut: TokenData;
19
22
  marketsInfoData: MarketsInfoData | undefined;
20
- externalSwapQuoteParams: ExternalSwapQuoteParams;
23
+ externalSwapQuoteParams: ExternalSwapQuoteParams | undefined;
21
24
  swapOptimizationOrder: SwapOptimizationOrderArray | undefined;
25
+ swapPricingType: SwapPricingType;
26
+ allowSameTokenSwap: boolean;
22
27
  }): SwapStrategyForSwapOrders;
@@ -1,5 +1,6 @@
1
1
  import { GasLimitsConfig } from "../../types/fees";
2
2
  import { MarketsInfoData } from "../../types/markets";
3
+ import { SwapPricingType } from "../../types/orders";
3
4
  import { TokensData } from "../../types/tokens";
4
5
  import { FindSwapPath } from "../../types/trade";
5
6
  export declare const getWrappedAddress: (chainId: number, address: string | undefined) => import("../../types/tokens").ERC20Address | undefined;
@@ -16,7 +17,7 @@ export declare const createFindSwapPath: (params: {
16
17
  gasLimits: GasLimitsConfig;
17
18
  tokensData: TokensData;
18
19
  } | undefined;
19
- isExpressFeeSwap: boolean | undefined;
20
+ swapPricingType: SwapPricingType | undefined;
20
21
  disabledMarkets?: string[] | undefined;
21
22
  manualPath?: string[] | undefined;
22
23
  }) => FindSwapPath;
@@ -1,11 +1,16 @@
1
1
  import { GasLimitsConfig } from "../../types/fees";
2
2
  import { MarketsInfoData } from "../../types/markets";
3
+ import { SwapPricingType } from "../../types/orders";
3
4
  import { TokensData } from "../../types/tokens";
4
5
  import { MarketEdge, MarketEdgeLiquidityGetter, NaiveNetworkEstimator, NaiveSwapEstimator, SwapEstimator, SwapPaths } from "../../types/trade";
5
6
  import { MarketsGraph } from "./buildMarketsAdjacencyGraph";
6
- export declare const createSwapEstimator: (marketsInfoData: MarketsInfoData, isAtomicSwap: boolean) => SwapEstimator;
7
+ export declare const createSwapEstimator: (marketsInfoData: MarketsInfoData, swapPricingType: SwapPricingType) => SwapEstimator;
7
8
  export declare const createMarketEdgeLiquidityGetter: (marketsInfoData: MarketsInfoData) => MarketEdgeLiquidityGetter;
8
- export declare const createNaiveSwapEstimator: (marketsInfoData: MarketsInfoData, isAtomicSwap: boolean) => NaiveSwapEstimator;
9
+ /**
10
+ TODO MLTCH does naive estimator need to know about swap pricing type?
11
+ Its naive for a reason and i think it would work the same without knowing about it
12
+ */
13
+ export declare const createNaiveSwapEstimator: (marketsInfoData: MarketsInfoData, swapPricingType: SwapPricingType) => NaiveSwapEstimator;
9
14
  export declare const createNaiveNetworkEstimator: ({ gasLimits, tokensData, gasPrice, chainId, }: {
10
15
  gasLimits: GasLimitsConfig;
11
16
  tokensData: TokensData;
@@ -1,4 +1,5 @@
1
1
  import { MarketInfo, MarketsInfoData } from "../../types/markets";
2
+ import { SwapPricingType } from "../../types/orders";
2
3
  import { SwapPathStats, SwapStats } from "../../types/trade";
3
4
  export declare function getSwapCapacityUsd(marketInfo: MarketInfo, isLong: boolean): bigint;
4
5
  export declare function getSwapPathOutputAddresses(p: {
@@ -26,7 +27,7 @@ export declare function getSwapPathStats(p: {
26
27
  usdIn: bigint;
27
28
  shouldUnwrapNativeToken: boolean;
28
29
  shouldApplyPriceImpact: boolean;
29
- isAtomicSwap: boolean;
30
+ swapPricingType: SwapPricingType;
30
31
  }): SwapPathStats | undefined;
31
32
  export declare function getSwapStats(p: {
32
33
  marketInfo: MarketInfo;
@@ -34,7 +35,7 @@ export declare function getSwapStats(p: {
34
35
  tokenOutAddress: string;
35
36
  usdIn: bigint;
36
37
  shouldApplyPriceImpact: boolean;
37
- isAtomicSwap: boolean;
38
+ swapPricingType: SwapPricingType;
38
39
  }): SwapStats;
39
40
  export declare function getMaxSwapPathLiquidity(p: {
40
41
  marketsInfoData: MarketsInfoData;
@@ -15,6 +15,7 @@ export declare function getSwapAmountsByFromValue(p: {
15
15
  chainId: number;
16
16
  externalSwapQuoteParams: ExternalSwapQuoteParams | undefined;
17
17
  findSwapPath: FindSwapPath;
18
+ allowSameTokenSwap: boolean;
18
19
  }): SwapAmounts;
19
20
  export declare function getSwapAmountsByToValue(p: {
20
21
  tokenIn: TokenData;
@@ -29,5 +30,6 @@ export declare function getSwapAmountsByToValue(p: {
29
30
  chainId: number;
30
31
  externalSwapQuoteParams: ExternalSwapQuoteParams | undefined;
31
32
  findSwapPath: FindSwapPath;
33
+ allowSameTokenSwap: boolean;
32
34
  }): SwapAmounts;
33
- export declare function getSwapPathComparator(order?: SwapOptimizationOrderArray | undefined): (a: SwapRoute, b: SwapRoute) => 0 | 1 | -1;
35
+ export declare function getSwapPathComparator(order?: SwapOptimizationOrderArray | undefined): (a: SwapRoute, b: SwapRoute) => 1 | 0 | -1;
@@ -1,3 +1,4 @@
1
+ import { ContractsChainId } from "../configs/chains";
1
2
  import { ContractPrice, Token, TokenData, TokenPrices, TokensData, TokensRatio, TokensRatioAndSlippage } from "../types/tokens";
2
3
  export declare function parseContractPrice(price: bigint, tokenDecimals: number): bigint;
3
4
  export declare function convertToContractPrice(price: bigint, tokenDecimals: number): ContractPrice;
@@ -47,3 +48,5 @@ export declare function getTokensRatioByPrice(p: {
47
48
  fromPrice: bigint;
48
49
  toPrice: bigint;
49
50
  }): TokensRatio;
51
+ export declare function getGmToken(chainId: ContractsChainId, marketTokenAddress: string): Token;
52
+ export declare function getGlvToken(chainId: ContractsChainId, glvTokenAddress: string): Token;
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@gmx-io/sdk",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/gmx-io/gmx-interface",
8
+ "directory": "sdk"
9
+ },
5
10
  "main": "./build/cjs/src/index.js",
6
11
  "module": "./build/esm/src/index.js",
7
12
  "types": "./build/types/src/index.d.ts",
@@ -48,12 +53,19 @@
48
53
  "prepare": "ts-patch install -s",
49
54
  "test": "vitest",
50
55
  "test:ci": "vitest run",
56
+ "test:multicall": "vitest run --config vitest.multicall.config.ts",
51
57
  "build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > build/cjs/src/package.json",
52
58
  "build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > build/esm/src/package.json",
53
59
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
54
- "build:subsquid": "./node_modules/@graphql-codegen/cli/cjs/bin.js -c subsquid-codegen.ts",
55
- "tscheck": "tsc -p tsconfig.json --noEmit",
60
+ "build:subsquid": "./node_modules/@graphql-codegen/cli/cjs/bin.js -c subsquid-codegen.ts && npx prettier --write src/types/subsquid.ts",
61
+ "tscheck": "tsc -p tsconfig.json --noEmit --incremental",
62
+ "tscheck:ci": "tsc -p tsconfig.json --noEmit",
63
+ "lint": "cd .. && node node_modules/.bin/eslint sdk --fix --cache --cache-location .eslintcache",
64
+ "lint:ci": "cd .. && node node_modules/.bin/eslint sdk --max-warnings=0",
56
65
  "clean": "rm -rf build/**/*.tsbuildinfo",
66
+ "clean:cache": "rm -rf ../.eslintcache ../tsconfig.tsbuildinfo build/**/*.tsbuildinfo",
67
+ "clean:lint": "rm -rf ../.eslintcache",
68
+ "clean:ts": "rm -rf ../tsconfig.tsbuildinfo build/**/*.tsbuildinfo",
57
69
  "build": "rm -rf build && yarn build:subsquid && yarn build:types && yarn build:cjs && yarn build:esm && yarn clean"
58
70
  },
59
71
  "publishConfig": {
@@ -75,7 +87,7 @@
75
87
  "viem": "^2.37.1"
76
88
  },
77
89
  "devDependencies": {
78
- "@babel/plugin-proposal-private-property-in-object": "7.21.11",
90
+ "@babel/plugin-transform-private-property-in-object": "^7.25.9",
79
91
  "@graphql-codegen/cli": "5.0.6",
80
92
  "@graphql-codegen/client-preset": "4.8.1",
81
93
  "@graphql-codegen/typescript": "4.1.6",
@@ -87,7 +99,7 @@
87
99
  "tsx": "4.19.0",
88
100
  "typescript-transform-paths": "3.5.1",
89
101
  "viem": "2.39.0",
90
- "vitest": "3.0.4"
102
+ "vitest": "^3.0.5"
91
103
  },
92
104
  "files": [
93
105
  "build"
@@ -1,133 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = [
4
- {
5
- inputs: [
6
- {
7
- internalType: "address",
8
- name: "account",
9
- type: "address",
10
- },
11
- {
12
- internalType: "address",
13
- name: "token",
14
- type: "address",
15
- },
16
- ],
17
- name: "EmptyMultichainTransferInAmount",
18
- type: "error",
19
- },
20
- {
21
- inputs: [
22
- {
23
- internalType: "address",
24
- name: "account",
25
- type: "address",
26
- },
27
- {
28
- internalType: "address",
29
- name: "token",
30
- type: "address",
31
- },
32
- {
33
- internalType: "uint256",
34
- name: "balance",
35
- type: "uint256",
36
- },
37
- {
38
- internalType: "uint256",
39
- name: "amount",
40
- type: "uint256",
41
- },
42
- ],
43
- name: "InsufficientMultichainBalance",
44
- type: "error",
45
- },
46
- {
47
- inputs: [
48
- {
49
- internalType: "address",
50
- name: "endpoint",
51
- type: "address",
52
- },
53
- ],
54
- name: "InvalidMultichainEndpoint",
55
- type: "error",
56
- },
57
- {
58
- inputs: [
59
- {
60
- internalType: "address",
61
- name: "provider",
62
- type: "address",
63
- },
64
- ],
65
- name: "InvalidMultichainProvider",
66
- type: "error",
67
- },
68
- {
69
- inputs: [
70
- {
71
- internalType: "contract DataStore",
72
- name: "dataStore",
73
- type: "DataStore",
74
- },
75
- {
76
- internalType: "address",
77
- name: "account",
78
- type: "address",
79
- },
80
- {
81
- internalType: "address",
82
- name: "token",
83
- type: "address",
84
- },
85
- ],
86
- name: "getMultichainBalanceAmount",
87
- outputs: [
88
- {
89
- internalType: "uint256",
90
- name: "",
91
- type: "uint256",
92
- },
93
- ],
94
- stateMutability: "view",
95
- type: "function",
96
- },
97
- {
98
- inputs: [
99
- {
100
- internalType: "contract DataStore",
101
- name: "dataStore",
102
- type: "DataStore",
103
- },
104
- {
105
- internalType: "address",
106
- name: "endpoint",
107
- type: "address",
108
- },
109
- ],
110
- name: "validateMultichainEndpoint",
111
- outputs: [],
112
- stateMutability: "view",
113
- type: "function",
114
- },
115
- {
116
- inputs: [
117
- {
118
- internalType: "contract DataStore",
119
- name: "dataStore",
120
- type: "DataStore",
121
- },
122
- {
123
- internalType: "address",
124
- name: "provider",
125
- type: "address",
126
- },
127
- ],
128
- name: "validateMultichainProvider",
129
- outputs: [],
130
- stateMutability: "view",
131
- type: "function",
132
- },
133
- ];
@@ -1,131 +0,0 @@
1
- export default [
2
- {
3
- inputs: [
4
- {
5
- internalType: "address",
6
- name: "account",
7
- type: "address",
8
- },
9
- {
10
- internalType: "address",
11
- name: "token",
12
- type: "address",
13
- },
14
- ],
15
- name: "EmptyMultichainTransferInAmount",
16
- type: "error",
17
- },
18
- {
19
- inputs: [
20
- {
21
- internalType: "address",
22
- name: "account",
23
- type: "address",
24
- },
25
- {
26
- internalType: "address",
27
- name: "token",
28
- type: "address",
29
- },
30
- {
31
- internalType: "uint256",
32
- name: "balance",
33
- type: "uint256",
34
- },
35
- {
36
- internalType: "uint256",
37
- name: "amount",
38
- type: "uint256",
39
- },
40
- ],
41
- name: "InsufficientMultichainBalance",
42
- type: "error",
43
- },
44
- {
45
- inputs: [
46
- {
47
- internalType: "address",
48
- name: "endpoint",
49
- type: "address",
50
- },
51
- ],
52
- name: "InvalidMultichainEndpoint",
53
- type: "error",
54
- },
55
- {
56
- inputs: [
57
- {
58
- internalType: "address",
59
- name: "provider",
60
- type: "address",
61
- },
62
- ],
63
- name: "InvalidMultichainProvider",
64
- type: "error",
65
- },
66
- {
67
- inputs: [
68
- {
69
- internalType: "contract DataStore",
70
- name: "dataStore",
71
- type: "DataStore",
72
- },
73
- {
74
- internalType: "address",
75
- name: "account",
76
- type: "address",
77
- },
78
- {
79
- internalType: "address",
80
- name: "token",
81
- type: "address",
82
- },
83
- ],
84
- name: "getMultichainBalanceAmount",
85
- outputs: [
86
- {
87
- internalType: "uint256",
88
- name: "",
89
- type: "uint256",
90
- },
91
- ],
92
- stateMutability: "view",
93
- type: "function",
94
- },
95
- {
96
- inputs: [
97
- {
98
- internalType: "contract DataStore",
99
- name: "dataStore",
100
- type: "DataStore",
101
- },
102
- {
103
- internalType: "address",
104
- name: "endpoint",
105
- type: "address",
106
- },
107
- ],
108
- name: "validateMultichainEndpoint",
109
- outputs: [],
110
- stateMutability: "view",
111
- type: "function",
112
- },
113
- {
114
- inputs: [
115
- {
116
- internalType: "contract DataStore",
117
- name: "dataStore",
118
- type: "DataStore",
119
- },
120
- {
121
- internalType: "address",
122
- name: "provider",
123
- type: "address",
124
- },
125
- ],
126
- name: "validateMultichainProvider",
127
- outputs: [],
128
- stateMutability: "view",
129
- type: "function",
130
- },
131
- ];