|
| 1 | +--- |
| 2 | +sidebar_position: 14 |
| 3 | +--- |
| 4 | + |
| 5 | +# L2 |
| 6 | + |
| 7 | +Modules exposes Lido MultiChain deployments. [See full info here](https://lido.fi/lido-multichain). |
| 8 | + |
| 9 | +## LidoSDKL2 |
| 10 | + |
| 11 | +This is core module for all L2 functionality. It will throw error if used on with chains that are not currently supported. |
| 12 | + |
| 13 | +| **Chain** | **wsETH** | **stETH+(un)Wrap** | |
| 14 | +| ---------------- | --------- | ------------------ | |
| 15 | +| Optimism Sepolia | ✅ | ✅ | |
| 16 | +| Optmism | ✅ | ✅ | |
| 17 | +| 🔜 | | | |
| 18 | + |
| 19 | +Use this helper to understand which contracts are supported on chain: |
| 20 | + |
| 21 | +```ts |
| 22 | +import { |
| 23 | + LidoSDKL2, |
| 24 | + LIDO_L2_CONTRACT_NAMES, |
| 25 | + CHAINS, |
| 26 | +} from '@lidofinance/lido-ethereum-sdk'; |
| 27 | + |
| 28 | +LidoSDKL2.isContractAvailableOn( |
| 29 | + LIDO_L2_CONTRACT_NAMES.wsteth, |
| 30 | + CHAINS.OptimismSepolia, |
| 31 | +); // true |
| 32 | +// Example |
| 33 | +LidoSDKL2.isContractAvailableOn(LIDO_L2_CONTRACT_NAMES.steth, CHAINS.Arbitrum); // false |
| 34 | +``` |
| 35 | + |
| 36 | +### Fields |
| 37 | + |
| 38 | +- `wsteth`: see [LidoSDKL2Wsteth](#lidosdkl2wsteth) |
| 39 | +- `steth`: see [LidoSDKL2Steth](#lidosdkl2steth) |
| 40 | + |
| 41 | +### Methods |
| 42 | + |
| 43 | +On L2 with stETH deployments bridged wstETH is wrapped to stETH. And stETH is unwrapped to wstETH. Those semantics are upkept in SDK with more explicit naming. See [LIP-22](https://github.com/lidofinance/lido-improvement-proposals/blob/develop/LIPS/lip-22.md#rebasable-token-steth-on-l2) for more details. |
| 44 | + |
| 45 | +#### Wrap bridged wstETH to stETH |
| 46 | + |
| 47 | +To wrap stETH you first need to approve stETH to wrap contract: |
| 48 | + |
| 49 | +```ts |
| 50 | +import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; |
| 51 | + |
| 52 | +const lidoSDK = new LidoSDK({ |
| 53 | + rpcUrls: ['https://rpc-url'], |
| 54 | + chainId: 11155420, // OP sepolia |
| 55 | + web3Provider: LidoSDKCore.createWeb3Provider(11155420, window.ethereum), |
| 56 | +}); |
| 57 | + |
| 58 | +// get existing allowance |
| 59 | +const allowance = await lidoSDK.l2.getWstethForWrapAllowance(); |
| 60 | + |
| 61 | +// if value is more than allowance perform approve |
| 62 | +if (allowance < value) { |
| 63 | + const approveResult = await lidoSDK.wrap.approveWstethForWrap({ |
| 64 | + value, |
| 65 | + callback, |
| 66 | + }); |
| 67 | +} |
| 68 | + |
| 69 | +// wrap wstETH |
| 70 | +const wrapTx = await lidoSDK.wrap.wrapWstethToSteth({ value, callback }); |
| 71 | + |
| 72 | +const { stethReceived, wstethWrapped } = wrapTx.results; |
| 73 | +``` |
| 74 | + |
| 75 | +#### Unwrap stETH to wstETH |
| 76 | + |
| 77 | +```ts |
| 78 | +// unwrap stETH to receive wstETH |
| 79 | +const unwrapTx = await lidoSDK.l2.unwrapStethToWsteth({ |
| 80 | + value: unwrapAmount, |
| 81 | + callback, |
| 82 | +}); |
| 83 | + |
| 84 | +console.log(unwrapTx.result.stethUnwrapped, unwrapTx.result.wstethReceived); |
| 85 | +``` |
| 86 | + |
| 87 | +### Wrap utilities |
| 88 | + |
| 89 | +For all transaction methods helper methods are available similar to `stake` module: |
| 90 | + |
| 91 | +- `...populateTX`: returns ready to sign transaction object with all data encoded |
| 92 | +- `...simulateTX`: performs dry-ran of the transaction to see if it will execute on the network |
| 93 | + |
| 94 | +## LidoSDKL2Wsteth |
| 95 | + |
| 96 | +This submodule is built on top of existing ERC20 modules and has extra functionality. See docs for all [ERC20 related methods](./w-steth.md). |
| 97 | +For original L2 ABI functionality use `.getL2Contract()` and get raw Viem contract instance. |
| 98 | + |
| 99 | +## LidoSDKL2Steth |
| 100 | + |
| 101 | +This submodule is built on top of existing ERC20 modules but has extra L2 stETH related features. See docs for all [ERC20 related methods](./w-steth.md). |
| 102 | +For original L2 ABI functionality use `.getL2Contract()` and get raw Viem contract instance. |
| 103 | + |
| 104 | +```ts |
| 105 | +import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; |
| 106 | + |
| 107 | +const lidoSDK = new LidoSDK({ |
| 108 | + rpcUrls: ['https://rpc-url'], |
| 109 | + chainId: 11155420, // OP sepolia |
| 110 | + web3Provider: LidoSDKCore.createWeb3Provider(11155420, window.ethereum), |
| 111 | +}); |
| 112 | + |
| 113 | +// balance of stETH for account in shares |
| 114 | +const balanceShares = await lidoSDK.l2.steth.balanceShares(address); |
| 115 | + |
| 116 | +// transferring shares is equivalent to transferring corresponding amount of stETH |
| 117 | +const transferTx = await lidoSDK.l2.steth.transferShares({ |
| 118 | + account, |
| 119 | + amount, |
| 120 | + to, |
| 121 | +}); |
| 122 | + |
| 123 | +// converting stETH amount to shares trough on-chain call based on actual share rate |
| 124 | +// This also can be used to convert stETH to wstETH as 1 wstETH = 1 share |
| 125 | +const shares = await lidoSDK.l2.steth.convertToShares(1000n); |
| 126 | +// reverse |
| 127 | +const steth = await lidoSDK.l2.steth.convertToSteth(1000n); |
| 128 | + |
| 129 | +// total supply of shares and ether in protocol |
| 130 | +const totalShares = await lidoSDK.totalShares(); |
| 131 | +``` |
0 commit comments