Skip to content

Commit

Permalink
Merge pull request #60 from primevprotocol/use-ownable
Browse files Browse the repository at this point in the history
Use openzeppelin's Ownable.sol for whitelist
  • Loading branch information
shaspitz authored Dec 19, 2023
2 parents af88356 + c33a145 commit 33473c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
20 changes: 8 additions & 12 deletions contracts/Whitelist.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
// SPDX-License-Identifier: BSL 1.1
pragma solidity ^0.8.15;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

// Contract that allows an admin to add/remove addresses from the whitelist,
// and allows whitelisted addresses to mint/burn native tokens.
contract Whitelist {
address public admin;
contract Whitelist is Ownable {

mapping(address => bool) public whitelistedAddresses;

// Mint/burn precompile addresses.
// See: https://github.com/primevprotocol/go-ethereum/blob/03ae168c6ac15dda8c5a3f123e2b9f3350aad613/core/vm/contracts.go
address constant MINT = address(0x89);
address constant BURN = address(0x90);

constructor(address _admin) {
require(_admin != address(0), "Admin address cannot be zero");
admin = _admin;
}

modifier onlyAdmin() {
require(msg.sender == admin, "Only admin can call this function");
_;
constructor(address _owner) Ownable() {
_transferOwnership(_owner);
}

function addToWhitelist(address _address) external onlyAdmin {
function addToWhitelist(address _address) external onlyOwner {
whitelistedAddresses[_address] = true;
}

function removeFromWhitelist(address _address) external onlyAdmin {
function removeFromWhitelist(address _address) external onlyOwner {
whitelistedAddresses[_address] = false;
}

Expand Down
4 changes: 2 additions & 2 deletions test/WhitelistTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract WhitelistTest is Test {

function test_RevertNormalUserAddToWhitelist() public {
vm.prank(normalUser);
vm.expectRevert("Only admin can call this function");
vm.expectRevert("Ownable: caller is not the owner");
whitelist.addToWhitelist(addressInstance);
}

Expand All @@ -53,7 +53,7 @@ contract WhitelistTest is Test {
whitelist.addToWhitelist(addressInstance);
assertTrue(whitelist.isWhitelisted(addressInstance));
vm.prank(normalUser);
vm.expectRevert("Only admin can call this function");
vm.expectRevert("Ownable: caller is not the owner");
whitelist.removeFromWhitelist(addressInstance);
}
}

0 comments on commit 33473c1

Please sign in to comment.