Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

packages and sol version updated #73

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions contracts/AbstractNamePrice.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

/// @title NamePrice interface
/// @author Javier Esses
/// @notice Defines an interface for name price calculations
contract AbstractNamePrice {
function price (string calldata name, uint expires, uint duration) external view returns(uint);
abstract contract AbstractNamePrice {
function price (string calldata name, uint expires, uint duration) virtual external view returns(uint);
}
11 changes: 6 additions & 5 deletions contracts/AbstractNodeOwner.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

/// @title NodeOwner interface
/// @notice Defines an interface for the NodeOwner implementation.
contract AbstractNodeOwner is IERC721 {
function available (uint256 tokenId) public view returns(bool);
function reclaim(uint256 tokenId, address newOwner) external;
function removeExpired(uint256[] calldata tokenIds) external;
abstract contract AbstractNodeOwner is IERC721 {
function available (uint256 tokenId) public virtual view returns(bool);
function reclaim(uint256 tokenId, address newOwner) external virtual;
function removeExpired(uint256[] calldata tokenIds) external virtual;
}
19 changes: 8 additions & 11 deletions contracts/BytesUtils.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
pragma solidity ^0.5.3;

import "@openzeppelin/contracts/math/SafeMath.sol";
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

library BytesUtils {
using SafeMath for uint256;

modifier minLength (uint size, uint offset, uint length) {
require(size >= offset.add(length), "Short input");
require(size >= offset + length, "Short input");
_;
}

function toBytes32 (bytes memory input, uint offset) public view minLength(input.length, offset, 32) returns (bytes32) {
function toBytes32 (bytes memory input, uint offset) public pure minLength(input.length, offset, 32) returns (bytes32) {
bytes32 output;

assembly {
Expand All @@ -20,7 +17,7 @@ library BytesUtils {
return output;
}

function toBytes4 (bytes memory input, uint offset) public view minLength(input.length, offset, 4) returns (bytes4) {
function toBytes4 (bytes memory input, uint offset) public pure minLength(input.length, offset, 4) returns (bytes4) {
bytes4 output;

assembly {
Expand All @@ -30,12 +27,12 @@ library BytesUtils {
return output;
}

function toUint (bytes memory input, uint offset) public view returns (uint) {
function toUint (bytes memory input, uint offset) public pure returns (uint) {
return uint(toBytes32(input, offset));
}

// source: https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol
function toString (bytes memory input, uint offset, uint strLength) public view minLength(input.length, offset, strLength) returns (string memory) {
function toString (bytes memory input, uint offset, uint strLength) public pure minLength(input.length, offset, strLength) returns (string memory) {
bytes memory output;

assembly {
Expand Down Expand Up @@ -90,7 +87,7 @@ library BytesUtils {
return string(output);
}

function toAddress (bytes memory input, uint offset) public view minLength(input.length, offset, 20) returns (address) {
function toAddress (bytes memory input, uint offset) public pure minLength(input.length, offset, 20) returns (address) {
bytes20 output;

assembly {
Expand Down
3 changes: 2 additions & 1 deletion contracts/Dummy.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@rsksmart/rns-registry/contracts/RNS.sol";
import "@rsksmart/rns-auction-registrar/contracts/TokenRegistrar.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/FIFSAddrRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@rsksmart/rns-registry/contracts/AbstractRNS.sol";
import "@rsksmart/rns-resolver/contracts/legacy/AbstractAddrResolver.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/FIFSRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "./FIFSRegistrarBase.sol";
import "./PricedContract.sol";
Expand Down
8 changes: 4 additions & 4 deletions contracts/FIFSRegistrarBase.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@ensdomains/ethregistrar/contracts/StringUtils.sol";
import "@rsksmart/erc677/contracts/ERC677.sol";
import "@rsksmart/erc677/contracts/ERC677TransferReceiver.sol";
import "@rsksmart/erc677/contracts/IERC677TransferReceiver.sol";
import "./NodeOwner.sol";
import "./AbstractNamePrice.sol";
import "./BytesUtils.sol";
Expand All @@ -13,7 +13,7 @@ import "./BytesUtils.sol";
/// @notice This is an abstract contract. A Registrar can inherit from
/// this contract to implement basic commit-reveal and admin functionality.
/// @dev Inherited contract should have registrar permission in Node Owner.
contract FIFSRegistrarBase is ERC677TransferReceiver, Ownable {
contract FIFSRegistrarBase is IERC677TransferReceiver, Ownable {
using SafeMath for uint256;
using StringUtils for string;
using BytesUtils for bytes;
Expand Down
5 changes: 3 additions & 2 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

contract Migrations {
address public owner;
uint public lastCompletedMigration;

constructor() public {
constructor() {
owner = msg.sender;
}

Expand Down
12 changes: 5 additions & 7 deletions contracts/NamePrice.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "./AbstractNamePrice.sol";

/// @title NamePrice contract
/// @author Javier Esses
/// @notice Used to calculate the price in RIF token for a given name and duration
/// @dev Implements AbstractNamePrice interface
contract NamePrice is AbstractNamePrice {
using SafeMath for uint256;

/// @author Javi Esses

/// @notice Calculate name price in RIF token for a given duration
/// @dev Is a pure function, but converted to view due the AbstractNamePrice spec
/// @param duration Duration of the name to register in years
/// @return price Price in RIF tokens
function price (string calldata /*name*/, uint /*expires*/, uint duration) external view returns(uint) {
function price (string calldata /*name*/, uint /*expires*/, uint duration) external override pure returns(uint) {
require(duration >= 1, "NamePrice: no zero duration");

if (duration == 1) return 2 * (10**18);
if (duration == 2) return 4 * (10**18);

return duration.add(2).mul(10**18);
return (duration+2) * (10**18);
}
}
30 changes: 15 additions & 15 deletions contracts/NodeOwner.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts/access/Roles.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@rsksmart/rns-registry/contracts/AbstractRNS.sol";
import "./AbstractNodeOwner.sol";

contract NodeOwner is ERC721, Ownable, AbstractNodeOwner {
using Roles for Roles.Role;
contract NodeOwner is ERC721, Ownable, AbstractNodeOwner, AccessControl {
bytes32 public constant RENEWER_ROLE = keccak256("RENEWER_ROLE");
bytes32 public constant REGISTRAR_ROLE = keccak256("REGISTRAR_ROLE");

AbstractRNS private rns;
bytes32 private rootNode;
Expand All @@ -17,12 +19,12 @@ contract NodeOwner is ERC721, Ownable, AbstractNodeOwner {
event ExpirationChanged(uint256 tokenId, uint expirationTime);

modifier onlyRegistrar {
require(registrars.has(msg.sender), "Only registrar.");
require(hasRole(REGISTRAR_ROLE, msg.sender), "Only registrar.");
_;
}

modifier onlyRenewer {
require(renewers.has(msg.sender), "Only renewer.");
require(hasRole(RENEWER_ROLE, msg.sender), "Only renewer.");
_;
}

Expand Down Expand Up @@ -81,27 +83,26 @@ contract NodeOwner is ERC721, Ownable, AbstractNodeOwner {
*/

// An account with registrar role can register domains.
Roles.Role registrars;

/// @notice Give an account access to registrar role.
/// @dev Only owner.
/// @param registrar new registrar.
function addRegistrar(address registrar) external onlyOwner {
registrars.add(registrar);
grantRole(REGISTRAR_ROLE, registrar);
}

/// @notice Check if an account has registrar role.
/// @param registrar to query if has registrar role.
/// @return true if it has registrar role.
function isRegistrar(address registrar) external view returns (bool) {
return registrars.has(registrar);
return hasRole(REGISTRAR_ROLE, registrar);
}

/// @notice Remove an account's access to registrar role.
/// @dev Only owner
/// @param registrar registrar to remove from registrar role.
function removeRegistrar(address registrar) external onlyOwner {
registrars.remove(registrar);
revokeRole(REGISTRAR_ROLE, registrar);
}

/// @notice Registers a domain in RNS for a given duration.
Expand Down Expand Up @@ -155,27 +156,26 @@ contract NodeOwner is ERC721, Ownable, AbstractNodeOwner {
*/

// An account with renewer role can extend domain expirations.
Roles.Role renewers;

/// @notice Give an account access to renewer role.
/// @dev Only owner
/// @param renewer new renewer.
function addRenewer(address renewer) external onlyOwner {
renewers.add(renewer);
grantRole(RENEWER_ROLE, renewer);
}

/// @notice Check if an account has renewer role.
/// @param renewer to query if has renewer role.
/// @return true if it has renewer role.
function isRenewer(address renewer) external view returns (bool) {
return renewers.has(renewer);
return hasRole(RENEWER_ROLE, renewer);
}

/// @notice Remove an account's access to renewer role.
/// @dev Only owner
/// @param renewer renewer to remove from renewer role.
function removeRenewer(address renewer) external onlyOwner {
renewers.remove(renewer);
revokeRole(RENEWER, renewer);
}

/// @notice Renew a domain for a given duraiton.
Expand Down
7 changes: 4 additions & 3 deletions contracts/PricedContract.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./AbstractNamePrice.sol";

contract PricedContract is Ownable {
AbstractNamePrice public namePrice;

event NamePriceChanged(AbstractNamePrice contractAddress);

constructor(AbstractNamePrice _namePrice) public Ownable() {
constructor(AbstractNamePrice _namePrice) {
namePrice = _namePrice;
}

Expand Down
3 changes: 2 additions & 1 deletion contracts/RSKOwner.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@rsksmart/rns-auction-registrar/contracts/TokenRegistrar.sol";
import "@rsksmart/rns-auction-registrar/contracts/TokenDeed.sol";
Expand Down
8 changes: 4 additions & 4 deletions contracts/Renewer.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma solidity ^0.5.3;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "@ensdomains/ethregistrar/contracts/StringUtils.sol";
import "@rsksmart/erc677/contracts/ERC677.sol";
import "@rsksmart/erc677/contracts/ERC677TransferReceiver.sol";
import "@rsksmart/erc677/contracts/IERC677TransferReceiver.sol";
import "./NodeOwner.sol";
import "./PricedContract.sol";
import "./AbstractNamePrice.sol";
Expand All @@ -12,7 +12,7 @@ import "./BytesUtils.sol";
/// @title Simple renewer.
/// @notice You can use this contract to renew names registered in Node Owner.
/// @dev This contract has permission to renew in Node Owner.
contract Renewer is PricedContract, ERC677TransferReceiver {
contract Renewer is PricedContract, IERC677TransferReceiver {
using SafeMath for uint256;
using StringUtils for string;
using BytesUtils for bytes;
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/StringUtilsMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.3;
pragma solidity ^0.8.16;

import "@ensdomains/ethregistrar/contracts/StringUtils.sol";

Expand Down
Loading