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
This repo provides a scratch of a Python project. Its purpose is to serve as starting point for the development of a Python project based on a minimal working structure.
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!')
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.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
Development
Clone project:
git clone git@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:
pip install -r requirements.txt
pip install -r requirements-dev.txt
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:
pytest .
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.0.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2c9f91363ba7651bc16d22f72d880f83b51c418f8308fa1344003ef2a31771 |
|
MD5 | 23066589247cc0a4a6fedf1831dd3c09 |
|
BLAKE2b-256 | f39c717567d612e653546f6732a98dc1e63f1d5f6817db962d5b7844a7a0830d |
Hashes for lido_sdk-2.0.1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac56ec1282d0cb5f6af065d1228520573453f042a267c4616c4903a5f01e69de |
|
MD5 | 5c50fd5a8a73e59fca49fa6ea771e36d |
|
BLAKE2b-256 | 832c6c53637204b3dd7684aa2c1e6718fde24edecdff4749dbb4528153574863 |
Hashes for lido_sdk-2.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6557925f482d4ce82b6835e32169878aff11fc619cc9ba100d5d4c9db5f67f58 |
|
MD5 | e253ec7bda794bbcc49d84e83a8202d6 |
|
BLAKE2b-256 | 0602b0a3b57655ac61a46b8583a498cc185b7d56961dd574bd07a994a360bf17 |
Hashes for lido_sdk-2.0.1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fd04654890433319127b57b87b2b533e1824fd5ab49b3bc7e64eee207e51d3f |
|
MD5 | 4255a4f11a194f1243af0b4d7cc9e422 |
|
BLAKE2b-256 | 92e35315ceb42d573b24cf3ed223fac2bb92b80ae8f4f37ce9ce166d65f6494c |
Hashes for lido_sdk-2.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4f8487a4806b472d0497a4b7bddba854d3408349aca274790c7631138f4fa7c |
|
MD5 | 7cd340d63734cb444aed0af8eef39a17 |
|
BLAKE2b-256 | 4a858bb59988534f375587443cd7c1b3faf276898dff3bd7b354329184dd5339 |
Hashes for lido_sdk-2.0.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5717942cb88eef932e9311bdaadd80ef89292455e326494147d5cdb3076d2076 |
|
MD5 | eeeea8cced5dd6e737a9a8148313868f |
|
BLAKE2b-256 | f2cc4eac33a36e8217e30e803350744020485bba5f8a34577c0ce6b5e52209ad |