Skip to content

Commit

Permalink
Add dogechain and dogechain-testnet deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
mainnet-pat committed Aug 22, 2022
1 parent ef4704b commit 88ca736
Show file tree
Hide file tree
Showing 39 changed files with 12,408 additions and 2 deletions.
74 changes: 74 additions & 0 deletions contracts/resolvers/DogeChainPublicResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

import "../registry/ENS.sol";
import "./profiles/ABIResolver.sol";
import "./profiles/DogeChainAddrResolver.sol";
import "./profiles/ContentHashResolver.sol";
import "./profiles/DNSResolver.sol";
import "./profiles/DogeChainInterfaceResolver.sol";
import "./profiles/NameResolver.sol";
import "./profiles/PubkeyResolver.sol";
import "./profiles/TextResolver.sol";
import "./Multicallable.sol";

interface INameWrapper {
function ownerOf(uint256 id) external view returns (address);
}

/**
* A simple resolver anyone can use; only allows the owner of a node to set its
* address.
*/
contract DogeChainPublicResolver is Multicallable, ABIResolver, DogeChainAddrResolver, ContentHashResolver, DNSResolver, DogeChainInterfaceResolver, NameResolver, PubkeyResolver, TextResolver {
ENS ens;
INameWrapper nameWrapper;

/**
* A mapping of operators. An address that is authorised for an address
* may make any changes to the name that the owner could, but may not update
* the set of authorisations.
* (owner, operator) => approved
*/
mapping(address => mapping(address => bool)) private _operatorApprovals;

// Logged when an operator is added or removed.
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

constructor(ENS _ens, INameWrapper wrapperAddress){
ens = _ens;
nameWrapper = wrapperAddress;
}

/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) external{
require(
msg.sender != operator,
"ERC1155: setting approval status for self"
);

_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}

function isAuthorised(bytes32 node) internal override view returns(bool) {
address owner = ens.owner(node);
if(owner == address(nameWrapper) ){
owner = nameWrapper.ownerOf(uint256(node));
}
return owner == msg.sender || isApprovedForAll(owner, msg.sender);
}

/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view returns (bool){
return _operatorApprovals[account][operator];
}

function supportsInterface(bytes4 interfaceID) public override(Multicallable, ABIResolver, DogeChainAddrResolver, ContentHashResolver, DNSResolver, DogeChainInterfaceResolver, NameResolver, PubkeyResolver, TextResolver) pure returns(bool) {
return interfaceID == type(IMulticallable).interfaceId || super.supportsInterface(interfaceID);
}
}
65 changes: 65 additions & 0 deletions contracts/resolvers/profiles/DogeChainAddrResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

import "../ResolverBase.sol";
import "./IAddrResolver.sol";
import "./IAddressResolver.sol";

abstract contract DogeChainAddrResolver is IAddrResolver, IAddressResolver, ResolverBase {
uint constant private COIN_TYPE_DOGECHAIN = 2147485648;

mapping(bytes32=>mapping(uint=>bytes)) _addresses;

/**
* Sets the address associated with an ENS node.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param a The address to set.
*/
function setAddr(bytes32 node, address a) virtual external authorised(node) {
setAddr(node, COIN_TYPE_DOGECHAIN, addressToBytes(a));
}

/**
* Returns the address associated with an ENS node.
* @param node The ENS node to query.
* @return The associated address.
*/
function addr(bytes32 node) virtual override public view returns (address payable) {
bytes memory a = addr(node, COIN_TYPE_DOGECHAIN);
if(a.length == 0) {
return payable(0);
}
return bytesToAddress(a);
}

function setAddr(bytes32 node, uint coinType, bytes memory a) virtual public authorised(node) {
if(coinType == COIN_TYPE_DOGECHAIN) {
emit AddrChanged(node, bytesToAddress(a));
}
emit AddressChanged(node, coinType, a);
_addresses[node][coinType] = a;
}

function addr(bytes32 node, uint coinType) virtual override public view returns(bytes memory) {
return _addresses[node][coinType];
}

function supportsInterface(bytes4 interfaceID) virtual override public pure returns(bool) {
return interfaceID == type(IAddrResolver).interfaceId || interfaceID == type(IAddressResolver).interfaceId || super.supportsInterface(interfaceID);
}

function bytesToAddress(bytes memory b) internal pure returns(address payable a) {
require(b.length == 20);
assembly {
a := div(mload(add(b, 32)), exp(256, 12))
}
}

function addressToBytes(address a) internal pure returns(bytes memory b) {
b = new bytes(20);
assembly {
mstore(add(b, 32), mul(a, exp(256, 12)))
}
}
}
63 changes: 63 additions & 0 deletions contracts/resolvers/profiles/DogeChainInterfaceResolver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

import "../ResolverBase.sol";
import "../ISupportsInterface.sol";
import "./DogeChainAddrResolver.sol";
import "./IInterfaceResolver.sol";

abstract contract DogeChainInterfaceResolver is IInterfaceResolver, DogeChainAddrResolver {
mapping(bytes32=>mapping(bytes4=>address)) interfaces;

/**
* 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.
* @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) virtual external authorised(node) {
interfaces[node][interfaceID] = implementer;
emit InterfaceChanged(node, interfaceID, implementer);
}

/**
* 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 ENS 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) virtual override external view returns (address) {
address implementer = interfaces[node][interfaceID];
if(implementer != address(0)) {
return implementer;
}

address a = addr(node);
if(a == address(0)) {
return address(0);
}

(bool success, bytes memory returnData) = a.staticcall(abi.encodeWithSignature("supportsInterface(bytes4)", type(ISupportsInterface).interfaceId));
if(!success || returnData.length < 32 || returnData[31] == 0) {
// EIP 165 not supported by target
return address(0);
}

(success, returnData) = a.staticcall(abi.encodeWithSignature("supportsInterface(bytes4)", interfaceID));
if(!success || returnData.length < 32 || returnData[31] == 0) {
// Specified interface not supported by target
return address(0);
}

return a;
}

function supportsInterface(bytes4 interfaceID) virtual override public pure returns(bool) {
return interfaceID == type(IInterfaceResolver).interfaceId || super.supportsInterface(interfaceID);
}
}
1 change: 1 addition & 0 deletions deployments/dogechain-testnet/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
568
3 changes: 3 additions & 0 deletions deployments/dogechain-testnet/.migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dogechain": 1660985781
}
Loading

0 comments on commit 88ca736

Please sign in to comment.