编译器
0.8.21+commit.d9974bed
文件 1 的 9:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 9:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
文件 3 的 9:ILightAccountFactory.sol
pragma solidity ^0.8.9;
interface ILightAccountFactory {
function createAccount(address owner, uint256 salt) external returns (address ret);
function getAddress(address owner, uint256 salt) external view returns (address);
}
文件 4 的 9:ISocketVault.sol
pragma solidity ^0.8.9;
interface ISocketVault {
function depositToAppChain(address receiver_, uint256 amount_, uint256 msgGasLimit_, address connector_)
external
payable;
function __token() external view returns (address);
function getMinFees(address connector, uint256 minGasLimit) external view returns (uint256);
}
文件 5 的 9:IStETH.sol
pragma solidity ^0.8.9;
import {IERC20} from "../../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
interface IStETH is IERC20 {
function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);
function getSharesByPooledEth(uint256 _pooledEthAmount) external view returns (uint256);
function submit(address _referral) external payable returns (uint256);
}
文件 6 的 9:IWETH.sol
pragma solidity >=0.5.0;
import {IERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint256) external;
}
文件 7 的 9:IWstETH.sol
pragma solidity ^0.8.9;
import {IERC20} from "../../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IStETH} from "./IStETH.sol";
interface IWstETH is IERC20 {
function stETH() external view returns (IStETH);
function wrap(uint256 _stETHAmount) external returns (uint256 wstETHAmount);
}
文件 8 的 9:LyraWstETHZapper.sol
pragma solidity ^0.8.9;
import {IERC20} from "../../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {ISocketVault} from "../interfaces/ISocketVault.sol";
import {ILightAccountFactory} from "../interfaces/ILightAccountFactory.sol";
import {Ownable} from "../../lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import {IWstETH} from "../interfaces/wstETH/IWstETH.sol";
import {IStETH} from "../interfaces/wstETH/IStETH.sol";
import {IWETH} from "../interfaces/IWETH.sol";
contract LyraWstETHZapper is Ownable {
IWETH public immutable weth;
IWstETH public immutable wstETH;
IStETH public immutable stETH;
address public constant lightAccountFactory = 0x000000893A26168158fbeaDD9335Be5bC96592E2;
constructor(address _weth, address _wstETH) Ownable() {
weth = IWETH(_weth);
wstETH = IWstETH(_wstETH);
stETH = IStETH(wstETH.stETH());
}
function recover(address token, uint256 amount) external onlyOwner {
IERC20(token).transfer(msg.sender, amount);
_returnAllEth();
}
function estimateWstethReceived(
uint256 amountEth,
address socketVault,
uint256 gasLimit,
address connector,
bool takeOutFee
) external view returns (uint256) {
uint256 socketFee = 0;
if (takeOutFee) {
socketFee = ISocketVault(socketVault).getMinFees(connector, gasLimit);
}
uint256 depositAmount = amountEth - socketFee;
return wstETH.stETH().getSharesByPooledEth(depositAmount);
}
function zapETH(address socketVault, bool isSCW, uint256 gasLimit, address connector) external payable {
_wrapETHAndDeposit(socketVault, isSCW, gasLimit, connector);
}
function zapWETH(uint256 amount, address socketVault, bool isSCW, uint256 gasLimit, address connector)
external
payable
{
weth.transferFrom(msg.sender, address(this), amount);
weth.withdraw(weth.balanceOf(address(this)));
_wrapETHAndDeposit(socketVault, isSCW, gasLimit, connector);
}
function _wrapETHAndDeposit(address socketVault, bool isSCW, uint256 gasLimit, address connector) internal {
uint256 ethBalance = address(this).balance;
uint256 socketFee = ISocketVault(socketVault).getMinFees(connector, gasLimit);
uint256 depositAmount = ethBalance - socketFee;
stETH.submit{value: depositAmount}(address(this));
stETH.approve(address(wstETH), depositAmount);
wstETH.wrap(depositAmount);
_depositAllWstETH(socketVault, gasLimit, connector, socketFee, _getL2Receiver(isSCW));
}
function zapStETH(uint256 amount, address socketVault, bool isSCW, uint256 gasLimit, address connector)
external
payable
{
stETH.transferFrom(msg.sender, address(this), amount);
stETH.approve(address(wstETH), amount);
wstETH.wrap(amount);
uint256 socketFee = ISocketVault(socketVault).getMinFees(connector, gasLimit);
_depositAllWstETH(socketVault, gasLimit, connector, socketFee, _getL2Receiver(isSCW));
}
function _depositAllWstETH(
address socketVault,
uint256 gasLimit,
address connector,
uint256 socketFee,
address recipient
) internal {
uint256 amount = wstETH.balanceOf(address(this));
wstETH.approve(socketVault, type(uint256).max);
ISocketVault(socketVault).depositToAppChain{value: socketFee}(recipient, amount, gasLimit, connector);
_returnAllEth();
}
function _getL2Receiver(bool isScwWallet) internal view returns (address) {
if (isScwWallet) {
return ILightAccountFactory(lightAccountFactory).getAddress(msg.sender, 0);
} else {
return msg.sender;
}
}
function _returnAllEth() internal {
payable(msg.sender).transfer(address(this).balance);
}
receive() external payable {}
}
文件 9 的 9:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
{
"compilationTarget": {
"src/helpers/LyraWstETHZapper.sol": "LyraWstETHZapper"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 2000
},
"remappings": [
":@openzeppelin/=lib/openzeppelin-contracts/",
":account-abstraction/=lib/account-abstraction/contracts/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":openzeppelin/=lib/openzeppelin-contracts/contracts/",
":relay-context-contracts/=lib/relay-context-contracts/contracts/"
]
}
[{"inputs":[{"internalType":"address","name":"_weth","type":"address"},{"internalType":"address","name":"_wstETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"uint256","name":"amountEth","type":"uint256"},{"internalType":"address","name":"socketVault","type":"address"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"address","name":"connector","type":"address"},{"internalType":"bool","name":"takeOutFee","type":"bool"}],"name":"estimateWstethReceived","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lightAccountFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"recover","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stETH","outputs":[{"internalType":"contract IStETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IWETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wstETH","outputs":[{"internalType":"contract IWstETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"socketVault","type":"address"},{"internalType":"bool","name":"isSCW","type":"bool"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"address","name":"connector","type":"address"}],"name":"zapETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"socketVault","type":"address"},{"internalType":"bool","name":"isSCW","type":"bool"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"address","name":"connector","type":"address"}],"name":"zapStETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"socketVault","type":"address"},{"internalType":"bool","name":"isSCW","type":"bool"},{"internalType":"uint256","name":"gasLimit","type":"uint256"},{"internalType":"address","name":"connector","type":"address"}],"name":"zapWETH","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]