@@ -6,32 +6,45 @@ import {IAddressResolver} from "ens-contracts/resolvers/profiles/IAddressResolve
6
6
7
7
import {ResolverBase} from "./ResolverBase.sol " ;
8
8
9
+ /// @title AddrResolver
10
+ ///
11
+ /// @notice ENSIP-11 compliant Address Resolver. Adaptation of the ENS AddrResolver.sol profile contract, with
12
+ /// EIP-7201 storage compliance.
13
+ /// https://github.com/ensdomains/ens-contracts/blob/staging/contracts/resolvers/profiles/AddrResolver.sol
14
+ ///
15
+ /// @author Coinbase (https://github.com/base-org/basenames)
9
16
abstract contract AddrResolver is IAddrResolver , IAddressResolver , ResolverBase {
10
17
struct AddrResolverStorage {
18
+ /// @notice Address record per cointype, node and version.
11
19
mapping (uint64 version = > mapping (bytes32 node = > mapping (uint256 cointype = > bytes addr )))
12
20
versionable_addresses;
13
21
}
14
22
23
+ /// @notice EIP-7201 storage location.
15
24
// keccak256(abi.encode(uint256(keccak256("addr.resolver.storage")) - 1)) & ~bytes32(uint256(0xff));
16
25
bytes32 constant ADDR_RESOLVER_STORAGE = 0x1871a91a9a944f867849820431bb11c2d1625edae573523bceb5b38b8b8a7500 ;
17
26
27
+ /// @notice Ethereum mainnet network-as-cointype.
18
28
uint256 private constant COIN_TYPE_ETH = 60 ;
19
29
20
- /**
21
- * Sets the address associated with an ENS node.
22
- * May only be called by the owner of that node in the ENS registry.
23
- * @param node The node to update.
24
- * @param a The address to set.
25
- */
30
+
31
+ /// @notice Sets the address associated with an ENS node.
32
+ ///
33
+ /// @dev May only be called by the owner of that node in the ENS registry.
34
+ ///
35
+ /// @param node The node to update.
36
+ /// @param a The address to set.
26
37
function setAddr (bytes32 node , address a ) external virtual authorised (node) {
27
38
setAddr (node, COIN_TYPE_ETH, addressToBytes (a));
28
39
}
29
40
30
- /**
31
- * Returns the address associated with an ENS node.
32
- * @param node The ENS node to query.
33
- * @return The associated address.
34
- */
41
+ /// @notice Returns the address associated with a specified ENS `node`.
42
+ ///
43
+ /// @dev Returns the `addr` record for the Ethereum Mainnet network-as-cointype.
44
+ ///
45
+ /// @param node The ENS node to query.
46
+ ///
47
+ /// @return The associated address.
35
48
function addr (bytes32 node ) public view virtual override returns (address payable ) {
36
49
bytes memory a = addr (node, COIN_TYPE_ETH);
37
50
if (a.length == 0 ) {
@@ -40,6 +53,11 @@ abstract contract AddrResolver is IAddrResolver, IAddressResolver, ResolverBase
40
53
return bytesToAddress (a);
41
54
}
42
55
56
+ /// @notice Set the network or coin-specific address for an ENS `node`.
57
+ ///
58
+ /// @param node The ENS node to update.
59
+ /// @param coinType The coinType for this address.
60
+ /// @param a The network-agnostic bytes of the address.
43
61
function setAddr (bytes32 node , uint256 coinType , bytes memory a ) public virtual authorised (node) {
44
62
emit AddressChanged (node, coinType, a);
45
63
if (coinType == COIN_TYPE_ETH) {
@@ -49,29 +67,41 @@ abstract contract AddrResolver is IAddrResolver, IAddressResolver, ResolverBase
49
67
= a;
50
68
}
51
69
70
+ /// @notice Returns the address of the `node` for a specified `coinType`.
71
+ ///
72
+ /// @dev Complies with ENSIP-9 and ENSIP-11.
73
+ ///
74
+ /// @param node The ENS node to update.
75
+ /// @param coinType The coinType to fetch.
76
+ ///
77
+ /// @return The address of the specified `node` for the specified `coinType`.
52
78
function addr (bytes32 node , uint256 coinType ) public view virtual override returns (bytes memory ) {
53
79
return _getAddrResolverStorage ().versionable_addresses[_getResolverBaseStorage ().recordVersions[node]][node][coinType];
54
80
}
55
81
82
+ /// @notice ERC-165 compliance.
56
83
function supportsInterface (bytes4 interfaceID ) public view virtual override returns (bool ) {
57
84
return interfaceID == type (IAddrResolver).interfaceId || interfaceID == type (IAddressResolver).interfaceId
58
85
|| super .supportsInterface (interfaceID);
59
86
}
60
87
88
+ /// @notice Helper to convert bytes into an EVM address object.
61
89
function bytesToAddress (bytes memory b ) internal pure returns (address payable a ) {
62
90
require (b.length == 20 );
63
91
assembly {
64
92
a := div (mload (add (b, 32 )), exp (256 , 12 ))
65
93
}
66
94
}
67
95
96
+ /// @notice Helper to convert an EVM address to a bytes object.
68
97
function addressToBytes (address a ) internal pure returns (bytes memory b ) {
69
98
b = new bytes (20 );
70
99
assembly {
71
100
mstore (add (b, 32 ), mul (a, exp (256 , 12 )))
72
101
}
73
102
}
74
103
104
+ /// @notice EIP-7201 storage pointer fetch helper.
75
105
function _getAddrResolverStorage () internal pure returns (AddrResolverStorage storage $) {
76
106
assembly {
77
107
$.slot := ADDR_RESOLVER_STORAGE
0 commit comments