Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation setup #110

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
01ecc26
add package.json
doerfli Jun 2, 2023
fabd05e
Edit Docu
ladylyly Jun 2, 2023
65b9037
Documentation of smart contracts
ladylyly Jun 5, 2023
77adc63
First push of docs
ladylyly Jun 7, 2023
99de8cd
add artifacts to .gitignore
christoph2806 Jun 7, 2023
bf74a77
remove artifacts from git
christoph2806 Jun 7, 2023
1d9ed50
add solidity-docgen dev dependency
christoph2806 Jun 7, 2023
4c9ec80
add cache/ to .gitignore
christoph2806 Jun 7, 2023
7c14c9a
update .gitignore
christoph2806 Jun 7, 2023
a6edb79
Fix natspec syntax
christoph2806 Jun 7, 2023
bad8168
Add README.adoc to every contract subfolder
christoph2806 Jun 8, 2023
094647c
Update list formatting
christoph2806 Jun 8, 2023
2e367d2
Rerun docgen
christoph2806 Jun 8, 2023
e509a29
Error Codes
christoph2806 Jun 9, 2023
2a591be
Format error codes
christoph2806 Jun 9, 2023
ffdefb8
Fix link
christoph2806 Jun 9, 2023
ae27dba
Reformat
christoph2806 Jun 9, 2023
66a7fcc
Fix format
christoph2806 Jun 9, 2023
79a4676
Fix heading
christoph2806 Jun 9, 2023
33239fa
Fix format...
christoph2806 Jun 9, 2023
330f64f
fix format....
christoph2806 Jun 9, 2023
105fb82
test new format
christoph2806 Jun 9, 2023
ab8f62d
zwischenstand
christoph2806 Jun 12, 2023
9c88a8e
Docs update
ladylyly Jun 12, 2023
60372ce
Docs update
ladylyly Jun 15, 2023
fa3c77c
Update adocs
ladylyly Jun 15, 2023
966efcb
Updated ReadMe comments
ladylyly Jun 15, 2023
e3cbd76
only validate and list error codes surrounded by quotes
doerfli Jun 15, 2023
a91d3ce
ReadMe.adoc updates
ladylyly Jun 15, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ __pycache__
.history
.hypothesis/
build/
artifacts/
reports/
cache/
dump_sources/
node_modules
tmp/
Expand All @@ -14,3 +16,4 @@ tmp/
.vscode/launch.json

etherisc*.tgz

8 changes: 8 additions & 0 deletions contracts/flows/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
= Flows

[.readme-notice]
NOTE: This document is better viewed at https://docs.etherisc.com/contracts/api/flows

== Contracts

{{PolicyDefaultFlow}}
123 changes: 76 additions & 47 deletions contracts/modules/AccessController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,59 @@ import "@etherisc/gif-interface/contracts/modules/IAccess.sol";
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";


contract AccessController is
IAccess,
CoreController,
AccessControlEnumerable
{

/**
* @dev The provided smart contract is called "AccessController" and is written in Solidity. It implements the "IAccess" interface and inherits from the "CoreController" contract and the "AccessControlEnumerable" contract. The contract provides functionalities for access control and role management.
*
* Roles:
*
* The contract defines three role identifiers as bytes32 constants:
* 1. PRODUCT_OWNER_ROLE: Represents the role of a product owner.
* 2. ORACLE_PROVIDER_ROLE: Represents the role of an oracle provider.
* 3. RISKPOOL_KEEPER_ROLE: Represents the role of a risk pool keeper.
*
* State Variables:
*
* - `validRole`: A mapping that stores the validity of each role. It maps a role identifier (bytes32) to a boolean value indicating whether the role is valid.
* - `_defaultAdminSet`: A boolean flag indicating whether the default admin role has been set.
*
* Functions:
*
* - `_afterInitialize()`: Internal function called after contract initialization, which adds the product owner, oracle provider, and risk pool keeper roles. It calls the `_populateValidRoles()` function.
* - `_getName()`: Internal pure function that returns the name of the contract as a bytes32 value.
* - `setDefaultAdminRole(address defaultAdmin)`: Sets the default admin role for the Access Control List (ACL) by granting the DEFAULT_ADMIN_ROLE to the specified address. It can only be called once, and emits a `RoleGranted` event.
* - `grantRole(bytes32 role, address principal)`: Grants a specific role to a principal (address). The caller must be an instance operator. It checks the validity of the role and calls the `grantRole()` function from the `AccessControl` contract.
* - `revokeRole(bytes32 role, address principal)`: Revokes a specific role from a principal. The caller must be an instance operator. It calls the `revokeRole()` function from the `AccessControl` contract.
* - `renounceRole(bytes32 role, address principal)`: Removes a principal from a specific role in the access control list (ACL) of the contract. It calls the `renounceRole()` function from the `AccessControl` contract.
* - `addRole(bytes32 role)`: Adds a new role to the Access Control List. The caller must be an instance operator. It checks if the role is already valid and adds it to the `validRole` mapping.
* - `invalidateRole(bytes32 role)`: Invalidates a role by marking it as not valid. The caller must be an instance operator. It checks if the role is valid and updates the `validRole` mapping.
* - `hasRole(bytes32 role, address principal)`: Checks if a given principal has a specific role. It returns a boolean value indicating whether the principal has the specified role.
* - `getDefaultAdminRole()`: Returns the bytes32 value of the DEFAULT_ADMIN_ROLE.
* - `getProductOwnerRole()`: Returns the bytes32 value of the PRODUCT_OWNER_ROLE.
* - `getOracleProviderRole()`: Returns the bytes32 value of the ORACLE_PROVIDER_ROLE.
* - `getRiskpoolKeeperRole()`: Returns the bytes32 value of the RISKPOOL_KEEPER_ROLE.
* - `_populateValidRoles()`: Internal function that populates the `validRole` mapping with the roles considered valid for the contract. It sets the validity of the predefined roles to true.
*
* Modifiers:
*
* - `onlyInstanceOperator`: A modifier that restricts access to functions to only instance operators.
*
* Overall, the contract provides a flexible access control mechanism by defining roles and
* allowing the assignment, revocation, and validation of roles by instance operators.
* It also sets a default admin role and manages the validity of roles through the `validRole` mapping.
*/

contract AccessController is IAccess, CoreController, AccessControlEnumerable {
// 0xe984cfd1d1fa34f80e24ddb2a60c8300359d79eee44555bc35c106eb020394cd
bytes32 public constant PRODUCT_OWNER_ROLE = keccak256("PRODUCT_OWNER_ROLE");
bytes32 public constant PRODUCT_OWNER_ROLE =
keccak256("PRODUCT_OWNER_ROLE");

// 0xd26b4cd59ffa91e4599f3d18b02fcd5ffb06e03216f3ee5f25f68dc75cbbbaa2
bytes32 public constant ORACLE_PROVIDER_ROLE = keccak256("ORACLE_PROVIDER_ROLE");
bytes32 public constant ORACLE_PROVIDER_ROLE =
keccak256("ORACLE_PROVIDER_ROLE");

// 0x3c4cdb47519f2f89924ebeb1ee7a8a43b8b00120826915726460bb24576012fd
bytes32 public constant RISKPOOL_KEEPER_ROLE = keccak256("RISKPOOL_KEEPER_ROLE");
bytes32 public constant RISKPOOL_KEEPER_ROLE =
keccak256("RISKPOOL_KEEPER_ROLE");

mapping(bytes32 => bool) public validRole;

Expand All @@ -33,84 +71,75 @@ contract AccessController is
_populateValidRoles();
}

function _getName() internal override pure returns(bytes32) { return "Access"; }
function _getName() internal pure override returns (bytes32) {
return "Access";
}

// IMPORTANT check the setting of the default admin role
// after the deployment of a GIF instance.
// this method is called in the deployment of
// the instance operator proxy/controller
function setDefaultAdminRole(address defaultAdmin)
external
{
// the instance operator proxy/controller
function setDefaultAdminRole(address defaultAdmin) external {
require(!_defaultAdminSet, "ERROR:ACL-001:ADMIN_ROLE_ALREADY_SET");
_defaultAdminSet = true;

_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
}

//--- manage role ownership ---------------------------------------------//
function grantRole(bytes32 role, address principal)
public
override(IAccessControl, IAccess)
onlyInstanceOperator
{
function grantRole(
bytes32 role,
address principal
) public override(IAccessControl, IAccess) onlyInstanceOperator {
require(validRole[role], "ERROR:ACL-002:ROLE_UNKNOWN_OR_INVALID");
AccessControl.grantRole(role, principal);
}

function revokeRole(bytes32 role, address principal)
public
override(IAccessControl, IAccess)
onlyInstanceOperator
{
function revokeRole(
bytes32 role,
address principal
) public override(IAccessControl, IAccess) onlyInstanceOperator {
AccessControl.revokeRole(role, principal);
}

function renounceRole(bytes32 role, address principal)
public
override(IAccessControl, IAccess)
{
function renounceRole(
bytes32 role,
address principal
) public override(IAccessControl, IAccess) {
AccessControl.renounceRole(role, principal);
}

//--- manage roles ------------------------------------------------------//
function addRole(bytes32 role)
public override
onlyInstanceOperator
{
function addRole(bytes32 role) public override onlyInstanceOperator {
require(!validRole[role], "ERROR:ACL-003:ROLE_EXISTING_AND_VALID");
validRole[role] = true;
}

function invalidateRole(bytes32 role)
public override
onlyInstanceOperator
{
function invalidateRole(bytes32 role) public override onlyInstanceOperator {
require(validRole[role], "ERROR:ACL-004:ROLE_UNKNOWN_OR_INVALID");
validRole[role] = false;
}

function hasRole(bytes32 role, address principal)
public view
override(IAccessControl, IAccess)
returns(bool)
{
function hasRole(
bytes32 role,
address principal
) public view override(IAccessControl, IAccess) returns (bool) {
return super.hasRole(role, principal);
}

function getDefaultAdminRole() public pure override returns(bytes32) {
function getDefaultAdminRole() public pure override returns (bytes32) {
return DEFAULT_ADMIN_ROLE;
}

function getProductOwnerRole() public pure override returns(bytes32) {
function getProductOwnerRole() public pure override returns (bytes32) {
return PRODUCT_OWNER_ROLE;
}

function getOracleProviderRole() public pure override returns(bytes32) {
function getOracleProviderRole() public pure override returns (bytes32) {
return ORACLE_PROVIDER_ROLE;
}

function getRiskpoolKeeperRole() public pure override returns(bytes32) {
function getRiskpoolKeeperRole() public pure override returns (bytes32) {
return RISKPOOL_KEEPER_ROLE;
}

Expand Down
Loading