pragmasolidity ^0.5.5;/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @dev Returns true if `account` is a contract.
*
* This test is non-exhaustive, and there may be false-negatives: during the
* execution of a contract's constructor, its address will be reported as
* not containing a contract.
*
* IMPORTANT: It is unsafe to assume that an address for which this
* function returns false is an externally-owned account (EOA) and not a
* contract.
*/functionisContract(address account) internalviewreturns (bool) {
// This method relies in extcodesize, which returns 0 for contracts in// construction, since the code is only stored at the end of the// constructor execution.// According to EIP-1052, 0x0 is the value returned for not-yet created accounts// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned// for accounts without code, i.e. `keccak256('')`bytes32 codehash;
bytes32 accountHash =0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assemblyassembly { codehash :=extcodehash(account) }
return (codehash !=0x0&& codehash != accountHash);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/functiontoPayable(address account) internalpurereturns (addresspayable) {
returnaddress(uint160(account));
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/functionsendValue(addresspayable recipient, uint256 amount) internal{
require(address(this).balance>= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount)("");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
Contract Source Code
File 2 of 7: Context.sol
pragmasolidity ^0.5.0;/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/contractContext{
// Empty internal constructor, to prevent people from mistakenly deploying// an instance of this contract, which should be used via inheritance.constructor () internal{ }
// solhint-disable-previous-line no-empty-blocksfunction_msgSender() internalviewreturns (addresspayable) {
returnmsg.sender;
}
function_msgData() internalviewreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
Contract Source Code
File 3 of 7: DCLControllerV2.sol
pragmasolidity ^0.5.15;import"openzeppelin-solidity/contracts/ownership/Ownable.sol";
import"openzeppelin-solidity/contracts/utils/Address.sol";
import"../interfaces/IENSRegistry.sol";
import"../interfaces/IDCLRegistrar.sol";
import"../interfaces/IERC20Token.sol";
contractDCLControllerV2isOwnable{
usingAddressforaddress;
// Price of each nameuint256constantpublic PRICE =100ether;
// Accepted ERC20 token
IERC20Token public acceptedToken;
// DCL Registrar
IDCLRegistrar public registrar;
// Fee Collectoraddresspublic feeCollector;
// Emitted when a name is boughteventNameBought(addressindexed _caller, addressindexed _beneficiary, uint256 _price, string _name);
// Emitted when the fee collector is changedeventFeeCollectorChanged(addressindexed _oldFeeCollector, addressindexed _newFeeCollector);
/**
* @dev Constructor of the contract
* This contract does not support ERC20 tokens that do not revert on an invalid transfer.
* @param _acceptedToken - address of the accepted ERC20 token
* @param _registrar - address of the DCL registrar contract
* @param _feeCollector - address of the fee collector
* @param _owner - address of the contract owner
*/constructor(IERC20Token _acceptedToken, IDCLRegistrar _registrar, address _feeCollector, address _owner) public{
require(address(_acceptedToken).isContract(), "Accepted token should be a contract");
require(address(_registrar).isContract(), "Registrar should be a contract");
// Accepted token
acceptedToken = _acceptedToken;
// DCL registrar
registrar = _registrar;
_setFeeCollector(_feeCollector);
_transferOwnership(_owner);
}
/**
* @dev Register a name
* This function transfers the PRICE from the sender to the fee collector without checking the return value of the transferFrom function.
* This means that only tokens that revert when the transfer fails due to insufficient balance or insufficient approve should be used.
* If the token does not revert on an invalid transfer, the register will succeed and a name will be minted without being paid for.
* @param _name - name to be registered
* @param _beneficiary - owner of the name
*/functionregister(stringmemory _name, address _beneficiary) public{
// Check for valid beneficiaryrequire(_beneficiary !=address(0), "Invalid beneficiary");
// Check if the name is valid
_requireNameValid(_name);
// Register the name
registrar.register(_name, _beneficiary);
// Transfer PRICE to the fee collector
acceptedToken.transferFrom(msg.sender, feeCollector, PRICE);
// Logemit NameBought(msg.sender, _beneficiary, PRICE, _name);
}
/**
* @notice Set the fee collector
* @dev Only the owner can change the fee collector
* @param _feeCollector - the address of the new collector
*/functionsetFeeCollector(address _feeCollector) externalonlyOwner{
_setFeeCollector(_feeCollector);
}
/**
* @dev Validate a name
* @notice that only a-z is allowed
* @param _name - string for the name
*/function_requireNameValid(stringmemory _name) internalpure{
bytesmemory tempName =bytes(_name);
require(
tempName.length>=2&& tempName.length<=15,
"Name should be greater than or equal to 2 and less than or equal to 15"
);
for(uint256 i =0; i < tempName.length; i++) {
require(_isLetter(tempName[i]) || _isNumber(tempName[i]), "Invalid Character");
}
}
function_isLetter(bytes1 _char) internalpurereturns (bool) {
return (_char >=0x41&& _char <=0x5A) || (_char >=0x61&& _char <=0x7A);
}
function_isNumber(bytes1 _char) internalpurereturns (bool) {
return (_char >=0x30&& _char <=0x39);
}
function_setFeeCollector(address _feeCollector) internal{
require(_feeCollector !=address(0), "Invalid fee collector");
emit FeeCollectorChanged(feeCollector, _feeCollector);
feeCollector = _feeCollector;
}
}
Contract Source Code
File 4 of 7: IDCLRegistrar.sol
pragmasolidity ^0.5.15;contractIDCLRegistrar{
/**
* @dev Allows to create a subdomain (e.g. "nacho.dcl.eth"), set its resolver, owner and target address
* @param _subdomain - subdomain (e.g. "nacho")
* @param _beneficiary - address that will become owner of this new subdomain
*/functionregister(stringcalldata _subdomain, address _beneficiary) external;
/**
* @dev Re-claim the ownership of a subdomain (e.g. "nacho").
* @notice After a subdomain is transferred by this contract, the owner in the ENS registry contract
* is still the old owner. Therefore, the owner should call `reclaim` to update the owner of the subdomain.
* @param _tokenId - erc721 token id which represents the node (subdomain).
* @param _owner - new owner.
*/functionreclaim(uint256 _tokenId, address _owner) external;
/**
* @dev Transfer a name to a new owner.
* @param _from - current owner of the node.
* @param _to - new owner of the node.
* @param _id - node id.
*/functiontransferFrom(address _from, address _to, uint256 _id) public;
/**
* @dev Check whether a name is available to be registered or not
* @param _labelhash - hash of the name to check
* @return whether the name is available or not
*/functionavailable(bytes32 _labelhash) publicviewreturns (bool);
}
pragmasolidity ^0.5.0;import"../GSN/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/contractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor () internal{
_owner = _msgSender();
emit OwnershipTransferred(address(0), _owner);
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewreturns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/functionisOwner() publicviewreturns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publiconlyOwner{
emit OwnershipTransferred(_owner, address(0));
_owner =address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publiconlyOwner{
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/function_transferOwnership(address newOwner) internal{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}