-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from OffchainLabs/express-lane-auction-burn
Express lane auction burn
- Loading branch information
Showing
4 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import { | ||
ERC20BurnableUpgradeable | ||
} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol"; | ||
import "./Errors.sol"; | ||
|
||
/// @notice A simple contract that can burn any tokens that are transferred to it | ||
/// Token must support the ERC20BurnableUpgradeable.burn(uint256) interface | ||
contract Burner { | ||
ERC20BurnableUpgradeable public immutable token; | ||
|
||
constructor(address _token) { | ||
if (_token == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
token = ERC20BurnableUpgradeable(_token); | ||
} | ||
|
||
/// @notice Can be called at any time by anyone to burn any tokens held by this burner | ||
function burn() external { | ||
token.burn(token.balanceOf(address(this))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
import { | ||
ERC20BurnableUpgradeable | ||
} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol"; | ||
import {Burner} from "../../src/express-lane-auction/Burner.sol"; | ||
import "../../src/express-lane-auction/Errors.sol"; | ||
|
||
contract MockERC20 is ERC20BurnableUpgradeable { | ||
function initialize() public initializer { | ||
__ERC20_init("LANE", "LNE"); | ||
_mint(msg.sender, 1_000_000); | ||
} | ||
} | ||
|
||
contract ExpressLaneBurner is Test { | ||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
|
||
function testBurn() public { | ||
vm.expectRevert(ZeroAddress.selector); | ||
new Burner(address(0)); | ||
|
||
MockERC20 erc20 = new MockERC20(); | ||
erc20.initialize(); | ||
Burner burner = new Burner(address(erc20)); | ||
assertEq(address(burner.token()), address(erc20)); | ||
|
||
erc20.transfer(address(burner), 20); | ||
|
||
uint256 totalSupplyBefore = erc20.totalSupply(); | ||
assertEq(erc20.balanceOf(address(burner)), 20); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit Transfer(address(burner), address(0), 20); | ||
vm.prank(vm.addr(137)); | ||
burner.burn(); | ||
|
||
assertEq(totalSupplyBefore - erc20.totalSupply(), 20); | ||
assertEq(erc20.balanceOf(address(burner)), 0); | ||
|
||
// can burn 0 if we want to | ||
vm.expectEmit(true, true, true, true); | ||
emit Transfer(address(burner), address(0), 0); | ||
vm.prank(vm.addr(138)); | ||
burner.burn(); | ||
} | ||
} |