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/staking/ZKCPool.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
import "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
import "src/staking/BasePool.sol";
/**
* @title ZKC Liquidity staking pool
* @author ZKCPool
* @notice ZKC Liquidity Staking pool on top of BasePool
*/
contract ZKCPool is Initializable, BasePool {
constructor() {
_disableInitializers();
}
function initialize(
address _ownerAddr,
uint256 _apr,
uint256 _totalUnderlyingAsset,
address _dao,
address _nZKC,
address _zkcToken,
address _rateManager,
address _withdrawalVault,
bool _unstakeAllowed
) public initializer {
__BasePool_init(
_ownerAddr,
266400,
_apr,
_totalUnderlyingAsset,
_dao,
_nZKC,
_zkcToken,
_rateManager,
_withdrawalVault,
_unstakeAllowed
);
}
/**
* @notice Contract type id
*/
function typeId() public pure override returns (bytes32) {
return keccak256("ZKCPool");
}
/**
* @notice Contract version
*/
function version() public pure override returns (uint8) {
return 1;
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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]
* ```
* 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 the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Internal function that returns the initialized version. Returns `_initialized`
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Internal function that returns the initialized version. Returns `_initializing`
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
"
},
"src/staking/BasePool.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
import "src/modules/Version.sol";
import "src/modules/Dao.sol";
import "src/modules/WithdrawalRequest.sol";
import "src/modules/Rate.sol";
import "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
import "src/interfaces/ILsd.sol";
import {Errors} from "src/libraries/Errors.sol";
import "src/interfaces/IBasePool.sol";
import {IERC20} from "openzeppelin-contracts/interfaces/IERC20.sol";
import {SafeERC20} from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";
import "src/interfaces/IWithdrawalVault.sol";
/**
* @title Provide basic functions of liquidity staking
* @author NodeDAO
* @notice Provides
* - stake
* - unstake
* - requestWithdrawals
* - claimWithdrawals
* - convertToShares
* - convertToAssets
* - exchangeRate
* - setting: setValidatorManager & setRateManager & setWithdrawalDelayBlocks & pause & unpause
*/
abstract contract BasePool is Initializable, Version, Rate, WithdrawalRequest, Dao, IBasePool {
using SafeERC20 for IERC20;
/// Liquidity token, erc20 contract address
ILsd public nZKC;
IERC20 public zkcToken;
bool public unstakeAllowed;
// Staking strategy vault and total funds entering the strategy
address public strategyVault;
uint256 public strategyAmount;
IWithdrawalVault public withdrawalVault;
function __BasePool_init(
address _ownerAddr,
uint256 _withdrawalDelayBlocks,
uint256 _apr,
uint256 _totalUnderlyingAsset,
address _dao,
address _nZKC,
address _zkcToken,
address _rateManager,
address _withdrawalVault,
bool _unstakeAllowed
) public onlyInitializing {
__Version_init(_ownerAddr);
__Dao_init(_dao);
__Rate_init(_apr, _rateManager, _totalUnderlyingAsset);
__WithdrawalRequest_init(_withdrawalDelayBlocks);
nZKC = ILsd(_nZKC);
zkcToken = IERC20(_zkcToken);
withdrawalVault = IWithdrawalVault(_withdrawalVault);
if (_unstakeAllowed) {
unstakeAllowed = _unstakeAllowed;
}
}
function transferTokensIn(address from, address to, uint256 amount) internal {
zkcToken.safeTransferFrom(from, to, amount);
}
function transferTokensOut(address to, uint256 amount) internal {
zkcToken.safeTransfer(to, amount);
}
/**
* @notice Receive ZKC, mint stZKC according to the exchange rate
* @notice Allows the function to be rewritten to add functionality, such as adding a whitelist mechanism
*/
function stake(uint256 _stakeAmount) external virtual {
_stake(_stakeAmount);
}
function _stake(uint256 _stakeAmount) internal whenNotPaused {
address _staker = msg.sender;
if (_stakeAmount < 1 ether) {
// min 1 zkc
revert Errors.InvalidAmount();
}
transferTokensIn(_staker, address(this), _stakeAmount);
// Calculate the amount of lsdETH minted based on the exchange rate
uint256 _mintAmount = _convertToShares(_stakeAmount, nZKC.totalSupply());
_increaseAssets(_stakeAmount);
nZKC.whiteListMint(_mintAmount, _staker);
emit ZKCStake(_staker, _stakeAmount, _mintAmount);
}
/**
* @notice Burn stZKC and redeem ZKC according to the exchange rate
* @notice Available redemption funds include:
* current pool funds + funds that can be aggregated (including execution layer rewards and consensus layer rewards)
*/
function unstake(uint256 _unstakeAmount) external nonReentrant whenNotPaused {
if (!unstakeAllowed) {
revert Errors.UnstakeNotEnabled();
}
address _sender = msg.sender;
uint256 _amount = _convertToAssets(_unstakeAmount, nZKC.totalSupply());
_checkFunds(_amount, true);
_reduceAssets(_amount);
nZKC.whiteListBurn(_unstakeAmount, _sender);
transferTokensOut(_sender, _amount);
emit ZKCUnstake(_sender, _unstakeAmount, _amount);
}
/**
* @notice Create withdrawal request
* @param _unstakeAmount unstake stZKC amount
*/
function requestWithdrawals(uint256 _unstakeAmount) external whenNotPaused {
if (!unstakeAllowed) {
revert Errors.UnstakeNotEnabled();
}
uint256 _totalSupply = nZKC.totalSupply();
uint256 _amount = _convertToAssets(_unstakeAmount, _totalSupply);
(uint256 _instantAvailableAmount,) = getPoolAvailableAmount();
if (_instantAvailableAmount >= _amount) {
revert Errors.CanUnstake();
}
address _sender = msg.sender;
_reduceAssets(_amount);
nZKC.whiteListBurn(_unstakeAmount, _sender);
_requestWithdrawals(_sender, _unstakeAmount, _exchangeRate(_totalSupply), _amount);
}
/**
* @notice Claim withdrawal
* @param _receiver fund recipient
* @param _requestIds withdrawal request ids
*/
function claimWithdrawals(address _receiver, uint256[] memory _requestIds) external nonReentrant whenNotPaused {
uint256 _totalAmount = 0;
for (uint256 i = 0; i < _requestIds.length; ++i) {
uint256 _requestId = _requestIds[i];
if (!canClaimWithdrawal(_receiver, _requestId)) {
revert Errors.WithrawalsRequestCannotClaimed();
}
WithdrawalInfo memory _withdrawal = _getWithdrawal(_receiver, _requestId);
_claimWithdrawals(_receiver, _requestId);
_totalAmount += _withdrawal.claimAmount;
}
_checkFunds(_totalAmount, false);
transferTokensOut(_receiver, _totalAmount);
}
function _checkFunds(uint256 _requireAmount, bool _isCheckWithdrawalReuqest) internal {
uint256 _poolBalance = zkcToken.balanceOf(address(this));
if (_requireAmount > _poolBalance) {
uint256 _amount = 0;
uint256 _delayWithdrawalBalance = zkcToken.balanceOf(address(withdrawalVault));
if (_isCheckWithdrawalReuqest) {
uint256 _totalWithdrawalAmount = totalWithdrawalAmount;
if (_delayWithdrawalBalance > _totalWithdrawalAmount) {
_amount = _delayWithdrawalBalance - _totalWithdrawalAmount;
}
} else {
// _isCheckWithdrawalReuqest == false, called from claimWithdrawals
if (_delayWithdrawalBalance > _requireAmount) {
_amount = _requireAmount;
} else {
_amount = _delayWithdrawalBalance;
}
}
if (_amount != 0) {
withdrawalVault.transferToken(address(this), _amount);
_poolBalance = _poolBalance + _amount;
}
if (_poolBalance < _requireAmount) {
revert Errors.InsufficientFunds();
}
}
}
/**
* @notice ZKC to stZKC exchange rate
* @param _stakeAmount stake amount
*/
function convertToShares(uint256 _stakeAmount) external view returns (uint256) {
return _convertToShares(_stakeAmount, nZKC.totalSupply());
}
/**
* @notice stZKC to ZKC exchange rate
* @param _unstakeAmount unstake lsdETH amount
*/
function convertToAssets(uint256 _unstakeAmount) external view returns (uint256) {
return _convertToAssets(_unstakeAmount, nZKC.totalSupply());
}
/**
* @notice stZKC to ZKC exchange rate
*/
function exchangeRate() external view returns (uint256) {
return _exchangeRate(nZKC.totalSupply());
}
/**
* @notice Allows DAO to set up strategic funds to achieve flexible pledge strategies
*/
function setStrategyVault(address _strategyVault) public onlyDao {
if (_strategyVault == address(0)) {
revert Errors.InvalidAddr();
}
emit StrategyVaultChanged(strategyVault, _strategyVault);
strategyVault = _strategyVault;
}
/**
* @notice DAO deposit funds to the strategy vault
* @notice Excess funds cannot be used when there is a withdrawal request
*/
function strategyDeposit(uint256 _amount) public onlyDao nonReentrant {
if (strategyVault == address(0)) {
revert Errors.InvalidAddr();
}
_checkFunds(_amount, true);
// Record the total deposit funds
strategyAmount += _amount;
transferTokensOut(strategyVault, _amount);
emit StrategyDeposited(_amount, strategyAmount);
}
/**
* @notice DAO deposit funds to the strategy vault
* @notice The strategy vault returns funds
*/
function strategyReturn(uint256 _amount) public {
uint256 _returnAmount = _amount;
uint256 _totalWithdrawalAmount = totalWithdrawalAmount;
uint256 _delayWithdrawalBalance = zkcToken.balanceOf(address(withdrawalVault));
if (_delayWithdrawalBalance < _totalWithdrawalAmount) {
uint256 _toVaultAmount = 0;
uint256 _requireAmount = _totalWithdrawalAmount - _delayWithdrawalBalance;
if (_amount > _requireAmount) {
_toVaultAmount = _requireAmount;
} else {
_toVaultAmount = _amount;
}
_amount = _amount - _toVaultAmount;
transferTokensIn(msg.sender, address(withdrawalVault), _toVaultAmount);
}
if (_amount != 0) {
transferTokensIn(msg.sender, address(this), _amount);
}
// No overpayment allowed
strategyAmount -= _returnAmount;
emit StrategyReturn(_returnAmount);
}
/**
* @notice getPoolAvailableAmount return available amount
*/
function getPoolAvailableAmount()
public
view
returns (uint256 _instantAvailableAmount, uint256 _delayedAvailableAmount)
{
uint256 _poolAmount = zkcToken.balanceOf(address(this));
uint256 _vaultAmount = zkcToken.balanceOf(address(withdrawalVault));
uint256 _withdrawalAmount = totalWithdrawalAmount;
uint256 _availableAmount = _poolAmount + _vaultAmount;
if (_withdrawalAmount > _vaultAmount) {
return (_poolAmount, _availableAmount);
}
return (_availableAmount - _withdrawalAmount, _availableAmount);
}
/**
* @notice set DAO address
*/
function setDao(address _dao) public onlyOwner {
_setDao(_dao);
}
/**
* @notice update rate manager
* @param _rateManager new rate manager
*/
function setRateManager(address _rateManager) public onlyDao {
_setRateManager(_rateManager);
}
/**
* @notice update withdarawal delay block number
* @param _withdrawalDelayBlocks new delay block number
*/
function setWithdrawalDelayBlocks(uint256 _withdrawalDelayBlocks) public onlyDao {
_setWithdrawalDelayBlocks(_withdrawalDelayBlocks);
}
/**
* @notice update unstakeAllowed
* @param _unstakeAllowed unstake allowed
*/
function setUnstakeAllowed(bool _unstakeAllowed) public onlyDao {
emit UnstakeAllowedUpdated(unstakeAllowed, _unstakeAllowed);
unstakeAllowed = _unstakeAllowed;
}
/**
* @notice update withdrawalVault
*/
function setWithdrawalVault(address _withdrawalVault) public onlyDao {
emit WithdrawalVaultUpdated(address(withdrawalVault), _withdrawalVault);
withdrawalVault = IWithdrawalVault(_withdrawalVault);
}
/**
* @notice stop protocol
*/
function pause() external onlyDao {
_pause();
}
/**
* @notice start protocol
*/
function unpause() external onlyDao {
_unpause();
}
/**
* @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[50] private __gap;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
"
},
"src/modules/Version.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
import "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
import "openzeppelin-contracts-upgradeable/access/OwnableUpgradeable.sol";
import "openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "openzeppelin-contracts-upgradeable/security/PausableUpgradeable.sol";
import "openzeppelin-contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {Errors} from "src/libraries/Errors.sol";
import "src/interfaces/IVersion.sol";
/**
* @title Version management contract
* @author NodeDAO
* @notice Encapsulates the basic functions of
* UUPSUpgradeable contract,
* OwnableUpgradeable contract,
* PausableUpgradeable contract,
* and ReentrancyGuardUpgradeable contract.
*/
abstract contract Version is
Initializable,
UUPSUpgradeable,
OwnableUpgradeable,
PausableUpgradeable,
ReentrancyGuardUpgradeable
{
function __Version_init(address _ownerAddr) internal onlyInitializing {
_transferOwnership(_ownerAddr);
__UUPSUpgradeable_init();
__Pausable_init();
}
/**
* @notice When upgrading the contract,
* it is required that the typeid of the contract must be constant and version +1.
*/
function _authorizeUpgrade(address newImplementation) internal view override onlyOwner {
if (IVersion(newImplementation).typeId() != typeId()) {
revert Errors.InvalidtypeId();
}
if (IVersion(newImplementation).version() != version() + 1) {
revert Errors.InvalidVersion();
}
}
function implementation() external view returns (address) {
return _getImplementation();
}
/**
* @notice Contract type id
*/
function typeId() public pure virtual returns (bytes32);
/**
* @notice Contract version
*/
function version() public pure virtual returns (uint8);
/**
* @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[50] private __gap;
}
"
},
"src/modules/Dao.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
import {Errors} from "src/libraries/Errors.sol";
import "src/interfaces/IDao.sol";
import "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @title dao permission contract
* @author NodeDAO
* @notice This is an abstract contract, although there are no unimplemented functions.
* This contract is used in other contracts as a basic contract for dao's authority management.
*/
abstract contract Dao is Initializable, IDao {
address public dao;
modifier onlyDao() {
_onlyDao();
_;
}
function _onlyDao() internal view {
if (msg.sender != dao) revert Errors.PermissionDenied();
}
function __Dao_init(address _dao) internal onlyInitializing {
dao = _dao;
}
function _setDao(address _dao) internal {
emit DaoChanged(dao, _dao);
dao = _dao;
}
/**
* @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[50] private __gap;
}
"
},
"src/modules/WithdrawalRequest.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
import "src/libraries/Errors.sol";
import "src/interfaces/IWithdrawalRequest.sol";
import "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @title Withdrawal request contract
* @author NodeDAO
* @notice Provides basic functions for withdrawal orders.
* Used for asynchronous withdrawal requests in liquidity staking pools.
*/
abstract contract WithdrawalRequest is Initializable, IWithdrawalRequest {
struct WithdrawalInfo {
uint96 withdrawalHeight;
uint96 withdrawalExchange;
uint64 isClaim;
uint128 withdrawalAmount;
uint128 claimAmount;
}
uint256 public withdrawalDelayBlocks;
mapping(address => WithdrawalInfo[]) internal withdrawalQueue;
uint256 public totalWithdrawalAmount;
function __WithdrawalRequest_init(uint256 _withdrawalDelayBlocks) internal onlyInitializing {
withdrawalDelayBlocks = _withdrawalDelayBlocks;
}
/**
* @notice Query all withdrawals of the recipient
* @param _receiver fund recipient
*/
function getUserWithdrawals(address _receiver) public view returns (WithdrawalInfo[] memory) {
return withdrawalQueue[_receiver];
}
function _getWithdrawal(address _receiver, uint256 _requestId) internal view returns (WithdrawalInfo memory) {
return withdrawalQueue[_receiver][_requestId];
}
/**
* @notice Check if the withdrawal can be claimed
* @param _receiver fund recipient
* @param _requestId withdrawal request id
*/
function canClaimWithdrawal(address _receiver, uint256 _requestId) public view returns (bool) {
WithdrawalInfo[] memory _userWithdrawals = withdrawalQueue[_receiver];
if (_requestId >= _userWithdrawals.length) {
revert Errors.InvalidLength();
}
if (block.number < _userWithdrawals[_requestId].withdrawalHeight + withdrawalDelayBlocks) {
return false;
}
return true;
}
/**
* @notice Create withdrawal request
* @param _receiver fund recipient
* @param _withdrawalAmount withdrawal amount
*/
function _requestWithdrawals(
address _receiver,
uint256 _withdrawalAmount,
uint256 _withdrawalExchange,
uint256 _claimAmount
) internal {
uint256 _blockNumber = block.number;
withdrawalQueue[_receiver].push(
WithdrawalInfo({
withdrawalHeight: uint96(_blockNumber),
withdrawalExchange: uint96(_withdrawalExchange),
withdrawalAmount: uint128(_withdrawalAmount),
claimAmount: uint128(_claimAmount),
isClaim: 0
})
);
totalWithdrawalAmount += _claimAmount;
emit WithdrawalsRequest(_receiver, _withdrawalAmount, _blockNumber);
}
/**
* @notice Claim withdrawal
* @param _receiver fund recipient
* @param _requestId withdrawal request id
*/
function _claimWithdrawals(address _receiver, uint256 _requestId) internal {
WithdrawalInfo memory _userWithdrawal = withdrawalQueue[_receiver][_requestId];
if (_userWithdrawal.withdrawalAmount == 0 || _userWithdrawal.isClaim != 0) {
revert Errors.InvalidRequestId();
}
withdrawalQueue[_receiver][_requestId] = WithdrawalInfo({
withdrawalHeight: _userWithdrawal.withdrawalHeight,
withdrawalExchange: _userWithdrawal.withdrawalExchange,
withdrawalAmount: _userWithdrawal.withdrawalAmount,
claimAmount: _userWithdrawal.claimAmount,
isClaim: 1
});
totalWithdrawalAmount -= _userWithdrawal.claimAmount;
emit WithdrawalsClaimed(_receiver, _requestId, _userWithdrawal.claimAmount);
}
/**
* @notice update withdarawal delay block number
* @param _withdrawalDelayBlocks new delay block number
*/
function _setWithdrawalDelayBlocks(uint256 _withdrawalDelayBlocks) internal {
emit WithdrawalDelayChanged(withdrawalDelayBlocks, _withdrawalDelayBlocks);
withdrawalDelayBlocks = _withdrawalDelayBlocks;
}
/**
* @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[50] private __gap;
}
"
},
"src/modules/Rate.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
import "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
import {Errors} from "src/libraries/Errors.sol";
import "src/interfaces/IRate.sol";
/**
* @title This is yield management contract
* @author NodeDAO
* @notice This is a revenue management contract with compound interest.
* It steadily increases totalUnderlyingAsset according to the set apr.
* @notice The totalUnderlyingAsset will grow with the block, and every time the block is increased,
* the totalUnderlyingAsset will be recalculated.
* But the final state update occurs when assets join and exit or when the administrator updates the APR.
*/
abstract contract Rate is Initializable, IRate {
address public rateManager;
uint256 public totalUnderlyingAsset;
uint256 public currentApr;
uint256 public rewardsUpdateBlock;
uint256 public constant UPDATE_BLOCK_LIMIT = 7200;
uint256 public constant BLOCK_NUMBER_PER_YEAR = 7200 * 360;
uint256 public constant MAX_APR = 100000; // max apr is 1000%
uint256 public constant APR_PERCENT = 10000;
modifier onlyRateManager() {
_onlyRateManager();
_;
}
function _onlyRateManager() internal view {
if (msg.sender != rateManager) revert Errors.PermissionDenied();
}
function __Rate_init(uint256 _apr, address _rateManager, uint256 _totalUnderlyingAsset) internal onlyInitializing {
if (_apr > MAX_APR) {
revert Errors.InvalidApr();
}
currentApr = _apr;
rateManager = _rateManager;
rewardsUpdateBlock = block.number;
if (_totalUnderlyingAsset != 0) {
totalUnderlyingAsset = _totalUnderlyingAsset;
}
}
/**
* @notice totalAsset = totalUnderlyingAsset + settleAsset
*/
function totalAssets() public view returns (uint256) {
(uint256 _totalUnderlyingAsset, uint256 _estimatedRewards,) = _unsettleAssets();
if (_estimatedRewards != 0) {
return _totalUnderlyingAsset + _estimatedRewards;
}
return _totalUnderlyingAsset;
}
/**
* @notice zkc to stzkc exchange rate
* @param _assets zkc amount
* @param _totalShares stzkc totalSupply
*/
function _convertToShares(uint256 _assets, uint256 _totalShares) internal view returns (uint256) {
uint256 _totalAssets = totalAssets();
if (_totalShares == 0 || _totalAssets == 0) {
return _assets;
}
return _assets * _totalShares / _totalAssets;
}
/**
* @notice stzkc to zkc exchange rate
* @param _shares stzkc amount
* @param _totalShares stzkc totalSupply
*/
function _convertToAssets(uint256 _shares, uint256 _totalShares) internal view returns (uint256 _assets) {
uint256 _totalAssets = totalAssets();
if (_totalShares == 0) {
return _shares;
}
return _shares * _totalAssets / _totalShares;
}
/**
* @notice stzkc to zkc exchange rate
* @param _totalShares stzkc totalSupply
*/
function _exchangeRate(uint256 _totalShares) internal view returns (uint256) {
return _convertToAssets(1 ether, _totalShares);
}
/**
* @notice Calculate the unsettle assets from the last settlement block to the current block based on apr
*/
function _unsettleAssets()
internal
view
returns (uint256 _totalUnderlyingAsset, uint256 _unsettleRewards, uint256 _blockNumber)
{
_totalUnderlyingAsset = totalUnderlyingAsset;
_blockNumber = block.number;
uint256 _rewardsUpdateBlock = rewardsUpdateBlock;
if (_rewardsUpdateBlock == _blockNumber) {
return (_totalUnderlyingAsset, 0, _blockNumber);
}
// _unsettleRewards = totalUnderlyingAsset * apr / APR_PERCENT * blockNumber / BLOCK_NUMBER_PER_YEAR
return (
_totalUnderlyingAsset,
totalUnderlyingAsset * currentApr * (_blockNumber - _rewardsUpdateBlock) / APR_PERCENT
/ BLOCK_NUMBER_PER_YEAR,
_blockNumber
);
}
/**
* @notice increase assets only occurs when the user stake
* @param _amount stake amount
*/
function _increaseAssets(uint256 _amount) internal {
(uint256 _totalUnderlyingAsset, uint256 _estimatedRewards, uint256 _blockNumber) = _unsettleAssets();
rewardsUpdateBlock = _blockNumber;
if (_estimatedRewards != 0) {
totalUnderlyingAsset = _totalUnderlyingAsset + _estimatedRewards + _amount;
} else {
totalUnderlyingAsset = _totalUnderlyingAsset + _amount;
}
emit AssetsUpdated(_totalUnderlyingAsset, _estimatedRewards, _blockNumber);
}
/**
* @notice reduce assets only occurs when the user unstake
* @param _amount unstake amount
*/
function _reduceAssets(uint256 _amount) internal {
(uint256 _totalUnderlyingAsset, uint256 _estimatedRewards, uint256 _blockNumber) = _unsettleAssets();
rewardsUpdateBlock = _blockNumber;
if (_estimatedRewards != 0) {
totalUnderlyingAsset = _totalUnderlyingAsset + _estimatedRewards - _amount;
} else {
totalUnderlyingAsset = _totalUnderlyingAsset - _amount;
}
emit AssetsUpdated(_totalUnderlyingAsset, _estimatedRewards, _blockNumber);
}
/**
* @notice The rate administrator updates apr. Update totalUnderlyingAsset before apr update.
* @param _apr new apr
*/
function updateApr(uint256 _apr) public onlyRateManager {
if (_apr > MAX_APR) {
revert Errors.InvalidApr();
}
if (block.number < rewardsUpdateBlock + UPDATE_BLOCK_LIMIT) {
revert Errors.UpdateTimelocked();
}
(uint256 _totalUnderlyingAsset, uint256 _estimatedRewards, uint256 _blockNumber) = _unsettleAssets();
rewardsUpdateBlock = _blockNumber;
if (_estimatedRewards != 0) {
totalUnderlyingAsset = _totalUnderlyingAsset + _estimatedRewards;
}
emit AssetsUpdated(_totalUnderlyingAsset, _estimatedRewards, _blockNumber);
emit AprUpdated(currentApr, _apr);
currentApr = _apr;
}
/**
* @notice update rate manager
* @param _rateManager new rate manager
*/
function _setRateManager(address _rateManager) internal {
emit RateManagerChanged(rateManager, _rateManager);
rateManager = _rateManager;
}
/**
* @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[50] private __gap;
}
"
},
"src/interfaces/ILsd.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
import "openzeppelin-contracts/token/ERC20/IERC20.sol";
interface ILsd is IERC20 {
function whiteListMint(uint256 _amount, address _account) external;
function whiteListBurn(uint256 _amount, address _account) external;
event PoolChanged(address _oldPool, address _pool);
}
"
},
"src/libraries/Errors.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
library Errors {
error PermissionDenied();
error InvalidAddr();
error InvalidVersion();
error InvalidtypeId();
error InvalidApr();
error InvalidParameter();
error InvalidAmount();
error InsufficientFunds();
error InvalidLength();
error InvalidRequestId();
error CanUnstake();
error WithrawalsRequestCannotClaimed();
error UnstakeNotEnabled();
error UpdateTimelocked();
error BlackListed();
}
"
},
"src/interfaces/IBasePool.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
interface IBasePool {
event ZKCStake(address _staker, uint256 _stakeAmount, uint256 _mintAmount);
event ZKCUnstake(address _sender, uint256 _unstakeAmount, uint256 _ethAmount);
event UnstakeAllowedUpdated(bool _oldUnstakeAllowed, bool _unstakeAllowed);
event StrategyVaultChanged(address _oldStrategyVault, address _strategyVault);
event StrategyDeposited(uint256 _amount, uint256 _strategyAmount);
event StrategyReturn(uint256 _amount);
event WithdrawalVaultUpdated(address _oldWithdrawalVault, address _withdrawalVault);
}
"
},
"lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol";
"
},
"lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.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 SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 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(
IERC20 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));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit 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(IERC20 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");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
"
},
"src/interfaces/IWithdrawalVault.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.8;
interface IWithdrawalVault {
function transferToken(address _to, uint256 _amount) external;
event PoolSet(address _pool);
event PoolChanged(address _oldPool, address _pool);
event Transfer(address _to, uint256 _amount);
event Received(uint256 _amount);
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../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 anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing 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/UUPSUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
require(address(this) != __self, "Function must be called through delegatecall");
require(_getImplementation() == __self, "Function must be called through active proxy");
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
_;
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeTo(address newImplementation) external virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @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[50] private __gap;
}
"
},
"lib/openzeppelin-contracts-upgradeable/contracts/security/PausableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
function __Pausable_init() internal onlyInitializing {
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
/**
* @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/security/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
/
Submitted on: 2025-09-21 05:39:03
Comments
Log in to comment.
No comments yet.