Skip to content

Commit

Permalink
fix: Add setting payment config as part of default registration proce…
Browse files Browse the repository at this point in the history
…ss (#79)
  • Loading branch information
Whytecrowe authored Dec 1, 2023
2 parents 6a8c490 + 2c4d39b commit 06d7783
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 53 deletions.
5 changes: 4 additions & 1 deletion contracts/registrar/IZNSRootRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.18;

import { IDistributionConfig } from "../types/IDistributionConfig.sol";
import { PaymentConfig } from "../treasury/IZNSTreasury.sol";


/**
Expand All @@ -18,6 +19,7 @@ struct CoreRegisterArgs {
string label;
string tokenURI;
bool isStakePayment;
PaymentConfig paymentConfig;
}

/**
Expand Down Expand Up @@ -127,7 +129,8 @@ interface IZNSRootRegistrar is IDistributionConfig {
string calldata name,
address domainAddress,
string calldata tokenURI,
DistributionConfig calldata distributionConfig
DistributionConfig calldata distributionConfig,
PaymentConfig calldata paymentConfig
) external returns (bytes32);

function coreRegister(
Expand Down
4 changes: 3 additions & 1 deletion contracts/registrar/IZNSSubRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.18;

import { IDistributionConfig } from "../types/IDistributionConfig.sol";
import { PaymentConfig } from "../treasury/IZNSTreasury.sol";
import { IZNSPricer } from "../types/IZNSPricer.sol";


Expand Down Expand Up @@ -79,7 +80,8 @@ interface IZNSSubRegistrar is IDistributionConfig {
string calldata label,
address domainAddress,
string calldata tokenURI,
DistributionConfig calldata configForSubdomains
DistributionConfig calldata configForSubdomains,
PaymentConfig calldata paymentConfig
) external returns (bytes32);

function hashWithParent(
Expand Down
22 changes: 15 additions & 7 deletions contracts/registrar/ZNSRootRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

import { AAccessControlled } from "../access/AAccessControlled.sol";
import { ARegistryWired } from "../registry/ARegistryWired.sol";
import { IZNSRootRegistrar, CoreRegisterArgs } from "./IZNSRootRegistrar.sol";
import { IZNSTreasury } from "../treasury/IZNSTreasury.sol";
import { IZNSTreasury, PaymentConfig } from "../treasury/IZNSTreasury.sol";
import { IZNSDomainToken } from "../token/IZNSDomainToken.sol";
import { IZNSAddressResolver } from "../resolver/IZNSAddressResolver.sol";
import { AAccessControlled } from "../access/AAccessControlled.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { IZNSSubRegistrar } from "../registrar/IZNSSubRegistrar.sol";
import { ARegistryWired } from "../registry/ARegistryWired.sol";
import { IZNSPricer } from "../types/IZNSPricer.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { StringUtils } from "../utils/StringUtils.sol";


Expand Down Expand Up @@ -75,7 +75,7 @@ contract ZNSRootRegistrar is
* checks existence of the domain in the registry and reverts if it exists.
* Calls `ZNSTreasury` to do the staking part, gets `tokenId` for the new token to be minted
* as domain hash casted to uint256, mints the token and sets the domain data in the `ZNSRegistry`
* and, possibly, `ZNSAddressResolver`. Emits a `DomainRegistered` event.
* and, possibly, `ZNSAddressResolver`. Emits a `DomainRegistered` event.
* @param name Name (label) of the domain to register
* @param domainAddress (optional) Address for the `ZNSAddressResolver` to return when requested
* @param tokenURI URI to assign to the Domain Token issued for the domain
Expand All @@ -88,7 +88,8 @@ contract ZNSRootRegistrar is
string calldata name,
address domainAddress,
string calldata tokenURI,
DistributionConfig calldata distributionConfig
DistributionConfig calldata distributionConfig,
PaymentConfig calldata paymentConfig
) external override returns (bytes32) {
// Confirms string values are only [a-z0-9-]
name.validate();
Expand All @@ -114,7 +115,8 @@ contract ZNSRootRegistrar is
0,
name,
tokenURI,
true
true,
paymentConfig
)
);

Expand Down Expand Up @@ -184,6 +186,12 @@ contract ZNSRootRegistrar is
registry.createDomainRecord(args.domainHash, args.registrant, "");
}

// Because we check in the web app for the existance of both values in a payment config,
// it's fine to just check for one here
if (args.paymentConfig.beneficiary != address(0)) {
treasury.setPaymentConfig(args.domainHash, args.paymentConfig);
}

emit DomainRegistered(
args.parentHash,
args.domainHash,
Expand Down
7 changes: 5 additions & 2 deletions contracts/registrar/ZNSSubRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IZNSSubRegistrar } from "./IZNSSubRegistrar.sol";
import { AAccessControlled } from "../access/AAccessControlled.sol";
import { ARegistryWired } from "../registry/ARegistryWired.sol";
import { StringUtils } from "../utils/StringUtils.sol";
import { PaymentConfig } from "../treasury/IZNSTreasury.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";


Expand Down Expand Up @@ -84,7 +85,8 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable,
string calldata label,
address domainAddress,
string calldata tokenURI,
DistributionConfig calldata distrConfig
DistributionConfig calldata distrConfig,
PaymentConfig calldata paymentConfig
) external override returns (bytes32) {
// Confirms string values are only [a-z0-9-]
label.validate();
Expand Down Expand Up @@ -122,7 +124,8 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable,
stakeFee: 0,
domainAddress: domainAddress,
tokenURI: tokenURI,
isStakePayment: parentConfig.paymentType == PaymentType.STAKE
isStakePayment: parentConfig.paymentType == PaymentType.STAKE,
paymentConfig: paymentConfig
});

if (!isOwnerOrOperator) {
Expand Down
6 changes: 5 additions & 1 deletion contracts/treasury/ZNSTreasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ contract ZNSTreasury is AAccessControlled, ARegistryWired, UUPSUpgradeable, IZNS
function setPaymentConfig(
bytes32 domainHash,
PaymentConfig memory paymentConfig
) external override onlyOwnerOrOperator(domainHash) {
) external override {
require(
registry.isOwnerOrOperator(domainHash, msg.sender) || accessController.isRegistrar(msg.sender),
"ZNSTreasury: Not authorized."
);
_setBeneficiary(domainHash, paymentConfig.beneficiary);
_setPaymentToken(domainHash, address(paymentConfig.token));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AAccessControlled } from "../../access/AAccessControlled.sol";
import { ARegistryWired } from "../../registry/ARegistryWired.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { StringUtils } from "../../utils/StringUtils.sol";
import { PaymentConfig } from "../../treasury/IZNSTreasury.sol";


enum AccessType {
Expand Down Expand Up @@ -75,7 +76,8 @@ contract ZNSSubRegistrarUpgradeMock is
string calldata label,
address domainAddress,
string memory tokenURI,
DistributionConfig calldata distrConfig
DistributionConfig calldata distrConfig,
PaymentConfig calldata paymentConfig
) external returns (bytes32) {
label.validate();

Expand Down Expand Up @@ -103,7 +105,8 @@ contract ZNSSubRegistrarUpgradeMock is
stakeFee: 0,
domainAddress: domainAddress,
tokenURI: tokenURI,
isStakePayment: parentConfig.paymentType == PaymentType.STAKE
isStakePayment: parentConfig.paymentType == PaymentType.STAKE,
paymentConfig: paymentConfig
});

require(
Expand Down
5 changes: 3 additions & 2 deletions src/tenderly/devnet/run-all-flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
deployZNS,
hashDomainLabel, PaymentType,
DEFAULT_PRICE_CONFIG,
AccessType,
} from "../../../test/helpers";
import { registrationWithSetup } from "../../../test/helpers/register-setup";

Expand Down Expand Up @@ -34,7 +35,7 @@ export const runAllFlows = async () => {
distrConfig: {
pricerContract: zns.fixedPricer.address,
paymentType: PaymentType.STAKE,
accessType: 1,
accessType: AccessType.OPEN,
},
paymentConfig: {
token: zns.meowToken.address,
Expand All @@ -61,7 +62,7 @@ export const runAllFlows = async () => {
distrConfig: {
pricerContract: zns.curvePricer.address,
paymentType: PaymentType.DIRECT,
accessType: 1,
accessType: AccessType.OPEN,
},
paymentConfig: {
token: zns.meowToken.address,
Expand Down
3 changes: 2 additions & 1 deletion test/ZNSCurvePricer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
INVALID_NAME_ERR,
} from "./helpers";
import {
AccessType,
DEFAULT_DECIMALS,
DEFAULT_PRICE_CONFIG,
DEFAULT_REGISTRATION_FEE_PERCENT,
Expand Down Expand Up @@ -64,7 +65,7 @@ describe("ZNSCurvePricer", () => {
distrConfig: {
paymentType: PaymentType.DIRECT,
pricerContract: zns.curvePricer.address,
accessType: 1,
accessType: AccessType.OPEN,
},
paymentConfig: {
token: zns.meowToken.address,
Expand Down
5 changes: 3 additions & 2 deletions test/ZNSFixedPricer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DEFAULT_PERCENTAGE_BASIS,
DEFAULT_PRICE_CONFIG,
validateUpgrade,
AccessType,
} from "./helpers";
import * as hre from "hardhat";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
Expand Down Expand Up @@ -54,7 +55,7 @@ describe("ZNSFixedPricer", () => {
distrConfig: {
paymentType: PaymentType.DIRECT,
pricerContract: zns.fixedPricer.address,
accessType: 1,
accessType: AccessType.OPEN,
},
paymentConfig: {
token: zns.meowToken.address,
Expand Down Expand Up @@ -311,7 +312,7 @@ describe("ZNSFixedPricer", () => {
distrConfig: {
paymentType: PaymentType.DIRECT,
pricerContract: zns.fixedPricer.address,
accessType: 1,
accessType: AccessType.OPEN,
},
paymentConfig: {
token: zns.meowToken.address,
Expand Down
Loading

0 comments on commit 06d7783

Please sign in to comment.