@@ -4,8 +4,8 @@ module HydraAuctionOnchain.Validators.BidderDeposit
4
4
( PBidderDepositRedeemer
5
5
( UseDepositWinnerRedeemer
6
6
, ReclaimDepositLoserRedeemer
7
- , DepositReclaimedAuctionConcludedRedeemer
8
- , DepositCleanupRedeemer
7
+ , ReclaimDepositAuctionConcludedRedeemer
8
+ , ReclaimDepositCleanupRedeemer
9
9
)
10
10
, bidderDepositValidator
11
11
) where
@@ -21,6 +21,7 @@ import HydraAuctionOnchain.Helpers
21
21
)
22
22
import HydraAuctionOnchain.Lib.Address (paddrPaymentKeyHash )
23
23
import HydraAuctionOnchain.Lib.ScriptContext (pinputSpentWithRedeemer )
24
+ import HydraAuctionOnchain.Types.AuctionEscrowState (PAuctionEscrowState (AuctionConcluded ))
24
25
import HydraAuctionOnchain.Types.AuctionTerms
25
26
( PAuctionTerms
26
27
, pcleanupPeriod
@@ -47,8 +48,8 @@ import Plutarch.Monadic qualified as P
47
48
data PBidderDepositRedeemer (s :: S )
48
49
= UseDepositWinnerRedeemer (Term s (PDataRecord '[] ))
49
50
| ReclaimDepositLoserRedeemer (Term s (PDataRecord '[] ))
50
- | DepositReclaimedAuctionConcludedRedeemer (Term s (PDataRecord '[] ))
51
- | DepositCleanupRedeemer (Term s (PDataRecord '[] ))
51
+ | ReclaimDepositAuctionConcludedRedeemer (Term s (PDataRecord '[] ))
52
+ | ReclaimDepositCleanupRedeemer (Term s (PDataRecord '[] ))
52
53
deriving stock (Generic )
53
54
deriving anyclass (PlutusType , PIsData , PShow , PEq )
54
55
@@ -108,12 +109,18 @@ bidderDepositValidator = phoistAcyclic $
108
109
# auctionCs
109
110
# auctionTerms
110
111
# bidderInfo
111
- DepositCleanupRedeemer _ ->
112
- pcheckDepositCleanup
112
+ ReclaimDepositAuctionConcludedRedeemer _ ->
113
+ pcheckReclaimDepositAuctionConcluded
114
+ # txInfo
115
+ # auctionEscrowSh
116
+ # auctionCs
117
+ # auctionTerms
118
+ # bidderInfo
119
+ ReclaimDepositCleanupRedeemer _ ->
120
+ pcheckReclaimDepositCleanup
113
121
# txInfo
114
122
# auctionTerms
115
123
# bidderInfo
116
- _ -> undefined
117
124
118
125
----------------------------------------------------------------------
119
126
-- UseDepositWinner
@@ -152,7 +159,7 @@ pcheckUseDepositWinner = phoistAcyclic $
152
159
plet $
153
160
passertMaybe
154
161
$ (errCode BidderDeposit'UseDepositWinner'Error'FailedToDecodeStandingBidState )
155
- (pdecodeInlineDatum @ PStandingBidState # standingBidInputResolved)
162
+ (pdecodeInlineDatum # standingBidInputResolved)
156
163
157
164
-- The bidder deposit's bidder won the auction.
158
165
passert $ (errCode BidderDeposit'UseDepositWinner'Error'BidderNotWinner ) $
@@ -202,25 +209,25 @@ pcheckReclaimDepositLoser = phoistAcyclic $
202
209
txInfoFields <- pletFields @ [" signatories" , " validRange" ] txInfo
203
210
204
211
-- There should be exactly one standing bid reference input.
205
- standingBidInput <-
212
+ standingBidRefInput <-
206
213
plet $
207
214
passertMaybe
208
215
$ (errCode BidderDeposit'ReclaimDepositLoser'Error'MissingStandingBidInput )
209
216
(pfindUniqueRefInputWithScriptHash # standingBidSh # txInfo)
210
217
211
218
-- The standing bid reference input should contain the standing
212
219
-- bid token.
213
- standingBidInputResolved <- plet $ pfield @ " resolved" # standingBidInput
220
+ standingBidRefInputResolved <- plet $ pfield @ " resolved" # standingBidRefInput
214
221
passert $ (errCode BidderDeposit'ReclaimDepositLoser'Error'StandingBidInputMissingToken ) $
215
- ptxOutContainsStandingBidToken # auctionCs # standingBidInputResolved
222
+ ptxOutContainsStandingBidToken # auctionCs # standingBidRefInputResolved
216
223
217
224
-- The standing bid input contains a datum that can be decoded
218
225
-- as a standing bid state.
219
226
bidState <-
220
227
plet $
221
228
passertMaybe
222
229
$ (errCode BidderDeposit'ReclaimDepositLoser'Error'FailedToDecodeStandingBidState )
223
- (pdecodeInlineDatum @ PStandingBidState # standingBidInputResolved )
230
+ (pdecodeInlineDatum @ PStandingBidState # standingBidRefInputResolved )
224
231
225
232
-- The bidder deposit's bidder lost the auction.
226
233
passert $ (errCode BidderDeposit'ReclaimDepositLoser'Error'BidderNotLoser ) $
@@ -244,30 +251,97 @@ pcheckReclaimDepositLoser = phoistAcyclic $
244
251
pcon PUnit
245
252
246
253
----------------------------------------------------------------------
247
- -- DepositCleanup
254
+ -- ReclaimDepositAuctionConcluded
255
+ --
256
+ -- The bidder deposit is reclaimed by a bidder after the auction
257
+ -- conclusion. If the auction has concluded then the seller and the
258
+ -- winning bidder have already had an opportunity to claim
259
+ -- whichever deposits they are entitled to.
260
+
261
+ pcheckReclaimDepositAuctionConcluded
262
+ :: Term
263
+ s
264
+ ( PTxInfo
265
+ :--> PScriptHash
266
+ :--> PCurrencySymbol
267
+ :--> PAuctionTerms
268
+ :--> PBidderInfo
269
+ :--> PUnit
270
+ )
271
+ pcheckReclaimDepositAuctionConcluded = phoistAcyclic $
272
+ plam $ \ txInfo auctionEscrowSh auctionCs auctionTerms bidderInfo -> P. do
273
+ txInfoFields <- pletFields @ [" signatories" , " validRange" ] txInfo
274
+
275
+ -- There should be exactly one auction escrow reference input.
276
+ auctionEscrowRefInput <-
277
+ plet $
278
+ passertMaybe
279
+ $ (errCode BidderDeposit'ReclaimDepositConcluded'Error'MissingAuctionRefInput )
280
+ (pfindUniqueRefInputWithScriptHash # auctionEscrowSh # txInfo)
281
+
282
+ -- The auction escrow reference input should contain the auction
283
+ -- escrow token.
284
+ auctionEscrowRefInputResolved <- plet $ pfield @ " resolved" # auctionEscrowRefInput
285
+ passert $ (errCode BidderDeposit'ReclaimDepositConcluded'Error'AuctionRefInputMissingToken ) $
286
+ ptxOutContainsStandingBidToken # auctionCs # auctionEscrowRefInputResolved
287
+
288
+ -- The auction escrow input contains a datum that can be
289
+ -- decoded as an auction escrow state.
290
+ auctionState <-
291
+ plet $
292
+ passertMaybe
293
+ $ (errCode BidderDeposit'ReclaimDepositConcluded'Error'FailedToDecodeAuctionState )
294
+ (pdecodeInlineDatum # auctionEscrowRefInputResolved)
295
+
296
+ -- The auction is concluded.
297
+ passert $ (errCode BidderDeposit'ReclaimDepositConcluded'Error'AuctionNotConcluded ) $
298
+ auctionState #== pcon (AuctionConcluded pdnil)
299
+
300
+ -- This redeemer can only be used after the bidding period.
301
+ -- TODO: Remove this check? It is probably redundant since the
302
+ -- auction can only conclude after the bidding end time, which is
303
+ -- enforced by the auction escrow validator.
304
+ passert $ (errCode BidderDeposit'ReclaimDepositConcluded'Error'IncorrectValidityInterval ) $
305
+ pcontains # (ppostBiddingPeriod # auctionTerms) # txInfoFields. validRange
306
+
307
+ -- The payment part of the bidder address should be pkh.
308
+ bidderPkh <-
309
+ plet $
310
+ passertMaybe
311
+ $ (errCode BidderDeposit'ReclaimDepositConcluded'Error'InvalidBidderAddress )
312
+ (paddrPaymentKeyHash #$ pfield @ " biBidderAddress" # bidderInfo)
313
+
314
+ -- The bidder deposit's bidder signed the transaction.
315
+ passert $ (errCode BidderDeposit'ReclaimDepositConcluded'Error'NoBidderConsent ) $
316
+ ptxSignedBy # txInfoFields. signatories # pdata bidderPkh
317
+
318
+ pcon PUnit
319
+
320
+ ----------------------------------------------------------------------
321
+ -- ReclaimDepositCleanup
248
322
--
249
323
-- If, for whatever reason, there are bidder deposits left during
250
324
-- the cleanup period, then whoever placed a deposit can freely
251
325
-- reclaim it.
252
326
253
- pcheckDepositCleanup :: Term s (PTxInfo :--> PAuctionTerms :--> PBidderInfo :--> PUnit )
254
- pcheckDepositCleanup = phoistAcyclic $
327
+ pcheckReclaimDepositCleanup :: Term s (PTxInfo :--> PAuctionTerms :--> PBidderInfo :--> PUnit )
328
+ pcheckReclaimDepositCleanup = phoistAcyclic $
255
329
plam $ \ txInfo auctionTerms bidderInfo -> P. do
256
330
txInfoFields <- pletFields @ [" signatories" , " validRange" ] txInfo
257
331
258
332
-- This redeemer can only be used during the cleanup period.
259
- passert $ (errCode BidderDeposit'DepositCleanup 'Error'IncorrectValidityInterval ) $
333
+ passert $ (errCode BidderDeposit'ReclaimDepositCleanup 'Error'IncorrectValidityInterval ) $
260
334
pcontains # (pcleanupPeriod # auctionTerms) # txInfoFields. validRange
261
335
262
336
-- The payment part of the bidder address should be pkh.
263
337
bidderPkh <-
264
338
plet $
265
339
passertMaybe
266
- $ (errCode BidderDeposit'DepositCleanup 'Error'InvalidBidderAddress )
340
+ $ (errCode BidderDeposit'ReclaimDepositCleanup 'Error'InvalidBidderAddress )
267
341
(paddrPaymentKeyHash #$ pfield @ " biBidderAddress" # bidderInfo)
268
342
269
343
-- The bidder deposit's bidder signed the transaction.
270
- passert $ (errCode BidderDeposit'DepositCleanup 'Error'NoBidderConsent ) $
344
+ passert $ (errCode BidderDeposit'ReclaimDepositCleanup 'Error'NoBidderConsent ) $
271
345
ptxSignedBy # txInfoFields. signatories # pdata bidderPkh
272
346
273
347
pcon PUnit
0 commit comments