Skip to content

Commit

Permalink
inherit classes from SBT and NFT
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcabot committed Aug 18, 2022
1 parent 9349b16 commit 24e5ae3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 147 deletions.
14 changes: 3 additions & 11 deletions contracts/SoulBoundCreditReport.sol
@@ -1,20 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.7;

import "./SoulBoundToken.sol";
import "./tokens/SBT.sol";

contract SoulBoundCreditReport is SoulBoundToken {
contract SoulBoundCreditReport is SBT {
constructor(
address owner,
address soulLinker,
string memory baseTokenURI
)
SoulBoundToken(
owner,
soulLinker,
"Masa Credit Report",
"MCR",
baseTokenURI
)
{}
) SBT(owner, soulLinker, "Masa Credit Report", "MCR", baseTokenURI) {}
}
10 changes: 5 additions & 5 deletions contracts/SoulBoundIdentity.sol
@@ -1,18 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.7;

import "./SoulBoundToken.sol";
import "./tokens/SBT.sol";

contract SoulBoundIdentity is SoulBoundToken {
contract SoulBoundIdentity is SBT {
constructor(
address owner,
address soulLinker,
string memory baseTokenURI
) SoulBoundToken(owner, soulLinker, "Masa Identity", "MID", baseTokenURI) {}
) SBT(owner, soulLinker, "Masa Identity", "MID", baseTokenURI) {}

function mint(address to) public override {
function mint(address to) public override returns (uint256) {
require(balanceOf(to) < 1, "Soulbound identity already created!");

super.mint(to);
return super.mint(to);
}
}
75 changes: 18 additions & 57 deletions contracts/SoulBoundName.sol
@@ -1,31 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Base64.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./tokens/NFT.sol";
import "./interfaces/ISoulBoundNameResolver.sol";
import "./SoulBoundIdentity.sol";

contract SoulBoundName is
ERC721,
ERC721Enumerable,
Pausable,
AccessControl,
ERC721Burnable,
ISoulBoundNameResolver
{
contract SoulBoundName is NFT, ISoulBoundNameResolver {
using Strings for uint256;
using Counters for Counters.Counter;

bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
Counters.Counter private _tokenIdCounter;

SoulBoundIdentity public soulBoundIdentity;
string public extension; // suffix of the names (.sol?)
Expand All @@ -42,26 +25,15 @@ contract SoulBoundName is
constructor(
address owner,
SoulBoundIdentity _soulBoundIdentity,
string memory _extension
) ERC721("Masa Identity Name", "MIN") {
string memory _extension,
string memory baseTokenURI
) NFT(owner, "Masa Identity Name", "MIN", baseTokenURI) {
require(address(_soulBoundIdentity) != address(0), "ZERO_ADDRESS");

_grantRole(DEFAULT_ADMIN_ROLE, owner);
_grantRole(PAUSER_ROLE, owner);
_grantRole(MINTER_ROLE, owner);

soulBoundIdentity = _soulBoundIdentity;
extension = _extension;
}

function pause() public onlyRole(PAUSER_ROLE) {
_pause();
}

function unpause() public onlyRole(PAUSER_ROLE) {
_unpause();
}

function setExtension(string memory _extension)
external
onlyRole(DEFAULT_ADMIN_ROLE)
Expand Down Expand Up @@ -153,22 +125,30 @@ contract SoulBoundName is
);
}
function mint(address to)
public
override
onlyRole(MINTER_ROLE)
returns (uint256)
{
revert(
"Function disabled. Use mint(address, name, identityId) instead"
);
}
function mint(
address to,
string memory name,
uint256 identityId
) public onlyRole(MINTER_ROLE) {
require(to != address(0), "ZERO_ADDRESS");
) public onlyRole(MINTER_ROLE) returns (uint256) {
require(!nameExists(name), "NAME_ALREADY_EXISTS");
require(bytes(name).length > 0, "ZERO_LENGTH_NAME");
require(
soulBoundIdentity.ownerOf(identityId) != address(0),
"IDENTITY_NOT_FOUND"
);
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
uint256 tokenId = super.mint(to);
string memory lowercaseName = _toLowerCase(name);
tokenIdToName[tokenId] = lowercaseName;
Expand Down Expand Up @@ -216,25 +196,6 @@ contract SoulBoundName is
super.burn(tokenId);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal override(ERC721, ERC721Enumerable) whenNotPaused {
super._beforeTokenTransfer(from, to, tokenId);
}
// The following functions are overrides required by Solidity.
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function _toLowerCase(string memory _str)
private
pure
Expand Down
74 changes: 0 additions & 74 deletions contracts/SoulBoundToken.sol

This file was deleted.

1 change: 1 addition & 0 deletions contracts/tokens/NFT.sol
Expand Up @@ -66,6 +66,7 @@ abstract contract NFT is
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
Expand Down

0 comments on commit 24e5ae3

Please sign in to comment.