Skip to content

Mint-Burn gas token privileged contract #334

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

Open
wants to merge 6 commits into
base: mb-arbowner-dev
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions src/bridge/IMinterBurnerForwarder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

interface IMinterBurnerForwarder {
/**
* @notice Mints some amount of the native gas token for this chain to the calling address.
* @dev This function calls mintNativeToken in the ArbOwner precompile, so this contract must also be a chain owner.
* No events are emitted in this function, since the ArbOwner precompile already emits OwnerActs()
* @param to The address credited with the minted native gas token
* @param amount The amount of native gas token to mint
*/
function mintNativeToken(address to, uint256 amount) external;

/**
* @notice Burns some amount of the native gas token for this chain from the given address.
* @dev This function calls burnNativeToken in the ArbOwner precompile, so this contract must also be a chain owner.
* No events are emitted in this function, since the ArbOwner precompile already emits OwnerActs()
* @param from The address to burn the native gas token from
* @param amount The amount of native gas token to burn
*/
function burnNativeToken(address from, uint256 amount) external;

/// @notice The role given to the addresses that can mint native gas token
function MINTER_ROLE() external returns (bytes32);

/// @notice The role given to the addresses that can burn native gas token
function BURNER_ROLE() external returns (bytes32);
}
63 changes: 63 additions & 0 deletions src/bridge/MinterBurnerForwarder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "./IMinterBurnerForwarder.sol";
import "../precompiles/ArbOwner.sol";

/**
* @title MinterBurnerForwarder
* @notice This contract allows the chain owner of a chain to give rights for minting and burning native gas tokens to third parties.
* Minting and burning will be done by using the ArbOwner functions mintNativeToken and burnNativeToken.
* This contract must be set as a chain owner of the chain to be able to call ArbOwner functions
*/
contract MinterBurnerForwarder is IMinterBurnerForwarder, AccessControlEnumerable {
// Roles
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");

// ArbOwner precompile
ArbOwner constant ARB_OWNER = ArbOwner(address(112));

/// @param minters Addresses to grant the MINTER_ROLE
/// @param burners Addresses to grant the BURNER_ROLE
constructor(address[] memory minters, address[] memory burners) {
// Grant MINTER_ROLE role to minters
for (uint256 i = 0; i < minters.length; i++) {
_grantRole(MINTER_ROLE, minters[i]);
}

// Grant BURNER_ROLE role to burners
for (uint256 i = 0; i < burners.length; i++) {
_grantRole(BURNER_ROLE, burners[i]);
}
}

/**
* @dev Returns `true` if:
* - we are checking for the admin role, and `account` is a chain owner
* - we are checking for a different role and `account` has been granted `role`.
*/
function hasRole(
bytes32 role,
address account
) public view override(AccessControl, IAccessControl) returns (bool) {
if (role == DEFAULT_ADMIN_ROLE) {
return ARB_OWNER.isChainOwner(account);
}
return super.hasRole(role, account);
}

/// @inheritdoc IMinterBurnerForwarder
function mintNativeToken(address to, uint256 amount) external onlyRole(MINTER_ROLE) {
ARB_OWNER.mintNativeToken(to, amount);
}

/// @inheritdoc IMinterBurnerForwarder
function burnNativeToken(address from, uint256 amount) external onlyRole(BURNER_ROLE) {
ARB_OWNER.burnNativeToken(from, amount);
}
}
Loading