Skip to content

Commit

Permalink
fix: refactor fund service
Browse files Browse the repository at this point in the history
  • Loading branch information
Divya-Solulab committed Nov 15, 2024
1 parent b55741b commit 49e071c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,26 +1137,28 @@ def fund_service( # pylint: disable=too-many-arguments,too-many-locals
chain_type=ledger_config.chain, rpc=rpc or ledger_config.rpc
)
agent_fund_threshold = (
agent_fund_threshold or chain_data.user_params.fund_requirements.agent
agent_fund_threshold if agent_fund_threshold is not None else chain_data.user_params.fund_requirements.agent
)

for key in service.keys:
agent_balance = ledger_api.get_balance(address=key.address)
self.logger.info(f"Agent {key.address} balance: {agent_balance}")
self.logger.info(f"Required balance: {agent_fund_threshold}")
if agent_balance < agent_fund_threshold:
self.logger.info("Funding agents")
to_transfer = (
agent_topup or chain_data.user_params.fund_requirements.agent
)
self.logger.info(f"Transferring {to_transfer} units to {key.address}")
wallet.transfer(
to=key.address,
amount=int(to_transfer),
chain_type=ledger_config.chain,
from_safe=from_safe,
rpc=rpc or ledger_config.rpc,
)
if agent_fund_threshold > 0:
self.logger.info(f"Required balance: {agent_fund_threshold}")
if agent_balance < agent_fund_threshold:
self.logger.info("Funding agents")
to_transfer = (
agent_topup or chain_data.user_params.fund_requirements.agent
)
self.logger.info(f"Transferring {to_transfer} units to {key.address}")
wallet.transfer(
to=key.address,
amount=int(to_transfer),
chain_type=ledger_config.chain,
from_safe=from_safe,
rpc=rpc or ledger_config.rpc,
)


safe_balance = ledger_api.get_balance(chain_data.multisig)
safe_fund_treshold = (
Expand Down

0 comments on commit 49e071c

Please sign in to comment.