feat: add fleek site nft interfaces and implementation (#2)

* feat: add fleek site nft interfaces and implementation

* refactor: rename contracts and interfaces

* refactor: replace FleekAccessControl with AccessControl from open zeppelin

* refactor: split structure in public variables

* feat: add Fleek and FleekSite constructors

* refactor: remove getMetadata functions
This commit is contained in:
Felipe Mendes 2022-11-24 09:19:45 -03:00 committed by GitHub
parent 80a0ae98c1
commit 3a316a6fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 189 additions and 0 deletions

28
contracts/Fleek.sol Normal file
View File

@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "../interfaces/IFleek.sol";
import "./FleekBuilds.sol";
import "./FleekAccessControl.sol";
abstract contract Fleek is IFleek, FleekBuilds {
constructor(string memory _name, string memory _description) {
name = _name;
description = _description;
}
function setName(
string calldata _name
) external override requireController {
name = _name;
emit MetadataUpdated(name, description);
}
function setDescription(
string calldata _description
) external override requireController {
description = _description;
emit MetadataUpdated(name, description);
}
}

View File

@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "../interfaces/IFleekSite.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
abstract contract FleekAccessControl is AccessControl {
bytes32 public constant OWNER_ROLE = keccak256("OWNER_ROLE");
bytes32 public constant CONTROLLER_ROLE = keccak256("CONTROLLER_ROLE");
constructor() {
_setRoleAdmin(OWNER_ROLE, DEFAULT_ADMIN_ROLE);
_grantRole(OWNER_ROLE, msg.sender);
}
modifier requireOwner() {
require(
hasRole(OWNER_ROLE, msg.sender),
"FleekAccessControl: must have owner role"
);
_;
}
modifier requireController() {
bool hasPermission = hasRole(CONTROLLER_ROLE, msg.sender) ||
hasRole(DEFAULT_ADMIN_ROLE, msg.sender);
require(
hasPermission,
"FleekAccessControl: caller is not a controller"
);
_;
}
}

31
contracts/FleekBuilds.sol Normal file
View File

@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "../interfaces/IFleekBuilds.sol";
import "./FleekAccessControl.sol";
abstract contract FleekBuilds is IFleekBuilds, FleekAccessControl {
build[] public builds;
function update(
build calldata _newBuild
) external override requireController {
builds.push(_newBuild);
emit Upgraded(_newBuild);
}
function getCurrentBuild() external view override returns (build memory) {
return builds[builds.length - 1];
}
function getBuildById(
uint256 _buildId
) external view override returns (build memory) {
return builds[_buildId];
}
function getBuilds() external view override returns (build[] memory) {
return builds;
}
}

32
contracts/FleekSite.sol Normal file
View File

@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "./Fleek.sol";
import "../interfaces/IFleekSite.sol";
contract FleekSite is IFleekSite, Fleek {
constructor(
string memory _name,
string memory _description,
string memory _thumbnail,
string memory _external_url
) Fleek(_name, _description) {
thumbnail = _thumbnail;
external_url = _external_url;
}
function setThumbnail(
string calldata _thumbnail
) external override requireController {
thumbnail = _thumbnail;
emit MetadataUpdated(name, description, thumbnail, external_url);
}
function setExternalUrl(
string calldata _external_url
) external override requireController {
external_url = _external_url;
emit MetadataUpdated(name, description, thumbnail, external_url);
}
}

17
interfaces/IFleek.sol Normal file
View File

@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "./IFleekBuilds.sol";
import "@openzeppelin/contracts/access/IAccessControl.sol";
interface IFleek is IFleekBuilds, IAccessControl {
string name;
string description;
event MetadataUpdated(string name, string description);
function setName(string calldata _name) external;
function setDescription(string calldata _description) external;
}

View File

@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
interface IFleekBuilds {
struct build {
string _uri;
string _hash;
string _repo;
string _repository;
}
event InitialVersionDeploy();
event Upgraded(build _build);
function update(build calldata _newBuild) external;
function getCurrentBuild() external view returns (build memory);
function getBuildById(
uint256 _buildId
) external view returns (build memory);
function getBuilds() external view returns (build[] memory);
}

21
interfaces/IFleekSite.sol Normal file
View File

@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "./IFleek.sol";
interface IFleekSite is IFleek {
string thumbnail;
string external_url;
event MetadataUpdated(
string name,
string description,
string thumbnail,
string external_url
);
function setThumbnail(string calldata _thumbnail) external;
function setExternalUrl(string calldata _external_url) external;
}