Skip to content

Commit

Permalink
adapt to gif-interface v1.5.0-staging-j, fix solc to 0.8.2 and oz to 4.7
Browse files Browse the repository at this point in the history
matthiaszimmermann committed Jun 30, 2022
1 parent 22de87d commit 370e731
Showing 12 changed files with 138 additions and 99 deletions.
10 changes: 5 additions & 5 deletions brownie-config.yaml
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@ dotenv: .env
compiler:
evm_version: null
solc:
version: null
version: 0.8.2
optimizer:
enabled: true
runs: 200
# https://eth-brownie.readthedocs.io/en/stable/compile.html#compiler-settings
remappings:
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.6.0"
- "@gif-interface=etherisc/gif-interface@1.5.0-staging-i"
- "@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.7.0"
- "@gif-interface=etherisc/gif-interface@1.5.0-staging-j"
vyper:
version: null

@@ -21,8 +21,8 @@ compiler:
# to list the packages installed via the dependency list below
dependencies:
# github dependency format: <owner>/<repository>@<release>
- OpenZeppelin/openzeppelin-contracts@4.6.0
- etherisc/gif-interface@1.5.0-staging-i
- OpenZeppelin/openzeppelin-contracts@4.7.0
- etherisc/gif-interface@1.5.0-staging-j

# exclude Ownable when calculating test coverage
# https://eth-brownie.readthedocs.io/en/v1.10.3/config.html#exclude_paths
6 changes: 6 additions & 0 deletions contracts/flows/PolicyFlowDefault.sol
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
pragma solidity ^0.8.0;

import "../shared/WithRegistry.sol";
// import "../shared/CoreController.sol";
import "@gif-interface/contracts/modules/ILicense.sol";
import "@gif-interface/contracts/modules/IPolicy.sol";
import "@gif-interface/contracts/modules/IQuery.sol";
@@ -17,6 +18,7 @@ import "@gif-interface/contracts/modules/IQuery.sol";

contract PolicyFlowDefault is
WithRegistry
// CoreController
{
bytes32 public constant NAME = "PolicyFlowDefault";

@@ -183,4 +185,8 @@ contract PolicyFlowDefault is
function getQueryContract() internal view returns (IQuery) {
return IQuery(getContractFromRegistry("Query"));
}

// function getContractFromRegistry(bytes32 moduleName) internal view returns(address) {
// return _getContractAddress(moduleName);
// }
}
64 changes: 32 additions & 32 deletions contracts/modules/AccessController.sol
Original file line number Diff line number Diff line change
@@ -42,37 +42,37 @@ contract AccessController is
}

//--- enforce role ownership --------------------------------------------//
function enforceProductOwnerRole(address principal) public view {
enforceRole(PRODUCT_OWNER_ROLE, principal);
}

function enforceOracleProviderRole(address principal) public view {
enforceRole(ORACLE_PROVIDER_ROLE, principal);
}

function enforceRiskpoolKeeperRole(address principal) public view {
enforceRole(RISKPOOL_KEEPER_ROLE, principal);
}

// adapted from oz AccessControl._checkRole
function enforceRole(bytes32 role, address principal) public view {
require(
hasRole(role, principal),
string(
abi.encodePacked(
"AccessController.enforceRole: account ",
Strings.toHexString(uint160(principal), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
// function enforceProductOwnerRole(address principal) public view {
// enforceRole(PRODUCT_OWNER_ROLE, principal);
// }

// function enforceOracleProviderRole(address principal) public view {
// enforceRole(ORACLE_PROVIDER_ROLE, principal);
// }

// function enforceRiskpoolKeeperRole(address principal) public view {
// enforceRole(RISKPOOL_KEEPER_ROLE, principal);
// }

// // adapted from oz AccessControl._checkRole
// function enforceRole(bytes32 role, address principal) public view {
// require(
// hasRole(role, principal),
// string(
// abi.encodePacked(
// "AccessController.enforceRole: account ",
// Strings.toHexString(uint160(principal), 20),
// " is missing role ",
// Strings.toHexString(uint256(role), 32)
// )
// )
// );
// }

//--- manage role ownership ---------------------------------------------//
function grantRole(bytes32 role, address principal)
public
override(AccessControl, IAccessControl, IAccess)
override(IAccessControl, IAccess)
onlyInstanceOperator
{
require(validRole[role], "ERROR:ACL-002:ROLE_UNKNOWN_OR_INVALID");
@@ -81,30 +81,30 @@ contract AccessController is

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

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

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

function invalidateRole(bytes32 role)
public
public override
onlyInstanceOperator
{
require(validRole[role], "ERROR:ACL-004:ROLE_UNKNOWN_OR_INVALID");
@@ -113,7 +113,7 @@ contract AccessController is

function hasRole(bytes32 role, address principal)
public view
override(AccessControl, IAccessControl, IAccess)
override(IAccessControl, IAccess)
returns(bool)
{
return super.hasRole(role, principal);
9 changes: 6 additions & 3 deletions contracts/modules/ComponentController.sol
Original file line number Diff line number Diff line change
@@ -32,7 +32,10 @@ contract ComponentController is
_;
}

function propose(IComponent component) external onlyComponentOwnerService {
function propose(IComponent component)
external
onlyComponentOwnerService
{
// input validation
require(_componentIdByAddress[address(component)] == 0, "ERROR:CCR-002:COMPONENT_ALREADY_EXISTS");
require(_componentIdByName[component.getName()] == 0, "ERROR:CCR-003:COMPONENT_NAME_ALREADY_EXISTS");
@@ -75,7 +78,7 @@ contract ComponentController is
}

function approve(uint256 id)
external
external
onlyInstanceOperatorService
{
IComponent component = getComponent(id);
@@ -87,7 +90,7 @@ contract ComponentController is
}

function decline(uint256 id)
external
external
onlyInstanceOperatorService
{
IComponent component = getComponent(id);
2 changes: 1 addition & 1 deletion contracts/modules/PolicyController.sol
Original file line number Diff line number Diff line change
@@ -252,7 +252,7 @@ contract PolicyController is
}

function getMetadata(bytes32 _bpKey)
public
public override
view
returns (IPolicy.Metadata memory _metadata)
{
22 changes: 17 additions & 5 deletions contracts/services/ComponentOwnerService.sol
Original file line number Diff line number Diff line change
@@ -37,26 +37,38 @@ contract ComponentOwnerService is
}

function propose(IComponent component)
external
external override
onlyOwnerWithRoleFromComponent(component)
{
_component.propose(component);
}

function stake(uint256 id) external onlyOwnerWithRole(id) {
function stake(uint256 id)
external override
onlyOwnerWithRole(id)
{
revert("ERROR:COS-006:IMPLEMENATION_MISSING");
}

function withdraw(uint256 id) external onlyOwnerWithRole(id) {
function withdraw(uint256 id)
external override
onlyOwnerWithRole(id)
{
revert("ERROR:COS-007:IMPLEMENATION_MISSING");
}


function pause(uint256 id) external onlyOwnerWithRole(id) {
function pause(uint256 id)
external override
onlyOwnerWithRole(id)
{
_component.pause(id);
}

function unpause(uint256 id) external onlyOwnerWithRole(id) {
function unpause(uint256 id)
external override
onlyOwnerWithRole(id)
{
_component.unpause(id);
}

3 changes: 2 additions & 1 deletion contracts/services/InstanceOperatorService.sol
Original file line number Diff line number Diff line change
@@ -74,7 +74,6 @@ contract InstanceOperatorService is
_access.grantRole(role, principal);
}

// TODO add implementation in accesscontroller
function revokeRole(bytes32 role, address principal)
external override
onlyOwner
@@ -112,6 +111,7 @@ contract InstanceOperatorService is
}

// service staking
// TODO implement setDefaultStaking staking
function setDefaultStaking(
uint16 componentType,
bytes calldata data
@@ -122,6 +122,7 @@ contract InstanceOperatorService is
revert("ERROR:IOS-001:IMPLEMENATION_MISSING");
}

// TODO implement adjustStakingRequirements staking
function adjustStakingRequirements(
uint256 id,
bytes calldata data
49 changes: 33 additions & 16 deletions contracts/services/InstanceService.sol
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ contract InstanceService is
return IProductService(_getContractAddress(PRODUCT_SERVICE_NAME));
}

function getOwner() external view returns(address) {
function getOwner() external override view returns(address) {
InstanceOperatorService ios = InstanceOperatorService(_getContractAddress(INSTANCE_OPERATOR_SERVICE_NAME));
return ios.owner();
}
@@ -73,19 +73,6 @@ contract InstanceService is
return _access.hasRole(role, principal);
}

/* policy */
function getMetadata(bytes32 bpKey) external view returns(IPolicy.Metadata memory metadata) {
metadata = _policy().getMetadata(bpKey);
}

function getApplication(bytes32 bpKey) external view returns(IPolicy.Application memory application) {
application = _policy().getApplication(bpKey);
}

function getPolicy(bytes32 bpKey) external view returns(IPolicy.Policy memory policy) {
policy = _policy().getPolicy(bpKey);
}

/* component */
function products() external override view returns(uint256) {
return _component().products();
@@ -95,15 +82,15 @@ contract InstanceService is
return _component().oracles();
}

function riskPools() external override view returns(uint256) {
function riskpools() external override view returns(uint256) {
return _component().riskpools();
}

function getComponent(uint256 id) external override view returns(IComponent) {
return _component().getComponent(id);
}

// service staking
/* service staking */
function getStakingRequirements(uint256 id)
external override
view
@@ -120,6 +107,36 @@ contract InstanceService is
revert("ERROR:IS-002:IMPLEMENATION_MISSING");
}

/* policy */
function getMetadata(bytes32 bpKey) external view returns(IPolicy.Metadata memory metadata) {
metadata = _policy().getMetadata(bpKey);
}

function getApplication(bytes32 processId) external override view returns(IPolicy.Application memory application) {
application = _policy().getApplication(processId);
}

function getPolicy(bytes32 processId) external override view returns(IPolicy.Policy memory policy) {
policy = _policy().getPolicy(processId);
}

function claims(bytes32 processId) external override view returns(uint256 numberOfClaims) {
numberOfClaims = _policy().getMetadata(processId).claimsCount;
}

function payouts(bytes32 processId) external override view returns(uint256 numberOfPayouts) {
numberOfPayouts = _policy().getMetadata(processId).payoutsCount;
}

function getClaim(bytes32 processId, uint256 claimId) external override view returns (IPolicy.Claim memory claim) {
claim = _policy().getClaim(processId, claimId);
}

function getPayout(bytes32 processId, uint256 payoutId) external override view returns (IPolicy.Payout memory payout) {
payout = _policy().getPayout(processId, payoutId);
}

/* internal functions */
function _policy() internal view returns(PolicyController) {
return PolicyController(_getContractAddress(POLICY_NAME));
}
30 changes: 1 addition & 29 deletions contracts/services/ProductService.sol
Original file line number Diff line number Diff line change
@@ -22,35 +22,7 @@ contract ProductService is
require(isAuthorized, "ERROR:PRS-001:NOT_AUTHORIZED");
require(policyFlow != address(0),"ERROR:PRS-002:POLICY_FLOW_NOT_RESOLVED");

_delegateGif(policyFlow);
}

// delegate from GIF.Delegator
function _delegateGif(address _implementation) internal {
bytes memory data = msg.data;

/* solhint-disable no-inline-assembly */
assembly {
let result := delegatecall(
gas(),
_implementation,
add(data, 0x20),
mload(data),
0,
0
)
let size := returndatasize()
let ptr := mload(0x40)
returndatacopy(ptr, 0, size)
switch result
case 0 {
revert(ptr, size)
}
default {
return(ptr, size)
}
}
/* solhint-enable no-inline-assembly */
_delegate(policyFlow);
}


Loading

0 comments on commit 370e731

Please sign in to comment.