Skip to content

Commit

Permalink
fix: Small changes and tagging test (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Whytecrowe authored Apr 17, 2023
2 parents 1946680 + 39bf14f commit 742b271
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
6 changes: 3 additions & 3 deletions contracts/ZNSAddressResolver.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IZNSAddressResolver} from "./IZNSAddressResolver.sol";
import {IZNSRegistry} from "./IZNSRegistry.sol";
import { ERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import { IZNSAddressResolver } from "./IZNSAddressResolver.sol";
import { IZNSRegistry } from "./IZNSRegistry.sol";

contract ZNSAddressResolver is ERC165, IZNSAddressResolver {
/**
Expand Down
24 changes: 15 additions & 9 deletions contracts/ZNSDomainToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ pragma solidity ^0.8.18;
import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import { IZNSDomainToken } from "./IZNSDomainToken.sol";

///@title A contract for tokenizing domains under the ZNS Architecture
/**
* @title A contract for tokenizing domains under the ZNS Architecture
*/
contract ZNSDomainToken is ERC721, IZNSDomainToken {
// solhint-disable-next-line no-empty-blocks
constructor() ERC721("ZNSDomainToken", "ZDT") {}

///@notice Mints a token with a specified tokenId, using _safeMint, and sends it to the given address
///@dev TODO: Add Access Control
///@param to The address that will recieve the newly minted domain token
///@param tokenId The TokenId that the caller wishes to mint/register
/**
* @notice Mints a token with a specified tokenId, using _safeMint, and sends it to the given address
* @dev TODO: Add Access Control
* @param to The address that will recieve the newly minted domain token
* @param tokenId The TokenId that the caller wishes to mint/register
*/
function register(address to, uint256 tokenId) external {
_safeMint(to, tokenId);
}

///@notice Burns the token with the specified tokenId
///@dev TODO: Add Access Control, replace require to also allow registry to revoke
///@param tokenId The tokenId that the caller wishes to burn/revoke
/**
* @notice Burns the token with the specified tokenId
* @dev TODO: Add Access Control, replace require to also other specific contracts to revoke
* @param tokenId The tokenId that the caller wishes to burn/revoke
*/
function revoke(uint256 tokenId) external {
require(
msg.sender == ownerOf(tokenId),
"ZNSDomainToken: Owner of sender does not match Owner of token"
"ZNSDomainToken: Only token owner can burn a token"
);
_burn(tokenId);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/ZNSPriceOracle.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IZNSPriceOracle} from "./IZNSPriceOracle.sol";
import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { IZNSPriceOracle } from "./IZNSPriceOracle.sol";

contract ZNSPriceOracle is IZNSPriceOracle, Initializable {
/**
Expand Down
21 changes: 11 additions & 10 deletions contracts/ZNSRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract ZNSRegistry is IZNSRegistry, ERC1967UpgradeUpgradeable {
modifier onlyOwnerOrOperator(bytes32 domainNameHash) {
address owner = records[domainNameHash].owner;
require(
msg.sender == owner || operators[owner][msg.sender],
msg.sender == owner || isAllowedOperator(owner, msg.sender),
"ZNS: Not allowed"
);
_;
Expand Down Expand Up @@ -68,7 +68,7 @@ contract ZNSRegistry is IZNSRegistry, ERC1967UpgradeUpgradeable {
function isAllowedOperator(
address owner,
address operator
) external view returns (bool) {
) public view returns (bool) {
return operators[owner][operator];
}

Expand Down Expand Up @@ -102,33 +102,33 @@ contract ZNSRegistry is IZNSRegistry, ERC1967UpgradeUpgradeable {

/**
* @dev Set or create a subdomain record
* @param domainNameHash The base domain name hash
* @param parentNameHash The parent domain name hash
* @param label The label label of the subdomain
* @param owner The owner to set
* @param resolver The resolver to set
*/
function setSubdomainRecord(
bytes32 domainNameHash,
bytes32 parentNameHash,
bytes32 label,
address owner,
address resolver
) external {
bytes32 subdomain = setSubdomainOwner(domainNameHash, label, owner);
bytes32 subdomain = setSubdomainOwner(parentNameHash, label, owner);
setDomainResolver(subdomain, resolver);
}

/**
* @dev Update the subdomain's owner
* @param domainNameHash The base domain name hash
* @param parentNameHash The parent domain name hash
* @param label The label of the subdomain
* @param owner The owner to set
*/
function setSubdomainOwner(
bytes32 domainNameHash,
bytes32 parentNameHash,
bytes32 label,
address owner
) public onlyOwnerOrOperator(domainNameHash) returns (bytes32) {
bytes32 subdomain = keccak256(abi.encodePacked(domainNameHash, label));
) public onlyOwnerOrOperator(parentNameHash) returns (bytes32) {
bytes32 subdomain = keccak256(abi.encodePacked(parentNameHash, label));
_setDomainOwner(subdomain, owner);

emit DomainOwnerSet(owner, subdomain);
Expand Down Expand Up @@ -201,6 +201,7 @@ contract ZNSRegistry is IZNSRegistry, ERC1967UpgradeUpgradeable {
* @param owner The owner to set
*/
function _setDomainOwner(bytes32 domainNameHash, address owner) internal {
require(owner != address(0), "ZNS: Owner can NOT be zero address");
records[domainNameHash].owner = owner;
}

Expand All @@ -213,7 +214,7 @@ contract ZNSRegistry is IZNSRegistry, ERC1967UpgradeUpgradeable {
bytes32 domainNameHash,
address resolver
) internal {
require(resolver != address(0), "ZNS: Zero address");
require(resolver != address(0), "ZNS: Resolver can NOT be zero address");

records[domainNameHash].resolver = resolver;
}
Expand Down
2 changes: 1 addition & 1 deletion test/ZNSDomainToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe("ZNSDomainToken:", () => {
.connect(deployer)
.revoke(tokenId);
await expect(tx).to.be.revertedWith(
"ZNSDomainToken: Owner of sender does not match Owner of token"
"ZNSDomainToken: Only token owner can burn a token"
);

// Verify token has not been burned
Expand Down

0 comments on commit 742b271

Please sign in to comment.