Commit 07009b36 authored by Karl Floersch's avatar Karl Floersch Committed by GitHub

Add mint & burn to L2 ETH (#178)

* Initial attempt at adding mint to ETH

* Fix lint error

* fix modifier
Co-authored-by: default avatarBen Jones <ben@pseudonym.party>
parent 3cadef55
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
// +build ovm // +build ovm
pragma solidity >0.5.0 <0.8.0; pragma solidity >0.5.0 <0.8.0;
/* Library Imports */
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
/* Interface Imports */ /* Interface Imports */
import { iOVM_ERC20 } from "../../iOVM/precompiles/iOVM_ERC20.sol"; import { iOVM_ERC20 } from "../../iOVM/precompiles/iOVM_ERC20.sol";
import { iOVM_BaseCrossDomainMessenger } from "../../iOVM/bridge/iOVM_BaseCrossDomainMessenger.sol";
/** /**
* @title OVM_ETH * @title OVM_ETH
* @dev L2 CONTRACT (COMPILED) * @dev L2 CONTRACT (COMPILED)
*/ */
contract OVM_ETH is iOVM_ERC20 { contract OVM_ETH is iOVM_ERC20, Lib_AddressResolver {
uint256 constant private MAX_UINT256 = 2**256 - 1; uint256 constant private MAX_UINT256 = 2**256 - 1;
mapping (address => uint256) public balances; mapping (address => uint256) public balances;
...@@ -26,11 +30,15 @@ contract OVM_ETH is iOVM_ERC20 { ...@@ -26,11 +30,15 @@ contract OVM_ETH is iOVM_ERC20 {
uint256 public override totalSupply; uint256 public override totalSupply;
constructor( constructor(
address _libAddressManager,
uint256 _initialAmount, uint256 _initialAmount,
string memory _tokenName, string memory _tokenName,
uint8 _decimalUnits, uint8 _decimalUnits,
string memory _tokenSymbol string memory _tokenSymbol
) public { )
public
Lib_AddressResolver(_libAddressManager)
{
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens balances[msg.sender] = _initialAmount; // Give the creator all initial tokens
totalSupply = _initialAmount; // Update total supply totalSupply = _initialAmount; // Update total supply
name = _tokenName; // Set the name for display purposes name = _tokenName; // Set the name for display purposes
...@@ -38,6 +46,13 @@ contract OVM_ETH is iOVM_ERC20 { ...@@ -38,6 +46,13 @@ contract OVM_ETH is iOVM_ERC20 {
symbol = _tokenSymbol; // Set the symbol for display purposes symbol = _tokenSymbol; // Set the symbol for display purposes
} }
modifier onlyOVMETHBridge() {
address bridgeOnL2 = resolve("OVM_L2ETHBridge");
require(bridgeOnL2 != address(0), "OVM_L2ETHBridge is not yet initialized.");
require(msg.sender == bridgeOnL2, "Only callable by OVM ETH Deposit/Withdrawal contract");
_;
}
function transfer(address _to, uint256 _value) external override returns (bool success) { function transfer(address _to, uint256 _value) external override returns (bool success) {
require(balances[msg.sender] >= _value); require(balances[msg.sender] >= _value);
balances[msg.sender] -= _value; balances[msg.sender] -= _value;
...@@ -71,4 +86,23 @@ contract OVM_ETH is iOVM_ERC20 { ...@@ -71,4 +86,23 @@ contract OVM_ETH is iOVM_ERC20 {
function allowance(address _owner, address _spender) external view override returns (uint256 remaining) { function allowance(address _owner, address _spender) external view override returns (uint256 remaining) {
return allowed[_owner][_spender]; return allowed[_owner][_spender];
} }
}
\ No newline at end of file function mint(address _account, uint256 _amount) external onlyOVMETHBridge returns (bool success) {
uint256 newTotalSupply = totalSupply + _amount;
require(newTotalSupply >= totalSupply, "SafeMath: addition overflow");
totalSupply = newTotalSupply;
balances[_account] += _amount;
emit Mint(_account, _amount);
return true;
}
function burn(address _account, uint256 _amount) external onlyOVMETHBridge returns (bool success) {
require(balances[_account] >= _amount, "Unable to burn due to insufficient balance");
balances[_account] -= _amount;
totalSupply -= _amount;
emit Burn(_account, _amount);
return true;
}
}
...@@ -49,4 +49,6 @@ interface iOVM_ERC20 { ...@@ -49,4 +49,6 @@ interface iOVM_ERC20 {
// solhint-disable-next-line no-simple-event-func-name // solhint-disable-next-line no-simple-event-func-name
event Transfer(address indexed _from, address indexed _to, uint256 _value); event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} event Mint(address indexed _account, uint256 _amount);
\ No newline at end of file event Burn(address indexed _account, uint256 _amount);
}
...@@ -210,7 +210,13 @@ export const makeContractDeployConfig = async ( ...@@ -210,7 +210,13 @@ export const makeContractDeployConfig = async (
}, },
OVM_ETH: { OVM_ETH: {
factory: getContractFactory('OVM_ETH'), factory: getContractFactory('OVM_ETH'),
params: [config.ethConfig.initialAmount, 'Ether', 18, 'ETH'], params: [
AddressManager.address,
config.ethConfig.initialAmount,
'Ether',
18,
'ETH',
],
}, },
'OVM_ChainStorageContainer:CTC:batches': { 'OVM_ChainStorageContainer:CTC:batches': {
factory: getContractFactory('OVM_ChainStorageContainer'), factory: getContractFactory('OVM_ChainStorageContainer'),
......
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