@across-protocol/sdk 3.1.36 → 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/interfaces/Common.d.ts +7 -0
- 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/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/interfaces/Common.d.ts +7 -0
- 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/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/interfaces/Common.d.ts +7 -0
- package/dist/types/interfaces/Common.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/interfaces/Common.ts +7 -0
- package/src/utils/EventUtils.ts +12 -7
|
@@ -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();
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
|
-
import { Contract
|
|
2
|
+
import { Contract } from "ethers";
|
|
3
3
|
import { random } from "lodash";
|
|
4
4
|
import winston from "winston";
|
|
5
5
|
import { ZERO_ADDRESS } from "../../constants";
|
|
6
6
|
import {
|
|
7
|
+
Log,
|
|
7
8
|
DepositWithBlock,
|
|
8
9
|
FillType,
|
|
9
|
-
V3FundsDepositedEvent,
|
|
10
|
-
RealizedLpFee,
|
|
11
10
|
RelayerRefundExecutionWithBlock,
|
|
12
11
|
SlowFillRequestWithBlock,
|
|
13
12
|
Fill,
|
|
@@ -15,25 +14,20 @@ import {
|
|
|
15
14
|
SlowFillLeaf,
|
|
16
15
|
SpeedUp,
|
|
17
16
|
} from "../../interfaces";
|
|
18
|
-
import {
|
|
17
|
+
import { toBN, toBNWei, getCurrentTime, randomAddress } from "../../utils";
|
|
19
18
|
import { SpokePoolClient, SpokePoolUpdate } from "../SpokePoolClient";
|
|
20
19
|
import { HubPoolClient } from "../HubPoolClient";
|
|
21
20
|
import { EventManager, EventOverrides, getEventManager } from "./MockEvents";
|
|
22
21
|
import { AcrossConfigStoreClient } from "../AcrossConfigStoreClient";
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// This class replaces internal SpokePoolClient functionality, enabling the
|
|
27
|
-
// user to bypass on-chain queries and inject ethers Event objects directly.
|
|
23
|
+
// This class replaces internal SpokePoolClient functionality, enabling
|
|
24
|
+
// the user to bypass on-chain queries and inject Log objects directly.
|
|
28
25
|
export class MockSpokePoolClient extends SpokePoolClient {
|
|
29
26
|
public eventManager: EventManager;
|
|
30
|
-
private realizedLpFeePct: BigNumber = bnZero;
|
|
31
|
-
private realizedLpFeePctOverride = false;
|
|
32
27
|
private destinationTokenForChainOverride: Record<number, string> = {};
|
|
33
28
|
// Allow tester to set the numberOfDeposits() returned by SpokePool at a block height.
|
|
34
29
|
public depositIdAtBlock: number[] = [];
|
|
35
30
|
public numberOfDeposits = 0;
|
|
36
|
-
public blocks: Record<number, Block> = {};
|
|
37
31
|
|
|
38
32
|
constructor(
|
|
39
33
|
logger: winston.Logger,
|
|
@@ -47,36 +41,10 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
47
41
|
this.eventManager = getEventManager(chainId, this.eventSignatures, deploymentBlock);
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
setDefaultRealizedLpFeePct(fee: BigNumber): void {
|
|
51
|
-
this.realizedLpFeePct = fee;
|
|
52
|
-
this.realizedLpFeePctOverride = true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
44
|
setConfigStoreClient(configStore?: AcrossConfigStoreClient): void {
|
|
56
45
|
this.configStoreClient = configStore;
|
|
57
46
|
}
|
|
58
47
|
|
|
59
|
-
clearDefaultRealizedLpFeePct(): void {
|
|
60
|
-
this.realizedLpFeePctOverride = false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async computeRealizedLpFeePct(depositEvent: V3FundsDepositedEvent) {
|
|
64
|
-
const { realizedLpFeePct, realizedLpFeePctOverride } = this;
|
|
65
|
-
const { blockNumber: quoteBlock } = depositEvent;
|
|
66
|
-
return realizedLpFeePctOverride
|
|
67
|
-
? { realizedLpFeePct, quoteBlock }
|
|
68
|
-
: await super.computeRealizedLpFeePct(depositEvent);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async batchComputeRealizedLpFeePct(depositEvents: V3FundsDepositedEvent[]): Promise<RealizedLpFee[]> {
|
|
72
|
-
const { realizedLpFeePct, realizedLpFeePctOverride } = this;
|
|
73
|
-
return realizedLpFeePctOverride
|
|
74
|
-
? depositEvents.map(({ blockNumber: quoteBlock }) => {
|
|
75
|
-
return { realizedLpFeePct, quoteBlock };
|
|
76
|
-
})
|
|
77
|
-
: await super.batchComputeRealizedLpFeePct(depositEvents);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
48
|
setDestinationTokenForChain(chainId: number, token: string): void {
|
|
81
49
|
this.destinationTokenForChainOverride[chainId] = token;
|
|
82
50
|
}
|
|
@@ -107,33 +75,32 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
107
75
|
return Promise.resolve(this.depositIdAtBlock[blockTag]);
|
|
108
76
|
}
|
|
109
77
|
|
|
110
|
-
|
|
78
|
+
_update(eventsToQuery: string[]): Promise<SpokePoolUpdate> {
|
|
111
79
|
// Generate new "on chain" responses.
|
|
112
80
|
const latestBlockSearched = this.eventManager.blockNumber;
|
|
113
81
|
const currentTime = getCurrentTime();
|
|
114
82
|
|
|
115
|
-
const blocks: { [blockNumber: number]: Block } = {};
|
|
116
|
-
|
|
117
83
|
// Ensure an array for every requested event exists, in the requested order.
|
|
118
84
|
// All requested event types must be populated in the array (even if empty).
|
|
119
|
-
const events:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
85
|
+
const events: Log[][] = eventsToQuery.map(() => []);
|
|
86
|
+
this.eventManager
|
|
87
|
+
.getEvents()
|
|
88
|
+
.flat()
|
|
89
|
+
.forEach((event) => {
|
|
90
|
+
const idx = eventsToQuery.indexOf(event.event);
|
|
91
|
+
if (idx !== -1) {
|
|
92
|
+
events[idx].push(event);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
128
95
|
|
|
129
96
|
// Update latestDepositIdQueried.
|
|
130
97
|
const idx = eventsToQuery.indexOf("V3FundsDeposited");
|
|
131
98
|
const latestDepositId = (events[idx] ?? []).reduce(
|
|
132
|
-
(depositId, event) => Math.max(depositId, event.args
|
|
99
|
+
(depositId, event) => Math.max(depositId, (event.args["depositId"] ?? 0) as number),
|
|
133
100
|
this.latestDepositIdQueried
|
|
134
101
|
);
|
|
135
102
|
|
|
136
|
-
return {
|
|
103
|
+
return Promise.resolve({
|
|
137
104
|
success: true,
|
|
138
105
|
firstDepositId: 0,
|
|
139
106
|
latestDepositId,
|
|
@@ -141,7 +108,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
141
108
|
oldestTime: 0,
|
|
142
109
|
events,
|
|
143
110
|
searchEndBlock: this.eventSearchConfig.toBlock || latestBlockSearched,
|
|
144
|
-
};
|
|
111
|
+
});
|
|
145
112
|
}
|
|
146
113
|
|
|
147
114
|
// Event signatures. Not strictly required, but they make generated events more recognisable.
|
|
@@ -151,7 +118,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
151
118
|
FundsDeposited: "uint256,uint256,uint256,int64,uint32,uint32,address,address,address,bytes",
|
|
152
119
|
};
|
|
153
120
|
|
|
154
|
-
depositV3(deposit: DepositWithBlock):
|
|
121
|
+
depositV3(deposit: DepositWithBlock): Log {
|
|
155
122
|
const event = "V3FundsDeposited";
|
|
156
123
|
|
|
157
124
|
const { blockNumber, transactionIndex } = deposit;
|
|
@@ -197,7 +164,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
197
164
|
});
|
|
198
165
|
}
|
|
199
166
|
|
|
200
|
-
fillV3Relay(fill: FillWithBlock):
|
|
167
|
+
fillV3Relay(fill: FillWithBlock): Log {
|
|
201
168
|
const event = "FilledV3Relay";
|
|
202
169
|
|
|
203
170
|
const { blockNumber, transactionIndex } = fill;
|
|
@@ -247,7 +214,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
247
214
|
});
|
|
248
215
|
}
|
|
249
216
|
|
|
250
|
-
speedUpV3Deposit(speedUp: SpeedUp):
|
|
217
|
+
speedUpV3Deposit(speedUp: SpeedUp): Log {
|
|
251
218
|
const event = "RequestedSpeedUpV3Deposit";
|
|
252
219
|
const topics = [speedUp.depositId, speedUp.depositor];
|
|
253
220
|
const args = { ...speedUp };
|
|
@@ -260,7 +227,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
260
227
|
});
|
|
261
228
|
}
|
|
262
229
|
|
|
263
|
-
requestV3SlowFill(request: SlowFillRequestWithBlock):
|
|
230
|
+
requestV3SlowFill(request: SlowFillRequestWithBlock): Log {
|
|
264
231
|
const event = "RequestedV3SlowFill";
|
|
265
232
|
|
|
266
233
|
const { originChainId, depositId } = request;
|
|
@@ -279,7 +246,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
279
246
|
|
|
280
247
|
// This is a simple wrapper around fillV3Relay().
|
|
281
248
|
// rootBundleId and proof are discarded here - we have no interest in verifying that.
|
|
282
|
-
executeV3SlowRelayLeaf(leaf: SlowFillLeaf):
|
|
249
|
+
executeV3SlowRelayLeaf(leaf: SlowFillLeaf): Log {
|
|
283
250
|
const fill: Fill = {
|
|
284
251
|
...leaf.relayData,
|
|
285
252
|
destinationChainId: this.chainId,
|
|
@@ -296,7 +263,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
296
263
|
return this.fillV3Relay(fill as FillWithBlock);
|
|
297
264
|
}
|
|
298
265
|
|
|
299
|
-
executeRelayerRefundLeaf(refund: RelayerRefundExecutionWithBlock):
|
|
266
|
+
executeRelayerRefundLeaf(refund: RelayerRefundExecutionWithBlock): Log {
|
|
300
267
|
const event = "ExecutedRelayerRefundRoot";
|
|
301
268
|
|
|
302
269
|
const chainId = refund.chainId ?? this.chainId;
|
|
@@ -328,7 +295,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
328
295
|
destinationChainId: number,
|
|
329
296
|
enabled: boolean,
|
|
330
297
|
overrides: EventOverrides = {}
|
|
331
|
-
):
|
|
298
|
+
): Log {
|
|
332
299
|
const event = "EnabledDepositRoute";
|
|
333
300
|
|
|
334
301
|
const topics = [originToken, destinationChainId];
|
package/src/contracts/utils.ts
CHANGED
package/src/interfaces/Common.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { Log as _Log } from "@ethersproject/abstract-provider";
|
|
1
2
|
import { BigNumber } from "../utils";
|
|
2
3
|
|
|
4
|
+
export type Log = _Log & {
|
|
5
|
+
event: string;
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
args: { [key: string]: any };
|
|
8
|
+
};
|
|
9
|
+
|
|
3
10
|
export interface SortableEvent {
|
|
4
11
|
blockNumber: number;
|
|
5
12
|
transactionIndex: number;
|
package/src/utils/EventUtils.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { Result } from "@ethersproject/abi";
|
|
2
|
-
|
|
3
|
-
import { SortableEvent } from "../interfaces";
|
|
2
|
+
// eslint-disable-next-line no-restricted-imports
|
|
4
3
|
import { Contract, Event, EventFilter } from "ethers";
|
|
4
|
+
import { Log, SortableEvent } from "../interfaces";
|
|
5
|
+
import { delay } from "./common";
|
|
5
6
|
|
|
6
7
|
const maxRetries = 3;
|
|
7
8
|
const retrySleepTime = 10;
|
|
8
9
|
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
export function spreadEvent(args: Result
|
|
11
|
+
export function spreadEvent(args: Result | Record<string, unknown>): { [key: string]: any } {
|
|
11
12
|
const keys = Object.keys(args).filter((key: string) => isNaN(+key)); // Extract non-numeric keys.
|
|
12
13
|
|
|
13
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
const returnedObject:
|
|
15
|
+
const returnedObject: { [key: string]: unknown } = {};
|
|
15
16
|
keys.forEach((key: string) => {
|
|
16
17
|
switch (typeof args[key]) {
|
|
17
18
|
case "boolean": // fallthrough
|
|
@@ -67,15 +68,18 @@ export interface EventSearchConfig {
|
|
|
67
68
|
maxBlockLookBack?: number;
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
export const eventToLog = (event: Event): Log => ({ ...event, event: event.event!, args: spreadEvent(event.args!) });
|
|
72
|
+
|
|
70
73
|
export async function paginatedEventQuery(
|
|
71
74
|
contract: Contract,
|
|
72
75
|
filter: EventFilter,
|
|
73
76
|
searchConfig: EventSearchConfig,
|
|
74
77
|
retryCount = 0
|
|
75
|
-
): Promise<
|
|
78
|
+
): Promise<Log[]> {
|
|
76
79
|
// If the max block look back is set to 0 then we dont need to do any pagination and can query over the whole range.
|
|
77
80
|
if (searchConfig.maxBlockLookBack === 0) {
|
|
78
|
-
|
|
81
|
+
const events = await contract.queryFilter(filter, searchConfig.fromBlock, searchConfig.toBlock);
|
|
82
|
+
return events.map(eventToLog);
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
// Compute the number of queries needed. If there is no maxBlockLookBack set then we can execute the whole query in
|
|
@@ -93,6 +97,7 @@ export async function paginatedEventQuery(
|
|
|
93
97
|
.flat()
|
|
94
98
|
// Filter events by block number because ranges can include blocks that are outside the range specified for caching reasons.
|
|
95
99
|
.filter((event) => event.blockNumber >= searchConfig.fromBlock && event.blockNumber <= searchConfig.toBlock)
|
|
100
|
+
.map(eventToLog)
|
|
96
101
|
);
|
|
97
102
|
} catch (error) {
|
|
98
103
|
if (retryCount < maxRetries) {
|
|
@@ -163,7 +168,7 @@ export function getPaginatedBlockRanges({
|
|
|
163
168
|
return ranges;
|
|
164
169
|
}
|
|
165
170
|
|
|
166
|
-
export function spreadEventWithBlockNumber(event:
|
|
171
|
+
export function spreadEventWithBlockNumber(event: Log): SortableEvent {
|
|
167
172
|
return {
|
|
168
173
|
...spreadEvent(event.args),
|
|
169
174
|
blockNumber: event.blockNumber,
|