Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/depositors/DirectDepositor.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IMachine} from "@makina-core/interfaces/IMachine.sol";
import {IDirectDepositor} from "../interfaces/IDirectDepositor.sol";
import {IWhitelist} from "../interfaces/IWhitelist.sol";
import {MachinePeriphery} from "../utils/MachinePeriphery.sol";
import {Whitelist} from "../utils/Whitelist.sol";
contract DirectDepositor is MachinePeriphery, Whitelist, IDirectDepositor {
using SafeERC20 for IERC20;
constructor(address _registry) MachinePeriphery(_registry) {}
function initialize(bytes calldata data) external virtual override initializer {
(bool _whitelistStatus) = abi.decode(data, (bool));
__Whitelist_init(_whitelistStatus);
}
/// @inheritdoc IDirectDepositor
function deposit(uint256 assets, address receiver, uint256 minShares)
public
virtual
override
whitelistCheck
returns (uint256)
{
address _machine = machine();
address asset = IMachine(_machine).accountingToken();
IERC20(asset).safeTransferFrom(msg.sender, address(this), assets);
IERC20(asset).forceApprove(_machine, assets);
return IMachine(_machine).deposit(assets, receiver, minShares);
}
/// @inheritdoc IWhitelist
function setWhitelistStatus(bool enabled) external override onlyRiskManager {
_setWhitelistStatus(enabled);
}
/// @inheritdoc IWhitelist
function setWhitelistedUsers(address[] calldata users, bool whitelisted) external override onlyRiskManager {
_setWhitelistedUsers(users, whitelisted);
}
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
"
},
"lib/makina-core/src/interfaces/IMachine.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import {GuardianSignature} from "@wormhole/sdk/libraries/VaaLib.sol";
import {IMachineEndpoint} from "./IMachineEndpoint.sol";
interface IMachine is IMachineEndpoint {
event CaliberStaleThresholdChanged(uint256 indexed oldThreshold, uint256 indexed newThreshold);
event Deposit(address indexed sender, address indexed receiver, uint256 assets, uint256 shares);
event DepositorChanged(address indexed oldDepositor, address indexed newDepositor);
event FeeManagerChanged(address indexed oldFeeManager, address indexed newFeeManager);
event FeeMintCooldownChanged(uint256 indexed oldFeeMintCooldown, uint256 indexed newFeeMintCooldown);
event FeesMinted(uint256 shares);
event MaxFixedFeeAccrualRateChanged(uint256 indexed oldMaxAccrualRate, uint256 indexed newMaxAccrualRate);
event MaxPerfFeeAccrualRateChanged(uint256 indexed oldMaxAccrualRate, uint256 indexed newMaxAccrualRate);
event Redeem(address indexed owner, address indexed receiver, uint256 assets, uint256 shares);
event RedeemerChanged(address indexed oldRedeemer, address indexed newRedeemer);
event ShareLimitChanged(uint256 indexed oldShareLimit, uint256 indexed newShareLimit);
event SpokeBridgeAdapterSet(uint256 indexed chainId, uint256 indexed bridgeId, address indexed adapter);
event SpokeCaliberMailboxSet(uint256 indexed chainId, address indexed caliberMailbox);
event TotalAumUpdated(uint256 totalAum);
event TransferToCaliber(uint256 indexed chainId, address indexed token, uint256 amount);
/// @notice Initialization parameters.
/// @param initialDepositor The address of the initial depositor.
/// @param initialRedeemer The address of the initial redeemer.
/// @param initialFeeManager The address of the initial fee manager.
/// @param initialCaliberStaleThreshold The caliber accounting staleness threshold in seconds.
/// @param initialMaxFixedFeeAccrualRate The maximum fixed fee accrual rate per second, 1e18 = 100%.
/// @param initialMaxPerfFeeAccrualRate The maximum performance fee accrual rate per second, 1e18 = 100%.
/// @param initialFeeMintCooldown The minimum time to be elapsed between two fee minting events in seconds.
/// @param initialShareLimit The share cap value.
struct MachineInitParams {
address initialDepositor;
address initialRedeemer;
address initialFeeManager;
uint256 initialCaliberStaleThreshold;
uint256 initialMaxFixedFeeAccrualRate;
uint256 initialMaxPerfFeeAccrualRate;
uint256 initialFeeMintCooldown;
uint256 initialShareLimit;
}
/// @dev Internal state structure for a spoke caliber data.
/// @param mailbox The foreign address of the spoke caliber mailbox.
/// @param bridgeAdapters The mapping of bridge IDs to their corresponding adapters.
/// @param timestamp The timestamp of the last accounting.
/// @param netAum The net AUM of the spoke caliber.
/// @param positions The list of positions of the spoke caliber, each encoded as abi.encode(positionId, value).
/// @param baseTokens The list of base tokens of the spoke caliber, each encoded as abi.encode(token, value).
/// @param caliberBridgesIn The mapping of spoke caliber incoming bridge amounts.
/// @param caliberBridgesOut The mapping of spoke caliber outgoing bridge amounts.
/// @param machineBridgesIn The mapping of machine incoming bridge amounts.
/// @param machineBridgesOut The mapping of machine outgoing bridge amounts.
struct SpokeCaliberData {
address mailbox;
mapping(uint16 bridgeId => address adapter) bridgeAdapters;
uint256 timestamp;
uint256 netAum;
bytes[] positions;
bytes[] baseTokens;
EnumerableMap.AddressToUintMap caliberBridgesIn;
EnumerableMap.AddressToUintMap caliberBridgesOut;
EnumerableMap.AddressToUintMap machineBridgesIn;
EnumerableMap.AddressToUintMap machineBridgesOut;
}
/// @notice Initializer of the contract.
/// @param mParams The machine initialization parameters.
/// @param mgParams The makina governable initialization parameters.
/// @param _preDepositVault The address of the pre-deposit vault.
/// @param _shareToken The address of the share token.
/// @param _accountingToken The address of the accounting token.
/// @param _hubCaliber The address of the hub caliber.
function initialize(
MachineInitParams calldata mParams,
MakinaGovernableInitParams calldata mgParams,
address _preDepositVault,
address _shareToken,
address _accountingToken,
address _hubCaliber
) external;
/// @notice Address of the Wormhole Core Bridge.
function wormhole() external view returns (address);
/// @notice Address of the depositor.
function depositor() external view returns (address);
/// @notice Address of the redeemer.
function redeemer() external view returns (address);
/// @notice Address of the share token.
function shareToken() external view returns (address);
/// @notice Address of the accounting token.
function accountingToken() external view returns (address);
/// @notice Address of the hub caliber.
function hubCaliber() external view returns (address);
/// @notice Address of the fee manager.
function feeManager() external view returns (address);
/// @notice Maximum duration a caliber can remain unaccounted for before it is considered stale.
function caliberStaleThreshold() external view returns (uint256);
/// @notice Maximum fixed fee accrual rate per second used to compute an upper bound on shares to be minted, 1e18 = 100%.
function maxFixedFeeAccrualRate() external view returns (uint256);
/// @notice Maximum performance fee accrual rate per second used to compute an upper bound on shares to be minted, 1e18 = 100%.
function maxPerfFeeAccrualRate() external view returns (uint256);
/// @notice Minimum time to be elapsed between two fee minting events.
function feeMintCooldown() external view returns (uint256);
/// @notice Share token supply limit that cannot be exceeded by new deposits.
function shareLimit() external view returns (uint256);
/// @notice Maximum amount of shares that can currently be minted through asset deposits.
function maxMint() external view returns (uint256);
/// @notice Maximum amount of accounting tokens that can currently be withdrawn through share redemptions.
function maxWithdraw() external view returns (uint256);
/// @notice Last total machine AUM.
function lastTotalAum() external view returns (uint256);
/// @notice Timestamp of the last global machine accounting.
function lastGlobalAccountingTime() external view returns (uint256);
/// @notice Token => Is the token an idle token.
function isIdleToken(address token) external view returns (bool);
/// @notice Number of calibers associated with the machine.
function getSpokeCalibersLength() external view returns (uint256);
/// @notice Spoke caliber index => Spoke Chain ID.
function getSpokeChainId(uint256 idx) external view returns (uint256);
/// @notice Spoke Chain ID => Spoke caliber's AUM, individual positions values and accounting timestamp.
function getSpokeCaliberDetailedAum(uint256 chainId)
external
view
returns (uint256 aum, bytes[] memory positions, bytes[] memory baseTokens, uint256 timestamp);
/// @notice Spoke Chain ID => Spoke Caliber Mailbox Address.
function getSpokeCaliberMailbox(uint256 chainId) external view returns (address);
/// @notice Spoke Chain ID => Spoke Bridge ID => Spoke Bridge Adapter.
function getSpokeBridgeAdapter(uint256 chainId, uint16 bridgeId) external view returns (address);
/// @notice Returns the amount of shares that the Machine would exchange for the amount of accounting tokens provided.
/// @param assets The amount of accounting tokens.
/// @return shares The amount of shares.
function convertToShares(uint256 assets) external view returns (uint256);
/// @notice Returns the amount of accounting tokens that the Machine would exchange for the amount of shares provided.
/// @param shares The amount of shares.
/// @return assets The amount of accounting tokens.
function convertToAssets(uint256 shares) external view returns (uint256);
/// @notice Initiates a token transfers to the hub caliber.
/// @param token The address of the token to transfer.
/// @param amount The amount of token to transfer.
function transferToHubCaliber(address token, uint256 amount) external;
/// @notice Initiates a token transfers to the spoke caliber.
/// @param bridgeId The ID of the bridge to use for the transfer.
/// @param chainId The foreign EVM chain ID of the spoke caliber.
/// @param token The address of the token to transfer.
/// @param amount The amount of token to transfer.
/// @param minOutputAmount The minimum output amount expected from the transfer.
function transferToSpokeCaliber(
uint16 bridgeId,
uint256 chainId,
address token,
uint256 amount,
uint256 minOutputAmount
) external;
/// @notice Updates the total AUM of the machine.
/// @return totalAum The updated total AUM.
function updateTotalAum() external returns (uint256);
/// @notice Deposits accounting tokens into the machine and mints shares to the receiver.
/// @param assets The amount of accounting tokens to deposit.
/// @param receiver The receiver of minted shares.
/// @param minShares The minimum amount of shares to be minted.
/// @return shares The amount of shares minted.
function deposit(uint256 assets, address receiver, uint256 minShares) external returns (uint256);
/// @notice Redeems shares from the machine and transfers accounting tokens to the receiver.
/// @param shares The amount of shares to redeem.
/// @param receiver The receiver of the accounting tokens.
/// @param minAssets The minimum amount of accounting tokens to be transferred.
/// @return assets The amount of accounting tokens transferred.
function redeem(uint256 shares, address receiver, uint256 minAssets) external returns (uint256);
/// @notice Updates spoke caliber accounting data using Wormhole Cross-Chain Queries (CCQ).
/// @dev Validates the Wormhole CCQ response and guardian signatures before updating state.
/// @param response The Wormhole CCQ response payload containing the accounting data.
/// @param signatures The array of Wormhole guardians signatures attesting to the validity of the response.
function updateSpokeCaliberAccountingData(bytes memory response, GuardianSignature[] memory signatures) external;
/// @notice Registers a spoke caliber mailbox and related bridge adapters.
/// @param chainId The foreign EVM chain ID of the spoke caliber.
/// @param spokeCaliberMailbox The address of the spoke caliber mailbox.
/// @param bridges The list of bridges supported with the spoke caliber.
/// @param adapters The list of corresponding adapters for each bridge. Must be the same length as `bridges`.
function setSpokeCaliber(
uint256 chainId,
address spokeCaliberMailbox,
uint16[] calldata bridges,
address[] calldata adapters
) external;
/// @notice Registers a spoke bridge adapter.
/// @param chainId The foreign EVM chain ID of the adapter.
/// @param bridgeId The ID of the bridge.
/// @param adapter The foreign address of the bridge adapter.
function setSpokeBridgeAdapter(uint256 chainId, uint16 bridgeId, address adapter) external;
/// @notice Sets the depositor address.
/// @param newDepositor The address of the new depositor.
function setDepositor(address newDepositor) external;
/// @notice Sets the redeemer address.
/// @param newRedeemer The address of the new redeemer.
function setRedeemer(address newRedeemer) external;
/// @notice Sets the fee manager address.
/// @param newFeeManager The address of the new fee manager.
function setFeeManager(address newFeeManager) external;
/// @notice Sets the caliber accounting staleness threshold.
/// @param newCaliberStaleThreshold The new threshold in seconds.
function setCaliberStaleThreshold(uint256 newCaliberStaleThreshold) external;
/// @notice Sets the maximum fixed fee accrual rate.
/// @param newMaxAccrualRate The new maximum fixed fee accrual rate per second, 1e18 = 100%.
function setMaxFixedFeeAccrualRate(uint256 newMaxAccrualRate) external;
/// @notice Sets the maximum performance fee accrual rate.
/// @param newMaxAccrualRate The new maximum performance fee accrual rate per second, 1e18 = 100%.
function setMaxPerfFeeAccrualRate(uint256 newMaxAccrualRate) external;
/// @notice Sets the minimum time to be elapsed between two fee minting events.
/// @param newFeeMintCooldown The new cooldown in seconds.
function setFeeMintCooldown(uint256 newFeeMintCooldown) external;
/// @notice Sets the new share token supply limit that cannot be exceeded by new deposits.
/// @param newShareLimit The new share limit
function setShareLimit(uint256 newShareLimit) external;
}
"
},
"src/interfaces/IDirectDepositor.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {IMachinePeriphery} from "./IMachinePeriphery.sol";
interface IDirectDepositor is IMachinePeriphery {
function deposit(uint256 assets, address receiver, uint256 minShares) external returns (uint256);
}
"
},
"src/interfaces/IWhitelist.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IWhitelist {
event UserWhitelistingChanged(address indexed user, bool indexed whitelisted);
event WhitelistStatusChanged(bool indexed enabled);
/// @notice True if whitelist is enabled, false otherwise.
function isWhitelistEnabled() external view returns (bool);
/// @notice User => Whitelisting status.
function isWhitelistedUser(address user) external view returns (bool);
/// @notice Enables or disables the whitelist.
/// @param enabled True to enable the whitelist, false to disable.
function setWhitelistStatus(bool enabled) external;
/// @notice Whitelists or unwhitelists a list of users.
/// @param users The addresses of the users to update.
/// @param whitelisted True to whitelist the users, false to unwhitelist.
function setWhitelistedUsers(address[] calldata users, bool whitelisted) external;
}
"
},
"src/utils/MachinePeriphery.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IMakinaGovernable} from "@makina-core/interfaces/IMakinaGovernable.sol";
import {Errors, CoreErrors} from "../libraries/Errors.sol";
import {MakinaPeripheryContext} from "./MakinaPeripheryContext.sol";
import {IHubPeripheryRegistry} from "../interfaces/IHubPeripheryRegistry.sol";
import {IMachinePeriphery} from "../interfaces/IMachinePeriphery.sol";
abstract contract MachinePeriphery is Initializable, MakinaPeripheryContext, IMachinePeriphery {
/// @custom:storage-location erc7201:makina.storage.MachinePeriphery
struct MachinePeripheryStorage {
address _machine;
}
// keccak256(abi.encode(uint256(keccak256("makina.storage.MachinePeriphery")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant MachinePeripheryStorageLocation =
0xf8e170f38959918ab7e583dba012d1b8610047e073c7ca874900b1e0c133c900;
function _getMachinePeripheryStorage() internal pure returns (MachinePeripheryStorage storage $) {
assembly {
$.slot := MachinePeripheryStorageLocation
}
}
constructor(address _peripheryRegistry) MakinaPeripheryContext(_peripheryRegistry) {
_disableInitializers();
}
modifier onlyFactory() {
if (msg.sender != IHubPeripheryRegistry(peripheryRegistry).peripheryFactory()) {
revert CoreErrors.NotFactory();
}
_;
}
modifier onlyMechanic() {
if (msg.sender != IMakinaGovernable(machine()).mechanic()) {
revert CoreErrors.UnauthorizedCaller();
}
_;
}
modifier onlySecurityCouncil() {
if (msg.sender != IMakinaGovernable(machine()).securityCouncil()) {
revert CoreErrors.UnauthorizedCaller();
}
_;
}
modifier onlyRiskManager() {
if (msg.sender != IMakinaGovernable(machine()).riskManager()) {
revert CoreErrors.UnauthorizedCaller();
}
_;
}
modifier onlyRiskManagerTimelock() {
if (msg.sender != IMakinaGovernable(machine()).riskManagerTimelock()) {
revert CoreErrors.UnauthorizedCaller();
}
_;
}
/// @inheritdoc IMachinePeriphery
function machine() public view virtual returns (address) {
address _machine = _getMachinePeripheryStorage()._machine;
if (_machine == address(0)) {
revert Errors.MachineNotSet();
}
return _machine;
}
/// @inheritdoc IMachinePeriphery
function setMachine(address _machine) external onlyFactory {
_setMachine(_machine);
}
/// @dev Sets the machine this contract is associated with.
function _setMachine(address _machine) internal virtual {
MachinePeripheryStorage storage $ = _getMachinePeripheryStorage();
if ($._machine != address(0)) {
revert Errors.MachineAlreadySet();
}
if (_machine == address(0)) {
revert Errors.ZeroMachineAddress();
}
$._machine = _machine;
emit MachineSet(_machine);
}
}
"
},
"src/utils/Whitelist.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {CoreErrors} from "../libraries/Errors.sol";
import {IWhitelist} from "../interfaces/IWhitelist.sol";
abstract contract Whitelist is Initializable, IWhitelist {
/// @custom:storage-location erc7201:makina.storage.Whitelist
struct WhitelistStorage {
mapping(address user => bool isWhitelisted) _isWhitelistedUser;
bool _isWhitelistEnabled;
}
// keccak256(abi.encode(uint256(keccak256("makina.storage.Whitelist")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant WhitelistStorageLocation =
0x8ecd71e87c506d6932770ce52ba8e8dc85963cc6e1a5097e1b32e68fbabfcb00;
function _getWhitelistStorage() private pure returns (WhitelistStorage storage $) {
assembly {
$.slot := WhitelistStorageLocation
}
}
function __Whitelist_init(bool _initialWhitelistStatus) internal onlyInitializing {
WhitelistStorage storage $ = _getWhitelistStorage();
$._isWhitelistEnabled = _initialWhitelistStatus;
}
modifier whitelistCheck() {
WhitelistStorage storage $ = _getWhitelistStorage();
if ($._isWhitelistEnabled && !$._isWhitelistedUser[msg.sender]) {
revert CoreErrors.UnauthorizedCaller();
}
_;
}
/// @inheritdoc IWhitelist
function isWhitelistEnabled() public view returns (bool) {
return _getWhitelistStorage()._isWhitelistEnabled;
}
/// @inheritdoc IWhitelist
function isWhitelistedUser(address user) public view override returns (bool) {
return _getWhitelistStorage()._isWhitelistedUser[user];
}
/// @dev Internal function to set the whitelist status.
function _setWhitelistStatus(bool enabled) internal {
WhitelistStorage storage $ = _getWhitelistStorage();
if ($._isWhitelistEnabled != enabled) {
$._isWhitelistEnabled = enabled;
emit WhitelistStatusChanged(enabled);
}
}
/// @dev Internal function to set the whitelisted users.
function _setWhitelistedUsers(address[] calldata users, bool whitelisted) internal {
WhitelistStorage storage $ = _getWhitelistStorage();
uint256 len = users.length;
for (uint256 i = 0; i < len; ++i) {
if ($._isWhitelistedUser[users[i]] != whitelisted) {
$._isWhitelistedUser[users[i]] = whitelisted;
emit UserWhitelistingChanged(users[i], whitelisted);
}
}
}
}
"
},
"lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
"
},
"lib/openzeppelin-contracts/contracts/utils/structs/EnumerableMap.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/structs/EnumerableMap.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableMap.js.
pragma solidity ^0.8.20;
import {EnumerableSet} from "./EnumerableSet.sol";
/**
* @dev Library for managing an enumerable variant of Solidity's
* https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
* type.
*
* Maps have the following properties:
*
* - Entries are added, removed, and checked for existence in constant time
* (O(1)).
* - Entries are enumerated in O(n). No guarantees are made on the ordering.
* - Map can be cleared (all entries removed) in O(n).
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableMap for EnumerableMap.UintToAddressMap;
*
* // Declare a set state variable
* EnumerableMap.UintToAddressMap private myMap;
* }
* ```
*
* The following map types are supported:
*
* - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
* - `address -> uint256` (`AddressToUintMap`) since v4.6.0
* - `bytes32 -> bytes32` (`Bytes32ToBytes32Map`) since v4.6.0
* - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0
* - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0
* - `uint256 -> bytes32` (`UintToBytes32Map`) since v5.1.0
* - `address -> address` (`AddressToAddressMap`) since v5.1.0
* - `address -> bytes32` (`AddressToBytes32Map`) since v5.1.0
* - `bytes32 -> address` (`Bytes32ToAddressMap`) since v5.1.0
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableMap.
* ====
*/
library EnumerableMap {
using EnumerableSet for EnumerableSet.Bytes32Set;
// To implement this library for multiple types with as little code repetition as possible, we write it in
// terms of a generic Map type with bytes32 keys and values. The Map implementation uses private functions,
// and user-facing implementations such as `UintToAddressMap` are just wrappers around the underlying Map.
// This means that we can only create new EnumerableMaps for types that fit in bytes32.
/**
* @dev Query for a nonexistent map key.
*/
error EnumerableMapNonexistentKey(bytes32 key);
struct Bytes32ToBytes32Map {
// Storage of keys
EnumerableSet.Bytes32Set _keys;
mapping(bytes32 key => bytes32) _values;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(Bytes32ToBytes32Map storage map, bytes32 key, bytes32 value) internal returns (bool) {
map._values[key] = value;
return map._keys.add(key);
}
/**
* @dev Removes a key-value pair from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {
delete map._values[key];
return map._keys.remove(key);
}
/**
* @dev Removes all the entries from a map. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(Bytes32ToBytes32Map storage map) internal {
uint256 len = length(map);
for (uint256 i = 0; i < len; ++i) {
delete map._values[map._keys.at(i)];
}
map._keys.clear();
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {
return map._keys.contains(key);
}
/**
* @dev Returns the number of key-value pairs in the map. O(1).
*/
function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {
return map._keys.length();
}
/**
* @dev Returns the key-value pair stored at position `index` in the map. O(1).
*
* Note that there are no guarantees on the ordering of entries inside the
* array, and it may change when more entries are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32 key, bytes32 value) {
bytes32 atKey = map._keys.at(index);
return (atKey, map._values[atKey]);
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool exists, bytes32 value) {
bytes32 val = map._values[key];
if (val == bytes32(0)) {
return (contains(map, key), bytes32(0));
} else {
return (true, val);
}
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {
bytes32 value = map._values[key];
if (value == 0 && !contains(map, key)) {
revert EnumerableMapNonexistentKey(key);
}
return value;
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(Bytes32ToBytes32Map storage map) internal view returns (bytes32[] memory) {
return map._keys.values();
}
// UintToUintMap
struct UintToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToUintMap storage map, uint256 key, uint256 value) internal returns (bool) {
return set(map._inner, bytes32(key), bytes32(value));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToUintMap storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Removes all the entries from a map. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(UintToUintMap storage map) internal {
clear(map._inner);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToUintMap storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToUintMap storage map, uint256 index) internal view returns (uint256 key, uint256 value) {
(bytes32 atKey, bytes32 val) = at(map._inner, index);
return (uint256(atKey), uint256(val));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool exists, uint256 value) {
(bool success, bytes32 val) = tryGet(map._inner, bytes32(key));
return (success, uint256(val));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(key)));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(UintToUintMap storage map) internal view returns (uint256[] memory) {
bytes32[] memory store = keys(map._inner);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// UintToAddressMap
struct UintToAddressMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Removes all the entries from a map. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(UintToAddressMap storage map) internal {
clear(map._inner);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToAddressMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256 key, address value) {
(bytes32 atKey, bytes32 val) = at(map._inner, index);
return (uint256(atKey), address(uint160(uint256(val))));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool exists, address value) {
(bool success, bytes32 val) = tryGet(map._inner, bytes32(key));
return (success, address(uint160(uint256(val))));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
return address(uint160(uint256(get(map._inner, bytes32(key)))));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(UintToAddressMap storage map) internal view returns (uint256[] memory) {
bytes32[] memory store = keys(map._inner);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// UintToBytes32Map
struct UintToBytes32Map {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(UintToBytes32Map storage map, uint256 key, bytes32 value) internal returns (bool) {
return set(map._inner, bytes32(key), value);
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(UintToBytes32Map storage map, uint256 key) internal returns (bool) {
return remove(map._inner, bytes32(key));
}
/**
* @dev Removes all the entries from a map. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(UintToBytes32Map storage map) internal {
clear(map._inner);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(UintToBytes32Map storage map, uint256 key) internal view returns (bool) {
return contains(map._inner, bytes32(key));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(UintToBytes32Map storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintToBytes32Map storage map, uint256 index) internal view returns (uint256 key, bytes32 value) {
(bytes32 atKey, bytes32 val) = at(map._inner, index);
return (uint256(atKey), val);
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(UintToBytes32Map storage map, uint256 key) internal view returns (bool exists, bytes32 value) {
(bool success, bytes32 val) = tryGet(map._inner, bytes32(key));
return (success, val);
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(UintToBytes32Map storage map, uint256 key) internal view returns (bytes32) {
return get(map._inner, bytes32(key));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(UintToBytes32Map storage map) internal view returns (uint256[] memory) {
bytes32[] memory store = keys(map._inner);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// AddressToUintMap
struct AddressToUintMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(AddressToUintMap storage map, address key, uint256 value) internal returns (bool) {
return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(AddressToUintMap storage map, address key) internal returns (bool) {
return remove(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Removes all the entries from a map. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(AddressToUintMap storage map) internal {
clear(map._inner);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(AddressToUintMap storage map, address key) internal view returns (bool) {
return contains(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(AddressToUintMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressToUintMap storage map, uint256 index) internal view returns (address key, uint256 value) {
(bytes32 atKey, bytes32 val) = at(map._inner, index);
return (address(uint160(uint256(atKey))), uint256(val));
}
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/
function tryGet(AddressToUintMap storage map, address key) internal view returns (bool exists, uint256 value) {
(bool success, bytes32 val) = tryGet(map._inner, bytes32(uint256(uint160(key))));
return (success, uint256(val));
}
/**
* @dev Returns the value associated with `key`. O(1).
*
* Requirements:
*
* - `key` must be in the map.
*/
function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
return uint256(get(map._inner, bytes32(uint256(uint160(key)))));
}
/**
* @dev Return the an array containing all the keys
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function keys(AddressToUintMap storage map) internal view returns (address[] memory) {
bytes32[] memory store = keys(map._inner);
address[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// AddressToAddressMap
struct AddressToAddressMap {
Bytes32ToBytes32Map _inner;
}
/**
* @dev Adds a key-value pair to a map, or updates the value for an existing
* key. O(1).
*
* Returns true if the key was added to the map, that is if it was not
* already present.
*/
function set(AddressToAddressMap storage map, address key, address value) internal returns (bool) {
return set(map._inner, bytes32(uint256(uint160(key))), bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a map. O(1).
*
* Returns true if the key was removed from the map, that is if it was present.
*/
function remove(AddressToAddressMap storage map, address key) internal returns (bool) {
return remove(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Removes all the entries from a map. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(AddressToAddressMap storage map) internal {
clear(map._inner);
}
/**
* @dev Returns true if the key is in the map. O(1).
*/
function contains(AddressToAddressMap storage map, address key) internal view returns (bool) {
return contains(map._inner, bytes32(uint256(uint160(key))));
}
/**
* @dev Returns the number of elements in the map. O(1).
*/
function length(AddressToAddressMap storage map) internal view returns (uint256) {
return length(map._inner);
}
/**
* @dev Returns the element stored at position `index` in the map. O(1).
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly le
Submitted on: 2025-09-17 17:11:10
Comments
Log in to comment.
No comments yet.