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/DepositVaultFactory.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20Upgradeable} from "@openzeppelin-upgradeable/contracts/interfaces/IERC20Upgradeable.sol";
import {DepositVault} from "./DepositVault.sol";
/**
* @title DepositVaultFactory
* @dev Factory contract for deploying and managing multiple DepositVault instances
* @notice This contract allows for easy deployment of new vaults with standardized configurations
*/
contract DepositVaultFactory is Ownable {
/// @notice The implementation contract address for all vault proxies
address public immutable vaultImplementation;
/// @notice Array of all vault addresses
address[] public vaults;
/// @notice Default configuration for new vaults
struct DefaultConfig {
uint256 minLockDuration; // Default: 1 day
uint256 maxLockDuration; // Default: 365 days
address defaultMultisig; // Default multisig (can be overridden)
}
DefaultConfig public defaultConfig;
// Events
event VaultDeployed(
address indexed vault,
address indexed asset,
string name,
string symbol,
uint256 lockDuration,
address indexed deployer
);
event VaultStatusUpdated(address indexed vault, bool isActive);
event DefaultConfigUpdated(uint256 minLockDuration, uint256 maxLockDuration, address defaultMultisig);
event ImplementationUpdated(address indexed oldImplementation, address indexed newImplementation);
// Errors
error InvalidAsset();
error InvalidLockDuration();
error InvalidMultisigWallet();
error VaultNotFound();
error VaultAlreadyExists();
error UnauthorizedVault();
constructor(address _vaultImplementation, address _defaultMultisig) {
if (_vaultImplementation == address(0)) revert InvalidAsset();
vaultImplementation = _vaultImplementation;
// Set default configuration
defaultConfig =
DefaultConfig({minLockDuration: 1 days, maxLockDuration: 365 days, defaultMultisig: _defaultMultisig});
}
/**
* @notice Deploy a new DepositVault with standard configuration
* @param asset The underlying ERC20 asset
* @param name The name of the vault token
* @param symbol The symbol of the vault token
* @param lockDuration The lock duration for deposits
* @param multisigWallet The multisig wallet (use address(0) for default)
* @return vault The address of the deployed vault
*/
function deployVault(
address asset,
string memory name,
string memory symbol,
uint256 lockDuration,
address multisigWallet
) external onlyOwner returns (address vault) {
return _deployVaultInternal(asset, name, symbol, lockDuration, multisigWallet);
}
/**
* @notice Internal function to deploy a new DepositVault
*/
function _deployVaultInternal(
address asset,
string memory name,
string memory symbol,
uint256 lockDuration,
address multisigWallet
) internal returns (address vault) {
if (asset == address(0)) revert InvalidAsset();
if (lockDuration == 0) revert InvalidLockDuration();
// Use default multisig if not provided
address _multisig = multisigWallet == address(0) ? defaultConfig.defaultMultisig : multisigWallet;
if (_multisig == address(0)) revert InvalidMultisigWallet();
// Create initialization data
bytes memory initData = abi.encodeWithSelector(
DepositVault.initialize.selector,
IERC20Upgradeable(asset),
name,
symbol,
lockDuration,
_multisig,
defaultConfig.minLockDuration,
defaultConfig.maxLockDuration
);
// Deploy proxy
vault = address(new ERC1967Proxy(vaultImplementation, initData));
vaults.push(vault);
emit VaultDeployed(vault, asset, name, symbol, lockDuration, msg.sender);
}
/**
* @notice Get all deployed vaults
* @return Array of all vault addresses
*/
function getAllVaults() external view returns (address[] memory) {
return vaults;
}
/**
* @notice Get total number of deployed vaults
* @return The number of deployed vaults
*/
function getVaultCount() external view returns (uint256) {
return vaults.length;
}
/**
* @notice Update default configuration (only owner)
* @param minLockDuration New minimum lock duration
* @param maxLockDuration New maximum lock duration
* @param defaultMultisig New default multisig address
*/
function updateDefaultConfig(uint256 minLockDuration, uint256 maxLockDuration, address defaultMultisig)
external
onlyOwner
{
if (minLockDuration == 0 || maxLockDuration == 0 || minLockDuration >= maxLockDuration) {
revert InvalidLockDuration();
}
defaultConfig.minLockDuration = minLockDuration;
defaultConfig.maxLockDuration = maxLockDuration;
defaultConfig.defaultMultisig = defaultMultisig;
emit DefaultConfigUpdated(minLockDuration, maxLockDuration, defaultMultisig);
}
}
"
},
"lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/ERC1967/ERC1967Proxy.sol)
pragma solidity ^0.8.0;
import "../Proxy.sol";
import "./ERC1967Upgrade.sol";
/**
* @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
* implementation address that can be changed. This address is stored in storage in the location specified by
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
* implementation behind the proxy.
*/
contract ERC1967Proxy is Proxy, ERC1967Upgrade {
/**
* @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
*
* If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
* function call, and allows initializing the storage of the proxy like a Solidity constructor.
*/
constructor(address _logic, bytes memory _data) payable {
_upgradeToAndCall(_logic, _data, false);
}
/**
* @dev Returns the current implementation address.
*/
function _implementation() internal view virtual override returns (address impl) {
return ERC1967Upgrade._getImplementation();
}
}
"
},
"lib/openzeppelin-contracts/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC20Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20Upgradeable.sol";
"
},
"src/DepositVault.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {ERC4626Upgradeable} from "@openzeppelin-upgradeable/contracts/token/ERC20/extensions/ERC4626Upgradeable.sol";
import {SafeERC20Upgradeable} from "@openzeppelin-upgradeable/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol";
import {IERC20Upgradeable} from "@openzeppelin-upgradeable/contracts/interfaces/IERC20Upgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import {Initializable} from "@openzeppelin-upgradeable/contracts/proxy/utils/Initializable.sol";
import {PausableUpgradeable} from "@openzeppelin-upgradeable/contracts/security/PausableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
contract DepositVault is Initializable, ERC4626Upgradeable, OwnableUpgradeable, PausableUpgradeable, UUPSUpgradeable {
using SafeERC20Upgradeable for IERC20Upgradeable;
uint256 public lockDuration;
uint256 public minLockDuration;
uint256 public maxLockDuration;
mapping(address => uint256) public userLockTimestamp;
mapping(address => uint256) public userDepositAmount;
bool public emergencyUnlockEnabled;
// Deposit limits and access control
uint256 public maxDepositPerWallet;
uint256 public vaultDepositCap;
uint256 public minDepositAmount;
mapping(address => bool) public denyList;
mapping(address => bool) public whitelist;
bool public whitelistEnabled;
uint256 public minFirstDepositAmount;
// Multisig wallet for asset transfers
address public multisigWallet;
uint256[50] private __gap;
event Deposited(address indexed user, uint256 assets, uint256 shares, uint256 unlockTime);
event LockDurationUpdated(uint256 oldDuration, uint256 newDuration);
event EmergencyUnlockToggled(bool enabled);
event MaxDepositPerWalletUpdated(uint256 oldLimit, uint256 newLimit);
event VaultDepositCapUpdated(uint256 oldCap, uint256 newCap);
event DenyListUpdated(address indexed user, bool denied);
event WhitelistUpdated(address indexed user, bool whitelisted);
event WhitelistEnabledUpdated(bool enabled);
event MinDepositAmountUpdated(uint256 oldAmount, uint256 newAmount);
event MinFirstDepositAmountUpdated(uint256 oldAmount, uint256 newAmount);
event MultisigWalletUpdated(address indexed oldWallet, address indexed newWallet);
event AssetsTransferredToMultisig(uint256 amount, address indexed multisig);
error WithdrawalLocked(address user, uint256 unlockTime);
error ZeroAmount();
error NotAuthorized();
error ExceedsMaxDepositPerWallet(uint256 currentDeposit, uint256 attemptedDeposit, uint256 maxAllowed);
error ExceedsVaultDepositCap(uint256 currentTotal, uint256 attemptedDeposit, uint256 maxCap);
error UserOnDenyList(address user);
error UserNotWhitelisted(address user);
error BelowMinimumDeposit(uint256 attemptedDeposit, uint256 minRequired);
error BelowMinimumFirstDeposit(uint256 attemptedDeposit, uint256 minRequired);
error MultisigWalletNotSet();
error InvalidMultisigWallet();
error InvalidLockDuration();
error LockDurationOutOfBounds(uint256 provided, uint256 min, uint256 max);
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(
IERC20Upgradeable asset_,
string memory name_,
string memory symbol_,
uint256 lockDuration_,
address multisigWallet_,
uint256 minLockDuration_,
uint256 maxLockDuration_
) public initializer {
if (lockDuration_ == 0) {
revert InvalidLockDuration();
}
if (multisigWallet_ == address(0)) {
revert InvalidMultisigWallet();
}
if (minLockDuration_ == 0 || maxLockDuration_ == 0 || minLockDuration_ >= maxLockDuration_) {
revert InvalidLockDuration();
}
if (lockDuration_ < minLockDuration_ || lockDuration_ > maxLockDuration_) {
revert LockDurationOutOfBounds(lockDuration_, minLockDuration_, maxLockDuration_);
}
__ERC4626_init(asset_);
__ERC20_init(name_, symbol_);
__Ownable_init();
__Pausable_init();
__UUPSUpgradeable_init();
lockDuration = lockDuration_;
minLockDuration = minLockDuration_;
maxLockDuration = maxLockDuration_;
// Initialize deposit settings - defaults to no limits
maxDepositPerWallet = type(uint256).max;
vaultDepositCap = type(uint256).max;
minDepositAmount = 0; // No minimum by default
minFirstDepositAmount = 1e18; // Default to 1 token for inflation protection
multisigWallet = multisigWallet_;
}
function deposit(uint256 assets, address receiver) public virtual override whenNotPaused returns (uint256 shares) {
if (assets == 0) revert ZeroAmount();
// This check is critical to prevent the re-locking attack.
if (receiver != msg.sender) revert NotAuthorized();
_checkDepositAllowed(receiver, assets);
shares = super.deposit(assets, receiver);
_handleDepositLock(receiver, assets, shares);
return shares;
}
function mint(uint256 shares, address receiver) public virtual override whenNotPaused returns (uint256 assets) {
if (shares == 0) revert ZeroAmount();
// This check is critical to prevent the re-locking attack.
if (receiver != msg.sender) revert NotAuthorized();
assets = previewMint(shares);
_checkDepositAllowed(receiver, assets);
assets = super.mint(shares, receiver);
_handleDepositLock(receiver, assets, shares);
return assets;
}
function withdraw(uint256 assets, address receiver, address owner)
public
virtual
override
returns (uint256 shares)
{
if (!_canWithdraw(owner)) {
uint256 unlockTime = userLockTimestamp[owner] + lockDuration;
revert WithdrawalLocked(owner, unlockTime);
}
shares = super.withdraw(assets, receiver, owner);
if (userDepositAmount[owner] >= assets) {
userDepositAmount[owner] -= assets;
} else {
userDepositAmount[owner] = 0;
}
return shares;
}
function redeem(uint256 shares, address receiver, address owner) public virtual override returns (uint256 assets) {
if (!_canWithdraw(owner)) {
uint256 unlockTime = userLockTimestamp[owner] + lockDuration;
assets = previewRedeem(shares);
revert WithdrawalLocked(owner, unlockTime);
}
assets = super.redeem(shares, receiver, owner);
if (userDepositAmount[owner] >= assets) {
userDepositAmount[owner] -= assets;
} else {
userDepositAmount[owner] = 0;
}
return assets;
}
function _canWithdraw(address user) internal view returns (bool) {
if (emergencyUnlockEnabled) {
return true;
}
if (userLockTimestamp[user] == 0) {
return true;
}
return block.timestamp >= userLockTimestamp[user] + lockDuration;
}
function getUserUnlockTime(address user) external view returns (uint256) {
if (userLockTimestamp[user] == 0) {
return 0;
}
return userLockTimestamp[user] + lockDuration;
}
function canUserWithdraw(address user) external view returns (bool) {
return _canWithdraw(user);
}
function getRemainingLockTime(address user) external view returns (uint256) {
if (_canWithdraw(user)) {
return 0;
}
uint256 unlockTime = userLockTimestamp[user] + lockDuration;
return unlockTime - block.timestamp;
}
function setLockDuration(uint256 newLockDuration) external onlyOwner {
if (newLockDuration < minLockDuration || newLockDuration > maxLockDuration) {
revert LockDurationOutOfBounds(newLockDuration, minLockDuration, maxLockDuration);
}
uint256 oldDuration = lockDuration;
lockDuration = newLockDuration;
emit LockDurationUpdated(oldDuration, newLockDuration);
}
function toggleEmergencyUnlock() external onlyOwner {
emergencyUnlockEnabled = !emergencyUnlockEnabled;
emit EmergencyUnlockToggled(emergencyUnlockEnabled);
}
function setMaxDepositPerWallet(uint256 newMaxDeposit) external onlyOwner {
uint256 oldLimit = maxDepositPerWallet;
maxDepositPerWallet = newMaxDeposit;
emit MaxDepositPerWalletUpdated(oldLimit, newMaxDeposit);
}
function setVaultDepositCap(uint256 newDepositCap) external onlyOwner {
uint256 oldCap = vaultDepositCap;
vaultDepositCap = newDepositCap;
emit VaultDepositCapUpdated(oldCap, newDepositCap);
}
function updateDenyList(address user, bool denied) external onlyOwner {
denyList[user] = denied;
emit DenyListUpdated(user, denied);
}
function batchUpdateDenyList(address[] calldata users, bool denied) external onlyOwner {
for (uint256 i = 0; i < users.length; i++) {
denyList[users[i]] = denied;
emit DenyListUpdated(users[i], denied);
}
}
function updateWhitelist(address user, bool whitelisted) external onlyOwner {
whitelist[user] = whitelisted;
emit WhitelistUpdated(user, whitelisted);
}
function batchUpdateWhitelist(address[] calldata users, bool whitelisted) external onlyOwner {
for (uint256 i = 0; i < users.length; i++) {
whitelist[users[i]] = whitelisted;
emit WhitelistUpdated(users[i], whitelisted);
}
}
function setWhitelistEnabled(bool enabled) external onlyOwner {
whitelistEnabled = enabled;
emit WhitelistEnabledUpdated(enabled);
}
function setMinDepositAmount(uint256 newMinAmount) external onlyOwner {
uint256 oldAmount = minDepositAmount;
minDepositAmount = newMinAmount;
emit MinDepositAmountUpdated(oldAmount, newMinAmount);
}
function setMinFirstDepositAmount(uint256 newMinFirstAmount) external onlyOwner {
uint256 oldAmount = minFirstDepositAmount;
minFirstDepositAmount = newMinFirstAmount;
emit MinFirstDepositAmountUpdated(oldAmount, newMinFirstAmount);
}
function setMultisigWallet(address newMultisigWallet) external onlyOwner {
if (newMultisigWallet == address(0)) {
revert InvalidMultisigWallet();
}
address oldWallet = multisigWallet;
multisigWallet = newMultisigWallet;
emit MultisigWalletUpdated(oldWallet, newMultisigWallet);
}
function transferAssets(uint256 amount) external onlyOwner {
if (multisigWallet == address(0)) {
revert MultisigWalletNotSet();
}
if (amount == 0) {
revert ZeroAmount();
}
IERC20Upgradeable assetToken = IERC20Upgradeable(asset());
uint256 contractBalance = assetToken.balanceOf(address(this));
if (amount > contractBalance) {
amount = contractBalance;
}
assetToken.safeTransfer(multisigWallet, amount);
emit AssetsTransferredToMultisig(amount, multisigWallet);
}
function transferAllAssets() external onlyOwner {
if (multisigWallet == address(0)) {
revert MultisigWalletNotSet();
}
IERC20Upgradeable assetToken = IERC20Upgradeable(asset());
uint256 contractBalance = assetToken.balanceOf(address(this));
if (contractBalance == 0) {
revert ZeroAmount();
}
assetToken.safeTransfer(multisigWallet, contractBalance);
emit AssetsTransferredToMultisig(contractBalance, multisigWallet);
}
function _checkDepositAllowed(address receiver, uint256 assets) internal view {
// Check minimum deposit amount
if (assets < minDepositAmount) {
revert BelowMinimumDeposit(assets, minDepositAmount);
}
// Check minimum first deposit to prevent inflation attacks
if (totalSupply() == 0 && assets < minFirstDepositAmount) {
revert BelowMinimumFirstDeposit(assets, minFirstDepositAmount);
}
// Check whitelist first - if user is whitelisted, skip deny list check
// If whitelist is enabled and user is not whitelisted, they cannot deposit
if (whitelistEnabled) {
if (!whitelist[receiver]) {
revert UserNotWhitelisted(receiver);
}
} else {
// If no whitelist is active, check deny list
if (denyList[receiver]) {
revert UserOnDenyList(receiver);
}
}
// Check vault deposit cap
uint256 currentTotal = totalAssets();
if (currentTotal + assets > vaultDepositCap) {
revert ExceedsVaultDepositCap(currentTotal, assets, vaultDepositCap);
}
// Check per-wallet deposit limit
uint256 currentUserDeposit = userDepositAmount[receiver];
if (currentUserDeposit + assets > maxDepositPerWallet) {
revert ExceedsMaxDepositPerWallet(currentUserDeposit, assets, maxDepositPerWallet);
}
}
function pause() external onlyOwner {
_pause();
}
function unpause() external onlyOwner {
_unpause();
}
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
function _handleDepositLock(address receiver, uint256 assets, uint256 shares) internal {
// This is safe because caller functions check receiver == msg.sender
if (_canWithdraw(receiver)) {
userLockTimestamp[receiver] = block.timestamp;
}
userDepositAmount[receiver] += assets;
uint256 unlockTime = userLockTimestamp[receiver] == 0 ? 0 : userLockTimestamp[receiver] + lockDuration;
emit Deposited(receiver, assets, shares, unlockTime);
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
super._beforeTokenTransfer(from, to, amount);
if (from != address(0) && to != address(0)) {
if (!_canWithdraw(from)) {
uint256 unlockTime = userLockTimestamp[from] + lockDuration;
revert WithdrawalLocked(from, unlockTime);
}
// When transferring to a new address, inherit the sender's lock timestamp
// This ensures the lock period travels with the shares
if (userLockTimestamp[to] == 0 && userLockTimestamp[from] > 0) {
userLockTimestamp[to] = userLockTimestamp[from];
}
}
}
function maxWithdraw(address owner) public view virtual override returns (uint256) {
if (!_canWithdraw(owner)) {
return 0;
}
return super.maxWithdraw(owner);
}
function maxRedeem(address owner) public view virtual override returns (uint256) {
if (!_canWithdraw(owner)) {
return 0;
}
return super.maxRedeem(owner);
}
}
"
},
"lib/openzeppelin-contracts/contracts/proxy/Proxy.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overridden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}
"
},
"lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Upgrade.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeacon.sol";
import "../../interfaces/IERC1967.sol";
import "../../interfaces/draft-IERC1822.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*/
abstract contract ERC1967Upgrade is IERC1967 {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}
"
},
"lib/openzeppelin-contracts/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/IERC20Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @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 amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` 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 amount) external returns (bool);
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC4626Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/ERC4626.sol)
pragma solidity ^0.8.0;
import "../ERC20Upgradeable.sol";
import "../utils/SafeERC20Upgradeable.sol";
import "../../../interfaces/IERC4626Upgradeable.sol";
import "../../../utils/math/MathUpgradeable.sol";
import {Initializable} from "../../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in
* https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
*
* This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
* underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
* the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this
* contract and not the "assets" token which is an independent contract.
*
* [CAUTION]
* ====
* In empty (or nearly empty) ERC-4626 vaults, deposits are at high risk of being stolen through frontrunning
* with a "donation" to the vault that inflates the price of a share. This is variously known as a donation or inflation
* attack and is essentially a problem of slippage. Vault deployers can protect against this attack by making an initial
* deposit of a non-trivial amount of the asset, such that price manipulation becomes infeasible. Withdrawals may
* similarly be affected by slippage. Users can protect against this attack as well as unexpected slippage in general by
* verifying the amount received is as expected, using a wrapper that performs these checks such as
* https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router].
*
* Since v4.9, this implementation uses virtual assets and shares to mitigate that risk. The `_decimalsOffset()`
* corresponds to an offset in the decimal representation between the underlying asset's decimals and the vault
* decimals. This offset also determines the rate of virtual shares to virtual assets in the vault, which itself
* determines the initial exchange rate. While not fully preventing the attack, analysis shows that the default offset
* (0) makes it non-profitable, as a result of the value being captured by the virtual shares (out of the attacker's
* donation) matching the attacker's expected gains. With a larger offset, the attack becomes orders of magnitude more
* expensive than it is profitable. More details about the underlying math can be found
* xref:erc4626.adoc#inflation-attack[here].
*
* The drawback of this approach is that the virtual shares do capture (a very small) part of the value being accrued
* to the vault. Also, if the vault experiences losses, the users try to exit the vault, the virtual shares and assets
* will cause the first user to exit to experience reduced losses in detriment to the last users that will experience
* bigger losses. Developers willing to revert back to the pre-v4.9 behavior just need to override the
* `_convertToShares` and `_convertToAssets` functions.
*
* To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide].
* ====
*
* _Available since v4.7._
*/
abstract contract ERC4626Upgradeable is Initializable, ERC20Upgradeable, IERC4626Upgradeable {
using MathUpgradeable for uint256;
IERC20Upgradeable private _asset;
uint8 private _underlyingDecimals;
/**
* @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777).
*/
function __ERC4626_init(IERC20Upgradeable asset_) internal onlyInitializing {
__ERC4626_init_unchained(asset_);
}
function __ERC4626_init_unchained(IERC20Upgradeable asset_) internal onlyInitializing {
(bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
_underlyingDecimals = success ? assetDecimals : 18;
_asset = asset_;
}
/**
* @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
*/
function _tryGetAssetDecimals(IERC20Upgradeable asset_) private view returns (bool, uint8) {
(bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
abi.encodeWithSelector(IERC20MetadataUpgradeable.decimals.selector)
);
if (success && encodedDecimals.length >= 32) {
uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
if (returnedDecimals <= type(uint8).max) {
return (true, uint8(returnedDecimals));
}
}
return (false, 0);
}
/**
* @dev Decimals are computed by adding the decimal offset on top of the underlying asset's decimals. This
* "original" value is cached during construction of the vault contract. If this read operation fails (e.g., the
* asset has not been created yet), a default of 18 is used to represent the underlying asset's decimals.
*
* See {IERC20Metadata-decimals}.
*/
function decimals() public view virtual override(IERC20MetadataUpgradeable, ERC20Upgradeable) returns (uint8) {
return _underlyingDecimals + _decimalsOffset();
}
/** @dev See {IERC4626-asset}. */
function asset() public view virtual override returns (address) {
return address(_asset);
}
/** @dev See {IERC4626-totalAssets}. */
function totalAssets() public view virtual override returns (uint256) {
return _asset.balanceOf(address(this));
}
/** @dev See {IERC4626-convertToShares}. */
function convertToShares(uint256 assets) public view virtual override returns (uint256) {
return _convertToShares(assets, MathUpgradeable.Rounding.Down);
}
/** @dev See {IERC4626-convertToAssets}. */
function convertToAssets(uint256 shares) public view virtual override returns (uint256) {
return _convertToAssets(shares, MathUpgradeable.Rounding.Down);
}
/** @dev See {IERC4626-maxDeposit}. */
function maxDeposit(address) public view virtual override returns (uint256) {
return type(uint256).max;
}
/** @dev See {IERC4626-maxMint}. */
function maxMint(address) public view virtual override returns (uint256) {
return type(uint256).max;
}
/** @dev See {IERC4626-maxWithdraw}. */
function maxWithdraw(address owner) public view virtual override returns (uint256) {
return _convertToAssets(balanceOf(owner), MathUpgradeable.Rounding.Down);
}
/** @dev See {IERC4626-maxRedeem}. */
function maxRedeem(address owner) public view virtual override returns (uint256) {
return balanceOf(owner);
}
/** @dev See {IERC4626-previewDeposit}. */
function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
return _convertToShares(assets, MathUpgradeable.Rounding.Down);
}
/** @dev See {IERC4626-previewMint}. */
function previewMint(uint256 shares) public view virtual override returns (uint256) {
return _convertToAssets(shares, MathUpgradeable.Rounding.Up);
}
/** @dev See {IERC4626-previewWithdraw}. */
function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
return _convertToShares(assets, MathUpgradeable.Rounding.Up);
}
/** @dev See {IERC4626-previewRedeem}. */
function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
return _convertToAssets(shares, MathUpgradeable.Rounding.Down);
}
/** @dev See {IERC4626-deposit}. */
function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max");
uint256 shares = previewDeposit(assets);
_deposit(_msgSender(), receiver, assets, shares);
return shares;
}
/** @dev See {IERC4626-mint}.
*
* As opposed to {deposit}, minting is allowed even if the vault is in a state where the price of a share is zero.
* In this case, the shares will be minted without requiring any assets to be deposited.
*/
function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
require(shares <= maxMint(receiver), "ERC4626: mint more than max");
uint256 assets = previewMint(shares);
_deposit(_msgSender(), receiver, assets, shares);
return assets;
}
/** @dev See {IERC4626-withdraw}. */
function withdraw(uint256 assets, address receiver, address owner) public virtual override returns (uint256) {
require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
uint256 shares = previewWithdraw(assets);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return shares;
}
/** @dev See {IERC4626-redeem}. */
function redeem(uint256 shares, address receiver, address owner) public virtual override returns (uint256) {
require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");
uint256 assets = previewRedeem(shares);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return assets;
}
/**
* @dev Internal conversion function (from assets to shares) with support for rounding direction.
*/
function _convertToShares(uint256 assets, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256) {
return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
}
/**
* @dev Internal conversion function (from shares to assets) with support for rounding direction.
*/
function _convertToAssets(uint256 shares, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256) {
return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), rounding);
}
/**
* @dev Deposit/mint common workflow.
*/
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual {
// If _asset is ERC777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the
// `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
// calls the vault, which is assumed not malicious.
//
// Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
// assets are transferred and before the shares are minted, which is a valid state.
// slither-disable-next-line reentrancy-no-eth
SafeERC20Upgradeable.safeTransferFrom(_asset, caller, address(this), assets);
_mint(receiver, shares);
emit Deposit(caller, receiver, assets, shares);
}
/**
* @dev Withdraw/redeem common workflow.
*/
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256 shares
) internal virtual {
if (caller != owner) {
_spendAllowance(owner, caller, shares);
}
// If _asset is ERC777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
// `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
// calls the vault, which is assumed not malicious.
//
// Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
// shares are burned and after the assets are transferred, which is a valid state.
_burn(owner, shares);
SafeERC20Upgradeable.safeTransfer(_asset, receiver, assets);
emit Withdraw(caller, receiver, owner, assets, shares);
}
function _decimalsOffset() internal view virtual returns (uint8) {
return 0;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
import "../extensions/IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 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 SafeERC20Upgradeable {
using AddressUpgradeable for address;
/**
* @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(IERC20Upgradeable token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, 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(IERC20Upgradeable token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 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.
*/
function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @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.
*/
function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20PermitUpgradeable token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @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).
*/
function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @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 silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && AddressUpgradeable.isContract(address(token));
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent
Submitted on: 2025-09-29 10:41:38
Comments
Log in to comment.
No comments yet.