@lukso/lsp-smart-contracts 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +31 -0
- package/README.md +73 -28
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +227 -15
- package/artifacts/LSP0ERC725AccountInit.json +227 -41
- package/artifacts/LSP11BasicSocialRecovery.json +493 -0
- package/artifacts/LSP11BasicSocialRecoveryInit.json +513 -0
- package/artifacts/LSP16UniversalFactory.json +236 -0
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +134 -15
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +80 -15
- package/artifacts/LSP4Compatibility.json +22 -0
- package/artifacts/LSP4DigitalAssetMetadata.json +22 -0
- package/artifacts/{LSP4DigitalAssetMetadataInit.json → LSP4DigitalAssetMetadataInitAbstract.json} +24 -51
- package/artifacts/LSP6KeyManager.json +188 -33
- package/artifacts/LSP6KeyManagerInit.json +188 -33
- package/artifacts/LSP7CappedSupply.json +58 -31
- package/artifacts/{LSP7CappedSupplyInit.json → LSP7CappedSupplyInitAbstract.json} +60 -72
- package/artifacts/LSP7CompatibleERC20.json +52 -46
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +733 -0
- package/artifacts/LSP7CompatibleERC20Mintable.json +61 -34
- package/artifacts/LSP7CompatibleERC20MintableInit.json +66 -60
- package/artifacts/LSP7DigitalAsset.json +52 -51
- package/artifacts/LSP7DigitalAssetInitAbstract.json +556 -0
- package/artifacts/LSP7Mintable.json +62 -35
- package/artifacts/LSP7MintableInit.json +62 -61
- package/artifacts/LSP8CappedSupply.json +64 -5
- package/artifacts/LSP8CappedSupplyInitAbstract.json +667 -0
- package/artifacts/LSP8CompatibleERC721.json +102 -21
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +936 -0
- package/artifacts/LSP8CompatibleERC721Mintable.json +111 -9
- package/artifacts/LSP8CompatibleERC721MintableInit.json +116 -35
- package/artifacts/LSP8IdentifiableDigitalAsset.json +58 -20
- package/artifacts/{LSP8CappedSupplyInit.json → LSP8IdentifiableDigitalAssetInitAbstract.json} +62 -65
- package/artifacts/LSP8Mintable.json +67 -8
- package/artifacts/LSP8MintableInit.json +67 -34
- package/artifacts/LSP9Vault.json +235 -17
- package/artifacts/LSP9VaultInit.json +235 -43
- package/artifacts/UniversalProfile.json +227 -15
- package/artifacts/UniversalProfileInit.json +227 -41
- package/artifacts/UniversalReceiverAddressStore.json +3 -3
- package/constants.js +416 -95
- package/contracts/Custom/EIP191Signer.sol +12 -0
- package/contracts/Factories/Create2Factory.sol +1 -3
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +13 -2
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +2 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +274 -74
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +2 -2
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +3 -2
- package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +4 -4
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +214 -0
- package/contracts/LSP11BasicSocialRecovery/ILSP11BasicSocialRecovery.sol +177 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol +23 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +258 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +26 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInitAbstract.sol +19 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11Constants.sol +6 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +60 -0
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +53 -0
- package/contracts/LSP14Ownable2Step/LSP14Constants.sol +15 -0
- package/contracts/LSP14Ownable2Step/LSP14Errors.sol +12 -0
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +212 -0
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +246 -0
- package/contracts/LSP17ContractExtension/LSP17Constants.sol +17 -0
- package/contracts/LSP17ContractExtension/LSP17Errors.sol +7 -0
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +104 -0
- package/contracts/LSP17ContractExtension/LSP17Extension.sol +45 -0
- package/contracts/LSP17ContractExtension/LSP17Utils.sol +20 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +5 -5
- package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +5 -3
- package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +21 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +156 -42
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +64 -31
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +54 -41
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +136 -28
- package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +16 -7
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +16 -7
- package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +3 -3
- package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +4 -4
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +103 -115
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +26 -8
- package/contracts/LSP6KeyManager/LSP6Constants.sol +45 -45
- package/contracts/LSP6KeyManager/LSP6Errors.sol +97 -20
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -2
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +786 -359
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +2 -2
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +4 -3
- package/contracts/LSP6KeyManager/LSP6Utils.sol +127 -35
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +26 -13
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +6 -6
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +5 -5
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +65 -52
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +3 -3
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +30 -1
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +24 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +28 -8
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +28 -11
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +87 -20
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +97 -19
- package/contracts/LSP7DigitalAsset/presets/ILSP7Mintable.sol +3 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +3 -4
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +9 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +3 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +12 -12
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +5 -5
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +11 -10
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +10 -8
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +11 -11
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +45 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +75 -71
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +20 -3
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +20 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +27 -7
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +27 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +236 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +240 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +49 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +51 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +3 -4
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +9 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +9 -8
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +2 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +8 -7
- package/contracts/LSP9Vault/LSP9Constants.sol +11 -8
- package/contracts/LSP9Vault/LSP9Errors.sol +8 -0
- package/contracts/LSP9Vault/LSP9Vault.sol +6 -4
- package/contracts/LSP9Vault/LSP9VaultCore.sol +324 -90
- package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -2
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +5 -4
- package/contracts/Legacy/Registries/AddressRegistry.sol +1 -1
- package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +1 -1
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +4 -13
- package/contracts/UniversalProfile.sol +2 -2
- package/contracts/UniversalProfileInit.sol +2 -2
- package/contracts/UniversalProfileInitAbstract.sol +1 -1
- package/contracts/Utils/GasLib.sol +17 -0
- package/package.json +37 -32
- package/artifacts/LSP7CompatibleERC20Init.json +0 -760
- package/artifacts/LSP7DigitalAssetInit.json +0 -588
- package/artifacts/LSP8CompatibleERC721Init.json +0 -883
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +0 -639
- package/artifacts/UniversalFactory.json +0 -127
- package/contracts/Custom/ClaimOwnership.sol +0 -34
- package/contracts/Custom/ERC165Checker.sol +0 -130
- package/contracts/Custom/IClaimOwnership.sol +0 -10
- package/contracts/Factories/UniversalFactory.sol +0 -164
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +0 -24
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +0 -85
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +0 -76
- package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +0 -9
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +0 -26
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +0 -39
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +0 -17
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +0 -57
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +0 -19
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +0 -112
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +0 -29
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableCore.sol +0 -26
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +0 -35
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +0 -17
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +0 -58
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +0 -19
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleConstants.sol +0 -6
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +0 -187
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Init.sol +0 -25
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableCore.sol +0 -26
- package/contracts/Utils/UtilsLib.sol +0 -31
|
@@ -1,22 +1,66 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// --- Errors
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @dev reverts when `tokenId` has not been minted.
|
|
8
|
+
*/
|
|
6
9
|
error LSP8NonExistentTokenId(bytes32 tokenId);
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @dev reverts when `caller` is not the `tokenOwner` of the `tokenId`.
|
|
13
|
+
*/
|
|
8
14
|
error LSP8NotTokenOwner(address tokenOwner, bytes32 tokenId, address caller);
|
|
9
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @dev reverts when `caller` is not an allowed operator for `tokenId`.
|
|
18
|
+
*/
|
|
10
19
|
error LSP8NotTokenOperator(bytes32 tokenId, address caller);
|
|
11
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @dev reverts when `operator` is already authorized for the `tokenId`.
|
|
23
|
+
*/
|
|
24
|
+
error LSP8OperatorAlreadyAuthorized(address operator, bytes32 tokenId);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @dev reverts when trying to set the zero address as an operator.
|
|
28
|
+
*/
|
|
12
29
|
error LSP8CannotUseAddressZeroAsOperator();
|
|
13
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @dev reverts when trying to send token to the zero address.
|
|
33
|
+
*/
|
|
14
34
|
error LSP8CannotSendToAddressZero();
|
|
15
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @dev reverts when specifying the same address for `from` and `to` in a token transfer.
|
|
38
|
+
*/
|
|
39
|
+
error LSP8CannotSendToSelf();
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @dev reverts when `operator` is not an operator for the `tokenId`.
|
|
43
|
+
*/
|
|
44
|
+
error LSP8NonExistingOperator(address operator, bytes32 tokenId);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @dev reverts when `tokenId` has already been minted.
|
|
48
|
+
*/
|
|
16
49
|
error LSP8TokenIdAlreadyMinted(bytes32 tokenId);
|
|
17
50
|
|
|
51
|
+
/**
|
|
52
|
+
* @dev reverts when the parameters used for `transferBatch` have different lengths.
|
|
53
|
+
*/
|
|
18
54
|
error LSP8InvalidTransferBatch();
|
|
19
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @dev reverts if the `tokenReceiver` does not implement LSP1
|
|
58
|
+
* when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
|
|
59
|
+
*/
|
|
20
60
|
error LSP8NotifyTokenReceiverContractMissingLSP1Interface(address tokenReceiver);
|
|
21
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @dev reverts if the `tokenReceiver` is an EOA
|
|
64
|
+
* when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
|
|
65
|
+
*/
|
|
22
66
|
error LSP8NotifyTokenReceiverIsEOA(address tokenReceiver);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
5
5
|
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
@@ -17,7 +17,7 @@ import {_INTERFACEID_LSP8} from "./LSP8Constants.sol";
|
|
|
17
17
|
* @author Matthew Stevens
|
|
18
18
|
* @dev Implementation of a LSP8 compliant contract.
|
|
19
19
|
*/
|
|
20
|
-
contract LSP8IdentifiableDigitalAsset is
|
|
20
|
+
abstract contract LSP8IdentifiableDigitalAsset is
|
|
21
21
|
LSP4DigitalAssetMetadata,
|
|
22
22
|
LSP8IdentifiableDigitalAssetCore
|
|
23
23
|
{
|
|
@@ -31,7 +31,7 @@ contract LSP8IdentifiableDigitalAsset is
|
|
|
31
31
|
string memory name_,
|
|
32
32
|
string memory symbol_,
|
|
33
33
|
address newOwner_
|
|
34
|
-
) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {}
|
|
34
|
+
) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @dev See {IERC165-supportsInterface}.
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
5
5
|
import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
|
|
6
6
|
import {ILSP8IdentifiableDigitalAsset} from "./ILSP8IdentifiableDigitalAsset.sol";
|
|
7
7
|
|
|
8
8
|
// libraries
|
|
9
|
+
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
9
10
|
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
10
|
-
import {ERC165Checker} from "
|
|
11
|
+
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
12
|
+
import {GasLib} from "../Utils/GasLib.sol";
|
|
11
13
|
|
|
12
14
|
// modules
|
|
13
|
-
|
|
14
|
-
import {Context} from "@openzeppelin/contracts/utils/Context.sol";
|
|
15
|
+
|
|
15
16
|
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
16
17
|
|
|
17
18
|
// errors
|
|
@@ -19,7 +20,6 @@ import "./LSP8Errors.sol";
|
|
|
19
20
|
|
|
20
21
|
// constants
|
|
21
22
|
import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
|
|
22
|
-
// import {} from "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
|
|
23
23
|
import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "./LSP8Constants.sol";
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -27,7 +27,7 @@ import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "./LSP8Con
|
|
|
27
27
|
* @author Matthew Stevens
|
|
28
28
|
* @dev Core Implementation of a LSP8 compliant contract.
|
|
29
29
|
*/
|
|
30
|
-
abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
30
|
+
abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAsset {
|
|
31
31
|
using EnumerableSet for EnumerableSet.AddressSet;
|
|
32
32
|
using EnumerableSet for EnumerableSet.Bytes32Set;
|
|
33
33
|
using Address for address;
|
|
@@ -45,12 +45,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
45
45
|
// Mapping a `tokenId` to its authorized operator addresses.
|
|
46
46
|
mapping(bytes32 => EnumerableSet.AddressSet) internal _operators;
|
|
47
47
|
|
|
48
|
+
mapping(address => EnumerableSet.Bytes32Set) internal _tokenIdsForOperator;
|
|
49
|
+
|
|
48
50
|
// --- Token queries
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
53
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
52
54
|
*/
|
|
53
|
-
function totalSupply() public view
|
|
55
|
+
function totalSupply() public view virtual returns (uint256) {
|
|
54
56
|
return _existingTokens;
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -59,14 +61,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
59
61
|
/**
|
|
60
62
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
61
63
|
*/
|
|
62
|
-
function balanceOf(address tokenOwner) public view
|
|
64
|
+
function balanceOf(address tokenOwner) public view virtual returns (uint256) {
|
|
63
65
|
return _ownedTokens[tokenOwner].length();
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
69
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
68
70
|
*/
|
|
69
|
-
function tokenOwnerOf(bytes32 tokenId) public view
|
|
71
|
+
function tokenOwnerOf(bytes32 tokenId) public view virtual returns (address) {
|
|
70
72
|
address tokenOwner = _tokenOwners[tokenId];
|
|
71
73
|
|
|
72
74
|
if (tokenOwner == address(0)) {
|
|
@@ -79,7 +81,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
79
81
|
/**
|
|
80
82
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
81
83
|
*/
|
|
82
|
-
function tokenIdsOf(address tokenOwner) public view
|
|
84
|
+
function tokenIdsOf(address tokenOwner) public view virtual returns (bytes32[] memory) {
|
|
83
85
|
return _ownedTokens[tokenOwner].values();
|
|
84
86
|
}
|
|
85
87
|
|
|
@@ -88,9 +90,9 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
88
90
|
/**
|
|
89
91
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
90
92
|
*/
|
|
91
|
-
function authorizeOperator(address operator, bytes32 tokenId) public virtual
|
|
93
|
+
function authorizeOperator(address operator, bytes32 tokenId) public virtual {
|
|
92
94
|
address tokenOwner = tokenOwnerOf(tokenId);
|
|
93
|
-
address caller =
|
|
95
|
+
address caller = msg.sender;
|
|
94
96
|
|
|
95
97
|
if (tokenOwner != caller) {
|
|
96
98
|
revert LSP8NotTokenOwner(tokenOwner, tokenId, caller);
|
|
@@ -105,7 +107,8 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
105
107
|
return;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
_operators[tokenId].add(operator);
|
|
110
|
+
bool isAdded = _operators[tokenId].add(operator);
|
|
111
|
+
if (!isAdded) revert LSP8OperatorAlreadyAuthorized(operator, tokenId);
|
|
109
112
|
|
|
110
113
|
emit AuthorizedOperator(operator, tokenOwner, tokenId);
|
|
111
114
|
}
|
|
@@ -113,9 +116,9 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
113
116
|
/**
|
|
114
117
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
115
118
|
*/
|
|
116
|
-
function revokeOperator(address operator, bytes32 tokenId) public virtual
|
|
119
|
+
function revokeOperator(address operator, bytes32 tokenId) public virtual {
|
|
117
120
|
address tokenOwner = tokenOwnerOf(tokenId);
|
|
118
|
-
address caller =
|
|
121
|
+
address caller = msg.sender;
|
|
119
122
|
|
|
120
123
|
if (tokenOwner != caller) {
|
|
121
124
|
revert LSP8NotTokenOwner(tokenOwner, tokenId, caller);
|
|
@@ -136,13 +139,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
136
139
|
/**
|
|
137
140
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
138
141
|
*/
|
|
139
|
-
function isOperatorFor(address operator, bytes32 tokenId)
|
|
140
|
-
public
|
|
141
|
-
view
|
|
142
|
-
virtual
|
|
143
|
-
override
|
|
144
|
-
returns (bool)
|
|
145
|
-
{
|
|
142
|
+
function isOperatorFor(address operator, bytes32 tokenId) public view virtual returns (bool) {
|
|
146
143
|
_existsOrError(tokenId);
|
|
147
144
|
|
|
148
145
|
return _isOperatorOrOwner(operator, tokenId);
|
|
@@ -151,18 +148,16 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
151
148
|
/**
|
|
152
149
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
153
150
|
*/
|
|
154
|
-
function getOperatorsOf(bytes32 tokenId)
|
|
155
|
-
public
|
|
156
|
-
view
|
|
157
|
-
virtual
|
|
158
|
-
override
|
|
159
|
-
returns (address[] memory)
|
|
160
|
-
{
|
|
151
|
+
function getOperatorsOf(bytes32 tokenId) public view virtual returns (address[] memory) {
|
|
161
152
|
_existsOrError(tokenId);
|
|
162
153
|
|
|
163
154
|
return _operators[tokenId].values();
|
|
164
155
|
}
|
|
165
156
|
|
|
157
|
+
/**
|
|
158
|
+
* @dev verifies if the `caller` is operator or owner for the `tokenId`
|
|
159
|
+
* @return true if `caller` is either operator or owner
|
|
160
|
+
*/
|
|
166
161
|
function _isOperatorOrOwner(address caller, bytes32 tokenId)
|
|
167
162
|
internal
|
|
168
163
|
view
|
|
@@ -183,16 +178,16 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
183
178
|
address from,
|
|
184
179
|
address to,
|
|
185
180
|
bytes32 tokenId,
|
|
186
|
-
bool
|
|
181
|
+
bool allowNonLSP1Recipient,
|
|
187
182
|
bytes memory data
|
|
188
|
-
) public virtual
|
|
189
|
-
address operator =
|
|
183
|
+
) public virtual {
|
|
184
|
+
address operator = msg.sender;
|
|
190
185
|
|
|
191
186
|
if (!_isOperatorOrOwner(operator, tokenId)) {
|
|
192
187
|
revert LSP8NotTokenOperator(tokenId, operator);
|
|
193
188
|
}
|
|
194
189
|
|
|
195
|
-
_transfer(from, to, tokenId,
|
|
190
|
+
_transfer(from, to, tokenId, allowNonLSP1Recipient, data);
|
|
196
191
|
}
|
|
197
192
|
|
|
198
193
|
/**
|
|
@@ -202,31 +197,42 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
202
197
|
address[] memory from,
|
|
203
198
|
address[] memory to,
|
|
204
199
|
bytes32[] memory tokenId,
|
|
205
|
-
bool
|
|
200
|
+
bool[] memory allowNonLSP1Recipient,
|
|
206
201
|
bytes[] memory data
|
|
207
|
-
) public virtual
|
|
202
|
+
) public virtual {
|
|
203
|
+
uint256 fromLength = from.length;
|
|
208
204
|
if (
|
|
209
|
-
|
|
205
|
+
fromLength != to.length ||
|
|
206
|
+
fromLength != tokenId.length ||
|
|
207
|
+
fromLength != allowNonLSP1Recipient.length ||
|
|
208
|
+
fromLength != data.length
|
|
210
209
|
) {
|
|
211
210
|
revert LSP8InvalidTransferBatch();
|
|
212
211
|
}
|
|
213
212
|
|
|
214
|
-
for (uint256 i = 0; i <
|
|
215
|
-
transfer(from[i], to[i], tokenId[i],
|
|
213
|
+
for (uint256 i = 0; i < fromLength; i = GasLib.uncheckedIncrement(i)) {
|
|
214
|
+
transfer(from[i], to[i], tokenId[i], allowNonLSP1Recipient[i], data[i]);
|
|
216
215
|
}
|
|
217
216
|
}
|
|
218
217
|
|
|
218
|
+
/**
|
|
219
|
+
* @dev removes `operator` from the list of operators for the `tokenId`
|
|
220
|
+
*/
|
|
219
221
|
function _revokeOperator(
|
|
220
222
|
address operator,
|
|
221
223
|
address tokenOwner,
|
|
222
224
|
bytes32 tokenId
|
|
223
225
|
) internal virtual {
|
|
224
|
-
_operators[tokenId].remove(operator);
|
|
226
|
+
bool isRemoved = _operators[tokenId].remove(operator);
|
|
227
|
+
if (!isRemoved) revert LSP8NonExistingOperator(operator, tokenId);
|
|
225
228
|
emit RevokedOperator(operator, tokenOwner, tokenId);
|
|
226
229
|
}
|
|
227
230
|
|
|
231
|
+
/**
|
|
232
|
+
* @dev clear all the operators for the `tokenId`
|
|
233
|
+
*/
|
|
228
234
|
function _clearOperators(address tokenOwner, bytes32 tokenId) internal virtual {
|
|
229
|
-
//
|
|
235
|
+
// here is a good example of why having multiple operators will be expensive.. we
|
|
230
236
|
// need to clear them on token transfer
|
|
231
237
|
//
|
|
232
238
|
// NOTE: this may cause a tx to fail if there is too many operators to clear, in which case
|
|
@@ -235,7 +241,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
235
241
|
EnumerableSet.AddressSet storage operatorsForTokenId = _operators[tokenId];
|
|
236
242
|
|
|
237
243
|
uint256 operatorListLength = operatorsForTokenId.length();
|
|
238
|
-
for (uint256 i = 0; i < operatorListLength; i
|
|
244
|
+
for (uint256 i = 0; i < operatorListLength; i = GasLib.uncheckedIncrement(i)) {
|
|
239
245
|
// we are emptying the list, always remove from index 0
|
|
240
246
|
address operator = operatorsForTokenId.at(0);
|
|
241
247
|
_revokeOperator(operator, tokenOwner, tokenId);
|
|
@@ -255,7 +261,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
255
261
|
/**
|
|
256
262
|
* @dev When `tokenId` does not exist then revert with an error.
|
|
257
263
|
*/
|
|
258
|
-
function _existsOrError(bytes32 tokenId) internal view {
|
|
264
|
+
function _existsOrError(bytes32 tokenId) internal view virtual {
|
|
259
265
|
if (!_exists(tokenId)) {
|
|
260
266
|
revert LSP8NonExistentTokenId(tokenId);
|
|
261
267
|
}
|
|
@@ -274,7 +280,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
274
280
|
function _mint(
|
|
275
281
|
address to,
|
|
276
282
|
bytes32 tokenId,
|
|
277
|
-
bool
|
|
283
|
+
bool allowNonLSP1Recipient,
|
|
278
284
|
bytes memory data
|
|
279
285
|
) internal virtual {
|
|
280
286
|
if (to == address(0)) {
|
|
@@ -285,16 +291,19 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
285
291
|
revert LSP8TokenIdAlreadyMinted(tokenId);
|
|
286
292
|
}
|
|
287
293
|
|
|
288
|
-
address operator =
|
|
294
|
+
address operator = msg.sender;
|
|
289
295
|
|
|
290
296
|
_beforeTokenTransfer(address(0), to, tokenId);
|
|
291
297
|
|
|
298
|
+
// token being minted
|
|
299
|
+
_existingTokens += 1;
|
|
300
|
+
|
|
292
301
|
_ownedTokens[to].add(tokenId);
|
|
293
302
|
_tokenOwners[tokenId] = to;
|
|
294
303
|
|
|
295
|
-
emit Transfer(operator, address(0), to, tokenId,
|
|
304
|
+
emit Transfer(operator, address(0), to, tokenId, allowNonLSP1Recipient, data);
|
|
296
305
|
|
|
297
|
-
_notifyTokenReceiver(address(0), to, tokenId,
|
|
306
|
+
_notifyTokenReceiver(address(0), to, tokenId, allowNonLSP1Recipient, data);
|
|
298
307
|
}
|
|
299
308
|
|
|
300
309
|
/**
|
|
@@ -308,10 +317,13 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
308
317
|
*/
|
|
309
318
|
function _burn(bytes32 tokenId, bytes memory data) internal virtual {
|
|
310
319
|
address tokenOwner = tokenOwnerOf(tokenId);
|
|
311
|
-
address operator =
|
|
320
|
+
address operator = msg.sender;
|
|
312
321
|
|
|
313
322
|
_beforeTokenTransfer(tokenOwner, address(0), tokenId);
|
|
314
323
|
|
|
324
|
+
// token being burned
|
|
325
|
+
_existingTokens -= 1;
|
|
326
|
+
|
|
315
327
|
_clearOperators(tokenOwner, tokenId);
|
|
316
328
|
|
|
317
329
|
_ownedTokens[tokenOwner].remove(tokenId);
|
|
@@ -336,9 +348,13 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
336
348
|
address from,
|
|
337
349
|
address to,
|
|
338
350
|
bytes32 tokenId,
|
|
339
|
-
bool
|
|
351
|
+
bool allowNonLSP1Recipient,
|
|
340
352
|
bytes memory data
|
|
341
353
|
) internal virtual {
|
|
354
|
+
if (from == to) {
|
|
355
|
+
revert LSP8CannotSendToSelf();
|
|
356
|
+
}
|
|
357
|
+
|
|
342
358
|
address tokenOwner = tokenOwnerOf(tokenId);
|
|
343
359
|
if (tokenOwner != from) {
|
|
344
360
|
revert LSP8NotTokenOwner(tokenOwner, tokenId, from);
|
|
@@ -348,7 +364,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
348
364
|
revert LSP8CannotSendToAddressZero();
|
|
349
365
|
}
|
|
350
366
|
|
|
351
|
-
address operator =
|
|
367
|
+
address operator = msg.sender;
|
|
352
368
|
|
|
353
369
|
_beforeTokenTransfer(from, to, tokenId);
|
|
354
370
|
|
|
@@ -358,10 +374,10 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
358
374
|
_ownedTokens[to].add(tokenId);
|
|
359
375
|
_tokenOwners[tokenId] = to;
|
|
360
376
|
|
|
361
|
-
emit Transfer(operator, from, to, tokenId,
|
|
377
|
+
emit Transfer(operator, from, to, tokenId, allowNonLSP1Recipient, data);
|
|
362
378
|
|
|
363
379
|
_notifyTokenSender(from, to, tokenId, data);
|
|
364
|
-
_notifyTokenReceiver(from, to, tokenId,
|
|
380
|
+
_notifyTokenReceiver(from, to, tokenId, allowNonLSP1Recipient, data);
|
|
365
381
|
}
|
|
366
382
|
|
|
367
383
|
/**
|
|
@@ -374,25 +390,13 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
374
390
|
* transferred to `to`.
|
|
375
391
|
* - When `from` is zero, `tokenId` will be minted for `to`.
|
|
376
392
|
* - When `to` is zero, ``from``'s `tokenId` will be burned.
|
|
393
|
+
* - `from` and `to` are never both zero.
|
|
377
394
|
*/
|
|
378
395
|
function _beforeTokenTransfer(
|
|
379
396
|
address from,
|
|
380
397
|
address to,
|
|
381
398
|
bytes32 tokenId
|
|
382
|
-
) internal virtual {
|
|
383
|
-
// silence compiler warning about unused variable
|
|
384
|
-
tokenId;
|
|
385
|
-
|
|
386
|
-
// token being minted
|
|
387
|
-
if (from == address(0)) {
|
|
388
|
-
_existingTokens += 1;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// token being burned
|
|
392
|
-
if (to == address(0)) {
|
|
393
|
-
_existingTokens -= 1;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
399
|
+
) internal virtual {}
|
|
396
400
|
|
|
397
401
|
/**
|
|
398
402
|
* @dev An attempt is made to notify the token sender about the `tokenId` changing owners using
|
|
@@ -404,7 +408,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
404
408
|
bytes32 tokenId,
|
|
405
409
|
bytes memory data
|
|
406
410
|
) internal virtual {
|
|
407
|
-
if (ERC165Checker.
|
|
411
|
+
if (ERC165Checker.supportsERC165InterfaceUnchecked(from, _INTERFACEID_LSP1)) {
|
|
408
412
|
bytes memory packedData = abi.encodePacked(from, to, tokenId, data);
|
|
409
413
|
ILSP1UniversalReceiver(from).universalReceiver(_TYPEID_LSP8_TOKENSSENDER, packedData);
|
|
410
414
|
}
|
|
@@ -412,7 +416,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
412
416
|
|
|
413
417
|
/**
|
|
414
418
|
* @dev An attempt is made to notify the token receiver about the `tokenId` changing owners
|
|
415
|
-
* using LSP1 interface. When
|
|
419
|
+
* using LSP1 interface. When allowNonLSP1Recipient is FALSE the token receiver MUST support LSP1.
|
|
416
420
|
*
|
|
417
421
|
* The receiver may revert when the token being sent is not wanted.
|
|
418
422
|
*/
|
|
@@ -420,14 +424,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
|
|
|
420
424
|
address from,
|
|
421
425
|
address to,
|
|
422
426
|
bytes32 tokenId,
|
|
423
|
-
bool
|
|
427
|
+
bool allowNonLSP1Recipient,
|
|
424
428
|
bytes memory data
|
|
425
429
|
) internal virtual {
|
|
426
|
-
if (ERC165Checker.
|
|
430
|
+
if (ERC165Checker.supportsERC165InterfaceUnchecked(to, _INTERFACEID_LSP1)) {
|
|
427
431
|
bytes memory packedData = abi.encodePacked(from, to, tokenId, data);
|
|
428
432
|
ILSP1UniversalReceiver(to).universalReceiver(_TYPEID_LSP8_TOKENSRECIPIENT, packedData);
|
|
429
|
-
} else if (!
|
|
430
|
-
if (to.
|
|
433
|
+
} else if (!allowNonLSP1Recipient) {
|
|
434
|
+
if (to.isContract()) {
|
|
431
435
|
revert LSP8NotifyTokenReceiverContractMissingLSP1Interface(to);
|
|
432
436
|
} else {
|
|
433
437
|
revert LSP8NotifyTokenReceiverIsEOA(to);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
pragma solidity ^0.8.0;
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
4
3
|
|
|
5
4
|
// interfaces
|
|
6
5
|
import {ILSP8IdentifiableDigitalAsset} from "../ILSP8IdentifiableDigitalAsset.sol";
|
|
7
6
|
|
|
7
|
+
// --- ERC165 interface ids
|
|
8
|
+
bytes4 constant _INTERFACEID_ERC721 = 0x80ac58cd;
|
|
9
|
+
bytes4 constant _INTERFACEID_ERC721METADATA = 0x5b5e139f;
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* @dev LSP8 extension, for compatibility for clients / tools that expect ERC721.
|
|
10
13
|
*/
|
|
@@ -27,6 +30,12 @@ interface ILSP8CompatibleERC721 is ILSP8IdentifiableDigitalAsset {
|
|
|
27
30
|
*/
|
|
28
31
|
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
|
|
29
32
|
|
|
33
|
+
/**
|
|
34
|
+
* @dev This emits when an operator is enabled or disabled for an owner.
|
|
35
|
+
* The operator can manage all NFTs of the owner.
|
|
36
|
+
*/
|
|
37
|
+
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
|
|
38
|
+
|
|
30
39
|
/**
|
|
31
40
|
* @dev Compatible with ERC721 transferFrom.
|
|
32
41
|
* @param from The sending address
|
|
@@ -74,11 +83,19 @@ interface ILSP8CompatibleERC721 is ILSP8IdentifiableDigitalAsset {
|
|
|
74
83
|
|
|
75
84
|
/**
|
|
76
85
|
* @dev Compatible with ERC721 approve.
|
|
77
|
-
* @param operator The address to approve for `
|
|
86
|
+
* @param operator The address to approve for `tokenId`
|
|
78
87
|
* @param tokenId The tokenId to approve
|
|
79
88
|
*/
|
|
80
89
|
function approve(address operator, uint256 tokenId) external;
|
|
81
90
|
|
|
91
|
+
/**
|
|
92
|
+
* @notice Enable or disable approval for a third party ("operator") to manage all of `msg.sender`'s assets
|
|
93
|
+
* @dev Emits the ApprovalForAll event. The contract MUST allow multiple operators per owner.
|
|
94
|
+
* @param _operator Address to add to the set of authorized operators
|
|
95
|
+
* @param _approved True if the operator is approved, false to revoke approval
|
|
96
|
+
*/
|
|
97
|
+
function setApprovalForAll(address _operator, bool _approved) external;
|
|
98
|
+
|
|
82
99
|
/**
|
|
83
100
|
* @dev Compatible with ERC721 getApproved.
|
|
84
101
|
* @param tokenId The tokenId to query
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
|
|
5
|
+
|
|
6
|
+
// errors
|
|
7
|
+
import {LSP8NotTokenOperator} from "../LSP8Errors.sol";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @dev LSP8 extension that allows token holders to destroy both
|
|
11
|
+
* their own tokens and those that they have an allowance for as an operator.
|
|
12
|
+
*/
|
|
13
|
+
abstract contract LSP8Burnable is LSP8IdentifiableDigitalAssetCore {
|
|
14
|
+
function burn(bytes32 tokenId, bytes memory data) public {
|
|
15
|
+
if (!_isOperatorOrOwner(msg.sender, tokenId)) {
|
|
16
|
+
revert LSP8NotTokenOperator(tokenId, msg.sender);
|
|
17
|
+
}
|
|
18
|
+
_burn(tokenId, data);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
|
|
3
|
-
pragma solidity ^0.8.
|
|
3
|
+
pragma solidity ^0.8.4;
|
|
4
4
|
|
|
5
5
|
// modules
|
|
6
6
|
import {LSP8IdentifiableDigitalAsset} from "../LSP8IdentifiableDigitalAsset.sol";
|
|
7
7
|
import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
|
|
8
|
-
import {LSP8CappedSupplyCore} from "./LSP8CappedSupplyCore.sol";
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* @dev LSP8 extension, adds token supply cap.
|
|
12
11
|
*/
|
|
13
|
-
abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset
|
|
12
|
+
abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset {
|
|
13
|
+
// --- Errors
|
|
14
|
+
error LSP8CappedSupplyRequired();
|
|
15
|
+
error LSP8CappedSupplyCannotMintOverCap();
|
|
16
|
+
|
|
17
|
+
// --- Storage
|
|
18
|
+
uint256 internal _tokenSupplyCap;
|
|
19
|
+
|
|
14
20
|
/**
|
|
15
21
|
* @notice Sets the token max supply
|
|
16
22
|
* @param tokenSupplyCap_ The Token max supply
|
|
@@ -23,7 +29,17 @@ abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset, LSP8CappedSu
|
|
|
23
29
|
_tokenSupplyCap = tokenSupplyCap_;
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
// ---
|
|
32
|
+
// --- Token queries
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @dev Returns the number of tokens that can be minted.
|
|
36
|
+
* @return The token max supply
|
|
37
|
+
*/
|
|
38
|
+
function tokenSupplyCap() public view virtual returns (uint256) {
|
|
39
|
+
return _tokenSupplyCap;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// --- Transfer functionality
|
|
27
43
|
|
|
28
44
|
/**
|
|
29
45
|
* @dev Mints `tokenId` and transfers it to `to`.
|
|
@@ -39,9 +55,13 @@ abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset, LSP8CappedSu
|
|
|
39
55
|
function _mint(
|
|
40
56
|
address to,
|
|
41
57
|
bytes32 tokenId,
|
|
42
|
-
bool
|
|
58
|
+
bool allowNonLSP1Recipient,
|
|
43
59
|
bytes memory data
|
|
44
|
-
) internal virtual override
|
|
45
|
-
|
|
60
|
+
) internal virtual override {
|
|
61
|
+
if (totalSupply() + 1 > tokenSupplyCap()) {
|
|
62
|
+
revert LSP8CappedSupplyCannotMintOverCap();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
super._mint(to, tokenId, allowNonLSP1Recipient, data);
|
|
46
66
|
}
|
|
47
67
|
}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
|
|
3
|
-
pragma solidity ^0.8.
|
|
3
|
+
pragma solidity ^0.8.4;
|
|
4
4
|
|
|
5
5
|
// modules
|
|
6
6
|
import {LSP8IdentifiableDigitalAssetCore} from "../LSP8IdentifiableDigitalAssetCore.sol";
|
|
7
7
|
import {
|
|
8
8
|
LSP8IdentifiableDigitalAssetInitAbstract
|
|
9
9
|
} from "../LSP8IdentifiableDigitalAssetInitAbstract.sol";
|
|
10
|
-
import {LSP8CappedSupplyCore} from "./LSP8CappedSupplyCore.sol";
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* @dev LSP8 extension, adds token supply cap.
|
|
14
13
|
*/
|
|
15
|
-
abstract contract LSP8CappedSupplyInitAbstract is
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
abstract contract LSP8CappedSupplyInitAbstract is LSP8IdentifiableDigitalAssetInitAbstract {
|
|
15
|
+
// --- Errors
|
|
16
|
+
error LSP8CappedSupplyRequired();
|
|
17
|
+
error LSP8CappedSupplyCannotMintOverCap();
|
|
18
|
+
|
|
19
|
+
// --- Storage
|
|
20
|
+
uint256 internal _tokenSupplyCap;
|
|
21
|
+
|
|
19
22
|
function _initialize(uint256 tokenSupplyCap_) internal virtual onlyInitializing {
|
|
20
23
|
if (tokenSupplyCap_ == 0) {
|
|
21
24
|
revert LSP8CappedSupplyRequired();
|
|
@@ -24,7 +27,17 @@ abstract contract LSP8CappedSupplyInitAbstract is
|
|
|
24
27
|
_tokenSupplyCap = tokenSupplyCap_;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
// ---
|
|
30
|
+
// --- Token queries
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @dev Returns the number of tokens that can be minted.
|
|
34
|
+
* @return The token max supply
|
|
35
|
+
*/
|
|
36
|
+
function tokenSupplyCap() public view virtual returns (uint256) {
|
|
37
|
+
return _tokenSupplyCap;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// --- Transfer functionality
|
|
28
41
|
|
|
29
42
|
/**
|
|
30
43
|
* @dev Mints `tokenId` and transfers it to `to`.
|
|
@@ -40,9 +53,13 @@ abstract contract LSP8CappedSupplyInitAbstract is
|
|
|
40
53
|
function _mint(
|
|
41
54
|
address to,
|
|
42
55
|
bytes32 tokenId,
|
|
43
|
-
bool
|
|
56
|
+
bool allowNonLSP1Recipient,
|
|
44
57
|
bytes memory data
|
|
45
|
-
) internal virtual override
|
|
46
|
-
|
|
58
|
+
) internal virtual override {
|
|
59
|
+
if (totalSupply() + 1 > tokenSupplyCap()) {
|
|
60
|
+
revert LSP8CappedSupplyCannotMintOverCap();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
super._mint(to, tokenId, allowNonLSP1Recipient, data);
|
|
47
64
|
}
|
|
48
65
|
}
|