Verified contractExactMIT
PowseyStakingPodContract
Address0xa25a0a54c7588edfbc093ee400c6699cdf62deee
- Balance
0.057336 ETH
- Transactions
14
- Compiler
solc 0.8.31
- Same code
Only this contract
Details
- Compiler
- solc 0.8.31+commit.fd3a2265
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- osaka
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 23,961,467
- Creation transaction
- 0xd067a94e72…08a3b6e858
PowseyStakingPodContract.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
/// @author powsey.eth
/// @title A simple staking control contract enforcing caps and vesting periods
contract PowseyStakingPodContract {
//
// Constants
//
// Releases within allowance: maximum cummulative amount that can be released over a period
uint256 private constant ALLOWANCE_AMOUNT_WEI = 4 ether;
// Releases within allowance: duration of a period
uint256 private constant ALLOWANCE_PERIOD = 30 days;
// Vesting mechanism: balance threshold above which a vesting period can be started, and below which it is closed
uint256 private constant VESTING_THRESHOLD_WEI = 16 ether;
// Vesting mechanism: duration of the vesting period, after which the balance can be released in full
uint256 private constant VESTING_PERIOD = 30 days;
// Constants for EIP-7002 execution layer triggerred validator withdrawals
address private constant WITHDRAWAL_CONTRACT_ADDRESS = 0x00000961Ef480Eb55e80D19ad83579A64c007002;
uint64 private constant WITHDRAWAL_AMOUNT_GWEI_RANGE_MIN = 1;
uint64 private constant WITHDRAWAL_AMOUNT_GWEI_RANGE_MAX = 2048000000000; /* 2048 ETH */
uint256 private constant WITHDRAWAL_FEE_WEI_RANGE_MIN = 1;
uint256 private constant WITHDRAWAL_FEE_WEI_RANGE_MAX = 1000000000000000; /* 0.001 ETH */
// Rate limiting for EIP-7002 execution layer triggered validator withdrawals
uint64 private constant WITHDRAWAL_MAX_REQUESTS = 16;
uint256 private constant WITHDRAWAL_PERIOD = 30 days;
//
// State variables
//
// Contract owner: the address that deployed the contract, the only one allowed to interact with it
address private _owner;
// Cold wallet: the only address that can receive large withdrawals' proceeds (subject to vesting period)
address private _coldWallet;
// Vesting period: start timestamp
uint256 private _vestingPeriodStartTs;
// Release within allowance: start timestamp and remaining allowance
uint256 private _allowanceStartTs;
uint256 private _allowanceRemainingWei;
// Validator withdrawals: start timestamp and remaining withdrawals
uint256 private _withdrawalStartTs;
uint64 private _withdrawalRemaining;
// Reentrency guard state
bool private transient _locked;
//
// Events
//
/// @notice Emitted when a vesting period is started
/// @param startsat timestamp at which the vesting period starts
/// @param endsat timestamp at which the vesting period will end
event VestingPeriodStarted(uint256 startsat, uint256 endsat);
/// @notice Emitted when funds are released from the smart contract
/// @param receiver address to which the funds were released
/// @param amount amount released in wei
event FundsReleased(address receiver, uint256 amount);
/// @notice Emitted when execution layer validator withdrawal is initiated by the contract
/// @param validator_pubkey public key of the validator from which funds are withdrawn
/// @param amount_gwei amount withdrawn in gwei
/// @param fee_wei withdrawal fees in wei (value of the withdrawai transaction)
event ValidatorWithdrawalInitiated(bytes validator_pubkey, uint64 amount_gwei, uint256 fee_wei);
/// @notice Emitted when execution layer validator voluntary exit is initiated by the contract
/// @param validator_pubkey public key of the validator from which funds are withdrawn
/// @param fee_wei withdrawal fees in wei (value of the withdrawai transaction)
event ValidatorExitInitiated(bytes validator_pubkey, uint256 fee_wei);
//
// Errors
//
// Raised if Reentrancy check failed
error ReentrancyCheckFailed();
/// @notice Raised when the caller is not allowed to perform the requested action
/// @param caller address of the caller that attempted the unauthorized operation
/// @param owner address allowed to interact with this contract
error Unauthorized(address caller, address owner);
/// @notice Raised if the requested amount is greater than the applicable limit
/// @param requested amount requested to be released in wei
/// @param limit maximum amount that can be released in wei
error AmountOffLimit(uint256 requested, uint256 limit);
/// @notice Raised if the requested operation is not allowed at this time
/// @param now current timestamp
/// @param possibleafter time after which the operation will be possible
error NotPossibleYet(uint256 now, uint256 possibleafter);
/// @notice Raised when the contract balance is too low to perform the requested operation
/// @param needed amount needed to perform the requested operation
/// @param balance current balance available in the contract in wei
error InsufficientBalance(uint256 needed, uint256 balance);
/// @notice Raised if a call parameter did not pass input validation
error InvalidParamValue();
/// @notice Raised if a call to an external function failed
error ExternalCallFailed();
//
// Modifiers
//
/// @notice Prevents reentrancy attacks on functions calling external code
modifier nonReentrant {
if (_locked)
revert ReentrancyCheckFailed();
_locked = true;
_;
_locked = false;
}
//
// Functions: constructor, receive, fallback
//
/// @notice Constructor that initializes the contract with the given release constraints
/// @param coldWallet coldwallet address
constructor(address coldWallet) {
_owner = msg.sender;
_coldWallet = coldWallet;
_vestingPeriodStartTs = 0;
_allowanceStartTs = block.timestamp;
_allowanceRemainingWei = ALLOWANCE_AMOUNT_WEI;
_withdrawalStartTs = block.timestamp;
_withdrawalRemaining = WITHDRAWAL_MAX_REQUESTS;
}
// Allow to receive inbound transactions with funds
receive() external payable {
}
fallback() external payable {
}
//
// Functions: public
//
/// @notice Start a vesting period
function startVestingPeriod() public {
// only the contract owner can call this function
if (msg.sender != _owner)
revert Unauthorized({caller: msg.sender, owner: _owner});
// make sure that there is at least VESTING_THRESHOLD_WEI in the contract
if (address(this).balance < VESTING_THRESHOLD_WEI)
revert InsufficientBalance({needed: VESTING_THRESHOLD_WEI, balance: address(this).balance});
// make sure that there is not another ongoing vesting period
if (_vestingPeriodStartTs != 0)
revert NotPossibleYet({now: block.timestamp, possibleafter: _vestingPeriodStartTs + VESTING_PERIOD});
// update state
_vestingPeriodStartTs = block.timestamp;
emit VestingPeriodStarted({startsat: block.timestamp, endsat: block.timestamp + VESTING_PERIOD});
}
/// @notice Release funds to the owner within monthly allowance
/// @param amountWei requested amount in wei
function releaseEtherToOwner(uint256 amountWei) public nonReentrant {
// only the contract owner can call this function
if (msg.sender != _owner)
revert Unauthorized({caller: msg.sender, owner: _owner});
// replenish the allowance if the previous period had expired
if (block.timestamp > _allowanceStartTs + ALLOWANCE_PERIOD) {
_allowanceStartTs = block.timestamp;
_allowanceRemainingWei = ALLOWANCE_AMOUNT_WEI;
}
// make sure that the requested amount does not exceed the remaining allowance
if (amountWei > _allowanceRemainingWei)
revert AmountOffLimit({requested: amountWei, limit: _allowanceRemainingWei});
// update state
_allowanceRemainingWei -= amountWei;
if (_vestingPeriodStartTs != 0 && address(this).balance - amountWei < VESTING_THRESHOLD_WEI)
_vestingPeriodStartTs = 0;
// send the funds
(bool success,) = _owner.call{value: amountWei}("");
if (!success)
revert ExternalCallFailed();
emit FundsReleased(_owner, amountWei);
}
/// @notice Release funds to the cold wallet after vesting period expiration
/// @param amountWei requested amount in wei
function releaseEtherToColdWallet(uint256 amountWei) public nonReentrant {
// only the contract owner can call this function
if (msg.sender != _owner)
revert Unauthorized({caller: msg.sender, owner: _owner});
uint256 vestingPeriodEndTs = getVestingPeriodEndTs();
// make sure that the requested amount does not exceed the contract balance
if (amountWei > address(this).balance)
revert InsufficientBalance({needed: amountWei, balance: address(this).balance});
// make sure that a vesting period was initiated and has expired
if (_vestingPeriodStartTs == 0 || block.timestamp < vestingPeriodEndTs)
revert NotPossibleYet({now: block.timestamp, possibleafter: vestingPeriodEndTs});
// update state
if (address(this).balance - amountWei < VESTING_THRESHOLD_WEI)
_vestingPeriodStartTs = 0;
// send the funds
(bool success,) = _coldWallet.call{value: amountWei}("");
if (!success)
revert ExternalCallFailed();
emit FundsReleased(_coldWallet, amountWei);
}
/// @notice Request an EL triggered withdrawal or exit for the specified validator (EIP-7002)
/// @param validatorPubkey public key of the validator from which funds will be withdrawn
/// @param amountGwei amount to withdraw in gwei or the special value of 0 to exit the validator
/// @param feeWei withdrawal fees to pay in wei (value of the transaction)
function withdrawValidator(bytes calldata validatorPubkey, uint64 amountGwei, uint256 feeWei) public nonReentrant {
// only the contract owner can call this function
if (msg.sender != _owner)
revert Unauthorized({caller: msg.sender, owner: _owner});
// make sure that the input parameters are valid
if (validatorPubkey.length != 48 ||
!((amountGwei >= WITHDRAWAL_AMOUNT_GWEI_RANGE_MIN && amountGwei <= WITHDRAWAL_AMOUNT_GWEI_RANGE_MAX) || amountGwei == 0) ||
feeWei < WITHDRAWAL_FEE_WEI_RANGE_MIN || feeWei > WITHDRAWAL_FEE_WEI_RANGE_MAX)
revert InvalidParamValue();
// make sure that the contract balance is sufficient to cover withdrawal fees
if (address(this).balance < feeWei)
revert InsufficientBalance({needed: feeWei, balance: address(this).balance});
// reset the witdrawal rate limit if the previous period had expired
if (block.timestamp > _withdrawalStartTs + WITHDRAWAL_PERIOD) {
_withdrawalStartTs = block.timestamp;
_withdrawalRemaining = WITHDRAWAL_MAX_REQUESTS;
}
// make sure that the withdrawal rate limit is not exceeded
if (_withdrawalRemaining < 1)
revert NotPossibleYet({now: block.timestamp, possibleafter: _withdrawalStartTs + WITHDRAWAL_PERIOD});
// update state
_withdrawalRemaining -= 1;
// request the validator withdrawal or exit
(bool success,) = WITHDRAWAL_CONTRACT_ADDRESS.call{value: feeWei}(abi.encodePacked(validatorPubkey, amountGwei));
if (!success)
revert ExternalCallFailed();
if (amountGwei > 0)
emit ValidatorWithdrawalInitiated(validatorPubkey, amountGwei, feeWei);
else
emit ValidatorExitInitiated(validatorPubkey, feeWei);
}
/// @notice Get information about the contract state
/// @return ownerAddress contract owner address
/// @return coldWalletAddress cold wallet address
/// @return balanceWei amount currently held in the contract in wei
/// @return releaseAllowanceResetTs when the release allowance to the owner will be replenished
/// @return releaseAllowanceLeft maximum amount available for release to the owner
/// @return vestingPeriodEndTs when the vested funds can be released to the cold wallet, or 0 if there are no vested funds
/// @return withdrawalRequestsResetTs when the validator withdrawal or exit request rate limit will be reset
/// @return withdrawalRequestsLeft number of validator withdrawal or exit requests left
function getState() public view returns (
address ownerAddress,
address coldWalletAddress,
uint256 balanceWei,
uint256 releaseAllowanceResetTs,
uint256 releaseAllowanceLeft,
uint256 vestingPeriodEndTs,
uint256 withdrawalRequestsResetTs,
uint64 withdrawalRequestsLeft
) {
return (
_owner,
_coldWallet,
address(this).balance,
_allowanceStartTs + ALLOWANCE_PERIOD,
((block.timestamp > _allowanceStartTs + ALLOWANCE_PERIOD) ? ALLOWANCE_AMOUNT_WEI : _allowanceRemainingWei),
getVestingPeriodEndTs(),
_withdrawalStartTs + WITHDRAWAL_PERIOD,
((block.timestamp > _withdrawalStartTs + WITHDRAWAL_PERIOD) ? WITHDRAWAL_MAX_REQUESTS : _withdrawalRemaining)
);
}
//
// Functions: private
//
/// @notice Calculate the time at which the vesting period ends
/// @return timestamp of the end of the current vesting period or 0 if no vesting period is active
function getVestingPeriodEndTs() private view returns (uint256) {
return ((_vestingPeriodStartTs != 0) ? _vestingPeriodStartTs + VESTING_PERIOD : 0);
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "osaka",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.