Skip to content

Commit

Permalink
Merge pull request #2422 from IntersectMBO/staging
Browse files Browse the repository at this point in the history
GovTool - v1.0.28
  • Loading branch information
MSzalowski authored Nov 26, 2024
2 parents d18ebab + e8695b7 commit 5f9b030
Show file tree
Hide file tree
Showing 43 changed files with 6,268 additions and 1,020 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ changes.

-

## [v1.0.28](https://github.com/IntersectMBO/govtool/releases/tag/v1.0.28) 2024-11-26

### Added

- Add more useful metrics to the backend GET /network/metrics endpoint [Issue 2010](https://github.com/IntersectMBO/govtool/issues/2010)

### Fixed

- Fix ada holder voting power calculation
- Fix wrong statuses on past DRep info
- Fix listing voted-on governance actions [Issue 2379](https://github.com/IntersectMBO/govtool/issues/2379)
- Fix wronly displayed markdown on slider card [Issue 2263](https://github.com/IntersectMBO/govtool/issues/2316)
- fix ada quantities format to avoid thousands when the total is 0 [Issue 2372](https://github.com/IntersectMBO/govtool/issues/2382)
- fix inconsistent display of delegated DRep card during delegation [Issue 2332](https://github.com/IntersectMBO/govtool/issues/2332)

### Changed

- Bump CSL version to 13.1.0 [Issue 2169](https://github.com/IntersectMBO/govtool/issues/2169)
- Display supporting links below labels than in same row [Issue 2391](https://github.com/IntersectMBO/govtool/issues/2391)
- change link to support page [Issue 2292](https://github.com/IntersectMBO/govtool/issues/2292)
- Bump @intersect.mbo/pdf-ui to v0.5.0

### Removed

-

## [v1.0.27](https://github.com/IntersectMBO/govtool/releases/tag/v1.0.27) 2024-11-19

### Added
Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
WORKDIR /src
COPY . .
RUN cabal build
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.27/x/vva-be/build/vva-be/vva-be /usr/local/bin
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.28/x/vva-be/build/vva-be/vva-be /usr/local/bin
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile.qovery
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
WORKDIR /src
COPY . .
RUN cabal build
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.27/x/vva-be/build/vva-be/vva-be /usr/local/bin
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.28/x/vva-be/build/vva-be/vva-be /usr/local/bin

# Expose the necessary port
EXPOSE 9876
Expand Down
2 changes: 2 additions & 0 deletions govtool/backend/sql/get-drep-info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ WasRegisteredAsDRep AS (
CROSS JOIN DRepId
WHERE
drep_hash.raw = DRepId.raw
AND drep_registration.deposit >= 0
AND drep_registration.voting_anchor_id IS NOT NULL)) AS value
),
WasRegisteredAsSoleVoter AS (
Expand All @@ -100,6 +101,7 @@ WasRegisteredAsSoleVoter AS (
CROSS JOIN DRepId
WHERE
drep_hash.raw = DRepId.raw
AND drep_registration.deposit >= 0
AND drep_registration.voting_anchor_id IS NULL)) AS value
),
CurrentMetadata AS (
Expand Down
156 changes: 144 additions & 12 deletions govtool/backend/sql/get-network-metrics.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
WITH current_epoch AS (
WITH DRepActivity AS (
SELECT
drep_activity AS drep_activity,
epoch_no AS epoch_no
FROM
epoch_param
WHERE
epoch_no IS NOT NULL
ORDER BY
epoch_no DESC
LIMIT 1
),
active_drep_boundary_epoch AS (
SELECT
epoch_no - drep_activity AS epoch_no
FROM
DRepActivity
),
RankedDRep AS (
SELECT
dh.raw AS drep_hash_raw,
b.epoch_no,
dr.deposit,
dr.voting_anchor_id,
ROW_NUMBER() OVER (PARTITION BY dh.raw ORDER BY dr.tx_id DESC) AS rank
FROM
drep_hash dh
JOIN
drep_registration dr ON dh.id = dr.drep_hash_id
JOIN
tx t ON dr.tx_id = t.id
JOIN
block b ON t.block_id = b.id
WHERE
dr.deposit >= 0
GROUP BY
dh.raw,
b.epoch_no,
dr.voting_anchor_id,
dr.deposit,
dr.tx_id
),
current_epoch AS (
SELECT
Max(NO) AS no
FROM
Expand Down Expand Up @@ -36,11 +78,74 @@ total_drep_votes AS (
WHERE
voter_role = 'DRep'
),
total_stake_controlled_by_dreps AS (
SELECT
SUM(dd.amount)::bigint AS total
FROM
drep_distr dd
),
total_registered_direct_voters AS (
SELECT
COUNT(DISTINCT dh.raw) AS unique_direct_voters
FROM
drep_registration dr
JOIN
drep_hash dh
ON
dr.drep_hash_id = dh.id
LEFT JOIN
voting_anchor va
ON
dr.voting_anchor_id = va.id
WHERE
dr.deposit > 0
AND va.url IS NULL
),
total_registered_dreps AS (
SELECT
count(DISTINCT dh.raw) AS unique_registrations
FROM
drep_registration dr
JOIN
drep_hash dh
ON
dr.drep_hash_id = dh.id
WHERE
dr.deposit > 0
),
total_active_dreps AS (
SELECT
count(*) AS count
count(DISTINCT drep_hash_raw) AS unique_active_drep_registrations
FROM
RankedDRep
WHERE
epoch_no >= (SELECT epoch_no FROM active_drep_boundary_epoch)
AND rank = 1
),
total_inactive_dreps AS (
SELECT
total_registered_dreps.unique_registrations - total_active_dreps.unique_active_drep_registrations AS total_inactive_dreps
FROM
drep_hash
total_registered_dreps
CROSS JOIN
total_active_dreps
),
total_active_cip119_compliant_dreps AS (
SELECT
count(DISTINCT drep_hash_raw) AS unique_active_cip119_compliant_drep_registrations
FROM
RankedDRep
JOIN
voting_anchor va on va.id = RankedDRep.voting_anchor_id
JOIN off_chain_vote_data ocvd on ocvd.voting_anchor_id = va.id
JOIN off_chain_vote_drep_data ocvdd on ocvdd.off_chain_vote_data_id = ocvd.id
WHERE
-- given_name is the only compulsory field in CIP-119
ocvdd.given_name IS NOT NULL
AND
epoch_no >= (SELECT epoch_no FROM active_drep_boundary_epoch)
AND
rank = 1
),
always_abstain_voting_power AS (
SELECT
Expand All @@ -63,15 +168,20 @@ always_no_confidence_voting_power AS (
drep_hash.view = 'drep_always_no_confidence' ORDER BY epoch_no DESC LIMIT 1), 0) AS amount
)
SELECT
current_epoch.no,
current_epoch.no as epoch_no,
current_block.block_no,
unique_delegators.count,
total_delegations.count,
total_gov_action_proposals.count,
total_drep_votes.count,
total_registered_dreps.count,
always_abstain_voting_power.amount,
always_no_confidence_voting_power.amount,
unique_delegators.count as unique_delegators,
total_delegations.count as total_delegations,
total_gov_action_proposals.count as total_gov_action_proposals,
total_drep_votes.count as total_drep_votes,
total_registered_dreps.unique_registrations as total_registered_dreps,
total_stake_controlled_by_dreps.total as total_stake_controlled_by_dreps,
total_active_dreps.unique_active_drep_registrations as total_active_dreps,
total_inactive_dreps.total_inactive_dreps as total_inactive_dreps,
total_active_cip119_compliant_dreps.unique_active_cip119_compliant_drep_registrations as total_active_cip119_compliant_dreps,
total_registered_direct_voters.unique_direct_voters as total_registered_direct_voters,
always_abstain_voting_power.amount as always_abstain_voting_power,
always_no_confidence_voting_power.amount as always_no_confidence_voting_power,
network_name
FROM
current_epoch
Expand All @@ -81,6 +191,28 @@ FROM
CROSS JOIN total_gov_action_proposals
CROSS JOIN total_drep_votes
CROSS JOIN total_registered_dreps
CROSS JOIN total_stake_controlled_by_dreps
CROSS JOIN total_active_dreps
CROSS JOIN total_inactive_dreps
CROSS JOIN total_active_cip119_compliant_dreps
CROSS JOIN total_registered_direct_voters
CROSS JOIN always_abstain_voting_power
CROSS JOIN always_no_confidence_voting_power
CROSS JOIN meta;
CROSS JOIN meta
GROUP BY
current_epoch.no,
current_block.block_no,
unique_delegators.count,
total_delegations.count,
total_gov_action_proposals.count,
total_drep_votes.count,
total_registered_dreps.unique_registrations,
total_stake_controlled_by_dreps.total,
total_active_dreps.unique_active_drep_registrations,
total_inactive_dreps.total_inactive_dreps,
total_active_cip119_compliant_dreps.unique_active_cip119_compliant_drep_registrations,
total_registered_direct_voters.unique_direct_voters,
always_abstain_voting_power.amount,
always_no_confidence_voting_power.amount,
network_name;

9 changes: 2 additions & 7 deletions govtool/backend/sql/get-stake-key-voting-power.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
SELECT COALESCE(SUM(utxo_view.value::numeric), 0) + COALESCE(reward_sum.total_reward, 0) AS total_value,
SELECT COALESCE(SUM(utxo_view.value::numeric), 0),
encode(stake_address.hash_raw, 'hex')
FROM stake_address
JOIN utxo_view ON utxo_view.stake_address_id = stake_address.id
LEFT JOIN (
SELECT addr_id, SUM(reward_rest.amount) AS total_reward
FROM reward_rest
GROUP BY addr_id
) AS reward_sum ON reward_sum.addr_id = stake_address.id
WHERE stake_address.hash_raw = decode(?, 'hex')
GROUP BY stake_address.hash_raw, reward_sum.total_reward;
GROUP BY stake_address.hash_raw;
5 changes: 5 additions & 0 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ getNetworkMetrics = do
, getNetworkMetricsResponseTotalGovernanceActions = networkMetricsTotalGovernanceActions
, getNetworkMetricsResponseTotalDRepVotes = networkMetricsTotalDRepVotes
, getNetworkMetricsResponseTotalRegisteredDReps = networkMetricsTotalRegisteredDReps
, getNetworkMetricsResponseTotalStakeControlledByDReps = networkMetricsTotalStakeControlledByDReps
, getNetworkMetricsResponseTotalActiveDReps = networkMetricsTotalActiveDReps
, getNetworkMetricsResponseTotalInactiveDReps = networkMetricsTotalInactiveDReps
, getNetworkMetricsResponseTotalActiveCIP119CompliantDReps = networkMetricsTotalActiveCIP119CompliantDReps
, getNetworkMetricsResponseTotalRegisteredDirectVoters = networkMetricsTotalRegisteredDirectVoters
, getNetworkMetricsResponseAlwaysAbstainVotingPower = networkMetricsAlwaysAbstainVotingPower
, getNetworkMetricsResponseAlwaysNoConfidenceVotingPower = networkMetricsAlwaysNoConfidenceVotingPower
, getNetworkMetricsResponseNetworkName = networkMetricsNetworkName
Expand Down
32 changes: 21 additions & 11 deletions govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -878,17 +878,22 @@ instance ToSchema DelegationResponse where

data GetNetworkMetricsResponse
= GetNetworkMetricsResponse
{ getNetworkMetricsResponseCurrentTime :: UTCTime
, getNetworkMetricsResponseCurrentEpoch :: Integer
, getNetworkMetricsResponseCurrentBlock :: Integer
, getNetworkMetricsResponseUniqueDelegators :: Integer
, getNetworkMetricsResponseTotalDelegations :: Integer
, getNetworkMetricsResponseTotalGovernanceActions :: Integer
, getNetworkMetricsResponseTotalDRepVotes :: Integer
, getNetworkMetricsResponseTotalRegisteredDReps :: Integer
, getNetworkMetricsResponseAlwaysAbstainVotingPower :: Integer
, getNetworkMetricsResponseAlwaysNoConfidenceVotingPower :: Integer
, getNetworkMetricsResponseNetworkName :: Text
{ getNetworkMetricsResponseCurrentTime :: UTCTime
, getNetworkMetricsResponseCurrentEpoch :: Integer
, getNetworkMetricsResponseCurrentBlock :: Integer
, getNetworkMetricsResponseUniqueDelegators :: Integer
, getNetworkMetricsResponseTotalDelegations :: Integer
, getNetworkMetricsResponseTotalGovernanceActions :: Integer
, getNetworkMetricsResponseTotalDRepVotes :: Integer
, getNetworkMetricsResponseTotalRegisteredDReps :: Integer
, getNetworkMetricsResponseTotalStakeControlledByDReps :: Integer
, getNetworkMetricsResponseTotalActiveDReps :: Integer
, getNetworkMetricsResponseTotalInactiveDReps :: Integer
, getNetworkMetricsResponseTotalActiveCIP119CompliantDReps :: Integer
, getNetworkMetricsResponseTotalRegisteredDirectVoters :: Integer
, getNetworkMetricsResponseAlwaysAbstainVotingPower :: Integer
, getNetworkMetricsResponseAlwaysNoConfidenceVotingPower :: Integer
, getNetworkMetricsResponseNetworkName :: Text
}

deriveJSON (jsonOptions "getNetworkMetricsResponse") ''GetNetworkMetricsResponse
Expand All @@ -903,6 +908,11 @@ exampleGetNetworkMetricsResponse =
<> "\"totalGovernanceActions\": 0,"
<> "\"totalDRepVotes\": 0,"
<> "\"totalRegisteredDReps\": 0,"
<> "\"totalStakeControlledByDReps\": 0,"
<> "\"totalActiveDReps\": 0,"
<> "\"totalInactiveDReps\": 0,"
<> "\"totalActiveCIP119CompliantDReps\": 0,"
<> "\"totalRegisteredDirectVoters\": 0,"
<> "\"alwaysAbstainVotingPower\": 0,"
<> "\"alwaysNoConfidenceVotingPower\": 0,"
<> "\"networkName\": \"Mainnet\"}"
Expand Down
20 changes: 13 additions & 7 deletions govtool/backend/src/VVA/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,21 @@ getVotes drepId selectedProposals = withPool $ \conn -> do
let proposalsToSelect = if null selectedProposals
then [ govActionId | (_, govActionId, _, _, _, _, _, _, _) <- results]
else selectedProposals
proposals <- if null proposalsToSelect
then return []
else Proposal.getProposals (Just proposalsToSelect)

allProposals <- mapM (Proposal.getProposals . Just . (:[])) proposalsToSelect

let proposals = concat allProposals

let proposalMap = M.fromList $ map (\x -> (proposalId x, x)) proposals

timeZone <- liftIO getCurrentTimeZone
let votes = [ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash'
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results
, govActionId' `elem` proposalsToSelect
]

let votes =
[ Vote proposalId' drepId' vote' url' docHash' epochNo' (localTimeToUTC timeZone date') voteTxHash'
| (proposalId', govActionId', drepId', vote', url', docHash', epochNo', date', voteTxHash') <- results
, govActionId' `elem` proposalsToSelect
]

return (votes, proposals)

getDRepInfoSql :: SQL.Query
Expand Down
10 changes: 10 additions & 0 deletions govtool/backend/src/VVA/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ networkMetrics = withPool $ \conn -> do
, total_gov_action_proposals
, total_drep_votes
, total_registered_dreps
, total_stake_controlled_by_dreps
, total_active_dreps
, total_inactive_dreps
, total_active_cip119_compliant_dreps
, total_registered_direct_voters
, always_abstain_voting_power
, always_no_confidence_voting_power
, network_name
Expand All @@ -54,6 +59,11 @@ networkMetrics = withPool $ \conn -> do
total_gov_action_proposals
total_drep_votes
total_registered_dreps
total_stake_controlled_by_dreps
total_active_dreps
total_inactive_dreps
total_active_cip119_compliant_dreps
total_registered_direct_voters
always_abstain_voting_power
always_no_confidence_voting_power
network_name
Expand Down
Loading

0 comments on commit 5f9b030

Please sign in to comment.