-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added utilization field to pool
- Loading branch information
Showing
5 changed files
with
80 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from decimal import Decimal | ||
from django.core.management.base import BaseCommand | ||
|
||
from ajna.v1.goerli.chain import GoerliModels | ||
from ajna.v1.ethereum.chain import EthereumModels | ||
|
||
|
||
class Command(BaseCommand): | ||
def _fix_goerli(self): | ||
models = GoerliModels() | ||
snapshots = models.pool_snapshot.objects.filter(utilization__isnull=True) | ||
self.stdout.write( | ||
"Fixing {} goerli pool snapshot utilization".format(snapshots.count()) | ||
) | ||
for snapshot in snapshots: | ||
utilization = Decimal("0") | ||
if snapshot.pool_size > 0: | ||
utilization = snapshot.debt / snapshot.pool_size | ||
|
||
snapshot.utilization = utilization | ||
snapshot.save(update_fields=["utilization"]) | ||
|
||
def _fix_ethereum(self): | ||
models = EthereumModels() | ||
snapshots = models.pool_snapshot.objects.filter(utilization__isnull=True) | ||
self.stdout.write( | ||
"Fixing {} ethereum pool snapshot utilization".format(snapshots.count()) | ||
) | ||
for snapshot in snapshots: | ||
utilization = Decimal("0") | ||
if snapshot.pool_size > 0: | ||
utilization = snapshot.debt / snapshot.pool_size | ||
|
||
snapshot.utilization = utilization | ||
snapshot.save(update_fields=["utilization"]) | ||
|
||
def handle(self, *args, **options): | ||
self._fix_goerli() | ||
self._fix_ethereum() |
32 changes: 32 additions & 0 deletions
32
ajna/migrations/0024_v1ethereumpool_utilization_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 4.2.3 on 2023-07-19 08:12 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("ajna", "0023_v1ethereumliquidationauction_wallet_address_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="v1ethereumpool", | ||
name="utilization", | ||
field=models.DecimalField(decimal_places=18, max_digits=32, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="v1ethereumpoolsnapshot", | ||
name="utilization", | ||
field=models.DecimalField(decimal_places=18, max_digits=32, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="v1goerlipool", | ||
name="utilization", | ||
field=models.DecimalField(decimal_places=18, max_digits=32, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="v1goerlipoolsnapshot", | ||
name="utilization", | ||
field=models.DecimalField(decimal_places=18, max_digits=32, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters