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

Diamond on others contracts #440

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.

Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
using SafeERC20 for IERC20;
using Clone for address;

string public constant VERSION = "0.0";
// string public constant VERSION = "0.0";
function VERSION() public pure virtual returns (string memory) {
return "0.0";
}
/// @notice The native address to represent native token eg: ETH in mainnet
address public constant NATIVE = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/// @notice The precision scale used in the contract to avoid loss of precision
Expand Down
6 changes: 5 additions & 1 deletion pkg/contracts/src/RegistryFactory/RegistryFactoryV0_0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct CommunityInfo {

/// @custom:oz-upgrades-from RegistryFactoryV0_0
contract RegistryFactoryV0_0 is ProxyOwnableUpgrader {
string public constant VERSION = "0.0";
// string public constant VERSION = "0.0";
uint256 public nonce;

mapping(address => CommunityInfo) communityToInfo;
Expand Down Expand Up @@ -134,5 +134,9 @@ contract RegistryFactoryV0_0 is ProxyOwnableUpgrader {
return communityToInfo[_community].fee;
}


function VERSION() public pure virtual returns (string memory) {
return "0.0";
}
uint256[50] private __gap;
}
20 changes: 14 additions & 6 deletions pkg/contracts/src/diamonds/BaseDiamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
pragma solidity ^0.8.19;


import {LibDiamond} from "./libraries/LibDiamond.sol";
import {IDiamondCut} from "./interfaces/IDiamondCut.sol";
import {IDiamondLoupe} from "./interfaces/IDiamondLoupe.sol";
import {IERC173} from "./interfaces/IERC173.sol";
//import { IERC165} from "./interfaces/IERC165.sol";
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 @@ -29,12 +28,21 @@ contract BaseDiamond is IERC1822Proxiable, IDiamondCut {
constructor() payable {
}

function initialize(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
18 changes: 6 additions & 12 deletions pkg/contracts/src/diamonds/RegistryFactoryDiamond.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;

import {BaseDiamond} from "./BaseDiamond.sol";
import {LibDiamond} from "./libraries/LibDiamond.sol";
import {IDiamondCut} from "./interfaces/IDiamondCut.sol";
import {IDiamondLoupe} from "./interfaces/IDiamondLoupe.sol";
import {IERC173} from "./interfaces/IERC173.sol";
//import { IERC165} from "./interfaces/IERC165.sol";
import {BaseDiamond} from "@src/diamonds/BaseDiamond.sol";
import {LibDiamond} from "@src/diamonds/libraries/LibDiamond.sol";

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
// When no function exists for function called

struct CommunityInfo {
uint256 fee;
bool valid;
}
contract RegistryFactoryDiamond is BaseDiamond {
contract RegistryFactoryDiamond is BaseDiamond {
/*|--------------------------------------------|*/
/*| CONSTANTS & IMMUTABLE |*/
/*|--------------------------------------------|*/
string public constant VERSION = "0.0";
// string public constant VERSION = "0.0";
/*|--------------------------------------------|*/
/*| STORAGE |*/
/*|--------------------------------------------|*/
uint8 private _initialized;
uint8 private _initialized;
bool private _initializing;
uint256[50] private __gap1;
address public _owner;
address public _owner;
uint256[49] private __gap2;
uint256 public nonce;

Expand Down
103 changes: 103 additions & 0 deletions pkg/contracts/src/diamonds/StorageCommunityDiamond.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;

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

import {IRegistry} from "allo-v2-contracts/core/interfaces/IRegistry.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ISafe} from "@src/interfaces/ISafe.sol";
import {FAllo} from "@src/interfaces/FAllo.sol";
import {Metadata} from "allo-v2-contracts/core/libraries/Metadata.sol";

/*|--------------------------------------------|*/
/*| STRUCTS/ENUMS |*/
/*|--------------------------------------------|*/

/// @dev Initialize parameters for the contract
/// @param _allo The Allo contract address
/// @param _gardenToken The token used to stake in the community
/// @param _registerStakeAmount The amount of tokens required to register a member
/// @param _communityFee The fee charged to the community for each registration
/// @param _nonce The nonce used to create new strategy clones
/// @param _registryFactory The address of the registry factory
/// @param _feeReceiver The address that receives the community fee
/// @param _metadata The covenant IPFS hash of the community
/// @param _councilSafe The council safe contract address
/// @param _communityName The community name
/// @param _isKickEnabled Enable or disable the kick feature
struct RegistryCommunityInitializeParamsV0_0 {
address _allo;
IERC20 _gardenToken;
uint256 _registerStakeAmount;
uint256 _communityFee;
uint256 _nonce;
address _registryFactory;
address _feeReceiver;
Metadata _metadata;
address payable _councilSafe;
string _communityName;
bool _isKickEnabled;
string covenantIpfsHash;
}

struct Member {
address member;
uint256 stakedAmount;
bool isRegistered;
}

struct Strategies {
address[] strategies;
}
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
abstract contract StorageCommunityDiamond is BaseDiamond {
/*|--------------------------------------------|*/
/*| CONSTANTS & IMMUTABLE |*/
/*|--------------------------------------------|*/

/*|--------------------------------------------|*/
/*| STORAGE |*/
/*|--------------------------------------------|*/

uint8 private _initialized; // || SLOT 0
bool private _initializing; // || SLOT 0
uint256[50] private __gap1; // || SLOT 1
address public _owner; // || SLOT 51
uint256[49] private __gap2; // || SLOT 52
uint256 private _status; // || SLOT 101
uint256[49] private __gap3; // || SLOT 102
uint256[50] private __gap4; // || SLOT 151
mapping(bytes32 => RoleData) private _roles; // || SLOT 201
uint256[49] private __gap5; // || SLOT 202

uint256 public registerStakeAmount; // || SLOT 251
uint256 public communityFee; // || SLOT 252
uint256 public cloneNonce; // || SLOT 253
bytes32 public profileId; // || SLOT 254
bool public isKickEnabled; // || SLOT 255
address public feeReceiver; // || SLOT 255
address public registryFactory; // || SLOT 256
address public collateralVaultTemplate; // || SLOT 257
address public strategyTemplate; // || SLOT 258
address payable public pendingCouncilSafe; // || SLOT 259
IRegistry public registry; // || SLOT 260
IERC20 public gardenToken; // || SLOT 261
ISafe public councilSafe; // || SLOT 262
FAllo public allo; // || SLOT 263
string public communityName; // || SLOT 264
string public covenantIpfsHash; // || SLOT 265
mapping(address => bool) public enabledStrategies; // || SLOT 266
mapping(address => mapping(address => uint256)) public memberPowerInStrategy; // || SLOT 267
mapping(address => Member) public addressToMemberInfo; // || SLOT 268
mapping(address => address[]) public strategiesByMember; // || SLOT 269
mapping(address => mapping(address => bool)) public memberActivatedInStrategies; // || SLOT 270
address[] public initialMembers; // || SLOT 271
uint256[50] private __gap6; // || SLOT 272
/*|--------------------------------------------|*/
/*| STORAGE |*/
/*|--------------------------------------------|*/
}
45 changes: 45 additions & 0 deletions pkg/contracts/src/diamonds/facets/RegistryCommunityFacet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;

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

import {RegistryCommunityV0_1 } from "@src/RegistryCommunity/RegistryCommunityV0_1.sol";
import {ProxyOwnableUpgrader} from "@src/ProxyOwnableUpgrader.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Clone} from "allo-v2-contracts/core/libraries/Clone.sol";


contract RegistryCommunityFacet is RegistryCommunityV0_1 {

// AUDIT: acknowledged upgradeable contract hat does not protect initialize functions,
// slither-disable-next-line unprotected-upgrade
function initializeV2(
address _owner,
address _strategyTemplate,
address _collateralVaultTemplate
) public reinitializer(2) onlyOwner {
_revertZeroAddress(_owner);
_revertZeroAddress(_strategyTemplate);
_revertZeroAddress(_collateralVaultTemplate);

transferOwnership(_owner);

strategyTemplate = _strategyTemplate;
collateralVaultTemplate = _collateralVaultTemplate;
//TODO emit event reinitialized
}


function VERSION() public pure override returns (string memory) {
return "0.1";
}

// This implements ERC-165.
function supportsInterface(bytes4 _interfaceId) public view override virtual returns (bool) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return ds.supportedInterfaces[_interfaceId];
}


uint256[50] private __gap;
}
Loading
Loading