@nadohq/indexer-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/IndexerBaseClient.cjs +608 -0
- package/dist/IndexerBaseClient.cjs.map +1 -0
- package/dist/IndexerBaseClient.d.cts +183 -0
- package/dist/IndexerBaseClient.d.ts +183 -0
- package/dist/IndexerBaseClient.js +605 -0
- package/dist/IndexerBaseClient.js.map +1 -0
- package/dist/IndexerClient.cjs +368 -0
- package/dist/IndexerClient.cjs.map +1 -0
- package/dist/IndexerClient.d.cts +50 -0
- package/dist/IndexerClient.d.ts +50 -0
- package/dist/IndexerClient.js +348 -0
- package/dist/IndexerClient.js.map +1 -0
- package/dist/dataMappers.cjs +324 -0
- package/dist/dataMappers.cjs.map +1 -0
- package/dist/dataMappers.d.cts +31 -0
- package/dist/dataMappers.d.ts +31 -0
- package/dist/dataMappers.js +296 -0
- package/dist/dataMappers.js.map +1 -0
- package/dist/endpoints.cjs +35 -0
- package/dist/endpoints.cjs.map +1 -0
- package/dist/endpoints.d.cts +5 -0
- package/dist/endpoints.d.ts +5 -0
- package/dist/endpoints.js +10 -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 +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types/CandlestickPeriod.cjs +42 -0
- package/dist/types/CandlestickPeriod.cjs.map +1 -0
- package/dist/types/CandlestickPeriod.d.cts +13 -0
- package/dist/types/CandlestickPeriod.d.ts +13 -0
- package/dist/types/CandlestickPeriod.js +17 -0
- package/dist/types/CandlestickPeriod.js.map +1 -0
- package/dist/types/IndexerEventType.cjs +19 -0
- package/dist/types/IndexerEventType.cjs.map +1 -0
- package/dist/types/IndexerEventType.d.cts +3 -0
- package/dist/types/IndexerEventType.d.ts +3 -0
- package/dist/types/IndexerEventType.js +1 -0
- package/dist/types/IndexerEventType.js.map +1 -0
- package/dist/types/IndexerLeaderboardType.cjs +19 -0
- package/dist/types/IndexerLeaderboardType.cjs.map +1 -0
- package/dist/types/IndexerLeaderboardType.d.cts +3 -0
- package/dist/types/IndexerLeaderboardType.d.ts +3 -0
- package/dist/types/IndexerLeaderboardType.js +1 -0
- package/dist/types/IndexerLeaderboardType.js.map +1 -0
- package/dist/types/NadoTx.cjs +19 -0
- package/dist/types/NadoTx.cjs.map +1 -0
- package/dist/types/NadoTx.d.cts +49 -0
- package/dist/types/NadoTx.d.ts +49 -0
- package/dist/types/NadoTx.js +1 -0
- package/dist/types/NadoTx.js.map +1 -0
- package/dist/types/clientTypes.cjs +19 -0
- package/dist/types/clientTypes.cjs.map +1 -0
- package/dist/types/clientTypes.d.cts +467 -0
- package/dist/types/clientTypes.d.ts +467 -0
- package/dist/types/clientTypes.js +1 -0
- package/dist/types/clientTypes.js.map +1 -0
- package/dist/types/collateralEventType.cjs +19 -0
- package/dist/types/collateralEventType.cjs.map +1 -0
- package/dist/types/collateralEventType.d.cts +3 -0
- package/dist/types/collateralEventType.d.ts +3 -0
- package/dist/types/collateralEventType.js +1 -0
- package/dist/types/collateralEventType.js.map +1 -0
- package/dist/types/index.cjs +41 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +13 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/paginatedEventsTypes.cjs +19 -0
- package/dist/types/paginatedEventsTypes.cjs.map +1 -0
- package/dist/types/paginatedEventsTypes.d.cts +115 -0
- package/dist/types/paginatedEventsTypes.d.ts +115 -0
- package/dist/types/paginatedEventsTypes.js +1 -0
- package/dist/types/paginatedEventsTypes.js.map +1 -0
- package/dist/types/serverModelTypes.cjs +19 -0
- package/dist/types/serverModelTypes.cjs.map +1 -0
- package/dist/types/serverModelTypes.d.cts +224 -0
- package/dist/types/serverModelTypes.d.ts +224 -0
- package/dist/types/serverModelTypes.js +1 -0
- package/dist/types/serverModelTypes.js.map +1 -0
- package/dist/types/serverTypes.cjs +19 -0
- package/dist/types/serverTypes.cjs.map +1 -0
- package/dist/types/serverTypes.d.cts +304 -0
- package/dist/types/serverTypes.d.ts +304 -0
- package/dist/types/serverTypes.js +1 -0
- package/dist/types/serverTypes.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 +12 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/indexerBalanceValue.cjs +43 -0
- package/dist/utils/indexerBalanceValue.cjs.map +1 -0
- package/dist/utils/indexerBalanceValue.d.cts +39 -0
- package/dist/utils/indexerBalanceValue.d.ts +39 -0
- package/dist/utils/indexerBalanceValue.js +16 -0
- package/dist/utils/indexerBalanceValue.js.map +1 -0
- package/package.json +53 -0
- package/src/IndexerBaseClient.ts +851 -0
- package/src/IndexerClient.ts +468 -0
- package/src/dataMappers.ts +362 -0
- package/src/endpoints.ts +7 -0
- package/src/index.ts +4 -0
- package/src/types/CandlestickPeriod.ts +11 -0
- package/src/types/IndexerEventType.ts +9 -0
- package/src/types/IndexerLeaderboardType.ts +2 -0
- package/src/types/NadoTx.ts +63 -0
- package/src/types/clientTypes.ts +679 -0
- package/src/types/collateralEventType.ts +4 -0
- package/src/types/index.ts +9 -0
- package/src/types/paginatedEventsTypes.ts +194 -0
- package/src/types/serverModelTypes.ts +271 -0
- package/src/types/serverTypes.ts +427 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/indexerBalanceValue.ts +46 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRecvTimeFromOrderNonce,
|
|
3
|
+
Market,
|
|
4
|
+
parseRawExpirationTimestamp,
|
|
5
|
+
PerpMarket,
|
|
6
|
+
ProductEngineType,
|
|
7
|
+
SpotMarket,
|
|
8
|
+
subaccountFromHex,
|
|
9
|
+
} from '@nadohq/contracts';
|
|
10
|
+
import {
|
|
11
|
+
mapEngineServerPerpProduct,
|
|
12
|
+
mapEngineServerSpotProduct,
|
|
13
|
+
} from '@nadohq/engine-client';
|
|
14
|
+
import {
|
|
15
|
+
mapValues,
|
|
16
|
+
removeDecimals,
|
|
17
|
+
toBigDecimal,
|
|
18
|
+
toIntegerString,
|
|
19
|
+
} from '@nadohq/utils';
|
|
20
|
+
import {
|
|
21
|
+
Candlestick,
|
|
22
|
+
IndexerEvent,
|
|
23
|
+
IndexerEventWithTx,
|
|
24
|
+
IndexerFundingRate,
|
|
25
|
+
IndexerLeaderboardContest,
|
|
26
|
+
IndexerLeaderboardParticipant,
|
|
27
|
+
IndexerLeaderboardRegistration,
|
|
28
|
+
IndexerMaker,
|
|
29
|
+
IndexerMarketSnapshot,
|
|
30
|
+
IndexerMatchEventBalances,
|
|
31
|
+
IndexerOrder,
|
|
32
|
+
IndexerPerpBalance,
|
|
33
|
+
IndexerPerpPrices,
|
|
34
|
+
IndexerProductPayment,
|
|
35
|
+
IndexerServerBalance,
|
|
36
|
+
IndexerServerCandlestick,
|
|
37
|
+
IndexerServerEvent,
|
|
38
|
+
IndexerServerFundingRate,
|
|
39
|
+
IndexerServerLeaderboardContest,
|
|
40
|
+
IndexerServerLeaderboardPosition,
|
|
41
|
+
IndexerServerLeaderboardRegistration,
|
|
42
|
+
IndexerServerMaker,
|
|
43
|
+
IndexerServerMarketSnapshot,
|
|
44
|
+
IndexerServerMatchEventBalances,
|
|
45
|
+
IndexerServerOrder,
|
|
46
|
+
IndexerServerPerpPrices,
|
|
47
|
+
IndexerServerProduct,
|
|
48
|
+
IndexerServerProductPayment,
|
|
49
|
+
IndexerServerSnapshotsInterval,
|
|
50
|
+
IndexerServerTx,
|
|
51
|
+
IndexerServerVlpSnapshot,
|
|
52
|
+
IndexerSnapshotsIntervalParams,
|
|
53
|
+
IndexerSpotBalance,
|
|
54
|
+
IndexerVlpSnapshot,
|
|
55
|
+
} from './types';
|
|
56
|
+
|
|
57
|
+
export function mapSnapshotsIntervalToServerParams(
|
|
58
|
+
params: IndexerSnapshotsIntervalParams,
|
|
59
|
+
): IndexerServerSnapshotsInterval {
|
|
60
|
+
return {
|
|
61
|
+
count: params.limit,
|
|
62
|
+
max_time: params.maxTimeInclusive
|
|
63
|
+
? toIntegerString(params.maxTimeInclusive)
|
|
64
|
+
: undefined,
|
|
65
|
+
granularity: params.granularity,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function mapIndexerServerProduct(product: IndexerServerProduct): Market {
|
|
70
|
+
if ('spot' in product) {
|
|
71
|
+
return mapEngineServerSpotProduct(product.spot);
|
|
72
|
+
}
|
|
73
|
+
return mapEngineServerPerpProduct(product.perp);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function mapIndexerServerBalance(
|
|
77
|
+
balance: IndexerServerBalance,
|
|
78
|
+
): IndexerSpotBalance | IndexerPerpBalance {
|
|
79
|
+
if ('spot' in balance) {
|
|
80
|
+
return {
|
|
81
|
+
amount: toBigDecimal(balance.spot.balance.amount),
|
|
82
|
+
productId: balance.spot.product_id,
|
|
83
|
+
type: ProductEngineType.SPOT,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
amount: toBigDecimal(balance.perp.balance.amount),
|
|
88
|
+
productId: balance.perp.product_id,
|
|
89
|
+
type: ProductEngineType.PERP,
|
|
90
|
+
vQuoteBalance: toBigDecimal(balance.perp.balance.v_quote_balance),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function mapIndexerOrder(order: IndexerServerOrder): IndexerOrder {
|
|
95
|
+
const expiration = toBigDecimal(order.expiration);
|
|
96
|
+
const expirationEncodedData = parseRawExpirationTimestamp(order.expiration);
|
|
97
|
+
return {
|
|
98
|
+
amount: toBigDecimal(order.amount),
|
|
99
|
+
digest: order.digest,
|
|
100
|
+
isolated: order.isolated,
|
|
101
|
+
rawExpiration: expiration,
|
|
102
|
+
isReduceOnly: expirationEncodedData.reduceOnly,
|
|
103
|
+
expiration: expirationEncodedData.expirationTime,
|
|
104
|
+
orderType: expirationEncodedData.type,
|
|
105
|
+
nonce: toBigDecimal(order.nonce),
|
|
106
|
+
recvTimeSeconds: getRecvTimeFromOrderNonce(order.nonce) / 1000,
|
|
107
|
+
price: removeDecimals(order.price_x18),
|
|
108
|
+
productId: order.product_id,
|
|
109
|
+
subaccount: order.subaccount,
|
|
110
|
+
submissionIndex: order.submission_idx,
|
|
111
|
+
baseFilled: toBigDecimal(order.base_filled),
|
|
112
|
+
quoteFilled: toBigDecimal(order.quote_filled),
|
|
113
|
+
totalFee: toBigDecimal(order.fee),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function mapIndexerEvent(event: IndexerServerEvent): IndexerEvent {
|
|
118
|
+
const eventState: IndexerEvent['state'] = (() => {
|
|
119
|
+
// Assume backend data is consistent
|
|
120
|
+
if ('spot' in event.pre_balance) {
|
|
121
|
+
return {
|
|
122
|
+
type: ProductEngineType.SPOT,
|
|
123
|
+
market: mapIndexerServerProduct(event.product) as SpotMarket,
|
|
124
|
+
preBalance: mapIndexerServerBalance(
|
|
125
|
+
event.pre_balance,
|
|
126
|
+
) as IndexerSpotBalance,
|
|
127
|
+
postBalance: mapIndexerServerBalance(
|
|
128
|
+
event.post_balance,
|
|
129
|
+
) as IndexerSpotBalance,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
type: ProductEngineType.PERP,
|
|
134
|
+
market: mapIndexerServerProduct(event.product) as PerpMarket,
|
|
135
|
+
preBalance: mapIndexerServerBalance(
|
|
136
|
+
event.pre_balance,
|
|
137
|
+
) as IndexerPerpBalance,
|
|
138
|
+
postBalance: mapIndexerServerBalance(
|
|
139
|
+
event.post_balance,
|
|
140
|
+
) as IndexerPerpBalance,
|
|
141
|
+
};
|
|
142
|
+
})();
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
eventType: event.event_type,
|
|
146
|
+
productId: event.product_id,
|
|
147
|
+
isolated: event.isolated,
|
|
148
|
+
isolatedProductId: event.isolated_product_id,
|
|
149
|
+
state: eventState,
|
|
150
|
+
subaccount: event.subaccount,
|
|
151
|
+
submissionIndex: event.submission_idx,
|
|
152
|
+
trackedVars: {
|
|
153
|
+
netEntryCumulative: toBigDecimal(event.net_entry_cumulative),
|
|
154
|
+
netEntryUnrealized: toBigDecimal(event.net_entry_unrealized),
|
|
155
|
+
netFundingCumulative: toBigDecimal(event.net_funding_cumulative),
|
|
156
|
+
netFundingUnrealized: toBigDecimal(event.net_funding_unrealized),
|
|
157
|
+
netInterestCumulative: toBigDecimal(event.net_interest_cumulative),
|
|
158
|
+
netInterestUnrealized: toBigDecimal(event.net_interest_unrealized),
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function mapIndexerEventWithTx(
|
|
164
|
+
event: IndexerServerEvent,
|
|
165
|
+
tx: IndexerServerTx,
|
|
166
|
+
): IndexerEventWithTx {
|
|
167
|
+
return {
|
|
168
|
+
timestamp: toBigDecimal(tx.timestamp),
|
|
169
|
+
tx: tx.tx,
|
|
170
|
+
...mapIndexerEvent(event),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function mapIndexerMatchEventBalances(
|
|
175
|
+
eventBalances: IndexerServerMatchEventBalances,
|
|
176
|
+
): IndexerMatchEventBalances {
|
|
177
|
+
return {
|
|
178
|
+
base: mapIndexerServerBalance(eventBalances.base),
|
|
179
|
+
quote: eventBalances.quote
|
|
180
|
+
? (mapIndexerServerBalance(eventBalances.quote) as IndexerSpotBalance)
|
|
181
|
+
: undefined,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function mapIndexerProductPayment(
|
|
186
|
+
payment: IndexerServerProductPayment,
|
|
187
|
+
): IndexerProductPayment {
|
|
188
|
+
return {
|
|
189
|
+
submissionIndex: payment.idx,
|
|
190
|
+
timestamp: toBigDecimal(payment.timestamp),
|
|
191
|
+
paymentAmount: toBigDecimal(payment.amount),
|
|
192
|
+
balanceAmount: toBigDecimal(payment.balance_amount),
|
|
193
|
+
annualPaymentRate: removeDecimals(payment.rate_x18),
|
|
194
|
+
oraclePrice: removeDecimals(payment.oracle_price_x18),
|
|
195
|
+
isolated: payment.isolated,
|
|
196
|
+
productId: payment.product_id,
|
|
197
|
+
isolatedProductId: payment.isolated_product_id,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function mapIndexerPerpPrices(
|
|
202
|
+
perpPrices: IndexerServerPerpPrices,
|
|
203
|
+
): IndexerPerpPrices {
|
|
204
|
+
return {
|
|
205
|
+
indexPrice: removeDecimals(perpPrices.index_price_x18),
|
|
206
|
+
markPrice: removeDecimals(perpPrices.mark_price_x18),
|
|
207
|
+
updateTime: toBigDecimal(perpPrices.update_time),
|
|
208
|
+
productId: perpPrices.product_id,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function mapIndexerFundingRate(
|
|
213
|
+
fundingRate: IndexerServerFundingRate,
|
|
214
|
+
): IndexerFundingRate {
|
|
215
|
+
return {
|
|
216
|
+
fundingRate: removeDecimals(fundingRate.funding_rate_x18),
|
|
217
|
+
updateTime: toBigDecimal(fundingRate.update_time),
|
|
218
|
+
productId: fundingRate.product_id,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function mapIndexerMakerStatistics(
|
|
223
|
+
maker: IndexerServerMaker,
|
|
224
|
+
): IndexerMaker {
|
|
225
|
+
return {
|
|
226
|
+
address: maker.address,
|
|
227
|
+
snapshots: maker.data.map((makerData) => {
|
|
228
|
+
return {
|
|
229
|
+
timestamp: toBigDecimal(makerData.timestamp),
|
|
230
|
+
makerFee: toBigDecimal(makerData.maker_fee),
|
|
231
|
+
uptime: toBigDecimal(makerData.uptime),
|
|
232
|
+
sumQMin: toBigDecimal(makerData.sum_q_min),
|
|
233
|
+
qScore: toBigDecimal(makerData.q_score),
|
|
234
|
+
makerShare: toBigDecimal(makerData.maker_share),
|
|
235
|
+
expectedMakerReward: toBigDecimal(makerData.expected_maker_reward),
|
|
236
|
+
};
|
|
237
|
+
}),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function mapIndexerLeaderboardPosition(
|
|
242
|
+
position: IndexerServerLeaderboardPosition,
|
|
243
|
+
): IndexerLeaderboardParticipant {
|
|
244
|
+
return {
|
|
245
|
+
subaccount: subaccountFromHex(position.subaccount),
|
|
246
|
+
contestId: position.contest_id,
|
|
247
|
+
pnl: toBigDecimal(position.pnl),
|
|
248
|
+
pnlRank: toBigDecimal(position.pnl_rank),
|
|
249
|
+
percentRoi: toBigDecimal(position.roi),
|
|
250
|
+
roiRank: toBigDecimal(position.roi_rank),
|
|
251
|
+
accountValue: toBigDecimal(position.account_value),
|
|
252
|
+
volume: position.volume ? toBigDecimal(position.volume) : undefined,
|
|
253
|
+
updateTime: toBigDecimal(position.update_time),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function mapIndexerLeaderboardRegistration(
|
|
258
|
+
registration: IndexerServerLeaderboardRegistration,
|
|
259
|
+
): IndexerLeaderboardRegistration {
|
|
260
|
+
return {
|
|
261
|
+
subaccount: subaccountFromHex(registration.subaccount),
|
|
262
|
+
contestId: registration.contest_id,
|
|
263
|
+
updateTime: toBigDecimal(registration.update_time),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function mapIndexerLeaderboardContest(
|
|
268
|
+
contest: IndexerServerLeaderboardContest,
|
|
269
|
+
): IndexerLeaderboardContest {
|
|
270
|
+
return {
|
|
271
|
+
contestId: contest.contest_id,
|
|
272
|
+
startTime: toBigDecimal(contest.start_time),
|
|
273
|
+
endTime: toBigDecimal(contest.end_time),
|
|
274
|
+
period: toBigDecimal(contest.threshold),
|
|
275
|
+
totalParticipants: toBigDecimal(contest.count),
|
|
276
|
+
minRequiredAccountValue: toBigDecimal(contest.threshold),
|
|
277
|
+
minRequiredVolume: toBigDecimal(contest.volume_threshold),
|
|
278
|
+
requiredProductIds: contest.product_ids,
|
|
279
|
+
active: contest.active,
|
|
280
|
+
lastUpdated: toBigDecimal(contest.last_updated),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function mapIndexerCandlesticks(
|
|
285
|
+
candlestick: IndexerServerCandlestick,
|
|
286
|
+
): Candlestick {
|
|
287
|
+
return {
|
|
288
|
+
close: removeDecimals(candlestick.close_x18),
|
|
289
|
+
high: removeDecimals(candlestick.high_x18),
|
|
290
|
+
low: removeDecimals(candlestick.low_x18),
|
|
291
|
+
open: removeDecimals(candlestick.open_x18),
|
|
292
|
+
time: toBigDecimal(candlestick.timestamp),
|
|
293
|
+
volume: toBigDecimal(candlestick.volume),
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function mapIndexerMarketSnapshot(
|
|
298
|
+
snapshot: IndexerServerMarketSnapshot,
|
|
299
|
+
): IndexerMarketSnapshot {
|
|
300
|
+
return {
|
|
301
|
+
timestamp: toBigDecimal(snapshot.timestamp),
|
|
302
|
+
cumulativeUsers: toBigDecimal(snapshot.cumulative_users),
|
|
303
|
+
dailyActiveUsers: toBigDecimal(snapshot.daily_active_users),
|
|
304
|
+
tvl: toBigDecimal(snapshot.tvl),
|
|
305
|
+
borrowRates: mapValues(snapshot.borrow_rates, (value) =>
|
|
306
|
+
removeDecimals(value),
|
|
307
|
+
),
|
|
308
|
+
cumulativeLiquidationAmounts: mapValues(
|
|
309
|
+
snapshot.cumulative_liquidation_amounts,
|
|
310
|
+
toBigDecimal,
|
|
311
|
+
),
|
|
312
|
+
cumulativeMakerFees: mapValues(
|
|
313
|
+
snapshot.cumulative_maker_fees,
|
|
314
|
+
toBigDecimal,
|
|
315
|
+
),
|
|
316
|
+
cumulativeSequencerFees: mapValues(
|
|
317
|
+
snapshot.cumulative_sequencer_fees,
|
|
318
|
+
toBigDecimal,
|
|
319
|
+
),
|
|
320
|
+
cumulativeTakerFees: mapValues(
|
|
321
|
+
snapshot.cumulative_taker_fees,
|
|
322
|
+
toBigDecimal,
|
|
323
|
+
),
|
|
324
|
+
cumulativeTrades: mapValues(snapshot.cumulative_trades, toBigDecimal),
|
|
325
|
+
cumulativeVolumes: mapValues(snapshot.cumulative_volumes, toBigDecimal),
|
|
326
|
+
depositRates: mapValues(snapshot.deposit_rates, (value) =>
|
|
327
|
+
removeDecimals(value),
|
|
328
|
+
),
|
|
329
|
+
fundingRates: mapValues(snapshot.funding_rates, (value) =>
|
|
330
|
+
removeDecimals(value),
|
|
331
|
+
),
|
|
332
|
+
openInterestsQuote: mapValues(snapshot.open_interests, toBigDecimal),
|
|
333
|
+
totalBorrows: mapValues(snapshot.total_borrows, toBigDecimal),
|
|
334
|
+
totalDeposits: mapValues(snapshot.total_deposits, toBigDecimal),
|
|
335
|
+
cumulativeTradeSizes: mapValues(
|
|
336
|
+
snapshot.cumulative_trade_sizes,
|
|
337
|
+
toBigDecimal,
|
|
338
|
+
),
|
|
339
|
+
cumulativeInflows: mapValues(snapshot.cumulative_inflows, toBigDecimal),
|
|
340
|
+
cumulativeOutflows: mapValues(snapshot.cumulative_outflows, toBigDecimal),
|
|
341
|
+
oraclePrices: mapValues(snapshot.oracle_prices, (value) =>
|
|
342
|
+
removeDecimals(value),
|
|
343
|
+
),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function mapIndexerVlpSnapshot(
|
|
348
|
+
snapshot: IndexerServerVlpSnapshot,
|
|
349
|
+
): IndexerVlpSnapshot {
|
|
350
|
+
return {
|
|
351
|
+
submissionIndex: snapshot.submission_idx,
|
|
352
|
+
timestamp: toBigDecimal(snapshot.timestamp),
|
|
353
|
+
cumulativeBurnAmountUsdc: toBigDecimal(snapshot.cumulative_burn_usdc),
|
|
354
|
+
cumulativeMintAmountUsdc: toBigDecimal(snapshot.cumulative_mint_usdc),
|
|
355
|
+
cumulativePnl: toBigDecimal(snapshot.cumulative_pnl),
|
|
356
|
+
cumulativeTrades: toBigDecimal(snapshot.cumulative_trades),
|
|
357
|
+
cumulativeVolume: toBigDecimal(snapshot.cumulative_volume),
|
|
358
|
+
depositors: toBigDecimal(snapshot.depositors),
|
|
359
|
+
oraclePrice: removeDecimals(snapshot.oracle_price_x18),
|
|
360
|
+
tvl: toBigDecimal(snapshot.tvl),
|
|
361
|
+
};
|
|
362
|
+
}
|
package/src/endpoints.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ChainEnv } from '@nadohq/contracts';
|
|
2
|
+
|
|
3
|
+
export const INDEXER_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
|
|
4
|
+
local: 'http://localhost:8000/indexer',
|
|
5
|
+
arbitrumTestnet: 'https://archive.sepolia-test.vertexprotocol.com/v1',
|
|
6
|
+
arbitrum: 'https://archive.prod.vertexprotocol.com/v1',
|
|
7
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface NadoMatchOrdersTx {
|
|
2
|
+
match_orders: {
|
|
3
|
+
product_id: number;
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface NadoMatchOrdersRfqTx {
|
|
8
|
+
match_orders_r_f_q: {
|
|
9
|
+
product_id: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface NadoLiquidateSubaccountTx {
|
|
14
|
+
liquidate_subaccount: {
|
|
15
|
+
sender: string;
|
|
16
|
+
liquidatee: string;
|
|
17
|
+
mode: number;
|
|
18
|
+
// On V2 - should encode health group
|
|
19
|
+
product_id: number | undefined;
|
|
20
|
+
// On V1
|
|
21
|
+
health_group: number | undefined;
|
|
22
|
+
amount: string;
|
|
23
|
+
nonce: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface NadoWithdrawCollateralTx {
|
|
28
|
+
withdraw_collateral: {
|
|
29
|
+
sender: string;
|
|
30
|
+
product_id: number;
|
|
31
|
+
amount: string;
|
|
32
|
+
nonce: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface NadoDepositCollateralTx {
|
|
37
|
+
deposit_collateral: {
|
|
38
|
+
sender: string;
|
|
39
|
+
product_id: number;
|
|
40
|
+
amount: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface NadoTransferQuoteTx {
|
|
45
|
+
transfer_quote: {
|
|
46
|
+
sender: string;
|
|
47
|
+
recipient: string;
|
|
48
|
+
amount: string;
|
|
49
|
+
nonce: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type NadoTx =
|
|
54
|
+
| NadoMatchOrdersTx
|
|
55
|
+
| NadoMatchOrdersRfqTx
|
|
56
|
+
| NadoLiquidateSubaccountTx
|
|
57
|
+
| NadoDepositCollateralTx
|
|
58
|
+
| NadoTransferQuoteTx
|
|
59
|
+
| NadoWithdrawCollateralTx
|
|
60
|
+
| {
|
|
61
|
+
// TODO: Populate all types
|
|
62
|
+
[key: string]: never;
|
|
63
|
+
};
|