Skip to content

Commit

Permalink
deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
kyriediculous committed Oct 25, 2024
1 parent 041c8d2 commit 5fb269c
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 68 deletions.
4 changes: 2 additions & 2 deletions script/add_liq.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ contract AddLiquidity is Script {
function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
address swap = 0xa5d6F9108f953AE259Cc2C357547FbbdD693347A;
address swap = 0xF3a75E087A92770b4150fFF14c6d36FB07796252;

LpETH(payable(swap)).deposit{ value: 1000 ether }(0);
LpETH(payable(swap)).deposit{ value: 0.5 ether }(0.5 ether);
vm.stopBroadcast();
}
}
7 changes: 3 additions & 4 deletions script/deploy.local.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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";
import { SwapRouter } from "@/periphery/SwapRouter.sol";

// Adapters
import { Adapter } from "@/adapters/Adapter.sol";
Expand Down Expand Up @@ -75,9 +74,9 @@ contract DeployLocal is Script {
registryProxy.setAdapter(STETH_TOKEN, stETHAdapter);
console2.log("StETH Adapter: %s", address(stETHAdapter));

SwapRouter swapRouter = new SwapRouter();
console2.log("SwapRouter: %s", address(swapRouter));

// TODO: Tranfer ownership to SAFE
address SAFE = 0x5542b58080FEE48dBE6f38ec0135cE9011519d96;
lpETHProxy.transferOwnership(SAFE);
vm.stopBroadcast();
}
}
2 changes: 0 additions & 2 deletions script/deploy.local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ forge build

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","id":67,"method":"anvil_setCode","params": ["0x4e59b44847b379578588920ca78fbf26c0b4956c","0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3"]}' 127.0.0.1:8545

export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

forge script script/deploy.local.s.sol --legacy --rpc-url http://127.0.0.1:8545 --broadcast --private-key $PRIVATE_KEY -vvvv
forge script script/add_liq.s.sol --legacy --rpc-url http://127.0.0.1:8545 --broadcast --private-key $PRIVATE_KEY -vvvv
forge script script/prelaunch.local.s.sol --legacy --rpc-url http://127.0.0.1:8545 --broadcast --private-key $PRIVATE_KEY -vvvv
Expand Down
83 changes: 83 additions & 0 deletions script/lpeth.deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
pragma solidity >=0.8.25;

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";

// 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(0x76302e312e300000000000000000000000000000000000000000000000000000); // "v0.1.0"

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

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 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, unsETH: unsETHProxy, treasury: address(0) });

address lpETH_impl = address(new LpETH{ salt: salt }(config));
LpETH lpETHProxy = LpETH(payable(address(new ERC1967Proxy{ salt: salt }(lpETH_impl, ""))));
lpETHProxy.initialize();
lpToken.transferOwnership(address(lpETHProxy));
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));

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 stETHAdapter = new StETHAdapter();
registryProxy.setAdapter(STETH_TOKEN, stETHAdapter);
console2.log("StETH Adapter: %s", address(stETHAdapter));

address SAFE = 0x5542b58080FEE48dBE6f38ec0135cE9011519d96;
lpETHProxy.transferOwnership(SAFE);
unsETHProxy.transferOwnership(SAFE);
registryProxy.transferOwnership(SAFE);
vm.stopBroadcast();
}
}
39 changes: 39 additions & 0 deletions script/new_adapter.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pragma solidity >=0.8.25;

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";

// 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(0x76302e312e300000000000000000000000000000000000000000000000000000); // "v0.1.0"

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

Adapter swETHAdapter = new SwETHAdapter();
console2.log("SwtETH Adapter: %s", address(swETHAdapter));

vm.stopBroadcast();
}
}
2 changes: 1 addition & 1 deletion script/prelaunch.deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract DeployPrelaunch is Script {
function run() public {
Config memory cfg = Config({
cap: 80_000 ether,
deadline: block.timestamp + 4 weeks,
deadline: 1_728_746_087,
minLockup: 1,
maxLockup: 52,
epochLength: 604_800,
Expand Down
19 changes: 14 additions & 5 deletions src/lpETH/LpETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ import { UUPSUpgradeable } from "@openzeppelin/upgradeable/proxy/utils/UUPSUpgra

uint256 constant UNSETH_EXPIRATION_TIME = 3 days + 12 hours;
UD60x18 constant BASE_FEE = UD60x18.wrap(0.0005e18);
UD60x18 constant K = UD60x18.wrap(4.5e18);
UD60x18 constant K = UD60x18.wrap(3.5e18);
UD60x18 constant RELAYER_CUT = UD60x18.wrap(0.025e18);
UD60x18 constant TREASURY_CUT = UD60x18.wrap(0.2e18);
UD60x18 constant MIN_LP_CUT = UD60x18.wrap(0.2e18);
UD60x18 constant MIN_LP_CUT = UD60x18.wrap(0.33e18);

struct ConstructorConfig {
Registry registry;
Expand Down Expand Up @@ -244,15 +244,24 @@ contract LpETH is
emit Withdraw(msg.sender, amount, lpShares, requestId);
}

function quote(address asset, uint256 amount) external view returns (uint256 out) {
function quote(address asset, uint256 amount) external view returns (uint256 out, uint256 fee) {
Adapter adapter = REGISTRY.adapters(asset);
if (address(adapter) == address(0)) revert ErrorInvalidAsset(asset);
SwapParams memory p = _getSwapParams(asset, adapter);
uint256 ethExpected = adapter.previewWithdraw(amount);
out = _quote(asset, ethExpected, p);
fee = ethExpected - out;
}

function swap(address asset, uint256 amount, uint256 minOut) external nonreentrant returns (uint256 out) {
function swap(
address asset,
uint256 amount,
uint256 minOut
)
external
nonreentrant
returns (uint256 out, uint256 fee)
{
Data storage $ = _loadStorageSlot();
Adapter adapter = REGISTRY.adapters(asset);
if (address(adapter) == address(0)) revert ErrorInvalidAsset(asset);
Expand All @@ -270,7 +279,7 @@ contract LpETH is
(uint256 tokenId, uint256 amountExpected) = UNSETH.requestWithdraw(asset, amount);

(out) = _quote(asset, amountExpected, p);
uint256 fee = amountExpected - out;
fee = amountExpected - out;

// Revert if slippage threshold is exceeded, i.e. if `out` is less than `minOut`
if (out < minOut) revert ErrorSlippage(out, minOut);
Expand Down
16 changes: 9 additions & 7 deletions src/periphery/PreLaunch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract PreLaunch is Initializable, OwnableUpgradeable, UUPSUpgradeable {
uint256 public totalDeposits; // Total deposits
address public votingEscrow; // Voting escrow contract
address payable lpEth; // LP token for lpETH
uint96 claimableTimestamp; // Timestamp when deposits become claimable
uint96 public claimableTimestamp; // Timestamp when deposits become claimable
uint256 lpEthReceived = 0;

mapping(address account => Lockup) internal lockups;
Expand Down Expand Up @@ -80,12 +80,12 @@ contract PreLaunch is Initializable, OwnableUpgradeable, UUPSUpgradeable {
return lockups[account];
}

function isActive() public view returns (bool) {
return block.timestamp <= deadline;
function isActive() public pure returns (bool) {
return false;
}

function isClaimable() public view returns (bool) {
return votingEscrow != address(0) && lpEthReceived > 0;
return lpEthReceived > 0;
}

function setLpEth(address payable _lpEth) external onlyOwner {
Expand All @@ -100,7 +100,6 @@ contract PreLaunch is Initializable, OwnableUpgradeable, UUPSUpgradeable {
revert();
}
votingEscrow = _votingEscrow;
claimableTimestamp = uint96(block.timestamp);
}

function mintLpEth(uint256 minLpShares) external onlyOwner {
Expand All @@ -114,6 +113,7 @@ contract PreLaunch is Initializable, OwnableUpgradeable, UUPSUpgradeable {

uint256 lpShares = LpETH(lpEth).deposit{ value: address(this).balance }(minLpShares);
lpEthReceived += lpShares;
claimableTimestamp = uint96(block.timestamp - 7 days);
}

function depositETH(uint256 duration) external payable {
Expand Down Expand Up @@ -214,9 +214,11 @@ contract PreLaunch is Initializable, OwnableUpgradeable, UUPSUpgradeable {
// Account for elapsed time since the deposits became claimable in epochs
uint256 epochsElapsedSinceClaimable = (block.timestamp - claimableTimestamp) / EPOCH_LENGTH;
uint256 lpEthAmount = lockup.amount * lpEthReceived / totalDeposits;
SafeTransferLib.safeApprove(lpEth, votingEscrow, lpEthAmount);
if (lockup.duration > epochsElapsedSinceClaimable) {
VotingEscrow(votingEscrow).lockFor(msg.sender, lpEthAmount, lockup.duration - epochsElapsedSinceClaimable);
revert NotClaimable();
// SafeTransferLib.safeApprove(lpEth, votingEscrow, lpEthAmount);
// VotingEscrow(votingEscrow).lockFor(msg.sender, lpEthAmount, lockup.duration -
// epochsElapsedSinceClaimable);
} else {
ERC20(LpETH(lpEth).lpToken()).transfer(msg.sender, lpEthAmount);
}
Expand Down
47 changes: 0 additions & 47 deletions src/periphery/SwapRouter.sol

This file was deleted.

0 comments on commit 5fb269c

Please sign in to comment.