Skip to content

Commit 215288c

Browse files
committed
feat(auction_escrow): implement CleanupAuction sub-validator
1 parent bd5d5f1 commit 215288c

File tree

4 files changed

+94
-6
lines changed

4 files changed

+94
-6
lines changed

src/HydraAuctionOnchain/Errors/AuctionEscrow.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ data PAuctionEscrowError (s :: S)
4949
| AuctionEscrow'SellerReclaims'Error'PaymentToSellerIncorrect
5050
| AuctionEscrow'SellerReclaims'Error'NoSellerConsent
5151
| AuctionEscrow'SellerReclaims'Error'PaymentToFeeEscrowIncorrect
52+
| -- CleanupAuction errors
53+
AuctionEscrow'CleanupAuction'Error'AuctionTokensNotBurnedExactly
54+
| AuctionEscrow'CleanupAuction'Error'IncorrectValidityInterval
55+
| AuctionEscrow'CleanupAuction'Error'NoSellerConsent
56+
| AuctionEscrow'CleanupAuction'Error'AuctionIsNotConcluded
57+
| AuctionEscrow'CleanupAuction'Error'AuctionEscrowInputMissingStandingBidToken
5258
deriving stock (Generic, Eq)
5359
deriving anyclass (PlutusType)
5460

src/HydraAuctionOnchain/MintingPolicies/Auction.hs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
module HydraAuctionOnchain.MintingPolicies.Auction
2-
( auctionEscrowTokenName
2+
( allAuctionTokensBurned
3+
, auctionEscrowTokenName
34
, auctionMetadataTokenName
45
, standingBidTokenName
56
) where
67

7-
import Plutarch.Api.V2 (PTokenName)
8+
import Plutarch.Api.V1.Value qualified as Value (psingleton)
9+
import Plutarch.Api.V2
10+
( AmountGuarantees (NonZero)
11+
, KeyGuarantees (Sorted)
12+
, PCurrencySymbol
13+
, PTokenName
14+
, PValue
15+
)
16+
import Plutarch.Monadic qualified as P
817

918
-- | Auction state token, identifying the true auction escrow.
1019
auctionEscrowTokenName :: Term s PTokenName
@@ -17,3 +26,11 @@ auctionMetadataTokenName = pconstant "AUCTION_METADATA"
1726
-- | Standing bid token, identifying the true standing bid.
1827
standingBidTokenName :: Term s PTokenName
1928
standingBidTokenName = pconstant "STANDING_BID"
29+
30+
allAuctionTokensBurned :: Term s (PCurrencySymbol :--> PValue 'Sorted 'NonZero)
31+
allAuctionTokensBurned = phoistAcyclic $
32+
plam $ \auctionCs -> P.do
33+
mkValue <- plet $ plam $ \tn -> Value.psingleton # auctionCs # tn # (-1)
34+
(mkValue # auctionEscrowTokenName)
35+
<> (mkValue # auctionMetadataTokenName)
36+
<> (mkValue # standingBidTokenName)

src/HydraAuctionOnchain/Types/AuctionTerms.hs

Lines changed: 7 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+
, pcleanupPeriod
45
, ppenaltyPeriod
56
, ppurchasePeriod
67
, ptotalAuctionFees
@@ -16,6 +17,7 @@ import Plutarch.Api.V2
1617
, PValue
1718
)
1819
import Plutarch.DataRepr (PDataFields)
20+
import Plutarch.Extra.Interval qualified as Interval (pfrom)
1921
import Plutarch.Monadic qualified as P
2022
import Ply.Plutarch (PlyArgOf)
2123

@@ -83,3 +85,8 @@ ppenaltyPeriod = phoistAcyclic $
8385
pintervalFiniteClosedOpen
8486
# auctionTermsFields.purchaseDeadline
8587
# auctionTermsFields.cleanup
88+
89+
pcleanupPeriod :: Term s (PAuctionTerms :--> PPOSIXTimeRange)
90+
pcleanupPeriod = phoistAcyclic $
91+
plam $ \auctionTerms ->
92+
Interval.pfrom #$ pfield @"cleanup" # auctionTerms

src/HydraAuctionOnchain/Validators/AuctionEscrow.hs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,32 @@ import HydraAuctionOnchain.Helpers
2525
, pvaluePaidTo
2626
, pvaluePaidToScript
2727
)
28+
import HydraAuctionOnchain.MintingPolicies.Auction (allAuctionTokensBurned)
2829
import HydraAuctionOnchain.Types.AuctionEscrowState
29-
( PAuctionEscrowState
30+
( PAuctionEscrowState (AuctionConcluded)
3031
, pvalidateAuctionEscrowTransitionToAuctionConcluded
3132
, pvalidateAuctionEscrowTransitionToBiddingStarted
3233
)
3334
import HydraAuctionOnchain.Types.AuctionTerms
3435
( PAuctionTerms
3536
, pbiddingPeriod
37+
, pcleanupPeriod
3638
, ppenaltyPeriod
3739
, ppurchasePeriod
3840
, ptotalAuctionFees
3941
)
4042
import HydraAuctionOnchain.Types.BidTerms (psellerPayout, pvalidateBidTerms)
4143
import HydraAuctionOnchain.Types.Error (errCode, passert, passertMaybe, passertMaybeData)
4244
import HydraAuctionOnchain.Types.StandingBidState (PStandingBidState (PStandingBidState))
43-
import Plutarch.Api.V1.Value (plovelaceValueOf)
44-
import Plutarch.Api.V2 (PAddress, PCurrencySymbol, PScriptContext, PScriptHash, PTxInfo)
45+
import Plutarch.Api.V1.Value (plovelaceValueOf, pnormalize)
46+
import Plutarch.Api.V2
47+
( PAddress
48+
, PCurrencySymbol
49+
, PScriptContext
50+
, PScriptHash
51+
, PTxInInfo
52+
, PTxInfo
53+
)
4554
import Plutarch.Extra.Interval (pcontains)
4655
import Plutarch.Extra.Maybe (pdnothing)
4756
import Plutarch.Extra.ScriptContext (ptxSignedBy)
@@ -136,7 +145,12 @@ auctionEscrowValidator = phoistAcyclic $
136145
# oldAuctionState
137146
# ownAddress
138147
CleanupAuctionRedeemer _ ->
139-
undefined
148+
pcheckCleanupAuction
149+
# txInfo
150+
# auctionCs
151+
# auctionTerms
152+
# oldAuctionState
153+
# ownInput
140154

141155
--------------------------------------------------------------------------------
142156
-- StartBidding
@@ -456,3 +470,47 @@ pcheckSellerReclaims = phoistAcyclic $
456470
#<= (plovelaceValueOf #$ pvaluePaidToScript # txInfo # feeEscrowSh)
457471

458472
pcon PUnit
473+
474+
--------------------------------------------------------------------------------
475+
-- CleanupAuction
476+
--------------------------------------------------------------------------------
477+
478+
pcheckCleanupAuction
479+
:: Term
480+
s
481+
( PTxInfo
482+
:--> PCurrencySymbol
483+
:--> PAuctionTerms
484+
:--> PAuctionEscrowState
485+
:--> PTxInInfo
486+
:--> PUnit
487+
)
488+
pcheckCleanupAuction = phoistAcyclic $
489+
plam $ \txInfo auctionCs auctionTerms auctionState ownInput -> P.do
490+
txInfoFields <- pletFields @["mint", "signatories", "validRange"] txInfo
491+
492+
-- (AUES39) The auction state, auction metadata,and standing bid
493+
-- tokens of the auction should all be burned. No other tokens
494+
-- should be minted or burned.
495+
passert $(errCode AuctionEscrow'CleanupAuction'Error'AuctionTokensNotBurnedExactly) $
496+
pnormalize # txInfoFields.mint #== allAuctionTokensBurned # auctionCs
497+
498+
-- (AUES40) This redeemer can only be used during the cleanup period.
499+
passert $(errCode AuctionEscrow'CleanupAuction'Error'IncorrectValidityInterval) $
500+
pcontains # (pcleanupPeriod # auctionTerms) # txInfoFields.validRange
501+
502+
-- (AUES41) The seller signed the transaction.
503+
sellerPkh <- plet $ pfield @"sellerPkh" # auctionTerms
504+
passert $(errCode AuctionEscrow'CleanupAuction'Error'NoSellerConsent) $
505+
ptxSignedBy # txInfoFields.signatories # pdata sellerPkh
506+
507+
-- (AUES42) The auction is concluded.
508+
passert $(errCode AuctionEscrow'CleanupAuction'Error'AuctionIsNotConcluded) $
509+
auctionState #== pcon (AuctionConcluded pdnil)
510+
511+
-- (AUES43) The auction escrow input contains the standing bid
512+
-- token in addition to the auction token.
513+
passert $(errCode AuctionEscrow'CleanupAuction'Error'AuctionEscrowInputMissingStandingBidToken) $
514+
ptxOutContainsStandingBidToken # auctionCs #$ pfield @"resolved" # ownInput
515+
516+
pcon PUnit

0 commit comments

Comments
 (0)