diff --git a/CHANGELOG.md b/CHANGELOG.md index 72ca070..53ec79b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ This format is based on [Keep A Changelog](https://keepachangelog.com/en/1.0.0). ### Modified +- Use `Credential` instead of `PubKeyHash` + + Included by [#158](https://github.com/Liqwid-Labs/agora/pull/158). + + NOTE: This changes the representation of the following types: + + - `PStakeDatum` + - `PStakeRedeemer` + - `PProposalDatum` + - `PProposalRedeemer` + - Use plutus v2 types. Included by [#156](https://github.com/Liqwid-Labs/agora/pull/156). diff --git a/agora/Agora/Credential.hs b/agora/Agora/Credential.hs index c772851..b42d91b 100644 --- a/agora/Agora/Credential.hs +++ b/agora/Agora/Credential.hs @@ -5,30 +5,21 @@ Description: Functions for dealing with generalized credentials. Functions for dealing with generalized credentials. -} -module Agora.Credential (PAuthorizationCredential, AuthorizationCredential, pauthorizedBy, authorizationContext) where +module Agora.Credential ( + pauthorizedBy, + authorizationContext, +) where import GHC.Records (HasField) -import Plutarch.Api.V1 (PCredential (..), PPubKeyHash) -import Plutarch.Api.V2 (PTxInInfo (..)) +import Plutarch.Api.V1 (PCredential (PPubKeyCredential, PScriptCredential), PPubKeyHash) +import Plutarch.Api.V2 (PTxInInfo) import Plutarch.Extra.ScriptContext (ptxSignedBy) import Plutarch.Extra.TermCont (pmatchC) -import PlutusLedgerApi.V2 (Credential) - -{- | This type represents a general purpose authority which can be used - to check for approval. - - The most basic case is simply a PubKeyCredential. - - @since 1.0.0 --} -type AuthorizationCredential = - Credential - -type PAuthorizationCredential = - PCredential {- | Context required in order to check 'AuthorizationCredential'. + Construct using 'authorizationContext'. + @since 1.0.0 -} data PAuthorizationContext (s :: S) = PAuthorizationContext @@ -55,7 +46,7 @@ instance DerivePlutusType PAuthorizationContext where @since 1.0.0 -} authorizationContext :: - forall {r} {s :: S}. + forall (s :: S) r. ( HasField "inputs" r (Term s (PBuiltinList PTxInInfo)) , HasField "signatories" r (Term s (PBuiltinList (PAsData PPubKeyHash))) ) => @@ -68,7 +59,7 @@ authorizationContext f = @since 1.0.0 -} -pauthorizedBy :: forall (s :: S). Term s (PAuthorizationContext :--> PAuthorizationCredential :--> PBool) +pauthorizedBy :: forall (s :: S). Term s (PAuthorizationContext :--> PCredential :--> PBool) pauthorizedBy = phoistAcyclic $ plam $ \ctx credential -> unTermCont $ do ctxF <- pmatchC ctx diff --git a/agora/Agora/Proposal.hs b/agora/Agora/Proposal.hs index e18984d..9b71989 100644 --- a/agora/Agora/Proposal.hs +++ b/agora/Agora/Proposal.hs @@ -42,7 +42,6 @@ module Agora.Proposal ( pisProposalThresholdsValid, ) where -import Agora.Credential (AuthorizationCredential, PAuthorizationCredential) import Agora.Plutarch.Orphans () import Agora.Proposal.Time ( PProposalStartingTime, @@ -53,7 +52,7 @@ import Agora.Proposal.Time ( import Agora.SafeMoney (GTTag) import Data.Tagged (Tagged) import Generics.SOP qualified as SOP -import Plutarch.Api.V1 (PMap, PValidatorHash) +import Plutarch.Api.V1 (PCredential, PMap, PValidatorHash) import Plutarch.Api.V1.AssocMap qualified as PAssocMap import Plutarch.Api.V2 ( KeyGuarantees (Unsorted), @@ -347,7 +346,7 @@ data ProposalRedeemer -- provided enough GT is shared among them. -- -- This list should be sorted in ascending order. - Cosign [AuthorizationCredential] + Cosign [Credential] | -- | Allow unlocking one or more stakes with votes towards particular 'ResultTag'. Unlock | -- | Advance the proposal, performing the required checks for whether that is legal. @@ -617,7 +616,7 @@ newtype PProposalDatum (s :: S) = PProposalDatum '[ "proposalId" ':= PProposalId , "effects" ':= PMap 'Unsorted PResultTag PProposalEffectGroup , "status" ':= PProposalStatus - , "cosigners" ':= PBuiltinList (PAsData PAuthorizationCredential) + , "cosigners" ':= PBuiltinList (PAsData PCredential) , "thresholds" ':= PProposalThresholds , "votes" ':= PProposalVotes , "timingConfig" ':= PProposalTimingConfig @@ -656,7 +655,7 @@ deriving via (DerivePConstantViaDataList ProposalDatum PProposalDatum) instance -} data PProposalRedeemer (s :: S) = PVote (Term s (PDataRecord '["resultTag" ':= PResultTag])) - | PCosign (Term s (PDataRecord '["newCosigners" ':= PBuiltinList (PAsData PAuthorizationCredential)])) + | PCosign (Term s (PDataRecord '["newCosigners" ':= PBuiltinList (PAsData PCredential)])) | PUnlock (Term s (PDataRecord '[])) | PAdvanceProposal (Term s (PDataRecord '[])) deriving stock diff --git a/agora/Agora/Proposal/Scripts.hs b/agora/Agora/Proposal/Scripts.hs index 1bd3a9b..44d9f2c 100644 --- a/agora/Agora/Proposal/Scripts.hs +++ b/agora/Agora/Proposal/Scripts.hs @@ -10,7 +10,7 @@ module Agora.Proposal.Scripts ( proposalPolicy, ) where -import Agora.Credential (PAuthorizationCredential, authorizationContext, pauthorizedBy) +import Agora.Credential (authorizationContext, pauthorizedBy) import Agora.Proposal ( PProposalDatum (PProposalDatum), PProposalRedeemer (..), @@ -40,6 +40,7 @@ import Agora.Stake ( import Agora.Utils ( pltAsData, ) +import Plutarch.Api.V1 (PCredential) import Plutarch.Api.V2 ( PDatumHash, PMintingPolicy, @@ -299,7 +300,7 @@ proposalValidator as maximumCosigners = Term _ ( ( PInteger - :--> PBuiltinList (PAsData PAuthorizationCredential) + :--> PBuiltinList (PAsData PCredential) :--> PUnit ) :--> PUnit