Skip to content

Commit 989e175

Browse files
tba new interface (#491)
* wip * conform to new interface * delete duplicate readme * fix formatting * fix license and add ascii --------- Co-authored-by: nkrishang <[email protected]> Co-authored-by: Krishang <[email protected]>
1 parent 77dd318 commit 989e175

File tree

2 files changed

+66
-29
lines changed

2 files changed

+66
-29
lines changed

contracts/prebuilts/account/token-bound-account/TokenBoundAccount.sol

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-License-Identifier: UNLICENSED
1+
// SPDX-License-Identifier: Apache 2.0
22
pragma solidity ^0.8.0;
33

44
/* solhint-disable avoid-low-level-calls */
@@ -26,6 +26,15 @@ import "./erc6551-utils/IERC6551Account.sol";
2626
import "../../../eip/interface/IERC721.sol";
2727
import "../non-upgradeable/Account.sol";
2828

29+
// $$\ $$\ $$\ $$\ $$\
30+
// $$ | $$ | \__| $$ | $$ |
31+
// $$$$$$\ $$$$$$$\ $$\ $$$$$$\ $$$$$$$ |$$\ $$\ $$\ $$$$$$\ $$$$$$$\
32+
// \_$$ _| $$ __$$\ $$ |$$ __$$\ $$ __$$ |$$ | $$ | $$ |$$ __$$\ $$ __$$\
33+
// $$ | $$ | $$ |$$ |$$ | \__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ |
34+
// $$ |$$\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ |
35+
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
36+
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/
37+
2938
contract TokenBoundAccount is
3039
Initializable,
3140
ERC1271,
@@ -55,6 +64,8 @@ contract TokenBoundAccount is
5564
/// @notice EIP 4337 Entrypoint contract.
5665
IEntryPoint private immutable entrypointContract;
5766

67+
uint256 public state;
68+
5869
/*///////////////////////////////////////////////////////////////
5970
Constructor, Initializer, Modifiers
6071
//////////////////////////////////////////////////////////////*/
@@ -85,6 +96,17 @@ contract TokenBoundAccount is
8596
return (owner() == _signer);
8697
}
8798

99+
function isValidSigner(address signer, bytes calldata) external view returns (bytes4) {
100+
if (_isValidSigner(signer)) {
101+
return IERC6551Account.isValidSigner.selector;
102+
}
103+
return bytes4(0);
104+
}
105+
106+
function _isValidSigner(address signer) internal view returns (bool) {
107+
return signer == owner();
108+
}
109+
88110
/// @notice See EIP-1271
89111
function isValidSignature(bytes32 _hash, bytes memory _signature)
90112
public
@@ -108,14 +130,6 @@ contract TokenBoundAccount is
108130
return IERC721(tokenContract).ownerOf(tokenId);
109131
}
110132

111-
function executeCall(
112-
address to,
113-
uint256 value,
114-
bytes calldata data
115-
) external payable onlyAdminOrEntrypoint returns (bytes memory result) {
116-
return _call(to, value, data);
117-
}
118-
119133
/// @notice Withdraw funds for this account from Entrypoint.
120134
function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public virtual {
121135
require(owner() == msg.sender, "Account: not NFT owner");
@@ -134,10 +148,6 @@ contract TokenBoundAccount is
134148
return ERC6551AccountLib.token();
135149
}
136150

137-
function nonce() external view returns (uint256) {
138-
return getNonce();
139-
}
140-
141151
/// @notice See {IERC165-supportsInterface}.
142152
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155Receiver) returns (bool) {
143153
return
@@ -191,6 +201,7 @@ contract TokenBoundAccount is
191201
uint256 value,
192202
bytes memory _calldata
193203
) internal virtual returns (bytes memory result) {
204+
++state;
194205
bool success;
195206
(success, result) = _target.call{ value: value }(_calldata);
196207
if (!success) {
Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
// SPDX-License-Identifier: UNLICENSED
1+
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.0;
33

4-
interface IERC6551AccountProxy {
5-
function implementation() external view returns (address);
6-
}
7-
8-
/// @dev the ERC-165 identifier for this interface is `0xeff4d378`
4+
/// @dev the ERC-165 identifier for this interface is `0x6faff5f1`
95
interface IERC6551Account {
10-
event TransactionExecuted(address indexed target, uint256 indexed value, bytes data);
11-
6+
/**
7+
* @dev Allows the account to receive Ether
8+
*
9+
* Accounts MUST implement a `receive` function
10+
*
11+
* Accounts MAY perform arbitrary logic to restrict conditions
12+
* under which Ether can be received
13+
*/
1214
receive() external payable;
1315

14-
function executeCall(
15-
address to,
16-
uint256 value,
17-
bytes calldata data
18-
) external payable returns (bytes memory);
19-
16+
/**
17+
* @dev Returns the identifier of the non-fungible token which owns the account
18+
*
19+
* The return value of this function MUST be constant - it MUST NOT change over time
20+
*
21+
* @return chainId The EIP-155 ID of the chain the token exists on
22+
* @return tokenContract The contract address of the token
23+
* @return tokenId The ID of the token
24+
*/
2025
function token()
2126
external
2227
view
@@ -26,7 +31,28 @@ interface IERC6551Account {
2631
uint256 tokenId
2732
);
2833

29-
function owner() external view returns (address);
34+
/**
35+
* @dev Returns a value that SHOULD be modified each time the account changes state
36+
*
37+
* @return The current account state
38+
*/
39+
function state() external view returns (uint256);
3040

31-
function nonce() external view returns (uint256);
41+
/**
42+
* @dev Returns a magic value indicating whether a given signer is authorized to act on behalf
43+
* of the account
44+
*
45+
* MUST return the bytes4 magic value 0x523e3260 if the given signer is valid
46+
*
47+
* By default, the holder of the non-fungible token the account is bound to MUST be considered
48+
* a valid signer
49+
*
50+
* Accounts MAY implement additional authorization logic which invalidates the holder as a
51+
* signer or grants signing permissions to other non-holder accounts
52+
*
53+
* @param signer The address to check signing authorization for
54+
* @param context Additional data used to determine whether the signer is valid
55+
* @return magicValue Magic value indicating whether the signer is valid
56+
*/
57+
function isValidSigner(address signer, bytes calldata context) external view returns (bytes4 magicValue);
3258
}

0 commit comments

Comments
 (0)