|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity 0.8.19; |
| 3 | + |
| 4 | +import {Script} from "forge-std/Script.sol"; |
| 5 | +import {console} from "forge-std/console.sol"; |
| 6 | + |
| 7 | +import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; |
| 8 | +import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; |
| 9 | + |
| 10 | +import {AttesterProxy} from "../src/AttesterProxy.sol"; |
| 11 | +import {EthereumYearBadge} from "../src/badge/examples/EthereumYearBadge.sol"; |
| 12 | +import {ProfileRegistry} from "../src/profile/ProfileRegistry.sol"; |
| 13 | +import {ScrollBadgeResolver} from "../src/resolver/ScrollBadgeResolver.sol"; |
| 14 | +import {ScrollBadge} from "../src/badge/ScrollBadge.sol"; |
| 15 | +import {ScrollBadgeTokenOwner} from "../src/badge/examples/ScrollBadgeTokenOwner.sol"; |
| 16 | +import {ScrollBadgeEligibilityCheck} from "../src/badge/extensions/ScrollBadgeEligibilityCheck.sol"; |
| 17 | +import {ScrollBadgeAccessControl} from "../src/badge/extensions/ScrollBadgeAccessControl.sol"; |
| 18 | + |
| 19 | +contract CheckBadge is Script { |
| 20 | + uint256 SCROLL_CHAIN_ID = 534_352; |
| 21 | + address SCROLL_BADGE_RESOLVER_CONTRACT_ADDRESS = 0x4560FECd62B14A463bE44D40fE5Cfd595eEc0113; |
| 22 | + |
| 23 | + function run() external { |
| 24 | + address badge = vm.promptAddress("Please provide your badge address"); |
| 25 | + address attesterProxy = promptAddressOpt("Please provide your attester proxy address (leave empty if none)"); |
| 26 | + address signer = promptAddressOpt("Please provide your backend signer address (leave empty if none)"); |
| 27 | + |
| 28 | + run(badge, attesterProxy, signer); |
| 29 | + } |
| 30 | + |
| 31 | + function run(address badge, address attesterProxy, address signer) public { |
| 32 | + console.log( |
| 33 | + string( |
| 34 | + abi.encodePacked( |
| 35 | + "Checking badge ", |
| 36 | + vm.toString(badge), |
| 37 | + " with attester proxy ", |
| 38 | + vm.toString(attesterProxy), |
| 39 | + " and signer ", |
| 40 | + vm.toString(signer) |
| 41 | + ) |
| 42 | + ) |
| 43 | + ); |
| 44 | + |
| 45 | + // check chain id |
| 46 | + if (block.chainid != SCROLL_CHAIN_ID) { |
| 47 | + revert("Wrong chain, make sure to run this script with --rpc-url https://rpc.scroll.io"); |
| 48 | + } |
| 49 | + |
| 50 | + // check if badge exists |
| 51 | + if (badge.code.length == 0) { |
| 52 | + revert(unicode"❌ Badge contract not deployed"); |
| 53 | + } else { |
| 54 | + console.log(unicode"✅ Badge contract deployed"); |
| 55 | + } |
| 56 | + |
| 57 | + // check if attester proxy exists |
| 58 | + if (attesterProxy != address(0) && attesterProxy.code.length == 0) { |
| 59 | + revert(unicode"❌ Attester proxy contract not deployed"); |
| 60 | + } else { |
| 61 | + console.log(unicode"✅ Attester proxy contract deployed"); |
| 62 | + } |
| 63 | + |
| 64 | + // check resolver |
| 65 | + try ScrollBadge(badge).resolver() returns (address resolver) { |
| 66 | + if (resolver != SCROLL_BADGE_RESOLVER_CONTRACT_ADDRESS) { |
| 67 | + console.log( |
| 68 | + unicode"❌ Incorrect resolver, make sure that you pass the correct constructor argument to ScrollBadge" |
| 69 | + ); |
| 70 | + } else { |
| 71 | + console.log(unicode"✅ Badge resolver configured"); |
| 72 | + } |
| 73 | + } catch { |
| 74 | + console.log(unicode"❌ Failed to call badge.resolver(), make sure that your badge implements ScrollBadge"); |
| 75 | + } |
| 76 | + |
| 77 | + // check default badgeTokenURI |
| 78 | + try ScrollBadge(badge).badgeTokenURI(bytes32("")) returns (string memory defaultUri) { |
| 79 | + if (bytes(defaultUri).length == 0) { |
| 80 | + console.log( |
| 81 | + unicode"❌ Missing default badge URI, make sure that your badge implements ScrollBadgeDefaultURI" |
| 82 | + ); |
| 83 | + } else { |
| 84 | + console.log(unicode"✅ Default badge URI is configured"); |
| 85 | + } |
| 86 | + } catch { |
| 87 | + console.log( |
| 88 | + unicode"❌ Missing default badge URI, make sure that your badge implements ScrollBadgeDefaultURI" |
| 89 | + ); |
| 90 | + } |
| 91 | + |
| 92 | + // on-chain eligibility check |
| 93 | + if (attesterProxy == address(0)) { |
| 94 | + try ScrollBadgeEligibilityCheck(badge).isEligible(address(1)) { |
| 95 | + console.log(unicode"✅ On-chain eligibility check is configured"); |
| 96 | + } catch { |
| 97 | + console.log( |
| 98 | + unicode"❌ Missing on-chain eligibility check, make sure that your badge implements ScrollBadgeEligibilityCheck" |
| 99 | + ); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + // authorization |
| 104 | + if (attesterProxy != address(0)) { |
| 105 | + try ScrollBadgeAccessControl(badge).isAttester(attesterProxy) returns (bool isAttester) { |
| 106 | + if (!isAttester) { |
| 107 | + console.log( |
| 108 | + unicode"❌ Attester proxy is not whitelisted, please call badge.toggleAttester(attesterProxy, true)" |
| 109 | + ); |
| 110 | + } else { |
| 111 | + console.log(unicode"✅ Attester proxy is whitelisted"); |
| 112 | + } |
| 113 | + } catch { |
| 114 | + console.log( |
| 115 | + unicode"❌ Missing access control, make sure that your badge implements ScrollBadgeAccessControl" |
| 116 | + ); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + if (attesterProxy != address(0) && signer != address(0)) { |
| 121 | + try AttesterProxy(attesterProxy).isAttester(signer) returns (bool isAttester) { |
| 122 | + if (!isAttester) { |
| 123 | + console.log( |
| 124 | + unicode"❌ Your signer is not whitelisted, please call attesterProxy.toggleAttester(signer, true)" |
| 125 | + ); |
| 126 | + } else { |
| 127 | + console.log(unicode"✅ Signer is whitelisted"); |
| 128 | + } |
| 129 | + } catch { |
| 130 | + console.log( |
| 131 | + unicode"❌ Failed to query attester proxy, make sure this contract is an instance of AttesterProxy" |
| 132 | + ); |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + function promptAddressOpt(string memory promptText) private returns (address addr) { |
| 138 | + string memory str = vm.prompt(promptText); |
| 139 | + |
| 140 | + if (bytes(str).length > 0) { |
| 141 | + addr = vm.parseAddress(str); |
| 142 | + } |
| 143 | + } |
| 144 | +} |
0 commit comments