-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom entitlement factory to enable POAP gating #905
Changes from all commits
870ed0c
d4938a5
c3c70f3
a4e0bc3
ea2811b
02e4f51
832d9c6
260ec44
bf8b180
4653081
506db1d
45347bb
e3086dd
2b724b3
bd53e50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.23; | ||
|
||
import {Deployer} from "contracts/scripts/common/Deployer.s.sol"; | ||
import {PoapEntitlementFactory} from "contracts/src/spaces/entitlements/poap/PoapEntitlementFactory.sol"; | ||
|
||
contract DeployPoapEntitlementFactory is Deployer { | ||
function versionName() public pure override returns (string memory) { | ||
return "DeployPoapEntitlementFactory"; | ||
} | ||
|
||
function __deploy(address deployer) public override returns (address) { | ||
vm.broadcast(deployer); | ||
|
||
PoapEntitlementFactory factory = new PoapEntitlementFactory(); | ||
|
||
return address(factory); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {ICustomEntitlement} from "contracts/src/spaces/entitlements/ICustomEntitlement.sol"; | ||
|
||
interface IPOAP { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to a different file IPoapEntitlement.sol |
||
function balanceOf(address owner) external view returns (uint256); | ||
function tokenDetailsOfOwnerByIndex( | ||
address owner, | ||
uint256 index | ||
) external view returns (uint256 eventId, uint256 tokenId); | ||
} | ||
|
||
IPOAP constant poapContract = IPOAP(0x22C1f6050E56d2876009903609a2cC3fEf83B415); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move this inside the contract |
||
|
||
contract PoapEntitlement is ICustomEntitlement { | ||
uint256 public immutable eventId; | ||
|
||
constructor(uint256 _eventId) { | ||
require(_eventId > 0, "Invalid event ID"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
eventId = _eventId; | ||
} | ||
|
||
function isEntitled( | ||
address[] calldata wallets | ||
) external view override returns (bool) { | ||
for (uint256 i = 0; i < wallets.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cache wallet length |
||
if (_hasEventPoap(wallets[i])) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function _hasEventPoap(address user) internal view returns (bool) { | ||
uint256 balance = poapContract.balanceOf(user); | ||
for (uint256 j = 0; j < balance; j++) { | ||
(uint256 ownedEventId, ) = poapContract.tokenDetailsOfOwnerByIndex( | ||
user, | ||
j | ||
); | ||
if (eventId == ownedEventId) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {Factory} from "contracts/src/utils/Factory.sol"; | ||
import {PoapEntitlement} from "./PoapEntitlement.sol"; | ||
|
||
contract PoapEntitlementFactory is Factory { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. provide an interface for PoapEntitlementFactory in separate file |
||
function deployEntitlement(uint256 eventId) public { | ||
bytes32 salt = getSalt(eventId); | ||
address predictedAddress = predictEntitlementAddress(eventId); | ||
|
||
// Check if the contract is already deployed | ||
uint32 size; | ||
assembly { | ||
size := extcodesize(predictedAddress) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
} | ||
require(size == 0, "Entitlement already deployed for this event"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use if with custom error |
||
|
||
bytes memory initCode = abi.encodePacked( | ||
type(PoapEntitlement).creationCode, | ||
abi.encode(eventId) | ||
); | ||
|
||
address deployment = _deploy(initCode, salt); | ||
if (deployment != predictedAddress) { | ||
revert("Deployment failed"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an event that emits the deployed address |
||
} | ||
|
||
function getEntitlementAddress( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't think we need this function if we have |
||
uint256 eventId | ||
) public view returns (address) { | ||
return predictEntitlementAddress(eventId); | ||
} | ||
|
||
function getSalt(uint256 eventId) public pure returns (bytes32) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make internal |
||
return keccak256(abi.encodePacked("POAP", eventId)); | ||
} | ||
|
||
function predictEntitlementAddress( | ||
uint256 eventId | ||
) public view returns (address) { | ||
bytes32 initCodeHash = keccak256( | ||
abi.encodePacked(type(PoapEntitlement).creationCode, abi.encode(eventId)) | ||
); | ||
return _calculateDeploymentAddress(initCodeHash, getSalt(eventId)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the version name is the name of the contract you're deploying
poapEntitlementFactory