Skip to content

Commit

Permalink
WIP snapshot debugging subdomain registration with transfer still
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesEarle committed Sep 4, 2024
1 parent 62c950f commit 19c4b3e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
13 changes: 9 additions & 4 deletions contracts/registrar/ZNSRootRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
42 changes: 30 additions & 12 deletions contracts/registrar/ZNSSubRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 19 additions & 5 deletions src/utils/migration/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -125,16 +129,26 @@ 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,
parentHashes,
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,
);
}
Expand Down

0 comments on commit 19c4b3e

Please sign in to comment.