Перейти к содержимому
Проверенный контрактТочноеBSD-3-Clause-Clear

NuvaHomeDepositBatcherConfidential

Адрес0x2a900740f691d9fdfd00cd414dc15eb2e0e622c1
Баланс

0 ETH

 

Транзакций

11

 

Компилятор

solc 0.8.28

 

Тот же код

Только этот контракт

 

Подробности

Компилятор
solc 0.8.28+commit.7893614a
Язык
solidity
Оптимизация
Да, 800 прогонов
Версия EVM
cancun
Лицензия
BSD-3-Clause-Clear
Совпадение
Точноекод создания: да, код в сети: да
Проверен на Sourcify
Создан в блоке
26 407 041
Транзакция создания
0x20702a89b3…4c2b8c1e7b

47 файлов

Исходный код большой: показывается один файл. Выберите файл в списке.

src/batcher/adapters/NuvaHomeDepositBatcherConfidential.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 {IRemoteVault} from "../../../vendor/nuva/IRemoteVault.sol";
import {VaultBatcherConfidential} from "../VaultBatcherConfidential.sol";
import {IAsyncBatcher} from "../interfaces/IAsyncBatcher.sol";

/// @custom:security-contact [email protected]
/// @notice Deposits USDC through Nuva's RemoteVault and settles once Nuva's keeper mints the nvHOME.
/// @dev The deposit is tracked by its RemoteVault id, derived before the call and checked after it. Only the keeper's
/// mint clears that record, so a cleared record completes the batch. The USDC leaves in the request, and RemoteVault
/// has no deposit refund: from then on neither pause nor the deadline can cancel the batch, which waits for the mint.
/// Dispatch pins the destination for the batch's deposit, so a later update applies from the next batch. The owner
/// therefore cannot rescue a dispatched batch: if Nuva stops accepting the pinned destination, the deposit retries
/// until the deadline refunds the batch.
contract NuvaHomeDepositBatcherConfidential is VaultBatcherConfidential, IAsyncBatcher {
    error InvalidDepositDestination(address destination);
    error RequestIdMismatch(bytes32 requestId);

    event DepositDestinationSet(address destination);

    struct Request {
        uint256 batchId;
        bytes32 requestId;
        uint256 assets;
    }

    Request private _request;
    address private _destination;
    // The in-flight batch's destination, pinned at its dispatch.
    address private _batchDestination;

    constructor(
        IERC7984ERC20Wrapper fromToken_,
        IERC7984ERC20Wrapper toToken_,
        IRemoteVault remoteVault_,
        address owner_,
        uint256 minBatchAge_,
        uint256 callbackDeadline_,
        address destination_
    )
        VaultBatcherConfidential(
            fromToken_,
            toToken_,
            IERC4626(address(remoteVault_)),
            owner_,
            minBatchAge_,
            callbackDeadline_
        )
    {
        address asset = remoteVault_.assetToken();
        address fromUnderlying = fromToken_.underlying();
        require(fromUnderlying == asset, RouteAssetMismatch(fromUnderlying, asset));
        address share = remoteVault_.shareToken();
        address toUnderlying = toToken_.underlying();
        require(toUnderlying == share, RouteShareMismatch(toUnderlying, share));
        _setDepositDestination(destination_);
    }

    function routeDescription() public pure override returns (string memory) {
        return "Deposit USDC through Nuva's RemoteVault and settle once Nuva mints the nvHOME.";
    }

    function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
        return interfaceId == type(IAsyncBatcher).interfaceId || super.supportsInterface(interfaceId);
    }

    /// @dev The pending amount drops to zero once Nuva's mint clears the deposit record.
    function asyncRequest(uint256 batchId) external view returns (AsyncRequest memory request) {
        if (_requestPlaced(batchId)) {
            return AsyncRequest(uint256(_request.requestId), _minted() ? 0 : _request.assets, 0);
        }
    }

    /// @notice The whitelisted RemoteVault destination later deposits forward their USDC to.
    function depositDestination() external view returns (address) {
        return _destination;
    }

    /// @dev Only callable by the owner. A dispatched batch keeps the destination pinned at its dispatch.
    /// @param destination Whitelisted RemoteVault receiver for later batches' USDC.
    function setDepositDestination(address destination) external onlyOwner {
        _setDepositDestination(destination);
    }

    function dispatchBatch() public override {
        super.dispatchBatch();
        _batchDestination = _destination;
    }

    function _requestPlaced(uint256 batchId) private view returns (bool) {
        return batchId != 0 && _request.batchId == batchId && batchState(batchId) == BatchState.Dispatched;
    }

    /// @dev Once the USDC has left, only the mint ends the batch: pause and the deadline no longer apply.
    function _executeRoute(uint256 batchId, uint256 amount) internal override returns (ExecuteOutcome) {
        if (_request.batchId == batchId) return _minted() ? ExecuteOutcome.Complete : ExecuteOutcome.Partial;
        return super._executeRoute(batchId, amount);
    }

    /// @dev Places the deposit. A refused deposit keeps the USDC and retries until the deadline, as the synchronous
    /// deposit batcher does.
    function _executeVaultRoute(uint256 batchId, uint256 amount) internal override returns (ExecuteOutcome) {
        IERC20 asset = IERC20(fromToken().underlying());
        IRemoteVault remoteVault = _remoteVault();
        uint256 assets = amount * fromToken().rate();
        bytes32 requestId = _nextRequestId(remoteVault);
        SafeERC20.forceApprove(asset, address(remoteVault), assets);
        try remoteVault.deposit(assets, _batchDestination) {
            (address user, uint256 recorded) = remoteVault.pendingDeposits(requestId);
            require(user == address(this) && recorded == assets, RequestIdMismatch(requestId));
            _request = Request(batchId, requestId, assets);
            emit AsyncRequested(batchId, uint256(requestId), assets);
        } catch (bytes memory reason) {
            SafeERC20.forceApprove(asset, address(remoteVault), 0);
            emit AsyncRequestFailed(batchId, reason);
        }
        return ExecuteOutcome.Partial;
    }

    /// @dev The keeper's mint deletes the record and mints a nonzero amount to this contract in one call, so a
    /// cleared record means the shares are here. Shares sent before it cannot complete the batch.
    function _minted() private view returns (bool) {
        (address user,) = _remoteVault().pendingDeposits(_request.requestId);
        return user == address(0);
    }

    /// @dev The id RemoteVault gives this contract's next request in this block.
    function _nextRequestId(IRemoteVault remoteVault) private view returns (bytes32) {
        return keccak256(
            abi.encodePacked(
                block.timestamp, block.chainid, address(remoteVault), address(this), remoteVault.depositNonce() + 1
            )
        );
    }

    function _setDepositDestination(address destination) private {
        require(_remoteVault().isDestination(destination), InvalidDepositDestination(destination));
        _destination = destination;
        emit DepositDestinationSet(destination);
    }

    function _remoteVault() private view returns (IRemoteVault) {
        return IRemoteVault(address(_vault()));
    }
}
Настройки компилятораПоказать
{
  "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/"
  ]
}

Исходный код и метаданные: Sourcify.

Исходный код принадлежит авторам контракта.