Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Coupon mintlist system #101

Open
wants to merge 15 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ MONGO_DB_VERSION=
ARCHIVE_PREVIOUS_DB_VERSION="true" | "false"

# ENV vars for Logger
LOG_LEVEL="debug" | "info" | "warn" | "error
LOG_LEVEL="debug" | "info" | "warn" | "error"

# Removes logger output and does not write to file as well
SILENT_LOGGER="false" | "true"

Expand Down Expand Up @@ -65,6 +66,10 @@ ADMIN_ADDRESSES=
MONITOR_CONTRACTS="false"
VERIFY_CONTRACTS="false"

# The domain name and version for using EIP712
EIP712_NAME=
EIP712_VERSION=

DEFENDER_KEY=
DEFENDER_SECRET=
RELAYER_KEY=
Expand Down
59 changes: 59 additions & 0 deletions contracts/registrar/EIP712Helper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

import { IEIP712Helper } from "./IEIP712Helper.sol";
import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";


contract EIP712Helper is EIP712, IEIP712Helper {
using ECDSA for bytes32;

// TODO make this real, not the HH rootOwner
// idea around creating signer in `hashCoupon` or similar
// then storing that data, and in recreation we have to get the address that signed?
// how do we bulk sign?
address private constant COUPON_SIGNER = 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this should be a state var.


bytes32 private constant COUPON_TYPEHASH = keccak256(
"Coupon(bytes32 parentHash,address registrantAddress,string domainLabel)"
);

constructor(
string memory name,
string memory version
) EIP712(name, version) {}

function hashCoupon(Coupon memory coupon) public view override returns (bytes32) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be a pure function?

return
_hashTypedDataV4(
keccak256(
abi.encode(
COUPON_TYPEHASH,
coupon.parentHash,
coupon.registrantAddress,
keccak256(bytes(coupon.domainLabel))
)
)
);
}

/**
* @notice Recovers the account that signed a message using openzeppelin's ECDSA library.
* @param coupon The unsigned coupon data
* @param signature The signed message
*/
function recoverSigner(Coupon memory coupon, bytes memory signature) public view override returns (address) {
return _recoverSigner(coupon, signature);
}

function isCouponSigner(Coupon memory coupon, bytes memory signature) public view override returns (bool) {
address signer = _recoverSigner(coupon, signature);
return signer == COUPON_SIGNER;
}

function _recoverSigner(Coupon memory coupon, bytes memory signature) internal view returns (address) {
bytes32 hash = hashCoupon(coupon);
return hash.recover(signature);
}
}
25 changes: 25 additions & 0 deletions contracts/registrar/IEIP712Helper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;


interface IEIP712Helper {
struct Coupon {
bytes32 parentHash;
address registrantAddress;
string domainLabel;
}

function hashCoupon(
Coupon memory coupon
) external view returns (bytes32);

function recoverSigner(
Coupon memory coupon,
bytes memory signature
) external view returns (address);

function isCouponSigner(
Coupon memory coupon,
bytes memory signature
) external view returns (bool);
}
50 changes: 24 additions & 26 deletions contracts/registrar/IZNSSubRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ pragma solidity 0.8.18;
import { IDistributionConfig } from "../types/IDistributionConfig.sol";
import { PaymentConfig } from "../treasury/IZNSTreasury.sol";
import { IZNSPricer } from "../types/IZNSPricer.sol";

import { IEIP712Helper } from "./IEIP712Helper.sol";

/**
* @title IZNSSubRegistrar.sol - Interface for the ZNSSubRegistrar contract responsible for registering subdomains.
*/
interface IZNSSubRegistrar is IDistributionConfig {

struct RegistrationArgs {
bytes32 parentHash;
string label;
string tokenURI;
address domainAddress;
}

/**
* @notice Emitted when a new `DistributionConfig.pricerContract` is set for a domain.
*/
Expand Down Expand Up @@ -65,31 +72,30 @@ interface IZNSSubRegistrar is IDistributionConfig {
AccessType accessType
);

function isMintlistedForDomain(
bytes32 domainHash,
address candidate
) external view returns (bool);

function initialize(
address _accessController,
address _registry,
address _rootRegistrar
address accessController,
address registry,
address rootRegistrar,
address eip712Helper
) external;

function registerSubdomain(
bytes32 parentHash,
string calldata label,
address domainAddress,
string calldata tokenURI,
DistributionConfig calldata configForSubdomains,
PaymentConfig calldata paymentConfig
RegistrationArgs calldata args,
DistributionConfig calldata distrConfig,
PaymentConfig calldata paymentConfig,
bytes calldata signature
) external returns (bytes32);

function hashWithParent(
bytes32 parentHash,
string calldata label
) external pure returns (bytes32);

function recoverSigner(
IEIP712Helper.Coupon memory coupon,
bytes memory signature
) external view returns (address);

function setDistributionConfigForDomain(
bytes32 parentHash,
DistributionConfig calldata config
Expand All @@ -110,17 +116,9 @@ interface IZNSSubRegistrar is IDistributionConfig {
AccessType accessType
) external;

function updateMintlistForDomain(
bytes32 domainHash,
address[] calldata candidates,
bool[] calldata allowed
) external;

function clearMintlistForDomain(bytes32 domainHash) external;

function clearMintlistAndLock(bytes32 domainHash) external;
function setRegistry(address registry) external;

function setRegistry(address registry_) external;
function setEIP712Helper(address helper) external;

function setRootRegistrar(address registrar_) external;
function setRootRegistrar(address registrar) external;
}
3 changes: 2 additions & 1 deletion contracts/registrar/ZNSRootRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ contract ZNSRootRegistrar is
"ZNSRootRegistrar: Not the owner of both Name and Token"
);

subRegistrar.clearMintlistAndLock(domainHash);
// subRegistrar.clearMintlistAndLock(domainHash);
subRegistrar.setAccessTypeForDomain(domainHash, AccessType.LOCKED);
_coreRevoke(domainHash, msg.sender);
}

Expand Down
Loading