@across-protocol/sdk 3.1.35 → 3.2.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 +4 -4
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +1 -2
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +7 -4
- package/dist/cjs/clients/HubPoolClient.js +37 -25
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient.d.ts +7 -5
- package/dist/cjs/clients/SpokePoolClient.js +53 -90
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockConfigStoreClient.d.ts +4 -3
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js +27 -44
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockEvents.d.ts +5 -5
- package/dist/cjs/clients/mocks/MockEvents.js +7 -44
- package/dist/cjs/clients/mocks/MockEvents.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +5 -5
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +9 -19
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +22 -96
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/contracts/utils.d.ts +1 -1
- package/dist/cjs/contracts/utils.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/polygon.js +30 -7
- package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/cjs/interfaces/Common.d.ts +7 -0
- package/dist/cjs/priceClient/adapters/baseAdapter.js +11 -9
- package/dist/cjs/priceClient/adapters/baseAdapter.js.map +1 -1
- package/dist/cjs/utils/EventUtils.d.ts +7 -4
- package/dist/cjs/utils/EventUtils.js +9 -5
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/JSONUtils.js +1 -1
- package/dist/cjs/utils/JSONUtils.js.map +1 -1
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +4 -4
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +2 -3
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +19 -4
- package/dist/esm/clients/HubPoolClient.js +51 -27
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient.d.ts +13 -12
- package/dist/esm/clients/SpokePoolClient.js +61 -104
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockConfigStoreClient.d.ts +4 -3
- package/dist/esm/clients/mocks/MockConfigStoreClient.js +33 -47
- package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockEvents.d.ts +5 -5
- package/dist/esm/clients/mocks/MockEvents.js +9 -50
- package/dist/esm/clients/mocks/MockEvents.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +5 -5
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +9 -19
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +30 -100
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/contracts/utils.d.ts +1 -1
- package/dist/esm/contracts/utils.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/polygon.js +31 -10
- package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/esm/interfaces/Common.d.ts +7 -0
- package/dist/esm/priceClient/adapters/baseAdapter.js +11 -9
- package/dist/esm/priceClient/adapters/baseAdapter.js.map +1 -1
- package/dist/esm/utils/EventUtils.d.ts +7 -4
- package/dist/esm/utils/EventUtils.js +7 -4
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/JSONUtils.js +1 -1
- package/dist/esm/utils/JSONUtils.js.map +1 -1
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +4 -4
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +19 -4
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient.d.ts +13 -12
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockConfigStoreClient.d.ts +4 -3
- package/dist/types/clients/mocks/MockConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockEvents.d.ts +5 -5
- package/dist/types/clients/mocks/MockEvents.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts +5 -5
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +9 -19
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/contracts/utils.d.ts +1 -1
- package/dist/types/contracts/utils.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/polygon.d.ts.map +1 -1
- package/dist/types/interfaces/Common.d.ts +7 -0
- package/dist/types/interfaces/Common.d.ts.map +1 -1
- package/dist/types/priceClient/adapters/baseAdapter.d.ts.map +1 -1
- package/dist/types/utils/EventUtils.d.ts +7 -4
- package/dist/types/utils/EventUtils.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +9 -10
- package/src/clients/HubPoolClient.ts +34 -24
- package/src/clients/SpokePoolClient.ts +55 -74
- package/src/clients/mocks/MockConfigStoreClient.ts +11 -11
- package/src/clients/mocks/MockEvents.ts +15 -65
- package/src/clients/mocks/MockHubPoolClient.ts +6 -6
- package/src/clients/mocks/MockSpokePoolClient.ts +26 -59
- package/src/contracts/utils.ts +2 -1
- package/src/gasPriceOracle/adapters/polygon.ts +19 -8
- package/src/interfaces/Common.ts +7 -0
- package/src/priceClient/adapters/baseAdapter.ts +1 -0
- package/src/utils/EventUtils.ts +12 -7
- package/src/utils/JSONUtils.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { utils, across } from "@uma/sdk";
|
|
2
2
|
import assert from "assert";
|
|
3
|
-
import { Contract
|
|
3
|
+
import { Contract } from "ethers";
|
|
4
4
|
import winston from "winston";
|
|
5
5
|
import { isError } from "../../typeguards";
|
|
6
6
|
import {
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
paginatedEventQuery,
|
|
15
15
|
sortEventsAscendingInPlace,
|
|
16
16
|
sortEventsDescending,
|
|
17
|
-
spreadEvent,
|
|
18
17
|
spreadEventWithBlockNumber,
|
|
19
18
|
toBN,
|
|
20
19
|
utf8ToHex,
|
|
@@ -25,8 +24,10 @@ import {
|
|
|
25
24
|
DisabledChainsUpdate,
|
|
26
25
|
GlobalConfigUpdate,
|
|
27
26
|
LiteChainsIdListUpdate,
|
|
27
|
+
Log,
|
|
28
28
|
ParsedTokenConfig,
|
|
29
29
|
RouteRateModelUpdate,
|
|
30
|
+
SortableEvent,
|
|
30
31
|
SpokePoolTargetBalance,
|
|
31
32
|
SpokeTargetBalanceUpdate,
|
|
32
33
|
TokenConfig,
|
|
@@ -41,8 +42,8 @@ type ConfigStoreUpdateSuccess = {
|
|
|
41
42
|
chainId: number;
|
|
42
43
|
searchEndBlock: number;
|
|
43
44
|
events: {
|
|
44
|
-
updatedTokenConfigEvents:
|
|
45
|
-
updatedGlobalConfigEvents:
|
|
45
|
+
updatedTokenConfigEvents: Log[];
|
|
46
|
+
updatedGlobalConfigEvents: Log[];
|
|
46
47
|
globalConfigUpdateTimes: number[];
|
|
47
48
|
};
|
|
48
49
|
};
|
|
@@ -430,12 +431,10 @@ export class AcrossConfigStoreClient extends BaseAbstractClient {
|
|
|
430
431
|
|
|
431
432
|
// Save new Global config updates.
|
|
432
433
|
for (let i = 0; i < updatedGlobalConfigEvents.length; i++) {
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
logIndex: event.logIndex,
|
|
438
|
-
...spreadEvent(event.args),
|
|
434
|
+
const args = spreadEventWithBlockNumber(updatedGlobalConfigEvents[i]) as SortableEvent & {
|
|
435
|
+
key: string;
|
|
436
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
437
|
+
value: any;
|
|
439
438
|
};
|
|
440
439
|
|
|
441
440
|
if (args.key === utf8ToHex(GLOBAL_CONFIG_STORE_KEYS.MAX_RELAYER_REPAYMENT_LEAF_SIZE)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
|
-
import { Contract,
|
|
2
|
+
import { Contract, EventFilter } from "ethers";
|
|
3
3
|
import _ from "lodash";
|
|
4
4
|
import winston from "winston";
|
|
5
5
|
import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL } from "../constants";
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
DisputedRootBundle,
|
|
14
14
|
ExecutedRootBundle,
|
|
15
15
|
L1Token,
|
|
16
|
+
Log,
|
|
16
17
|
LpToken,
|
|
17
18
|
PendingRootBundle,
|
|
18
19
|
ProposedRootBundle,
|
|
@@ -38,7 +39,6 @@ import {
|
|
|
38
39
|
paginatedEventQuery,
|
|
39
40
|
shouldCache,
|
|
40
41
|
sortEventsDescending,
|
|
41
|
-
spreadEvent,
|
|
42
42
|
spreadEventWithBlockNumber,
|
|
43
43
|
toBN,
|
|
44
44
|
getTokenInfo,
|
|
@@ -52,7 +52,7 @@ type HubPoolUpdateSuccess = {
|
|
|
52
52
|
success: true;
|
|
53
53
|
currentTime: number;
|
|
54
54
|
pendingRootBundleProposal: PendingRootBundle;
|
|
55
|
-
events: Record<string,
|
|
55
|
+
events: Record<string, Log[]>;
|
|
56
56
|
searchEndBlock: number;
|
|
57
57
|
};
|
|
58
58
|
type HubPoolUpdateFailure = {
|
|
@@ -291,11 +291,33 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
291
291
|
return getL1TokenInfo(tokenAddress, chain);
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
|
|
294
|
+
/**
|
|
295
|
+
* Resolve a given timestamp to a block number on the HubPool chain.
|
|
296
|
+
* @param timestamp A single timestamp to be resolved to a block number on the HubPool chain.
|
|
297
|
+
* @returns The block number corresponding to the supplied timestamp.
|
|
298
|
+
*/
|
|
299
|
+
getBlockNumber(timestamp: number): Promise<number> {
|
|
295
300
|
const hints = { lowBlock: this.deploymentBlock };
|
|
296
301
|
return getCachedBlockForTimestamp(this.chainId, timestamp, this.blockFinder, this.cachingMechanism, hints);
|
|
297
302
|
}
|
|
298
303
|
|
|
304
|
+
/**
|
|
305
|
+
* For an array of timestamps, resolve each unique timestamp to a block number on the HubPool chain.
|
|
306
|
+
* @dev Inputs are filtered for uniqueness and sorted to improve BlockFinder efficiency.
|
|
307
|
+
* @dev Querying block numbers sequentially also improves BlockFinder efficiency.
|
|
308
|
+
* @param timestamps Array of timestamps to be resolved to a block number on the HubPool chain.
|
|
309
|
+
* @returns A mapping of quoteTimestamp -> HubPool block number.
|
|
310
|
+
*/
|
|
311
|
+
async getBlockNumbers(timestamps: number[]): Promise<{ [quoteTimestamp: number]: number }> {
|
|
312
|
+
const sortedTimestamps = dedupArray(timestamps).sort((x, y) => x - y);
|
|
313
|
+
const blockNumbers: { [quoteTimestamp: number]: number } = {};
|
|
314
|
+
for (const timestamp of sortedTimestamps) {
|
|
315
|
+
blockNumbers[timestamp] = await this.getBlockNumber(timestamp);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return blockNumbers;
|
|
319
|
+
}
|
|
320
|
+
|
|
299
321
|
async getCurrentPoolUtilization(l1Token: string): Promise<BigNumber> {
|
|
300
322
|
const blockNumber = this.latestBlockSearched ?? (await this.hubPool.provider.getBlockNumber());
|
|
301
323
|
return await this.getUtilization(l1Token, blockNumber, bnZero, getCurrentTime(), 0);
|
|
@@ -400,15 +422,6 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
400
422
|
}
|
|
401
423
|
};
|
|
402
424
|
|
|
403
|
-
// Helper to resolve a quoteTimestamp to a HubPool block number.
|
|
404
|
-
const resolveTimestampsToBlocks = async (quoteTimestamp: number): Promise<[number, number]> => {
|
|
405
|
-
const quoteBlock = await this.getBlockNumber(quoteTimestamp);
|
|
406
|
-
if (!isDefined(quoteBlock)) {
|
|
407
|
-
throw new Error(`Could not find block for timestamp ${quoteTimestamp}`);
|
|
408
|
-
}
|
|
409
|
-
return [quoteTimestamp, quoteBlock];
|
|
410
|
-
};
|
|
411
|
-
|
|
412
425
|
// Helper to resolve existing HubPool token utilisation for an array of unique block numbers.
|
|
413
426
|
// Produces a mapping of blockNumber -> utilization for a specific token.
|
|
414
427
|
const resolveUtilization = async (hubPoolToken: string): Promise<Record<number, BigNumber>> => {
|
|
@@ -462,14 +475,12 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
462
475
|
*/
|
|
463
476
|
const timeToCache = this.configOverride.timeToCache ?? DEFAULT_CACHING_SAFE_LAG;
|
|
464
477
|
|
|
465
|
-
// Identify the unique hubPoolToken & quoteTimestamp mappings. This is used to optimise subsequent HubPool queries.
|
|
466
|
-
deposits.forEach((deposit) => resolveUniqueQuoteTimestamps(deposit));
|
|
467
|
-
|
|
468
478
|
// Filter all deposits for unique quoteTimestamps, to be resolved to a blockNumber in parallel.
|
|
469
479
|
const quoteTimestamps = dedupArray(deposits.map(({ quoteTimestamp }) => quoteTimestamp));
|
|
470
|
-
quoteBlocks =
|
|
471
|
-
|
|
472
|
-
|
|
480
|
+
quoteBlocks = await this.getBlockNumbers(quoteTimestamps);
|
|
481
|
+
|
|
482
|
+
// Identify the unique hubPoolToken & quoteTimestamp mappings. This is used to optimise subsequent HubPool queries.
|
|
483
|
+
deposits.forEach((deposit) => resolveUniqueQuoteTimestamps(deposit));
|
|
473
484
|
|
|
474
485
|
// For each token / quoteBlock pair, resolve the utilisation for each quoted block.
|
|
475
486
|
// This can be reused for each deposit with the same HubPool token and quoteTimestamp pair.
|
|
@@ -890,11 +901,10 @@ export class HubPoolClient extends BaseAbstractClient {
|
|
|
890
901
|
// only run iff a new token has been enabled. Will only append iff the info is not there already.
|
|
891
902
|
// Filter out any duplicate addresses. This might happen due to enabling, disabling and re-enabling a token.
|
|
892
903
|
if (eventsToQuery.includes("L1TokenEnabledForLiquidityProvision")) {
|
|
893
|
-
const uniqueL1Tokens =
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
];
|
|
904
|
+
const uniqueL1Tokens = dedupArray(
|
|
905
|
+
events["L1TokenEnabledForLiquidityProvision"].map((event) => String(event.args["l1Token"]))
|
|
906
|
+
);
|
|
907
|
+
|
|
898
908
|
const [tokenInfo, lpTokenInfo] = await Promise.all([
|
|
899
909
|
Promise.all(uniqueL1Tokens.map((l1Token: string) => fetchTokenInfo(l1Token, this.hubPool.provider))),
|
|
900
910
|
Promise.all(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Contract,
|
|
1
|
+
import { Contract, EventFilter } from "ethers";
|
|
2
2
|
import winston from "winston";
|
|
3
3
|
import {
|
|
4
4
|
AnyObject,
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
spreadEventWithBlockNumber,
|
|
21
21
|
} from "../utils/EventUtils";
|
|
22
22
|
import { validateFillForDeposit } from "../utils/FlowUtils";
|
|
23
|
-
|
|
24
23
|
import { ZERO_ADDRESS } from "../constants";
|
|
25
24
|
import {
|
|
26
25
|
Deposit,
|
|
@@ -28,15 +27,13 @@ import {
|
|
|
28
27
|
Fill,
|
|
29
28
|
FillStatus,
|
|
30
29
|
FillWithBlock,
|
|
31
|
-
|
|
32
|
-
RealizedLpFee,
|
|
30
|
+
Log,
|
|
33
31
|
RelayData,
|
|
34
32
|
RelayerRefundExecutionWithBlock,
|
|
35
33
|
RootBundleRelayWithBlock,
|
|
36
34
|
SlowFillRequestWithBlock,
|
|
37
35
|
SpeedUpWithBlock,
|
|
38
36
|
TokensBridged,
|
|
39
|
-
V3FundsDepositedEvent,
|
|
40
37
|
} from "../interfaces";
|
|
41
38
|
import { SpokePool } from "../typechain";
|
|
42
39
|
import { getNetworkName } from "../utils/NetworkUtils";
|
|
@@ -51,7 +48,7 @@ type SpokePoolUpdateSuccess = {
|
|
|
51
48
|
oldestTime: number;
|
|
52
49
|
firstDepositId: number;
|
|
53
50
|
latestDepositId: number;
|
|
54
|
-
events:
|
|
51
|
+
events: Log[][];
|
|
55
52
|
searchEndBlock: number;
|
|
56
53
|
};
|
|
57
54
|
type SpokePoolUpdateFailure = {
|
|
@@ -511,7 +508,7 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
511
508
|
}
|
|
512
509
|
|
|
513
510
|
// Sort all events to ensure they are stored in a consistent order.
|
|
514
|
-
events.forEach((events:
|
|
511
|
+
events.forEach((events: Log[]) => sortEventsAscendingInPlace(events));
|
|
515
512
|
|
|
516
513
|
return {
|
|
517
514
|
success: true,
|
|
@@ -550,24 +547,34 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
550
547
|
}
|
|
551
548
|
|
|
552
549
|
if (eventsToQuery.includes("V3FundsDeposited")) {
|
|
553
|
-
const depositEvents = [
|
|
554
|
-
...((queryResults[eventsToQuery.indexOf("V3FundsDeposited")] ?? []) as V3FundsDepositedEvent[]),
|
|
555
|
-
];
|
|
550
|
+
const depositEvents = queryResults[eventsToQuery.indexOf("V3FundsDeposited")] ?? [];
|
|
556
551
|
if (depositEvents.length > 0) {
|
|
557
552
|
this.log("debug", `Using ${depositEvents.length} newly queried deposit events for chain ${this.chainId}`, {
|
|
558
553
|
earliestEvent: depositEvents[0].blockNumber,
|
|
559
554
|
});
|
|
560
555
|
}
|
|
561
556
|
|
|
562
|
-
|
|
563
|
-
for
|
|
564
|
-
|
|
557
|
+
// For each deposit, resolve its quoteTimestamp to a block number on the HubPool.
|
|
558
|
+
// Don't bother filtering for uniqueness; the HubPoolClient handles this efficienctly.
|
|
559
|
+
const quoteBlockNumbers = await this.getBlockNumbers(
|
|
560
|
+
depositEvents.map(({ args }) => Number(args["quoteTimestamp"]))
|
|
561
|
+
);
|
|
562
|
+
for (const event of depositEvents) {
|
|
563
|
+
const quoteBlockNumber = quoteBlockNumbers[Number(event.args["quoteTimestamp"])];
|
|
565
564
|
|
|
566
565
|
// Derive and append the common properties that are not part of the onchain event.
|
|
567
|
-
const
|
|
568
|
-
|
|
566
|
+
const deposit = {
|
|
567
|
+
...spreadEventWithBlockNumber(event),
|
|
568
|
+
quoteBlockNumber,
|
|
569
|
+
originChainId: this.chainId,
|
|
570
|
+
// The following properties are placeholders to be updated immediately.
|
|
571
|
+
fromLiteChain: true,
|
|
572
|
+
toLiteChain: true,
|
|
573
|
+
} as DepositWithBlock;
|
|
574
|
+
|
|
569
575
|
deposit.fromLiteChain = this.isOriginLiteChain(deposit);
|
|
570
576
|
deposit.toLiteChain = this.isDestinationLiteChain(deposit);
|
|
577
|
+
|
|
571
578
|
if (deposit.outputToken === ZERO_ADDRESS) {
|
|
572
579
|
deposit.outputToken = this.getDestinationTokenForDeposit(deposit);
|
|
573
580
|
}
|
|
@@ -586,16 +593,12 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
586
593
|
}
|
|
587
594
|
}
|
|
588
595
|
|
|
589
|
-
// TODO: When validating fills with deposits for the purposes of UBA flows, do we need to consider
|
|
590
|
-
// speed ups as well? For example, do we need to also consider that the speed up is before the fill
|
|
591
|
-
// timestamp to be applied for the fill? My brain hurts.
|
|
592
596
|
// Update deposits with speed up requests from depositor.
|
|
593
597
|
if (eventsToQuery.includes("RequestedSpeedUpV3Deposit")) {
|
|
594
|
-
const speedUpEvents =
|
|
598
|
+
const speedUpEvents = queryResults[eventsToQuery.indexOf("RequestedSpeedUpV3Deposit")] ?? [];
|
|
595
599
|
|
|
596
600
|
for (const event of speedUpEvents) {
|
|
597
|
-
const
|
|
598
|
-
const speedUp = { ...rawEvent, originChainId: this.chainId } as SpeedUpWithBlock;
|
|
601
|
+
const speedUp = { ...spreadEventWithBlockNumber(event), originChainId: this.chainId } as SpeedUpWithBlock;
|
|
599
602
|
assign(this.speedUps, [speedUp.depositor, speedUp.depositId], [speedUp]);
|
|
600
603
|
|
|
601
604
|
// Find deposit hash matching this speed up event and update the deposit data associated with the hash,
|
|
@@ -614,10 +617,11 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
614
617
|
if (eventsToQuery.includes("RequestedV3SlowFill")) {
|
|
615
618
|
const slowFillRequests = queryResults[eventsToQuery.indexOf("RequestedV3SlowFill")];
|
|
616
619
|
for (const event of slowFillRequests) {
|
|
617
|
-
const slowFillRequest
|
|
618
|
-
...
|
|
620
|
+
const slowFillRequest = {
|
|
621
|
+
...spreadEventWithBlockNumber(event),
|
|
619
622
|
destinationChainId: this.chainId,
|
|
620
|
-
};
|
|
623
|
+
} as SlowFillRequestWithBlock;
|
|
624
|
+
|
|
621
625
|
const relayDataHash = getRelayDataHash(slowFillRequest, this.chainId);
|
|
622
626
|
if (this.slowFillRequests[relayDataHash] !== undefined) {
|
|
623
627
|
continue;
|
|
@@ -627,7 +631,7 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
627
631
|
}
|
|
628
632
|
|
|
629
633
|
if (eventsToQuery.includes("FilledV3Relay")) {
|
|
630
|
-
const fillEvents =
|
|
634
|
+
const fillEvents = queryResults[eventsToQuery.indexOf("FilledV3Relay")] ?? [];
|
|
631
635
|
|
|
632
636
|
if (fillEvents.length > 0) {
|
|
633
637
|
this.log("debug", `Using ${fillEvents.length} newly queried fill events for chain ${this.chainId}`, {
|
|
@@ -639,9 +643,9 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
639
643
|
// test that the types are complete. A broader change in strategy for safely unpacking events will be introduced.
|
|
640
644
|
for (const event of fillEvents) {
|
|
641
645
|
const fill = {
|
|
642
|
-
...
|
|
646
|
+
...spreadEventWithBlockNumber(event),
|
|
643
647
|
destinationChainId: this.chainId,
|
|
644
|
-
};
|
|
648
|
+
} as FillWithBlock;
|
|
645
649
|
|
|
646
650
|
assign(this.fills, [fill.originChainId], [fill]);
|
|
647
651
|
assign(this.depositHashesToFills, [this.getDepositHash(fill)], [fill]);
|
|
@@ -719,46 +723,24 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
719
723
|
}
|
|
720
724
|
|
|
721
725
|
/**
|
|
722
|
-
*
|
|
723
|
-
* @param
|
|
724
|
-
* @returns The
|
|
726
|
+
* Resolve a given timestamp to a block number on the HubPool chain via the HubPoolClient.
|
|
727
|
+
* @param timestamp A single timestamp to be resolved via the HubPoolClient.
|
|
728
|
+
* @returns The block number on the HubPool chain corresponding to the supplied timestamp.
|
|
725
729
|
*/
|
|
726
|
-
protected
|
|
727
|
-
|
|
728
|
-
return lpFee;
|
|
730
|
+
protected getBlockNumber(timestamp: number): Promise<number> {
|
|
731
|
+
return this.hubPoolClient?.getBlockNumber(timestamp) ?? Promise.resolve(MAX_BIG_INT.toNumber());
|
|
729
732
|
}
|
|
730
733
|
|
|
731
734
|
/**
|
|
732
|
-
*
|
|
733
|
-
* @
|
|
734
|
-
* @
|
|
735
|
-
* @returns The array of realized LP fee percentages and associated HubPool block numbers.
|
|
735
|
+
* For an array of timestamps, resolve each timestamp to a block number on the HubPool chain via the HubPoolClient.
|
|
736
|
+
* @param timestamps Array of timestamps to be resolved to a block number via the HubPoolClient.
|
|
737
|
+
* @returns A mapping of quoteTimestamp -> HubPool block number.
|
|
736
738
|
*/
|
|
737
|
-
protected
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
const quoteBlock = MAX_BIG_INT.toNumber();
|
|
743
|
-
return depositEvents.map(() => {
|
|
744
|
-
return { realizedLpFeePct, quoteBlock };
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
const deposits = depositEvents.map(({ args }) => {
|
|
749
|
-
// For v3 deposits, leave payment chain ID undefined so we don't compute lp fee since we don't have the
|
|
750
|
-
// payment chain ID until we match this deposit with a fill.
|
|
751
|
-
const { inputToken, inputAmount, quoteTimestamp } = args;
|
|
752
|
-
return {
|
|
753
|
-
inputToken,
|
|
754
|
-
inputAmount,
|
|
755
|
-
originChainId: this.chainId,
|
|
756
|
-
paymentChainId: undefined,
|
|
757
|
-
quoteTimestamp,
|
|
758
|
-
};
|
|
759
|
-
});
|
|
760
|
-
|
|
761
|
-
return deposits.length > 0 ? await this.hubPoolClient.batchComputeRealizedLpFeePct(deposits) : [];
|
|
739
|
+
protected getBlockNumbers(timestamps: number[]): Promise<{ [quoteTimestamp: number]: number }> {
|
|
740
|
+
return (
|
|
741
|
+
this.hubPoolClient?.getBlockNumbers(timestamps) ??
|
|
742
|
+
Promise.resolve(Object.fromEntries(timestamps.map((timestamp) => [timestamp, MAX_BIG_INT.toNumber()])))
|
|
743
|
+
);
|
|
762
744
|
}
|
|
763
745
|
|
|
764
746
|
/**
|
|
@@ -829,7 +811,7 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
829
811
|
);
|
|
830
812
|
const tStop = Date.now();
|
|
831
813
|
|
|
832
|
-
const event =
|
|
814
|
+
const event = query.find(({ args }) => args["depositId"] === depositId);
|
|
833
815
|
if (event === undefined) {
|
|
834
816
|
const srcChain = getNetworkName(this.chainId);
|
|
835
817
|
const dstChain = getNetworkName(destinationChainId);
|
|
@@ -838,19 +820,18 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
838
820
|
` between ${srcChain} blocks [${searchBounds.low}, ${searchBounds.high}]`
|
|
839
821
|
);
|
|
840
822
|
}
|
|
841
|
-
const partialDeposit = spreadEventWithBlockNumber(event) as DepositWithBlock;
|
|
842
|
-
const { quoteBlock: quoteBlockNumber } = await this.computeRealizedLpFeePct(event);
|
|
843
823
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
...partialDeposit,
|
|
824
|
+
const deposit = {
|
|
825
|
+
...spreadEventWithBlockNumber(event),
|
|
847
826
|
originChainId: this.chainId,
|
|
848
|
-
quoteBlockNumber,
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
827
|
+
quoteBlockNumber: await this.getBlockNumber(Number(event.args["quoteTimestamp"])),
|
|
828
|
+
fromLiteChain: true, // To be updated immediately afterwards.
|
|
829
|
+
toLiteChain: true, // To be updated immediately afterwards.
|
|
830
|
+
} as DepositWithBlock;
|
|
831
|
+
|
|
832
|
+
if (deposit.outputToken === ZERO_ADDRESS) {
|
|
833
|
+
deposit.outputToken = this.getDestinationTokenForDeposit(deposit);
|
|
834
|
+
}
|
|
854
835
|
deposit.fromLiteChain = this.isOriginLiteChain(deposit);
|
|
855
836
|
deposit.toLiteChain = this.isDestinationLiteChain(deposit);
|
|
856
837
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import winston from "winston";
|
|
3
|
-
import { Contract,
|
|
4
|
-
import {
|
|
3
|
+
import { Contract, ethers } from "ethers";
|
|
4
|
+
import { Log } from "../../interfaces";
|
|
5
|
+
import { getCurrentTime, EventSearchConfig, MakeOptional, isDefined, utf8ToHex } from "../../utils";
|
|
5
6
|
import {
|
|
6
7
|
AcrossConfigStoreClient,
|
|
7
8
|
ConfigStoreUpdate,
|
|
@@ -60,7 +61,7 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient {
|
|
|
60
61
|
this.configStoreVersion = version;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
_update(): Promise<ConfigStoreUpdate> {
|
|
64
65
|
// Backwards compatibility for pre-existing MockConfigStoreClient users.
|
|
65
66
|
if (this.eventManager === null) {
|
|
66
67
|
return super._update();
|
|
@@ -72,7 +73,7 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient {
|
|
|
72
73
|
// Ensure an array for every requested event exists, in the requested order.
|
|
73
74
|
// All requested event types must be populated in the array (even if empty).
|
|
74
75
|
const globalConfigUpdateTimes: number[] = [];
|
|
75
|
-
const _events:
|
|
76
|
+
const _events: Log[][] = eventNames.map(() => []);
|
|
76
77
|
for (const event of this.eventManager.getEvents().flat()) {
|
|
77
78
|
const idx = eventNames.indexOf(event.event as string);
|
|
78
79
|
if (idx !== -1) {
|
|
@@ -80,15 +81,14 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient {
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
if (event.event === "UpdatedGlobalConfig") {
|
|
83
|
-
|
|
84
|
-
globalConfigUpdateTimes.push(block.timestamp);
|
|
84
|
+
globalConfigUpdateTimes.push(getCurrentTime());
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// Transform 2d-events array into a record.
|
|
89
89
|
const events = Object.fromEntries(eventNames.map((eventName, idx) => [eventName, _events[idx]]));
|
|
90
90
|
|
|
91
|
-
return {
|
|
91
|
+
return Promise.resolve({
|
|
92
92
|
success: true,
|
|
93
93
|
chainId: this.chainId as number,
|
|
94
94
|
searchEndBlock: this.eventSearchConfig.toBlock || latestBlockSearched,
|
|
@@ -97,14 +97,14 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient {
|
|
|
97
97
|
globalConfigUpdateTimes,
|
|
98
98
|
updatedTokenConfigEvents: events["UpdatedTokenConfig"],
|
|
99
99
|
},
|
|
100
|
-
};
|
|
100
|
+
});
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
updateGlobalConfig(key: string, value: string, overrides: EventOverrides = {}):
|
|
103
|
+
updateGlobalConfig(key: string, value: string, overrides: EventOverrides = {}): Log {
|
|
104
104
|
return this.generateConfig("UpdatedGlobalConfig", utf8ToHex(key), value, overrides);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
updateTokenConfig(key: string, value: string, overrides: EventOverrides = {}):
|
|
107
|
+
updateTokenConfig(key: string, value: string, overrides: EventOverrides = {}): Log {
|
|
108
108
|
// Verify that the key is a valid address
|
|
109
109
|
if (ethers.utils.isAddress(key) === false) {
|
|
110
110
|
throw new Error(`Invalid address: ${key}`);
|
|
@@ -112,7 +112,7 @@ export class MockConfigStoreClient extends AcrossConfigStoreClient {
|
|
|
112
112
|
return this.generateConfig("UpdatedTokenConfig", key, value, overrides);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
private generateConfig(event: string, key: string, value: string, overrides: EventOverrides = {}):
|
|
115
|
+
private generateConfig(event: string, key: string, value: string, overrides: EventOverrides = {}): Log {
|
|
116
116
|
assert(this.eventManager !== null);
|
|
117
117
|
|
|
118
118
|
const topics = [key, value];
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
|
-
import { utils as ethersUtils
|
|
2
|
+
import { utils as ethersUtils } from "ethers";
|
|
3
3
|
import { random } from "lodash";
|
|
4
|
-
import {
|
|
4
|
+
import { Log } from "../../interfaces";
|
|
5
|
+
import { isDefined } from "../../utils";
|
|
5
6
|
|
|
6
7
|
const { id, keccak256, toUtf8Bytes } = ethersUtils;
|
|
7
8
|
export type EventOverrides = {
|
|
8
9
|
blockNumber?: number;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
type Block = providers.Block;
|
|
12
|
-
type TransactionResponse = providers.TransactionResponse;
|
|
13
|
-
type TransactionReceipt = providers.TransactionReceipt;
|
|
14
|
-
|
|
15
12
|
type EthersEventTemplate = {
|
|
16
13
|
address: string;
|
|
17
14
|
event: string;
|
|
@@ -25,22 +22,9 @@ type EthersEventTemplate = {
|
|
|
25
22
|
|
|
26
23
|
const eventManagers: { [chainId: number]: EventManager } = {};
|
|
27
24
|
|
|
28
|
-
// May need to populate getTransaction and getTransactionReceipt if calling code starts using it.
|
|
29
|
-
// https://docs.ethers.org/v5/api/providers/provider/#Provider-getTransaction
|
|
30
|
-
const getTransaction = (): Promise<TransactionResponse> => {
|
|
31
|
-
throw new Error("getTransaction() not supported");
|
|
32
|
-
};
|
|
33
|
-
// https://docs.ethers.org/v5/api/providers/provider/#Provider-getTransactionReceipt
|
|
34
|
-
const getTransactionReceipt = (): Promise<TransactionReceipt> => {
|
|
35
|
-
throw new Error("getTransactionReceipt() not supported");
|
|
36
|
-
};
|
|
37
|
-
const removeListener = (): void => {
|
|
38
|
-
throw new Error("removeListener not supported");
|
|
39
|
-
};
|
|
40
|
-
|
|
41
25
|
export class EventManager {
|
|
42
26
|
private logIndexes: Record<string, number> = {};
|
|
43
|
-
public events:
|
|
27
|
+
public events: Log[] = [];
|
|
44
28
|
public readonly minBlockRange = 10;
|
|
45
29
|
public readonly eventSignatures: Record<string, string> = {};
|
|
46
30
|
|
|
@@ -55,78 +39,44 @@ export class EventManager {
|
|
|
55
39
|
});
|
|
56
40
|
}
|
|
57
41
|
|
|
58
|
-
addEvent(event:
|
|
42
|
+
addEvent(event: Log): void {
|
|
59
43
|
this.events.push(event);
|
|
60
44
|
}
|
|
61
45
|
|
|
62
|
-
getEvents():
|
|
46
|
+
getEvents(): Log[] {
|
|
63
47
|
const events = this.events;
|
|
64
48
|
this.events = [];
|
|
65
49
|
return events;
|
|
66
50
|
}
|
|
67
51
|
|
|
68
|
-
generateEvent(inputs: EthersEventTemplate):
|
|
69
|
-
const { address, event, topics
|
|
70
|
-
const eventSignature = `${event}(${this.eventSignatures[event]})`;
|
|
71
|
-
const topics = [keccak256(toUtf8Bytes(eventSignature))].concat(_topics);
|
|
72
|
-
|
|
52
|
+
generateEvent(inputs: EthersEventTemplate): Log {
|
|
53
|
+
const { address, event, topics, data, args } = inputs;
|
|
73
54
|
let { blockNumber, transactionIndex } = inputs;
|
|
55
|
+
const eventSignature = `${event}(${this.eventSignatures[event]})`;
|
|
74
56
|
|
|
75
57
|
// Increment the block number by at least 1, by default. The caller may override
|
|
76
58
|
// to force the same block number to be used, but never a previous block number.
|
|
77
59
|
blockNumber ??= random(this.blockNumber + 1, this.blockNumber + this.minBlockRange, false);
|
|
78
60
|
assert(blockNumber >= this.blockNumber, `${blockNumber} < ${this.blockNumber}`);
|
|
79
61
|
this.blockNumber = blockNumber;
|
|
80
|
-
|
|
81
62
|
transactionIndex ??= random(1, 32, false);
|
|
82
|
-
const transactionHash = id(`Across-${event}-${blockNumber}-${transactionIndex}-${random(1, 100_000)}`);
|
|
83
63
|
|
|
84
64
|
const _logIndex = `${blockNumber}-${transactionIndex}`;
|
|
85
65
|
this.logIndexes[_logIndex] ??= 0;
|
|
86
|
-
const logIndex = this.logIndexes[_logIndex]++;
|
|
87
|
-
|
|
88
|
-
const decodeError = new Error(`${event} decoding error`);
|
|
89
|
-
const parentHash = id(`Across-blockHash-${random(1, 100_000)}`);
|
|
90
|
-
const blockHash = id(`Across-blockHash-${parentHash}-${random(1, 100_000)}`);
|
|
91
|
-
|
|
92
|
-
// getBlock() may later be used to retrieve (for example) the block timestamp.
|
|
93
|
-
// @todo: If multiple events coincide on the same block number, this callback should return the same Block object.
|
|
94
|
-
const getBlock = (): Promise<Block> => {
|
|
95
|
-
return Promise.resolve({
|
|
96
|
-
hash: blockHash,
|
|
97
|
-
parentHash,
|
|
98
|
-
number: blockNumber as number,
|
|
99
|
-
timestamp: Math.floor(Date.now() / 1000),
|
|
100
|
-
nonce: "",
|
|
101
|
-
difficulty: random(1, 1000, false),
|
|
102
|
-
_difficulty: toBN(random(1, 1000, false)),
|
|
103
|
-
gasLimit: toBN(random(1_000_000, 10_000_000, false)),
|
|
104
|
-
gasUsed: toBN(random(1, 1000, false)),
|
|
105
|
-
miner: randomAddress(),
|
|
106
|
-
extraData: `Block containing test transaction ${transactionHash}.`,
|
|
107
|
-
transactions: [transactionHash],
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
66
|
|
|
111
67
|
const generatedEvent = {
|
|
68
|
+
event,
|
|
112
69
|
blockNumber,
|
|
113
70
|
transactionIndex,
|
|
114
|
-
logIndex
|
|
115
|
-
transactionHash,
|
|
71
|
+
logIndex: this.logIndexes[_logIndex]++,
|
|
72
|
+
transactionHash: id(`Across-${event}-${blockNumber}-${transactionIndex}-${random(1, 100_000)}`),
|
|
116
73
|
removed: false,
|
|
117
74
|
address,
|
|
118
75
|
data: data ?? id(`Across-random-txndata-${random(1, 100_000)}`),
|
|
119
|
-
topics,
|
|
76
|
+
topics: [keccak256(toUtf8Bytes(eventSignature)), ...topics],
|
|
120
77
|
args,
|
|
121
|
-
blockHash,
|
|
122
|
-
|
|
123
|
-
eventSignature,
|
|
124
|
-
decodeError,
|
|
125
|
-
getBlock,
|
|
126
|
-
getTransaction,
|
|
127
|
-
getTransactionReceipt,
|
|
128
|
-
removeListener,
|
|
129
|
-
} as Event;
|
|
78
|
+
blockHash: id(`Across-blockHash-${random(1, 100_000)}`),
|
|
79
|
+
};
|
|
130
80
|
|
|
131
81
|
this.addEvent(generatedEvent);
|
|
132
82
|
return generatedEvent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import winston from "winston";
|
|
2
|
-
import { Contract
|
|
2
|
+
import { Contract } from "ethers";
|
|
3
3
|
import { BigNumber, randomAddress, assign, bnZero } from "../../utils";
|
|
4
|
-
import { L1Token, PendingRootBundle, RealizedLpFee } from "../../interfaces";
|
|
4
|
+
import { L1Token, Log, PendingRootBundle, RealizedLpFee } from "../../interfaces";
|
|
5
5
|
import { AcrossConfigStoreClient as ConfigStoreClient } from "../AcrossConfigStoreClient";
|
|
6
6
|
import { HubPoolClient, HubPoolUpdate, LpFeeRequest } from "../HubPoolClient";
|
|
7
7
|
import { EventManager, EventOverrides, getEventManager } from "./MockEvents";
|
|
@@ -127,7 +127,7 @@ export class MockHubPoolClient extends HubPoolClient {
|
|
|
127
127
|
|
|
128
128
|
// Ensure an array for every requested event exists, in the requested order.
|
|
129
129
|
// All requested event types must be populated in the array (even if empty).
|
|
130
|
-
const _events:
|
|
130
|
+
const _events: Log[][] = eventNames.map(() => []);
|
|
131
131
|
this.eventManager
|
|
132
132
|
.getEvents()
|
|
133
133
|
.flat()
|
|
@@ -163,7 +163,7 @@ export class MockHubPoolClient extends HubPoolClient {
|
|
|
163
163
|
l1Token: string,
|
|
164
164
|
destinationToken: string,
|
|
165
165
|
overrides: EventOverrides = {}
|
|
166
|
-
):
|
|
166
|
+
): Log {
|
|
167
167
|
const event = "SetPoolRebalanceRoute";
|
|
168
168
|
|
|
169
169
|
const topics = [destinationChainId, l1Token, destinationToken];
|
|
@@ -191,7 +191,7 @@ export class MockHubPoolClient extends HubPoolClient {
|
|
|
191
191
|
slowRelayRoot?: string,
|
|
192
192
|
proposer?: string,
|
|
193
193
|
overrides: EventOverrides = {}
|
|
194
|
-
):
|
|
194
|
+
): Log {
|
|
195
195
|
const event = "ProposeRootBundle";
|
|
196
196
|
|
|
197
197
|
poolRebalanceRoot ??= "XX";
|
|
@@ -229,7 +229,7 @@ export class MockHubPoolClient extends HubPoolClient {
|
|
|
229
229
|
runningBalances: BigNumber[],
|
|
230
230
|
caller?: string,
|
|
231
231
|
overrides: EventOverrides = {}
|
|
232
|
-
):
|
|
232
|
+
): Log {
|
|
233
233
|
const event = "RootBundleExecuted";
|
|
234
234
|
|
|
235
235
|
caller ??= randomAddress();
|