Skip to content

Commit

Permalink
Update EIP-6059 interface (ethereum#6637)
Browse files Browse the repository at this point in the history
This commit renames the interface of EIP-6059 from Nestable to ERC-6059.
It also updates the example suite to use the new interface.
  • Loading branch information
ThunderDeliverer authored Mar 7, 2023
1 parent c0b43d1 commit 32ab439
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion EIPS/eip-6059.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL
pragma solidity ^0.8.16;
interface INestable {
interface IERC6059 /* is ERC165 */ {
/**
* @notice The core struct of ownership.
* @dev The `DirectOwner` struct is used to store information of the next immediate owner, be it the parent token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.16;


interface INestable {
interface IERC6059 {
struct DirectOwner {
uint256 tokenId;
address ownerAddress;
Expand Down
22 changes: 11 additions & 11 deletions assets/eip-6059/contracts/NestableToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

pragma solidity ^0.8.16;

import "./INestable.sol";
import "./IERC6059.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
Expand Down Expand Up @@ -46,7 +46,7 @@ error UnexpectedNumberOfChildren();
* @dev This contract is hierarchy agnostic and can support an arbitrary number of nested levels up and down, as long as
* gas limits allow it.
*/
contract NestableToken is Context, IERC165, IERC721, INestable {
contract NestableToken is Context, IERC165, IERC721, IERC6059 {
using Address for address;

uint256 private constant _MAX_LEVELS_TO_CHECK_FOR_INHERITANCE_LOOP = 100;
Expand Down Expand Up @@ -133,7 +133,7 @@ contract NestableToken is Context, IERC165, IERC721, INestable {
interfaceId == type(IERC165).interfaceId ||
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
interfaceId == type(INestable).interfaceId;
interfaceId == type(IERC6059).interfaceId;
}

/**
Expand Down Expand Up @@ -291,7 +291,7 @@ contract NestableToken is Context, IERC165, IERC721, INestable {
// Destination contract checks:
// It seems redundant, but otherwise it would revert with no error
if (!to.isContract()) revert IsNotContract();
if (!IERC165(to).supportsInterface(type(INestable).interfaceId))
if (!IERC165(to).supportsInterface(type(IERC6059).interfaceId))
revert NestableTransferToNonNestableImplementer();
_checkForInheritanceLoop(tokenId, to, destinationId);

Expand Down Expand Up @@ -331,7 +331,7 @@ contract NestableToken is Context, IERC165, IERC721, INestable {
uint256 tokenId,
bytes memory data
) private {
INestable destContract = INestable(to);
IERC6059 destContract = IERC6059(to);
destContract.addChild(destinationId, tokenId, data);
_afterTokenTransfer(from, to, tokenId);
_afterNestedTokenTransfer(from, to, parentId, destinationId, tokenId);
Expand Down Expand Up @@ -359,7 +359,7 @@ contract NestableToken is Context, IERC165, IERC721, INestable {
address nextOwner,
uint256 nextOwnerTokenId,
bool isNft
) = INestable(targetContract).directOwnerOf(targetId);
) = IERC6059(targetContract).directOwnerOf(targetId);
// If there's a final address, we're good. There's no loop.
if (!isNft) {
return;
Expand Down Expand Up @@ -449,7 +449,7 @@ contract NestableToken is Context, IERC165, IERC721, INestable {
) internal virtual {
// It seems redundant, but otherwise it would revert with no error
if (!to.isContract()) revert IsNotContract();
if (!IERC165(to).supportsInterface(type(INestable).interfaceId))
if (!IERC165(to).supportsInterface(type(IERC6059).interfaceId))
revert MintToNonNestableImplementer();

_innerMint(to, tokenId, destinationId);
Expand Down Expand Up @@ -501,12 +501,12 @@ contract NestableToken is Context, IERC165, IERC721, INestable {
*/
function ownerOf(
uint256 tokenId
) public view virtual override(INestable, IERC721) returns (address) {
) public view virtual override(IERC6059, IERC721) returns (address) {
(address owner, uint256 ownerTokenId, bool isNft) = directOwnerOf(
tokenId
);
if (isNft) {
owner = INestable(owner).ownerOf(ownerTokenId);
owner = IERC6059(owner).ownerOf(ownerTokenId);
}
return owner;
}
Expand Down Expand Up @@ -622,7 +622,7 @@ contract NestableToken is Context, IERC165, IERC721, INestable {
// We substract one to the next level to count for the token being burned, then add it again on returns
// This is to allow the behavior of 0 recursive burns meaning only the current token is deleted.
totalChildBurns +=
INestable(children[i].contractAddress).burn(
IERC6059(children[i].contractAddress).burn(
children[i].tokenId,
pendingRecursiveBurns - 1
) +
Expand Down Expand Up @@ -1090,7 +1090,7 @@ contract NestableToken is Context, IERC165, IERC721, INestable {
);
} else {
// Destination is an NFT
INestable(child.contractAddress).nestTransferFrom(
IERC6059(child.contractAddress).nestTransferFrom(
address(this),
to,
child.tokenId,
Expand Down
2 changes: 1 addition & 1 deletion assets/eip-6059/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "nestable-tokens",
"name": "erc-6059",
"dependencies": {
"@openzeppelin/contracts": "^4.6.0"
},
Expand Down
6 changes: 3 additions & 3 deletions assets/eip-6059/test/nestable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe('NestableToken', function () {
expect(await parent.supportsInterface('0x80ac58cd')).to.equal(true);
});

it('can support INestable', async function () {
it('can support IERC6059', async function () {
expect(await parent.supportsInterface('0x42b0e56f')).to.equal(true);
});

Expand Down Expand Up @@ -1115,7 +1115,7 @@ describe('NestableToken', function () {
).to.be.revertedWithCustomError(child, 'IsNotContract');
});

it('cannot nest tranfer to contract if it does implement INestable', async function () {
it('cannot nest tranfer to contract if it does implement IERC6059', async function () {
const ERC721 = await ethers.getContractFactory('ERC721Mock');
const nonNestable = await ERC721.deploy('Non receiver', 'NR');
await nonNestable.deployed();
Expand All @@ -1124,7 +1124,7 @@ describe('NestableToken', function () {
).to.be.revertedWithCustomError(child, 'NestableTransferToNonNestableImplementer');
});

it('can nest tranfer to INestable contract', async function () {
it('can nest tranfer to IERC6059 contract', async function () {
await child.connect(firstOwner).nestTransfer(parent.address, childId1, parentId);
expect(await child.ownerOf(childId1)).to.eql(firstOwner.address);
expect(await child.directOwnerOf(childId1)).to.eql([parent.address, bn(parentId), true]);
Expand Down

0 comments on commit 32ab439

Please sign in to comment.