Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure refund address is stored correctly #329

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions contracts/chain-adapters/ZkSync_Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,25 @@
// goes live. For now, we'll hardcode these and use aggressive values to ensure inclusion.

// Limit on L2 gas to spend.
uint256 public constant l2GasLimit = 300_000;

Check warning on line 75 in contracts/chain-adapters/ZkSync_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Constant name must be in capitalized SNAKE_CASE

// How much gas is required to publish a byte of data from L1 to L2. 800 is the required value
// as set here https://github.com/matter-labs/era-contracts/blob/6391c0d7bf6184d7f6718060e3991ba6f0efe4a7/ethereum/contracts/zksync/facets/Mailbox.sol#L226
// Note, this value can change and will require an updated adapter.
uint256 public constant l1GasToL2GasPerPubDataLimit = 800;

Check warning on line 80 in contracts/chain-adapters/ZkSync_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Constant name must be in capitalized SNAKE_CASE

// This address receives any remaining fee after an L1 to L2 transaction completes.
// If refund recipient = address(0) then L2 msg.sender is used, unelss msg.sender is a contract then its address
// gets aliased.
address public constant l2RefundAddress = 0x428AB2BA90Eba0a4Be7aF34C9Ac451ab061AC010;
address public immutable l2RefundAddress;

// Hardcode the following ZkSync system contract addresses to save gas on construction. This adapter can be
// 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);

Check warning on line 91 in contracts/chain-adapters/ZkSync_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Constant name must be in capitalized SNAKE_CASE
// Bridges to send ERC20 and ETH to L2. Fetchable via `zks_getBridgeContracts` method on JSON RPC.
ZkBridgeLike public constant zkErc20Bridge = ZkBridgeLike(0x57891966931Eb4Bb6FB81430E6cE0A03AAbDe063);

Check warning on line 93 in contracts/chain-adapters/ZkSync_Adapter.sol

View workflow job for this annotation

GitHub Actions / Solhint (16)

Constant name must be in capitalized SNAKE_CASE

// 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,11 @@
/**
* @notice Constructs new Adapter.
* @param _l1Weth WETH address on L1.
* @param _l2RefundAddress address that recieves excess gas refunds on L2.
*/
constructor(WETH9Interface _l1Weth) {
constructor(WETH9Interface _l1Weth, address _l2RefundAddress) {
l1Weth = _l1Weth;
l2RefundAddress = _l2RefundAddress;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions deploy/015_deploy_zksync_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
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());

await deploy("ZkSync_Adapter", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [],
// Most common across dataworker set as the refund address, but changeable by whoever runs the script.
args: [L1_ADDRESS_MAP[chainId].weth, "0x428AB2BA90Eba0a4Be7aF34C9Ac451ab061AC010"],
});
};

Expand Down
17 changes: 11 additions & 6 deletions test/chain-adapters/ZkSync_Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { smock } from "@defi-wonderland/smock";

let hubPool: Contract, zkSyncAdapter: Contract, weth: Contract, dai: Contract, timer: Contract, mockSpoke: Contract;
let l2Weth: string, l2Dai: string, mainnetWeth: FakeContract;
let owner: SignerWithAddress, dataWorker: SignerWithAddress, liquidityProvider: SignerWithAddress;
let owner: SignerWithAddress,
dataWorker: SignerWithAddress,
liquidityProvider: SignerWithAddress,
refundAddress: SignerWithAddress;
let zkSync: FakeContract, zkSyncErc20Bridge: FakeContract;

const zkSyncChainId = 324;
Expand Down Expand Up @@ -73,7 +76,7 @@ const l2TransactionBaseCost = toWei("0.0001");

describe("ZkSync Chain Adapter", function () {
beforeEach(async function () {
[owner, dataWorker, liquidityProvider] = await ethers.getSigners();
[owner, dataWorker, liquidityProvider, refundAddress] = await ethers.getSigners();
({ weth, dai, l2Weth, l2Dai, hubPool, mockSpoke, timer } = await hubPoolFixture());
await seedWallet(dataWorker, [dai], weth, amountToLp);
await seedWallet(liquidityProvider, [dai], weth, amountToLp.mul(10));
Expand All @@ -93,7 +96,9 @@ describe("ZkSync Chain Adapter", function () {
address: "0x57891966931Eb4Bb6FB81430E6cE0A03AAbDe063",
});

zkSyncAdapter = await (await getContractFactory("ZkSync_Adapter", owner)).deploy(weth.address);
zkSyncAdapter = await (
await getContractFactory("ZkSync_Adapter", owner)
).deploy(weth.address, refundAddress.address);

// Seed the HubPool some funds so it can send L1->L2 messages.
await hubPool.connect(liquidityProvider).loadEthForL2Calls({ value: toWei("100000") });
Expand All @@ -116,7 +121,7 @@ describe("ZkSync Chain Adapter", function () {
await zkSyncAdapter.l2GasLimit(),
await zkSyncAdapter.l1GasToL2GasPerPubDataLimit(),
[],
await zkSyncAdapter.l2RefundAddress()
refundAddress.address
);
expect(zkSync.requestL2Transaction).to.have.been.calledWithValue(l2TransactionBaseCost);
});
Expand All @@ -135,7 +140,7 @@ describe("ZkSync Chain Adapter", function () {
tokensSendToL2,
await zkSyncAdapter.l2GasLimit(),
await zkSyncAdapter.l1GasToL2GasPerPubDataLimit(),
await zkSyncAdapter.l2RefundAddress(),
refundAddress.address,
];
expect(zkSyncErc20Bridge.deposit).to.have.been.calledWith(...expectedErc20L1ToL2BridgeParams);
expect(zkSyncErc20Bridge.deposit).to.have.been.calledWithValue(l2TransactionBaseCost);
Expand All @@ -159,7 +164,7 @@ describe("ZkSync Chain Adapter", function () {
await zkSyncAdapter.l2GasLimit(),
await zkSyncAdapter.l1GasToL2GasPerPubDataLimit(),
[],
await zkSyncAdapter.l2RefundAddress()
refundAddress.address
);
expect(zkSync.requestL2Transaction).to.have.been.calledWithValue(
l2TransactionBaseCost.add(leaves[0].netSendAmounts[0])
Expand Down
Loading