From dd9b8563ec5ce1a7ed3d3054170399a5f6834fd5 Mon Sep 17 00:00:00 2001 From: boyuanx Date: Tue, 20 Aug 2024 19:55:53 -0700 Subject: [PATCH] Update examples --- .vscode/settings.json | 2 +- foundry.toml | 3 +- hardhat.config.ts | 2 +- .../ActuallyMetIRL.sol | 0 src/02-schema-hook/WhitelistHook.sol | 80 +++++++++++++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) rename src/{ => 01-actually-met-irl}/ActuallyMetIRL.sol (100%) create mode 100644 src/02-schema-hook/WhitelistHook.sol diff --git a/.vscode/settings.json b/.vscode/settings.json index 419451f..06e6078 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "solidity.compileUsingRemoteVersion": "v0.8.24+commit.e11b9ed9", + "solidity.compileUsingRemoteVersion": "v0.8.26+commit.8a97fa7a", "editor.formatOnSave": true, "[solidity]": { "editor.defaultFormatter": "JuanBlanco.solidity" diff --git a/foundry.toml b/foundry.toml index 5bc3def..3a20d7c 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,7 +1,7 @@ [profile.default] src = "src" out = "out" -solc = "0.8.24" +solc = "0.8.26" bytecode_hash = "none" optimizer = true optimizer_runs = 200 @@ -9,6 +9,7 @@ build_info = true extra_output = ["storageLayout"] auto_detect_remappings = true gas_reports = ["*"] +via_ir = true [fmt] bracket_spacing = true diff --git a/hardhat.config.ts b/hardhat.config.ts index 6d39baa..de4e569 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -19,7 +19,7 @@ const config: HardhatUserConfig = { solidity: { compilers: [ { - version: '0.8.24', + version: '0.8.26', settings: { optimizer: { enabled: true, diff --git a/src/ActuallyMetIRL.sol b/src/01-actually-met-irl/ActuallyMetIRL.sol similarity index 100% rename from src/ActuallyMetIRL.sol rename to src/01-actually-met-irl/ActuallyMetIRL.sol diff --git a/src/02-schema-hook/WhitelistHook.sol b/src/02-schema-hook/WhitelistHook.sol new file mode 100644 index 0000000..aad7828 --- /dev/null +++ b/src/02-schema-hook/WhitelistHook.sol @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.26; + +import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; +import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; +import { ISPHook } from "@ethsign/sign-protocol-evm/src/interfaces/ISPHook.sol"; + +// @dev This contract manages the whitelist. We are separating the whitelist logic from the hook to make things easier +// to read. +contract WhitelistMananger is Ownable { + mapping(address attester => bool allowed) public whitelist; + + error UnauthorizedAttester(); + + constructor() Ownable(_msgSender()) { } + + function setWhitelist(address attester, bool allowed) external onlyOwner { + whitelist[attester] = allowed; + } + + function _checkAttesterWhitelistStatus(address attester) internal view { + // solhint-disable-next-line custom-errors + require(whitelist[attester], UnauthorizedAttester()); + } +} + +// @dev This contract implements the actual schema hook. +contract WhitelistHook is ISPHook, WhitelistMananger { + function didReceiveAttestation( + address attester, + uint64, // schemaId + uint64, // attestationId + bytes calldata // extraData + ) + external + payable + { + _checkAttesterWhitelistStatus(attester); + } + + function didReceiveAttestation( + address attester, + uint64, // schemaId + uint64, // attestationId + IERC20, // resolverFeeERC20Token + uint256, // resolverFeeERC20Amount + bytes calldata // extraData + ) + external + view + { + _checkAttesterWhitelistStatus(attester); + } + + function didReceiveRevocation( + address attester, + uint64, // schemaId + uint64, // attestationId + bytes calldata // extraData + ) + external + payable + { + _checkAttesterWhitelistStatus(attester); + } + + function didReceiveRevocation( + address attester, + uint64, // schemaId + uint64, // attestationId + IERC20, // resolverFeeERC20Token + uint256, // resolverFeeERC20Amount + bytes calldata // extraData + ) + external + view + { + _checkAttesterWhitelistStatus(attester); + } +}