Skip to content

Commit b6cb780

Browse files
committed
feat(standing_bid): implement MoveToHydra sub-validator
1 parent c0dc4bc commit b6cb780

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/HydraAuctionOnchain/Validators/StandingBid.hs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import HydraAuctionOnchain.Types.StandingBidState (PStandingBidState, pvalidateN
1414
import Plutarch.Api.V1.Value (pvalueOf)
1515
import Plutarch.Api.V2 (PCurrencySymbol, PScriptContext, PTxInInfo, PTxInfo, PTxOut)
1616
import Plutarch.Extra.Interval (pcontains)
17-
import Plutarch.Extra.ScriptContext (ptryOwnInput)
17+
import Plutarch.Extra.ScriptContext (ptryOwnInput, ptxSignedBy)
1818
import Plutarch.Monadic qualified as P
1919

2020
--------------------------------------------------------------------------------
@@ -52,6 +52,7 @@ instance ToErrorCode PStandingBidError where
5252
StandingBid'Error'UnexpectedTokensMintedBurned ->
5353
pconstant "StandingBid02"
5454

55+
-- NewBid ----------------------------------------------------------------------
5556
data PStandingBid'NewBid'Error (s :: S)
5657
= StandingBid'NewBid'Error'MissingOwnOutput
5758
| StandingBid'NewBid'Error'OwnOutputMissingToken
@@ -78,6 +79,24 @@ instance ToErrorCode PStandingBid'NewBid'Error where
7879
StandingBid'NewBid'Error'IncorrectValidityInterval ->
7980
pconstant "StandingBid_NewBid_05"
8081

82+
-- MoveToHydra -----------------------------------------------------------------
83+
data PStandingBid'MoveToHydra'Error (s :: S)
84+
= StandingBid'MoveToHydra'Error'MissingDelegateSignatures
85+
| StandingBid'MoveToHydra'Error'IncorrectValidityInterval
86+
deriving stock (Generic)
87+
deriving anyclass (PlutusType)
88+
89+
instance DerivePlutusType PStandingBid'MoveToHydra'Error where
90+
type DPTStrat _ = PlutusTypeScott
91+
92+
instance ToErrorCode PStandingBid'MoveToHydra'Error where
93+
toErrorCode = phoistAcyclic $
94+
plam $ \err -> pmatch err $ \case
95+
StandingBid'MoveToHydra'Error'MissingDelegateSignatures ->
96+
pconstant "StandingBid_MoveToHydra_01"
97+
StandingBid'MoveToHydra'Error'IncorrectValidityInterval ->
98+
pconstant "StandingBid_MoveToHydra_02"
99+
81100
--------------------------------------------------------------------------------
82101
-- Validator
83102
--------------------------------------------------------------------------------
@@ -112,7 +131,7 @@ standingBidValidator = phoistAcyclic $
112131
NewBidRedeemer _ ->
113132
pcheckNewBid # txInfo # auctionCs # auctionTerms # ownInput # oldBidState
114133
MoveToHydraRedeemer _ ->
115-
pcheckMoveToHydra
134+
pcheckMoveToHydra # txInfo # auctionTerms
116135
ConcludeAuctionRedeemer _ ->
117136
pcheckConcludeAuction
118137

@@ -172,8 +191,23 @@ pcheckNewBid = phoistAcyclic $
172191
-- MoveToHydra
173192
--------------------------------------------------------------------------------
174193

175-
pcheckMoveToHydra :: Term s PUnit
176-
pcheckMoveToHydra = undefined
194+
pcheckMoveToHydra :: Term s (PTxInfo :--> PAuctionTerms :--> PUnit)
195+
pcheckMoveToHydra = phoistAcyclic $
196+
plam $ \txInfo auctionTerms -> P.do
197+
txInfoFields <- pletFields @["signatories", "validRange"] txInfo
198+
199+
-- (StandingBid_MoveToHydra_01)
200+
-- The transaction should be signed by all the delegates.
201+
delegates <- plet $ pfield @"delegates" # auctionTerms
202+
err StandingBid'MoveToHydra'Error'MissingDelegateSignatures $
203+
pall # plam (\sig -> ptxSignedBy # txInfoFields.signatories # sig) # delegates
204+
205+
-- (StandingBid_MoveToHydra_02)
206+
-- The transaction validity should end before the bidding end time.
207+
err StandingBid'MoveToHydra'Error'IncorrectValidityInterval $
208+
pcontains # (pbiddingPeriod # auctionTerms) # txInfoFields.validRange
209+
210+
pcon PUnit
177211

178212
--------------------------------------------------------------------------------
179213
-- ConcludeAuction

0 commit comments

Comments
 (0)