Verified contractExactMIT
StUSDSMaxWithdrawer
Address0xe0abffec1c0cf9631ef8860e5a3a9a84d6f2f8c4
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 1,000,000 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,443,663
- Creation transaction
- 0x2638a6a418…df87de0f98
src/StUSDSMaxWithdrawer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// @notice Minimal ERC-4626 subset used here
interface IERC4626 {
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
function maxRedeem(address owner) external view returns (uint256);
function maxWithdraw(address owner) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
}
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}
/// @title StUSDSMaxWithdrawer
/// @notice Keeper-driven exit from mainnet stUSDS. OWNER approves this contract for its stUSDS shares.
/// On each executeWithdraw() the contract redeems as many of OWNER's shares as the vault's
/// current liquidity (maxRedeem) and OWNER's allowance permit. USDS goes straight to OWNER;
/// nothing is held by this contract.
/// @dev Only the deployer (the keeper key) can call executeWithdraw / rescueToken.
contract StUSDSMaxWithdrawer {
/// @dev Mainnet stUSDS (ERC-4626, asset = USDS)
address public constant VAULT = 0x99CD4Ec3f88A45940936F469E4bB72A2A701EEB9;
/// @dev Share owner and USDS receiver
address public immutable OWNER;
/// @dev Keeper (deployer)
address public immutable keeper;
event Executed(address indexed caller, uint256 sharesRedeemed, uint256 assetsWithdrawn);
event RescueToken(address indexed token, address indexed to, uint256 amount);
error NotKeeper();
error ZeroAddress();
error NothingToWithdraw();
error TransferFailed();
constructor(address owner_) {
if (owner_ == address(0)) revert ZeroAddress();
OWNER = owner_;
keeper = msg.sender;
}
modifier onlyKeeper() {
if (msg.sender != keeper) revert NotKeeper();
_;
}
/// @notice Shares redeemable right now: min(vault liquidity limit, OWNER's allowance to this contract)
function redeemableShares() public view returns (uint256) {
IERC4626 vault = IERC4626(VAULT);
uint256 shares = vault.maxRedeem(OWNER);
uint256 allowed = vault.allowance(OWNER, address(this));
return shares < allowed ? shares : allowed;
}
/// @notice Current max withdrawable USDS for OWNER (ignores allowance)
function currentMaxWithdraw() external view returns (uint256) {
return IERC4626(VAULT).maxWithdraw(OWNER);
}
/// @notice Redeem everything currently possible to OWNER. Reverts NothingToWithdraw when 0,
/// so an off-chain simulate filters out empty rounds without spending gas.
function executeWithdraw() external onlyKeeper returns (uint256 assets) {
uint256 shares = redeemableShares();
if (shares == 0) revert NothingToWithdraw();
assets = IERC4626(VAULT).redeem(shares, OWNER, OWNER);
if (assets == 0) revert NothingToWithdraw();
emit Executed(msg.sender, shares, assets);
}
/// @notice Rescue an ERC20 sent here by mistake
function rescueToken(address token, uint256 amount, address to) external onlyKeeper {
if (!IERC20(token).transfer(to, amount)) revert TransferFailed();
emit RescueToken(token, to, amount);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 1000000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"create3-factory/=lib/create3-factory/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solmate/=lib/solmate/src/",
"@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/",
"chainlink-brownie-contracts/=lib/chainlink-brownie-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.