Skip to content

Commit

Permalink
updated API to return subaccount
Browse files Browse the repository at this point in the history
  • Loading branch information
leemount96 committed Sep 9, 2024
1 parent aefe288 commit 5733a48
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/liquidation/liquidation_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 14 additions & 5 deletions app/liquidation/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5733a48

Please sign in to comment.