Skip to content

Commit

Permalink
improve contract code
Browse files Browse the repository at this point in the history
  • Loading branch information
pumpedlunch committed Jul 12, 2023
1 parent 382999a commit 63f01dd
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ HatsEligibilityModules is a repo containing a number of separate eligility modul

All contracts are based on the Hats Protocol's repo: [hats-module](https://github.com/Hats-Protocol/hats-module)

**Note**: The contracts have not been audited - use at your own risk.

## Development

This repo uses Foundry for development and testing. To get started:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract DecentralistEligibility is HatsEligibilityModule {
* --------------------------------------------------------------------+
*/

/// The address of the ERC20 contract used to check eligibility
/// The address of the Decentralist contract used to check eligibility
function LIST_ADDRESS() public pure returns (address) {
return _getArgAddress(72);
}
Expand All @@ -56,7 +56,6 @@ contract DecentralistEligibility is HatsEligibilityModule {
uint256 /*_hatId */
) public view override returns (bool eligible, bool standing) {
eligible = DecentralistInterface(LIST_ADDRESS()).onList(_wearer);

standing = true;
}
}
20 changes: 12 additions & 8 deletions src/ERC1155Eligibility.sol → src/ERC1155EligibilityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ contract ERC1155Eligibility is HatsEligibilityModule {
return _getArgAddress(72);
}

/// The address of the ERC1155 contract used to check eligibility
/// The length of the TOKEN_IDS & MIN_BALANCES arrays - these MUST be equal.
function ARRAY_LENGTH() public pure returns (uint256) {
return _getArgUint256(92);
}

/// The token IDs that allow eligibility. Wearer must satisfy only one token ID criteria for eligiblity
/// The ERC1155token IDs that allow eligibility.
/// @dev NOTE: Wearer must satisfy only one token ID criteria for eligiblity.
/// @dev NOTE: the TOKEN_IDS length must match the MIN_BALANCES length
function TOKEN_IDS() public pure returns (uint256[] memory) {
return _getArgUint256Array(124, ARRAY_LENGTH());
}

/// The minimum balances required (for token ID in the corresponding index) for eligibility.
/// Wearer must satisfy only one token ID criteria for eligiblity
/// @dev NOTE: Wearer must satisfy only one token ID criteria for eligiblity
/// @dev NOTE: the TOKEN_IDS length must match the MIN_BALANCES length
function MIN_BALANCES() public pure returns (uint256[] memory) {
return _getArgUint256Array(124 + ARRAY_LENGTH() * 32, ARRAY_LENGTH());
}
Expand All @@ -58,7 +61,7 @@ contract ERC1155Eligibility is HatsEligibilityModule {
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/**
* @notice Deploy the ERC20Eligibility implementation contract and set its version
* @notice Deploy the ERC1155Eligibility implementation contract and set its version
* @dev This is only used to deploy the implementation contract, and should not be used to deploy clones
*/
constructor(string memory _version) HatsModule(_version) {}
Expand All @@ -78,10 +81,11 @@ contract ERC1155Eligibility is HatsEligibilityModule {
uint256[] memory tokenIds = TOKEN_IDS();
uint256[] memory minBalances = MIN_BALANCES();

for (uint256 i = 0; i < len; i++) {
if (token.balanceOf(_wearer, tokenIds[i]) >= minBalances[i]) {
eligible = true;
break;
for (uint256 i = 0; i < len;) {
eligible = token.balanceOf(_wearer, tokenIds[i]) >= minBalances[i];
if (eligible) break;
unchecked {
++i;
}
}
standing = true;
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/ERC721Eligibility.sol → src/ERC721EligibilityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract ERC721Eligibility is HatsEligibilityModule {
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/

/// @notice Deploy the ERC20Eligibility implementation contract and set its version
/// @notice Deploy the ERC721Eligibility implementation contract and set its version
/// @dev This is only used to deploy the implementation contract, and should not be used to deploy clones
constructor(string memory _version) HatsModule(_version) {}

Expand All @@ -59,7 +59,7 @@ contract ERC721Eligibility is HatsEligibilityModule {
uint256 /*_hatId */
) public view override returns (bool eligible, bool standing) {
uint256 balance = IERC721(TOKEN_ADDRESS()).balanceOf(_wearer);
eligible = balance >= MIN_BALANCE() ? true : false;
eligible = balance >= MIN_BALANCE();
standing = true;
}
}
2 changes: 1 addition & 1 deletion test/AddressEligibility.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.18;

import {Test, console2} from "forge-std/Test.sol";
import {HatsModule, HatsModuleFactory, IHats, Deploy} from "../script/HatsModuleFactory.s.sol";
import {AddressEligibility} from "src/AddressEligibility.sol";
import {AddressEligibility} from "src/AddressEligibilityModule.sol";

contract AddressEligibilityTest is Deploy, Test {
error AddressEligibility_NotHatAdmin();
Expand Down
2 changes: 1 addition & 1 deletion test/DecentralistEligibility.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.18;

import {Test, console2} from "forge-std/Test.sol";
import {HatsModule, HatsModuleFactory, IHats, Deploy} from "../script/HatsModuleFactory.s.sol";
import {DecentralistEligibility} from "src/DecentralistEligibility.sol";
import {DecentralistEligibility} from "src/DecentralistEligibilityModule.sol";

// NOTE: this test script does not deploy Decentralist or UMA contracts, soit must be run on Goerli
contract DecentralistEligibilityTest is Deploy, Test {
Expand Down
4 changes: 2 additions & 2 deletions test/ERC1155Eligibility.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity ^0.8.18;
import {Test, console2} from "forge-std/Test.sol";
import {ERC1155} from "@openzeppelin-contracts/contracts/token/ERC1155/ERC1155.sol";
import {HatsModule, HatsModuleFactory, IHats, Deploy} from "../script/HatsModuleFactory.s.sol";
import {ERC1155Eligibility} from "src/ERC1155Eligibility.sol";
import {ERC1155Eligibility} from "src/ERC1155EligibilityModule.sol";

contract MintableERC1155 is ERC1155 {
constructor() ERC1155("") {}

function mint(address to, uint256 tokenId, uint256 amount) public {
_mint(to, tokenId, amount, "");
}
}F
}

contract ERC1155EligibilityTest is Deploy, Test {
string public FACTORY_VERSION = "factory test version";
Expand Down
2 changes: 1 addition & 1 deletion test/ERC20Eligibility.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.18;
import {Test, console2} from "forge-std/Test.sol";
import {ERC20} from "@openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {HatsModule, HatsModuleFactory, IHats, Deploy} from "../script/HatsModuleFactory.s.sol";
import {ERC20Eligibility} from "src/ERC20Eligibility.sol";
import {ERC20Eligibility} from "src/ERC20EligibilityModule.sol";

contract MintableERC20 is ERC20 {
constructor() ERC20("Test Token", "TT") {}
Expand Down
2 changes: 1 addition & 1 deletion test/ERC721Eligibility.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.18;
import {Test, console2} from "forge-std/Test.sol";
import {ERC721} from "@openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
import {HatsModule, HatsModuleFactory, IHats, Deploy} from "../script/HatsModuleFactory.s.sol";
import {ERC721Eligibility} from "src/ERC721Eligibility.sol";
import {ERC721Eligibility} from "src/ERC721EligibilityModule.sol";

contract MintableERC721 is ERC721 {
constructor() ERC721("Test NFT", "TNFT") {}
Expand Down

0 comments on commit 63f01dd

Please sign in to comment.