@1stdex/first-sdk 1.0.35 → 1.0.37

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.
@@ -0,0 +1,277 @@
1
+ import { createPublicClient, formatUnits, getAddress, http, isAddressEqual, parseEventLogs, } from 'viem';
2
+ import { BOOK_MANAGER_ABI } from '../../constants/abis/core/book-manager-abi';
3
+ import { CHAIN_MAP } from '../../constants/chain-configs/chain';
4
+ import { Subgraph } from '../../constants/chain-configs/subgraph';
5
+ import { formatPrice, invertTick, toPrice } from '../../utils';
6
+ import { getMarketId } from '../../entities/market/utils/market-id';
7
+ import { quoteToBase, baseToQuote } from '../../utils/conversion';
8
+ const fetchBookInfo = async (chainId, bookId) => {
9
+ const { data: { book }, } = await Subgraph.get(chainId, 'getBookForLimitOrderResult', 'query getBookForLimitOrderResult($bookId: ID!) { book(id: $bookId) { id unitSize base { id name symbol decimals } quote { id name symbol decimals } } }', {
10
+ bookId: bookId.toString(),
11
+ });
12
+ if (!book) {
13
+ throw new Error(`Book not found: ${bookId}`);
14
+ }
15
+ return book;
16
+ };
17
+ const toCurrency = (currencyDto) => ({
18
+ address: getAddress(currencyDto.id),
19
+ name: currencyDto.name,
20
+ symbol: currencyDto.symbol,
21
+ decimals: Number(currencyDto.decimals),
22
+ });
23
+ /**
24
+ * Get limit order result from transaction hash
25
+ * @param chainId - chain id from {@link CHAIN_IDS}
26
+ * @param txHash - transaction hash of the limit order placement
27
+ * @param options {@link DefaultReadContractOptions} options.
28
+ * @returns Limit order result with make, taken, and spent flows
29
+ *
30
+ * @example
31
+ * import { getLimitOrderResult } from '@clober/v2-sdk'
32
+ *
33
+ * const result = await getLimitOrderResult({
34
+ * chainId: 421614,
35
+ * txHash: '0x...',
36
+ * })
37
+ */
38
+ export const getLimitOrderResult = async ({ chainId, txHash, options, }) => {
39
+ const publicClient = createPublicClient({
40
+ chain: CHAIN_MAP[chainId],
41
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
42
+ });
43
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
44
+ const logs = parseEventLogs({
45
+ abi: BOOK_MANAGER_ABI,
46
+ logs: receipt.logs,
47
+ });
48
+ const makeEvents = logs.filter((log) => log.eventName === 'Make');
49
+ const takeEvents = logs.filter((log) => log.eventName === 'Take');
50
+ if (makeEvents.length === 0 && takeEvents.length === 0) {
51
+ throw new Error('No Make or Take events found in transaction');
52
+ }
53
+ // Get unique bookIds and fetch book info
54
+ const bookIds = new Set([
55
+ ...makeEvents.map((e) => e.args.bookId),
56
+ ...takeEvents.map((e) => e.args.bookId),
57
+ ]);
58
+ const bookInfoMap = new Map();
59
+ await Promise.all(Array.from(bookIds).map(async (bookId) => {
60
+ const info = await fetchBookInfo(chainId, bookId);
61
+ bookInfoMap.set(bookId, info);
62
+ }));
63
+ // Process Make events (if any)
64
+ let makeCurrency = null;
65
+ let makeAmount = '0';
66
+ let makePrice = '0';
67
+ let makeBookBase = null;
68
+ let makeBookQuote = null;
69
+ let isMakeBidBook = false;
70
+ if (makeEvents.length > 0) {
71
+ const makeBookId = makeEvents[0].args.bookId;
72
+ const makeBookInfo = bookInfoMap.get(makeBookId);
73
+ makeBookBase = toCurrency(makeBookInfo.base);
74
+ makeBookQuote = toCurrency(makeBookInfo.quote);
75
+ const makeUnitSize = BigInt(makeBookInfo.unitSize);
76
+ // Determine if Make book is bid or ask
77
+ const { quoteTokenAddress: marketQuoteAddress } = getMarketId(chainId, [
78
+ makeBookBase.address,
79
+ makeBookQuote.address,
80
+ ]);
81
+ isMakeBidBook = isAddressEqual(makeBookQuote.address, marketQuoteAddress);
82
+ // Calculate total make amount
83
+ const totalMakeUnits = makeEvents.reduce((sum, e) => sum + e.args.unit, 0n);
84
+ const totalMakeAmount = totalMakeUnits * makeUnitSize;
85
+ // Get make tick (should be same for all Make events in same transaction)
86
+ const makeTick = BigInt(makeEvents[0].args.tick);
87
+ // Calculate make currency and amount
88
+ makeCurrency = isMakeBidBook ? makeBookQuote : makeBookBase;
89
+ makeAmount = formatUnits(totalMakeAmount, makeCurrency.decimals);
90
+ // Calculate make price
91
+ const rawPrice = isMakeBidBook
92
+ ? toPrice(makeTick)
93
+ : toPrice(invertTick(makeTick));
94
+ makePrice = formatPrice(rawPrice, makeBookQuote.decimals, makeBookBase.decimals);
95
+ }
96
+ // Process Take events (if any)
97
+ const takeEventsWithInfo = takeEvents.map((e) => {
98
+ const bookInfo = bookInfoMap.get(e.args.bookId);
99
+ const base = toCurrency(bookInfo.base);
100
+ const quote = toCurrency(bookInfo.quote);
101
+ const unitSize = BigInt(bookInfo.unitSize);
102
+ // Determine if Take book is bid or ask
103
+ const { quoteTokenAddress: marketQuoteAddress } = getMarketId(chainId, [
104
+ base.address,
105
+ quote.address,
106
+ ]);
107
+ const isTakeBidBook = isAddressEqual(quote.address, marketQuoteAddress);
108
+ const tick = BigInt(e.args.tick);
109
+ const units = e.args.unit;
110
+ const rawAmount = units * unitSize;
111
+ // Calculate price
112
+ const rawPrice = isTakeBidBook ? toPrice(tick) : toPrice(invertTick(tick));
113
+ const price = formatPrice(rawPrice, quote.decimals, base.decimals);
114
+ // Calculate taken and spent amounts
115
+ let takenAmount;
116
+ let spentAmount;
117
+ let takenCurrency;
118
+ let spentCurrency;
119
+ if (isTakeBidBook) {
120
+ // Bid book: taking means receiving base, spending quote
121
+ takenAmount = quoteToBase(tick, rawAmount, false);
122
+ spentAmount = rawAmount;
123
+ takenCurrency = base;
124
+ spentCurrency = quote;
125
+ }
126
+ else {
127
+ // Ask book: taking means receiving quote, spending base
128
+ takenAmount = rawAmount;
129
+ spentAmount = baseToQuote(invertTick(tick), rawAmount, false);
130
+ takenCurrency = quote;
131
+ spentCurrency = base;
132
+ }
133
+ return {
134
+ price,
135
+ takenAmount: formatUnits(takenAmount, takenCurrency.decimals),
136
+ spentAmount: formatUnits(spentAmount, spentCurrency.decimals),
137
+ takenCurrency,
138
+ spentCurrency,
139
+ };
140
+ });
141
+ // Group by currency and calculate totals
142
+ const takenEventsMap = new Map();
143
+ const spentEventsMap = new Map();
144
+ takeEventsWithInfo.forEach((event) => {
145
+ const takenKey = event.takenCurrency.address;
146
+ const spentKey = event.spentCurrency.address;
147
+ if (!takenEventsMap.has(takenKey)) {
148
+ takenEventsMap.set(takenKey, []);
149
+ }
150
+ if (!spentEventsMap.has(spentKey)) {
151
+ spentEventsMap.set(spentKey, []);
152
+ }
153
+ takenEventsMap.get(takenKey).push({
154
+ price: event.price,
155
+ amount: event.takenAmount,
156
+ });
157
+ spentEventsMap.get(spentKey).push({
158
+ price: event.price,
159
+ amount: event.spentAmount,
160
+ });
161
+ });
162
+ // Calculate totals and averages
163
+ const calculateTotalAndAverage = (events) => {
164
+ if (events.length === 0) {
165
+ return { total: '0', averagePrice: '0' };
166
+ }
167
+ const total = events.reduce((sum, e) => sum + Number(e.amount), 0);
168
+ const totalWeightedPrice = events.reduce((sum, e) => sum + Number(e.price) * Number(e.amount), 0);
169
+ const averagePrice = total === 0 ? '0' : (totalWeightedPrice / total).toString();
170
+ return { total: total.toString(), averagePrice };
171
+ };
172
+ // Determine taken and spent currencies
173
+ let takenCurrency;
174
+ let spentCurrency;
175
+ let takenEvents = [];
176
+ let spentEvents = [];
177
+ if (makeEvents.length > 0 && makeCurrency && makeBookBase && makeBookQuote) {
178
+ // We have Make events, so we know the expected currencies
179
+ // For a limit order:
180
+ // - make.currency = inputCurrency (what's being placed in the order)
181
+ // - spent.currency = inputCurrency (what was spent immediately)
182
+ // - taken.currency = outputCurrency (what was received immediately)
183
+ //
184
+ // If Make is bid: spending quote, making base order -> spent=quote, taken=base
185
+ // If Make is ask: spending base, making quote order -> spent=base, taken=quote
186
+ const expectedSpentCurrency = makeCurrency; // Same as make currency
187
+ const expectedTakenCurrency = isMakeBidBook ? makeBookBase : makeBookQuote; // Opposite of make currency
188
+ // Find matching currencies from Take events
189
+ takenCurrency = expectedTakenCurrency;
190
+ spentCurrency = expectedSpentCurrency;
191
+ // Try to find events matching expected currencies
192
+ for (const [currencyKey, events] of takenEventsMap.entries()) {
193
+ const currency = takeEventsWithInfo.find((e) => e.takenCurrency.address === currencyKey).takenCurrency;
194
+ if (isAddressEqual(currency.address, expectedTakenCurrency.address)) {
195
+ takenCurrency = currency;
196
+ takenEvents = events;
197
+ break;
198
+ }
199
+ }
200
+ for (const [currencyKey, events] of spentEventsMap.entries()) {
201
+ const currency = takeEventsWithInfo.find((e) => e.spentCurrency.address === currencyKey).spentCurrency;
202
+ if (isAddressEqual(currency.address, expectedSpentCurrency.address)) {
203
+ spentCurrency = currency;
204
+ spentEvents = events;
205
+ break;
206
+ }
207
+ }
208
+ // Fallback: use first currency if not found
209
+ if (takenEvents.length === 0 && takenEventsMap.size > 0) {
210
+ const firstKey = Array.from(takenEventsMap.keys())[0];
211
+ takenCurrency = takeEventsWithInfo.find((e) => e.takenCurrency.address === firstKey).takenCurrency;
212
+ takenEvents = takenEventsMap.get(firstKey);
213
+ }
214
+ if (spentEvents.length === 0 && spentEventsMap.size > 0) {
215
+ const firstKey = Array.from(spentEventsMap.keys())[0];
216
+ spentCurrency = takeEventsWithInfo.find((e) => e.spentCurrency.address === firstKey).spentCurrency;
217
+ spentEvents = spentEventsMap.get(firstKey);
218
+ }
219
+ }
220
+ else if (takeEvents.length > 0) {
221
+ // No Make events, but we have Take events - use currencies from Take events
222
+ // Use the most common currencies from Take events
223
+ if (takenEventsMap.size > 0) {
224
+ const firstKey = Array.from(takenEventsMap.keys())[0];
225
+ takenCurrency = takeEventsWithInfo.find((e) => e.takenCurrency.address === firstKey).takenCurrency;
226
+ takenEvents = takenEventsMap.get(firstKey);
227
+ }
228
+ else {
229
+ // Fallback: use first Take event currency
230
+ takenCurrency = takeEventsWithInfo[0].takenCurrency;
231
+ }
232
+ if (spentEventsMap.size > 0) {
233
+ const firstKey = Array.from(spentEventsMap.keys())[0];
234
+ spentCurrency = takeEventsWithInfo.find((e) => e.spentCurrency.address === firstKey).spentCurrency;
235
+ spentEvents = spentEventsMap.get(firstKey);
236
+ }
237
+ else {
238
+ // Fallback: use first Take event currency
239
+ spentCurrency = takeEventsWithInfo[0].spentCurrency;
240
+ }
241
+ }
242
+ else {
243
+ // No events at all (shouldn't happen due to earlier check, but handle it)
244
+ throw new Error('No Make or Take events found in transaction');
245
+ }
246
+ const { total: takenTotal, averagePrice: takenAveragePrice } = calculateTotalAndAverage(takenEvents);
247
+ const { total: spentTotal, averagePrice: spentAveragePrice } = calculateTotalAndAverage(spentEvents);
248
+ // If no Make events, we need to provide a default currency for make
249
+ // Use spent currency as fallback since make and spent are typically the same currency
250
+ const defaultMakeCurrency = makeCurrency || spentCurrency || takeEventsWithInfo[0]?.spentCurrency;
251
+ if (!defaultMakeCurrency) {
252
+ throw new Error('Unable to determine currencies from transaction events');
253
+ }
254
+ return {
255
+ make: {
256
+ currency: makeCurrency || defaultMakeCurrency,
257
+ amount: makeAmount,
258
+ direction: 'in',
259
+ price: makePrice,
260
+ },
261
+ taken: {
262
+ currency: takenCurrency,
263
+ amount: takenTotal,
264
+ direction: 'out',
265
+ events: takenEvents,
266
+ averagePrice: takenAveragePrice,
267
+ },
268
+ spent: {
269
+ currency: spentCurrency,
270
+ amount: spentTotal,
271
+ direction: 'in',
272
+ events: spentEvents,
273
+ averagePrice: spentAveragePrice,
274
+ },
275
+ };
276
+ };
277
+ //# sourceMappingURL=limit-order-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limit-order-result.js","sourceRoot":"","sources":["../../../../src/views/market/limit-order-result.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,IAAI,EACJ,cAAc,EACd,cAAc,GACf,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAa,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAGlE,OAAO,EAAE,WAAW,EAA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