Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
630c876b
Commit
630c876b
authored
Mar 30, 2023
by
James Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update_Optimist_to_use_allowlist
parent
915036aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
29 deletions
+49
-29
Optimist.t.sol
...ontracts-periphery/contracts/foundry-tests/Optimist.t.sol
+23
-15
Optimist.sol
...ntracts-periphery/contracts/universal/op-nft/Optimist.sol
+26
-14
No files found.
packages/contracts-periphery/contracts/foundry-tests/Optimist.t.sol
View file @
630c876b
...
...
@@ -12,9 +12,6 @@ contract Optimist_Initializer is Test {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
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 symbol = "OPTIMISTSYMBOL";
string constant base_uri =
...
...
@@ -22,6 +19,12 @@ contract Optimist_Initializer is Test {
AttestationStation attestationStation;
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 {
AttestationStation.AttestationData[]
memory attestationData = new AttestationStation.AttestationData[](1);
...
...
@@ -48,14 +51,17 @@ contract Optimist_Initializer is Test {
}
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
vm.deal(alice_admin, 1 ether);
vm.deal(bob, 1 ether);
vm.deal(sally, 1 ether);
vm.label(alice_admin, "alice_admin");
vm.label(bob, "bob");
vm.label(sally, "sally");
_initializeContracts();
}
...
...
@@ -63,19 +69,21 @@ contract Optimist_Initializer is Test {
attestationStation = new AttestationStation();
vm.expectEmit(true, true, false, false);
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 {
function test_
optimist_initialize
() external {
function test_
initialize_success
() external {
// expect name to be set
assertEq(optimist.name(), name);
// expect symbol to be set
assertEq(optimist.symbol(), symbol);
// expect attestationStation to be set
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");
}
...
...
@@ -83,7 +91,7 @@ contract OptimistTest is Optimist_Initializer {
* @dev Bob should be able to mint an NFT if he is allowlisted
* 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
assertEq(optimist.balanceOf(bob), 0);
...
...
@@ -112,7 +120,7 @@ contract OptimistTest is Optimist_Initializer {
/**
* @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);
bytes memory data = abi.encodeWithSelector(
...
...
@@ -139,7 +147,7 @@ contract OptimistTest is Optimist_Initializer {
/**
* @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.expectRevert("Optimist: address is not on allowList");
optimist.mint(bob);
...
...
@@ -148,7 +156,7 @@ contract OptimistTest is Optimist_Initializer {
/**
* @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);
// mint initial nft with bob
...
...
@@ -167,7 +175,7 @@ contract OptimistTest is Optimist_Initializer {
* @dev The baseURI should be set by attestation station
* by the owner of contract alice_admin
*/
function test_
optimist_baseURI
() external {
function test_
baseURI_succeeds
() external {
attestBaseuri(base_uri);
bytes memory data = abi.encodeWithSelector(
...
...
@@ -187,7 +195,7 @@ contract OptimistTest is Optimist_Initializer {
* @dev The tokenURI should return the token uri
* for a minted token
*/
function test_
optimist_token_uri
() external {
function test_
tokenURI_succeeds
() external {
attestAllowlist(bob);
// we are using true but it can be any non empty value
attestBaseuri(base_uri);
...
...
packages/contracts-periphery/contracts/universal/op-nft/Optimist.sol
View file @
630c876b
...
...
@@ -6,6 +6,7 @@ import {
ERC721BurnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import { AttestationStation } from "./AttestationStation.sol";
import { OptimistAllowlist } from "./OptimistAllowlist.sol";
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).
*/
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.
*/
AttestationStation public immutable ATTESTATION_STATION;
/**
* @notice A
ttestor who attests to baseURI and allowlis
t.
* @notice A
ddress of the OptimistAllowlist contrac
t.
*/
address public immutable ATTESTOR
;
OptimistAllowlist public immutable OPTIMIST_ALLOWLIST
;
/**
* @custom:semver 1.0.0
* @param _name Token name.
* @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 _optimistAllowlist Address of the OptimistAllowlist contract
*/
constructor(
string memory _name,
string memory _symbol,
address _attestor,
AttestationStation _attestationStation
address _baseURIAttestor,
AttestationStation _attestationStation,
OptimistAllowlist _optimistAllowlist
) Semver(1, 0, 0) {
ATTESTOR = _a
ttestor;
BASE_URI_ATTESTOR = _baseURIA
ttestor;
ATTESTATION_STATION = _attestationStation;
OPTIMIST_ALLOWLIST = _optimistAllowlist;
initialize(_name, _symbol);
}
...
...
@@ -76,7 +90,7 @@ contract Optimist is ERC721BurnableUpgradeable, Semver {
string(
abi.encodePacked(
ATTESTATION_STATION.attestations(
ATTESTOR,
BASE_URI_
ATTESTOR,
address(this),
bytes32("optimist.base-uri")
)
...
...
@@ -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
* Optimist NFT will also be used as part of the Citizens House, mints are currently
* restricted. Eventually anyone will be able to mint.
* @notice Checks OptimistAllowlist to determine whether a given address is allowed to mint
* the Optimist NFT yet. Since the Optimist NFT will also be used as part of the
* Citizens House, mints are currently restricted. Eventually anyone will be able
* to mint.
*
* @return Whether or not the address is allowed to mint yet.
*/
function isOnAllowList(address _recipient) public view returns (bool) {
return
ATTESTATION_STATION
.attestations(ATTESTOR, _recipient, bytes32("optimist.can-mint"))
.length > 0;
return OPTIMIST_ALLOWLIST.isAllowedToMint(_recipient);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment