Skip to content

Commit

Permalink
Merge branch 'master' into pxrl/initialV3Test
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Feb 12, 2024
2 parents dc7152c + 56d371d commit 81daa65
Show file tree
Hide file tree
Showing 21 changed files with 125 additions and 162 deletions.
12 changes: 6 additions & 6 deletions src/clients/mocks/MockSpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ export class MockSpokePoolClient extends SpokePoolClient {
depositor: fill.depositor ?? randomAddress(),
recipient,
message,
updatableRelayData: {
updatedRecipient: fill.updatableRelayData?.recipient ?? recipient,
updatedMessage: fill.updatableRelayData?.message ?? message,
updatedOutputAmount: fill.updatableRelayData?.outputAmount ?? outputAmount,
fillType: fill.updatableRelayData?.fillType ?? FillType.FastFill,
relayExecutionInfo: {
updatedRecipient: fill.relayExecutionInfo?.recipient ?? recipient,
updatedMessage: fill.relayExecutionInfo?.message ?? message,
updatedOutputAmount: fill.relayExecutionInfo?.outputAmount ?? outputAmount,
fillType: fill.relayExecutionInfo?.fillType ?? FillType.FastFill,
},
};

Expand Down Expand Up @@ -392,7 +392,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
destinationChainId: this.chainId,
relayer: ZERO_ADDRESS,
repaymentChainId: 0,
updatableRelayData: {
relayExecutionInfo: {
recipient: leaf.relayData.recipient,
outputAmount: leaf.updatedOutputAmount,
message: leaf.relayData.message,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/SpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export interface V3Fill extends V3RelayData {
destinationChainId: number;
relayer: string;
repaymentChainId: number;
updatableRelayData: V3RelayExecutionEventInfo;
relayExecutionInfo: V3RelayExecutionEventInfo;
}

export interface V2FillWithBlock extends V2Fill, SortableEvent {}
Expand Down
27 changes: 0 additions & 27 deletions src/interfaces/UBA.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from "./ConfigStore";
export * from "./HubPool";
export * from "./SpokePool";
export * from "./Bridge";
export * from "./UBA";
export * from "./Error";
export * from "./TypedData";
export * from "./CachingMechanism";
77 changes: 32 additions & 45 deletions src/utils/FlowUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Deposit, Fill } from "../interfaces";
import { isV2Deposit, isV3Deposit, isV2Fill, isV3Fill } from "./V3Utils";
import { Deposit, Fill, RelayData, SlowFillRequest, V2RelayData, V3Fill } from "../interfaces";
import { getV2RelayHash, getV3RelayHash } from "./SpokeUtils";
import { isV2Deposit, isV2RelayData, isV3Deposit, isV2Fill, isV3Fill } from "./V3Utils";

export const FILL_DEPOSIT_COMPARISON_KEYS = [
"depositId",
Expand Down Expand Up @@ -31,61 +32,47 @@ export const V3_DEPOSIT_COMPARISON_KEYS = [

export function filledSameDeposit(fillA: Fill, fillB: Fill): boolean {
if (isV2Fill(fillA) && isV2Fill(fillB)) {
return (
fillA.depositId === fillB.depositId &&
fillA.originChainId === fillB.originChainId &&
fillA.amount.eq(fillB.amount) &&
fillA.destinationChainId === fillB.destinationChainId &&
fillA.relayerFeePct.eq(fillB.relayerFeePct) &&
fillA.recipient === fillB.recipient &&
fillA.depositor === fillB.depositor &&
fillA.message === fillB.message
);
return getV2RelayHash(fillA) === getV2RelayHash(fillB);
} else if (isV3Fill(fillA) && isV3Fill(fillB)) {
return (
fillA.depositId === fillB.depositId &&
fillA.originChainId === fillB.originChainId &&
fillA.destinationChainId === fillB.destinationChainId &&
fillA.recipient === fillB.recipient &&
fillA.depositor === fillB.depositor &&
fillA.inputToken === fillB.inputToken &&
fillA.outputToken === fillB.outputToken &&
fillA.message === fillB.message &&
fillA.inputAmount.eq(fillB.inputAmount) &&
fillA.outputAmount.eq(fillB.outputAmount) &&
fillA.fillDeadline === fillB.fillDeadline &&
fillA.exclusivityDeadline === fillB.exclusivityDeadline &&
fillA.exclusiveRelayer === fillB.exclusiveRelayer
);
const { destinationChainId: chainA } = fillA;
const { destinationChainId: chainB } = fillB;
return getV3RelayHash(fillA, chainA) === getV3RelayHash(fillB, chainB);
}

return false;
}

// Ensure that each deposit element is included with the same value in the fill. This includes all elements defined
// by the depositor as well as the realizedLpFeePct and the destinationToken, which are pulled from other clients.
export function validateFillForDeposit(fill: Fill, deposit?: Deposit, fillFieldsToIgnore: string[] = []): boolean {
export function validateFillForDeposit(
relayData: RelayData & { destinationChainId: number }, // V2Deposit, V3Fill, SlowFillRequest...
deposit?: Deposit,
fillFieldsToIgnore: string[] = []
): boolean {
if (deposit === undefined) {
return false;
}

if (isV2Deposit(deposit) && isV2Fill(fill)) {
return V2_DEPOSIT_COMPARISON_KEYS.every((key) => {
if (fillFieldsToIgnore.includes(key)) {
return true;
}
return fill[key] !== undefined && fill[key].toString() === deposit[key]?.toString();
});
return isV2RelayData(relayData)
? validateV2FillForDeposit(relayData, deposit, fillFieldsToIgnore)
: validateV3FillForDeposit(relayData, deposit);
}

function validateV2FillForDeposit(fill: V2RelayData, deposit: Deposit, fillFieldsToIgnore: string[] = []): boolean {
if (!isV2Deposit(deposit)) {
return false;
}

if (isV3Deposit(deposit) && isV3Fill(fill)) {
return V3_DEPOSIT_COMPARISON_KEYS.every((key) => {
if (fillFieldsToIgnore.includes(key)) {
return true;
}
return fill[key] !== undefined && fill[key].toString() === deposit[key]?.toString();
});
return V2_DEPOSIT_COMPARISON_KEYS.every((key) => {
if (fillFieldsToIgnore.includes(key)) {
return true;
}
return fill[key] !== undefined && fill[key].toString() === deposit[key]?.toString();
});
}

function validateV3FillForDeposit(fill: V3Fill | SlowFillRequest, deposit: Deposit): boolean {
if (!isV3Deposit(deposit)) {
return false;
}

return false;
return getV3RelayHash(fill, fill.destinationChainId) === getV3RelayHash(deposit, deposit.destinationChainId);
}
4 changes: 2 additions & 2 deletions src/utils/SpokeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId?: numb
* @param relayData V2RelayData information that is used to complete a fill.
* @returns The corresponding RelayData hash.
*/
function getV2RelayHash(relayData: V2RelayData): string {
export function getV2RelayHash(relayData: V2RelayData): string {
return ethersUtils.keccak256(
ethersUtils.defaultAbiCoder.encode(
[
Expand Down Expand Up @@ -215,7 +215,7 @@ function getV2RelayHash(relayData: V2RelayData): string {
* @param destinationChainId Supplementary destination chain ID required by V3 hashes.
* @returns The corresponding RelayData hash.
*/
function getV3RelayHash(relayData: V3RelayData, destinationChainId: number): string {
export function getV3RelayHash(relayData: V3RelayData, destinationChainId: number): string {
return ethersUtils.keccak256(
ethersUtils.defaultAbiCoder.encode(
[
Expand Down
2 changes: 1 addition & 1 deletion src/utils/V3Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function isV3RelayData<T extends MinV3RelayData, U extends MinV2RelayData
}

export function isSlowFill(fill: Fill): boolean {
return isV2Fill(fill) ? fill.updatableRelayData.isSlowRelay : fill.updatableRelayData.fillType === FillType.SlowFill;
return isV2Fill(fill) ? fill.updatableRelayData.isSlowRelay : fill.relayExecutionInfo.fillType === FillType.SlowFill;
}

type MinV2SlowFillLeaf = Pick<V2SlowFillLeaf, "payoutAdjustmentPct">;
Expand Down
4 changes: 2 additions & 2 deletions test/HubPoolClient.DepositToDestinationToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Event } from "ethers";
import {
CONFIG_STORE_VERSION,
destinationChainId,
originChainId,
randomDestinationToken,
randomDestinationToken2,
randomL1Token,
Expand All @@ -12,11 +14,9 @@ import {
SignerWithAddress,
createSpyLogger,
deployConfigStore,
destinationChainId,
ethers,
expect,
getContractFactory,
originChainId,
zeroAddress,
} from "./utils";

Expand Down
6 changes: 3 additions & 3 deletions test/HubPoolClient.Utilization.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
amountToLp,
originChainId,
repaymentChainId,
destinationChainId,
mockTreeRoot,
randomAddress,
refundProposalLiveness,
totalBond,
} from "./constants";
Expand All @@ -20,8 +21,7 @@ import {
expect,
hubPoolFixture,
mineRandomBlocks,
originChainId,
repaymentChainId,
randomAddress,
setupTokensForWallet,
toBN,
toBNWei,
Expand Down
14 changes: 2 additions & 12 deletions test/SpokePoolClient.DepositRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import {
Contract,
createSpyLogger,
deploySpokePool,
destinationChainId,
enableRoutes,
ethers,
expect,
originChainId,
randomAddress,
} from "./utils";

import { SpokePoolClient } from "../src/clients"; // tested
import { originChainId, destinationChainId } from "./constants";
import { Contract, createSpyLogger, deploySpokePool, enableRoutes, ethers, expect, randomAddress } from "./utils";

let spokePool: Contract;

Expand Down
4 changes: 2 additions & 2 deletions test/SpokePoolClient.SpeedUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EMPTY_MESSAGE } from "../src/constants";
import { SpokePoolClient } from "../src/clients";
import { DepositWithBlock, V2DepositWithBlock, V3Deposit, V3DepositWithBlock, V3SpeedUp } from "../src/interfaces";
import { bnOne, isV3Deposit } from "../src/utils";
import { depositRelayerFeePct, destinationChainId, getUpdatedV3DepositSignature, modifyRelayHelper } from "./constants";
import { depositRelayerFeePct, destinationChainId, originChainId } from "./constants";
import {
assert,
assertPromisePasses,
Expand All @@ -17,7 +17,7 @@ import {
enableRoutes,
ethers,
expect,
originChainId,
modifyRelayHelper,
setupTokensForWallet,
simpleDeposit,
toBNWei,
Expand Down
4 changes: 1 addition & 3 deletions test/SpokePoolClient.ValidateFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
validateFillForDeposit,
queryHistoricalDepositForFill,
} from "../src/utils";
import { CHAIN_ID_TEST_LIST, originChainId, destinationChainId, repaymentChainId } from "./constants";
import {
assert,
expect,
Expand All @@ -23,8 +24,6 @@ import {
buildModifiedFill,
deploySpokePoolWithToken,
Contract,
originChainId,
destinationChainId,
createSpyLogger,
zeroAddress,
deployAndConfigureHubPool,
Expand All @@ -38,7 +37,6 @@ import {
winston,
lastSpyLogIncludes,
} from "./utils";
import { CHAIN_ID_TEST_LIST, repaymentChainId } from "./constants";
import { MockConfigStoreClient, MockHubPoolClient, MockSpokePoolClient } from "./mocks";

let spokePool_1: Contract, erc20_1: Contract, spokePool_2: Contract, erc20_2: Contract, hubPool: Contract;
Expand Down
3 changes: 1 addition & 2 deletions test/SpokePoolClient.deposits.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { SpokePoolClient } from "../src/clients";
import { Deposit } from "../src/interfaces";
import { originChainId, destinationChainId } from "./constants";
import {
Contract,
SignerWithAddress,
buildFill,
createSpyLogger,
deploySpokePoolWithToken,
destinationChainId,
ethers,
expect,
originChainId,
setupTokensForWallet,
toBNWei,
} from "./utils";
Expand Down
3 changes: 1 addition & 2 deletions test/SpokePoolClient.fills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ZERO_ADDRESS, EMPTY_MESSAGE } from "../src/constants";
import { SpokePoolClient } from "../src/clients";
import { Deposit, V3Deposit } from "../src/interfaces";
import { bnOne, findFillBlock, getCurrentTime, getNetworkName } from "../src/utils";
import { originChainId, destinationChainId } from "./constants";
import {
assertPromiseError,
Contract,
Expand All @@ -11,10 +12,8 @@ import {
fillV3Relay,
createSpyLogger,
deploySpokePoolWithToken,
destinationChainId,
ethers,
expect,
originChainId,
setupTokensForWallet,
toBNWei,
} from "./utils";
Expand Down
6 changes: 3 additions & 3 deletions test/SpokePoolClient.v3Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import {
hubPoolFixture,
deploySpokePool,
ethers,
contractsV2Utils,
modifyRelayHelper,
SignerWithAddress,
toBNWei,
} from "./utils";
import { modifyRelayHelper } from "./constants";

type EventSearchConfig = sdkUtils.EventSearchConfig;

Expand All @@ -53,7 +53,7 @@ describe("SpokePoolClient: Event Filtering", function () {
const filledRelayEvents = ["FilledRelay", "FilledV3Relay"];
const executedRelayerRefundEvents = ["ExecutedRelayerRefundRoot", "ExecutedV3RelayerRefundRoot"];

let owner: contractsV2Utils.SignerWithAddress, depositor: contractsV2Utils.SignerWithAddress;
let owner: SignerWithAddress, depositor: SignerWithAddress;
let chainIds: number[];
let originChainId: number, destinationChainId: number, repaymentChainId: number;
let hubPoolClient: MockHubPoolClient;
Expand Down
Loading

0 comments on commit 81daa65

Please sign in to comment.