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

Add SwapAndBridge feature #64

Merged
merged 115 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 110 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
4a284e7
Add SwapAndBridge contract and Lido deployment and tests
ricott1 Mar 18, 2024
5e01bf9
SwapAndBridge: Remove duplicate variables, add check against 0 addres…
ricott1 Mar 19, 2024
ee0e494
SwapAndBridge: Remove duplicate variables, add check against 0 addres…
ricott1 Mar 19, 2024
3fc7446
Added e2e tests.
ricott1 Mar 19, 2024
d9c2d4c
clean up deploy.sh
ricott1 Mar 19, 2024
7ebc48a
SwapAndBridge.sol: add docs to constructor
ricott1 Mar 19, 2024
ee9100b
Clean up test
ricott1 Mar 19, 2024
b9850bc
update .env.example
ricott1 Mar 19, 2024
b5af0f9
Clean up deployment script
ricott1 Mar 19, 2024
8998fe0
Clean up env file
ricott1 Mar 19, 2024
eb3aad8
Add more balance for tests
ricott1 Mar 19, 2024
15dd30f
Add unit tests
ricott1 Mar 19, 2024
473764d
forge install: solady
ricott1 Mar 21, 2024
6587f50
remove unused contracts, update tests
ricott1 Mar 21, 2024
52276b2
automate deployment
ricott1 Mar 22, 2024
7b2c324
fix env.example
ricott1 Mar 22, 2024
1fc3c12
cleanup SwapAndBridge tests
ricott1 Mar 22, 2024
c1482a2
address review
ricott1 Apr 9, 2024
b4ca2e1
update contract license
ricott1 Apr 9, 2024
b488ae8
address review
ricott1 Apr 17, 2024
8f69a20
Fix E2E tests for Diva
ricott1 Apr 23, 2024
2afbc24
Minor fixes to Utils.sol
ricott1 Apr 23, 2024
18e635f
Update Utils.sol with SwapAndBridge functionalities
ricott1 Apr 23, 2024
fd2394a
Fix import in Utils.sol
ricott1 Apr 23, 2024
120e606
Fix import in Utils.sol
ricott1 Apr 23, 2024
ffb028e
Fix variable usage
ricott1 Apr 23, 2024
4e43841
Move env variables to contract constants to fix CI
ricott1 May 2, 2024
6175913
Fix formatting
ricott1 May 2, 2024
476f617
Remove use of env variables
ricott1 May 2, 2024
4c617f1
remove unused TOKEN_HOLDER_PRIV_KEY variable
ricott1 May 2, 2024
1074230
Save temporary data files to local storage
ricott1 May 2, 2024
499e30e
fix fmt
ricott1 May 2, 2024
1d7b0ac
Move e2e tests to script
ricott1 May 3, 2024
8448d9a
Move integration tests to script; add unit tests
ricott1 May 6, 2024
60f6f63
remove old test folder
ricott1 May 6, 2024
e4e218d
Fix integration tests
ricott1 May 7, 2024
3e8ebd5
remove unnecessary function
ricott1 May 7, 2024
eb611f4
Add new unit tests
ricott1 May 7, 2024
76bad91
Add mock contracts
ricott1 May 7, 2024
fa27e1f
Merge branch 'main' into feature/swapAndBridge
ricott1 May 7, 2024
566b65a
add tests for L2WdivETH
ricott1 May 7, 2024
1eab7d6
Merge branch 'feature/swapAndBridge' of https://github.com/LiskHQ/lis…
ricott1 May 7, 2024
9565867
Add AccessControl to VestingWallet
Phanco May 13, 2024
e6f89a6
Add NatSpec comments
Phanco May 13, 2024
9cfb527
Update contract owner
Phanco May 13, 2024
44cadf7
Added NatSpec and beneficiary check
Phanco May 13, 2024
019173b
Remove redundant mappings
ricott1 May 13, 2024
756e6a8
Improve contract interface
ricott1 May 13, 2024
f97e003
Increase test coverage
ricott1 May 13, 2024
740ff40
Update data for Testnet migration (#135)
matjazv May 13, 2024
0264d33
Add address checking to contract
Phanco May 13, 2024
2b6149d
Merge branch 'main' of github.com:LiskHQ/lisk-contracts-private into …
Phanco May 13, 2024
21b2997
Update error message
Phanco May 13, 2024
61cf7ea
Add virtual to functions
Phanco May 13, 2024
8f0e996
Separate beneficiary and owner in VestingWallet (#133)
Phanco May 13, 2024
c6ed62d
Vesting Wallet on Ethereum L1 Mainnet (#123)
Phanco May 13, 2024
84ece85
Merge branch 'main' into feature/swapAndBridge
ricott1 May 14, 2024
a703619
merge main
ricott1 May 31, 2024
7408874
Use OptimismMintableERC20Factory for Diva ERC20
ricott1 Jun 3, 2024
426c7be
remove optimism library
ricott1 Jun 7, 2024
91590fe
Merge branch 'main' into feature/swapAndBridge
ricott1 Jun 7, 2024
e3e2321
remove unnecessary contracts
ricott1 Jun 10, 2024
f55eb52
add deployment scripts
ricott1 Jun 10, 2024
0137ae6
fixing e2e
ricott1 Jun 17, 2024
6fd810d
fix e2e tests
ricott1 Jun 17, 2024
0c9227e
remove optimism lib
ricott1 Jun 17, 2024
9f80c5c
fix e2e tests
ricott1 Jun 17, 2024
17608f6
Merge branch 'main' into feature/swapAndBridge
ricott1 Jun 18, 2024
96058e2
Add Airdrop contract Testnet deployment data (#159)
matjazv Jun 10, 2024
9f95eac
Added L2VotingPowerPaused and L2GovernorPaused contract with test cas…
Phanco Jun 12, 2024
3a214fe
Merkle root for Airdrop contract is set inside deployment script (#161)
matjazv Jun 17, 2024
a8c0e71
Add automated toolings for testing contracts (#151)
matjazv Jun 24, 2024
5879c25
fix env files
ricott1 Jun 24, 2024
e634448
merge development
ricott1 Jun 24, 2024
40e0439
merge
ricott1 Jun 26, 2024
d353b52
Merge branch 'development' into feature/swapAndBridge
ricott1 Jun 26, 2024
930aaac
forge install: openzeppelin-contracts
ricott1 Jun 26, 2024
9ee8aec
forge install: openzeppelin-contracts-upgradeable
ricott1 Jun 26, 2024
37d7a91
forge install: openzeppelin-contracts
ricott1 Jun 26, 2024
0abb15c
forge install: openzeppelin-contracts-upgradeable
ricott1 Jun 26, 2024
6cd5ac1
forge install: forge-std
ricott1 Jun 26, 2024
b518116
cleanup
ricott1 Jun 26, 2024
c042afb
cleanup
ricott1 Jun 26, 2024
1c48dbf
address Slither and Matjaz comments
ricott1 Jun 26, 2024
988ae0c
add extra deployment checks
ricott1 Jun 26, 2024
1299fdc
Update script/swap_and_bridge/example/README.md
ricott1 Jun 27, 2024
635103f
Update pr.yaml
ricott1 Jun 27, 2024
f0f06b9
improving deployment script
ricott1 Jun 27, 2024
7679768
improving testing scripts
ricott1 Jun 27, 2024
c8d9e60
improve test scripts and rename folder
ricott1 Jun 27, 2024
eab7b68
Merge branch 'development' into feature/swapAndBridge
ricott1 Jun 27, 2024
4613fa5
Merge branch 'development' into feature/swapAndBridge
ricott1 Jul 1, 2024
f49d05d
Address review comments
ricott1 Jul 1, 2024
9113490
Fix contracts folder path inside deployment directory
matjazv Jul 1, 2024
3a7370e
Fix typo in e2e test and move contracts to test folder
ricott1 Jul 1, 2024
4847f2e
remove unnecessary interaction with deployment folder
ricott1 Jul 1, 2024
14f0d1c
Merge branch 'development' into feature/swapAndBridge
ricott1 Jul 1, 2024
84620f8
Fix contracts folder path inside deployment directory
matjazv Jul 1, 2024
5f428a6
Merge branch 'development' of github.com:LiskHQ/lisk-contracts into d…
ricott1 Jul 1, 2024
85e8fa1
merge development
ricott1 Jul 1, 2024
8010f9c
add testing contracts
ricott1 Jul 1, 2024
ed7723b
merge
ricott1 Jul 1, 2024
75c96af
merge from development
ricott1 Jul 1, 2024
e5e3fde
fix sed rule
ricott1 Jul 1, 2024
3406aed
remove store of L@_DIVA_TOKEN
ricott1 Jul 1, 2024
1db835a
Improve README file
ricott1 Jul 2, 2024
989ec24
add readme
ricott1 Jul 2, 2024
4a6ed44
fix typo
ricott1 Jul 2, 2024
45c06a5
add readme
ricott1 Jul 2, 2024
28ec78e
change folder structure
ricott1 Jul 3, 2024
3c6ec3b
Update script/swap_and_bridge/README.md
ricott1 Jul 3, 2024
9dc56fb
Merge branch 'development' into feature/swapAndBridge
ricott1 Jul 4, 2024
d19952a
update documentation
ricott1 Jul 11, 2024
78d50b6
Merge branch 'feature/swapAndBridge' of github.com:LiskHQ/lisk-contra…
ricott1 Jul 11, 2024
06ccd8f
Fix slither warning
ricott1 Jul 11, 2024
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
26 changes: 26 additions & 0 deletions .env.example
matjazv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ DETERMINISTIC_ADDRESS_SALT="test_contract_address_salt"
# L1 standard bridge address (Mainnet, Goerli, Sepolia or custom)
L1_STANDARD_BRIDGE_ADDR=0xFBb0621E0B23b5478B630BD55a5f21f67730B0F1

# L2 standard bridge address
L2_STANDARD_BRIDGE_ADDR=0x4200000000000000000000000000000000000010

# L1 USDT token contract address to be bridged to L2
REMOTE_TOKEN_ADDR_USDT=0x0

# L1 RPC URL, e.g. Infura, Alchemy, or your own node
L1_RPC_URL=https://sepolia.infura.io/v3/YOUR_INFURA_KEY

Expand Down Expand Up @@ -76,3 +82,23 @@ L2_FORK_RPC_URL=https://optimism-sepolia.infura.io/v3/YOUR_INFURA_KEY

# Test network default mnemonic
TEST_NETWORK_MNEMONIC="test test test test test test test test test test test junk"

# *************** SWAP AND BRIDGE ***************

# L1 wdivETH token contract address to be bridged to L2
L1_TOKEN_ADDR_DIVA=

# L1 wstETH token contract address to be bridged to L2
L1_TOKEN_ADDR_LIDO=

# L1 custom bridge for wstETH
L1_LIDO_BRIDGE_ADDR=

# L2 wdivETH token contract
L2_TOKEN_ADDR_DIVA=

# L2 wstETH token contract
L2_TOKEN_ADDR_LIDO=

# L2 custom bridge for wstETH
L2_LIDO_BRIDGE_ADDR=
23 changes: 23 additions & 0 deletions .env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ DETERMINISTIC_ADDRESS_SALT="lisk_l2_token_deterministic_salt"
# L1 standard bridge address (Mainnet, Goerli, Sepolia or custom)
L1_STANDARD_BRIDGE_ADDR=0x2658723Bf70c7667De6B25F99fcce13A16D25d08

# L2 standard bridge address
L2_STANDARD_BRIDGE_ADDR=0x4200000000000000000000000000000000000010

# L1 USDT token contract address to be bridged to L2
REMOTE_TOKEN_ADDR_USDT=0xdAC17F958D2ee523a2206206994597C13D831ec7

Expand Down Expand Up @@ -80,3 +83,23 @@ L2_FORK_RPC_URL=https://optimism-sepolia.infura.io/v3/YOUR_INFURA_KEY

# Test network default mnemonic
TEST_NETWORK_MNEMONIC="test test test test test test test test test test test junk"

# *************** SWAP AND BRIDGE ***************

# L1 wdivETH token contract address to be bridged to L2
L1_TOKEN_ADDR_DIVA=

# L1 wstETH token contract address to be bridged to L2
L1_TOKEN_ADDR_LIDO=

# L1 custom bridge for wstETH
L1_LIDO_BRIDGE_ADDR=

# L2 wdivETH token contract
L2_TOKEN_ADDR_DIVA=

# L2 wstETH token contract
L2_TOKEN_ADDR_LIDO=

# L2 custom bridge for wstETH
L2_LIDO_BRIDGE_ADDR=
24 changes: 24 additions & 0 deletions .env.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ DETERMINISTIC_ADDRESS_SALT="lisk_l2_token_salt_test_network"
# L1 standard bridge address (Mainnet, Goerli, Sepolia or custom)
L1_STANDARD_BRIDGE_ADDR=0x1Fb30e446eA791cd1f011675E5F3f5311b70faF5

# L2 standard bridge address
L2_STANDARD_BRIDGE_ADDR=0x4200000000000000000000000000000000000010

# L1 USDT token contract address to be bridged to L2
REMOTE_TOKEN_ADDR_USDT=0x7169d38820dfd117c3fa1f22a697dba58d90ba06

Expand Down Expand Up @@ -79,3 +82,24 @@ L2_FORK_RPC_URL=https://optimism-goerli.infura.io/v3/YOUR_INFURA_KEY

# Test network default mnemonic
TEST_NETWORK_MNEMONIC="test test test test test test test test test test test junk"


# *************** SWAP AND BRIDGE ***************

# L1 wdivETH token contract address to be bridged to L2
L1_TOKEN_ADDR_DIVA=0x91701E62B2DA59224e92C42a970d7901d02C2F24

# L1 wstETH token contract address to be bridged to L2
L1_TOKEN_ADDR_LIDO=0xB82381A3fBD3FaFA77B3a7bE693342618240067b

# L1 custom bridge for wstETH
L1_LIDO_BRIDGE_ADDR=0xdDDbC273a81e6BC49c269Af55d007c08c005ea56

# L2 wdivETH token contract
L2_TOKEN_ADDR_DIVA=

# L2 wstETH token contract
L2_TOKEN_ADDR_LIDO=0xA363167588e8b3060fFFf69519bC440D1D8e4945

# L2 custom bridge for wstETH
L2_LIDO_BRIDGE_ADDR=0x7A7265ae66b094b60D9196fD5d677c11a6A03438
4 changes: 3 additions & 1 deletion documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ This folder contains the following documents essential for understanding the dep

5. [Migration Airdrop Documentation](./airdrop.md): This page explains the technical details concerning design and lifecycle of the migration airdrop smart contract that distributes LSK tokens as a reward to the users that migrated from the Lisk L1 network.

6. [Staking and Lisk DAO Documentation](./staking-governance.md): This page explains the technical details concerning Staking and Lisk DAO. The two topics are combined in one document as they are strongly linked to each other.
6. [Staking and Lisk DAO Documentation](./staking-governance.md): This page explains the technical details concerning Staking and Lisk DAO. The two topics are combined in one document as they are strongly linked to each other.

7. [Overview of the swap-and-bridge feature](./swap-and-bridge.md): This page explains the motivation, technical details, and integration deployments concerning the swap-and-bridge feature.
54 changes: 54 additions & 0 deletions documentation/swap-and-bridge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Overview of the swap-and-bridge feature

The swap-and-bridge feature allows users to swap ETH for an ERC20 Liquid Staking Token (LST) and to bridge it directly to an L2 with a single user interaction. This is achieved by implementing the `SwapAndBridge` contract, handling both conversion and bridging. For better integrating the LST with user interfaces, the contract swaps ETH for the wrapped version of it, that can always be converted back to the underlying LST.

## Motivation

Liquid staking pools allow users to participate in ETH staking without managing their own validator node or owning the full 32 ETH deposit amount. ETH from several users is pooled together and used to register a validator which then shares the rewards with the users. A Liquid Staking Token is an ERC20 token representing one of this staking position. As such, it can be converted back to ETH, while at the same time being freely tradable as an independent token. Furthermore, this token provide the extra yield from the validators reward either by rebasing, i.e. changing the user balance to account for the extra tokens acquired, or, in their wrapped version, by changing the underlying conversion rate to ETH.
gkoumout marked this conversation as resolved.
Show resolved Hide resolved

The swap-and-bridge feature prefers to interact with the wrapped version of a LST, as this tends to be better supported on the UX of several DeFi protocols (see the discussion for Lido's [wstETH](https://docs.lido.fi/contracts/wsteth/#why-use-wsteth)) and since the Optimism standard bridge [does not support rebasing tokens correctly](https://docs.optimism.io/builders/app-developers/bridging/standard-bridge).

A similar result for the end-user (swapping L1 ETH for L2 wrapped LST with a single interaction) can be achieved by using one of the several bridges available. However, this flow likely offers better security guarantees by relying on the L1<-->L2 bridging protocol and also stakes the ETH in the underlying staking pool protocol. Because of this, it should be considered an alternative option to stimulate participation in ETH staking.
gkoumout marked this conversation as resolved.
Show resolved Hide resolved

## Rationale

gkoumout marked this conversation as resolved.
Show resolved Hide resolved
Each `SwapAndBridge` contract supports a single wrapped LST. We specified it to be as compatible as possible with a wide range of protocols. The minimum requirements are that the LST contract exposes the `receive` fallback to perform the staking and conversion of ETH to LST.

The `SwapAndBridge` contract itself uses the `receive` fallback as a shortcut to the the swap-and-bridge flow, so that users can send ETH to the contract and receive L2 LST directly.

The `SwapAndBridge` contract does not include any special role such as contract 'owner' and should not hold any ETH balance, with the notable exception of being the [target of a self-destructing contract](https://solidity-by-example.org/hacks/self-destruct/). Even in this case though, no one is able to extract the ETH balance of the contract. This means that, while no privileged operation can be executed on the contract in case of an emergency (like pausing it), no funds are at risk.

This repository does not include any UI-related code.

## Incident response plan
gkoumout marked this conversation as resolved.
Show resolved Hide resolved

Because no special role is assigned and since we do not deploy any user-facing interface, there are no concrete steps that we can take in case of an emergency. As explained above though, the range of problems that can occur is quite limited:

- If a bug is present in the contract, users can lose at most the amount of ETH sent to perform the swap-and-bridge operation;
- The contract does not hold any mutable property, so the range of possible interactions that could result in a malicious state is limited.

## Specifications

### Constructor

The `SwapAndBridge` contract accepts the following parameters in its contructor:

- `address _l1Bridge`: The address of the L1 bridge contract used to transfer the tokens from the L1 to the L2. This bridge must implement the `depositERC20To` function. See, for instance, the [Optimism `L1StandardBridge` contract](https://github.com/ethereum-optimism/optimism/blob/op-contracts/v1.5.0/packages/contracts-bedrock/src/L1/L1StandardBridge.sol) or the [Lido `IL1ERC20Bridge` interface](https://github.com/lidofinance/lido-l2/blob/main/contracts/optimism/interfaces/IL1ERC20Bridge.sol);
- `address _l1Token`: The address of the L1 LST contract. This contract must implement the `receive` fallback to exchange the ETH sent with the transaction for the underlying LST. See, for instance, the [Lido `WstETH` contract](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.6.12/WstETH.sol#L80) and [relative documentation](https://docs.lido.fi/contracts/wsteth/#staking-shortcut);
- `address _l2Token`: The address of the L2 LST contract. There are no particular restrictions on this contract apart from the usual bridging rules that depend on the bridge used. For instance, the standard bridge and the [`OptimismMintableERC20` standard](https://github.com/ethereum-optimism/optimism/blob/op-contracts/v1.5.0/packages/contracts-bedrock/src/universal/OptimismMintableERC20.sol) requires that this contract specifies `_l1Token` as the relative `REMOTE_TOKEN`.

### Public functions

The `SwapAndBridge` contract exposes the following public/external functions:

- `receive() external payable`: Convenience function allowing users to interact with the contract just by sending ETH. It redirects to `swapAndBridgeTo(msg.sender)`;
- `swapAndBridgeTo(address recipient) public payable`: Convenience function to swap ETH for LST without specifying the minimum amount of LST to be received. It redirects to `swapAndBridgeToWithMinimumAmount(recipient, 0)`;
- `swapAndBridgeToWithMinimumAmount(address recipient, uint256 minL1Tokens) public payable`: The core function performing boht ETH-->LST conversion (by sending ETH to the LST contract) and the L1 LST-->L2 LST bridging (by calling the bridge contract `depositERC20To` function). Several checks are included to ensure that the conversion is succesfull. It is possible to specify a `uint256 minL1Tokens` value larger than 0, in which case the contract will also check that swap resulted in an amount of LST larger than the specified minimum. A value of 0 passed to this function skips this check, allowing for any (non-zero) value to be accepted.

## Integrations

In this repository, we add integration tests and deployment scripts for two concrete liquid staking protocols: [Lido](https://lido.fi/) and [Diva](https://divastaking.com/).

The Diva deployment uses the Op-stack standard bridge as any other ERC20 token. The L2 LST contract can be deployed by running the `7_deployWdivETHContract.sh` script located in the parent folder.

The Lido deployment uses a custom bridge developed to deploy the Lido LST on L2s, as explained and specified in the [lido-l2 repository](https://github.com/lidofinance/lido-l2/tree/main). Because of this, the deployment of the Lido custom bridge and Lido L2 LST token are not part of this repository.
3 changes: 2 additions & 1 deletion foundry.toml
ricott1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[profile.default]
evm_version = "cancun"
src = "src"
out = "out"
libs = ["lib"]
Expand Down Expand Up @@ -37,4 +38,4 @@ wrap_comments = true
[invariant]
runs = 50
depth = 50
fail_on_revert = false
fail_on_revert = false
17 changes: 17 additions & 0 deletions script/7_deployWdivETHContract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

echo "Instructing the shell to exit immediately if any command returns a non-zero exit status..."
set -e
echo "Done."

echo "Navigating to the root directory of the project..."
cd ../
echo "Done."

echo "Setting environment variables..."
source .env
echo "Done."

echo "Deploying OptimismMintableERC20 wdivETH token smart contract..."
cast send --rpc-url $L2_RPC_URL "0x4200000000000000000000000000000000000012" "createOptimismMintableERC20WithDecimals(address,string,string,uint8)" $L1_TOKEN_ADDR_DIVA "Wrapped Diva Ether Token" wdivETH 18 --private-key $PRIVATE_KEY
echo "Done."
45 changes: 45 additions & 0 deletions script/8_deploySwapAndBridge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

echo "Instructing the shell to exit immediately if any command returns a non-zero exit status..."
set -e
echo "Done."

echo "Navigating to the root directory of the project..."
cd ../
echo "Done."

echo "Setting environment variables..."
source .env
echo "Done."

echo "Deploying and if enabled verifying SwapAndBridge smart contract for DIVA protocol..."
if [ -z "$CONTRACT_VERIFIER" ]
then
forge script --rpc-url="$L1_RPC_URL" --broadcast -vvvv script/contracts/L1/SwapAndBridge.s.sol:SwapAndBridgeScript $L1_STANDARD_BRIDGE_ADDR $L1_TOKEN_ADDR_DIVA $L2_TOKEN_ADDR_DIVA --sig 'run(address,address,address)'
else
if [ $CONTRACT_VERIFIER = "blockscout" ]
then
forge script --rpc-url="$L1_RPC_URL" --broadcast --verify --verifier blockscout --verifier-url $L1_VERIFIER_URL -vvvv script/contracts/L1/SwapAndBridge.s.sol:SwapAndBridgeScript $L1_STANDARD_BRIDGE_ADDR $L1_TOKEN_ADDR_DIVA $L2_TOKEN_ADDR_DIVA --sig 'run(address,address,address)'
fi
if [ $CONTRACT_VERIFIER = "etherscan" ]
then
forge script --rpc-url="$L1_RPC_URL" --broadcast --verify --verifier etherscan --etherscan-api-key="$L1_ETHERSCAN_API_KEY" --verifier-url $L1_VERIFIER_URL -vvvv script/contracts/L1/SwapAndBridge.s.sol:SwapAndBridgeScript $L1_STANDARD_BRIDGE_ADDR $L1_TOKEN_ADDR_DIVA $L2_TOKEN_ADDR_DIVA --sig 'run(address,address,address)'
fi
fi
echo "Done."

echo "Deploying and if enabled verifying SwapAndBridge smart contract for LIDO protocol..."
if [ -z "$CONTRACT_VERIFIER" ]
then
forge script --rpc-url="$L1_RPC_URL" --broadcast -vvvv script/contracts/L1/SwapAndBridge.s.sol:SwapAndBridgeScript $L1_LIDO_BRIDGE_ADDR $L1_TOKEN_ADDR_LIDO $L2_TOKEN_ADDR_LIDO --sig 'run(address,address,address)'
else
if [ $CONTRACT_VERIFIER = "blockscout" ]
then
forge script --rpc-url="$L1_RPC_URL" --broadcast --verify --verifier blockscout --verifier-url $L1_VERIFIER_URL -vvvv script/contracts/L1/SwapAndBridge.s.sol:SwapAndBridgeScript $L1_LIDO_BRIDGE_ADDR $L1_TOKEN_ADDR_LIDO $L2_TOKEN_ADDR_LIDO --sig 'run(address,address,address)'
fi
if [ $CONTRACT_VERIFIER = "etherscan" ]
then
forge script --rpc-url="$L1_RPC_URL" --broadcast --verify --verifier etherscan --etherscan-api-key="$L1_ETHERSCAN_API_KEY" --verifier-url $L1_VERIFIER_URL -vvvv script/contracts/L1/SwapAndBridge.s.sol:SwapAndBridgeScript $L1_LIDO_BRIDGE_ADDR $L1_TOKEN_ADDR_LIDO $L2_TOKEN_ADDR_LIDO --sig 'run(address,address,address)'
fi
fi
echo "Done."
25 changes: 25 additions & 0 deletions script/contracts/L1/SwapAndBridge.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.23;

import { Script, console2 } from "forge-std/Script.sol";
import { SwapAndBridge } from "src/L1/SwapAndBridge.sol";

/// @title SwapAndBridgeScript - SwapAndBridge deployment script
/// @notice This contract is used to deploy SwapAndBridge contract.
contract SwapAndBridgeScript is Script {
/// @notice This function deploys the SwapAndBridge contract.
function run(address _l1Bridge, address _l1Token, address _l2Token) public {
assert(_l1Bridge != address(0));
assert(_l1Token != address(0));
assert(_l2Token != address(0));
// Deployer's private key. PRIVATE_KEY is set in .env file.
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");

console2.log("Deploying SwapAndBridge contract...");
vm.startBroadcast(deployerPrivateKey);
SwapAndBridge swapAndBridge = new SwapAndBridge(_l1Bridge, _l1Token, _l2Token);
vm.stopBroadcast();
assert(address(swapAndBridge) != address(0));
console2.log("SwapAndBridge successfully deployed at address: %s", address(swapAndBridge));
}
}
15 changes: 15 additions & 0 deletions script/swap_and_bridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Test Scripts for SwapAndBridge

Tests in this folder are run as script as they require to be run in a Sepolia forked environment, since they depend on the contracts owned and deployed by Lido and Diva teams.

Before running them, start an L1 and L2 fork node using the shell scripts `runL1TestNetwork.sh` and `runL2TestNetwork.sh` inside [script](../..) folder respectively and make sure to run the tests from this folder.
ricott1 marked this conversation as resolved.
Show resolved Hide resolved

Notice that these tests may fail fo reasons unrelated to the implementation of this feature, but rather because of problems with the target integration (for instance if the target LST contract does not mint new LSTs). If the `L2_TOKEN_ADDR_DIVA` value is not set in the `.env` file, the script will automatically deploy a test contract. Notice however that this deployment may fail if the very same test contract has already been deployed in your forked environment (which could be the case, for instance, if you run the scripts multiple times). In this case, just restart the fork nodes or modify the test contract name.

## E2E Tests

These tests simulate the user flow for transferring ETH on the L1 to either Lido or Diva LST on the Lisk L2 in a single transaction. Run them with `./e2e_test.sh`.

## Integration Tests

These tests run some checks on the interaction between the `SwapAndBridge` contract and the Lido and Diva LSTs. Run them with `./integration_test.sh`.
Loading
Loading