Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add helper methods for usage in Dataworker #535

Merged
merged 229 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 225 commits
Commits
Show all changes
229 commits
Select commit Hold shift + click to select a range
26c1b27
chore: Temporarily import select v3 typechain defs
pxrl Jan 12, 2024
f0408fa
Sync w/ contracts-v2
pxrl Jan 16, 2024
e15cfd2
lint
pxrl Jan 16, 2024
2aff1d7
chore: Prepare for new v3 types
pxrl Jan 15, 2024
2ef2965
chore(SpokePoolClient): Refactor before v3 introduction
pxrl Jan 15, 2024
2d0ed36
Additional types
pxrl Jan 16, 2024
b902f4a
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 16, 2024
c0bea2c
type nits
pxrl Jan 16, 2024
3d9af47
lint
pxrl Jan 16, 2024
e44dc51
SlowFillRequest
pxrl Jan 16, 2024
381c6d4
lint
pxrl Jan 16, 2024
0b6dabf
typo
pxrl Jan 16, 2024
6a95e5f
Merge branch 'pxrl/types-prep' into pxrl/v3Shuffle
pxrl Jan 16, 2024
d180234
Add mocked functions
pxrl Jan 16, 2024
ed507ba
lint
pxrl Jan 16, 2024
13124eb
Simplify slow fill request
pxrl Jan 16, 2024
12257ba
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 16, 2024
7dec756
Tweak speedUp filter
pxrl Jan 16, 2024
e0176e0
Remove unnecessary type assertion
pxrl Jan 17, 2024
0f01aeb
Typo
pxrl Jan 17, 2024
d6f2a33
Add v3RelayData type definition
pxrl Jan 17, 2024
583466c
Add todo
pxrl Jan 17, 2024
157ccb4
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 17, 2024
6586a2a
Type fixes
pxrl Jan 17, 2024
9e2c8e7
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 17, 2024
a31aebf
feat: Support querying v3 RelayData hash
pxrl Jan 17, 2024
10e6088
fix: Remove .only test constraint
pxrl Jan 18, 2024
8192d54
Merge remote-tracking branch 'origin/master' into pxrl/typechain
pxrl Jan 18, 2024
30e755e
Merge remote-tracking branch 'origin/pxrl/typechain' into pxrl/types-…
pxrl Jan 18, 2024
2bf9ffd
Merge remote-tracking branch 'origin/pxrl/fixOnly' into pxrl/typechain
pxrl Jan 18, 2024
948323f
Merge remote-tracking branch 'origin/pxrl/typechain' into pxrl/types-…
pxrl Jan 18, 2024
f41966f
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 18, 2024
51c7bbc
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 18, 2024
3c45b11
Merge branch 'master' into pxrl/types-prep
pxrl Jan 19, 2024
4272725
Add SpeedUps
pxrl Jan 19, 2024
1fb8b1d
lint
pxrl Jan 19, 2024
a2414e4
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 19, 2024
4fe6539
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 19, 2024
8937271
RelayData
pxrl Jan 17, 2024
7901cb5
Rename MigrationUtils -> V3Utils
pxrl Jan 23, 2024
ae02f14
fix: Derive v2 relay hashes locally
pxrl Jan 23, 2024
2bd3b2e
Merge remote-tracking branch 'origin/pxrl/relayHash' into pxrl/types-…
pxrl Jan 23, 2024
8162bd9
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 23, 2024
83a057b
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 23, 2024
083de58
fix: Explicitly append destinationChainId to SlowFill request
pxrl Jan 23, 2024
67d72ae
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 23, 2024
9bd09cf
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 23, 2024
9787518
Update v3 utils
pxrl Jan 24, 2024
25142e0
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 24, 2024
0095ce9
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 24, 2024
06fc1ff
Update MockSpokePoolClient
pxrl Jan 24, 2024
69f6c07
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 24, 2024
4d3a3c2
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 24, 2024
8a6a19c
fix: pad quoteTimestamp in test
pxrl Jan 24, 2024
6a6150e
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 24, 2024
0b6565b
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 24, 2024
c48dcca
Merge remote-tracking branch 'origin/master' into pxrl/types-prep
pxrl Jan 25, 2024
2adc78d
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 25, 2024
291a51a
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 25, 2024
19674d5
Merge remote-tracking branch 'origin/master' into pxrl/types-prep
pxrl Jan 25, 2024
134f12a
Merge remote-tracking branch 'origin/pxrl/types-prep' into pxrl/v3Shu…
pxrl Jan 25, 2024
8d44163
Merge remote-tracking branch 'origin/pxrl/v3Shuffle' into pxrl/relayData
pxrl Jan 25, 2024
6251f2c
Fix typo
pxrl Jan 25, 2024
2164962
Merge branch 'master' into pxrl/relayData
pxrl Jan 26, 2024
9d4e975
Merge branch 'master' into pxrl/relayData
pxrl Jan 26, 2024
64815f9
v3
pxrl Jan 15, 2024
8884af5
Simplify HubPool token resolution
pxrl Jan 29, 2024
74d2406
fix test
pxrl Jan 29, 2024
caca401
Merge remote-tracking branch 'origin/master' into pxrl/v3types
pxrl Jan 30, 2024
da7f989
Merge remote-tracking branch 'origin/master' into pxrl/v3types
pxrl Jan 31, 2024
8537602
refactor: Remove UBAFeeCalculator
pxrl Jan 31, 2024
1b13f1d
Merge remote-tracking branch 'origin/pxrl/ubaFeeCalculator' into pxrl…
pxrl Jan 31, 2024
7f21534
Additional UBA cleanup
pxrl Jan 31, 2024
ff3180d
Back out relayFeeCalculator changes
pxrl Jan 31, 2024
5326db2
Remove flow-related utils
pxrl Jan 31, 2024
ab1b9e4
Merge remote-tracking branch 'origin/pxrl/ubaFeeCalculator' into pxrl…
pxrl Jan 31, 2024
a25750a
Flush unused dependencies
pxrl Jan 31, 2024
1544118
refactor: Prepare relayFeeCalculator for v3 types
pxrl Jan 31, 2024
0496fbb
Merge remote-tracking branch 'origin/pxrl/v3prep' into pxrl/v3types
pxrl Jan 31, 2024
0a069f5
Merge remote-tracking branch 'origin/pxrl/ubaFeeCalculator' into pxrl…
pxrl Jan 31, 2024
5884228
Merge remote-tracking branch 'origin/pxrl/v3prep' into pxrl/v3types
pxrl Jan 31, 2024
df5de18
Sanity check
pxrl Jan 31, 2024
d1c2f72
Back out common
pxrl Jan 31, 2024
b71a1a9
Merge remote-tracking branch 'origin/pxrl/v3prep' into pxrl/v3types
pxrl Jan 31, 2024
b9608c6
Clarify batchCompute behaviour
pxrl Jan 31, 2024
679baa3
Back out unnecessary test change
pxrl Jan 31, 2024
d234dd2
Back out additional unnecessary test change
pxrl Jan 31, 2024
2070b2a
Back out additional unnecessary test change
pxrl Jan 31, 2024
9f5a4a0
Correct RelatyData & v2SlowFillLeaf
pxrl Jan 31, 2024
bb73a9b
Merge remote-tracking branch 'origin/master' into pxrl/v3types
pxrl Feb 1, 2024
981fae0
Tweak isDepositSpedUp
pxrl Feb 1, 2024
202770a
feat: Import SpokePoolV3 ABI
pxrl Feb 2, 2024
300c650
Merge remote-tracking branch 'origin/pxrl/v3ABI' into pxrl/v3types
pxrl Feb 2, 2024
40974d5
Refine test type annotations
pxrl Feb 2, 2024
26fcb22
Fix SlowFillRequested handling & add test
pxrl Feb 2, 2024
81bbbd1
Remove .only test constraint
pxrl Feb 2, 2024
7c2815c
Merge remote-tracking branch 'origin/master' into pxrl/v3types
pxrl Feb 2, 2024
3d64f09
Fix SpeedUp resolution
pxrl Feb 3, 2024
73c2e7e
lint
pxrl Feb 3, 2024
3897754
Update types
pxrl Feb 3, 2024
318282f
feat: Add helper methods
nicholaspai Feb 5, 2024
8ba8e98
Revert "feat: Add helper methods"
nicholaspai Feb 5, 2024
3a8e2db
Merge remote-tracking branch 'origin/master' into pxrl/v3types
pxrl Feb 6, 2024
c00442b
Merge remote-tracking branch 'origin/master' into pxrl/v3types
pxrl Feb 6, 2024
ce02b6b
Sync w/ contracts-v2
pxrl Jan 16, 2024
69cffaf
lint
pxrl Jan 16, 2024
3f56b94
chore: Prepare for new v3 types
pxrl Jan 15, 2024
a3fd949
Additional types
pxrl Jan 16, 2024
96a4357
lint
pxrl Jan 16, 2024
18560de
Add v3RelayData type definition
pxrl Jan 17, 2024
d1f25ed
Type fixes
pxrl Jan 17, 2024
7593720
Rename MigrationUtils -> V3Utils
pxrl Jan 23, 2024
a2b12e1
v3
pxrl Jan 15, 2024
d0082c3
feat: Add helper methods
nicholaspai Feb 5, 2024
049dc9c
Revert "feat: Add helper methods"
nicholaspai Feb 5, 2024
fe53e40
Revert "Revert "feat: Add helper methods""
nicholaspai Feb 5, 2024
6dcfec8
Update SpokeUtils.ts
nicholaspai Feb 6, 2024
5141e0e
WIP
nicholaspai Feb 6, 2024
c7696c1
WIP
nicholaspai Feb 6, 2024
64b2f9d
Update DepositUtils.ts
nicholaspai Feb 6, 2024
2b47e04
wip
nicholaspai Feb 6, 2024
a9006d1
Update SpokePoolClient.ts
nicholaspai Feb 6, 2024
3c2ae0d
WIP
nicholaspai Feb 7, 2024
d05fbf0
Update FlowUtils.ts
nicholaspai Feb 7, 2024
88a1963
Update DepositUtils.ts
nicholaspai Feb 7, 2024
960e6f0
Fix V3Fill destinationChainId
pxrl Feb 7, 2024
3f5bd9b
Define V3 queryableEventNames
pxrl Feb 7, 2024
68c258c
Update HubPoolClient.ts
nicholaspai Feb 7, 2024
7da42dc
Update HubPoolClient.ts
nicholaspai Feb 7, 2024
2ce485b
Fix previous
pxrl Feb 7, 2024
11bc613
Identify type discrimination todos
pxrl Feb 7, 2024
ca8168a
Parse ExecutedV3RelayerRefundRoot events
pxrl Feb 7, 2024
5477bd0
Revert unintended naming change
pxrl Feb 7, 2024
51261a5
lint
pxrl Feb 7, 2024
87ca20e
Merge remote-tracking branch 'origin/master' into HEAD
pxrl Feb 7, 2024
e5b44a1
lint
pxrl Feb 7, 2024
383ebbc
Condense type normalisation block
pxrl Feb 7, 2024
3db1e59
Revert unintended naming change
pxrl Feb 7, 2024
8d96c72
Simplify local SpokePoolClient discriminators
pxrl Feb 7, 2024
6defaed
Remove unnecessary type assertion
pxrl Feb 7, 2024
c6686f6
Revert unnecessary change
pxrl Feb 7, 2024
54f76b7
Specifically test for slowFillRequest destinationChainId
pxrl Feb 7, 2024
04937d1
Correct comment
pxrl Feb 7, 2024
1464df1
Remove realizedLpFeePct from V3Fill
pxrl Feb 7, 2024
df0a43c
Simplify isVXSlowFillLeaf discriminators
pxrl Feb 7, 2024
cf478b0
Complete fill equvalency checks
pxrl Feb 7, 2024
c3b6cb7
10x better tsc hinting on SpeedUp events
pxrl Feb 7, 2024
dc725f0
Update SpokePoolClient.ts
nicholaspai Feb 7, 2024
18a9f6a
Update HubPoolClient.ts
nicholaspai Feb 7, 2024
ba05317
Update SpokePoolClient.ts
nicholaspai Feb 7, 2024
2e58f4a
lint
nicholaspai Feb 7, 2024
5f5c7f4
Fix V3Fill destinationChainId
pxrl Feb 7, 2024
054e438
Define V3 queryableEventNames
pxrl Feb 7, 2024
864b8dd
Fix previous
pxrl Feb 7, 2024
c42e4f2
Identify type discrimination todos
pxrl Feb 7, 2024
8500562
Parse ExecutedV3RelayerRefundRoot events
pxrl Feb 7, 2024
7ca6166
Revert unintended naming change
pxrl Feb 7, 2024
49d24b3
lint
pxrl Feb 7, 2024
750c59e
feat: replace type guards with generics to avoid casting (#537)
mrice32 Feb 7, 2024
d2d4775
lint
pxrl Feb 7, 2024
0e884a0
Condense type normalisation block
pxrl Feb 7, 2024
c32ecb3
Revert unintended naming change
pxrl Feb 7, 2024
13f779f
Simplify local SpokePoolClient discriminators
pxrl Feb 7, 2024
4ef8cb2
Remove unnecessary type assertion
pxrl Feb 7, 2024
4c3ef16
Revert unnecessary change
pxrl Feb 7, 2024
f198639
Specifically test for slowFillRequest destinationChainId
pxrl Feb 7, 2024
d34d52b
Correct comment
pxrl Feb 7, 2024
7d8eeea
Simplify isVXSlowFillLeaf discriminators
pxrl Feb 7, 2024
6bf6a66
Complete fill equvalency checks
pxrl Feb 7, 2024
959543a
10x better tsc hinting on SpeedUp events
pxrl Feb 7, 2024
fdc7480
WIP
nicholaspai Feb 7, 2024
e51abbf
Merge branch 'pxrl/v3types' into npai/helper-v3
nicholaspai Feb 7, 2024
3e68234
rebase
nicholaspai Feb 7, 2024
3e3e5ed
WIP
nicholaspai Feb 7, 2024
b07a670
Update FlowUtils.ts
nicholaspai Feb 7, 2024
f28a5e0
Update HubPoolClient.ts
nicholaspai Feb 7, 2024
2589214
Merge remote-tracking branch 'origin/master' into npai/helper-v3
pxrl Feb 8, 2024
b5b4fc0
Update src/utils/V3Utils.ts
nicholaspai Feb 8, 2024
9516479
Update HubPoolClient.ts
nicholaspai Feb 8, 2024
128f7a7
Update SpokePoolClient.ts
nicholaspai Feb 8, 2024
06ffbf5
Typeguard WIP
nicholaspai Feb 8, 2024
4de36c2
Typeguards WIP
nicholaspai Feb 8, 2024
267d6c1
Revert "Typeguards WIP"
nicholaspai Feb 8, 2024
696a9cb
Revert "Typeguard WIP"
nicholaspai Feb 8, 2024
ccd2e40
Update FlowUtils.ts
nicholaspai Feb 8, 2024
a467a17
Revert "Revert "Typeguard WIP""
nicholaspai Feb 8, 2024
bc6de96
Revert "Revert "Typeguard WIP""
nicholaspai Feb 8, 2024
7f20048
Update TypeGuards.ts
nicholaspai Feb 8, 2024
d4578ff
Update TypeGuards.ts
nicholaspai Feb 8, 2024
9b12e4c
Update HubPoolClient.Utilization.ts
nicholaspai Feb 8, 2024
92257d1
fix tests
nicholaspai Feb 8, 2024
b84cf11
WIP
nicholaspai Feb 9, 2024
80d70be
WIP
nicholaspai Feb 9, 2024
5bda1eb
Update package.json
nicholaspai Feb 9, 2024
0e933c2
spokepool tests pass
nicholaspai Feb 9, 2024
d843c46
lint
nicholaspai Feb 9, 2024
cdf3303
update contracts-v2 version
nicholaspai Feb 9, 2024
cdf6efd
version
nicholaspai Feb 9, 2024
c295e4f
Merge branch 'npai/contracts-v2-2.5.0' into npai/helper-v3
nicholaspai Feb 11, 2024
cbbe3d0
Update SpokeUtils.ts
nicholaspai Feb 11, 2024
d09b7ad
fix
nicholaspai Feb 11, 2024
3bccb18
refactor: Refocus filledRelay utilites on v3
pxrl Feb 11, 2024
73a4fb2
Complete V3 FillStatus test
pxrl Feb 11, 2024
ecb433c
Tweak comments
pxrl Feb 11, 2024
a7adcbf
merge
nicholaspai Feb 11, 2024
682ad42
Update SpokePoolClient.ts
nicholaspai Feb 11, 2024
64a8e06
Merge branch 'master' into npai/helper-v3
nicholaspai Feb 11, 2024
c4f863b
Update SpokePool.ts
nicholaspai Feb 12, 2024
c93be0b
Update ValidatorUtils.ts
nicholaspai Feb 12, 2024
db85599
Merge branch 'master' into npai/helper-v3
nicholaspai Feb 12, 2024
15967b1
Update ValidatorUtils.ts
nicholaspai Feb 12, 2024
36e2b5e
Remove v3 relayer refund leaf
nicholaspai Feb 12, 2024
75421db
Merge branch 'master' into npai/helper-v3
pxrl Feb 13, 2024
9d8696f
Update SpokePoolClient.ts
nicholaspai Feb 13, 2024
1d29cbc
Update V3Utils.ts
nicholaspai Feb 14, 2024
e3bd6af
Update V3Utils.ts
nicholaspai Feb 14, 2024
a7a700e
Merge branch 'master' into npai/helper-v3
nicholaspai Feb 15, 2024
0a0e476
Merge master
nicholaspai Feb 15, 2024
9c1c0bd
Update SpokePoolUtils.ts
nicholaspai Feb 15, 2024
37dc185
Update SpokePoolUtils.ts
nicholaspai Feb 15, 2024
3735b24
Fix
nicholaspai Feb 15, 2024
2dddb22
Update V3Utils.ts
nicholaspai Feb 15, 2024
df94108
Update SpokeUtils.ts
nicholaspai Feb 15, 2024
bef6e15
Update CachingUtils.ts
nicholaspai Feb 15, 2024
5fbb07d
Revert "Update CachingUtils.ts"
nicholaspai Feb 15, 2024
202fa75
Update CachingUtils.ts
nicholaspai Feb 15, 2024
7ed4422
Update CachingUtils.ts
nicholaspai Feb 15, 2024
da8883f
Update CachingUtils.ts
nicholaspai Feb 15, 2024
63d9e6f
Update package.json
nicholaspai Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 108 additions & 9 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ import {
SlowFillRequestWithBlock,
SpeedUp,
TokensBridged,
V2Deposit,
V2DepositWithBlock,
V2Fill,
V2FillWithBlock,
V2SpeedUp,
V3DepositWithBlock,
Expand Down Expand Up @@ -380,6 +382,17 @@ export class SpokePoolClient extends BaseAbstractClient {
return this.slowFillRequests[hash];
}

/**
* Retrieves a list of slow fill requests for deposits from a specific origin chain ID.
* @param originChainId The origin chain ID.
* @returns A list of slow fill requests.
*/
public getSlowFillRequestsForOriginChain(originChainId: number): SlowFillRequestWithBlock[] {
return Object.values(this.slowFillRequests).filter(
(e: SlowFillRequestWithBlock) => e.originChainId === originChainId
);
}

/**
* Find a corresponding deposit for a given fill.
* @param fill The fill to find a corresponding deposit for.
Expand Down Expand Up @@ -526,7 +539,11 @@ export class SpokePoolClient extends BaseAbstractClient {
* @param toBlock The block number to search up to.
* @returns A list of fills that match the given fill and deposit.
*/
public async queryHistoricalMatchingFills(fill: Fill, deposit: Deposit, toBlock: number): Promise<FillWithBlock[]> {
public async queryHistoricalMatchingFills(
fill: V2Fill,
deposit: V2Deposit,
toBlock: number
): Promise<V2FillWithBlock[]> {
const searchConfig = {
fromBlock: this.deploymentBlock,
toBlock,
Expand All @@ -543,7 +560,10 @@ export class SpokePoolClient extends BaseAbstractClient {
* @param searchConfig The search configuration.
* @returns A Promise that resolves to a list of fills that match the given fill.
*/
public async queryFillsInBlockRange(matchingFill: Fill, searchConfig: EventSearchConfig): Promise<FillWithBlock[]> {
public async queryFillsInBlockRange(
matchingFill: V2Fill,
searchConfig: EventSearchConfig
): Promise<V2FillWithBlock[]> {
// Filtering on the fill's depositor address, the only indexed deposit field in the FilledRelay event,
// should speed up this search a bit.
// TODO: Once depositId is indexed in FilledRelay event, filter on that as well.
Expand All @@ -568,7 +588,7 @@ export class SpokePoolClient extends BaseAbstractClient {
),
searchConfig
);
const fills = query.map((event) => spreadEventWithBlockNumber(event) as FillWithBlock);
const fills = query.map((event) => spreadEventWithBlockNumber(event) as V2FillWithBlock);
return sortEventsAscending(fills.filter((_fill) => filledSameDeposit(_fill, matchingFill)));
}

Expand Down Expand Up @@ -769,6 +789,9 @@ export class SpokePoolClient extends BaseAbstractClient {
deposit.realizedLpFeePct = realizedLpFeePct;
deposit.quoteBlockNumber = quoteBlockNumber;

if (this.depositHashes[this.getDepositHash(deposit)] !== undefined) {
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
assign(this.depositHashes, [this.getDepositHash(deposit)], deposit);

if (deposit.depositId < this.earliestDepositIdQueried) {
Expand Down Expand Up @@ -815,6 +838,9 @@ export class SpokePoolClient extends BaseAbstractClient {
destinationChainId: this.chainId,
};
const relayDataHash = getRelayDataHash(slowFillRequest, this.chainId);
if (this.slowFillRequests[relayDataHash] !== undefined) {
continue;
}
this.slowFillRequests[relayDataHash] = slowFillRequest;
}
}
Expand Down Expand Up @@ -863,9 +889,6 @@ export class SpokePoolClient extends BaseAbstractClient {
}
}

// Exact sequencing of relayer refund executions doesn't seem to be important. There are very few consumers of
// these objects, and they are typically used to search for a specific rootBundleId & leafId pair. Therefore,
// relayerRefundExecutions don't need exact sequencing and parsing of v2/v3 events can occur without sorting.
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
if (eventsToQuery.includes("ExecutedRelayerRefundRoot")) {
const refundEvents = queryResults[eventsToQuery.indexOf("ExecutedRelayerRefundRoot")];
for (const event of refundEvents) {
Expand Down Expand Up @@ -1018,7 +1041,7 @@ export class SpokePoolClient extends BaseAbstractClient {
* @returns The deposit if found.
* @note This method is used to find deposits that are outside of the search range of this client.
*/
async findDeposit(depositId: number, destinationChainId: number, depositor: string): Promise<DepositWithBlock> {
async findDeposit(depositId: number, destinationChainId: number, depositor: string): Promise<V2DepositWithBlock> {
// Binary search for block. This way we can get the blocks before and after the deposit with
// deposit ID = fill.depositId and use those blocks to optimize the search for that deposit.
// Stop searches after a maximum # of searches to limit number of eth_call requests. Make an
Expand Down Expand Up @@ -1066,11 +1089,11 @@ export class SpokePoolClient extends BaseAbstractClient {
` between ${srcChain} blocks [${searchBounds.low}, ${searchBounds.high}]`
);
}
const partialDeposit = spreadEventWithBlockNumber(event) as DepositWithBlock;
const partialDeposit = spreadEventWithBlockNumber(event) as V2DepositWithBlock;
const { realizedLpFeePct, quoteBlock: quoteBlockNumber } = (await this.batchComputeRealizedLpFeePct([event]))[0]; // Append the realizedLpFeePct.

// Append destination token and realized lp fee to deposit.
const deposit: DepositWithBlock = {
const deposit: V2DepositWithBlock = {
...partialDeposit,
realizedLpFeePct,
destinationToken: this.getDestinationTokenForDeposit(partialDeposit),
Expand All @@ -1086,4 +1109,80 @@ export class SpokePoolClient extends BaseAbstractClient {

return deposit;
}

async findDepositV3(depositId: number, destinationChainId: number, depositor: string): Promise<V3DepositWithBlock> {
// Binary search for event search bounds. This way we can get the blocks before and after the deposit with
// deposit ID = fill.depositId and use those blocks to optimize the search for that deposit.
// Stop searches after a maximum # of searches to limit number of eth_call requests. Make an
// eth_getLogs call on the remaining block range (i.e. the [low, high] remaining from the binary
// search) to find the target deposit ID.
//
// @dev Limiting between 5-10 searches empirically performs best when there are ~300,000 deposits
// for a spoke pool and we're looking for a deposit <5 days older than HEAD.
const searchBounds = await this._getBlockRangeForDepositId(
depositId,
this.deploymentBlock,
this.latestBlockSearched,
7
);

const tStart = Date.now();
const query = await paginatedEventQuery(
pxrl marked this conversation as resolved.
Show resolved Hide resolved
this.spokePool,
this.spokePool.filters.V3FundsDeposited(
null,
null,
null,
null,
destinationChainId,
depositId,
null,
null,
null,
depositor,
null,
null,
null
),
{
fromBlock: searchBounds.low,
toBlock: searchBounds.high,
maxBlockLookBack: this.eventSearchConfig.maxBlockLookBack,
}
);
const tStop = Date.now();

const event = (query as V3FundsDepositedEvent[]).find((deposit) => deposit.args.depositId === depositId);
if (event === undefined) {
const srcChain = getNetworkName(this.chainId);
const dstChain = getNetworkName(destinationChainId);
throw new Error(
`Could not find deposit ${depositId} for ${dstChain} fill` +
` between ${srcChain} blocks [${searchBounds.low}, ${searchBounds.high}]`
);
}
const partialDeposit = spreadEventWithBlockNumber(event) as V3DepositWithBlock;
const { realizedLpFeePct, quoteBlock: quoteBlockNumber } = (await this.batchComputeRealizedLpFeePct([event]))[0]; // Append the realizedLpFeePct.
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved

// Append destination token and realized lp fee to deposit.
const deposit: V3DepositWithBlock = {
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
...partialDeposit,
originChainId: this.chainId,
realizedLpFeePct,
quoteBlockNumber,
outputToken:
partialDeposit.outputToken === ZERO_ADDRESS
? this.getDestinationTokenForDeposit(partialDeposit)
: partialDeposit.outputToken,
};

this.logger.debug({
at: "SpokePoolClient#findDepositV3",
message: "Located V3 deposit outside of SpokePoolClient's search range",
deposit,
elapsedMs: tStop - tStart,
});

return deposit;
}
}
4 changes: 2 additions & 2 deletions src/interfaces/SpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface RelayerRefundExecution extends RelayerRefundLeaf {
export interface RelayerRefundExecutionWithBlock extends RelayerRefundExecution, SortableEvent {}

export interface UnfilledDeposit {
deposit: Deposit;
deposit: V2Deposit;
unfilledAmount: BigNumber;
hasFirstPartialFill?: boolean;
relayerBalancingFee?: BigNumber;
Expand All @@ -182,7 +182,7 @@ export interface Refund {
export type FillsToRefund = {
[repaymentChainId: number]: {
[l2TokenAddress: string]: {
fills: Fill[];
fills: V2Fill[];
refunds?: Refund;
totalRefundAmount: BigNumber;
realizedLpFees: BigNumber;
Expand Down
12 changes: 6 additions & 6 deletions src/utils/CachingUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL } from "../constants";
import { CachingMechanismInterface, Deposit, Fill } from "../interfaces";
import { CachingMechanismInterface, Deposit, Fill, SlowFillRequest } from "../interfaces";
import { assert } from "./LogUtils";
import { composeRevivers, objectWithBigNumberReviver } from "./ReviverUtils";
import { getCurrentTime } from "./TimeUtils";
Expand Down Expand Up @@ -44,10 +44,10 @@ export async function setDepositInCache(
}

/**
* Resolves the key for caching either a deposit or a fill.
* @param depositOrFill Either a deposit or a fill. In either case, the depositId and originChainId are used to generate the key.
* @returns The key for caching the deposit or fill.
* Resolves the key for caching a bridge event.
* @param bridgeEvent The depositId and originChainId are used to generate the key.
* @returns The key for caching the event.
*/
export function getDepositKey(depositOrFill: Deposit | Fill): string {
return `deposit_${depositOrFill.originChainId}_${depositOrFill.depositId}`;
export function getDepositKey(bridgeEvent: Deposit | Fill | SlowFillRequest): string {
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
return `deposit_${bridgeEvent.originChainId}_${bridgeEvent.depositId}`;
}
12 changes: 8 additions & 4 deletions src/utils/DepositUtils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import assert from "assert";
import { SpokePoolClient } from "../clients";
import { DEFAULT_CACHING_TTL, EMPTY_MESSAGE } from "../constants";
import { CachingMechanismInterface, Deposit, DepositWithBlock, Fill } from "../interfaces";
import { CachingMechanismInterface, Deposit, DepositWithBlock, Fill, SlowFillRequest } from "../interfaces";
import { getNetworkName } from "./NetworkUtils";
import { getDepositInCache, getDepositKey, setDepositInCache } from "./CachingUtils";
import { validateFillForDeposit } from "./FlowUtils";
import { getCurrentTime } from "./TimeUtils";
import { isDefined } from "./TypeGuards";
import { isDepositFormedCorrectly } from "./ValidatorUtils";
import { isV2Deposit, isV3Deposit } from "./V3Utils";
import { isV2Deposit, isV2Fill, isV3Deposit } from "./V3Utils";

// Load a deposit for a fill if the fill's deposit ID is outside this client's search range.
// This can be used by the Dataworker to determine whether to give a relayer a refund for a fill
Expand Down Expand Up @@ -38,7 +38,7 @@ export type DepositSearchResult =
*/
export async function queryHistoricalDepositForFill(
spokePoolClient: SpokePoolClient,
fill: Fill,
fill: Fill | SlowFillRequest,
cache?: CachingMechanismInterface
): Promise<DepositSearchResult> {
if (fill.originChainId !== spokePoolClient.chainId) {
Expand Down Expand Up @@ -98,7 +98,11 @@ export async function queryHistoricalDepositForFill(
if (isDefined(cachedDeposit)) {
deposit = cachedDeposit as DepositWithBlock;
} else {
deposit = await spokePoolClient.findDeposit(fill.depositId, fill.destinationChainId, fill.depositor);
if (isV2Fill(fill)) {
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
deposit = await spokePoolClient.findDeposit(fill.depositId, fill.destinationChainId, fill.depositor);
} else {
deposit = await spokePoolClient.findDepositV3(fill.depositId, fill.destinationChainId, fill.depositor);
}
if (cache) {
await setDepositInCache(deposit, getCurrentTime(), cache, DEFAULT_CACHING_TTL);
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/SpokeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "assert";
import { Contract, utils as ethersUtils } from "ethers";
import { CHAIN_IDs } from "../constants";
import { FillStatus, RelayData, V2RelayData, V3RelayData } from "../interfaces";
import { FillStatus, RelayData, SlowFillRequest, V2RelayData, V3Deposit, V3Fill, V3RelayData } from "../interfaces";
import { SpokePoolClient } from "../clients";
import { isDefined } from "./TypeGuards";
import { isV2RelayData } from "./V3Utils";
Expand Down Expand Up @@ -240,6 +240,9 @@ export function getV3RelayHash(relayData: V3RelayData, destinationChainId: numbe
);
}

export function getV3RelayHashFromEvent(e: V3Deposit | V3Fill | SlowFillRequest): string {
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
return getV3RelayHash(e, e.destinationChainId);
}
/**
* Find the amount filled for a deposit at a particular block.
* @param spokePool SpokePool contract instance.
Expand Down
10 changes: 10 additions & 0 deletions src/utils/V3Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
V3SpeedUp,
} from "../interfaces";
import { BN } from "./BigNumberUtils";
import { fixedPointAdjustment } from "./common";

// Lowest ConfigStore version where the V3 model is in effect. The version update to the following value should take
// place atomically with the SpokePool upgrade to V3 so that the dataworker knows what kind of MerkleLeaves to propose
Expand Down Expand Up @@ -168,3 +169,12 @@ export function getSlowFillLeafChainId<
>(leaf: T | U): number {
return unsafeIsType<U, T>(leaf, "chainId") ? leaf.chainId : leaf.relayData.destinationChainId;
}

export function getSlowFillLeafLpFeePct<
T extends { relayData: { realizedLpFeePct: V2SlowFillLeaf["relayData"]["realizedLpFeePct"] } },
U extends Pick<V3SlowFillLeaf, "updatedOutputAmount" | "relayData">,
>(leaf: T | U): BN {
return unsafeIsType<U, T>(leaf, "updatedOutputAmount")
? leaf.relayData.inputAmount.sub(leaf.updatedOutputAmount).mul(fixedPointAdjustment).div(leaf.relayData.inputAmount)
: leaf.relayData.realizedLpFeePct;
}
32 changes: 29 additions & 3 deletions src/utils/ValidatorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const AddressValidator = define<string>("AddressValidator", (v) => ethers.utils.
const HexValidator = define<string>("HexValidator", (v) => ethers.utils.isHexString(String(v)));
const BigNumberValidator = define<BigNumber>("BigNumberValidator", (v) => ethers.BigNumber.isBigNumber(v));

const DepositSchema = object({
const V2DepositSchema = object({
depositId: Min(integer(), 0),
depositor: AddressValidator,
recipient: AddressValidator,
Expand All @@ -28,9 +28,35 @@ const DepositSchema = object({
logIndex: Min(integer(), 0),
quoteBlockNumber: Min(integer(), 0),
transactionHash: HexValidator,
blockTimestamp: optional(Min(integer(), 0)),
});

const V3DepositSchema = object({
depositId: Min(integer(), 0),
depositor: AddressValidator,
recipient: AddressValidator,
inputToken: AddressValidator,
inputAmount: BigNumberValidator,
originChainId: Min(integer(), 0),
destinationChainId: Min(integer(), 0),
quoteTimestamp: Min(integer(), 0),
fillDeadline: Min(integer(), 0),
exclusivityDeadline: Min(integer(), 0),
exclusiveRelayer: AddressValidator,
realizedLpFeePct: optional(BigNumberValidator),
outputToken: AddressValidator,
outputAmount: BigNumberValidator,
message: string(),
speedUpSignature: optional(HexValidator),
updatedOutputAmount: optional(BigNumberValidator),
updatedRecipient: optional(string()),
updatedMessage: optional(string()),
blockNumber: Min(integer(), 0),
transactionIndex: Min(integer(), 0),
logIndex: Min(integer(), 0),
quoteBlockNumber: Min(integer(), 0),
transactionHash: HexValidator,
});

export function isDepositFormedCorrectly(deposit: unknown): deposit is DepositWithBlock {
return DepositSchema.is(deposit);
return V2DepositSchema.is(deposit) || V3DepositSchema.is(deposit);
}
6 changes: 3 additions & 3 deletions test/utils/SpokePoolUtils.ts
pxrl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export function v3FillFromDeposit(deposit: V3DepositWithBlock, relayer: string):
exclusiveRelayer: relayer,
repaymentChainId: deposit.destinationChainId,
relayExecutionInfo: {
recipient: deposit.updatedRecipient ?? recipient,
message: deposit.updatedMessage ?? message,
outputAmount: deposit.updatedOutputAmount ?? deposit.outputAmount,
updatedRecipient: deposit.updatedRecipient ?? recipient,
updatedMessage: deposit.updatedMessage ?? message,
updatedOutputAmount: deposit.updatedOutputAmount ?? deposit.outputAmount,
fillType: FillType.FastFill,
},
};
Expand Down
8 changes: 4 additions & 4 deletions test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@ export async function fillV3Relay(
exclusiveRelayer: args.exclusiveRelayer,
relayer: args.relayer,
repaymentChainId: Number(args.repaymentChainId),
updatableRelayData: {
recipient: args.relayExecutionInfo.recipient,
message: args.relayExecutionInfo.message,
outputAmount: args.relayExecutionInfo.outputAmount,
relayExecutionInfo: {
updatedRecipient: args.relayExecutionInfo.recipient,
updatedMessage: args.relayExecutionInfo.message,
updatedOutputAmount: args.relayExecutionInfo.outputAmount,
fillType: args.relayExecutionInfo.fillType,
},
blockNumber,
Expand Down
Loading
Loading