@nadohq/engine-client 0.1.0-alpha.1 → 0.1.0-alpha.10
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 +33 -61
- package/dist/EngineExecuteBuilder.cjs.map +1 -1
- package/dist/EngineExecuteBuilder.d.cts +14 -25
- package/dist/EngineExecuteBuilder.d.ts +14 -25
- package/dist/EngineExecuteBuilder.js +25 -53
- package/dist/EngineExecuteBuilder.js.map +1 -1
- package/dist/EngineExecuteClient.cjs +12 -16
- package/dist/EngineExecuteClient.cjs.map +1 -1
- package/dist/EngineExecuteClient.d.cts +5 -6
- package/dist/EngineExecuteClient.d.ts +5 -6
- package/dist/EngineExecuteClient.js +12 -16
- package/dist/EngineExecuteClient.js.map +1 -1
- package/dist/EngineQueryClient.cjs +33 -57
- package/dist/EngineQueryClient.cjs.map +1 -1
- package/dist/EngineQueryClient.d.cts +4 -15
- package/dist/EngineQueryClient.d.ts +4 -15
- package/dist/EngineQueryClient.js +11 -35
- 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 +7 -8
- package/dist/index.d.ts +7 -8
- 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 +8 -16
- package/dist/types/clientExecuteTypes.d.ts +8 -16
- package/dist/types/clientQueryTypes.cjs.map +1 -1
- package/dist/types/clientQueryTypes.d.cts +15 -25
- package/dist/types/clientQueryTypes.d.ts +15 -25
- package/dist/types/index.d.cts +7 -8
- package/dist/types/index.d.ts +7 -8
- package/dist/types/serverExecuteTypes.cjs.map +1 -1
- package/dist/types/serverExecuteTypes.d.cts +10 -18
- package/dist/types/serverExecuteTypes.d.ts +10 -18
- 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 +8 -17
- package/dist/types/serverQueryTypes.d.ts +8 -17
- package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
- package/dist/types/serverSubscriptionEventTypes.d.cts +83 -24
- package/dist/types/serverSubscriptionEventTypes.d.ts +83 -24
- package/dist/types/serverSubscriptionTypes.cjs.map +1 -1
- package/dist/types/serverSubscriptionTypes.d.cts +21 -4
- package/dist/types/serverSubscriptionTypes.d.ts +21 -4
- 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 +30 -70
- package/src/EngineExecuteClient.ts +13 -21
- package/src/EngineQueryClient.ts +14 -42
- package/src/EngineWebClient.ts +0 -2
- package/src/endpoints.ts +4 -5
- package/src/types/EngineServerFailureError.ts +2 -2
- package/src/types/clientExecuteTypes.ts +13 -25
- package/src/types/clientQueryTypes.ts +21 -34
- package/src/types/serverExecuteTypes.ts +13 -24
- package/src/types/serverQueryModelTypes.ts +1 -1
- package/src/types/serverQueryTypes.ts +7 -20
- package/src/types/serverSubscriptionEventTypes.ts +130 -22
- package/src/types/serverSubscriptionTypes.ts +23 -3
- package/src/utils/productEngineTypeMappers.ts +1 -1
- package/src/utils/queryDataMappers.ts +7 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nadohq/engine-client",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "> TODO: description",
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@nadohq/
|
|
41
|
-
"@nadohq/utils": "^0.1.0-alpha.1",
|
|
40
|
+
"@nadohq/shared": "^0.1.0-alpha.10",
|
|
42
41
|
"axios": "*",
|
|
43
42
|
"ts-mixer": "*"
|
|
44
43
|
},
|
|
@@ -48,5 +47,5 @@
|
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"viem": "*"
|
|
50
49
|
},
|
|
51
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "d4907c30fee146e4463cab4bac0a7f5f07bb9299"
|
|
52
51
|
}
|
package/src/EngineBaseClient.ts
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
SignableRequestType,
|
|
4
4
|
SignableRequestTypeToParams,
|
|
5
5
|
WalletClientWithAccount,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
WalletNotProvidedError,
|
|
7
|
+
} from '@nadohq/shared';
|
|
8
8
|
import axios, { AxiosInstance, AxiosResponse } from 'axios';
|
|
9
9
|
import {
|
|
10
10
|
EngineServerExecuteRequestByType,
|
|
@@ -49,6 +49,8 @@ export class EngineBaseClient {
|
|
|
49
49
|
this.opts = opts;
|
|
50
50
|
this.axiosInstance = axios.create({
|
|
51
51
|
withCredentials: true,
|
|
52
|
+
// We have custom logic to validate response status and create an appropriate error
|
|
53
|
+
validateStatus: () => true,
|
|
52
54
|
});
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -206,7 +208,7 @@ export class EngineBaseClient {
|
|
|
206
208
|
private checkResponseStatus(response: AxiosResponse) {
|
|
207
209
|
if (response.status !== 200 || !response.data) {
|
|
208
210
|
throw Error(
|
|
209
|
-
`Unexpected response from server: ${response.status} ${response.statusText}`,
|
|
211
|
+
`Unexpected response from server: ${response.status} ${response.statusText}. Data: ${response.data}`,
|
|
210
212
|
);
|
|
211
213
|
}
|
|
212
214
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EIP712IsolatedOrderParams,
|
|
3
2
|
EIP712OrderParams,
|
|
4
3
|
getNadoEIP712Values,
|
|
5
4
|
getOrderNonce,
|
|
6
5
|
SignableRequestType,
|
|
7
6
|
SignableRequestTypeToParams,
|
|
8
|
-
} from '@nadohq/
|
|
7
|
+
} from '@nadohq/shared';
|
|
9
8
|
import { EngineBaseClient } from './EngineBaseClient';
|
|
10
9
|
import {
|
|
11
10
|
EngineExecuteRequestParamsByType,
|
|
12
|
-
EngineServerExecutePlaceIsolatedOrderPayload,
|
|
13
11
|
EngineServerExecutePlaceOrderPayload,
|
|
14
12
|
EngineServerExecuteRequestByType,
|
|
15
13
|
SignatureParams,
|
|
@@ -89,7 +87,7 @@ export class EngineExecuteBuilder {
|
|
|
89
87
|
const orderWithNonce = { ...clientParams.order, nonce };
|
|
90
88
|
|
|
91
89
|
const signature = await this.getSignatureIfNeeded('place_order', {
|
|
92
|
-
// Gets expected type
|
|
90
|
+
// Gets expected type (signature params from `clientParams` and order params from `orderWithNonce`)
|
|
93
91
|
...clientParams,
|
|
94
92
|
...orderWithNonce,
|
|
95
93
|
});
|
|
@@ -126,64 +124,26 @@ export class EngineExecuteBuilder {
|
|
|
126
124
|
order: orderEIP712Values,
|
|
127
125
|
signature: clientParams.signature,
|
|
128
126
|
spot_leverage: clientParams.spotLeverage ?? null,
|
|
127
|
+
borrow_margin: clientParams.borrowMargin ?? null,
|
|
129
128
|
},
|
|
130
129
|
orderParams: clientParams.order,
|
|
131
130
|
};
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
/**
|
|
135
|
-
* Builds server payload for the `
|
|
136
|
-
*
|
|
137
|
-
* @
|
|
138
|
-
* @returns `place_isolated_order` payload
|
|
139
|
-
*/
|
|
140
|
-
async buildIsolatedPlaceOrderPayload(
|
|
141
|
-
clientParams: EngineExecuteRequestParamsByType['place_isolated_order'],
|
|
142
|
-
): Promise<EngineServerExecutePlaceIsolatedOrderPayload> {
|
|
143
|
-
const nonce = this.getOrderNonceIfNeeded(clientParams);
|
|
144
|
-
const orderWithNonce = { ...clientParams.order, nonce };
|
|
145
|
-
|
|
146
|
-
const signature = await this.getSignatureIfNeeded('place_isolated_order', {
|
|
147
|
-
// Gets expected type
|
|
148
|
-
...clientParams,
|
|
149
|
-
...orderWithNonce,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
return this.buildPlaceIsolatedOrderPayloadSync({
|
|
153
|
-
...clientParams,
|
|
154
|
-
order: orderWithNonce,
|
|
155
|
-
signature,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Synchronously builds server payload for the `place_isolated_order` execute action.
|
|
161
|
-
*
|
|
162
|
-
* @param clientParams Client PlaceIsolatedOrder params.
|
|
163
|
-
* @returns `place_isolated_order` payload
|
|
134
|
+
* Builds server payload for the `place_orders` execute action.
|
|
135
|
+
* @param clientParams Client PlaceOrders params.
|
|
136
|
+
* @returns `place_orders` payload
|
|
164
137
|
*/
|
|
165
|
-
|
|
166
|
-
clientParams:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
'place_isolated_order',
|
|
174
|
-
clientParams.order,
|
|
138
|
+
async buildPlaceOrdersPayload(
|
|
139
|
+
clientParams: EngineExecuteRequestParamsByType['place_orders'],
|
|
140
|
+
): Promise<EngineServerExecuteRequestByType['place_orders']> {
|
|
141
|
+
return Promise.all(
|
|
142
|
+
clientParams.map(async (orderParams) => {
|
|
143
|
+
const payload = await this.buildPlaceOrderPayload(orderParams);
|
|
144
|
+
return payload.payload;
|
|
145
|
+
}),
|
|
175
146
|
);
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
payload: {
|
|
179
|
-
id: clientParams.id ?? null,
|
|
180
|
-
product_id: clientParams.productId,
|
|
181
|
-
isolated_order: isolatedOrderEIP712Values,
|
|
182
|
-
signature: clientParams.signature,
|
|
183
|
-
borrow_margin: clientParams.borrowMargin ?? null,
|
|
184
|
-
},
|
|
185
|
-
orderParams: clientParams.order,
|
|
186
|
-
};
|
|
187
147
|
}
|
|
188
148
|
|
|
189
149
|
/**
|
|
@@ -299,19 +259,19 @@ export class EngineExecuteBuilder {
|
|
|
299
259
|
}
|
|
300
260
|
|
|
301
261
|
/**
|
|
302
|
-
* Builds server payload for the `
|
|
303
|
-
* @param clientParams Client
|
|
304
|
-
* @returns `
|
|
262
|
+
* Builds server payload for the `mint_nlp` execute action.
|
|
263
|
+
* @param clientParams Client MintNlp params.
|
|
264
|
+
* @returns `mint_nlp` payload
|
|
305
265
|
*/
|
|
306
|
-
async
|
|
307
|
-
clientParams: EngineExecuteRequestParamsByType['
|
|
308
|
-
): Promise<EngineServerExecuteRequestByType['
|
|
266
|
+
async buildMintNlpPayload(
|
|
267
|
+
clientParams: EngineExecuteRequestParamsByType['mint_nlp'],
|
|
268
|
+
): Promise<EngineServerExecuteRequestByType['mint_nlp']> {
|
|
309
269
|
const nonce = await this.getTxNonceIfNeeded(clientParams);
|
|
310
270
|
const paramsWithNonce = { ...clientParams, nonce };
|
|
311
271
|
|
|
312
|
-
const tx = getNadoEIP712Values('
|
|
272
|
+
const tx = getNadoEIP712Values('mint_nlp', paramsWithNonce);
|
|
313
273
|
const signature = await this.getSignatureIfNeeded(
|
|
314
|
-
'
|
|
274
|
+
'mint_nlp',
|
|
315
275
|
paramsWithNonce,
|
|
316
276
|
);
|
|
317
277
|
|
|
@@ -323,19 +283,19 @@ export class EngineExecuteBuilder {
|
|
|
323
283
|
}
|
|
324
284
|
|
|
325
285
|
/**
|
|
326
|
-
* Builds server payload for the `
|
|
327
|
-
* @param clientParams Client
|
|
328
|
-
* @returns `
|
|
286
|
+
* Builds server payload for the `burn_nlp` execute action.
|
|
287
|
+
* @param clientParams Client BurnNlp params.
|
|
288
|
+
* @returns `burn_nlp` payload
|
|
329
289
|
*/
|
|
330
|
-
async
|
|
331
|
-
clientParams: EngineExecuteRequestParamsByType['
|
|
332
|
-
): Promise<EngineServerExecuteRequestByType['
|
|
290
|
+
async buildBurnNlpPayload(
|
|
291
|
+
clientParams: EngineExecuteRequestParamsByType['burn_nlp'],
|
|
292
|
+
): Promise<EngineServerExecuteRequestByType['burn_nlp']> {
|
|
333
293
|
const nonce = await this.getTxNonceIfNeeded(clientParams);
|
|
334
294
|
const paramsWithNonce = { ...clientParams, nonce };
|
|
335
295
|
|
|
336
|
-
const tx = getNadoEIP712Values('
|
|
296
|
+
const tx = getNadoEIP712Values('burn_nlp', paramsWithNonce);
|
|
337
297
|
const signature = await this.getSignatureIfNeeded(
|
|
338
|
-
'
|
|
298
|
+
'burn_nlp',
|
|
339
299
|
paramsWithNonce,
|
|
340
300
|
);
|
|
341
301
|
|
|
@@ -2,7 +2,6 @@ import { EngineBaseClient, EngineClientOpts } from './EngineBaseClient';
|
|
|
2
2
|
import { EngineExecuteBuilder } from './EngineExecuteBuilder';
|
|
3
3
|
import {
|
|
4
4
|
EngineExecuteRequestParamsByType,
|
|
5
|
-
EnginePlaceIsolatedOrderResult,
|
|
6
5
|
EnginePlaceOrderResult,
|
|
7
6
|
} from './types';
|
|
8
7
|
|
|
@@ -43,20 +42,6 @@ export class EngineExecuteClient extends EngineBaseClient {
|
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
async placeIsolatedOrder(
|
|
47
|
-
params: EngineExecuteRequestParamsByType['place_isolated_order'],
|
|
48
|
-
): Promise<EnginePlaceIsolatedOrderResult> {
|
|
49
|
-
const placeOrderPayload =
|
|
50
|
-
await this.payloadBuilder.buildIsolatedPlaceOrderPayload(params);
|
|
51
|
-
return {
|
|
52
|
-
...(await this.execute(
|
|
53
|
-
'place_isolated_order',
|
|
54
|
-
placeOrderPayload.payload,
|
|
55
|
-
)),
|
|
56
|
-
orderParams: placeOrderPayload.orderParams,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
45
|
async cancelOrders(
|
|
61
46
|
params: EngineExecuteRequestParamsByType['cancel_orders'],
|
|
62
47
|
) {
|
|
@@ -106,17 +91,24 @@ export class EngineExecuteClient extends EngineBaseClient {
|
|
|
106
91
|
);
|
|
107
92
|
}
|
|
108
93
|
|
|
109
|
-
async
|
|
94
|
+
async mintNlp(params: EngineExecuteRequestParamsByType['mint_nlp']) {
|
|
95
|
+
return this.execute(
|
|
96
|
+
'mint_nlp',
|
|
97
|
+
await this.payloadBuilder.buildMintNlpPayload(params),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async burnNlp(params: EngineExecuteRequestParamsByType['burn_nlp']) {
|
|
110
102
|
return this.execute(
|
|
111
|
-
'
|
|
112
|
-
await this.payloadBuilder.
|
|
103
|
+
'burn_nlp',
|
|
104
|
+
await this.payloadBuilder.buildBurnNlpPayload(params),
|
|
113
105
|
);
|
|
114
106
|
}
|
|
115
107
|
|
|
116
|
-
async
|
|
108
|
+
async placeOrders(params: EngineExecuteRequestParamsByType['place_orders']) {
|
|
117
109
|
return this.execute(
|
|
118
|
-
'
|
|
119
|
-
await this.payloadBuilder.
|
|
110
|
+
'place_orders',
|
|
111
|
+
await this.payloadBuilder.buildPlaceOrdersPayload(params),
|
|
120
112
|
);
|
|
121
113
|
}
|
|
122
114
|
}
|
package/src/EngineQueryClient.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
encodeSignedOrder,
|
|
3
|
-
MarketWithProduct,
|
|
4
|
-
subaccountToHex,
|
|
5
|
-
} from '@nadohq/contracts';
|
|
6
1
|
import {
|
|
7
2
|
addDecimals,
|
|
8
3
|
BigDecimal,
|
|
4
|
+
encodeSignedOrder,
|
|
5
|
+
getOrderVerifyingAddress,
|
|
9
6
|
mapValues,
|
|
7
|
+
MarketWithProduct,
|
|
10
8
|
removeDecimals,
|
|
9
|
+
subaccountToHex,
|
|
11
10
|
toBigDecimal,
|
|
12
11
|
toIntegerString,
|
|
13
|
-
} from '@nadohq/
|
|
12
|
+
} from '@nadohq/shared';
|
|
14
13
|
import { EngineBaseClient } from './EngineBaseClient';
|
|
15
14
|
import {
|
|
16
15
|
EngineServerStatusResponse,
|
|
@@ -31,13 +30,12 @@ import {
|
|
|
31
30
|
GetEngineMarketPriceResponse,
|
|
32
31
|
GetEngineMarketPricesParams,
|
|
33
32
|
GetEngineMarketPricesResponse,
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
GetEngineMaxMintNlpAmountParams,
|
|
34
|
+
GetEngineMaxMintNlpAmountResponse,
|
|
36
35
|
GetEngineMaxOrderSizeParams,
|
|
37
36
|
GetEngineMaxOrderSizeResponse,
|
|
38
37
|
GetEngineMaxWithdrawableParams,
|
|
39
38
|
GetEngineMaxWithdrawableResponse,
|
|
40
|
-
GetEngineMinDepositRatesResponse,
|
|
41
39
|
GetEngineOrderParams,
|
|
42
40
|
GetEngineOrderResponse,
|
|
43
41
|
GetEngineSubaccountFeeRatesParams,
|
|
@@ -75,7 +73,6 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
75
73
|
return {
|
|
76
74
|
chainId: Number(baseResponse.chain_id),
|
|
77
75
|
endpointAddr: baseResponse.endpoint_addr,
|
|
78
|
-
orderbookAddrs: baseResponse.book_addrs,
|
|
79
76
|
};
|
|
80
77
|
}
|
|
81
78
|
|
|
@@ -241,22 +238,6 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
241
238
|
};
|
|
242
239
|
}
|
|
243
240
|
|
|
244
|
-
/**
|
|
245
|
-
* Retrieves min deposit rates for all spot products from the engine
|
|
246
|
-
*/
|
|
247
|
-
async getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse> {
|
|
248
|
-
const baseResponse = await this.query('min_deposit_rates', {});
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
minDepositRates: mapValues(baseResponse.min_deposit_rates, (m) => {
|
|
252
|
-
return {
|
|
253
|
-
productId: m.product_id,
|
|
254
|
-
minDepositRate: removeDecimals(m.min_deposit_rate_x18),
|
|
255
|
-
};
|
|
256
|
-
}),
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
241
|
/**
|
|
261
242
|
* Retrieves an order from the offchain engine
|
|
262
243
|
*
|
|
@@ -285,7 +266,7 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
285
266
|
order: params.order,
|
|
286
267
|
signature: await this.sign(
|
|
287
268
|
'place_order',
|
|
288
|
-
params.
|
|
269
|
+
getOrderVerifyingAddress(params.productId),
|
|
289
270
|
params.chainId,
|
|
290
271
|
params.order,
|
|
291
272
|
),
|
|
@@ -400,6 +381,7 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
400
381
|
},
|
|
401
382
|
{} as Record<number, BigDecimal>,
|
|
402
383
|
),
|
|
384
|
+
feeTier: baseResponse.fee_tier,
|
|
403
385
|
};
|
|
404
386
|
}
|
|
405
387
|
|
|
@@ -492,14 +474,14 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
492
474
|
}
|
|
493
475
|
|
|
494
476
|
/**
|
|
495
|
-
* Retrieves the estimated max quote amount for minting
|
|
477
|
+
* Retrieves the estimated max quote amount for minting NLP.
|
|
496
478
|
*
|
|
497
479
|
* @param params
|
|
498
480
|
*/
|
|
499
|
-
async
|
|
500
|
-
params:
|
|
501
|
-
): Promise<
|
|
502
|
-
const baseResponse = await this.query('
|
|
481
|
+
async getMaxMintNlpAmount(
|
|
482
|
+
params: GetEngineMaxMintNlpAmountParams,
|
|
483
|
+
): Promise<GetEngineMaxMintNlpAmountResponse> {
|
|
484
|
+
const baseResponse = await this.query('max_nlp_mintable', {
|
|
503
485
|
sender: subaccountToHex({
|
|
504
486
|
subaccountOwner: params.subaccountOwner,
|
|
505
487
|
subaccountName: params.subaccountName,
|
|
@@ -540,14 +522,4 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
540
522
|
|
|
541
523
|
return toBigDecimal(baseResponse.insurance);
|
|
542
524
|
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Gets the orderbook contract address for a given product
|
|
546
|
-
* @param productId
|
|
547
|
-
* @returns
|
|
548
|
-
*/
|
|
549
|
-
public async getOrderbookAddress(productId: number): Promise<string> {
|
|
550
|
-
const contracts = await this.getContracts();
|
|
551
|
-
return contracts.orderbookAddrs[productId];
|
|
552
|
-
}
|
|
553
525
|
}
|
package/src/EngineWebClient.ts
CHANGED
|
@@ -18,8 +18,6 @@ export class EngineWebClient extends EngineBaseClient {
|
|
|
18
18
|
this.axiosInstance
|
|
19
19
|
// Use the /time endpoint and listen to 403 responses
|
|
20
20
|
.get(`${this.opts.url}/ip`, {
|
|
21
|
-
// Allow all statuses
|
|
22
|
-
validateStatus: () => true,
|
|
23
21
|
// IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false
|
|
24
22
|
withCredentials: false,
|
|
25
23
|
})
|
package/src/endpoints.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { ChainEnv } from '@nadohq/
|
|
1
|
+
import { ChainEnv } from '@nadohq/shared';
|
|
2
2
|
|
|
3
3
|
export const ENGINE_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
|
|
4
4
|
local: 'http://localhost:80',
|
|
5
|
-
arbitrumTestnet: 'https://gateway.sepolia-test.vertexprotocol.com/v1',
|
|
6
5
|
arbitrum: 'https://gateway.prod.vertexprotocol.com/v1',
|
|
6
|
+
inkTestnet: 'https://gateway.test.nado-backend.xyz/v1',
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export const ENGINE_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
|
|
10
10
|
local: 'ws://localhost:80',
|
|
11
|
-
arbitrumTestnet: 'wss://gateway.sepolia-test.vertexprotocol.com/v1/ws',
|
|
12
11
|
arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/ws',
|
|
12
|
+
inkTestnet: 'wss://gateway.test.nado-backend.xyz/v1/ws',
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export const ENGINE_WS_SUBSCRIPTION_CLIENT_ENDPOINTS: Record<ChainEnv, string> =
|
|
16
16
|
{
|
|
17
17
|
local: 'ws://localhost:80',
|
|
18
|
-
arbitrumTestnet:
|
|
19
|
-
'wss://gateway.sepolia-test.vertexprotocol.com/v1/subscribe',
|
|
20
18
|
arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/subscribe',
|
|
19
|
+
inkTestnet: 'wss://gateway.test.nado-backend.xyz/v1/subscribe',
|
|
21
20
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EngineServerQueryFailureResponse } from './serverQueryTypes';
|
|
2
1
|
import { EngineServerExecuteFailureResult } from './serverExecuteTypes';
|
|
2
|
+
import { EngineServerQueryFailureResponse } from './serverQueryTypes';
|
|
3
3
|
|
|
4
4
|
export class EngineServerFailureError extends Error {
|
|
5
5
|
constructor(
|
|
@@ -7,6 +7,6 @@ export class EngineServerFailureError extends Error {
|
|
|
7
7
|
| EngineServerQueryFailureResponse
|
|
8
8
|
| EngineServerExecuteFailureResult,
|
|
9
9
|
) {
|
|
10
|
-
super();
|
|
10
|
+
super(`${responseData.error_code}: ${responseData.error}`);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
EIP712BurnNlpParams,
|
|
3
3
|
EIP712CancelOrdersParams,
|
|
4
4
|
EIP712CancelProductOrdersParams,
|
|
5
|
-
EIP712IsolatedOrderParams,
|
|
6
5
|
EIP712LinkSignerParams,
|
|
7
6
|
EIP712LiquidateSubaccountParams,
|
|
8
|
-
|
|
7
|
+
EIP712MintNlpParams,
|
|
9
8
|
EIP712OrderParams,
|
|
10
9
|
EIP712TransferQuoteParams,
|
|
11
10
|
EIP712WithdrawCollateralParams,
|
|
12
|
-
} from '@nadohq/
|
|
11
|
+
} from '@nadohq/shared';
|
|
13
12
|
import { EngineServerExecuteSuccessResult } from './serverExecuteTypes';
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -50,15 +49,7 @@ export type EnginePlaceOrderParams = WithBaseEngineExecuteParams<{
|
|
|
50
49
|
order: EngineOrderParams;
|
|
51
50
|
// If not given, engine defaults to true (leverage/borrow enabled)
|
|
52
51
|
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.
|
|
52
|
+
// For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative USDC balance)
|
|
62
53
|
borrowMargin?: boolean;
|
|
63
54
|
}>;
|
|
64
55
|
|
|
@@ -86,23 +77,25 @@ export type EngineLinkSignerParams =
|
|
|
86
77
|
export type EngineTransferQuoteParams =
|
|
87
78
|
WithBaseEngineExecuteParams<EIP712TransferQuoteParams>;
|
|
88
79
|
|
|
89
|
-
export type
|
|
90
|
-
WithSpotLeverage<
|
|
80
|
+
export type EngineMintNlpParams = WithBaseEngineExecuteParams<
|
|
81
|
+
WithSpotLeverage<EIP712MintNlpParams>
|
|
91
82
|
>;
|
|
92
83
|
|
|
93
|
-
export type
|
|
94
|
-
WithBaseEngineExecuteParams<
|
|
84
|
+
export type EngineBurnNlpParams =
|
|
85
|
+
WithBaseEngineExecuteParams<EIP712BurnNlpParams>;
|
|
86
|
+
|
|
87
|
+
export type EnginePlaceOrdersParams = EnginePlaceOrderParams[];
|
|
95
88
|
|
|
96
89
|
export interface EngineExecuteRequestParamsByType {
|
|
97
|
-
|
|
90
|
+
burn_nlp: EngineBurnNlpParams;
|
|
98
91
|
cancel_and_place: EngineCancelAndPlaceParams;
|
|
99
92
|
cancel_orders: EngineCancelOrdersParams;
|
|
100
93
|
cancel_product_orders: EngineCancelProductOrdersParams;
|
|
101
94
|
link_signer: EngineLinkSignerParams;
|
|
102
95
|
liquidate_subaccount: EngineLiquidateSubaccountParams;
|
|
103
|
-
|
|
104
|
-
place_isolated_order: EnginePlaceIsolatedOrderParams;
|
|
96
|
+
mint_nlp: EngineMintNlpParams;
|
|
105
97
|
place_order: EnginePlaceOrderParams;
|
|
98
|
+
place_orders: EnginePlaceOrdersParams;
|
|
106
99
|
transfer_quote: EngineTransferQuoteParams;
|
|
107
100
|
withdraw_collateral: EngineWithdrawCollateralParams;
|
|
108
101
|
}
|
|
@@ -111,8 +104,3 @@ export type EnginePlaceOrderResult =
|
|
|
111
104
|
EngineServerExecuteSuccessResult<'place_order'> & {
|
|
112
105
|
orderParams: EIP712OrderParams;
|
|
113
106
|
};
|
|
114
|
-
|
|
115
|
-
export type EnginePlaceIsolatedOrderResult =
|
|
116
|
-
EngineServerExecuteSuccessResult<'place_isolated_order'> & {
|
|
117
|
-
orderParams: EIP712IsolatedOrderParams;
|
|
118
|
-
};
|
|
@@ -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
|
}
|
|
@@ -171,6 +166,7 @@ export interface GetEngineSubaccountFeeRatesResponse {
|
|
|
171
166
|
liquidationSequencerFee: BigDecimal;
|
|
172
167
|
healthCheckSequencerFee: BigDecimal;
|
|
173
168
|
takerSequencerFee: BigDecimal;
|
|
169
|
+
feeTier: number;
|
|
174
170
|
}
|
|
175
171
|
|
|
176
172
|
export interface EnginePriceTickLiquidity {
|
|
@@ -242,15 +238,6 @@ export interface GetEngineLinkedSignerResponse {
|
|
|
242
238
|
|
|
243
239
|
export type GetEngineInsuranceResponse = BigDecimal;
|
|
244
240
|
|
|
245
|
-
export interface EngineMinDepositRate {
|
|
246
|
-
productId: number;
|
|
247
|
-
minDepositRate: BigDecimal;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export interface GetEngineMinDepositRatesResponse {
|
|
251
|
-
minDepositRates: Record<number, EngineMinDepositRate>;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
241
|
/**
|
|
255
242
|
* Given an IP, backend will either:
|
|
256
243
|
* - Allow queries only through archive / engine (query_only)
|
|
@@ -259,9 +246,9 @@ export interface GetEngineMinDepositRatesResponse {
|
|
|
259
246
|
*/
|
|
260
247
|
export type GetEngineIpBlockStatusResponse = 'query_only' | 'blocked' | null;
|
|
261
248
|
|
|
262
|
-
export interface
|
|
249
|
+
export interface GetEngineMaxMintNlpAmountParams extends Subaccount {
|
|
263
250
|
// If not given, engine defaults to true (leverage/borrow enabled)
|
|
264
251
|
spotLeverage?: boolean;
|
|
265
252
|
}
|
|
266
253
|
|
|
267
|
-
export type
|
|
254
|
+
export type GetEngineMaxMintNlpAmountResponse = BigDecimal;
|