@@ -4,17 +4,30 @@ module HydraAuctionOnchain.Validators.StandingBid
4
4
5
5
import HydraAuctionOnchain.Helpers
6
6
( pdecodeInlineDatum
7
+ , pfindUniqueInputWithToken
7
8
, pfindUniqueOutputWithAddress
8
9
, putxoAddress
9
10
)
10
- import HydraAuctionOnchain.MintingPolicies.Auction (standingBidTokenName )
11
+ import HydraAuctionOnchain.MintingPolicies.Auction
12
+ ( auctionEscrowTokenName
13
+ , standingBidTokenName
14
+ )
11
15
import HydraAuctionOnchain.Types.AuctionTerms (PAuctionTerms , pbiddingPeriod )
12
16
import HydraAuctionOnchain.Types.Error (ToErrorCode (toErrorCode ), err , perrMaybe )
13
17
import HydraAuctionOnchain.Types.StandingBidState (PStandingBidState , pvalidateNewBid )
18
+ import HydraAuctionOnchain.Validators.AuctionEscrow (pisConcluding )
14
19
import Plutarch.Api.V1.Value (pvalueOf )
15
- import Plutarch.Api.V2 (PCurrencySymbol , PScriptContext , PTxInInfo , PTxInfo , PTxOut )
20
+ import Plutarch.Api.V2
21
+ ( PCurrencySymbol
22
+ , PScriptContext
23
+ , PScriptPurpose (PSpending )
24
+ , PTxInInfo
25
+ , PTxInfo
26
+ , PTxOut
27
+ )
16
28
import Plutarch.Extra.Interval (pcontains )
17
- import Plutarch.Extra.ScriptContext (ptryOwnInput , ptxSignedBy )
29
+ import Plutarch.Extra.Maybe (pmaybe )
30
+ import Plutarch.Extra.ScriptContext (ptryFromRedeemer , ptryOwnInput , ptxSignedBy )
18
31
import Plutarch.Monadic qualified as P
19
32
20
33
--------------------------------------------------------------------------------
@@ -97,6 +110,24 @@ instance ToErrorCode PStandingBid'MoveToHydra'Error where
97
110
StandingBid'MoveToHydra'Error'IncorrectValidityInterval ->
98
111
pconstant " StandingBid_MoveToHydra_02"
99
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
+
100
131
--------------------------------------------------------------------------------
101
132
-- Validator
102
133
--------------------------------------------------------------------------------
@@ -133,7 +164,7 @@ standingBidValidator = phoistAcyclic $
133
164
MoveToHydraRedeemer _ ->
134
165
pcheckMoveToHydra # txInfo # auctionTerms
135
166
ConcludeAuctionRedeemer _ ->
136
- pcheckConcludeAuction
167
+ pcheckConcludeAuction # txInfo # auctionCs
137
168
138
169
--------------------------------------------------------------------------------
139
170
-- NewBid
@@ -213,8 +244,33 @@ pcheckMoveToHydra = phoistAcyclic $
213
244
-- ConcludeAuction
214
245
--------------------------------------------------------------------------------
215
246
216
- pcheckConcludeAuction :: Term s PUnit
217
- pcheckConcludeAuction = undefined
247
+ pcheckConcludeAuction :: Term s (PTxInfo :--> PCurrencySymbol :--> PUnit )
248
+ pcheckConcludeAuction = phoistAcyclic $
249
+ plam $ \ txInfo auctionCs -> P. do
250
+ -- (StandingBid_ConcludeAuction_01)
251
+ -- There is an input that contains the auction escrow token.
252
+ auctionEscrowUtxo <-
253
+ 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.
263
+ redeemers <- plet $ pfield @ " redeemers" # txInfo
264
+ auctionEscrowOref <- plet $ pfield @ " outRef" # auctionEscrowUtxo
265
+ spendsAuctionEscrow <- plet $ pcon $ PSpending $ pdcons @ " _0" # auctionEscrowOref # pdnil
266
+ auctionEscrowRedeemer <- plet $ ptryFromRedeemer # spendsAuctionEscrow # redeemers
267
+ err StandingBid'ConcludeAuction'Error'InvalidAuctionEscrowRedeemer $
268
+ pmaybe
269
+ # pcon PFalse
270
+ # plam (\ redeemer -> pisConcluding # pfromData redeemer)
271
+ # auctionEscrowRedeemer
272
+
273
+ pcon PUnit
218
274
219
275
--------------------------------------------------------------------------------
220
276
-- Helpers
0 commit comments