forked from nervosnetwork/ckb-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unlaimed compenstaion generator worker
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
app/workers/dao_contract_unclaimed_compensation_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class DaoContractUnclaimedCompensationGenerator | ||
include Sidekiq::Worker | ||
|
||
def perform | ||
DaoContract.default_contract.update(unclaimed_compensation: cal_unclaimed_compensation) | ||
end | ||
|
||
private | ||
|
||
def cal_unclaimed_compensation | ||
phase1_dao_interests + unmade_dao_interests | ||
end | ||
|
||
def phase1_dao_interests | ||
CellOutput.nervos_dao_withdrawing.generated_before(ended_at).unconsumed_at(ended_at).reduce(0) do |memo, nervos_dao_withdrawing_cell| | ||
memo + CkbUtils.dao_interest(nervos_dao_withdrawing_cell) | ||
end | ||
end | ||
|
||
def unmade_dao_interests | ||
CellOutput.nervos_dao_deposit.generated_before(ended_at).unconsumed_at(ended_at).reduce(0) do |memo, cell_output| | ||
dao = cell_output.block.dao | ||
tip_dao = current_tip_block.dao | ||
parse_dao = CkbUtils.parse_dao(dao) | ||
tip_parse_dao = CkbUtils.parse_dao(tip_dao) | ||
memo + (cell_output.capacity * tip_parse_dao.ar_i / parse_dao.ar_i) - cell_output.capacity | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters