Skip to content

Commit

Permalink
New TVL Volume league
Browse files Browse the repository at this point in the history
  • Loading branch information
shuva10v committed Sep 12, 2024
1 parent fc16154 commit a95260c
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backends/defi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DefillamaDeFiBackend(CalculationBackend):
}
}
def __init__(self, tonapi: TonapiAdapter, executor: ContractsExecutor):
CalculationBackend.__init__(self, "defillama backend for defi leaderboard",
CalculationBackend.__init__(self, "defillama backend for defi leaderboard (TVL)",
leaderboards=[SeasonConfig.DEFI])
self.tonapi = tonapi
self.executor = executor
Expand Down Expand Up @@ -72,7 +72,7 @@ def _do_calculate(self, config: SeasonConfig, dry_run: bool = False):
snapshot_ton_rate = self.ton_rate(config.start_time)
logger.info(f"Snapshot TON rate: {snapshot_ton_rate}$, current TON rate: {current_ton_rate}$")

assert config.block_before_start_ref is not None, "Start block is required for the DeFi leaderboard"
# assert config.block_before_start_ref is not None, "Start block is required for the DeFi leaderboard"

end_block = None
if int(time.time()) > config.end_time:
Expand Down
1 change: 1 addition & 0 deletions models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ class DeFi(Project):
url: str # project url
defillama_slug: str # Defillama slug
prizes: bool = True # flat to ignore project in reward calculation
category: str = "dexs" # category for the project (for the Volume Leaderboard)
1 change: 1 addition & 0 deletions models/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ProjectStat:
DEFI_TVL_AFTER_COUNTED = 'defi_tvl_after_counted'
DEFI_TVL_DELTA = 'defi_tvl_delta_full'
DEFI_TVL_DELTA_COUNTED = 'defi_tvl_delta'
DEFI_VOLUME_USD = 'volume_usd'

TITLE = 'title'
URL = 'url'
Expand Down
3 changes: 2 additions & 1 deletion projects/defi/Tradoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
Tradoor = DeFi(
name='Tradoor',
defillama_slug='tradoor',
url='https://tradoor.io/'
url='https://tradoor.io/',
category='derivatives'
)
Binary file added projects/icons/defi_gaspump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ psycopg2==2.9.5
gitpython
requests
tonsdk
pillow
pillow
pandas
24 changes: 23 additions & 1 deletion seasons/defi_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def calculate(self, metrics: List[ProjectStat]):
"""
Returns contributin of positive TVL into overall TVL growth
"""
class DeFiContribution(ScoreModel):
class DeFiTVLContribution(ScoreModel):

def calculate(self, metrics: List[ProjectStat]):
total_tvl_delta = 0
Expand All @@ -66,4 +66,26 @@ def calculate(self, metrics: List[ProjectStat]):
project.score = 0

return sorted(metrics, key=lambda m: m.score, reverse=True)

"""
Returns contributin of trading volume into overall trading volume
"""
class DeFiVolumeContribution(ScoreModel):

def calculate(self, metrics: List[ProjectStat]):
total_volme = 0
for project in metrics:
volume = project.metrics[ProjectStat.DEFI_VOLUME_USD]
assert volume > 0
total_volme += volume
logger.info(f"Total trading volume is {total_volme:0.2f}$")

for project in metrics:
volume = project.metrics[ProjectStat.DEFI_VOLUME_USD]
if total_volme > 0:
project.score = volume / total_volme
else:
project.score = 0

return sorted(metrics, key=lambda m: m.score, reverse=True)

16 changes: 14 additions & 2 deletions seasons/s6.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from projects.defi.DAOLama import DAOLama
from projects.defi.DeDust import DeDust
from projects.defi.EVAA import EVAA
from projects.defi.GasPump import GasPumpDeFi
from projects.defi.StonFi import StonFi
from projects.defi.StormTrade import StormTrade
from projects.defi.Tradoor import Tradoor
Expand Down Expand Up @@ -74,7 +75,7 @@
from projects.nfts.PovelDurevNFT2 import PovelDurevNFT2
from projects.nfts.TONTanks import TONTanks
from seasons.app_models import AppLeaderboardModelS6
from seasons.defi_models import DeFiContribution, DeFiWeightedRewards
from seasons.defi_models import DeFiTVLContribution, DeFiVolumeContribution
from seasons.nfts_models import NFTLeaderboardModelV1

S6_START = 1726138800 # Thu Sep 12 2024 11:00:00 GMT+0000
Expand Down Expand Up @@ -156,6 +157,17 @@
projects=[
DAOLama, Tradoor
],
score_model=DeFiContribution(),
score_model=DeFiTVLContribution(),
options={SeasonConfig.OPTION_DEFI_EXCLUDED_POOLS: []}
)

S6_defi_volume = SeasonConfig(
leaderboard=SeasonConfig.DEFI,
name="S6",
start_time=S6_START,
end_time=S6_END,
projects=[
Tradoor, GasPumpDeFi
],
score_model=DeFiVolumeContribution()
)
8 changes: 6 additions & 2 deletions test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from backends.contracts_executor import ContractsExecutor
from backends.defi import DefillamaDeFiBackend
from backends.defi_volume import DefillamaDeFiVolumeBackend
from backends.sbt_enrollment import SBTEnrollmentSync
from backends.redoubt.apps import RedoubtAppBackend
from backends.redoubt.apps_v2 import RedoubtAppBackendV2
Expand All @@ -19,7 +20,7 @@
from models.render_method import JsonRenderMethod, HTMLRenderMethod
from models.season_config import SeasonConfig
from seasons.s5 import S5_apps, S5_tokens
from seasons.s6 import S6_apps, S6_nfts, S6_defi_tvl
from seasons.s6 import S6_apps, S6_nfts, S6_defi_tvl, S6_defi_volume

if __name__ == "__main__":
with psycopg2.connect() as conn:
Expand Down Expand Up @@ -47,6 +48,9 @@
executor=ContractsExecutor(os.getenv('CONTRACTS_EXECUTOR_URL'))
)
season = S6_defi_tvl
elif sys.argv[1] == 'defi_volume':
backend = DefillamaDeFiVolumeBackend()
season = S6_defi_volume
elif sys.argv[1] == 'sbt':
backend = SBTEnrollmentSync(conn,
tonapi=TonapiAdapter(),
Expand All @@ -59,7 +63,7 @@

res = backend.calculate(season, dry_run=len(sys.argv) > 2 and sys.argv[2] == '--dryrun')
logger.info(res)
render = JsonRenderMethod("output.json")
render = JsonRenderMethod("output.json", "https://the-open-league-static-data.s3.amazonaws.com/icons/")
render.render(res, season)
render = HTMLRenderMethod("output.html")
render.render(res, season)

0 comments on commit a95260c

Please sign in to comment.