-
Notifications
You must be signed in to change notification settings - Fork 490
Delegatable resolver #288
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
Open
makoto
wants to merge
21
commits into
staging
Choose a base branch
from
delegatable-resolver-wo-factory
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Delegatable resolver #288
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bdb5bde
Add DelegatableResolver.sol
makoto 440e77b
Merge branch 'staging' into delegatable-resolver
makoto 701bf66
WIP
makoto bbd083a
Add tests for DelegatableResolver
makoto 16d5a79
Add encodedname into the event
makoto 2aee50b
Add comment
makoto 429fa38
Add custom error
makoto afae77e
Add IDelegatableResolver
makoto 5eb3d37
Remove script/deploy.ts
makoto 6cc269f
Remove empty file
makoto 59b0cc7
Remove Ownable
makoto 0abb7cd
Revert indentation
makoto 2fadc67
Fix test
makoto 42acb3f
Remove test
makoto 7ecbe22
Revert to use OZ Ownable
makoto ed57aa8
Add a test to check the owner
makoto 093fbd2
Add comments and more test
makoto d07e6d9
Rename getAuthorizedNode to getAuthorisedNode
makoto 9ae2281
Delegatable resolver with factory (#289)
makoto e97d21f
Use addressOfClone2 instead of predictAddress
Chomtana 52ef40c
Merge pull request #344 from Opti-domains/delegatable-resolver-wo-fac…
Arachnid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| pragma solidity >=0.8.4; | ||
| import "./profiles/ABIResolver.sol"; | ||
| import "./profiles/AddrResolver.sol"; | ||
| import "./profiles/ContentHashResolver.sol"; | ||
| import "./profiles/DNSResolver.sol"; | ||
| import "./profiles/InterfaceResolver.sol"; | ||
| import "./profiles/NameResolver.sol"; | ||
| import "./profiles/PubkeyResolver.sol"; | ||
| import "./profiles/TextResolver.sol"; | ||
| import "./profiles/ExtendedResolver.sol"; | ||
| import "./Multicallable.sol"; | ||
| import "./IDelegatableResolver.sol"; | ||
| import {Clone} from "clones-with-immutable-args/src/Clone.sol"; | ||
|
|
||
| /** | ||
| * A delegated resolver that allows the resolver owner to add an operator to update records of a node on behalf of the owner. | ||
| * address. | ||
| */ | ||
| contract DelegatableResolver is | ||
| Clone, | ||
| Multicallable, | ||
| ABIResolver, | ||
| AddrResolver, | ||
| ContentHashResolver, | ||
| DNSResolver, | ||
| InterfaceResolver, | ||
| NameResolver, | ||
| PubkeyResolver, | ||
| TextResolver, | ||
| ExtendedResolver | ||
| { | ||
| using BytesUtils for bytes; | ||
|
|
||
| // Logged when an operator is added or removed. | ||
| event Approval( | ||
| bytes32 indexed node, | ||
| address indexed operator, | ||
| bytes name, | ||
| bool approved | ||
| ); | ||
|
|
||
| error NotAuthorized(bytes32 node); | ||
|
|
||
| //node => (delegate => isAuthorised) | ||
| mapping(bytes32 => mapping(address => bool)) operators; | ||
|
|
||
| /* | ||
| * Check to see if the operator has been approved by the owner for the node. | ||
| * @param name The ENS node to query | ||
| * @param offset The offset of the label to query recursively. Start from the 0 position and kepp adding the length of each label as it traverse. The function exits when len is 0. | ||
| * @param operator The address of the operator to query | ||
| * @return node The node of the name passed as an argument | ||
| * @return authorized The boolean state of whether the operator is approved to update record of the name | ||
| */ | ||
| function getAuthorisedNode( | ||
| bytes memory name, | ||
| uint256 offset, | ||
| address operator | ||
| ) public view returns (bytes32 node, bool authorized) { | ||
| uint256 len = name.readUint8(offset); | ||
| node = bytes32(0); | ||
| if (len > 0) { | ||
| bytes32 label = name.keccak(offset + 1, len); | ||
| (node, authorized) = getAuthorisedNode( | ||
| name, | ||
| offset + len + 1, | ||
| operator | ||
| ); | ||
| node = keccak256(abi.encodePacked(node, label)); | ||
| } else { | ||
| return ( | ||
| node, | ||
| authorized || operators[node][operator] || owner() == operator | ||
| ); | ||
| } | ||
| return (node, authorized || operators[node][operator]); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Approve an operator to be able to updated records on a node. | ||
| */ | ||
| function approve( | ||
| bytes memory name, | ||
| address operator, | ||
| bool approved | ||
| ) external { | ||
| (bytes32 node, bool authorized) = getAuthorisedNode( | ||
| name, | ||
| 0, | ||
| msg.sender | ||
| ); | ||
| if (!authorized) { | ||
| revert NotAuthorized(node); | ||
| } | ||
| operators[node][operator] = approved; | ||
| emit Approval(node, operator, name, approved); | ||
| } | ||
|
|
||
| /* | ||
| * Returns the owner address passed set by the Factory | ||
| * @return address The owner address | ||
| */ | ||
| function owner() public view returns (address) { | ||
| return _getArgAddress(0); | ||
| } | ||
|
|
||
| function isAuthorised(bytes32 node) internal view override returns (bool) { | ||
| return msg.sender == owner() || operators[node][msg.sender]; | ||
| } | ||
|
|
||
| function supportsInterface( | ||
| bytes4 interfaceID | ||
| ) | ||
| public | ||
| view | ||
| virtual | ||
| override( | ||
| Multicallable, | ||
| ABIResolver, | ||
| AddrResolver, | ||
| ContentHashResolver, | ||
| DNSResolver, | ||
| InterfaceResolver, | ||
| NameResolver, | ||
| PubkeyResolver, | ||
| TextResolver | ||
| ) | ||
| returns (bool) | ||
| { | ||
| return | ||
| interfaceID == type(IDelegatableResolver).interfaceId || | ||
| super.supportsInterface(interfaceID); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.17; | ||
|
|
||
| import "./DelegatableResolver.sol"; | ||
| import {ClonesWithImmutableArgs} from "clones-with-immutable-args/src/ClonesWithImmutableArgs.sol"; | ||
|
|
||
| /** | ||
| * A resolver factory that creates a dedicated resolver for each user | ||
| */ | ||
|
|
||
| contract DelegatableResolverFactory { | ||
| using ClonesWithImmutableArgs for address; | ||
|
|
||
| DelegatableResolver public implementation; | ||
| event NewDelegatableResolver(address resolver, address owner); | ||
|
|
||
| constructor(DelegatableResolver _implementation) { | ||
| implementation = _implementation; | ||
| } | ||
|
|
||
| /* | ||
| * Create the unique address unique to the owner | ||
| * @param address The address of the resolver owner | ||
| * @return address The address of the newly created Resolver | ||
| */ | ||
| function create( | ||
| address owner | ||
| ) external returns (DelegatableResolver clone) { | ||
| bytes memory data = abi.encodePacked(owner); | ||
| clone = DelegatableResolver(address(implementation).clone2(data)); | ||
| emit NewDelegatableResolver(address(clone), owner); | ||
| } | ||
|
|
||
| /* | ||
| * Returns the unique address unique to the owner | ||
| * @param address The address of the resolver owner | ||
| * @return address The address of the newly created Resolver | ||
| */ | ||
| function predictAddress(address owner) external returns (address clone) { | ||
| bytes memory data = abi.encodePacked(owner); | ||
| clone = address(implementation).addressOfClone2(data); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity >=0.8.4; | ||
|
|
||
| interface IDelegatableResolver { | ||
| function approve( | ||
| bytes memory name, | ||
| address operator, | ||
| bool approved | ||
| ) external; | ||
|
|
||
| function getAuthorisedNode( | ||
| bytes memory name, | ||
| uint256 offset, | ||
| address operator | ||
| ) external returns (bytes32 node, bool authorized); | ||
|
|
||
| function owner() external view returns (address); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.