Skip to content

Commit

Permalink
improve(bridges): add special USDC case for the ScrollBridge. (#1720)
Browse files Browse the repository at this point in the history
Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig authored Aug 7, 2024
1 parent ad3a100 commit a395064
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/adapter/bridges/BaseBridgeAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
CHAIN_IDs,
Contract,
BigNumber,
EventSearchConfig,
Expand All @@ -8,7 +7,6 @@ import {
getTranslatedTokenAddress,
assert,
isDefined,
TOKEN_SYMBOLS_MAP,
} from "../../utils";
import { SortableEvent } from "../../interfaces";

Expand Down Expand Up @@ -61,12 +59,7 @@ export abstract class BaseBridgeAdapter {
): Promise<BridgeEvents>;

protected resolveL2TokenAddress(l1Token: string): string {
// @todo: Fix call to `getTranslatedTokenAddress()` such that it does not require
// ifDefined(...). This is incompatible with remote chains where both native and
// bridged USDC are defined.
const isNativeUSDC =
this.l2chainId === CHAIN_IDs.SCROLL && isDefined(TOKEN_SYMBOLS_MAP.USDC.addresses[this.l2chainId]);
return getTranslatedTokenAddress(l1Token, this.hubChainId, this.l2chainId, isNativeUSDC);
return getTranslatedTokenAddress(l1Token, this.hubChainId, this.l2chainId, false);
}

protected getL1Bridge(): Contract {
Expand Down
9 changes: 9 additions & 0 deletions src/adapter/bridges/ScrollERC20Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
fixedPointAdjustment,
isContractDeployedToAddress,
bnZero,
compareAddressesSimple,
TOKEN_SYMBOLS_MAP,
} from "../../utils";
import { CONTRACT_ADDRESSES, SCROLL_CUSTOM_GATEWAY } from "../../common";
import { BaseBridgeAdapter, BridgeTransactionDetails, BridgeEvents } from "./BaseBridgeAdapter";
Expand Down Expand Up @@ -127,4 +129,11 @@ export class ScrollERC20Bridge extends BaseBridgeAdapter {
protected getScrollGatewayRouter(): Contract {
return this.scrollGatewayRouter;
}

protected override resolveL2TokenAddress(l1Token: string): string {
if (compareAddressesSimple(TOKEN_SYMBOLS_MAP.USDC.addresses[this.hubChainId], l1Token)) {
return TOKEN_SYMBOLS_MAP.USDC.addresses[this.l2chainId]; // Scroll only has one USDC token type.
}
return super.resolveL2TokenAddress(l1Token);
}
}

0 comments on commit a395064

Please sign in to comment.