Skip to content

chore: Drop legacy V3 support #906

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
52 changes: 15 additions & 37 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,9 @@ export class SpokePoolClient extends BaseAbstractClient {
"TokensBridged",
"RelayedRootBundle",
"ExecutedRelayerRefundRoot",
"V3FundsDeposited",
"FundsDeposited",
"RequestedSpeedUpV3Deposit",
"RequestedSpeedUpDeposit",
"RequestedV3SlowFill",
"RequestedSlowFill",
"FilledV3Relay",
"FilledRelay",
];
return Object.fromEntries(
Expand Down Expand Up @@ -328,9 +324,10 @@ export class SpokePoolClient extends BaseAbstractClient {
* @param relayData RelayData field for the SlowFill request.
* @returns The corresponding SlowFillRequest event if found, otherwise undefined.
*/
public getSlowFillRequest(relayData: RelayData): SlowFillRequestWithBlock | undefined {
const messageHash = getMessageHash(relayData.message);
const hash = getRelayEventKey({ ...relayData, messageHash, destinationChainId: this.chainId });
public getSlowFillRequest(
relayData: Omit<RelayData, "message"> & { messageHash: string }
): SlowFillRequestWithBlock | undefined {
const hash = getRelayEventKey({ ...relayData, destinationChainId: this.chainId });
return this.slowFillRequests[hash];
}

Expand Down Expand Up @@ -493,7 +490,7 @@ export class SpokePoolClient extends BaseAbstractClient {
/**
* @notice Return maximum of fill deadline buffer at start and end of block range. This is a contract
* immutable state variable so we can't query other events to find its updates.
* @dev V3 deposits have a fill deadline which can be set to a maximum of fillDeadlineBuffer + deposit.block.timestamp.
* @dev Deposits have a fill deadline which can be set to a maximum of fillDeadlineBuffer + deposit.block.timestamp.
* Therefore, we cannot evaluate a block range for expired deposits if the spoke pool client doesn't return us
* deposits whose block.timestamp is within fillDeadlineBuffer of the end block time. As a conservative check,
* we verify that the time between the end block timestamp and the first timestamp queried by the
Expand Down Expand Up @@ -683,7 +680,7 @@ export class SpokePoolClient extends BaseAbstractClient {
}
};

for (const event of ["V3FundsDeposited", "FundsDeposited"]) {
for (const event of ["FundsDeposited"]) {
if (eventsToQuery.includes(event)) {
await queryDepositEvents(event);
}
Expand Down Expand Up @@ -711,7 +708,7 @@ export class SpokePoolClient extends BaseAbstractClient {
};

// Update deposits with speed up requests from depositor.
["RequestedSpeedUpV3Deposit", "RequestedSpeedUpDeposit"].forEach((event) => {
["RequestedSpeedUpDeposit"].forEach((event) => {
if (eventsToQuery.includes(event)) {
querySpeedUpDepositEvents(event);
}
Expand All @@ -726,10 +723,6 @@ export class SpokePoolClient extends BaseAbstractClient {
destinationChainId: this.chainId,
} as SlowFillRequestWithBlock;

if (eventName === "RequestedV3SlowFill") {
slowFillRequest.messageHash = getMessageHash(slowFillRequest.message);
}

const depositHash = getRelayEventKey({ ...slowFillRequest, destinationChainId: this.chainId });

// Sanity check that this event is not a duplicate.
Expand All @@ -742,7 +735,7 @@ export class SpokePoolClient extends BaseAbstractClient {
}
};

["RequestedV3SlowFill", "RequestedSlowFill"].forEach((event) => {
["RequestedSlowFill"].forEach((event) => {
if (eventsToQuery.includes(event)) {
queryRequestedSlowFillEvents(event);
}
Expand All @@ -766,11 +759,6 @@ export class SpokePoolClient extends BaseAbstractClient {
destinationChainId: this.chainId,
} as FillWithBlock;

if (eventName === "FilledV3Relay") {
fill.messageHash = getMessageHash(event.args.message);
fill.relayExecutionInfo.updatedMessageHash = getMessageHash(event.args.relayExecutionInfo.updatedMessage);
}

// Sanity check that this event is not a duplicate.
const duplicateFill = this.fills[fill.originChainId]?.find((f) => duplicateEvent(fill, f));
if (duplicateFill) {
Expand All @@ -784,7 +772,7 @@ export class SpokePoolClient extends BaseAbstractClient {
};

// Update observed fills with ingested event data.
["FilledV3Relay", "FilledRelay"].forEach((event) => {
["FilledRelay"].forEach((event) => {
if (eventsToQuery.includes(event)) {
queryFilledRelayEvents(event);
}
Expand Down Expand Up @@ -947,23 +935,13 @@ export class SpokePoolClient extends BaseAbstractClient {
);

const tStart = Date.now();
// Check both V3FundsDeposited and FundsDeposited events to look for a specified depositId.
const [fromBlock, toBlock] = [searchBounds.low, searchBounds.high];
const { maxBlockLookBack } = this.eventSearchConfig;
const query = (
await Promise.all([
paginatedEventQuery(
this.spokePool,
this.spokePool.filters.V3FundsDeposited(null, null, null, null, null, depositId),
{ fromBlock, toBlock, maxBlockLookBack }
),
paginatedEventQuery(
this.spokePool,
this.spokePool.filters.FundsDeposited(null, null, null, null, null, depositId),
{ fromBlock, toBlock, maxBlockLookBack }
),
])
).flat();
const query = await paginatedEventQuery(
this.spokePool,
this.spokePool.filters.FundsDeposited(null, null, null, null, null, depositId),
{ fromBlock, toBlock, maxBlockLookBack }
);
const tStop = Date.now();

const event = query.find(({ args }) => args["depositId"].eq(depositId));
Expand Down Expand Up @@ -992,7 +970,7 @@ export class SpokePoolClient extends BaseAbstractClient {

this.logger.debug({
at: "SpokePoolClient#findDeposit",
message: "Located V3 deposit outside of SpokePoolClient's search range",
message: "Located deposit outside of SpokePoolClient's search range",
deposit,
elapsedMs: tStop - tStart,
});
Expand Down
103 changes: 36 additions & 67 deletions src/clients/mocks/MockSpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
bnZero,
bnMax,
bnOne,
toAddress,
toBytes32,
} from "../../utils";
import { SpokePoolClient, SpokePoolUpdate } from "../SpokePoolClient";
Expand Down Expand Up @@ -108,7 +107,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
});

// Update latestDepositIdQueried.
const idx = eventsToQuery.indexOf("V3FundsDeposited");
const idx = eventsToQuery.indexOf("FundsDeposited");
const latestDepositId = (events[idx] ?? []).reduce(
(depositId, event) => bnMax(depositId, event.args["depositId"] ?? bnZero),
this.latestDepositIdQueried
Expand All @@ -134,23 +133,18 @@ export class MockSpokePoolClient extends SpokePoolClient {
return this._deposit("FundsDeposited", deposit);
}

depositV3(deposit: Omit<Deposit, "messageHash"> & Partial<SortableEvent>): Log {
return this._deposit("V3FundsDeposited", deposit);
}

protected _deposit(event: string, deposit: Omit<Deposit, "messageHash"> & Partial<SortableEvent>): Log {
const { blockNumber, transactionIndex } = deposit;
let { depositId, destinationChainId, inputAmount, outputAmount } = deposit;
depositId ??= this.numberOfDeposits;
this.numberOfDeposits = depositId.add(bnOne);

destinationChainId ??= random(1, 42161, false);
const addressModifier = event === "FundsDeposited" ? toBytes32 : toAddress;
const depositor = addressModifier(deposit.depositor ?? randomAddress());
const recipient = addressModifier(deposit.recipient ?? depositor);
const inputToken = addressModifier(deposit.inputToken ?? randomAddress());
const outputToken = addressModifier(deposit.outputToken ?? inputToken);
const exclusiveRelayer = addressModifier(deposit.exclusiveRelayer ?? ZERO_ADDRESS);
const depositor = toBytes32(deposit.depositor ?? randomAddress());
const recipient = toBytes32(deposit.recipient ?? depositor);
const inputToken = toBytes32(deposit.inputToken ?? randomAddress());
const outputToken = toBytes32(deposit.outputToken ?? inputToken);
const exclusiveRelayer = toBytes32(deposit.exclusiveRelayer ?? ZERO_ADDRESS);

inputAmount ??= toBNWei(random(1, 1000, false));
outputAmount ??= inputAmount.mul(toBN("0.95"));
Expand Down Expand Up @@ -185,17 +179,13 @@ export class MockSpokePoolClient extends SpokePoolClient {
});
}

fillV3Relay(fill: Omit<Fill, "messageHash"> & { message: string } & Partial<SortableEvent>): Log {
return this._fillRelay("FilledV3Relay", fill);
}

fillRelay(fill: Omit<Fill, "messageHash"> & { message: string } & Partial<SortableEvent>): Log {
fillRelay(fill: Omit<Fill, "messageHash"> & { message?: string } & Partial<SortableEvent>): Log {
return this._fillRelay("FilledRelay", fill);
}

protected _fillRelay(
event: string,
fill: Omit<Fill, "messageHash"> & { message: string } & Partial<SortableEvent>
fill: Omit<Fill, "messageHash"> & { message?: string } & Partial<SortableEvent>
): Log {
const { blockNumber, transactionIndex } = fill;
let { originChainId, depositId, inputAmount, outputAmount, fillDeadline } = fill;
Expand All @@ -205,15 +195,14 @@ export class MockSpokePoolClient extends SpokePoolClient {
outputAmount ??= inputAmount;
fillDeadline ??= getCurrentTime() + 60;

const addressModifier = event === "FilledRelay" ? toBytes32 : toAddress;
const depositor = addressModifier(fill.depositor ?? randomAddress());
const recipient = addressModifier(fill.recipient ?? depositor);
const inputToken = addressModifier(fill.inputToken ?? randomAddress());
const outputToken = addressModifier(fill.outputToken ?? ZERO_ADDRESS);
const exclusiveRelayer = addressModifier(fill.exclusiveRelayer ?? ZERO_ADDRESS);
const relayer = addressModifier(fill.relayer ?? randomAddress());
const depositor = toBytes32(fill.depositor ?? randomAddress());
const recipient = toBytes32(fill.recipient ?? depositor);
const inputToken = toBytes32(fill.inputToken ?? randomAddress());
const outputToken = toBytes32(fill.outputToken ?? ZERO_ADDRESS);
const exclusiveRelayer = toBytes32(fill.exclusiveRelayer ?? ZERO_ADDRESS);
const relayer = toBytes32(fill.relayer ?? randomAddress());

const topics = [originChainId, depositId, relayer]; // @todo verify
const topics = [originChainId, depositId, relayer];
const message = fill.message ?? EMPTY_MESSAGE;
const updatedMessage = fill.relayExecutionInfo?.updatedMessage ?? message;

Expand Down Expand Up @@ -244,25 +233,14 @@ export class MockSpokePoolClient extends SpokePoolClient {
},
};

const args =
event === "FilledRelay"
? {
..._args,
messageHash: getMessageHash(message),
relayExecutionInfo: {
...relayExecutionInfo,
updatedMessageHash: getMessageHash(updatedMessage),
},
}
: {
// FilledV3Relay
..._args,
message,
relayExecutionInfo: {
...relayExecutionInfo,
updatedMessage,
},
};
const args = {
..._args,
messageHash: getMessageHash(message),
relayExecutionInfo: {
...relayExecutionInfo,
updatedMessageHash: getMessageHash(updatedMessage),
},
};

return this.eventManager.generateEvent({
event,
Expand All @@ -274,17 +252,12 @@ export class MockSpokePoolClient extends SpokePoolClient {
});
}

speedUpV3Deposit(speedUp: SpeedUp): Log {
return this._speedUpDeposit("RequestedSpeedUpV3Deposit", speedUp);
}

speedUpDeposit(speedUp: SpeedUp): Log {
return this._speedUpDeposit("RequestedSpeedUpDeposit", speedUp);
}

protected _speedUpDeposit(event: string, speedUp: SpeedUp): Log {
const addressModifier = event === "RequestedSpeedUpDeposit" ? toBytes32 : toAddress;
const depositor = addressModifier(speedUp.depositor);
const depositor = toBytes32(speedUp.depositor);
const topics = [speedUp.depositId, depositor];
const args = { ...speedUp };

Expand All @@ -295,7 +268,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
args: {
...args,
depositor,
updatedRecipient: addressModifier(speedUp.updatedRecipient),
updatedRecipient: toBytes32(speedUp.updatedRecipient),
},
});
}
Expand All @@ -313,45 +286,41 @@ export class MockSpokePoolClient extends SpokePoolClient {
});
}

requestV3SlowFill(request: Omit<SlowFillRequest, "messageHash"> & Partial<SortableEvent>): Log {
return this._requestSlowFill("RequestedV3SlowFill", request);
}

requestSlowFill(request: Omit<SlowFillRequest, "messageHash"> & Partial<SortableEvent>): Log {
requestSlowFill(request: Omit<SlowFillRequest, "destinationChainId"> & Partial<SortableEvent>): Log {
return this._requestSlowFill("RequestedSlowFill", request);
}

protected _requestSlowFill(
event: string,
request: Omit<SlowFillRequest, "messageHash"> & Partial<SortableEvent>
request: Omit<SlowFillRequest, "destinationChainId"> & Partial<SortableEvent>
): Log {
const { originChainId, depositId } = request;
const topics = [originChainId, depositId];
const args = { ...request };

const addressModifier = event === "RequestedSlowFill" ? toBytes32 : toAddress;
const depositor = addressModifier(args.depositor ?? randomAddress());
const depositor = toBytes32(args.depositor ?? randomAddress());

return this.eventManager.generateEvent({
event,
address: this.spokePool.address,
topics: topics.map((topic) => topic.toString()),
args: {
...args,
destinationChainId: this.chainId,
depositor,
recipient: addressModifier(args.recipient ?? depositor),
inputToken: addressModifier(args.inputToken ?? randomAddress()),
outputToken: addressModifier(args.outputToken ?? ZERO_ADDRESS),
exclusiveRelayer: addressModifier(args.exclusiveRelayer ?? ZERO_ADDRESS),
recipient: toBytes32(args.recipient ?? depositor),
inputToken: toBytes32(args.inputToken ?? randomAddress()),
outputToken: toBytes32(args.outputToken ?? ZERO_ADDRESS),
exclusiveRelayer: toBytes32(args.exclusiveRelayer ?? ZERO_ADDRESS),
},
blockNumber: request.blockNumber,
transactionIndex: request.transactionIndex,
});
}

// This is a simple wrapper around fillV3Relay().
// This is a simple wrapper around fillRelay().
// rootBundleId and proof are discarded here - we have no interest in verifying that.
executeV3SlowRelayLeaf(leaf: Omit<SlowFillLeaf, "messageHash">): Log {
executeSlowRelayLeaf(leaf: Omit<SlowFillLeaf, "messageHash">): Log {
const fill = {
...leaf.relayData,
destinationChainId: this.chainId,
Expand All @@ -366,7 +335,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
},
};

return this.fillV3Relay(fill);
return this.fillRelay(fill);
}

executeRelayerRefundLeaf(refund: RelayerRefundExecution & Partial<SortableEvent>): Log {
Expand Down
5 changes: 1 addition & 4 deletions src/interfaces/SpokePool.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { SortableEvent } from "./Common";
import { FilledV3RelayEvent, V3FundsDepositedEvent } from "../typechain";
import { SpokePoolClient } from "../clients";
import { BigNumber } from "../utils";
import { RelayerRefundLeaf } from "./HubPool";

export type { FilledV3RelayEvent, V3FundsDepositedEvent };

export interface RelayData {
originChainId: number;
depositor: string;
Expand Down Expand Up @@ -79,7 +76,7 @@ export interface SpeedUp {

export interface SpeedUpWithBlock extends SpeedUp, SortableEvent {}

export interface SlowFillRequest extends RelayData {
export interface SlowFillRequest extends Omit<RelayData, "message"> {
messageHash: string;
destinationChainId: number;
}
Expand Down
Loading
Loading