Skip to content

tba new interface #491

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

Merged
merged 7 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: Apache 2.0
pragma solidity ^0.8.0;

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

// $$\ $$\ $$\ $$\ $$\
// $$ | $$ | \__| $$ | $$ |
// $$$$$$\ $$$$$$$\ $$\ $$$$$$\ $$$$$$$ |$$\ $$\ $$\ $$$$$$\ $$$$$$$\
// \_$$ _| $$ __$$\ $$ |$$ __$$\ $$ __$$ |$$ | $$ | $$ |$$ __$$\ $$ __$$\
// $$ | $$ | $$ |$$ |$$ | \__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ |
// $$ |$$\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ |
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

contract TokenBoundAccount is
Initializable,
ERC1271,
Expand Down Expand Up @@ -55,6 +64,8 @@ contract TokenBoundAccount is
/// @notice EIP 4337 Entrypoint contract.
IEntryPoint private immutable entrypointContract;

uint256 public state;

/*///////////////////////////////////////////////////////////////
Constructor, Initializer, Modifiers
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -85,6 +96,17 @@ contract TokenBoundAccount is
return (owner() == _signer);
}

function isValidSigner(address signer, bytes calldata) external view returns (bytes4) {
if (_isValidSigner(signer)) {
return IERC6551Account.isValidSigner.selector;
}
return bytes4(0);
}

function _isValidSigner(address signer) internal view returns (bool) {
return signer == owner();
}

/// @notice See EIP-1271
function isValidSignature(bytes32 _hash, bytes memory _signature)
public
Expand All @@ -108,14 +130,6 @@ contract TokenBoundAccount is
return IERC721(tokenContract).ownerOf(tokenId);
}

function executeCall(
address to,
uint256 value,
bytes calldata data
) external payable onlyAdminOrEntrypoint returns (bytes memory result) {
return _call(to, value, data);
}

/// @notice Withdraw funds for this account from Entrypoint.
function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public virtual {
require(owner() == msg.sender, "Account: not NFT owner");
Expand All @@ -134,10 +148,6 @@ contract TokenBoundAccount is
return ERC6551AccountLib.token();
}

function nonce() external view returns (uint256) {
return getNonce();
}

/// @notice See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155Receiver) returns (bool) {
return
Expand Down Expand Up @@ -191,6 +201,7 @@ contract TokenBoundAccount is
uint256 value,
bytes memory _calldata
) internal virtual returns (bytes memory result) {
++state;
bool success;
(success, result) = _target.call{ value: value }(_calldata);
if (!success) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IERC6551AccountProxy {
function implementation() external view returns (address);
}

/// @dev the ERC-165 identifier for this interface is `0xeff4d378`
/// @dev the ERC-165 identifier for this interface is `0x6faff5f1`
interface IERC6551Account {
event TransactionExecuted(address indexed target, uint256 indexed value, bytes data);

/**
* @dev Allows the account to receive Ether
*
* Accounts MUST implement a `receive` function
*
* Accounts MAY perform arbitrary logic to restrict conditions
* under which Ether can be received
*/
receive() external payable;

function executeCall(
address to,
uint256 value,
bytes calldata data
) external payable returns (bytes memory);

/**
* @dev Returns the identifier of the non-fungible token which owns the account
*
* The return value of this function MUST be constant - it MUST NOT change over time
*
* @return chainId The EIP-155 ID of the chain the token exists on
* @return tokenContract The contract address of the token
* @return tokenId The ID of the token
*/
function token()
external
view
Expand All @@ -26,7 +31,28 @@ interface IERC6551Account {
uint256 tokenId
);

function owner() external view returns (address);
/**
* @dev Returns a value that SHOULD be modified each time the account changes state
*
* @return The current account state
*/
function state() external view returns (uint256);

function nonce() external view returns (uint256);
/**
* @dev Returns a magic value indicating whether a given signer is authorized to act on behalf
* of the account
*
* MUST return the bytes4 magic value 0x523e3260 if the given signer is valid
*
* By default, the holder of the non-fungible token the account is bound to MUST be considered
* a valid signer
*
* Accounts MAY implement additional authorization logic which invalidates the holder as a
* signer or grants signing permissions to other non-holder accounts
*
* @param signer The address to check signing authorization for
* @param context Additional data used to determine whether the signer is valid
* @return magicValue Magic value indicating whether the signer is valid
*/
function isValidSigner(address signer, bytes calldata context) external view returns (bytes4 magicValue);
}