79 lines
3.2 KiB
Solidity
79 lines
3.2 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.19;
|
|
|
|
import { IENSResolver } from "@interfaces/IENSResolver.sol";
|
|
import { IENSRegistry } from "@interfaces/IENSRegistry.sol";
|
|
import { ENSNamehash } from "./ENSNamehash.sol";
|
|
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
|
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
|
|
|
|
contract GoerliDomainOwner is Ownable, ERC1155Holder {
|
|
address internal ensRegistryAddress = 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e;
|
|
|
|
IENSRegistry ensRegistry = IENSRegistry(ensRegistryAddress);
|
|
|
|
function calculateDomainNode(string memory domain) private pure returns (bytes32) {
|
|
return ENSNamehash.namehash(bytes(domain));
|
|
}
|
|
|
|
function transferDomainOwnership(string memory domain, address to) public onlyOwner {
|
|
_transferDomainOwnership(calculateDomainNode(domain), to);
|
|
}
|
|
|
|
function transferSubdomainOwnership(string memory domain, string memory subdomainLabel, address to) public onlyOwner {
|
|
_transferSubdomainOwnership(domain, subdomainLabel, to);
|
|
}
|
|
|
|
function _transferSubdomainOwnership(string memory domain, string memory subdomainLabel, address to) private {
|
|
bytes32 rootNode = calculateDomainNode(domain);
|
|
bytes32 subdomainLabelhash = calculateSubdomainLabelhash(subdomainLabel);
|
|
bytes32 subdomainNode = keccak256(abi.encodePacked(rootNode, subdomainLabelhash));
|
|
require(ensRegistry.recordExists(subdomainNode), "Subdomain not registered");
|
|
require(ensRegistry.owner(rootNode) == address(this), "This contract must be an owner of domain");
|
|
|
|
ensRegistry.setSubnodeOwner(rootNode, subdomainLabelhash, to);
|
|
}
|
|
|
|
function _transferDomainOwnership(bytes32 domainNode, address to) private {
|
|
require(ensRegistry.owner(domainNode) == address(this), "This test contract must be an owner of domain");
|
|
ensRegistry.setOwner(domainNode, to);
|
|
}
|
|
|
|
function calculateSubdomainLabelhash(string memory subdomainLabel) internal pure returns (bytes32) {
|
|
return keccak256(bytes(subdomainLabel));
|
|
}
|
|
|
|
function ownSubdomain(string memory domain, string memory subdomainLabel) public onlyOwner {
|
|
_transferSubdomainOwnership(domain, subdomainLabel, address(this));
|
|
}
|
|
|
|
function registerSubname(string memory domain, string memory subdomainLabel) public onlyOwner {
|
|
bytes32 rootNode = calculateDomainNode(domain);
|
|
address rootResolver = ensRegistry.resolver(rootNode);
|
|
bytes32 subdomainLabelhash = calculateSubdomainLabelhash(subdomainLabel);
|
|
|
|
ensRegistry.setSubnodeRecord(rootNode, subdomainLabelhash, address(this), rootResolver, 0);
|
|
}
|
|
|
|
function isContract(address _addr) private view returns (bool) {
|
|
uint32 size;
|
|
assembly {
|
|
size := extcodesize(_addr)
|
|
}
|
|
return (size > 0);
|
|
}
|
|
|
|
function execute(address proposal) public onlyOwner {
|
|
require(isContract(proposal), "not a contract");
|
|
(bool success, bytes memory data) = proposal.delegatecall(abi.encodeWithSignature("executeProposal()"));
|
|
if (!success) {
|
|
if (data.length > 0) {
|
|
revert(string(data));
|
|
} else {
|
|
revert("Proposal execution failed");
|
|
}
|
|
}
|
|
}
|
|
}
|