Commit 630c876b authored by James Kim's avatar James Kim

update_Optimist_to_use_allowlist

parent 915036aa
...@@ -12,9 +12,6 @@ contract Optimist_Initializer is Test { ...@@ -12,9 +12,6 @@ contract Optimist_Initializer is Test {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Initialized(uint8); event Initialized(uint8);
address constant alice_admin = address(128);
address constant bob = address(256);
address constant sally = address(512);
string constant name = "Optimist name"; string constant name = "Optimist name";
string constant symbol = "OPTIMISTSYMBOL"; string constant symbol = "OPTIMISTSYMBOL";
string constant base_uri = string constant base_uri =
...@@ -22,6 +19,12 @@ contract Optimist_Initializer is Test { ...@@ -22,6 +19,12 @@ contract Optimist_Initializer is Test {
AttestationStation attestationStation; AttestationStation attestationStation;
Optimist optimist; Optimist optimist;
address internal carol_baseURIAttestor;
address internal alice_allowlistAttestor;
address internal ted_coinbaseAttestor;
address internal bob;
address internal sally;
function attestBaseuri(string memory _baseUri) internal { function attestBaseuri(string memory _baseUri) internal {
AttestationStation.AttestationData[] AttestationStation.AttestationData[]
memory attestationData = new AttestationStation.AttestationData[](1); memory attestationData = new AttestationStation.AttestationData[](1);
...@@ -48,14 +51,17 @@ contract Optimist_Initializer is Test { ...@@ -48,14 +51,17 @@ contract Optimist_Initializer is Test {
} }
function setUp() public { function setUp() public {
carol_baseURIAttestor = makeAddr("carol_baseURIAttestor");
alice_allowlistAttestor = makeAddr("alice_allowlistAttestor");
ted_coinbaseAttestor = makeAddr("ted_coinbaseAttestor");
bob = makeAddr("bob");
sally = makeAddr("sally");
// Give alice and bob and sally some ETH // Give alice and bob and sally some ETH
vm.deal(alice_admin, 1 ether); vm.deal(alice_admin, 1 ether);
vm.deal(bob, 1 ether); vm.deal(bob, 1 ether);
vm.deal(sally, 1 ether); vm.deal(sally, 1 ether);
vm.label(alice_admin, "alice_admin");
vm.label(bob, "bob");
vm.label(sally, "sally");
_initializeContracts(); _initializeContracts();
} }
...@@ -63,19 +69,21 @@ contract Optimist_Initializer is Test { ...@@ -63,19 +69,21 @@ contract Optimist_Initializer is Test {
attestationStation = new AttestationStation(); attestationStation = new AttestationStation();
vm.expectEmit(true, true, false, false); vm.expectEmit(true, true, false, false);
emit Initialized(1); emit Initialized(1);
optimist = new Optimist(name, symbol, alice_admin, attestationStation);
OptimistAllowlist optimistAllowlist = new OptimistAllowlist(attestationStation, alice_admin, );
optimist = new Optimist(name, symbol, alice_admin, attestationStation, optimistAllowlist);
} }
} }
contract OptimistTest is Optimist_Initializer { contract OptimistTest is Optimist_Initializer {
function test_optimist_initialize() external { function test_initialize_success() external {
// expect name to be set // expect name to be set
assertEq(optimist.name(), name); assertEq(optimist.name(), name);
// expect symbol to be set // expect symbol to be set
assertEq(optimist.symbol(), symbol); assertEq(optimist.symbol(), symbol);
// expect attestationStation to be set // expect attestationStation to be set
assertEq(address(optimist.ATTESTATION_STATION()), address(attestationStation)); assertEq(address(optimist.ATTESTATION_STATION()), address(attestationStation));
assertEq(optimist.ATTESTOR(), alice_admin); assertEq(optimist.BASE_URI_ATTESTOR(), alice_admin);
assertEq(optimist.version(), "1.0.0"); assertEq(optimist.version(), "1.0.0");
} }
...@@ -83,7 +91,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -83,7 +91,7 @@ contract OptimistTest is Optimist_Initializer {
* @dev Bob should be able to mint an NFT if he is allowlisted * @dev Bob should be able to mint an NFT if he is allowlisted
* by the attestation station and has a balance of 0 * by the attestation station and has a balance of 0
*/ */
function test_optimist_mint_happy_path() external { function test_mint_happyPath_success() external {
// bob should start with 0 balance // bob should start with 0 balance
assertEq(optimist.balanceOf(bob), 0); assertEq(optimist.balanceOf(bob), 0);
...@@ -112,7 +120,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -112,7 +120,7 @@ contract OptimistTest is Optimist_Initializer {
/** /**
* @dev Sally should be able to mint a token on behalf of bob * @dev Sally should be able to mint a token on behalf of bob
*/ */
function test_optimist_mint_secondary_minter() external { function test_mint_secondaryMinter_succeeds() external {
attestAllowlist(bob); attestAllowlist(bob);
bytes memory data = abi.encodeWithSelector( bytes memory data = abi.encodeWithSelector(
...@@ -139,7 +147,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -139,7 +147,7 @@ contract OptimistTest is Optimist_Initializer {
/** /**
* @dev Bob should not be able to mint an NFT if he is not whitelisted * @dev Bob should not be able to mint an NFT if he is not whitelisted
*/ */
function test_optimist_mint_no_attestation() external { function test_mint_forNonAllowlistedClaimer_reverts() external {
vm.prank(bob); vm.prank(bob);
vm.expectRevert("Optimist: address is not on allowList"); vm.expectRevert("Optimist: address is not on allowList");
optimist.mint(bob); optimist.mint(bob);
...@@ -148,7 +156,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -148,7 +156,7 @@ contract OptimistTest is Optimist_Initializer {
/** /**
* @dev Bob's tx should revert if he already minted * @dev Bob's tx should revert if he already minted
*/ */
function test_optimist_mint_already_minted() external { function test_mint_forAlreadyMintedClaimer_reverts() external {
attestAllowlist(bob); attestAllowlist(bob);
// mint initial nft with bob // mint initial nft with bob
...@@ -167,7 +175,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -167,7 +175,7 @@ contract OptimistTest is Optimist_Initializer {
* @dev The baseURI should be set by attestation station * @dev The baseURI should be set by attestation station
* by the owner of contract alice_admin * by the owner of contract alice_admin
*/ */
function test_optimist_baseURI() external { function test_baseURI_succeeds() external {
attestBaseuri(base_uri); attestBaseuri(base_uri);
bytes memory data = abi.encodeWithSelector( bytes memory data = abi.encodeWithSelector(
...@@ -187,7 +195,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -187,7 +195,7 @@ contract OptimistTest is Optimist_Initializer {
* @dev The tokenURI should return the token uri * @dev The tokenURI should return the token uri
* for a minted token * for a minted token
*/ */
function test_optimist_token_uri() external { function test_tokenURI_succeeds() external {
attestAllowlist(bob); attestAllowlist(bob);
// we are using true but it can be any non empty value // we are using true but it can be any non empty value
attestBaseuri(base_uri); attestBaseuri(base_uri);
......
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
ERC721BurnableUpgradeable ERC721BurnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol"; } from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import { AttestationStation } from "./AttestationStation.sol"; import { AttestationStation } from "./AttestationStation.sol";
import { OptimistAllowlist } from "./OptimistAllowlist.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
/** /**
...@@ -15,31 +16,44 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; ...@@ -15,31 +16,44 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
* @notice A Soul Bound Token for real humans only(tm). * @notice A Soul Bound Token for real humans only(tm).
*/ */
contract Optimist is ERC721BurnableUpgradeable, Semver { contract Optimist is ERC721BurnableUpgradeable, Semver {
/**
* @notice Attestation key used by the attestor to attest the baseURI.
*/
bytes32 public constant BASE_URI_ATTESTATION_KEY = bytes32("optimist.base-uri");
/**
* @notice Attestor who attests to baseURI.
*/
address public immutable BASE_URI_ATTESTOR;
/** /**
* @notice Address of the AttestationStation contract. * @notice Address of the AttestationStation contract.
*/ */
AttestationStation public immutable ATTESTATION_STATION; AttestationStation public immutable ATTESTATION_STATION;
/** /**
* @notice Attestor who attests to baseURI and allowlist. * @notice Address of the OptimistAllowlist contract.
*/ */
address public immutable ATTESTOR; OptimistAllowlist public immutable OPTIMIST_ALLOWLIST;
/** /**
* @custom:semver 1.0.0 * @custom:semver 1.0.0
* @param _name Token name. * @param _name Token name.
* @param _symbol Token symbol. * @param _symbol Token symbol.
* @param _attestor Address of the attestor. * @param _baseURIAttestor Address of the baseURI attestor.
* @param _attestationStation Address of the AttestationStation contract. * @param _attestationStation Address of the AttestationStation contract.
* @param _optimistAllowlist Address of the OptimistAllowlist contract
*/ */
constructor( constructor(
string memory _name, string memory _name,
string memory _symbol, string memory _symbol,
address _attestor, address _baseURIAttestor,
AttestationStation _attestationStation AttestationStation _attestationStation,
OptimistAllowlist _optimistAllowlist
) Semver(1, 0, 0) { ) Semver(1, 0, 0) {
ATTESTOR = _attestor; BASE_URI_ATTESTOR = _baseURIAttestor;
ATTESTATION_STATION = _attestationStation; ATTESTATION_STATION = _attestationStation;
OPTIMIST_ALLOWLIST = _optimistAllowlist;
initialize(_name, _symbol); initialize(_name, _symbol);
} }
...@@ -76,7 +90,7 @@ contract Optimist is ERC721BurnableUpgradeable, Semver { ...@@ -76,7 +90,7 @@ contract Optimist is ERC721BurnableUpgradeable, Semver {
string( string(
abi.encodePacked( abi.encodePacked(
ATTESTATION_STATION.attestations( ATTESTATION_STATION.attestations(
ATTESTOR, BASE_URI_ATTESTOR,
address(this), address(this),
bytes32("optimist.base-uri") bytes32("optimist.base-uri")
) )
...@@ -105,17 +119,15 @@ contract Optimist is ERC721BurnableUpgradeable, Semver { ...@@ -105,17 +119,15 @@ contract Optimist is ERC721BurnableUpgradeable, Semver {
} }
/** /**
* @notice Checks whether a given address is allowed to mint the Optimist NFT yet. Since the * @notice Checks OptimistAllowlist to determine whether a given address is allowed to mint
* Optimist NFT will also be used as part of the Citizens House, mints are currently * the Optimist NFT yet. Since the Optimist NFT will also be used as part of the
* restricted. Eventually anyone will be able to mint. * Citizens House, mints are currently restricted. Eventually anyone will be able
* to mint.
* *
* @return Whether or not the address is allowed to mint yet. * @return Whether or not the address is allowed to mint yet.
*/ */
function isOnAllowList(address _recipient) public view returns (bool) { function isOnAllowList(address _recipient) public view returns (bool) {
return return OPTIMIST_ALLOWLIST.isAllowedToMint(_recipient);
ATTESTATION_STATION
.attestations(ATTESTOR, _recipient, bytes32("optimist.can-mint"))
.length > 0;
} }
/** /**
......
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