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

improve(relayer): Drop slow fill request queries #1340

Merged
merged 36 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5150ff8
refactor(relayer): Factor out MDC computation
pxrl Mar 20, 2024
44bdb9a
refactor(relayer): Defer deposit MDCs check
pxrl Mar 20, 2024
c34ba19
Merge branch 'master' into pxrl/mdcRefactor
pxrl Mar 20, 2024
244127d
Merge branch 'pxrl/mdcRefactor' into pxrl/deferMDCCheck
pxrl Mar 20, 2024
bfef865
refactor(relayer): Relocate profitability & fill execution
pxrl Mar 20, 2024
489bc6f
simplify
pxrl Mar 20, 2024
55df690
Merge remote-tracking branch 'origin/pxrl/deferMDCCheck' into pxrl/re…
pxrl Mar 20, 2024
78eb55b
lint
pxrl Mar 20, 2024
4e618bb
Exit early
pxrl Mar 20, 2024
9e13803
fixes
pxrl Mar 20, 2024
1df1757
Merge remote-tracking branch 'origin/pxrl/deferMDCCheck' into pxrl/re…
pxrl Mar 20, 2024
40114d6
Merge remote-tracking branch 'origin/master' into pxrl/relayerRefacto…
pxrl Mar 21, 2024
0b3ccf8
Restore logging
pxrl Mar 21, 2024
89cf27b
Merge branch 'master' into pxrl/relayerRefactorEvaluate
pxrl Mar 21, 2024
5a246b9
Merge branch 'master' into pxrl/relayerRefactorEvaluate
pxrl Mar 21, 2024
3eb1877
improve(relayer): Batch query deposit fill status
pxrl Mar 21, 2024
4816ba4
Merge branch 'master' into pxrl/relayerRefactorEvaluate
pxrl Mar 21, 2024
fe7cbc2
Merge branch 'pxrl/relayerRefactorEvaluate' into pxrl/batchFillStatus
pxrl Mar 21, 2024
bf892e2
Improve test
pxrl Mar 21, 2024
05c7bdd
lint
pxrl Mar 21, 2024
8c7b76d
Tweak filter
pxrl Mar 21, 2024
da509bb
Restore comment
pxrl Mar 21, 2024
0d43509
improve(relayer): Drop slow fill request queries
pxrl Mar 21, 2024
b72b550
Fix test
pxrl Mar 21, 2024
7d5076e
Merge branch 'pxrl/batchFillStatus' into pxrl/slowFillRequests
pxrl Mar 21, 2024
d58fb8b
lint
pxrl Mar 21, 2024
9d9225f
Remove redundant Object.values()
pxrl Mar 21, 2024
5d76888
Merge branch 'pxrl/relayerRefactorEvaluate' into pxrl/batchFillStatus
pxrl Mar 21, 2024
2457dca
Merge branch 'pxrl/batchFillStatus' into pxrl/slowFillRequests
pxrl Mar 21, 2024
88cc4b3
Restore comment
pxrl Mar 21, 2024
56477fa
Merge remote-tracking branch 'origin/master' into pxrl/slowFillRequests
pxrl Apr 3, 2024
373dd4d
Fix test
pxrl Apr 3, 2024
fceab85
Drop redundant changes
pxrl Apr 3, 2024
6c87a83
Drop additional redundant change
pxrl Apr 3, 2024
bbb2d3a
Merge branch 'master' into pxrl/slowFillRequests
pxrl Apr 5, 2024
887c17e
Merge branch 'master' into pxrl/slowFillRequests
pxrl Apr 8, 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
38 changes: 19 additions & 19 deletions src/relayer/Relayer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { utils as sdkUtils } from "@across-protocol/sdk-v2";
import { utils as ethersUtils } from "ethers";
import { L1Token, V3Deposit, V3DepositWithBlock } from "../interfaces";
import { FillStatus, L1Token, V3Deposit, V3DepositWithBlock } from "../interfaces";
import {
BigNumber,
bnZero,
Expand Down Expand Up @@ -257,7 +257,12 @@ export class Relayer {
// c) the fill is profitable.
// If all hold true then complete the fill. If there is insufficient balance to complete the fill and slow fills are
// enabled then request a slow fill instead.
async evaluateFill(deposit: V3DepositWithBlock, maxBlockNumber: number, sendSlowRelays: boolean): Promise<void> {
async evaluateFill(
deposit: V3DepositWithBlock,
fillStatus: number,
maxBlockNumber: number,
sendSlowRelays: boolean
): Promise<void> {
const { depositId, depositor, recipient, destinationChainId, originChainId, inputToken } = deposit;
const { hubPoolClient, profitClient, tokenClient } = this.clients;
const { slowDepositors } = this.config;
Expand All @@ -277,17 +282,13 @@ export class Relayer {
}

// If depositor is on the slow deposit list, then send a zero fill to initiate a slow relay and return early.
if (slowDepositors?.includes(depositor)) {
if (sendSlowRelays) {
pxrl marked this conversation as resolved.
Show resolved Hide resolved
this.logger.debug({
at: "Relayer::evaluateFill",
message: "Initiating slow fill for grey listed depositor",
depositor,
});
this.requestSlowFill(deposit);
}
// Regardless of whether we should send a slow fill or not for this depositor, exit early at this point
// so we don't fast fill an already slow filled deposit from the slow fill-only list.
if (slowDepositors?.includes(depositor) && fillStatus === FillStatus.Unfilled) {
this.logger.debug({
at: "Relayer::evaluateFill",
message: "Initiating slow fill for grey listed depositor",
depositor,
});
this.requestSlowFill(deposit);
return;
}

Expand Down Expand Up @@ -324,7 +325,7 @@ export class Relayer {
// TokenClient.getBalance returns that we don't have enough balance to submit the fast fill.
// At this point, capture the shortfall so that the inventory manager can rebalance the token inventory.
tokenClient.captureTokenShortfallForFill(deposit);
if (sendSlowRelays) {
if (sendSlowRelays && fillStatus === FillStatus.Unfilled) {
this.requestSlowFill(deposit);
}
}
Expand All @@ -338,21 +339,20 @@ export class Relayer {
* @returns void
*/
async evaluateFills(
deposits: V3DepositWithBlock[],
deposits: (V3DepositWithBlock & { fillStatus: number })[],
maxBlockNumbers: { [chainId: number]: number },
sendSlowRelays: boolean
): Promise<void> {
for (let i = 0; i < deposits.length; ++i) {
const deposit = deposits[i];
await this.evaluateFill(deposit, maxBlockNumbers[deposit.originChainId], sendSlowRelays);
const { fillStatus, ...deposit } = deposits[i];
await this.evaluateFill(deposit, fillStatus, maxBlockNumbers[deposit.originChainId], sendSlowRelays);
}
}

async checkForUnfilledDepositsAndFill(
sendSlowRelays = true,
simulate = false
): Promise<{ [chainId: number]: string[] }> {
// Fetch all unfilled deposits, order by total earnable fee.
const { profitClient, spokePoolClients, tokenClient, multiCallerClient } = this.clients;

// Flush any pre-existing enqueued transactions that might not have been executed.
Expand Down Expand Up @@ -390,7 +390,7 @@ export class Relayer {
}

await this.evaluateFills(
unfilledDeposits.map(({ deposit }) => deposit),
unfilledDeposits.map(({ deposit, fillStatus }) => ({ ...deposit, fillStatus })),
maxBlockNumbers,
sendSlowRelays
);
Expand Down
1 change: 0 additions & 1 deletion src/relayer/RelayerClientHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export async function updateRelayerClients(clients: RelayerClients, config: Rela
await updateSpokePoolClients(spokePoolClients, [
"V3FundsDeposited",
"RequestedSpeedUpV3Deposit",
"RequestedV3SlowFill",
"FilledV3Relay",
"EnabledDepositRoute",
"RelayedRootBundle",
Expand Down
Loading