Skip to content
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ forge test
```

For more information on writing and running tests, refer to the [Foundry testing guide](https://github.com/foundry-rs/book/blob/master/src/forge/writing-tests.md).


## History

**0.2.1**

- Making examples' functions `virtual` and `public` so that the examples can be used as a base for more advanced contracts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "erc6551-reference",
"version": "0.2.0",
"version": "0.2.1",
"scripts": {
"test": "forge test",
"prettier": "prettier --write '{**/*,*}.{js,ts,tsx,md,mdx,yml,sol}'",
Expand Down
14 changes: 8 additions & 6 deletions src/examples/simple/SimpleERC6551Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract SimpleERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Exe
uint256 value,
bytes calldata data,
uint256 operation
) external payable returns (bytes memory result) {
) public payable virtual returns (bytes memory result) {
require(_isValidSigner(msg.sender), "Invalid signer");
require(operation == 0, "Only call operations are supported");

Expand All @@ -35,7 +35,7 @@ contract SimpleERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Exe
}
}

function isValidSigner(address signer, bytes calldata) external view returns (bytes4) {
function isValidSigner(address signer, bytes calldata) public view virtual returns (bytes4) {
if (_isValidSigner(signer)) {
return IERC6551Account.isValidSigner.selector;
}
Expand All @@ -44,8 +44,9 @@ contract SimpleERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Exe
}

function isValidSignature(bytes32 hash, bytes memory signature)
external
public
view
virtual
returns (bytes4 magicValue)
{
bool isValid = SignatureChecker.isValidSignatureNow(owner(), hash, signature);
Expand All @@ -57,7 +58,7 @@ contract SimpleERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Exe
return "";
}

function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool) {
return (interfaceId == type(IERC165).interfaceId ||
interfaceId == type(IERC6551Account).interfaceId ||
interfaceId == type(IERC6551Executable).interfaceId);
Expand All @@ -66,6 +67,7 @@ contract SimpleERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Exe
function token()
public
view
virtual
returns (
uint256,
address,
Expand All @@ -81,14 +83,14 @@ contract SimpleERC6551Account is IERC165, IERC1271, IERC6551Account, IERC6551Exe
return abi.decode(footer, (uint256, address, uint256));
}

function owner() public view returns (address) {
function owner() public view virtual returns (address) {
(uint256 chainId, address tokenContract, uint256 tokenId) = token();
if (chainId != block.chainid) return address(0);

return IERC721(tokenContract).ownerOf(tokenId);
}

function _isValidSigner(address signer) internal view returns (bool) {
function _isValidSigner(address signer) internal view virtual returns (bool) {
return signer == owner();
}
}
26 changes: 13 additions & 13 deletions src/examples/upgradeable/ERC6551AccountUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract ERC6551AccountUpgradeable is
uint256 _value,
bytes calldata _data,
uint256 _operation
) external payable override returns (bytes memory _result) {
) public payable virtual override returns (bytes memory _result) {
require(_isValidSigner(msg.sender), "Caller is not owner");
require(_operation == 0, "Only call operations are supported");
++state;
Expand All @@ -62,16 +62,16 @@ contract ERC6551AccountUpgradeable is
/**
* @dev Upgrades the implementation. Only the token owner can call this.
*/
function upgrade(address implementation_) external {
function upgrade(address implementation_) public virtual {
require(_isValidSigner(msg.sender), "Caller is not owner");
require(implementation_ != address(0), "Invalid implementation address");
++state;
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = implementation_;
}

function isValidSignature(bytes32 hash, bytes memory signature)
external
view
public
view virtual
returns (bytes4 magicValue)
{
bool isValid = SignatureChecker.isValidSignatureNow(owner(), hash, signature);
Expand All @@ -82,7 +82,7 @@ contract ERC6551AccountUpgradeable is
return "";
}

function isValidSigner(address signer, bytes calldata) external view returns (bytes4) {
function isValidSigner(address signer, bytes calldata) public view virtual returns (bytes4) {
if (_isValidSigner(signer)) {
return IERC6551Account.isValidSigner.selector;
}
Expand All @@ -95,7 +95,7 @@ contract ERC6551AccountUpgradeable is
address,
uint256 receivedTokenId,
bytes memory
) external view returns (bytes4) {
) public view virtual returns (bytes4) {
_revertIfOwnershipCycle(msg.sender, receivedTokenId);
return IERC721Receiver.onERC721Received.selector;
}
Expand All @@ -106,7 +106,7 @@ contract ERC6551AccountUpgradeable is
uint256,
uint256,
bytes memory
) external pure returns (bytes4) {
) public pure virtual returns (bytes4) {
return IERC1155Receiver.onERC1155Received.selector;
}

Expand All @@ -116,11 +116,11 @@ contract ERC6551AccountUpgradeable is
uint256[] memory,
uint256[] memory,
bytes memory
) external pure returns (bytes4) {
) public pure virtual returns (bytes4) {
return IERC1155Receiver.onERC1155BatchReceived.selector;
}

function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool) {
return (interfaceId == type(IERC6551Account).interfaceId ||
interfaceId == type(IERC6551Executable).interfaceId ||
interfaceId == type(IERC1155Receiver).interfaceId ||
Expand All @@ -133,7 +133,7 @@ contract ERC6551AccountUpgradeable is
*/
function token()
public
view
view virtual
override
returns (
uint256,
Expand All @@ -147,13 +147,13 @@ contract ERC6551AccountUpgradeable is
/**
* @dev {See IERC6551Account-owner}
*/
function owner() public view returns (address) {
function owner() public view virtual returns (address) {
(uint256 chainId, address contractAddress, uint256 tokenId) = token();
if (chainId != block.chainid) return address(0);
return IERC721(contractAddress).ownerOf(tokenId);
}

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

Expand All @@ -164,7 +164,7 @@ contract ERC6551AccountUpgradeable is
*/
function _revertIfOwnershipCycle(address receivedTokenAddress, uint256 receivedTokenId)
internal
view
view virtual
{
(uint256 _chainId, address _contractAddress, uint256 _tokenId) = token();
require(
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erc6551/reference",
"version": "0.2.0",
"version": "0.2.1",
"files": [
"**/*.sol"
],
Expand Down