Skip to content

Commit

Permalink
Merge pull request #74 from IntersectMBO/fix/59-fix-predefined-drep-v…
Browse files Browse the repository at this point in the history
…oting-power

[59] Fixed vote counting problem
  • Loading branch information
jankun4 authored Jan 24, 2024
2 parents 0a49daf + 9fcfeaf commit cfe2b2b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
As a minor extension, we also keep a semantic version for the `UNRELEASED`
changes.

## [Unreleased]

### Fixed
- Fixed vote calculation problems related to NoConfidence DRep [Issue 59](https://github.com/IntersectMBO/govtool/issues/59)

## [sancho-v1.0.1](https://github.com/IntersectMBO/govtool/releases/tag/sancho-v1.0.1) 2023-12-XX

### Added
-
-

### Fixed
-
-

### Changed
- Changed Node version from 8.7.1-pre to 8.7.2 and Db-sync version from sancho-2-3-0 to sancho-3-0-0.
- (`docs/update-working-conventions`) Addressing [Issue 25](https://github.com/IntersectMBO/govtool/issues/25) changed working conventions documentation to improve intended flows.

### Removed
-
-

## [sancho-v1.0.0](https://github.com/IntersectMBO/govtool/releases/tag/sancho-v1.0.0) 2023-12-17

Expand Down
47 changes: 43 additions & 4 deletions src/vva-be/sql/list-proposals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ WITH LatestDrepDistr AS (
Max(no) as last_epoch_no,
Max(end_time) as last_epoch_end_time
FROM epoch
), always_no_confidence_voting_power as (
select amount
from drep_distr
join drep_hash
on drep_hash.id = drep_distr.hash_id
where drep_hash.view = 'drep_always_no_confidence'
order by epoch_no desc
limit 1
), always_abstain_voting_power as (
select amount
from drep_distr
join drep_hash
on drep_hash.id = drep_distr.hash_id
where drep_hash.view = 'drep_always_abstain'
order by epoch_no desc
limit 1
)

select
Expand All @@ -21,11 +37,22 @@ select
creator_block.time, /* created date */
voting_anchor.url,
encode(voting_anchor.data_hash, 'hex'),
coalesce(Sum(ldd.amount) filter (where voting_procedure.vote::text = 'Yes'),0) "yes_votes",
coalesce((select no_confidence_drep_distr.amount from drep_distr as no_confidence_drep_distr join drep_hash on no_confidence_drep_distr.hash_id = drep_hash.id where drep_hash.view='drep_always_no_confidence' order by no_confidence_drep_distr.epoch_no desc limit 1) + Sum(ldd.amount) filter (where voting_procedure.vote::text = 'No'), 0) "no_votes",
coalesce((select abstain_drep_distr.amount from drep_distr as abstain_drep_distr join drep_hash on abstain_drep_distr.hash_id = drep_hash.id where drep_hash.view='drep_always_abstain' order by abstain_drep_distr.epoch_no desc limit 1), 0) "abstain_votes"

coalesce(Sum(ldd.amount) filter (where voting_procedure.vote::text = 'Yes'),0)
+ (case
when gov_action_proposal.type = 'NoConfidence' then always_no_confidence_voting_power.amount
else 0
end) "yes_votes",
coalesce(Sum(ldd.amount) filter (where voting_procedure.vote::text = 'No'),0) +
(case
when gov_action_proposal.type = 'NoConfidence' then 0
else always_no_confidence_voting_power.amount
end) "no_votes",
coalesce(Sum(ldd.amount) filter (where voting_procedure.vote::text = 'Abstain'),0) + always_abstain_voting_power.amount "abstain_votes"
from gov_action_proposal
cross join EpochUtils as epoch_utils
cross join always_no_confidence_voting_power
cross join always_abstain_voting_power
join tx as creator_tx
on creator_tx.id = gov_action_proposal.tx_id
join block as creator_block
Expand All @@ -44,4 +71,16 @@ and gov_action_proposal.enacted_epoch is null
and gov_action_proposal.expired_epoch is null
and gov_action_proposal.dropped_epoch is null

group by (gov_action_proposal.id, gov_action_proposal.index, creator_tx.hash, creator_block.time, epoch_utils.epoch_duration, epoch_utils.last_epoch_no, epoch_utils.last_epoch_end_time, voting_anchor.url, voting_anchor.data_hash)
group by (
gov_action_proposal.id,
gov_action_proposal.index,
creator_tx.hash,
creator_block.time,
epoch_utils.epoch_duration,
epoch_utils.last_epoch_no,
epoch_utils.last_epoch_end_time,
voting_anchor.url,
voting_anchor.data_hash,
always_no_confidence_voting_power.amount,
always_abstain_voting_power.amount
)

0 comments on commit cfe2b2b

Please sign in to comment.