3
3
module HydraAuctionOnchain.Validators.BidderDeposit
4
4
( PBidderDepositRedeemer
5
5
( UseDepositWinnerRedeemer
6
+ , ClaimDepositSellerRedeemer
6
7
, ReclaimDepositLoserRedeemer
7
8
, ReclaimDepositAuctionConcludedRedeemer
8
9
, ReclaimDepositCleanupRedeemer
@@ -26,6 +27,7 @@ import HydraAuctionOnchain.Types.AuctionTerms
26
27
( PAuctionTerms
27
28
, pcleanupPeriod
28
29
, ppostBiddingPeriod
30
+ , ppostPurchasePeriod
29
31
)
30
32
import HydraAuctionOnchain.Types.BidderInfo (PBidderInfo )
31
33
import HydraAuctionOnchain.Types.Error (errCode , passert , passertMaybe )
@@ -36,7 +38,7 @@ import HydraAuctionOnchain.Types.Tokens
36
38
, ptxOutContainsStandingBidToken
37
39
)
38
40
import HydraAuctionOnchain.Validators.AuctionEscrow
39
- ( PAuctionEscrowRedeemer (BidderBuysRedeemer )
41
+ ( PAuctionEscrowRedeemer (BidderBuysRedeemer , SellerReclaimsRedeemer )
40
42
)
41
43
import Plutarch.Api.V2 (PCurrencySymbol , PScriptContext , PTxInfo )
42
44
import Plutarch.Extra.Interval (pcontains )
@@ -48,6 +50,7 @@ import Plutarch.Monadic qualified as P
48
50
49
51
data PBidderDepositRedeemer (s :: S )
50
52
= UseDepositWinnerRedeemer (Term s (PDataRecord '[] ))
53
+ | ClaimDepositSellerRedeemer (Term s (PDataRecord '[] ))
51
54
| ReclaimDepositLoserRedeemer (Term s (PDataRecord '[] ))
52
55
| ReclaimDepositAuctionConcludedRedeemer (Term s (PDataRecord '[] ))
53
56
| ReclaimDepositCleanupRedeemer (Term s (PDataRecord '[] ))
@@ -103,6 +106,14 @@ bidderDepositValidator = phoistAcyclic $
103
106
# auctionEscrowSh
104
107
# auctionCs
105
108
# bidderInfo
109
+ ClaimDepositSellerRedeemer _ ->
110
+ pcheckClaimDepositSeller
111
+ # txInfo
112
+ # standingBidSh
113
+ # auctionEscrowSh
114
+ # auctionCs
115
+ # auctionTerms
116
+ # bidderInfo
106
117
ReclaimDepositLoserRedeemer _ ->
107
118
pcheckReclaimDepositLoser
108
119
# txInfo
@@ -189,6 +200,78 @@ pcheckUseDepositWinner = phoistAcyclic $
189
200
190
201
pcon PUnit
191
202
203
+ ----------------------------------------------------------------------
204
+ -- ClaimDepositSeller
205
+ --
206
+ -- The bidder deposit is claimed by the seller if the auction lot has
207
+ -- not been purchased before the purchase deadline.
208
+
209
+ pcheckClaimDepositSeller
210
+ :: Term
211
+ s
212
+ ( PTxInfo
213
+ :--> PStandingBidScriptHash
214
+ :--> PAuctionEscrowScriptHash
215
+ :--> PCurrencySymbol
216
+ :--> PAuctionTerms
217
+ :--> PBidderInfo
218
+ :--> PUnit
219
+ )
220
+ pcheckClaimDepositSeller = phoistAcyclic $
221
+ plam $ \ txInfo standingBidSh auctionEscrowSh auctionCs auctionTerms bidderInfo -> P. do
222
+ -- This redeemer can only be used after the purchase deadline.
223
+ validRange <- plet $ pfield @ " validRange" # txInfo
224
+ passert $ (errCode BidderDeposit'ClaimDepositSeller'Error'IncorrectValidityInterval ) $
225
+ pcontains # (ppostPurchasePeriod # auctionTerms) # validRange
226
+
227
+ -- There should be exactly one standing bid input.
228
+ standingBidInput <-
229
+ plet $
230
+ passertMaybe
231
+ $ (errCode BidderDeposit'ClaimDepositSeller'Error'MissingStandingBidInput )
232
+ (pfindUniqueInputWithScriptHash # pto standingBidSh # txInfo)
233
+
234
+ -- The standing bid input should contain the standing
235
+ -- bid token.
236
+ standingBidInputResolved <- plet $ pfield @ " resolved" # standingBidInput
237
+ passert $ (errCode BidderDeposit'ClaimDepositSeller'Error'StandingBidInputMissingToken ) $
238
+ ptxOutContainsStandingBidToken # auctionCs # standingBidInputResolved
239
+
240
+ -- The standing bid input contains a datum that can be decoded
241
+ -- as a standing bid state.
242
+ bidState <-
243
+ plet $
244
+ passertMaybe
245
+ $ (errCode BidderDeposit'ClaimDepositSeller'Error'FailedToDecodeStandingBidState )
246
+ (pdecodeInlineDatum # standingBidInputResolved)
247
+
248
+ -- The bidder deposit's bidder won the auction.
249
+ passert $ (errCode BidderDeposit'ClaimDepositSeller'Error'BidderNotWinner ) $
250
+ pbidderWon # bidState # bidderInfo
251
+
252
+ -- There should be exactly one auction escrow input.
253
+ auctionEscrowInput <-
254
+ plet $
255
+ passertMaybe
256
+ $ (errCode BidderDeposit'ClaimDepositSeller'Error'MissingAuctionEscrowInput )
257
+ (pfindUniqueInputWithScriptHash # pto auctionEscrowSh # txInfo)
258
+
259
+ -- The auction escrow input should contain the auction
260
+ -- escrow token.
261
+ auctionEscrowInputResolved <- plet $ pfield @ " resolved" # auctionEscrowInput
262
+ passert $ (errCode BidderDeposit'ClaimDepositSeller'Error'AuctionEscrowInputMissingToken ) $
263
+ ptxOutContainsAuctionEscrowToken # auctionCs # auctionEscrowInputResolved
264
+
265
+ -- The auction escrow input is being spent with
266
+ -- the `SellerReclaims` redeemer.
267
+ passert $ (errCode BidderDeposit'ClaimDepositSeller'Error'InvalidAuctionEscrowRedeemer ) $
268
+ pinputSpentWithRedeemer
269
+ # plam (\ redeemer -> redeemer #== pcon (SellerReclaimsRedeemer pdnil))
270
+ # txInfo
271
+ # auctionEscrowInput
272
+
273
+ pcon PUnit
274
+
192
275
----------------------------------------------------------------------
193
276
-- ReclaimDepositLoser
194
277
--
0 commit comments