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

Update USD TVL calculating #70

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
9 changes: 1 addition & 8 deletions backends/redoubt/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ def _do_calculate(self, config: SeasonConfig, dry_run: bool = False):
and build_time < to_timestamp({config.start_time}) - interval '14 day' -- end of the S4 season
order by thd.address, build_time desc
), tvl_prior_start as (
select symbol, sum(tvl_ton) as start_tvl,
(
select rate from ton_usd_rates
where build_time < to_timestamp({config.start_time}) - interval '14 day'
order by build_time desc limit 1
) * sum(tvl_ton) as start_tvl_usd
select symbol, sum(tvl_ton) as start_tvl
from tvl_prior_start_all
group by 1
), current_tvl as (
Expand Down Expand Up @@ -122,7 +117,6 @@ def _do_calculate(self, config: SeasonConfig, dry_run: bool = False):
prizes,
url, boost_link,
coalesce(start_tvl, 0) as start_tvl,
coalesce(start_tvl_usd, 0) as start_tvl_usd,
coalesce(last_tvl.tvl, 0) as last_tvl,
coalesce(100 * coalesce(price_change, 0), 0) as price_delta,
coalesce(price_before, 0) as price_before,
Expand Down Expand Up @@ -156,7 +150,6 @@ def _do_calculate(self, config: SeasonConfig, dry_run: bool = False):
results[row['symbol']].metrics[ProjectStat.TOKEN_IS_MEME] = row['is_meme']
results[row['symbol']].metrics[ProjectStat.TOKEN_HAS_BOOST] = row['has_boost']
results[row['symbol']].metrics[ProjectStat.TOKEN_START_TVL] = int(row['start_tvl'])
results[row['symbol']].metrics[ProjectStat.TOKEN_START_TVL_USD] = int(row['start_tvl_usd'])
results[row['symbol']].metrics[ProjectStat.TOKEN_LAST_TVL] = int(row['last_tvl'])
results[row['symbol']].metrics[ProjectStat.TOKEN_PRICE_BEFORE] = float(row['price_before'])
results[row['symbol']].metrics[ProjectStat.TOKEN_PRICE_AFTER] = float(row['price_after'])
Expand Down
4 changes: 3 additions & 1 deletion seasons/tokens_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, reward_list: Optional[List[int]] = None):
"500K – 1M": {"low": 500_000, "high": 1_000_000, "coefficient": 0.4},
"100K – 500K": {"low": None, "high": 500_000, "coefficient": 0.3},
}
self.ton_usd_rate = 7.50648 # 2024-06-26 11:00:00

def get_tvl_category(self, tvl_value) -> str:
for category_name, limits in self.tvl_category.items():
Expand All @@ -56,7 +57,8 @@ def get_tvl_category(self, tvl_value) -> str:
def calculate(self, metrics: List[ProjectStat]):
for project in metrics:
logger.info(f"Calculating score for {project}")
project.metrics[ProjectStat.TOKEN_TVL_CATEGORY] = self.get_tvl_category(project.metrics[ProjectStat.TOKEN_START_TVL_USD])
start_tvl_usd = project.metrics[ProjectStat.TOKEN_START_TVL] * self.ton_usd_rate
project.metrics[ProjectStat.TOKEN_TVL_CATEGORY] = self.get_tvl_category(start_tvl_usd)
price_change_weight = 30 * self.tvl_category[project.metrics[ProjectStat.TOKEN_TVL_CATEGORY]]["coefficient"]
tvl_change_weight = 30 + (30 - price_change_weight) * 3 / 7
new_holders_weight = 40 + (30 - price_change_weight) * 4 / 7
Expand Down
Loading