@gmx-io/sdk 1.5.0-alpha-9 → 1.5.0-alpha-11

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 (229) hide show
  1. package/build/cjs/scripts/subsquid-codegen.js +1 -1
  2. package/build/cjs/src/clients/v2/__tests__/data.spec.js +85 -0
  3. package/build/cjs/src/clients/v2/__tests__/decrease.spec.js +484 -0
  4. package/build/cjs/src/clients/v2/__tests__/editCancel.spec.js +260 -0
  5. package/build/cjs/src/clients/v2/__tests__/errors.spec.js +263 -0
  6. package/build/cjs/src/clients/v2/__tests__/increase.spec.js +777 -0
  7. package/build/cjs/src/clients/v2/__tests__/subaccount.spec.js +74 -0
  8. package/build/cjs/src/clients/v2/__tests__/swap.spec.js +192 -0
  9. package/build/cjs/src/clients/v2/__tests__/testUtil.js +135 -0
  10. package/build/cjs/src/clients/v2/index.js +171 -27
  11. package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +48 -0
  12. package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +1082 -0
  13. package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +90 -0
  14. package/build/cjs/src/codegen/subsquid.js +323 -1
  15. package/build/cjs/src/configs/api.js +17 -5
  16. package/build/cjs/src/configs/chains.js +11 -1
  17. package/build/cjs/src/configs/contracts.js +7 -7
  18. package/build/cjs/src/configs/markets.js +43 -1
  19. package/build/cjs/src/configs/tokens.js +63 -132
  20. package/build/cjs/src/test/mock.js +1 -1
  21. package/build/cjs/src/utils/__tests__/markets.spec.js +10 -0
  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__/positions.spec.js +59 -7
  26. package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +34 -0
  27. package/build/cjs/src/utils/balances/api.js +63 -0
  28. package/build/cjs/src/utils/buyback/api.js +7 -0
  29. package/build/cjs/src/utils/buyback/types.js +2 -0
  30. package/build/cjs/src/utils/errors/index.js +1 -0
  31. package/build/cjs/src/utils/errors/isIgnoredEstimateGasError.js +23 -0
  32. package/build/cjs/src/utils/express/index.js +18 -0
  33. package/build/cjs/src/utils/express/types.js +2 -0
  34. package/build/cjs/src/utils/express/utils/batchOrderUtils.js +218 -0
  35. package/build/cjs/src/utils/express/utils/bridgeOutUtils.js +73 -0
  36. package/build/cjs/src/utils/express/utils/estimateExpressParams.js +243 -0
  37. package/build/cjs/src/utils/express/utils/expressParamsUtils.js +22 -0
  38. package/build/cjs/src/utils/express/utils/fetchGelatoGasTankBalance.js +13 -0
  39. package/build/cjs/src/utils/express/utils/gelatoRelayUtils.js +77 -0
  40. package/build/cjs/src/utils/express/utils/globalExpressParams.js +40 -0
  41. package/build/cjs/src/utils/express/utils/index.js +27 -0
  42. package/build/cjs/src/utils/express/utils/oracleParamsUtils.js +49 -0
  43. package/build/cjs/src/utils/express/utils/referralUtils.js +35 -0
  44. package/build/cjs/src/utils/express/utils/relayParamsUtils.js +201 -0
  45. package/build/cjs/src/utils/fees/executionFee.js +8 -1
  46. package/build/cjs/src/utils/fees/priceImpact.js +1 -2
  47. package/build/cjs/src/utils/http/http.js +86 -13
  48. package/build/cjs/src/utils/http/httpFallback.js +65 -0
  49. package/build/cjs/src/utils/markets/__tests__/mockMarkets.js +4 -0
  50. package/build/cjs/src/utils/markets/hashKeys.js +16 -0
  51. package/build/cjs/src/utils/markets/multicall.js +20 -0
  52. package/build/cjs/src/utils/markets/utils.js +8 -0
  53. package/build/cjs/src/utils/metrics/index.js +7 -0
  54. package/build/cjs/src/utils/numbers/utils.js +29 -27
  55. package/build/cjs/src/utils/orderTransactions/api.js +88 -0
  56. package/build/cjs/src/utils/orderTransactions/index.js +1 -0
  57. package/build/cjs/src/utils/orderTransactions/utils.js +4 -1
  58. package/build/cjs/src/utils/orderTransactions/validateTypedData.js +89 -0
  59. package/build/cjs/src/utils/positions/utils.js +5 -19
  60. package/build/cjs/src/utils/rpc/createViemRpc.js +39 -0
  61. package/build/cjs/src/utils/rpc/index.js +5 -0
  62. package/build/cjs/src/utils/signer/index.js +5 -0
  63. package/build/cjs/src/utils/signer/privateKeySigner.js +42 -0
  64. package/build/cjs/src/utils/subaccount/api.js +22 -0
  65. package/build/cjs/src/utils/subaccount/generateSubaccount.js +19 -0
  66. package/build/cjs/src/utils/subaccount/getEmptySubaccountApproval.js +24 -0
  67. package/build/cjs/src/utils/subaccount/getSubaccountApprovalTypedData.js +46 -0
  68. package/build/cjs/src/utils/subaccount/hashSubaccountApproval.js +28 -0
  69. package/build/cjs/src/utils/subaccount/index.js +30 -0
  70. package/build/cjs/src/utils/subaccount/types.js +2 -0
  71. package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +49 -0
  72. package/build/cjs/src/utils/swap/__tests__/swapStats.spec.js +63 -0
  73. package/build/cjs/src/utils/swap/buildSwapStrategy.js +10 -2
  74. package/build/cjs/src/utils/swap/swapRouting.js +7 -2
  75. package/build/cjs/src/utils/swap/swapStats.js +90 -6
  76. package/build/cjs/src/utils/swap/swapValues.js +8 -2
  77. package/build/cjs/src/utils/trade/increase.js +7 -1
  78. package/build/cjs/src/utils/trade/types.js +1 -1
  79. package/build/cjs/src/utils/tradeHistory/utils.js +14 -28
  80. package/build/cjs/src/utils/twap/index.js +4 -1
  81. package/build/cjs/src/utils/twap/uiFeeReceiver.js +23 -7
  82. package/build/esm/scripts/subsquid-codegen.js +1 -1
  83. package/build/esm/src/clients/v2/__tests__/data.spec.js +83 -0
  84. package/build/esm/src/clients/v2/__tests__/decrease.spec.js +482 -0
  85. package/build/esm/src/clients/v2/__tests__/editCancel.spec.js +258 -0
  86. package/build/esm/src/clients/v2/__tests__/errors.spec.js +261 -0
  87. package/build/esm/src/clients/v2/__tests__/increase.spec.js +775 -0
  88. package/build/esm/src/clients/v2/__tests__/subaccount.spec.js +72 -0
  89. package/build/esm/src/clients/v2/__tests__/swap.spec.js +190 -0
  90. package/build/esm/src/clients/v2/__tests__/testUtil.js +123 -0
  91. package/build/esm/src/clients/v2/index.js +145 -5
  92. package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +48 -0
  93. package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +1082 -0
  94. package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +90 -0
  95. package/build/esm/src/codegen/subsquid.js +321 -0
  96. package/build/esm/src/configs/api.js +15 -4
  97. package/build/esm/src/configs/chains.js +11 -1
  98. package/build/esm/src/configs/contracts.js +7 -7
  99. package/build/esm/src/configs/markets.js +43 -1
  100. package/build/esm/src/configs/tokens.js +62 -130
  101. package/build/esm/src/test/mock.js +1 -1
  102. package/build/esm/src/utils/__tests__/markets.spec.js +10 -0
  103. package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
  104. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
  105. package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
  106. package/build/esm/src/utils/__tests__/positions.spec.js +60 -8
  107. package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +35 -1
  108. package/build/esm/src/utils/balances/api.js +54 -0
  109. package/build/esm/src/utils/buyback/api.js +3 -0
  110. package/build/esm/src/utils/buyback/types.js +1 -0
  111. package/build/esm/src/utils/errors/index.js +1 -0
  112. package/build/esm/src/utils/errors/isIgnoredEstimateGasError.js +19 -0
  113. package/build/esm/src/utils/express/index.js +2 -0
  114. package/build/esm/src/utils/express/types.js +1 -0
  115. package/build/esm/src/utils/express/utils/batchOrderUtils.js +210 -0
  116. package/build/esm/src/utils/express/utils/bridgeOutUtils.js +69 -0
  117. package/build/esm/src/utils/express/utils/estimateExpressParams.js +237 -0
  118. package/build/esm/src/utils/express/utils/expressParamsUtils.js +16 -0
  119. package/build/esm/src/utils/express/utils/fetchGelatoGasTankBalance.js +9 -0
  120. package/build/esm/src/utils/express/utils/gelatoRelayUtils.js +71 -0
  121. package/build/esm/src/utils/express/utils/globalExpressParams.js +36 -0
  122. package/build/esm/src/utils/express/utils/index.js +11 -0
  123. package/build/esm/src/utils/express/utils/oracleParamsUtils.js +42 -0
  124. package/build/esm/src/utils/express/utils/referralUtils.js +30 -0
  125. package/build/esm/src/utils/express/utils/relayParamsUtils.js +192 -0
  126. package/build/esm/src/utils/fees/executionFee.js +6 -0
  127. package/build/esm/src/utils/fees/priceImpact.js +1 -2
  128. package/build/esm/src/utils/http/http.js +84 -12
  129. package/build/esm/src/utils/http/httpFallback.js +61 -0
  130. package/build/esm/src/utils/markets/__tests__/mockMarkets.js +4 -0
  131. package/build/esm/src/utils/markets/hashKeys.js +17 -1
  132. package/build/esm/src/utils/markets/multicall.js +20 -0
  133. package/build/esm/src/utils/markets/utils.js +8 -0
  134. package/build/esm/src/utils/metrics/index.js +4 -0
  135. package/build/esm/src/utils/numbers/utils.js +25 -24
  136. package/build/esm/src/utils/orderTransactions/api.js +77 -0
  137. package/build/esm/src/utils/orderTransactions/index.js +1 -0
  138. package/build/esm/src/utils/orderTransactions/utils.js +4 -1
  139. package/build/esm/src/utils/orderTransactions/validateTypedData.js +84 -0
  140. package/build/esm/src/utils/positions/utils.js +5 -19
  141. package/build/esm/src/utils/rpc/createViemRpc.js +35 -0
  142. package/build/esm/src/utils/rpc/index.js +1 -0
  143. package/build/esm/src/utils/signer/index.js +1 -0
  144. package/build/esm/src/utils/signer/privateKeySigner.js +38 -0
  145. package/build/esm/src/utils/subaccount/api.js +16 -0
  146. package/build/esm/src/utils/subaccount/generateSubaccount.js +15 -0
  147. package/build/esm/src/utils/subaccount/getEmptySubaccountApproval.js +20 -0
  148. package/build/esm/src/utils/subaccount/getSubaccountApprovalTypedData.js +42 -0
  149. package/build/esm/src/utils/subaccount/hashSubaccountApproval.js +24 -0
  150. package/build/esm/src/utils/subaccount/index.js +6 -0
  151. package/build/esm/src/utils/subaccount/types.js +1 -0
  152. package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +49 -0
  153. package/build/esm/src/utils/swap/__tests__/swapStats.spec.js +64 -1
  154. package/build/esm/src/utils/swap/buildSwapStrategy.js +10 -2
  155. package/build/esm/src/utils/swap/swapRouting.js +7 -2
  156. package/build/esm/src/utils/swap/swapStats.js +90 -7
  157. package/build/esm/src/utils/swap/swapValues.js +8 -2
  158. package/build/esm/src/utils/trade/increase.js +7 -1
  159. package/build/esm/src/utils/trade/types.js +1 -1
  160. package/build/esm/src/utils/tradeHistory/utils.js +13 -26
  161. package/build/esm/src/utils/twap/index.js +1 -0
  162. package/build/esm/src/utils/twap/uiFeeReceiver.js +20 -6
  163. package/build/types/src/clients/v2/__tests__/data.spec.d.ts +1 -0
  164. package/build/types/src/clients/v2/__tests__/decrease.spec.d.ts +1 -0
  165. package/build/types/src/clients/v2/__tests__/editCancel.spec.d.ts +1 -0
  166. package/build/types/src/clients/v2/__tests__/errors.spec.d.ts +1 -0
  167. package/build/types/src/clients/v2/__tests__/increase.spec.d.ts +1 -0
  168. package/build/types/src/clients/v2/__tests__/subaccount.spec.d.ts +1 -0
  169. package/build/types/src/clients/v2/__tests__/swap.spec.d.ts +1 -0
  170. package/build/types/src/clients/v2/__tests__/testUtil.d.ts +24 -0
  171. package/build/types/src/clients/v2/index.d.ts +62 -1
  172. package/build/types/src/codegen/prebuilt/index.d.ts +1220 -0
  173. package/build/types/src/codegen/subsquid.d.ts +1276 -44
  174. package/build/types/src/configs/api.d.ts +1 -0
  175. package/build/types/src/configs/chains.d.ts +10 -1
  176. package/build/types/src/configs/contracts.d.ts +6 -6
  177. package/build/types/src/configs/tokens.d.ts +6 -1
  178. package/build/types/src/utils/balances/api.d.ts +39 -0
  179. package/build/types/src/utils/buyback/api.d.ts +5 -0
  180. package/build/types/src/utils/buyback/types.d.ts +15 -0
  181. package/build/types/src/utils/chains/types.d.ts +1 -0
  182. package/build/types/src/utils/errors/index.d.ts +1 -0
  183. package/build/types/src/utils/errors/isIgnoredEstimateGasError.d.ts +2 -0
  184. package/build/types/src/utils/express/index.d.ts +2 -0
  185. package/build/types/src/utils/express/types.d.ts +95 -0
  186. package/build/types/src/utils/express/utils/batchOrderUtils.d.ts +98 -0
  187. package/build/types/src/utils/express/utils/bridgeOutUtils.d.ts +21 -0
  188. package/build/types/src/utils/express/utils/estimateExpressParams.d.ts +37 -0
  189. package/build/types/src/utils/express/utils/expressParamsUtils.d.ts +19 -0
  190. package/build/types/src/utils/express/utils/fetchGelatoGasTankBalance.d.ts +5 -0
  191. package/build/types/src/utils/express/utils/gelatoRelayUtils.d.ts +25 -0
  192. package/build/types/src/utils/express/utils/globalExpressParams.d.ts +31 -0
  193. package/build/types/src/utils/express/utils/index.d.ts +11 -0
  194. package/build/types/src/utils/express/utils/oracleParamsUtils.d.ts +10 -0
  195. package/build/types/src/utils/express/utils/referralUtils.d.ts +17 -0
  196. package/build/types/src/utils/express/utils/relayParamsUtils.d.ts +49 -0
  197. package/build/types/src/utils/fees/executionFee.d.ts +1 -0
  198. package/build/types/src/utils/http/http.d.ts +16 -1
  199. package/build/types/src/utils/http/httpFallback.d.ts +18 -0
  200. package/build/types/src/utils/http/types.d.ts +3 -0
  201. package/build/types/src/utils/markets/types.d.ts +5 -1
  202. package/build/types/src/utils/metrics/index.d.ts +4 -0
  203. package/build/types/src/utils/numbers/utils.d.ts +2 -5
  204. package/build/types/src/utils/orderTransactions/api.d.ts +158 -0
  205. package/build/types/src/utils/orderTransactions/index.d.ts +1 -0
  206. package/build/types/src/utils/orderTransactions/validateTypedData.d.ts +6 -0
  207. package/build/types/src/utils/positions/utils.d.ts +1 -9
  208. package/build/types/src/utils/rpc/createViemRpc.d.ts +3 -0
  209. package/build/types/src/utils/rpc/index.d.ts +26 -0
  210. package/build/types/src/utils/signer/index.d.ts +23 -0
  211. package/build/types/src/utils/signer/privateKeySigner.d.ts +19 -0
  212. package/build/types/src/utils/subaccount/api.d.ts +51 -0
  213. package/build/types/src/utils/subaccount/generateSubaccount.d.ts +8 -0
  214. package/build/types/src/utils/subaccount/getEmptySubaccountApproval.d.ts +9 -0
  215. package/build/types/src/utils/subaccount/getSubaccountApprovalTypedData.d.ts +24 -0
  216. package/build/types/src/utils/subaccount/hashSubaccountApproval.d.ts +1 -0
  217. package/build/types/src/utils/subaccount/index.d.ts +7 -0
  218. package/build/types/src/utils/subaccount/types.d.ts +55 -0
  219. package/build/types/src/utils/swap/buildSwapStrategy.d.ts +6 -2
  220. package/build/types/src/utils/swap/swapStats.d.ts +14 -0
  221. package/build/types/src/utils/swap/swapValues.d.ts +4 -0
  222. package/build/types/src/utils/tokens/types.d.ts +0 -1
  223. package/build/types/src/utils/trade/increase.d.ts +2 -0
  224. package/build/types/src/utils/trade/types.d.ts +2 -1
  225. package/build/types/src/utils/tradeHistory/utils.d.ts +0 -1
  226. package/build/types/src/utils/twap/index.d.ts +1 -0
  227. package/build/types/src/utils/twap/types.d.ts +2 -0
  228. package/build/types/src/utils/twap/uiFeeReceiver.d.ts +10 -2
  229. package/package.json +40 -3
@@ -0,0 +1,49 @@
1
+ import type { ContractsChainId, SourceChainId } from "../../../configs/chains";
2
+ import { ExternalCallsPayload } from "../../orderTransactions";
3
+ import type { TypedDataDomain } from "../../signer";
4
+ import type { SignedTokenPermit, TokenData } from "../../tokens/types";
5
+ import type { ExternalSwapQuote, FindSwapPath, SwapAmounts } from "../../trade/types";
6
+ import type { GasPaymentParams, RawRelayParamsPayload, RelayFeePayload, RelayParamsPayload } from "../types";
7
+ export declare function getExpressContractAddress(chainId: ContractsChainId, { isSubaccount, isMultichain, scope, }: {
8
+ isSubaccount?: boolean;
9
+ isMultichain?: boolean;
10
+ scope?: "glv" | "gm" | "transfer" | "claims" | "order" | "subaccount";
11
+ }): string;
12
+ export declare function getGelatoRelayRouterDomain(chainId: SourceChainId | ContractsChainId, relayRouterAddress: string): TypedDataDomain;
13
+ export declare function getRelayerFeeParams({ chainId, account, gasPaymentToken, relayerFeeToken, relayerFeeAmount, totalRelayerFeeTokenAmount, gasPaymentTokenAsCollateralAmount, transactionExternalCalls, feeExternalSwapQuote, findFeeSwapPath, }: {
14
+ chainId: ContractsChainId;
15
+ account: string;
16
+ relayerFeeAmount: bigint;
17
+ totalRelayerFeeTokenAmount: bigint;
18
+ relayerFeeToken: TokenData;
19
+ gasPaymentToken: TokenData;
20
+ gasPaymentTokenAsCollateralAmount: bigint;
21
+ findFeeSwapPath: FindSwapPath | undefined;
22
+ feeExternalSwapQuote: ExternalSwapQuote | undefined;
23
+ transactionExternalCalls: ExternalCallsPayload | undefined;
24
+ }): {
25
+ feeParams: RelayFeePayload;
26
+ externalCalls: ExternalCallsPayload;
27
+ feeExternalSwapGasLimit: bigint;
28
+ gasPaymentParams: GasPaymentParams;
29
+ } | undefined;
30
+ export declare function getBestFeeSwapStrategy(internalSwapAmounts: SwapAmounts | undefined, externalSwapQuote: ExternalSwapQuote | undefined): {
31
+ amountIn: bigint;
32
+ amountOut: bigint;
33
+ externalSwapQuote: ExternalSwapQuote;
34
+ swapPath?: undefined;
35
+ } | {
36
+ amountIn: bigint;
37
+ amountOut: bigint;
38
+ swapPath: string[];
39
+ externalSwapQuote?: undefined;
40
+ } | undefined;
41
+ export declare function getRawRelayerParams({ chainId, gasPaymentTokenAddress, relayerFeeTokenAddress, feeParams, externalCalls, tokenPermits, }: {
42
+ chainId: ContractsChainId;
43
+ gasPaymentTokenAddress: string;
44
+ relayerFeeTokenAddress: string;
45
+ feeParams: RelayFeePayload;
46
+ externalCalls: ExternalCallsPayload;
47
+ tokenPermits: SignedTokenPermit[];
48
+ }): RawRelayParamsPayload;
49
+ export declare function hashRelayParams(relayParams: RelayParamsPayload): string;
@@ -14,6 +14,7 @@ export declare function estimateRelayerGasLimit({ gasLimits, tokenPermitsCount,
14
14
  transactionPayloadGasLimit: bigint;
15
15
  l1GasLimit: bigint;
16
16
  }): bigint;
17
+ export declare function applyGasBuffer(gasLimit: bigint): bigint;
17
18
  export declare function approximateL1GasBuffer({ l1Reference, sizeOfData, }: {
18
19
  l1Reference: L1ExpressOrderGasReference;
19
20
  sizeOfData: bigint;
@@ -1,9 +1,24 @@
1
1
  import { IHttp } from "./types";
2
+ export declare class HttpError extends Error {
3
+ /** HTTP status code */
4
+ statusCode: number;
5
+ /** Structured error code from API (e.g. "INTERNAL_ERROR", "VALIDATION_ERROR") */
6
+ code?: string;
7
+ /** Distributed trace ID for correlating with server logs */
8
+ traceId?: string;
9
+ /** Full parsed response body */
10
+ body?: Record<string, any>;
11
+ constructor(statusCode: number, message: string, body?: Record<string, any>);
12
+ }
2
13
  export declare class HttpClient implements IHttp {
3
14
  readonly url: string;
4
- constructor(url: string);
15
+ private readonly timeoutMs;
16
+ constructor(url: string, timeoutMs?: number);
5
17
  fetchJson<TResult>(path: string, opts?: {
6
18
  query?: Record<string, any>;
7
19
  transform?: (result: any) => TResult;
8
20
  }): Promise<TResult>;
21
+ postJson<TResult>(path: string, body: unknown, opts?: {
22
+ transform?: (result: any) => TResult;
23
+ }): Promise<TResult>;
9
24
  }
@@ -0,0 +1,18 @@
1
+ import { IHttp } from "./types";
2
+ export declare class HttpClientWithFallback implements IHttp {
3
+ private clients;
4
+ private primaryIndex;
5
+ private failureTimestamps;
6
+ constructor(urls: string[], timeoutMs?: number);
7
+ get url(): string;
8
+ fetchJson<TResult>(path: string, opts?: {
9
+ query?: Record<string, any>;
10
+ transform?: (result: any) => TResult;
11
+ }): Promise<TResult>;
12
+ postJson<TResult>(path: string, body: unknown, opts?: {
13
+ transform?: (result: any) => TResult;
14
+ }): Promise<TResult>;
15
+ private withFallback;
16
+ private getClientOrder;
17
+ private recordFailure;
18
+ }
@@ -4,4 +4,7 @@ export type IHttp = {
4
4
  query?: Record<string, any>;
5
5
  transform?: (result: any) => TResult;
6
6
  }) => Promise<TResult>;
7
+ postJson: <TResult>(path: string, body: unknown, opts?: {
8
+ transform?: (result: any) => TResult;
9
+ }) => Promise<TResult>;
7
10
  };
@@ -62,6 +62,10 @@ export type MarketInfo = Market & MarketPoolTokens & {
62
62
  swapImpactPoolAmountShort: bigint;
63
63
  maxPnlFactorForTradersLong: bigint;
64
64
  maxPnlFactorForTradersShort: bigint;
65
+ maxPnlFactorForDepositsLong?: bigint;
66
+ maxPnlFactorForDepositsShort?: bigint;
67
+ maxPnlFactorForWithdrawalsLong?: bigint;
68
+ maxPnlFactorForWithdrawalsShort?: bigint;
65
69
  claimableFundingAmountLong?: bigint;
66
70
  claimableFundingAmountShort?: bigint;
67
71
  longInterestUsd: bigint;
@@ -118,7 +122,7 @@ export type MarketValues = Pick<MarketInfo, "longInterestUsd" | "shortInterestUs
118
122
  /**
119
123
  * Updates seldom
120
124
  */
121
- export type MarketConfig = Pick<MarketInfo, "isDisabled" | "maxLongPoolUsdForDeposit" | "maxShortPoolUsdForDeposit" | "maxLongPoolAmount" | "maxShortPoolAmount" | "reserveFactorLong" | "reserveFactorShort" | "openInterestReserveFactorLong" | "openInterestReserveFactorShort" | "maxOpenInterestLong" | "maxOpenInterestShort" | "minPositionImpactPoolAmount" | "positionImpactPoolDistributionRate" | "borrowingFactorLong" | "borrowingFactorShort" | "borrowingExponentFactorLong" | "borrowingExponentFactorShort" | "fundingFactor" | "fundingExponentFactor" | "fundingIncreaseFactorPerSecond" | "fundingDecreaseFactorPerSecond" | "thresholdForDecreaseFunding" | "thresholdForStableFunding" | "minFundingFactorPerSecond" | "maxFundingFactorPerSecond" | "maxPnlFactorForTradersLong" | "maxPnlFactorForTradersShort" | "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" | "virtualLongTokenId" | "virtualShortTokenId">;
125
+ export type MarketConfig = Pick<MarketInfo, "isDisabled" | "maxLongPoolUsdForDeposit" | "maxShortPoolUsdForDeposit" | "maxLongPoolAmount" | "maxShortPoolAmount" | "reserveFactorLong" | "reserveFactorShort" | "openInterestReserveFactorLong" | "openInterestReserveFactorShort" | "maxOpenInterestLong" | "maxOpenInterestShort" | "minPositionImpactPoolAmount" | "positionImpactPoolDistributionRate" | "borrowingFactorLong" | "borrowingFactorShort" | "borrowingExponentFactorLong" | "borrowingExponentFactorShort" | "fundingFactor" | "fundingExponentFactor" | "fundingIncreaseFactorPerSecond" | "fundingDecreaseFactorPerSecond" | "thresholdForDecreaseFunding" | "thresholdForStableFunding" | "minFundingFactorPerSecond" | "maxFundingFactorPerSecond" | "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" | "virtualLongTokenId" | "virtualShortTokenId">;
122
126
  export type MarketsData = {
123
127
  [marketTokenAddress: string]: Market;
124
128
  };
@@ -0,0 +1,4 @@
1
+ export type IMetrics = {
2
+ pushError(error: unknown, source: string): void;
3
+ };
4
+ export declare const noopMetrics: IMetrics;
@@ -23,6 +23,7 @@ export type NonZero<T extends number | bigint> = T & {
23
23
  export declare function isNonZero<T extends number | bigint>(value: T): value is NonZero<T>;
24
24
  export declare function safeDivide<T extends number | bigint>(a: T, b: NonZero<T>): T;
25
25
  export declare function expandDecimals(n: BigNumberish, decimals: number): bigint;
26
+ export declare function toBigInt(value: BigNumberish | undefined | null): bigint | undefined;
26
27
  export declare function basisPointsToFloat(basisPoints: bigint): bigint;
27
28
  export declare function getBasisPoints(numerator: bigint, denominator: bigint, shouldRoundUp?: boolean): bigint;
28
29
  export declare function roundUpMagnitudeDivision(a: bigint, b: bigint): bigint;
@@ -81,6 +82,7 @@ export declare function formatRatePercentage(rate?: bigint, opts?: {
81
82
  }): string;
82
83
  export declare function formatUsdPrice(price?: bigint, opts?: Parameters<typeof formatUsd>[1]): string | undefined;
83
84
  export declare function formatPercentageDisplay(percentage: number, hideThreshold?: number): string;
85
+ export declare function formatNumberHuman(n: number, showDollar?: boolean, displayDecimals?: number): string;
84
86
  export declare function formatAmountHuman(amount: BigNumberish | undefined, tokenDecimals: number, showDollar?: boolean, displayDecimals?: number): string;
85
87
  export declare function formatBalanceAmount(amount: bigint, tokenDecimals: number, tokenSymbol?: string, { showZero, toExponential, isStable, signed, }?: {
86
88
  showZero?: boolean;
@@ -113,11 +115,6 @@ export declare function roundWithDecimals(value: BigNumberish, opts: {
113
115
  decimals: number;
114
116
  }): bigint;
115
117
  export declare function toBigNumberWithDecimals(value: string, decimals: number): bigint;
116
- /**
117
- *
118
- * @deprecated Use BigInt instead
119
- */
120
- export declare function bigNumberify(n?: BigNumberish | null | undefined): bigint | undefined;
121
118
  export declare const parseValue: (value: string, tokenDecimals: number) => bigint | undefined;
122
119
  export declare function roundUpDivision(a: bigint, b: bigint): bigint;
123
120
  export declare function roundToTwoDecimals(n: number): number;
@@ -0,0 +1,158 @@
1
+ import type { ContractsChainId } from "../../configs/chains";
2
+ import { IHttp } from "../http/types";
3
+ import type { IAbstractSigner } from "../signer";
4
+ export type OrderKind = "increase" | "decrease" | "swap";
5
+ export type SimpleOrderType = "market" | "limit" | "stop-market" | "take-profit" | "stop-loss" | "twap";
6
+ export type TransactionMode = "express" | "classic";
7
+ export type PrepareOrderRequest = {
8
+ kind: OrderKind;
9
+ symbol?: string;
10
+ direction?: "long" | "short";
11
+ orderType: SimpleOrderType;
12
+ size?: bigint;
13
+ triggerPrice?: bigint;
14
+ slippage?: number;
15
+ collateralToken?: string;
16
+ collateralToPay?: {
17
+ amount: bigint;
18
+ token: string;
19
+ };
20
+ receiveToken?: string;
21
+ keepLeverage?: boolean;
22
+ manualSwapPath?: string[];
23
+ acceptablePriceImpactBps?: bigint;
24
+ executionFeeBufferBps?: number;
25
+ twapConfig?: {
26
+ duration: number;
27
+ parts: number;
28
+ frequency?: number;
29
+ };
30
+ tpsl?: {
31
+ type: "take-profit" | "stop-loss";
32
+ triggerPrice: bigint;
33
+ size?: bigint;
34
+ }[];
35
+ gasPaymentToken?: string;
36
+ mode: TransactionMode;
37
+ from: string;
38
+ subaccountAddress?: string;
39
+ subaccountApproval?: Record<string, any>;
40
+ };
41
+ export type OrderEstimates = {
42
+ positionPriceImpactDeltaUsd: bigint;
43
+ swapPriceImpactDeltaUsd: bigint;
44
+ executionFeeAmount: bigint;
45
+ acceptablePrice: bigint;
46
+ sizeDeltaUsd: bigint;
47
+ positionFeeUsd: bigint;
48
+ borrowingFeeUsd: bigint;
49
+ fundingFeeUsd: bigint;
50
+ };
51
+ export type PrepareOrderResponse = {
52
+ requestId: string;
53
+ idempotencyKey?: string;
54
+ payloadType: "transaction" | "typed-data";
55
+ mode: TransactionMode;
56
+ payload: Record<string, any>;
57
+ estimates?: OrderEstimates;
58
+ expiresAt?: number;
59
+ warnings?: string[];
60
+ traceId?: string;
61
+ };
62
+ export type SubmitOrderRequest = {
63
+ mode: TransactionMode;
64
+ requestId?: string;
65
+ signature?: string;
66
+ from?: string;
67
+ eip712Data?: Record<string, any>;
68
+ idempotencyKey?: string;
69
+ };
70
+ export type SubmitOrderResponse = {
71
+ requestId: string;
72
+ status: "prepared" | "relay_accepted" | "relay_pending" | "relay_submitted" | "created" | "executed" | "cancelled" | "relay_failed" | "relay_reverted";
73
+ txHash?: string;
74
+ taskId?: string;
75
+ error?: {
76
+ code: string;
77
+ message: string;
78
+ };
79
+ traceId?: string;
80
+ };
81
+ export type OrderStatusRequest = {
82
+ requestId?: string;
83
+ idempotencyKey?: string;
84
+ };
85
+ export type OrderStatusResponse = {
86
+ requestId: string;
87
+ status: "prepared" | "relay_accepted" | "relay_pending" | "relay_submitted" | "created" | "executed" | "cancelled" | "relay_failed" | "relay_reverted";
88
+ txHash?: string;
89
+ createdTxnHash?: string;
90
+ executionTxnHash?: string;
91
+ orderKeys?: string[];
92
+ cancellationReason?: string;
93
+ taskId?: string;
94
+ error?: {
95
+ code: string;
96
+ message: string;
97
+ };
98
+ createdAt?: string;
99
+ updatedAt?: string;
100
+ traceId?: string;
101
+ };
102
+ export type PrepareEditOrderRequest = {
103
+ orderIds: string[];
104
+ newSize?: bigint;
105
+ newTriggerPrice?: bigint;
106
+ newAcceptablePrice?: bigint;
107
+ newAutoCancel?: boolean;
108
+ executionFeeTopUp?: bigint;
109
+ mode: TransactionMode;
110
+ from: string;
111
+ subaccountAddress?: string;
112
+ subaccountApproval?: Record<string, any>;
113
+ };
114
+ export type PrepareCancelOrderRequest = {
115
+ orderId?: string;
116
+ orderIds?: string[];
117
+ all?: boolean;
118
+ mode: TransactionMode;
119
+ from: string;
120
+ subaccountAddress?: string;
121
+ subaccountApproval?: Record<string, any>;
122
+ };
123
+ export type CollateralOperation = "deposit" | "withdraw";
124
+ export type PrepareCollateralRequest = {
125
+ operation: CollateralOperation;
126
+ positionKey: string;
127
+ amount: bigint;
128
+ slippage?: number;
129
+ executionFeeBufferBps?: number;
130
+ gasPaymentToken?: string;
131
+ mode: TransactionMode;
132
+ from: string;
133
+ subaccountAddress?: string;
134
+ subaccountApproval?: Record<string, any>;
135
+ };
136
+ export declare function prepareOrder(ctx: {
137
+ api: IHttp;
138
+ }, request: PrepareOrderRequest): Promise<PrepareOrderResponse>;
139
+ export declare function submitOrder(ctx: {
140
+ api: IHttp;
141
+ }, request: SubmitOrderRequest): Promise<SubmitOrderResponse>;
142
+ export declare function prepareEditOrder(ctx: {
143
+ api: IHttp;
144
+ }, request: PrepareEditOrderRequest): Promise<PrepareOrderResponse>;
145
+ export declare function prepareCancelOrder(ctx: {
146
+ api: IHttp;
147
+ }, request: PrepareCancelOrderRequest): Promise<PrepareOrderResponse>;
148
+ export declare function prepareCollateral(ctx: {
149
+ api: IHttp;
150
+ }, request: PrepareCollateralRequest): Promise<PrepareOrderResponse>;
151
+ export declare function fetchOrderStatus(ctx: {
152
+ api: IHttp;
153
+ }, request: OrderStatusRequest): Promise<OrderStatusResponse>;
154
+ export declare function signPreparedOrder(prepared: PrepareOrderResponse, signer: IAbstractSigner, chainId?: ContractsChainId, accountAddress?: string): Promise<string>;
155
+ export declare function executeExpressOrder(ctx: {
156
+ api: IHttp;
157
+ chainId?: ContractsChainId;
158
+ }, request: PrepareOrderRequest, signer: IAbstractSigner, accountAddress?: string): Promise<SubmitOrderResponse>;
@@ -1 +1,2 @@
1
1
  export * from "./utils";
2
+ export * from "./api";
@@ -0,0 +1,6 @@
1
+ import { ContractsChainId } from "../../configs/chains";
2
+ import type { TypedDataDomain, TypedDataTypes } from "../signer";
3
+ export declare function validateOrderTypedData(domain: TypedDataDomain, types: TypedDataTypes, message: Record<string, any>, chainId: ContractsChainId, signerAddress: string,
4
+ /** For subaccount orders, the main account (owner) is a valid receiver */
5
+ accountAddress?: string): void;
6
+ export declare function validateSubaccountApprovalTypedData(domain: TypedDataDomain, message: Record<string, any>, chainId: ContractsChainId, signerAddress: string, expectedSubaccountAddress: string): void;
@@ -31,23 +31,15 @@ export declare function getPositionPendingFeesUsd(p: {
31
31
  pendingBorrowingFeesUsd: bigint;
32
32
  }): bigint;
33
33
  export declare function getPositionNetValue(p: {
34
- totalPendingImpactDeltaUsd: bigint;
35
- priceImpactDiffUsd: bigint;
36
34
  collateralUsd: bigint;
37
35
  pendingFundingFeesUsd: bigint;
38
36
  pendingBorrowingFeesUsd: bigint;
39
37
  pnl: bigint;
40
- closingFeeUsd: bigint;
41
- uiFeeUsd: bigint;
42
38
  }): bigint;
43
- export declare function getPositionPnlAfterFees({ pnl, pendingBorrowingFeesUsd, pendingFundingFeesUsd, closingFeeUsd, uiFeeUsd, totalPendingImpactDeltaUsd, priceImpactDiffUsd, }: {
39
+ export declare function getPositionPnlAfterFees({ pnl, pendingBorrowingFeesUsd, pendingFundingFeesUsd, }: {
44
40
  pnl: bigint;
45
41
  pendingBorrowingFeesUsd: bigint;
46
42
  pendingFundingFeesUsd: bigint;
47
- closingFeeUsd: bigint;
48
- uiFeeUsd: bigint;
49
- totalPendingImpactDeltaUsd: bigint;
50
- priceImpactDiffUsd: bigint;
51
43
  }): bigint;
52
44
  export declare function getLeverage(p: {
53
45
  sizeInUsd: bigint;
@@ -0,0 +1,3 @@
1
+ import type { PublicClient } from "viem";
2
+ import type { IRpc } from "./index";
3
+ export declare function createViemRpc(client: PublicClient): IRpc;
@@ -0,0 +1,26 @@
1
+ export { createViemRpc } from "./createViemRpc";
2
+ export type StateOverrideEntry = {
3
+ address: string;
4
+ stateDiff?: {
5
+ slot: string;
6
+ value: string;
7
+ }[];
8
+ balance?: bigint;
9
+ nonce?: number;
10
+ code?: string;
11
+ };
12
+ export type RpcCallParams = {
13
+ to: string;
14
+ data: string;
15
+ from?: string;
16
+ value?: bigint;
17
+ gas?: bigint;
18
+ stateOverride?: StateOverrideEntry[];
19
+ };
20
+ export type RpcEstimateGasParams = RpcCallParams & {
21
+ stateOverride?: StateOverrideEntry[];
22
+ };
23
+ export interface IRpc {
24
+ estimateGas(params: RpcEstimateGasParams): Promise<bigint>;
25
+ call(params: RpcCallParams): Promise<string>;
26
+ }
@@ -0,0 +1,23 @@
1
+ export type TypedDataDomain = {
2
+ name: string;
3
+ version: string;
4
+ chainId: number;
5
+ verifyingContract: string;
6
+ };
7
+ export type TypedDataTypes = Record<string, {
8
+ name: string;
9
+ type: string;
10
+ }[]>;
11
+ export interface IAbstractSigner {
12
+ readonly address: string;
13
+ signTypedData(domain: TypedDataDomain, types: TypedDataTypes, value: Record<string, any>): Promise<string>;
14
+ signMessage(message: string): Promise<string>;
15
+ sendTransaction?(tx: {
16
+ to: string;
17
+ data: string;
18
+ value?: bigint;
19
+ }): Promise<string | {
20
+ hash: string;
21
+ }>;
22
+ }
23
+ export { PrivateKeySigner } from "./privateKeySigner";
@@ -0,0 +1,19 @@
1
+ import { type Chain } from "viem";
2
+ import type { IAbstractSigner, TypedDataDomain, TypedDataTypes } from "./index";
3
+ export declare class PrivateKeySigner implements IAbstractSigner {
4
+ readonly address: string;
5
+ private account;
6
+ private _chain?;
7
+ private _rpcUrl?;
8
+ constructor(privateKey: `0x${string}`, options?: {
9
+ rpcUrl?: string;
10
+ chain?: Chain;
11
+ });
12
+ signTypedData(domain: TypedDataDomain, types: TypedDataTypes, value: Record<string, any>): Promise<string>;
13
+ signMessage(message: string): Promise<string>;
14
+ sendTransaction(tx: {
15
+ to: string;
16
+ data: string;
17
+ value?: bigint;
18
+ }): Promise<string>;
19
+ }
@@ -0,0 +1,51 @@
1
+ import type { ContractsChainId } from "../../configs/chains";
2
+ import { IHttp } from "../http/types";
3
+ import type { IAbstractSigner } from "../signer";
4
+ export type SubaccountStatusRequest = {
5
+ account: string;
6
+ subaccountAddress: string;
7
+ };
8
+ export type SubaccountStatusResponse = {
9
+ active: boolean;
10
+ maxAllowedCount: string;
11
+ currentActionsCount: string;
12
+ remainingActions: string;
13
+ expiresAt: string;
14
+ approvalNonce: string;
15
+ multichainApprovalNonce: string;
16
+ integrationId: string | null;
17
+ };
18
+ export type SubaccountApprovalPrepareRequest = {
19
+ account: string;
20
+ subaccountAddress: string;
21
+ shouldAdd?: boolean;
22
+ expiresAt: string;
23
+ maxAllowedCount: string;
24
+ signingNetwork?: string;
25
+ };
26
+ export type SubaccountApprovalPrepareResponse = {
27
+ domain: {
28
+ name: string;
29
+ version: string;
30
+ chainId: number;
31
+ verifyingContract: string;
32
+ };
33
+ types: Record<string, {
34
+ name: string;
35
+ type: string;
36
+ }[]>;
37
+ message: Record<string, any>;
38
+ primaryType: string;
39
+ relayRouterAddress: string;
40
+ nonce: string;
41
+ };
42
+ export declare function fetchSubaccountStatus(ctx: {
43
+ api: IHttp;
44
+ }, request: SubaccountStatusRequest): Promise<SubaccountStatusResponse>;
45
+ export declare function prepareSubaccountApproval(ctx: {
46
+ api: IHttp;
47
+ }, request: SubaccountApprovalPrepareRequest): Promise<SubaccountApprovalPrepareResponse>;
48
+ export declare function signSubaccountApproval(prepared: SubaccountApprovalPrepareResponse, signer: IAbstractSigner, options?: {
49
+ chainId?: ContractsChainId;
50
+ expectedSubaccountAddress?: string;
51
+ }): Promise<string>;
@@ -0,0 +1,8 @@
1
+ import type { IAbstractSigner } from "../signer";
2
+ import { PrivateKeySigner } from "../signer";
3
+ export type GeneratedSubaccount = {
4
+ address: string;
5
+ signer: PrivateKeySigner;
6
+ privateKey: string;
7
+ };
8
+ export declare function generateSubaccount(mainSigner: IAbstractSigner): Promise<GeneratedSubaccount>;
@@ -0,0 +1,9 @@
1
+ import type { ContractsChainId } from "../../configs/chains";
2
+ import type { SubaccountApproval } from "./types";
3
+ /**
4
+ * Returns a subaccount approval with zeroed-out fields.
5
+ * Used as a placeholder for gas estimation when no real approval is available.
6
+ */
7
+ export declare function getEmptySubaccountApproval(chainId: ContractsChainId, subaccountAddress: string): SubaccountApproval & {
8
+ signature: string;
9
+ };
@@ -0,0 +1,24 @@
1
+ import type { ContractsChainId } from "../../configs/chains";
2
+ export type SubaccountApprovalTypedData = {
3
+ domain: {
4
+ name: string;
5
+ version: string;
6
+ chainId: number;
7
+ verifyingContract: string;
8
+ };
9
+ types: Record<string, {
10
+ name: string;
11
+ type: string;
12
+ }[]>;
13
+ message: Record<string, any>;
14
+ primaryType: string;
15
+ };
16
+ export declare function getSubaccountApprovalTypedData(params: {
17
+ chainId: ContractsChainId;
18
+ subaccountAddress: string;
19
+ shouldAdd: boolean;
20
+ expiresAt: bigint;
21
+ maxAllowedCount: bigint;
22
+ nonce: bigint;
23
+ signingChainId?: number;
24
+ }): SubaccountApprovalTypedData;
@@ -0,0 +1 @@
1
+ export declare function hashSubaccountApproval(approval: Record<string, any>): string;
@@ -0,0 +1,7 @@
1
+ export * from "./types";
2
+ export { generateSubaccount, type GeneratedSubaccount } from "./generateSubaccount";
3
+ export { hashSubaccountApproval } from "./hashSubaccountApproval";
4
+ export { getEmptySubaccountApproval } from "./getEmptySubaccountApproval";
5
+ export { getSubaccountApprovalTypedData, type SubaccountApprovalTypedData, } from "./getSubaccountApprovalTypedData";
6
+ export { fetchSubaccountStatus, prepareSubaccountApproval, signSubaccountApproval, } from "./api";
7
+ export type { SubaccountStatusRequest, SubaccountStatusResponse, SubaccountApprovalPrepareRequest, SubaccountApprovalPrepareResponse, } from "./api";
@@ -0,0 +1,55 @@
1
+ import type { AnyChainId, ContractsChainId } from "../../configs/chains";
2
+ import type { IAbstractSigner } from "../signer";
3
+ export type SubaccountOnchainData = {
4
+ active: boolean;
5
+ maxAllowedCount: bigint;
6
+ currentActionsCount: bigint;
7
+ expiresAt: bigint;
8
+ approvalNonce: bigint;
9
+ multichainApprovalNonce: bigint;
10
+ integrationId: string | undefined;
11
+ };
12
+ export type SubaccountSerializedConfig = {
13
+ privateKey: string;
14
+ address: string;
15
+ isNew?: boolean;
16
+ };
17
+ export type SubaccountApproval = {
18
+ subaccount: string;
19
+ nonce: bigint;
20
+ shouldAdd: boolean;
21
+ expiresAt: bigint;
22
+ maxAllowedCount: bigint;
23
+ actionType: string;
24
+ desChainId: bigint;
25
+ deadline: bigint;
26
+ integrationId: string;
27
+ };
28
+ export type SignedSubaccountApproval = SubaccountApproval & {
29
+ signature: string;
30
+ signedAt: number;
31
+ signatureChainId: AnyChainId;
32
+ subaccountRouterAddress: string;
33
+ };
34
+ export type Subaccount = {
35
+ address: string;
36
+ chainId: ContractsChainId;
37
+ signerChainId: AnyChainId;
38
+ signer: IAbstractSigner;
39
+ signedApproval: SignedSubaccountApproval;
40
+ onchainData: SubaccountOnchainData;
41
+ };
42
+ export type SubaccountValidations = {
43
+ isExpired: boolean;
44
+ isActionsExceeded: boolean;
45
+ isNonceExpired: boolean;
46
+ isApprovalInvalid: boolean;
47
+ isValid: boolean;
48
+ };
49
+ export type SubaccountSession = {
50
+ address: string;
51
+ approval?: {
52
+ message: Record<string, any>;
53
+ signature: string;
54
+ };
55
+ };
@@ -3,7 +3,7 @@ import { SwapPricingType } from "../orders/types";
3
3
  import { SwapStrategyForSwapOrders } from "./types";
4
4
  import { TokenData } from "../tokens/types";
5
5
  import { ExternalSwapQuoteParams, SwapOptimizationOrderArray } from "../trade/types";
6
- export declare function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType, allowSameTokenSwap, }: {
6
+ export declare function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, swapPricingType, allowSameTokenSwap, disabledMarkets, manualPath, }: {
7
7
  chainId: number;
8
8
  amountIn: bigint;
9
9
  tokenIn: TokenData;
@@ -13,8 +13,10 @@ export declare function buildSwapStrategy({ amountIn, tokenIn, tokenOut, markets
13
13
  externalSwapQuoteParams: ExternalSwapQuoteParams;
14
14
  swapPricingType: SwapPricingType;
15
15
  allowSameTokenSwap: boolean;
16
+ disabledMarkets?: string[];
17
+ manualPath?: string[];
16
18
  }): SwapStrategyForSwapOrders;
17
- export declare function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, swapPricingType, allowSameTokenSwap, }: {
19
+ export declare function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, swapPricingType, allowSameTokenSwap, disabledMarkets, manualPath, }: {
18
20
  chainId: number;
19
21
  amountOut: bigint;
20
22
  tokenIn: TokenData;
@@ -24,4 +26,6 @@ export declare function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut,
24
26
  swapOptimizationOrder: SwapOptimizationOrderArray | undefined;
25
27
  swapPricingType: SwapPricingType;
26
28
  allowSameTokenSwap: boolean;
29
+ disabledMarkets?: string[];
30
+ manualPath?: string[];
27
31
  }): SwapStrategyForSwapOrders;
@@ -37,6 +37,20 @@ export declare function getSwapStats(p: {
37
37
  shouldApplyPriceImpact: boolean;
38
38
  swapPricingType: SwapPricingType;
39
39
  }): SwapStats;
40
+ /**
41
+ * Mirrors the on-chain `SwapUtils.validateMaxPnl` check: after the swap is
42
+ * applied, BOTH the long and short PnL-to-pool factors must be within their
43
+ * limit. The shrinking (token-out) side is capped at MAX_PNL_FACTOR_FOR_WITHDRAWALS,
44
+ * the growing (token-in) side at MAX_PNL_FACTOR_FOR_DEPOSITS.
45
+ */
46
+ export declare function getIsMaxPnlFactorExceededAfterSwap(p: {
47
+ marketInfo: MarketInfo;
48
+ /**
49
+ * Money in long side and out from short side
50
+ */
51
+ isLong: boolean;
52
+ usdIn: bigint;
53
+ }): boolean;
40
54
  export declare function getMaxSwapPathLiquidity(p: {
41
55
  marketsInfoData: MarketsInfoData;
42
56
  swapPath: string[];