File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
contracts/extensions/freeForAll Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,28 @@ pragma solidity ^0.8.20;
44import {BasePolicy} from "../../policy/BasePolicy.sol " ;
55
66/// @title FreeForAllPolicy
7- /// @notice A policy which allows anyone to sign up.
7+ /// @notice A policy which allows anyone to sign up, but only once per address .
88contract FreeForAllPolicy is BasePolicy {
9+ /// @notice Store the addreses that have been enforced
10+ mapping (address => bool ) public enforcedUsers;
11+
912 /// @notice Create a new instance of FreeForAllPolicy
1013 // solhint-disable-next-line no-empty-blocks
1114 constructor () payable {}
1215
16+ /// @notice Enforce a user so they can only be enforced once
17+ /// @param subject The user's Ethereum address.
18+ /// @param evidence The ABI-encoded evidence data.
19+ function _enforce (address subject , bytes calldata evidence ) internal override {
20+ if (enforcedUsers[subject]) {
21+ revert AlreadyEnforced ();
22+ }
23+
24+ enforcedUsers[subject] = true ;
25+
26+ super ._enforce (subject, evidence);
27+ }
28+
1329 /// @notice Get the trait of the Policy
1430 /// @return The type of the Policy
1531 function trait () public pure override returns (string memory ) {
Original file line number Diff line number Diff line change @@ -79,5 +79,11 @@ describe("FreeForAll", () => {
7979
8080 expect ( receipt ?. status ) . to . eq ( 1 )
8181 } )
82+
83+ it ( "should prevent enforcing the same account twice" , async ( ) => {
84+ await expect (
85+ policy . connect ( target ) . enforce ( subject , AbiCoder . defaultAbiCoder ( ) . encode ( [ ] , [ ] ) )
86+ ) . to . be . revertedWithCustomError ( policy , "AlreadyEnforced" )
87+ } )
8288 } )
8389} )
You can’t perform that action at this time.
0 commit comments