Skip to content

Commit

Permalink
refactor: remove redundant func
Browse files Browse the repository at this point in the history
  • Loading branch information
hadelive committed Dec 8, 2023
1 parent c51c0ec commit aa6b55f
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 684 deletions.
30 changes: 0 additions & 30 deletions src/Plutarch/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,12 @@ import Plutarch.Prelude
import Plutarch.Utils (passert, pisPrefixOf)
import PlutusLedgerApi.V1 (TokenName)

projectTokenHolderTN :: Term s PTokenName
projectTokenHolderTN =
let tn :: TokenName
tn = "PTHolder"
in pconstant tn

commitFoldTN :: Term s PTokenName
commitFoldTN =
let tn :: TokenName
tn = "CFold"
in pconstant tn

rewardFoldTN :: Term s PTokenName
rewardFoldTN =
let tn :: TokenName
tn = "RFold"
in pconstant tn

poriginNodeTN :: Term s PTokenName
poriginNodeTN =
let tn :: TokenName
tn = "FSN"
in pconstant tn

pcorrNodeTN :: Term s PTokenName
pcorrNodeTN =
let tn :: TokenName
tn = "FCN"
in pconstant tn

psetNodePrefix :: ClosedTerm PByteString
psetNodePrefix = pconstant "FSN"

Expand All @@ -57,12 +33,6 @@ pparseNodeKey = phoistAcyclic $
passert "incorrect node prefix" $ pisPrefixOf # psetNodePrefix # tn
pif (prefixLength #< tnLength) (pcon $ PJust key) (pcon PNothing)

foldingFee :: Term s PInteger
foldingFee = pconstant 1_000_000

minAda :: Term s PInteger
minAda = pconstant 2_000_000

nodeAda :: Term s PInteger
nodeAda = pconstant 3_000_000

Expand Down
51 changes: 0 additions & 51 deletions src/Plutarch/Helpers.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
module Plutarch.Helpers (
coversSeparators,
coversKey,
hasUtxoWithRef,
pseparatorsMintValue,
correctNodeTokensMinted,
correctNodeTokenMinted,
)
where

import Plutarch.Api.V1.AssocMap qualified as AssocMap
import Plutarch.Api.V1.Value qualified as V
import Plutarch.Api.V2 (
AmountGuarantees (NonZero),
KeyGuarantees (Sorted),
Expand All @@ -19,8 +15,6 @@ import Plutarch.Api.V2 (
PTxOutRef,
PValue,
)
import Plutarch.Constants (pnodeKeyTN)
import Plutarch.Extra.Traversable (pfoldMap)
import Plutarch.Monadic qualified as P
import Plutarch.Prelude
import Plutarch.Types (PDiscoverySetNode, PNodeKey (PEmpty, PKey))
Expand All @@ -38,19 +32,6 @@ coversKey = phoistAcyclic $
PKey (pfromData . (pfield @"_0" #) -> next) -> keyToCover #< next
moreThanKey #&& lessThanNext

-- | Checks that all the separators are covered by the node
coversSeparators :: ClosedTerm (PAsData PDiscoverySetNode :--> PBuiltinList PByteString :--> PBool)
coversSeparators = phoistAcyclic $
plam $ \datum separators -> P.do
nodeDatum <- pletFields @'["key", "next"] datum
let moreThanKey = pmatch (nodeDatum.key) $ \case
PEmpty _ -> pcon PTrue
PKey (pfromData . (pfield @"_0" #) -> key) -> pall # plam (key #<) # separators
lessThanNext = pmatch (nodeDatum.next) $ \case
PEmpty _ -> pcon PTrue
PKey (pfromData . (pfield @"_0" #) -> next) -> pall # plam (#< next) # separators
moreThanKey #&& lessThanNext

{- | @hasUtxoWithRef # oref # inputs@
ensures that in @inputs@ there is an input having @TxOutRef@ @oref@ .
-}
Expand All @@ -64,38 +45,6 @@ hasUtxoWithRef = phoistAcyclic $
plam $ \oref inInputs ->
pany # plam (\input -> oref #== (pfield @"outRef" # input)) # inInputs

-- | Makes a Value from a list of separators keys
pseparatorsMintValue ::
ClosedTerm
( PInteger
:--> PCurrencySymbol
:--> PBuiltinList PByteString
:--> PValue 'Sorted 'NonZero
)
pseparatorsMintValue = phoistAcyclic $
plam $ \amount nodeCS separators ->
let mkSeparatorToken = plam $ \key -> V.psingleton # nodeCS # (pnodeKeyTN # key) # amount
in pfoldMap # mkSeparatorToken # separators

{- | Ensures that the minted amount of the FinSet CS is exactly the specified
list of tokenNames and amount
-}
correctNodeTokensMinted ::
ClosedTerm
( PCurrencySymbol
:--> PList PTokenName
:--> PInteger
:--> PValue 'Sorted 'NonZero
:--> PBool
)
correctNodeTokensMinted = phoistAcyclic $
plam $ \nodeCS tokenNames amount mint -> P.do
PJust nodeMint <- pmatch $ AssocMap.plookup # nodeCS # pto mint
let mkToken = plam $ \tn ->
AssocMap.pinsert # tn # amount
tokenMap = pfoldr # mkToken # AssocMap.pempty # tokenNames
tokenMap #== nodeMint

{- | Ensures that the minted amount of the FinSet CS is exactly the specified
tokenName and amount
-}
Expand Down
103 changes: 0 additions & 103 deletions src/Plutarch/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

module Plutarch.Types (
PDiscoveryNodeAction (..),
PNodeValidatorAction (..),
PDiscoveryConfig (..),
PDiscoveryLaunchConfig (..),
PSepNodeAction (..),
PSeparatorConfig (..),
PDiscoverySetNode (..),
PNodeKey (..),
PNodeKeyState (..),
Expand All @@ -33,7 +29,6 @@ import Plutarch.Api.V2 (
PAddress,
PPOSIXTime,
PPubKeyHash (PPubKeyHash),
PStakingCredential (..),
PTxOutRef,
)
import Plutarch.Classes
Expand All @@ -47,52 +42,6 @@ import Plutarch.Prelude
import PlutusLedgerApi.V2 (BuiltinByteString, PubKeyHash)
import PlutusTx qualified

data NodeValidatorAction
= LinkedListAct
| ModifyCommitment
| RewardFoldAct
deriving stock (Generic, Show)

PlutusTx.unstableMakeIsData ''NodeValidatorAction

data PNodeValidatorAction (s :: S)
= PLinkedListAct (Term s (PDataRecord '[]))
| PModifyCommitment (Term s (PDataRecord '[]))
| PRewardFoldAct (Term s (PDataRecord '[]))
deriving stock (Generic)
deriving anyclass (PlutusType, PIsData, PShow)

instance DerivePlutusType PNodeValidatorAction where
type DPTStrat _ = PlutusTypeData

instance PUnsafeLiftDecl PNodeValidatorAction where
type PLifted PNodeValidatorAction = NodeValidatorAction

deriving via
(DerivePConstantViaData NodeValidatorAction PNodeValidatorAction)
instance
(PConstantDecl NodeValidatorAction)

instance PTryFrom PData (PAsData PNodeValidatorAction)

instance PTryFrom PData PNodeValidatorAction

newtype PDiscoveryLaunchConfig (s :: S)
= PDiscoveryLaunchConfig
( Term
s
( PDataRecord
'[ "discoveryDeadline" ':= PPOSIXTime
, "penaltyAddress" ':= PAddress
, "globalCred" ':= PStakingCredential
]
)
)
deriving stock (Generic)
deriving anyclass (PlutusType, PIsData, PDataFields, PEq)

instance DerivePlutusType PDiscoveryLaunchConfig where type DPTStrat _ = PlutusTypeData

newtype PDiscoveryConfig (s :: S)
= PDiscoveryConfig
( Term
Expand Down Expand Up @@ -122,19 +71,6 @@ data DiscoverySetNode = MkSetNode

PlutusTx.unstableMakeIsData ''DiscoverySetNode

data SepNodeAction
= SepInit
| SepDeinit
| SepInsert PubKeyHash DiscoverySetNode
| SepRemove PubKeyHash DiscoverySetNode
| InsertSeps [BuiltinByteString] DiscoverySetNode
| -- | first arg is the key to insert, second arg is the covering node
RemoveSeps [BuiltinByteString] DiscoverySetNode
-- first arg is the key to remove, second arg is the covering node
deriving stock (Show, Eq, Generic)

PlutusTx.unstableMakeIsData ''SepNodeAction

data DiscoveryNodeAction
= Init
| Deinit
Expand Down Expand Up @@ -242,21 +178,6 @@ instance ScottConvertible PDiscoverySetNode where
)
)

newtype PSeparatorConfig (s :: S)
= PSeparatorConfig
( Term
s
( PDataRecord
'[ "signer" ':= PPubKeyHash
, "cutOff" ':= PPOSIXTime
]
)
)
deriving stock (Generic)
deriving anyclass (PlutusType, PIsData, PDataFields, PEq)

instance DerivePlutusType PSeparatorConfig where type DPTStrat _ = PlutusTypeData

mkNode :: Term s (PNodeKey :--> PNodeKey :--> PDiscoverySetNode)
mkNode = phoistAcyclic $
plam $ \key next ->
Expand Down Expand Up @@ -289,30 +210,6 @@ deriving via
instance
PConstantDecl DiscoveryNodeAction

data PSepNodeAction (s :: S)
= PSepInit (Term s (PDataRecord '[]))
| PSepDeinit (Term s (PDataRecord '[]))
| PSepInsert (Term s (PDataRecord '["keyToInsert" ':= PPubKeyHash, "coveringNode" ':= PDiscoverySetNode]))
| PSepRemove (Term s (PDataRecord '["keyToRemove" ':= PPubKeyHash, "coveringNode" ':= PDiscoverySetNode]))
| -- | separators must be sorted or validation will fail
PInsertSeps (Term s (PDataRecord '["separators" ':= PBuiltinList (PAsData PByteString), "coveringNode" ':= PDiscoverySetNode]))
| PRemoveSeps (Term s (PDataRecord '["separators" ':= PBuiltinList (PAsData PByteString), "coveringNode" ':= PDiscoverySetNode]))
deriving stock (Generic)
deriving anyclass (PlutusType, PIsData, PEq)

instance DerivePlutusType PSepNodeAction where type DPTStrat _ = PlutusTypeData

deriving anyclass instance
PTryFrom PData (PAsData PSepNodeAction)

instance PUnsafeLiftDecl PSepNodeAction where
type PLifted PSepNodeAction = SepNodeAction

deriving via
(DerivePConstantViaData SepNodeAction PSepNodeAction)
instance
PConstantDecl SepNodeAction

-----------------------------------------------
-- Helpers:

Expand Down
Loading

0 comments on commit aa6b55f

Please sign in to comment.