Skip to content

Commit

Permalink
✎﹏﹏﹏﹏
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z authored Aug 29, 2024
1 parent 105c0d8 commit 6485b02
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/paymasters/NEETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ import "@solady/src/tokens/ERC20.sol";

/// @notice Simple wrapped ERC4337 implementation with paymaster and yield functions.
/// @author nani.eth (https://github.com/NaniDAO/accounts/blob/main/src/paymasters/NEETH.sol)
/// @custom:version 1.1.1
/// @custom:version 1.2.3
contract NEETH is ERC20 {
/// ========================= CONSTANTS ========================= ///

/// @dev The governing DAO address.
address internal constant DAO = 0xDa000000000000d2885F108500803dfBAaB2f2aA;

/// @dev The Uniswap V3 pool on Arbitrum for swapping between WETH & stETH.
address internal immutable i_pool;
address internal immutable POOL;

/// @dev The WETH contract for wrapping and unwrapping ETH on Arbitrum.
address internal immutable i_weth;
address internal immutable WETH;

/// @dev The yield token contract address (in V1, bridged wrapped stETH).
address internal immutable i_yield;
address internal immutable YIELD;

/// @dev A canonical ERC4337 EntryPoint contract for NEETH alpha (0.6).
address internal immutable i_ep06;
address internal constant EP06 = 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789;

/// @dev A canonical ERC4337 EntryPoint contract for NEETH alpha (0.7).
address internal immutable i_ep07;
address internal constant EP07 = 0x0000000071727De22E5E9d8BAf0edAc6f37da032;

/// @dev The minimum value that can be returned from `getSqrtRatioAtTick` (plus one).
uint160 internal constant MIN_SQRT_RATIO_PLUS_ONE = 4295128740;
Expand Down Expand Up @@ -86,25 +86,25 @@ contract NEETH is ERC20 {
/// @dev Requires that the caller is the DAO.
modifier onlyDAO() virtual {
assembly ("memory-safe") {
if iszero(eq(caller(), DAO)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), DAO)) { revert(codesize(), codesize()) }
}
_;
}

/// @dev Requires that the caller is the EntryPoint (0.6).
modifier onlyEntryPoint06() virtual {
address ep06 = i_ep06;
address ep06 = EP06;
assembly ("memory-safe") {
if iszero(eq(caller(), ep06)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), ep06)) { revert(codesize(), codesize()) }
}
_;
}

/// @dev Requires that the caller is the EntryPoint (0.7).
modifier onlyEntryPoint07() virtual {
address ep07 = i_ep07;
address ep07 = EP07;
assembly ("memory-safe") {
if iszero(eq(caller(), ep07)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), ep07)) { revert(codesize(), codesize()) }
}
_;
}
Expand All @@ -124,12 +124,8 @@ contract NEETH is ERC20 {
/// ======================== CONSTRUCTOR ======================== ///

/// @dev Constructs NEETH.
constructor(address pool, address weth, address yield, address ep06, address ep07) payable {
i_pool = pool;
i_weth = weth;
i_yield = yield;
i_ep06 = ep06;
i_ep07 = ep07;
constructor(address pool, address weth, address yield) payable {
(POOL, WETH, YIELD) = (pool, weth, yield);
}

/// ===================== DEPOSIT OPERATIONS ===================== ///
Expand Down Expand Up @@ -167,7 +163,7 @@ contract NEETH is ERC20 {

/// @dev Executes a swap across the Uniswap V3 pool on Arbitrum for WETH & stETH.
function _swap(bool zeroForOne, int256 amount) internal virtual returns (uint256) {
(int256 amount0, int256 amount1) = ISwapRouter(i_pool).swap(
(int256 amount0, int256 amount1) = ISwapRouter(POOL).swap(
address(this),
zeroForOne,
amount,
Expand All @@ -180,7 +176,7 @@ contract NEETH is ERC20 {

/// @dev Fallback `uniswapV3SwapCallback`.
fallback() external payable virtual {
address pool = i_pool;
address pool = POOL;
uint256 amount0Delta;
int256 amount1Delta;
bool zeroForOne;
Expand All @@ -200,7 +196,7 @@ contract NEETH is ERC20 {

/// @dev Funds an `amount` of YIELD token (stETH) to pool caller for swap.
function _transferYieldToken(uint256 amount) internal virtual {
address yield = i_yield;
address yield = YIELD;
assembly ("memory-safe") {
mstore(0x14, caller()) // Store the `pool` argument.
mstore(0x34, amount) // Store the `amount` argument.
Expand All @@ -212,7 +208,7 @@ contract NEETH is ERC20 {

/// @dev Wraps an `amount` of ETH to WETH and funds pool caller for swap.
function _wrapETH(uint256 amount) internal virtual {
address weth = i_weth;
address weth = WETH;
assembly ("memory-safe") {
pop(call(gas(), weth, amount, codesize(), 0x00, codesize(), 0x00))
mstore(0x14, caller()) // Store the `pool` argument.
Expand All @@ -225,7 +221,7 @@ contract NEETH is ERC20 {

/// @dev Unwraps an `amount` of ETH from WETH for return.
function _unwrapETH(uint256 amount) internal virtual {
address weth = i_weth;
address weth = WETH;
assembly ("memory-safe") {
mstore(0x00, 0x2e1a7d4d) // `withdraw(uint256)`.
mstore(0x20, amount) // Store the `amount` argument.
Expand All @@ -246,9 +242,9 @@ contract NEETH is ERC20 {
/// @dev ETH receiver fallback.
/// Only canonical WETH can call.
receive() external payable virtual {
address weth = i_weth;
address weth = WETH;
assembly ("memory-safe") {
if iszero(eq(caller(), weth)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), weth)) { revert(codesize(), codesize()) }
}
}

Expand Down Expand Up @@ -316,17 +312,17 @@ contract NEETH is ERC20 {

/// @dev Adds stake to EntryPoint (if `old`, version 0.6 is used).
function addStake(bool old, uint32 unstakeDelaySec) public payable virtual onlyDAO {
IEntryPoint(payable(old ? i_ep06 : i_ep07)).addStake{value: msg.value}(unstakeDelaySec);
IEntryPoint(payable(old ? EP06 : EP07)).addStake{value: msg.value}(unstakeDelaySec);
}

/// @dev Unlocks stake from EntryPoint (if `old`, version 0.6 is used).
function unlockStake(bool old) public virtual onlyDAO {
IEntryPoint(payable(old ? i_ep06 : i_ep07)).unlockStake();
IEntryPoint(payable(old ? EP06 : EP07)).unlockStake();
}

/// @dev Withdraws stake from EntryPoint (if `old`, version 0.6 is used).
function withdrawStake(bool old, address payable withdrawAddress) public virtual onlyDAO {
IEntryPoint(payable(old ? i_ep06 : i_ep07)).withdrawStake(withdrawAddress);
IEntryPoint(payable(old ? EP06 : EP07)).withdrawStake(withdrawAddress);
}

/// @dev Withdraws EntryPoint deposits under DAO governance (if `old`, version 0.6 is used).
Expand All @@ -335,7 +331,7 @@ contract NEETH is ERC20 {
virtual
onlyDAO
{
IEntryPoint(old ? i_ep06 : i_ep07).withdrawTo(withdrawAddress, withdrawAmount);
IEntryPoint(old ? EP06 : EP07).withdrawTo(withdrawAddress, withdrawAmount);
}

/// =================== GOVERNANCE OPERATIONS =================== ///
Expand Down

0 comments on commit 6485b02

Please sign in to comment.