From 3a316a6feaa37d6c91c16a63fadf056faf747fac Mon Sep 17 00:00:00 2001 From: Felipe Mendes Date: Thu, 24 Nov 2022 09:19:45 -0300 Subject: [PATCH] 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 --- contracts/Fleek.sol | 28 ++++++++++++++++++++++++++ contracts/FleekAccessControl.sol | 34 ++++++++++++++++++++++++++++++++ contracts/FleekBuilds.sol | 31 +++++++++++++++++++++++++++++ contracts/FleekSite.sol | 32 ++++++++++++++++++++++++++++++ interfaces/IFleek.sol | 17 ++++++++++++++++ interfaces/IFleekBuilds.sol | 26 ++++++++++++++++++++++++ interfaces/IFleekSite.sol | 21 ++++++++++++++++++++ 7 files changed, 189 insertions(+) create mode 100644 contracts/Fleek.sol create mode 100644 contracts/FleekAccessControl.sol create mode 100644 contracts/FleekBuilds.sol create mode 100644 contracts/FleekSite.sol create mode 100644 interfaces/IFleek.sol create mode 100644 interfaces/IFleekBuilds.sol create mode 100644 interfaces/IFleekSite.sol diff --git a/contracts/Fleek.sol b/contracts/Fleek.sol new file mode 100644 index 0000000..c1b85d7 --- /dev/null +++ b/contracts/Fleek.sol @@ -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); + } +} diff --git a/contracts/FleekAccessControl.sol b/contracts/FleekAccessControl.sol new file mode 100644 index 0000000..bcbad22 --- /dev/null +++ b/contracts/FleekAccessControl.sol @@ -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" + ); + _; + } +} diff --git a/contracts/FleekBuilds.sol b/contracts/FleekBuilds.sol new file mode 100644 index 0000000..ecf0aed --- /dev/null +++ b/contracts/FleekBuilds.sol @@ -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; + } +} diff --git a/contracts/FleekSite.sol b/contracts/FleekSite.sol new file mode 100644 index 0000000..070f332 --- /dev/null +++ b/contracts/FleekSite.sol @@ -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); + } +} diff --git a/interfaces/IFleek.sol b/interfaces/IFleek.sol new file mode 100644 index 0000000..b164e77 --- /dev/null +++ b/interfaces/IFleek.sol @@ -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; +} diff --git a/interfaces/IFleekBuilds.sol b/interfaces/IFleekBuilds.sol new file mode 100644 index 0000000..67612ed --- /dev/null +++ b/interfaces/IFleekBuilds.sol @@ -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); +} diff --git a/interfaces/IFleekSite.sol b/interfaces/IFleekSite.sol new file mode 100644 index 0000000..81d55d1 --- /dev/null +++ b/interfaces/IFleekSite.sol @@ -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; +}