Skip to content

Commit

Permalink
feat: convert WithdrawQueue to library
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed May 31, 2024
1 parent 7282a82 commit d26db4b
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 187 deletions.
2 changes: 1 addition & 1 deletion script/add_liq.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Script, console2 } from "forge-std/Script.sol";
import { Registry } from "@/Registry.sol";
import { UnsETH } from "@/unsETH/UnsETH.sol";
import { Renderer } from "@/unsETH/Renderer.sol";
import { LPETH } from "@/LPETH.sol";
import { LPETH } from "@/lpETH/LPETH.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { ERC20 } from "solady/tokens/ERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion script/check.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.20;
import { Script, console2 } from "forge-std/Script.sol";
import { UnsETH } from "@/unsETH/UnsETH.sol";
import { Renderer } from "@/unsETH/Renderer.sol";
import { LPETH } from "@/LPETH.sol";
import { LPETH } from "@/lpETH/LPETH.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { ERC20 } from "solady/tokens/ERC20.sol";

Expand Down
135 changes: 67 additions & 68 deletions script/deploy.local.s.sol
Original file line number Diff line number Diff line change
@@ -1,83 +1,82 @@
// pragma solidity >=0.8.20;
pragma solidity >=0.8.20;

// import { Script, console2 } from "forge-std/Script.sol";
// import { Registry } from "@/Registry.sol";
// import { UnsETH } from "@/unsETH/UnsETH.sol";
// import { Renderer } from "@/unsETH/Renderer.sol";
// import { LPETH, ConstructorConfig } from "@/LPETH.sol";
// import { LPToken } from "@/LPToken.sol";
// import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
// import { ERC20 } from "solady/tokens/ERC20.sol";
import { Script, console2 } from "forge-std/Script.sol";
import { Registry } from "@/Registry.sol";
import { UnsETH } from "@/unsETH/UnsETH.sol";
import { Renderer } from "@/unsETH/Renderer.sol";
import { LPETH, ConstructorConfig } from "@/lpETH/LPETH.sol";
import { LPToken } from "@/lpETH/LPToken.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { ERC20 } from "solady/tokens/ERC20.sol";

// // Adapters
// import { Adapter } from "@/adapters/Adapter.sol";
// import { EETHAdapter, EETH_TOKEN } from "@/adapters/eETH/EETHAdapter.sol";
// import { ETHxAdapter, ETHx_TOKEN } from "@/adapters/ETHx/ETHxAdapter.sol";
// import { METHAdapter, METH_TOKEN } from "@/adapters/mETH/METHAdapter.sol";
// import { StETHAdapter, STETH_TOKEN } from "@/adapters/stETH/StETHAdapter.sol";
// import { SwETHAdapter, SWETH_TOKEN } from "@/adapters/swETH/SwETHAdapter.sol";
// Adapters
import { Adapter } from "@/adapters/Adapter.sol";
import { EETHAdapter, EETH_TOKEN } from "@/adapters/eETH/EETHAdapter.sol";
import { ETHxAdapter, ETHx_TOKEN } from "@/adapters/ETHx/ETHxAdapter.sol";
import { METHAdapter, METH_TOKEN } from "@/adapters/mETH/METHAdapter.sol";
import { StETHAdapter, STETH_TOKEN } from "@/adapters/stETH/StETHAdapter.sol";
import { SwETHAdapter, SWETH_TOKEN } from "@/adapters/swETH/SwETHAdapter.sol";

// // Token holders, to get some funds
// import { EETH_HOLDER } from "@test/adapters/EETHAdapter.t.sol";
// import { ETHx_HOLDER } from "@test/adapters/ETHxAdapter.t.sol";
// import { METH_HOLDER } from "@test/adapters/METHAdapter.t.sol";
// import { STETH_HOLDER } from "@test/adapters/StETHAdapter.t.sol";
// import { SWETH_HOLDER } from "@test/adapters/SwETHAdapter.t.sol";
// Token holders, to get some funds
import { EETH_HOLDER } from "@test/adapters/EETHAdapter.t.sol";
import { ETHx_HOLDER } from "@test/adapters/ETHxAdapter.t.sol";
import { METH_HOLDER } from "@test/adapters/METHAdapter.t.sol";
import { STETH_HOLDER } from "@test/adapters/StETHAdapter.t.sol";
import { SWETH_HOLDER } from "@test/adapters/SwETHAdapter.t.sol";

// contract DeployLocal is Script {
// bytes32 salt = bytes32(uint256(1));
contract DeployLocal is Script {
bytes32 salt = bytes32(uint256(1));

// function run() public {
// uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
// vm.startBroadcast(deployerPrivateKey);
function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

// LPToken lpToken = new LPToken();
LPToken lpToken = new LPToken();

// address registry_impl = address(new Registry{ salt: salt }());
// Registry registryProxy = Registry(address(new ERC1967Proxy{ salt: salt }(address(registry_impl), "")));
// registryProxy.initialize();
// console2.log("Registry Implementation: %s", registry_impl);
// console2.log("Registry Proxy: %s", address(registryProxy));
address registry_impl = address(new Registry{ salt: salt }());
Registry registryProxy = Registry(address(new ERC1967Proxy{ salt: salt }(address(registry_impl), "")));
registryProxy.initialize();
console2.log("Registry Implementation: %s", registry_impl);
console2.log("Registry Proxy: %s", address(registryProxy));

// address renderer = address(new Renderer());
// address unsETH_impl = address(new UnsETH{ salt: salt }(address(registryProxy), renderer));
// UnsETH unsETHProxy = UnsETH(payable(address(new ERC1967Proxy{ salt: salt }(unsETH_impl, ""))));
// unsETHProxy.initialize();
// console2.log("UnsETH Implementation: %s", unsETH_impl);
// console2.log("UnsETH Proxy: %s", address(unsETHProxy));
address renderer = address(new Renderer());
address unsETH_impl = address(new UnsETH{ salt: salt }(address(registryProxy), renderer));
UnsETH unsETHProxy = UnsETH(payable(address(new ERC1967Proxy{ salt: salt }(unsETH_impl, ""))));
unsETHProxy.initialize();
console2.log("UnsETH Implementation: %s", unsETH_impl);
console2.log("UnsETH Proxy: %s", address(unsETHProxy));

// ConstructorConfig memory config = ConstructorConfig({
// registry: registryProxy,
// lpToken: lpToken,
// treasury: address(0),
// unsETH: address(unsETHProxy),
// withdrawQueue: address(0)
// });
ConstructorConfig memory config = ConstructorConfig({
registry: registryProxy,
lpToken: lpToken,
unsETH: address(unsETHProxy),
treasury: address(0)
});

// address lpETH_impl = address(new LPETH{ salt: salt }());
// LPETH lpETHProxy = LPETH(payable(address(new ERC1967Proxy{ salt: salt }(lpETH_impl, ""))));
// lpETHProxy.initialize();
// console2.log("LPETH Implementation: %s", lpETH_impl);
// console2.log("LPETH Proxy: %s", address(lpETHProxy));
// console2.log("LP Token: %s", address(lpETHProxy.lpToken()));
address lpETH_impl = address(new LPETH{ salt: salt }(config));
LPETH lpETHProxy = LPETH(payable(address(new ERC1967Proxy{ salt: salt }(lpETH_impl, ""))));
lpETHProxy.initialize();
console2.log("LPETH Implementation: %s", lpETH_impl);
console2.log("LPETH Proxy: %s", address(lpETHProxy));
console2.log("LP Token: %s", address(lpETHProxy.lpToken()));

// // Register and deploy adapters, send some funds
// Adapter eETHAdapter = new EETHAdapter();
// registryProxy.setAdapter(EETH_TOKEN, eETHAdapter);
// console2.log("EETH Adapter: %s", address(eETHAdapter));
// Register and deploy adapters, send some funds
Adapter eETHAdapter = new EETHAdapter();
registryProxy.setAdapter(EETH_TOKEN, eETHAdapter);
console2.log("EETH Adapter: %s", address(eETHAdapter));

// Adapter ethxAdapter = new ETHxAdapter();
// registryProxy.setAdapter(ETHx_TOKEN, ethxAdapter);
// console2.log("ETHx Adapter: %s", address(ethxAdapter));
Adapter ethxAdapter = new ETHxAdapter();
registryProxy.setAdapter(ETHx_TOKEN, ethxAdapter);
console2.log("ETHx Adapter: %s", address(ethxAdapter));

// Adapter methAdapter = new METHAdapter();
// registryProxy.setAdapter(METH_TOKEN, methAdapter);
// console2.log("METH Adapter: %s", address(methAdapter));
Adapter methAdapter = new METHAdapter();
registryProxy.setAdapter(METH_TOKEN, methAdapter);
console2.log("METH Adapter: %s", address(methAdapter));

// Adapter stETHAdapter = new StETHAdapter();
// registryProxy.setAdapter(STETH_TOKEN, stETHAdapter);
// console2.log("StETH Adapter: %s", address(stETHAdapter));
Adapter stETHAdapter = new StETHAdapter();
registryProxy.setAdapter(STETH_TOKEN, stETHAdapter);
console2.log("StETH Adapter: %s", address(stETHAdapter));

// vm.stopBroadcast();
// }
// }
vm.stopBroadcast();
}
}
96 changes: 0 additions & 96 deletions src/WithdrawQueue.sol

This file was deleted.

36 changes: 21 additions & 15 deletions src/LPETH.sol → src/lpETH/LPETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
pragma solidity >=0.8.20;

import { Registry } from "@/Registry.sol";
import { LPToken } from "@/LPToken.sol";
import { LPToken } from "@/lpETH/LPToken.sol";
import { UnsETH, Metadata } from "@/unsETH/UnsETH.sol";
import { UnsETHQueue } from "@/UnsETHQueue.sol";
import { UnsETHQueue } from "@/lpETH/UnsETHQueue.sol";
import { Adapter } from "@/adapters/Adapter.sol";
import { WithdrawQueue } from "@/WithdrawQueue.sol";
import { WithdrawQueue } from "@/lpETH/WithdrawQueue.sol";
import { ERC721Receiver } from "@/utils/ERC721Receiver.sol";

import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
Expand Down Expand Up @@ -47,9 +47,8 @@ UD60x18 constant MIN_LP_CUT = UD60x18.wrap(0.2e18);
struct ConstructorConfig {
Registry registry;
LPToken lpToken;
address treasury;
address unsETH;
address withdrawQueue;
address treasury;
}

struct SwapParams {
Expand All @@ -71,7 +70,8 @@ abstract contract LpETHEvents {
error GaugeZero();

event Deposit(address indexed from, uint256 amount, uint256 lpSharesMinted);
event Withdraw(address indexed to, uint256 amount, uint256 lpSharesBurnt);
event Withdraw(address indexed to, uint256 amount, uint256 lpSharesBurnt, uint256 requestId);
event ClaimWithdrawRequest(uint256 indexed requestId, address indexed to, uint256 amount);
event Swap(address indexed caller, address indexed asset, uint256 amountIn, uint256 fee, uint256 unlockId);
event UnlockBought(address indexed caller, uint256 tokenId, uint256 amount, uint256 reward, uint256 lpFees);
event UnlockRedeemed(address indexed relayer, uint256 tokenId, uint256 amount, uint256 reward, uint256 lpFees);
Expand Down Expand Up @@ -99,6 +99,8 @@ abstract contract LpETHStorage {
uint256 treasuryRewards;
// Unlock queue to hold unlocks
UnsETHQueue.Data unsETHQueue;
// Withdraw request queue
WithdrawQueue.Data withdrawQueue;
// amount unlocking per asset
mapping(address asset => uint256 unlocking) unlockingForAsset;
// last supply of a tenderizer when seen, tracked because they are rebasing tokens
Expand Down Expand Up @@ -130,12 +132,12 @@ contract LPETH is
ERC721Receiver
{
using UnsETHQueue for UnsETHQueue.Data;
using WithdrawQueue for WithdrawQueue.Data;

LPToken private immutable LPTOKEN = LPToken(address(0));
Registry private immutable REGISTRY = Registry(address(0));
address payable private immutable TREASURY = payable(0x5542b58080FEE48dBE6f38ec0135cE9011519d96);
address payable private immutable UNSETH = payable(0xA2FE2b9298c03AF9C5d885e62Bc04F77a7Ff91BF);
address payable private immutable WITHDRAW_QUEUE = payable(address(0));
address payable private immutable TREASURY = payable(0x5542b58080FEE48dBE6f38ec0135cE9011519d96);

function initialize() public initializer {
__Ownable_init(msg.sender);
Expand All @@ -150,7 +152,6 @@ contract LPETH is
LPTOKEN = config.lpToken;
TREASURY = payable(config.treasury);
UNSETH = payable(config.unsETH);
WITHDRAW_QUEUE = payable(config.withdrawQueue);
_disableInitializers();
}

Expand Down Expand Up @@ -187,7 +188,7 @@ contract LPETH is

uint256 available = ud(amount).mul(ud($.unlocking).div(ud($.liabilities))).unwrap();

requestId = WithdrawQueue(WITHDRAW_QUEUE).createRequest(uint128(amount - available), payable(msg.sender));
requestId = $.withdrawQueue.createRequest(uint128(amount - available), payable(msg.sender));

// Calculate LP tokens to burn
uint256 lpShares =
Expand All @@ -204,7 +205,7 @@ contract LPETH is
// Transfer available tokens to caller
payable(msg.sender).transfer(available);

emit Withdraw(msg.sender, amount, lpShares);
emit Withdraw(msg.sender, amount, lpShares, requestId);
}

function quote(address asset, uint256 amount) external view returns (uint256 out) {
Expand Down Expand Up @@ -299,7 +300,7 @@ contract LPETH is
// Finalize requests
{
uint256 amountToFinalize = amountReceived - unlock.fee;
WithdrawQueue(WITHDRAW_QUEUE).finalizeRequests{ value: amountToFinalize }();
$.withdrawQueue.finalizeRequests(amountToFinalize);
}

emit UnlockRedeemed(msg.sender, unlock.tokenId, amountReceived, relayerReward, lpReward);
Expand Down Expand Up @@ -356,7 +357,7 @@ contract LPETH is
// Finalize requests
{
uint256 amountToFinalize = totalReceived - totalFee;
WithdrawQueue(WITHDRAW_QUEUE).finalizeRequests{ value: amountToFinalize }();
$.withdrawQueue.finalizeRequests(amountToFinalize);
}

emit BatchUnlockRedeemed(msg.sender, totalReceived, relayerReward, lpReward, tokenIds);
Expand Down Expand Up @@ -417,7 +418,7 @@ contract LPETH is
// Finalize requests
{
uint256 amountToFinalize = amountExpected - unlock.fee;
WithdrawQueue(WITHDRAW_QUEUE).finalizeRequests{ value: amountToFinalize }();
$.withdrawQueue.finalizeRequests(amountToFinalize);
}

// transfer unlock amount minus reward from caller to pool
Expand Down Expand Up @@ -497,7 +498,7 @@ contract LPETH is
// Finalize requests
{
uint256 amountToFinalize = totalAmountExpected - totalRewards - totalLpCut - totalTreasuryCut;
WithdrawQueue(WITHDRAW_QUEUE).finalizeRequests{ value: amountToFinalize }();
$.withdrawQueue.finalizeRequests(amountToFinalize);
}

emit BatchUnlockBought(msg.sender, totalAmountExpected, totalRewards, totalLpCut, tokenIds);
Expand Down Expand Up @@ -529,6 +530,11 @@ contract LPETH is
payable(TREASURY).transfer(treasuryReward);
}

function claimWithdrawRequest(uint256 id) external returns (uint256 amount) {
amount = _loadStorageSlot().withdrawQueue.claimRequest(id);
emit ClaimWithdrawRequest(id, msg.sender, amount);
}

function lpToken() external view returns (address) {
return address(LPTOKEN);
}
Expand Down
File renamed without changes.
Loading

0 comments on commit d26db4b

Please sign in to comment.