@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,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 {ILSP7DigitalAsset} from "./ILSP7DigitalAsset.sol";
|
|
7
7
|
|
|
8
8
|
// libraries
|
|
9
|
-
import {
|
|
9
|
+
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
10
|
+
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
11
|
+
import {GasLib} from "../Utils/GasLib.sol";
|
|
10
12
|
|
|
11
13
|
// modules
|
|
12
14
|
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
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
|
|
@@ -28,12 +29,12 @@ import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "./LSP7Con
|
|
|
28
29
|
*
|
|
29
30
|
* This contract implement the core logic of the functions for the {ILSP7DigitalAsset} interface.
|
|
30
31
|
*/
|
|
31
|
-
abstract contract LSP7DigitalAssetCore is
|
|
32
|
+
abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
32
33
|
using Address for address;
|
|
33
34
|
|
|
34
35
|
// --- Storage
|
|
35
36
|
|
|
36
|
-
bool internal
|
|
37
|
+
bool internal _isNonDivisible;
|
|
37
38
|
|
|
38
39
|
uint256 internal _existingTokens;
|
|
39
40
|
|
|
@@ -48,14 +49,14 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
48
49
|
/**
|
|
49
50
|
* @inheritdoc ILSP7DigitalAsset
|
|
50
51
|
*/
|
|
51
|
-
function decimals() public view
|
|
52
|
-
return
|
|
52
|
+
function decimals() public view virtual returns (uint8) {
|
|
53
|
+
return _isNonDivisible ? 0 : 18;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
57
|
* @inheritdoc ILSP7DigitalAsset
|
|
57
58
|
*/
|
|
58
|
-
function totalSupply() public view
|
|
59
|
+
function totalSupply() public view virtual returns (uint256) {
|
|
59
60
|
return _existingTokens;
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -64,7 +65,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
64
65
|
/**
|
|
65
66
|
* @inheritdoc ILSP7DigitalAsset
|
|
66
67
|
*/
|
|
67
|
-
function balanceOf(address tokenOwner) public view
|
|
68
|
+
function balanceOf(address tokenOwner) public view virtual returns (uint256) {
|
|
68
69
|
return _tokenOwnerBalances[tokenOwner];
|
|
69
70
|
}
|
|
70
71
|
|
|
@@ -72,26 +73,35 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
75
|
* @inheritdoc ILSP7DigitalAsset
|
|
76
|
+
*
|
|
77
|
+
* @dev To avoid front-running and Allowance Double-Spend Exploit when
|
|
78
|
+
* increasing or decreasing the authorized amount of an operator,
|
|
79
|
+
* it is advised to:
|
|
80
|
+
* 1. call {revokeOperator} first, and
|
|
81
|
+
* 2. then re-call {authorizeOperator} with the new amount
|
|
82
|
+
*
|
|
83
|
+
* for more information, see:
|
|
84
|
+
* https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/
|
|
85
|
+
*
|
|
75
86
|
*/
|
|
76
|
-
function authorizeOperator(address operator, uint256 amount) public virtual
|
|
77
|
-
_updateOperator(
|
|
87
|
+
function authorizeOperator(address operator, uint256 amount) public virtual {
|
|
88
|
+
_updateOperator(msg.sender, operator, amount);
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
/**
|
|
81
92
|
* @inheritdoc ILSP7DigitalAsset
|
|
82
93
|
*/
|
|
83
|
-
function revokeOperator(address operator) public virtual
|
|
84
|
-
_updateOperator(
|
|
94
|
+
function revokeOperator(address operator) public virtual {
|
|
95
|
+
_updateOperator(msg.sender, operator, 0);
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
/**
|
|
88
99
|
* @inheritdoc ILSP7DigitalAsset
|
|
89
100
|
*/
|
|
90
|
-
function
|
|
101
|
+
function authorizedAmountFor(address operator, address tokenOwner)
|
|
91
102
|
public
|
|
92
103
|
view
|
|
93
104
|
virtual
|
|
94
|
-
override
|
|
95
105
|
returns (uint256)
|
|
96
106
|
{
|
|
97
107
|
if (tokenOwner == operator) {
|
|
@@ -110,10 +120,12 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
110
120
|
address from,
|
|
111
121
|
address to,
|
|
112
122
|
uint256 amount,
|
|
113
|
-
bool
|
|
123
|
+
bool allowNonLSP1Recipient,
|
|
114
124
|
bytes memory data
|
|
115
|
-
) public virtual
|
|
116
|
-
|
|
125
|
+
) public virtual {
|
|
126
|
+
if (from == to) revert LSP7CannotSendToSelf();
|
|
127
|
+
|
|
128
|
+
address operator = msg.sender;
|
|
117
129
|
if (operator != from) {
|
|
118
130
|
uint256 operatorAmount = _operatorAuthorizedAmount[from][operator];
|
|
119
131
|
if (amount > operatorAmount) {
|
|
@@ -123,7 +135,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
123
135
|
_updateOperator(from, operator, operatorAmount - amount);
|
|
124
136
|
}
|
|
125
137
|
|
|
126
|
-
_transfer(from, to, amount,
|
|
138
|
+
_transfer(from, to, amount, allowNonLSP1Recipient, data);
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
/**
|
|
@@ -133,18 +145,22 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
133
145
|
address[] memory from,
|
|
134
146
|
address[] memory to,
|
|
135
147
|
uint256[] memory amount,
|
|
136
|
-
bool
|
|
148
|
+
bool[] memory allowNonLSP1Recipient,
|
|
137
149
|
bytes[] memory data
|
|
138
|
-
) public virtual
|
|
150
|
+
) public virtual {
|
|
151
|
+
uint256 fromLength = from.length;
|
|
139
152
|
if (
|
|
140
|
-
|
|
153
|
+
fromLength != to.length ||
|
|
154
|
+
fromLength != amount.length ||
|
|
155
|
+
fromLength != allowNonLSP1Recipient.length ||
|
|
156
|
+
fromLength != data.length
|
|
141
157
|
) {
|
|
142
158
|
revert LSP7InvalidTransferBatch();
|
|
143
159
|
}
|
|
144
160
|
|
|
145
|
-
for (uint256 i = 0; i <
|
|
161
|
+
for (uint256 i = 0; i < fromLength; i = GasLib.uncheckedIncrement(i)) {
|
|
146
162
|
// using the public transfer function to handle updates to operator authorized amounts
|
|
147
|
-
transfer(from[i], to[i], amount[i],
|
|
163
|
+
transfer(from[i], to[i], amount[i], allowNonLSP1Recipient[i], data[i]);
|
|
148
164
|
}
|
|
149
165
|
}
|
|
150
166
|
|
|
@@ -153,7 +169,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
153
169
|
* amount is zero then the operator is being revoked, otherwise the operator amount is being
|
|
154
170
|
* modified.
|
|
155
171
|
*
|
|
156
|
-
* See {
|
|
172
|
+
* See {authorizedAmountFor}.
|
|
157
173
|
*
|
|
158
174
|
* Emits either {AuthorizedOperator} or {RevokedOperator} event.
|
|
159
175
|
*
|
|
@@ -196,22 +212,25 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
196
212
|
function _mint(
|
|
197
213
|
address to,
|
|
198
214
|
uint256 amount,
|
|
199
|
-
bool
|
|
215
|
+
bool allowNonLSP1Recipient,
|
|
200
216
|
bytes memory data
|
|
201
217
|
) internal virtual {
|
|
202
218
|
if (to == address(0)) {
|
|
203
219
|
revert LSP7CannotSendWithAddressZero();
|
|
204
220
|
}
|
|
205
221
|
|
|
206
|
-
address operator =
|
|
222
|
+
address operator = msg.sender;
|
|
207
223
|
|
|
208
224
|
_beforeTokenTransfer(address(0), to, amount);
|
|
209
225
|
|
|
226
|
+
// tokens being minted
|
|
227
|
+
_existingTokens += amount;
|
|
228
|
+
|
|
210
229
|
_tokenOwnerBalances[to] += amount;
|
|
211
230
|
|
|
212
|
-
emit Transfer(operator, address(0), to, amount,
|
|
231
|
+
emit Transfer(operator, address(0), to, amount, allowNonLSP1Recipient, data);
|
|
213
232
|
|
|
214
|
-
_notifyTokenReceiver(address(0), to, amount,
|
|
233
|
+
_notifyTokenReceiver(address(0), to, amount, allowNonLSP1Recipient, data);
|
|
215
234
|
}
|
|
216
235
|
|
|
217
236
|
/**
|
|
@@ -240,7 +259,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
240
259
|
revert LSP7AmountExceedsBalance(balance, from, amount);
|
|
241
260
|
}
|
|
242
261
|
|
|
243
|
-
address operator =
|
|
262
|
+
address operator = msg.sender;
|
|
244
263
|
if (operator != from) {
|
|
245
264
|
uint256 authorizedAmount = _operatorAuthorizedAmount[from][operator];
|
|
246
265
|
if (amount > authorizedAmount) {
|
|
@@ -251,6 +270,9 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
251
270
|
|
|
252
271
|
_beforeTokenTransfer(from, address(0), amount);
|
|
253
272
|
|
|
273
|
+
// tokens being burned
|
|
274
|
+
_existingTokens -= amount;
|
|
275
|
+
|
|
254
276
|
_tokenOwnerBalances[from] -= amount;
|
|
255
277
|
|
|
256
278
|
emit Transfer(operator, from, address(0), amount, false, data);
|
|
@@ -275,7 +297,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
275
297
|
address from,
|
|
276
298
|
address to,
|
|
277
299
|
uint256 amount,
|
|
278
|
-
bool
|
|
300
|
+
bool allowNonLSP1Recipient,
|
|
279
301
|
bytes memory data
|
|
280
302
|
) internal virtual {
|
|
281
303
|
if (from == address(0) || to == address(0)) {
|
|
@@ -287,17 +309,17 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
287
309
|
revert LSP7AmountExceedsBalance(balance, from, amount);
|
|
288
310
|
}
|
|
289
311
|
|
|
290
|
-
address operator =
|
|
312
|
+
address operator = msg.sender;
|
|
291
313
|
|
|
292
314
|
_beforeTokenTransfer(from, to, amount);
|
|
293
315
|
|
|
294
316
|
_tokenOwnerBalances[from] -= amount;
|
|
295
317
|
_tokenOwnerBalances[to] += amount;
|
|
296
318
|
|
|
297
|
-
emit Transfer(operator, from, to, amount,
|
|
319
|
+
emit Transfer(operator, from, to, amount, allowNonLSP1Recipient, data);
|
|
298
320
|
|
|
299
321
|
_notifyTokenSender(from, to, amount, data);
|
|
300
|
-
_notifyTokenReceiver(from, to, amount,
|
|
322
|
+
_notifyTokenReceiver(from, to, amount, allowNonLSP1Recipient, data);
|
|
301
323
|
}
|
|
302
324
|
|
|
303
325
|
/**
|
|
@@ -310,22 +332,13 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
310
332
|
* transferred to `to`.
|
|
311
333
|
* - When `from` is zero, `amount` tokens will be minted for `to`.
|
|
312
334
|
* - When `to` is zero, ``from``'s `amount` tokens will be burned.
|
|
335
|
+
* - `from` and `to` are never both zero.
|
|
313
336
|
*/
|
|
314
337
|
function _beforeTokenTransfer(
|
|
315
338
|
address from,
|
|
316
339
|
address to,
|
|
317
340
|
uint256 amount
|
|
318
|
-
) internal virtual {
|
|
319
|
-
// tokens being minted
|
|
320
|
-
if (from == address(0)) {
|
|
321
|
-
_existingTokens += amount;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// tokens being burned
|
|
325
|
-
if (to == address(0)) {
|
|
326
|
-
_existingTokens -= amount;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
341
|
+
) internal virtual {}
|
|
329
342
|
|
|
330
343
|
/**
|
|
331
344
|
* @dev An attempt is made to notify the token sender about the `amount` tokens changing owners using
|
|
@@ -337,7 +350,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
337
350
|
uint256 amount,
|
|
338
351
|
bytes memory data
|
|
339
352
|
) internal virtual {
|
|
340
|
-
if (ERC165Checker.
|
|
353
|
+
if (ERC165Checker.supportsERC165InterfaceUnchecked(from, _INTERFACEID_LSP1)) {
|
|
341
354
|
bytes memory packedData = abi.encodePacked(from, to, amount, data);
|
|
342
355
|
ILSP1UniversalReceiver(from).universalReceiver(_TYPEID_LSP7_TOKENSSENDER, packedData);
|
|
343
356
|
}
|
|
@@ -345,7 +358,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
345
358
|
|
|
346
359
|
/**
|
|
347
360
|
* @dev An attempt is made to notify the token receiver about the `amount` tokens changing owners
|
|
348
|
-
* using LSP1 interface. When
|
|
361
|
+
* using LSP1 interface. When allowNonLSP1Recipient is FALSE the token receiver MUST support LSP1.
|
|
349
362
|
*
|
|
350
363
|
* The receiver may revert when the token being sent is not wanted.
|
|
351
364
|
*/
|
|
@@ -353,14 +366,14 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
|
|
|
353
366
|
address from,
|
|
354
367
|
address to,
|
|
355
368
|
uint256 amount,
|
|
356
|
-
bool
|
|
369
|
+
bool allowNonLSP1Recipient,
|
|
357
370
|
bytes memory data
|
|
358
371
|
) internal virtual {
|
|
359
|
-
if (ERC165Checker.
|
|
372
|
+
if (ERC165Checker.supportsERC165InterfaceUnchecked(to, _INTERFACEID_LSP1)) {
|
|
360
373
|
bytes memory packedData = abi.encodePacked(from, to, amount, data);
|
|
361
374
|
ILSP1UniversalReceiver(to).universalReceiver(_TYPEID_LSP7_TOKENSRECIPIENT, packedData);
|
|
362
|
-
} else if (!
|
|
363
|
-
if (to.
|
|
375
|
+
} else if (!allowNonLSP1Recipient) {
|
|
376
|
+
if (to.isContract()) {
|
|
364
377
|
revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
|
|
365
378
|
} else {
|
|
366
379
|
revert LSP7NotifyTokenReceiverIsEOA(to);
|
|
@@ -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";
|
|
@@ -27,9 +27,9 @@ abstract contract LSP7DigitalAssetInitAbstract is
|
|
|
27
27
|
string memory name_,
|
|
28
28
|
string memory symbol_,
|
|
29
29
|
address newOwner_,
|
|
30
|
-
bool
|
|
30
|
+
bool isNonDivisible_
|
|
31
31
|
) internal virtual onlyInitializing {
|
|
32
|
-
|
|
32
|
+
_isNonDivisible = isNonDivisible_;
|
|
33
33
|
LSP4DigitalAssetMetadataInitAbstract._initialize(name_, symbol_, newOwner_);
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -1,10 +1,17 @@
|
|
|
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 sending an `amount` of tokens larger than the current `balance` of the `tokenOwner`.
|
|
8
|
+
*/
|
|
6
9
|
error LSP7AmountExceedsBalance(uint256 balance, address tokenOwner, uint256 amount);
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @dev reverts when `operator` of `tokenOwner` send an `amount` of tokens
|
|
13
|
+
* larger than the `authorizedAmount`.
|
|
14
|
+
*/
|
|
8
15
|
error LSP7AmountExceedsAuthorizedAmount(
|
|
9
16
|
address tokenOwner,
|
|
10
17
|
uint256 authorizedAmount,
|
|
@@ -12,12 +19,34 @@ error LSP7AmountExceedsAuthorizedAmount(
|
|
|
12
19
|
uint256 amount
|
|
13
20
|
);
|
|
14
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @dev reverts when trying to set the zero address as an operator.
|
|
24
|
+
*/
|
|
15
25
|
error LSP7CannotUseAddressZeroAsOperator();
|
|
16
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @dev reverts when one tries to send tokens to or from the zero address.
|
|
29
|
+
*/
|
|
17
30
|
error LSP7CannotSendWithAddressZero();
|
|
18
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @dev reverts when specifying the same address for `from` or `to` in a token transfer.
|
|
34
|
+
*/
|
|
35
|
+
error LSP7CannotSendToSelf();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @dev reverts when the parameters used for `transferBatch` have different lengths.
|
|
39
|
+
*/
|
|
19
40
|
error LSP7InvalidTransferBatch();
|
|
20
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @dev reverts if the `tokenReceiver` does not implement LSP1
|
|
44
|
+
* when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
|
|
45
|
+
*/
|
|
21
46
|
error LSP7NotifyTokenReceiverContractMissingLSP1Interface(address tokenReceiver);
|
|
22
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @dev reverts if the `tokenReceiver` is an EOA
|
|
50
|
+
* when minting or transferring tokens with `bool allowNonLSP1Recipient` set as `false`.
|
|
51
|
+
*/
|
|
23
52
|
error LSP7NotifyTokenReceiverIsEOA(address tokenReceiver);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @dev LSP7 extension that allows token holders to destroy both
|
|
9
|
+
* their own tokens and those that they have an allowance for as an operator.
|
|
10
|
+
*/
|
|
11
|
+
abstract contract LSP7Burnable is LSP7DigitalAssetCore {
|
|
12
|
+
/**
|
|
13
|
+
* @dev Destroys `amount` tokens from the `from` address.
|
|
14
|
+
*
|
|
15
|
+
* See internal _burn function for more details
|
|
16
|
+
*/
|
|
17
|
+
function burn(
|
|
18
|
+
address from,
|
|
19
|
+
uint256 amount,
|
|
20
|
+
bytes memory data
|
|
21
|
+
) public {
|
|
22
|
+
_burn(from, amount, data);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -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 {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol";
|
|
7
7
|
import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
|
|
8
|
-
import {LSP7CappedSupplyCore} from "./LSP7CappedSupplyCore.sol";
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* @dev LSP7 extension, adds token supply cap.
|
|
12
11
|
*/
|
|
13
|
-
abstract contract LSP7CappedSupply is LSP7DigitalAsset
|
|
12
|
+
abstract contract LSP7CappedSupply is LSP7DigitalAsset {
|
|
13
|
+
// --- Errors
|
|
14
|
+
error LSP7CappedSupplyRequired();
|
|
15
|
+
error LSP7CappedSupplyCannotMintOverCap();
|
|
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,10 +29,20 @@ abstract contract LSP7CappedSupply is LSP7DigitalAsset, LSP7CappedSupplyCore {
|
|
|
23
29
|
_tokenSupplyCap = tokenSupplyCap_;
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
// ---
|
|
32
|
+
// --- Token queries
|
|
27
33
|
|
|
28
34
|
/**
|
|
29
|
-
* @dev
|
|
35
|
+
* @dev Returns the number of tokens that can be minted
|
|
36
|
+
* @return The number of tokens that can be minted
|
|
37
|
+
*/
|
|
38
|
+
function tokenSupplyCap() public view virtual returns (uint256) {
|
|
39
|
+
return _tokenSupplyCap;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// --- Transfer functionality
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @dev Mints `amount` and transfers it to `to`.
|
|
30
46
|
*
|
|
31
47
|
* Requirements:
|
|
32
48
|
*
|
|
@@ -38,9 +54,13 @@ abstract contract LSP7CappedSupply is LSP7DigitalAsset, LSP7CappedSupplyCore {
|
|
|
38
54
|
function _mint(
|
|
39
55
|
address to,
|
|
40
56
|
uint256 amount,
|
|
41
|
-
bool
|
|
57
|
+
bool allowNonLSP1Recipient,
|
|
42
58
|
bytes memory data
|
|
43
|
-
) internal virtual override
|
|
44
|
-
|
|
59
|
+
) internal virtual override {
|
|
60
|
+
if (totalSupply() + amount > tokenSupplyCap()) {
|
|
61
|
+
revert LSP7CappedSupplyCannotMintOverCap();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
super._mint(to, amount, allowNonLSP1Recipient, data);
|
|
45
65
|
}
|
|
46
66
|
}
|
|
@@ -1,19 +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 {LSP7DigitalAssetInitAbstract} from "../LSP7DigitalAssetInitAbstract.sol";
|
|
7
7
|
import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
|
|
8
|
-
import {LSP7CappedSupplyCore} from "./LSP7CappedSupplyCore.sol";
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* @dev LSP7 extension, adds token supply cap.
|
|
12
11
|
*/
|
|
13
|
-
abstract contract LSP7CappedSupplyInitAbstract is
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
abstract contract LSP7CappedSupplyInitAbstract is LSP7DigitalAssetInitAbstract {
|
|
13
|
+
// --- Errors
|
|
14
|
+
error LSP7CappedSupplyRequired();
|
|
15
|
+
error LSP7CappedSupplyCannotMintOverCap();
|
|
16
|
+
|
|
17
|
+
// --- Storage
|
|
18
|
+
uint256 internal _tokenSupplyCap;
|
|
19
|
+
|
|
17
20
|
function _initialize(uint256 tokenSupplyCap_) internal virtual onlyInitializing {
|
|
18
21
|
if (tokenSupplyCap_ == 0) {
|
|
19
22
|
revert LSP7CappedSupplyRequired();
|
|
@@ -22,10 +25,20 @@ abstract contract LSP7CappedSupplyInitAbstract is
|
|
|
22
25
|
_tokenSupplyCap = tokenSupplyCap_;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
// ---
|
|
28
|
+
// --- Token queries
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
|
-
* @dev
|
|
31
|
+
* @dev Returns the number of tokens that can be minted
|
|
32
|
+
* @return The number of tokens that can be minted
|
|
33
|
+
*/
|
|
34
|
+
function tokenSupplyCap() public view virtual returns (uint256) {
|
|
35
|
+
return _tokenSupplyCap;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// --- Transfer functionality
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @dev Mints `amount` and transfers it to `to`.
|
|
29
42
|
*
|
|
30
43
|
* Requirements:
|
|
31
44
|
*
|
|
@@ -37,9 +50,13 @@ abstract contract LSP7CappedSupplyInitAbstract is
|
|
|
37
50
|
function _mint(
|
|
38
51
|
address to,
|
|
39
52
|
uint256 amount,
|
|
40
|
-
bool
|
|
53
|
+
bool allowNonLSP1Recipient,
|
|
41
54
|
bytes memory data
|
|
42
|
-
) internal virtual override
|
|
43
|
-
|
|
55
|
+
) internal virtual override {
|
|
56
|
+
if (totalSupply() + amount > tokenSupplyCap()) {
|
|
57
|
+
revert LSP7CappedSupplyCannotMintOverCap();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
super._mint(to, amount, allowNonLSP1Recipient, data);
|
|
44
61
|
}
|
|
45
62
|
}
|