Skip to content

Commit adc7d30

Browse files
authored
Merge pull request #321 from lidofinance/develop
Release V5.5
2 parents f09ab67 + 61cbea6 commit adc7d30

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

src/bots/depositor.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
logger = logging.getLogger(__name__)
3434

3535

36-
class ModuleNotSupportedError(Exception):
37-
pass
38-
39-
4036
def run_depositor(w3):
4137
logger.info({'msg': 'Initialize Depositor bot.'})
4238
sender = Sender(w3)
@@ -112,14 +108,12 @@ def execute(self, block: BlockData) -> bool:
112108
for module_id in self._get_preferred_to_deposit_modules():
113109
logger.info({'msg': f'Do deposit to module with id: {module_id}.'})
114110

115-
try:
116-
result = self._deposit_to_module(module_id)
117-
except ModuleNotSupportedError as error:
118-
logger.warning({'msg': 'Module not supported exception.', 'error': str(error)})
119-
continue
120-
if result:
121-
logger.info({'msg': f'Deposit to module with id: {module_id} was successful.'})
122-
return True
111+
result = self._deposit_to_module(module_id)
112+
logger.info({'msg': f'Deposit status to Module[{module_id}]: {result}.', 'value': result})
113+
114+
if variables.DEPOSIT_TO_FIRST_HEALTHY_MODULE_ONLY or result:
115+
return result
116+
123117
logger.warning({'msg': f'Deposit to module with id: {module_id} failed.'})
124118

125119
return False

src/variables.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
RABBIT_MQ_USERNAME = os.getenv('RABBIT_MQ_USERNAME', 'guest')
4545
RABBIT_MQ_PASSWORD = os.getenv('RABBIT_MQ_PASSWORD', 'guest')
4646

47-
QUORUM_RETENTION_MINUTES: int = int(os.getenv('QUORUM_RETENTION_MINUTES', 5))
47+
QUORUM_RETENTION_MINUTES: int = int(os.getenv('QUORUM_RETENTION_MINUTES', 30))
48+
DEPOSIT_TO_FIRST_HEALTHY_MODULE_ONLY: bool = os.getenv('DEPOSIT_TO_FIRST_HEALTHY_MODULE_ONLY', 'true') == 'true'
4849

4950
# data bus
5051
# gnosis nodes
@@ -123,6 +124,8 @@
123124
'ACCOUNT': '' if ACCOUNT is None else ACCOUNT.address,
124125
'ONCHAIN_TRANSPORT_ADDRESS': ONCHAIN_TRANSPORT_ADDRESS,
125126
'BLOCKS_BETWEEN_EXECUTION': BLOCKS_BETWEEN_EXECUTION,
127+
'QUORUM_RETENTION_MINUTES': QUORUM_RETENTION_MINUTES,
128+
'DEPOSIT_TO_FIRST_HEALTHY_MODULE_ONLY': DEPOSIT_TO_FIRST_HEALTHY_MODULE_ONLY,
126129
}
127130

128131
PRIVATE_ENV_VARS = {

tests/bots/test_depositor.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,27 @@ def test_depositor_bot(
379379
db.message_storage.messages = deposit_messages
380380
assert db.execute(latest)
381381
assert web3_lido_integration.lido.staking_router.get_staking_module_nonce(module_id) == old_module_nonce + 1
382+
383+
384+
@pytest.mark.unit
385+
def test_depositor_execute(web3_lido_unit, depositor_bot):
386+
depositor_bot._check_balance = Mock()
387+
388+
depositor_bot._get_preferred_to_deposit_modules = Mock(return_value=[1, 2])
389+
390+
# Check unsuccess deposit to first module only
391+
variables.DEPOSIT_TO_FIRST_HEALTHY_MODULE_ONLY = True
392+
depositor_bot._deposit_to_module = Mock(return_value=False)
393+
depositor_bot.execute(None)
394+
assert depositor_bot._deposit_to_module.call_count == 1
395+
396+
# Check deposit to both modules
397+
variables.DEPOSIT_TO_FIRST_HEALTHY_MODULE_ONLY = False
398+
depositor_bot._deposit_to_module = Mock(return_value=False)
399+
depositor_bot.execute(None)
400+
assert depositor_bot._deposit_to_module.call_count == 2
401+
402+
# Check success to first module
403+
depositor_bot._deposit_to_module = Mock(return_value=True)
404+
depositor_bot.execute(None)
405+
assert depositor_bot._deposit_to_module.call_count == 1

0 commit comments

Comments
 (0)