Skip to content

Commit

Permalink
Merge the develop branch to the master branch, preparation to v2.0.0-rc3
Browse files Browse the repository at this point in the history
This update for the master branch contains the following set of changes:
  * [Improvement] Add interfaces version methods (#30), closes #14
  * [Improvement] Override supportsInterface in ERC721 and ERC1155 tokens (#31)
  • Loading branch information
akolotov authored May 26, 2021
2 parents 75902ce + fca0e37 commit 9702180
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
36 changes: 36 additions & 0 deletions contracts/tokens/ERC1155BridgeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ contract ERC1155BridgeToken is ERC1155, IBurnableMintableERC1155Token {
_;
}

/**
* @dev Tells if this contract implements the interface defined by
* `interfaceId`. See the corresponding EIP165.
* @return true, if interface is implemented.
*/
function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
bytes4 INTERFACE_ID_ERC165 = 0x01ffc9a7;
bytes4 INTERFACE_ID_ERC1155 = 0xd9b67a26;
bytes4 INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c;
return
interfaceId == INTERFACE_ID_ERC165 ||
interfaceId == INTERFACE_ID_ERC1155 ||
interfaceId == INTERFACE_ID_ERC1155_METADATA_URI;
}

/**
* @dev Stub for preventing unneeded storage writes.
* All supported interfaces are hardcoded in the supportsInterface function.
*/
function _registerInterface(bytes4) internal override {}

/**
* @dev Mint a batch of new ERC1155 tokens.
* Only bridge contract is authorized to mint tokens.
Expand Down Expand Up @@ -115,4 +136,19 @@ contract ERC1155BridgeToken is ERC1155, IBurnableMintableERC1155Token {
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
return string(abi.encodePacked(base, tokenURI));
}

/**
* @dev Tells the current version of the ERC1155 token interfaces.
*/
function getTokenInterfacesVersion()
external
pure
returns (
uint64 major,
uint64 minor,
uint64 patch
)
{
return (1, 0, 1);
}
}
38 changes: 38 additions & 0 deletions contracts/tokens/ERC721BridgeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ contract ERC721BridgeToken is ERC721, IBurnableMintableERC721Token {
_;
}

/**
* @dev Tells if this contract implements the interface defined by
* `interfaceId`. See the corresponding EIP165.
* @return true, if interface is implemented.
*/
function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
bytes4 INTERFACE_ID_ERC165 = 0x01ffc9a7;
bytes4 INTERFACE_ID_ERC721 = 0x80ac58cd;
bytes4 INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;
bytes4 INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;
return
interfaceId == INTERFACE_ID_ERC165 ||
interfaceId == INTERFACE_ID_ERC721 ||
interfaceId == INTERFACE_ID_ERC721_METADATA ||
interfaceId == INTERFACE_ID_ERC721_ENUMERABLE;
}

/**
* @dev Stub for preventing unneeded storage writes.
* All supported interfaces are hardcoded in the supportsInterface function.
*/
function _registerInterface(bytes4) internal override {}

/**
* @dev Mint new ERC721 token.
* Only bridge contract is authorized to mint tokens.
Expand Down Expand Up @@ -82,4 +105,19 @@ contract ERC721BridgeToken is ERC721, IBurnableMintableERC721Token {
function setTokenURI(uint256 _tokenId, string calldata _tokenURI) external override onlyOwner {
_setTokenURI(_tokenId, _tokenURI);
}

/**
* @dev Tells the current version of the ERC721 token interfaces.
*/
function getTokenInterfacesVersion()
external
pure
returns (
uint64 major,
uint64 minor,
uint64 patch
)
{
return (1, 0, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,19 @@ contract ERC1155TokenProxy is Proxy {
sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, _implementation)
}
}

/**
* @dev Tells the current version of the ERC1155 token proxy interfaces.
*/
function getTokenProxyInterfacesVersion()
external
pure
returns (
uint64 major,
uint64 minor,
uint64 patch
)
{
return (1, 0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,19 @@ contract ERC721TokenProxy is Proxy {
sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, _implementation)
}
}

/**
* @dev Tells the current version of the ERC721 token proxy interfaces.
*/
function getTokenProxyInterfacesVersion()
external
pure
returns (
uint64 major,
uint64 minor,
uint64 patch
)
{
return (1, 0, 0);
}
}
12 changes: 12 additions & 0 deletions test/omnibridge_nft/common.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const ForeignNFTOmnibridge = artifacts.require('ForeignNFTOmnibridge')
const EternalStorageProxy = artifacts.require('EternalStorageProxy')
const AMBMock = artifacts.require('AMBMock')
const ERC721BridgeToken = artifacts.require('ERC721BridgeToken')
const ERC721TokenProxy = artifacts.require('ERC721TokenProxy')
const ERC1155BridgeToken = artifacts.require('ERC1155BridgeToken')
const ERC1155TokenProxy = artifacts.require('ERC1155TokenProxy')
const ERC1155ReceiverMock = artifacts.require('ERC1155ReceiverMock')
const NFTForwardingRulesManager = artifacts.require('NFTForwardingRulesManager')
const SelectorTokenGasLimitManager = artifacts.require('SelectorTokenGasLimitManager')
Expand Down Expand Up @@ -1076,8 +1078,13 @@ function runTests(accounts, isHome) {
const { nativeToken, bridgedToken } = events[0].returnValues
expect(nativeToken).to.be.equal(otherSideToken1)
const deployedToken = await ERC721BridgeToken.at(bridgedToken)
const deployedTokenProxy = await ERC721TokenProxy.at(bridgedToken)

expect(await deployedToken.name()).to.be.equal(modifyName('Test'))
const v1 = await deployedToken.getTokenInterfacesVersion()
const v2 = await deployedTokenProxy.getTokenProxyInterfacesVersion()
expect(v1.major).to.be.bignumber.gte(ZERO)
expect(v2.major).to.be.bignumber.gte(ZERO)
expect(await deployedToken.symbol()).to.be.equal('TST')
expect(await contract.nativeTokenAddress(bridgedToken)).to.be.equal(nativeToken)
expect(await contract.bridgedTokenAddress(nativeToken)).to.be.equal(bridgedToken)
Expand Down Expand Up @@ -1650,9 +1657,14 @@ function runTests(accounts, isHome) {
const { nativeToken, bridgedToken } = events[0].returnValues
expect(nativeToken).to.be.equal(otherSideToken1)
const deployedToken = await ERC1155BridgeToken.at(bridgedToken)
const deployedTokenProxy = await ERC1155TokenProxy.at(bridgedToken)

expect(await deployedToken.name()).to.be.equal(modifyName('Test'))
expect(await deployedToken.symbol()).to.be.equal('TST')
const v1 = await deployedToken.getTokenInterfacesVersion()
const v2 = await deployedTokenProxy.getTokenProxyInterfacesVersion()
expect(v1.major).to.be.bignumber.gte(ZERO)
expect(v2.major).to.be.bignumber.gte(ZERO)
expect(await contract.nativeTokenAddress(bridgedToken)).to.be.equal(nativeToken)
expect(await contract.bridgedTokenAddress(nativeToken)).to.be.equal(bridgedToken)

Expand Down

0 comments on commit 9702180

Please sign in to comment.