Skip to content

Commit

Permalink
Add upgradeable contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk committed May 24, 2023
1 parent a98cacc commit 9770473
Show file tree
Hide file tree
Showing 25 changed files with 3,443 additions and 546 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "../tokens/ERC1155PackedBalanceUpgradeable/ERC1155MetaPackedBalanceUpgradeable.sol";
import "../tokens/ERC1155PackedBalanceUpgradeable/ERC1155MintBurnPackedBalanceUpgradeable.sol";
import "../tokens/ERC1155Upgradeable/ERC1155MetadataUpgradeable.sol";


contract ERC1155MetaMintBurnPackedBalanceUpgradeableMock is ERC1155MintBurnPackedBalanceUpgradeable, ERC1155MetaPackedBalanceUpgradeable, ERC1155MetadataUpgradeable {

/***********************************|
| ERC165 |
|__________________________________*/

/**
* @notice Query if a contract implements an interface
* @dev Parent contract inheriting multiple contracts with supportsInterface()
* need to implement an overriding supportsInterface() function specifying
* all inheriting contracts that have a supportsInterface() function.
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID`
*/
function supportsInterface(
bytes4 _interfaceID
) public override(
ERC1155PackedBalanceUpgradeable,
ERC1155MetadataUpgradeable
) view virtual returns (bool) {
return super.supportsInterface(_interfaceID);
}

/***********************************|
| Minting Functions |
|__________________________________*/

/**
* @dev Mint _value of tokens of a given id
* @param _to The address to mint tokens to.
* @param _id token id to mint
* @param _value The amount to be minted
* @param _data Data to be passed if receiver is contract
*/
function mintMock(address _to, uint256 _id, uint256 _value, bytes memory _data)
public
{
_mint(_to, _id, _value, _data);
}

/**
* @dev Mint tokens for each ids in _ids
* @param _to The address to mint tokens to.
* @param _ids Array of ids to mint
* @param _values Array of amount of tokens to mint per id
* @param _data Data to be passed if receiver is contract
*/
function batchMintMock(address _to, uint256[] memory _ids, uint256[] memory _values, bytes memory _data)
public
{
_batchMint(_to, _ids, _values, _data);
}


/***********************************|
| Burning Functions |
|__________________________________*/

/**
* @dev burn _value of tokens of a given token id
* @param _from The address to burn tokens from.
* @param _id token id to burn
* @param _value The amount to be burned
*/
function burnMock(address _from, uint256 _id, uint256 _value)
public
{
_burn(_from, _id, _value);
}

/**
* @dev burn _value of tokens of a given token id
* @param _from The address to burn tokens from.
* @param _ids Array of token ids to burn
* @param _values Array of the amount to be burned
*/
function batchBurnMock(address _from, uint256[] memory _ids, uint256[] memory _values)
public
{
_batchBurn(_from, _ids, _values);
}


/***********************************|
| Unsupported Functions |
|__________________________________*/

fallback () external {
revert("ERC1155MetaMintBurnPackedBalanceMock: INVALID_METHOD");
}
}
94 changes: 94 additions & 0 deletions src/contracts/mocks/ERC1155MetaMintBurnUpgradeableMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "../tokens/ERC1155Upgradeable/ERC1155MetaUpgradeable.sol";
import "../tokens/ERC1155Upgradeable/ERC1155MintBurnUpgradeable.sol";
import "../tokens/ERC1155Upgradeable/ERC1155MetadataUpgradeable.sol";


contract ERC1155MetaMintBurnUpgradeableMock is ERC1155MetaUpgradeable, ERC1155MintBurnUpgradeable, ERC1155MetadataUpgradeable {

/**
* @notice Query if a contract implements an interface
* @dev Parent contract inheriting multiple contracts with supportsInterface()
* need to implement an overriding supportsInterface() function specifying
* all inheriting contracts that have a supportsInterface() function.
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID`
*/
function supportsInterface(
bytes4 _interfaceID
) public override(
ERC1155Upgradeable,
ERC1155MetadataUpgradeable
) view virtual returns (bool) {
return super.supportsInterface(_interfaceID);
}

/***********************************|
| Minting Functions |
|__________________________________*/

/**
* @dev Mint _value of tokens of a given id
* @param _to The address to mint tokens to.
* @param _id token id to mint
* @param _value The amount to be minted
* @param _data Data to be passed if receiver is contract
*/
function mintMock(address _to, uint256 _id, uint256 _value, bytes memory _data)
public
{
super._mint(_to, _id, _value, _data);
}

/**
* @dev Mint tokens for each ids in _ids
* @param _to The address to mint tokens to.
* @param _ids Array of ids to mint
* @param _values Array of amount of tokens to mint per id
* @param _data Data to be passed if receiver is contract
*/
function batchMintMock(address _to, uint256[] memory _ids, uint256[] memory _values, bytes memory _data)
public
{
super._batchMint(_to, _ids, _values, _data);
}


/***********************************|
| Burning Functions |
|__________________________________*/

/**
* @dev burn _value of tokens of a given token id
* @param _from The address to burn tokens from.
* @param _id token id to burn
* @param _value The amount to be burned
*/
function burnMock(address _from, uint256 _id, uint256 _value)
public
{
super._burn(_from, _id, _value);
}

/**
* @dev burn _value of tokens of a given token id
* @param _from The address to burn tokens from.
* @param _ids Array of token ids to burn
* @param _values Array of the amount to be burned
*/
function batchBurnMock(address _from, uint256[] memory _ids, uint256[] memory _values)
public
{
super._batchBurn(_from, _ids, _values);
}

/***********************************|
| Unsupported Functions |
|__________________________________*/

fallback () virtual external {
revert("ERC1155MetaMintBurnMock: INVALID_METHOD");
}
}
77 changes: 77 additions & 0 deletions src/contracts/mocks/ERC1155MetadataUpgradeableMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "../tokens/ERC1155Upgradeable/ERC1155MintBurnUpgradeable.sol";
import "../tokens/ERC1155Upgradeable/ERC1155MetadataUpgradeable.sol";

contract ERC1155MetadataUpgradeableMock is ERC1155MintBurnUpgradeable, ERC1155MetadataUpgradeable {

/***********************************|
| Base URI Functions |
|__________________________________*/

/**
* @notice Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(string memory _newBaseMetadataURI) public {
super._setBaseMetadataURI(_newBaseMetadataURI);
}

/***********************************|
| Log URI Functions |
|__________________________________*/

/**
* @notice Will emit default URI log event for corresponding token _id
* @param _tokenIDs Array of IDs of tokens to log default URI
*/
function logURIsMock(uint256[] memory _tokenIDs) public {
super._logURIs(_tokenIDs);
}

/***********************************|
| Unsupported Functions |
|__________________________________*/

fallback () external {
revert('ERC1155MetadataMock: INVALID_METHOD');
}


/***********************************|
| ERC-165 Functions |
|__________________________________*/

/**
* @notice Query if a contract implements an interface
* @dev Parent contract inheriting multiple contracts with supportsInterface()
* need to implement an overriding supportsInterface() function specifying
* all inheriting contracts that have a supportsInterface() function.
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID`
*/
function supportsInterface(
bytes4 _interfaceID
) public override(
ERC1155Upgradeable,
ERC1155MetadataUpgradeable
) view virtual returns (bool) {
return super.supportsInterface(_interfaceID);
}
}

/**
* A v2 implementation to test upgradeability.
*/
contract ERC1155MetadataUpgradeableMockV2 is ERC1155MetadataUpgradeableMock {
mapping(uint256 => uint256) private idMapping;

function setIdMapping(uint256 _id, uint256 _mappedId) public {
idMapping[_id] = _mappedId;
}

function uri(uint256 _id) public override view returns (string memory) {
return string(abi.encodePacked(baseURI, _uint2str(idMapping[_id]))); // Removes .json extension, swaps ids
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "../tokens/ERC1155PackedBalanceUpgradeable/ERC1155MintBurnPackedBalanceUpgradeable.sol";
import "../tokens/ERC1155Upgradeable/ERC1155MetadataUpgradeable.sol";


contract ERC1155MintBurnPackedBalanceUpgradeableMock is ERC1155MintBurnPackedBalanceUpgradeable, ERC1155MetadataUpgradeable {

/***********************************|
| ERC165 |
|__________________________________*/

/**
* @notice Query if a contract implements an interface
* @dev Parent contract inheriting multiple contracts with supportsInterface()
* need to implement an overriding supportsInterface() function specifying
* all inheriting contracts that have a supportsInterface() function.
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID`
*/
function supportsInterface(
bytes4 _interfaceID
) public override(
ERC1155PackedBalanceUpgradeable,
ERC1155MetadataUpgradeable
) view virtual returns (bool) {
return super.supportsInterface(_interfaceID);
}

/***********************************|
| Minting Functions |
|__________________________________*/

/**
* @dev Mint _value of tokens of a given id
* @param _to The address to mint tokens to.
* @param _id token id to mint
* @param _value The amount to be minted
* @param _data Data to be passed if receiver is contract
*/
function mintMock(address _to, uint256 _id, uint256 _value, bytes memory _data)
public
{
_mint(_to, _id, _value, _data);
}

/**
* @dev Mint tokens for each ids in _ids
* @param _to The address to mint tokens to.
* @param _ids Array of ids to mint
* @param _values Array of amount of tokens to mint per id
* @param _data Data to be passed if receiver is contract
*/
function batchMintMock(address _to, uint256[] memory _ids, uint256[] memory _values, bytes memory _data)
public
{
_batchMint(_to, _ids, _values, _data);
}


/***********************************|
| Burning Functions |
|__________________________________*/

/**
* @dev burn _value of tokens of a given token id
* @param _from The address to burn tokens from.
* @param _id token id to burn
* @param _value The amount to be burned
*/
function burnMock(address _from, uint256 _id, uint256 _value)
public
{
_burn(_from, _id, _value);
}

/**
* @dev burn _value of tokens of a given token id
* @param _from The address to burn tokens from.
* @param _ids Array of token ids to burn
* @param _values Array of the amount to be burned
*/
function batchBurnMock(address _from, uint256[] memory _ids, uint256[] memory _values)
public
{
_batchBurn(_from, _ids, _values);
}


/***********************************|
| Unsupported Functions |
|__________________________________*/

fallback () external {
revert("ERC1155MetaMintBurnPackedBalanceMock: INVALID_METHOD");
}
}
Loading

0 comments on commit 9770473

Please sign in to comment.