Skip to content
Open
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
52 changes: 27 additions & 25 deletions src/utils/SpokeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,39 @@
} satisfies FillWithBlock;
}

const RELAYDATA_ABI = [
{
type: "tuple",
components: [
{ type: "bytes32", name: "depositor" },
{ type: "bytes32", name: "recipient" },
{ type: "bytes32", name: "exclusiveRelayer" },
{ type: "bytes32", name: "inputToken" },
{ type: "bytes32", name: "outputToken" },
{ type: "uint256", name: "inputAmount" },
{ type: "uint256", name: "outputAmount" },
{ type: "uint256", name: "originChainId" },
{ type: "uint256", name: "depositId" },
{ type: "uint32", name: "fillDeadline" },
{ type: "uint32", name: "exclusivityDeadline" },
{ type: "bytes", name: "message" },
],
},
{ type: "uint256", name: "destinationChainId" },
];

/**
* Compute the RelayData hash for a fill. This can be used to determine the fill status.
* @param relayData RelayData information that is used to complete a fill.
* @param destinationChainId Supplementary destination chain ID required by V3 hashes.
* @returns The corresponding RelayData hash.
*/
export function getRelayDataHash(relayData: RelayData, destinationChainId: number): string {
const abi = [
{
type: "tuple",
components: [
{ type: "bytes32", name: "depositor" },
{ type: "bytes32", name: "recipient" },
{ type: "bytes32", name: "exclusiveRelayer" },
{ type: "bytes32", name: "inputToken" },
{ type: "bytes32", name: "outputToken" },
{ type: "uint256", name: "inputAmount" },
{ type: "uint256", name: "outputAmount" },
{ type: "uint256", name: "originChainId" },
{ type: "uint256", name: "depositId" },
{ type: "uint32", name: "fillDeadline" },
{ type: "uint32", name: "exclusivityDeadline" },
{ type: "bytes", name: "message" },
],
},
{ type: "uint256", name: "destinationChainId" },
];

Check warning on line 144 in src/utils/SpokeUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎`
if (chainIsSvm(destinationChainId)) {
const messageHash = getMessageHash(relayData.message);
return svm.getRelayDataHash({ ...relayData, messageHash }, destinationChainId);
}

const _relayData = {
...relayData,
Expand All @@ -149,11 +155,7 @@
outputToken: relayData.outputToken.toBytes32(),
exclusiveRelayer: relayData.exclusiveRelayer.toBytes32(),
};
if (chainIsSvm(destinationChainId)) {
const messageHash = getMessageHash(relayData.message);
return svm.getRelayDataHash({ ...relayData, messageHash }, destinationChainId);
}
return keccak256(encodeAbiParameters(abi, [_relayData, destinationChainId]));
return keccak256(encodeAbiParameters(RELAYDATA_ABI, [_relayData, destinationChainId]));
}

export function getRelayHashFromEvent(e: RelayData & { destinationChainId: number }): string {
Expand Down
Loading