Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig committed Mar 3, 2025
1 parent f35aa77 commit 16dbd7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/clients/BundleDataClient/utils/FillUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ export async function verifyFillRepayment(
repaymentChainId = fill.destinationChainId;
}

if (!fill.relayer.isValidEvmAddress()) {
if (!fill.relayer.isValidOn(repaymentChainId)) {
// TODO: Handle case where fill was sent on non-EVM chain, in which case the following call would fail
// or return something unexpected. We'd want to return undefined here.
const fillTransaction = await destinationChainProvider.getTransaction(fill.transactionHash);
const destinationRelayer = fillTransaction?.from;
const replacementRelayer = toAddress(destinationRelayer, repaymentChainId, false);
// Repayment chain is still an EVM chain, but the msg.sender is a bytes32 address, so the fill is invalid.
if (!isDefined(destinationRelayer) || !replacementRelayer.isValidEvmAddress()) {
if (!isDefined(destinationRelayer) || !replacementRelayer.isValidOn(repaymentChainId)) {
return undefined;
}
if (!matchedDeposit.fromLiteChain) {
Expand Down
6 changes: 3 additions & 3 deletions src/clients/HubPoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export class HubPoolClient extends BaseAbstractClient {
);
}

getTokenInfo(chainId: number | string, tokenAddress: string): L1Token | undefined {
getTokenInfo(chainId: number | string, tokenAddress: Address): L1Token | undefined {
const deposit = { originChainId: parseInt(chainId.toString()), inputToken: tokenAddress };
return this.getTokenInfoForDeposit(deposit);
}
Expand Down Expand Up @@ -819,8 +819,8 @@ export class HubPoolClient extends BaseAbstractClient {
let runningBalance = toBN(0);
if (executedRootBundle) {
const indexOfL1Token = executedRootBundle.l1Tokens
.map((_l1Token) => _l1Token.toAddress().toLowerCase())
.indexOf(l1Token.toAddress().toLowerCase());
.map((_l1Token) => _l1Token.toAddress())
.indexOf(l1Token.toAddress());
runningBalance = executedRootBundle.runningBalances[indexOfL1Token];
}

Expand Down
8 changes: 8 additions & 0 deletions src/utils/AddressUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ export class Address {
return isSvmAddress(this.toBase58());
}

// Checks if the address is valid on the given chain ID.
isValidOn(chainId: number): boolean {
if (chainIsEvm(chainId)) {
return this.isValidEvmAddress();
}
return this.isValidSvmAddress();
}

// Checks if the object is an address by looking at whether it has an Address constructor.
static isAddress(obj: Record<string, unknown>): boolean {
return obj instanceof Address;
Expand Down

0 comments on commit 16dbd7e

Please sign in to comment.