@nadohq/engine-client 0.1.0-alpha.3 → 0.1.0-alpha.5
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.
- package/dist/EngineBaseClient.cjs +8 -7
- package/dist/EngineBaseClient.cjs.map +1 -1
- package/dist/EngineBaseClient.d.cts +1 -2
- package/dist/EngineBaseClient.d.ts +1 -2
- package/dist/EngineBaseClient.js +7 -5
- package/dist/EngineBaseClient.js.map +1 -1
- package/dist/EngineClient.d.cts +1 -2
- package/dist/EngineClient.d.ts +1 -2
- package/dist/EngineExecuteBuilder.cjs +23 -51
- package/dist/EngineExecuteBuilder.cjs.map +1 -1
- package/dist/EngineExecuteBuilder.d.cts +6 -17
- package/dist/EngineExecuteBuilder.d.ts +6 -17
- package/dist/EngineExecuteBuilder.js +13 -41
- package/dist/EngineExecuteBuilder.js.map +1 -1
- package/dist/EngineExecuteClient.cjs +6 -10
- package/dist/EngineExecuteClient.cjs.map +1 -1
- package/dist/EngineExecuteClient.d.cts +3 -4
- package/dist/EngineExecuteClient.d.ts +3 -4
- package/dist/EngineExecuteClient.js +6 -10
- package/dist/EngineExecuteClient.js.map +1 -1
- package/dist/EngineQueryClient.cjs +28 -53
- package/dist/EngineQueryClient.cjs.map +1 -1
- package/dist/EngineQueryClient.d.cts +2 -13
- package/dist/EngineQueryClient.d.ts +2 -13
- package/dist/EngineQueryClient.js +6 -31
- package/dist/EngineQueryClient.js.map +1 -1
- package/dist/EngineWebClient.cjs +0 -2
- package/dist/EngineWebClient.cjs.map +1 -1
- package/dist/EngineWebClient.d.cts +1 -2
- package/dist/EngineWebClient.d.ts +1 -2
- package/dist/EngineWebClient.js +0 -2
- package/dist/EngineWebClient.js.map +1 -1
- package/dist/endpoints.cjs +6 -6
- package/dist/endpoints.cjs.map +1 -1
- package/dist/endpoints.d.cts +1 -1
- package/dist/endpoints.d.ts +1 -1
- package/dist/endpoints.js +6 -6
- package/dist/endpoints.js.map +1 -1
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/types/EngineServerFailureError.cjs +1 -1
- package/dist/types/EngineServerFailureError.cjs.map +1 -1
- package/dist/types/EngineServerFailureError.d.cts +2 -2
- package/dist/types/EngineServerFailureError.d.ts +2 -2
- package/dist/types/EngineServerFailureError.js +1 -1
- package/dist/types/EngineServerFailureError.js.map +1 -1
- package/dist/types/clientExecuteTypes.cjs.map +1 -1
- package/dist/types/clientExecuteTypes.d.cts +4 -12
- package/dist/types/clientExecuteTypes.d.ts +4 -12
- package/dist/types/clientQueryTypes.cjs.map +1 -1
- package/dist/types/clientQueryTypes.d.cts +12 -23
- package/dist/types/clientQueryTypes.d.ts +12 -23
- package/dist/types/index.d.cts +5 -6
- package/dist/types/index.d.ts +5 -6
- package/dist/types/serverExecuteTypes.cjs.map +1 -1
- package/dist/types/serverExecuteTypes.d.cts +6 -14
- package/dist/types/serverExecuteTypes.d.ts +6 -14
- package/dist/types/serverQueryModelTypes.cjs.map +1 -1
- package/dist/types/serverQueryModelTypes.d.cts +1 -1
- package/dist/types/serverQueryModelTypes.d.ts +1 -1
- package/dist/types/serverQueryTypes.cjs.map +1 -1
- package/dist/types/serverQueryTypes.d.cts +3 -13
- package/dist/types/serverQueryTypes.d.ts +3 -13
- package/dist/types/serverSubscriptionEventTypes.d.cts +1 -1
- package/dist/types/serverSubscriptionEventTypes.d.ts +1 -1
- package/dist/utils/index.d.cts +1 -2
- package/dist/utils/index.d.ts +1 -2
- package/dist/utils/productEngineTypeMappers.cjs +5 -5
- package/dist/utils/productEngineTypeMappers.cjs.map +1 -1
- package/dist/utils/productEngineTypeMappers.d.cts +1 -1
- package/dist/utils/productEngineTypeMappers.d.ts +1 -1
- package/dist/utils/productEngineTypeMappers.js +1 -1
- package/dist/utils/productEngineTypeMappers.js.map +1 -1
- package/dist/utils/queryDataMappers.cjs +79 -90
- package/dist/utils/queryDataMappers.cjs.map +1 -1
- package/dist/utils/queryDataMappers.d.cts +1 -2
- package/dist/utils/queryDataMappers.d.ts +1 -2
- package/dist/utils/queryDataMappers.js +7 -19
- package/dist/utils/queryDataMappers.js.map +1 -1
- package/package.json +3 -4
- package/src/EngineBaseClient.ts +5 -3
- package/src/EngineExecuteBuilder.ts +14 -54
- package/src/EngineExecuteClient.ts +7 -15
- package/src/EngineQueryClient.ts +6 -35
- package/src/EngineWebClient.ts +0 -2
- package/src/endpoints.ts +4 -5
- package/src/types/EngineServerFailureError.ts +2 -2
- package/src/types/clientExecuteTypes.ts +5 -17
- package/src/types/clientQueryTypes.ts +18 -32
- package/src/types/serverExecuteTypes.ts +7 -18
- package/src/types/serverQueryModelTypes.ts +1 -1
- package/src/types/serverQueryTypes.ts +2 -16
- package/src/utils/productEngineTypeMappers.ts +1 -1
- package/src/utils/queryDataMappers.ts +7 -20
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BalanceHealthContributions,
|
|
3
3
|
BalanceSide,
|
|
4
|
+
BalanceWithProduct,
|
|
5
|
+
BigDecimal,
|
|
4
6
|
EIP712OrderParams,
|
|
5
|
-
GetAllMarketsResponse,
|
|
6
|
-
GetSubaccountSummaryParams,
|
|
7
7
|
HealthGroup,
|
|
8
|
-
|
|
8
|
+
HealthStatusByType,
|
|
9
|
+
MarketWithProduct,
|
|
10
|
+
OrderAppendix,
|
|
9
11
|
PerpBalanceWithProduct,
|
|
10
12
|
ProductEngineType,
|
|
11
13
|
SignedEIP712OrderParams,
|
|
12
14
|
SpotBalanceWithProduct,
|
|
13
15
|
Subaccount,
|
|
14
|
-
|
|
15
|
-
} from '@nadohq/contracts';
|
|
16
|
-
import { BigDecimal } from '@nadohq/utils';
|
|
16
|
+
} from '@nadohq/shared';
|
|
17
17
|
import {
|
|
18
18
|
EngineServerNoncesParams,
|
|
19
19
|
EngineServerTimeResponse,
|
|
20
20
|
} from './serverQueryTypes';
|
|
21
21
|
|
|
22
|
-
export type GetEngineSubaccountSummaryResponse =
|
|
22
|
+
export type GetEngineSubaccountSummaryResponse = {
|
|
23
|
+
exists: boolean;
|
|
24
|
+
balances: BalanceWithProduct[];
|
|
25
|
+
health: HealthStatusByType;
|
|
26
|
+
};
|
|
23
27
|
|
|
24
|
-
export type GetEngineSubaccountSummaryParams =
|
|
28
|
+
export type GetEngineSubaccountSummaryParams = Subaccount;
|
|
25
29
|
|
|
26
30
|
export type GetEngineIsolatedPositionsParams = Subaccount;
|
|
27
31
|
|
|
@@ -48,16 +52,11 @@ export interface SubaccountProductDeltaTx {
|
|
|
48
52
|
export interface GetEngineContractsResponse {
|
|
49
53
|
chainId: number;
|
|
50
54
|
endpointAddr: string;
|
|
51
|
-
/**
|
|
52
|
-
* Address for the orderbook contract, with the product ID being the index
|
|
53
|
-
*/
|
|
54
|
-
orderbookAddrs: string[];
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export type GetEngineEstimatedSubaccountSummaryParams =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
57
|
+
export type GetEngineEstimatedSubaccountSummaryParams = Subaccount & {
|
|
58
|
+
txs: SubaccountTx[];
|
|
59
|
+
};
|
|
61
60
|
|
|
62
61
|
export type GetEngineNoncesParams = EngineServerNoncesParams;
|
|
63
62
|
|
|
@@ -91,7 +90,7 @@ export interface EngineSymbol {
|
|
|
91
90
|
longWeightMaintenance: BigDecimal;
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
export type GetEngineAllMarketsResponse =
|
|
93
|
+
export type GetEngineAllMarketsResponse = MarketWithProduct[];
|
|
95
94
|
|
|
96
95
|
export interface GetEngineHealthGroupsResponse {
|
|
97
96
|
healthGroups: HealthGroup[];
|
|
@@ -109,14 +108,11 @@ export interface EngineOrder extends Subaccount {
|
|
|
109
108
|
totalAmount: BigDecimal;
|
|
110
109
|
// Amount still unfilled
|
|
111
110
|
unfilledAmount: BigDecimal;
|
|
112
|
-
expiration:
|
|
113
|
-
// Margin being transferred for the order, will be null if not an iso order
|
|
114
|
-
margin: BigDecimal | null;
|
|
111
|
+
expiration: number;
|
|
115
112
|
nonce: string;
|
|
116
113
|
digest: string;
|
|
117
|
-
orderParams: EIP712OrderParams;
|
|
118
114
|
placementTime: number;
|
|
119
|
-
|
|
115
|
+
appendix: OrderAppendix;
|
|
120
116
|
}
|
|
121
117
|
|
|
122
118
|
export type GetEngineOrderResponse = EngineOrder;
|
|
@@ -128,7 +124,6 @@ export interface ValidateSignedEngineOrderParams {
|
|
|
128
124
|
|
|
129
125
|
export interface ValidateEngineOrderParams {
|
|
130
126
|
productId: number;
|
|
131
|
-
orderbookAddr: string;
|
|
132
127
|
chainId: number;
|
|
133
128
|
order: EIP712OrderParams;
|
|
134
129
|
}
|
|
@@ -242,15 +237,6 @@ export interface GetEngineLinkedSignerResponse {
|
|
|
242
237
|
|
|
243
238
|
export type GetEngineInsuranceResponse = BigDecimal;
|
|
244
239
|
|
|
245
|
-
export interface EngineMinDepositRate {
|
|
246
|
-
productId: number;
|
|
247
|
-
minDepositRate: BigDecimal;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export interface GetEngineMinDepositRatesResponse {
|
|
251
|
-
minDepositRates: Record<number, EngineMinDepositRate>;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
240
|
/**
|
|
255
241
|
* Given an IP, backend will either:
|
|
256
242
|
* - Allow queries only through archive / engine (query_only)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EIP712BurnNlpValues,
|
|
3
|
-
EIP712IsolatedOrderParams,
|
|
4
3
|
EIP712LinkSignerValues,
|
|
5
4
|
EIP712LiquidateSubaccountValues,
|
|
6
5
|
EIP712MintNlpValues,
|
|
@@ -11,13 +10,16 @@ import {
|
|
|
11
10
|
EIP712TransferQuoteValues,
|
|
12
11
|
EIP712WithdrawCollateralValues,
|
|
13
12
|
SignedTx,
|
|
14
|
-
} from '@nadohq/
|
|
13
|
+
} from '@nadohq/shared';
|
|
15
14
|
import { EngineServerOrderResponse } from './serverQueryTypes';
|
|
16
15
|
|
|
17
16
|
export interface EngineServerPlaceOrderResponse {
|
|
18
17
|
digest: string;
|
|
18
|
+
error: string | null;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export type EngineServerPlaceOrdersResponse = EngineServerPlaceOrderResponse[];
|
|
22
|
+
|
|
21
23
|
export interface EngineServerCancelOrdersResponse {
|
|
22
24
|
cancelled_orders: EngineServerOrderResponse[];
|
|
23
25
|
}
|
|
@@ -30,8 +32,8 @@ export interface EngineServerExecuteResponseDataByType {
|
|
|
30
32
|
link_signer: null;
|
|
31
33
|
liquidate_subaccount: null;
|
|
32
34
|
mint_nlp: null;
|
|
33
|
-
place_isolated_order: EngineServerPlaceOrderResponse;
|
|
34
35
|
place_order: EngineServerPlaceOrderResponse;
|
|
36
|
+
place_orders: EngineServerPlaceOrdersResponse;
|
|
35
37
|
transfer_quote: null;
|
|
36
38
|
withdraw_collateral: null;
|
|
37
39
|
}
|
|
@@ -71,15 +73,7 @@ export interface EngineServerPlaceOrderParams {
|
|
|
71
73
|
signature: string;
|
|
72
74
|
// Engine defaults this to true
|
|
73
75
|
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
|
|
76
|
+
// For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative USDC balance)
|
|
83
77
|
borrow_margin: boolean | null;
|
|
84
78
|
}
|
|
85
79
|
|
|
@@ -116,8 +110,8 @@ export interface EngineServerExecuteRequestByType {
|
|
|
116
110
|
link_signer: SignedTx<EIP712LinkSignerValues>;
|
|
117
111
|
liquidate_subaccount: SignedTx<EIP712LiquidateSubaccountValues>;
|
|
118
112
|
mint_nlp: WithSpotLeverage<SignedTx<EIP712MintNlpValues>>;
|
|
119
|
-
place_isolated_order: EngineServerPlaceIsolatedOrderParams;
|
|
120
113
|
place_order: EngineServerPlaceOrderParams;
|
|
114
|
+
place_orders: EngineServerPlaceOrderParams[];
|
|
121
115
|
transfer_quote: SignedTx<EIP712TransferQuoteValues>;
|
|
122
116
|
withdraw_collateral: WithSpotLeverage<
|
|
123
117
|
SignedTx<EIP712WithdrawCollateralValues>
|
|
@@ -131,8 +125,3 @@ export interface EngineServerExecutePlaceOrderPayload {
|
|
|
131
125
|
payload: EngineServerExecuteRequestByType['place_order'];
|
|
132
126
|
orderParams: EIP712OrderParams;
|
|
133
127
|
}
|
|
134
|
-
|
|
135
|
-
export interface EngineServerExecutePlaceIsolatedOrderPayload {
|
|
136
|
-
payload: EngineServerExecuteRequestByType['place_isolated_order'];
|
|
137
|
-
orderParams: EIP712IsolatedOrderParams;
|
|
138
|
-
}
|
|
@@ -6,7 +6,6 @@ export interface EngineServerHealthBreakdown {
|
|
|
6
6
|
|
|
7
7
|
export interface EngineServerSpotBalanceData {
|
|
8
8
|
amount: string;
|
|
9
|
-
last_cumulative_multiplier_x18: string;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export interface EngineServerPerpBalanceData {
|
|
@@ -36,6 +35,7 @@ export interface EngineServerSpotConfig {
|
|
|
36
35
|
interest_floor_x18: string;
|
|
37
36
|
interest_small_cap_x18: string;
|
|
38
37
|
interest_large_cap_x18: string;
|
|
38
|
+
min_deposit_rate_x18: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export interface EngineServerSpotState {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HealthStatus } from '@nadohq/
|
|
1
|
+
import { HealthStatus } from '@nadohq/shared';
|
|
2
2
|
import {
|
|
3
3
|
EngineServerHealthBreakdown,
|
|
4
4
|
EngineServerPerpBalance,
|
|
@@ -116,7 +116,6 @@ export interface EngineServerQueryRequestByType {
|
|
|
116
116
|
max_nlp_mintable: EngineServerMaxMintNlpQueryParams;
|
|
117
117
|
max_order_size: EngineServerMaxOrderSizeQueryParams;
|
|
118
118
|
max_withdrawable: EngineServerMaxWithdrawableQueryParams;
|
|
119
|
-
min_deposit_rates: Record<string, never>;
|
|
120
119
|
nonces: EngineServerNoncesParams;
|
|
121
120
|
order: EngineServerGetOrderQueryParams;
|
|
122
121
|
orders: EngineServerOrdersQueryParams;
|
|
@@ -141,8 +140,6 @@ export type EngineServerQueryRequest<
|
|
|
141
140
|
export interface EngineServerContractsResponse {
|
|
142
141
|
chain_id: string;
|
|
143
142
|
endpoint_addr: string;
|
|
144
|
-
// Index is product ID
|
|
145
|
-
book_addrs: string[];
|
|
146
143
|
}
|
|
147
144
|
|
|
148
145
|
// Unless in active state, engine is not fully operational
|
|
@@ -281,7 +278,7 @@ export interface EngineServerOrder {
|
|
|
281
278
|
digest: string;
|
|
282
279
|
placed_at: number;
|
|
283
280
|
order_type: string;
|
|
284
|
-
|
|
281
|
+
appendix: string;
|
|
285
282
|
}
|
|
286
283
|
|
|
287
284
|
export type EngineServerOrderResponse = EngineServerOrder;
|
|
@@ -315,16 +312,6 @@ export interface EngineInsuranceResponse {
|
|
|
315
312
|
insurance: string;
|
|
316
313
|
}
|
|
317
314
|
|
|
318
|
-
export interface EngineServerMinDepositRate {
|
|
319
|
-
product_id: number;
|
|
320
|
-
min_deposit_rate_x18: string;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export interface EngineServerMinDepositRatesResponse {
|
|
324
|
-
// product_id -> EngineServerMinDepositRate
|
|
325
|
-
min_deposit_rates: Record<number, EngineServerMinDepositRate>;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
315
|
export interface EngineServerEdgeAllProductsResponse {
|
|
329
316
|
// chain_id -> EngineServerAllProductsResponse
|
|
330
317
|
edge_all_products: Record<number, EngineServerAllProductsResponse>;
|
|
@@ -349,7 +336,6 @@ export interface EngineServerQueryResponseByType {
|
|
|
349
336
|
max_nlp_mintable: EngineServerMaxMintNlpResponse;
|
|
350
337
|
max_order_size: EngineServerMaxOrderSizeResponse;
|
|
351
338
|
max_withdrawable: EngineServerMaxWithdrawableResponse;
|
|
352
|
-
min_deposit_rates: EngineServerMinDepositRatesResponse;
|
|
353
339
|
nonces: EngineServerNoncesResponse;
|
|
354
340
|
order: EngineServerOrderResponse;
|
|
355
341
|
orders: EngineServerProductOrdersResponse;
|
|
@@ -2,18 +2,15 @@ import {
|
|
|
2
2
|
BalanceHealthContributions,
|
|
3
3
|
calcTotalBorrowed,
|
|
4
4
|
calcTotalDeposited,
|
|
5
|
-
|
|
5
|
+
mapValues,
|
|
6
6
|
PerpMarket,
|
|
7
7
|
ProductEngineType,
|
|
8
|
+
removeDecimals,
|
|
8
9
|
SpotMarket,
|
|
9
10
|
subaccountFromHex,
|
|
10
|
-
} from '@nadohq/contracts';
|
|
11
|
-
import {
|
|
12
|
-
mapValues,
|
|
13
|
-
removeDecimals,
|
|
14
11
|
toBigDecimal,
|
|
15
|
-
|
|
16
|
-
} from '@nadohq/
|
|
12
|
+
unpackOrderAppendix,
|
|
13
|
+
} from '@nadohq/shared';
|
|
17
14
|
import {
|
|
18
15
|
EngineMarketPrice,
|
|
19
16
|
EngineOrder,
|
|
@@ -49,7 +46,7 @@ export function mapEngineServerOrder(
|
|
|
49
46
|
const subaccount = subaccountFromHex(order.sender);
|
|
50
47
|
return {
|
|
51
48
|
digest: order.digest,
|
|
52
|
-
expiration:
|
|
49
|
+
expiration: Number(order.expiration),
|
|
53
50
|
nonce: order.nonce,
|
|
54
51
|
price: removeDecimals(order.price_x18),
|
|
55
52
|
productId: order.product_id,
|
|
@@ -57,19 +54,8 @@ export function mapEngineServerOrder(
|
|
|
57
54
|
subaccountName: subaccount.subaccountName,
|
|
58
55
|
totalAmount: toBigDecimal(order.amount),
|
|
59
56
|
unfilledAmount: toBigDecimal(order.unfilled_amount),
|
|
60
|
-
margin: order.margin ? toBigDecimal(order.margin) : null,
|
|
61
|
-
// Standardizes from hex
|
|
62
|
-
// toFixed is required as toString gives values with `e`
|
|
63
|
-
orderParams: {
|
|
64
|
-
amount: toIntegerString(order.amount),
|
|
65
|
-
expiration: toIntegerString(order.expiration),
|
|
66
|
-
nonce: order.nonce,
|
|
67
|
-
price: toIntegerString(removeDecimals(order.price_x18)),
|
|
68
|
-
subaccountOwner: subaccount.subaccountOwner,
|
|
69
|
-
subaccountName: subaccount.subaccountName,
|
|
70
|
-
},
|
|
71
57
|
placementTime: order.placed_at,
|
|
72
|
-
|
|
58
|
+
appendix: unpackOrderAppendix(order.appendix),
|
|
73
59
|
};
|
|
74
60
|
}
|
|
75
61
|
|
|
@@ -100,6 +86,7 @@ export function mapEngineServerSpotProduct(
|
|
|
100
86
|
),
|
|
101
87
|
interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),
|
|
102
88
|
interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),
|
|
89
|
+
minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),
|
|
103
90
|
longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),
|
|
104
91
|
longWeightMaintenance: removeDecimals(
|
|
105
92
|
product.risk.long_weight_maintenance_x18,
|