|
2 | 2 | pragma solidity 0.8.18;
|
3 | 3 |
|
4 | 4 | import {MintGoldDustCompany} from "mgd-v2-contracts/MintGoldDustCompany.sol";
|
| 5 | +import {MGDL2SyncEIP712, ECDSAUpgradeable} from "./MGDL2SyncEIP712.sol"; |
| 6 | +import {SafeAccountChecker, ISafe} from "./utils/SafeAccountChecker.sol"; |
5 | 7 |
|
6 | 8 | /// @title MGDCompanyL2Sync
|
7 | 9 | /// @notice An extension to {MintGoldDustCompany} containing functions that
|
8 | 10 | /// syncs access levels management changes with a L2.
|
9 | 11 | /// @author Mint Gold Dust LLC
|
10 | 12 | /// @custom:contact klvh@mintgolddust.io
|
11 |
| -contract MGDCompanyL2Sync is MintGoldDustCompany { |
| 13 | +contract MGDCompanyL2Sync is MGDL2SyncEIP712, SafeAccountChecker, MintGoldDustCompany { |
| 14 | + /// Custom errors |
| 15 | + error MGDCompanyL2Sync_setValidatorWithL2Sync_longDeadline(); |
| 16 | + error MGDCompanyL2Sync_setValidatorWithL2Sync_notValidSigner(); |
| 17 | + |
| 18 | + bytes32 private constant _SETVALIDATOR_TYPEHASH = |
| 19 | + keccak256("SetValidator(address account,bool state,uint256 deadline)"); |
| 20 | + |
12 | 21 | function setValidatorWithL2Sync(
|
13 |
| - address _address, |
14 |
| - bool _state, |
| 22 | + address account, |
| 23 | + bool state, |
| 24 | + uint256 deadline, |
15 | 25 | uint8 v,
|
16 | 26 | bytes32 r,
|
17 | 27 | bytes32 s
|
18 | 28 | )
|
19 | 29 | external
|
20 | 30 | onlyOwner
|
21 |
| - isZeroAddress(_address) |
| 31 | + isZeroAddress(account) |
22 | 32 | {
|
23 |
| - isAddressValidator[_address] = _state; |
24 |
| - emit ValidatorAdded(_address, _state); |
| 33 | + if (deadline > block.timestamp + 1 days) { |
| 34 | + revert MGDCompanyL2Sync_setValidatorWithL2Sync_longDeadline(); |
| 35 | + } |
| 36 | + |
| 37 | + bytes32 structHash = keccak256(abi.encode(_SETVALIDATOR_TYPEHASH, account, state, deadline)); |
| 38 | + bytes32 digest = _hashTypedDataV4(structHash); |
| 39 | + address signer = ECDSAUpgradeable.recover(digest, v, r, s); |
| 40 | + |
| 41 | + if (_isOwnerAContract() && isAddressASafe(owner())) { |
| 42 | + if (!isAccountOwnerInSafe(signer, owner())) { |
| 43 | + revert MGDCompanyL2Sync_setValidatorWithL2Sync_notValidSigner(); |
| 44 | + } |
| 45 | + } else {} |
| 46 | + |
| 47 | + if (block.chainid == 0x1) { |
| 48 | + isAddressValidator[account] = state; |
| 49 | + } |
| 50 | + |
| 51 | + emit ValidatorAdded(account, state); |
| 52 | + } |
| 53 | + |
| 54 | + function _isOwnerAContract() internal view returns (bool) { |
| 55 | + return address(owner()).code.length > 0; |
25 | 56 | }
|
26 | 57 | }
|
0 commit comments