Skip to content

Commit 3ea18f2

Browse files
committed
feat(standing_bid): allow only one input from script address
1 parent 4befdda commit 3ea18f2

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

src/HydraAuctionOnchain/Errors/StandingBid.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import HydraAuctionOnchain.Types.Error (ErrorCodePrefix (errorCodePrefix))
88
data PStandingBidError (s :: S)
99
= -- Common errors
1010
StandingBid'Error'MissingStandingBidInput
11+
| StandingBid'Error'TooManyOwnScriptInputs
1112
| StandingBid'Error'OwnInputMissingToken
1213
| StandingBid'Error'UnexpectedTokensMintedBurned
1314
| -- NewBid errors

src/HydraAuctionOnchain/Helpers.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module HydraAuctionOnchain.Helpers
77
, pfindUniqueOutputWithAddress
88
, pgetOwnInput
99
, pintervalFiniteClosedOpen
10+
, ponlyOneInputFromAddress
1011
, pserialise
1112
, putxoAddress
1213
) where
@@ -112,6 +113,17 @@ pintervalFiniteClosedOpen = phoistAcyclic $
112113
)
113114
# pdnil
114115

116+
ponlyOneInputFromAddress :: Term s (PAddress :--> PTxInfo :--> PBool)
117+
ponlyOneInputFromAddress = phoistAcyclic $
118+
plam $ \addr txInfo -> P.do
119+
inputs <- plet $ pfromData $ pfield @"inputs" # txInfo
120+
inputsFromAddress <-
121+
plet $
122+
pfilter
123+
# plam (\utxo -> (pfield @"address" #$ pfield @"resolved" # utxo) #== addr)
124+
# inputs
125+
plength # inputsFromAddress #== 1
126+
115127
pserialise :: PIsData a => Term s (a :--> PByteString)
116128
pserialise = phoistAcyclic $ plam $ \x -> pserialiseData #$ pforgetData $ pdata x
117129

src/HydraAuctionOnchain/Validators/StandingBid.hs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import HydraAuctionOnchain.Helpers
1010
, pfindUniqueInputWithToken
1111
, pfindUniqueOutputWithAddress
1212
, pgetOwnInput
13+
, ponlyOneInputFromAddress
1314
, putxoAddress
1415
)
1516
import HydraAuctionOnchain.MintingPolicies.Auction
@@ -64,21 +65,25 @@ standingBidValidator
6465
)
6566
standingBidValidator = phoistAcyclic $
6667
plam $ \auctionCs auctionTerms oldBidState redeemer ctx -> P.do
68+
txInfo <- plet $ pfield @"txInfo" # ctx
69+
6770
-- (STBD0) The validator's own input should exist.
6871
ownInput <-
6972
plet $
7073
passertMaybe
7174
$(errCode StandingBid'Error'MissingStandingBidInput)
7275
(pgetOwnInput # ctx)
7376

74-
txInfo <- plet $ pfield @"txInfo" # ctx
77+
-- (STBD1) There should only be one standing bid input.
78+
passert $(errCode StandingBid'Error'TooManyOwnScriptInputs) $
79+
ponlyOneInputFromAddress # (putxoAddress # ownInput) # txInfo
7580

76-
-- (STBD1) The standing bid input should contain the standing
81+
-- (STBD2) The standing bid input should contain the standing
7782
-- bid token.
7883
passert $(errCode StandingBid'Error'OwnInputMissingToken) $
7984
ptxOutContainsStandingBidToken # auctionCs #$ pfield @"resolved" # ownInput
8085

81-
-- (STBD2) There should be no tokens minted or burned.
86+
-- (STBD3) There should be no tokens minted or burned.
8287
mintValue <- plet $ pfield @"mint" # txInfo
8388
passert $(errCode StandingBid'Error'UnexpectedTokensMintedBurned) $
8489
pfromData mintValue #== mempty
@@ -107,32 +112,32 @@ pcheckNewBid
107112
)
108113
pcheckNewBid = phoistAcyclic $
109114
plam $ \txInfo auctionCs auctionTerms ownInput oldBidState -> P.do
110-
-- (STBD3) The standing bid output should exist.
115+
-- (STBD4) The standing bid output should exist.
111116
ownOutput <-
112117
plet $
113118
passertMaybe
114119
$(errCode StandingBid'NewBid'Error'MissingOwnOutput)
115120
(pfindUniqueOutputWithAddress # (putxoAddress # ownInput) # txInfo)
116121

117-
-- (STBD4) The standing bid output should contain the standing
122+
-- (STBD5) The standing bid output should contain the standing
118123
-- bid token.
119124
passert $(errCode StandingBid'NewBid'Error'OwnOutputMissingToken) $
120125
ptxOutContainsStandingBidToken # auctionCs # ownOutput
121126

122-
-- (STBD5) The standing bid output's datum should be decodable
127+
-- (STBD6) The standing bid output's datum should be decodable
123128
-- as a standing bid state.
124129
newBidState <-
125130
plet $
126131
passertMaybe
127132
$(errCode StandingBid'NewBid'Error'FailedToDecodeNewBid)
128133
(pdecodeInlineDatum # ownOutput)
129134

130-
-- (STBD6) The transition from the old bid state to the new
135+
-- (STBD7) The transition from the old bid state to the new
131136
-- bid state should be valid.
132137
passert $(errCode StandingBid'NewBid'Error'InvalidNewBidState) $
133138
pvalidateNewBid # auctionCs # auctionTerms # oldBidState # newBidState
134139

135-
-- (STBD7) The transaction validity should end before the
140+
-- (STBD8) The transaction validity should end before the
136141
-- bidding end time.
137142
txInfoValidRange <- plet $ pfield @"validRange" # txInfo
138143
passert $(errCode StandingBid'NewBid'Error'IncorrectValidityInterval) $
@@ -149,12 +154,12 @@ pcheckMoveToHydra = phoistAcyclic $
149154
plam $ \txInfo auctionTerms -> P.do
150155
txInfoFields <- pletFields @["signatories", "validRange"] txInfo
151156

152-
-- (STBD8) The transaction should be signed by all the delegates.
157+
-- (STBD9) The transaction should be signed by all the delegates.
153158
delegates <- plet $ pfield @"delegates" # auctionTerms
154159
passert $(errCode StandingBid'MoveToHydra'Error'MissingDelegateSignatures) $
155160
pall # plam (\sig -> ptxSignedBy # txInfoFields.signatories # sig) # delegates
156161

157-
-- (STBD9) The transaction validity should end before the
162+
-- (STBD10) The transaction validity should end before the
158163
-- bidding end time.
159164
passert $(errCode StandingBid'MoveToHydra'Error'IncorrectValidityInterval) $
160165
pcontains # (pbiddingPeriod # auctionTerms) # txInfoFields.validRange
@@ -168,15 +173,15 @@ pcheckMoveToHydra = phoistAcyclic $
168173
pcheckConcludeAuction :: Term s (PTxInfo :--> PCurrencySymbol :--> PUnit)
169174
pcheckConcludeAuction = phoistAcyclic $
170175
plam $ \txInfo auctionCs -> P.do
171-
-- (STBD10) There is an input that contains
176+
-- (STBD11) There is an input that contains
172177
-- the auction escrow token.
173178
auctionEscrowUtxo <-
174179
plet $
175180
passertMaybe
176181
$(errCode StandingBid'ConcludeAuction'Error'MissingAuctionEscrowInput)
177182
(pfindUniqueInputWithToken # auctionCs # auctionEscrowTokenName # txInfo)
178183

179-
-- (STBD11) The auction escrow input is being spent with the
184+
-- (STBD12) The auction escrow input is being spent with the
180185
-- `BidderBuys` or `SellerReclaims` redeemer. Implicitly, this
181186
-- means that the auction is concluding with either the winning
182187
-- bidder buying the auction lot or the seller reclaiming it.

0 commit comments

Comments
 (0)