{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}

module Cardano.Ledger.Core.PParams (
  EraPParams (..),
  PParams (..),
  PParam (..),
  PParamUpdate (..),
  emptyPParams,
  PParamsUpdate (..),
  emptyPParamsUpdate,
  genericApplyPPUpdates,

  -- * PParams lens
  ppMinFeeAL,
  ppMinFeeBL,
  ppMaxBBSizeL,
  ppMaxTxSizeL,
  ppMaxBHSizeL,
  ppKeyDepositL,
  ppPoolDepositL,
  ppEMaxL,
  ppNOptL,
  ppA0L,
  ppRhoL,
  ppTauL,
  ppDL,
  ppExtraEntropyL,
  ppMinUTxOValueL,
  ppMinPoolCostL,

  -- * PParamsUpdate lens
  ppuMinFeeAL,
  ppuMinFeeBL,
  ppuMaxBBSizeL,
  ppuMaxTxSizeL,
  ppuMaxBHSizeL,
  ppuKeyDepositL,
  ppuPoolDepositL,
  ppuEMaxL,
  ppuNOptL,
  ppuA0L,
  ppuRhoL,
  ppuTauL,
  ppuDL,
  ppuExtraEntropyL,
  ppuMinUTxOValueL,
  ppuMinPoolCostL,

  -- * Utility
  ppLensHKD,
  ppuLensHKD,
  mapPParams,
  mapPParamsUpdate,
  upgradePParams,
  downgradePParams,
  upgradePParamsUpdate,
  downgradePParamsUpdate,
) where

import Cardano.Ledger.BaseTypes (
  EpochInterval (..),
  NonNegativeInterval,
  Nonce (..),
  ProtVer,
  StrictMaybe (..),
  UnitInterval,
  maybeToStrictMaybe,
 )
import Cardano.Ledger.Binary
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Core.Era (Era (..), PreviousEra, ProtVerAtMost, fromEraCBOR, toEraCBOR)
import Cardano.Ledger.HKD (HKD, HKDApplicative, HKDFunctor (..), NoUpdate (..))
import Cardano.Ledger.Plutus.ToPlutusData (ToPlutusData (..))
import Control.DeepSeq (NFData)
import Control.Monad.Identity (Identity)
import Data.Aeson (FromJSON (..), ToJSON (..), object, pairs, (.:), (.=))
import qualified Data.Aeson as Aeson (KeyValue, withObject)
import qualified Data.Aeson.Key as Aeson (fromText)
import Data.Default (Default (..))
import qualified Data.Foldable as F (foldMap', foldl', foldlM)
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.Kind (Type)
import Data.Proxy (Proxy (..))
import Data.Text (Text)
import qualified Data.Text as T
import Data.Typeable (typeRep)
import Data.Word (Word16, Word32)
import GHC.Generics (Generic (..), K1 (..), M1 (..), U1, V1, type (:*:) (..))
import Lens.Micro (Lens', SimpleGetter, lens, set, (^.))
import NoThunks.Class (NoThunks)

-- | Protocol parameters
newtype PParams era = PParams (PParamsHKD Identity era)

instance EraPParams era => Default (PParams era) where
  def :: PParams era
def = PParams era
forall era. EraPParams era => PParams era
emptyPParams

deriving newtype instance
  Eq (PParamsHKD Identity era) => Eq (PParams era)

deriving newtype instance
  Ord (PParamsHKD Identity era) => Ord (PParams era)

deriving newtype instance
  NFData (PParamsHKD Identity era) => NFData (PParams era)

deriving newtype instance
  NoThunks (PParamsHKD Identity era) => NoThunks (PParams era)

deriving stock instance
  Show (PParamsHKD Identity era) => Show (PParams era)

instance EraPParams era => ToJSON (PParams era) where
  toJSON :: PParams era -> Value
toJSON = [Pair] -> Value
object ([Pair] -> Value)
-> (PParams era -> [Pair]) -> PParams era -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PParams era -> [Pair]
forall era e a.
(EraPParams era, KeyValue e a) =>
PParams era -> [a]
jsonPairsPParams
  toEncoding :: PParams era -> Encoding
toEncoding = Series -> Encoding
pairs (Series -> Encoding)
-> (PParams era -> Series) -> PParams era -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Series] -> Series
forall a. Monoid a => [a] -> a
mconcat ([Series] -> Series)
-> (PParams era -> [Series]) -> PParams era -> Series
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PParams era -> [Series]
forall era e a.
(EraPParams era, KeyValue e a) =>
PParams era -> [a]
jsonPairsPParams

instance EraPParams era => FromJSON (PParams era) where
  parseJSON :: Value -> Parser (PParams era)
parseJSON =
    String
-> (Object -> Parser (PParams era))
-> Value
-> Parser (PParams era)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject (TypeRep -> String
forall a. Show a => a -> String
show (TypeRep -> String)
-> (Proxy (PParams era) -> TypeRep)
-> Proxy (PParams era)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (PParams era) -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy (PParams era) -> String) -> Proxy (PParams era) -> String
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(PParams era)) ((Object -> Parser (PParams era)) -> Value -> Parser (PParams era))
-> (Object -> Parser (PParams era))
-> Value
-> Parser (PParams era)
forall a b. (a -> b) -> a -> b
$ \Object
obj ->
      let accum :: PParams era -> PParam era -> Parser (PParams era)
accum PParams era
acc PParam {Text
ppName :: Text
ppName :: forall era. PParam era -> Text
ppName, Lens' (PParams era) t
ppLens :: Lens' (PParams era) t
ppLens :: ()
ppLens} =
            ASetter (PParams era) (PParams era) t t
-> t -> PParams era -> PParams era
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter (PParams era) (PParams era) t t
Lens' (PParams era) t
ppLens (t -> PParams era -> PParams era)
-> Parser t -> Parser (PParams era -> PParams era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser t
forall a. FromJSON a => Object -> Key -> Parser a
.: Text -> Key
Aeson.fromText Text
ppName Parser (PParams era -> PParams era)
-> Parser (PParams era) -> Parser (PParams era)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PParams era -> Parser (PParams era)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PParams era
acc
       in (PParams era -> PParam era -> Parser (PParams era))
-> PParams era -> [PParam era] -> Parser (PParams era)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
F.foldlM PParams era -> PParam era -> Parser (PParams era)
accum (forall era. EraPParams era => PParams era
emptyPParams @era) (forall era. EraPParams era => [PParam era]
eraPParams @era)

instance EraPParams era => EncCBOR (PParams era) where
  encCBOR :: PParams era -> Encoding
encCBOR PParams era
pp =
    Word -> Encoding
encodeListLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([PParam era] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall era. EraPParams era => [PParam era]
eraPParams @era)))
      Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (PParam era -> Encoding) -> [PParam era] -> Encoding
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
F.foldMap' PParam era -> Encoding
toEnc (forall era. EraPParams era => [PParam era]
eraPParams @era)
    where
      toEnc :: PParam era -> Encoding
toEnc PParam {Lens' (PParams era) t
ppLens :: ()
ppLens :: Lens' (PParams era) t
ppLens} = t -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (t -> Encoding) -> t -> Encoding
forall a b. (a -> b) -> a -> b
$ PParams era
pp PParams era -> Getting t (PParams era) t -> t
forall s a. s -> Getting a s a -> a
^. Getting t (PParams era) t
Lens' (PParams era) t
ppLens

instance EraPParams era => DecCBOR (PParams era) where
  decCBOR :: forall s. Decoder s (PParams era)
decCBOR =
    Text
-> (PParams era -> Int)
-> Decoder s (PParams era)
-> Decoder s (PParams era)
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed
      (String -> Text
T.pack (String -> Text)
-> (Proxy (PParams era) -> String) -> Proxy (PParams era) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeRep -> String
forall a. Show a => a -> String
show (TypeRep -> String)
-> (Proxy (PParams era) -> TypeRep)
-> Proxy (PParams era)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (PParams era) -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy (PParams era) -> Text) -> Proxy (PParams era) -> Text
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(PParams era))
      (Int -> PParams era -> Int
forall a b. a -> b -> a
const (Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([PParam era] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall era. EraPParams era => [PParam era]
eraPParams @era))))
      (Decoder s (PParams era) -> Decoder s (PParams era))
-> Decoder s (PParams era) -> Decoder s (PParams era)
forall a b. (a -> b) -> a -> b
$ (PParams era -> PParam era -> Decoder s (PParams era))
-> PParams era -> [PParam era] -> Decoder s (PParams era)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
F.foldlM PParams era -> PParam era -> Decoder s (PParams era)
forall {era} {s}.
PParams era -> PParam era -> Decoder s (PParams era)
accum (forall era. EraPParams era => PParams era
emptyPParams @era) (forall era. EraPParams era => [PParam era]
eraPParams @era)
    where
      accum :: PParams era -> PParam era -> Decoder s (PParams era)
accum PParams era
acc PParam {Lens' (PParams era) t
ppLens :: ()
ppLens :: Lens' (PParams era) t
ppLens} =
        ASetter (PParams era) (PParams era) t t
-> t -> PParams era -> PParams era
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter (PParams era) (PParams era) t t
Lens' (PParams era) t
ppLens (t -> PParams era -> PParams era)
-> Decoder s t -> Decoder s (PParams era -> PParams era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s t
forall s. Decoder s t
forall a s. DecCBOR a => Decoder s a
decCBOR Decoder s (PParams era -> PParams era)
-> Decoder s (PParams era) -> Decoder s (PParams era)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PParams era -> Decoder s (PParams era)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PParams era
acc

instance EraPParams era => ToCBOR (PParams era) where
  toCBOR :: PParams era -> Encoding
toCBOR = forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR @era

instance EraPParams era => FromCBOR (PParams era) where
  fromCBOR :: forall s. Decoder s (PParams era)
fromCBOR = forall era t s. (Era era, DecCBOR t) => Decoder s t
fromEraCBOR @era

deriving instance Generic (PParams era)

-- | The type of updates to Protocol parameters
newtype PParamsUpdate era = PParamsUpdate (PParamsHKD StrictMaybe era)

instance EraPParams era => Default (PParamsUpdate era) where
  def :: PParamsUpdate era
def = PParamsUpdate era
forall era. EraPParams era => PParamsUpdate era
emptyPParamsUpdate

deriving newtype instance
  Eq (PParamsHKD StrictMaybe era) => Eq (PParamsUpdate era)

deriving newtype instance
  Ord (PParamsHKD StrictMaybe era) => Ord (PParamsUpdate era)

deriving newtype instance
  NFData (PParamsHKD StrictMaybe era) => NFData (PParamsUpdate era)

deriving newtype instance
  NoThunks (PParamsHKD StrictMaybe era) => NoThunks (PParamsUpdate era)

deriving stock instance
  Show (PParamsHKD StrictMaybe era) => Show (PParamsUpdate era)

instance EraPParams era => EncCBOR (PParamsUpdate era) where
  encCBOR :: PParamsUpdate era -> Encoding
encCBOR PParamsUpdate era
pp = Word -> Encoding
encodeMapLen Word
count Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding
enc
    where
      !(!Word
count, !Encoding
enc) = [PParam era] -> (Word, Encoding)
countAndConcat (forall era. EraPParams era => [PParam era]
eraPParams @era)
      encodeField :: PParam era -> StrictMaybe Encoding
encodeField PParam {Maybe (PParamUpdate era t)
ppUpdate :: Maybe (PParamUpdate era t)
ppUpdate :: ()
ppUpdate} = do
        PParamUpdate {Word
ppuTag :: Word
ppuTag :: forall era t. PParamUpdate era t -> Word
ppuTag, Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens :: Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens :: forall era t.
PParamUpdate era t -> Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens} <- Maybe (PParamUpdate era t) -> StrictMaybe (PParamUpdate era t)
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe Maybe (PParamUpdate era t)
ppUpdate
        (Word -> Encoding
encodeWord Word
ppuTag Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<>) (Encoding -> Encoding) -> (t -> Encoding) -> t -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (t -> Encoding) -> StrictMaybe t -> StrictMaybe Encoding
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PParamsUpdate era
pp PParamsUpdate era
-> Getting (StrictMaybe t) (PParamsUpdate era) (StrictMaybe t)
-> StrictMaybe t
forall s a. s -> Getting a s a -> a
^. Getting (StrictMaybe t) (PParamsUpdate era) (StrictMaybe t)
Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens
      countAndConcat :: [PParam era] -> (Word, Encoding)
countAndConcat = ((Word, Encoding) -> PParam era -> (Word, Encoding))
-> (Word, Encoding) -> [PParam era] -> (Word, Encoding)
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' (Word, Encoding) -> PParam era -> (Word, Encoding)
accum (Word
0, Encoding
forall a. Monoid a => a
mempty)
        where
          accum :: (Word, Encoding) -> PParam era -> (Word, Encoding)
accum (!Word
n, !Encoding
acc) PParam era
x = case PParam era -> StrictMaybe Encoding
encodeField PParam era
x of
            SJust Encoding
y -> (Word
n Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1, Encoding
acc Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding
y)
            StrictMaybe Encoding
SNothing -> (Word
n, Encoding
acc)

instance EraPParams era => DecCBOR (PParamsUpdate era) where
  decCBOR :: forall s. Decoder s (PParamsUpdate era)
decCBOR =
    Decode ('Closed 'Dense) (PParamsUpdate era)
-> Decoder s (PParamsUpdate era)
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode (Decode ('Closed 'Dense) (PParamsUpdate era)
 -> Decoder s (PParamsUpdate era))
-> Decode ('Closed 'Dense) (PParamsUpdate era)
-> Decoder s (PParamsUpdate era)
forall a b. (a -> b) -> a -> b
$
      String
-> PParamsUpdate era
-> (Word -> Field (PParamsUpdate era))
-> [(Word, String)]
-> Decode ('Closed 'Dense) (PParamsUpdate era)
forall t.
Typeable t =>
String
-> t
-> (Word -> Field t)
-> [(Word, String)]
-> Decode ('Closed 'Dense) t
SparseKeyed
        (TypeRep -> String
forall a. Show a => a -> String
show (TypeRep -> String)
-> (Proxy (PParamsUpdate era) -> TypeRep)
-> Proxy (PParamsUpdate era)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (PParamsUpdate era) -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy (PParamsUpdate era) -> String)
-> Proxy (PParamsUpdate era) -> String
forall a b. (a -> b) -> a -> b
$ forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @(PParamsUpdate era))
        PParamsUpdate era
forall era. EraPParams era => PParamsUpdate era
emptyPParamsUpdate
        Word -> Field (PParamsUpdate era)
updateField
        []
    where
      updateField :: Word -> Field (PParamsUpdate era)
updateField Word
k =
        Field (PParamsUpdate era)
-> Int
-> IntMap (Field (PParamsUpdate era))
-> Field (PParamsUpdate era)
forall a. a -> Int -> IntMap a -> a
IntMap.findWithDefault
          (Word -> Field (PParamsUpdate era)
forall t. Word -> Field t
invalidField Word
k)
          (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
k)
          IntMap (Field (PParamsUpdate era))
updateFieldMap
      updateFieldMap :: IntMap (Field (PParamsUpdate era))
      updateFieldMap :: IntMap (Field (PParamsUpdate era))
updateFieldMap =
        [(Int, Field (PParamsUpdate era))]
-> IntMap (Field (PParamsUpdate era))
forall a. [(Int, a)] -> IntMap a
IntMap.fromList
          [ (Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
ppuTag, (t -> PParamsUpdate era -> PParamsUpdate era)
-> Decode ('Closed Any) t -> Field (PParamsUpdate era)
forall x t (d :: Density).
Typeable x =>
(x -> t -> t) -> Decode ('Closed d) x -> Field t
field (ASetter
  (PParamsUpdate era)
  (PParamsUpdate era)
  (StrictMaybe t)
  (StrictMaybe t)
-> StrictMaybe t -> PParamsUpdate era -> PParamsUpdate era
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter
  (PParamsUpdate era)
  (PParamsUpdate era)
  (StrictMaybe t)
  (StrictMaybe t)
Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens (StrictMaybe t -> PParamsUpdate era -> PParamsUpdate era)
-> (t -> StrictMaybe t)
-> t
-> PParamsUpdate era
-> PParamsUpdate era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> StrictMaybe t
forall a. a -> StrictMaybe a
SJust) Decode ('Closed Any) t
forall t (w :: Wrapped). DecCBOR t => Decode w t
From)
          | PParam {ppUpdate :: ()
ppUpdate = Just PParamUpdate {Word
ppuTag :: forall era t. PParamUpdate era t -> Word
ppuTag :: Word
ppuTag, Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens :: forall era t.
PParamUpdate era t -> Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens :: Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens}} <- forall era. EraPParams era => [PParam era]
eraPParams @era
          ]

instance EraPParams era => ToCBOR (PParamsUpdate era) where
  toCBOR :: PParamsUpdate era -> Encoding
toCBOR = forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR @era

instance EraPParams era => FromCBOR (PParamsUpdate era) where
  fromCBOR :: forall s. Decoder s (PParamsUpdate era)
fromCBOR = forall era t s. (Era era, DecCBOR t) => Decoder s t
fromEraCBOR @era

instance EraPParams era => ToJSON (PParamsUpdate era) where
  toJSON :: PParamsUpdate era -> Value
toJSON = [Pair] -> Value
object ([Pair] -> Value)
-> (PParamsUpdate era -> [Pair]) -> PParamsUpdate era -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PParamsUpdate era -> [Pair]
forall era e a.
(EraPParams era, KeyValue e a) =>
PParamsUpdate era -> [a]
jsonPairsPParamsUpdate
  toEncoding :: PParamsUpdate era -> Encoding
toEncoding = Series -> Encoding
pairs (Series -> Encoding)
-> (PParamsUpdate era -> Series) -> PParamsUpdate era -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Series] -> Series
forall a. Monoid a => [a] -> a
mconcat ([Series] -> Series)
-> (PParamsUpdate era -> [Series]) -> PParamsUpdate era -> Series
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PParamsUpdate era -> [Series]
forall era e a.
(EraPParams era, KeyValue e a) =>
PParamsUpdate era -> [a]
jsonPairsPParamsUpdate

deriving instance Generic (PParamsUpdate era)

-- Generic derivation of `applyPPUpdates`

class Updatable a u where
  applyUpdate :: a -> u -> a

instance Updatable (U1 a) (U1 u) where
  applyUpdate :: U1 a -> U1 u -> U1 a
applyUpdate U1 a
x U1 u
_ = U1 a
x

instance Updatable (V1 a) (V1 u) where
  applyUpdate :: V1 a -> V1 u -> V1 a
applyUpdate V1 a
x V1 u
_ = case V1 a
x of {}

instance
  (Updatable (a1 a) (u1 u), Updatable (a2 a) (u2 u)) =>
  Updatable ((a1 :*: a2) a) ((u1 :*: u2) u)
  where
  applyUpdate :: (:*:) a1 a2 a -> (:*:) u1 u2 u -> (:*:) a1 a2 a
applyUpdate (a1 a
x1 :*: a2 a
x2) (u1 u
u1 :*: u2 u
u2) = a1 a -> u1 u -> a1 a
forall a u. Updatable a u => a -> u -> a
applyUpdate a1 a
x1 u1 u
u1 a1 a -> a2 a -> (:*:) a1 a2 a
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: a2 a -> u2 u -> a2 a
forall a u. Updatable a u => a -> u -> a
applyUpdate a2 a
x2 u2 u
u2

instance Updatable (a x) (a' x') => Updatable (M1 i c a x) (M1 i' c' a' x') where
  applyUpdate :: M1 i c a x -> M1 i' c' a' x' -> M1 i c a x
applyUpdate (M1 a x
x) (M1 a' x'
y) = a x -> M1 i c a x
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (a x -> M1 i c a x) -> a x -> M1 i c a x
forall a b. (a -> b) -> a -> b
$ a x -> a' x' -> a x
forall a u. Updatable a u => a -> u -> a
applyUpdate a x
x a' x'
y

instance Updatable (K1 t x a) (K1 t (StrictMaybe x) u) where
  applyUpdate :: K1 t x a -> K1 t (StrictMaybe x) u -> K1 t x a
applyUpdate (K1 x
x') (K1 StrictMaybe x
sm) = x -> K1 t x a
forall k i c (p :: k). c -> K1 i c p
K1 (x -> K1 t x a) -> x -> K1 t x a
forall a b. (a -> b) -> a -> b
$ case StrictMaybe x
sm of
    SJust x
x -> x
x
    StrictMaybe x
SNothing -> x
x'

instance Updatable (K1 t x a) (K1 t (NoUpdate x) u) where
  applyUpdate :: K1 t x a -> K1 t (NoUpdate x) u -> K1 t x a
applyUpdate (K1 x
x) (K1 NoUpdate x
NoUpdate) = x -> K1 t x a
forall k i c (p :: k). c -> K1 i c p
K1 x
x

genericApplyPPUpdates ::
  forall era a u.
  ( Generic (PParamsHKD Identity era)
  , Generic (PParamsHKD StrictMaybe era)
  , Updatable (Rep (PParamsHKD Identity era) a) (Rep (PParamsHKD StrictMaybe era) u)
  ) =>
  PParams era ->
  PParamsUpdate era ->
  PParams era
genericApplyPPUpdates :: forall era a u.
(Generic (PParamsHKD Identity era),
 Generic (PParamsHKD StrictMaybe era),
 Updatable
   (Rep (PParamsHKD Identity era) a)
   (Rep (PParamsHKD StrictMaybe era) u)) =>
PParams era -> PParamsUpdate era -> PParams era
genericApplyPPUpdates (PParams PParamsHKD Identity era
a) (PParamsUpdate PParamsHKD StrictMaybe era
u) =
  PParamsHKD Identity era -> PParams era
forall era. PParamsHKD Identity era -> PParams era
PParams (PParamsHKD Identity era -> PParams era)
-> (Rep (PParamsHKD Identity era) a -> PParamsHKD Identity era)
-> Rep (PParamsHKD Identity era) a
-> PParams era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rep (PParamsHKD Identity era) a -> PParamsHKD Identity era
forall a x. Generic a => Rep a x -> a
forall x.
Rep (PParamsHKD Identity era) x -> PParamsHKD Identity era
to (Rep (PParamsHKD Identity era) a -> PParams era)
-> Rep (PParamsHKD Identity era) a -> PParams era
forall a b. (a -> b) -> a -> b
$ Rep (PParamsHKD Identity era) a
-> Rep (PParamsHKD StrictMaybe era) u
-> Rep (PParamsHKD Identity era) a
forall a u. Updatable a u => a -> u -> a
applyUpdate (forall a x. Generic a => a -> Rep a x
from @_ @a PParamsHKD Identity era
a) (forall a x. Generic a => a -> Rep a x
from @_ @u PParamsHKD StrictMaybe era
u)

class
  ( Era era
  , Eq (PParamsHKD Identity era)
  , Ord (PParamsHKD Identity era)
  , Show (PParamsHKD Identity era)
  , NFData (PParamsHKD Identity era)
  , NoThunks (PParamsHKD Identity era)
  , Eq (PParamsHKD StrictMaybe era)
  , Ord (PParamsHKD StrictMaybe era)
  , Show (PParamsHKD StrictMaybe era)
  , NFData (PParamsHKD StrictMaybe era)
  , NoThunks (PParamsHKD StrictMaybe era)
  ) =>
  EraPParams era
  where
  -- | Protocol parameters where the fields are represented with a HKD
  type PParamsHKD (f :: Type -> Type) era = (r :: Type) | r -> era

  -- | Applies a protocol parameters update
  applyPPUpdates ::
    PParams era ->
    PParamsUpdate era ->
    PParams era
  default applyPPUpdates ::
    forall a u.
    ( Generic (PParamsHKD Identity era)
    , Generic (PParamsHKD StrictMaybe era)
    , Updatable (Rep (PParamsHKD Identity era) a) (Rep (PParamsHKD StrictMaybe era) u)
    ) =>
    PParams era ->
    PParamsUpdate era ->
    PParams era
  applyPPUpdates = forall era a u.
(Generic (PParamsHKD Identity era),
 Generic (PParamsHKD StrictMaybe era),
 Updatable
   (Rep (PParamsHKD Identity era) a)
   (Rep (PParamsHKD StrictMaybe era) u)) =>
PParams era -> PParamsUpdate era -> PParams era
genericApplyPPUpdates @_ @a @u

  emptyPParamsIdentity :: PParamsHKD Identity era
  emptyPParamsStrictMaybe :: PParamsHKD StrictMaybe era

  -- |
  type UpgradePParams (f :: Type -> Type) era :: Type

  type DowngradePParams (f :: Type -> Type) era :: Type

  -- | Upgrade PParams from previous era to the current one
  upgradePParamsHKD ::
    (HKDApplicative f, EraPParams (PreviousEra era)) =>
    UpgradePParams f era ->
    PParamsHKD f (PreviousEra era) ->
    PParamsHKD f era

  -- | Downgrade PParams from the current era to the previous one
  downgradePParamsHKD ::
    (HKDFunctor f, EraPParams (PreviousEra era)) =>
    DowngradePParams f era ->
    PParamsHKD f era ->
    PParamsHKD f (PreviousEra era)

  -- HKD Versions of lenses

  -- | The linear factor for the minimum fee calculation
  hkdMinFeeAL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Coin)

  -- | The constant factor for the minimum fee calculation
  hkdMinFeeBL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Coin)

  -- | Maximal block body size
  hkdMaxBBSizeL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Word32)

  -- | Maximal transaction size
  hkdMaxTxSizeL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Word32)

  -- | Maximal block header size
  hkdMaxBHSizeL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Word16)

  -- | The amount of a key registration deposit
  hkdKeyDepositL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Coin)

  -- | The amount of a pool registration deposit
  hkdPoolDepositL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Coin)

  -- | epoch bound on pool retirement
  hkdEMaxL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f EpochInterval)

  -- | Desired number of pools
  hkdNOptL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Word16)

  -- | Pool influence
  hkdA0L :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f NonNegativeInterval)

  -- | Monetary expansion
  hkdRhoL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f UnitInterval)

  -- | Treasury expansion
  hkdTauL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f UnitInterval)

  -- | Decentralization parameter
  hkdDL :: (HKDFunctor f, ProtVerAtMost era 6) => Lens' (PParamsHKD f era) (HKD f UnitInterval)

  -- | Decentralization parameter getter
  ppDG :: SimpleGetter (PParams era) UnitInterval
  default ppDG :: ProtVerAtMost era 6 => SimpleGetter (PParams era) UnitInterval
  ppDG = (PParamsHKD Identity era -> Const r (PParamsHKD Identity era))
-> PParams era -> Const r (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> Const r (PParamsHKD Identity era))
 -> PParams era -> Const r (PParams era))
-> ((UnitInterval -> Const r UnitInterval)
    -> PParamsHKD Identity era -> Const r (PParamsHKD Identity era))
-> (UnitInterval -> Const r UnitInterval)
-> PParams era
-> Const r (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 6) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdDL @era @Identity

  -- | Extra entropy
  hkdExtraEntropyL :: (HKDFunctor f, ProtVerAtMost era 6) => Lens' (PParamsHKD f era) (HKD f Nonce)

  -- | Protocol version
  hkdProtocolVersionL ::
    (HKDFunctor f, ProtVerAtMost era 8) => Lens' (PParamsHKD f era) (HKD f ProtVer)

  ppProtocolVersionL :: Lens' (PParams era) ProtVer
  default ppProtocolVersionL :: ProtVerAtMost era 8 => Lens' (PParams era) ProtVer
  ppProtocolVersionL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((ProtVer -> f ProtVer)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (ProtVer -> f ProtVer)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 8) =>
Lens' (PParamsHKD f era) (HKD f ProtVer)
hkdProtocolVersionL @era @Identity

  -- | PParamsUpdate Protocol version
  ppuProtocolVersionL :: ProtVerAtMost era 8 => Lens' (PParamsUpdate era) (StrictMaybe ProtVer)
  ppuProtocolVersionL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe ProtVer -> f (StrictMaybe ProtVer))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe ProtVer -> f (StrictMaybe ProtVer))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 8) =>
Lens' (PParamsHKD f era) (HKD f ProtVer)
hkdProtocolVersionL @era @StrictMaybe

  -- | Minimum UTxO value
  hkdMinUTxOValueL :: HKDFunctor f => ProtVerAtMost era 4 => Lens' (PParamsHKD f era) (HKD f Coin)

  -- | Minimum Stake Pool Cost
  hkdMinPoolCostL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Coin)

  eraPParams :: [PParam era]

emptyPParams :: EraPParams era => PParams era
emptyPParams :: forall era. EraPParams era => PParams era
emptyPParams = PParamsHKD Identity era -> PParams era
forall era. PParamsHKD Identity era -> PParams era
PParams PParamsHKD Identity era
forall era. EraPParams era => PParamsHKD Identity era
emptyPParamsIdentity

emptyPParamsUpdate :: EraPParams era => PParamsUpdate era
emptyPParamsUpdate :: forall era. EraPParams era => PParamsUpdate era
emptyPParamsUpdate = PParamsHKD StrictMaybe era -> PParamsUpdate era
forall era. PParamsHKD StrictMaybe era -> PParamsUpdate era
PParamsUpdate PParamsHKD StrictMaybe era
forall era. EraPParams era => PParamsHKD StrictMaybe era
emptyPParamsStrictMaybe

ppLensHKD :: Lens' (PParams era) (PParamsHKD Identity era)
ppLensHKD :: forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD = (PParams era -> PParamsHKD Identity era)
-> (PParams era -> PParamsHKD Identity era -> PParams era)
-> Lens
     (PParams era)
     (PParams era)
     (PParamsHKD Identity era)
     (PParamsHKD Identity era)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\(PParams PParamsHKD Identity era
x) -> PParamsHKD Identity era
x) (\PParams era
_ PParamsHKD Identity era
pp -> PParamsHKD Identity era -> PParams era
forall era. PParamsHKD Identity era -> PParams era
PParams PParamsHKD Identity era
pp)

ppuLensHKD :: Lens' (PParamsUpdate era) (PParamsHKD StrictMaybe era)
ppuLensHKD :: forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD = (PParamsUpdate era -> PParamsHKD StrictMaybe era)
-> (PParamsUpdate era
    -> PParamsHKD StrictMaybe era -> PParamsUpdate era)
-> Lens
     (PParamsUpdate era)
     (PParamsUpdate era)
     (PParamsHKD StrictMaybe era)
     (PParamsHKD StrictMaybe era)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens (\(PParamsUpdate PParamsHKD StrictMaybe era
x) -> PParamsHKD StrictMaybe era
x) (\PParamsUpdate era
_ PParamsHKD StrictMaybe era
pp -> PParamsHKD StrictMaybe era -> PParamsUpdate era
forall era. PParamsHKD StrictMaybe era -> PParamsUpdate era
PParamsUpdate PParamsHKD StrictMaybe era
pp)

-- PParams versions of lenses

-- | The linear factor for the minimum fee calculation
ppMinFeeAL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppMinFeeAL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppMinFeeAL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Coin -> f Coin)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Coin -> f Coin)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinFeeAL @era @Identity

-- | The constant factor for the minimum fee calculation
ppMinFeeBL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppMinFeeBL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppMinFeeBL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Coin -> f Coin)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Coin -> f Coin)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinFeeBL @era @Identity

-- | Maximal block body size
ppMaxBBSizeL :: forall era. EraPParams era => Lens' (PParams era) Word32
ppMaxBBSizeL :: forall era. EraPParams era => Lens' (PParams era) Word32
ppMaxBBSizeL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Word32 -> f Word32)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Word32 -> f Word32)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word32)
hkdMaxBBSizeL @era @Identity

-- | Maximal transaction size
ppMaxTxSizeL :: forall era. EraPParams era => Lens' (PParams era) Word32
ppMaxTxSizeL :: forall era. EraPParams era => Lens' (PParams era) Word32
ppMaxTxSizeL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Word32 -> f Word32)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Word32 -> f Word32)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word32)
hkdMaxTxSizeL @era @Identity

-- | Maximal block header size
ppMaxBHSizeL :: forall era. EraPParams era => Lens' (PParams era) Word16
ppMaxBHSizeL :: forall era. EraPParams era => Lens' (PParams era) Word16
ppMaxBHSizeL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Word16 -> f Word16)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Word16 -> f Word16)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word16)
hkdMaxBHSizeL @era @Identity

-- | The amount of a key registration deposit
ppKeyDepositL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppKeyDepositL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppKeyDepositL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Coin -> f Coin)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Coin -> f Coin)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdKeyDepositL @era @Identity

-- | The amount of a pool registration deposit
ppPoolDepositL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppPoolDepositL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppPoolDepositL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Coin -> f Coin)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Coin -> f Coin)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdPoolDepositL @era @Identity

-- | epoch bound on pool retirement
ppEMaxL :: forall era. EraPParams era => Lens' (PParams era) EpochInterval
ppEMaxL :: forall era. EraPParams era => Lens' (PParams era) EpochInterval
ppEMaxL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((EpochInterval -> f EpochInterval)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (EpochInterval -> f EpochInterval)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f EpochInterval)
hkdEMaxL @era @Identity

-- | Desired number of pools
ppNOptL :: forall era. EraPParams era => Lens' (PParams era) Word16
ppNOptL :: forall era. EraPParams era => Lens' (PParams era) Word16
ppNOptL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Word16 -> f Word16)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Word16 -> f Word16)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word16)
hkdNOptL @era @Identity

-- | Pool influence
ppA0L :: forall era. EraPParams era => Lens' (PParams era) NonNegativeInterval
ppA0L :: forall era.
EraPParams era =>
Lens' (PParams era) NonNegativeInterval
ppA0L = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((NonNegativeInterval -> f NonNegativeInterval)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (NonNegativeInterval -> f NonNegativeInterval)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f NonNegativeInterval)
hkdA0L @era @Identity

-- | Monetary expansion
ppRhoL :: forall era. EraPParams era => Lens' (PParams era) UnitInterval
ppRhoL :: forall era. EraPParams era => Lens' (PParams era) UnitInterval
ppRhoL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((UnitInterval -> f UnitInterval)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (UnitInterval -> f UnitInterval)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdRhoL @era @Identity

-- | Treasury expansion
ppTauL :: forall era. EraPParams era => Lens' (PParams era) UnitInterval
ppTauL :: forall era. EraPParams era => Lens' (PParams era) UnitInterval
ppTauL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((UnitInterval -> f UnitInterval)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (UnitInterval -> f UnitInterval)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdTauL @era @Identity

-- | Decentralization parameter
ppDL :: forall era. (EraPParams era, ProtVerAtMost era 6) => Lens' (PParams era) UnitInterval
ppDL :: forall era.
(EraPParams era, ProtVerAtMost era 6) =>
Lens' (PParams era) UnitInterval
ppDL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((UnitInterval -> f UnitInterval)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (UnitInterval -> f UnitInterval)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 6) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdDL @era @Identity

-- | Extra entropy
ppExtraEntropyL :: forall era. (EraPParams era, ProtVerAtMost era 6) => Lens' (PParams era) Nonce
ppExtraEntropyL :: forall era.
(EraPParams era, ProtVerAtMost era 6) =>
Lens' (PParams era) Nonce
ppExtraEntropyL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Nonce -> f Nonce)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Nonce -> f Nonce)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 6) =>
Lens' (PParamsHKD f era) (HKD f Nonce)
hkdExtraEntropyL @era @Identity

-- | Minimum UTxO value
ppMinUTxOValueL :: forall era. (EraPParams era, ProtVerAtMost era 4) => Lens' (PParams era) Coin
ppMinUTxOValueL :: forall era.
(EraPParams era, ProtVerAtMost era 4) =>
Lens' (PParams era) Coin
ppMinUTxOValueL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Coin -> f Coin)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Coin -> f Coin)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 4) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinUTxOValueL @era @Identity

-- | Minimum Stake Pool Cost
ppMinPoolCostL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppMinPoolCostL :: forall era. EraPParams era => Lens' (PParams era) Coin
ppMinPoolCostL = (PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> PParams era -> f (PParams era)
ppLensHKD ((PParamsHKD Identity era -> f (PParamsHKD Identity era))
 -> PParams era -> f (PParams era))
-> ((Coin -> f Coin)
    -> PParamsHKD Identity era -> f (PParamsHKD Identity era))
-> (Coin -> f Coin)
-> PParams era
-> f (PParams era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinPoolCostL @era @Identity

-- PParamsUpdate versions of lenses

-- | The linear factor for the minimum fee calculation
ppuMinFeeAL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuMinFeeAL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuMinFeeAL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Coin -> f (StrictMaybe Coin))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Coin -> f (StrictMaybe Coin))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinFeeAL @era @StrictMaybe

-- | The constant factor for the minimum fee calculation
ppuMinFeeBL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuMinFeeBL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuMinFeeBL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Coin -> f (StrictMaybe Coin))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Coin -> f (StrictMaybe Coin))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinFeeBL @era @StrictMaybe

-- | Maximal block body size
ppuMaxBBSizeL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Word32)
ppuMaxBBSizeL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Word32)
ppuMaxBBSizeL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Word32 -> f (StrictMaybe Word32))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Word32 -> f (StrictMaybe Word32))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word32)
hkdMaxBBSizeL @era @StrictMaybe

-- | Maximal transaction size
ppuMaxTxSizeL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Word32)
ppuMaxTxSizeL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Word32)
ppuMaxTxSizeL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Word32 -> f (StrictMaybe Word32))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Word32 -> f (StrictMaybe Word32))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word32)
hkdMaxTxSizeL @era @StrictMaybe

-- | Maximal block header size
ppuMaxBHSizeL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Word16)
ppuMaxBHSizeL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Word16)
ppuMaxBHSizeL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Word16 -> f (StrictMaybe Word16))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Word16 -> f (StrictMaybe Word16))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word16)
hkdMaxBHSizeL @era @StrictMaybe

-- | The amount of a key registration deposit
ppuKeyDepositL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuKeyDepositL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuKeyDepositL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Coin -> f (StrictMaybe Coin))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Coin -> f (StrictMaybe Coin))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdKeyDepositL @era @StrictMaybe

-- | The amount of a pool registration deposit
ppuPoolDepositL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuPoolDepositL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuPoolDepositL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Coin -> f (StrictMaybe Coin))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Coin -> f (StrictMaybe Coin))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdPoolDepositL @era @StrictMaybe

-- | epoch bound on pool retirement
ppuEMaxL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe EpochInterval)
ppuEMaxL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe EpochInterval)
ppuEMaxL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe EpochInterval -> f (StrictMaybe EpochInterval))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe EpochInterval -> f (StrictMaybe EpochInterval))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f EpochInterval)
hkdEMaxL @era @StrictMaybe

-- | Desired number of pools
ppuNOptL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Word16)
ppuNOptL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Word16)
ppuNOptL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Word16 -> f (StrictMaybe Word16))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Word16 -> f (StrictMaybe Word16))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Word16)
hkdNOptL @era @StrictMaybe

-- | Pool influence
ppuA0L :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe NonNegativeInterval)
ppuA0L :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe NonNegativeInterval)
ppuA0L = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe NonNegativeInterval
     -> f (StrictMaybe NonNegativeInterval))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe NonNegativeInterval
    -> f (StrictMaybe NonNegativeInterval))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f NonNegativeInterval)
hkdA0L @era @StrictMaybe

-- | Monetary expansion
ppuRhoL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe UnitInterval)
ppuRhoL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe UnitInterval)
ppuRhoL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe UnitInterval -> f (StrictMaybe UnitInterval))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe UnitInterval -> f (StrictMaybe UnitInterval))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdRhoL @era @StrictMaybe

-- | Treasury expansion
ppuTauL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe UnitInterval)
ppuTauL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe UnitInterval)
ppuTauL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe UnitInterval -> f (StrictMaybe UnitInterval))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe UnitInterval -> f (StrictMaybe UnitInterval))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdTauL @era @StrictMaybe

-- | Decentralization parameter
ppuDL ::
  forall era.
  (EraPParams era, ProtVerAtMost era 6) =>
  Lens' (PParamsUpdate era) (StrictMaybe UnitInterval)
ppuDL :: forall era.
(EraPParams era, ProtVerAtMost era 6) =>
Lens' (PParamsUpdate era) (StrictMaybe UnitInterval)
ppuDL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe UnitInterval -> f (StrictMaybe UnitInterval))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe UnitInterval -> f (StrictMaybe UnitInterval))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 6) =>
Lens' (PParamsHKD f era) (HKD f UnitInterval)
hkdDL @era @StrictMaybe

-- | Extra entropy
ppuExtraEntropyL ::
  forall era.
  (EraPParams era, ProtVerAtMost era 6) =>
  Lens' (PParamsUpdate era) (StrictMaybe Nonce)
ppuExtraEntropyL :: forall era.
(EraPParams era, ProtVerAtMost era 6) =>
Lens' (PParamsUpdate era) (StrictMaybe Nonce)
ppuExtraEntropyL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Nonce -> f (StrictMaybe Nonce))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Nonce -> f (StrictMaybe Nonce))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 6) =>
Lens' (PParamsHKD f era) (HKD f Nonce)
hkdExtraEntropyL @era @StrictMaybe

-- | Minimum UTxO value
ppuMinUTxOValueL ::
  forall era.
  (EraPParams era, ProtVerAtMost era 4) =>
  Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuMinUTxOValueL :: forall era.
(EraPParams era, ProtVerAtMost era 4) =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuMinUTxOValueL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Coin -> f (StrictMaybe Coin))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Coin -> f (StrictMaybe Coin))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, ProtVerAtMost era 4) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinUTxOValueL @era @StrictMaybe

-- | Minimum Stake Pool Cost
ppuMinPoolCostL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuMinPoolCostL :: forall era.
EraPParams era =>
Lens' (PParamsUpdate era) (StrictMaybe Coin)
ppuMinPoolCostL = (PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
forall era (f :: * -> *).
Functor f =>
(PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> PParamsUpdate era -> f (PParamsUpdate era)
ppuLensHKD ((PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
 -> PParamsUpdate era -> f (PParamsUpdate era))
-> ((StrictMaybe Coin -> f (StrictMaybe Coin))
    -> PParamsHKD StrictMaybe era -> f (PParamsHKD StrictMaybe era))
-> (StrictMaybe Coin -> f (StrictMaybe Coin))
-> PParamsUpdate era
-> f (PParamsUpdate era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era (f :: * -> *).
(EraPParams era, HKDFunctor f) =>
Lens' (PParamsHKD f era) (HKD f Coin)
hkdMinPoolCostL @era @StrictMaybe

jsonPairsPParams :: forall era e a. EraPParams era => Aeson.KeyValue e a => PParams era -> [a]
jsonPairsPParams :: forall era e a.
(EraPParams era, KeyValue e a) =>
PParams era -> [a]
jsonPairsPParams PParams era
pp =
  [ Text -> Key
Aeson.fromText Text
ppName Key -> Value -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= t -> Value
forall a. ToJSON a => a -> Value
toJSON (PParams era
pp PParams era -> Getting t (PParams era) t -> t
forall s a. s -> Getting a s a -> a
^. Getting t (PParams era) t
Lens' (PParams era) t
ppLens)
  | PParam {Text
ppName :: forall era. PParam era -> Text
ppName :: Text
ppName, Lens' (PParams era) t
ppLens :: ()
ppLens :: Lens' (PParams era) t
ppLens} <- forall era. EraPParams era => [PParam era]
eraPParams @era
  ]

jsonPairsPParamsUpdate ::
  forall era e a.
  (EraPParams era, Aeson.KeyValue e a) =>
  PParamsUpdate era -> [a]
jsonPairsPParamsUpdate :: forall era e a.
(EraPParams era, KeyValue e a) =>
PParamsUpdate era -> [a]
jsonPairsPParamsUpdate PParamsUpdate era
ppu =
  [ Text -> Key
Aeson.fromText Text
ppName Key -> Value -> a
forall v. ToJSON v => Key -> v -> a
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= t -> Value
forall a. ToJSON a => a -> Value
toJSON t
v
  | PParam {Text
ppName :: forall era. PParam era -> Text
ppName :: Text
ppName, ppUpdate :: ()
ppUpdate = Just (PParamUpdate {Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens :: forall era t.
PParamUpdate era t -> Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens :: Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens})} <- forall era. EraPParams era => [PParam era]
eraPParams @era
  , SJust t
v <- [PParamsUpdate era
ppu PParamsUpdate era
-> Getting (StrictMaybe t) (PParamsUpdate era) (StrictMaybe t)
-> StrictMaybe t
forall s a. s -> Getting a s a -> a
^. Getting (StrictMaybe t) (PParamsUpdate era) (StrictMaybe t)
Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens]
  ]

mapPParams :: (PParamsHKD Identity era1 -> PParamsHKD Identity era2) -> PParams era1 -> PParams era2
mapPParams :: forall era1 era2.
(PParamsHKD Identity era1 -> PParamsHKD Identity era2)
-> PParams era1 -> PParams era2
mapPParams PParamsHKD Identity era1 -> PParamsHKD Identity era2
f (PParams PParamsHKD Identity era1
pp) = PParamsHKD Identity era2 -> PParams era2
forall era. PParamsHKD Identity era -> PParams era
PParams (PParamsHKD Identity era2 -> PParams era2)
-> PParamsHKD Identity era2 -> PParams era2
forall a b. (a -> b) -> a -> b
$ PParamsHKD Identity era1 -> PParamsHKD Identity era2
f PParamsHKD Identity era1
pp

mapPParamsUpdate ::
  (PParamsHKD StrictMaybe era1 -> PParamsHKD StrictMaybe era2) ->
  PParamsUpdate era1 ->
  PParamsUpdate era2
mapPParamsUpdate :: forall era1 era2.
(PParamsHKD StrictMaybe era1 -> PParamsHKD StrictMaybe era2)
-> PParamsUpdate era1 -> PParamsUpdate era2
mapPParamsUpdate PParamsHKD StrictMaybe era1 -> PParamsHKD StrictMaybe era2
f (PParamsUpdate PParamsHKD StrictMaybe era1
pp) = PParamsHKD StrictMaybe era2 -> PParamsUpdate era2
forall era. PParamsHKD StrictMaybe era -> PParamsUpdate era
PParamsUpdate (PParamsHKD StrictMaybe era2 -> PParamsUpdate era2)
-> PParamsHKD StrictMaybe era2 -> PParamsUpdate era2
forall a b. (a -> b) -> a -> b
$ PParamsHKD StrictMaybe era1 -> PParamsHKD StrictMaybe era2
f PParamsHKD StrictMaybe era1
pp

upgradePParams ::
  (EraPParams era, EraPParams (PreviousEra era)) =>
  UpgradePParams Identity era ->
  PParams (PreviousEra era) ->
  PParams era
upgradePParams :: forall era.
(EraPParams era, EraPParams (PreviousEra era)) =>
UpgradePParams Identity era
-> PParams (PreviousEra era) -> PParams era
upgradePParams UpgradePParams Identity era
args (PParams PParamsHKD Identity (PreviousEra era)
pphkd) =
  PParamsHKD Identity era -> PParams era
forall era. PParamsHKD Identity era -> PParams era
PParams (forall era (f :: * -> *).
(EraPParams era, HKDApplicative f, EraPParams (PreviousEra era)) =>
UpgradePParams f era
-> PParamsHKD f (PreviousEra era) -> PParamsHKD f era
upgradePParamsHKD @_ @Identity UpgradePParams Identity era
args PParamsHKD Identity (PreviousEra era)
pphkd)

downgradePParams ::
  (EraPParams era, EraPParams (PreviousEra era)) =>
  DowngradePParams Identity era ->
  PParams era ->
  PParams (PreviousEra era)
downgradePParams :: forall era.
(EraPParams era, EraPParams (PreviousEra era)) =>
DowngradePParams Identity era
-> PParams era -> PParams (PreviousEra era)
downgradePParams DowngradePParams Identity era
args (PParams PParamsHKD Identity era
pphkd) =
  PParamsHKD Identity (PreviousEra era) -> PParams (PreviousEra era)
forall era. PParamsHKD Identity era -> PParams era
PParams (forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, EraPParams (PreviousEra era)) =>
DowngradePParams f era
-> PParamsHKD f era -> PParamsHKD f (PreviousEra era)
downgradePParamsHKD @_ @Identity DowngradePParams Identity era
args PParamsHKD Identity era
pphkd)

upgradePParamsUpdate ::
  (EraPParams era, EraPParams (PreviousEra era)) =>
  UpgradePParams StrictMaybe era ->
  PParamsUpdate (PreviousEra era) ->
  PParamsUpdate era
upgradePParamsUpdate :: forall era.
(EraPParams era, EraPParams (PreviousEra era)) =>
UpgradePParams StrictMaybe era
-> PParamsUpdate (PreviousEra era) -> PParamsUpdate era
upgradePParamsUpdate UpgradePParams StrictMaybe era
args (PParamsUpdate PParamsHKD StrictMaybe (PreviousEra era)
pphkd) =
  PParamsHKD StrictMaybe era -> PParamsUpdate era
forall era. PParamsHKD StrictMaybe era -> PParamsUpdate era
PParamsUpdate (forall era (f :: * -> *).
(EraPParams era, HKDApplicative f, EraPParams (PreviousEra era)) =>
UpgradePParams f era
-> PParamsHKD f (PreviousEra era) -> PParamsHKD f era
upgradePParamsHKD @_ @StrictMaybe UpgradePParams StrictMaybe era
args PParamsHKD StrictMaybe (PreviousEra era)
pphkd)

downgradePParamsUpdate ::
  (EraPParams era, EraPParams (PreviousEra era)) =>
  DowngradePParams StrictMaybe era ->
  PParamsUpdate era ->
  PParamsUpdate (PreviousEra era)
downgradePParamsUpdate :: forall era.
(EraPParams era, EraPParams (PreviousEra era)) =>
DowngradePParams StrictMaybe era
-> PParamsUpdate era -> PParamsUpdate (PreviousEra era)
downgradePParamsUpdate DowngradePParams StrictMaybe era
args (PParamsUpdate PParamsHKD StrictMaybe era
pphkd) =
  PParamsHKD StrictMaybe (PreviousEra era)
-> PParamsUpdate (PreviousEra era)
forall era. PParamsHKD StrictMaybe era -> PParamsUpdate era
PParamsUpdate (forall era (f :: * -> *).
(EraPParams era, HKDFunctor f, EraPParams (PreviousEra era)) =>
DowngradePParams f era
-> PParamsHKD f era -> PParamsHKD f (PreviousEra era)
downgradePParamsHKD @_ @StrictMaybe DowngradePParams StrictMaybe era
args PParamsHKD StrictMaybe era
pphkd)

-- | Represents a single protocol parameter and the data required to serialize it.
data PParam era where
  PParam ::
    (DecCBOR t, EncCBOR t, FromJSON t, ToJSON t, ToPlutusData t) =>
    { forall era. PParam era -> Text
ppName :: Text
    -- ^ Used as JSON key
    , ()
ppLens :: Lens' (PParams era) t
    , ()
ppUpdate :: Maybe (PParamUpdate era t)
    -- ^ Not all protocol parameters have an update functionality in all eras
    } ->
    PParam era

data PParamUpdate era t = PParamUpdate
  { forall era t. PParamUpdate era t -> Word
ppuTag :: Word
  -- ^ Used in CBOR and Plutus Data encoding of
  , forall era t.
PParamUpdate era t -> Lens' (PParamsUpdate era) (StrictMaybe t)
ppuLens :: Lens' (PParamsUpdate era) (StrictMaybe t)
  }