Skip to content
Verified contractPartialGPL-2.0-or-later

WhitelistReceiveSharesGate

Address0x1c70beb383fbd620f54f769c9c44f9bc385d2ae2
Balance

0 ETH

 

Transactions

4

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 100,000 runs
EVM version
cancun
Via IR
yes
License
GPL-2.0-or-later
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,335,321
Creation transaction
0xf384dd0744…8c9fcfd386

src/periphery/WhitelistReceiveSharesGate.sol

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity 0.8.28;

import {IWhitelistReceiveSharesGate, SET_IS_WHITELISTED_TYPEHASH} from "./interfaces/IWhitelistReceiveSharesGate.sol";
import {DOMAIN_TYPEHASH} from "../libraries/ConstantsLib.sol";

/// @dev Using this gate allows to restrict who can own shares of a vault.
/// @dev As with any receive shares gates, a whitelisted account could own shares to let other accounts access the
/// vault's payoff.
/// @dev CRITICAL NOTE: if a depositor transfers their shares (typically to deposit them on a DeFi protocol), they might
/// not be able to get their shares back (typically to withdraw them) if they get un-whitelisted afterwards.
/// @dev No-ops are allowed.
/// @dev Zero checks are not systematically performed.
contract WhitelistReceiveSharesGate is IWhitelistReceiveSharesGate {
    address public roleSetter;
    mapping(address account => bool) public isWhitelister;
    mapping(address whitelister => mapping(address account => uint256)) public nonces;
    mapping(address account => bool) public isWhitelisted;

    constructor(address _roleSetter) {
        roleSetter = _roleSetter;
        emit Constructor(_roleSetter);
    }

    /// @dev Useful for EOAs to batch privileged calls.
    /// @dev Does not return anything, because accounts who would use the return data would be contracts, which can do
    /// the multicall themselves.
    function multicall(bytes[] calldata data) external {
        for (uint256 i = 0; i < data.length; i++) {
            (bool success, bytes memory returnData) = address(this).delegatecall(data[i]);
            if (!success) {
                assembly ("memory-safe") {
                    revert(add(32, returnData), mload(returnData))
                }
            }
        }
    }

    function canReceiveShares(address account) external view returns (bool) {
        return isWhitelisted[account];
    }

    function setRoleSetter(address newRoleSetter) external {
        require(msg.sender == roleSetter, NotRoleSetter());
        roleSetter = newRoleSetter;
        emit SetRoleSetter(newRoleSetter);
    }

    function setIsWhitelister(address account, bool newIsWhitelister) external {
        require(msg.sender == roleSetter, NotRoleSetter());
        isWhitelister[account] = newIsWhitelister;
        emit SetIsWhitelister(account, newIsWhitelister);
    }

    function setIsWhitelisted(address account, bool newIsWhitelisted) external {
        require(isWhitelister[msg.sender], NotWhitelister());
        isWhitelisted[account] = newIsWhitelisted;
        emit SetIsWhitelisted(msg.sender, account, newIsWhitelisted);
    }

    /// @dev Signature malleability is not explicitly prevented but it is not a problem thanks to the nonce.
    /// @dev Allows to batch setIsWhitelisted with the deposit, without requiring a transaction from the whitelister.
    function setIsWhitelistedWithSig(
        address whitelister,
        address account,
        bool newIsWhitelisted,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external {
        require(deadline >= block.timestamp, DeadlineExpired());
        bytes32 hashStruct = keccak256(
            abi.encode(
                SET_IS_WHITELISTED_TYPEHASH,
                whitelister,
                account,
                newIsWhitelisted,
                nonces[whitelister][account]++,
                deadline
            )
        );
        bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), hashStruct));
        address recovered = ecrecover(digest, v, r, s);
        require(recovered != address(0) && recovered == whitelister && isWhitelister[recovered], InvalidSigner());
        isWhitelisted[account] = newIsWhitelisted;
        emit SetIsWhitelistedWithSig(recovered, account, newIsWhitelisted);
    }

    /// forge-lint: disable-next-item(mixed-case-function)
    function DOMAIN_SEPARATOR() public view returns (bytes32) {
        return keccak256(abi.encode(DOMAIN_TYPEHASH, block.chainid, address(this)));
    }
}

src/interfaces/IGate.sol

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2025 Morpho Association
pragma solidity >=0.5.0;

interface IReceiveSharesGate {
    function canReceiveShares(address account) external view returns (bool);
}

interface ISendSharesGate {
    function canSendShares(address account) external view returns (bool);
}

interface IReceiveAssetsGate {
    function canReceiveAssets(address account) external view returns (bool);
}

interface ISendAssetsGate {
    function canSendAssets(address account) external view returns (bool);
}

src/libraries/ConstantsLib.sol

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2025 Morpho Association
pragma solidity ^0.8.0;

uint256 constant WAD = 1e18;
bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(uint256 chainId,address verifyingContract)");
bytes32 constant PERMIT_TYPEHASH =
    keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
uint256 constant MAX_MAX_RATE = 200e16 / uint256(365 days); // 200% APR
uint256 constant MAX_PERFORMANCE_FEE = 0.5e18; // 50%
uint256 constant MAX_MANAGEMENT_FEE = 0.05e18 / uint256(365 days); // 5%
uint256 constant MAX_FORCE_DEALLOCATE_PENALTY = 0.02e18; // 2%

src/periphery/interfaces/IWhitelistReceiveSharesGate.sol

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity >=0.5.0;

import {IReceiveSharesGate} from "../../interfaces/IGate.sol";

bytes32 constant SET_IS_WHITELISTED_TYPEHASH = keccak256(
    "SetIsWhitelisted(address whitelister,address account,bool newIsWhitelisted,uint256 nonce,uint256 deadline)"
);

interface IWhitelistReceiveSharesGate is IReceiveSharesGate {
    /* EVENTS */

    event Constructor(address indexed roleSetter);
    event SetRoleSetter(address indexed newRoleSetter);
    event SetIsWhitelister(address indexed account, bool newIsWhitelister);
    event SetIsWhitelisted(address indexed whitelister, address indexed account, bool newIsWhitelisted);
    event SetIsWhitelistedWithSig(address indexed whitelister, address indexed account, bool newIsWhitelisted);

    /* ERRORS */

    error NotRoleSetter();
    error NotWhitelister();
    error DeadlineExpired();
    error InvalidSigner();

    /* FUNCTIONS */

    function roleSetter() external view returns (address);
    function isWhitelister(address account) external view returns (bool);
    function nonces(address whitelister, address account) external view returns (uint256);
    function isWhitelisted(address account) external view returns (bool);
    function setRoleSetter(address newRoleSetter) external;
    function setIsWhitelister(address account, bool newIsWhitelister) external;
    function setIsWhitelisted(address account, bool newIsWhitelisted) external;
    function setIsWhitelistedWithSig(
        address whitelister,
        address account,
        bool newIsWhitelisted,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function multicall(bytes[] calldata data) external;
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 100000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "ds-test/=lib/morpho-blue-irm/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/metamorpho/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/morpho-blue/lib/halmos-cheatcodes/src/",
    "metamorpho-v1.1/=lib/metamorpho-v1.1/",
    "metamorpho/=lib/metamorpho/",
    "morpho-blue-irm/=lib/morpho-blue-irm/",
    "morpho-blue/=lib/morpho-blue/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "solmate/=lib/morpho-blue-irm/lib/solmate/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.