Skip to content

Commit d609379

Browse files
authored
Merge pull request #167 from lidofinance/develop
v3.5.0
2 parents 0f5d0e6 + 51f02c0 commit d609379

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2658
-415
lines changed

.github/workflows/checks.yml

+2
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ jobs:
4040
TEST_PRIVATE_KEY: ${{ secrets.TEST_PRIVATE_KEY }}
4141
TEST_CHAIN_ID: ${{ vars.TEST_CHAIN_ID }}
4242
TEST_RPC_URL: ${{ secrets.TEST_RPC_URL }}
43+
TEST_L2_CHAIN_ID: ${{ vars.TEST_L2_CHAIN_ID }}
44+
TEST_L2_RPC_URL: ${{ secrets.TEST_L2_RPC_URL }}
4345
TEST_SUBGRAPH_URL: ${{ secrets.TEST_SUBGRAPH_URL }}

.github/workflows/publish-dry-run.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
publish-dry-run:
1212
runs-on: ubuntu-latest
13-
environment: development
13+
environment: pre-publish
1414
steps:
1515
- name: Checkout repo
1616
uses: actions/checkout@v4
@@ -31,14 +31,16 @@ jobs:
3131
run: yarn build:packages
3232

3333
- name: Dry run Publish
34-
run: yarn multi-semantic-release --dry-run --silent | grep -E '#|###|\*' > dry_run_output.txt
34+
run: |
35+
yarn multi-semantic-release --dry-run --silent > /tmp/multi-semantic-release-output
36+
grep -E '#|###|\*' /tmp/multi-semantic-release-output > dry_run_output.txt || [ $? -eq 1 ]
3537
env:
3638
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3739
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3840

3941
- name: Write results to summary
4042
run: |
41-
if [ -s dry_run_output.txt ]; then
43+
if [ -s dry_run_output.txt ]; then
4244
echo "# Packages to be published:" >> $GITHUB_STEP_SUMMARY
4345
cat dry_run_output.txt >> $GITHUB_STEP_SUMMARY
4446
else

docs/examples/rewards/intro.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The proposed approach involves maintaining an accounting model based on stETH [s
2626
## Implementation notes
2727

2828
Token shares are managed at the contract level, with dedicated methods for handling share-related operations. Detailed documentation on these methods can be found in the [shares-related methods](https://docs.lido.fi/contracts/lido/#shares-related-methods) section.
29-
You can also use [SDK methods](/methods/shares) to work with users’ shares directly.
29+
You can also use [SDK methods](/modules/shares) to work with users’ shares directly.
3030

3131
## Usage
3232

@@ -40,13 +40,13 @@ By adopting this approach and leveraging the capabilities of the SDK, developers
4040
4141
The [Lido Ethereum SDK](/) has the full set of features in this regard:
4242

43-
- [estimating APR](/methods/lido-statistics#getlastapr) for the latest token rebase.
44-
- [calculating average APR](/methods/lido-statistics#getsmaapr) over a selected period.
45-
- [last rebase event](/methods/lido-events#getlastrebaseevent) (contains share rate)
46-
- [first rebase event](/methods/lido-events#getfirstrebaseevent) starting from the reference point in the past
47-
- [get last N](/methods/lido-events#getlastrebaseevents) rebase events
48-
- [get all rebase events](/methods/lido-events#getrebaseevents) for the last N days
43+
- [estimating APR](/modules/lido-statistics#getlastapr) for the latest token rebase.
44+
- [calculating average APR](/modules/lido-statistics#getsmaapr) over a selected period.
45+
- [last rebase event](/modules/lido-events#getlastrebaseevent) (contains share rate)
46+
- [first rebase event](/modules/lido-events#getfirstrebaseevent) starting from the reference point in the past
47+
- [get last N](/modules/lido-events#getlastrebaseevents) rebase events
48+
- [get all rebase events](/modules/lido-events#getrebaseevents) for the last N days
4949
- assessing specific rewards accrued over a chosen period by an address
50-
- [On-chain](/methods/rewards#get-rewards-from-chain)
51-
- [Subgraph](/methods/rewards#get-rewards-from-subgraph)
52-
- work with [user balances](/methods/shares) based on stETH shares
50+
- [On-chain](/modules/rewards#get-rewards-from-chain)
51+
- [Subgraph](/modules/rewards#get-rewards-from-subgraph)
52+
- work with [user balances](/modules/shares) based on stETH shares

docs/examples/rewards/retrieve-rewards-onchain.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sidebar_position: 4
1111
[Implementation example](https://github.com/lidofinance/lido-ethereum-sdk/blob/main/examples/rewards/src/rewardsOnChain.ts)
1212

1313
Information about the user’s rewards can be calculating from on-chain using SDK without the need to calculate using a formula.
14-
To do this, you need to use the `getRewardsFromChain` method ([Docs](/methods/rewards))
14+
To do this, you need to use the `getRewardsFromChain` method ([Docs](/modules/rewards))
1515
The method allows you to request rewards for a certain period of time (days, seconds, blocks)
1616

1717
Simplified code example:

docs/examples/rewards/retrieve-rewards-subgraph.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ sidebar_position: 5
1414
[Implementation example](https://github.com/lidofinance/lido-ethereum-sdk/blob/main/examples/rewards/src/rewardsSubgraph.ts)
1515

1616
Information about the user’s rewards can be obtained from off-chain using SDK without the need for calculation using a formula.
17-
To do this, you need to use the `getRewardsFromSubgraph` method [[Docs](/methods/rewards)]. You will also need a key to access `The Graph`. ([Docs](https://docs.lido.fi/integrations/subgraph/))
17+
To do this, you need to use the `getRewardsFromSubgraph` method [[Docs](/modules/rewards)]. You will also need a key to access `The Graph`. ([Docs](https://docs.lido.fi/integrations/subgraph/))
1818

1919
Simplified code example:
2020

docs/examples/rewards/subscribe-on-events.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The first thing you need to do is subscribe to the `TokenRebased` event to recei
2020

2121
Next, you need to calculate the user’s balance in stETH before the event (if unknown) and calculate the user’s balance in stETH after the event. The difference between these values will be the user’s rewards for the rebase.
2222

23-
Docs: [Shares](/methods/shares)
23+
Docs: [Shares](/modules/shares)
2424
Simplified code example:
2525

2626
```ts

docs/lidoPulse/get-started/usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To form a JSON-RPC request, you need to specify:
1515
- `params`: The parameters required by the method.
1616
- `id`: A unique identifier for the request.
1717

18-
The method names and their required parameters can be found in the [Lido SDK documentation](/category/methods).
18+
The method names and their required parameters can be found in the [Lido SDK documentation](/category/modules).
1919

2020
## Example JSON-RPC Request
2121

docs/sdk/intro.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ For changes between versions see [CHANGELOG.MD](https://github.com/lidofinance/l
1818

1919
## Installation
2020

21-
You can install the Lido Ethereum SDK using npm or yarn:
21+
You can install the Lido Ethereum SDK using npm or yarn. `viem` is required as a peer dep:
2222

2323
```bash
2424
// SDK (stakes, wrap, withdrawals)
25-
yarn add @lidofinance/lido-ethereum-sdk
25+
yarn add viem @lidofinance/lido-ethereum-sdk
2626
```
2727

2828
## Usage
@@ -107,7 +107,7 @@ For breaking changes between versions see [MIGRATION.md](https://github.com/lido
107107

108108
## Documentation
109109

110-
For additional information about available methods and functionality, refer to the [the documentation for the Lido Ethereum SDK](/category/methods).
110+
For additional information about available methods and functionality, refer to the [the documentation for the Lido Ethereum SDK](/category/modules).
111111

112112
## Playground
113113

docs/sdk/methods/_category_.json docs/sdk/modules/_category_.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"label": "Methods",
2+
"label": "Modules",
33
"position": 3,
44
"link": {
55
"type": "generated-index"

docs/sdk/modules/l2.md

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
```
File renamed without changes.
File renamed without changes.

docs/sdk/methods/rewards.md docs/sdk/modules/rewards.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ y
1010
## Common Options
1111

1212
- **address** - (Type: Address) address of an account you want to query rewards for
13-
- **to** (Type: [`blockType`](/methods/lido-events#getrebaseevents)) defaults to `{block: "latest"}`, upper bound for query
13+
- **to** (Type: [`blockType`](/modules/lido-events#getrebaseevents)) defaults to `{block: "latest"}`, upper bound for query
1414

15-
- **from** (Type: [`blockType`](/methods/lido-events#getrebaseevents)) lower bound for query
15+
- **from** (Type: [`blockType`](/modules/lido-events#getrebaseevents)) lower bound for query
1616
or
17-
- **back** (Type: [`backType`](/methods/lido-events#getrebaseevents)) alternative way to define lower bound relative to `to`
17+
- **back** (Type: [`backType`](/modules/lido-events#getrebaseevents)) alternative way to define lower bound relative to `to`
1818

1919
- **includeZeroRebases** [default: `false` ] - include rebase events when users had no rewards(because of empty balance)
2020
- **includeOnlyRewards** [default: `false` ] - include only rebase events
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/erlang-bridge/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
},
1010
"dependencies": {
1111
"@lidofinance/lido-ethereum-sdk": "workspace:*",
12-
"viem": "^2.0.6"
12+
"viem": "^2.21.9"
1313
}
1414
}

examples/rewards/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@lidofinance/lido-ethereum-sdk": "workspace:*",
17-
"viem": "^2.0.6"
17+
"viem": "^2.21.9"
1818
},
1919
"devDependencies": {
2020
"rimraf": "^5.0.5",

packages/lido-pulse/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"fastify": "^4.28.1",
5454
"fastify-plugin": "^4.5.1",
5555
"reflect-metadata": "^0.2.2",
56-
"viem": "^2.0.6"
56+
"viem": "^2.21.9"
5757
},
5858
"devDependencies": {
5959
"@types/node": "^20.14.10",

packages/sdk/CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
# 3.5.0
2+
3+
## Breaking change
4+
5+
- `viem` is no longer an internal dependency and is listed as peer dependency
6+
7+
## SDK
8+
9+
### Added
10+
11+
- `LidoSDKL2` module is added to support Lido on L2 networks functionality
12+
- `Optimism` and `Optimism-sepolia` chains are added as separate L2 chains
13+
- `core.getL2ContractAddress` and `LIDO_L2_CONTRACT_NAMES enum` are added to support l2 contracts
14+
- ABIs are exported from corresponding modules to support custom functionality and direct viem access
15+
16+
### Fixed
17+
18+
- `multicall` is used only if supported by client
19+
20+
## Playground
21+
22+
- L2 and updated reef-knot support
23+
124
# 3.4.0
225

326
## SDK

packages/sdk/MIGRATION.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Migrating from V3 -> V4
2+
3+
- `viem` is now a peer dependency and you will need to install it separately.
4+
15
# Migrating from V2 -> V3
26

37
## Common

packages/sdk/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
"default": "./dist/cjs/shares/index.js",
7272
"types": "./dist/types/shares/index.d.ts"
7373
},
74+
"./l2": {
75+
"import": "./dist/esm/l2/index.js",
76+
"default": "./dist/cjs/l2/index.js",
77+
"types": "./dist/types/l2/index.d.ts"
78+
},
7479
"./package.json": "./package.json"
7580
},
7681
"typesVersions": {
@@ -104,6 +109,9 @@
104109
],
105110
"shares": [
106111
"./dist/types/shares/index.d.ts"
112+
],
113+
"l2": [
114+
"./dist/types/l2/index.d.ts"
107115
]
108116
}
109117
},
@@ -145,8 +153,10 @@
145153
"dependencies": {
146154
"@ethersproject/bytes": "^5.7.0",
147155
"graphql": "^16.8.1",
148-
"graphql-request": "^6.1.0",
149-
"viem": "^2.0.6"
156+
"graphql-request": "^6.1.0"
157+
},
158+
"peerDependencies": {
159+
"viem": "^2.21"
150160
},
151161
"devDependencies": {
152162
"@jest/globals": "^29.7.0",

0 commit comments

Comments
 (0)