Skip to content
Verified contractExactBUSL-1.1

TesseractVaultDeployer

Address0x55073cdf0b0e42c8b807a265eadff69973274a8d
Balance

0 ETH

 

Transactions

7

 

Compiler

solc 0.8.30

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 10,000,000 runs
EVM version
cancun
License
BUSL-1.1
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,748,752
Creation transaction
0x0f6e31dc39…989d7b9cf4
Main copy (most transactions)
0xe4d85722…ad942fd9

103 files

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

contracts/TesseractVaultDeployer.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.30;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {FusionFactoryLogicLib} from "@ipor-fusion/factory/lib/FusionFactoryLogicLib.sol";
import {IFusionFactory} from "./interfaces/IFusionFactory.sol";
import {IporFusionAccessManager} from "@ipor-fusion/managers/access/IporFusionAccessManager.sol";
import {FeeManager} from "@ipor-fusion/managers/fee/FeeManager.sol";
import {RecipientFee} from "@ipor-fusion/managers/fee/FeeManagerFactory.sol";
import {PlasmaVault} from "@ipor-fusion/vaults/PlasmaVault.sol";
import {Roles} from "@ipor-fusion/libraries/Roles.sol";
import {IWhitelisting} from "./interfaces/IWhitelisting.sol";

/// @title TesseractVaultDeployer
/// @notice Deploys pre-configured IPOR Fusion vaults for whitelisted clients
/// @dev Each deployer instance is bound to a single underlying asset.
///      Whitelisted callers invoke deployVault() and automatically receive WHITELIST_ROLE on the created vault.
contract TesseractVaultDeployer is Ownable2Step {
    using SafeERC20 for IERC20;

    error ZeroAddress();
    error NotWhitelisted();
    error InsufficientInitialDeposit();
    error PermitFailed();
    error ManagementFeeTooHigh();
    error PerformanceFeeTooHigh();
    error ManagementFeeExceedsMax(uint256 fee, uint256 maxFee);
    error PerformanceFeeExceedsMax(uint256 fee, uint256 maxFee);

    event VaultOwnerUpdated(address indexed newVaultOwner);
    event GuardianUpdated(address indexed newGuardian);
    event AtomistUpdated(address indexed newAtomist);
    event AlphaUpdated(address indexed newAlpha);
    event FuseManagerUpdated(address indexed newFuseManager);
    event TesseractRewardsManagerUpdated(address indexed newTesseractRewardsManager);
    event MinInitialDepositUpdated(uint256 newMinInitialDeposit);
    event FeesUpdated(uint256 newManagementFee, uint256 newPerformanceFee);
    event FeeRecipientUpdated(address indexed newFeeRecipient);
    event DaoFeePackageIndexUpdated(uint256 newDaoFeePackageIndex);
    event VaultDeployed(
        address indexed plasmaVault,
        address indexed owner,
        address accessManager,
        address feeManager,
        address rewardsManager,
        address withdrawManager,
        address contextManager,
        address priceManager
    );

    // === Constants ===
    uint256 public constant MAX_MANAGEMENT_FEE = 10_00; // 10%
    uint256 public constant MAX_PERFORMANCE_FEE = 50_00; // 50%

    IFusionFactory public immutable FUSION_FACTORY;
    IWhitelisting public immutable WHITELISTING;
    address public immutable UNDERLYING_TOKEN;
    uint256 public immutable REDEMPTION_DELAY_IN_SECONDS;
    string public assetName;
    string public assetSymbol;

    // === Mutable (owner can update) ===
    uint256 public daoFeePackageIndex;
    address public vaultOwner;
    address public guardian;
    address public atomist;
    address public alpha;
    address public fuseManager;
    address public tesseractRewardsManager;
    uint256 public minInitialDeposit;
    uint256 public managementFee;
    uint256 public performanceFee;
    address public feeRecipient;

    /// @notice Initialization parameters for the deployer
    struct InitParams {
        address owner;
        address fusionFactory;
        address whitelisting;
        string assetName;
        string assetSymbol;
        address underlyingToken;
        uint256 redemptionDelayInSeconds;
        uint256 daoFeePackageIndex;
        address vaultOwner;
        address guardian;
        address atomist;
        address alpha;
        address fuseManager;
        address tesseractRewardsManager;
        uint256 minInitialDeposit;
        uint256 managementFee;
        uint256 performanceFee;
        address feeRecipient;
    }

    modifier onlyWhitelisted() {
        if (!WHITELISTING.isWhitelisted(msg.sender)) revert NotWhitelisted();
        _;
    }

    constructor(InitParams memory p) Ownable(p.owner) {
        if (p.fusionFactory == address(0)) revert ZeroAddress();
        if (p.whitelisting == address(0)) revert ZeroAddress();
        if (p.underlyingToken == address(0)) revert ZeroAddress();
        if (p.vaultOwner == address(0)) revert ZeroAddress();
        if (p.guardian == address(0)) revert ZeroAddress();
        if (p.atomist == address(0)) revert ZeroAddress();
        if (p.alpha == address(0)) revert ZeroAddress();
        if (p.fuseManager == address(0)) revert ZeroAddress();
        if (p.tesseractRewardsManager == address(0)) revert ZeroAddress();
        if (p.feeRecipient == address(0)) revert ZeroAddress();
        if (p.managementFee > MAX_MANAGEMENT_FEE) revert ManagementFeeTooHigh();
        if (p.performanceFee > MAX_PERFORMANCE_FEE) revert PerformanceFeeTooHigh();

        FUSION_FACTORY = IFusionFactory(p.fusionFactory);
        WHITELISTING = IWhitelisting(p.whitelisting);
        UNDERLYING_TOKEN = p.underlyingToken;
        REDEMPTION_DELAY_IN_SECONDS = p.redemptionDelayInSeconds;

        assetName = p.assetName;
        assetSymbol = p.assetSymbol;
        daoFeePackageIndex = p.daoFeePackageIndex;

        vaultOwner = p.vaultOwner;
        guardian = p.guardian;
        atomist = p.atomist;
        alpha = p.alpha;
        fuseManager = p.fuseManager;
        tesseractRewardsManager = p.tesseractRewardsManager;
        minInitialDeposit = p.minInitialDeposit;
        managementFee = p.managementFee;
        performanceFee = p.performanceFee;
        feeRecipient = p.feeRecipient;
    }

    // === Setters (onlyOwner) ===

    function setVaultOwner(address newVaultOwner) external onlyOwner {
        if (newVaultOwner == address(0)) revert ZeroAddress();
        vaultOwner = newVaultOwner;
        emit VaultOwnerUpdated(newVaultOwner);
    }

    function setGuardian(address newGuardian) external onlyOwner {
        if (newGuardian == address(0)) revert ZeroAddress();
        guardian = newGuardian;
        emit GuardianUpdated(newGuardian);
    }

    function setAtomist(address newAtomist) external onlyOwner {
        if (newAtomist == address(0)) revert ZeroAddress();
        atomist = newAtomist;
        emit AtomistUpdated(newAtomist);
    }

    function setAlpha(address newAlpha) external onlyOwner {
        if (newAlpha == address(0)) revert ZeroAddress();
        alpha = newAlpha;
        emit AlphaUpdated(newAlpha);
    }

    function setFuseManager(address newFuseManager) external onlyOwner {
        if (newFuseManager == address(0)) revert ZeroAddress();
        fuseManager = newFuseManager;
        emit FuseManagerUpdated(newFuseManager);
    }

    function setTesseractRewardsManager(address newTesseractRewardsManager) external onlyOwner {
        if (newTesseractRewardsManager == address(0)) revert ZeroAddress();
        tesseractRewardsManager = newTesseractRewardsManager;
        emit TesseractRewardsManagerUpdated(newTesseractRewardsManager);
    }

    function setMinInitialDeposit(uint256 newMinInitialDeposit) external onlyOwner {
        minInitialDeposit = newMinInitialDeposit;
        emit MinInitialDepositUpdated(newMinInitialDeposit);
    }

    function setFees(uint256 newManagementFee, uint256 newPerformanceFee) external onlyOwner {
        if (newManagementFee > MAX_MANAGEMENT_FEE) revert ManagementFeeTooHigh();
        if (newPerformanceFee > MAX_PERFORMANCE_FEE) revert PerformanceFeeTooHigh();
        managementFee = newManagementFee;
        performanceFee = newPerformanceFee;
        emit FeesUpdated(newManagementFee, newPerformanceFee);
    }

    function setFeeRecipient(address newFeeRecipient) external onlyOwner {
        if (newFeeRecipient == address(0)) revert ZeroAddress();
        feeRecipient = newFeeRecipient;
        emit FeeRecipientUpdated(newFeeRecipient);
    }

    function setDaoFeePackageIndex(uint256 newDaoFeePackageIndex) external onlyOwner {
        daoFeePackageIndex = newDaoFeePackageIndex;
        emit DaoFeePackageIndexUpdated(newDaoFeePackageIndex);
    }

    // === Deploy ===

    /// @notice Deploys a new vault with pre-configured parameters (requires prior ERC20 approve)
    /// @param initialDeposit Amount of underlying token to deposit into the new vault
    /// @param maxManagementFee Maximum acceptable management fee (reverts if current fee exceeds this)
    /// @param maxPerformanceFee Maximum acceptable performance fee (reverts if current fee exceeds this)
    /// @return fusionInstance The created FusionInstance with all contract addresses
    function deployVault(uint256 initialDeposit, uint256 maxManagementFee, uint256 maxPerformanceFee)
        external
        onlyWhitelisted
        returns (FusionFactoryLogicLib.FusionInstance memory fusionInstance)
    {
        return _deployVault(initialDeposit, maxManagementFee, maxPerformanceFee);
    }

    /// @notice Deploys a new vault using EIP-2612 permit for token approval
    /// @param initialDeposit Amount of underlying token to deposit into the new vault
    /// @param maxManagementFee Maximum acceptable management fee (reverts if current fee exceeds this)
    /// @param maxPerformanceFee Maximum acceptable performance fee (reverts if current fee exceeds this)
    /// @param deadline Permit signature deadline
    /// @param v Permit signature v component
    /// @param r Permit signature r component
    /// @param s Permit signature s component
    /// @return fusionInstance The created FusionInstance with all contract addresses
    function deployVaultWithPermit(
        uint256 initialDeposit,
        uint256 maxManagementFee,
        uint256 maxPerformanceFee,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external onlyWhitelisted returns (FusionFactoryLogicLib.FusionInstance memory fusionInstance) {
        try IERC20Permit(UNDERLYING_TOKEN).permit(msg.sender, address(this), initialDeposit, deadline, v, r, s) {}
        catch {
            if (IERC20(UNDERLYING_TOKEN).allowance(msg.sender, address(this)) < initialDeposit) {
                revert PermitFailed();
            }
        }
        return _deployVault(initialDeposit, maxManagementFee, maxPerformanceFee);
    }

    function _deployVault(uint256 initialDeposit, uint256 maxManagementFee, uint256 maxPerformanceFee)
        internal
        returns (FusionFactoryLogicLib.FusionInstance memory fusionInstance)
    {
        if (initialDeposit < minInitialDeposit) revert InsufficientInitialDeposit();
        if (managementFee > maxManagementFee) revert ManagementFeeExceedsMax(managementFee, maxManagementFee);
        if (performanceFee > maxPerformanceFee) revert PerformanceFeeExceedsMax(performanceFee, maxPerformanceFee);

        // Step 1: Clone vault with deployer as temporary owner
        fusionInstance = FUSION_FACTORY.clone(
            assetName,
            assetSymbol,
            UNDERLYING_TOKEN,
            REDEMPTION_DELAY_IN_SECONDS,
            address(this),
            daoFeePackageIndex
        );

        IporFusionAccessManager accessManager = IporFusionAccessManager(fusionInstance.accessManager);

        // Step 2: Grant OWNER-managed roles
        accessManager.grantRole(Roles.GUARDIAN_ROLE, guardian, 0);

        // Step 3: Grant temporary ATOMIST_ROLE to deployer
        accessManager.grantRole(Roles.ATOMIST_ROLE, address(this), 0);

        // Step 4: Grant ATOMIST-managed roles
        accessManager.grantRole(Roles.ALPHA_ROLE, alpha, 0);
        accessManager.grantRole(Roles.WHITELIST_ROLE, msg.sender, 0);
        accessManager.grantRole(Roles.WHITELIST_ROLE, address(this), 0);
        accessManager.grantRole(Roles.FUSE_MANAGER_ROLE, atomist, 0);
        accessManager.grantRole(Roles.FUSE_MANAGER_ROLE, fuseManager, 0);
        accessManager.grantRole(Roles.CONFIG_INSTANT_WITHDRAWAL_FUSES_ROLE, alpha, 0);
        accessManager.grantRole(Roles.CLAIM_REWARDS_ROLE, tesseractRewardsManager, 0);
        accessManager.grantRole(Roles.TRANSFER_REWARDS_ROLE, tesseractRewardsManager, 0);
        accessManager.grantRole(Roles.UPDATE_REWARDS_BALANCE_ROLE, tesseractRewardsManager, 0);

        // Step 5: Grant real ATOMIST_ROLE
        accessManager.grantRole(Roles.ATOMIST_ROLE, atomist, 0);

        // Step 6: Configure fees (skip if both are 0)
        uint256 perfFee = performanceFee;
        uint256 mgmtFee = managementFee;
        if (perfFee > 0 || mgmtFee > 0) {
            address feeManagerAddr = fusionInstance.feeManager;
            RecipientFee[] memory fees = new RecipientFee[](1);

            if (perfFee > 0) {
                fees[0] = RecipientFee({recipient: feeRecipient, feeValue: perfFee});
                FeeManager(feeManagerAddr).updatePerformanceFee(fees);
            }

            if (mgmtFee > 0) {
                fees[0] = RecipientFee({recipient: feeRecipient, feeValue: mgmtFee});
                FeeManager(feeManagerAddr).updateManagementFee(fees);
            }
        }

        // Step 7: Emit before initial deposit so indexers see VaultDeployed first
        emit VaultDeployed(
            fusionInstance.plasmaVault,
            msg.sender,
            fusionInstance.accessManager,
            fusionInstance.feeManager,
            fusionInstance.rewardsManager,
            fusionInstance.withdrawManager,
            fusionInstance.contextManager,
            fusionInstance.priceManager
        );

        // Step 8: Initial deposit (deployer still has roles at this point)
        if (initialDeposit > 0) {
            IERC20(UNDERLYING_TOKEN).safeTransferFrom(msg.sender, address(this), initialDeposit);
            IERC20(UNDERLYING_TOKEN).forceApprove(fusionInstance.plasmaVault, initialDeposit);
            PlasmaVault(fusionInstance.plasmaVault).deposit(initialDeposit, msg.sender);
        }

        // Step 9: Grant OWNER_ROLE to the configured vault owner
        accessManager.grantRole(Roles.OWNER_ROLE, vaultOwner, 0);

        // Step 10: Renounce all roles from deployer
        accessManager.renounceRole(Roles.WHITELIST_ROLE, address(this));
        accessManager.renounceRole(Roles.ATOMIST_ROLE, address(this));
        accessManager.renounceRole(Roles.OWNER_ROLE, address(this));

        return fusionInstance;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 10000000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/=node_modules/@openzeppelin/",
    "@ipor-fusion/=lib/ipor-fusion/contracts/",
    "@uniswap/v3-core/=node_modules/@uniswap/v3-core/",
    "@ethereum-vault-connector/=node_modules/ethereum-vault-connector/",
    "@pendle/core-v2/=node_modules/@pendle/core-v2/",
    "forge-std/=lib/forge-std/src/",
    "@chainlink/=node_modules/@chainlink/",
    "@eth-optimism/=node_modules/@eth-optimism/",
    "@morpho-org/=node_modules/@morpho-org/",
    "@prb/test/=lib/ipor-fusion/lib/foundry-random/lib/prb-test/src/",
    "@scroll-tech/=node_modules/@scroll-tech/",
    "CramBit/=lib/ipor-fusion/lib/foundry-random/lib/CramBit/",
    "base64-sol/=node_modules/base64-sol/",
    "crambit/=lib/ipor-fusion/lib/foundry-random/lib/CramBit/src/",
    "ds-test/=lib/ipor-fusion/lib/forge-std/lib/ds-test/src/",
    "eth-gas-reporter/=lib/ipor-fusion/node_modules/eth-gas-reporter/",
    "ethereum-vault-connector/=node_modules/ethereum-vault-connector/",
    "foundry-random/=lib/ipor-fusion/lib/foundry-random/src/",
    "ipor-fusion/=lib/ipor-fusion/contracts/",
    "openzeppelin/=node_modules/ethereum-vault-connector/lib/openzeppelin-contracts/contracts/",
    "prb-test/=lib/ipor-fusion/lib/foundry-random/lib/prb-test/src/",
    "solidity-bytes-utils/=lib/ipor-fusion/lib/foundry-random/lib/solidity-bytes-utils/contracts/",
    "@uniswap/v4-core/=lib/ipor-fusion/node_modules/@uniswap/v4-core/",
    "src/=lib/ipor-fusion/lib/foundry-random/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.