Commit a8798268 authored by James Kim's avatar James Kim

refactor _hasValidAttestation

parent 1ded9c45
...@@ -65,6 +65,26 @@ contract OptimistAllowlist is Semver { ...@@ -65,6 +65,26 @@ contract OptimistAllowlist is Semver {
OPTIMIST_INVITER = _optimistInviter; OPTIMIST_INVITER = _optimistInviter;
} }
/**
* @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.
*
* Currently, address is allowed to mint if it satisfies any of the following:
* 1) Has a valid 'optimist.can-mint' attestation from the allowlist attestor.
* 2) Has a valid 'coinbase.quest-eligible' attestation from Coinbase Quest attestor
* 3) Has a valid 'optimist.can-mint-from-invite' attestation from the OptimistInviter
* contract.
*
* @return Whether or not the address is allowed to mint yet.
*/
function isAllowedToMint(address _claimer) public view returns (bool) {
return
_hasAttestationFromAllowlistAttestor(_claimer) ||
_hasAttestationFromCoinbaseQuestAttestor(_claimer) ||
_hasAttestationFromOptimistInviter(_claimer);
}
/** /**
* @notice Checks whether an address has a valid 'optimist.can-mint' attestation from the * @notice Checks whether an address has a valid 'optimist.can-mint' attestation from the
* allowlist attestor. * allowlist attestor.
...@@ -74,12 +94,9 @@ contract OptimistAllowlist is Semver { ...@@ -74,12 +94,9 @@ contract OptimistAllowlist is Semver {
* @return Whether or not the address has a valid attestation. * @return Whether or not the address has a valid attestation.
*/ */
function _hasAttestationFromAllowlistAttestor(address _claimer) internal view returns (bool) { function _hasAttestationFromAllowlistAttestor(address _claimer) internal view returns (bool) {
// Expected attestation value is bytes32("true"), but we consider any non-zero value // Expected attestation value is bytes32("true")
// to be truthy.
return return
ATTESTATION_STATION _hasValidAttestation(ALLOWLIST_ATTESTOR, _claimer, OPTIMIST_CAN_MINT_ATTESTATION_KEY);
.attestations(ALLOWLIST_ATTESTOR, _claimer, OPTIMIST_CAN_MINT_ATTESTATION_KEY)
.length > 0;
} }
/** /**
...@@ -94,16 +111,13 @@ contract OptimistAllowlist is Semver { ...@@ -94,16 +111,13 @@ contract OptimistAllowlist is Semver {
view view
returns (bool) returns (bool)
{ {
// Expected attestation value is bytes32("true"), but we consider any non-zero value // Expected attestation value is bytes32("true")
// to be truthy.
return return
ATTESTATION_STATION _hasValidAttestation(
.attestations( COINBASE_QUEST_ATTESTOR,
COINBASE_QUEST_ATTESTOR, _claimer,
_claimer, COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY
COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY );
)
.length > 0;
} }
/** /**
...@@ -114,34 +128,30 @@ contract OptimistAllowlist is Semver { ...@@ -114,34 +128,30 @@ contract OptimistAllowlist is Semver {
* @return Whether or not the address has a valid attestation. * @return Whether or not the address has a valid attestation.
*/ */
function _hasAttestationFromOptimistInviter(address _claimer) internal view returns (bool) { function _hasAttestationFromOptimistInviter(address _claimer) internal view returns (bool) {
// Expected attestation value is the inviter's address, but we just check that it's set. // Expected attestation value is the inviter's address
return return
ATTESTATION_STATION _hasValidAttestation(
.attestations( OPTIMIST_INVITER,
OPTIMIST_INVITER, _claimer,
_claimer, OptimistConstants.OPTIMIST_CAN_MINT_FROM_INVITE_ATTESTATION_KEY
OptimistConstants.OPTIMIST_CAN_MINT_FROM_INVITE_ATTESTATION_KEY );
)
.length > 0;
} }
/** /**
* @notice Checks whether a given address is allowed to mint the Optimist NFT yet. Since the * @notice Checks whether an address has a valid truthy attestation.
* Optimist NFT will also be used as part of the Citizens House, mints are currently * Any attestation val other than bytes32("") is considered truthy.
* restricted. Eventually anyone will be able to mint.
* *
* Currently, address is allowed to mint if it satisfies any of the following: * @param _creator Address that made the attestation.
* 1) Has a valid 'optimist.can-mint' attestation from the allowlist attestor. * @param _about Address attestation is about.
* 2) Has a valid 'coinbase.quest-eligible' attestation from Coinbase Quest attestor * @param _key Key of the attestation.
* 3) Has a valid 'optimist.can-mint-from-invite' attestation from the OptimistInviter
* contract.
* *
* @return Whether or not the address is allowed to mint yet. * @return Whether or not the address has a valid truthy attestation.
*/ */
function isAllowedToMint(address _claimer) public view returns (bool) { function _hasValidAttestation(
return address _creator,
_hasAttestationFromAllowlistAttestor(_claimer) || address _about,
_hasAttestationFromCoinbaseQuestAttestor(_claimer) || bytes32 _key
_hasAttestationFromOptimistInviter(_claimer); ) internal view returns (bool) {
return ATTESTATION_STATION.attestations(_creator, _about, _key).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