Skip to content
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

feat: EOA auction addresses #6

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ajna/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,18 @@ def call_multicall(self, calls, block_id=None):
multi = Multicall(multicalls, _w3=self.web3, block_id=block_id)

return multi()

def get_eoa(self, contract_address):
abi = [
{
"inputs": [],
"name": "owner",
"outputs": [{"internalType": "address", "name": "", "type": "address"}],
"stateMutability": "view",
"type": "function",
},
]
contract = self.eth.contract(
address=Web3.toChecksumAddress(contract_address), abi=abi
)
return contract.caller.owner()
18 changes: 0 additions & 18 deletions ajna/management/commands/backpopulate_pool_volume_snapshot.py

This file was deleted.

29 changes: 29 additions & 0 deletions ajna/management/commands/fix_auction_eoa_addresses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.core.management.base import BaseCommand

from ajna.v1.ethereum.chain import Ethereum, EthereumModels
from ajna.v1.goerli.chain import Goerli, GoerliModels
from ajna.v1.modules.auctions import _get_wallet_address


class Command(BaseCommand):
def _fix_eth(self):
self.stdout.write("Fixing ethereum auctions")
chain = Ethereum()
models = EthereumModels()
auctions = models.liqudation_auction.objects.all()
for auction in auctions:
auction.wallet_address = _get_wallet_address(chain, auction.borrower)
auction.save()

def _fix_goerli(self):
self.stdout.write("Fixing goerli auctions")
chain = Goerli()
models = GoerliModels()
auctions = models.liqudation_auction.objects.all()
for auction in auctions:
auction.wallet_address = _get_wallet_address(chain, auction.borrower)
auction.save()

def handle(self, *args, **options):
self._fix_eth()
self._fix_goerli()
17 changes: 0 additions & 17 deletions ajna/management/commands/fix_pool_actual_utilization.py

This file was deleted.

29 changes: 0 additions & 29 deletions ajna/management/commands/fix_pool_collateralization.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.3 on 2023-07-14 08:41

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("ajna", "0022_remove_v1ethereumpool_collateralization_and_more"),
]

operations = [
migrations.AddField(
model_name="v1ethereumliquidationauction",
name="wallet_address",
field=models.CharField(max_length=42, null=True),
),
migrations.AddField(
model_name="v1goerliliquidationauction",
name="wallet_address",
field=models.CharField(max_length=42, null=True),
),
]
1 change: 1 addition & 0 deletions ajna/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class LiquidationAuction(models.Model):
collateral_remaining = models.DecimalField(max_digits=32, decimal_places=18)
collateral = models.DecimalField(max_digits=32, decimal_places=18)
borrower = models.CharField(max_length=42)
wallet_address = models.CharField(max_length=42, null=True)
bond_size = models.DecimalField(max_digits=32, decimal_places=18)
bond_factor = models.DecimalField(max_digits=32, decimal_places=18)
last_take_price = models.DecimalField(max_digits=32, decimal_places=18, null=True)
Expand Down
2 changes: 1 addition & 1 deletion ajna/sources/subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _fetch_all_by_field(self, query, key, field, value, page_size=1000):
if len(data) < page_size:
break

log.warning(
log.error(
"Potential data loss while fetching from subgraph",
extra={
"endpoint": self.client.endpoint,
Expand Down
8 changes: 5 additions & 3 deletions ajna/v1/ethereum/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ def sync_liquidation_auctions_tasks():
else:
last_settle_time = 0

chain = Ethereum()
subgraph = EthereumSubgraph()
fetch_and_save_settled_liquidation_auctions(
subgraph, models.liqudation_auction, models.price_feed, last_settle_time
chain, subgraph, models.liqudation_auction, models.price_feed, last_settle_time
)
fetch_and_save_active_liquidation_auctions(
chain, subgraph, models.liqudation_auction
)
subgraph = EthereumSubgraph()
fetch_and_save_active_liquidation_auctions(subgraph, models.liqudation_auction)


@app.task
Expand Down
8 changes: 5 additions & 3 deletions ajna/v1/goerli/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ def sync_liquidation_auctions_tasks():
else:
last_settle_time = 0

chain = Goerli()
subgraph = GoerliSubgraph()
fetch_and_save_settled_liquidation_auctions(
subgraph, models.liqudation_auction, models.price_feed, last_settle_time
chain, subgraph, models.liqudation_auction, models.price_feed, last_settle_time
)
fetch_and_save_active_liquidation_auctions(
chain, subgraph, models.liqudation_auction
)
subgraph = GoerliSubgraph()
fetch_and_save_active_liquidation_auctions(subgraph, models.liqudation_auction)


@app.task
Expand Down
22 changes: 20 additions & 2 deletions ajna/v1/modules/auctions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
from datetime import datetime
from decimal import Decimal

from web3 import Web3


def _get_wallet_address(chain, address):
address = Web3.toChecksumAddress(address)
code = chain.eth.get_code(address).hex()
if len(code) > 2:
address = chain.get_eoa(address)
return address.lower()


def fetch_and_save_settled_liquidation_auctions(
subgraph, liquidation_auction_model, price_feed_model, settle_time=0
chain, subgraph, liquidation_auction_model, price_feed_model, settle_time=0
):
"""
Fetches liquidationAuctions from the Subgraph and saves it to the LiquidationAuctions
Expand Down Expand Up @@ -44,6 +54,9 @@ def fetch_and_save_settled_liquidation_auctions(
.earliest()
.price
)

wallet_address = _get_wallet_address(chain, auction["borrower"])

liquidation_auction_model.objects.update_or_create(
uid=auction["id"],
defaults={
Expand All @@ -57,6 +70,7 @@ def fetch_and_save_settled_liquidation_auctions(
"collateral_remaining": Decimal(auction["collateralRemaining"]),
"collateral": Decimal(auction["collateral"]),
"borrower": auction["borrower"],
"wallet_address": wallet_address,
"bond_size": Decimal(auction["bondSize"]),
"bond_factor": Decimal(auction["bondFactor"]),
"last_take_price": Decimal(auction["lastTakePrice"]),
Expand All @@ -70,7 +84,9 @@ def fetch_and_save_settled_liquidation_auctions(
)


def fetch_and_save_active_liquidation_auctions(subgraph, liquidation_auction_model):
def fetch_and_save_active_liquidation_auctions(
chain, subgraph, liquidation_auction_model
):
"""
Fetches liquidationAuctions from the Subgraph and saves it to the LiquidationAuctions
model.
Expand All @@ -79,6 +95,7 @@ def fetch_and_save_active_liquidation_auctions(subgraph, liquidation_auction_mod
for auction in auctions:
collateral_token_address = auction["pool"]["collateralToken"]["id"]
debt_token_address = auction["pool"]["quoteToken"]["id"]
wallet_address = _get_wallet_address(chain, auction["borrower"])
liquidation_auction_model.objects.update_or_create(
uid=auction["id"],
defaults={
Expand All @@ -92,6 +109,7 @@ def fetch_and_save_active_liquidation_auctions(subgraph, liquidation_auction_mod
"collateral_remaining": Decimal(auction["collateralRemaining"]),
"collateral": Decimal(auction["collateral"]),
"borrower": auction["borrower"],
"wallet_address": wallet_address,
"bond_size": Decimal(auction["bondSize"]),
"bond_factor": Decimal(auction["bondFactor"]),
"last_take_price": Decimal(auction["lastTakePrice"]),
Expand Down
2 changes: 1 addition & 1 deletion latest_migrations.manifest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
admin: 0003_logentry_add_action_flag_choices
ajna: 0022_remove_v1ethereumpool_collateralization_and_more
ajna: 0023_v1ethereumliquidationauction_wallet_address_and_more
auth: 0012_alter_user_first_name_max_length
contenttypes: 0002_remove_content_type_name
django_celery_beat: 0018_improve_crontab_helptext
Expand Down