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

Fix non native tokens updated #15

Merged
merged 10 commits into from
Feb 14, 2024
Merged
53 changes: 39 additions & 14 deletions l1-contracts/contracts/bridge/L1ERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
using SafeERC20 for IERC20;

/// @dev zkSync smart contract that is used to operate with L2 via asynchronous L2 <-> L1 communication
IZkSync internal immutable zkSync;

Check warning on line 33 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 33 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 33 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @dev A mapping L2 batch number => message number => flag
/// @dev Used to indicate that zkSync L2 -> L1 message was already processed
Expand Down Expand Up @@ -87,12 +87,18 @@
uint256 _deployBridgeProxyFee,
uint256 _amount
) external payable reentrancyGuardInitializer {
bool nativeErc20 = _amount != 0;

require(_l2TokenBeacon != address(0), "nf");

Check warning on line 92 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 92 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 92 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements
require(_governor != address(0), "nh");

Check warning on line 93 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 93 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 93 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements
// We are expecting to see the exact three bytecodes that are needed to initialize the bridge
require(_factoryDeps.length == 3, "mk");

Check warning on line 95 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 95 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 95 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements
// The caller miscalculated deploy transactions fees
require(_amount == _deployBridgeImplementationFee + _deployBridgeProxyFee, "fee");
if (nativeErc20) {
require(_amount == _deployBridgeImplementationFee + _deployBridgeProxyFee, "fee");

Check warning on line 98 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 98 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 98 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements
} else {
require(msg.value == _deployBridgeImplementationFee + _deployBridgeProxyFee, "fee");

Check warning on line 100 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 100 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 100 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements
}
l2TokenProxyBytecodeHash = L2ContractHelper.hashL2Bytecode(_factoryDeps[2]);
l2TokenBeacon = _l2TokenBeacon;

Expand Down Expand Up @@ -149,9 +155,18 @@
address _l1Token,
uint256 _amount,
uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte
uint256 _l2TxGasPerPubdataByte,
uint256 _l2MaxFee
) external payable returns (bytes32 l2TxHash) {
l2TxHash = deposit(_l2Receiver, _l1Token, _amount, _l2TxGasLimit, _l2TxGasPerPubdataByte, address(0));
l2TxHash = deposit(
_l2Receiver,
_l1Token,
_amount,
_l2TxGasLimit,
_l2TxGasPerPubdataByte,
address(0),
_l2MaxFee
);
}

/// @notice Initiates a deposit by locking funds on the contract and sending the request
Expand All @@ -164,6 +179,7 @@
/// @param _l2TxGasLimit The L2 gas limit to be used in the corresponding L2 transaction
/// @param _l2TxGasPerPubdataByte The gasPerPubdataByteLimit to be used in the corresponding L2 transaction
/// @param _refundRecipient The address on L2 that will receive the refund for the transaction.
/// @param _l2MaxFee The max fee to be paid in L2.
/// @dev If the L2 deposit finalization transaction fails, the `_refundRecipient` will receive the `_l2Value`.
/// Please note, the contract may change the refund recipient's address to eliminate sending funds to addresses
/// out of control.
Expand All @@ -184,35 +200,44 @@
uint256 _amount,
uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte,
address _refundRecipient
address _refundRecipient,
uint256 _l2MaxFee
) public payable nonReentrant returns (bytes32 l2TxHash) {
require(_amount != 0, "2T"); // empty deposit amount

Check warning on line 206 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 206 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 206 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements
uint256 amount = _depositFunds(msg.sender, IERC20(_l1Token), _amount);
require(amount == _amount, "1T"); // The token has non-standard transfer logic

Check warning on line 208 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 208 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 208 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

l2TxHash = _getRefundRecipientAndRequestL2Transaction(_refundRecipient, _l2MaxFee, _l2Receiver, _l1Token, _l2TxGasLimit, _l2TxGasPerPubdataByte, amount);
// Save the deposited amount to claim funds on L1 if the deposit failed on L2
depositAmount[msg.sender][_l1Token][l2TxHash] = amount;
emit DepositInitiated(l2TxHash, msg.sender, _l2Receiver, _l1Token, amount);
}

function _getRefundRecipientAndRequestL2Transaction(address _refundRecipient, uint256 _l2MaxFee, address _l2Receiver, address _l1Token, uint256 _l2TxGasLimit, uint256 _l2TxGasPerPubdataByte, uint256 amount) internal returns (bytes32) {
bytes memory l2TxCalldata = _getDepositL2Calldata(msg.sender, _l2Receiver, _l1Token, amount);
// If the refund recipient is not specified, the refund will be sent to the sender of the transaction.
// Otherwise, the refund will be sent to the specified address.
// If the recipient is a contract on L1, the address alias will be applied.
address refundRecipient = _refundRecipient;
if (_refundRecipient == address(0)) {
refundRecipient = msg.sender != tx.origin ? AddressAliasHelper.applyL1ToL2Alias(msg.sender) : msg.sender;
}
l2TxHash = zkSync.requestL2Transaction{value: msg.value}(
address refundRecipient = _getRefundRecipient(_refundRecipient);

return zkSync.requestL2Transaction{value: msg.value}(
l2Bridge,
0, // L2 msg.value
0,
_l2MaxFee,
l2TxCalldata,
_l2TxGasLimit,
_l2TxGasPerPubdataByte,
new bytes[](0),
refundRecipient
);
}

// Save the deposited amount to claim funds on L1 if the deposit failed on L2
depositAmount[msg.sender][_l1Token][l2TxHash] = amount;

emit DepositInitiated(l2TxHash, msg.sender, _l2Receiver, _l1Token, amount);
// Refund recipient logic
function _getRefundRecipient(address _refundRecipient) internal view returns (address) {
return
_refundRecipient == address(0)
? (msg.sender != tx.origin ? AddressAliasHelper.applyL1ToL2Alias(msg.sender) : msg.sender)

Check warning on line 239 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 239 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 239 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin
: _refundRecipient;
}

/// @dev Transfers tokens from the depositor address to the smart contract address
Expand Down Expand Up @@ -273,7 +298,7 @@
_merkleProof,
TxStatus.Failure
);
require(proofValid, "yn");

Check warning on line 301 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 301 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

Check warning on line 301 in l1-contracts/contracts/bridge/L1ERC20Bridge.sol

View workflow job for this annotation

GitHub Actions / lint

Use Custom Errors instead of require statements

uint256 amount = depositAmount[_depositSender][_l1Token][_l2TxHash];
require(amount > 0, "y1");
Expand Down
20 changes: 14 additions & 6 deletions l1-contracts/contracts/bridge/L1WethBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,20 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard {
uint256 _deployBridgeProxyFee,
uint256 _amount
) external payable reentrancyGuardInitializer {
bool nativeErc20 = _amount != 0;

require(_l2WethAddress != address(0), "L2 WETH address cannot be zero");
require(_governor != address(0), "Governor address cannot be zero");
require(_factoryDeps.length == 2, "Invalid factory deps length provided");
require(
_amount == _deployBridgeImplementationFee + _deployBridgeProxyFee,
"Miscalculated deploy transactions fees"
);

if (nativeErc20) {
require(
_amount == _deployBridgeImplementationFee + _deployBridgeProxyFee,
"Miscalculated deploy transactions fees"
);
} else {
require(msg.value == _deployBridgeImplementationFee + _deployBridgeProxyFee, "Miscalculated deploy transactions fees");
}

l2WethAddress = _l2WethAddress;

Expand Down Expand Up @@ -164,7 +171,8 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard {
uint256 _amount,
uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte,
address _refundRecipient
address _refundRecipient,
uint256 _l2MaxFee
) external payable nonReentrant returns (bytes32 txHash) {
require(_l1Token == l1WethAddress, "Invalid L1 token address");
require(_amount != 0, "Amount cannot be zero");
Expand All @@ -187,7 +195,7 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard {
txHash = zkSync.requestL2Transaction{value: _amount + msg.value}(
l2Bridge,
_amount,
0,
_l2MaxFee,
l2TxCalldata,
_l2TxGasLimit,
_l2TxGasPerPubdataByte,
Expand Down
3 changes: 2 additions & 1 deletion l1-contracts/contracts/bridge/interfaces/IL1Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ interface IL1Bridge {
uint256 _amount,
uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte,
address _refundRecipient
address _refundRecipient,
uint256 _l2MaxFee
) external payable returns (bytes32 txHash);

function claimFailedDeposit(
Expand Down
3 changes: 2 additions & 1 deletion l1-contracts/contracts/bridge/interfaces/IL1BridgeLegacy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IL1BridgeLegacy {
address _l1Token,
uint256 _amount,
uint256 _l2TxGasLimit,
uint256 _l2TxGasPerPubdataByte
uint256 _l2TxGasPerPubdataByte,
uint256 _l2MaxFee
) external payable returns (bytes32 txHash);
}
45 changes: 26 additions & 19 deletions l1-contracts/contracts/zksync/facets/Mailbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// While formally the following import is not used, it is needed to inherit documentation from it
import {IBase} from "../interfaces/IBase.sol";

bool constant NATIVE_ERC20 = $(NATIVE_ERC20);

/// @title zkSync Mailbox contract providing interfaces for L1 <-> L2 interaction.
/// @author Matter Labs
/// @custom:security-contact security@matterlabs.dev
Expand Down Expand Up @@ -173,8 +175,7 @@ contract MailboxFacet is Base, IMailbox {
bytes calldata _message,
bytes32[] calldata _merkleProof
) external nonReentrant {
// #def TOKEN_TYPE 'ERC20'
// #if TOKEN_TYPE == 'ETH'
// #if NATIVE_ERC20 == false
require(!s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "jj");

L2Message memory l2ToL1Message = L2Message({
Expand All @@ -183,16 +184,16 @@ contract MailboxFacet is Base, IMailbox {
data: _message
});

(address _l1WithdrawReceiver, address _t, uint256 _amount) = _parseL2WithdrawalMessage(_message);
(address _l1WithdrawReceiver, uint256 _amount) = _parseL2WithdrawalMessage(_message);
{
bool proofValid = proveL2MessageInclusion(_l2BatchNumber, _l2MessageIndex, l2ToL1Message, _merkleProof);
require(proofValid, "pi"); // Failed to verify that withdrawal was actually initialized on L2
}
s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex] = true;
_withdrawFunds(_l1WithdrawReceiver, _amount);

emit EthWithdrawalFinalized(_l1WithdrawReceiver, _amount);
// #elif TOKEN_TYPE == 'ERC20'
// #elif NATIVE_ERC20 == true
require(!s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "pw");

L2Message memory l2ToL1Message = L2Message({
Expand Down Expand Up @@ -230,10 +231,10 @@ contract MailboxFacet is Base, IMailbox {
) external payable nonReentrant returns (bytes32 canonicalTxHash) {
// Change the sender address if it is a smart contract to prevent address collision between L1 and L2.
// Please note, currently zkSync address derivation is different from Ethereum one, but it may be changed in the future.
// address sender = msg.sender;
// if (sender != tx.origin) {
// sender = AddressAliasHelper.applyL1ToL2Alias(msg.sender);
// }
address sender = msg.sender;
if (sender != tx.origin) {
sender = AddressAliasHelper.applyL1ToL2Alias(msg.sender);
}

// Enforcing that `_l2GasPerPubdataByteLimit` equals to a certain constant number. This is needed
// to ensure that users do not get used to using "exotic" numbers for _l2GasPerPubdataByteLimit, e.g. 1-2, etc.
Expand All @@ -243,7 +244,7 @@ contract MailboxFacet is Base, IMailbox {
require(_l2GasPerPubdataByteLimit == REQUIRED_L2_GAS_PRICE_PER_PUBDATA, "qp");

canonicalTxHash = _requestL2Transaction(
msg.sender,
sender,
_contractL2,
_l2Value,
_amount,
Expand Down Expand Up @@ -273,12 +274,15 @@ contract MailboxFacet is Base, IMailbox {
// Here we manually assign fields for the struct to prevent "stack too deep" error
WritePriorityOpParams memory params;

uint256 amount = _amount != 0 ? _amount : msg.value;
// uint256 amount = msg.value;

// Checking that the user provided enough ether to pay for the transaction.
// Using a new scope to prevent "stack too deep" error
{
params.l2GasPrice = _isFree ? 0 : _deriveL2GasPrice(tx.gasprice, _l2GasPerPubdataByteLimit);
uint256 baseCost = params.l2GasPrice * _l2GasLimit;
require(_amount >= baseCost + _l2Value, "mv"); // The `msg.value` doesn't cover the transaction cost
require(amount >= baseCost + _l2Value, "mv"); // The `amount` doesn't cover the transaction cost
}

// If the `_refundRecipient` is not provided, we use the `_sender` as the recipient.
Expand All @@ -288,22 +292,25 @@ contract MailboxFacet is Base, IMailbox {
refundRecipient = AddressAliasHelper.applyL1ToL2Alias(refundRecipient);
}

// The address of the token that is used in the L2 as native.
address nativeTokenAddress = address($(L1_NATIVE_TOKEN_ADDRESS));
// Check balance and allowance.
require(IERC20(nativeTokenAddress).balanceOf(tx.origin) >= _amount, "Not enough balance");
require(IERC20(nativeTokenAddress).allowance(tx.origin, address(this)) >= _amount, "Not enough allowance");
// Check if we are operating with native tokens.
if (_amount != 0) {
// The address of the token that is used in the L2 as native.
address nativeTokenAddress = address($(L1_NATIVE_TOKEN_ADDRESS));
// Check balance and allowance.
require(IERC20(nativeTokenAddress).balanceOf(tx.origin) >= amount, "Not enough balance");
require(IERC20(nativeTokenAddress).allowance(tx.origin, address(this)) >= amount, "Not enough allowance");

// Transfer tokens to the contract.
IERC20(nativeTokenAddress).safeTransferFrom(tx.origin, address(this), _amount);
// Transfer tokens to the contract.
IERC20(nativeTokenAddress).safeTransferFrom(tx.origin, address(this), amount);
}

params.sender = _sender;
params.txId = s.priorityQueue.getTotalPriorityTxs();
params.l2Value = _l2Value;
params.contractAddressL2 = _contractAddressL2;
params.expirationTimestamp = uint64(block.timestamp + PRIORITY_EXPIRATION);
params.l2GasLimit = _l2GasLimit;
params.valueToMint = _amount;
params.valueToMint = amount;
params.l2GasPricePerPubdata = _l2GasPerPubdataByteLimit;
params.refundRecipient = refundRecipient;

Expand Down
1 change: 1 addition & 0 deletions l1-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
let testConfigFile = fs.readFileSync(`${testConfigPath}/native_erc20.json`, { encoding: "utf-8" });

if (testConfigFile === "") {
testConfigFile = '{ "address": "0x0" }';

Check failure on line 31 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

Check failure on line 31 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

Check failure on line 31 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
}

const nativeERC20Token = JSON.parse(testConfigFile);
Expand Down Expand Up @@ -105,17 +105,18 @@
defs: (() => {
const defs = process.env.CONTRACT_TESTS ? contractDefs.test : contractDefs[process.env.CHAIN_ETH_NETWORK];

let path = `${process.env.ZKSYNC_HOME}/etc/tokens/native_erc20.json`;

Check failure on line 108 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'path' is never reassigned. Use 'const' instead

Check failure on line 108 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'path' is never reassigned. Use 'const' instead

Check failure on line 108 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'path' is never reassigned. Use 'const' instead
let rawData = fs.readFileSync(path, "utf8");

Check failure on line 109 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'rawData' is never reassigned. Use 'const' instead

Check failure on line 109 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'rawData' is never reassigned. Use 'const' instead

Check failure on line 109 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'rawData' is never reassigned. Use 'const' instead
let address = "0x52312AD6f01657413b2eaE9287f6B9ADaD93D5FE";
try {
let jsonConfig = JSON.parse(rawData);

Check failure on line 112 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'jsonConfig' is never reassigned. Use 'const' instead

Check failure on line 112 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'jsonConfig' is never reassigned. Use 'const' instead

Check failure on line 112 in l1-contracts/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint

'jsonConfig' is never reassigned. Use 'const' instead
address = jsonConfig.address;
} catch (_e) {
address = "0x52312AD6f01657413b2eaE9287f6B9ADaD93D5FE";
}

return {
NATIVE_ERC20: process.env.NATIVE_ERC20,
NATIVE_ERC20_ADDRESS: address,
...systemParams,
...defs,
Expand Down
10 changes: 7 additions & 3 deletions l1-contracts/scripts/initialize-bridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@
.option("--gas-price <gas-price>")
.option("--nonce <nonce>")
.option("--erc20-bridge <erc20-bridge>")
.option("--native-erc20")
.action(async (cmd) => {
const deployWallet = cmd.privateKey
? new Wallet(cmd.privateKey, provider)
: Wallet.fromMnemonic(
process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic,
"m/44'/60'/0'/0/0"

Check failure on line 70 in l1-contracts/scripts/initialize-bridges.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`

Check failure on line 70 in l1-contracts/scripts/initialize-bridges.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`

Check failure on line 70 in l1-contracts/scripts/initialize-bridges.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
).connect(provider);

const nativeErc20impl = cmd.nativeErc20 ? true : false;
console.log(`Using native erc20: ${nativeErc20impl}`);

console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
Expand Down Expand Up @@ -152,7 +157,7 @@
zkSync.requestL2Transaction(
ethers.constants.AddressZero,
0,
requiredValueToPublishBytecodes,
nativeErc20impl ? requiredValueToPublishBytecodes : 0,
"0x",
priorityTxMaxGasLimit,
SYSTEM_CONFIG.requiredL2GasPricePerPubdata,
Expand All @@ -166,15 +171,14 @@
l2GovernorAddress,
requiredValueToInitializeBridge,
requiredValueToInitializeBridge,
requiredValueToInitializeBridge.mul(2),
nativeErc20impl ? requiredValueToInitializeBridge.mul(2) : 0,
{
gasPrice,
nonce: nonce + 1,
value: requiredValueToInitializeBridge.mul(2),
}
),
];

const txs = await Promise.all(independentInitialization);
for (const tx of txs) {
console.log(`Transaction sent with hash ${tx.hash} and nonce ${tx.nonce}. Waiting for receipt...`);
Expand Down
7 changes: 6 additions & 1 deletion l1-contracts/scripts/initialize-l2-weth-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
.option("--private-key <private-key>")
.option("--gas-price <gas-price>")
.option("--nonce <nonce>")
.option('--native-erc20')

Check failure on line 127 in l1-contracts/scripts/initialize-l2-weth-token.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'--native-erc20'` with `"--native-erc20"`

Check failure on line 127 in l1-contracts/scripts/initialize-l2-weth-token.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

Check failure on line 127 in l1-contracts/scripts/initialize-l2-weth-token.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'--native-erc20'` with `"--native-erc20"`

Check failure on line 127 in l1-contracts/scripts/initialize-l2-weth-token.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

Check failure on line 127 in l1-contracts/scripts/initialize-l2-weth-token.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'--native-erc20'` with `"--native-erc20"`

Check failure on line 127 in l1-contracts/scripts/initialize-l2-weth-token.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
.action(async (cmd) => {
if (!l1WethTokenAddress) {
console.log("Base Layer WETH address not provided. Skipping.");
Expand All @@ -136,6 +137,10 @@
process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic,
"m/44'/60'/0'/0/1"
).connect(provider);

const nativeErc20impl = cmd.nativeErc20 ? true : false;
console.log(`Using native erc20: ${nativeErc20impl}`);

console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
Expand All @@ -160,7 +165,7 @@
const tx = await zkSync.requestL2Transaction(
l2WethTokenProxyAddress,
0,
requiredValueToInitializeBridge,
nativeErc20impl? requiredValueToInitializeBridge : 0,
calldata,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
SYSTEM_CONFIG.requiredL2GasPricePerPubdata,
Expand Down
7 changes: 6 additions & 1 deletion l1-contracts/scripts/initialize-weth-bridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ async function main() {
.option("--private-key <private-key>")
.option("--gas-price <gas-price>")
.option("--nonce <nonce>")
.option("--native-erc20")
.action(async (cmd) => {
const deployWallet = cmd.privateKey
? new Wallet(cmd.privateKey, provider)
: Wallet.fromMnemonic(
process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic,
"m/44'/60'/0'/0/0"
).connect(provider);

const nativeErc20impl = cmd.nativeErc20 ? true : false;
console.log(`Using native erc20: ${nativeErc20impl}`);

console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
Expand Down Expand Up @@ -82,7 +87,7 @@ async function main() {
l2GovernorAddress,
requiredValueToInitializeBridge,
requiredValueToInitializeBridge,
requiredValueToInitializeBridge.mul(2),
nativeErc20impl ? requiredValueToInitializeBridge.mul(2) : 0,
{
gasPrice,
value: requiredValueToInitializeBridge.mul(2),
Expand Down
Loading
Loading