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
A library with which you can get all Lido validator's signatures and check their validity.
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
- Ropsten
- Rinkeby
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
Hashes for lido_sdk-3.0.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e98d6f55ad563c96757a4d0d0b50e3e53c4b4ac0263361130b0b0ef360105d13 |
|
MD5 | edbd3011d5cafab43c6b999af858794b |
|
BLAKE2b-256 | 2baceb1c1bacf9468852dba2c513947d9fc3ae487d82e308c33930530cb2cbb3 |
Hashes for lido_sdk-3.0.4-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b082612247b9d7336bb66aae87b522f40d6a6c1d18b5894caeebc1c745e279c |
|
MD5 | b3c8831af63dea6e758af0d71e3c307e |
|
BLAKE2b-256 | 476ee499b6625c68190578e7a4c42b9ca5f4d4935a21bd8aec85daa39efd4445 |
Hashes for lido_sdk-3.0.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23ce6470caf6ede7c19498c55fdedca1558d79d2afc9f1ff926c3e8236ad8fbf |
|
MD5 | 05c3614688f08aa95f8a18b7d5af00b5 |
|
BLAKE2b-256 | 190c360805ee167c01875613a8430f7e9bf5939d7a12b22507f7d74f48d4e70e |
Hashes for lido_sdk-3.0.4-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42535243c2e09ad5bc77e77ecb28573aee28ab5a6ad076cfbffa0e371850c457 |
|
MD5 | 9d7c76c09fb7cdbd9fad24ddc8917e13 |
|
BLAKE2b-256 | e0cf70f50b5bf5e0a5a458c47d05260febd3739ca04cd614ee40cb0d8ccac020 |
Hashes for lido_sdk-3.0.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a1dca6f62b6c09204ae39b25ffc48141e53f8b9e5b2d3a60b53dc758ebea468 |
|
MD5 | 3f5502ec313a35cd83c01a1a7bc91864 |
|
BLAKE2b-256 | 08ec6cb524274dd3d4b3f68da6e81649dd48e8680ddd0dfdbf73a7457d140f28 |
Hashes for lido_sdk-3.0.4-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18c4c0206d6d6871b8ef4e924c46e651956c396761aa78d8175ee80882df4b95 |
|
MD5 | 2e36c750ca240a193a7c35b85aa86ef2 |
|
BLAKE2b-256 | 5a8a33b704dd3b61d7bdef52a620698960177fa03a1179db285fdfc40b8dc7d7 |
Hashes for lido_sdk-3.0.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb87d6835035e585044590930eac46f814f20cf585b0dcc80ec329255b9051a8 |
|
MD5 | ec7338592c11f7a72e2a13996e86bac4 |
|
BLAKE2b-256 | 757bfa5362bcda70694fa3a967be60fb09fb0c5037cc78887a57ec37c60113a4 |
Hashes for lido_sdk-3.0.4-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85fd929d65f5231a6978aedee4f248ce0f175c3ba05c0210e3b44651a06613c7 |
|
MD5 | 85713230571acfe36905efc71cf6e511 |
|
BLAKE2b-256 | 02d9e075bc19bd09da7646a309637ef1d67ba79d56bea523e20244bd953e4d9d |