Commit 8708ef22 authored by elenadimitrova's avatar elenadimitrova Committed by Elena Gesheva

Add Factory contract for creating standard ERC20 tokens

compliant with the standard bridge
parent 21e47e1f
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0;
pragma experimental ABIEncoderV2;
/* Contract Imports */
import { L2StandardERC20 } from "../../../libraries/standards/L2StandardERC20.sol";
import { Lib_PredeployAddresses } from "../../../libraries/constants/Lib_PredeployAddresses.sol";
/**
* @title OVM_L2StandardTokenFactory
* @dev Factory contract for creating standard L2 token representations of L1 ERC20s
* compatible with and working on the standard bridge.
* Compiler used: optimistic-solc
* Runtime target: OVM
*/
contract OVM_L2StandardTokenFactory {
event StandardL2TokenCreated(address indexed _l1Token, address indexed _l2Token);
/**
* @dev Creates an instance of the standard ERC20 token on L2.
* @param _l1Token Address of the corresponding L1 token.
* @param _name ERC20 name.
* @param _symbol ERC20 symbol.
*/
function createStandardL2Token(
address _l1Token,
string memory _name,
string memory _symbol
)
external
{
L2StandardERC20 l2Token = new L2StandardERC20(
Lib_PredeployAddresses.L2_STANDARD_BRIDGE,
_l1Token,
_name,
_symbol);
emit StandardL2TokenCreated(_l1Token, address(l2Token));
}
}
......@@ -10,6 +10,7 @@ contract L2StandardERC20 is IL2StandardERC20, ERC20 {
address public l2Bridge;
/**
* @param _l2Bridge Address of the L2 standard bridge.
* @param _l1Token Address of the corresponding L1 token.
* @param _name ERC20 name.
* @param _symbol ERC20 symbol.
......
import { expect } from '../../../../setup'
/* External Imports */
import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract } from 'ethers'
import { smoddit } from '@eth-optimism/smock'
import { getContractInterface } from '@eth-optimism/contracts'
/* Internal Imports */
import { NON_NULL_BYTES32, NON_ZERO_ADDRESS } from '../../../../helpers'
import { predeploys } from '../../../../../src'
describe('OVM_L2StandardTokenFactory', () => {
let signer: Signer
let Factory__L1ERC20: ContractFactory
let L1ERC20: Contract
let OVM_L2StandardTokenFactory: Contract
before(async () => {
;[signer] = await ethers.getSigners()
// deploy an ERC20 contract on L1
Factory__L1ERC20 = await smoddit(
'@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20'
)
L1ERC20 = await Factory__L1ERC20.deploy('L1ERC20', 'ERC')
OVM_L2StandardTokenFactory = await (
await ethers.getContractFactory('OVM_L2StandardTokenFactory')
).deploy()
})
describe('Standard token factory', () => {
it('should be able to create a standard token', async () => {
const tx = await OVM_L2StandardTokenFactory.createStandardL2Token(
L1ERC20.address,
'L2ERC20',
'ERC'
)
const receipt = await tx.wait()
const [tokenCreatedEvent] = receipt.events
// Expect there to be an event emmited for the standard token creation
expect(tokenCreatedEvent.event).to.be.eq('StandardL2TokenCreated')
// Get the L2 token address from the emmited event and check it was created correctly
const l2TokenAddress = tokenCreatedEvent.args._l2Token
const l2Token = new Contract(
l2TokenAddress,
getContractInterface('L2StandardERC20'),
signer
)
expect(await l2Token.l2Bridge()).to.equal(predeploys.OVM_L2StandardBridge)
expect(await l2Token.l1Token()).to.equal(L1ERC20.address)
expect(await l2Token.name()).to.equal('L2ERC20')
expect(await l2Token.symbol()).to.equal('ERC')
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment