@across-protocol/sdk 4.1.46-beta.4 → 4.1.47-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +15 -11
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +52 -6
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +48 -20
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +8 -6
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +3 -0
- package/dist/cjs/clients/HubPoolClient.js +16 -6
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js +2 -2
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +3 -0
- package/dist/cjs/clients/mocks/MockHubPoolClient.js +7 -0
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +5 -5
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/interfaces/Common.d.ts +2 -2
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -0
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +5 -0
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -0
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/EventUtils.d.ts +2 -1
- package/dist/cjs/utils/EventUtils.js +21 -12
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.js +0 -2
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +15 -11
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +58 -7
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +48 -20
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +5 -3
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +10 -0
- package/dist/esm/clients/HubPoolClient.js +24 -7
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockConfigStoreClient.js +3 -3
- package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +3 -0
- package/dist/esm/clients/mocks/MockHubPoolClient.js +7 -0
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +5 -5
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/interfaces/Common.d.ts +2 -2
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -0
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +10 -0
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +1 -0
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/EventUtils.d.ts +2 -1
- package/dist/esm/utils/EventUtils.js +18 -10
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.js +0 -2
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +48 -20
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +10 -0
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts +3 -0
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
- package/dist/types/interfaces/Common.d.ts +2 -2
- package/dist/types/interfaces/Common.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -0
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +1 -0
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/EventUtils.d.ts +2 -1
- package/dist/types/utils/EventUtils.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +17 -15
- package/src/clients/BundleDataClient/BundleDataClient.ts +107 -5
- package/src/clients/BundleDataClient/utils/FillUtils.ts +1 -3
- package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +7 -3
- package/src/clients/HubPoolClient.ts +30 -10
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +2 -1
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +1 -1
- package/src/clients/mocks/MockConfigStoreClient.ts +10 -3
- package/src/clients/mocks/MockHubPoolClient.ts +9 -0
- package/src/clients/mocks/MockSpokePoolClient.ts +5 -5
- package/src/interfaces/Common.ts +2 -2
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +10 -0
- package/src/relayFeeCalculator/relayFeeCalculator.ts +1 -0
- package/src/utils/EventUtils.ts +19 -13
- package/src/utils/TokenUtils.ts +0 -2
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
DisabledChainsUpdate,
|
|
25
25
|
GlobalConfigUpdate,
|
|
26
26
|
LiteChainsIdListUpdate,
|
|
27
|
-
Log,
|
|
28
27
|
ParsedTokenConfig,
|
|
29
28
|
RateModelUpdate,
|
|
30
29
|
RouteRateModelUpdate,
|
|
@@ -43,8 +42,8 @@ type ConfigStoreUpdateSuccess = {
|
|
|
43
42
|
chainId: number;
|
|
44
43
|
searchEndBlock: number;
|
|
45
44
|
events: {
|
|
46
|
-
updatedTokenConfigEvents:
|
|
47
|
-
updatedGlobalConfigEvents:
|
|
45
|
+
updatedTokenConfigEvents: SortableEvent[];
|
|
46
|
+
updatedGlobalConfigEvents: SortableEvent[];
|
|
48
47
|
globalConfigUpdateTimes: number[];
|
|
49
48
|
};
|
|
50
49
|
};
|
|
@@ -341,8 +340,13 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
341
340
|
paginatedEventQuery(this.configStore, this.configStore.filters.UpdatedGlobalConfig(), searchConfig),
|
|
342
341
|
]);
|
|
343
342
|
|
|
343
|
+
const updatedTokenConfigSortableEvents = updatedTokenConfigEvents.map(spreadEventWithBlockNumber);
|
|
344
|
+
const updatedGlobalConfigSortableEvents = updatedGlobalConfigEvents.map(spreadEventWithBlockNumber);
|
|
345
|
+
|
|
344
346
|
// Events *should* normally be received in ascending order, but explicitly enforce the ordering.
|
|
345
|
-
[
|
|
347
|
+
[updatedTokenConfigSortableEvents, updatedGlobalConfigSortableEvents].forEach((events) =>
|
|
348
|
+
sortEventsAscendingInPlace(events)
|
|
349
|
+
);
|
|
346
350
|
|
|
347
351
|
const globalConfigUpdateTimes = (
|
|
348
352
|
await Promise.all(updatedGlobalConfigEvents.map((event) => this.configStore.provider.getBlock(event.blockNumber)))
|
|
@@ -353,8 +357,8 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
353
357
|
chainId,
|
|
354
358
|
searchEndBlock: searchConfig.toBlock,
|
|
355
359
|
events: {
|
|
356
|
-
updatedTokenConfigEvents,
|
|
357
|
-
updatedGlobalConfigEvents,
|
|
360
|
+
updatedTokenConfigEvents: updatedTokenConfigSortableEvents,
|
|
361
|
+
updatedGlobalConfigEvents: updatedGlobalConfigSortableEvents,
|
|
358
362
|
globalConfigUpdateTimes,
|
|
359
363
|
},
|
|
360
364
|
};
|
|
@@ -380,13 +384,11 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
380
384
|
// Save new TokenConfig updates.
|
|
381
385
|
for (const event of updatedTokenConfigEvents) {
|
|
382
386
|
// If transaction hash is known to be invalid, skip it immediately to avoid creating extra logs.
|
|
383
|
-
if (KNOWN_INVALID_TOKEN_CONFIG_UPDATE_HASHES.includes(event.
|
|
387
|
+
if (KNOWN_INVALID_TOKEN_CONFIG_UPDATE_HASHES.includes(event.txnRef.toLowerCase())) {
|
|
384
388
|
continue;
|
|
385
389
|
}
|
|
386
390
|
|
|
387
|
-
const args =
|
|
388
|
-
...(spreadEventWithBlockNumber(event) as TokenConfig),
|
|
389
|
-
};
|
|
391
|
+
const args = event as TokenConfig;
|
|
390
392
|
|
|
391
393
|
try {
|
|
392
394
|
const { rateModel, routeRateModel, spokeTargetBalances } = this.validateTokenConfigUpdate(args);
|
|
@@ -418,7 +420,7 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
418
420
|
this.logger.debug({
|
|
419
421
|
at: "ConfigStoreClient::update",
|
|
420
422
|
message: `Skipping invalid historical update at block ${event.blockNumber}`,
|
|
421
|
-
|
|
423
|
+
txnRef: event.txnRef,
|
|
422
424
|
});
|
|
423
425
|
}
|
|
424
426
|
continue;
|
|
@@ -427,7 +429,7 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
427
429
|
|
|
428
430
|
// Save new Global config updates.
|
|
429
431
|
for (let i = 0; i < updatedGlobalConfigEvents.length; i++) {
|
|
430
|
-
const args =
|
|
432
|
+
const args = updatedGlobalConfigEvents[i] as SortableEvent & {
|
|
431
433
|
key: string;
|
|
432
434
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
433
435
|
value: any;
|
|
@@ -562,7 +564,7 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
562
564
|
rateModel: string | undefined;
|
|
563
565
|
routeRateModel: RouteRateModelUpdate["routeRateModel"];
|
|
564
566
|
} {
|
|
565
|
-
const { value, key,
|
|
567
|
+
const { value, key, txnRef } = args;
|
|
566
568
|
const parsedValue = parseJSONWithNumericString(value) as ParsedTokenConfig;
|
|
567
569
|
const l1Token = key;
|
|
568
570
|
|
|
@@ -578,7 +580,7 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
578
580
|
const rateModel = parsedValue.rateModel;
|
|
579
581
|
assert(
|
|
580
582
|
this.isValidRateModel(rateModel),
|
|
581
|
-
`Invalid rateModel UBar for ${l1Token} at transaction ${
|
|
583
|
+
`Invalid rateModel UBar for ${l1Token} at transaction ${txnRef}, ${JSON.stringify(rateModel)}`
|
|
582
584
|
);
|
|
583
585
|
rateModelForToken = JSON.stringify(rateModel);
|
|
584
586
|
|
|
@@ -601,7 +603,7 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
601
603
|
Object.entries(parsedValue.routeRateModel).map(([path, routeRateModel]) => {
|
|
602
604
|
assert(
|
|
603
605
|
this.isValidRateModel(routeRateModel) &&
|
|
604
|
-
`Invalid routeRateModel UBar for ${path} for ${l1Token} at transaction ${
|
|
606
|
+
`Invalid routeRateModel UBar for ${path} for ${l1Token} at transaction ${txnRef}, ${JSON.stringify(
|
|
605
607
|
routeRateModel
|
|
606
608
|
)}`
|
|
607
609
|
);
|
|
@@ -237,13 +237,115 @@ export class BundleDataClient {
|
|
|
237
237
|
{} as Record<number, Record<string, UnderlyingType>>
|
|
238
238
|
);
|
|
239
239
|
|
|
240
|
+
const convertSortableEventFieldsIntoRequiredFields = <
|
|
241
|
+
T extends {
|
|
242
|
+
txnIndex?: number;
|
|
243
|
+
transactionIndex?: number;
|
|
244
|
+
txnRef?: string;
|
|
245
|
+
transactionHash?: string;
|
|
246
|
+
},
|
|
247
|
+
>(
|
|
248
|
+
data: T[]
|
|
249
|
+
): Array<
|
|
250
|
+
Omit<T, "txnIndex" | "transactionIndex" | "txnRef" | "transactionHash"> & {
|
|
251
|
+
txnIndex: number;
|
|
252
|
+
txnRef: string;
|
|
253
|
+
}
|
|
254
|
+
> => {
|
|
255
|
+
return data.map((item) => {
|
|
256
|
+
// For txnIndex/transactionIndex: throw if both are defined or both are missing.
|
|
257
|
+
if (
|
|
258
|
+
(item.txnIndex !== undefined && item.transactionIndex !== undefined) ||
|
|
259
|
+
(item.txnIndex === undefined && item.transactionIndex === undefined)
|
|
260
|
+
) {
|
|
261
|
+
throw new Error("Either txnIndex or transactionIndex must be defined, but not both.");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// For txnRef/transactionHash: throw if both are defined or both are missing.
|
|
265
|
+
if (
|
|
266
|
+
(item.txnRef !== undefined && item.transactionHash !== undefined) ||
|
|
267
|
+
(item.txnRef === undefined && item.transactionHash === undefined)
|
|
268
|
+
) {
|
|
269
|
+
throw new Error("Either txnRef or transactionHash must be defined, but not both.");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Destructure the fields we don't need anymore
|
|
273
|
+
const { txnIndex, transactionIndex, txnRef, transactionHash, ...rest } = item;
|
|
274
|
+
|
|
275
|
+
// Return a new object with normalized fields.
|
|
276
|
+
// The non-null assertion (!) is safe here because our conditions ensure that one of each pair is defined.
|
|
277
|
+
return {
|
|
278
|
+
...rest,
|
|
279
|
+
txnIndex: txnIndex ?? transactionIndex!,
|
|
280
|
+
txnRef: txnRef ?? transactionHash!,
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const convertEmbeddedSortableEventFieldsIntoRequiredFields = <
|
|
286
|
+
T extends {
|
|
287
|
+
txnIndex?: number;
|
|
288
|
+
transactionIndex?: number;
|
|
289
|
+
txnRef?: string;
|
|
290
|
+
transactionHash?: string;
|
|
291
|
+
},
|
|
292
|
+
>(
|
|
293
|
+
data: Record<string, Record<string, T[]>>
|
|
294
|
+
) => {
|
|
295
|
+
return Object.fromEntries(
|
|
296
|
+
Object.entries(data).map(([chainId, tokenData]) => [
|
|
297
|
+
chainId,
|
|
298
|
+
Object.fromEntries(
|
|
299
|
+
Object.entries(tokenData).map(([token, data]) => [
|
|
300
|
+
token,
|
|
301
|
+
convertSortableEventFieldsIntoRequiredFields(data),
|
|
302
|
+
])
|
|
303
|
+
),
|
|
304
|
+
])
|
|
305
|
+
);
|
|
306
|
+
};
|
|
307
|
+
|
|
240
308
|
const data = persistedData[0].data;
|
|
309
|
+
|
|
310
|
+
// This section processes and transforms bundle data loaded from Arweave storage into the correct format:
|
|
311
|
+
// 1. Each field (bundleFillsV3, expiredDepositsToRefundV3, etc.) contains nested records keyed by chainId and token
|
|
312
|
+
// 2. The chainId keys are converted from strings to numbers using convertTypedStringRecordIntoNumericRecord
|
|
313
|
+
// 3. For arrays of events (fills, deposits, etc.), the transaction fields are normalized:
|
|
314
|
+
// - txnIndex/transactionIndex -> txnIndex
|
|
315
|
+
// - txnRef/transactionHash -> txnRef
|
|
316
|
+
// This ensures consistent field names across all event objects
|
|
317
|
+
// 4. The data structure maintains all other fields like refunds, totalRefundAmount, and realizedLpFees
|
|
241
318
|
const bundleData = {
|
|
242
|
-
bundleFillsV3: convertTypedStringRecordIntoNumericRecord(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
319
|
+
bundleFillsV3: convertTypedStringRecordIntoNumericRecord(
|
|
320
|
+
Object.fromEntries(
|
|
321
|
+
Object.entries(data.bundleFillsV3).map(([chainId, tokenData]) => [
|
|
322
|
+
chainId,
|
|
323
|
+
Object.fromEntries(
|
|
324
|
+
Object.entries(tokenData).map(([token, data]) => [
|
|
325
|
+
token,
|
|
326
|
+
{
|
|
327
|
+
refunds: data.refunds,
|
|
328
|
+
totalRefundAmount: data.totalRefundAmount,
|
|
329
|
+
realizedLpFees: data.realizedLpFees,
|
|
330
|
+
fills: convertSortableEventFieldsIntoRequiredFields(data.fills),
|
|
331
|
+
},
|
|
332
|
+
])
|
|
333
|
+
),
|
|
334
|
+
])
|
|
335
|
+
)
|
|
336
|
+
),
|
|
337
|
+
expiredDepositsToRefundV3: convertTypedStringRecordIntoNumericRecord(
|
|
338
|
+
convertEmbeddedSortableEventFieldsIntoRequiredFields(data.expiredDepositsToRefundV3)
|
|
339
|
+
),
|
|
340
|
+
bundleDepositsV3: convertTypedStringRecordIntoNumericRecord(
|
|
341
|
+
convertEmbeddedSortableEventFieldsIntoRequiredFields(data.bundleDepositsV3)
|
|
342
|
+
),
|
|
343
|
+
unexecutableSlowFills: convertTypedStringRecordIntoNumericRecord(
|
|
344
|
+
convertEmbeddedSortableEventFieldsIntoRequiredFields(data.unexecutableSlowFills)
|
|
345
|
+
),
|
|
346
|
+
bundleSlowFillsV3: convertTypedStringRecordIntoNumericRecord(
|
|
347
|
+
convertEmbeddedSortableEventFieldsIntoRequiredFields(data.bundleSlowFillsV3)
|
|
348
|
+
),
|
|
247
349
|
};
|
|
248
350
|
this.logger.debug({
|
|
249
351
|
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
@@ -91,9 +91,7 @@ export async function verifyFillRepayment(
|
|
|
91
91
|
if (_repaymentAddressNeedsToBeOverwritten(fill)) {
|
|
92
92
|
// TODO: Handle case where fill was sent on non-EVM chain, in which case the following call would fail
|
|
93
93
|
// or return something unexpected. We'd want to return undefined here.
|
|
94
|
-
|
|
95
|
-
// @todo: If chainIsEvm:
|
|
96
|
-
const fillTransaction = await destinationChainProvider.getTransaction(fill.transactionHash);
|
|
94
|
+
const fillTransaction = await destinationChainProvider.getTransaction(fill.txnRef);
|
|
97
95
|
const destinationRelayer = fillTransaction?.from;
|
|
98
96
|
// Repayment chain is still an EVM chain, but the msg.sender is a bytes32 address, so the fill is invalid.
|
|
99
97
|
if (!isDefined(destinationRelayer) || !isValidEvmAddress(destinationRelayer)) {
|
|
@@ -48,11 +48,15 @@ const V3RelayDataSS = {
|
|
|
48
48
|
message: string(),
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
const SortableEventSS = {
|
|
51
|
+
export const SortableEventSS = {
|
|
52
52
|
blockNumber: number(),
|
|
53
|
-
transactionIndex: number(),
|
|
54
53
|
logIndex: number(),
|
|
55
|
-
|
|
54
|
+
|
|
55
|
+
txnRef: optional(string()),
|
|
56
|
+
txnIndex: optional(number()),
|
|
57
|
+
|
|
58
|
+
transactionHash: optional(string()),
|
|
59
|
+
transactionIndex: optional(number()),
|
|
56
60
|
};
|
|
57
61
|
|
|
58
62
|
const V3DepositSS = {
|
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
toBN,
|
|
44
44
|
getTokenInfo,
|
|
45
45
|
getUsdcSymbol,
|
|
46
|
+
getL1TokenInfo,
|
|
46
47
|
compareAddressesSimple,
|
|
47
48
|
chainIsSvm,
|
|
48
49
|
getDeployedAddress,
|
|
@@ -284,6 +285,17 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
284
285
|
return tokenInfo;
|
|
285
286
|
}
|
|
286
287
|
|
|
288
|
+
/**
|
|
289
|
+
* @dev If tokenAddress + chain do not exist in TOKEN_SYMBOLS_MAP then this will throw.
|
|
290
|
+
* @dev if the token matched in TOKEN_SYMBOLS_MAP does not have an L1 token address then this will throw.
|
|
291
|
+
* @param tokenAddress Token address on `chain`
|
|
292
|
+
* @param chain Chain where the `tokenAddress` exists in TOKEN_SYMBOLS_MAP.
|
|
293
|
+
* @returns Token info for the given token address on the Hub chain including symbol and decimal and L1 address.
|
|
294
|
+
*/
|
|
295
|
+
getL1TokenInfoForAddress(tokenAddress: string, chain: number): L1Token {
|
|
296
|
+
return getL1TokenInfo(tokenAddress, chain);
|
|
297
|
+
}
|
|
298
|
+
|
|
287
299
|
/**
|
|
288
300
|
* Resolve a given timestamp to a block number on the HubPool chain.
|
|
289
301
|
* @param timestamp A single timestamp to be resolved to a block number on the HubPool chain.
|
|
@@ -503,6 +515,17 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
503
515
|
return this.getTokenInfoForL1Token(l1TokenCounterpart);
|
|
504
516
|
}
|
|
505
517
|
|
|
518
|
+
getTokenInfoForDeposit(deposit: Pick<Deposit, "inputToken" | "originChainId">): L1Token | undefined {
|
|
519
|
+
return this.getTokenInfoForL1Token(
|
|
520
|
+
this.getL1TokenForL2TokenAtBlock(deposit.inputToken, deposit.originChainId, this.latestBlockSearched)
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
getTokenInfo(chainId: number | string, tokenAddress: string): L1Token | undefined {
|
|
525
|
+
const deposit = { originChainId: parseInt(chainId.toString()), inputToken: tokenAddress };
|
|
526
|
+
return this.getTokenInfoForDeposit(deposit);
|
|
527
|
+
}
|
|
528
|
+
|
|
506
529
|
areTokensEquivalent(
|
|
507
530
|
tokenA: string,
|
|
508
531
|
chainIdA: number,
|
|
@@ -884,11 +907,13 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
884
907
|
if (eventsToQuery.includes("CrossChainContractsSet")) {
|
|
885
908
|
for (const event of events["CrossChainContractsSet"]) {
|
|
886
909
|
const args = spreadEventWithBlockNumber(event) as CrossChainContractsSet;
|
|
887
|
-
const dataToAdd = {
|
|
910
|
+
const dataToAdd: CrossChainContractsSet = {
|
|
888
911
|
spokePool: args.spokePool,
|
|
889
912
|
blockNumber: args.blockNumber,
|
|
890
|
-
|
|
913
|
+
txnRef: args.txnRef,
|
|
891
914
|
logIndex: args.logIndex,
|
|
915
|
+
txnIndex: args.txnIndex,
|
|
916
|
+
l2ChainId: args.l2ChainId,
|
|
892
917
|
};
|
|
893
918
|
// If the chain is SVM then our `args.spokePool` will be set to the `solanaSpokePool.toAddressUnchecked()` in the
|
|
894
919
|
// hubpool event because our hub deals with `address` types and not byte32. Therefore, we should confirm that the
|
|
@@ -946,9 +971,9 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
946
971
|
l1Token: args.l1Token,
|
|
947
972
|
l2Token: destinationToken,
|
|
948
973
|
blockNumber: args.blockNumber,
|
|
949
|
-
|
|
974
|
+
txnIndex: args.txnIndex,
|
|
950
975
|
logIndex: args.logIndex,
|
|
951
|
-
|
|
976
|
+
txnRef: args.txnRef,
|
|
952
977
|
},
|
|
953
978
|
]
|
|
954
979
|
);
|
|
@@ -994,12 +1019,7 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
994
1019
|
this.proposedRootBundles.push(
|
|
995
1020
|
...events["ProposeRootBundle"]
|
|
996
1021
|
.filter((event) => !this.configOverride.ignoredHubProposedBundles.includes(event.blockNumber))
|
|
997
|
-
.map((event) =>
|
|
998
|
-
return {
|
|
999
|
-
...spreadEventWithBlockNumber(event),
|
|
1000
|
-
transactionHash: event.transactionHash,
|
|
1001
|
-
} as ProposedRootBundle;
|
|
1002
|
-
})
|
|
1022
|
+
.map((event) => spreadEventWithBlockNumber(event) as ProposedRootBundle)
|
|
1003
1023
|
);
|
|
1004
1024
|
}
|
|
1005
1025
|
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
} from "../../utils";
|
|
20
20
|
import {
|
|
21
21
|
EventSearchConfig,
|
|
22
|
+
logToSortableEvent,
|
|
22
23
|
paginatedEventQuery,
|
|
23
24
|
sortEventsAscendingInPlace,
|
|
24
25
|
spreadEventWithBlockNumber,
|
|
@@ -127,7 +128,7 @@ export class EVMSpokePoolClient extends SpokePoolClient {
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
// Sort all events to ensure they are stored in a consistent order.
|
|
130
|
-
events.forEach((events) => sortEventsAscendingInPlace(events));
|
|
131
|
+
events.forEach((events) => sortEventsAscendingInPlace(events.map(logToSortableEvent)));
|
|
131
132
|
|
|
132
133
|
return {
|
|
133
134
|
success: true,
|
|
@@ -401,7 +401,7 @@ export abstract class SpokePoolClient extends BaseAbstractClient {
|
|
|
401
401
|
|
|
402
402
|
// Log any invalid deposits with same deposit id but different params.
|
|
403
403
|
const invalidFillsForDeposit = invalidFills.filter((x) => {
|
|
404
|
-
const txnUid = `${x.
|
|
404
|
+
const txnUid = `${x.txnRef}:${x.logIndex}`;
|
|
405
405
|
// if txnUid doesn't exist in the invalidFills set, add it now, but log the corresponding fill.
|
|
406
406
|
const newInvalidFill = x.depositId.eq(deposit.depositId) && !this.invalidFills.has(txnUid);
|
|
407
407
|
if (newInvalidFill) {
|
|
@@ -2,7 +2,14 @@ import assert from "assert";
|
|
|
2
2
|
import winston from "winston";
|
|
3
3
|
import { Contract, ethers } from "ethers";
|
|
4
4
|
import { Log } from "../../interfaces";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getCurrentTime,
|
|
7
|
+
EventSearchConfig,
|
|
8
|
+
MakeOptional,
|
|
9
|
+
isDefined,
|
|
10
|
+
utf8ToHex,
|
|
11
|
+
spreadEventWithBlockNumber,
|
|
12
|
+
} from "../../utils";
|
|
6
13
|
import {
|
|
7
14
|
AcrossConfigStoreClient,
|
|
8
15
|
ConfigStoreUpdate,
|
|
@@ -92,9 +99,9 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient {
|
|
|
92
99
|
chainId: this.chainId as number,
|
|
93
100
|
searchEndBlock: this.eventSearchConfig.toBlock || latestBlockSearched,
|
|
94
101
|
events: {
|
|
95
|
-
updatedGlobalConfigEvents: events["UpdatedGlobalConfig"],
|
|
102
|
+
updatedGlobalConfigEvents: events["UpdatedGlobalConfig"].map(spreadEventWithBlockNumber),
|
|
96
103
|
globalConfigUpdateTimes,
|
|
97
|
-
updatedTokenConfigEvents: events["UpdatedTokenConfig"],
|
|
104
|
+
updatedTokenConfigEvents: events["UpdatedTokenConfig"].map(spreadEventWithBlockNumber),
|
|
98
105
|
},
|
|
99
106
|
});
|
|
100
107
|
}
|
|
@@ -23,6 +23,7 @@ export class MockHubPoolClient extends HubPoolClient {
|
|
|
23
23
|
private realizedLpFeePctOverride = false;
|
|
24
24
|
|
|
25
25
|
private l1TokensMock: L1Token[] = []; // L1Tokens and their associated info.
|
|
26
|
+
private tokenInfoToReturn: L1Token = { address: "", decimals: 0, symbol: "" };
|
|
26
27
|
|
|
27
28
|
private spokePoolTokens: { [l1Token: string]: { [chainId: number]: string } } = {};
|
|
28
29
|
|
|
@@ -90,6 +91,10 @@ export class MockHubPoolClient extends HubPoolClient {
|
|
|
90
91
|
return this.l1TokensMock;
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
getTokenInfoForDeposit() {
|
|
95
|
+
return this.tokenInfoToReturn;
|
|
96
|
+
}
|
|
97
|
+
|
|
93
98
|
setTokenMapping(l1Token: string, chainId: number, l2Token: string) {
|
|
94
99
|
this.spokePoolTokens[l1Token] ??= {};
|
|
95
100
|
this.spokePoolTokens[l1Token][chainId] = l2Token;
|
|
@@ -131,6 +136,10 @@ export class MockHubPoolClient extends HubPoolClient {
|
|
|
131
136
|
return this.l1TokensMock.find((token) => token.address === l1Token);
|
|
132
137
|
}
|
|
133
138
|
|
|
139
|
+
setTokenInfoToReturn(tokenInfo: L1Token) {
|
|
140
|
+
this.tokenInfoToReturn = tokenInfo;
|
|
141
|
+
}
|
|
142
|
+
|
|
134
143
|
_update(eventNames: string[]): Promise<HubPoolUpdate> {
|
|
135
144
|
// Generate new "on chain" responses.
|
|
136
145
|
const latestBlockSearched = this.eventManager.blockNumber;
|
|
@@ -129,7 +129,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
protected _deposit(event: string, deposit: Omit<Deposit, "messageHash"> & Partial<SortableEvent>): Log {
|
|
132
|
-
const { blockNumber,
|
|
132
|
+
const { blockNumber, txnIndex } = deposit;
|
|
133
133
|
let { depositId, destinationChainId, inputAmount, outputAmount } = deposit;
|
|
134
134
|
depositId ??= this.numberOfDeposits;
|
|
135
135
|
this.numberOfDeposits = depositId.add(bnOne);
|
|
@@ -171,7 +171,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
171
171
|
topics: topics.map((topic) => topic.toString()),
|
|
172
172
|
args,
|
|
173
173
|
blockNumber,
|
|
174
|
-
transactionIndex,
|
|
174
|
+
transactionIndex: txnIndex,
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
|
|
@@ -187,7 +187,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
187
187
|
event: string,
|
|
188
188
|
fill: Omit<Fill, "messageHash"> & { message: string } & Partial<SortableEvent>
|
|
189
189
|
): Log {
|
|
190
|
-
const { blockNumber,
|
|
190
|
+
const { blockNumber, txnIndex } = fill;
|
|
191
191
|
let { originChainId, depositId, inputAmount, outputAmount, fillDeadline } = fill;
|
|
192
192
|
originChainId ??= random(1, 42161, false);
|
|
193
193
|
depositId ??= BigNumber.from(random(1, 100_000, false));
|
|
@@ -260,7 +260,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
260
260
|
topics: topics.map((topic) => topic.toString()),
|
|
261
261
|
args,
|
|
262
262
|
blockNumber,
|
|
263
|
-
transactionIndex,
|
|
263
|
+
transactionIndex: txnIndex,
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -335,7 +335,7 @@ export class MockSpokePoolClient extends EVMSpokePoolClient {
|
|
|
335
335
|
exclusiveRelayer: addressModifier(args.exclusiveRelayer ?? ZERO_ADDRESS),
|
|
336
336
|
},
|
|
337
337
|
blockNumber: request.blockNumber,
|
|
338
|
-
transactionIndex: request.
|
|
338
|
+
transactionIndex: request.txnIndex,
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
341
|
|
package/src/interfaces/Common.ts
CHANGED
|
@@ -252,4 +252,14 @@ export class QueryBase implements QueryInterface {
|
|
|
252
252
|
);
|
|
253
253
|
return price;
|
|
254
254
|
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Resolves the number of decimal places a token can have
|
|
258
|
+
* @param tokenSymbol A valid Across-Enabled Token ID
|
|
259
|
+
* @returns The number of decimals of precision for the corresponding tokenSymbol
|
|
260
|
+
*/
|
|
261
|
+
getTokenDecimals(tokenSymbol: string): number {
|
|
262
|
+
if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
|
|
263
|
+
return this.symbolMapping[tokenSymbol].decimals;
|
|
264
|
+
}
|
|
255
265
|
}
|
|
@@ -34,6 +34,7 @@ export interface QueryInterface {
|
|
|
34
34
|
}>
|
|
35
35
|
) => Promise<TransactionCostEstimate>;
|
|
36
36
|
getTokenPrice: (tokenSymbol: string) => Promise<number>;
|
|
37
|
+
getTokenDecimals: (tokenSymbol: string) => number;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export const expectedCapitalCostsKeys = ["lowerBound", "upperBound", "cutoff", "decimals"];
|
package/src/utils/EventUtils.ts
CHANGED
|
@@ -204,13 +204,19 @@ export function getPaginatedBlockRanges({
|
|
|
204
204
|
return ranges;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
export function logToSortableEvent(log: Log): SortableEvent {
|
|
208
|
+
return {
|
|
209
|
+
txnIndex: log.transactionIndex,
|
|
210
|
+
txnRef: log.transactionHash,
|
|
211
|
+
logIndex: log.logIndex,
|
|
212
|
+
blockNumber: log.blockNumber,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
207
216
|
export function spreadEventWithBlockNumber(event: Log): SortableEvent {
|
|
208
217
|
return {
|
|
209
218
|
...spreadEvent(event.args),
|
|
210
|
-
|
|
211
|
-
transactionIndex: event.transactionIndex,
|
|
212
|
-
logIndex: event.logIndex,
|
|
213
|
-
transactionHash: event.transactionHash,
|
|
219
|
+
...logToSortableEvent(event),
|
|
214
220
|
};
|
|
215
221
|
}
|
|
216
222
|
|
|
@@ -226,8 +232,8 @@ export function sortEventsAscendingInPlace<T extends SortableEvent>(events: T[])
|
|
|
226
232
|
if (ex.blockNumber !== ey.blockNumber) {
|
|
227
233
|
return ex.blockNumber - ey.blockNumber;
|
|
228
234
|
}
|
|
229
|
-
if (ex.
|
|
230
|
-
return ex.
|
|
235
|
+
if (ex.txnIndex !== ey.txnIndex) {
|
|
236
|
+
return ex.txnIndex - ey.txnIndex;
|
|
231
237
|
}
|
|
232
238
|
return ex.logIndex - ey.logIndex;
|
|
233
239
|
});
|
|
@@ -245,8 +251,8 @@ export function sortEventsDescendingInPlace<T extends SortableEvent>(events: T[]
|
|
|
245
251
|
if (ex.blockNumber !== ey.blockNumber) {
|
|
246
252
|
return ey.blockNumber - ex.blockNumber;
|
|
247
253
|
}
|
|
248
|
-
if (ex.
|
|
249
|
-
return ey.
|
|
254
|
+
if (ex.txnIndex !== ey.txnIndex) {
|
|
255
|
+
return ey.txnIndex - ex.txnIndex;
|
|
250
256
|
}
|
|
251
257
|
return ey.logIndex - ex.logIndex;
|
|
252
258
|
});
|
|
@@ -257,16 +263,16 @@ export function isEventOlder<T extends SortableEvent>(ex: T, ey: T): boolean {
|
|
|
257
263
|
if (ex.blockNumber !== ey.blockNumber) {
|
|
258
264
|
return ex.blockNumber < ey.blockNumber;
|
|
259
265
|
}
|
|
260
|
-
if (ex.
|
|
261
|
-
return ex.
|
|
266
|
+
if (ex.txnIndex !== ey.txnIndex) {
|
|
267
|
+
return ex.txnIndex < ey.txnIndex;
|
|
262
268
|
}
|
|
263
269
|
return ex.logIndex < ey.logIndex;
|
|
264
270
|
}
|
|
265
271
|
|
|
266
|
-
export function
|
|
267
|
-
return [...Array.from(new Set(events.map((e) => e.
|
|
272
|
+
export function getTransactionRefs(events: SortableEvent[]): string[] {
|
|
273
|
+
return [...Array.from(new Set(events.map((e) => e.txnRef)))];
|
|
268
274
|
}
|
|
269
275
|
|
|
270
276
|
export function duplicateEvent(a: SortableEvent, b: SortableEvent): boolean {
|
|
271
|
-
return a.
|
|
277
|
+
return a.txnRef === b.txnRef && a.logIndex === b.logIndex;
|
|
272
278
|
}
|
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -147,8 +147,6 @@ export function getUsdcSymbol(l2Token: string, chainId: number): string | undefi
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
export function getL1TokenInfo(l2TokenAddress: string, chainId: number): L1Token {
|
|
150
|
-
if (chainId === CHAIN_IDs.MAINNET)
|
|
151
|
-
throw new Error("chainId should be an L2 chainId because many mappings re-use the same L1 token address");
|
|
152
150
|
const tokenObject = Object.values(TOKEN_SYMBOLS_MAP).find(({ addresses }) => addresses[chainId] === l2TokenAddress);
|
|
153
151
|
const l1TokenAddress = tokenObject?.addresses[CHAIN_IDs.MAINNET];
|
|
154
152
|
if (!l1TokenAddress) {
|