Cardano.Gov

Handling gov-related stuff.

type Id
= CcHotCredId Credential
| CcColdCredId Credential
| DrepId Credential
| PoolId (Bytes Id)
| GovActionId ActionId

Governance Id related to CIP 129. In addition to CC and DRep, this also includes SPOs as potential governance Ids!

idFromBech32 : String -> Maybe Id

Convert a Gov Id from its Bech32 governance Id (CIP 129) or Pool Id (CIP 5).

Remark: will fail if a gov action index is >= 256 since we make the simplifying assumption it’s only 1 byte long.

idToBech32 : Id -> String

Convert a Gov Id from its Bech32 governance Id (CIP 129) or Pool Id (CIP 5).

Remark: will be wrong if a gov action index is >= 256 since we make the simplifying assumption it’s only 1 byte long.

type Drep
= DrepCredential Credential
| AlwaysAbstain
| AlwaysNoConfidence

Delegate representative.

decodeDrep : Decoder Drep

Decoder for Drep type.

encodeDrep : Drep -> Encoder

Encoder for Drep type.

type alias ProposalProcedure =
{ deposit : Natural
, depositReturnAccount : StakeAddress
, govAction : Action
, anchor : Anchor
}

Represents a proposal procedure.

proposalProcedureFromCbor : Decoder ProposalProcedure

Decoder for ProposalProcedure type.

type Action
= ParameterChange
{ latestEnacted : Maybe ActionId
, protocolParamUpdate : ProtocolParamUpdate
, guardrailsPolicy : Maybe (Bytes PolicyId)
}
| HardForkInitiation
{ latestEnacted : Maybe ActionId
, protocolVersion : ProtocolVersion
}
| TreasuryWithdrawals
{ withdrawals : List ( StakeAddress, Natural )
, guardrailsPolicy : Maybe (Bytes PolicyId)
}
| NoConfidence { latestEnacted : Maybe ActionId }
| UpdateCommittee
{ latestEnacted : Maybe ActionId
, removedMembers : List Credential
, addedMembers :
List
{ newMember : Credential
, expirationEpoch : Natural
}
, quorumThreshold : UnitInterval
}
| NewConstitution
{ latestEnacted : Maybe ActionId
, constitution : Constitution
}
| Info

Represents different types of governance actions.

Decoder for Action type.

encodeAction : Action -> Encoder

Encoder for Action type.

type alias ActionId =
{ transactionId : Bytes TransactionId
, govActionIndex : Int
}

Represents an action ID.

actionIdToString : ActionId -> String

Convert [ActionId] into its Hex string.

actionIdFromCbor : Decoder ActionId

Decoder for ActionId type.

encodeActionId : ActionId -> Encoder

Encoder for ActionId type.

type alias Constitution =
{ anchor : Anchor
, scripthash : Maybe (Bytes CredentialHash)
}

Represents a constitution.

decodeConstitution : Decoder Constitution

Decoder for Constitution type.

encodeConstitution : Constitution -> Encoder

Encoder for Constitution type.

type alias ProtocolParamUpdate =
{ minFeeA : Maybe Natural
, minFeeB : Maybe Natural
, maxBlockBodySize : Maybe Int
, maxTransactionSize : Maybe Int
, maxBlockHeaderSize : Maybe Int
, keyDeposit : Maybe Natural
, poolDeposit : Maybe Natural
, maximumEpoch : Maybe Natural
, desiredNumberOfStakePools : Maybe Int
, poolPledgeInfluence : Maybe RationalNumber
, expansionRate : Maybe UnitInterval
, treasuryGrowthRate : Maybe UnitInterval
, decentralizationConstant : Maybe UnitInterval
, extraEntropy : Maybe Nonce
, protocolVersion : Maybe ProtocolVersion
, minUtxoValue : Maybe Natural
, minPoolCost : Maybe Natural
, adaPerUtxoByte : Maybe Natural
, costModelsForScriptLanguages : Maybe CostModels
, executionCosts : Maybe ExUnitPrices
, maxTxExUnits : Maybe ExUnits
, maxBlockExUnits : Maybe ExUnits
, maxValueSize : Maybe Int
, collateralPercentage : Maybe Int
, maxCollateralInputs : Maybe Int
, poolVotingThresholds : Maybe PoolVotingThresholds
, drepVotingThresholds : Maybe DrepVotingThresholds
, minCommitteeSize : Maybe Int
, committeeTermLimit : Maybe Natural
, governanceActionValidityPeriod : Maybe Natural
, governanceActionDeposit : Maybe Natural
, drepDeposit : Maybe Natural
, drepInactivityPeriod : Maybe Natural
, minFeeRefScriptCostPerByte : Maybe Int
}

Adjustable parameters that power key aspects of the network.

noParamUpdate : ProtocolParamUpdate

Default (no update) for [ProtocolParamUpdate].

decodeProtocolParamUpdate : Decoder ProtocolParamUpdate

Decoder for ProtocolParamUpdate type.

encodeProtocolParamUpdate : ProtocolParamUpdate -> Encoder

Encoder for ProtocolParamUpdate type.

{ motionNoConfidence : UnitInterval
, committeeNormal : UnitInterval
, committeeNoConfidence : UnitInterval
, hardforkInitiation : UnitInterval
, securityRelevantParameter : UnitInterval
}

Represents voting thresholds for stake pools.

decodePoolVotingThresholds : Decoder PoolVotingThresholds

Decoder for PoolVotingThresholds type.

encodePoolVotingThresholds : PoolVotingThresholds -> Encoder

Encoder for PoolVotingThresholds type.

{ motionNoConfidence : UnitInterval
, committeeNormal : UnitInterval
, committeeNoConfidence : UnitInterval
, updateConstitution : UnitInterval
, hardforkInitiation : UnitInterval
, ppNetworkGroup : UnitInterval
, ppEconomicGroup : UnitInterval
, ppTechnicalGroup : UnitInterval
, ppGovernanceGroup : UnitInterval
, treasuryWithdrawal : UnitInterval
}

Represents voting thresholds for delegate representatives.

decodeDrepVotingThresholds : Decoder DrepVotingThresholds

Decoder for DrepVotingThresholds type.

encodeDrepVotingThresholds : DrepVotingThresholds -> Encoder

Encoder for DrepVotingThresholds type.

type alias CostModels =
{ plutusV1 : Maybe (List Int)
, plutusV2 : Maybe (List Int)
, plutusV3 : Maybe (List Int)
}

Represents cost models for different Plutus versions.

decodeCostModels : Decoder CostModels

Decoder for CostModels type.

encodeCostModels : CostModels -> Encoder

Encode [CostModels] to CBOR.

type alias ProtocolVersion =
( Int, Int )

Represents a protocol version.

decodeProtocolVersion : Decoder ProtocolVersion

Decoder for ProtocolVersion type.

encodeProtocolVersion : ProtocolVersion -> Encoder

Encoder for ProtocolVersion type.

type Nonce
= Just0
| RandomBytes (Bytes Any)

Represents a nonce for extra entropy.

type alias VotingProcedure =
{ vote : Vote
, anchor : Maybe Anchor
}

Represents a voting procedure.

votingProcedureFromCbor : Decoder VotingProcedure

Decoder for VotingProcedure type.

encodeVotingProcedure : VotingProcedure -> Encoder

Encoder for VotingProcedure type.

type Vote
= VoteNo
| VoteYes
| VoteAbstain

Represents different types of votes.

encodeVote : Vote -> Encoder

Encoder for Vote type.

type Voter
= VoterCommitteeHotCred Credential
| VoterDrepCred Credential
| VoterPoolId (Bytes CredentialHash)

Represents different types of voters.

type alias VoterDict a =
AnyDict ( Int, String ) Voter a

Convenient alias for a Dict with [Voter] keys. When converting to a List, its keys are sorted with the same order as the Haskell node. The order is determined by [voterLedgerOrder].

WARNING: do not compare them with == since they contain functions.

emptyVoterDict : VoterDict a

Create a empty voter dictionary. For other operations, use the AnyDict module directly.

WARNING: do not compare them with == since they contain functions.

voterDictFromList : List ( Voter, a ) -> VoterDict a

Create a voter dictionary from a list. For other operations, use the AnyDict module directly.

WARNING: do not compare them with == since they contain functions.

Convert a Voter into a CIP-129 governance Id.

Extract the credential hash of a voter.

Helper function to extract keys that would need signing.

voterLedgerOrder : Voter -> ( Int, String )

Helper function to help sort voters for redeemers in the same order as Haskell node.

The problem is that the ledger code sort these maps with auto derived order. And the Credential definition uses ScriptHash first, instead of VKeyHash first. https://github.com/IntersectMBO/cardano-ledger/blob/2f199b94716350b5fbd6c07505eb333d89cffa90/libs/cardano-ledger-core/src/Cardano/Ledger/Credential.hs#L85

Decoder for Voter type.

encodeVoter : Voter -> Encoder

Encoder for Voter type.

type alias Anchor =
{ url : String
, dataHash : Bytes AnchorDataHash
}

Represents an anchor for governance actions.

Opaque phantom type for an [Anchor] data hash. It is 32-bytes long.

decodeAnchor : Decoder Anchor

Decoder for Anchor type.

encodeAnchor : Anchor -> Encoder

Encoder for Anchor type.