Skip to content

Commit

Permalink
fix multiplier calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandpo committed Aug 15, 2023
1 parent a1383d0 commit 1e7e038
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
4 changes: 4 additions & 0 deletions eagleproject/core/blockchain/harvest/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ def ensure_supply_snapshot(block_number, project=OriginTokens.OUSD) -> SupplySna
)
s.rebasing_credits_ratio = next_rebase_supply / s.credits
s.rebasing_credits_per_token = rebasing_credits_per_token(block_number)
ousd_amo_supply = OUSDMetaStrategy.get_underlying_balance().get("OUSD", Decimal(0))
s.non_rebasing_boost_multiplier = (s.computed_supply - ousd_amo_supply) / (s.computed_supply - s.non_rebasing_supply)
else:
eth = ensure_asset("ETH", block_number, OriginTokens.OETH).redeem_value()
weth = ensure_asset("WETH", block_number, OriginTokens.OETH).redeem_value()
Expand Down Expand Up @@ -413,6 +415,8 @@ def ensure_supply_snapshot(block_number, project=OriginTokens.OUSD) -> SupplySna
else:
s.rebasing_credits_ratio = next_rebase_supply / s.credits
s.rebasing_credits_per_token = rebasing_credits_per_token(block_number, contract=OETH)
oeth_amo_supply = OETHCurveAMOStrategy.get_underlying_balance().get("OETH", Decimal(0))
s.non_rebasing_boost_multiplier = (s.computed_supply - oeth_amo_supply) / (s.computed_supply - s.non_rebasing_supply)

s.save()
return s
Expand Down
8 changes: 4 additions & 4 deletions eagleproject/core/blockchain/harvest/transaction_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@
)
from core.blockchain.rpc import (
creditsBalanceOf,
)
from core.blockchain.rpc import (
balanceOf,
totalSupply,
dripper_available
dripper_available,
OETHCurveAMOStrategy
)
from core.blockchain.apy import (
get_trailing_apy,
Expand Down Expand Up @@ -1619,10 +1618,11 @@ def _daily_rows(steps, latest_block_number, project, start_at=0):
Decimal(100) * change * (Decimal(365) * BLOCKS_PER_DAY) / blocks
)
s.apy = to_apy(s.apr, 1)
amo_supply = OUSDMetaStrategy.get_underlying_balance().get("OUSD", Decimal(0)) if project == OriginTokens.OUSD else OETHCurveAMOStrategy.get_underlying_balance().get("OETH", Decimal(0))
try:
s.unboosted = to_apy(
(s.computed_supply - s.non_rebasing_supply)
/ s.computed_supply
/ (s.computed_supply - amo_supply)
* s.apr,
1,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.1.7 on 2023-08-15 19:06

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0051_update_analytics_reports"),
]

operations = [
migrations.AddField(
model_name="supplysnapshot",
name="non_rebasing_boost_multiplier",
field=models.DecimalField(decimal_places=18, default=0, max_digits=64),
),
]
9 changes: 1 addition & 8 deletions eagleproject/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class SupplySnapshot(models.Model):
rebasing_credits_per_token = models.DecimalField(
max_digits=64, decimal_places=18, default=0
)
non_rebasing_boost_multiplier = models.DecimalField(max_digits=64, decimal_places=18, default=0)
apr = Decimal(0) # Not persisted
apy = Decimal(0) # Not persisted
gain = Decimal(0) # Not persisted
Expand Down Expand Up @@ -189,14 +190,6 @@ def non_rebasing_boost_percentage(self):
- 1
) * 100

def non_rebasing_boost_multiplier(self):
number = self.computed_supply - self.non_rebasing_supply
if number == 0:
return 0
return self.computed_supply / (
number
)

class Meta:
ordering = ["-block_number"]
indexes = [
Expand Down
6 changes: 3 additions & 3 deletions eagleproject/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
latest_block,
rebasing_credits_per_token,
totalSupply,
OUSDMetaStrategy
OUSDMetaStrategy,
)

from core.channels.email import Email
Expand Down Expand Up @@ -483,12 +483,12 @@ def api_daily_stats(request, project, days, start=0):
"date": x.effective_day,
"yield": x.gain,
"fees": x.fees,
"backing_supply" : x.computed_supply,
"backing_supply" : x.computed_supply,
"rebasing_supply": x.rebasing_computed_supply(),
"non_rebasing_supply": x.non_rebasing_supply,
"apy": x.apy,
"raw_apy": x.unboosted,
"apy_boost": x.non_rebasing_boost_multiplier(),
"apy_boost": x.non_rebasing_boost_multiplier,
"rebase_events": x.rebase_events
} for x in rows],
}
Expand Down
4 changes: 3 additions & 1 deletion eagleproject/scripts/recompute_oeth_supplysnapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from core.blockchain.harvest.snapshots import ensure_supply_snapshot, ensure_asset
from core.models import OriginTokens, SupplySnapshot

from core.blockchain.rpc import origin_token_rebasing_credits, totalSupply, origin_token_non_rebasing_supply, rebasing_credits_per_token
from core.blockchain.rpc import origin_token_rebasing_credits, totalSupply, origin_token_non_rebasing_supply, rebasing_credits_per_token, OETHCurveAMOStrategy

def run(*script_args):
start_block = int(script_args[0]) if len(script_args) > 0 else START_OF_OETH
Expand Down Expand Up @@ -48,6 +48,8 @@ def run(*script_args):
else:
s.rebasing_credits_ratio = next_rebase_supply / s.credits
s.rebasing_credits_per_token = rebasing_credits_per_token(s.block_number, contract=OETH)
oeth_amo_supply = OETHCurveAMOStrategy.get_underlying_balance(s.block_number).get("OETH", Decimal(0))
s.non_rebasing_boost_multiplier = (s.computed_supply - oeth_amo_supply) / (s.computed_supply - s.non_rebasing_supply)

s.save()

Expand Down

0 comments on commit 1e7e038

Please sign in to comment.