From 19c4b3e359fa883e5724aaf9a82598dead85d542 Mon Sep 17 00:00:00 2001 From: James Earle Date: Wed, 4 Sep 2024 14:25:38 -0700 Subject: [PATCH] WIP snapshot debugging subdomain registration with transfer still --- contracts/registrar/ZNSRootRegistrar.sol | 13 +++++--- contracts/registrar/ZNSSubRegistrar.sol | 42 +++++++++++++++++------- src/utils/migration/registration.ts | 24 +++++++++++--- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/contracts/registrar/ZNSRootRegistrar.sol b/contracts/registrar/ZNSRootRegistrar.sol index 48b0e602..e0baadbb 100644 --- a/contracts/registrar/ZNSRootRegistrar.sol +++ b/contracts/registrar/ZNSRootRegistrar.sol @@ -154,10 +154,13 @@ contract ZNSRootRegistrar is ) ); - if (address(distributionConfig.pricerContract) != address(0)) { + // if no pricer contract, no distr config set + // so all values 0, meaning it is locked + // must pass dummy address OR modify this to always set distrConfig + // if (address(distributionConfig.pricerContract) != address(0)) { // this adds additional gas to the register tx if passed subRegistrar.setDistributionConfigForDomain(domainHash, distributionConfig); - } + // } return domainHash; } @@ -211,13 +214,15 @@ contract ZNSRootRegistrar is // If the `domainAddress` is not provided upon registration, a user can call `ZNSAddressResolver.setAddress` // to set the address themselves. if (args.domainAddress != address(0)) { - registry.createDomainRecord(args.domainHash, args.registrant, "address"); + // TODO maybe we have to use msg.sender here in the registry + // but registrant in the token so that we can still register subdomains? + registry.createDomainRecord(args.domainHash, msg.sender, "address"); IZNSAddressResolver(registry.getDomainResolver(args.domainHash)) .setAddress(args.domainHash, args.domainAddress); } else { // By passing an empty string we tell the registry to not add a resolver - registry.createDomainRecord(args.domainHash, args.registrant, ""); + registry.createDomainRecord(args.domainHash, msg.sender, ""); } // Because we check in the web app for the existance of both values in a payment config, diff --git a/contracts/registrar/ZNSSubRegistrar.sol b/contracts/registrar/ZNSSubRegistrar.sol index dce61517..423a1fd5 100644 --- a/contracts/registrar/ZNSSubRegistrar.sol +++ b/contracts/registrar/ZNSSubRegistrar.sol @@ -12,6 +12,7 @@ import { IZNSDomainToken } from "../token/IZNSDomainToken.sol"; import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import { DomainAlreadyExists, ZeroAddressPassed, NotAuthorizedForDomain } from "../utils/CommonErrors.sol"; +// import { console } from "hardhat/console.sol"; /** * @title ZNSSubRegistrar.sol - The contract for registering and revoking subdomains of zNS. @@ -98,6 +99,8 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, } } + error ConfusingThing(bytes32 domainHash, address realOwner, address registrant); + /** * @notice Entry point to register a subdomain under a parent domain specified. * @dev Reads the `DistributionConfig` for the parent domain to determine how to distribute, @@ -113,6 +116,8 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, * > `paymentConfig` has to be fully filled or all zeros. It is optional as a whole, * but all the parameters inside are required. */ + + function registerSubdomain( address registrant, bytes32 parentHash, @@ -123,6 +128,7 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, PaymentConfig calldata paymentConfig ) public override returns (bytes32) { // Confirms string values are only [a-z0-9-] + label.validate(); bytes32 domainHash = hashWithParent(parentHash, label); @@ -132,20 +138,32 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, DistributionConfig memory parentConfig = distrConfigs[parentHash]; bool isOwnerOrOperator = registry.isOwnerOrOperator(parentHash, registrant); // in the eyes of the registry it should still be migration admin? + // address realOwner = registry.getDomainOwner(parentHash); + + // console.log("parentHash"); + // console.logBytes32(parentHash); + // console.log("isOwnerOrOperator", isOwnerOrOperator); + // console.log("realOwner", realOwner); + // console.log("registrant", registrant); + // console.log("msg.sender", msg.sender); + + // if (!isOwnerOrOperator) { + // revert ConfusingThing(parentHash, msg.sender, registrant); + // } + // if (true) revert("nahhhh"); + if (parentConfig.accessType == AccessType.LOCKED) { - revert ParentLockedOrDoesntExist(parentHash); + revert ConfusingThing(parentHash, msg.sender, registrant); } - require(isOwnerOrOperator, "sad face"); - - if (parentConfig.accessType == AccessType.MINTLIST) { - if ( - !mintlist[parentHash] - .list - [mintlist[parentHash].ownerIndex] - [msg.sender] - ) revert SenderNotApprovedForPurchase(parentHash, msg.sender); - } + // if (parentConfig.accessType == AccessType.MINTLIST) { + // if ( + // !mintlist[parentHash] + // .list + // [mintlist[parentHash].ownerIndex] + // [msg.sender] + // ) revert SenderNotApprovedForPurchase(parentHash, msg.sender); + // } CoreRegisterArgs memory coreRegisterArgs = CoreRegisterArgs({ parentHash: parentHash, @@ -217,7 +235,7 @@ contract ZNSSubRegistrar is AAccessControlled, ARegistryWired, UUPSUpgradeable, bytes32 domainHash, DistributionConfig calldata config ) public override onlyOwnerOperatorOrRegistrar(domainHash) { - if (address(config.pricerContract) == address(0)) + if (address(config.pricerContract) == address(0)) // TODO ignore 0 pricer contract for migration? revert ZeroAddressPassed(); distrConfigs[domainHash] = config; diff --git a/src/utils/migration/registration.ts b/src/utils/migration/registration.ts index 9b7e415e..0a2acbf2 100644 --- a/src/utils/migration/registration.ts +++ b/src/utils/migration/registration.ts @@ -2,7 +2,7 @@ import * as hre from "hardhat"; import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; import { DomainData, RegisteredDomains, Domain } from "./types"; import { IZNSContracts } from "../../deploy/campaign/types"; -import { distrConfigEmpty, paymentConfigEmpty } from "../../../test/helpers"; +import { AccessType, distrConfigEmpty, paymentConfigEmpty, PaymentType } from "../../../test/helpers"; import { IZNSContractsLocal } from "../../../test/helpers/types"; import { ContractTransactionReceipt } from "ethers"; import { DOMAIN_REGISTERED_TOPIC_SEPOLIA } from "./constants"; @@ -112,7 +112,11 @@ export const registerBase = async ({ labels, domainAddresses, tokenURIs, - distrConfigEmpty, // TODO what should this be? stake vs, direct should be upheld maybe? + { + pricerContract: await zns.curvePricer.getAddress(), // if real pricer have to then also set price config, maybe just allow 0 instead + paymentType: PaymentType.DIRECT, // TODO staked? direct? does it matter? should we just copy from domain? + accessType: AccessType.OPEN, + }, paymentConfigEmpty, // { // // TODO Debug, force the TX @@ -125,8 +129,14 @@ export const registerBase = async ({ // does any of this matter? If we are burning and replacing all meow tokens? } else { // console.log("y here?") - console.log("exists check: ", await zns.registry.exists(parentHashes[0])); - console.log("ownerOrOperator check: ", await zns.registry.isOwnerOrOperator(parentHashes[0], regAdmin.address)); + // console.log("parentHash: ", parentHashes[0]); + // console.log("exists check: ", await zns.registry.exists(parentHashes[0])); + // const ownerofDomain = await zns.registry.getDomainOwner(parentHashes[0]); + // console.log("owner check: ", await zns.registry.getDomainOwner(parentHashes[0])); + // console.log("ownerOrOperator check: ", await zns.registry.isOwnerOrOperator(parentHashes[0], regAdmin.address)); + // console.log("ownerOrOperator check: ", await zns.registry.isOwnerOrOperator(parentHashes[0], ownerofDomain)); + const distConfig = await zns.subRegistrar.distrConfigs(parentHashes[0]); + console.log(distConfig.accessType); // should NOT be 0 tx = await zns.subRegistrar.connect(regAdmin).registerSubdomainBulk( owners, @@ -134,7 +144,11 @@ export const registerBase = async ({ labels, domainAddresses, tokenURIs, - distrConfigEmpty, + { + pricerContract: await zns.curvePricer.getAddress(), + paymentType: PaymentType.DIRECT, // TODO staked? direct? does it matter? should we just copy from domain? + accessType: AccessType.OPEN, + }, paymentConfigEmpty, ); }