Skip to content

Commit

Permalink
feat: add bridge l2 to l1
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielZhangReal committed Jan 5, 2024
1 parent de260b0 commit 1d827e2
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
8 changes: 8 additions & 0 deletions standard-bridge-custom-token/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ const TOKENS = {
l2TokenAddress: "0xA2B0b1DF7FbD966560A302E9E2cFB9d0f115FfD6",
isTestnet: true,
},
TestTT: {
name: "TestToken",
symbol: "TT",
decimals: 18,
l1TokenAddress: "0x8D7090DdDa057f48FdBbb2ABCeA22D1113AB566a",
l2TokenAddress: "0x8D7090DdDa057f48FdBbb2ABCeA22D1113AB566a",
isTestnet: true,
},
MATIC: {
name: "Matic Token",
symbol: "MATIC",
Expand Down
10 changes: 10 additions & 0 deletions standard-bridge-custom-token/contracts/TestToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract TestToken is ERC20 {
constructor(uint256 initialSupply) ERC20("TestToken", "TT") {
_mint(msg.sender, initialSupply);
}
}
12 changes: 11 additions & 1 deletion standard-bridge-custom-token/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ module.exports = {
},
},
networks: {
goerli: {
// Ankr's Public RPC URL
url: "https://rpc.ankr.com/eth_goerli",
// PRIVATE_KEY loaded from .env file
accounts: [process.env.PRIVATE_KEY],
},
"optimism-goerli": {
chainId: 420,
url: `https://opt-goerli.g.alchemy.com/v2/${process.env.L2_ALCHEMY_KEY}`,
Expand All @@ -39,7 +45,11 @@ module.exports = {
},
},
etherscan: {
apiKey: { "manta-testnet": "test", "manta-mainnet": "test" },
apiKey: {
"manta-testnet": "test",
"manta-mainnet": "test",
goerli: process.env.ETHER_SCAN_API_KEY,
},
customChains: [
{
network: "manta-testnet",
Expand Down
42 changes: 42 additions & 0 deletions standard-bridge-custom-token/scripts/deploy_l1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require("dotenv").config();

const { ethers, run } = require("hardhat");
const { TOKENS } = require("../config");

async function main(token) {
const l2CustomERC20Factory = await ethers.getContractFactory(
"MantaMintableERC20"
);
const args = [
"0x4638aC6b5727a8b9586D3eba5B44Be4b74ED41Fc",
token.l2TokenAddress,
token.name,
token.symbol,
token.decimals,
];
const l2CustomERC20 = await l2CustomERC20Factory.deploy(...args);
console.log(`${token.symbol} L1 Address: ${l2CustomERC20.address}`);

await l2CustomERC20.deployTransaction.wait();

await run("verify:verify", {
address: l2CustomERC20.address,
constructorArguments: args,
contract: "contracts/MantaMintableERC20.sol:MantaMintableERC20"
});
}

const tokenInfo = TOKENS[process.env.DEPLOY_TOKEN_NAME];
if (!tokenInfo) {
console.error('Invalid Token: "process.env.DEPLOY_TOKEN_NAME"');
return;
}
if (tokenInfo.l1TokenAddress) {
console.error(`Already Deployed: ${tokenInfo.l1TokenAddress}`);
return;
}

main(tokenInfo).catch((error) => {
console.error(error);
process.exitCode = 1;
});
24 changes: 24 additions & 0 deletions standard-bridge-custom-token/scripts/deploy_l2_native_token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require("dotenv").config();

const { ethers, run } = require("hardhat");


async function main() {
const factory = await ethers.getContractFactory("TestToken");
const args = [ethers.BigNumber.from("10000000000000000000000")];
const l1CustomERC20 = await factory.deploy(...args);
console.log(`L2 Address: ${l1CustomERC20.address}`);

await l1CustomERC20.deployTransaction.wait();

await run("verify:verify", {
address: l1CustomERC20.address,
constructorArguments: args,
contract: "contracts/TestToken.sol:TestToken",
});
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

0 comments on commit 1d827e2

Please sign in to comment.