-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Funding job to send amount upto the topup #637
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
from aea_ledger_ethereum import EthereumCrypto | ||
from autonomy.chain.base import registry_contracts | ||
|
||
from operate.constants import ZERO_ADDRESS | ||
from operate.constants import WRAPPED_NATIVE_ASSET, ZERO_ADDRESS | ||
from operate.keys import Key, KeysManager | ||
from operate.ledger import PUBLIC_RPCS | ||
from operate.ledger.profiles import CONTRACTS, OLAS, STAKING, WXDAI | ||
|
@@ -1491,19 +1491,25 @@ def fund_service_single_chain( # pylint: disable=too-many-arguments,too-many-lo | |
address=key.address, | ||
) | ||
self.logger.info( | ||
f"Agent {key.address} Asset: {asset_address} balance: {agent_balance}" | ||
f"[FUNDING_JOB] Agent {key.address} Asset: {asset_address} balance: {agent_balance}" | ||
) | ||
if agent_fund_threshold > 0: | ||
self.logger.info(f"Required balance: {agent_fund_threshold}") | ||
self.logger.info(f"[FUNDING_JOB] Required balance: {agent_fund_threshold}") | ||
if agent_balance < agent_fund_threshold: | ||
jmoreira-valory marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.logger.info("Funding agents") | ||
to_transfer = ( | ||
self.logger.info("[FUNDING_JOB] Funding agents") | ||
target_balance = ( | ||
asset_funding_values["agent"]["topup"] | ||
if asset_funding_values is not None | ||
else fund_requirements.agent | ||
) | ||
transferable_balance = get_asset_balance( | ||
ledger_api=ledger_api, | ||
contract_address=asset_address, | ||
address=wallet.safes[ledger_config.chain], | ||
) | ||
to_transfer = max(min(transferable_balance, target_balance - agent_balance), 0) | ||
self.logger.info( | ||
f"Transferring {to_transfer} asset ({asset_address}) to {key.address}" | ||
f"[FUNDING_JOB] Transferring {to_transfer} asset ({asset_address}) to {key.address}" | ||
) | ||
wallet.transfer_asset( | ||
asset=asset_address, | ||
|
@@ -1519,24 +1525,38 @@ def fund_service_single_chain( # pylint: disable=too-many-arguments,too-many-lo | |
contract_address=asset_address, | ||
address=chain_data.multisig, | ||
) | ||
if asset_address == ZERO_ADDRESS: | ||
# also count the balance of the wrapped native asset | ||
safe_balance += get_asset_balance( | ||
ledger_api=ledger_api, | ||
contract_address=WRAPPED_NATIVE_ASSET.get(chain, asset_address), | ||
address=chain_data.multisig, | ||
) | ||
Comment on lines
+1528
to
+1534
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this approach not taken into account also for the agent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because in the case of Agent EOA, the agent doesn't swap xDAI for wxDAI and we don't want to it to happen that someone send wxDAI to the Agent EOA and the funding job no long funds xDAI in it, failing the agent to make transactions anymore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems quite custom logic, but ok. |
||
|
||
safe_fund_treshold = ( | ||
asset_funding_values["safe"]["threshold"] | ||
if asset_funding_values is not None | ||
else fund_requirements.safe | ||
) | ||
self.logger.info( | ||
f"Safe {chain_data.multisig} Asset: {asset_address} balance: {safe_balance}" | ||
f"[FUNDING_JOB] Safe {chain_data.multisig} Asset: {asset_address} balance: {safe_balance}" | ||
) | ||
self.logger.info(f"Required balance: {safe_fund_treshold}") | ||
self.logger.info(f"[FUNDING_JOB] Required balance: {safe_fund_treshold}") | ||
if safe_balance < safe_fund_treshold: | ||
self.logger.info("Funding safe") | ||
to_transfer = ( | ||
self.logger.info("[FUNDING_JOB] Funding safe") | ||
target_balance = ( | ||
asset_funding_values["safe"]["topup"] | ||
if asset_funding_values is not None | ||
else fund_requirements.safe | ||
) | ||
transferable_balance = get_asset_balance( | ||
ledger_api=ledger_api, | ||
contract_address=asset_address, | ||
address=wallet.safes[ledger_config.chain], | ||
) | ||
to_transfer = max(min(transferable_balance, target_balance - safe_balance), 0) | ||
self.logger.info( | ||
f"Transferring {to_transfer} asset ({asset_address}) to {chain_data.multisig}" | ||
f"[FUNDING_JOB] Transferring {to_transfer} asset ({asset_address}) to {chain_data.multisig}" | ||
) | ||
# TODO: This is a temporary fix | ||
# we avoid the error here because there is a seperate prompt on the UI | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this check not performed in safe as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see why we have this check. agent_fund_threshold will always be passed as positive without any programming error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither. Assuming the template has nonnegative values for the fund requirement, if we set, e.g. 0 fund requirements for USDC, then the condition agent_balance < agent_fund_threshold will not be triggered anyways...