Skip to content

Commit

Permalink
fix: [N-01] Adjust zkSync interfaces
Browse files Browse the repository at this point in the history
This change should move the zkSync contract and deployment scripts
closer to the existing patterns established in this repo.
  • Loading branch information
pxrl committed Jul 28, 2023
1 parent bf98ded commit f8801b8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
14 changes: 11 additions & 3 deletions contracts/chain-adapters/ZkSync_Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ contract ZkSync_Adapter is AdapterInterface {
// redeployed in the event that the following addresses change.

// Main contract used to send L1 --> L2 messages. Fetchable via `zks_getMainContract` method on JSON RPC.
ZkSyncInterface public constant zkSync = ZkSyncInterface(0x32400084C286CF3E17e7B677ea9583e60a000324);
ZkSyncInterface public immutable zkSync;
// Bridges to send ERC20 and ETH to L2. Fetchable via `zks_getBridgeContracts` method on JSON RPC.
ZkBridgeLike public constant zkErc20Bridge = ZkBridgeLike(0x57891966931Eb4Bb6FB81430E6cE0A03AAbDe063);
ZkBridgeLike public immutable zkErc20Bridge;

// Set l1Weth at construction time to make testing easier. TODO: Think of some way to be able to hardcode this
// while keeping unit tests easy to write with custom WETH that we can mint/transfer.
Expand All @@ -101,9 +101,17 @@ contract ZkSync_Adapter is AdapterInterface {
/**
* @notice Constructs new Adapter.
* @param _l1Weth WETH address on L1.
* @param _zkSync zkSync mailbox address on L1.
* @param _erc20Bridge zkSync ERC20 bridge address on L1.
*/
constructor(WETH9Interface _l1Weth) {
constructor(
WETH9Interface _l1Weth,
ZkSyncInterface _zkSync,
ZkBridgeLike _zkErc20Bridge
) {
l1Weth = _l1Weth;
zkSync = ZkSyncInterface(_zkSync);
zkErc20Bridge = ZkBridgeLike(_zkErc20Bridge);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions deploy/015_deploy_zksync_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { L1_ADDRESS_MAP } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deployments, getNamedAccounts, getChainId } = hre;

const { deploy } = deployments;

const { deployer } = await getNamedAccounts();
const chainId = parseInt(await getChainId());

// zkSync era contract address can be found at:
// https://era.zksync.io/docs/dev/building-on-zksync/useful-address.html
const { weth, zkSyncMailbox, zkSyncErc20Bridge } = L1_ADDRESS_MAP[chainId];

await deploy("ZkSync_Adapter", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [],
args: [weth, zkSyncMailbox, zkSyncErc20Bridge],
});
};

Expand Down
2 changes: 2 additions & 0 deletions deploy/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const L1_ADDRESS_MAP: { [key: number]: { [contractName: string]: string }
polygonDepositManager: "0x401F6c983eA34274ec46f84D70b31C151321188b",
matic: "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
l2WrappedMatic: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
zkSyncMailbox: "0x32400084C286CF3E17e7B677ea9583e60a000324",
zkSyncErc20Bridge: "0x57891966931Eb4Bb6FB81430E6cE0A03AAbDe063",
},
4: {
weth: "0xc778417E063141139Fce010982780140Aa0cD5Ab",
Expand Down
3 changes: 2 additions & 1 deletion test/chain-adapters/ZkSync_Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ describe("ZkSync Chain Adapter", function () {
address: "0x57891966931Eb4Bb6FB81430E6cE0A03AAbDe063",
});

zkSyncAdapter = await (await getContractFactory("ZkSync_Adapter", owner)).deploy(weth.address);
const constructorArgs = [weth.address, zkSync.address, zkSyncErc20Bridge.address];
zkSyncAdapter = await (await getContractFactory("ZkSync_Adapter", owner)).deploy(...constructorArgs);

// Seed the HubPool some funds so it can send L1->L2 messages.
await hubPool.connect(liquidityProvider).loadEthForL2Calls({ value: toWei("100000") });
Expand Down

0 comments on commit f8801b8

Please sign in to comment.