-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from lidofinance/feature/si-1524-steth-on-opt…
…imism-in-sdk Docs and optimism
- Loading branch information
Showing
23 changed files
with
168 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/sdk/methods/_category_.json → docs/sdk/modules/_category_.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"label": "Methods", | ||
"label": "Modules", | ||
"position": 3, | ||
"link": { | ||
"type": "generated-index" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
--- | ||
sidebar_position: 14 | ||
--- | ||
|
||
# L2 | ||
|
||
Modules exposes Lido MultiChain deployments. [See full info here](https://lido.fi/lido-multichain). | ||
|
||
## LidoSDKL2 | ||
|
||
This is core module for all L2 functionality. It will throw error if used on with chains that are not currently supported. | ||
|
||
| **Chain** | **wsETH** | **stETH+(un)Wrap** | | ||
| ---------------- | --------- | ------------------ | | ||
| Optimism Sepolia | ✅ | ✅ | | ||
| Optmism | ✅ | ✅ | | ||
| 🔜 | | | | ||
|
||
Use this helper to understand which contracts are supported on chain: | ||
|
||
```ts | ||
import { | ||
LidoSDKL2, | ||
LIDO_L2_CONTRACT_NAMES, | ||
CHAINS, | ||
} from '@lidofinance/lido-ethereum-sdk'; | ||
|
||
LidoSDKL2.isContractAvailableOn( | ||
LIDO_L2_CONTRACT_NAMES.wsteth, | ||
CHAINS.OptimismSepolia, | ||
); // true | ||
// Example | ||
LidoSDKL2.isContractAvailableOn(LIDO_L2_CONTRACT_NAMES.steth, CHAINS.Arbitrum); // false | ||
``` | ||
|
||
### Fields | ||
|
||
- `wsteth`: see [LidoSDKL2Wsteth](#lidosdkl2wsteth) | ||
- `steth`: see [LidoSDKL2Steth](#lidosdkl2steth) | ||
|
||
### Methods | ||
|
||
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. | ||
|
||
#### Wrap bridged wstETH to stETH | ||
|
||
To wrap stETH you first need to approve stETH to wrap contract: | ||
|
||
```ts | ||
import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; | ||
|
||
const lidoSDK = new LidoSDK({ | ||
rpcUrls: ['https://rpc-url'], | ||
chainId: 11155420, // OP sepolia | ||
web3Provider: LidoSDKCore.createWeb3Provider(11155420, window.ethereum), | ||
}); | ||
|
||
// get existing allowance | ||
const allowance = await lidoSDK.l2.getWstethForWrapAllowance(); | ||
|
||
// if value is more than allowance perform approve | ||
if (allowance < value) { | ||
const approveResult = await lidoSDK.wrap.approveWstethForWrap({ | ||
value, | ||
callback, | ||
}); | ||
} | ||
|
||
// wrap wstETH | ||
const wrapTx = await lidoSDK.wrap.wrapWstethToSteth({ value, callback }); | ||
|
||
const { stethReceived, wstethWrapped } = wrapTx.results; | ||
``` | ||
|
||
#### Unwrap stETH to wstETH | ||
|
||
```ts | ||
// unwrap stETH to receive wstETH | ||
const unwrapTx = await lidoSDK.l2.unwrapStethToWsteth({ | ||
value: unwrapAmount, | ||
callback, | ||
}); | ||
|
||
console.log(unwrapTx.result.stethUnwrapped, unwrapTx.result.wstethReceived); | ||
``` | ||
|
||
### Wrap utilities | ||
|
||
For all transaction methods helper methods are available similar to `stake` module: | ||
|
||
- `...populateTX`: returns ready to sign transaction object with all data encoded | ||
- `...simulateTX`: performs dry-ran of the transaction to see if it will execute on the network | ||
|
||
## LidoSDKL2Wsteth | ||
|
||
This submodule is built on top of existing ERC20 modules and has extra functionality. See docs for all [ERC20 related methods](./w-steth.md). | ||
For original L2 ABI functionality use `.getL2Contract()` and get raw Viem contract instance. | ||
|
||
## LidoSDKL2Steth | ||
|
||
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). | ||
For original L2 ABI functionality use `.getL2Contract()` and get raw Viem contract instance. | ||
|
||
```ts | ||
import { LidoSDK } from '@lidofinance/lido-ethereum-sdk'; | ||
|
||
const lidoSDK = new LidoSDK({ | ||
rpcUrls: ['https://rpc-url'], | ||
chainId: 11155420, // OP sepolia | ||
web3Provider: LidoSDKCore.createWeb3Provider(11155420, window.ethereum), | ||
}); | ||
|
||
// balance of stETH for account in shares | ||
const balanceShares = await lidoSDK.l2.steth.balanceShares(address); | ||
|
||
// transferring shares is equivalent to transferring corresponding amount of stETH | ||
const transferTx = await lidoSDK.l2.steth.transferShares({ | ||
account, | ||
amount, | ||
to, | ||
}); | ||
|
||
// converting stETH amount to shares trough on-chain call based on actual share rate | ||
// This also can be used to convert stETH to wstETH as 1 wstETH = 1 share | ||
const shares = await lidoSDK.l2.steth.convertToShares(1000n); | ||
// reverse | ||
const steth = await lidoSDK.l2.steth.convertToSteth(1000n); | ||
|
||
// total supply of shares and ether in protocol | ||
const totalShares = await lidoSDK.totalShares(); | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters