@nadohq/engine-client 0.1.0-alpha.5 → 0.1.0-alpha.51
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.d.cts +1 -1
- package/dist/EngineBaseClient.d.ts +1 -1
- package/dist/EngineExecuteBuilder.cjs +9 -6
- package/dist/EngineExecuteBuilder.cjs.map +1 -1
- package/dist/EngineExecuteBuilder.js +9 -6
- package/dist/EngineExecuteBuilder.js.map +1 -1
- package/dist/EngineExecuteClient.cjs +6 -6
- package/dist/EngineExecuteClient.cjs.map +1 -1
- package/dist/EngineExecuteClient.d.cts +1 -1
- package/dist/EngineExecuteClient.d.ts +1 -1
- package/dist/EngineExecuteClient.js +6 -6
- package/dist/EngineExecuteClient.js.map +1 -1
- package/dist/EngineQueryClient.cjs +48 -4
- package/dist/EngineQueryClient.cjs.map +1 -1
- package/dist/EngineQueryClient.d.cts +18 -2
- package/dist/EngineQueryClient.d.ts +18 -2
- package/dist/EngineQueryClient.js +50 -4
- package/dist/EngineQueryClient.js.map +1 -1
- package/dist/endpoints.cjs +6 -6
- package/dist/endpoints.cjs.map +1 -1
- package/dist/endpoints.js +6 -6
- package/dist/endpoints.js.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/clientExecuteTypes.cjs.map +1 -1
- package/dist/types/clientExecuteTypes.d.cts +8 -1
- package/dist/types/clientExecuteTypes.d.ts +8 -1
- package/dist/types/clientQueryTypes.cjs.map +1 -1
- package/dist/types/clientQueryTypes.d.cts +38 -5
- package/dist/types/clientQueryTypes.d.ts +38 -5
- package/dist/types/index.cjs +10 -10
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +6 -6
- package/dist/types/index.d.ts +6 -6
- package/dist/types/index.js +5 -5
- package/dist/types/index.js.map +1 -1
- package/dist/types/serverExecuteTypes.cjs.map +1 -1
- package/dist/types/serverExecuteTypes.d.cts +8 -1
- package/dist/types/serverExecuteTypes.d.ts +8 -1
- package/dist/types/serverQueryModelTypes.cjs.map +1 -1
- package/dist/types/serverQueryModelTypes.d.cts +24 -1
- package/dist/types/serverQueryModelTypes.d.ts +24 -1
- package/dist/types/serverQueryTypes.cjs.map +1 -1
- package/dist/types/serverQueryTypes.d.cts +48 -22
- package/dist/types/serverQueryTypes.d.ts +48 -22
- package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
- package/dist/types/serverSubscriptionEventTypes.d.cts +86 -22
- package/dist/types/serverSubscriptionEventTypes.d.ts +86 -22
- 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 +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/queryDataMappers.cjs +67 -19
- package/dist/utils/queryDataMappers.cjs.map +1 -1
- package/dist/utils/queryDataMappers.d.cts +7 -5
- package/dist/utils/queryDataMappers.d.ts +7 -5
- package/dist/utils/queryDataMappers.js +65 -19
- package/dist/utils/queryDataMappers.js.map +1 -1
- package/package.json +8 -4
- package/src/EngineExecuteBuilder.ts +9 -6
- package/src/EngineExecuteClient.ts +7 -7
- package/src/EngineQueryClient.ts +63 -1
- package/src/endpoints.ts +6 -6
- package/src/index.ts +2 -2
- package/src/types/clientExecuteTypes.ts +9 -2
- package/src/types/clientQueryTypes.ts +49 -4
- package/src/types/index.ts +5 -5
- package/src/types/serverExecuteTypes.ts +9 -2
- package/src/types/serverQueryModelTypes.ts +25 -0
- package/src/types/serverQueryTypes.ts +65 -25
- package/src/types/serverSubscriptionEventTypes.ts +122 -21
- package/src/types/serverSubscriptionTypes.ts +23 -3
- package/src/utils/queryDataMappers.ts +86 -20
|
@@ -107,9 +107,24 @@ function mapEngineServerBalanceHealthContributions(healthContributionsForBalance
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
function mapSubaccountSummary(baseResponse) {
|
|
110
|
+
return {
|
|
111
|
+
exists: baseResponse.exists,
|
|
112
|
+
...mapSubaccountSummaryState(
|
|
113
|
+
baseResponse,
|
|
114
|
+
baseResponse.spot_products,
|
|
115
|
+
baseResponse.perp_products
|
|
116
|
+
),
|
|
117
|
+
preState: baseResponse.pre_state ? mapSubaccountSummaryState(
|
|
118
|
+
baseResponse.pre_state,
|
|
119
|
+
baseResponse.spot_products,
|
|
120
|
+
baseResponse.perp_products
|
|
121
|
+
) : void 0
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function mapSubaccountSummaryState(state, spotProducts, perpProducts) {
|
|
110
125
|
const balances = [];
|
|
111
|
-
|
|
112
|
-
const product =
|
|
126
|
+
state.spot_balances.forEach((spotBalance) => {
|
|
127
|
+
const product = spotProducts.find(
|
|
113
128
|
(product2) => product2.product_id === spotBalance.product_id
|
|
114
129
|
);
|
|
115
130
|
if (!product) {
|
|
@@ -118,13 +133,13 @@ function mapSubaccountSummary(baseResponse) {
|
|
|
118
133
|
balances.push({
|
|
119
134
|
amount: toBigDecimal(spotBalance.balance.amount),
|
|
120
135
|
healthContributions: mapEngineServerBalanceHealthContributions(
|
|
121
|
-
|
|
136
|
+
state.health_contributions[spotBalance.product_id]
|
|
122
137
|
),
|
|
123
138
|
...mapEngineServerSpotProduct(product).product
|
|
124
139
|
});
|
|
125
140
|
});
|
|
126
|
-
|
|
127
|
-
const product =
|
|
141
|
+
state.perp_balances.forEach((perpBalance) => {
|
|
142
|
+
const product = perpProducts.find(
|
|
128
143
|
(product2) => product2.product_id === perpBalance.product_id
|
|
129
144
|
);
|
|
130
145
|
if (!product) {
|
|
@@ -134,29 +149,28 @@ function mapSubaccountSummary(baseResponse) {
|
|
|
134
149
|
amount: toBigDecimal(perpBalance.balance.amount),
|
|
135
150
|
vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),
|
|
136
151
|
healthContributions: mapEngineServerBalanceHealthContributions(
|
|
137
|
-
|
|
152
|
+
state.health_contributions[perpBalance.product_id]
|
|
138
153
|
),
|
|
139
154
|
...mapEngineServerPerpProduct(product).product
|
|
140
155
|
});
|
|
141
156
|
});
|
|
142
157
|
return {
|
|
143
158
|
balances,
|
|
144
|
-
exists: baseResponse.exists,
|
|
145
159
|
health: {
|
|
146
160
|
initial: {
|
|
147
|
-
health: toBigDecimal(
|
|
148
|
-
assets: toBigDecimal(
|
|
149
|
-
liabilities: toBigDecimal(
|
|
161
|
+
health: toBigDecimal(state.healths[0].health),
|
|
162
|
+
assets: toBigDecimal(state.healths[0].assets),
|
|
163
|
+
liabilities: toBigDecimal(state.healths[0].liabilities)
|
|
150
164
|
},
|
|
151
165
|
maintenance: {
|
|
152
|
-
health: toBigDecimal(
|
|
153
|
-
assets: toBigDecimal(
|
|
154
|
-
liabilities: toBigDecimal(
|
|
166
|
+
health: toBigDecimal(state.healths[1].health),
|
|
167
|
+
assets: toBigDecimal(state.healths[1].assets),
|
|
168
|
+
liabilities: toBigDecimal(state.healths[1].liabilities)
|
|
155
169
|
},
|
|
156
170
|
unweighted: {
|
|
157
|
-
health: toBigDecimal(
|
|
158
|
-
assets: toBigDecimal(
|
|
159
|
-
liabilities: toBigDecimal(
|
|
171
|
+
health: toBigDecimal(state.healths[2].health),
|
|
172
|
+
assets: toBigDecimal(state.healths[2].assets),
|
|
173
|
+
liabilities: toBigDecimal(state.healths[2].liabilities)
|
|
160
174
|
}
|
|
161
175
|
}
|
|
162
176
|
};
|
|
@@ -212,8 +226,6 @@ function mapEngineServerSymbol(engineServerSymbol) {
|
|
|
212
226
|
priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),
|
|
213
227
|
sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),
|
|
214
228
|
minSize: toBigDecimal(engineServerSymbol.min_size),
|
|
215
|
-
minDepth: removeDecimals(engineServerSymbol.min_depth_x18),
|
|
216
|
-
maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),
|
|
217
229
|
makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),
|
|
218
230
|
takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),
|
|
219
231
|
longWeightInitial: removeDecimals(
|
|
@@ -221,7 +233,9 @@ function mapEngineServerSymbol(engineServerSymbol) {
|
|
|
221
233
|
),
|
|
222
234
|
longWeightMaintenance: removeDecimals(
|
|
223
235
|
engineServerSymbol.long_weight_maintenance_x18
|
|
224
|
-
)
|
|
236
|
+
),
|
|
237
|
+
maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),
|
|
238
|
+
isolatedOnly: engineServerSymbol.isolated_only
|
|
225
239
|
};
|
|
226
240
|
}
|
|
227
241
|
function mapEngineMarketPrice(baseResponse) {
|
|
@@ -231,10 +245,42 @@ function mapEngineMarketPrice(baseResponse) {
|
|
|
231
245
|
productId: baseResponse.product_id
|
|
232
246
|
};
|
|
233
247
|
}
|
|
248
|
+
function mapEngineServerNlpLockedBalances(baseResponse) {
|
|
249
|
+
const lockedBalances = baseResponse.locked_balances.map((lockedBalance) => ({
|
|
250
|
+
productId: lockedBalance.balance.product_id,
|
|
251
|
+
balance: toBigDecimal(lockedBalance.balance.balance.amount),
|
|
252
|
+
unlockedAt: lockedBalance.unlocked_at
|
|
253
|
+
}));
|
|
254
|
+
return {
|
|
255
|
+
lockedBalances,
|
|
256
|
+
balanceLocked: {
|
|
257
|
+
productId: baseResponse.balance_locked.product_id,
|
|
258
|
+
balance: toBigDecimal(baseResponse.balance_locked.balance.amount)
|
|
259
|
+
},
|
|
260
|
+
balanceUnlocked: {
|
|
261
|
+
productId: baseResponse.balance_unlocked.product_id,
|
|
262
|
+
balance: toBigDecimal(baseResponse.balance_unlocked.balance.amount)
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function mapEngineServerNlpPoolInfo(baseResponse) {
|
|
267
|
+
return {
|
|
268
|
+
nlpPools: baseResponse.nlp_pools.map((pool) => ({
|
|
269
|
+
poolId: pool.pool_id,
|
|
270
|
+
subaccountHex: pool.subaccount,
|
|
271
|
+
ownerAddress: pool.owner,
|
|
272
|
+
balanceWeight: removeDecimals(pool.balance_weight_x18),
|
|
273
|
+
subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
|
|
274
|
+
openOrders: pool.open_orders.map(mapEngineServerOrder)
|
|
275
|
+
}))
|
|
276
|
+
};
|
|
277
|
+
}
|
|
234
278
|
export {
|
|
235
279
|
mapEngineMarketPrice,
|
|
236
280
|
mapEngineServerBalanceHealthContributions,
|
|
237
281
|
mapEngineServerIsolatedPositions,
|
|
282
|
+
mapEngineServerNlpLockedBalances,
|
|
283
|
+
mapEngineServerNlpPoolInfo,
|
|
238
284
|
mapEngineServerOrder,
|
|
239
285
|
mapEngineServerPerpProduct,
|
|
240
286
|
mapEngineServerSpotProduct,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineSubaccountSummaryResponse,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n const balances: GetEngineSubaccountSummaryResponse['balances'] = [];\n\n baseResponse.spot_balances.forEach((spotBalance) => {\n const product = baseResponse.spot_products.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n baseResponse.perp_balances.forEach((perpBalance) => {\n const product = baseResponse.perp_products.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances: balances,\n exists: baseResponse.exists,\n health: {\n initial: {\n health: toBigDecimal(baseResponse.healths[0].health),\n assets: toBigDecimal(baseResponse.healths[0].assets),\n liabilities: toBigDecimal(baseResponse.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(baseResponse.healths[1].health),\n assets: toBigDecimal(baseResponse.healths[1].assets),\n liabilities: toBigDecimal(baseResponse.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(baseResponse.healths[2].health),\n assets: toBigDecimal(baseResponse.healths[2].assets),\n liabilities: toBigDecimal(baseResponse.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n minDepth: removeDecimals(engineServerSymbol.min_depth_x18),\n maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAmBP,SAAS,kCAAkC;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,OAAO,eAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,WAAW,aAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAE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AAE;AAAA,MACxD;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,SAAS,uBACd,cACuB;AACvB,QAAM,UAAwC;AAAA,IAC5C,aAAa;AAAA,IACb;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,sBACd,oBACc;AACd,SAAO;AAAA,IACL,MAAM,2BAA2B,mBAAmB,IAAI;AAAA,IACxD,WAAW,mBAAmB;AAAA,IAC9B,QAAQ,mBAAmB;AAAA,IAC3B,gBAAgB,eAAe,mBAAmB,mBAAmB;AAAA,IACrE,eAAe,aAAa,mBAAmB,cAAc;AAAA,IAC7D,SAAS,aAAa,mBAAmB,QAAQ;AAAA,IACjD,UAAU,eAAe,mBAAmB,aAAa;AAAA,IACzD,eAAe,eAAe,mBAAmB,mBAAmB;AAAA,IACpE,cAAc,eAAe,mBAAmB,kBAAkB;AAAA,IAClE,cAAc,eAAe,mBAAmB,kBAAkB;AAAA,IAClE,mBAAmB;AAAA,MACjB,mBAAmB;AAAA,IACrB;AAAA,IACA,uBAAuB;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,KAAK,eAAe,aAAa,OAAO;AAAA,IACxC,KAAK,eAAe,aAAa,OAAO;AAAA,IACxC,WAAW,aAAa;AAAA,EAC1B;AACF;","names":["product"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineNlpLockedBalance,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerNlpLockedBalancesResponse,\n EngineServerNlpPoolInfoResponse,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSubaccountInfoState,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineNlpLockedBalancesResponse,\n GetEngineNlpPoolInfoResponse,\n GetEngineSubaccountSummaryResponse,\n SubaccountSummaryState,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n return {\n exists: baseResponse.exists,\n ...mapSubaccountSummaryState(\n baseResponse,\n baseResponse.spot_products,\n baseResponse.perp_products,\n ),\n preState: baseResponse.pre_state\n ? mapSubaccountSummaryState(\n baseResponse.pre_state,\n baseResponse.spot_products,\n baseResponse.perp_products,\n )\n : undefined,\n };\n}\n\nfunction mapSubaccountSummaryState(\n state: EngineServerSubaccountInfoState,\n spotProducts: EngineServerSubaccountInfoResponse['spot_products'],\n perpProducts: EngineServerSubaccountInfoResponse['perp_products'],\n): SubaccountSummaryState {\n const balances: SubaccountSummaryState['balances'] = [];\n\n state.spot_balances.forEach((spotBalance) => {\n const product = spotProducts.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n state.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n state.perp_balances.forEach((perpBalance) => {\n const product = perpProducts.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n state.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances,\n health: {\n initial: {\n health: toBigDecimal(state.healths[0].health),\n assets: toBigDecimal(state.healths[0].assets),\n liabilities: toBigDecimal(state.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(state.healths[1].health),\n assets: toBigDecimal(state.healths[1].assets),\n liabilities: toBigDecimal(state.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(state.healths[2].health),\n assets: toBigDecimal(state.healths[2].assets),\n liabilities: toBigDecimal(state.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),\n isolatedOnly: engineServerSymbol.isolated_only,\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n\nexport function mapEngineServerNlpLockedBalances(\n baseResponse: EngineServerNlpLockedBalancesResponse,\n): GetEngineNlpLockedBalancesResponse {\n const lockedBalances: EngineNlpLockedBalance[] =\n baseResponse.locked_balances.map((lockedBalance) => ({\n productId: lockedBalance.balance.product_id,\n balance: toBigDecimal(lockedBalance.balance.balance.amount),\n unlockedAt: lockedBalance.unlocked_at,\n }));\n\n return {\n lockedBalances,\n balanceLocked: {\n productId: baseResponse.balance_locked.product_id,\n balance: toBigDecimal(baseResponse.balance_locked.balance.amount),\n },\n balanceUnlocked: {\n productId: baseResponse.balance_unlocked.product_id,\n balance: toBigDecimal(baseResponse.balance_unlocked.balance.amount),\n },\n };\n}\n\nexport function mapEngineServerNlpPoolInfo(\n baseResponse: EngineServerNlpPoolInfoResponse,\n): GetEngineNlpPoolInfoResponse {\n return {\n nlpPools: baseResponse.nlp_pools.map((pool) => ({\n poolId: pool.pool_id,\n subaccountHex: pool.subaccount,\n ownerAddress: pool.owner,\n balanceWeight: removeDecimals(pool.balance_weight_x18),\n subaccountInfo: mapSubaccountSummary(pool.subaccount_info),\n openOrders: pool.open_orders.map(mapEngineServerOrder),\n })),\n };\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA0BP,SAAS,kCAAkC;AAEpC,SAAS,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QAAM,iBACJ,aAAa,gBAAgB,IAAI,CAAC,mBAAmB;AAAA,IACnD,WAAW,cAAc,QAAQ;AAAA,IACjC,SAAS,aAAa,cAAc,QAAQ,QAAQ,MAAM;AAAA,IAC1D,YAAY,cAAc;AAAA,EAC5B,EAAE;AAEJ,SAAO;AAAA,IACL;AAAA,IACA,eAAe;AAAA,MACb,WAAW,aAAa,eAAe;AAAA,MACvC,SAAS,aAAa,aAAa,eAAe,QAAQ,MAAM;AAAA,IAClE;AAAA,IACA,iBAAiB;AAAA,MACf,WAAW,aAAa,iBAAiB;AAAA,MACzC,SAAS,aAAa,aAAa,iBAAiB,QAAQ,MAAM;AAAA,IACpE;AAAA,EACF;AACF;AAEO,SAAS,2BACd,cAC8B;AAC9B,SAAO;AAAA,IACL,UAAU,aAAa,UAAU,IAAI,CAAC,UAAU;AAAA,MAC9C,QAAQ,KAAK;AAAA,MACb,eAAe,KAAK;AAAA,MACpB,cAAc,KAAK;AAAA,MACnB,eAAe,eAAe,KAAK,kBAAkB;AAAA,MACrD,gBAAgB,qBAAqB,KAAK,eAAe;AAAA,MACzD,YAAY,KAAK,YAAY,IAAI,oBAAoB;AAAA,IACvD,EAAE;AAAA,EACJ;AACF;","names":["product"]}
|
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.51",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "> TODO: description",
|
|
@@ -36,8 +36,12 @@
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
+
"react-native": "./dist/index.js",
|
|
40
|
+
"main": "./dist/index.cjs",
|
|
41
|
+
"module": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"@nadohq/shared": "
|
|
44
|
+
"@nadohq/shared": "0.1.0-alpha.51",
|
|
41
45
|
"axios": "*",
|
|
42
46
|
"ts-mixer": "*"
|
|
43
47
|
},
|
|
@@ -45,7 +49,7 @@
|
|
|
45
49
|
"viem": "*"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
|
-
"viem": "
|
|
52
|
+
"viem": "workspace:*"
|
|
49
53
|
},
|
|
50
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "bcd86b536b1f0b3b5eabf53e8f4ba5158e0051fc"
|
|
51
55
|
}
|
|
@@ -138,12 +138,15 @@ export class EngineExecuteBuilder {
|
|
|
138
138
|
async buildPlaceOrdersPayload(
|
|
139
139
|
clientParams: EngineExecuteRequestParamsByType['place_orders'],
|
|
140
140
|
): Promise<EngineServerExecuteRequestByType['place_orders']> {
|
|
141
|
-
return
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
return {
|
|
142
|
+
orders: await Promise.all(
|
|
143
|
+
clientParams.orders.map(async (orderParams) => {
|
|
144
|
+
const payload = await this.buildPlaceOrderPayload(orderParams);
|
|
145
|
+
return payload.payload;
|
|
146
|
+
}),
|
|
147
|
+
),
|
|
148
|
+
stop_on_failure: clientParams.stopOnFailure ?? null,
|
|
149
|
+
};
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
/**
|
|
@@ -42,6 +42,13 @@ export class EngineExecuteClient extends EngineBaseClient {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
async placeOrders(params: EngineExecuteRequestParamsByType['place_orders']) {
|
|
46
|
+
return this.execute(
|
|
47
|
+
'place_orders',
|
|
48
|
+
await this.payloadBuilder.buildPlaceOrdersPayload(params),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
async cancelOrders(
|
|
46
53
|
params: EngineExecuteRequestParamsByType['cancel_orders'],
|
|
47
54
|
) {
|
|
@@ -104,11 +111,4 @@ export class EngineExecuteClient extends EngineBaseClient {
|
|
|
104
111
|
await this.payloadBuilder.buildBurnNlpPayload(params),
|
|
105
112
|
);
|
|
106
113
|
}
|
|
107
|
-
|
|
108
|
-
async placeOrders(params: EngineExecuteRequestParamsByType['place_orders']) {
|
|
109
|
-
return this.execute(
|
|
110
|
-
'place_orders',
|
|
111
|
-
await this.payloadBuilder.buildPlaceOrdersPayload(params),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
114
|
}
|
package/src/EngineQueryClient.ts
CHANGED
|
@@ -30,12 +30,17 @@ import {
|
|
|
30
30
|
GetEngineMarketPriceResponse,
|
|
31
31
|
GetEngineMarketPricesParams,
|
|
32
32
|
GetEngineMarketPricesResponse,
|
|
33
|
+
GetEngineMaxBurnNlpAmountParams,
|
|
34
|
+
GetEngineMaxBurnNlpAmountResponse,
|
|
33
35
|
GetEngineMaxMintNlpAmountParams,
|
|
34
36
|
GetEngineMaxMintNlpAmountResponse,
|
|
35
37
|
GetEngineMaxOrderSizeParams,
|
|
36
38
|
GetEngineMaxOrderSizeResponse,
|
|
37
39
|
GetEngineMaxWithdrawableParams,
|
|
38
40
|
GetEngineMaxWithdrawableResponse,
|
|
41
|
+
GetEngineNlpLockedBalancesParams,
|
|
42
|
+
GetEngineNlpLockedBalancesResponse,
|
|
43
|
+
GetEngineNlpPoolInfoResponse,
|
|
39
44
|
GetEngineOrderParams,
|
|
40
45
|
GetEngineOrderResponse,
|
|
41
46
|
GetEngineSubaccountFeeRatesParams,
|
|
@@ -56,6 +61,8 @@ import { mapProductEngineType } from './utils/productEngineTypeMappers';
|
|
|
56
61
|
import {
|
|
57
62
|
mapEngineMarketPrice,
|
|
58
63
|
mapEngineServerIsolatedPositions,
|
|
64
|
+
mapEngineServerNlpLockedBalances,
|
|
65
|
+
mapEngineServerNlpPoolInfo,
|
|
59
66
|
mapEngineServerOrder,
|
|
60
67
|
mapEngineServerPerpProduct,
|
|
61
68
|
mapEngineServerSpotProduct,
|
|
@@ -159,6 +166,9 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
159
166
|
const baseResponse = await this.query('subaccount_info', {
|
|
160
167
|
subaccount: queryParams.subaccount,
|
|
161
168
|
txns: JSON.stringify(queryParams.txns),
|
|
169
|
+
// Backend expects string variants of booleans
|
|
170
|
+
pre_state:
|
|
171
|
+
params.preState !== undefined ? String(params.preState) : undefined,
|
|
162
172
|
});
|
|
163
173
|
|
|
164
174
|
return mapSubaccountSummary(baseResponse);
|
|
@@ -381,6 +391,7 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
381
391
|
},
|
|
382
392
|
{} as Record<number, BigDecimal>,
|
|
383
393
|
),
|
|
394
|
+
feeTier: baseResponse.fee_tier,
|
|
384
395
|
};
|
|
385
396
|
}
|
|
386
397
|
|
|
@@ -444,9 +455,16 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
444
455
|
subaccountOwner: params.subaccountOwner,
|
|
445
456
|
subaccountName: params.subaccountName,
|
|
446
457
|
}),
|
|
458
|
+
// Backend expects string variants of booleans
|
|
447
459
|
spot_leverage:
|
|
448
460
|
params.spotLeverage != null ? String(params.spotLeverage) : null,
|
|
449
461
|
reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,
|
|
462
|
+
isolated: params.isolated != null ? String(params.isolated) : null,
|
|
463
|
+
borrow_margin:
|
|
464
|
+
// This field is only relevant for isolated orders
|
|
465
|
+
params.isolated && params.isoBorrowMargin != null
|
|
466
|
+
? String(params.isoBorrowMargin)
|
|
467
|
+
: null,
|
|
450
468
|
});
|
|
451
469
|
|
|
452
470
|
return toBigDecimal(baseResponse.max_order_size);
|
|
@@ -492,6 +510,24 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
492
510
|
return toBigDecimal(baseResponse.max_quote_amount);
|
|
493
511
|
}
|
|
494
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Retrieves the max amount of NLP that can be burned.
|
|
515
|
+
*
|
|
516
|
+
* @param params
|
|
517
|
+
*/
|
|
518
|
+
async getMaxBurnNlpAmount(
|
|
519
|
+
params: GetEngineMaxBurnNlpAmountParams,
|
|
520
|
+
): Promise<GetEngineMaxBurnNlpAmountResponse> {
|
|
521
|
+
const baseResponse = await this.query('max_nlp_burnable', {
|
|
522
|
+
sender: subaccountToHex({
|
|
523
|
+
subaccountOwner: params.subaccountOwner,
|
|
524
|
+
subaccountName: params.subaccountName,
|
|
525
|
+
}),
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
return toBigDecimal(baseResponse.max_nlp_amount);
|
|
529
|
+
}
|
|
530
|
+
|
|
495
531
|
/**
|
|
496
532
|
* Gets the currently linked signer for the subaccount
|
|
497
533
|
* @param params
|
|
@@ -513,7 +549,7 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
513
549
|
}
|
|
514
550
|
|
|
515
551
|
/**
|
|
516
|
-
* Gets the insurance funds in
|
|
552
|
+
* Gets the insurance funds in USDT.
|
|
517
553
|
* @returns
|
|
518
554
|
*/
|
|
519
555
|
public async getInsurance(): Promise<GetEngineInsuranceResponse> {
|
|
@@ -521,4 +557,30 @@ export class EngineQueryClient extends EngineBaseClient {
|
|
|
521
557
|
|
|
522
558
|
return toBigDecimal(baseResponse.insurance);
|
|
523
559
|
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Retrieves the NLP locked and unlocked balances for a subaccount.
|
|
563
|
+
*
|
|
564
|
+
* @param params
|
|
565
|
+
*/
|
|
566
|
+
async getNlpLockedBalances(
|
|
567
|
+
params: GetEngineNlpLockedBalancesParams,
|
|
568
|
+
): Promise<GetEngineNlpLockedBalancesResponse> {
|
|
569
|
+
const baseResponse = await this.query('nlp_locked_balances', {
|
|
570
|
+
subaccount: subaccountToHex({
|
|
571
|
+
subaccountOwner: params.subaccountOwner,
|
|
572
|
+
subaccountName: params.subaccountName,
|
|
573
|
+
}),
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
return mapEngineServerNlpLockedBalances(baseResponse);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Retrieves information about all NLP sub-pools
|
|
581
|
+
*/
|
|
582
|
+
async getNlpPoolInfo(): Promise<GetEngineNlpPoolInfoResponse> {
|
|
583
|
+
const baseResponse = await this.query('nlp_pool_info', {});
|
|
584
|
+
return mapEngineServerNlpPoolInfo(baseResponse);
|
|
585
|
+
}
|
|
524
586
|
}
|
package/src/endpoints.ts
CHANGED
|
@@ -2,19 +2,19 @@ import { ChainEnv } from '@nadohq/shared';
|
|
|
2
2
|
|
|
3
3
|
export const ENGINE_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
|
|
4
4
|
local: 'http://localhost:80',
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
inkTestnet: 'https://gateway.test.nado.xyz/v1',
|
|
6
|
+
inkMainnet: 'https://gateway.prod.nado.xyz/v1',
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export const ENGINE_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
|
|
10
10
|
local: 'ws://localhost:80',
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
inkTestnet: 'wss://gateway.test.nado.xyz/v1/ws',
|
|
12
|
+
inkMainnet: 'wss://gateway.prod.nado.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
|
-
|
|
19
|
-
|
|
18
|
+
inkTestnet: 'wss://gateway.test.nado.xyz/v1/subscribe',
|
|
19
|
+
inkMainnet: 'wss://gateway.prod.nado.xyz/v1/subscribe',
|
|
20
20
|
};
|
package/src/index.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type EnginePlaceOrderParams = WithBaseEngineExecuteParams<{
|
|
|
49
49
|
order: EngineOrderParams;
|
|
50
50
|
// If not given, engine defaults to true (leverage/borrow enabled)
|
|
51
51
|
spotLeverage?: boolean;
|
|
52
|
-
// For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative
|
|
52
|
+
// For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative USDT balance)
|
|
53
53
|
borrowMargin?: boolean;
|
|
54
54
|
}>;
|
|
55
55
|
|
|
@@ -84,7 +84,14 @@ export type EngineMintNlpParams = WithBaseEngineExecuteParams<
|
|
|
84
84
|
export type EngineBurnNlpParams =
|
|
85
85
|
WithBaseEngineExecuteParams<EIP712BurnNlpParams>;
|
|
86
86
|
|
|
87
|
-
export type EnginePlaceOrdersParams =
|
|
87
|
+
export type EnginePlaceOrdersParams = {
|
|
88
|
+
orders: EnginePlaceOrderParams[];
|
|
89
|
+
/**
|
|
90
|
+
* If `true`, aborts the batch after the first failed order; if `false`, remaining orders continue to execute.
|
|
91
|
+
* If not provided, the default value is `false`.
|
|
92
|
+
*/
|
|
93
|
+
stopOnFailure?: boolean;
|
|
94
|
+
};
|
|
88
95
|
|
|
89
96
|
export interface EngineExecuteRequestParamsByType {
|
|
90
97
|
burn_nlp: EngineBurnNlpParams;
|
|
@@ -19,11 +19,15 @@ import {
|
|
|
19
19
|
EngineServerTimeResponse,
|
|
20
20
|
} from './serverQueryTypes';
|
|
21
21
|
|
|
22
|
-
export
|
|
22
|
+
export interface GetEngineSubaccountSummaryResponse extends SubaccountSummaryState {
|
|
23
23
|
exists: boolean;
|
|
24
|
+
preState?: SubaccountSummaryState;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SubaccountSummaryState {
|
|
24
28
|
balances: BalanceWithProduct[];
|
|
25
29
|
health: HealthStatusByType;
|
|
26
|
-
}
|
|
30
|
+
}
|
|
27
31
|
|
|
28
32
|
export type GetEngineSubaccountSummaryParams = Subaccount;
|
|
29
33
|
|
|
@@ -56,6 +60,7 @@ export interface GetEngineContractsResponse {
|
|
|
56
60
|
|
|
57
61
|
export type GetEngineEstimatedSubaccountSummaryParams = Subaccount & {
|
|
58
62
|
txs: SubaccountTx[];
|
|
63
|
+
preState?: boolean;
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
export type GetEngineNoncesParams = EngineServerNoncesParams;
|
|
@@ -82,12 +87,13 @@ export interface EngineSymbol {
|
|
|
82
87
|
priceIncrement: BigDecimal;
|
|
83
88
|
sizeIncrement: BigDecimal;
|
|
84
89
|
minSize: BigDecimal;
|
|
85
|
-
minDepth: BigDecimal;
|
|
86
|
-
maxSpreadRate: BigDecimal;
|
|
87
90
|
makerFeeRate: BigDecimal;
|
|
88
91
|
takerFeeRate: BigDecimal;
|
|
89
92
|
longWeightInitial: BigDecimal;
|
|
90
93
|
longWeightMaintenance: BigDecimal;
|
|
94
|
+
// undefined when there is no max open interest limit (always undefined for spot products)
|
|
95
|
+
maxOpenInterest: BigDecimal | undefined;
|
|
96
|
+
isolatedOnly: boolean;
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
export type GetEngineAllMarketsResponse = MarketWithProduct[];
|
|
@@ -166,6 +172,7 @@ export interface GetEngineSubaccountFeeRatesResponse {
|
|
|
166
172
|
liquidationSequencerFee: BigDecimal;
|
|
167
173
|
healthCheckSequencerFee: BigDecimal;
|
|
168
174
|
takerSequencerFee: BigDecimal;
|
|
175
|
+
feeTier: number;
|
|
169
176
|
}
|
|
170
177
|
|
|
171
178
|
export interface EnginePriceTickLiquidity {
|
|
@@ -215,6 +222,10 @@ export interface GetEngineMaxOrderSizeParams extends Subaccount {
|
|
|
215
222
|
// If not given, engine defaults to false. If true, the max order size will be capped to the subaccount's current position size;
|
|
216
223
|
// If no position exists, it will return 0.
|
|
217
224
|
reduceOnly?: boolean;
|
|
225
|
+
isolated?: boolean;
|
|
226
|
+
// If not given, engine defaults to true (do not borrow margin for isolated orders)
|
|
227
|
+
// Max order size query for `isolated` includes available transfer from the cross subaccount
|
|
228
|
+
isoBorrowMargin?: boolean;
|
|
218
229
|
}
|
|
219
230
|
|
|
220
231
|
export type GetEngineMaxOrderSizeResponse = BigDecimal;
|
|
@@ -251,3 +262,37 @@ export interface GetEngineMaxMintNlpAmountParams extends Subaccount {
|
|
|
251
262
|
}
|
|
252
263
|
|
|
253
264
|
export type GetEngineMaxMintNlpAmountResponse = BigDecimal;
|
|
265
|
+
|
|
266
|
+
export type GetEngineMaxBurnNlpAmountParams = Subaccount;
|
|
267
|
+
|
|
268
|
+
export type GetEngineMaxBurnNlpAmountResponse = BigDecimal;
|
|
269
|
+
|
|
270
|
+
export type GetEngineNlpLockedBalancesParams = Subaccount;
|
|
271
|
+
|
|
272
|
+
export interface EngineNlpBalance {
|
|
273
|
+
productId: number;
|
|
274
|
+
balance: BigDecimal;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface EngineNlpLockedBalance extends EngineNlpBalance {
|
|
278
|
+
unlockedAt: number;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface GetEngineNlpLockedBalancesResponse {
|
|
282
|
+
lockedBalances: EngineNlpLockedBalance[];
|
|
283
|
+
balanceLocked: EngineNlpBalance;
|
|
284
|
+
balanceUnlocked: EngineNlpBalance;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface NlpPool {
|
|
288
|
+
poolId: number;
|
|
289
|
+
subaccountHex: string;
|
|
290
|
+
ownerAddress: string;
|
|
291
|
+
balanceWeight: BigDecimal;
|
|
292
|
+
subaccountInfo: GetEngineSubaccountSummaryResponse;
|
|
293
|
+
openOrders: EngineOrder[];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface GetEngineNlpPoolInfoResponse {
|
|
297
|
+
nlpPools: NlpPool[];
|
|
298
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './clientQueryTypes';
|
|
2
1
|
export * from './clientExecuteTypes';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
2
|
+
export * from './clientQueryTypes';
|
|
3
|
+
export * from './EngineServerFailureError';
|
|
5
4
|
export * from './serverExecuteTypes';
|
|
6
|
-
export * from './
|
|
5
|
+
export * from './serverQueryModelTypes';
|
|
6
|
+
export * from './serverQueryTypes';
|
|
7
7
|
export * from './serverSubscriptionEventTypes';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './serverSubscriptionTypes';
|
|
@@ -73,7 +73,7 @@ export interface EngineServerPlaceOrderParams {
|
|
|
73
73
|
signature: string;
|
|
74
74
|
// Engine defaults this to true
|
|
75
75
|
spot_leverage: boolean | null;
|
|
76
|
-
// For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative
|
|
76
|
+
// For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative USDT balance)
|
|
77
77
|
borrow_margin: boolean | null;
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -111,7 +111,14 @@ export interface EngineServerExecuteRequestByType {
|
|
|
111
111
|
liquidate_subaccount: SignedTx<EIP712LiquidateSubaccountValues>;
|
|
112
112
|
mint_nlp: WithSpotLeverage<SignedTx<EIP712MintNlpValues>>;
|
|
113
113
|
place_order: EngineServerPlaceOrderParams;
|
|
114
|
-
place_orders:
|
|
114
|
+
place_orders: {
|
|
115
|
+
orders: EngineServerPlaceOrderParams[];
|
|
116
|
+
/**
|
|
117
|
+
* If `true`, aborts the batch after the first failed order; if `false`, remaining orders continue to execute.
|
|
118
|
+
* If `null`, the default value is `false`.
|
|
119
|
+
*/
|
|
120
|
+
stop_on_failure: boolean | null;
|
|
121
|
+
};
|
|
115
122
|
transfer_quote: SignedTx<EIP712TransferQuoteValues>;
|
|
116
123
|
withdraw_collateral: WithSpotLeverage<
|
|
117
124
|
SignedTx<EIP712WithdrawCollateralValues>
|
|
@@ -81,3 +81,28 @@ export interface EngineServerPerpBalance {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export type EngineServerProductType = 'perp' | 'spot';
|
|
84
|
+
|
|
85
|
+
export interface EngineServerOrder {
|
|
86
|
+
product_id: number;
|
|
87
|
+
sender: string;
|
|
88
|
+
price_x18: string;
|
|
89
|
+
amount: string;
|
|
90
|
+
expiration: string;
|
|
91
|
+
nonce: string;
|
|
92
|
+
unfilled_amount: string;
|
|
93
|
+
digest: string;
|
|
94
|
+
placed_at: number;
|
|
95
|
+
order_type: string;
|
|
96
|
+
appendix: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface EngineServerNlpBalance {
|
|
100
|
+
product_id: number;
|
|
101
|
+
balance: {
|
|
102
|
+
amount: string;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export interface EngineServerNlpLockedBalance {
|
|
106
|
+
unlocked_at: number;
|
|
107
|
+
balance: EngineServerNlpBalance;
|
|
108
|
+
}
|