@nadohq/engine-client 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/EngineBaseClient.cjs +166 -0
- package/dist/EngineBaseClient.cjs.map +1 -0
- package/dist/EngineBaseClient.d.cts +75 -0
- package/dist/EngineBaseClient.d.ts +75 -0
- package/dist/EngineBaseClient.js +133 -0
- package/dist/EngineBaseClient.js.map +1 -0
- package/dist/EngineClient.cjs +40 -0
- package/dist/EngineClient.cjs.map +1 -0
- package/dist/EngineClient.d.cts +23 -0
- package/dist/EngineClient.d.ts +23 -0
- package/dist/EngineClient.js +15 -0
- package/dist/EngineClient.js.map +1 -0
- package/dist/EngineExecuteBuilder.cjs +304 -0
- package/dist/EngineExecuteBuilder.cjs.map +1 -0
- package/dist/EngineExecuteBuilder.d.cts +118 -0
- package/dist/EngineExecuteBuilder.d.ts +118 -0
- package/dist/EngineExecuteBuilder.js +282 -0
- package/dist/EngineExecuteBuilder.js.map +1 -0
- package/dist/EngineExecuteClient.cjs +114 -0
- package/dist/EngineExecuteClient.cjs.map +1 -0
- package/dist/EngineExecuteClient.d.cts +28 -0
- package/dist/EngineExecuteClient.d.ts +28 -0
- package/dist/EngineExecuteClient.js +89 -0
- package/dist/EngineExecuteClient.js.map +1 -0
- package/dist/EngineQueryClient.cjs +431 -0
- package/dist/EngineQueryClient.cjs.map +1 -0
- package/dist/EngineQueryClient.d.cts +143 -0
- package/dist/EngineQueryClient.d.ts +143 -0
- package/dist/EngineQueryClient.js +424 -0
- package/dist/EngineQueryClient.js.map +1 -0
- package/dist/EngineWebClient.cjs +75 -0
- package/dist/EngineWebClient.cjs.map +1 -0
- package/dist/EngineWebClient.d.cts +31 -0
- package/dist/EngineWebClient.d.ts +31 -0
- package/dist/EngineWebClient.js +50 -0
- package/dist/EngineWebClient.js.map +1 -0
- package/dist/endpoints.cjs +49 -0
- package/dist/endpoints.cjs.map +1 -0
- package/dist/endpoints.d.cts +7 -0
- package/dist/endpoints.d.ts +7 -0
- package/dist/endpoints.js +22 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/index.cjs +31 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types/EngineServerFailureError.cjs +36 -0
- package/dist/types/EngineServerFailureError.cjs.map +1 -0
- package/dist/types/EngineServerFailureError.d.cts +11 -0
- package/dist/types/EngineServerFailureError.d.ts +11 -0
- package/dist/types/EngineServerFailureError.js +11 -0
- package/dist/types/EngineServerFailureError.js.map +1 -0
- package/dist/types/clientExecuteTypes.cjs +19 -0
- package/dist/types/clientExecuteTypes.cjs.map +1 -0
- package/dist/types/clientExecuteTypes.d.cts +74 -0
- package/dist/types/clientExecuteTypes.d.ts +74 -0
- package/dist/types/clientExecuteTypes.js +1 -0
- package/dist/types/clientExecuteTypes.js.map +1 -0
- package/dist/types/clientQueryTypes.cjs +19 -0
- package/dist/types/clientQueryTypes.cjs.map +1 -0
- package/dist/types/clientQueryTypes.d.cts +189 -0
- package/dist/types/clientQueryTypes.d.ts +189 -0
- package/dist/types/clientQueryTypes.js +1 -0
- package/dist/types/clientQueryTypes.js.map +1 -0
- package/dist/types/index.cjs +39 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +10 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/serverExecuteTypes.cjs +19 -0
- package/dist/types/serverExecuteTypes.cjs.map +1 -0
- package/dist/types/serverExecuteTypes.d.cts +91 -0
- package/dist/types/serverExecuteTypes.d.ts +91 -0
- package/dist/types/serverExecuteTypes.js +1 -0
- package/dist/types/serverExecuteTypes.js.map +1 -0
- package/dist/types/serverQueryModelTypes.cjs +19 -0
- package/dist/types/serverQueryModelTypes.cjs.map +1 -0
- package/dist/types/serverQueryModelTypes.d.cts +73 -0
- package/dist/types/serverQueryModelTypes.d.ts +73 -0
- package/dist/types/serverQueryModelTypes.js +1 -0
- package/dist/types/serverQueryModelTypes.js.map +1 -0
- package/dist/types/serverQueryTypes.cjs +19 -0
- package/dist/types/serverQueryTypes.cjs.map +1 -0
- package/dist/types/serverQueryTypes.d.cts +292 -0
- package/dist/types/serverQueryTypes.d.ts +292 -0
- package/dist/types/serverQueryTypes.js +1 -0
- package/dist/types/serverQueryTypes.js.map +1 -0
- package/dist/types/serverSubscriptionEventTypes.cjs +19 -0
- package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -0
- package/dist/types/serverSubscriptionEventTypes.d.cts +71 -0
- package/dist/types/serverSubscriptionEventTypes.d.ts +71 -0
- package/dist/types/serverSubscriptionEventTypes.js +1 -0
- package/dist/types/serverSubscriptionEventTypes.js.map +1 -0
- package/dist/types/serverSubscriptionTypes.cjs +19 -0
- package/dist/types/serverSubscriptionTypes.cjs.map +1 -0
- package/dist/types/serverSubscriptionTypes.d.cts +63 -0
- package/dist/types/serverSubscriptionTypes.d.ts +63 -0
- package/dist/types/serverSubscriptionTypes.js +1 -0
- package/dist/types/serverSubscriptionTypes.js.map +1 -0
- package/dist/utils/index.cjs +25 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +6 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/productEngineTypeMappers.cjs +49 -0
- package/dist/utils/productEngineTypeMappers.cjs.map +1 -0
- package/dist/utils/productEngineTypeMappers.d.cts +7 -0
- package/dist/utils/productEngineTypeMappers.d.ts +7 -0
- package/dist/utils/productEngineTypeMappers.js +23 -0
- package/dist/utils/productEngineTypeMappers.js.map +1 -0
- package/dist/utils/queryDataMappers.cjs +282 -0
- package/dist/utils/queryDataMappers.cjs.map +1 -0
- package/dist/utils/queryDataMappers.d.cts +18 -0
- package/dist/utils/queryDataMappers.d.ts +18 -0
- package/dist/utils/queryDataMappers.js +258 -0
- package/dist/utils/queryDataMappers.js.map +1 -0
- package/package.json +52 -0
- package/src/EngineBaseClient.ts +223 -0
- package/src/EngineClient.ts +13 -0
- package/src/EngineExecuteBuilder.ts +381 -0
- package/src/EngineExecuteClient.ts +122 -0
- package/src/EngineQueryClient.ts +553 -0
- package/src/EngineWebClient.ts +72 -0
- package/src/endpoints.ts +21 -0
- package/src/index.ts +4 -0
- package/src/types/EngineServerFailureError.ts +12 -0
- package/src/types/clientExecuteTypes.ts +118 -0
- package/src/types/clientQueryTypes.ts +267 -0
- package/src/types/index.ts +8 -0
- package/src/types/serverExecuteTypes.ts +138 -0
- package/src/types/serverQueryModelTypes.ts +83 -0
- package/src/types/serverQueryTypes.ts +382 -0
- package/src/types/serverSubscriptionEventTypes.ts +74 -0
- package/src/types/serverSubscriptionTypes.ts +79 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/productEngineTypeMappers.ts +24 -0
- package/src/utils/queryDataMappers.ts +303 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/queryDataMappers.ts
|
|
21
|
+
var queryDataMappers_exports = {};
|
|
22
|
+
__export(queryDataMappers_exports, {
|
|
23
|
+
mapEngineMarketPrice: () => mapEngineMarketPrice,
|
|
24
|
+
mapEngineServerBalanceHealthContributions: () => mapEngineServerBalanceHealthContributions,
|
|
25
|
+
mapEngineServerIsolatedPositions: () => mapEngineServerIsolatedPositions,
|
|
26
|
+
mapEngineServerOrder: () => mapEngineServerOrder,
|
|
27
|
+
mapEngineServerPerpProduct: () => mapEngineServerPerpProduct,
|
|
28
|
+
mapEngineServerSpotProduct: () => mapEngineServerSpotProduct,
|
|
29
|
+
mapEngineServerSymbol: () => mapEngineServerSymbol,
|
|
30
|
+
mapEngineServerSymbols: () => mapEngineServerSymbols,
|
|
31
|
+
mapEngineServerTickLiquidity: () => mapEngineServerTickLiquidity,
|
|
32
|
+
mapSubaccountSummary: () => mapSubaccountSummary
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(queryDataMappers_exports);
|
|
35
|
+
var import_contracts = require("@nadohq/contracts");
|
|
36
|
+
var import_utils = require("@nadohq/utils");
|
|
37
|
+
var import_productEngineTypeMappers = require("./productEngineTypeMappers.cjs");
|
|
38
|
+
function mapEngineServerTickLiquidity(tick) {
|
|
39
|
+
return {
|
|
40
|
+
price: (0, import_utils.removeDecimals)(tick[0]),
|
|
41
|
+
liquidity: (0, import_utils.toBigDecimal)(tick[1])
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function mapEngineServerOrder(order) {
|
|
45
|
+
const subaccount = (0, import_contracts.subaccountFromHex)(order.sender);
|
|
46
|
+
return {
|
|
47
|
+
digest: order.digest,
|
|
48
|
+
expiration: (0, import_utils.toBigDecimal)(order.expiration),
|
|
49
|
+
nonce: order.nonce,
|
|
50
|
+
price: (0, import_utils.removeDecimals)(order.price_x18),
|
|
51
|
+
productId: order.product_id,
|
|
52
|
+
subaccountOwner: subaccount.subaccountOwner,
|
|
53
|
+
subaccountName: subaccount.subaccountName,
|
|
54
|
+
totalAmount: (0, import_utils.toBigDecimal)(order.amount),
|
|
55
|
+
unfilledAmount: (0, import_utils.toBigDecimal)(order.unfilled_amount),
|
|
56
|
+
margin: order.margin ? (0, import_utils.toBigDecimal)(order.margin) : null,
|
|
57
|
+
// Standardizes from hex
|
|
58
|
+
// toFixed is required as toString gives values with `e`
|
|
59
|
+
orderParams: {
|
|
60
|
+
amount: (0, import_utils.toIntegerString)(order.amount),
|
|
61
|
+
expiration: (0, import_utils.toIntegerString)(order.expiration),
|
|
62
|
+
nonce: order.nonce,
|
|
63
|
+
price: (0, import_utils.toIntegerString)((0, import_utils.removeDecimals)(order.price_x18)),
|
|
64
|
+
subaccountOwner: subaccount.subaccountOwner,
|
|
65
|
+
subaccountName: subaccount.subaccountName
|
|
66
|
+
},
|
|
67
|
+
placementTime: order.placed_at,
|
|
68
|
+
orderType: order.order_type
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function mapEngineServerSpotProduct(product) {
|
|
72
|
+
return {
|
|
73
|
+
type: import_contracts.ProductEngineType.SPOT,
|
|
74
|
+
productId: product.product_id,
|
|
75
|
+
minSize: (0, import_utils.toBigDecimal)(product.book_info.min_size),
|
|
76
|
+
priceIncrement: (0, import_utils.removeDecimals)(product.book_info.price_increment_x18),
|
|
77
|
+
sizeIncrement: (0, import_utils.toBigDecimal)(product.book_info.size_increment),
|
|
78
|
+
product: {
|
|
79
|
+
productId: product.product_id,
|
|
80
|
+
type: import_contracts.ProductEngineType.SPOT,
|
|
81
|
+
totalBorrowed: (0, import_contracts.calcTotalBorrowed)(
|
|
82
|
+
product.state.total_borrows_normalized,
|
|
83
|
+
product.state.cumulative_borrows_multiplier_x18
|
|
84
|
+
),
|
|
85
|
+
totalDeposited: (0, import_contracts.calcTotalDeposited)(
|
|
86
|
+
product.state.total_deposits_normalized,
|
|
87
|
+
product.state.cumulative_deposits_multiplier_x18
|
|
88
|
+
),
|
|
89
|
+
oraclePrice: (0, import_utils.removeDecimals)(product.oracle_price_x18),
|
|
90
|
+
interestFloor: (0, import_utils.removeDecimals)(product.config.interest_floor_x18),
|
|
91
|
+
interestInflectionUtil: (0, import_utils.removeDecimals)(
|
|
92
|
+
product.config.interest_inflection_util_x18
|
|
93
|
+
),
|
|
94
|
+
interestLargeCap: (0, import_utils.removeDecimals)(product.config.interest_large_cap_x18),
|
|
95
|
+
interestSmallCap: (0, import_utils.removeDecimals)(product.config.interest_small_cap_x18),
|
|
96
|
+
longWeightInitial: (0, import_utils.removeDecimals)(product.risk.long_weight_initial_x18),
|
|
97
|
+
longWeightMaintenance: (0, import_utils.removeDecimals)(
|
|
98
|
+
product.risk.long_weight_maintenance_x18
|
|
99
|
+
),
|
|
100
|
+
shortWeightInitial: (0, import_utils.removeDecimals)(product.risk.short_weight_initial_x18),
|
|
101
|
+
shortWeightMaintenance: (0, import_utils.removeDecimals)(
|
|
102
|
+
product.risk.short_weight_maintenance_x18
|
|
103
|
+
),
|
|
104
|
+
tokenAddr: product.config.token
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function mapEngineServerPerpProduct(product) {
|
|
109
|
+
return {
|
|
110
|
+
type: import_contracts.ProductEngineType.PERP,
|
|
111
|
+
productId: product.product_id,
|
|
112
|
+
minSize: (0, import_utils.toBigDecimal)(product.book_info.min_size),
|
|
113
|
+
priceIncrement: (0, import_utils.removeDecimals)(product.book_info.price_increment_x18),
|
|
114
|
+
sizeIncrement: (0, import_utils.toBigDecimal)(product.book_info.size_increment),
|
|
115
|
+
product: {
|
|
116
|
+
productId: product.product_id,
|
|
117
|
+
type: import_contracts.ProductEngineType.PERP,
|
|
118
|
+
oraclePrice: (0, import_utils.removeDecimals)(product.oracle_price_x18),
|
|
119
|
+
longWeightInitial: (0, import_utils.removeDecimals)(product.risk.long_weight_initial_x18),
|
|
120
|
+
longWeightMaintenance: (0, import_utils.removeDecimals)(
|
|
121
|
+
product.risk.long_weight_maintenance_x18
|
|
122
|
+
),
|
|
123
|
+
shortWeightInitial: (0, import_utils.removeDecimals)(product.risk.short_weight_initial_x18),
|
|
124
|
+
shortWeightMaintenance: (0, import_utils.removeDecimals)(
|
|
125
|
+
product.risk.short_weight_maintenance_x18
|
|
126
|
+
),
|
|
127
|
+
openInterest: (0, import_utils.toBigDecimal)(product.state.open_interest),
|
|
128
|
+
cumulativeFundingLong: (0, import_utils.removeDecimals)(
|
|
129
|
+
product.state.cumulative_funding_long_x18
|
|
130
|
+
),
|
|
131
|
+
cumulativeFundingShort: (0, import_utils.removeDecimals)(
|
|
132
|
+
product.state.cumulative_funding_short_x18
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function mapEngineServerBalanceHealthContributions(healthContributionsForBalance) {
|
|
138
|
+
return {
|
|
139
|
+
initial: (0, import_utils.toBigDecimal)(healthContributionsForBalance[0]),
|
|
140
|
+
maintenance: (0, import_utils.toBigDecimal)(healthContributionsForBalance[1]),
|
|
141
|
+
unweighted: (0, import_utils.toBigDecimal)(healthContributionsForBalance[2])
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function mapSubaccountSummary(baseResponse) {
|
|
145
|
+
const balances = [];
|
|
146
|
+
baseResponse.spot_balances.forEach((spotBalance) => {
|
|
147
|
+
const product = baseResponse.spot_products.find(
|
|
148
|
+
(product2) => product2.product_id === spotBalance.product_id
|
|
149
|
+
);
|
|
150
|
+
if (!product) {
|
|
151
|
+
throw Error(`Could not find product ${spotBalance.product_id}`);
|
|
152
|
+
}
|
|
153
|
+
balances.push({
|
|
154
|
+
amount: (0, import_utils.toBigDecimal)(spotBalance.balance.amount),
|
|
155
|
+
healthContributions: mapEngineServerBalanceHealthContributions(
|
|
156
|
+
baseResponse.health_contributions[spotBalance.product_id]
|
|
157
|
+
),
|
|
158
|
+
...mapEngineServerSpotProduct(product).product
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
baseResponse.perp_balances.forEach((perpBalance) => {
|
|
162
|
+
const product = baseResponse.perp_products.find(
|
|
163
|
+
(product2) => product2.product_id === perpBalance.product_id
|
|
164
|
+
);
|
|
165
|
+
if (!product) {
|
|
166
|
+
throw Error(`Could not find product ${perpBalance.product_id}`);
|
|
167
|
+
}
|
|
168
|
+
balances.push({
|
|
169
|
+
amount: (0, import_utils.toBigDecimal)(perpBalance.balance.amount),
|
|
170
|
+
vQuoteBalance: (0, import_utils.toBigDecimal)(perpBalance.balance.v_quote_balance),
|
|
171
|
+
healthContributions: mapEngineServerBalanceHealthContributions(
|
|
172
|
+
baseResponse.health_contributions[perpBalance.product_id]
|
|
173
|
+
),
|
|
174
|
+
...mapEngineServerPerpProduct(product).product
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
return {
|
|
178
|
+
balances,
|
|
179
|
+
exists: baseResponse.exists,
|
|
180
|
+
health: {
|
|
181
|
+
initial: {
|
|
182
|
+
health: (0, import_utils.toBigDecimal)(baseResponse.healths[0].health),
|
|
183
|
+
assets: (0, import_utils.toBigDecimal)(baseResponse.healths[0].assets),
|
|
184
|
+
liabilities: (0, import_utils.toBigDecimal)(baseResponse.healths[0].liabilities)
|
|
185
|
+
},
|
|
186
|
+
maintenance: {
|
|
187
|
+
health: (0, import_utils.toBigDecimal)(baseResponse.healths[1].health),
|
|
188
|
+
assets: (0, import_utils.toBigDecimal)(baseResponse.healths[1].assets),
|
|
189
|
+
liabilities: (0, import_utils.toBigDecimal)(baseResponse.healths[1].liabilities)
|
|
190
|
+
},
|
|
191
|
+
unweighted: {
|
|
192
|
+
health: (0, import_utils.toBigDecimal)(baseResponse.healths[2].health),
|
|
193
|
+
assets: (0, import_utils.toBigDecimal)(baseResponse.healths[2].assets),
|
|
194
|
+
liabilities: (0, import_utils.toBigDecimal)(baseResponse.healths[2].liabilities)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function mapEngineServerIsolatedPositions(baseResponse) {
|
|
200
|
+
return baseResponse.isolated_positions.map((position) => {
|
|
201
|
+
const perpBalance = position.base_balance;
|
|
202
|
+
const quoteBalance = position.quote_balance;
|
|
203
|
+
return {
|
|
204
|
+
subaccount: (0, import_contracts.subaccountFromHex)(position.subaccount),
|
|
205
|
+
healths: {
|
|
206
|
+
initial: (0, import_utils.toBigDecimal)(position.healths[0].health),
|
|
207
|
+
maintenance: (0, import_utils.toBigDecimal)(position.healths[1].health),
|
|
208
|
+
unweighted: (0, import_utils.toBigDecimal)(position.healths[2].health)
|
|
209
|
+
},
|
|
210
|
+
baseBalance: {
|
|
211
|
+
amount: (0, import_utils.toBigDecimal)(perpBalance.balance.amount),
|
|
212
|
+
vQuoteBalance: (0, import_utils.toBigDecimal)(perpBalance.balance.v_quote_balance),
|
|
213
|
+
// Health contributions === healths for an isolated position
|
|
214
|
+
healthContributions: {
|
|
215
|
+
initial: (0, import_utils.toBigDecimal)(position.base_healths[0]),
|
|
216
|
+
maintenance: (0, import_utils.toBigDecimal)(position.base_healths[1]),
|
|
217
|
+
unweighted: (0, import_utils.toBigDecimal)(position.base_healths[2])
|
|
218
|
+
},
|
|
219
|
+
...mapEngineServerPerpProduct(position.base_product).product
|
|
220
|
+
},
|
|
221
|
+
quoteBalance: {
|
|
222
|
+
amount: (0, import_utils.toBigDecimal)(quoteBalance.balance.amount),
|
|
223
|
+
healthContributions: {
|
|
224
|
+
initial: (0, import_utils.toBigDecimal)(position.quote_healths[0]),
|
|
225
|
+
maintenance: (0, import_utils.toBigDecimal)(position.quote_healths[1]),
|
|
226
|
+
unweighted: (0, import_utils.toBigDecimal)(position.quote_healths[2])
|
|
227
|
+
},
|
|
228
|
+
...mapEngineServerSpotProduct(position.quote_product).product
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function mapEngineServerSymbols(baseResponse) {
|
|
234
|
+
const symbols = (0, import_utils.mapValues)(
|
|
235
|
+
baseResponse.symbols,
|
|
236
|
+
mapEngineServerSymbol
|
|
237
|
+
);
|
|
238
|
+
return {
|
|
239
|
+
symbols
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function mapEngineServerSymbol(engineServerSymbol) {
|
|
243
|
+
return {
|
|
244
|
+
type: (0, import_productEngineTypeMappers.mapEngineServerProductType)(engineServerSymbol.type),
|
|
245
|
+
productId: engineServerSymbol.product_id,
|
|
246
|
+
symbol: engineServerSymbol.symbol,
|
|
247
|
+
priceIncrement: (0, import_utils.removeDecimals)(engineServerSymbol.price_increment_x18),
|
|
248
|
+
sizeIncrement: (0, import_utils.toBigDecimal)(engineServerSymbol.size_increment),
|
|
249
|
+
minSize: (0, import_utils.toBigDecimal)(engineServerSymbol.min_size),
|
|
250
|
+
minDepth: (0, import_utils.removeDecimals)(engineServerSymbol.min_depth_x18),
|
|
251
|
+
maxSpreadRate: (0, import_utils.removeDecimals)(engineServerSymbol.max_spread_rate_x18),
|
|
252
|
+
makerFeeRate: (0, import_utils.removeDecimals)(engineServerSymbol.maker_fee_rate_x18),
|
|
253
|
+
takerFeeRate: (0, import_utils.removeDecimals)(engineServerSymbol.taker_fee_rate_x18),
|
|
254
|
+
longWeightInitial: (0, import_utils.removeDecimals)(
|
|
255
|
+
engineServerSymbol.long_weight_initial_x18
|
|
256
|
+
),
|
|
257
|
+
longWeightMaintenance: (0, import_utils.removeDecimals)(
|
|
258
|
+
engineServerSymbol.long_weight_maintenance_x18
|
|
259
|
+
)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function mapEngineMarketPrice(baseResponse) {
|
|
263
|
+
return {
|
|
264
|
+
ask: (0, import_utils.removeDecimals)(baseResponse.ask_x18),
|
|
265
|
+
bid: (0, import_utils.removeDecimals)(baseResponse.bid_x18),
|
|
266
|
+
productId: baseResponse.product_id
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
270
|
+
0 && (module.exports = {
|
|
271
|
+
mapEngineMarketPrice,
|
|
272
|
+
mapEngineServerBalanceHealthContributions,
|
|
273
|
+
mapEngineServerIsolatedPositions,
|
|
274
|
+
mapEngineServerOrder,
|
|
275
|
+
mapEngineServerPerpProduct,
|
|
276
|
+
mapEngineServerSpotProduct,
|
|
277
|
+
mapEngineServerSymbol,
|
|
278
|
+
mapEngineServerSymbols,
|
|
279
|
+
mapEngineServerTickLiquidity,
|
|
280
|
+
mapSubaccountSummary
|
|
281
|
+
});
|
|
282
|
+
//# sourceMappingURL=queryDataMappers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n OrderExpirationType,\n PerpMarket,\n ProductEngineType,\n SpotMarket,\n subaccountFromHex,\n} from '@nadohq/contracts';\nimport {\n mapValues,\n removeDecimals,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/utils';\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: toBigDecimal(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 margin: order.margin ? toBigDecimal(order.margin) : null,\n // Standardizes from hex\n // toFixed is required as toString gives values with `e`\n orderParams: {\n amount: toIntegerString(order.amount),\n expiration: toIntegerString(order.expiration),\n nonce: order.nonce,\n price: toIntegerString(removeDecimals(order.price_x18)),\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n },\n placementTime: order.placed_at,\n orderType: order.order_type as OrderExpirationType,\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 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBASO;AACP,mBAKO;AAmBP,sCAA2C;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,WAAO,6BAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,eAAW,2BAAa,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B;AACF;","names":["product"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/contracts';
|
|
2
|
+
import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice } from '../types/clientQueryTypes.cjs';
|
|
3
|
+
import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice } from '../types/serverQueryTypes.cjs';
|
|
4
|
+
import { EngineServerSpotProduct, EngineServerPerpProduct } from '../types/serverQueryModelTypes.cjs';
|
|
5
|
+
import '@nadohq/utils';
|
|
6
|
+
|
|
7
|
+
declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
|
|
8
|
+
declare function mapEngineServerOrder(order: EngineServerOrderResponse): EngineOrder;
|
|
9
|
+
declare function mapEngineServerSpotProduct(product: EngineServerSpotProduct): SpotMarket;
|
|
10
|
+
declare function mapEngineServerPerpProduct(product: EngineServerPerpProduct): PerpMarket;
|
|
11
|
+
declare function mapEngineServerBalanceHealthContributions(healthContributionsForBalance: string[]): BalanceHealthContributions;
|
|
12
|
+
declare function mapSubaccountSummary(baseResponse: EngineServerSubaccountInfoResponse): GetEngineSubaccountSummaryResponse;
|
|
13
|
+
declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsolatedPositionsResponse): GetEngineIsolatedPositionsResponse;
|
|
14
|
+
declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
|
|
15
|
+
declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
|
|
16
|
+
declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
|
|
17
|
+
|
|
18
|
+
export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/contracts';
|
|
2
|
+
import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice } from '../types/clientQueryTypes.js';
|
|
3
|
+
import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice } from '../types/serverQueryTypes.js';
|
|
4
|
+
import { EngineServerSpotProduct, EngineServerPerpProduct } from '../types/serverQueryModelTypes.js';
|
|
5
|
+
import '@nadohq/utils';
|
|
6
|
+
|
|
7
|
+
declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
|
|
8
|
+
declare function mapEngineServerOrder(order: EngineServerOrderResponse): EngineOrder;
|
|
9
|
+
declare function mapEngineServerSpotProduct(product: EngineServerSpotProduct): SpotMarket;
|
|
10
|
+
declare function mapEngineServerPerpProduct(product: EngineServerPerpProduct): PerpMarket;
|
|
11
|
+
declare function mapEngineServerBalanceHealthContributions(healthContributionsForBalance: string[]): BalanceHealthContributions;
|
|
12
|
+
declare function mapSubaccountSummary(baseResponse: EngineServerSubaccountInfoResponse): GetEngineSubaccountSummaryResponse;
|
|
13
|
+
declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsolatedPositionsResponse): GetEngineIsolatedPositionsResponse;
|
|
14
|
+
declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
|
|
15
|
+
declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
|
|
16
|
+
declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
|
|
17
|
+
|
|
18
|
+
export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// src/utils/queryDataMappers.ts
|
|
2
|
+
import {
|
|
3
|
+
calcTotalBorrowed,
|
|
4
|
+
calcTotalDeposited,
|
|
5
|
+
ProductEngineType,
|
|
6
|
+
subaccountFromHex
|
|
7
|
+
} from "@nadohq/contracts";
|
|
8
|
+
import {
|
|
9
|
+
mapValues,
|
|
10
|
+
removeDecimals,
|
|
11
|
+
toBigDecimal,
|
|
12
|
+
toIntegerString
|
|
13
|
+
} from "@nadohq/utils";
|
|
14
|
+
import { mapEngineServerProductType } from "./productEngineTypeMappers.js";
|
|
15
|
+
function mapEngineServerTickLiquidity(tick) {
|
|
16
|
+
return {
|
|
17
|
+
price: removeDecimals(tick[0]),
|
|
18
|
+
liquidity: toBigDecimal(tick[1])
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function mapEngineServerOrder(order) {
|
|
22
|
+
const subaccount = subaccountFromHex(order.sender);
|
|
23
|
+
return {
|
|
24
|
+
digest: order.digest,
|
|
25
|
+
expiration: toBigDecimal(order.expiration),
|
|
26
|
+
nonce: order.nonce,
|
|
27
|
+
price: removeDecimals(order.price_x18),
|
|
28
|
+
productId: order.product_id,
|
|
29
|
+
subaccountOwner: subaccount.subaccountOwner,
|
|
30
|
+
subaccountName: subaccount.subaccountName,
|
|
31
|
+
totalAmount: toBigDecimal(order.amount),
|
|
32
|
+
unfilledAmount: toBigDecimal(order.unfilled_amount),
|
|
33
|
+
margin: order.margin ? toBigDecimal(order.margin) : null,
|
|
34
|
+
// Standardizes from hex
|
|
35
|
+
// toFixed is required as toString gives values with `e`
|
|
36
|
+
orderParams: {
|
|
37
|
+
amount: toIntegerString(order.amount),
|
|
38
|
+
expiration: toIntegerString(order.expiration),
|
|
39
|
+
nonce: order.nonce,
|
|
40
|
+
price: toIntegerString(removeDecimals(order.price_x18)),
|
|
41
|
+
subaccountOwner: subaccount.subaccountOwner,
|
|
42
|
+
subaccountName: subaccount.subaccountName
|
|
43
|
+
},
|
|
44
|
+
placementTime: order.placed_at,
|
|
45
|
+
orderType: order.order_type
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function mapEngineServerSpotProduct(product) {
|
|
49
|
+
return {
|
|
50
|
+
type: ProductEngineType.SPOT,
|
|
51
|
+
productId: product.product_id,
|
|
52
|
+
minSize: toBigDecimal(product.book_info.min_size),
|
|
53
|
+
priceIncrement: removeDecimals(product.book_info.price_increment_x18),
|
|
54
|
+
sizeIncrement: toBigDecimal(product.book_info.size_increment),
|
|
55
|
+
product: {
|
|
56
|
+
productId: product.product_id,
|
|
57
|
+
type: ProductEngineType.SPOT,
|
|
58
|
+
totalBorrowed: calcTotalBorrowed(
|
|
59
|
+
product.state.total_borrows_normalized,
|
|
60
|
+
product.state.cumulative_borrows_multiplier_x18
|
|
61
|
+
),
|
|
62
|
+
totalDeposited: calcTotalDeposited(
|
|
63
|
+
product.state.total_deposits_normalized,
|
|
64
|
+
product.state.cumulative_deposits_multiplier_x18
|
|
65
|
+
),
|
|
66
|
+
oraclePrice: removeDecimals(product.oracle_price_x18),
|
|
67
|
+
interestFloor: removeDecimals(product.config.interest_floor_x18),
|
|
68
|
+
interestInflectionUtil: removeDecimals(
|
|
69
|
+
product.config.interest_inflection_util_x18
|
|
70
|
+
),
|
|
71
|
+
interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),
|
|
72
|
+
interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),
|
|
73
|
+
longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),
|
|
74
|
+
longWeightMaintenance: removeDecimals(
|
|
75
|
+
product.risk.long_weight_maintenance_x18
|
|
76
|
+
),
|
|
77
|
+
shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),
|
|
78
|
+
shortWeightMaintenance: removeDecimals(
|
|
79
|
+
product.risk.short_weight_maintenance_x18
|
|
80
|
+
),
|
|
81
|
+
tokenAddr: product.config.token
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function mapEngineServerPerpProduct(product) {
|
|
86
|
+
return {
|
|
87
|
+
type: ProductEngineType.PERP,
|
|
88
|
+
productId: product.product_id,
|
|
89
|
+
minSize: toBigDecimal(product.book_info.min_size),
|
|
90
|
+
priceIncrement: removeDecimals(product.book_info.price_increment_x18),
|
|
91
|
+
sizeIncrement: toBigDecimal(product.book_info.size_increment),
|
|
92
|
+
product: {
|
|
93
|
+
productId: product.product_id,
|
|
94
|
+
type: ProductEngineType.PERP,
|
|
95
|
+
oraclePrice: removeDecimals(product.oracle_price_x18),
|
|
96
|
+
longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),
|
|
97
|
+
longWeightMaintenance: removeDecimals(
|
|
98
|
+
product.risk.long_weight_maintenance_x18
|
|
99
|
+
),
|
|
100
|
+
shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),
|
|
101
|
+
shortWeightMaintenance: removeDecimals(
|
|
102
|
+
product.risk.short_weight_maintenance_x18
|
|
103
|
+
),
|
|
104
|
+
openInterest: toBigDecimal(product.state.open_interest),
|
|
105
|
+
cumulativeFundingLong: removeDecimals(
|
|
106
|
+
product.state.cumulative_funding_long_x18
|
|
107
|
+
),
|
|
108
|
+
cumulativeFundingShort: removeDecimals(
|
|
109
|
+
product.state.cumulative_funding_short_x18
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function mapEngineServerBalanceHealthContributions(healthContributionsForBalance) {
|
|
115
|
+
return {
|
|
116
|
+
initial: toBigDecimal(healthContributionsForBalance[0]),
|
|
117
|
+
maintenance: toBigDecimal(healthContributionsForBalance[1]),
|
|
118
|
+
unweighted: toBigDecimal(healthContributionsForBalance[2])
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function mapSubaccountSummary(baseResponse) {
|
|
122
|
+
const balances = [];
|
|
123
|
+
baseResponse.spot_balances.forEach((spotBalance) => {
|
|
124
|
+
const product = baseResponse.spot_products.find(
|
|
125
|
+
(product2) => product2.product_id === spotBalance.product_id
|
|
126
|
+
);
|
|
127
|
+
if (!product) {
|
|
128
|
+
throw Error(`Could not find product ${spotBalance.product_id}`);
|
|
129
|
+
}
|
|
130
|
+
balances.push({
|
|
131
|
+
amount: toBigDecimal(spotBalance.balance.amount),
|
|
132
|
+
healthContributions: mapEngineServerBalanceHealthContributions(
|
|
133
|
+
baseResponse.health_contributions[spotBalance.product_id]
|
|
134
|
+
),
|
|
135
|
+
...mapEngineServerSpotProduct(product).product
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
baseResponse.perp_balances.forEach((perpBalance) => {
|
|
139
|
+
const product = baseResponse.perp_products.find(
|
|
140
|
+
(product2) => product2.product_id === perpBalance.product_id
|
|
141
|
+
);
|
|
142
|
+
if (!product) {
|
|
143
|
+
throw Error(`Could not find product ${perpBalance.product_id}`);
|
|
144
|
+
}
|
|
145
|
+
balances.push({
|
|
146
|
+
amount: toBigDecimal(perpBalance.balance.amount),
|
|
147
|
+
vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),
|
|
148
|
+
healthContributions: mapEngineServerBalanceHealthContributions(
|
|
149
|
+
baseResponse.health_contributions[perpBalance.product_id]
|
|
150
|
+
),
|
|
151
|
+
...mapEngineServerPerpProduct(product).product
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
balances,
|
|
156
|
+
exists: baseResponse.exists,
|
|
157
|
+
health: {
|
|
158
|
+
initial: {
|
|
159
|
+
health: toBigDecimal(baseResponse.healths[0].health),
|
|
160
|
+
assets: toBigDecimal(baseResponse.healths[0].assets),
|
|
161
|
+
liabilities: toBigDecimal(baseResponse.healths[0].liabilities)
|
|
162
|
+
},
|
|
163
|
+
maintenance: {
|
|
164
|
+
health: toBigDecimal(baseResponse.healths[1].health),
|
|
165
|
+
assets: toBigDecimal(baseResponse.healths[1].assets),
|
|
166
|
+
liabilities: toBigDecimal(baseResponse.healths[1].liabilities)
|
|
167
|
+
},
|
|
168
|
+
unweighted: {
|
|
169
|
+
health: toBigDecimal(baseResponse.healths[2].health),
|
|
170
|
+
assets: toBigDecimal(baseResponse.healths[2].assets),
|
|
171
|
+
liabilities: toBigDecimal(baseResponse.healths[2].liabilities)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function mapEngineServerIsolatedPositions(baseResponse) {
|
|
177
|
+
return baseResponse.isolated_positions.map((position) => {
|
|
178
|
+
const perpBalance = position.base_balance;
|
|
179
|
+
const quoteBalance = position.quote_balance;
|
|
180
|
+
return {
|
|
181
|
+
subaccount: subaccountFromHex(position.subaccount),
|
|
182
|
+
healths: {
|
|
183
|
+
initial: toBigDecimal(position.healths[0].health),
|
|
184
|
+
maintenance: toBigDecimal(position.healths[1].health),
|
|
185
|
+
unweighted: toBigDecimal(position.healths[2].health)
|
|
186
|
+
},
|
|
187
|
+
baseBalance: {
|
|
188
|
+
amount: toBigDecimal(perpBalance.balance.amount),
|
|
189
|
+
vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),
|
|
190
|
+
// Health contributions === healths for an isolated position
|
|
191
|
+
healthContributions: {
|
|
192
|
+
initial: toBigDecimal(position.base_healths[0]),
|
|
193
|
+
maintenance: toBigDecimal(position.base_healths[1]),
|
|
194
|
+
unweighted: toBigDecimal(position.base_healths[2])
|
|
195
|
+
},
|
|
196
|
+
...mapEngineServerPerpProduct(position.base_product).product
|
|
197
|
+
},
|
|
198
|
+
quoteBalance: {
|
|
199
|
+
amount: toBigDecimal(quoteBalance.balance.amount),
|
|
200
|
+
healthContributions: {
|
|
201
|
+
initial: toBigDecimal(position.quote_healths[0]),
|
|
202
|
+
maintenance: toBigDecimal(position.quote_healths[1]),
|
|
203
|
+
unweighted: toBigDecimal(position.quote_healths[2])
|
|
204
|
+
},
|
|
205
|
+
...mapEngineServerSpotProduct(position.quote_product).product
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function mapEngineServerSymbols(baseResponse) {
|
|
211
|
+
const symbols = mapValues(
|
|
212
|
+
baseResponse.symbols,
|
|
213
|
+
mapEngineServerSymbol
|
|
214
|
+
);
|
|
215
|
+
return {
|
|
216
|
+
symbols
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function mapEngineServerSymbol(engineServerSymbol) {
|
|
220
|
+
return {
|
|
221
|
+
type: mapEngineServerProductType(engineServerSymbol.type),
|
|
222
|
+
productId: engineServerSymbol.product_id,
|
|
223
|
+
symbol: engineServerSymbol.symbol,
|
|
224
|
+
priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),
|
|
225
|
+
sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),
|
|
226
|
+
minSize: toBigDecimal(engineServerSymbol.min_size),
|
|
227
|
+
minDepth: removeDecimals(engineServerSymbol.min_depth_x18),
|
|
228
|
+
maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),
|
|
229
|
+
makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),
|
|
230
|
+
takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),
|
|
231
|
+
longWeightInitial: removeDecimals(
|
|
232
|
+
engineServerSymbol.long_weight_initial_x18
|
|
233
|
+
),
|
|
234
|
+
longWeightMaintenance: removeDecimals(
|
|
235
|
+
engineServerSymbol.long_weight_maintenance_x18
|
|
236
|
+
)
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function mapEngineMarketPrice(baseResponse) {
|
|
240
|
+
return {
|
|
241
|
+
ask: removeDecimals(baseResponse.ask_x18),
|
|
242
|
+
bid: removeDecimals(baseResponse.bid_x18),
|
|
243
|
+
productId: baseResponse.product_id
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
export {
|
|
247
|
+
mapEngineMarketPrice,
|
|
248
|
+
mapEngineServerBalanceHealthContributions,
|
|
249
|
+
mapEngineServerIsolatedPositions,
|
|
250
|
+
mapEngineServerOrder,
|
|
251
|
+
mapEngineServerPerpProduct,
|
|
252
|
+
mapEngineServerSpotProduct,
|
|
253
|
+
mapEngineServerSymbol,
|
|
254
|
+
mapEngineServerSymbols,
|
|
255
|
+
mapEngineServerTickLiquidity,
|
|
256
|
+
mapSubaccountSummary
|
|
257
|
+
};
|
|
258
|
+
//# sourceMappingURL=queryDataMappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n OrderExpirationType,\n PerpMarket,\n ProductEngineType,\n SpotMarket,\n subaccountFromHex,\n} from '@nadohq/contracts';\nimport {\n mapValues,\n removeDecimals,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/utils';\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: toBigDecimal(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 margin: order.margin ? toBigDecimal(order.margin) : null,\n // Standardizes from hex\n // toFixed is required as toString gives values with `e`\n orderParams: {\n amount: toIntegerString(order.amount),\n expiration: toIntegerString(order.expiration),\n nonce: order.nonce,\n price: toIntegerString(removeDecimals(order.price_x18)),\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n },\n placementTime: order.placed_at,\n orderType: order.order_type as OrderExpirationType,\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 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,EAGA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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