Verified contractPartialMIT
Reserve
Address0x98feec93d4b95d9fc4f7642535da2941c636997b
- Balance
0.000689 ETH
- Transactions
0
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,234,213
- Creation transaction
- 0x674386d1b0…15b6eb5f85
src/Reserve.sol
// SPDX-License-Identifier: MIT
// https://www.ratchet.live https://x.com/ratchetprotocol
pragma solidity 0.8.28;
/*
RATCHET · SPEC SHEET 2 OF 4 · THE RESERVE
HOLDS ETH (the buffer), wstETH (Lido staked ETH, earning the staking yield) and stETH waiting in Lido's
withdrawal queue on its way back to ETH
IN the 1% reserve fee of every trade (sent by the Pawl), the staking yield, and any ETH anyone sends
OUT exactly one path: payToPawl, callable only by the Pawl, which buys RATCHET at the floor and burns it.
There is no owner, no withdraw, no upgrade.
VALUE value() = ETH + wstETH x Lido's stEthPerToken + stETH queued for withdrawal. Staking and unstaking
go through Lido itself at Lido's own rate, never through a market, so neither changes the value: the
floor moves only with fees, yield and floor buys.
BUFFER stake() (anyone): when the ETH buffer is over 30% of value, everything above 20% goes to Lido (ETH sent
to the wstETH contract is staked and wrapped in one call).
unstake() (anyone): when the buffer is under 10% of value, wstETH worth the gap back to 20% is queued
in Lido's withdrawal queue (0x889e...F9B1). claim() (anyone) collects the ETH of finished requests.
Measured 2026-10-20: the queue was finalizing requests 17 hours old.
LIMITS A floor buy can only pay out the ETH buffer; past it the Pawl leaves the rest of a sell to the pool
until the buffer is refilled. At most MAX_PENDING (8) withdrawal requests wait at once, so claim()
loops at most 8 times. If Lido ever finalizes a request below its queued amount (a slashing loss),
the floor falls by that difference: the one way it can, and it is Lido's, not this contract's.
*/
interface IWstETH {
function stEthPerToken() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
function approve(address, uint256) external returns (bool);
}
interface IWithdrawalQueue {
struct WithdrawalRequestStatus {
uint256 amountOfStETH;
uint256 amountOfShares;
address owner;
uint256 timestamp;
bool isFinalized;
bool isClaimed;
}
function requestWithdrawalsWstETH(uint256[] calldata amounts, address owner) external returns (uint256[] memory);
function getWithdrawalStatus(uint256[] calldata ids) external view returns (WithdrawalRequestStatus[] memory);
function claimWithdrawal(uint256 id) external;
}
contract Reserve {
IWstETH public constant WSTETH = IWstETH(0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0);
IWithdrawalQueue public constant QUEUE = IWithdrawalQueue(0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1);
uint256 public constant TARGET_BPS = 2_000; // the buffer aims at 20% of value
uint256 public constant STAKE_ABOVE_BPS = 3_000;
uint256 public constant UNSTAKE_BELOW_BPS = 1_000;
uint256 public constant MAX_PENDING = 8;
uint256 public constant MAX_REQUEST_STETH = 1_000e18; // Lido's own cap per request
uint256 public constant MIN_REQUEST_STETH = 0.01 ether;
address public immutable LAUNCH; // binds the Pawl, once
address public pawl;
uint256[] public pending; // Lido withdrawal request ids, oldest first
uint256 public pendingStEth; // stETH queued in them
uint256 public paidOut; // ETH paid for floor buys
uint256 public staked; // ETH sent to Lido
uint256 public unstaked; // ETH back from Lido
event Bound(address pawl);
event Paid(uint256 eth);
event Staked(uint256 eth, uint256 wstEth);
event Queued(uint256 indexed id, uint256 wstEth, uint256 stEth);
event Claimed(uint256 indexed id, uint256 stEth, uint256 eth);
error NotLaunch();
error NotPawl();
error AlreadyBound();
error PayFailed();
constructor(address launch) {
LAUNCH = launch;
}
receive() external payable {}
/// @dev Lido mints a withdrawal NFT to the owner of each request.
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return this.onERC721Received.selector;
}
function bind(address pawl_) external {
if (msg.sender != LAUNCH) revert NotLaunch();
if (pawl != address(0)) revert AlreadyBound();
pawl = pawl_;
WSTETH.approve(address(QUEUE), type(uint256).max);
emit Bound(pawl_);
}
// ------------------------------------------------------------------------------------------------ value
/// @notice What the reserve is worth in ETH: the numerator of the floor.
function value() public view returns (uint256) {
return address(this).balance + WSTETH.balanceOf(address(this)) * WSTETH.stEthPerToken() / 1e18 + pendingStEth;
}
function buffer() external view returns (uint256) {
return address(this).balance;
}
function pendingCount() external view returns (uint256) {
return pending.length;
}
// ------------------------------------------------------------------------------------------------ out
/// @notice The only way ETH leaves: the Pawl paying for tokens it buys at the floor and burns.
function payToPawl(uint256 eth) external {
address p = pawl;
if (msg.sender != p) revert NotPawl();
paidOut += eth;
(bool ok,) = p.call{value: eth}("");
if (!ok) revert PayFailed();
emit Paid(eth);
}
// ------------------------------------------------------------------------------------------------ buffer
/// @notice Anyone: stake the ETH above the 20% buffer, when the buffer is over 30% of value.
function stake() external returns (uint256 eth) {
uint256 v = value();
uint256 b = address(this).balance;
if (b * 10_000 <= v * STAKE_ABOVE_BPS) return 0;
eth = b - v * TARGET_BPS / 10_000;
uint256 w0 = WSTETH.balanceOf(address(this));
(bool ok,) = address(WSTETH).call{value: eth}("");
if (!ok) return 0; // Lido paused or over its staking limit: try later
staked += eth;
emit Staked(eth, WSTETH.balanceOf(address(this)) - w0);
}
/// @notice Anyone: when the buffer is under 10% of value, queue wstETH worth the gap back to 20% in Lido's
/// withdrawal queue (one request, at most 1,000 stETH, at most 8 waiting).
function unstake() external returns (uint256 id) {
if (pending.length >= MAX_PENDING) return 0;
uint256 v = value();
uint256 b = address(this).balance + pendingStEth; // ETH already on its way counts toward the buffer
if (b * 10_000 >= v * UNSTAKE_BELOW_BPS) return 0;
uint256 rate = WSTETH.stEthPerToken();
uint256 st = v * TARGET_BPS / 10_000 - b;
if (st > MAX_REQUEST_STETH) st = MAX_REQUEST_STETH;
uint256 wst = st * 1e18 / rate;
uint256 have = WSTETH.balanceOf(address(this));
if (wst > have) wst = have;
if (wst * rate / 1e18 < MIN_REQUEST_STETH) return 0;
uint256[] memory amounts = new uint256[](1);
amounts[0] = wst;
id = QUEUE.requestWithdrawalsWstETH(amounts, address(this))[0];
uint256[] memory ids = new uint256[](1);
ids[0] = id;
uint256 queued = QUEUE.getWithdrawalStatus(ids)[0].amountOfStETH;
pending.push(id);
pendingStEth += queued;
emit Queued(id, wst, queued);
}
/// @notice Anyone: collect the ETH of every finished withdrawal request (at most 8).
function claim() external returns (uint256 eth) {
uint256 n = pending.length;
if (n == 0) return 0;
IWithdrawalQueue.WithdrawalRequestStatus[] memory s = QUEUE.getWithdrawalStatus(pending);
uint256 kept;
for (uint256 i; i < n; ++i) {
uint256 id = pending[i];
if (s[i].isFinalized && !s[i].isClaimed) {
uint256 b0 = address(this).balance;
QUEUE.claimWithdrawal(id);
uint256 got = address(this).balance - b0;
pendingStEth -= s[i].amountOfStETH;
unstaked += got;
eth += got;
emit Claimed(id, s[i].amountOfStETH, got);
} else {
pending[kept++] = id;
}
}
while (pending.length > kept) pending.pop();
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "none"
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@uniswap/v4-core/=lib/v4-core/",
":forge-std/=lib/forge-std/src/",
":permit2/=lib/permit2/",
":solmate/=lib/solmate/",
":v4-core/=lib/v4-core/",
":v4-periphery/=lib/v4-periphery/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.