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

Erc20 transfer from and checks #5

Merged
merged 5 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions ethereum/contracts/zksync/facets/Mailbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ 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(msg.sender) >= _amount, "Not enough balance");
require(IERC20(nativeTokenAddress).allowance(msg.sender, address(this)) >= _amount, "Not enough allowance");

// Transfer tokens to the contract.
IERC20(nativeTokenAddress).safeTransferFrom(msg.sender, address(this), _amount);

params.sender = _sender;
params.txId = s.priorityQueue.getTotalPriorityTxs();
params.l2Value = _l2Value;
Expand Down
21 changes: 19 additions & 2 deletions ethereum/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import { task } from "hardhat/config";
import "solidity-coverage";
import { getNumberFromEnv } from "./scripts/utils";
import * as fs from 'fs';
import path = require("path");
import * as fs from "fs";

// If no network is specified, use the default config
if (!process.env.CHAIN_ETH_NETWORK) {
Expand All @@ -23,6 +24,19 @@
const PRIORITY_TX_MAX_GAS_LIMIT = getNumberFromEnv("CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT");
const DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT = getNumberFromEnv("CONTRACTS_DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT");

const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, "etc/tokens");
console.error("testConfigPath", testConfigPath);
let testConfigFile = fs.readFileSync(`${testConfigPath}/native_erc20.json`, { encoding: "utf-8" });
console.error("testConfigFile", testConfigFile);

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

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

View workflow job for this annotation

GitHub Actions / lint-l1

Strings must use doublequote
}

const nativeERC20Token = JSON.parse(testConfigFile);
console.error("nativeERC20Token", nativeERC20Token);
const L1_NATIVE_TOKEN_ADDRESS = nativeERC20Token.address;

const prodConfig = {
UPGRADE_NOTICE_PERIOD: 0,
// PRIORITY_EXPIRATION: 101,
Expand All @@ -31,6 +45,7 @@
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: false,
L1_NATIVE_TOKEN_ADDRESS,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some comment/doc explaining the nature of this? If not, can we add it? (Just to avoid third party confusions).

};
const testnetConfig = {
UPGRADE_NOTICE_PERIOD: 0,
Expand All @@ -40,6 +55,7 @@
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: true,
L1_NATIVE_TOKEN_ADDRESS,
};
const testConfig = {
UPGRADE_NOTICE_PERIOD: 0,
Expand All @@ -48,6 +64,7 @@
PRIORITY_TX_MAX_GAS_LIMIT,
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT,
DUMMY_VERIFIER: true,
L1_NATIVE_TOKEN_ADDRESS,
};
const localConfig = {
...prodConfig,
Expand Down Expand Up @@ -91,11 +108,11 @@
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');
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";
Expand Down
12 changes: 10 additions & 2 deletions ethereum/scripts/deploy-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ async function deployToken(token: TokenDescription, wallet: Wallet): Promise<Tok
const erc20 = await tokenFactory.deploy(...args, { gasLimit: 5000000 });
await erc20.deployTransaction.wait();

console.error("Wallet address: ", wallet.address);
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 All @@ -44,8 +49,10 @@ async function deployToken(token: TokenDescription, wallet: Wallet): Promise<Tok
}
}

console.error("erc20 address: ", erc20.address);
console.error("token address: ", token.address);
token.address = erc20.address;

console.error("token address after: ", token.address);
// Remove the unneeded field
if (token.implementation) {
delete token.implementation;
Expand Down Expand Up @@ -97,8 +104,9 @@ async function main() {
for (const token of tokens) {
result.push(await deployToken(token, wallet));
}

console.error("result: ", result);
console.log(JSON.stringify(result, null, 2));
console.error("Json stringify passed");
});

await program.parseAsync(process.argv);
Expand Down
Loading