Skip to content

Commit

Permalink
RelayData
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Jan 19, 2024
1 parent 4fe6539 commit 8937271
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/utils/SpokeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FillStatus, RelayData, v2RelayData, v3RelayData } from "../interfaces";
import { SpokePoolClient } from "../clients";
import { bnZero } from "./BigNumberUtils";
import { isDefined } from "./TypeGuards";
import { isV2RelayData } from "./MigrationUtils";
import { getRelayDataOutputAmount, isV2RelayData } from "./MigrationUtils";
import { getNetworkName } from "./NetworkUtils";

/**
Expand Down Expand Up @@ -169,7 +169,7 @@ export async function getDepositIdAtBlock(contract: Contract, blockTag: number):
* @param destinationChainId Supplementary destination chain ID required by V3 hashes.
* @returns The corresponding RelayData hash.
*/
export function getRelayHash(relayData: RelayData, destinationChainId?: number): string {
export function getRelayDataHash(relayData: RelayData, destinationChainId?: number): string {
if (isV2RelayData(relayData)) {
// If destinationChainId was supplied, ensure it matches relayData.
assert(!isDefined(destinationChainId) || destinationChainId === relayData.destinationChainId);
Expand Down Expand Up @@ -233,7 +233,7 @@ export async function relayFilledAmount(
relayData: RelayData,
blockTag?: number | "latest"
): Promise<BigNumber> {
const hash = getRelayHash(relayData);
const hash = getRelayDataHash(relayData);

if (isV2RelayData(relayData)) {
return spokePool.relayFills(hash, { blockTag });
Expand All @@ -248,6 +248,7 @@ export async function relayFilledAmount(

/**
* Find the block at which a fill was completed.
* @todo After SpokePool upgrade, this function can be simplified to use the FillStatus enum.
* @param spokePool SpokePool contract instance.
* @param relayData Deposit information that is used to complete a fill.
* @param lowBlockNumber The lower bound of the search. Must be bounded by SpokePool deployment.
Expand All @@ -272,12 +273,13 @@ export async function findFillBlock(
]);

// Wasn't filled within the specified block range.
if (finalFillAmount.lt(relayData.amount)) {
const relayAmount = getRelayDataOutputAmount(relayData);
if (finalFillAmount.lt(relayAmount)) {
return undefined;
}

// Was filled earlier than the specified lowBlock.. This is an error by the caller.
if (initialFillAmount.eq(relayData.amount)) {
if (initialFillAmount.eq(relayAmount)) {
const { depositId, originChainId } = relayData;
const [srcChain, dstChain] = [getNetworkName(originChainId), getNetworkName(destinationChainId)];
throw new Error(`${srcChain} deposit ${depositId} filled on ${dstChain} before block ${lowBlockNumber}`);
Expand All @@ -288,7 +290,7 @@ export async function findFillBlock(
const midBlockNumber = Math.floor((highBlockNumber + lowBlockNumber) / 2);
const filledAmount = await relayFilledAmount(spokePool, relayData, midBlockNumber);

if (filledAmount.eq(relayData.amount)) {
if (filledAmount.eq(relayAmount)) {
highBlockNumber = midBlockNumber;
} else {
lowBlockNumber = midBlockNumber + 1;
Expand Down

0 comments on commit 8937271

Please sign in to comment.