pendulum-chain/spacewalk

Add `on_initialize` hook to `reward-distribution` pallet

Closed this issue · 2 comments

This ticket is a part of https://github.com/pendulum-chain/tasks/issues/47

This ticket depends on #405

Add an on_initialize hook

  • if RewardPerBlock is None, return
  • call ensure_parachain_status_running of the security pallet and return if error
  • call parachain_block_expired of the security pallet providing RewardsAdaptedAt and the DecayInterval - 1 (because parachain_block_expired checks for > instead of >=). If it is true, then multiply RewardPerBlock by DecayRate and set RewardsAdaptedAt to the current active block number
  • for each collateral currency id in the system
    • call total_stake of PooledRewards, where pool_id is that currency id
    • determine the USD value of the total locked collateral of this currency id (using convert_to of the Amount type)
  • add up the USD value over all currency ids
  • for each collateral currency id in the system
    • determine the percentage of the USD value of this currency id over the total USD value (as a Perquintill using Perquintill::from_rational)
    • call distribute_reward of PooledRewards, where pool_id is the currency id, currency_id is the native token, reward is RewardPerBlock multiplied with the percentage
ebma commented

This was addressed in #415