forked from mento-protocol/simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcelo_system.py
48 lines (43 loc) · 1.8 KB
/
celo_system.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
"""
Celo System
General Celo blockchain mechanisms:
* epoch rewards
"""
from model.entities.balance import Balance
from model.generators.accounts import AccountGenerator
from model.constants import target_epoch_rewards_downscaled, seconds_per_epoch, blocktime_seconds
from model.types.base import CryptoAsset, Fiat, Stable
from model.types.pair import Pair
from model.utils.generator_container import inject
@inject(AccountGenerator)
def p_epoch_rewards(_params, _substep, _state_history, prev_state,
account_generator=AccountGenerator):
"""
Naively propage celo supply by adding target epoch rewards per epoch (every 17280 blocks)
Celo epoch target rewards are rewarded linearly over the next 15 years and after
that logarithmically. Here it's only about the next 15 linear years
"""
is_not_epoch_block = (
(prev_state['timestep'] * blocktime_seconds) % seconds_per_epoch) != 0
if is_not_epoch_block or prev_state['timestep'] == 0:
return {
"floating_supply": prev_state["floating_supply"],
"reserve_balance": prev_state["reserve_balance"],
}
validator_rewards = 0.07 * target_epoch_rewards_downscaled
celo_rewards = target_epoch_rewards_downscaled - validator_rewards
validator_rewards_in_cusd = (
validator_rewards
/ prev_state["oracle_rate"].get(Pair(CryptoAsset.CELO, Fiat.USD))
)
account_generator.reserve.balance += Balance({
CryptoAsset.CELO: validator_rewards,
})
account_generator.untracked_floating_supply += Balance({
CryptoAsset.CELO: celo_rewards - validator_rewards,
Stable.CUSD: validator_rewards_in_cusd
})
return {
"floating_supply": account_generator.floating_supply,
"reserve_balance": account_generator.reserve.balance,
}