Skip to content

Commit

Permalink
feat: add Public Resolvers into testnet v0.2.0 (#17)
Browse files Browse the repository at this point in the history
* forge install: ens-contracts

v0.1

* forge install: buffer

688aa09e9ad241a94609e6af539e65f229912b16

* chore: migrate from private repo

* feat: add PublicResolver & dependency

* fix: outdated name and address in Public Resolver (#5)

fix: outdated name and address in Public Resolver

* fix: resolve merge conflicts

* fix: resolve merge conflicts

---------

Co-authored-by: Duc Tho Tran <ducthotran2010@gmail.com>
  • Loading branch information
Tu Do and ducthotran2010 authored Oct 12, 2023
1 parent 57803a6 commit 317fc96
Show file tree
Hide file tree
Showing 30 changed files with 1,139 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
[submodule "lib/contract-template"]
path = lib/contract-template
url = https://github.com/axieinfinity/contract-template
[submodule "lib/ens-contracts"]
path = lib/ens-contracts
url = https://github.com/ensdomains/ens-contracts
[submodule "lib/buffer"]
path = lib/buffer
url = https://github.com/ensdomains/buffer
1 change: 1 addition & 0 deletions lib/buffer
Submodule buffer added at 688aa0
1 change: 1 addition & 0 deletions lib/ens-contracts
Submodule ens-contracts added at 0c75ba
4 changes: 3 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
@openzeppelin/=lib/openzeppelin-contracts/
contract-template/=lib/contract-template/src/
contract-template/=lib/contract-template/src/
@ensdomains/ens-contracts/=lib/ens-contracts/contracts/
@ensdomains/buffer/=lib/buffer/
5 changes: 5 additions & 0 deletions src/RNSUnified.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ contract RNSUnified is Initializable, RNSToken {
emit RecordUpdated(0x0, ModifyingField.Expiry.indicator(), record);
}

/// @inheritdoc INSUnified
function namehash(string memory) external pure returns (bytes32 node) {
revert("TODO");
}

/// @inheritdoc INSUnified
function available(uint256 id) public view returns (bool) {
return block.timestamp > LibSafeRange.add(_expiry(id), _gracePeriod);
Expand Down
52 changes: 52 additions & 0 deletions src/extensions/Multicallable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { ERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import { IMulticallable } from "@rns-contracts/interfaces/IMulticallable.sol";
import { ErrorHandler } from "@rns-contracts/libraries/ErrorHandler.sol";

abstract contract Multicallable is ERC165, IMulticallable {
using ErrorHandler for bool;

/**
* @dev Override {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceID) public view virtual override returns (bool) {
return interfaceID == type(IMulticallable).interfaceId || super.supportsInterface(interfaceID);
}

/**
* @inheritdoc IMulticallable
*/
function multicall(bytes[] calldata data) public override returns (bytes[] memory results) {
return _tryMulticall(true, data);
}

/**
* @inheritdoc IMulticallable
*/
function tryMulticall(bool requireSuccess, bytes[] calldata data) public override returns (bytes[] memory results) {
return _tryMulticall(requireSuccess, data);
}

/**
* @dev See {IMulticallable-tryMulticall}.
*/
function _tryMulticall(bool requireSuccess, bytes[] calldata data) internal returns (bytes[] memory results) {
uint256 length = data.length;
results = new bytes[](length);

bool success;
bytes memory result;

for (uint256 i; i < length;) {
(success, result) = address(this).delegatecall(data[i]);
if (requireSuccess) success.handleRevert(result);
results[i] = result;

unchecked {
++i;
}
}
}
}
37 changes: 37 additions & 0 deletions src/interfaces/IMulticallable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

/**
* @notice To multi-call to a specified contract which has multicall interface:
*
* ```solidity
* interface IMock is IMulticallable {
* function foo() external;
* function bar() external;
* }
*
* bytes[] memory calldatas = new bytes[](2);
* calldatas[0] = abi.encodeCall(IMock.foo,());
* calldatas[1] = abi.encodeCall(IMock.bar,());
* IMock(target).multicall(calldatas);
* ```
*/
interface IMulticallable {
/**
* @dev Executes bulk action to the original contract.
* Reverts if there is a single call failed.
*
* @param data The calldata to original contract.
*
*/
function multicall(bytes[] calldata data) external returns (bytes[] memory results);

/**
* @dev Executes bulk action to the original contract.
*
* @param requireSuccess Flag to indicating whether the contract reverts if there is a single call failed.
* @param data The calldata to original contract.
*
*/
function tryMulticall(bool requireSuccess, bytes[] calldata data) external returns (bytes[] memory results);
}
5 changes: 5 additions & 0 deletions src/interfaces/INSUnified.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ interface INSUnified is IAccessControlEnumerable, IERC721Metadata {
*/
function MAX_EXPIRY() external pure returns (uint64);

/**
* @dev Returns the name hash output of a domain.
*/
function namehash(string memory domain) external pure returns (bytes32 node);

/**
* @dev Returns true if the specified name is available for registration.
* Note: Only available after passing the grace period.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IReverseRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-LicINSe-Identifier: UNLICINSED
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
Expand Down
38 changes: 38 additions & 0 deletions src/interfaces/resolvers/IABIResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

interface IABIResolver {
/// Thrown when the input content type is invalid.
error InvalidContentType();

/// @dev Emitted when the ABI is changed.
event ABIChanged(bytes32 indexed node, uint256 indexed contentType);

/**
* @dev Sets the ABI associated with an INS node. Nodes may have one ABI of each content type. To remove an ABI, set it
* to the empty string.
*
* Requirements:
* - The method caller must be authorized to change user fields of RNS Token `node`. See indicator
* {ModifyingIndicator.USER_FIELDS_INDICATOR}.
* - The content type must be powers of 2.
*
* Emitted an event {ABIChanged}.
*
* @param node The node to update.
* @param contentType The content type of the ABI
* @param data The ABI data.
*/
function setABI(bytes32 node, uint256 contentType, bytes calldata data) external;

/**
* @dev Returns the ABI associated with an INS node.
* Defined in EIP-205, see more at https://eips.ethereum.org/EIPS/eip-205
*
* @param node The INS node to query
* @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
* @return contentType The content type of the return value
* @return data The ABI data
*/
function ABI(bytes32 node, uint256 contentTypes) external view returns (uint256 contentType, bytes memory data);
}
28 changes: 28 additions & 0 deletions src/interfaces/resolvers/IAddressResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

interface IAddressResolver {
/// @dev Emitted when an address of a node is changed.
event AddrChanged(bytes32 indexed node, address addr);

/**
* @dev Sets the address associated with an INS node.
*
* Requirement:
* - The method caller must be authorized to change user fields of RNS Token `node`. See indicator
* {ModifyingIndicator.USER_FIELDS_INDICATOR}.
*
* Emits an event {AddrChanged}.
*
* @param node The node to update.
* @param addr The address to set.
*/
function setAddr(bytes32 node, address addr) external;

/**
* @dev Returns the address associated with an INS node.
* @param node The INS node to query.
* @return The associated address.
*/
function addr(bytes32 node) external view returns (address payable);
}
28 changes: 28 additions & 0 deletions src/interfaces/resolvers/IContentHashResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IContentHashResolver {
/// @dev Emitted when the content hash of a node is changed.
event ContentHashChanged(bytes32 indexed node, bytes hash);

/**
* @dev Sets the content hash associated with an INS node.
*
* Requirements:
* - The method caller must be authorized to change user fields of RNS Token `node`. See indicator
* {ModifyingIndicator.USER_FIELDS_INDICATOR}.
*
* Emits an event {ContentHashChanged}.
*
* @param node The node to update.
* @param hash The content hash to set
*/
function setContentHash(bytes32 node, bytes calldata hash) external;

/**
* @dev Returns the content hash associated with an INS node.
* @param node The INS node to query.
* @return The associated content hash.
*/
function contentHash(bytes32 node) external view returns (bytes memory);
}
41 changes: 41 additions & 0 deletions src/interfaces/resolvers/IDNSRecordResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

interface IDNSRecordResolver {
/// @dev Emitted whenever a given node/name/resource's RRSET is updated.
event DNSRecordChanged(bytes32 indexed node, bytes name, uint16 resource, bytes record);
/// @dev Emitted whenever a given node/name/resource's RRSET is deleted.
event DNSRecordDeleted(bytes32 indexed node, bytes name, uint16 resource);

/**
* @dev Set one or more DNS records. Records are supplied in wire-format. Records with the same node/name/resource
* must be supplied one after the other to ensure the data is updated correctly. For example, if the data was
* supplied:
* a.example.com IN A 1.2.3.4
* a.example.com IN A 5.6.7.8
* www.example.com IN CNAME a.example.com.
* then this would store the two A records for a.example.com correctly as a single RRSET, however if the data was
* supplied:
* a.example.com IN A 1.2.3.4
* www.example.com IN CNAME a.example.com.
* a.example.com IN A 5.6.7.8
* then this would store the first A record, the CNAME, then the second A record which would overwrite the first.
*
* Requirements:
* - The method caller must be authorized to change user fields of RNS Token `node`. See indicator
* {ModifyingIndicator.USER_FIELDS_INDICATOR}.
*
* @param node the namehash of the node for which to set the records
* @param data the DNS wire format records to set
*/
function setDNSRecords(bytes32 node, bytes calldata data) external;

/**
* @dev Obtain a DNS record.
* @param node the namehash of the node for which to fetch the record
* @param name the keccak-256 hash of the fully-qualified name for which to fetch the record
* @param resource the ID of the resource as per https://en.wikipedia.org/wiki/List_of_DNS_record_types
* @return the DNS record in wire format if present, otherwise empty
*/
function dnsRecord(bytes32 node, bytes32 name, uint16 resource) external view returns (bytes memory);
}
28 changes: 28 additions & 0 deletions src/interfaces/resolvers/IDNSZoneResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

interface IDNSZoneResolver {
/// @dev Emitted whenever a given node's zone hash is updated.
event DNSZonehashChanged(bytes32 indexed node, bytes lastzonehash, bytes zonehash);

/**
* @dev Sets the hash for the zone.
*
* Requirements:
* - The method caller must be authorized to change user fields of RNS Token `node`. See indicator
* {ModifyingIndicator.USER_FIELDS_INDICATOR}.
*
* Emits an event {DNSZonehashChanged}.
*
* @param node The node to update.
* @param hash The zonehash to set
*/
function setZonehash(bytes32 node, bytes calldata hash) external;

/**
* @dev Obtains the hash for the zone.
* @param node The INS node to query.
* @return The associated contenthash.
*/
function zonehash(bytes32 node) external view returns (bytes memory);
}
34 changes: 34 additions & 0 deletions src/interfaces/resolvers/IInterfaceResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IInterfaceResolver {
/// @dev Emitted when the interface of node is changed.
event InterfaceChanged(bytes32 indexed node, bytes4 indexed interfaceID, address implementer);

/**
* @dev Sets an interface associated with a name.
* Setting the address to 0 restores the default behaviour of querying the contract at `addr()` for interface support.
*
* Requirements:
* - The method caller must be authorized to change user fields of RNS Token `node`. See indicator
* {ModifyingIndicator.USER_FIELDS_INDICATOR}.
*
* @param node The node to update.
* @param interfaceID The EIP 165 interface ID.
* @param implementer The address of a contract that implements this interface for this node.
*/
function setInterface(bytes32 node, bytes4 interfaceID, address implementer) external;

/**
* @dev Returns the address of a contract that implements the specified interface for this name.
*
* If an implementer has not been set for this interfaceID and name, the resolver will query the contract at `addr()`.
* If `addr()` is set, a contract exists at that address, and that contract implements EIP165 and returns `true` for
* the specified interfaceID, its address will be returned.
*
* @param node The INS node to query.
* @param interfaceID The EIP 165 interface ID to check for.
* @return The address that implements this interface, or 0 if the interface is unsupported.
*/
function interfaceImplementer(bytes32 node, bytes4 interfaceID) external view returns (address);
}
37 changes: 37 additions & 0 deletions src/interfaces/resolvers/IPublicKeyResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

interface IPublicKeyResolver {
struct PublicKey {
bytes32 x;
bytes32 y;
}

/// @dev Emitted when a node public key is changed.
event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y);

/**
* @dev Sets the SECP256k1 public key associated with an INS node.
*
* Requirements:
* - The method caller must be authorized to change user fields of RNS Token `node`. See indicator
* {ModifyingIndicator.USER_FIELDS_INDICATOR}.
*
* Emits an event {PubkeyChanged}.
*
* @param node The INS node to query
* @param x the X coordinate of the curve point for the public key.
* @param y the Y coordinate of the curve point for the public key.
*/
function setPubkey(bytes32 node, bytes32 x, bytes32 y) external;

/**
* @dev Returns the SECP256k1 public key associated with an INS node.
* Defined in EIP 619.
*
* @param node The INS node to query
* @return x The X coordinate of the curve point for the public key.
* @return y The Y coordinate of the curve point for the public key.
*/
function pubkey(bytes32 node) external view returns (bytes32 x, bytes32 y);
}
Loading

0 comments on commit 317fc96

Please sign in to comment.