Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [Migration ZChain] Domain Migration: Backend Registration/Transfer #112

Open
wants to merge 60 commits into
base: rc/zns-meowchain
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
ae74c06
Types upgrade after PROVIDER removal
MichaelKorchagin Jul 16, 2024
12b9ccf
create crucial domain helpers to be called from the frontend
Whytecrowe Jul 17, 2024
18fee16
add owner change helper
Whytecrowe Jul 17, 2024
b387d4f
Deploy contracts through Hardhat script
MichaelKorchagin Jul 17, 2024
cfd06cc
Add Meow-testnet data
MichaelKorchagin Jul 18, 2024
d3a999f
Disable Meow-testnet
MichaelKorchagin Jul 18, 2024
0db9875
Correct contract format
MichaelKorchagin Jul 18, 2024
0481b6e
refactor and create getters
Whytecrowe Jul 19, 2024
edabf84
WIP begin validation flow for subgraph data in migration
JamesEarle Jul 22, 2024
ec4b501
fuller list of things to check. Many comments still, but no need to v…
JamesEarle Jul 23, 2024
f13d54a
improvements in the subgraph itself, modified the query to match
JamesEarle Jul 24, 2024
b0a8d9b
finalize validation script after more changes to subgraph, clean and …
JamesEarle Jul 25, 2024
0db030f
lint fixes
JamesEarle Jul 25, 2024
d419dd7
Merge branch 'migration-scripts' into meow-domain-migration-code
JamesEarle Jul 26, 2024
98db1e9
adjust file structure
JamesEarle Jul 26, 2024
b457156
add check for tests to fail if run with non-dev env file
Whytecrowe Jul 29, 2024
dc22ba2
remove unnecessary yarn-error file
Whytecrowe Jul 29, 2024
a6ae807
update yarn.lock
Whytecrowe Jul 29, 2024
d86a13e
rework zns getter to read from actual DB instead of hardcoded values
Whytecrowe Jul 29, 2024
e4d9619
refactor contract data getter file
Whytecrowe Jul 30, 2024
1e20549
refactor db getter logic
Whytecrowe Jul 30, 2024
bdb81c8
resolve merge conflict with stahed changes
JamesEarle Jul 31, 2024
5c976e7
resolve db issuers and connect code correctly now, working on adding …
JamesEarle Jul 31, 2024
a22e7fe
testing change network in runtime, if possible
JamesEarle Jul 31, 2024
47a09ce
continue adding details to registration functions under various condi…
JamesEarle Jul 31, 2024
2176a3c
minor comment edit
JamesEarle Jul 31, 2024
8e37c64
updates for flow with local dev, testnet dev, or actual modification …
JamesEarle Aug 1, 2024
95344fe
comments
JamesEarle Aug 2, 2024
b76e02f
first flow working with local complete
JamesEarle Aug 2, 2024
408e7af
flow works fully but need to fix error in subgraph deleting revoked d…
JamesEarle Aug 2, 2024
3db08a6
WIP playing with different ways to do better array => domain object m…
JamesEarle Aug 2, 2024
9795cab
WIP issues reading events after contract call on HH after switching t…
JamesEarle Aug 9, 2024
2b39b37
still having event emission issues, need to debug further
JamesEarle Aug 9, 2024
75af3c3
working on registration flow with retry logic for domains that donfai…
JamesEarle Aug 13, 2024
06d8c8a
registration flow works but blocked by subgraph error for some domains
JamesEarle Aug 14, 2024
028006e
thinking about data flow for postMigration validation function
JamesEarle Aug 14, 2024
5e5e830
flow works, remove json file output from source control
JamesEarle Aug 16, 2024
c870800
cleanup, remove redundant or unused code and comments
JamesEarle Aug 16, 2024
b3ae28b
begin setup for sepolia
JamesEarle Aug 16, 2024
46f5f86
work successfully and register 10 domains on sepolia, get domain hash…
JamesEarle Aug 19, 2024
97d8200
some cleanup, remove unnecessary
JamesEarle Aug 19, 2024
9fd0f10
WIP working on change to bulk registration to speed up the process. C…
JamesEarle Aug 20, 2024
e7e5e71
WIP snapshot before splitting world domains and subdomains into separ…
JamesEarle Aug 20, 2024
59806ba
split between root and subdomains for query, two output files for val…
JamesEarle Aug 20, 2024
0e3203e
delete test file for now
JamesEarle Aug 20, 2024
620129b
split validation into two queries and datasets for easier registratio…
JamesEarle Aug 21, 2024
2e5809e
adjust validation
JamesEarle Aug 21, 2024
227bd50
logging and event inconsistencies on hardhat vs. testnet, some remedi…
JamesEarle Aug 21, 2024
ca07872
include subdomains in flow and add minor math calcs for difference in…
JamesEarle Aug 22, 2024
8ec6a89
Merge branch 'update-zDC' into meow-domain-migration-code
JamesEarle Aug 22, 2024
ff83412
update environment config a bit to avoid possibly undefined values an…
JamesEarle Aug 26, 2024
ede1f3a
verify contracts with bulk functions on sepolia, run bulk flow for a …
JamesEarle Aug 27, 2024
80ebed2
improved the event logging to get domain hashes, minor testing, next …
JamesEarle Aug 27, 2024
c30630f
bulk flow on sepolia working, some manual testing to think about numb…
JamesEarle Aug 27, 2024
a7f3bb5
entire flow for all domains working on sepolia
JamesEarle Aug 29, 2024
0a02499
undid some work, root registration and transfer works but transfer th…
JamesEarle Sep 4, 2024
8638dd2
full flow working including transfer for rotots, fixed issue involvin…
JamesEarle Sep 5, 2024
a3a8303
registration and transfers working for all domain, setup post validat…
JamesEarle Sep 5, 2024
30b779d
full flow all subdomains register and transfer on sepolia with slice 50
JamesEarle Sep 9, 2024
c99b0d4
WIP domain migration code in progress but not priority at the moment
JamesEarle Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ docker*.tgz

# We don't ever use the generated manifests
.openzeppelin

# Ignore the output files of migration
valid-root-domains.json
valid-subdomains.json
invalid-domains.json

# Deploy logs
deploy-*.log
76 changes: 65 additions & 11 deletions contracts/price/ZNSCurvePricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
bytes32 domainHash,
CurvePriceConfig calldata priceConfig
) public override {
setPrecisionMultiplier(domainHash, priceConfig.precisionMultiplier);
priceConfigs[domainHash].baseLength = priceConfig.baseLength;
priceConfigs[domainHash].maxPrice = priceConfig.maxPrice;
priceConfigs[domainHash].minPrice = priceConfig.minPrice;
priceConfigs[domainHash].maxLength = priceConfig.maxLength;
setFeePercentage(domainHash, priceConfig.feePercentage);
priceConfigs[domainHash].isSet = true;
// Validate a new or existing config
_setPrecisionMultiplier(domainHash, priceConfig.precisionMultiplier);
_validateCurveMultiplier(domainHash, priceConfig.curveMultiplier, priceConfig);
// _validateBaseLength
// _validateMaxPrice
// _validateMaxLength
// _validateFeePercentage

_validateConfig(domainHash);
priceConfigs[domainHash].isSet = true;

emit PriceConfigSet(
domainHash,
Expand Down Expand Up @@ -186,11 +186,27 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
bytes32 domainHash,
uint256 minPrice
) external override onlyOwnerOrOperator(domainHash) {
priceConfigs[domainHash].minPrice = minPrice;
// Grab an existing config
CurvePriceConfig memory config = priceConfigs[domainHash];

_validateConfig(domainHash);
_validateCurveMultiplier(domainHash, curveMultiplier, config);

emit CurveMultiplierSet(domainHash, curveMultiplier);
}

emit MinPriceSet(domainHash, minPrice);
function _validateCurveMultiplier(
bytes32 domainHash,
uint256 curveMultiplier,
CurvePriceConfig memory config
) internal {
if (
(curveMultiplier == 0 && config.baseLength == 0) ||
(curveMultiplier == 0 && config.maxLength == 0)
) {
revert DivisionByZero(0x0);
}

priceConfigs[domainHash].curveMultiplier = curveMultiplier;
}

/**
Expand Down Expand Up @@ -287,6 +303,44 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
_setRegistry(registry_);
}

function validateConfig (
bytes32 domainHash
) internal view {
CurvePriceConfig memory config = priceConfigs[domainHash];

if (config.maxLength < config.baseLength)
revert MaxLengthSmallerThanBaseLength(
domainHash
);

if (config.maxPrice == 0 && config.maxLength == 0)
revert InvalidMaxPrice(domainHash);

// curveMultiplier = 0 && baseLength = 0
// curveMultiplier = 0 && maxLength = 0
// baseLength = 0 && curveMultiplier == 0
// baseLength = 0 && maxLength = 0

if (
(config.curveMultiplier == 0 && config.baseLength == 0) ||
(config.curveMultiplier == 0 && config.maxLength == 0) ||
(config.baseLength == 0 && config.maxLength == 0)
)
revert DivisionByZero(domainHash);

// if (config.baseLength == 0 && (config.curveMultiplier == 0 || config.maxLength == 0))
// revert DivisionByZero(domainHash);

if (config.feePercentage > PERCENTAGE_BASIS)
revert FeePercentageValueTooLarge(
config.feePercentage,
PERCENTAGE_BASIS
);

if (config.precisionMultiplier == 0 || config.precisionMultiplier > 10**18
) revert InvalidMultiplierPassed(config.precisionMultiplier);
}

/**
* @notice Internal function to calculate price based on the config set,
* and the length of the domain label.
Expand Down
19 changes: 19 additions & 0 deletions contracts/registrar/IZNSRootRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ struct CoreRegisterArgs {
PaymentConfig paymentConfig;
}

// Args for bulk tx
struct DomainData {
string[] names;
address[] domainAddresses;
string [] tokenURIs;
IDistributionConfig.DistributionConfig[] distributionConfigs;
PaymentConfig[] paymentConfigs;
}

/**
* @title IZNSRootRegistrar.sol - Interface for the ZNSRootRegistrar contract resposible for registering root domains.
* @notice Below are docs for the types in this file:
Expand All @@ -42,6 +51,16 @@ struct CoreRegisterArgs {
* + `isStakePayment`: A flag for whether the payment is a stake payment or not
*/
interface IZNSRootRegistrar is IDistributionConfig {
// TODO TEMP DELETE after migration
struct RootBulkMigrationArgs {
address[] tokenOwners;
address[] recordOwners;
string[] names;
address[] domainAddresses;
string[] tokenURIs;
DistributionConfig[] distributionConfigs;
PaymentConfig[] paymentConfigs;
}
error NotTheOwnerOf(
OwnerOf ownerOf,
address candidate,
Expand Down
65 changes: 44 additions & 21 deletions contracts/registrar/IZNSSubRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,37 @@ import { IDistributionConfig } from "../types/IDistributionConfig.sol";
import { PaymentConfig } from "../treasury/IZNSTreasury.sol";
import { IZNSPricer } from "../types/IZNSPricer.sol";


/**
* @title IZNSSubRegistrar.sol - Interface for the ZNSSubRegistrar contract responsible for registering subdomains.
*/
*/
interface IZNSSubRegistrar is IDistributionConfig {

// TODO TEMP DELETE after migration
struct SubBulkMigrationArgs {
address domainToken; // DomainToken contract for transfers
address[] tokenOwners;
address[] recordOwners;
bytes32[] parentHashes;
string[] labels;
address[] domainAddresses;
string[] tokenURIs;
DistributionConfig[] distributionConfigs;
PaymentConfig[] paymentConfigs;
}

struct RegisterSubdomainArgs {
bytes32 parentHash;
string label;
address domainAddress;
address recordOwner;
string tokenURI;
DistributionConfig distrConfig;
PaymentConfig paymentConfig;
}

/**
* @notice Reverted when someone other than parent owner is trying to buy a subdomain under the parent that is locked\
* @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);
Expand All @@ -23,22 +47,25 @@ interface IZNSSubRegistrar is IDistributionConfig {

/**
* @notice Emitted when a new `DistributionConfig.pricerContract` is set for a domain.
*/
event PricerContractSet(bytes32 indexed domainHash, address indexed pricerContract);
*/
event PricerContractSet(
bytes32 indexed domainHash,
address indexed pricerContract
);

/**
* @notice Emitted when a new `DistributionConfig.paymentType` is set for a domain.
*/
*/
event PaymentTypeSet(bytes32 indexed domainHash, PaymentType paymentType);

/**
* @notice Emitted when a new `DistributionConfig.accessType` is set for a domain.
*/
*/
event AccessTypeSet(bytes32 indexed domainHash, AccessType accessType);

/**
* @notice Emitted when a new full `DistributionConfig` is set for a domain at once.
*/
*/
event DistributionConfigSet(
bytes32 indexed domainHash,
IZNSPricer pricerContract,
Expand All @@ -48,7 +75,7 @@ interface IZNSSubRegistrar is IDistributionConfig {

/**
* @notice Emitted when a `mintlist` is updated for a domain.
*/
*/
event MintlistUpdated(
bytes32 indexed domainHash,
uint256 indexed ownerIndex,
Expand All @@ -64,16 +91,17 @@ interface IZNSSubRegistrar is IDistributionConfig {

/**
* @notice Emitted when the ZNSRootRegistrar address is set in state.
*/
*/
event RootRegistrarSet(address registrar);

function distrConfigs(
bytes32 domainHash
) external view returns (
IZNSPricer pricerContract,
PaymentType paymentType,
AccessType accessType
);
)
external view returns (
IZNSPricer pricerContract,
PaymentType paymentType,
AccessType accessType
);

function isMintlistedForDomain(
bytes32 domainHash,
Expand All @@ -87,12 +115,7 @@ interface IZNSSubRegistrar is IDistributionConfig {
) external;

function registerSubdomain(
bytes32 parentHash,
string calldata label,
address domainAddress,
string calldata tokenURI,
DistributionConfig calldata configForSubdomains,
PaymentConfig calldata paymentConfig
RegisterSubdomainArgs calldata args
) external returns (bytes32);

function hashWithParent(
Expand Down
32 changes: 31 additions & 1 deletion contracts/registrar/ZNSRootRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils
import { StringUtils } from "../utils/StringUtils.sol";
import { ZeroAddressPassed, DomainAlreadyExists } from "../utils/CommonErrors.sol";

// import { BulkMigrationArgs } from "./IZNSRootRegistrar.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { console } from "hardhat/console.sol";

/**
* @title Main entry point for the three main flows of ZNS - Register Root Domain, Reclaim and Revoke any domain.
Expand Down Expand Up @@ -69,6 +73,31 @@ contract ZNSRootRegistrar is
setDomainToken(domainToken_);
}

function registerRootDomainBulk(
RootBulkMigrationArgs calldata args
) public onlyAdmin {
// Expect all arrays are the same length
for (uint256 i = 0; i < args.names.length;) {
bytes32 domainHash = registerRootDomain(
args.names[i],
args.domainAddresses[i],
args.tokenURIs[i],
args.distributionConfigs[i],
args.paymentConfigs[i]
);

// Transfer ERC721 to domain token owner
domainToken.transferFrom(msg.sender, args.tokenOwners[i], uint256(domainHash));

// Update the domain record in the registry with the proper record owner
registry.updateDomainOwnerForMigration(domainHash, args.recordOwners[i]);

unchecked {
++i;
}
}
}

/**
* @notice This function is the main entry point for the Register Root Domain flow.
* Registers a new root domain such as `0://wilder`.
Expand All @@ -94,7 +123,7 @@ contract ZNSRootRegistrar is
string calldata tokenURI,
DistributionConfig calldata distributionConfig,
PaymentConfig calldata paymentConfig
) external override returns (bytes32) {
) public override onlyAdmin returns (bytes32) {
// Confirms string values are only [a-z0-9-]
name.validate();

Expand Down Expand Up @@ -164,6 +193,7 @@ contract ZNSRootRegistrar is
CoreRegisterArgs memory args
) internal {
// payment part of the logic
// TODO uncomment after migration
if (args.price > 0) {
_processPayment(args);
}
Expand Down
Loading