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

v3.5.0 #167

Merged
merged 39 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
aa38538
feat: L2 chains constants
Jeday Sep 12, 2024
e4017e9
fix: abi exports
Jeday Sep 12, 2024
1919e2a
feat: l2 module
Jeday Sep 18, 2024
df7ce65
fix: method name
Jeday Sep 18, 2024
6a188bf
fix: build
Jeday Sep 18, 2024
99db55f
Merge pull request #156 from lidofinance/feature/si-1524-steth-on-opt…
Jeday Sep 18, 2024
fdce1a0
build(deps): bump find-my-way from 8.2.0 to 8.2.2
dependabot[bot] Sep 18, 2024
86e82f5
Merge pull request #157 from lidofinance/dependabot/npm_and_yarn/find…
Jeday Sep 19, 2024
983bae4
build(deps): bump express from 4.19.2 to 4.21.0
dependabot[bot] Sep 21, 2024
4490f62
test: base l2 test setup
Jeday Sep 30, 2024
17eef9c
test: l2 wrap tests
Jeday Sep 30, 2024
ba63915
test: permit tests
Jeday Sep 30, 2024
a134396
test: fix permit for v2
Jeday Sep 30, 2024
09a6b34
test: l2 shares test
Jeday Oct 1, 2024
cd2b597
chore: misconfiguration comment
Jeday Oct 1, 2024
6414a2b
Merge pull request #158 from lidofinance/dependabot/npm_and_yarn/expr…
Jeday Oct 1, 2024
a8e5f29
test: lint
Jeday Oct 1, 2024
3086fac
build(ci): add envs
Jeday Oct 1, 2024
7f7be74
Merge pull request #159 from lidofinance/feature/si-1524-steth-on-opt…
Jeday Oct 2, 2024
10c816f
fix: update pre-publish wf
DiRaiks Oct 2, 2024
5e95319
Merge pull request #160 from lidofinance/fix/publish_wf
Jeday Oct 2, 2024
a7d9c00
fix: check wf
DiRaiks Oct 2, 2024
840fe8f
fix: remove permissions
DiRaiks Oct 2, 2024
70038f5
Merge pull request #161 from lidofinance/fix/publish_wf
DiRaiks Oct 2, 2024
fe09ca9
fix: update pre-publish wf
DiRaiks Oct 2, 2024
fcf0e6a
Merge pull request #162 from lidofinance/fix/pre-publish_wf
Jeday Oct 2, 2024
d033410
fix: add decorator
Jeday Oct 2, 2024
fc5c3a9
Merge pull request #163 from lidofinance/feature/si-1524-steth-on-opt…
DiRaiks Oct 2, 2024
56ec2cf
docs: add l2 to docs
Jeday Oct 3, 2024
ce61494
fix: naming for l2 unwrap
Jeday Oct 3, 2024
14b31dc
fix: demo
Jeday Oct 3, 2024
da66ff4
feat: op mainnet
Jeday Oct 4, 2024
6861aa4
docs: fix build
Jeday Oct 4, 2024
6343188
Merge pull request #164 from lidofinance/feature/si-1524-steth-on-opt…
Jeday Oct 4, 2024
2bfb069
build(deps): bump find-my-way from 8.2.0 to 8.2.2
dependabot[bot] Oct 7, 2024
c001120
feat: 3.5.0 version
Jeday Oct 14, 2024
6f02983
docs: add viem to install
Jeday Oct 14, 2024
a08ab00
Merge pull request #166 from lidofinance/feature/si-1524-steth-on-opt…
Jeday Oct 14, 2024
51f02c0
Merge pull request #165 from lidofinance/dependabot/npm_and_yarn/find…
Jeday Oct 14, 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
2 changes: 2 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ jobs:
TEST_PRIVATE_KEY: ${{ secrets.TEST_PRIVATE_KEY }}
TEST_CHAIN_ID: ${{ vars.TEST_CHAIN_ID }}
TEST_RPC_URL: ${{ secrets.TEST_RPC_URL }}
TEST_L2_CHAIN_ID: ${{ vars.TEST_L2_CHAIN_ID }}
TEST_L2_RPC_URL: ${{ secrets.TEST_L2_RPC_URL }}
TEST_SUBGRAPH_URL: ${{ secrets.TEST_SUBGRAPH_URL }}
8 changes: 5 additions & 3 deletions .github/workflows/publish-dry-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
publish-dry-run:
runs-on: ubuntu-latest
environment: development
environment: pre-publish
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -31,14 +31,16 @@ jobs:
run: yarn build:packages

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

- name: Write results to summary
run: |
if [ -s dry_run_output.txt ]; then
if [ -s dry_run_output.txt ]; then
echo "# Packages to be published:" >> $GITHUB_STEP_SUMMARY
cat dry_run_output.txt >> $GITHUB_STEP_SUMMARY
else
Expand Down
20 changes: 10 additions & 10 deletions docs/examples/rewards/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The proposed approach involves maintaining an accounting model based on stETH [s
## Implementation notes

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.
You can also use [SDK methods](/methods/shares) to work with users’ shares directly.
You can also use [SDK methods](/modules/shares) to work with users’ shares directly.

## Usage

Expand All @@ -40,13 +40,13 @@ By adopting this approach and leveraging the capabilities of the SDK, developers

The [Lido Ethereum SDK](/) has the full set of features in this regard:

- [estimating APR](/methods/lido-statistics#getlastapr) for the latest token rebase.
- [calculating average APR](/methods/lido-statistics#getsmaapr) over a selected period.
- [last rebase event](/methods/lido-events#getlastrebaseevent) (contains share rate)
- [first rebase event](/methods/lido-events#getfirstrebaseevent) starting from the reference point in the past
- [get last N](/methods/lido-events#getlastrebaseevents) rebase events
- [get all rebase events](/methods/lido-events#getrebaseevents) for the last N days
- [estimating APR](/modules/lido-statistics#getlastapr) for the latest token rebase.
- [calculating average APR](/modules/lido-statistics#getsmaapr) over a selected period.
- [last rebase event](/modules/lido-events#getlastrebaseevent) (contains share rate)
- [first rebase event](/modules/lido-events#getfirstrebaseevent) starting from the reference point in the past
- [get last N](/modules/lido-events#getlastrebaseevents) rebase events
- [get all rebase events](/modules/lido-events#getrebaseevents) for the last N days
- assessing specific rewards accrued over a chosen period by an address
- [On-chain](/methods/rewards#get-rewards-from-chain)
- [Subgraph](/methods/rewards#get-rewards-from-subgraph)
- work with [user balances](/methods/shares) based on stETH shares
- [On-chain](/modules/rewards#get-rewards-from-chain)
- [Subgraph](/modules/rewards#get-rewards-from-subgraph)
- work with [user balances](/modules/shares) based on stETH shares
2 changes: 1 addition & 1 deletion docs/examples/rewards/retrieve-rewards-onchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sidebar_position: 4
[Implementation example](https://github.com/lidofinance/lido-ethereum-sdk/blob/main/examples/rewards/src/rewardsOnChain.ts)

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

Simplified code example:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/rewards/retrieve-rewards-subgraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sidebar_position: 5
[Implementation example](https://github.com/lidofinance/lido-ethereum-sdk/blob/main/examples/rewards/src/rewardsSubgraph.ts)

Information about the user’s rewards can be obtained from off-chain using SDK without the need for calculation using a formula.
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/))
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/))

Simplified code example:

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/rewards/subscribe-on-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The first thing you need to do is subscribe to the `TokenRebased` event to recei

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.

Docs: [Shares](/methods/shares)
Docs: [Shares](/modules/shares)
Simplified code example:

```ts
Expand Down
2 changes: 1 addition & 1 deletion docs/lidoPulse/get-started/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To form a JSON-RPC request, you need to specify:
- `params`: The parameters required by the method.
- `id`: A unique identifier for the request.

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

## Example JSON-RPC Request

Expand Down
6 changes: 3 additions & 3 deletions docs/sdk/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ For changes between versions see [CHANGELOG.MD](https://github.com/lidofinance/l

## Installation

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

```bash
// SDK (stakes, wrap, withdrawals)
yarn add @lidofinance/lido-ethereum-sdk
yarn add viem @lidofinance/lido-ethereum-sdk
```

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

## Documentation

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

## Playground

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"label": "Methods",
"label": "Modules",
"position": 3,
"link": {
"type": "generated-index"
Expand Down
131 changes: 131 additions & 0 deletions docs/sdk/modules/l2.md
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.
6 changes: 3 additions & 3 deletions docs/sdk/methods/rewards.md → docs/sdk/modules/rewards.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ y
## Common Options

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

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

- **includeZeroRebases** [default: `false` ] - include rebase events when users had no rewards(because of empty balance)
- **includeOnlyRewards** [default: `false` ] - include only rebase events
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/erlang-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
},
"dependencies": {
"@lidofinance/lido-ethereum-sdk": "workspace:*",
"viem": "^2.0.6"
"viem": "^2.21.9"
}
}
2 changes: 1 addition & 1 deletion examples/rewards/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@lidofinance/lido-ethereum-sdk": "workspace:*",
"viem": "^2.0.6"
"viem": "^2.21.9"
},
"devDependencies": {
"rimraf": "^5.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/lido-pulse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"fastify": "^4.28.1",
"fastify-plugin": "^4.5.1",
"reflect-metadata": "^0.2.2",
"viem": "^2.0.6"
"viem": "^2.21.9"
},
"devDependencies": {
"@types/node": "^20.14.10",
Expand Down
23 changes: 23 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# 3.5.0

## Breaking change

- `viem` is no longer an internal dependency and is listed as peer dependency

## SDK

### Added

- `LidoSDKL2` module is added to support Lido on L2 networks functionality
- `Optimism` and `Optimism-sepolia` chains are added as separate L2 chains
- `core.getL2ContractAddress` and `LIDO_L2_CONTRACT_NAMES enum` are added to support l2 contracts
- ABIs are exported from corresponding modules to support custom functionality and direct viem access

### Fixed

- `multicall` is used only if supported by client

## Playground

- L2 and updated reef-knot support

# 3.4.0

## SDK
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Migrating from V3 -> V4

- `viem` is now a peer dependency and you will need to install it separately.

# Migrating from V2 -> V3

## Common
Expand Down
14 changes: 12 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
"default": "./dist/cjs/shares/index.js",
"types": "./dist/types/shares/index.d.ts"
},
"./l2": {
"import": "./dist/esm/l2/index.js",
"default": "./dist/cjs/l2/index.js",
"types": "./dist/types/l2/index.d.ts"
},
"./package.json": "./package.json"
},
"typesVersions": {
Expand Down Expand Up @@ -104,6 +109,9 @@
],
"shares": [
"./dist/types/shares/index.d.ts"
],
"l2": [
"./dist/types/l2/index.d.ts"
]
}
},
Expand Down Expand Up @@ -145,8 +153,10 @@
"dependencies": {
"@ethersproject/bytes": "^5.7.0",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"viem": "^2.0.6"
"graphql-request": "^6.1.0"
},
"peerDependencies": {
"viem": "^2.21"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand Down
Loading