@@ -21,7 +21,11 @@ import HydraAuctionOnchain.Helpers
21
21
)
22
22
import HydraAuctionOnchain.Lib.Address (paddrPaymentKeyHash )
23
23
import HydraAuctionOnchain.Lib.ScriptContext (pinputSpentWithRedeemer )
24
- import HydraAuctionOnchain.Types.AuctionTerms (PAuctionTerms , ppostBiddingPeriod )
24
+ import HydraAuctionOnchain.Types.AuctionTerms
25
+ ( PAuctionTerms
26
+ , pcleanupPeriod
27
+ , ppostBiddingPeriod
28
+ )
25
29
import HydraAuctionOnchain.Types.BidderInfo (PBidderInfo )
26
30
import HydraAuctionOnchain.Types.Error (errCode , passert , passertMaybe )
27
31
import HydraAuctionOnchain.Types.StandingBidState (PStandingBidState , pbidderLost , pbidderWon )
@@ -104,6 +108,11 @@ bidderDepositValidator = phoistAcyclic $
104
108
# auctionCs
105
109
# auctionTerms
106
110
# bidderInfo
111
+ DepositCleanupRedeemer _ ->
112
+ pcheckDepositCleanup
113
+ # txInfo
114
+ # auctionTerms
115
+ # bidderInfo
107
116
_ -> undefined
108
117
109
118
----------------------------------------------------------------------
@@ -233,3 +242,32 @@ pcheckReclaimDepositLoser = phoistAcyclic $
233
242
ptxSignedBy # txInfoFields. signatories # pdata bidderPkh
234
243
235
244
pcon PUnit
245
+
246
+ ----------------------------------------------------------------------
247
+ -- DepositCleanup
248
+ --
249
+ -- If, for whatever reason, there are bidder deposits left during
250
+ -- the cleanup period, then whoever placed a deposit can freely
251
+ -- reclaim it.
252
+
253
+ pcheckDepositCleanup :: Term s (PTxInfo :--> PAuctionTerms :--> PBidderInfo :--> PUnit )
254
+ pcheckDepositCleanup = phoistAcyclic $
255
+ plam $ \ txInfo auctionTerms bidderInfo -> P. do
256
+ txInfoFields <- pletFields @ [" signatories" , " validRange" ] txInfo
257
+
258
+ -- This redeemer can only be used during the cleanup period.
259
+ passert $ (errCode BidderDeposit'DepositCleanup'Error'IncorrectValidityInterval ) $
260
+ pcontains # (pcleanupPeriod # auctionTerms) # txInfoFields. validRange
261
+
262
+ -- The payment part of the bidder address should be pkh.
263
+ bidderPkh <-
264
+ plet $
265
+ passertMaybe
266
+ $ (errCode BidderDeposit'DepositCleanup'Error'InvalidBidderAddress )
267
+ (paddrPaymentKeyHash #$ pfield @ " biBidderAddress" # bidderInfo)
268
+
269
+ -- The bidder deposit's bidder signed the transaction.
270
+ passert $ (errCode BidderDeposit'DepositCleanup'Error'NoBidderConsent ) $
271
+ ptxSignedBy # txInfoFields. signatories # pdata bidderPkh
272
+
273
+ pcon PUnit
0 commit comments