Skip to content
Verified contractPartialAGPL-3.0-only

CommunityPoolFacet

Address0x95b08eeed52060fb529b9268b65f3bee5046ee92
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.23

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.23+commit.f704f362
Language
solidity
Optimization
Yes, 0 runs
EVM version
shanghai
Via IR
yes
License
AGPL-3.0-only
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,432,548
Creation transaction
0xafe146ff4d…4ea3967415

127 files

The source code is large: one file is shown at a time. Choose a file in the list.

pkg/contracts/src/RegistryCommunity/facets/CommunityPoolFacet.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;

import {CommunityBaseFacet} from "../CommunityBaseFacet.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IRegistry, Metadata} from "allo-v2-contracts/core/interfaces/IRegistry.sol";
import {CVStrategyInitializeParamsV0_3} from "../../CVStrategy/ICVStrategy.sol";
import {CVStrategy} from "../../CVStrategy/CVStrategy.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {IDiamondCut} from "../../diamonds/interfaces/IDiamondCut.sol";
import {IRegistryFactory} from "../../IRegistryFactory.sol";

/// @notice Initialize parameters for the contract
struct RegistryCommunityInitializeParams {
    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;
}

interface IPauseFacet {
    // Sig: 0x1add1a0d
    function setPauseController(address controller) external;
}

/**
 * @title CommunityPoolFacet
 * @notice Facet containing pool creation and initialization functions for RegistryCommunity
 * @dev This facet is called via delegatecall from RegistryCommunity
 *      CRITICAL: Inherits storage layout from CommunityBaseFacet
 */
contract CommunityPoolFacet is CommunityBaseFacet {
    /*|--------------------------------------------|*/
    /*|              EVENTS                        |*/
    /*|--------------------------------------------|*/
    event RegistryInitialized(bytes32 _profileId, string _communityName, Metadata _metadata);
    event PoolCreated(uint256 _poolId, address _strategy, address _community, address _token, Metadata _metadata);

    /*|--------------------------------------------|*/
    /*|              ERRORS                        |*/
    /*|--------------------------------------------|*/
    error ValueCannotBeZero();
    error AllowlistTooBig(uint256 size);

    /*|--------------------------------------------|*/
    /*|              FUNCTIONS                     |*/
    /*|--------------------------------------------|*/

    // Sig: 0xce7e2cd3
    function createPool(address _token, CVStrategyInitializeParamsV0_3 memory _params, Metadata memory _metadata)
        public
        returns (uint256 poolId, address strategy)
    {
        address factoryStrategyTemplate = IRegistryFactory(registryFactory).strategyTemplate();
        address strategyProxy = address(
            new ERC1967Proxy(
                factoryStrategyTemplate,
                abi.encodeWithSelector(CVStrategy.init.selector, address(allo), collateralVaultTemplate, address(this))
            )
        );
        _configureStrategyFacets(strategyProxy);
        (poolId, strategy) = createPool(strategyProxy, _token, _params, _metadata);

        if (address(_params.sybilScorer) == address(0)) {
            if (_params.initialAllowlist.length > 10000) {
                revert AllowlistTooBig(_params.initialAllowlist.length);
            }
            bytes32 allowlistRole = keccak256(abi.encodePacked("ALLOWLIST", poolId));
            for (uint256 i = 0; i < _params.initialAllowlist.length; i++) {
                _grantRole(allowlistRole, _params.initialAllowlist[i]);
            }
        }

        // Set up role admin hierarchy and grant strategy the admin role
        _setRoleAdmin(
            keccak256(abi.encodePacked("ALLOWLIST", poolId)), keccak256(abi.encodePacked("ALLOWLIST_ADMIN", poolId))
        );
        _grantRole(keccak256(abi.encodePacked("ALLOWLIST_ADMIN", poolId)), strategy);
    }

    function _configureStrategyFacets(address strategyProxy) internal {
        address template = IRegistryFactory(registryFactory).strategyTemplate();
        (bool ok, bytes memory data) = template.staticcall(abi.encodeWithSignature("routingFactory()"));
        bool sharedRouter = ok && data.length == 32 && abi.decode(data, (address)) == registryFactory;
        if (!sharedRouter) {
            (IDiamondCut.FacetCut[] memory strategyFacetCuts_, address strategyInit_, bytes memory strategyInitCalldata_) =
                IRegistryFactory(registryFactory).getStrategyFacets();
            if (strategyFacetCuts_.length > 0 || strategyInit_ != address(0)) {
                IDiamondCut(strategyProxy).diamondCut(strategyFacetCuts_, strategyInit_, strategyInitCalldata_);
            }
        }
        address pauseController = IRegistryFactory(registryFactory).globalPauseController();
        if (pauseController != address(0)) {
            IPauseFacet(strategyProxy).setPauseController(pauseController);
        }
        CVStrategy(payable(strategyProxy)).transferOwnership(proxyOwner());
    }

    // Sig: 0x82b18ef4
    function createPool(
        address _strategy,
        address _token,
        CVStrategyInitializeParamsV0_3 memory _params,
        Metadata memory _metadata
    ) public returns (uint256 poolId, address strategy) {
        address token = NATIVE;
        if (_token != address(0)) {
            token = _token;
        }
        strategy = _strategy;

        poolId = allo.createPoolWithCustomStrategy(
            profileId, strategy, abi.encode(_params), token, 0, _metadata, initialMembers
        );

        emit PoolCreated(poolId, strategy, address(this), _token, _metadata);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 0,
    "enabled": true
  },
  "evmVersion": "shanghai",
  "remappings": [
    "allo-v2/=lib/allo-v2/",
    "allo-v2-contracts/=lib/allo-v2/contracts/",
    "allo-v2-test/=lib/allo-v2/test/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/foundry/=lib/openzeppelin-foundry-upgrades/src/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@superfluid-finance/=lib/protocol-monorepo/packages/",
    "@src/=pkg/contracts/src/",
    "forge-std/=lib/forge-std/src/",
    "solady/=lib/allo-v2/lib/solady/src/",
    "@prb/math/=lib/allo-v2/lib/v2-core/lib/prb-math/",
    "@prb/test/=lib/allo-v2/lib/v2-core/lib/prb-test/src/",
    "@sablier/v2-core/=lib/allo-v2/lib/v2-core/",
    "ERC1155/=lib/allo-v2/lib/hats-protocol/lib/ERC1155/",
    "__safe-smart-account/=lib/__safe-smart-account/",
    "ds-test/=lib/allo-v2/lib/forge-std/lib/ds-test/src/",
    "eas-contracts/=lib/allo-v2/lib/eas-contracts/contracts/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "hats-protocol/=lib/allo-v2/lib/hats-protocol/",
    "hedgey-vesting/=lib/allo-v2/lib/hedgey-vesting/contracts/",
    "lib/ERC1155/=lib/allo-v2/lib/hats-protocol/lib/ERC1155/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "permit2/=lib/allo-v2/lib/permit2/src/",
    "protocol-monorepo/=lib/protocol-monorepo/packages/solidity-semantic-money/src/",
    "safe-smart-account/=lib/safe-smart-account/",
    "solarray/=lib/allo-v2/lib/v2-core/lib/solarray/src/",
    "solbase/=lib/allo-v2/lib/hats-protocol/lib/solbase/src/",
    "solidity-stringutils/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/",
    "solmate/=lib/allo-v2/lib/permit2/lib/solmate/",
    "superfluid-protocol-monorepo/=lib/allo-v2/lib/superfluid-protocol-monorepo/packages/solidity-semantic-money/src/",
    "utils/=lib/allo-v2/lib/hats-protocol/lib/utils/",
    "v2-core/=lib/allo-v2/lib/v2-core/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.