Skip to content

Commit bd5d5f1

Browse files
committed
feat(auction_escrow): implement SellerReclaims sub-validator
1 parent 31262fa commit bd5d5f1

File tree

3 files changed

+122
-4
lines changed

3 files changed

+122
-4
lines changed

src/HydraAuctionOnchain/Errors/AuctionEscrow.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ data PAuctionEscrowError (s :: S)
3838
| AuctionEscrow'BidderBuys'Error'NoBidderConsent
3939
| AuctionEscrow'BidderBuys'Error'SellerPaymentIncorrect
4040
| AuctionEscrow'BidderBuys'Error'PaymentToFeeEscrowIncorrect
41+
| -- SellerReclaims errors
42+
AuctionEscrow'SellerReclaims'Error'UnexpectedTokensMintedBurned
43+
| AuctionEscrow'SellerReclaims'Error'IncorrectValidityInterval
44+
| AuctionEscrow'SellerReclaims'Error'MissingAuctionEscrowOutput
45+
| AuctionEscrow'SellerReclaims'Error'AuctionEscrowOutputMissingAuctionEscrowToken
46+
| AuctionEscrow'SellerReclaims'Error'AuctionEscrowOutputMissingStandingBidToken
47+
| AuctionEscrow'SellerReclaims'Error'FailedToDecodeAuctionEscrowState
48+
| AuctionEscrow'SellerReclaims'Error'InvalidAuctionStateTransition
49+
| AuctionEscrow'SellerReclaims'Error'PaymentToSellerIncorrect
50+
| AuctionEscrow'SellerReclaims'Error'NoSellerConsent
51+
| AuctionEscrow'SellerReclaims'Error'PaymentToFeeEscrowIncorrect
4152
deriving stock (Generic, Eq)
4253
deriving anyclass (PlutusType)
4354

src/HydraAuctionOnchain/Types/AuctionTerms.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module HydraAuctionOnchain.Types.AuctionTerms
22
( PAuctionTerms (PAuctionTerms)
33
, pbiddingPeriod
4+
, ppenaltyPeriod
45
, ppurchasePeriod
56
, ptotalAuctionFees
67
) where
@@ -74,3 +75,11 @@ ppurchasePeriod = phoistAcyclic $
7475
pintervalFiniteClosedOpen
7576
# auctionTermsFields.biddingEnd
7677
# auctionTermsFields.purchaseDeadline
78+
79+
ppenaltyPeriod :: Term s (PAuctionTerms :--> PPOSIXTimeRange)
80+
ppenaltyPeriod = phoistAcyclic $
81+
plam $ \auctionTerms -> P.do
82+
auctionTermsFields <- pletFields @["purchaseDeadline", "cleanup"] auctionTerms
83+
pintervalFiniteClosedOpen
84+
# auctionTermsFields.purchaseDeadline
85+
# auctionTermsFields.cleanup

src/HydraAuctionOnchain/Validators/AuctionEscrow.hs

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import HydraAuctionOnchain.Types.AuctionEscrowState
3333
import HydraAuctionOnchain.Types.AuctionTerms
3434
( PAuctionTerms
3535
, pbiddingPeriod
36+
, ppenaltyPeriod
3637
, ppurchasePeriod
3738
, ptotalAuctionFees
3839
)
@@ -127,7 +128,13 @@ auctionEscrowValidator = phoistAcyclic $
127128
# oldAuctionState
128129
# ownAddress
129130
SellerReclaimsRedeemer _ ->
130-
undefined
131+
pcheckSellerReclaims
132+
# feeEscrowSh
133+
# txInfo
134+
# auctionCs
135+
# auctionTerms
136+
# oldAuctionState
137+
# ownAddress
131138
CleanupAuctionRedeemer _ ->
132139
undefined
133140

@@ -332,9 +339,7 @@ pcheckBidderBuys = phoistAcyclic $
332339
passert $(errCode AuctionEscrow'BidderBuys'Error'AuctionLotNotPaidToBidder) $
333340
auctionTermsFields.auctionLot #<= pvaluePaidTo # txInfo # bidderPkh
334341

335-
-- (AUES26) The bidder deposit's bidder consents to the
336-
-- transcation either explictly by signing the transaction or
337-
-- implicitly by receiving the bid deposit ADA.
342+
-- (AUES26) The bidder signed the transaction.
338343
passert $(errCode AuctionEscrow'BidderBuys'Error'NoBidderConsent) $
339344
ptxSignedBy # txInfoFields.signatories # pdata bidderPkh
340345

@@ -358,3 +363,96 @@ pcheckBidderBuys = phoistAcyclic $
358363
#<= (plovelaceValueOf #$ pvaluePaidToScript # txInfo # feeEscrowSh)
359364

360365
pcon PUnit
366+
367+
--------------------------------------------------------------------------------
368+
-- SellerReclaims
369+
--------------------------------------------------------------------------------
370+
371+
pcheckSellerReclaims
372+
:: Term
373+
s
374+
( PScriptHash
375+
:--> PTxInfo
376+
:--> PCurrencySymbol
377+
:--> PAuctionTerms
378+
:--> PAuctionEscrowState
379+
:--> PAddress
380+
:--> PUnit
381+
)
382+
pcheckSellerReclaims = phoistAcyclic $
383+
plam $ \feeEscrowSh txInfo auctionCs auctionTerms oldAuctionState ownAddress -> P.do
384+
txInfoFields <- pletFields @["mint", "signatories", "validRange"] txInfo
385+
auctionTermsFields <- pletFields @["auctionLot", "sellerPkh"] auctionTerms
386+
let sellerPkh = auctionTermsFields.sellerPkh
387+
388+
-- (AUES29) There should be no tokens minted or burned.
389+
passert $(errCode AuctionEscrow'SellerReclaims'Error'UnexpectedTokensMintedBurned) $
390+
pfromData txInfoFields.mint #== mempty
391+
392+
-- (AUES30) This redeemer can only be used during
393+
-- the penalty period.
394+
passert $(errCode AuctionEscrow'SellerReclaims'Error'IncorrectValidityInterval) $
395+
pcontains # (ppenaltyPeriod # auctionTerms) # txInfoFields.validRange
396+
397+
----------------------------------------------------------------------------
398+
-- Check auction escrow state transition
399+
----------------------------------------------------------------------------
400+
401+
-- (AUES31) There should be exactly one auction escrow output.
402+
ownOutput <-
403+
plet $
404+
passertMaybe
405+
$(errCode AuctionEscrow'SellerReclaims'Error'MissingAuctionEscrowOutput)
406+
(pfindUniqueOutputWithAddress # ownAddress # txInfo)
407+
408+
-- (AUES32) The auction escrow output should contain
409+
-- the auction escrow token.
410+
passert
411+
$(errCode AuctionEscrow'SellerReclaims'Error'AuctionEscrowOutputMissingAuctionEscrowToken)
412+
(ptxOutContainsAuctionEscrowToken # auctionCs # ownOutput)
413+
414+
-- (AUES33) The auction escrow output should contain
415+
-- the standing bid token.
416+
passert
417+
$(errCode AuctionEscrow'SellerReclaims'Error'AuctionEscrowOutputMissingStandingBidToken)
418+
(ptxOutContainsStandingBidToken # auctionCs # ownOutput)
419+
420+
-- (AUES34) The auction escrow output's datum should be decodable
421+
-- as an auction escrow state.
422+
newAuctionState <-
423+
plet $
424+
passertMaybe
425+
$(errCode AuctionEscrow'SellerReclaims'Error'FailedToDecodeAuctionEscrowState)
426+
(pdecodeInlineDatum # ownOutput)
427+
428+
-- (AUES35) The auction state should transition from
429+
-- `BiddingStarted` to `AuctionConcluded`.
430+
passert $(errCode AuctionEscrow'SellerReclaims'Error'InvalidAuctionStateTransition) $
431+
pvalidateAuctionEscrowTransitionToAuctionConcluded
432+
# oldAuctionState
433+
# newAuctionState
434+
435+
----------------------------------------------------------------------------
436+
-- Check auction lot transfer back to the seller
437+
----------------------------------------------------------------------------
438+
439+
-- (AUES36) The auction lot is returned to the seller.
440+
passert $(errCode AuctionEscrow'SellerReclaims'Error'PaymentToSellerIncorrect) $
441+
auctionTermsFields.auctionLot
442+
#<= (pvaluePaidTo # txInfo # sellerPkh)
443+
444+
-- (AUES37) The seller signed the transaction.
445+
passert $(errCode AuctionEscrow'SellerReclaims'Error'NoSellerConsent) $
446+
ptxSignedBy # txInfoFields.signatories # pdata sellerPkh
447+
448+
----------------------------------------------------------------------------
449+
-- Check auction fees
450+
----------------------------------------------------------------------------
451+
452+
-- (AUES38) The total auction fees are sent to
453+
-- the fee escrow validator.
454+
passert $(errCode AuctionEscrow'SellerReclaims'Error'PaymentToFeeEscrowIncorrect) $
455+
(ptotalAuctionFees # auctionTerms)
456+
#<= (plovelaceValueOf #$ pvaluePaidToScript # txInfo # feeEscrowSh)
457+
458+
pcon PUnit

0 commit comments

Comments
 (0)