Skip to content

Commit

Permalink
Codebase and dependency update (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
Whytecrowe authored Jul 2, 2024
2 parents 5dd6a86 + 6908566 commit d0e1ae5
Show file tree
Hide file tree
Showing 59 changed files with 2,381 additions and 2,326 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ orbs:
defaults: &defaults
working_directory: ~/repo
docker:
- image: cimg/node:18.15.0
- image: cimg/node:18.20.3
- image: mongo:7.0.0-rc5-jammy

jobs:
Expand Down
4 changes: 4 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
mocha: {
grep: "@skip-on-coverage", // Find everything with this tag
invert: true // Run the grep's inverse set.
},
skipFiles: [
'utils/StringUtils.sol',
'token/mocks',
Expand Down
6 changes: 3 additions & 3 deletions contracts/access/AAccessControlled.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { IZNSAccessController } from "./IZNSAccessController.sol";
import { ZeroAddressPassed } from "../utils/CommonErrors.sol";


/**
Expand All @@ -11,7 +12,6 @@ import { IZNSAccessController } from "./IZNSAccessController.sol";
* this contract needs to be inherited by the module.
*/
abstract contract AAccessControlled {

/**
* @notice Emitted when the access controller contract address is set.
*/
Expand Down Expand Up @@ -66,7 +66,7 @@ abstract contract AAccessControlled {
* @param _accessController Address of the ZNSAccessController contract.
*/
function _setAccessController(address _accessController) internal {
require(_accessController != address(0), "AC: _accessController is 0x0 address");
if (_accessController == address(0)) revert ZeroAddressPassed();
accessController = IZNSAccessController(_accessController);
emit AccessControllerSet(_accessController);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/access/IZNSAccessController.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";

Expand Down
9 changes: 4 additions & 5 deletions contracts/access/ZNSAccessController.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { IZNSAccessController } from "./IZNSAccessController.sol";
import { ZNSRoles } from "./ZNSRoles.sol";
import { ZeroAddressPassed } from "../utils/CommonErrors.sol";


/**
Expand Down Expand Up @@ -77,10 +78,8 @@ contract ZNSAccessController is AccessControl, ZNSRoles, IZNSAccessController {
function _grantRoleToMany(bytes32 role, address[] memory addresses) internal {
uint256 length = addresses.length;
for (uint256 i = 0; i < length; ++i) {
require(
addresses[i] != address(0),
"ZNSAccessController: Can't grant role to zero address"
);
if (addresses[i] == address(0)) revert ZeroAddressPassed();

_grantRole(role, addresses[i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/access/ZNSRoles.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;


/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/oz-proxies/ERC1967ProxyAcc.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

// solhint-disable-next-line no-global-import
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/oz-proxies/TransparentUpgradeableProxyAcc.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

// solhint-disable-next-line no-global-import
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
Expand Down
19 changes: 18 additions & 1 deletion contracts/price/IZNSCurvePricer.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { ICurvePriceConfig } from "../types/ICurvePriceConfig.sol";
import { IZNSPricer } from "../types/IZNSPricer.sol";


interface IZNSCurvePricer is ICurvePriceConfig, IZNSPricer {

/**
* @notice Reverted when multiplier passed by the domain owner
* is equal to 0 or more than 10^18, which is too large.
*/
error InvalidMultiplierPassed(uint256 multiplier);

/**
* @notice Reverted when `priceConfig` set by the owner does not result in a proper asymptotic curve
* and one of it's incorrect values causes the price spike at maxLength, meaning that the price
* for a domain label shorter than `baseLength` (the one before `minPrice`) becomes higher than `minPrice`.
*/
error InvalidConfigCausingPriceSpikes(
bytes32 configsDomainHash,
uint256 minPrice,
uint256 previousToMinPrice
);

/**
* @notice Emitted when the `maxPrice` is set in `CurvePriceConfig`
* @param price The new maxPrice value
Expand Down
2 changes: 1 addition & 1 deletion contracts/price/IZNSFixedPricer.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { IZNSPricer } from "../types/IZNSPricer.sol";

Expand Down
27 changes: 12 additions & 15 deletions contracts/price/ZNSCurvePricer.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { IZNSCurvePricer } from "./IZNSCurvePricer.sol";
Expand Down Expand Up @@ -75,10 +75,7 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
string calldata label,
bool skipValidityCheck
) public view override returns (uint256) {
require(
priceConfigs[parentHash].isSet,
"ZNSCurvePricer: parent's price config has not been set properly through IZNSPricer.setPriceConfig()"
);
if (!priceConfigs[parentHash].isSet) revert ParentPriceConfigNotSet(parentHash);

if (!skipValidityCheck) {
// Confirms string values are only [a-z0-9-]
Expand Down Expand Up @@ -256,8 +253,8 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
bytes32 domainHash,
uint256 multiplier
) public override onlyOwnerOrOperator(domainHash) {
require(multiplier != 0, "ZNSCurvePricer: precisionMultiplier cannot be 0");
require(multiplier <= 10**18, "ZNSCurvePricer: precisionMultiplier cannot be greater than 10^18");
if (multiplier == 0 || multiplier > 10**18) revert InvalidMultiplierPassed(multiplier);

priceConfigs[domainHash].precisionMultiplier = multiplier;

emit PrecisionMultiplierSet(domainHash, multiplier);
Expand All @@ -275,10 +272,8 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
public
override
onlyOwnerOrOperator(domainHash) {
require(
feePercentage <= PERCENTAGE_BASIS,
"ZNSCurvePricer: feePercentage cannot be greater than PERCENTAGE_BASIS"
);
if (feePercentage > PERCENTAGE_BASIS)
revert FeePercentageValueTooLarge(feePercentage, PERCENTAGE_BASIS);

priceConfigs[domainHash].feePercentage = feePercentage;
emit FeePercentageSet(domainHash, feePercentage);
Expand Down Expand Up @@ -337,10 +332,12 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
*/
function _validateConfig(bytes32 domainHash) internal view {
uint256 prevToMinPrice = _getPrice(domainHash, priceConfigs[domainHash].maxLength);
require(
priceConfigs[domainHash].minPrice <= prevToMinPrice,
"ZNSCurvePricer: incorrect value set causes the price spike at maxLength."
);
if (priceConfigs[domainHash].minPrice > prevToMinPrice)
revert InvalidConfigCausingPriceSpikes(
domainHash,
priceConfigs[domainHash].minPrice,
prevToMinPrice
);
}

/**
Expand Down
13 changes: 4 additions & 9 deletions contracts/price/ZNSFixedPricer.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { AAccessControlled } from "../access/AAccessControlled.sol";
import { ARegistryWired } from "../registry/ARegistryWired.sol";
Expand Down Expand Up @@ -60,10 +60,7 @@ contract ZNSFixedPricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
string calldata label,
bool skipValidityCheck
) public override view returns (uint256) {
require(
priceConfigs[parentHash].isSet,
"ZNSFixedPricer: parent's price config has not been set properly through IZNSPricer.setPriceConfig()"
);
if (!priceConfigs[parentHash].isSet) revert ParentPriceConfigNotSet(parentHash);

if (!skipValidityCheck) {
// Confirms string values are only [a-z0-9-]
Expand Down Expand Up @@ -161,10 +158,8 @@ contract ZNSFixedPricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
* @param feePercentage The new feePercentage
*/
function _setFeePercentage(bytes32 domainHash, uint256 feePercentage) internal {
require(
feePercentage <= PERCENTAGE_BASIS,
"ZNSFixedPricer: feePercentage cannot be greater than PERCENTAGE_BASIS"
);
if (feePercentage > PERCENTAGE_BASIS)
revert FeePercentageValueTooLarge(feePercentage, PERCENTAGE_BASIS);

priceConfigs[domainHash].feePercentage = feePercentage;
emit FeePercentageSet(domainHash, feePercentage);
Expand Down
10 changes: 8 additions & 2 deletions contracts/registrar/IZNSRootRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { IDistributionConfig } from "../types/IDistributionConfig.sol";
import { PaymentConfig } from "../treasury/IZNSTreasury.sol";
Expand Down Expand Up @@ -42,13 +42,19 @@ struct CoreRegisterArgs {
* + `isStakePayment`: A flag for whether the payment is a stake payment or not
*/
interface IZNSRootRegistrar is IDistributionConfig {
error NotTheOwnerOf(
OwnerOf ownerOf,
address candidate,
bytes32 domainHash
);

error InvalidOwnerOfEnumValue(OwnerOf value);

enum OwnerOf {
NAME,
TOKEN,
BOTH
}

/**
* @notice Emitted when a NEW domain is registered.
* @dev `domainAddress` parameter is the address to which a domain name will relate to in ZNS.
Expand Down
12 changes: 11 additions & 1 deletion contracts/registrar/IZNSSubRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { IDistributionConfig } from "../types/IDistributionConfig.sol";
import { PaymentConfig } from "../treasury/IZNSTreasury.sol";
Expand All @@ -10,6 +10,16 @@ import { IZNSPricer } from "../types/IZNSPricer.sol";
* @title IZNSSubRegistrar.sol - Interface for the ZNSSubRegistrar contract responsible for registering subdomains.
*/
interface IZNSSubRegistrar is IDistributionConfig {
/**
* @notice Reverted when someone other than parent owner is trying to buy a subdomain under the parent that is locked\
* or when the parent provided does not exist.
*/
error ParentLockedOrDoesntExist(bytes32 parentHash);

/**
* @notice Reverted when the buyer of subdomain is not approved by the parent in it's mintlist.
*/
error SenderNotApprovedForPurchase(bytes32 parentHash, address sender);

/**
* @notice Emitted when a new `DistributionConfig.pricerContract` is set for a domain.
Expand Down
48 changes: 21 additions & 27 deletions contracts/registrar/ZNSRootRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
pragma solidity 0.8.26;

import { AAccessControlled } from "../access/AAccessControlled.sol";
import { ARegistryWired } from "../registry/ARegistryWired.sol";
Expand All @@ -11,6 +11,7 @@ import { IZNSSubRegistrar } from "../registrar/IZNSSubRegistrar.sol";
import { IZNSPricer } from "../types/IZNSPricer.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { StringUtils } from "../utils/StringUtils.sol";
import { ZeroAddressPassed, DomainAlreadyExists } from "../utils/CommonErrors.sol";


/**
Expand Down Expand Up @@ -100,10 +101,8 @@ contract ZNSRootRegistrar is
// Create hash for given domain name
bytes32 domainHash = keccak256(bytes(name));

require(
!registry.exists(domainHash),
"ZNSRootRegistrar: Domain already exists"
);
if (registry.exists(domainHash))
revert DomainAlreadyExists(domainHash);

// Get price for the domain
uint256 domainPrice = rootPricer.getPrice(0x0, name, true);
Expand Down Expand Up @@ -256,10 +255,8 @@ contract ZNSRootRegistrar is
external
override
{
require(
isOwnerOf(domainHash, msg.sender, OwnerOf.BOTH),
"ZNSRootRegistrar: Not the owner of both Name and Token"
);
if (!isOwnerOf(domainHash, msg.sender, OwnerOf.BOTH))
revert NotTheOwnerOf(OwnerOf.BOTH, msg.sender, domainHash);

subRegistrar.clearMintlistAndLock(domainHash);
_coreRevoke(domainHash, msg.sender);
Expand Down Expand Up @@ -305,10 +302,9 @@ contract ZNSRootRegistrar is
external
override
{
require(
isOwnerOf(domainHash, msg.sender, OwnerOf.TOKEN),
"ZNSRootRegistrar: Not the owner of the Token"
);
if (!isOwnerOf(domainHash, msg.sender, OwnerOf.TOKEN))
revert NotTheOwnerOf(OwnerOf.TOKEN, msg.sender, domainHash);

registry.updateDomainOwner(domainHash, msg.sender);

emit DomainReclaimed(domainHash, msg.sender);
Expand All @@ -330,7 +326,7 @@ contract ZNSRootRegistrar is
&& candidate == domainToken.ownerOf(uint256(domainHash));
}

revert("Wrong enum value for `ownerOf`");
revert InvalidOwnerOfEnumValue(ownerOf);
}

/**
Expand All @@ -348,10 +344,9 @@ contract ZNSRootRegistrar is
* @param rootPricer_ Address of the IZNSPricer type contract to set as pricer of Root Domains
*/
function setRootPricer(address rootPricer_) public override onlyAdmin {
require(
rootPricer_ != address(0),
"ZNSRootRegistrar: rootPricer_ is 0x0 address"
);
if (rootPricer_ == address(0))
revert ZeroAddressPassed();

rootPricer = IZNSPricer(rootPricer_);

emit RootPricerSet(rootPricer_);
Expand All @@ -363,10 +358,9 @@ contract ZNSRootRegistrar is
* @param treasury_ Address of the `ZNSTreasury` contract
*/
function setTreasury(address treasury_) public override onlyAdmin {
require(
treasury_ != address(0),
"ZNSRootRegistrar: treasury_ is 0x0 address"
);
if (treasury_ == address(0))
revert ZeroAddressPassed();

treasury = IZNSTreasury(treasury_);

emit TreasurySet(treasury_);
Expand All @@ -378,10 +372,9 @@ contract ZNSRootRegistrar is
* @param domainToken_ Address of the `ZNSDomainToken` contract
*/
function setDomainToken(address domainToken_) public override onlyAdmin {
require(
domainToken_ != address(0),
"ZNSRootRegistrar: domainToken_ is 0x0 address"
);
if (domainToken_ == address(0))
revert ZeroAddressPassed();

domainToken = IZNSDomainToken(domainToken_);

emit DomainTokenSet(domainToken_);
Expand All @@ -392,7 +385,8 @@ contract ZNSRootRegistrar is
* @param subRegistrar_ Address of the `ZNSSubRegistrar` contract
*/
function setSubRegistrar(address subRegistrar_) external override onlyAdmin {
require(subRegistrar_ != address(0), "ZNSRootRegistrar: subRegistrar_ is 0x0 address");
if (subRegistrar_ == address(0))
revert ZeroAddressPassed();

subRegistrar = IZNSSubRegistrar(subRegistrar_);
emit SubRegistrarSet(subRegistrar_);
Expand Down
Loading

0 comments on commit d0e1ae5

Please sign in to comment.