Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API endpoint to expose total stake. #1836

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Shelley.Spec.Ledger.API.Wallet
getUTxO,
getFilteredUTxO,
getLeaderSchedule,
getTotalStake,
)
where

Expand Down Expand Up @@ -33,7 +34,8 @@ import Shelley.Spec.Ledger.Delegation.Certificates (IndividualPoolStake (..), un
import qualified Shelley.Spec.Ledger.EpochBoundary as EB
import Shelley.Spec.Ledger.Keys (KeyHash, KeyRole (..), SignKeyVRF)
import Shelley.Spec.Ledger.LedgerState
( DPState (..),
( AccountState (..),
DPState (..),
EpochState (..),
LedgerState (..),
NewEpochState (..),
Expand All @@ -52,6 +54,14 @@ import Shelley.Spec.Ledger.Rewards
import Shelley.Spec.Ledger.STS.Tickn (TicknState (..))
import Shelley.Spec.Ledger.TxData (PoolParams (..), TxOut (..))
import Shelley.Spec.Ledger.UTxO (UTxO (..))
import qualified Shelley.Spec.Ledger.Val as Val

-- | Calculate the current total stake.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it might be useful to reference the spot where this is defined as "total". E.g. it's not obvious why reserves should be excluded, but treasury not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! The reason I'm using this here is that that's also what we're using in the reward calculation, in createRUpd. So yes, either a comment, or maybe it's even better to have a single function calculate the total stake, and use that everywhere (this endpoint, reward calculation, and the non myopic rewards api endpoint).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called "circulation" in the createRUpd function, perhaps that's a name we can standardise on

getTotalStake :: Globals -> ShelleyState era -> Coin
getTotalStake globals ss =
let supply = Coin . fromIntegral $ maxLovelaceSupply globals
EpochState acnt _ _ _ _ _ = nesEs ss
in supply Val.~~ (_reserves acnt)

-- | Calculate the Non-Myopic Pool Member Rewards for a set of credentials.
-- For each given credential, this function returns a map from each stake
Expand Down