Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zap wsteth bridge #73

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .env.wsteth.manta_sepolia
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Detailed info: https://github.com/lidofinance/lido-l2#Project-Configuration

# ############################
# RPCs
# ############################

RPC_ETH_SEPOLIA=https://rpc.ankr.com/eth_sepolia
RPC_OPT_SEPOLIA=https://manta-sepolia.rpc.caldera.xyz/http
RPC_MANTA_SEPOLIA=https://manta-sepolia.rpc.caldera.xyz/http

# ############################
# Etherscan
# ############################

ETHERSCAN_API_KEY_ETH=
ETHERSCAN_API_KEY_OPT=
ETHERSCAN_API_KEY_MANTA=

# ############################
# Bridge/Gateway Deployment
# ############################

# Address of the token to deploy the bridge/gateway for
TOKEN=0xB82381A3fBD3FaFA77B3a7bE693342618240067b

# Name of the network environments used by deployment scripts.
# Might be one of: "mainnet", "sepolia".
NETWORK=sepolia

# Private key of the deployer account used for deployment process
ETH_DEPLOYER_PRIVATE_KEY=090cf6a293b034926caf9bb6ac41390be6bb4aa7f7cd3ea3ec2118a6784f0230
OPT_DEPLOYER_PRIVATE_KEY=090cf6a293b034926caf9bb6ac41390be6bb4aa7f7cd3ea3ec2118a6784f0230

# 0x32A0E5828B62AAb932362a4816ae03b860b65e83 is the Lido DAO Agent
L1_PROXY_ADMIN=0x32A0E5828B62AAb932362a4816ae03b860b65e83
L1_BRIDGE_ADMIN=0x32A0E5828B62AAb932362a4816ae03b860b65e83
L1_DEPOSITS_ENABLED=true
L1_WITHDRAWALS_ENABLED=true
L1_DEPOSITS_ENABLERS=["0x32A0E5828B62AAb932362a4816ae03b860b65e83"]
L1_DEPOSITS_DISABLERS="["0x32A0E5828B62AAb932362a4816ae03b860b65e83", "0xAf5B6AE540fCf3BD76f1b4C83fC87143932AAd09"]"
L1_WITHDRAWALS_ENABLERS=["0x32A0E5828B62AAb932362a4816ae03b860b65e83"]
L1_WITHDRAWALS_DISABLERS="["0x32A0E5828B62AAb932362a4816ae03b860b65e83", "0xAf5B6AE540fCf3BD76f1b4C83fC87143932AAd09"]"

L2_PROXY_ADMIN=0xA74Eb604b0995409F7203BDc3Ae2c7a001873eEb
L2_BRIDGE_ADMIN=0xA74Eb604b0995409F7203BDc3Ae2c7a001873eEb
L2_DEPOSITS_ENABLED=true
L2_WITHDRAWALS_ENABLED=true
L2_DEPOSITS_ENABLERS=["0xA74Eb604b0995409F7203BDc3Ae2c7a001873eEb"]
L2_DEPOSITS_DISABLERS="["0xA74Eb604b0995409F7203BDc3Ae2c7a001873eEb", "0xAf5B6AE540fCf3BD76f1b4C83fC87143932AAd09"]"
L2_WITHDRAWALS_ENABLERS=["0xA74Eb604b0995409F7203BDc3Ae2c7a001873eEb"]
L2_WITHDRAWALS_DISABLERS="["0xA74Eb604b0995409F7203BDc3Ae2c7a001873eEb", "0xAf5B6AE540fCf3BD76f1b4C83fC87143932AAd09"]"

# ############################
# Integration & E2E Testing
# ############################

TESTING_OPT_NETWORK=sepolia
TESTING_OPT_L1_TOKEN=0xB82381A3fBD3FaFA77B3a7bE693342618240067b
TESTING_OPT_L2_TOKEN=0x24B47cd3A74f1799b32B2de11073764Cb1bb318B
TESTING_OPT_L1_ERC20_TOKEN_BRIDGE=0x4Abf633d9c0F4aEebB4C2E3213c7aa1b8505D332
TESTING_OPT_L2_ERC20_TOKEN_BRIDGE=0xdBA2760246f315203F8B716b3a7590F0FFdc704a

# ############################
# Integration Testing
# ############################

TESTING_USE_DEPLOYED_CONTRACTS=true
TESTING_L1_TOKENS_HOLDER=

# ############################
# E2E Testing
# ############################

TESTING_PRIVATE_KEY=
80 changes: 80 additions & 0 deletions contracts/manta/StakeHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-FileCopyrightText: 2022 Lido <info@lido.fi>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.10;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {IERC20Bridged} from "../token/interfaces/IERC20Bridged.sol";


interface IL1TokenBridge {
function depositERC20To(
address l1Token_,
address l2Token_,
address to_,
uint256 amount_,
uint32 l2Gas_,
bytes calldata data_
) external;
}

error ZeroAddress();

error WrapETHFailed();

error ZeroAmount();

error InsufficientWstETHReceived();

contract StakeHelper is ReentrancyGuard {
IERC20 public immutable l1Token;

address public immutable l2Token;

IL1TokenBridge public immutable l1TokenBridge;

event Stake(address indexed staker, uint256 indexed amount);

constructor(
address l1Token_,
address l2Token_,
address l1TokenBridge_
) {
l1Token = IERC20(l1Token_);
l2Token = l2Token_;
l1TokenBridge = IL1TokenBridge(l1TokenBridge_);
}

// Wrap sender's ETH to wstETH and bridge to L2
function stakeETH(
address to,
uint32 l2Gas_,
bytes calldata data_
) external payable nonReentrant {
if (to == address(0)) {
revert ZeroAddress();
}
uint256 amount = msg.value;
if (amount == 0) {
revert ZeroAmount();
}
// wstETH on L1 will automatically wrap sent Ether in `receive` function
(bool success, ) = address(l1Token).call{value: msg.value}("");
if (!success) {
revert WrapETHFailed();
}
// double check amount
if (l1Token.balanceOf(address(this)) < amount) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ sorry, it wouldn't work for wstETH (wstETH balance is defined by the stETH shares https://docs.lido.fi/guides/lido-tokens-integration-guide#wsteth)

revert InsufficientWstETHReceived();
}
// now the wstETH is at this contract, bridge to L2 in behalf of the sender
// 1. approve token bridge to use `l1Token` of this contract
l1Token.approve(address(l1TokenBridge), amount);
// 2. actual cross bridge transfer
l1TokenBridge.depositERC20To(address(l1Token), l2Token, msg.sender, amount, l2Gas_, data_);

emit Stake(msg.sender, amount);
}

}
Loading