3
3
module HydraAuctionOnchain.Validators.BidderDeposit
4
4
( PBidderDepositRedeemer
5
5
( UseDepositWinnerRedeemer
6
- , DepositReclaimedByLoserRedeemer
6
+ , ReclaimDepositLoserRedeemer
7
7
, DepositReclaimedAuctionConcludedRedeemer
8
8
, DepositCleanupRedeemer
9
9
)
@@ -14,14 +14,17 @@ import HydraAuctionOnchain.Errors.Validators.BidderDeposit (PBidderDepositError
14
14
import HydraAuctionOnchain.Helpers
15
15
( pdecodeInlineDatum
16
16
, pfindUniqueInputWithScriptHash
17
+ , pfindUniqueRefInputWithScriptHash
17
18
, pgetOwnInput
18
19
, ponlyOneInputFromAddress
19
20
, putxoAddress
20
21
)
22
+ import HydraAuctionOnchain.Lib.Address (paddrPaymentKeyHash )
21
23
import HydraAuctionOnchain.Lib.ScriptContext (pinputSpentWithRedeemer )
24
+ import HydraAuctionOnchain.Types.AuctionTerms (PAuctionTerms , ppostBiddingPeriod )
22
25
import HydraAuctionOnchain.Types.BidderInfo (PBidderInfo )
23
26
import HydraAuctionOnchain.Types.Error (errCode , passert , passertMaybe )
24
- import HydraAuctionOnchain.Types.StandingBidState (PStandingBidState , pbidderWon )
27
+ import HydraAuctionOnchain.Types.StandingBidState (PStandingBidState , pbidderLost , pbidderWon )
25
28
import HydraAuctionOnchain.Types.Tokens
26
29
( ptxOutContainsAuctionEscrowToken
27
30
, ptxOutContainsStandingBidToken
@@ -30,14 +33,16 @@ import HydraAuctionOnchain.Validators.AuctionEscrow
30
33
( PAuctionEscrowRedeemer (BidderBuysRedeemer )
31
34
)
32
35
import Plutarch.Api.V2 (PCurrencySymbol , PScriptContext , PScriptHash , PTxInfo )
36
+ import Plutarch.Extra.Interval (pcontains )
37
+ import Plutarch.Extra.ScriptContext (ptxSignedBy )
33
38
import Plutarch.Monadic qualified as P
34
39
35
40
----------------------------------------------------------------------
36
41
-- Redeemers
37
42
38
43
data PBidderDepositRedeemer (s :: S )
39
44
= UseDepositWinnerRedeemer (Term s (PDataRecord '[] ))
40
- | DepositReclaimedByLoserRedeemer (Term s (PDataRecord '[] ))
45
+ | ReclaimDepositLoserRedeemer (Term s (PDataRecord '[] ))
41
46
| DepositReclaimedAuctionConcludedRedeemer (Term s (PDataRecord '[] ))
42
47
| DepositCleanupRedeemer (Term s (PDataRecord '[] ))
43
48
deriving stock (Generic )
@@ -57,13 +62,14 @@ bidderDepositValidator
57
62
( PScriptHash
58
63
:--> PScriptHash
59
64
:--> PCurrencySymbol
65
+ :--> PAuctionTerms
60
66
:--> PBidderInfo
61
67
:--> PBidderDepositRedeemer
62
68
:--> PScriptContext
63
69
:--> PUnit
64
70
)
65
71
bidderDepositValidator = phoistAcyclic $
66
- plam $ \ standingBidSh auctionEscrowSh auctionCs bidderInfo redeemer ctx -> P. do
72
+ plam $ \ standingBidSh auctionEscrowSh auctionCs auctionTerms bidderInfo redeemer ctx -> P. do
67
73
txInfo <- plet $ pfield @ " txInfo" # ctx
68
74
69
75
-- The validator's own input should exist.
@@ -91,8 +97,21 @@ bidderDepositValidator = phoistAcyclic $
91
97
# auctionEscrowSh
92
98
# auctionCs
93
99
# bidderInfo
100
+ ReclaimDepositLoserRedeemer _ ->
101
+ pcheckReclaimDepositLoser
102
+ # txInfo
103
+ # standingBidSh
104
+ # auctionCs
105
+ # auctionTerms
106
+ # bidderInfo
94
107
_ -> undefined
95
108
109
+ ----------------------------------------------------------------------
110
+ -- UseDepositWinner
111
+ --
112
+ -- Deposit is used by the bidder who won the auction to buy
113
+ -- the auction lot.
114
+
96
115
pcheckUseDepositWinner
97
116
:: Term
98
117
s
@@ -152,3 +171,65 @@ pcheckUseDepositWinner = phoistAcyclic $
152
171
# auctionEscrowInput
153
172
154
173
pcon PUnit
174
+
175
+ ----------------------------------------------------------------------
176
+ -- ReclaimDepositLoser
177
+ --
178
+ -- The bidder deposit is reclaimed by a bidder that did not win
179
+ -- the auction.
180
+
181
+ pcheckReclaimDepositLoser
182
+ :: Term
183
+ s
184
+ ( PTxInfo
185
+ :--> PScriptHash
186
+ :--> PCurrencySymbol
187
+ :--> PAuctionTerms
188
+ :--> PBidderInfo
189
+ :--> PUnit
190
+ )
191
+ pcheckReclaimDepositLoser = phoistAcyclic $
192
+ plam $ \ txInfo standingBidSh auctionCs auctionTerms bidderInfo -> P. do
193
+ txInfoFields <- pletFields @ [" signatories" , " validRange" ] txInfo
194
+
195
+ -- There should be exactly one standing bid reference input.
196
+ standingBidInput <-
197
+ plet $
198
+ passertMaybe
199
+ $ (errCode BidderDeposit'ReclaimDepositLoser'Error'MissingStandingBidInput )
200
+ (pfindUniqueRefInputWithScriptHash # standingBidSh # txInfo)
201
+
202
+ -- The standing bid reference input should contain the standing
203
+ -- bid token.
204
+ standingBidInputResolved <- plet $ pfield @ " resolved" # standingBidInput
205
+ passert $ (errCode BidderDeposit'ReclaimDepositLoser'Error'StandingBidInputMissingToken ) $
206
+ ptxOutContainsStandingBidToken # auctionCs # standingBidInputResolved
207
+
208
+ -- The standing bid input contains a datum that can be decoded
209
+ -- as a standing bid state.
210
+ bidState <-
211
+ plet $
212
+ passertMaybe
213
+ $ (errCode BidderDeposit'ReclaimDepositLoser'Error'FailedToDecodeStandingBidState )
214
+ (pdecodeInlineDatum @ PStandingBidState # standingBidInputResolved)
215
+
216
+ -- The bidder deposit's bidder lost the auction.
217
+ passert $ (errCode BidderDeposit'ReclaimDepositLoser'Error'BidderNotLoser ) $
218
+ pbidderLost # bidState # bidderInfo
219
+
220
+ -- This redeemer can only be used after the bidding period.
221
+ passert $ (errCode BidderDeposit'ReclaimDepositLoser'Error'IncorrectValidityInterval ) $
222
+ pcontains # (ppostBiddingPeriod # auctionTerms) # txInfoFields. validRange
223
+
224
+ -- The payment part of the bidder address should be pkh.
225
+ bidderPkh <-
226
+ plet $
227
+ passertMaybe
228
+ $ (errCode BidderDeposit'ReclaimDepositLoser'Error'InvalidBidderAddress )
229
+ (paddrPaymentKeyHash #$ pfield @ " biBidderAddress" # bidderInfo)
230
+
231
+ -- The bidder deposit's bidder signed the transaction.
232
+ passert $ (errCode BidderDeposit'ReclaimDepositLoser'Error'NoBidderConsent ) $
233
+ ptxSignedBy # txInfoFields. signatories # pdata bidderPkh
234
+
235
+ pcon PUnit
0 commit comments