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': [...],
}
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
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.
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-2.5.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9f3cee3c8a8c6d0dd128568e55affdaa811da848cf4cafc77e8d2481bb1c7ed |
|
MD5 | d64d49d4d436c0296bbe9e958c065324 |
|
BLAKE2b-256 | e1a2cd8cc33a6a33ccab8254a7ba8c5377450979b26e3e79a7937ceaaf3b01d0 |
Hashes for lido_sdk-2.5.4-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8d6a931942254e5546a151643f29845e1f6f49eb5c2efc852fd1dd91b93b549 |
|
MD5 | b2ac554cd5d75775c3edf70ccd0aa361 |
|
BLAKE2b-256 | 5dba86ad505f5b3a4645d7067c8f854fb581af65428f312068a5277f7c7f8544 |
Hashes for lido_sdk-2.5.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbbb3cac89330edfe15aad32c7af58914da701da3617d7474b01d800c4aff19e |
|
MD5 | 0df4342efbdfb73a10c10f70ceaf0db2 |
|
BLAKE2b-256 | ea5c37b4d1254aa155084d3d5e16bb2d5a250174d08268f08b5cf2d6cbc277e8 |
Hashes for lido_sdk-2.5.4-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 232d435bd30895662577bafd8caebc70bd9eeb9263482d78f4d01d0ecb75a8ac |
|
MD5 | 2563c6431056ac753122330efd0789f0 |
|
BLAKE2b-256 | 958b52499faeb47e9bd6e0a3854855893bc6111764fffe9a17d0ada95d023a6c |
Hashes for lido_sdk-2.5.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbeba828390e61ac68d46a3235c51a006058cce77a340407e3d53f920dafa429 |
|
MD5 | bf7c7dc8bbba95ed6d8b5cc04ada97f1 |
|
BLAKE2b-256 | 9b3740feb6787bc4307622e388e140a2d7581b94dd0dd1210ab2395480d819ed |
Hashes for lido_sdk-2.5.4-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 871ac435c9ee60706301e58ca3cbb9784feaa6b24da6a4feae60fb5f7d464d75 |
|
MD5 | 755ef50d0de58e1778ccdb3aaac652af |
|
BLAKE2b-256 | d1bb996badc32b28880a5a76c6a6c70b7d71739b2010bdb9cc97334ac2dc7df5 |
Hashes for lido_sdk-2.5.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c83d71462de49a1c05ff646ecc660faaa3a809b188a25da9ce67399177574391 |
|
MD5 | d91b66fd96bfb12df33f90cefc758284 |
|
BLAKE2b-256 | ea93fe6ccc2b9961406c89e12d1ccee99f9e065d6a218b3dd7e79ddc293a86b4 |
Hashes for lido_sdk-2.5.4-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9540b4b7eb0af5307e8deb6c7fc667c993cf71beeae7d50b5d2d24bfae60089c |
|
MD5 | 9a4bd84071a361bdfea551aec27cfc3f |
|
BLAKE2b-256 | 36274db506c58499e3297b4f090ba37329ec894d4244114d818bf36a59ca6e6b |