From 5733a48b334a22129814a802ec48fe0a1d358be0 Mon Sep 17 00:00:00 2001 From: Lee Date: Mon, 9 Sep 2024 13:32:48 -0700 Subject: [PATCH] updated API to return subaccount --- app/liquidation/liquidation_bot.py | 2 +- app/liquidation/routes.py | 19 ++++++++++++++----- requirements.txt | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/liquidation/liquidation_bot.py b/app/liquidation/liquidation_bot.py index c68b545..cd94ff4 100644 --- a/app/liquidation/liquidation_bot.py +++ b/app/liquidation/liquidation_bot.py @@ -1472,7 +1472,7 @@ def get_uniswap_swap_data(asset_in: str, return None def get_account_monitor_and_evc_listener(): - acct_monitor = AccountMonitor(True, True) + acct_monitor = AccountMonitor(False, False) acct_monitor.load_state(config.SAVE_STATE_PATH) evc_listener = EVCListener(acct_monitor) diff --git a/app/liquidation/routes.py b/app/liquidation/routes.py index 313ad55..a726860 100644 --- a/app/liquidation/routes.py +++ b/app/liquidation/routes.py @@ -29,10 +29,19 @@ def get_all_positions(): logger.info("API: Getting all positions") sorted_accounts = monitor.get_accounts_by_health_score() - response = [ - {"address": address, "health_score": health_score, "value_borrowed": value_borrowed} - for (address, health_score, value_borrowed) in sorted_accounts - if not math.isinf(health_score) - ] + response = [] + for (address, health_score, value_borrowed) in sorted_accounts: + owner, sub_account = get_subaccount_number(address) + if math.isinf(health_score): + continue + response.append({"address": owner, "sub_account": sub_account, "health_score": health_score, "value_borrowed": value_borrowed}) return make_response(jsonify(response)) + +def get_subaccount_number(account): + owner = evc_listener.evc_instance.functions.getAccountOwner(account).call() + if owner == "0x0000000000000000000000000000000000000000": + owner = account + + subaccount_number = int(int(account, 16) ^ int(owner, 16)) + return owner, subaccount_number \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 90073e9..4265688 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,9 +22,9 @@ eth-typing==4.2.3 eth-utils==4.1.1 eth_abi==5.1.0 Flask==3.0.3 -Flask-Cors==4.0.0 -gunicorn==21.2.0 +Flask-Cors==5.0.0 frozenlist==1.4.1 +gunicorn==23.0.0 hexbytes==0.3.1 idna==3.7 isort==5.13.2