-
Notifications
You must be signed in to change notification settings - Fork 12
/
Pools.py
63 lines (49 loc) · 2.95 KB
/
Pools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from Pool import Pool
import Params
import Query
from util import *
class Pools:
def __init__(self):
distr_info = Query.load_distr_info()
self.gauge_weights = {int(r["gauge_id"]) : int(r["weight"]) for r in distr_info["records"]}
self.total_weight = int(distr_info["total_weight"])
self.cache : dict[str, Any] = {}
all_pools_with_incentives = list(Params.incentivized_pool_ids)
all_pools_with_incentives.extend(x for x in Params.matched_pool_ids if x not in all_pools_with_incentives)
all_pools_with_incentives.sort()
self.pools = {pid : Pool(self, pid) for pid in all_pools_with_incentives}
def get_current_share(self, gids : dict[str, int]):
return sum([self.gauge_weights.get(gid,0) for gid in gids.values()])/self.total_weight
def total_liquidity(self, category : str) -> int:
return cached_call(self.cache, "total_liquidity", lambda:
sum([p.liquidity for p in self.pools.values() if category=="" or p.category == category])
)
def total_fees(self, category : str) -> int:
return sum([p.fees_collected for p in self.pools.values() if category=="" or p.category == category])
def total_capped_fees(self, category : str) -> int:
return sum([p.capped_fees() for p in self.pools.values() if category=="" or p.category == category])
def avg_fee_apr(self, category : str) -> float:
return (365 * self.total_fees(category)) / self.total_liquidity(category)
def total_adjusted_revenue_for(self, category : str) -> int:
return max(sum([p.adjusted_revenue() for p in self.pools.values() if category=="" or p.category == category]),1)
def scale_limit_renormalization_factor(self) -> float:
return cached_call(self.cache, "scale_limit_renormalization_factor", lambda:
Params.total_incentive_share / sum([p.unnorm_scale_limited_target() for p in self.pools.values()])
)
def adjustment_renormalization_factor(self) -> float:
return cached_call(self.cache, "adjusted_renormalization_factor", lambda:
Params.total_incentive_share / sum([p.unnorm_adjusted_share() for p in self.pools.values()])
)
def new_gauges(self) -> dict[int, int]:
gs = {0 : int(Params.gauge_precision * Params.community_pool_share)}
for p in self.pools.values():
new_share = p.adjusted_share()
try:
gs[p.gauge_ids["1209600s"]] = int(new_share * Params.gauge_precision)
# Supercharged pools display as a 24 hour bonded pool to fit into this system. They only have this one gauge while Classic pools have 3 so this can be used as an identifier.
except:
gs[p.gauge_ids["86400s"]] = int(new_share * Params.gauge_precision)
return gs
def total_variable_use(self, category : str) -> float:
pools = [p for p in self.pools.values() if p.category == category]
return sum([p.adjusted_share() for p in pools])