Skip to content
Verified contractExactBSD-3-Clause-Clear

DepositVaultBatcherConfidential

Address0x2eb076e4e5b50e567bc10cbfeb7a319268437b14
Balance

0 ETH

 

Transactions

15

 

Compiler

solc 0.8.28

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 800 runs
EVM version
cancun
License
BSD-3-Clause-Clear
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,407,081
Creation transaction
0x051e88560d…c7fe082a7f
Main copy (most transactions)
0xc6c2682b…ed183595

45 files

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

src/batcher/DepositVaultBatcherConfidential.sol

// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity 0.8.28;

import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC7984ERC20Wrapper} from "@openzeppelin/confidential-contracts/interfaces/IERC7984ERC20Wrapper.sol";

import {VaultBatcherConfidential} from "./VaultBatcherConfidential.sol";

/// @title DepositVaultBatcherConfidential
/// @custom:security-contact [email protected]
/// @notice Confidential DeFi Gateway deposit batcher: aggregates ERC7984 confidential deposits
/// and routes only the decrypted aggregate into an ERC4626 vault.
/// @dev Individual user amounts remain FHE-encrypted; only the aggregate batch amount is decrypted.
/// Price protection is enforced by the vault.
///
/// ERC-7575 vaults, whose shares live in a separate `share()` token, take a `toToken` wrapping that token.
///
/// Operational risk: under a catastrophic target-vault drawdown (share-per-asset ratio inflates so
/// that a batch produces over about 1.8e7 wrapped shares per input unit, or > uint64.max wrapped shares),
/// the OZ base callback will revert on `SafeCast.toUint64` and the batch deadline-cancels. Users recover deposits via `quit`; no funds
/// are lost. Integrate only with reviewed synchronous vaults returning the configured output token.
///
/// Seed the vault with at least one whole unit of the token it takes before its route goes live (INVARIANTS P-41). A
/// donation to an empty vault can price its shares so high that every batch settles below `MIN_EXCHANGE_RATE`
/// and refunds at its deadline; later deposits keep that price. After the seed, that takes about 1e9 whole units.
contract DepositVaultBatcherConfidential is VaultBatcherConfidential {
    /// @dev Lowest exchange rate a deposit may settle at, in `exchangeRateDecimals`. Flooring the rate loses
    /// under 1 / rate of the output, so 1e3 bounds the unallocated share of a batch's wrapped output to 0.1%.
    uint256 internal constant MIN_EXCHANGE_RATE = 1e3;

    error ExchangeRateTooLow(uint256 batchId, uint256 exchangeRate);

    /// @notice Deploys a deposit batcher for a given confidential token pair and vault.
    /// @dev Uses shared constructor checks; the vault allowance is granted per deposit during settlement.
    /// `toToken_` must wrap the vault's share token, so settlement wraps what the vault mints.
    /// @param fromToken_ Confidential wrapper for vault asset (input token).
    /// @param toToken_ Confidential wrapper for vault shares (output token).
    /// @param vault_ ERC4626 vault that receives aggregated deposits.
    /// @param owner_ Owner authorized to update policy parameters.
    /// @param minBatchAge_ Minimum seconds a batch must age before dispatch.
    /// @param callbackDeadline_ Seconds after dispatch before batch is automatically cancelled.
    constructor(
        IERC7984ERC20Wrapper fromToken_,
        IERC7984ERC20Wrapper toToken_,
        IERC4626 vault_,
        address owner_,
        uint256 minBatchAge_,
        uint256 callbackDeadline_
    ) VaultBatcherConfidential(fromToken_, toToken_, vault_, owner_, minBatchAge_, callbackDeadline_) {
        address toUnderlying = toToken_.underlying();
        address share = _shareToken(vault_);
        require(toUnderlying == share, RouteShareMismatch(toUnderlying, share));
    }

    /// @notice Human-readable summary of the deposit route executed on callback settlement.
    function routeDescription() public pure virtual override returns (string memory) {
        return "Deposit underlying asset into ERC4626 vault and receive vault shares.";
    }

    /// @inheritdoc VaultBatcherConfidential
    /// @dev Converts wrapped units into underlying units, then deposits them into the vault.
    /// Zero amounts are handled by the base callback before this hook is reached.
    /// Returns `Partial` if the vault call reverts. Reverts, undoing the deposit, if it succeeds without increasing
    /// the output balance or below `MIN_EXCHANGE_RATE`, as a donation to a near-empty vault can cause. In every
    /// case the base layer retries until the callback deadline cancels the batch.
    function _executeVaultRoute(uint256 batchId, uint256 amount) internal virtual override returns (ExecuteOutcome) {
        uint256 underlyingAmount = amount * fromToken().rate();
        IERC20 output = IERC20(toToken().underlying());
        uint256 outputBefore = output.balanceOf(address(this));
        SafeERC20.forceApprove(IERC20(fromToken().underlying()), address(_vault()), underlyingAmount);
        try _vault().deposit(underlyingAmount, address(this)) {
            uint256 outputAfter = output.balanceOf(address(this));
            // Existing dust cannot stand in for a synchronous deposit's missing output.
            require(outputAfter > outputBefore, MissingVaultOutput(address(output)));
            // The rate the base callback will store for the whole balance it wraps.
            uint256 rate = outputAfter / toToken().rate() * 10 ** exchangeRateDecimals() / amount;
            require(rate >= MIN_EXCHANGE_RATE, ExchangeRateTooLow(batchId, rate));
            return ExecuteOutcome.Complete;
        } catch (bytes memory reason) {
            // Reset the vault allowance
            SafeERC20.forceApprove(IERC20(fromToken().underlying()), address(_vault()), 0);
            emit VaultRouteFailed(batchId, reason);
            return ExecuteOutcome.Partial;
        }
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 800,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@fhevm/solidity/=dependencies/@fhevm-solidity-0.13.0/",
    "@openzeppelin/confidential-contracts/=dependencies/@openzeppelin-confidential-contracts-0.5.3/contracts/",
    "@openzeppelin/community-contracts/=dependencies/@openzeppelin-community-contracts-0.0.1/contracts/",
    "dependencies/@openzeppelin-community-contracts-0.0.1/:@openzeppelin/contracts/=dependencies/community-oz-contracts-5.7.0/",
    "@openzeppelin/contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-5.1.0/",
    "@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.1.0/",
    "encrypted-types/=dependencies/@encrypted-types-0.0.4/",
    "forge-fhevm/=dependencies/forge-fhevm-0.1.0/src/",
    "forge-std/=dependencies/forge-std-1.14.0/src/",
    "metamorpho/=dependencies/metamorpho-v1.1-1.1.0/src/",
    "morpho-blue/=dependencies/morpho-blue-1.0.0/",
    "vault-v2/=dependencies/vault-v2-2026.08.13/src/",
    "vendor/nest/:@solmate/=vendor/nest/lib/solmate/src/",
    "vendor/nest/:contracts/=vendor/nest/contracts/",
    "@axelar-network/axelar-gmp-sdk-solidity/=dependencies/@openzeppelin-community-contracts-0.0.1/lib/axelar-gmp-sdk-solidity/",
    "@encrypted-types-0.0.4/=dependencies/@encrypted-types-0.0.4/",
    "@fhevm-solidity-0.13.0/=dependencies/@fhevm-solidity-0.13.0/",
    "@fhevm/host-contracts/=dependencies/forge-fhevm-0.1.0/src/fhevm-host/",
    "@openzeppelin-community-contracts-0.0.1/=dependencies/@openzeppelin-community-contracts-0.0.1/contracts/",
    "@openzeppelin-confidential-contracts-0.5.3/=dependencies/@openzeppelin-confidential-contracts-0.5.3/contracts/",
    "@openzeppelin-contracts-5.1.0/=dependencies/@openzeppelin-contracts-5.1.0/",
    "@openzeppelin-contracts-upgradeable-5.1.0/=dependencies/@openzeppelin-contracts-upgradeable-5.1.0/",
    "@zk-email/contracts/=dependencies/@openzeppelin-community-contracts-0.0.1/lib/zk-email-verify/packages/contracts/",
    "@zk-email/email-tx-builder/=dependencies/@openzeppelin-community-contracts-0.0.1/lib/email-tx-builder/packages/contracts/",
    "community-oz-contracts-5.7.0/=dependencies/community-oz-contracts-5.7.0/",
    "forge-fhevm-0.1.0/=dependencies/forge-fhevm-0.1.0/src/",
    "forge-std-1.14.0/=dependencies/forge-std-1.14.0/src/",
    "metamorpho-v1.1-1.1.0/=dependencies/metamorpho-v1.1-1.1.0/src/",
    "morpho-blue-1.0.0/=dependencies/morpho-blue-1.0.0/src/",
    "vault-v2-2026.08.13/=dependencies/vault-v2-2026.08.13/src/",
    "wormhole-solidity-sdk/=dependencies/@openzeppelin-community-contracts-0.0.1/lib/wormhole-solidity-sdk/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.