@@ -69,14 +69,16 @@ def liquidity
6969 define_logic :claimed_compensation do
7070 claimed_compensation = 0
7171 if from_scratch
72- CellOutput . nervos_dao_withdrawing . consumed_before ( ended_at ) . find_each do |nervos_dao_withdrawing_cell |
72+ DaoEvent . processed . withdraw_from_dao . consumed_before ( ended_at ) . find_each do |dao_event |
73+ nervos_dao_withdrawing_cell = CellOutput . find_by ( ckb_transaction_id : dao_event . ckb_transaction_id , cell_index : dao_event . cell_index )
7374 claimed_compensation += CkbUtils . dao_interest ( nervos_dao_withdrawing_cell )
7475 end
7576 else
7677 claimed_compensation_today = 0
7778
78- CellOutput . nervos_dao_withdrawing . consumed_between ( started_at ,
79- ended_at ) . find_each do |nervos_dao_withdrawing_cell |
79+ DaoEvent . processed . withdraw_from_dao . consumed_between ( started_at ,
80+ ended_at ) . find_each do |dao_event |
81+ nervos_dao_withdrawing_cell = CellOutput . find_by ( ckb_transaction_id : dao_event . ckb_transaction_id , cell_index : dao_event . cell_index )
8082 claimed_compensation_today += CkbUtils . dao_interest ( nervos_dao_withdrawing_cell )
8183 end
8284
@@ -90,14 +92,14 @@ def liquidity
9092 sum_interest_bearing = 0
9193 sum_uninterest_bearing = 0
9294
93- CellOutput . nervos_dao_withdrawing . generated_before ( ended_at ) . unconsumed_at ( ended_at ) . find_each do |nervos_dao_withdrawing_cell |
94- nervos_dao_withdrawing_cell_generated_tx = nervos_dao_withdrawing_cell . ckb_transaction
95- nervos_dao_deposit_cell = nervos_dao_withdrawing_cell_generated_tx . cell_inputs . order ( :id ) [ nervos_dao_withdrawing_cell . cell_index ] . previous_cell_output
95+ DaoEvent . processed . withdraw_from_dao . created_before ( ended_at ) . unconsumed_at ( ended_at ) . find_each do |nervos_dao_withdrawing_cell |
96+ nervos_dao_deposit_cell = CellInput . find_by ( ckb_transaction_id : nervos_dao_withdrawing_cell . ckb_transaction_id , index : nervos_dao_withdrawing_cell . cell_index ) . previous_cell_output
9697 interest_bearing_deposits += nervos_dao_deposit_cell . capacity
9798 sum_interest_bearing += nervos_dao_deposit_cell . capacity * ( nervos_dao_withdrawing_cell . block_timestamp - nervos_dao_deposit_cell . block_timestamp ) / MILLISECONDS_IN_DAY
9899 end
99100
100- CellOutput . nervos_dao_deposit . generated_before ( ended_at ) . unconsumed_at ( ended_at ) . find_each do |nervos_dao_deposit_cell |
101+ DaoEvent . includes ( :cell_output ) . processed . deposit_to_dao . created_before ( ended_at ) . unconsumed_at ( ended_at ) . find_each do |dao_event |
102+ nervos_dao_deposit_cell = dao_event . cell_output
101103 uninterest_bearing_deposits += nervos_dao_deposit_cell . capacity
102104
103105 sum_uninterest_bearing += nervos_dao_deposit_cell . capacity * ( ended_at - nervos_dao_deposit_cell . block_timestamp ) / MILLISECONDS_IN_DAY
@@ -478,8 +480,9 @@ def phase1_dao_interests
478480 @phase1_dao_interests ||=
479481 begin
480482 total = 0
481- CellOutput . nervos_dao_withdrawing .
482- generated_before ( ended_at ) . unconsumed_at ( ended_at ) . find_each do |nervos_dao_withdrawing_cell |
483+ DaoEvent . processed . withdraw_from_dao .
484+ created_before ( ended_at ) . unconsumed_at ( ended_at ) . find_each do |dao_event |
485+ nervos_dao_withdrawing_cell = CellOutput . find_by ( ckb_transaction_id : dao_event . ckb_transaction_id , cell_index : dao_event . cell_index )
483486 total += CkbUtils . dao_interest ( nervos_dao_withdrawing_cell )
484487 end
485488 total
@@ -491,9 +494,9 @@ def unmade_dao_interests
491494 begin
492495 tip_dao = current_tip_block . dao
493496 total = 0
494- CellOutput . nervos_dao_deposit .
495- generated_before ( ended_at ) . unconsumed_at ( ended_at ) . find_each do |cell_output |
496- total += DaoCompensationCalculator . new ( cell_output , tip_dao ) . call
497+ DaoEvent . includes ( :cell_output ) . processed . deposit_to_dao .
498+ created_before ( ended_at ) . unconsumed_at ( ended_at ) . find_each do |dao_event |
499+ total += DaoCompensationCalculator . new ( dao_event . cell_output , tip_dao ) . call
497500 end
498501 total
499502 end
0 commit comments