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

chore: Remove v2/v3 relayer refund distinctions #555

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 5 additions & 17 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ import {
TokensBridged,
V2DepositWithBlock,
V2FillWithBlock,
V2RelayerRefundExecutionWithBlock,
V2SpeedUp,
V3DepositWithBlock,
V3FillWithBlock,
V3FundsDepositedEvent,
V3RelayData,
V3RelayerRefundExecutionWithBlock,
V3SpeedUp,
} from "../interfaces";
import { SpokePool } from "../typechain";
Expand Down Expand Up @@ -129,8 +127,8 @@ export class SpokePoolClient extends BaseAbstractClient {
"ExecutedRelayerRefundRoot",
"V3FundsDeposited",
"RequestedSpeedUpV3Deposit",
"RequestedV3SlowFill",
"FilledV3Relay",
"ExecutedV3RelayerRefundRoot",
];
return Object.fromEntries(
this.spokePool.interface.fragments
Expand Down Expand Up @@ -868,20 +866,10 @@ 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.
if (eventsToQuery.includes("ExecutedRelayerRefundRoot") || eventsToQuery.includes("ExecutedV3RelayerRefundRoot")) {
const v2RefundEvents = queryResults[eventsToQuery.indexOf("ExecutedRelayerRefundRoot")] ?? [];
for (const event of v2RefundEvents) {
const executedRefund = spreadEventWithBlockNumber(event) as V2RelayerRefundExecutionWithBlock;
executedRefund.l2TokenAddress = SpokePoolClient.getExecutedRefundLeafL2Token(
executedRefund.chainId,
executedRefund.l2TokenAddress
);
this.relayerRefundExecutions.push(executedRefund);
}

const v3RefundEvents = queryResults[eventsToQuery.indexOf("ExecutedV3RelayerRefundRoot")] ?? [];
for (const event of v3RefundEvents) {
const executedRefund = spreadEventWithBlockNumber(event) as V3RelayerRefundExecutionWithBlock;
if (eventsToQuery.includes("ExecutedRelayerRefundRoot")) {
const refundEvents = queryResults[eventsToQuery.indexOf("ExecutedRelayerRefundRoot")];
for (const event of refundEvents) {
const executedRefund = spreadEventWithBlockNumber(event) as RelayerRefundExecutionWithBlock;
executedRefund.l2TokenAddress = SpokePoolClient.getExecutedRefundLeafL2Token(
executedRefund.chainId,
executedRefund.l2TokenAddress
Expand Down
34 changes: 2 additions & 32 deletions src/clients/mocks/MockSpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import {
FillType,
FundsDepositedEvent,
RealizedLpFee,
RelayerRefundExecutionWithBlock,
SlowFillRequestWithBlock,
V2DepositWithBlock,
V2FillWithBlock,
V2RelayerRefundExecutionWithBlock,
V2SpeedUp,
V3DepositWithBlock,
V3Fill,
V3FillWithBlock,
V3RelayerRefundExecutionWithBlock,
V3SlowFillLeaf,
V3SpeedUp,
} from "../../interfaces";
Expand Down Expand Up @@ -403,7 +402,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
return this.fillV3Relay(fill as V3FillWithBlock);
}

executeRelayerRefundLeaf(refund: V2RelayerRefundExecutionWithBlock): Event {
executeRelayerRefundLeaf(refund: RelayerRefundExecutionWithBlock): Event {
const event = "ExecutedRelayerRefundRoot";

const chainId = refund.chainId ?? this.chainId;
Expand All @@ -430,35 +429,6 @@ export class MockSpokePoolClient extends SpokePoolClient {
});
}

executeV3RelayerRefundLeaf(refund: V3RelayerRefundExecutionWithBlock): Event {
const event = "ExecutedV3RelayerRefundRoot";

const chainId = refund.chainId ?? this.chainId;
assert(chainId === this.chainId);

const { rootBundleId, leafId } = refund;
const topics = [chainId, rootBundleId, leafId];
const args = {
chainId,
rootBundleId,
leafId,
amountToReturn: refund.amountToReturn,
l2TokenAddress: refund.l2TokenAddress,
refundAddresses: refund.refundAddresses,
refundAmounts: refund.refundAmounts,
fillsRefundedRoot: refund.fillsRefundedRoot,
fillsRefundedHash: refund.fillsRefundedHash,
};

return this.eventManager.generateEvent({
event,
address: this.spokePool.address,
topics: topics.map((topic) => topic.toString()),
args,
blockNumber: refund.blockNumber,
});
}

setEnableRoute(
originToken: string,
destinationChainId: number,
Expand Down
10 changes: 1 addition & 9 deletions src/interfaces/HubPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface PoolRebalanceLeaf {
l1Tokens: string[];
}

export interface RelayerRefundLeafCommon {
export interface RelayerRefundLeaf {
amountToReturn: BigNumber;
chainId: number;
refundAmounts: BigNumber[];
Expand All @@ -20,14 +20,6 @@ export interface RelayerRefundLeafCommon {
refundAddresses: string[];
}

export interface V2RelayerRefundLeaf extends RelayerRefundLeafCommon {}
export interface V3RelayerRefundLeaf extends RelayerRefundLeafCommon {
fillsRefundedRoot: string;
fillsRefundedHash: string;
}

export type RelayerRefundLeaf = V2RelayerRefundLeaf;

export interface ProposedRootBundle extends SortableEvent {
challengePeriodEndTimestamp: number;
poolRebalanceLeafCount: number;
Expand Down
14 changes: 3 additions & 11 deletions src/interfaces/SpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumber } from "ethers";
import { SortableEvent } from "./Common";
import { FilledRelayEvent, FilledV3RelayEvent, FundsDepositedEvent, V3FundsDepositedEvent } from "../typechain";
import { SpokePoolClient } from "../clients";
import { V2RelayerRefundLeaf, V3RelayerRefundLeaf } from "./HubPool";
import { RelayerRefundLeaf } from "./HubPool";

export type { FilledRelayEvent, FilledV3RelayEvent, FundsDepositedEvent, V3FundsDepositedEvent };

Expand Down Expand Up @@ -159,19 +159,11 @@ export interface RootBundleRelay {

export interface RootBundleRelayWithBlock extends RootBundleRelay, SortableEvent {}

export interface V2RelayerRefundExecution extends V2RelayerRefundLeaf {
export interface RelayerRefundExecution extends RelayerRefundLeaf {
rootBundleId: number;
}

export interface V3RelayerRefundExecution extends V3RelayerRefundLeaf {
rootBundleId: number;
}

export interface V2RelayerRefundExecutionWithBlock extends V2RelayerRefundExecution, SortableEvent {}
export interface V3RelayerRefundExecutionWithBlock extends V3RelayerRefundExecution, SortableEvent {}

export type RelayerRefundExecution = V2RelayerRefundExecution | V3RelayerRefundExecution;
export type RelayerRefundExecutionWithBlock = V2RelayerRefundExecutionWithBlock | V3RelayerRefundExecutionWithBlock;
export interface RelayerRefundExecutionWithBlock extends RelayerRefundExecution, SortableEvent {}

export interface UnfilledDeposit {
deposit: Deposit;
Expand Down
43 changes: 4 additions & 39 deletions src/utils/V3Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@ import {
V2Deposit,
V2Fill,
V2RelayData,
V2RelayerRefundExecution,
V2RelayerRefundLeaf,
V2SlowFillLeaf,
V2SpeedUp,
V3Deposit,
V3Fill,
V3RelayData,
V3RelayerRefundExecution,
V3RelayerRefundLeaf,
V3SlowFillLeaf,
V3SpeedUp,
} from "../interfaces";
import { BN } from "./BigNumberUtils";

// 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 in root bundles (i.e. RelayerRefundLeaf and SlowFillLeaf have different shapes). We assume that
// V3 will be deployed in between bundles (after a bundle execution and before a proposal). The dataworker/relayer
// code can use the following isV3() function to separate logic for calling V3 vs. legacy methods.
// 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
// in root bundles (i.e. SlowFillLeaf has different shapes). The dataworker/relayer code can use the following isV3()
// function to separate logic for calling V3 vs. legacy methods.
export const V3_MIN_CONFIG_STORE_VERSION = 3;

export function isV3(version: number): boolean {
Expand Down Expand Up @@ -102,36 +97,6 @@ export function isV3SlowFillLeaf<T extends MinV3SlowFillLeaf, U extends MinV2Slo
return unsafeIsType<T, U>(slowFillLeaf, "updatedOutputAmount");
}

type MinV2RelayerRefundLeaf = Pick<V2RelayerRefundLeaf, "amountToReturn">;
type MinV3RelayerRefundLeaf = Pick<V3RelayerRefundLeaf, "fillsRefundedRoot" | "fillsRefundedHash">;
export function isV2RelayerRefundLeaf<T extends MinV2RelayerRefundLeaf, U extends MinV3RelayerRefundLeaf>(
leaf: T | U
): leaf is T {
return unsafeIsType<T, U>(leaf, "amountToReturn") && !isV3RelayerRefundLeaf(leaf);
}

export function isV3RelayerRefundLeaf<T extends MinV3RelayerRefundLeaf, U extends MinV2RelayerRefundLeaf>(
leaf: T | U
): leaf is T {
return unsafeIsType<T, U>(leaf, "fillsRefundedRoot");
}

type MinV2RelayerRefundExecution = Pick<V2RelayerRefundExecution, "amountToReturn">;
type MinV3RelayerRefundExecution = Pick<V3RelayerRefundExecution, "fillsRefundedRoot" | "fillsRefundedHash">;
export function isV2RelayerRefundExecution<
T extends MinV2RelayerRefundExecution,
U extends MinV3RelayerRefundExecution,
>(leaf: T | U): leaf is T {
return unsafeIsType<T, U>(leaf, "amountToReturn") && !isV3RelayerRefundExecution(leaf);
}

export function isV3RelayerRefundExecution<
T extends MinV3RelayerRefundExecution,
U extends MinV2RelayerRefundExecution,
>(leaf: T | U): leaf is T {
return unsafeIsType<T, U>(leaf, "fillsRefundedRoot");
}

export function getDepositInputToken<T extends MinV2Deposit, U extends MinV3Deposit>(deposit: T | U): string {
return isV2Deposit(deposit) ? deposit.originToken : deposit.inputToken;
}
Expand Down
Loading
Loading