@nadohq/engine-client 0.1.0-alpha.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 (142) hide show
  1. package/README.md +2 -0
  2. package/dist/EngineBaseClient.cjs +166 -0
  3. package/dist/EngineBaseClient.cjs.map +1 -0
  4. package/dist/EngineBaseClient.d.cts +75 -0
  5. package/dist/EngineBaseClient.d.ts +75 -0
  6. package/dist/EngineBaseClient.js +133 -0
  7. package/dist/EngineBaseClient.js.map +1 -0
  8. package/dist/EngineClient.cjs +40 -0
  9. package/dist/EngineClient.cjs.map +1 -0
  10. package/dist/EngineClient.d.cts +23 -0
  11. package/dist/EngineClient.d.ts +23 -0
  12. package/dist/EngineClient.js +15 -0
  13. package/dist/EngineClient.js.map +1 -0
  14. package/dist/EngineExecuteBuilder.cjs +304 -0
  15. package/dist/EngineExecuteBuilder.cjs.map +1 -0
  16. package/dist/EngineExecuteBuilder.d.cts +118 -0
  17. package/dist/EngineExecuteBuilder.d.ts +118 -0
  18. package/dist/EngineExecuteBuilder.js +282 -0
  19. package/dist/EngineExecuteBuilder.js.map +1 -0
  20. package/dist/EngineExecuteClient.cjs +114 -0
  21. package/dist/EngineExecuteClient.cjs.map +1 -0
  22. package/dist/EngineExecuteClient.d.cts +28 -0
  23. package/dist/EngineExecuteClient.d.ts +28 -0
  24. package/dist/EngineExecuteClient.js +89 -0
  25. package/dist/EngineExecuteClient.js.map +1 -0
  26. package/dist/EngineQueryClient.cjs +431 -0
  27. package/dist/EngineQueryClient.cjs.map +1 -0
  28. package/dist/EngineQueryClient.d.cts +143 -0
  29. package/dist/EngineQueryClient.d.ts +143 -0
  30. package/dist/EngineQueryClient.js +424 -0
  31. package/dist/EngineQueryClient.js.map +1 -0
  32. package/dist/EngineWebClient.cjs +75 -0
  33. package/dist/EngineWebClient.cjs.map +1 -0
  34. package/dist/EngineWebClient.d.cts +31 -0
  35. package/dist/EngineWebClient.d.ts +31 -0
  36. package/dist/EngineWebClient.js +50 -0
  37. package/dist/EngineWebClient.js.map +1 -0
  38. package/dist/endpoints.cjs +49 -0
  39. package/dist/endpoints.cjs.map +1 -0
  40. package/dist/endpoints.d.cts +7 -0
  41. package/dist/endpoints.d.ts +7 -0
  42. package/dist/endpoints.js +22 -0
  43. package/dist/endpoints.js.map +1 -0
  44. package/dist/index.cjs +31 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.d.cts +20 -0
  47. package/dist/index.d.ts +20 -0
  48. package/dist/index.js +6 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/types/EngineServerFailureError.cjs +36 -0
  51. package/dist/types/EngineServerFailureError.cjs.map +1 -0
  52. package/dist/types/EngineServerFailureError.d.cts +11 -0
  53. package/dist/types/EngineServerFailureError.d.ts +11 -0
  54. package/dist/types/EngineServerFailureError.js +11 -0
  55. package/dist/types/EngineServerFailureError.js.map +1 -0
  56. package/dist/types/clientExecuteTypes.cjs +19 -0
  57. package/dist/types/clientExecuteTypes.cjs.map +1 -0
  58. package/dist/types/clientExecuteTypes.d.cts +74 -0
  59. package/dist/types/clientExecuteTypes.d.ts +74 -0
  60. package/dist/types/clientExecuteTypes.js +1 -0
  61. package/dist/types/clientExecuteTypes.js.map +1 -0
  62. package/dist/types/clientQueryTypes.cjs +19 -0
  63. package/dist/types/clientQueryTypes.cjs.map +1 -0
  64. package/dist/types/clientQueryTypes.d.cts +189 -0
  65. package/dist/types/clientQueryTypes.d.ts +189 -0
  66. package/dist/types/clientQueryTypes.js +1 -0
  67. package/dist/types/clientQueryTypes.js.map +1 -0
  68. package/dist/types/index.cjs +39 -0
  69. package/dist/types/index.cjs.map +1 -0
  70. package/dist/types/index.d.cts +10 -0
  71. package/dist/types/index.d.ts +10 -0
  72. package/dist/types/index.js +10 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/types/serverExecuteTypes.cjs +19 -0
  75. package/dist/types/serverExecuteTypes.cjs.map +1 -0
  76. package/dist/types/serverExecuteTypes.d.cts +91 -0
  77. package/dist/types/serverExecuteTypes.d.ts +91 -0
  78. package/dist/types/serverExecuteTypes.js +1 -0
  79. package/dist/types/serverExecuteTypes.js.map +1 -0
  80. package/dist/types/serverQueryModelTypes.cjs +19 -0
  81. package/dist/types/serverQueryModelTypes.cjs.map +1 -0
  82. package/dist/types/serverQueryModelTypes.d.cts +73 -0
  83. package/dist/types/serverQueryModelTypes.d.ts +73 -0
  84. package/dist/types/serverQueryModelTypes.js +1 -0
  85. package/dist/types/serverQueryModelTypes.js.map +1 -0
  86. package/dist/types/serverQueryTypes.cjs +19 -0
  87. package/dist/types/serverQueryTypes.cjs.map +1 -0
  88. package/dist/types/serverQueryTypes.d.cts +292 -0
  89. package/dist/types/serverQueryTypes.d.ts +292 -0
  90. package/dist/types/serverQueryTypes.js +1 -0
  91. package/dist/types/serverQueryTypes.js.map +1 -0
  92. package/dist/types/serverSubscriptionEventTypes.cjs +19 -0
  93. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -0
  94. package/dist/types/serverSubscriptionEventTypes.d.cts +71 -0
  95. package/dist/types/serverSubscriptionEventTypes.d.ts +71 -0
  96. package/dist/types/serverSubscriptionEventTypes.js +1 -0
  97. package/dist/types/serverSubscriptionEventTypes.js.map +1 -0
  98. package/dist/types/serverSubscriptionTypes.cjs +19 -0
  99. package/dist/types/serverSubscriptionTypes.cjs.map +1 -0
  100. package/dist/types/serverSubscriptionTypes.d.cts +63 -0
  101. package/dist/types/serverSubscriptionTypes.d.ts +63 -0
  102. package/dist/types/serverSubscriptionTypes.js +1 -0
  103. package/dist/types/serverSubscriptionTypes.js.map +1 -0
  104. package/dist/utils/index.cjs +25 -0
  105. package/dist/utils/index.cjs.map +1 -0
  106. package/dist/utils/index.d.cts +6 -0
  107. package/dist/utils/index.d.ts +6 -0
  108. package/dist/utils/index.js +3 -0
  109. package/dist/utils/index.js.map +1 -0
  110. package/dist/utils/productEngineTypeMappers.cjs +49 -0
  111. package/dist/utils/productEngineTypeMappers.cjs.map +1 -0
  112. package/dist/utils/productEngineTypeMappers.d.cts +7 -0
  113. package/dist/utils/productEngineTypeMappers.d.ts +7 -0
  114. package/dist/utils/productEngineTypeMappers.js +23 -0
  115. package/dist/utils/productEngineTypeMappers.js.map +1 -0
  116. package/dist/utils/queryDataMappers.cjs +282 -0
  117. package/dist/utils/queryDataMappers.cjs.map +1 -0
  118. package/dist/utils/queryDataMappers.d.cts +18 -0
  119. package/dist/utils/queryDataMappers.d.ts +18 -0
  120. package/dist/utils/queryDataMappers.js +258 -0
  121. package/dist/utils/queryDataMappers.js.map +1 -0
  122. package/package.json +52 -0
  123. package/src/EngineBaseClient.ts +223 -0
  124. package/src/EngineClient.ts +13 -0
  125. package/src/EngineExecuteBuilder.ts +381 -0
  126. package/src/EngineExecuteClient.ts +122 -0
  127. package/src/EngineQueryClient.ts +553 -0
  128. package/src/EngineWebClient.ts +72 -0
  129. package/src/endpoints.ts +21 -0
  130. package/src/index.ts +4 -0
  131. package/src/types/EngineServerFailureError.ts +12 -0
  132. package/src/types/clientExecuteTypes.ts +118 -0
  133. package/src/types/clientQueryTypes.ts +267 -0
  134. package/src/types/index.ts +8 -0
  135. package/src/types/serverExecuteTypes.ts +138 -0
  136. package/src/types/serverQueryModelTypes.ts +83 -0
  137. package/src/types/serverQueryTypes.ts +382 -0
  138. package/src/types/serverSubscriptionEventTypes.ts +74 -0
  139. package/src/types/serverSubscriptionTypes.ts +79 -0
  140. package/src/utils/index.ts +1 -0
  141. package/src/utils/productEngineTypeMappers.ts +24 -0
  142. package/src/utils/queryDataMappers.ts +303 -0
@@ -0,0 +1,72 @@
1
+ import { EngineBaseClient } from './EngineBaseClient';
2
+ import {
3
+ EngineServerIpBlockResponse,
4
+ GetEngineIpBlockStatusResponse,
5
+ GetEngineTimeResponse,
6
+ } from './types';
7
+
8
+ /**
9
+ * Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
10
+ * use cases to justify a separate package
11
+ */
12
+ export class EngineWebClient extends EngineBaseClient {
13
+ /**
14
+ * Determines the IP block status for the current client
15
+ */
16
+ async getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse> {
17
+ return (
18
+ this.axiosInstance
19
+ // Use the /time endpoint and listen to 403 responses
20
+ .get(`${this.opts.url}/ip`, {
21
+ // Allow all statuses
22
+ validateStatus: () => true,
23
+ // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false
24
+ withCredentials: false,
25
+ })
26
+ .then((res) => {
27
+ if (res.status !== 403) {
28
+ return null;
29
+ }
30
+ const resData = res.data as EngineServerIpBlockResponse;
31
+
32
+ if (!resData.blocked) {
33
+ return null;
34
+ }
35
+
36
+ return resData.reason === 'ip_query_only' ? 'query_only' : 'blocked';
37
+ })
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Determines whether a client needs to complete the cloudflare JS challenge to interact with the API
43
+ *
44
+ * @return true if the client needs to complete the JS challenge at '/challenge', false otherwise
45
+ */
46
+ async getRequiresCloudflareAuth(): Promise<boolean> {
47
+ // We use a generic endpoint and check for the CF challenge header
48
+ // Note: this uses a CORS set to the relevant frontend endpoint (ex. testnet.vertexprotocol.com) so it will NOT
49
+ // work from other domains
50
+ return this.axiosInstance
51
+ .get(`${this.opts.url}/cf-check`, {
52
+ // Allow all statuses
53
+ validateStatus: () => true,
54
+ })
55
+ .then((res) => {
56
+ if (res.status !== 403) {
57
+ return false;
58
+ }
59
+
60
+ return res.headers['cf-mitigated'] === 'challenge';
61
+ });
62
+ }
63
+
64
+ /**
65
+ * Retrieves current server epoch in milliseconds
66
+ */
67
+ async getTime(): Promise<GetEngineTimeResponse> {
68
+ return this.axiosInstance
69
+ .get(`${this.opts.url}/time`)
70
+ .then((res) => res.data as GetEngineTimeResponse);
71
+ }
72
+ }
@@ -0,0 +1,21 @@
1
+ import { ChainEnv } from '@nadohq/contracts';
2
+
3
+ export const ENGINE_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
4
+ local: 'http://localhost:80',
5
+ arbitrumTestnet: 'https://gateway.sepolia-test.vertexprotocol.com/v1',
6
+ arbitrum: 'https://gateway.prod.vertexprotocol.com/v1',
7
+ };
8
+
9
+ export const ENGINE_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
10
+ local: 'ws://localhost:80',
11
+ arbitrumTestnet: 'wss://gateway.sepolia-test.vertexprotocol.com/v1/ws',
12
+ arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/ws',
13
+ };
14
+
15
+ export const ENGINE_WS_SUBSCRIPTION_CLIENT_ENDPOINTS: Record<ChainEnv, string> =
16
+ {
17
+ local: 'ws://localhost:80',
18
+ arbitrumTestnet:
19
+ 'wss://gateway.sepolia-test.vertexprotocol.com/v1/subscribe',
20
+ arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/subscribe',
21
+ };
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export * from './EngineClient';
3
+ export * from './endpoints';
4
+ export * from './utils';
@@ -0,0 +1,12 @@
1
+ import { EngineServerQueryFailureResponse } from './serverQueryTypes';
2
+ import { EngineServerExecuteFailureResult } from './serverExecuteTypes';
3
+
4
+ export class EngineServerFailureError extends Error {
5
+ constructor(
6
+ readonly responseData:
7
+ | EngineServerQueryFailureResponse
8
+ | EngineServerExecuteFailureResult,
9
+ ) {
10
+ super();
11
+ }
12
+ }
@@ -0,0 +1,118 @@
1
+ import {
2
+ EIP712BurnVlpParams,
3
+ EIP712CancelOrdersParams,
4
+ EIP712CancelProductOrdersParams,
5
+ EIP712IsolatedOrderParams,
6
+ EIP712LinkSignerParams,
7
+ EIP712LiquidateSubaccountParams,
8
+ EIP712MintVlpParams,
9
+ EIP712OrderParams,
10
+ EIP712TransferQuoteParams,
11
+ EIP712WithdrawCollateralParams,
12
+ } from '@nadohq/contracts';
13
+ import { EngineServerExecuteSuccessResult } from './serverExecuteTypes';
14
+
15
+ /**
16
+ * Either verifying address or signature must be provided;
17
+ * If signature is not provided, the verifying address with the engine signer will be used to sign.
18
+ */
19
+ export type SignatureParams =
20
+ | {
21
+ // Endpoint address for all executes except order placement
22
+ verifyingAddr: string;
23
+ chainId: number;
24
+ }
25
+ | {
26
+ signature: string;
27
+ };
28
+
29
+ type WithoutNonce<T extends { nonce: unknown }> = Omit<T, 'nonce'>;
30
+
31
+ type WithSpotLeverage<T> = T & {
32
+ spotLeverage?: boolean;
33
+ };
34
+
35
+ export type WithSignature<T> = T & {
36
+ signature: string;
37
+ };
38
+
39
+ // Params associated with all engine executes
40
+ export type WithBaseEngineExecuteParams<T> = SignatureParams &
41
+ Omit<T, 'nonce'> & {
42
+ nonce?: string;
43
+ };
44
+
45
+ export type EngineOrderParams = WithoutNonce<EIP712OrderParams>;
46
+
47
+ export type EnginePlaceOrderParams = WithBaseEngineExecuteParams<{
48
+ id?: number;
49
+ productId: number;
50
+ order: EngineOrderParams;
51
+ // If not given, engine defaults to true (leverage/borrow enabled)
52
+ spotLeverage?: boolean;
53
+ }>;
54
+
55
+ export type EngineIsolatedOrderParams = WithoutNonce<EIP712IsolatedOrderParams>;
56
+
57
+ export type EnginePlaceIsolatedOrderParams = WithBaseEngineExecuteParams<{
58
+ id?: number;
59
+ productId: number;
60
+ order: EngineIsolatedOrderParams;
61
+ // Whether the cross subaccount can borrow quote for the margin transfer into the isolated subaccount. If not given, engine defaults to true.
62
+ borrowMargin?: boolean;
63
+ }>;
64
+
65
+ export type EngineLiquidateSubaccountParams =
66
+ WithBaseEngineExecuteParams<EIP712LiquidateSubaccountParams>;
67
+
68
+ export type EngineWithdrawCollateralParams = WithBaseEngineExecuteParams<
69
+ WithSpotLeverage<EIP712WithdrawCollateralParams>
70
+ >;
71
+
72
+ export type EngineCancelOrdersParams =
73
+ WithBaseEngineExecuteParams<EIP712CancelOrdersParams>;
74
+
75
+ export type EngineCancelAndPlaceParams = {
76
+ cancelOrders: EngineCancelOrdersParams;
77
+ placeOrder: EnginePlaceOrderParams;
78
+ };
79
+
80
+ export type EngineCancelProductOrdersParams =
81
+ WithBaseEngineExecuteParams<EIP712CancelProductOrdersParams>;
82
+
83
+ export type EngineLinkSignerParams =
84
+ WithBaseEngineExecuteParams<EIP712LinkSignerParams>;
85
+
86
+ export type EngineTransferQuoteParams =
87
+ WithBaseEngineExecuteParams<EIP712TransferQuoteParams>;
88
+
89
+ export type EngineMintVlpParams = WithBaseEngineExecuteParams<
90
+ WithSpotLeverage<EIP712MintVlpParams>
91
+ >;
92
+
93
+ export type EngineBurnVlpParams =
94
+ WithBaseEngineExecuteParams<EIP712BurnVlpParams>;
95
+
96
+ export interface EngineExecuteRequestParamsByType {
97
+ burn_vlp: EngineBurnVlpParams;
98
+ cancel_and_place: EngineCancelAndPlaceParams;
99
+ cancel_orders: EngineCancelOrdersParams;
100
+ cancel_product_orders: EngineCancelProductOrdersParams;
101
+ link_signer: EngineLinkSignerParams;
102
+ liquidate_subaccount: EngineLiquidateSubaccountParams;
103
+ mint_vlp: EngineMintVlpParams;
104
+ place_isolated_order: EnginePlaceIsolatedOrderParams;
105
+ place_order: EnginePlaceOrderParams;
106
+ transfer_quote: EngineTransferQuoteParams;
107
+ withdraw_collateral: EngineWithdrawCollateralParams;
108
+ }
109
+
110
+ export type EnginePlaceOrderResult =
111
+ EngineServerExecuteSuccessResult<'place_order'> & {
112
+ orderParams: EIP712OrderParams;
113
+ };
114
+
115
+ export type EnginePlaceIsolatedOrderResult =
116
+ EngineServerExecuteSuccessResult<'place_isolated_order'> & {
117
+ orderParams: EIP712IsolatedOrderParams;
118
+ };
@@ -0,0 +1,267 @@
1
+ import {
2
+ BalanceHealthContributions,
3
+ BalanceSide,
4
+ EIP712OrderParams,
5
+ GetAllMarketsResponse,
6
+ GetSubaccountSummaryParams,
7
+ HealthGroup,
8
+ OrderExpirationType,
9
+ PerpBalanceWithProduct,
10
+ ProductEngineType,
11
+ SignedEIP712OrderParams,
12
+ SpotBalanceWithProduct,
13
+ Subaccount,
14
+ SubaccountSummaryResponse,
15
+ } from '@nadohq/contracts';
16
+ import { BigDecimal } from '@nadohq/utils';
17
+ import {
18
+ EngineServerNoncesParams,
19
+ EngineServerTimeResponse,
20
+ } from './serverQueryTypes';
21
+
22
+ export type GetEngineSubaccountSummaryResponse = SubaccountSummaryResponse;
23
+
24
+ export type GetEngineSubaccountSummaryParams = GetSubaccountSummaryParams;
25
+
26
+ export type GetEngineIsolatedPositionsParams = Subaccount;
27
+
28
+ export interface SubaccountIsolatedPosition {
29
+ subaccount: Subaccount;
30
+ healths: BalanceHealthContributions;
31
+ quoteBalance: SpotBalanceWithProduct;
32
+ baseBalance: PerpBalanceWithProduct;
33
+ }
34
+
35
+ export type GetEngineIsolatedPositionsResponse = SubaccountIsolatedPosition[];
36
+
37
+ export type SubaccountTx = {
38
+ type: 'apply_delta';
39
+ tx: SubaccountProductDeltaTx;
40
+ };
41
+
42
+ export interface SubaccountProductDeltaTx {
43
+ productId: number;
44
+ amountDelta: BigDecimal;
45
+ vQuoteDelta: BigDecimal;
46
+ }
47
+
48
+ export interface GetEngineContractsResponse {
49
+ chainId: number;
50
+ endpointAddr: string;
51
+ /**
52
+ * Address for the orderbook contract, with the product ID being the index
53
+ */
54
+ orderbookAddrs: string[];
55
+ }
56
+
57
+ export type GetEngineEstimatedSubaccountSummaryParams =
58
+ GetSubaccountSummaryParams & {
59
+ txs: SubaccountTx[];
60
+ };
61
+
62
+ export type GetEngineNoncesParams = EngineServerNoncesParams;
63
+
64
+ export interface GetEngineNoncesResponse {
65
+ orderNonce: string;
66
+ txNonce: string;
67
+ }
68
+
69
+ export interface GetEngineSymbolsParams {
70
+ productType?: ProductEngineType;
71
+ productIds?: number[];
72
+ }
73
+
74
+ export interface EngineSymbolsResponse {
75
+ // mapping of product symbol to symbols info
76
+ symbols: Record<string, EngineSymbol>;
77
+ }
78
+
79
+ export interface EngineSymbol {
80
+ type: ProductEngineType;
81
+ productId: number;
82
+ symbol: string;
83
+ priceIncrement: BigDecimal;
84
+ sizeIncrement: BigDecimal;
85
+ minSize: BigDecimal;
86
+ minDepth: BigDecimal;
87
+ maxSpreadRate: BigDecimal;
88
+ makerFeeRate: BigDecimal;
89
+ takerFeeRate: BigDecimal;
90
+ longWeightInitial: BigDecimal;
91
+ longWeightMaintenance: BigDecimal;
92
+ }
93
+
94
+ export type GetEngineAllMarketsResponse = GetAllMarketsResponse;
95
+
96
+ export interface GetEngineHealthGroupsResponse {
97
+ healthGroups: HealthGroup[];
98
+ }
99
+
100
+ export interface GetEngineOrderParams {
101
+ productId: number;
102
+ digest: string;
103
+ }
104
+
105
+ export interface EngineOrder extends Subaccount {
106
+ productId: number;
107
+ price: BigDecimal;
108
+ // Amount initially requested
109
+ totalAmount: BigDecimal;
110
+ // Amount still unfilled
111
+ unfilledAmount: BigDecimal;
112
+ expiration: BigDecimal;
113
+ // Margin being transferred for the order, will be null if not an iso order
114
+ margin: BigDecimal | null;
115
+ nonce: string;
116
+ digest: string;
117
+ orderParams: EIP712OrderParams;
118
+ placementTime: number;
119
+ orderType: OrderExpirationType;
120
+ }
121
+
122
+ export type GetEngineOrderResponse = EngineOrder;
123
+
124
+ export interface ValidateSignedEngineOrderParams {
125
+ productId: number;
126
+ signedOrder: SignedEIP712OrderParams;
127
+ }
128
+
129
+ export interface ValidateEngineOrderParams {
130
+ productId: number;
131
+ orderbookAddr: string;
132
+ chainId: number;
133
+ order: EIP712OrderParams;
134
+ }
135
+
136
+ export interface ValidateEngineOrderResponse {
137
+ productId: number;
138
+ valid: boolean;
139
+ }
140
+
141
+ export interface GetEngineSubaccountOrdersParams extends Subaccount {
142
+ productId: number;
143
+ }
144
+
145
+ export interface EngineSubaccountOrders {
146
+ productId: number;
147
+ orders: EngineOrder[];
148
+ }
149
+
150
+ export type GetEngineSubaccountOrdersResponse = EngineSubaccountOrders;
151
+
152
+ export interface GetEngineSubaccountProductOrdersParams extends Subaccount {
153
+ productIds: number[];
154
+ }
155
+
156
+ export interface GetEngineSubaccountProductOrdersResponse {
157
+ productOrders: EngineSubaccountOrders[];
158
+ }
159
+
160
+ export type GetEngineSubaccountFeeRatesParams = Subaccount;
161
+
162
+ export interface SubaccountOrderFeeRates {
163
+ maker: BigDecimal;
164
+ taker: BigDecimal;
165
+ }
166
+
167
+ export interface GetEngineSubaccountFeeRatesResponse {
168
+ // By Product ID
169
+ orders: Record<number, SubaccountOrderFeeRates>;
170
+ withdrawal: Record<number, BigDecimal>;
171
+ liquidationSequencerFee: BigDecimal;
172
+ healthCheckSequencerFee: BigDecimal;
173
+ takerSequencerFee: BigDecimal;
174
+ }
175
+
176
+ export interface EnginePriceTickLiquidity {
177
+ price: BigDecimal;
178
+ liquidity: BigDecimal;
179
+ }
180
+
181
+ export interface GetEngineMarketLiquidityParams {
182
+ productId: number;
183
+ // The minimum depth in base price ticks (i.e. per side
184
+ depth: number;
185
+ }
186
+
187
+ export interface GetEngineMarketLiquidityResponse {
188
+ bids: EnginePriceTickLiquidity[];
189
+ asks: EnginePriceTickLiquidity[];
190
+ }
191
+
192
+ export interface GetEngineMarketPriceParams {
193
+ productId: number;
194
+ }
195
+
196
+ export interface EngineMarketPrice {
197
+ productId: number;
198
+ bid: BigDecimal;
199
+ ask: BigDecimal;
200
+ }
201
+
202
+ export type GetEngineMarketPriceResponse = EngineMarketPrice;
203
+
204
+ export interface GetEngineMarketPricesParams {
205
+ productIds: number[];
206
+ }
207
+
208
+ export interface GetEngineMarketPricesResponse {
209
+ marketPrices: EngineMarketPrice[];
210
+ }
211
+
212
+ export interface GetEngineMaxOrderSizeParams extends Subaccount {
213
+ price: BigDecimal;
214
+ productId: number;
215
+ // Note: When `reduceOnly` is true, `side` must be opposite of the current position, otherwise it returns 0.
216
+ side: BalanceSide;
217
+ // If not given, engine defaults to true (leverage/borrow enabled) for spot
218
+ // Do not pass this for perp products
219
+ spotLeverage?: boolean;
220
+ // If not given, engine defaults to false. If true, the max order size will be capped to the subaccount's current position size;
221
+ // If no position exists, it will return 0.
222
+ reduceOnly?: boolean;
223
+ }
224
+
225
+ export type GetEngineMaxOrderSizeResponse = BigDecimal;
226
+
227
+ export interface GetEngineMaxWithdrawableParams extends Subaccount {
228
+ productId: number;
229
+ // If not given, engine defaults to true (leverage/borrow enabled)
230
+ spotLeverage?: boolean;
231
+ }
232
+
233
+ export type GetEngineMaxWithdrawableResponse = BigDecimal;
234
+
235
+ export type GetEngineTimeResponse = EngineServerTimeResponse;
236
+
237
+ export type GetEngineLinkedSignerParams = Subaccount;
238
+
239
+ export interface GetEngineLinkedSignerResponse {
240
+ signer: string;
241
+ }
242
+
243
+ export type GetEngineInsuranceResponse = BigDecimal;
244
+
245
+ export interface EngineMinDepositRate {
246
+ productId: number;
247
+ minDepositRate: BigDecimal;
248
+ }
249
+
250
+ export interface GetEngineMinDepositRatesResponse {
251
+ minDepositRates: Record<number, EngineMinDepositRate>;
252
+ }
253
+
254
+ /**
255
+ * Given an IP, backend will either:
256
+ * - Allow queries only through archive / engine (query_only)
257
+ * - Block all requests (blocked)
258
+ * - Allow all requests (null)
259
+ */
260
+ export type GetEngineIpBlockStatusResponse = 'query_only' | 'blocked' | null;
261
+
262
+ export interface GetEngineMaxMintVlpAmountParams extends Subaccount {
263
+ // If not given, engine defaults to true (leverage/borrow enabled)
264
+ spotLeverage?: boolean;
265
+ }
266
+
267
+ export type GetEngineMaxMintVlpAmountResponse = BigDecimal;
@@ -0,0 +1,8 @@
1
+ export * from './clientQueryTypes';
2
+ export * from './clientExecuteTypes';
3
+ export * from './serverQueryTypes';
4
+ export * from './serverQueryModelTypes';
5
+ export * from './serverExecuteTypes';
6
+ export * from './serverSubscriptionTypes';
7
+ export * from './serverSubscriptionEventTypes';
8
+ export * from './EngineServerFailureError';
@@ -0,0 +1,138 @@
1
+ import {
2
+ EIP712BurnVlpValues,
3
+ EIP712IsolatedOrderParams,
4
+ EIP712LinkSignerValues,
5
+ EIP712LiquidateSubaccountValues,
6
+ EIP712MintVlpValues,
7
+ EIP712OrderCancellationValues,
8
+ EIP712OrderParams,
9
+ EIP712OrderValues,
10
+ EIP712ProductOrdersCancellationValues,
11
+ EIP712TransferQuoteValues,
12
+ EIP712WithdrawCollateralValues,
13
+ SignedTx,
14
+ } from '@nadohq/contracts';
15
+ import { EngineServerOrderResponse } from './serverQueryTypes';
16
+
17
+ export interface EngineServerPlaceOrderResponse {
18
+ digest: string;
19
+ }
20
+
21
+ export interface EngineServerCancelOrdersResponse {
22
+ cancelled_orders: EngineServerOrderResponse[];
23
+ }
24
+
25
+ export interface EngineServerExecuteResponseDataByType {
26
+ burn_vlp: null;
27
+ cancel_and_place: EngineServerPlaceOrderResponse;
28
+ cancel_orders: EngineServerCancelOrdersResponse;
29
+ cancel_product_orders: EngineServerCancelOrdersResponse;
30
+ link_signer: null;
31
+ liquidate_subaccount: null;
32
+ mint_vlp: null;
33
+ place_isolated_order: EngineServerPlaceOrderResponse;
34
+ place_order: EngineServerPlaceOrderResponse;
35
+ transfer_quote: null;
36
+ withdraw_collateral: null;
37
+ }
38
+
39
+ export interface EngineServerExecuteSuccessResult<
40
+ T extends EngineServerExecuteRequestType = EngineServerExecuteRequestType,
41
+ > {
42
+ status: 'success';
43
+ data: EngineServerExecuteResponseDataByType[T];
44
+ signature: string;
45
+ request_type: EngineServerExecuteResultRequestType;
46
+ // NOTE: `id` is excluded from the response to avoid parsing issues.
47
+ // type of `id` on the backend is `u64` which can overflow until we introduce proper parsing on the SDK.
48
+ }
49
+
50
+ export interface EngineServerExecuteFailureResult {
51
+ status: 'failure';
52
+ signature: string;
53
+ error: string;
54
+ error_code: number;
55
+ request_type: EngineServerExecuteResultRequestType;
56
+ }
57
+
58
+ export type EngineServerExecuteResult<
59
+ T extends EngineServerExecuteRequestType = EngineServerExecuteRequestType,
60
+ > = EngineServerExecuteSuccessResult<T> | EngineServerExecuteFailureResult;
61
+
62
+ type EngineServerExecuteResultRequestType = {
63
+ [K in keyof EngineServerExecuteRequestByType]: `execute_${K}`;
64
+ }[keyof EngineServerExecuteRequestByType];
65
+
66
+ export interface EngineServerPlaceOrderParams {
67
+ id: number | null;
68
+ product_id: number;
69
+ order: EIP712OrderValues;
70
+ // Bytes
71
+ signature: string;
72
+ // Engine defaults this to true
73
+ spot_leverage: boolean | null;
74
+ }
75
+
76
+ export interface EngineServerPlaceIsolatedOrderParams {
77
+ id: number | null;
78
+ product_id: number;
79
+ isolated_order: EIP712OrderValues;
80
+ // Bytes
81
+ signature: string;
82
+ // Engine defaults this to false
83
+ borrow_margin: boolean | null;
84
+ }
85
+
86
+ export type EngineServerCancelOrdersParams = SignedTx<
87
+ Omit<EIP712OrderCancellationValues, 'productIds'> & {
88
+ // number[] is technically assignable to "Bytes", so we need to override the ByteFieldsToHex result here
89
+ productIds: number[];
90
+ }
91
+ >;
92
+
93
+ export type EngineServiceCancelAndPlaceParams = Omit<
94
+ EngineServerCancelOrdersParams,
95
+ 'tx' | 'signature'
96
+ > & {
97
+ cancel_tx: EngineServerCancelOrdersParams['tx'];
98
+ cancel_signature: EngineServerCancelOrdersParams['signature'];
99
+ place_order: EngineServerPlaceOrderParams;
100
+ };
101
+
102
+ type WithSpotLeverage<T> = T & {
103
+ spot_leverage: boolean | null;
104
+ };
105
+
106
+ export interface EngineServerExecuteRequestByType {
107
+ burn_vlp: SignedTx<EIP712BurnVlpValues>;
108
+ cancel_and_place: EngineServiceCancelAndPlaceParams;
109
+ cancel_orders: EngineServerCancelOrdersParams;
110
+ cancel_product_orders: SignedTx<
111
+ Omit<EIP712ProductOrdersCancellationValues, 'productIds'> & {
112
+ // number[] is technically assignable to "Bytes", so we need to override the ByteFieldsToHex result here
113
+ productIds: number[];
114
+ }
115
+ >;
116
+ link_signer: SignedTx<EIP712LinkSignerValues>;
117
+ liquidate_subaccount: SignedTx<EIP712LiquidateSubaccountValues>;
118
+ mint_vlp: WithSpotLeverage<SignedTx<EIP712MintVlpValues>>;
119
+ place_isolated_order: EngineServerPlaceIsolatedOrderParams;
120
+ place_order: EngineServerPlaceOrderParams;
121
+ transfer_quote: SignedTx<EIP712TransferQuoteValues>;
122
+ withdraw_collateral: WithSpotLeverage<
123
+ SignedTx<EIP712WithdrawCollateralValues>
124
+ >;
125
+ }
126
+
127
+ export type EngineServerExecuteRequestType =
128
+ keyof EngineServerExecuteRequestByType;
129
+
130
+ export interface EngineServerExecutePlaceOrderPayload {
131
+ payload: EngineServerExecuteRequestByType['place_order'];
132
+ orderParams: EIP712OrderParams;
133
+ }
134
+
135
+ export interface EngineServerExecutePlaceIsolatedOrderPayload {
136
+ payload: EngineServerExecuteRequestByType['place_isolated_order'];
137
+ orderParams: EIP712IsolatedOrderParams;
138
+ }