strategy.py 905 B

12345678910111213141516171819202122232425262728293031323334
  1. from utils import *
  2. class Strategy(object):
  3. def __init__(self, epoch_len=0):
  4. self.epoch_len = epoch_len
  5. self.staked_tokens_ratio = Num(1)
  6. def set_ratio(self, slot=0, apy=0):
  7. pass
  8. def staked_value(self, stake):
  9. return self.staked_tokens_ratio*Num(stake)
  10. class RandomStrategy(Strategy):
  11. def __init__(self, epoch_len):
  12. Strategy.__init__(self, epoch_len)
  13. def set_ratio(self, slot, apy=0):
  14. if slot%self.epoch_len==0:
  15. self.staked_tokens_ratio = random.random()
  16. class LinearStrategy(Strategy):
  17. '''
  18. linear staking strategy wrt apy.
  19. assume optimal is 20% APY!
  20. '''
  21. def __init__(self, epoch_len=0):
  22. Strategy.__init__(self, epoch_len)
  23. self.TARGET_APY = 20.0
  24. def set_ratio(self, slot, apy):
  25. if slot%self.epoch_len==0:
  26. self.staked_tokens_ratio = apy/Num(self.TARGET_APY)