This library consolidates various functions to efficiently load network data for Lido, validate node operator keys and find key duplicates.
Project description
Lido Python SDK
❗Python SDK supports only Curated Staking module. Check out KAPI project if you need all Lido keys.❗
Lido Python SDK - convenient interface to check validator's pub keys in Node Operators registry. Provides ability to download, verify and check for duplicates keys in curated module (Node Operators registry).
Installation
This library is available on PyPi:
pip install lido-sdk
Fast start
- Create Web3 provider. One of fast options to start is INFURA.
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/{INFURA_PROJECT_ID}'))
- Create Lido instance and provide web3 provider
from lido_sdk import Lido
lido = Lido(w3)
- Call one
response = lido.fetch_all_keys_and_validate()
if response['invalid_keys'] or response['duplicated_keys']:
# This is not cool
print('There is invalid or duplicated keys\n')
print(response)
else:
print('Everything is good!')
Params for Lido
Param name | Default value | Description |
---|---|---|
w3 | required | Web3 provider |
MULTICALL_MAX_BUNCH | 275 | Count of calls in one multicall (not recommended to increase) |
MULTICALL_MAX_WORKERS | 6 | Count of requests in parallel (not recommended to have more than 12) |
MULTICALL_MAX_RETRIES | 5 | Count of retries before exception will be raised |
MULTICALL_POOL_EXECUTOR_TIMEOUT | 30 | Thread pool timeout for multicall (seconds) |
VALIDATE_POOL_EXECUTOR_TIMEOUT | 10 | Process pool timeout for keys validation (seconds) |
Settings example if timeout exception was raised:
Lido(w3=w3, MULTICALL_MAX_BUNCH=100, MULTICALL_MAX_WORKERS=3)
Base methods
Everything you need is in Lido class.
Lido.get_operators_indexes(self) -> List[int]
Returns: Node operators indexes in contract.
>>> lido.get_operators_indexes()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Lido.get_operators_data(self, operators_indexes: Optional[List[int]] = None) -> List[Operator]
Receives: List of operators indexes. If nothing provided will take previous return fromget_operators_indexes
method.
Returns: List of operators details.
>>> lido.get_operators_data([1])
[{'active': True, 'name': 'Certus One', 'rewardAddress': '0x8d689476eb446a1fb0065bffac32398ed7f89165', 'stakingLimit': 1000, 'stoppedValidators': 0, 'totalSigningKeys': 1000, 'usedSigningKeys': 1000, 'index': 1}]```
Lido.get_operators_keys(self, operators: Optional[List[Operator]] = None) -> List[OperatorKey]
Receives: List of operators details. If nothing provided will take previous return fromget_operators_data
method. Returns: List of keys in contract.
>>> lido.get_operators_keys(operators_data)
[{'key': b'...', 'depositSignature': b'...', 'used': False, 'index': 6921, 'operator_index': 8}, ...]
Lido.update_keys(self) -> List[OperatorKey]
Returns actual keys list. Works only inget_operators_keys
was called before. Should be used to periodically update keys. Faster because not all keys are updated from the contract.
>>> lido.update_keys()
[{'key': b'...', 'depositSignature': b'...', 'used': False, 'index': 6521, 'operator_index': 5}]
Lido.validate_keys(self, keys: Optional[List[OperatorKey]] = None) -> List[OperatorKey]
Receives: List of keys to validate. If nothing provided will take previous return fromget_operators_keys
method.
Returns: List of invalid keys.
>>> lido.validate_keys()
[{'key': b'...', 'depositSignature': b'...', 'used': False, 'index': 6521, 'operator_index': 5}]
Lido.find_duplicated_keys(self, keys: Optional[List[OperatorKey]] = None) -> List[Tuple[OperatorKey, OperatorKey]]
Receives: List of keys to compare. If nothing provided will take previous return fromget_operators_keys
method.
Returns: List of same pairs keys.
>>> lido.find_duplicated_keys()
[
(
{'key': b'abc...', 'index': 222, 'operator_index': 5, ...},
{'key': b'abc...', 'index': 111, 'operator_index': 5, ...}
)
]
Lido.get_status(self) -> dict
Returns dict with Lido current state.
>>> lido.get_status()
{
'isStopped': False,
'totalPooledEther': 1045230979275869331637351,
'withdrawalCredentials': b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb9\xd7\x93Hx\xb4\xfb\x96\x10\xb3\xfe\x8a^D\x1e\x8f\xad~)?',
'bufferedEther': 76467538672788331637351,
'feeBasisPoints': 1000,
'treasuryFeeBasisPoints': 0,
'insuranceFeeBasisPoints': 5000,
'operatorsFeeBasisPoints': 5000,
'depositedValidators': 29800,
'beaconValidators': 29800,
'beaconBalance': 968763440603081000000000,
'last_block': 13110151,
'last_blocktime': 1630103538,
}
Lido.fetch_all_keys_and_validate(self) -> Dict[str, list]
Makes all steps below exceptget_status
.
Returns all invalid and duplicated keys.
>>> lido.fetch_all_keys_and_validate()
{
'invalid_keys': [...],
'duplicated_keys': [...],
}
Issues
There is issues with using blst lib on macos ARM cpu. But everything works on linux ARM cpu.
Main Features
Multicall Function Calls
- Instead of making network requests one-by-one, this library combines many requests into one RPC call. It uses banteg/multicall.py, a Python wrapper for makerdao/multicall.
- Fast validation system powered by blst
Automatic Testnet / Mainnet Switching
Depending on which network is configured in web3 object, a set of contracts will be used. Available networks:
- Mainnet
- Görli
- Holesky
Development
Clone project:
git clone --recurse-submodules https://github.com/lidofinance/lido-python-sdk.git
cd lido-python-sdk
Create virtual env:
virtualenv .env --python=python3
source .env/bin/activate
Install all dependencies:
poetry install
Activate virtual env
poetry shell
Build blst locally (linux):
cd blst/
./build.sh
cd ..
mkdir -p ./blst-lib/linux/
cp ./blst/libblst.a ./blst-lib/linux/
cp ./blst/bindings/blst.h ./blst-lib/
cp ./blst/bindings/blst.hpp ./blst-lib/
cp ./blst/bindings/blst_aux.h ./blst-lib/
python setup.py build_ext --inplace
Build blst locally (osx):
cd blst/
./build.sh
cd ..
mkdir -p ./blst-lib/darwin/
cp ./blst/libblst.a ./blst-lib/darwin/
cp ./blst/bindings/blst.h ./blst-lib/
cp ./blst/bindings/blst.hpp ./blst-lib/
cp ./blst/bindings/blst_aux.h ./blst-lib/
python setup.py build_ext --inplace
Build blst locally (osx arm):
cd blst/
./build.sh
cd ..
mkdir -p ./blst-lib/darwin-arm64/
cp ./blst/libblst.a ./blst-lib/darwin-arm64/
cp ./blst/bindings/blst.h ./blst-lib/
cp ./blst/bindings/blst.hpp ./blst-lib/
cp ./blst/bindings/blst_aux.h ./blst-lib/
python setup.py build_ext --inplace
How to test
Simply run in project root directory:
poetry run pytest .
Release new version
git tag v2.x.x master
git push --tags
New version should be published after all pipelines passed.
Rebuild blst
Goto actions "Build blst and create PR". Note that darwin-arm64 binaries are not rebuilt automatically due to GitHub Actions not supporting macOS runners on arm yet Review PR and merge. Do a release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file lido-sdk-4.1.0.tar.gz
.
File metadata
- Download URL: lido-sdk-4.1.0.tar.gz
- Upload date:
- Size: 715.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91c4c4fbf487b8cb5d40b6afd08ca0997d2bb80bc6d2062b7f7711754ce4af61 |
|
MD5 | 3eb9b3c9098b578d2bfbe8eafce99a98 |
|
BLAKE2b-256 | 50b727c9c4ea72445a939e3a6f6281ff498a54a30aa9814ced8ada69fc7b936d |
File details
Details for the file lido_sdk-4.1.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: lido_sdk-4.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 160.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae458f19d46b303ed84fdeb7fb0d69954258b2c02c62fdc756a714d39cc5d7f4 |
|
MD5 | bc0856298be224d3fdb00067bb357d36 |
|
BLAKE2b-256 | 21710c47fd6a0d97e297334645e1e151529ee4003998c2c0726b25bda3f83761 |
File details
Details for the file lido_sdk-4.1.0-cp310-cp310-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: lido_sdk-4.1.0-cp310-cp310-macosx_11_0_x86_64.whl
- Upload date:
- Size: 146.8 kB
- Tags: CPython 3.10, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3c92f4b78bd8ad7ba84f8a74015c03e53b58066b2815ce0e3e8231a777bb3c0 |
|
MD5 | 373ca8c2af7f66374e6fdf4c114a97cf |
|
BLAKE2b-256 | aa91ffc7ba3529f0afff3d03571548e3b445f24b90552812055035ea845e4f9f |
File details
Details for the file lido_sdk-4.1.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: lido_sdk-4.1.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 171.7 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 854c4d9dfe55fe7928e8ee78e10744888dff87a76ab928b515d2f5fa48103fe3 |
|
MD5 | 7e152c71ed624c1ab37389b44ffe8ed6 |
|
BLAKE2b-256 | 54409e273d2de26493ff44a8851adf03b148b52905fffce7675fbb08458779a3 |
File details
Details for the file lido_sdk-4.1.0-cp39-cp39-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: lido_sdk-4.1.0-cp39-cp39-macosx_11_0_x86_64.whl
- Upload date:
- Size: 146.8 kB
- Tags: CPython 3.9, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ec8be4680bb9e4f3cf17e25ab0632fd9397a44af1ad4f88ebaafc9f6f073e54 |
|
MD5 | 37a5474672394e6b8ef6967e4d9ca6ad |
|
BLAKE2b-256 | 3f173266bd70d3c699bc0b65834b9818e10fe0d2d2b53c19517fced4a021be7c |
File details
Details for the file lido_sdk-4.1.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: lido_sdk-4.1.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 170.9 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6dddfb05d0b5ae6f5a0f3bccf10b17672e1958e1bd06c5d81c29d1ebdb4c20a |
|
MD5 | 3a8937cfdba6d68cb2138667c051881d |
|
BLAKE2b-256 | 0a852c954cf9319b2d4af1c634623f0751b14d94b6d45000116d5ea41d52755f |
File details
Details for the file lido_sdk-4.1.0-cp38-cp38-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: lido_sdk-4.1.0-cp38-cp38-macosx_11_0_x86_64.whl
- Upload date:
- Size: 147.1 kB
- Tags: CPython 3.8, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab8898c1e900c0cba9f7d7551c1c4dbfd178ee4144208db6c4809c2bbec2cb7a |
|
MD5 | eaaf8522909c1fbbe1a97520cb9cefb9 |
|
BLAKE2b-256 | fc57b8bee4b7fe6214292ba88e532b7fed2b3b84d4859c9ed279486bac58521b |
File details
Details for the file lido_sdk-4.1.0-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: lido_sdk-4.1.0-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 170.5 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0228220058c3162aba32c645d439915eb01317f4cdf9c3dd1ae3bc89f838ed78 |
|
MD5 | bed8c04b87769898d9b500fd465232a8 |
|
BLAKE2b-256 | 0dc937a5eccdf03272f818a4e50eb487906f7078c63a87dec376947b82a7256a |
File details
Details for the file lido_sdk-4.1.0-cp37-cp37m-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: lido_sdk-4.1.0-cp37-cp37m-macosx_11_0_x86_64.whl
- Upload date:
- Size: 146.6 kB
- Tags: CPython 3.7m, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 679d087401e87aa016169d9ddf843dd305475392d26e91475358fc0771ae5a60 |
|
MD5 | 76b74c0908bdac0d2a5df3c599f7258f |
|
BLAKE2b-256 | f73746071f935c9a5d692e102ed047d39ecdf4514d66df6a7121c7c15b113674 |