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

Get stake pool data using GetRewardInfoPools query #3195

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module Cardano.Wallet.Api.Types
, ApiBase64
, ApiMintBurnData (..)
, ApiStakePool (..)
, invariantApiStakePool
, ApiStakePoolMetrics (..)
, ApiStakePoolFlag (..)
, ApiWallet (..)
Expand Down Expand Up @@ -811,14 +812,23 @@ data ApiStakePool = ApiStakePool
, flags :: ![ApiStakePoolFlag]
} deriving (Eq, Generic, Show)

-- | The 'ApiStakePool' response contains redundant information
-- and needs to satisfy this invariant.
invariantApiStakePool :: ApiStakePool -> Bool
invariantApiStakePool r =
(OwnerStakeLowerThanPledge `elem` flags r)
== (pledge r < ownerStake (metrics r))

data ApiStakePoolFlag
= Delisted
| OwnerStakeLowerThanPledge
deriving stock (Eq, Generic, Show)
deriving anyclass NFData

data ApiStakePoolMetrics = ApiStakePoolMetrics
{ nonMyopicMemberRewards :: !(Quantity "lovelace" Natural)
, relativeStake :: !(Quantity "percent" Percentage)
, ownerStake :: !(Quantity "lovelace" Natural)
, saturation :: !Double
, producedBlocks :: !(Quantity "block" Natural)
} deriving (Eq, Generic, Show)
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Wallet/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import Cardano.BM.Data.Severity
( Severity (..) )
import Cardano.BM.Data.Tracer
( HasPrivacyAnnotation (..), HasSeverityAnnotation (..) )
import Cardano.Pool.Rank
( StakePoolsSummary )
import Cardano.Wallet.Primitive.BlockSummary
( LightSummary )
import Cardano.Wallet.Primitive.Slotting
Expand All @@ -55,7 +57,6 @@ import Cardano.Wallet.Primitive.Types
, ProtocolParameters
, SlotNo (..)
, SlottingParameters (..)
, StakePoolsSummary
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin )
Expand Down Expand Up @@ -160,8 +161,7 @@ data NetworkLayer m block = NetworkLayer
-- ^ Broadcast a transaction to the chain producer

, stakeDistribution
:: Coin -- Stake to consider for rewards
-> m StakePoolsSummary
:: m (Maybe StakePoolsSummary)

, getCachedRewardAccountBalance
:: RewardAccount
Expand Down
18 changes: 0 additions & 18 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ module Cardano.Wallet.Primitive.Types
, IsDelegatingTo (..)

-- * Stake Pools
, StakePoolsSummary (..)
, PoolId(..)
, PoolOwner(..)
, poolIdBytesLength
Expand Down Expand Up @@ -215,8 +214,6 @@ import Data.Kind
( Type )
import Data.List
( intercalate )
import Data.Map.Strict
( Map )
import Data.Maybe
( isJust, isNothing )
import Data.Proxy
Expand Down Expand Up @@ -253,7 +250,6 @@ import Fmt
, blockListF'
, indentF
, listF'
, mapF
, prefixF
, pretty
, suffixF
Expand All @@ -276,7 +272,6 @@ import Test.QuickCheck
import qualified Codec.Binary.Bech32 as Bech32
import qualified Codec.Binary.Bech32.TH as Bech32
import qualified Data.ByteString as BS
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import qualified Data.Text.Encoding as T

Expand Down Expand Up @@ -759,19 +754,6 @@ instance FromJSON PoolOwner where
instance ToJSON PoolOwner where
toJSON = toJSON . toText

data StakePoolsSummary = StakePoolsSummary
{ nOpt :: Int
, rewards :: Map PoolId Coin
, stake :: Map PoolId Percentage
} deriving (Show, Eq)

instance Buildable StakePoolsSummary where
build StakePoolsSummary{nOpt,rewards,stake} = listF' id
[ "Stake: " <> mapF (Map.toList stake)
, "Non-myopic member rewards: " <> mapF (Map.toList rewards)
, "Optimum number of pools: " <> pretty nOpt
]

{-------------------------------------------------------------------------------
Block
-------------------------------------------------------------------------------}
Expand Down
Loading