Skip to content

Commit 9770473

Browse files
committed
Add upgradeable contracts
1 parent a98cacc commit 9770473

25 files changed

+3443
-546
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "../tokens/ERC1155PackedBalanceUpgradeable/ERC1155MetaPackedBalanceUpgradeable.sol";
5+
import "../tokens/ERC1155PackedBalanceUpgradeable/ERC1155MintBurnPackedBalanceUpgradeable.sol";
6+
import "../tokens/ERC1155Upgradeable/ERC1155MetadataUpgradeable.sol";
7+
8+
9+
contract ERC1155MetaMintBurnPackedBalanceUpgradeableMock is ERC1155MintBurnPackedBalanceUpgradeable, ERC1155MetaPackedBalanceUpgradeable, ERC1155MetadataUpgradeable {
10+
11+
/***********************************|
12+
| ERC165 |
13+
|__________________________________*/
14+
15+
/**
16+
* @notice Query if a contract implements an interface
17+
* @dev Parent contract inheriting multiple contracts with supportsInterface()
18+
* need to implement an overriding supportsInterface() function specifying
19+
* all inheriting contracts that have a supportsInterface() function.
20+
* @param _interfaceID The interface identifier, as specified in ERC-165
21+
* @return `true` if the contract implements `_interfaceID`
22+
*/
23+
function supportsInterface(
24+
bytes4 _interfaceID
25+
) public override(
26+
ERC1155PackedBalanceUpgradeable,
27+
ERC1155MetadataUpgradeable
28+
) view virtual returns (bool) {
29+
return super.supportsInterface(_interfaceID);
30+
}
31+
32+
/***********************************|
33+
| Minting Functions |
34+
|__________________________________*/
35+
36+
/**
37+
* @dev Mint _value of tokens of a given id
38+
* @param _to The address to mint tokens to.
39+
* @param _id token id to mint
40+
* @param _value The amount to be minted
41+
* @param _data Data to be passed if receiver is contract
42+
*/
43+
function mintMock(address _to, uint256 _id, uint256 _value, bytes memory _data)
44+
public
45+
{
46+
_mint(_to, _id, _value, _data);
47+
}
48+
49+
/**
50+
* @dev Mint tokens for each ids in _ids
51+
* @param _to The address to mint tokens to.
52+
* @param _ids Array of ids to mint
53+
* @param _values Array of amount of tokens to mint per id
54+
* @param _data Data to be passed if receiver is contract
55+
*/
56+
function batchMintMock(address _to, uint256[] memory _ids, uint256[] memory _values, bytes memory _data)
57+
public
58+
{
59+
_batchMint(_to, _ids, _values, _data);
60+
}
61+
62+
63+
/***********************************|
64+
| Burning Functions |
65+
|__________________________________*/
66+
67+
/**
68+
* @dev burn _value of tokens of a given token id
69+
* @param _from The address to burn tokens from.
70+
* @param _id token id to burn
71+
* @param _value The amount to be burned
72+
*/
73+
function burnMock(address _from, uint256 _id, uint256 _value)
74+
public
75+
{
76+
_burn(_from, _id, _value);
77+
}
78+
79+
/**
80+
* @dev burn _value of tokens of a given token id
81+
* @param _from The address to burn tokens from.
82+
* @param _ids Array of token ids to burn
83+
* @param _values Array of the amount to be burned
84+
*/
85+
function batchBurnMock(address _from, uint256[] memory _ids, uint256[] memory _values)
86+
public
87+
{
88+
_batchBurn(_from, _ids, _values);
89+
}
90+
91+
92+
/***********************************|
93+
| Unsupported Functions |
94+
|__________________________________*/
95+
96+
fallback () external {
97+
revert("ERC1155MetaMintBurnPackedBalanceMock: INVALID_METHOD");
98+
}
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "../tokens/ERC1155Upgradeable/ERC1155MetaUpgradeable.sol";
5+
import "../tokens/ERC1155Upgradeable/ERC1155MintBurnUpgradeable.sol";
6+
import "../tokens/ERC1155Upgradeable/ERC1155MetadataUpgradeable.sol";
7+
8+
9+
contract ERC1155MetaMintBurnUpgradeableMock is ERC1155MetaUpgradeable, ERC1155MintBurnUpgradeable, ERC1155MetadataUpgradeable {
10+
11+
/**
12+
* @notice Query if a contract implements an interface
13+
* @dev Parent contract inheriting multiple contracts with supportsInterface()
14+
* need to implement an overriding supportsInterface() function specifying
15+
* all inheriting contracts that have a supportsInterface() function.
16+
* @param _interfaceID The interface identifier, as specified in ERC-165
17+
* @return `true` if the contract implements `_interfaceID`
18+
*/
19+
function supportsInterface(
20+
bytes4 _interfaceID
21+
) public override(
22+
ERC1155Upgradeable,
23+
ERC1155MetadataUpgradeable
24+
) view virtual returns (bool) {
25+
return super.supportsInterface(_interfaceID);
26+
}
27+
28+
/***********************************|
29+
| Minting Functions |
30+
|__________________________________*/
31+
32+
/**
33+
* @dev Mint _value of tokens of a given id
34+
* @param _to The address to mint tokens to.
35+
* @param _id token id to mint
36+
* @param _value The amount to be minted
37+
* @param _data Data to be passed if receiver is contract
38+
*/
39+
function mintMock(address _to, uint256 _id, uint256 _value, bytes memory _data)
40+
public
41+
{
42+
super._mint(_to, _id, _value, _data);
43+
}
44+
45+
/**
46+
* @dev Mint tokens for each ids in _ids
47+
* @param _to The address to mint tokens to.
48+
* @param _ids Array of ids to mint
49+
* @param _values Array of amount of tokens to mint per id
50+
* @param _data Data to be passed if receiver is contract
51+
*/
52+
function batchMintMock(address _to, uint256[] memory _ids, uint256[] memory _values, bytes memory _data)
53+
public
54+
{
55+
super._batchMint(_to, _ids, _values, _data);
56+
}
57+
58+
59+
/***********************************|
60+
| Burning Functions |
61+
|__________________________________*/
62+
63+
/**
64+
* @dev burn _value of tokens of a given token id
65+
* @param _from The address to burn tokens from.
66+
* @param _id token id to burn
67+
* @param _value The amount to be burned
68+
*/
69+
function burnMock(address _from, uint256 _id, uint256 _value)
70+
public
71+
{
72+
super._burn(_from, _id, _value);
73+
}
74+
75+
/**
76+
* @dev burn _value of tokens of a given token id
77+
* @param _from The address to burn tokens from.
78+
* @param _ids Array of token ids to burn
79+
* @param _values Array of the amount to be burned
80+
*/
81+
function batchBurnMock(address _from, uint256[] memory _ids, uint256[] memory _values)
82+
public
83+
{
84+
super._batchBurn(_from, _ids, _values);
85+
}
86+
87+
/***********************************|
88+
| Unsupported Functions |
89+
|__________________________________*/
90+
91+
fallback () virtual external {
92+
revert("ERC1155MetaMintBurnMock: INVALID_METHOD");
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "../tokens/ERC1155Upgradeable/ERC1155MintBurnUpgradeable.sol";
5+
import "../tokens/ERC1155Upgradeable/ERC1155MetadataUpgradeable.sol";
6+
7+
contract ERC1155MetadataUpgradeableMock is ERC1155MintBurnUpgradeable, ERC1155MetadataUpgradeable {
8+
9+
/***********************************|
10+
| Base URI Functions |
11+
|__________________________________*/
12+
13+
/**
14+
* @notice Will update the base URL of token's URI
15+
* @param _newBaseMetadataURI New base URL of token's URI
16+
*/
17+
function setBaseMetadataURI(string memory _newBaseMetadataURI) public {
18+
super._setBaseMetadataURI(_newBaseMetadataURI);
19+
}
20+
21+
/***********************************|
22+
| Log URI Functions |
23+
|__________________________________*/
24+
25+
/**
26+
* @notice Will emit default URI log event for corresponding token _id
27+
* @param _tokenIDs Array of IDs of tokens to log default URI
28+
*/
29+
function logURIsMock(uint256[] memory _tokenIDs) public {
30+
super._logURIs(_tokenIDs);
31+
}
32+
33+
/***********************************|
34+
| Unsupported Functions |
35+
|__________________________________*/
36+
37+
fallback () external {
38+
revert('ERC1155MetadataMock: INVALID_METHOD');
39+
}
40+
41+
42+
/***********************************|
43+
| ERC-165 Functions |
44+
|__________________________________*/
45+
46+
/**
47+
* @notice Query if a contract implements an interface
48+
* @dev Parent contract inheriting multiple contracts with supportsInterface()
49+
* need to implement an overriding supportsInterface() function specifying
50+
* all inheriting contracts that have a supportsInterface() function.
51+
* @param _interfaceID The interface identifier, as specified in ERC-165
52+
* @return `true` if the contract implements `_interfaceID`
53+
*/
54+
function supportsInterface(
55+
bytes4 _interfaceID
56+
) public override(
57+
ERC1155Upgradeable,
58+
ERC1155MetadataUpgradeable
59+
) view virtual returns (bool) {
60+
return super.supportsInterface(_interfaceID);
61+
}
62+
}
63+
64+
/**
65+
* A v2 implementation to test upgradeability.
66+
*/
67+
contract ERC1155MetadataUpgradeableMockV2 is ERC1155MetadataUpgradeableMock {
68+
mapping(uint256 => uint256) private idMapping;
69+
70+
function setIdMapping(uint256 _id, uint256 _mappedId) public {
71+
idMapping[_id] = _mappedId;
72+
}
73+
74+
function uri(uint256 _id) public override view returns (string memory) {
75+
return string(abi.encodePacked(baseURI, _uint2str(idMapping[_id]))); // Removes .json extension, swaps ids
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
import "../tokens/ERC1155PackedBalanceUpgradeable/ERC1155MintBurnPackedBalanceUpgradeable.sol";
5+
import "../tokens/ERC1155Upgradeable/ERC1155MetadataUpgradeable.sol";
6+
7+
8+
contract ERC1155MintBurnPackedBalanceUpgradeableMock is ERC1155MintBurnPackedBalanceUpgradeable, ERC1155MetadataUpgradeable {
9+
10+
/***********************************|
11+
| ERC165 |
12+
|__________________________________*/
13+
14+
/**
15+
* @notice Query if a contract implements an interface
16+
* @dev Parent contract inheriting multiple contracts with supportsInterface()
17+
* need to implement an overriding supportsInterface() function specifying
18+
* all inheriting contracts that have a supportsInterface() function.
19+
* @param _interfaceID The interface identifier, as specified in ERC-165
20+
* @return `true` if the contract implements `_interfaceID`
21+
*/
22+
function supportsInterface(
23+
bytes4 _interfaceID
24+
) public override(
25+
ERC1155PackedBalanceUpgradeable,
26+
ERC1155MetadataUpgradeable
27+
) view virtual returns (bool) {
28+
return super.supportsInterface(_interfaceID);
29+
}
30+
31+
/***********************************|
32+
| Minting Functions |
33+
|__________________________________*/
34+
35+
/**
36+
* @dev Mint _value of tokens of a given id
37+
* @param _to The address to mint tokens to.
38+
* @param _id token id to mint
39+
* @param _value The amount to be minted
40+
* @param _data Data to be passed if receiver is contract
41+
*/
42+
function mintMock(address _to, uint256 _id, uint256 _value, bytes memory _data)
43+
public
44+
{
45+
_mint(_to, _id, _value, _data);
46+
}
47+
48+
/**
49+
* @dev Mint tokens for each ids in _ids
50+
* @param _to The address to mint tokens to.
51+
* @param _ids Array of ids to mint
52+
* @param _values Array of amount of tokens to mint per id
53+
* @param _data Data to be passed if receiver is contract
54+
*/
55+
function batchMintMock(address _to, uint256[] memory _ids, uint256[] memory _values, bytes memory _data)
56+
public
57+
{
58+
_batchMint(_to, _ids, _values, _data);
59+
}
60+
61+
62+
/***********************************|
63+
| Burning Functions |
64+
|__________________________________*/
65+
66+
/**
67+
* @dev burn _value of tokens of a given token id
68+
* @param _from The address to burn tokens from.
69+
* @param _id token id to burn
70+
* @param _value The amount to be burned
71+
*/
72+
function burnMock(address _from, uint256 _id, uint256 _value)
73+
public
74+
{
75+
_burn(_from, _id, _value);
76+
}
77+
78+
/**
79+
* @dev burn _value of tokens of a given token id
80+
* @param _from The address to burn tokens from.
81+
* @param _ids Array of token ids to burn
82+
* @param _values Array of the amount to be burned
83+
*/
84+
function batchBurnMock(address _from, uint256[] memory _ids, uint256[] memory _values)
85+
public
86+
{
87+
_batchBurn(_from, _ids, _values);
88+
}
89+
90+
91+
/***********************************|
92+
| Unsupported Functions |
93+
|__________________________________*/
94+
95+
fallback () external {
96+
revert("ERC1155MetaMintBurnPackedBalanceMock: INVALID_METHOD");
97+
}
98+
}

0 commit comments

Comments
 (0)