Package: lido-sdk-fork
<<<<<<< HEADLido Python SDKThis 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.InstallationThis library is available on PyPi:pipinstalllido-sdkFast startCreate Web3 provider. One of fast options to start is INFURA.fromweb3importWeb3#w3=Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/{INFURA_PROJECT_ID}'))Create Lido instance and provide web3 providerfromlido_sdkimportLidolido=Lido(w3)Call oneresponse=lido.fetch_all_keys_and_validate()ifresponse['invalid_keys']orresponse['duplicated_keys']:# This is not coolprint('There is invalid or duplicated keys\n')print(response)else:print('Everything is good!')Params for LidoParam nameDefault valueDescriptionw3requiredWeb3 providerMULTICALL_MAX_BUNCH275Count of calls in one multicall (not recommended to increase)MULTICALL_MAX_WORKERS6Count of requests in parallel (not recommended to have more than 12)MULTICALL_MAX_RETRIES5Count of retries before exception will be raisedMULTICALL_POOL_EXECUTOR_TIMEOUT30Thread pool timeout for multicall (seconds)VALIDATE_POOL_EXECUTOR_TIMEOUT10Process 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 methodsEverything 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_indexesmethod.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_datamethod.
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_keyswas 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_keysmethod.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_keysmethod.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) -> dictReturns 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 FeaturesMulticall Function CallsInstead of making network requests one-by-one, this library combines many requests into one RPC call. It usesbanteg/multicall.py, a Python wrapper formakerdao/multicall.Fast validation system powered byblstAutomatic Testnet / Mainnet SwitchingDepending on which network is configured in web3 object, a set of contracts will be used.
Available networks:MainnetGörliRopstenRinkebyDevelopmentClone project:gitclonegit@github.com:lidofinance/lido-python-sdk.gitcdlido-python-sdkCreate virtual env:virtualenv.env--python=python3source.env/bin/activateInstall all dependencies:poetryinstallActivate virtual envpoetryshellBuild blst locally (linux):cdblst/./build.shcd..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/pythonsetup.pybuild_ext--inplaceBuild blst locally (osx):cdblst/./build.shcd..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/pythonsetup.pybuild_ext--inplaceHow to testSimply run in project root directory:poetryrunpytest.Release new versiongittagv2.x.xmaster
gitpush--tagsNew version should be published after all pipelines passed.lido-python-sdk-forkfork lido-python-sdk88a206396b11da0010ce47e201569b90c5d0945f