1
+ {-# LANGUAGE TemplateHaskell #-}
2
+
1
3
module HydraAuctionOnchain.Validators.StandingBid
2
4
( standingBidValidator
3
5
) where
4
6
7
+ import HydraAuctionOnchain.Errors.StandingBid (PStandingBidError (.. ))
5
8
import HydraAuctionOnchain.Helpers
6
9
( pdecodeInlineDatum
7
10
, pfindUniqueInputWithToken
@@ -13,7 +16,7 @@ import HydraAuctionOnchain.MintingPolicies.Auction
13
16
, standingBidTokenName
14
17
)
15
18
import HydraAuctionOnchain.Types.AuctionTerms (PAuctionTerms , pbiddingPeriod )
16
- import HydraAuctionOnchain.Types.Error (ToErrorCode ( toErrorCode ), err , perrMaybe )
19
+ import HydraAuctionOnchain.Types.Error (errCode , passert , passertMaybe )
17
20
import HydraAuctionOnchain.Types.StandingBidState (PStandingBidState , pvalidateNewBid )
18
21
import HydraAuctionOnchain.Validators.AuctionEscrow (pisConcluding )
19
22
import Plutarch.Api.V1.Value (pvalueOf )
@@ -44,90 +47,6 @@ data PStandingBidRedeemer (s :: S)
44
47
instance DerivePlutusType PStandingBidRedeemer where
45
48
type DPTStrat _ = PlutusTypeData
46
49
47
- --------------------------------------------------------------------------------
48
- -- Errors
49
- --------------------------------------------------------------------------------
50
-
51
- data PStandingBidError (s :: S )
52
- = StandingBid'Error'OwnInputMissingToken
53
- | StandingBid'Error'UnexpectedTokensMintedBurned
54
- deriving stock (Generic )
55
- deriving anyclass (PlutusType )
56
-
57
- instance DerivePlutusType PStandingBidError where
58
- type DPTStrat _ = PlutusTypeScott
59
-
60
- instance ToErrorCode PStandingBidError where
61
- toErrorCode = phoistAcyclic $
62
- plam $ \ err -> pmatch err $ \ case
63
- StandingBid'Error'OwnInputMissingToken ->
64
- pconstant " StandingBid01"
65
- StandingBid'Error'UnexpectedTokensMintedBurned ->
66
- pconstant " StandingBid02"
67
-
68
- -- NewBid ----------------------------------------------------------------------
69
- data PStandingBid'NewBid'Error (s :: S )
70
- = StandingBid'NewBid'Error'MissingOwnOutput
71
- | StandingBid'NewBid'Error'OwnOutputMissingToken
72
- | StandingBid'NewBid'Error'FailedToDecodeNewBid
73
- | StandingBid'NewBid'Error'InvalidNewBidState
74
- | StandingBid'NewBid'Error'IncorrectValidityInterval
75
- deriving stock (Generic )
76
- deriving anyclass (PlutusType )
77
-
78
- instance DerivePlutusType PStandingBid'NewBid'Error where
79
- type DPTStrat _ = PlutusTypeScott
80
-
81
- instance ToErrorCode PStandingBid'NewBid'Error where
82
- toErrorCode = phoistAcyclic $
83
- plam $ \ err -> pmatch err $ \ case
84
- StandingBid'NewBid'Error'MissingOwnOutput ->
85
- pconstant " StandingBid_NewBid_01"
86
- StandingBid'NewBid'Error'OwnOutputMissingToken ->
87
- pconstant " StandingBid_NewBid_02"
88
- StandingBid'NewBid'Error'FailedToDecodeNewBid ->
89
- pconstant " StandingBid_NewBid_03"
90
- StandingBid'NewBid'Error'InvalidNewBidState ->
91
- pconstant " StandingBid_NewBid_04"
92
- StandingBid'NewBid'Error'IncorrectValidityInterval ->
93
- pconstant " StandingBid_NewBid_05"
94
-
95
- -- MoveToHydra -----------------------------------------------------------------
96
- data PStandingBid'MoveToHydra'Error (s :: S )
97
- = StandingBid'MoveToHydra'Error'MissingDelegateSignatures
98
- | StandingBid'MoveToHydra'Error'IncorrectValidityInterval
99
- deriving stock (Generic )
100
- deriving anyclass (PlutusType )
101
-
102
- instance DerivePlutusType PStandingBid'MoveToHydra'Error where
103
- type DPTStrat _ = PlutusTypeScott
104
-
105
- instance ToErrorCode PStandingBid'MoveToHydra'Error where
106
- toErrorCode = phoistAcyclic $
107
- plam $ \ err -> pmatch err $ \ case
108
- StandingBid'MoveToHydra'Error'MissingDelegateSignatures ->
109
- pconstant " StandingBid_MoveToHydra_01"
110
- StandingBid'MoveToHydra'Error'IncorrectValidityInterval ->
111
- pconstant " StandingBid_MoveToHydra_02"
112
-
113
- -- ConcludeAuction -------------------------------------------------------------
114
- data PStandingBid'ConcludeAuction'Error (s :: S )
115
- = StandingBid'ConcludeAuction'Error'MissingAuctionEscrowInput
116
- | StandingBid'ConcludeAuction'Error'InvalidAuctionEscrowRedeemer
117
- deriving stock (Generic )
118
- deriving anyclass (PlutusType )
119
-
120
- instance DerivePlutusType PStandingBid'ConcludeAuction'Error where
121
- type DPTStrat _ = PlutusTypeScott
122
-
123
- instance ToErrorCode PStandingBid'ConcludeAuction'Error where
124
- toErrorCode = phoistAcyclic $
125
- plam $ \ err -> pmatch err $ \ case
126
- StandingBid'ConcludeAuction'Error'MissingAuctionEscrowInput ->
127
- pconstant " StandingBid_ConcludeAuction_01"
128
- StandingBid'ConcludeAuction'Error'InvalidAuctionEscrowRedeemer ->
129
- pconstant " StandingBid_ConcludeAuction_02"
130
-
131
50
--------------------------------------------------------------------------------
132
51
-- Validator
133
52
--------------------------------------------------------------------------------
@@ -147,15 +66,14 @@ standingBidValidator = phoistAcyclic $
147
66
ownInput <- plet $ ptryOwnInput # ctx
148
67
txInfo <- plet $ pfield @ " txInfo" # ctx
149
68
150
- -- (StandingBid01)
151
- -- The standing bid input should contain the standing bid token.
152
- err StandingBid'Error'OwnInputMissingToken $
69
+ -- (STBD0) The standing bid input should contain the standing
70
+ -- bid token.
71
+ passert $ (errCode StandingBid'Error'OwnInputMissingToken ) $
153
72
ptxOutContainsStandingBidToken # auctionCs #$ pfield @ " resolved" # ownInput
154
73
155
- -- (StandingBid02)
156
- -- There should be no tokens minted or burned.
74
+ -- (STBD1) There should be no tokens minted or burned.
157
75
mintValue <- plet $ pfield @ " mint" # txInfo
158
- err StandingBid'Error'UnexpectedTokensMintedBurned $
76
+ passert $ (errCode StandingBid'Error'UnexpectedTokensMintedBurned ) $
159
77
pfromData mintValue #== mempty
160
78
161
79
pmatch redeemer $ \ case
@@ -182,38 +100,35 @@ pcheckNewBid
182
100
)
183
101
pcheckNewBid = phoistAcyclic $
184
102
plam $ \ txInfo auctionCs auctionTerms ownInput oldBidState -> P. do
185
- -- (StandingBid_NewBid_01)
186
- -- The standing bid output should exist.
103
+ -- (STBD2) The standing bid output should exist.
187
104
ownOutput <-
188
105
plet $
189
- perrMaybe
190
- # pcon StandingBid'NewBid'Error'MissingOwnOutput
191
- # (pfindUniqueOutputWithAddress # (putxoAddress # ownInput) # txInfo)
106
+ passertMaybe
107
+ $ (errCode StandingBid'NewBid'Error'MissingOwnOutput )
108
+ (pfindUniqueOutputWithAddress # (putxoAddress # ownInput) # txInfo)
192
109
193
- -- (StandingBid_NewBid_02)
194
- -- The standing bid output should contain the standing bid token.
195
- err StandingBid'NewBid'Error'OwnOutputMissingToken $
110
+ -- (STBD3) The standing bid output should contain the standing
111
+ -- bid token.
112
+ passert $ (errCode StandingBid'NewBid'Error'OwnOutputMissingToken ) $
196
113
ptxOutContainsStandingBidToken # auctionCs # ownOutput
197
114
198
- -- (StandingBid_NewBid_03)
199
- -- The standing bid output's datum should be decodable
115
+ -- (STBD4) The standing bid output's datum should be decodable
200
116
-- as a standing bid state.
201
117
newBidState <-
202
118
plet $
203
- perrMaybe
204
- # pcon StandingBid'NewBid'Error'FailedToDecodeNewBid
205
- # (pdecodeInlineDatum # ownOutput)
119
+ passertMaybe
120
+ $ (errCode StandingBid'NewBid'Error'FailedToDecodeNewBid )
121
+ (pdecodeInlineDatum # ownOutput)
206
122
207
- -- (StandingBid_NewBid_04)
208
- -- The transition from the old bid state to the new bid state
209
- -- should be valid.
210
- err StandingBid'NewBid'Error'InvalidNewBidState $
123
+ -- (STBD5) The transition from the old bid state to the new
124
+ -- bid state should be valid.
125
+ passert $ (errCode StandingBid'NewBid'Error'InvalidNewBidState ) $
211
126
pvalidateNewBid # auctionCs # auctionTerms # oldBidState # newBidState
212
127
213
- -- (StandingBid_NewBid_05)
214
- -- The transaction validity should end before the bidding end time.
128
+ -- (STBD6) The transaction validity should end before the
129
+ -- bidding end time.
215
130
txInfoValidRange <- plet $ pfield @ " validRange" # txInfo
216
- err StandingBid'NewBid'Error'IncorrectValidityInterval $
131
+ passert $ (errCode StandingBid'NewBid'Error'IncorrectValidityInterval ) $
217
132
pcontains # (pbiddingPeriod # auctionTerms) # txInfoValidRange
218
133
219
134
pcon PUnit
@@ -227,15 +142,14 @@ pcheckMoveToHydra = phoistAcyclic $
227
142
plam $ \ txInfo auctionTerms -> P. do
228
143
txInfoFields <- pletFields @ [" signatories" , " validRange" ] txInfo
229
144
230
- -- (StandingBid_MoveToHydra_01)
231
- -- The transaction should be signed by all the delegates.
145
+ -- (STBD7) The transaction should be signed by all the delegates.
232
146
delegates <- plet $ pfield @ " delegates" # auctionTerms
233
- err StandingBid'MoveToHydra'Error'MissingDelegateSignatures $
147
+ passert $ (errCode StandingBid'MoveToHydra'Error'MissingDelegateSignatures ) $
234
148
pall # plam (\ sig -> ptxSignedBy # txInfoFields. signatories # sig) # delegates
235
149
236
- -- (StandingBid_MoveToHydra_02)
237
- -- The transaction validity should end before the bidding end time.
238
- err StandingBid'MoveToHydra'Error'IncorrectValidityInterval $
150
+ -- (STBD8) The transaction validity should end before the
151
+ -- bidding end time.
152
+ passert $ (errCode StandingBid'MoveToHydra'Error'IncorrectValidityInterval ) $
239
153
pcontains # (pbiddingPeriod # auctionTerms) # txInfoFields. validRange
240
154
241
155
pcon PUnit
@@ -247,24 +161,23 @@ pcheckMoveToHydra = phoistAcyclic $
247
161
pcheckConcludeAuction :: Term s (PTxInfo :--> PCurrencySymbol :--> PUnit )
248
162
pcheckConcludeAuction = phoistAcyclic $
249
163
plam $ \ txInfo auctionCs -> P. do
250
- -- (StandingBid_ConcludeAuction_01)
251
- -- There is an input that contains the auction escrow token.
164
+ -- (STBD9) There is an input that contains
165
+ -- the auction escrow token.
252
166
auctionEscrowUtxo <-
253
167
plet $
254
- perrMaybe
255
- # pcon StandingBid'ConcludeAuction'Error'MissingAuctionEscrowInput
256
- # (pfindUniqueInputWithToken # auctionCs # auctionEscrowTokenName # txInfo)
257
-
258
- -- (StandingBid_ConcludeAuction_02)
259
- -- The auction escrow input is being spent with the `BidderBuys` or
260
- -- `SellerReclaims` redeemer. Implicitly, this means that the auction is
261
- -- concluding with either the winning bidder buying the auction lot or the
262
- -- seller reclaiming it.
168
+ passertMaybe
169
+ $ (errCode StandingBid'ConcludeAuction'Error'MissingAuctionEscrowInput )
170
+ (pfindUniqueInputWithToken # auctionCs # auctionEscrowTokenName # txInfo)
171
+
172
+ -- (STBD10) The auction escrow input is being spent with the
173
+ -- `BidderBuys` or `SellerReclaims` redeemer. Implicitly, this
174
+ -- means that the auction is concluding with either the winning
175
+ -- bidder buying the auction lot or the seller reclaiming it.
263
176
redeemers <- plet $ pfield @ " redeemers" # txInfo
264
177
auctionEscrowOref <- plet $ pfield @ " outRef" # auctionEscrowUtxo
265
178
spendsAuctionEscrow <- plet $ pcon $ PSpending $ pdcons @ " _0" # auctionEscrowOref # pdnil
266
179
auctionEscrowRedeemer <- plet $ ptryFromRedeemer # spendsAuctionEscrow # redeemers
267
- err StandingBid'ConcludeAuction'Error'InvalidAuctionEscrowRedeemer $
180
+ passert $ (errCode StandingBid'ConcludeAuction'Error'InvalidAuctionEscrowRedeemer ) $
268
181
pmaybe
269
182
# pcon PFalse
270
183
# plam (\ redeemer -> pisConcluding # pfromData redeemer)
0 commit comments