feat: add contracts

This commit is contained in:
Ricardo Guilherme Schmidt 2024-06-07 04:57:35 -03:00
parent f827d2f0f1
commit 127dadaf28
23 changed files with 112 additions and 110 deletions

View File

@ -1,8 +1,8 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
contract Controlled {
abstract contract Controlled {
/// @notice The address of the controller is the only address that can call
/// a function with this modifier
modifier onlyController {
@ -12,8 +12,8 @@ contract Controlled {
address payable public controller;
constructor() internal {
controller = msg.sender;
constructor() {
controller = payable(msg.sender);
}
/// @notice Changes the controller of the contract

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.5.11;
pragma solidity 0.8.19;
/**

View File

@ -1,13 +1,11 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
/**
* @notice Uses ethereum signed messages
*/
contract MessageSigned {
constructor() internal {}
abstract contract MessageSigned {
/**
* @notice recovers address who signed the message
@ -77,4 +75,4 @@ contract MessageSigned {
require(v == 27 || v == 28, "Bad signature version");
}
}
}

View File

@ -1,10 +1,10 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
/// @dev `Owned` is a base level contract that assigns an `owner` that can be
/// later changed
contract Owned {
abstract contract Owned {
/// @dev `owner` is the only address that can call a function with this
/// modifier
@ -16,8 +16,8 @@ contract Owned {
address payable public owner;
/// @notice The Constructor assigns the message sender to be `owner`
constructor() internal {
owner = msg.sender;
constructor() {
owner = payable(msg.sender);
}
address payable public newOwner;
@ -35,4 +35,4 @@ contract Owned {
owner = newOwner;
}
}
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.5.11;
pragma solidity 0.8.19;
/**
* Math operations with safety checks

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: BSD-2-Clause
pragma solidity 0.5.11;
pragma solidity 0.8.19;
interface ENS {
@ -32,4 +32,4 @@ interface ENS {
function ttl(bytes32 _node) external view returns (uint64);
function recordExists(bytes32 _node) external view returns (bool);
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: BSD-2-Clause
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "./ENS.sol";
@ -28,7 +28,7 @@ contract ENSRegistry is ENS {
/**
* @dev Constructs a new ENS registrar.
*/
constructor() public {
constructor() {
records[0x0].owner = msg.sender;
}

View File

@ -1,8 +1,8 @@
// SPDX-License-Identifier: BSD-2-Clause
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "./ENS.sol";
import { ENS } from "./ENS.sol";
/**
* A simple resolver anyone can use; only allows the owner of a node to set its
@ -10,14 +10,14 @@ import "./ENS.sol";
*/
contract PublicResolver {
bytes4 constant INTERFACE_META_ID = 0x01ffc9a7;
bytes4 constant ADDR_INTERFACE_ID = 0x3b3b57de;
bytes4 constant NAME_INTERFACE_ID = 0x691f3431;
bytes4 constant ABI_INTERFACE_ID = 0x2203ab56;
bytes4 constant PUBKEY_INTERFACE_ID = 0xc8690233;
bytes4 constant TEXT_INTERFACE_ID = 0x59d1d43c;
bytes4 constant CONTENTHASH_INTERFACE_ID = 0xbc1c58d1;
bytes4 constant INTERFACE_INTERFACE_ID = bytes4(keccak256("interfaceImplementer(bytes32,bytes4)"));
bytes4 public constant INTERFACE_META_ID = 0x01ffc9a7;
bytes4 public constant ADDR_INTERFACE_ID = 0x3b3b57de;
bytes4 public constant NAME_INTERFACE_ID = 0x691f3431;
bytes4 public constant ABI_INTERFACE_ID = 0x2203ab56;
bytes4 public constant PUBKEY_INTERFACE_ID = 0xc8690233;
bytes4 public constant TEXT_INTERFACE_ID = 0x59d1d43c;
bytes4 public constant CONTENTHASH_INTERFACE_ID = 0xbc1c58d1;
bytes4 public constant INTERFACE_INTERFACE_ID = bytes4(keccak256("interfaceImplementer(bytes32,bytes4)"));
event AddrChanged(bytes32 indexed node, address a);
event NameChanged(bytes32 indexed node, string name);
@ -26,6 +26,8 @@ contract PublicResolver {
event TextChanged(bytes32 indexed node, string indexedKey, string key);
event ContenthashChanged(bytes32 indexed node, bytes hash);
event InterfaceChanged(bytes32 indexed node, bytes4 indexed interfaceID, address implementer);
error NotOwner();
error InvalidContentType();
struct PublicKey {
bytes32 x;
@ -42,12 +44,14 @@ contract PublicResolver {
mapping(bytes4=>address) interfaces;
}
ENS ens;
ENS public ens;
mapping (bytes32 => Record) records;
mapping (bytes32 key => Record data) public records;
modifier onlyOwner(bytes32 node) {
require(ens.owner(node) == msg.sender);
if (ens.owner(node) != msg.sender) {
revert NotOwner();
}
_;
}
@ -55,7 +59,7 @@ contract PublicResolver {
* Constructor.
* @param ensAddr The ENS registrar contract.
*/
constructor(ENS ensAddr) public {
constructor(ENS ensAddr) {
ens = ensAddr;
}
@ -63,11 +67,11 @@ contract PublicResolver {
* 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 addr The address to set.
* @param _addr The address to set.
*/
function setAddr(bytes32 node, address addr) external onlyOwner(node) {
records[node].addr = addr;
emit AddrChanged(node, addr);
function setAddr(bytes32 node, address _addr) external onlyOwner(node) {
records[node].addr = _addr;
emit AddrChanged(node, _addr);
}
/**
@ -85,11 +89,11 @@ contract PublicResolver {
* Sets the name associated with an ENS node, for reverse records.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param name The name to set.
* @param _name The name to set.
*/
function setName(bytes32 node, string calldata name) external onlyOwner(node) {
records[node].name = name;
emit NameChanged(node, name);
function setName(bytes32 node, string calldata _name) external onlyOwner(node) {
records[node].name = _name;
emit NameChanged(node, _name);
}
/**
@ -102,7 +106,9 @@ contract PublicResolver {
*/
function setABI(bytes32 node, uint256 contentType, bytes calldata data) external onlyOwner(node) {
// Content types must be powers of 2
require(((contentType - 1) & contentType) == 0);
if(((contentType - 1) & contentType) != 0){
revert InvalidContentType();
}
records[node].abis[contentType] = data;
emit ABIChanged(node, contentType);
@ -133,7 +139,8 @@ contract PublicResolver {
/**
* 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.
* 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 168 interface ID.
* @param implementer The address of a contract that implements this interface for this node.
@ -234,7 +241,9 @@ contract PublicResolver {
return address(0);
}
(bool success, bytes memory returnData) = a.staticcall(abi.encodeWithSignature("supportsInterface(bytes4)", INTERFACE_META_ID));
(bool success, bytes memory returnData) = a.staticcall(
abi.encodeWithSignature("supportsInterface(bytes4)", INTERFACE_META_ID)
);
if(!success || returnData.length < 32 || returnData[31] == 0) {
// EIP 168 not supported by target
return address(0);
@ -264,4 +273,4 @@ contract PublicResolver {
interfaceID == INTERFACE_INTERFACE_ID ||
interfaceID == INTERFACE_META_ID;
}
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: BSD-2-Clause
pragma solidity 0.5.11;
pragma solidity 0.8.19;
pragma experimental ABIEncoderV2;
/**

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "../registry/UsernameRegistrar.sol";
@ -15,7 +15,6 @@ contract Dummy2UsernameRegistrar is UsernameRegistrar {
bytes32 _reservedUsernamesMerkleRoot,
address _parentRegistry
)
public
UsernameRegistrar(
_token,
_ensRegistry,
@ -26,7 +25,7 @@ contract Dummy2UsernameRegistrar is UsernameRegistrar {
_parentRegistry
)
{
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "../registry/UsernameRegistrar.sol";
@ -15,7 +15,6 @@ contract DummyUsernameRegistrar is UsernameRegistrar {
bytes32 _reservedUsernamesMerkleRoot,
address _parentRegistry
)
public
UsernameRegistrar(
_token,
_ensRegistry,
@ -26,7 +25,7 @@ contract DummyUsernameRegistrar is UsernameRegistrar {
_parentRegistry
)
{
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "./Dummy2UsernameRegistrar.sol";
@ -15,7 +15,6 @@ contract UpdatedDummy2UsernameRegistrar is Dummy2UsernameRegistrar {
bytes32 _reservedUsernamesMerkleRoot,
address _parentRegistry
)
public
Dummy2UsernameRegistrar(
_token,
_ensRegistry,
@ -26,7 +25,7 @@ contract UpdatedDummy2UsernameRegistrar is Dummy2UsernameRegistrar {
_parentRegistry
)
{
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "./DummyUsernameRegistrar.sol";
@ -15,7 +15,6 @@ contract UpdatedDummyUsernameRegistrar is DummyUsernameRegistrar {
bytes32 _reservedUsernamesMerkleRoot,
address _parentRegistry
)
public
DummyUsernameRegistrar(
_token,
_ensRegistry,
@ -26,7 +25,7 @@ contract UpdatedDummyUsernameRegistrar is DummyUsernameRegistrar {
_parentRegistry
)
{
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "../registry/UsernameRegistrar.sol";
@ -15,7 +15,6 @@ contract UpdatedUsernameRegistrar is UsernameRegistrar {
bytes32 _reservedUsernamesMerkleRoot,
address _parentRegistry
)
public
UsernameRegistrar(
_token,
_ensRegistry,
@ -26,7 +25,7 @@ contract UpdatedUsernameRegistrar is UsernameRegistrar {
_parentRegistry
)
{
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "../common/MerkleProof.sol";
import "../common/Controlled.sol";
@ -81,7 +81,6 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
address _parentRegistry,
uint256 _releaseDelay
)
public
{
require(address(_token) != address(0), "No ERC20Token address defined.");
require(address(_ensRegistry) != address(0), "No ENS address defined.");
@ -109,7 +108,8 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
* - Usernames registered with less then `usernameMinLength` characters can be slashed.
* - Usernames contained in the merkle tree of root `reservedUsernamesMerkleRoot` can be slashed.
* - Usernames starting with `0x` and bigger then 12 characters can be slashed.
* - If terms of the contract changee.g. Status makes contract upgradesthe user has the right to release the username and get their deposit back.
* - If terms of the contract changee.g. Status makes contract upgradesthe user has the
* right to release the username and get their deposit back.
* @param _label Choosen unowned username hash.
* @param _account Optional address to set at public resolver.
* @param _pubkeyA Optional pubkey part A to set at public resolver.
@ -160,7 +160,7 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
address newOwner = ensRegistry.owner(ensNode);
//Low level call, case dropUsername not implemented or failing, proceed release.
//Return of this call have no use.
newOwner.call.gas(80000)(
newOwner.call{gas:80000}(
abi.encodeWithSelector(
this.dropUsername.selector,
_label
@ -225,10 +225,10 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
{
bytes memory username = bytes(_username);
require(username.length > 12, "Too small to look like an address.");
require(username[0] == byte("0"), "First character need to be 0");
require(username[1] == byte("x"), "Second character need to be x");
require(username[0] == bytes1("0"), "First character need to be 0");
require(username[1] == bytes1("x"), "Second character need to be x");
for(uint i = 2; i < 7; i++){
byte b = username[i];
bytes1 b = username[i];
require((b >= 0x30 && b <= 0x39) || (b >= 0x61 && b <= 0x66), "Does not look like an address");
}
slashUsername(username, _reserveSecret);
@ -272,7 +272,7 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
{
bytes memory username = bytes(_username);
require(username.length > _offendingPos, "Invalid position.");
byte b = username[_offendingPos];
bytes1 b = username[_offendingPos];
require(!((b >= 0x30 && b <= 0x39) || (b >= 0x61 && b <= 0x7A)), "Not invalid character.");
@ -552,6 +552,7 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
bytes memory _data
)
public
override
{
require(_amount == price, "Wrong value");
require(_token == address(token), "Wrong token");
@ -755,7 +756,11 @@ contract UsernameRegistrar is Controlled, ApproveAndCallFallBack {
/**
* @dev Decodes abi encoded data with selector for "register(bytes32,address,bytes32,bytes32)".
* @param _data Abi encoded data.
* @return Decoded registry call.
* @return sig Method selector.
* @return label Username hash.
* @return account Address to set at public resolver.
* @return pubkeyA Pubkey part A to set at public resolver.
* @return pubkeyB Pubkey part B to set at public resolver.
*/
function abiDecodeRegister(
bytes memory _data

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity >=0.8.19 <0.9.0;
import "../common/MerkleProof.sol";

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.5.11;
pragma solidity 0.8.19;
contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 _amount, address _token, bytes memory _data) public;
abstract contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 _amount, address _token, bytes memory _data) public virtual;
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "./ERC20Token.sol";
@ -11,8 +11,8 @@ contract ERC20Receiver {
mapping (address => mapping(address => uint256)) tokenBalances;
constructor() public {
constructor() {
}
function depositToken(
@ -24,7 +24,7 @@ contract ERC20Receiver {
msg.sender,
_token,
_token.allowance(
msg.sender,
msg.sender,
address(this)
)
);
@ -34,7 +34,7 @@ contract ERC20Receiver {
ERC20Token _token,
uint256 _amount
)
external
external
{
_withdrawToken(msg.sender, _token, _amount);
}
@ -42,7 +42,7 @@ contract ERC20Receiver {
function depositToken(
ERC20Token _token,
uint256 _amount
)
)
external
{
require(_token.allowance(msg.sender, address(this)) >= _amount, "Bad argument");
@ -53,9 +53,9 @@ contract ERC20Receiver {
ERC20Token _token,
address _from
)
external
view
returns(uint256 fromTokenBalance)
external
view
returns(uint256 fromTokenBalance)
{
return tokenBalances[address(_token)][_from];
}
@ -65,7 +65,7 @@ contract ERC20Receiver {
ERC20Token _token,
uint256 _amount
)
private
private
{
require(_amount > 0, "Bad argument");
if (_token.transferFrom(_from, address(this), _amount)) {
@ -88,5 +88,5 @@ contract ERC20Receiver {
emit TokenWithdrawn(address(_token), _from, _amount);
}
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
// Abstract contract for the full ERC 20 Token standard
// https://github.com/ethereum/EIPs/issues/20
@ -53,4 +53,4 @@ interface ERC20Token {
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
}

View File

@ -1,16 +1,16 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "./ERC20Token.sol";
contract StandardToken is ERC20Token {
abstract contract StandardToken is ERC20Token {
uint256 private totalTokens;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
constructor() internal { }
constructor() { }
function transfer(
address _to,
@ -93,7 +93,7 @@ contract StandardToken is ERC20Token {
return true;
}
function mint(
function _mint(
address _to,
uint256 _amount
)

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.5.11;
pragma solidity 0.8.19;
import "./StandardToken.sol";
import "./ApproveAndCallFallBack.sol";
@ -10,16 +10,24 @@ import "./ApproveAndCallFallBack.sol";
*/
contract TestToken is StandardToken {
constructor() public { }
constructor() { }
/**
* @notice any caller can mint any `_amount`
* @param _amount how much to be minted
*/
function mint(uint256 _amount) public {
mint(msg.sender, _amount);
_mint(msg.sender, _amount);
}
/**
* @notice any caller can mint any `_amount`
* @param _beneficiary who will receive the minted tokens
* @param _amount how much to be minted
*/
function mint(address _beneficiary, uint256 _amount) public {
_mint(_beneficiary, _amount);
}
function approveAndCall(address _spender, uint256 _value, bytes calldata _extraData)
external

View File

@ -14,7 +14,7 @@
out = "out"
script = "script"
solc = "0.8.19"
src = "src"
src = "contracts"
test = "test"
[profile.ci]

View File

@ -1,13 +0,0 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <=0.9.0;
import { Foo } from "../src/Foo.sol";
import { BaseScript } from "./Base.s.sol";
import { DeploymentConfig } from "./DeploymentConfig.s.sol";
contract Deploy is BaseScript {
function run() public returns (Foo foo, DeploymentConfig deploymentConfig) {
deploymentConfig = new DeploymentConfig(broadcaster);
foo = new Foo();
}
}