Skip to content

Commit caf52fc

Browse files
committed
add ERC2771 interfaces and storage library
1 parent 6c93a45 commit caf52fc

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

contracts/interfaces/IERC2771.sol

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.20;
4+
5+
import { _IERC2771 } from './_IERC2771.sol';
6+
7+
interface IERC2771 is _IERC2771 {
8+
function isTrustedForwarder(address forwarder) external view returns (bool);
9+
}

contracts/interfaces/_IERC2771.sol

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.20;
4+
5+
interface _IERC2771 {}

contracts/storage/ERC2771Storage.sol

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.20;
4+
5+
library ERC2771Storage {
6+
/**
7+
* @custom:storage-location erc7201:solidstate.contracts.storage.ERC2771
8+
*/
9+
struct Layout {
10+
mapping(address account => bool trustedStatus) trustedForwarders;
11+
}
12+
13+
bytes32 internal constant DEFAULT_STORAGE_SLOT =
14+
keccak256(
15+
abi.encode(
16+
uint256(
17+
keccak256(bytes('solidstate.contracts.storage.ERC2771'))
18+
) - 1
19+
)
20+
) & ~bytes32(uint256(0xff));
21+
22+
function layout() internal pure returns (Layout storage $) {
23+
$ = layout(DEFAULT_STORAGE_SLOT);
24+
}
25+
26+
function layout(bytes32 slot) internal pure returns (Layout storage $) {
27+
assembly {
28+
$.slot := slot
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)