@gmx-io/sdk 2.9.3 → 3.0.1

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 (163) hide show
  1. package/build/cjs/src/abis/RatioVesterReader.js +45 -0
  2. package/build/cjs/src/abis/index.js +2 -0
  3. package/build/cjs/src/clients/v1/modules/oracle.js +15 -0
  4. package/build/cjs/src/clients/v1/modules/oracle.spec.js +20 -0
  5. package/build/cjs/src/clients/v1/modules/orders/helpers.js +16 -12
  6. package/build/cjs/src/clients/v1/modules/orders/helpers.spec.js +21 -0
  7. package/build/cjs/src/clients/v1/modules/orders/orders.js +4 -0
  8. package/build/cjs/src/clients/v1/modules/orders/utils.js +1 -0
  9. package/build/cjs/src/clients/v2/__tests__/subaccount.spec.js +74 -17
  10. package/build/cjs/src/clients/v2/__tests__/subaccountLifecycle.spec.js +1 -1
  11. package/build/cjs/src/clients/v2/__tests__/testUtil.js +14 -2
  12. package/build/cjs/src/clients/v2/index.js +28 -7
  13. package/build/cjs/src/clients/v2/solana.spec.js +81 -4
  14. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +56 -0
  15. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +852 -0
  16. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +105 -0
  17. package/build/cjs/src/configs/contracts.js +10 -0
  18. package/build/cjs/src/configs/dataStore.js +22 -4
  19. package/build/cjs/src/configs/express.js +1 -2
  20. package/build/cjs/src/configs/markets.js +50 -0
  21. package/build/cjs/src/configs/tokens.js +12 -0
  22. package/build/cjs/src/test/mockCrossFetch.js +1 -0
  23. package/build/cjs/src/utils/__tests__/fees.spec.js +52 -0
  24. package/build/cjs/src/utils/__tests__/gmsolUnits.spec.js +101 -0
  25. package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +66 -0
  26. package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +6 -6
  27. package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +40 -0
  28. package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +4 -2
  29. package/build/cjs/src/utils/__tests__/tokens.spec.js +63 -0
  30. package/build/cjs/src/utils/errors/transactionsErrors.js +6 -0
  31. package/build/cjs/src/utils/fees/index.js +5 -0
  32. package/build/cjs/src/utils/fees/priceImpact.js +39 -6
  33. package/build/cjs/src/utils/gmsol/index.js +15 -0
  34. package/build/cjs/src/utils/gmsol/units.js +106 -0
  35. package/build/cjs/src/utils/http/http.js +21 -25
  36. package/build/cjs/src/utils/http/httpFallback.js +3 -3
  37. package/build/cjs/src/utils/http/validation.js +9 -1
  38. package/build/cjs/src/utils/markets/hashKeys.js +8 -0
  39. package/build/cjs/src/utils/markets/multicall.js +10 -0
  40. package/build/cjs/src/utils/markets/utils.js +2 -0
  41. package/build/cjs/src/utils/multichain/__tests__/api.spec.js +49 -0
  42. package/build/cjs/src/utils/multichain/api.js +29 -2
  43. package/build/cjs/src/utils/orderTransactions/utils.js +63 -5
  44. package/build/cjs/src/utils/orders/api.js +66 -3
  45. package/build/cjs/src/utils/positions/__tests__/liquidationImpact.spec.js +44 -0
  46. package/build/cjs/src/utils/positions/__tests__/liquidationPrice.spec.js +159 -2
  47. package/build/cjs/src/utils/positions/__tests__/trackingCollateral.spec.js +395 -0
  48. package/build/cjs/src/utils/positions/api.js +4 -0
  49. package/build/cjs/src/utils/positions/utils.js +119 -44
  50. package/build/cjs/src/utils/prices/api.js +2 -2
  51. package/build/cjs/src/utils/referrals/api.js +5 -4
  52. package/build/cjs/src/utils/subaccount/generateSubaccount.js +14 -14
  53. package/build/cjs/src/utils/subaccount/sdkClient.js +40 -19
  54. package/build/cjs/src/utils/tokens/utils.js +23 -7
  55. package/build/cjs/src/utils/trade/__tests__/decrease.spec.js +152 -0
  56. package/build/cjs/src/utils/trade/__tests__/gmsolTradeMath.spec.js +43 -0
  57. package/build/cjs/src/utils/trade/decrease.js +113 -33
  58. package/build/cjs/src/utils/trade/decreaseMarginCheck.js +38 -2
  59. package/build/cjs/src/utils/trade/decreaseOutputs.js +20 -5
  60. package/build/cjs/src/utils/trade/increase.js +30 -11
  61. package/build/cjs/src/utils/trade/increaseMarginCheck.js +14 -35
  62. package/build/esm/src/abis/RatioVesterReader.js +43 -0
  63. package/build/esm/src/abis/index.js +2 -0
  64. package/build/esm/src/clients/v1/modules/oracle.js +15 -0
  65. package/build/esm/src/clients/v1/modules/oracle.spec.js +18 -0
  66. package/build/esm/src/clients/v1/modules/orders/helpers.js +17 -13
  67. package/build/esm/src/clients/v1/modules/orders/helpers.spec.js +21 -0
  68. package/build/esm/src/clients/v1/modules/orders/orders.js +4 -0
  69. package/build/esm/src/clients/v1/modules/orders/utils.js +1 -0
  70. package/build/esm/src/clients/v2/__tests__/subaccount.spec.js +74 -17
  71. package/build/esm/src/clients/v2/__tests__/subaccountLifecycle.spec.js +2 -2
  72. package/build/esm/src/clients/v2/__tests__/testUtil.js +13 -2
  73. package/build/esm/src/clients/v2/index.js +29 -8
  74. package/build/esm/src/clients/v2/solana.spec.js +79 -2
  75. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +56 -0
  76. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +852 -0
  77. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +105 -0
  78. package/build/esm/src/configs/contracts.js +10 -0
  79. package/build/esm/src/configs/dataStore.js +14 -0
  80. package/build/esm/src/configs/express.js +0 -1
  81. package/build/esm/src/configs/markets.js +50 -0
  82. package/build/esm/src/configs/tokens.js +12 -0
  83. package/build/esm/src/test/mockCrossFetch.js +1 -0
  84. package/build/esm/src/utils/__tests__/fees.spec.js +53 -1
  85. package/build/esm/src/utils/__tests__/gmsolUnits.spec.js +99 -0
  86. package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +68 -2
  87. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +6 -6
  88. package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +40 -0
  89. package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +5 -3
  90. package/build/esm/src/utils/__tests__/tokens.spec.js +64 -1
  91. package/build/esm/src/utils/errors/transactionsErrors.js +6 -0
  92. package/build/esm/src/utils/fees/index.js +5 -0
  93. package/build/esm/src/utils/fees/priceImpact.js +36 -5
  94. package/build/esm/src/utils/gmsol/index.js +1 -0
  95. package/build/esm/src/utils/gmsol/units.js +97 -0
  96. package/build/esm/src/utils/http/http.js +21 -25
  97. package/build/esm/src/utils/http/httpFallback.js +3 -3
  98. package/build/esm/src/utils/http/validation.js +7 -0
  99. package/build/esm/src/utils/markets/hashKeys.js +9 -1
  100. package/build/esm/src/utils/markets/multicall.js +10 -0
  101. package/build/esm/src/utils/markets/utils.js +2 -0
  102. package/build/esm/src/utils/multichain/__tests__/api.spec.js +46 -0
  103. package/build/esm/src/utils/multichain/api.js +29 -2
  104. package/build/esm/src/utils/orderTransactions/utils.js +59 -5
  105. package/build/esm/src/utils/orders/api.js +64 -2
  106. package/build/esm/src/utils/positions/__tests__/liquidationImpact.spec.js +42 -0
  107. package/build/esm/src/utils/positions/__tests__/liquidationPrice.spec.js +161 -4
  108. package/build/esm/src/utils/positions/__tests__/trackingCollateral.spec.js +393 -0
  109. package/build/esm/src/utils/positions/api.js +4 -0
  110. package/build/esm/src/utils/positions/utils.js +115 -44
  111. package/build/esm/src/utils/prices/api.js +2 -2
  112. package/build/esm/src/utils/referrals/api.js +6 -5
  113. package/build/esm/src/utils/subaccount/generateSubaccount.js +13 -14
  114. package/build/esm/src/utils/subaccount/sdkClient.js +38 -19
  115. package/build/esm/src/utils/tokens/utils.js +20 -6
  116. package/build/esm/src/utils/trade/__tests__/decrease.spec.js +150 -0
  117. package/build/esm/src/utils/trade/__tests__/gmsolTradeMath.spec.js +43 -0
  118. package/build/esm/src/utils/trade/decrease.js +115 -35
  119. package/build/esm/src/utils/trade/decreaseMarginCheck.js +37 -2
  120. package/build/esm/src/utils/trade/decreaseOutputs.js +19 -5
  121. package/build/esm/src/utils/trade/increase.js +32 -13
  122. package/build/esm/src/utils/trade/increaseMarginCheck.js +18 -39
  123. package/build/tsconfig.tsbuildinfo +1 -1
  124. package/build/types/src/abis/RatioVesterReader.d.ts +74 -0
  125. package/build/types/src/abis/index.d.ts +73 -0
  126. package/build/types/src/clients/v1/modules/oracle.d.ts +6 -1
  127. package/build/types/src/clients/v1/modules/oracle.spec.d.ts +1 -0
  128. package/build/types/src/clients/v2/__tests__/testUtil.d.ts +1 -0
  129. package/build/types/src/clients/v2/index.d.ts +26 -5
  130. package/build/types/src/codegen/prebuilt/index.d.ts +1113 -100
  131. package/build/types/src/configs/contracts.d.ts +10 -0
  132. package/build/types/src/configs/dataStore.d.ts +8 -0
  133. package/build/types/src/configs/express.d.ts +0 -1
  134. package/build/types/src/utils/__tests__/gmsolUnits.spec.d.ts +1 -0
  135. package/build/types/src/utils/errors/parseError.d.ts +1 -1
  136. package/build/types/src/utils/errors/transactionsErrors.d.ts +6 -0
  137. package/build/types/src/utils/fees/priceImpact.d.ts +10 -0
  138. package/build/types/src/utils/gmsol/index.d.ts +1 -0
  139. package/build/types/src/utils/gmsol/units.d.ts +53 -0
  140. package/build/types/src/utils/http/types.d.ts +1 -0
  141. package/build/types/src/utils/http/validation.d.ts +1 -0
  142. package/build/types/src/utils/markets/types.d.ts +5 -2
  143. package/build/types/src/utils/multichain/api.d.ts +4 -1
  144. package/build/types/src/utils/orderTransactions/utils.d.ts +19 -4
  145. package/build/types/src/utils/orders/api.d.ts +2 -1
  146. package/build/types/src/utils/orders/types.d.ts +24 -0
  147. package/build/types/src/utils/positions/__tests__/liquidationImpact.spec.d.ts +1 -0
  148. package/build/types/src/utils/positions/__tests__/trackingCollateral.spec.d.ts +1 -0
  149. package/build/types/src/utils/positions/types.d.ts +2 -0
  150. package/build/types/src/utils/positions/utils.d.ts +30 -0
  151. package/build/types/src/utils/prices/api.d.ts +2 -0
  152. package/build/types/src/utils/referrals/types.d.ts +4 -0
  153. package/build/types/src/utils/subaccount/generateSubaccount.d.ts +9 -4
  154. package/build/types/src/utils/subaccount/sdkClient.d.ts +7 -1
  155. package/build/types/src/utils/subaccount/types.d.ts +2 -0
  156. package/build/types/src/utils/tokens/types.d.ts +1 -0
  157. package/build/types/src/utils/tokens/utils.d.ts +6 -0
  158. package/build/types/src/utils/trade/__tests__/decrease.spec.d.ts +1 -0
  159. package/build/types/src/utils/trade/decrease.d.ts +3 -0
  160. package/build/types/src/utils/trade/decreaseMarginCheck.d.ts +11 -0
  161. package/build/types/src/utils/trade/decreaseOutputs.d.ts +7 -2
  162. package/build/types/src/utils/trade/increaseMarginCheck.d.ts +1 -0
  163. package/package.json +10 -1
@@ -29,6 +29,8 @@ export declare const CONTRACTS: {
29
29
  GmxVester: string;
30
30
  GlpVester: string;
31
31
  AffiliateVester: string;
32
+ OrphanRatioVester: string;
33
+ RatioVesterReader: string;
32
34
  PositionRouter: string;
33
35
  UniswapGmxEthPool: string;
34
36
  ReferralStorage: string;
@@ -93,6 +95,8 @@ export declare const CONTRACTS: {
93
95
  GmxVester: string;
94
96
  GlpVester: string;
95
97
  AffiliateVester: string;
98
+ OrphanRatioVester: string;
99
+ RatioVesterReader: string;
96
100
  PositionRouter: string;
97
101
  TraderJoeGmxAvaxPool: string;
98
102
  ReferralStorage: string;
@@ -186,6 +190,8 @@ export declare const CONTRACTS: {
186
190
  GmxVester: "0x0000000000000000000000000000000000000000";
187
191
  GlpVester: "0x0000000000000000000000000000000000000000";
188
192
  AffiliateVester: "0x0000000000000000000000000000000000000000";
193
+ OrphanRatioVester: "0x0000000000000000000000000000000000000000";
194
+ RatioVesterReader: "0x0000000000000000000000000000000000000000";
189
195
  Router: "0x0000000000000000000000000000000000000000";
190
196
  GovToken: "0x0000000000000000000000000000000000000000";
191
197
  ES_GMX_IOU: "0x0000000000000000000000000000000000000000";
@@ -221,6 +227,8 @@ export declare const CONTRACTS: {
221
227
  GmxVester: "0x0000000000000000000000000000000000000000";
222
228
  GlpVester: "0x0000000000000000000000000000000000000000";
223
229
  AffiliateVester: "0x0000000000000000000000000000000000000000";
230
+ OrphanRatioVester: "0x0000000000000000000000000000000000000000";
231
+ RatioVesterReader: "0x0000000000000000000000000000000000000000";
224
232
  PositionRouter: "0x0000000000000000000000000000000000000000";
225
233
  TraderJoeGmxAvaxPool: "0x0000000000000000000000000000000000000000";
226
234
  ReferralStorage: string;
@@ -311,6 +319,8 @@ export declare const CONTRACTS: {
311
319
  GmxVester: "0x0000000000000000000000000000000000000000";
312
320
  GlpVester: "0x0000000000000000000000000000000000000000";
313
321
  AffiliateVester: "0x0000000000000000000000000000000000000000";
322
+ OrphanRatioVester: "0x0000000000000000000000000000000000000000";
323
+ RatioVesterReader: "0x0000000000000000000000000000000000000000";
314
324
  Router: "0x0000000000000000000000000000000000000000";
315
325
  VaultReader: "0x0000000000000000000000000000000000000000";
316
326
  Reader: "0x0000000000000000000000000000000000000000";
@@ -7,6 +7,8 @@ export declare const SWAP_IMPACT_EXPONENT_FACTOR_KEY: string;
7
7
  export declare const SWAP_FEE_FACTOR_KEY: string;
8
8
  export declare const ATOMIC_SWAP_FEE_FACTOR_KEY: string;
9
9
  export declare const WITHDRAWAL_FEE_FACTOR_KEY: string;
10
+ export declare const DEPOSIT_FEE_FACTOR_KEY: string;
11
+ export declare const SWAP_FEE_RECEIVER_FACTOR_KEY: string;
10
12
  export declare const FEE_RECEIVER_DEPOSIT_FACTOR_KEY: string;
11
13
  export declare const BORROWING_FEE_RECEIVER_FACTOR_KEY: string;
12
14
  export declare const FEE_RECEIVER_WITHDRAWAL_FACTOR_KEY: string;
@@ -105,9 +107,12 @@ export declare const BASE_BORROWING_FACTOR: string;
105
107
  export declare const ABOVE_OPTIMAL_USAGE_BORROWING_FACTOR: string;
106
108
  export declare const SUBACCOUNT_EXPIRES_AT: string;
107
109
  export declare const MULTICHAIN_BALANCE: string;
110
+ export declare const POSITION_LAST_SRC_CHAIN_ID: string;
108
111
  export declare const PRICE_FEED_KEY: string;
109
112
  export declare const GASLESS_FEATURE_DISABLED_KEY: string;
110
113
  export declare const SIGNAL_UNSTAKE_FEATURE_DISABLED_KEY: string;
114
+ export declare const INCENTIVE_VESTER_DEPOSIT_FEATURE_DISABLED_KEY: string;
115
+ export declare const INCENTIVE_VESTER_CLAIM_FEATURE_DISABLED_KEY: string;
111
116
  export declare const GELATO_RELAY_FEE_MULTIPLIER_FACTOR_KEY: string;
112
117
  export declare const REQUEST_EXPIRATION_TIME_KEY: string;
113
118
  export declare const GMX_SIMULATION_ORIGIN: string;
@@ -191,8 +196,11 @@ export declare function subaccountIntegrationIdKey(account: string, subaccount:
191
196
  export declare function subaccountRevocationCounterKey(account: string, subaccount: string): string;
192
197
  export declare function subaccountAutoTopUpAmountKey(account: string, subaccount: string): string;
193
198
  export declare function multichainBalanceKey(account: string, token: string): string;
199
+ export declare function positionLastSrcChainIdKey(positionKey: string): string;
194
200
  export declare function priceFeedKey(token: string): string;
195
201
  export declare function gaslessFeatureDisabledKey(module: string): string;
196
202
  export declare function signalUnstakeFeatureDisabledKey(rewardRouter: string): string;
203
+ export declare function incentiveVesterDepositFeatureDisabledKey(vester: string): string;
204
+ export declare function incentiveVesterClaimFeatureDisabledKey(vester: string): string;
197
205
  export declare function claimTermsKey(distributionId: bigint): string;
198
206
  export declare function claimsDisabledKey(distributionId: bigint): string;
@@ -1,5 +1,4 @@
1
1
  import { Token } from "../utils/tokens/types";
2
- export declare const SUBACCOUNT_MESSAGE = "Generate a GMX 1CT (One-Click Trading) session. Only sign this message on a trusted website.";
3
2
  export declare const SUBACCOUNT_DOCS_URL = "https://docs.gmx.io/docs/trading/overview/#express-trading-and-one-click-trading";
4
3
  export declare const DEFAULT_SUBACCOUNT_EXPIRY_DURATION: number;
5
4
  export declare const DEFAULT_SUBACCOUNT_MAX_ALLOWED_COUNT = 90;
@@ -2,7 +2,7 @@ import { AbiParameterToPrimitiveType, ContractErrorName, ExtractAbiItem } from "
2
2
  import { abis } from "../../abis";
3
3
  import { CustomErrorName, TxErrorType } from "./transactionsErrors";
4
4
  export declare function extractErrorDataFromViemError(error: any): string | undefined;
5
- export type OrderErrorContext = "simulation" | "gasLimit" | "gasPrice" | "bestNonce" | "sending" | "pending" | "relayer" | "minting" | "execution" | "unknown";
5
+ export type OrderErrorContext = "simulation" | "gasLimit" | "gasPrice" | "bestNonce" | "sending" | "pending" | "pendingWalletBatch" | "relayer" | "minting" | "execution" | "unknown";
6
6
  export type ErrorLike = {
7
7
  message?: string;
8
8
  stack?: string;
@@ -14,6 +14,7 @@ export declare enum CustomErrorName {
14
14
  DisabledMarket = "DisabledMarket",
15
15
  EmptyDesignatedVesters = "EmptyDesignatedVesters",
16
16
  EmptyStakeAmount = "EmptyStakeAmount",
17
+ EmptyVesterWithdrawal = "EmptyVesterWithdrawal",
17
18
  EndOfOracleSimulation = "EndOfOracleSimulation",
18
19
  ExternalCallFailed = "ExternalCallFailed",
19
20
  InsufficientBridgeOutputAmount = "InsufficientBridgeOutputAmount",
@@ -29,8 +30,10 @@ export declare enum CustomErrorName {
29
30
  OrderNotFulfillableAtAcceptablePrice = "OrderNotFulfillableAtAcceptablePrice",
30
31
  InsufficientSwapOutputAmount = "InsufficientSwapOutputAmount",
31
32
  InsufficientStrictTransferAllowance = "InsufficientStrictTransferAllowance",
33
+ InsufficientVesterBacking = "InsufficientVesterBacking",
32
34
  InvalidCollateralTokenForMarket = "InvalidCollateralTokenForMarket",
33
35
  InvalidDecreaseOrderSize = "InvalidDecreaseOrderSize",
36
+ InvalidDesignatedVester = "InvalidDesignatedVester",
34
37
  InvalidOraclePrice = "InvalidOraclePrice",
35
38
  LiquidatablePosition = "LiquidatablePosition",
36
39
  MarketNotFound = "MarketNotFound",
@@ -58,13 +61,16 @@ export declare enum CustomErrorName {
58
61
  TransferNotSignalled = "TransferNotSignalled",
59
62
  TransferVesterConfigChanged = "TransferVesterConfigChanged",
60
63
  UnableToWithdrawCollateral = "UnableToWithdrawCollateral",
64
+ UnbackedPairAmountLocked = "UnbackedPairAmountLocked",
61
65
  UnstakeAmountExceedsStake = "UnstakeAmountExceedsStake",
62
66
  UnstakeNotSignalled = "UnstakeNotSignalled",
63
67
  UsdDeltaExceedsLongOpenInterest = "UsdDeltaExceedsLongOpenInterest",
64
68
  UsdDeltaExceedsPoolValue = "UsdDeltaExceedsPoolValue",
65
69
  UsdDeltaExceedsShortOpenInterest = "UsdDeltaExceedsShortOpenInterest",
66
70
  VesterAccountFrozen = "VesterAccountFrozen",
71
+ VesterDeactivated = "VesterDeactivated",
67
72
  VesterProvisioningNotComplete = "VesterProvisioningNotComplete",
73
+ VestingCapExceeded = "VestingCapExceeded",
68
74
  VestingReceiverNotFresh = "VestingReceiverNotFresh",
69
75
  VestingSenderHasOpenSession = "VestingSenderHasOpenSession"
70
76
  }
@@ -50,12 +50,22 @@ export declare function getProportionalPendingImpactValues({ sizeInUsd, pendingI
50
50
  proportionalPendingImpactDeltaAmount: bigint;
51
51
  proportionalPendingImpactDeltaUsd: bigint;
52
52
  };
53
+ export declare function getPriceImpactDeltaAmount(indexToken: TokenData, priceImpactDeltaUsd: bigint): bigint;
53
54
  export declare function getPriceImpactForSwap(marketInfo: MarketInfo, tokenA: TokenData, tokenB: TokenData, usdDeltaTokenA: bigint, usdDeltaTokenB: bigint, opts?: {
54
55
  fallbackToZero?: boolean;
55
56
  }): {
56
57
  priceImpactDeltaUsd: bigint;
57
58
  balanceWasImproved: boolean;
58
59
  };
60
+ /**
61
+ * A positive deposit impact is paid out of the swap impact pool into the market pool, which takes back part of the
62
+ * balance improvement, so the contract prices it again with that rebate included
63
+ * @see https://github.com/gmx-io/gmx-synthetics/blob/973adf75/contracts/pricing/SwapPricingUtils.sol#L122
64
+ */
65
+ export declare function getPriceImpactForDeposit(marketInfo: MarketInfo, tokenA: TokenData, tokenB: TokenData, usdDeltaTokenA: bigint, usdDeltaTokenB: bigint): {
66
+ priceImpactDeltaUsd: bigint;
67
+ balanceWasImproved: boolean;
68
+ };
59
69
  export declare function getNextPoolAmountsParams(p: {
60
70
  longToken: TokenData;
61
71
  shortToken: TokenData;
@@ -5,6 +5,7 @@ export { getGmsolBorrowingFactorPerSecond, getGmsolMarketStatus, getGmsolNextFun
5
5
  export { getGmsolFractionalPower, gmsolMath } from "./numbers";
6
6
  export { getGmsolPendingPositionFees } from "./positions";
7
7
  export type { GmsolFeeDiscountConfig, GmsolFundingParams, GmsolMarketConfig, GmsolMarketPrices, GmsolMarketState, GmsolMarketStatus, GmsolNextFunding, GmsolPendingPositionFees, GmsolPerSide, GmsolPnlFactorKind, GmsolPositionState, GmsolPriceRange, GmsolSide, } from "./types";
8
+ export * from "./units";
8
9
  export declare function getGmsolUsdAmount(value: bigint): bigint;
9
10
  export declare function getGmsolMidPrice(token: TokenData): bigint;
10
11
  /** The impact is settled in the entry size; it never becomes pending collateral. 0 means the order fills no tokens. */
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Unit conversions from GMX SDK values to the inputs of the gmsol SDK (`CreateOrderParams`).
3
+ *
4
+ * The units are set by the gmsol program, not by the npm SDK version. `CreateOrderParams` is unchanged from
5
+ * `@gmsol-labs/gmsol-sdk` 0.9.0-test.2 through 0.11.0 (0.11 only adds the optional `nonce`). Recheck this table only
6
+ * when the gmsol program changes its precision.
7
+ *
8
+ * | Quantity | App (GMX SDK) | gmsol SDK | Conversion |
9
+ * | ------------------------------------------- | ----------------------------------- | ---------------------------------- | -------------------------------- |
10
+ * | USD value (`size`, decrease `min_output`) | USD × 10^30 | USD × 10^20 (u128) | ÷ 10^10, rounding chosen by caller; × 10^10 back (exact) |
11
+ * | Whole-token price (`TokenData.prices`) | USD × 10^30 per 1 whole token | — | ÷ 10^(decimals + 10) in one division -> unit price |
12
+ * | Contract price (`convertToContractPrice`) | USD × 10^30 per smallest unit | unit price: USD × 10^20 per smallest unit (u128) | ÷ 10^10 |
13
+ * | Token amount (`amount`, increase/swap `min_output`) | smallest units (lamports, mint base units) | smallest units (u64) | identity + u64 range check |
14
+ * | Display multiplier (`Token.visualMultiplier`) | display only | never applied | not an input of any helper |
15
+ *
16
+ * `trigger_price` and `acceptable_price` are unit prices. Decimals are the Solana mint's decimals, never the
17
+ * decimals of the Arbitrum token used for oracle prices.
18
+ *
19
+ * Contract: every input is a non-negative `bigint`; decimals is an integer in [0, 30]. Every lossy conversion takes an
20
+ * explicit rounding. A non-zero input that floors to zero is rejected (unrepresentable in gmsol units), as is an
21
+ * output above u128 (USD, prices) or u64 (amounts). Violations throw `RangeError`.
22
+ *
23
+ * Rounding guidance for order builders: round each bound toward the side that is stricter for the user.
24
+ * Acceptable price: "floor" when it is a maximum (long increase, short decrease), "ceil" when it is a minimum
25
+ * (short increase, long decrease). Size: "floor". `convertToContractPrice` always floors, so going through the contract
26
+ * price matches the direct conversion only for "floor"; for "ceil" it can come out one unit lower. Convert a "ceil"
27
+ * bound from the whole-token price with `appTokenPriceToGmsolUnitPrice`, which rounds once.
28
+ */
29
+ export declare const GMSOL_USD_DECIMALS = 20;
30
+ export declare const MAX_GMSOL_TOKEN_DECIMALS = 30;
31
+ export declare const APP_TO_GMSOL_USD_DIVISOR: bigint;
32
+ export declare const U64_MAX: bigint;
33
+ export declare const U128_MAX: bigint;
34
+ export type GmsolRounding = "floor" | "ceil";
35
+ /** App USD (10^30) -> gmsol USD (10^20). */
36
+ export declare function appUsdToGmsolUsd(usd: bigint, rounding: GmsolRounding): bigint;
37
+ /** gmsol USD (10^20) -> app USD (10^30). Exact. */
38
+ export declare function gmsolUsdToAppUsd(usd: bigint): bigint;
39
+ /** App contract price (USD 10^30 per smallest unit) -> gmsol unit price (USD 10^20 per smallest unit). */
40
+ export declare function appContractPriceToGmsolUnitPrice(contractPrice: bigint, rounding: GmsolRounding): bigint;
41
+ /** App whole-token price (USD 10^30 per whole token) -> gmsol unit price, rounding once. */
42
+ export declare function appTokenPriceToGmsolUnitPrice({ price, decimals, rounding, }: {
43
+ price: bigint;
44
+ decimals: number;
45
+ rounding: GmsolRounding;
46
+ }): bigint;
47
+ /** gmsol unit price -> app whole-token price (USD 10^30 per whole token). Exact. */
48
+ export declare function gmsolUnitPriceToAppTokenPrice({ unitPrice, decimals, }: {
49
+ unitPrice: bigint;
50
+ decimals: number;
51
+ }): bigint;
52
+ /** Token amount in smallest units, checked to fit gmsol's u64. Never pass a display-scaled value. */
53
+ export declare function toGmsolTokenAmount(amount: bigint): bigint;
@@ -17,6 +17,7 @@ export type FetchJsonOptions<TResult> = {
17
17
  query?: Record<string, any>;
18
18
  transform?: (result: any) => TResult;
19
19
  onResponse?: (response: HttpResponseMetadata) => void;
20
+ signal?: AbortSignal;
20
21
  };
21
22
  export type IHttp = {
22
23
  url: string;
@@ -9,6 +9,7 @@ type ApiFieldParams = {
9
9
  endpoint: string;
10
10
  };
11
11
  export declare function readApiString({ record, name, endpoint }: ApiFieldParams): string;
12
+ export declare function readApiUnsignedInteger({ record, name, endpoint }: ApiFieldParams): number;
12
13
  export declare function readApiUnsignedBigInt({ record, name, endpoint }: ApiFieldParams): bigint;
13
14
  export declare function assertApiRecords(value: unknown, endpoint: string): asserts value is Record<string, unknown>[];
14
15
  export declare function assertApiFields(record: Record<string, unknown>, fields: readonly ApiFieldSpec[], endpoint: string, index: number): void;
@@ -24,6 +24,7 @@ export type MarketPoolTokens = {
24
24
  indexToken: TokenData;
25
25
  };
26
26
  export type MarketInfo = GmsolMarketConfig & Market & MarketPoolTokens & {
27
+ useV221LiquidationImpact?: boolean;
27
28
  isDisabled: boolean;
28
29
  longPoolAmount: bigint;
29
30
  shortPoolAmount: bigint;
@@ -110,6 +111,8 @@ export type MarketInfo = GmsolMarketConfig & Market & MarketPoolTokens & {
110
111
  swapImpactExponentFactor: bigint;
111
112
  withdrawalFeeFactorBalanceWasImproved?: bigint;
112
113
  withdrawalFeeFactorBalanceWasNotImproved?: bigint;
114
+ depositFeeFactorBalanceWasImproved?: bigint;
115
+ depositFeeFactorBalanceWasNotImproved?: bigint;
113
116
  borrowingFactorPerSecondForLongs: bigint;
114
117
  borrowingFactorPerSecondForShorts: bigint;
115
118
  fundingFactorPerSecond: bigint;
@@ -141,11 +144,11 @@ export type MarketValues = Pick<MarketInfo, (typeof MARKET_VALUES_KEYS)[number]>
141
144
  /**
142
145
  * Updates seldom
143
146
  */
144
- export type MarketConfig = Pick<MarketInfo, keyof GmsolMarketConfig | "isDisabled" | "maxLongPoolUsdForDeposit" | "maxShortPoolUsdForDeposit" | "maxLongPoolAmount" | "maxShortPoolAmount" | "reserveFactorLong" | "reserveFactorShort" | "openInterestReserveFactorLong" | "openInterestReserveFactorShort" | "maxOpenInterestLong" | "maxOpenInterestShort" | "maxCollateralSumLongTokenLong" | "maxCollateralSumLongTokenShort" | "maxCollateralSumShortTokenLong" | "maxCollateralSumShortTokenShort" | "minPositionImpactPoolAmount" | "positionImpactPoolDistributionRate" | "borrowingFactorLong" | "borrowingFactorShort" | "borrowingExponentFactorLong" | "borrowingExponentFactorShort" | "fundingFactor" | "fundingExponentFactor" | "fundingIncreaseFactorPerSecond" | "minFundingIncreaseRatePerSecond" | "fundingDecreaseFactorPerSecond" | "thresholdForDecreaseFunding" | "thresholdForStableFunding" | "minFundingFactorPerSecondLong" | "minFundingFactorPerSecondShort" | "maxFundingFactorPerSecondLong" | "maxFundingFactorPerSecondShort" | "maxPnlFactorForTradersLong" | "maxPnlFactorForTradersShort" | "maxPnlFactorForDepositsLong" | "maxPnlFactorForDepositsShort" | "maxPnlFactorForWithdrawalsLong" | "maxPnlFactorForWithdrawalsShort" | "minCollateralFactor" | "minCollateralFactorForLiquidation" | "minCollateralFactorForOpenInterestLong" | "minCollateralFactorForOpenInterestShort" | "positionFeeFactorForBalanceWasImproved" | "positionFeeFactorForBalanceWasNotImproved" | "positionImpactFactorPositive" | "positionImpactFactorNegative" | "maxPositionImpactFactorPositive" | "maxPositionImpactFactorNegative" | "maxPositionImpactFactorForLiquidations" | "maxLendableImpactFactor" | "maxLendableImpactFactorForWithdrawals" | "maxLendableImpactUsd" | "lentPositionImpactPoolAmount" | "positionImpactExponentFactorPositive" | "positionImpactExponentFactorNegative" | "swapFeeFactorForBalanceWasImproved" | "swapFeeFactorForBalanceWasNotImproved" | "swapImpactFactorPositive" | "swapImpactFactorNegative" | "swapImpactExponentFactor" | "atomicSwapFeeFactor" | "withdrawalFeeFactorBalanceWasImproved" | "withdrawalFeeFactorBalanceWasNotImproved" | "virtualMarketId" | "virtualIndexTokenId" | "virtualLongTokenId" | "virtualShortTokenId">;
147
+ export type MarketConfig = Pick<MarketInfo, keyof GmsolMarketConfig | "isDisabled" | "maxLongPoolUsdForDeposit" | "maxShortPoolUsdForDeposit" | "maxLongPoolAmount" | "maxShortPoolAmount" | "reserveFactorLong" | "reserveFactorShort" | "openInterestReserveFactorLong" | "openInterestReserveFactorShort" | "maxOpenInterestLong" | "maxOpenInterestShort" | "maxCollateralSumLongTokenLong" | "maxCollateralSumLongTokenShort" | "maxCollateralSumShortTokenLong" | "maxCollateralSumShortTokenShort" | "minPositionImpactPoolAmount" | "positionImpactPoolDistributionRate" | "borrowingFactorLong" | "borrowingFactorShort" | "borrowingExponentFactorLong" | "borrowingExponentFactorShort" | "fundingFactor" | "fundingExponentFactor" | "fundingIncreaseFactorPerSecond" | "minFundingIncreaseRatePerSecond" | "fundingDecreaseFactorPerSecond" | "thresholdForDecreaseFunding" | "thresholdForStableFunding" | "minFundingFactorPerSecondLong" | "minFundingFactorPerSecondShort" | "maxFundingFactorPerSecondLong" | "maxFundingFactorPerSecondShort" | "maxPnlFactorForTradersLong" | "maxPnlFactorForTradersShort" | "maxPnlFactorForDepositsLong" | "maxPnlFactorForDepositsShort" | "maxPnlFactorForWithdrawalsLong" | "maxPnlFactorForWithdrawalsShort" | "minCollateralFactor" | "minCollateralFactorForLiquidation" | "minCollateralFactorForOpenInterestLong" | "minCollateralFactorForOpenInterestShort" | "positionFeeFactorForBalanceWasImproved" | "positionFeeFactorForBalanceWasNotImproved" | "positionImpactFactorPositive" | "positionImpactFactorNegative" | "maxPositionImpactFactorPositive" | "maxPositionImpactFactorNegative" | "maxPositionImpactFactorForLiquidations" | "maxLendableImpactFactor" | "maxLendableImpactFactorForWithdrawals" | "maxLendableImpactUsd" | "lentPositionImpactPoolAmount" | "positionImpactExponentFactorPositive" | "positionImpactExponentFactorNegative" | "swapFeeFactorForBalanceWasImproved" | "swapFeeFactorForBalanceWasNotImproved" | "swapImpactFactorPositive" | "swapImpactFactorNegative" | "swapImpactExponentFactor" | "atomicSwapFeeFactor" | "withdrawalFeeFactorBalanceWasImproved" | "withdrawalFeeFactorBalanceWasNotImproved" | "depositFeeFactorBalanceWasImproved" | "depositFeeFactorBalanceWasNotImproved" | "virtualMarketId" | "virtualIndexTokenId" | "virtualLongTokenId" | "virtualShortTokenId">;
145
148
  export type MarketsData = {
146
149
  [marketTokenAddress: string]: Market;
147
150
  };
148
- export type RawMarketInfo = Omit<MarketInfo, "longToken" | "shortToken" | "indexToken" | "claimableFundingAmountLong" | "claimableFundingAmountShort">;
151
+ export type RawMarketInfo = Omit<MarketInfo, "longToken" | "shortToken" | "indexToken" | "claimableFundingAmountLong" | "claimableFundingAmountShort" | "useV221LiquidationImpact">;
149
152
  export type RawMarketsInfoData = {
150
153
  [marketAddress: string]: RawMarketInfo;
151
154
  };
@@ -1,6 +1,7 @@
1
1
  import { type Hex } from "viem";
2
2
  import type { AnyChainId, SettlementChainId } from "../../configs/chains";
3
3
  import type { IAbstractSigner } from "../signer";
4
+ import type { SignedTokenPermit } from "../tokens/types";
4
5
  export type BridgeFeeParams = {
5
6
  feeToken: string;
6
7
  feeAmount: bigint;
@@ -28,10 +29,12 @@ export type SameChainDepositRequest = {
28
29
  amount: bigint;
29
30
  /** Receiving GMX account address (typically the same as `signer.address`). */
30
31
  account: string;
32
+ /** Signed GMX Router permits for `tokenAddress`, so the deposit needs no approval transaction */
33
+ tokenPermits?: SignedTokenPermit[];
31
34
  };
32
35
  /**
33
36
  * Wallet sits on the settlement chain and funds the GMX account directly via
34
- * `MultichainTransferRouter.multicall([sendWnt|sendTokens, bridgeIn])`.
37
+ * `MultichainTransferRouter.multicall([sendWnt|sendTokens, bridgeIn])`, or via ExchangeRouter when it carries permits.
35
38
  */
36
39
  export declare function buildSameChainDepositTxn(request: SameChainDepositRequest): BuildTxnResult;
37
40
  export declare function getEmptyBridgeFeeParams(): BridgeFeeParams;
@@ -1,8 +1,8 @@
1
1
  import { type Hex } from "viem";
2
2
  import { ContractsChainId } from "../../configs/chains";
3
3
  import { ExecutionFee } from "../fees/types";
4
- import { DecreasePositionSwapType, OrderType } from "../orders/types";
5
- import { ContractPrice, ERC20Address, TokensData } from "../tokens/types";
4
+ import { DecreasePositionSwapType, OrderInfo, OrderType } from "../orders/types";
5
+ import { ContractPrice, ERC20Address, SignedTokenPermit, TokensData } from "../tokens/types";
6
6
  import { ExternalSwapQuote } from "../trade/types";
7
7
  import { TwapOrderParams } from "../twap/types";
8
8
  export type ExchangeRouterCall = {
@@ -25,6 +25,12 @@ export type UpdateOrderTxnParams = {
25
25
  };
26
26
  export type CancelOrderTxnParams = {
27
27
  orderKey: string;
28
+ } & OrderPayoutAddresses;
29
+ /** Where an existing order pays out on execution or cancellation; undefined when the caller didn't load it */
30
+ export type OrderPayoutAddresses = {
31
+ receiver?: string;
32
+ cancellationReceiver?: string;
33
+ callbackContract?: string;
28
34
  };
29
35
  export type CreateOrderPayload = {
30
36
  addresses: {
@@ -72,7 +78,7 @@ export type UpdateOrderParams = {
72
78
  decreasePositionSwapType: DecreasePositionSwapType;
73
79
  executionFeeTopUp: bigint;
74
80
  executionGasLimit?: bigint;
75
- };
81
+ } & OrderPayoutAddresses;
76
82
  export type ExecutionFeeEstimate = {
77
83
  executionFee: bigint;
78
84
  gasLimit: bigint;
@@ -210,9 +216,15 @@ export declare function getExternalCallsPayload({ chainId, account, quote, }: {
210
216
  account: string;
211
217
  quote: ExternalSwapQuote;
212
218
  }): ExternalCallsPayload;
213
- export declare function getBatchOrderMulticallPayload({ chainId, params, }: {
219
+ /**
220
+ * Sets the Router allowance inside the same wallet transaction. ExchangeRouter and GlvRouter share this call, and it
221
+ * has to come before the first sendTokens, which spends the allowance.
222
+ */
223
+ export declare function buildTokenPermitsCall(tokenPermits: SignedTokenPermit[]): ExchangeRouterCall;
224
+ export declare function getBatchOrderMulticallPayload({ chainId, params, tokenPermits, }: {
214
225
  chainId: ContractsChainId;
215
226
  params: BatchOrderTxnParams;
227
+ tokenPermits?: SignedTokenPermit[];
216
228
  }): {
217
229
  multicall: ExchangeRouterCall[];
218
230
  value: bigint;
@@ -242,3 +254,6 @@ export declare function getBatchSwapsCount(orderParams: BatchOrderTxnParams | un
242
254
  export declare function getIsEmptyBatch(orderParams: BatchOrderTxnParams | undefined): boolean;
243
255
  export declare function getBatchIsNativePayment(orderParams: BatchOrderTxnParams): boolean;
244
256
  export declare function getIsInvalidBatchReceiver(batchParams: BatchOrderTxnParams, signerAddress: string): boolean;
257
+ export declare function getOrderPayoutAddresses(order: OrderPayoutAddresses | undefined): OrderPayoutAddresses;
258
+ export declare function getCancelOrderParams(order: OrderInfo): CancelOrderTxnParams[];
259
+ export declare function getIsBatchPayoutOnlyToAccount(batchParams: BatchOrderTxnParams, account: string): boolean;
@@ -1,5 +1,6 @@
1
1
  import type { IHttp, SolanaReadOptions } from "../http/types";
2
- import { ApiOrderInfo } from "./types";
2
+ import type { ApiOrderInfo } from "./types";
3
+ export declare function parseApiOrders(orders: unknown, endpoint: string): ApiOrderInfo[];
3
4
  export declare function fetchApiOrders(ctx: {
4
5
  api: IHttp;
5
6
  }, params: {
@@ -39,6 +39,7 @@ export type Order = {
39
39
  marketAddress: string;
40
40
  decreasePositionSwapType: DecreasePositionSwapType;
41
41
  receiver: string;
42
+ cancellationReceiver?: string;
42
43
  swapPath: string[];
43
44
  contractAcceptablePrice: bigint;
44
45
  contractTriggerPrice: bigint;
@@ -57,6 +58,7 @@ export type Order = {
57
58
  uiFeeReceiver: string;
58
59
  uiFeeFactor: bigint | undefined;
59
60
  validFromTime: bigint;
61
+ srcChainId: bigint;
60
62
  title?: string;
61
63
  };
62
64
  export type SwapOrderInfo = Order & {
@@ -132,5 +134,27 @@ export type ApiOrderInfo = {
132
134
  isFrozen: boolean;
133
135
  autoCancel: boolean;
134
136
  dataList: string[];
137
+ } & Partial<SolanaApiOrderFields>;
138
+ export type SolanaOrderActionState = "pending" | "completed" | "cancelled";
139
+ export type SolanaOrderCallback = {
140
+ version: number;
141
+ program: string;
142
+ sharedData: string;
143
+ partitionedData: string;
144
+ };
145
+ export type SolanaOrderEscrowTokens = {
146
+ initialCollateralToken: string | undefined;
147
+ finalOutputToken: string | undefined;
148
+ longToken: string | undefined;
149
+ shortToken: string | undefined;
150
+ };
151
+ export type SolanaApiOrderFields = {
152
+ orderAccount: string;
153
+ actionState: SolanaOrderActionState;
154
+ positionAccount: string | undefined;
155
+ rentReceiver: string;
156
+ referrer: string | undefined;
157
+ callback: SolanaOrderCallback | undefined;
158
+ escrowTokens: SolanaOrderEscrowTokens;
135
159
  };
136
160
  export {};
@@ -25,6 +25,8 @@ export type Position = {
25
25
  pendingImpactAmount: bigint;
26
26
  positionValueInUsd: bigint;
27
27
  data: string;
28
+ tradeId?: bigint;
29
+ updatedAtSlot?: bigint;
28
30
  };
29
31
  export type PositionInfo = Position & {
30
32
  marketInfo: MarketInfo | undefined;
@@ -63,6 +63,17 @@ export declare function getLeverage(p: {
63
63
  pendingFundingFeesUsd: bigint;
64
64
  pendingBorrowingFeesUsd: bigint;
65
65
  }): bigint | undefined;
66
+ export declare function getLiquidationPriceImpact(p: {
67
+ marketInfo: MarketInfo;
68
+ sizeInUsd: bigint;
69
+ sizeInTokens: bigint;
70
+ pendingImpactAmount: bigint;
71
+ isLong: boolean;
72
+ useMaxPriceImpact?: boolean;
73
+ }): {
74
+ priceImpactDeltaUsd: bigint;
75
+ balanceWasImproved: boolean;
76
+ };
66
77
  export declare function getLiquidationPriceImpactDeltaUsd(p: {
67
78
  marketInfo: MarketInfo;
68
79
  sizeInUsd: bigint;
@@ -71,6 +82,25 @@ export declare function getLiquidationPriceImpactDeltaUsd(p: {
71
82
  isLong: boolean;
72
83
  useMaxPriceImpact?: boolean;
73
84
  }): bigint;
85
+ export declare function getCollateralAmountInIndexTokens(p: {
86
+ collateralToken: TokenData;
87
+ indexToken: TokenData;
88
+ collateralAmount: bigint;
89
+ isLong: boolean;
90
+ }): bigint | undefined;
91
+ export declare function getTokenAtIndexPrice<T extends TokenData>(p: {
92
+ token: T;
93
+ collateralToken: TokenData;
94
+ indexToken: TokenData;
95
+ indexPrice: bigint;
96
+ isLong: boolean;
97
+ }): T;
98
+ export declare function getCollateralPriceAtIndexPrice(p: {
99
+ collateralToken: TokenData;
100
+ indexToken: TokenData;
101
+ indexPrice: bigint;
102
+ isLong: boolean;
103
+ }): bigint;
74
104
  export declare function getLiquidationPrice(p: {
75
105
  sizeInUsd: bigint;
76
106
  sizeInTokens: bigint;
@@ -7,6 +7,8 @@ export declare function fetchApiOhlcv(ctx: {
7
7
  export declare function parseApiTokenPrices(raw: unknown): TokenPricesData;
8
8
  export declare function fetchApiTokenPrices(ctx: {
9
9
  api: IHttp;
10
+ }, opts?: {
11
+ signal?: AbortSignal;
10
12
  }): Promise<{
11
13
  prices: TokenPricesData;
12
14
  originTs: number;
@@ -14,6 +14,10 @@ export type UserReferralInfo = {
14
14
  export type FeeDiscount = {
15
15
  userReferralInfo: UserReferralInfo;
16
16
  orderFeeDiscountFactor: bigint;
17
+ gtRank: number;
18
+ rankDiscountFactor: bigint;
19
+ referrer: string | undefined;
20
+ referredUserDiscountFactor: bigint;
17
21
  updatedAt: number | undefined;
18
22
  };
19
23
  export declare enum RebateDistributionType {
@@ -1,11 +1,16 @@
1
- import type { IAbstractSigner } from "../signer";
2
1
  import { PrivateKeySigner } from "../signer";
3
2
  export type GeneratedSubaccount = {
4
3
  address: string;
5
4
  signer: PrivateKeySigner;
6
- /** AES-encrypted private key (encrypted with main account address) */
7
- privateKey: string;
5
+ privateKey: `0x${string}`;
8
6
  };
9
- export declare function generateSubaccount(mainSigner: IAbstractSigner): Promise<GeneratedSubaccount>;
7
+ export declare function getSubaccountFromPrivateKey(privateKey: `0x${string}`): GeneratedSubaccount;
8
+ export declare function generateSubaccount(): GeneratedSubaccount;
9
+ /**
10
+ * @deprecated Only reads configs stored by SDK versions below 3.0.0.
11
+ */
10
12
  export declare function decryptSubaccountPrivateKey(encryptedPrivateKey: string, mainAccountAddress: string): `0x${string}`;
13
+ /**
14
+ * @deprecated Only reads configs stored by SDK versions below 3.0.0.
15
+ */
11
16
  export declare function createSubaccountSignerFromConfig(encryptedPrivateKey: string, mainAccountAddress: string): PrivateKeySigner;
@@ -2,6 +2,7 @@ import type { ContractsChainId } from "../../configs/chains";
2
2
  import type { IHttp } from "../http/types";
3
3
  import type { PrepareCancelOrderRequest, PrepareCollateralRequest, PrepareEditOrderRequest, PrepareOrderRequest, PrepareOrderResponse, SubmitOrderRequest, SubmitOrderResponse } from "../orderTransactions/api";
4
4
  import type { IAbstractSigner } from "../signer";
5
+ import { type GeneratedSubaccount } from "./generateSubaccount";
5
6
  import type { SdkSubaccountApproval, SdkSubaccountStatus, SubaccountState } from "./types";
6
7
  export type SdkSubaccountClientContext = {
7
8
  ctx: {
@@ -17,9 +18,14 @@ export type SubaccountPrepareRequest = PrepareOrderRequest | PrepareEditOrderReq
17
18
  export type PrepareWithContext<TRequest extends SubaccountPrepareRequest> = (ctx: {
18
19
  api: IHttp;
19
20
  }, request: TRequest) => Promise<PrepareOrderResponse>;
21
+ export type ExportedSubaccount = Pick<GeneratedSubaccount, "address" | "privateKey"> & {
22
+ account?: string;
23
+ };
20
24
  export declare function hasActiveSdkSubaccount(client: SdkSubaccountClientContext): boolean;
21
25
  export declare function getSdkSubaccountApprovalMessage(client: SdkSubaccountClientContext): SdkSubaccountApproval | undefined;
22
- export declare function generateSdkSubaccount(client: SdkSubaccountClientContext, mainSigner: IAbstractSigner): Promise<string>;
26
+ export declare function generateSdkSubaccount(client: SdkSubaccountClientContext, account?: string): string;
27
+ export declare function importSdkSubaccount(client: SdkSubaccountClientContext, exported: ExportedSubaccount): string;
28
+ export declare function exportSdkSubaccount(client: SdkSubaccountClientContext): ExportedSubaccount | undefined;
23
29
  export declare function reconcileSdkSubaccountApproval(subaccount: SubaccountState | undefined): void;
24
30
  export declare function refreshSdkSubaccountState(client: SdkSubaccountClientContext, account: string): Promise<SdkSubaccountStatus | undefined>;
25
31
  export declare function activateSdkSubaccount(client: SdkSubaccountClientContext, mainSigner: IAbstractSigner, options?: {
@@ -14,6 +14,7 @@ export type SubaccountSerializedConfig = {
14
14
  privateKey: string;
15
15
  address: string;
16
16
  isNew?: boolean;
17
+ version?: number;
17
18
  };
18
19
  export type SubaccountApproval = {
19
20
  subaccount: string;
@@ -63,6 +64,7 @@ export type Subaccount = {
63
64
  export type SubaccountValidations = {
64
65
  isExpired: boolean;
65
66
  isActionsExceeded: boolean;
67
+ isNonceExpired: boolean;
66
68
  isApprovalInvalid: boolean;
67
69
  isValid: boolean;
68
70
  };
@@ -17,6 +17,7 @@ export type Token = {
17
17
  symbol: string;
18
18
  assetSymbol?: string;
19
19
  baseSymbol?: string;
20
+ tracksPriceOf?: string;
20
21
  decimals: number;
21
22
  address: string;
22
23
  visualMultiplier?: number;
@@ -12,6 +12,7 @@ export declare function convertToUsd(tokenAmount: bigint | undefined, tokenDecim
12
12
  export declare function convertBetweenTokens(tokenAmount: bigint | undefined, fromToken: TokenData | undefined, toToken: TokenData | undefined, maximize: boolean): bigint | undefined;
13
13
  export declare function getMidPrice(prices: TokenPrices): bigint;
14
14
  export declare function getIsEquivalentTokens(token1: Token, token2: Token): boolean;
15
+ export declare function getIsTokenTrackingPrice(token: Token, trackedToken: Token): boolean;
15
16
  export declare function getTokenData(tokensData?: TokensData, address?: string, convertTo?: "wrapped" | "native"): TokenData | undefined;
16
17
  /**
17
18
  * Even though its not a generic function, it return the same type as the input.
@@ -47,5 +48,10 @@ export declare function getTokensRatioByPrice(p: {
47
48
  fromPrice: bigint;
48
49
  toPrice: bigint;
49
50
  }): TokensRatio;
51
+ export declare function getTokensRatioByPriceInDirection(p: {
52
+ fromToken: TokenData;
53
+ toToken: TokenData;
54
+ largestTokenAddress: string;
55
+ }): TokensRatio;
50
56
  export declare function getGmToken(chainId: ContractsChainId, marketTokenAddress: string): Token;
51
57
  export declare function getGlvToken(chainId: ContractsChainId, glvTokenAddress: string): Token;
@@ -33,6 +33,8 @@ export declare function getDecreasePositionAmounts(p: {
33
33
  receiveToken?: TokenData;
34
34
  forceDecreaseSwapType?: DecreasePositionSwapType;
35
35
  isTwap?: boolean;
36
+ numberOfParts?: number;
37
+ validatedCollateralWithdrawalAmount?: bigint;
36
38
  }): DecreasePositionAmounts;
37
39
  export declare function getIsFullClose(p: {
38
40
  position: PositionInfoLoaded;
@@ -149,6 +151,7 @@ export declare function getOptimalDecreaseAndSwapAmounts(p: {
149
151
  receiveToken: TokenData;
150
152
  forceDecreaseSwapType?: DecreasePositionSwapType;
151
153
  isTwap?: boolean;
154
+ numberOfParts?: number;
152
155
  findSwapPath: FindSwapPath;
153
156
  findSwapPathFromPnl: FindSwapPath;
154
157
  marketsInfoData: MarketsInfoData | undefined;
@@ -1,10 +1,13 @@
1
1
  import { MarketInfo } from "../markets/types";
2
+ import type { PositionInfoLoaded } from "../positions/types";
2
3
  import { UserReferralInfo } from "../referrals/types";
3
4
  import { TokenData } from "../tokens/types";
5
+ import { getDecreasePositionAmounts } from "./decrease";
4
6
  import { PositionMarginState } from "./increaseMarginCheck";
5
7
  import { DecreasePositionAmounts } from "./types";
6
8
  export type DecreasePositionMarginState = PositionMarginState & {
7
9
  isCollateralWithdrawalCancelled: boolean;
10
+ collateralDeltaAmount: bigint;
8
11
  };
9
12
  export type DecreaseResultingPositionMarginStateParams = {
10
13
  marketInfo: MarketInfo;
@@ -52,3 +55,11 @@ export type TriggerDecreaseRemainingPositionMarginStateParams = {
52
55
  * price and `collateralDeltaAmount` is the collateral withdrawal the order stores.
53
56
  */
54
57
  export declare function getTriggerDecreaseRemainingPositionMarginState(p: TriggerDecreaseRemainingPositionMarginStateParams): DecreasePositionMarginState | undefined;
58
+ export declare function getStoredTriggerDecreaseQuote(p: Omit<Parameters<typeof getDecreasePositionAmounts>[0], "validatedCollateralWithdrawalAmount" | "keepLeverage"> & {
59
+ position: PositionInfoLoaded;
60
+ triggerPrice: bigint;
61
+ storedCollateralDeltaAmount: bigint;
62
+ }): {
63
+ decreaseAmounts: DecreasePositionAmounts;
64
+ marginState?: DecreasePositionMarginState;
65
+ };