Skip to content

Commit

Permalink
Merge branch 'erc20_base_token' into erc20-transferFrom-and-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Pittella authored and Santiago Pittella committed Dec 21, 2023
2 parents e19c6cf + 74b9287 commit 204bf00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
27 changes: 5 additions & 22 deletions ethereum/contracts/zksync/facets/Mailbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract MailboxFacet is Base, IMailbox {
using SafeERC20 for IERC20;

string public constant override getName = "MailboxFacet";
event WithdrawalFinalized(address indexed to, address indexed l1Token, uint256 amount);
event WithdrawalFinalized(address indexed to, uint256 amount);

/// @notice Prove that a specific arbitrary-length message was sent in a specific L2 batch number
/// @param _batchNumber The executed L2 batch number in which the message appeared
Expand Down Expand Up @@ -215,7 +215,7 @@ contract MailboxFacet is Base, IMailbox {
data: _message
});

(address l1Receiver, address l1Token, uint256 amount) = _parseL2WithdrawalMessage(l2ToL1Message.data);
(address l1Receiver, uint256 amount) = _parseL2WithdrawalMessage(l2ToL1Message.data);
// Preventing the stack too deep error
{
bool success = proveL2MessageInclusion(_l2BatchNumber, _l2MessageIndex, l2ToL1Message, _merkleProof);
Expand All @@ -224,9 +224,10 @@ contract MailboxFacet is Base, IMailbox {

s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex] = true;
// Withdraw funds
address l1Token = $(NATIVE_ERC20_ADDRESS);
IERC20(l1Token).safeTransfer(l1Receiver, amount);

emit WithdrawalFinalized(l1Receiver, l1Token, amount);
emit WithdrawalFinalized(l1Receiver, amount);
// #endif
}

Expand Down Expand Up @@ -427,9 +428,7 @@ contract MailboxFacet is Base, IMailbox {
/// @dev Decode the withdraw message that came from L2
function _parseL2WithdrawalMessage(
bytes memory _message
) internal pure returns (address l1Receiver, address l1Token, uint256 amount) {
// #def TOKEN_TYPE 'ERC20'
// #if TOKEN_TYPE == 'ETH'
) internal pure returns (address l1Receiver, uint256 amount) {
// We check that the message is long enough to read the data.
// Please note that there are two versions of the message:
// 1. The message that is sent by `withdraw(address _l1Receiver)`
Expand All @@ -446,22 +445,6 @@ contract MailboxFacet is Base, IMailbox {
require(bytes4(functionSignature) == this.finalizeEthWithdrawal.selector, "is");

(l1Receiver, offset) = UnsafeBytes.readAddress(_message, offset);
l1Token = 0x0000000000000000000000000000000000000000;
(amount, offset) = UnsafeBytes.readUint256(_message, offset);

// #elif TOKEN_TYPE == 'ERC20'
// Check that the message length is correct.
// It should be equal to the length of the function signature + address + address + uint256 = 4 + 20 + 20 + 32 =
// 76 (bytes).
bytes memory _l2ToL1message = _message;
require(_l2ToL1message.length == 76, "kk");

(uint32 functionSignature, uint256 offset) = UnsafeBytes.readUint32(_l2ToL1message, 0);
require(bytes4(functionSignature) == this.finalizeEthWithdrawal.selector, "nt");

(l1Receiver, offset) = UnsafeBytes.readAddress(_l2ToL1message, offset);
(l1Token, offset) = UnsafeBytes.readAddress(_l2ToL1message, offset);
(amount, offset) = UnsafeBytes.readUint256(_l2ToL1message, offset);
// #endif
}
}
11 changes: 11 additions & 0 deletions ethereum/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,18 @@ export default {
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 111 in ethereum/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint-l1

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

Check failure on line 112 in ethereum/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint-l1

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

Check failure on line 115 in ethereum/hardhat.config.ts

View workflow job for this annotation

GitHub Actions / lint-l1

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

return {
NATIVE_ERC20_ADDRESS: address,
...systemParams,
...defs,
};
Expand Down
1 change: 1 addition & 0 deletions ethereum/scripts/deploy-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function deployToken(token: TokenDescription, wallet: Wallet): Promise<Tok
console.error("Wallet PK: ", wallet.privateKey);
console.error("Deploying token: ", token.name);
console.error("erc20: ", erc20);

if (token.implementation !== "WETH9") {
await erc20.mint(wallet.address, parseEther("3000000000"));
}
Expand Down

0 comments on commit 204bf00

Please sign in to comment.