Skip to content

Commit 9d3f9e7

Browse files
committed
feat: implement auction metadata validator
1 parent a441973 commit 9d3f9e7

File tree

11 files changed

+207
-4
lines changed

11 files changed

+207
-4
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flake.lock linguist-generated=true
2+
compiled/* linguist-generated=true

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build, repl, format
1+
.PHONY: build, repl, format, hoogle, auction_metadata_validator
22

33
hs-sources := $(shell fd --no-ignore-parent -ehs)
44
cabal-sources := $(shell fd --no-ignore-parent -ecabal)
@@ -11,3 +11,9 @@ repl:
1111

1212
format:
1313
fourmolu -m inplace ${hs-sources} && cabal-fmt -i ${cabal-sources} && nix run '.#nixFormat'
14+
15+
hoogle:
16+
hoogle server --local --port=8070 > /dev/null &
17+
18+
auction_metadata_validator:
19+
cabal v2-run hydra-auction-onchain-exe

app/Main.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
module Main (main) where
22

3+
import HydraAuctionOnchain.Scripts (auctionMetadataValidatorUntyped, writeScript)
4+
35
main :: IO ()
4-
main = return ()
6+
main =
7+
writeScript
8+
"Auction metadata validator"
9+
"compiled/auction_metadata_validator.plutus"
10+
auctionMetadataValidatorUntyped

compiled/auction_metadata_validator.plutus

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fourmolu.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ record-brace-space: true
88
newlines-between-decls: 1
99
haddock-style: single-line
1010
haddock-style-module: single-line
11-
let-style: newline
11+
let-style: mixed
1212
in-style: no-space
1313
single-constraint-parens: never
1414
unicode: never

hydra-auction-onchain.cabal

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ common common-lang
101101

102102
library
103103
import: common-lang
104-
exposed-modules: HydraAuctionOnchain.Helpers
104+
exposed-modules:
105+
HydraAuctionOnchain.Helpers
106+
HydraAuctionOnchain.MintingPolicies.Auction
107+
HydraAuctionOnchain.Scripts
108+
HydraAuctionOnchain.Types.AuctionInfo
109+
HydraAuctionOnchain.Types.AuctionTerms
110+
HydraAuctionOnchain.Validators.AuctionMetadata
111+
105112
build-depends:
106113
, bytestring
107114
, data-default
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module HydraAuctionOnchain.MintingPolicies.Auction
2+
( auctionEscrowTokenName
3+
, auctionMetadataTokenName
4+
, standingBidTokenName
5+
) where
6+
7+
import Plutarch.Api.V2 (PTokenName)
8+
9+
-- | Auction state token, identifying the true auction escrow.
10+
auctionEscrowTokenName :: Term s PTokenName
11+
auctionEscrowTokenName = pconstant "AUCTION"
12+
13+
-- | Auction metadata token, identifying the true auction metadata.
14+
auctionMetadataTokenName :: Term s PTokenName
15+
auctionMetadataTokenName = pconstant "AUCTION_METADATA"
16+
17+
-- | Standing bid token, identifying the true standing bid.
18+
standingBidTokenName :: Term s PTokenName
19+
standingBidTokenName = pconstant "STANDING_BID"

src/HydraAuctionOnchain/Scripts.hs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module HydraAuctionOnchain.Scripts
2+
( auctionMetadataValidatorScript
3+
, auctionMetadataValidatorUntyped
4+
, writeScript
5+
) where
6+
7+
import Data.Text (Text)
8+
import Data.Text qualified as T (unpack)
9+
import HydraAuctionOnchain.Validators.AuctionMetadata (auctionMetadataValidator)
10+
import Plutarch (Config (Config), Script, TracingMode (DoTracingAndBinds), compile)
11+
import Plutarch.Api.V2 (PValidator)
12+
import Plutarch.Unsafe (punsafeCoerce)
13+
import Ply.Plutarch.TypedWriter (TypedWriter, writeTypedScript)
14+
15+
auctionMetadataValidatorUntyped :: ClosedTerm PValidator
16+
auctionMetadataValidatorUntyped =
17+
phoistAcyclic $ plam $ \datum redeemer ctx ->
18+
popaque $
19+
auctionMetadataValidator
20+
# punsafeCoerce datum
21+
# punsafeCoerce redeemer
22+
# ctx
23+
24+
auctionMetadataValidatorScript :: Script
25+
auctionMetadataValidatorScript = compileScript auctionMetadataValidatorUntyped
26+
27+
config :: Config
28+
config = Config DoTracingAndBinds
29+
30+
writeScript :: TypedWriter a => Text -> FilePath -> ClosedTerm a -> IO ()
31+
writeScript desc term = writeTypedScript config desc term
32+
33+
compileScript :: ClosedTerm a -> Script
34+
compileScript term =
35+
either (error . mappend "Plutarch compilation error: " . T.unpack) id $
36+
compile config term
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module HydraAuctionOnchain.Types.AuctionInfo
2+
( PAuctionInfo (PAuctionInfo)
3+
) where
4+
5+
import HydraAuctionOnchain.Types.AuctionTerms (PAuctionTerms)
6+
import Plutarch.Api.V2 (PAddress, PCurrencySymbol)
7+
import Plutarch.DataRepr (PDataFields)
8+
9+
newtype PAuctionInfo (s :: S)
10+
= PAuctionInfo
11+
( Term
12+
s
13+
( PDataRecord
14+
'[ "auctionId" ':= PCurrencySymbol
15+
, "auctionTerms" ':= PAuctionTerms
16+
, "auctionEscrowAddr" ':= PAddress
17+
, "bidderDepositAddr" ':= PAddress
18+
, "feeEscrowAddr" ':= PAddress
19+
, "standingBidAddr" ':= PAddress
20+
]
21+
)
22+
)
23+
deriving stock (Generic)
24+
deriving anyclass (PlutusType, PIsData, PDataFields, PShow, PEq)
25+
26+
instance DerivePlutusType PAuctionInfo where
27+
type DPTStrat _ = PlutusTypeData
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module HydraAuctionOnchain.Types.AuctionTerms
2+
( PAuctionTerms (PAuctionTerms)
3+
) where
4+
5+
import Plutarch.Api.V2
6+
( AmountGuarantees (Positive)
7+
, KeyGuarantees (Sorted)
8+
, PPOSIXTime
9+
, PPubKeyHash
10+
, PValue
11+
)
12+
import Plutarch.DataRepr (PDataFields)
13+
14+
newtype PAuctionTerms (s :: S)
15+
= PAuctionTerms
16+
( Term
17+
s
18+
( PDataRecord
19+
'[ "auctionLot" ':= PValue 'Sorted 'Positive
20+
, "sellerPkh" ':= PPubKeyHash
21+
, "sellerVk" ':= PByteString
22+
, "delegates" ':= PBuiltinList (PAsData PPubKeyHash)
23+
, "biddingStart" ':= PPOSIXTime
24+
, "biddingEnd" ':= PPOSIXTime
25+
, "purchaseDeadline" ':= PPOSIXTime
26+
, "cleanup" ':= PPOSIXTime
27+
, "auctionFeePerDelegate" ':= PInteger
28+
, "startingBid" ':= PInteger
29+
, "minBidIncrement" ':= PInteger
30+
, "minDepositAmount" ':= PInteger
31+
]
32+
)
33+
)
34+
deriving stock (Generic)
35+
deriving anyclass (PlutusType, PIsData, PDataFields, PShow, PEq)
36+
37+
instance DerivePlutusType PAuctionTerms where
38+
type DPTStrat _ = PlutusTypeData

0 commit comments

Comments
 (0)