Skip to content

Commit

Permalink
feat(protocol): enable DAO and TaikoL2 to mint/burn Taiko token (#13955)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Jun 11, 2023
1 parent 55a4d4e commit f20cfcc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract TaikoToken is
uint256 amount
)
public
onlyFromNamed("proto_broker")
onlyFromNamedEither("taiko", "dao")
{
_mint(to, amount);
}
Expand All @@ -97,7 +97,7 @@ contract TaikoToken is
uint256 amount
)
public
onlyFromNamed("proto_broker")
onlyFromNamedEither("taiko", "dao")
{
_burn(from, amount);
}
Expand Down
10 changes: 9 additions & 1 deletion packages/protocol/contracts/common/AddressResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ abstract contract AddressResolver {
error RESOLVER_ZERO_ADDR(uint256 chainId, bytes32 name);

modifier onlyFromNamed(bytes32 name) {
if (msg.sender != resolve(name, false)) revert RESOLVER_DENIED();
if (msg.sender != resolve(name, true)) revert RESOLVER_DENIED();
_;
}

modifier onlyFromNamedEither(bytes32 name1, bytes32 name2) {
if (
msg.sender != resolve(name1, true)
&& msg.sender != resolve(name2, true)
) revert RESOLVER_DENIED();
_;
}

Expand Down
1 change: 0 additions & 1 deletion packages/protocol/script/DeployOnL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ contract DeployOnL1 is Script {
)
);
setAddress("taiko", taikoL1Proxy);
setAddress("proto_broker", taikoL1Proxy);

// Bridge
Bridge bridge = new ProxiedBridge();
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/test/TaikoL1TestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ abstract contract TaikoL1TestBase is Test {
);

// Set protocol broker
registerAddress("proto_broker", address(this));
registerAddress("taiko", address(this));
tko.mint(address(this), 1e9 * 1e8);
registerAddress("proto_broker", address(L1));
registerAddress("taiko", address(L1));

L1.init(address(addressManager), GENESIS_BLOCK_HASH, feeBase);
printVariables("init ");
Expand Down
43 changes: 21 additions & 22 deletions packages/protocol/test/TaikoToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ contract TaikoTokenTest is Test {

address public constant tokenAdmin =
0x200C9b60e19634E12FC6D68B7FeA7Bfb26c2e418;
address public constant protoBroker =
0x300C9b60E19634e12FC6D68B7FEa7bFB26c2E419;
address public constant taikoL1 = 0x300C9b60E19634e12FC6D68B7FEa7bFB26c2E419;
address public constant TeamWallet =
0x300C9b60E19634e12FC6D68B7FEa7bFB26c2E419;
address public constant DaoTreasury =
Expand All @@ -33,7 +32,7 @@ contract TaikoTokenTest is Test {
function setUp() public {
addressManager = new AddressManager();
addressManager.init();
registerAddress("proto_broker", protoBroker);
registerAddress("taiko", taikoL1);

tko = new TaikoToken();

Expand Down Expand Up @@ -90,46 +89,46 @@ contract TaikoTokenTest is Test {
assertEq(tko.balanceOf(Eve), 0 ether);

uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);
}

function test_mint_invalid_amount() public {
vm.prank(protoBroker);
vm.prank(taikoL1);
vm.expectRevert(TaikoToken.TKO_MINT_DISALLOWED.selector);
tko.mint(Eve, 1000 ether);
}

function test_mint_invalid_address() public {
vm.prank(protoBroker);
vm.prank(taikoL1);
vm.expectRevert("ERC20: mint to the zero address");
tko.mint(address(0), 1 ether);
}

function test_mint_not_proto_broker() public {
function test_mint_not_taiko_l1() public {
vm.expectRevert(AddressResolver.RESOLVER_DENIED.selector);
tko.mint(Eve, 1 ether);
}

function test_burn() public {
uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

vm.prank(protoBroker);
vm.prank(taikoL1);
tko.burn(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), 0);
}

function test_burn_invalid_address() public {
vm.prank(protoBroker);
vm.prank(taikoL1);
vm.expectRevert("ERC20: burn from the zero address");
tko.burn(address(0), 1 ether);
}

function test_burn_not_proto_broker() public {
function test_burn_not_taiko_l1() public {
vm.expectRevert(AddressResolver.RESOLVER_DENIED.selector);
tko.burn(address(0), 1 ether);
}
Expand All @@ -138,19 +137,19 @@ contract TaikoTokenTest is Test {
uint256 amountToMint = 1 ether;
uint256 amountToBurn = 2 ether;

vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

vm.prank(protoBroker);
vm.prank(taikoL1);
vm.expectRevert("ERC20: burn amount exceeds balance");
tko.burn(Eve, amountToBurn);
assertEq(tko.balanceOf(Eve), amountToMint);
}

function test_transfer() public {
uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand All @@ -163,7 +162,7 @@ contract TaikoTokenTest is Test {

function test_transfer_invalid_address() public {
uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand All @@ -174,7 +173,7 @@ contract TaikoTokenTest is Test {

function test_transfer_to_contract_address() public {
uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand All @@ -186,7 +185,7 @@ contract TaikoTokenTest is Test {
function test_transfer_amount_exceeded() public {
uint256 amountToMint = 1 ether;
uint256 amountToTransfer = 2 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand All @@ -198,7 +197,7 @@ contract TaikoTokenTest is Test {

function test_transferFrom() public {
uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand All @@ -214,7 +213,7 @@ contract TaikoTokenTest is Test {

function test_transferFrom_to_is_invalid() public {
uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand All @@ -228,7 +227,7 @@ contract TaikoTokenTest is Test {

function test_transferFrom_to_is_the_contract() public {
uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand All @@ -242,7 +241,7 @@ contract TaikoTokenTest is Test {

function test_transferFrom_from_is_invalid() public {
uint256 amountToMint = 1 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand All @@ -258,7 +257,7 @@ contract TaikoTokenTest is Test {
function test_transferFrom_amount_exceeded() public {
uint256 amountToMint = 1 ether;
uint256 amountToTransfer = 2 ether;
vm.prank(protoBroker);
vm.prank(taikoL1);
tko.mint(Eve, amountToMint);
assertEq(tko.balanceOf(Eve), amountToMint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ error RESOLVER_ZERO_ADDR(uint256 chainId, bytes32 name)
modifier onlyFromNamed(bytes32 name)
```

### onlyFromNamedEither

```solidity
modifier onlyFromNamedEither(bytes32 name1, bytes32 name2)
```

### resolve

```solidity
Expand Down

0 comments on commit f20cfcc

Please sign in to comment.