Skip to content

Commit

Permalink
🐛 owner + cut
Browse files Browse the repository at this point in the history
  • Loading branch information
kamikazebr committed Sep 21, 2024
1 parent 15b95c8 commit c00daf5
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/contracts/out/Allo.sol/Allo.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/CVStrategyV0_0.sol/CVStrategyV0_0.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/CVStrategyV0_0.sol/IPointStrategy.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/CVStrategyV0_1.sol/CVStrategyV0_1.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/Registry.sol/Registry.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/RegistrySetup.sol/RegistrySetup.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/RegistrySetup.sol/RegistrySetupFull.json

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion pkg/contracts/src/diamonds/BaseDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.19;
import {BaseDiamond} from "@src/diamonds/BaseDiamond.sol";
import {LibDiamond} from "@src/diamonds/libraries/LibDiamond.sol";
import {IDiamondCut} from "@src/diamonds/interfaces/IDiamondCut.sol";
import {IDiamond} from "@src/diamonds/interfaces/IDiamond.sol";

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
// When no function exists for function called
Expand All @@ -27,12 +28,21 @@ contract BaseDiamond is IERC1822Proxiable, IDiamondCut {
constructor() payable {
}

function initializeOwner(address _owner) external {
function initializeOwnerCut(address _owner,IDiamond.FacetCut[] memory _diamondCut, address _init, bytes memory _calldata) external {
_initializeOwner(_owner, _diamondCut, _init, _calldata);
}
function _initializeOwner(address _owner,IDiamond.FacetCut[] memory _diamondCut, address _init, bytes memory _calldata) internal {
if (LibDiamond.isInitialized()) {
revert DiamondAlreadyInitialized();
}
LibDiamond.setContractOwner(_owner);
LibDiamond.setInitialized();
LibDiamond.diamondCut(_diamondCut, _init, _calldata);

}

function initializeOwner(address _owner) external {
_initializeOwner(_owner, new FacetCut[](0), address(0), new bytes(0));
}


Expand Down
8 changes: 6 additions & 2 deletions pkg/contracts/src/diamonds/facets/RegistryFactoryFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {IDiamond} from "@src/diamonds/interfaces/IDiamond.sol";
import {IDiamondCut} from "@src/diamonds/interfaces/IDiamondCut.sol";
import {DiamondCutFacet} from "@src/diamonds/facets/DiamondCutFacet.sol";
import {DiamondLoupeFacet} from "@src/diamonds/facets/DiamondLoupeFacet.sol";
import {LibDiamond} from "@src/diamonds/libraries/LibDiamond.sol";

import {BaseDiamond} from "@src/diamonds/BaseDiamond.sol";

Expand Down Expand Up @@ -41,6 +42,8 @@ contract RegistryFactoryFacet is RegistryFactoryV0_0 {
registryCommunityTemplate = _registryCommunityTemplate;
strategyTemplate = _strategyTemplate;
collateralVaultTemplate = _collateralVaultTemplate;


for (uint i = 0; i < _cuts.length; i++) {
cutsCommunity.push(IDiamond.FacetCut({
facetAddress: _cuts[i].facetAddress,
Expand All @@ -63,10 +66,11 @@ contract RegistryFactoryFacet is RegistryFactoryV0_0 {

ERC1967Proxy proxy = new ERC1967Proxy(
address(registryCommunityTemplate),
abi.encodeWithSelector(BaseDiamond.initializeOwner.selector, owner())
abi.encodeWithSelector(BaseDiamond.initializeOwnerCut.selector, owner(), cutsCommunity, address(0), new bytes(0))
);
// LibDiamond.grantRoleDiamond(LibDiamond.DEFAULT_ADMIN_ROLE, address(proxy));

IDiamondCut(address(proxy)).diamondCut(cutsCommunity, address(0), ""); // @TODO put init address for add supportInterfaces with DiamondInit.sol
// IDiamondCut(address(proxy)).diamondCut(cutsCommunity, address(0), ""); // @TODO put init address for add supportInterfaces with DiamondInit.sol


RegistryCommunityV0_0 registryCommunity = RegistryCommunityV0_0(payable(address(proxy)));
Expand Down
23 changes: 22 additions & 1 deletion pkg/contracts/src/diamonds/libraries/LibDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ error InitializationFunctionReverted(address _initializationContractAddress, byt
library LibDiamond {
bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.diamond.storage");
bytes32 constant _IS_INITALIZED_SLOT = keccak256("diamond.contract.isInitialized");
// bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;


struct FacetAddressAndSelectorPosition {
address facetAddress;
uint16 selectorPosition;
}


struct DiamondStorage {
// function selector => facet address and selector position in selectors array
mapping(bytes4 => FacetAddressAndSelectorPosition) facetAddressAndSelectorPosition;
Expand All @@ -47,7 +49,12 @@ library LibDiamond {
// owner of the contract
address contractOwner;
bool isInitialized;
// mapping(bytes32 => AccessRoleData) roles;
}
// struct AccessRoleData {
// mapping(address => bool) members;
// bytes32 adminRole;
// }

function diamondStorage() internal pure returns (DiamondStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
Expand All @@ -72,14 +79,28 @@ library LibDiamond {
emit OwnershipTransferred(previousOwner, _newOwner);
}

// function grantRoleDiamond(bytes32 role, address account) internal {
// if (!hasRoleDiamond(role, account)) {
// diamondStorage().roles[role].members[account] = true;
// // emit RoleGranted(role, account, msg.msg.sender);
// }
// }
// function hasRoleDiamond(bytes32 role, address account) internal view returns (bool) {
// return diamondStorage().roles[role].members[account];
// }

function contractOwner() internal view returns (address contractOwner_) {
contractOwner_ = diamondStorage().contractOwner;
}

function enforceIsContractOwner() internal view {
if (msg.sender != diamondStorage().contractOwner) {
// if (diamondStorage().roles[DEFAULT_ADMIN_ROLE].members[msg.sender] == false) {
// revert NotContractOwner(msg.sender, address(0x0));
// }
if(msg.sender != diamondStorage().contractOwner){
revert NotContractOwner(msg.sender, diamondStorage().contractOwner);
}

}

event DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata);
Expand Down

0 comments on commit c00daf5

Please sign in to comment.