Skip to content

Commit

Permalink
fix(generic bridges): use scroll's canonical bridge function (across-…
Browse files Browse the repository at this point in the history
…protocol#1708)

Fix Scroll cross-chain adapters:
 - Use the native ERC20 bridge for WETH, rather than the 
   AtomicWethDepositor.
 - Correct the gateways used for USDC transfer tracking.
 - Add Scroll tests.
 - Fix an issue in the new Arbitrum cross-chain adapter. This new 
   adapter is not active in prod yet.

---------

Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig authored and sameersubudhi committed Sep 6, 2024
1 parent c3e4929 commit bd116e7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"node": ">=20"
},
"dependencies": {
"@across-protocol/constants": "^3.1.10",
"@across-protocol/constants": "^3.1.11",
"@across-protocol/contracts": "^3.0.6",
"@across-protocol/sdk": "^3.1.13",
"@across-protocol/sdk": "^3.1.14",
"@arbitrum/sdk": "^3.1.3",
"@aws-sdk/client-kms": "^3.592.0",
"@aws-sdk/client-s3": "^3.592.0",
Expand Down
9 changes: 8 additions & 1 deletion src/adapter/bridges/BaseBridgeAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CHAIN_IDs,
Contract,
BigNumber,
EventSearchConfig,
Expand All @@ -7,6 +8,7 @@ import {
getTranslatedTokenAddress,
assert,
isDefined,
TOKEN_SYMBOLS_MAP,
} from "../../utils";
import { SortableEvent } from "../../interfaces";

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

protected resolveL2TokenAddress(l1Token: string): string {
return getTranslatedTokenAddress(l1Token, this.hubChainId, this.l2chainId, false);
// @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);
}

protected getL1Bridge(): Contract {
Expand Down
9 changes: 0 additions & 9 deletions src/adapter/bridges/ScrollERC20Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ 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 @@ -129,11 +127,4 @@ 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);
}
}
14 changes: 14 additions & 0 deletions src/common/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,20 @@ export const DEFAULT_ARWEAVE_GATEWAY = { url: "arweave.net", port: 443, protocol
// This list should generally exclude Lite chains because the relayer ignores HubPool liquidity in that case.
export const SLOW_WITHDRAWAL_CHAINS = [CHAIN_IDs.ARBITRUM, CHAIN_IDs.BASE, CHAIN_IDs.OPTIMISM];

// We currently support WBTC, USDT, USDC, and WETH as routes on scroll. WBTC, USDT, and USDC transfer events can all be queried from the standard ERC20
// gateway, WETH has its own custom gateways, and other ERC20s may also have their own gateway, so it is very important to define unique gateways (ones
// which are NOT the standard ERC20 gateway) if/when we add new deposit routes.
export const SCROLL_CUSTOM_GATEWAY: { [chainId: number]: { l1: string; l2: string } } = {
[TOKEN_SYMBOLS_MAP.WETH.addresses[CHAIN_IDs.MAINNET]]: {
l1: "0x7AC440cAe8EB6328de4fA621163a792c1EA9D4fE",
l2: "0x7003E7B7186f0E6601203b99F7B8DECBfA391cf9",
},
[TOKEN_SYMBOLS_MAP.USDC.addresses[CHAIN_IDs.MAINNET]]: {
l1: "0xf1AF3b23DE0A5Ca3CAb7261cb0061C0D779A5c7B",
l2: "0x33B60d5Dd260d453cAC3782b0bDC01ce84672142",
},
};

// Expected worst-case time for message from L1 to propogate to L2 in seconds
export const EXPECTED_L1_TO_L2_MESSAGE_TIME = {
[CHAIN_IDs.ARBITRUM]: 20 * 60,
Expand Down
17 changes: 11 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
"@uma/common" "^2.17.0"
hardhat "^2.9.3"

"@across-protocol/constants@^3.1.10", "@across-protocol/constants@^3.1.9":
"@across-protocol/constants@^3.1.11":
version "3.1.11"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.11.tgz#8a55347fd058e1bfad6320f69f13eb5a06399bc6"
integrity sha512-AevN1x1acJVbi6zlH6M8eEKqzANO+H7nfLCChXlrS5vZi8QINs9RvSZX/U/j0UDW1tCbEKszKZcnL1ZM+Pgb0A==

"@across-protocol/constants@^3.1.9":
version "3.1.10"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.10.tgz#37d4f391dc68719c224634073dc8e1ef0445b75d"
integrity sha512-sG1QXVIZAMFsxURMz8U0ZJ2dfX72yjnE/0OGJTcDNcPvuK0MMDU9mFdSZWBtMwIxt0UZSIG/A5059UstT7+Cfg==
Expand Down Expand Up @@ -45,13 +50,13 @@
axios "^1.6.2"
zksync-web3 "^0.14.3"

"@across-protocol/sdk@^3.1.13":
version "3.1.13"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.1.13.tgz#a95b065674d97f5e516b37cac756f1983e1e4ec4"
integrity sha512-qXApbaAnQkpwpGhpX/hZPGA848YB2siwMpWHnIrRao+pl6xpqIBm4C+h93KxfnHnfjbpMX7eaSVy8KtKQyp+JA==
"@across-protocol/sdk@^3.1.14":
version "3.1.14"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.1.14.tgz#511bba54fcc26daaeeafecf7418f18ef1cc845d9"
integrity sha512-qLq3C8SJnZb5r3n2YBNXDQekgwVw06oRjpGmm3lsZq76kiTtTvb8v5E6nnZEYAbqxCnVJOk5f0GyGxfUzLsCaw==
dependencies:
"@across-protocol/across-token" "^1.0.0"
"@across-protocol/constants" "^3.1.10"
"@across-protocol/constants" "^3.1.11"
"@across-protocol/contracts" "^3.0.6"
"@eth-optimism/sdk" "^3.3.1"
"@pinata/sdk" "^2.1.0"
Expand Down

0 comments on commit bd116e7

Please sign in to comment.