@lukso/lsp-smart-contracts 0.9.0 → 0.10.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/README.md +15 -7
- package/artifacts/LSP0ERC725Account.json +62 -68
- package/artifacts/LSP0ERC725AccountInit.json +62 -68
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
- package/artifacts/LSP4Compatibility.json +32 -38
- package/artifacts/LSP4DigitalAssetMetadata.json +32 -38
- package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +32 -38
- package/artifacts/LSP6KeyManager.json +29 -15
- package/artifacts/LSP6KeyManagerInit.json +29 -15
- package/artifacts/LSP7CappedSupply.json +71 -36
- package/artifacts/LSP7CappedSupplyInitAbstract.json +71 -36
- package/artifacts/LSP7CompatibleERC20.json +71 -36
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +71 -36
- package/artifacts/LSP7CompatibleERC20Mintable.json +73 -38
- package/artifacts/LSP7CompatibleERC20MintableInit.json +73 -38
- package/artifacts/LSP7DigitalAsset.json +71 -36
- package/artifacts/LSP7DigitalAssetInitAbstract.json +71 -36
- package/artifacts/LSP7Mintable.json +73 -38
- package/artifacts/LSP7MintableInit.json +73 -38
- package/artifacts/LSP8CappedSupply.json +32 -38
- package/artifacts/LSP8CappedSupplyInitAbstract.json +32 -38
- package/artifacts/LSP8CompatibleERC721.json +35 -41
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +35 -41
- package/artifacts/LSP8CompatibleERC721Mintable.json +37 -43
- package/artifacts/LSP8CompatibleERC721MintableInit.json +37 -43
- package/artifacts/LSP8IdentifiableDigitalAsset.json +32 -38
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +32 -38
- package/artifacts/LSP8Mintable.json +34 -40
- package/artifacts/LSP8MintableInit.json +34 -40
- package/artifacts/LSP9Vault.json +61 -67
- package/artifacts/LSP9VaultInit.json +61 -67
- package/artifacts/UniversalProfile.json +62 -68
- package/artifacts/UniversalProfileInit.json +62 -68
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +45 -10
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +36 -6
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +361 -124
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +30 -4
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +37 -3
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -1
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +30 -15
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +0 -1
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +0 -1
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +5 -7
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -5
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +0 -4
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +91 -34
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +27 -8
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +18 -9
- package/contracts/LSP20CallVerification/LSP20Constants.sol +17 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +26 -12
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +0 -1
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +32 -16
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +11 -2
- package/contracts/LSP6KeyManager/LSP6Constants.sol +5 -5
- package/contracts/LSP6KeyManager/LSP6Errors.sol +10 -6
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +140 -68
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +30 -38
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +153 -60
- package/contracts/LSP6KeyManager/LSP6Utils.sol +1 -5
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +67 -13
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +24 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +1 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +3 -5
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +3 -5
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +15 -12
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +1 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +1 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +5 -5
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +6 -6
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +2 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +2 -2
- package/contracts/LSP9Vault/ILSP9Vault.sol +9 -1
- package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
- package/contracts/LSP9Vault/LSP9Vault.sol +0 -6
- package/contracts/LSP9Vault/LSP9VaultCore.sol +17 -15
- package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -1
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +8 -5
- package/contracts/UniversalProfileInitAbstract.sol +5 -0
- package/devdocs/Create2Factory.json +16 -0
- package/devdocs/LSP0ERC725Account.json +200 -0
- package/devdocs/LSP0ERC725AccountInit.json +203 -0
- package/devdocs/LSP11BasicSocialRecovery.json +146 -0
- package/devdocs/LSP11BasicSocialRecoveryInit.json +146 -0
- package/devdocs/LSP16UniversalFactory.json +51 -0
- package/devdocs/LSP1UniversalReceiverDelegateUP.json +80 -0
- package/devdocs/LSP1UniversalReceiverDelegateVault.json +62 -0
- package/devdocs/LSP4Compatibility.json +79 -0
- package/devdocs/LSP4DigitalAssetMetadata.json +84 -0
- package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +77 -0
- package/devdocs/LSP6KeyManager.json +257 -0
- package/devdocs/LSP6KeyManagerInit.json +260 -0
- package/devdocs/LSP7CappedSupply.json +211 -0
- package/devdocs/LSP7CappedSupplyInitAbstract.json +206 -0
- package/devdocs/LSP7CompatibleERC20.json +225 -0
- package/devdocs/LSP7CompatibleERC20InitAbstract.json +218 -0
- package/devdocs/LSP7CompatibleERC20Mintable.json +217 -0
- package/devdocs/LSP7CompatibleERC20MintableInit.json +227 -0
- package/devdocs/LSP7DigitalAsset.json +210 -0
- package/devdocs/LSP7DigitalAssetInitAbstract.json +202 -0
- package/devdocs/LSP7Mintable.json +219 -0
- package/devdocs/LSP7MintableInit.json +220 -0
- package/devdocs/LSP8CappedSupply.json +232 -0
- package/devdocs/LSP8CappedSupplyInitAbstract.json +227 -0
- package/devdocs/LSP8CompatibleERC721.json +298 -0
- package/devdocs/LSP8CompatibleERC721InitAbstract.json +291 -0
- package/devdocs/LSP8CompatibleERC721Mintable.json +290 -0
- package/devdocs/LSP8CompatibleERC721MintableInit.json +300 -0
- package/devdocs/LSP8IdentifiableDigitalAsset.json +230 -0
- package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +223 -0
- package/devdocs/LSP8Mintable.json +242 -0
- package/devdocs/LSP8MintableInit.json +245 -0
- package/devdocs/LSP9Vault.json +171 -0
- package/devdocs/LSP9VaultInit.json +175 -0
- package/devdocs/UniversalProfile.json +199 -0
- package/devdocs/UniversalProfileInit.json +202 -0
- package/devdocs/UniversalReceiverAddressStore.json +9 -0
- package/dist/constants.cjs.js +31569 -0
- package/dist/constants.d.ts +31681 -0
- package/dist/constants.es.js +31550 -0
- package/package.json +69 -52
- package/userdocs/Create2Factory.json +5 -0
- package/userdocs/LSP0ERC725Account.json +47 -0
- package/userdocs/LSP0ERC725AccountInit.json +47 -0
- package/userdocs/LSP11BasicSocialRecovery.json +29 -0
- package/userdocs/LSP11BasicSocialRecoveryInit.json +29 -0
- package/userdocs/LSP16UniversalFactory.json +5 -0
- package/userdocs/LSP1UniversalReceiverDelegateUP.json +10 -0
- package/userdocs/LSP1UniversalReceiverDelegateVault.json +10 -0
- package/userdocs/LSP4Compatibility.json +20 -0
- package/userdocs/LSP4DigitalAssetMetadata.json +23 -0
- package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +20 -0
- package/userdocs/LSP6KeyManager.json +18 -0
- package/userdocs/LSP6KeyManagerInit.json +18 -0
- package/userdocs/LSP7CappedSupply.json +29 -0
- package/userdocs/LSP7CappedSupplyInitAbstract.json +26 -0
- package/userdocs/LSP7CompatibleERC20.json +35 -0
- package/userdocs/LSP7CompatibleERC20InitAbstract.json +32 -0
- package/userdocs/LSP7CompatibleERC20Mintable.json +32 -0
- package/userdocs/LSP7CompatibleERC20MintableInit.json +35 -0
- package/userdocs/LSP7DigitalAsset.json +29 -0
- package/userdocs/LSP7DigitalAssetInitAbstract.json +26 -0
- package/userdocs/LSP7Mintable.json +29 -0
- package/userdocs/LSP7MintableInit.json +29 -0
- package/userdocs/LSP8CappedSupply.json +23 -0
- package/userdocs/LSP8CappedSupplyInitAbstract.json +20 -0
- package/userdocs/LSP8CompatibleERC721.json +29 -0
- package/userdocs/LSP8CompatibleERC721InitAbstract.json +26 -0
- package/userdocs/LSP8CompatibleERC721Mintable.json +26 -0
- package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -0
- package/userdocs/LSP8IdentifiableDigitalAsset.json +23 -0
- package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +20 -0
- package/userdocs/LSP8Mintable.json +23 -0
- package/userdocs/LSP8MintableInit.json +23 -0
- package/userdocs/LSP9Vault.json +38 -0
- package/userdocs/LSP9VaultInit.json +38 -0
- package/userdocs/UniversalProfile.json +50 -0
- package/userdocs/UniversalProfileInit.json +50 -0
- package/userdocs/UniversalReceiverAddressStore.json +5 -0
- package/CONTRIBUTING.md +0 -57
- package/common/constants.d.ts +0 -461
- package/common/constants.js +0 -789
- package/contracts/Utils/GasLib.sol +0 -17
- package/module/constants.d.ts +0 -461
- package/module/constants.js +0 -786
|
@@ -3,9 +3,9 @@ pragma solidity ^0.8.5;
|
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
5
|
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
|
+
import {ERC725Y_DataKeysValuesLengthMismatch} from "@erc725/smart-contracts/contracts/errors.sol";
|
|
6
7
|
|
|
7
8
|
// libraries
|
|
8
|
-
import {GasLib} from "../../Utils/GasLib.sol";
|
|
9
9
|
import {LSP6Utils} from "../LSP6Utils.sol";
|
|
10
10
|
|
|
11
11
|
// constants
|
|
@@ -62,6 +62,7 @@ abstract contract LSP6SetDataModule {
|
|
|
62
62
|
) internal view virtual {
|
|
63
63
|
bytes32 requiredPermission = _getPermissionRequiredToSetDataKey(
|
|
64
64
|
controlledContract,
|
|
65
|
+
controllerPermissions,
|
|
65
66
|
inputDataKey,
|
|
66
67
|
inputDataValue
|
|
67
68
|
);
|
|
@@ -79,6 +80,9 @@ abstract contract LSP6SetDataModule {
|
|
|
79
80
|
ERC725Y(controlledContract).getAllowedERC725YDataKeysFor(controllerAddress)
|
|
80
81
|
);
|
|
81
82
|
} else {
|
|
83
|
+
// Do not check again if we already checked that the controller had the permissions inside `_getPermissionRequiredToSetDataKey(...)`
|
|
84
|
+
if (requiredPermission == bytes32(0)) return;
|
|
85
|
+
|
|
82
86
|
// Otherwise CHECK the required permission if setting LSP6 permissions, LSP1 Delegate or LSP17 Extensions.
|
|
83
87
|
_requirePermissions(controllerAddress, controllerPermissions, requiredPermission);
|
|
84
88
|
}
|
|
@@ -87,20 +91,25 @@ abstract contract LSP6SetDataModule {
|
|
|
87
91
|
/**
|
|
88
92
|
* @dev verify if the `controllerAddress` has the permissions required to set an array of data keys on the ERC725Y storage of the `controlledContract`.
|
|
89
93
|
* @param controlledContract the address of the ERC725Y contract where the data key is set.
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
94
|
+
* @param controller the address of the controller who wants to set the data key.
|
|
95
|
+
* @param permissions the permissions of the controller address.
|
|
92
96
|
* @param inputDataKeys an array of data keys to set on the `controlledContract`.
|
|
93
97
|
* @param inputDataValues an array of data values to set for the `inputDataKeys`.
|
|
94
98
|
*/
|
|
95
99
|
function _verifyCanSetData(
|
|
96
100
|
address controlledContract,
|
|
97
|
-
address
|
|
98
|
-
bytes32
|
|
101
|
+
address controller,
|
|
102
|
+
bytes32 permissions,
|
|
99
103
|
bytes32[] memory inputDataKeys,
|
|
100
104
|
bytes[] memory inputDataValues
|
|
101
105
|
) internal view virtual {
|
|
106
|
+
if (inputDataKeys.length != inputDataValues.length) {
|
|
107
|
+
revert ERC725Y_DataKeysValuesLengthMismatch();
|
|
108
|
+
}
|
|
109
|
+
|
|
102
110
|
bool isSettingERC725YKeys;
|
|
103
111
|
bool[] memory validatedInputDataKeys = new bool[](inputDataKeys.length);
|
|
112
|
+
uint256 inputDataKeysAllowed = 0;
|
|
104
113
|
|
|
105
114
|
bytes32 requiredPermission;
|
|
106
115
|
|
|
@@ -108,6 +117,7 @@ abstract contract LSP6SetDataModule {
|
|
|
108
117
|
do {
|
|
109
118
|
requiredPermission = _getPermissionRequiredToSetDataKey(
|
|
110
119
|
controlledContract,
|
|
120
|
+
permissions,
|
|
111
121
|
inputDataKeys[ii],
|
|
112
122
|
inputDataValues[ii]
|
|
113
123
|
);
|
|
@@ -115,26 +125,34 @@ abstract contract LSP6SetDataModule {
|
|
|
115
125
|
if (requiredPermission == _PERMISSION_SETDATA) {
|
|
116
126
|
isSettingERC725YKeys = true;
|
|
117
127
|
} else {
|
|
118
|
-
//
|
|
119
|
-
|
|
128
|
+
// if we did not check already the permissions of the controller inside `_getPermissionRequiredToSetDataKey(...)`
|
|
129
|
+
if (requiredPermission != bytes32(0)) {
|
|
130
|
+
// CHECK the required permissions for setting LSP6 permissions, LSP1 Delegate or LSP17 Extensions.
|
|
131
|
+
_requirePermissions(controller, permissions, requiredPermission);
|
|
132
|
+
}
|
|
133
|
+
|
|
120
134
|
validatedInputDataKeys[ii] = true;
|
|
135
|
+
inputDataKeysAllowed++;
|
|
121
136
|
}
|
|
122
137
|
|
|
123
|
-
|
|
138
|
+
unchecked {
|
|
139
|
+
++ii;
|
|
140
|
+
}
|
|
124
141
|
} while (ii < inputDataKeys.length);
|
|
125
142
|
|
|
126
143
|
// CHECK if allowed to set one (or multiple) ERC725Y Data Keys
|
|
127
144
|
if (isSettingERC725YKeys) {
|
|
128
145
|
// Skip if caller has SUPER permissions
|
|
129
|
-
if (
|
|
146
|
+
if (permissions.hasPermission(_PERMISSION_SUPER_SETDATA)) return;
|
|
130
147
|
|
|
131
|
-
_requirePermissions(
|
|
148
|
+
_requirePermissions(controller, permissions, _PERMISSION_SETDATA);
|
|
132
149
|
|
|
133
150
|
_verifyAllowedERC725YDataKeys(
|
|
134
|
-
|
|
151
|
+
controller,
|
|
135
152
|
inputDataKeys,
|
|
136
|
-
ERC725Y(controlledContract).getAllowedERC725YDataKeysFor(
|
|
137
|
-
validatedInputDataKeys
|
|
153
|
+
ERC725Y(controlledContract).getAllowedERC725YDataKeysFor(controller),
|
|
154
|
+
validatedInputDataKeys,
|
|
155
|
+
inputDataKeysAllowed
|
|
138
156
|
);
|
|
139
157
|
}
|
|
140
158
|
}
|
|
@@ -148,22 +166,39 @@ abstract contract LSP6SetDataModule {
|
|
|
148
166
|
*/
|
|
149
167
|
function _getPermissionRequiredToSetDataKey(
|
|
150
168
|
address controlledContract,
|
|
169
|
+
bytes32 controllerPermissions,
|
|
151
170
|
bytes32 inputDataKey,
|
|
152
171
|
bytes memory inputDataValue
|
|
153
172
|
) internal view virtual returns (bytes32) {
|
|
154
173
|
// AddressPermissions[] or AddressPermissions[index]
|
|
155
174
|
if (bytes16(inputDataKey) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
|
|
175
|
+
// this is our best attempt to save gas to avoid reading the `target` storage multiple times
|
|
176
|
+
// to know if we need the permission `ADDCONTROLLER` or `EDITPERMISSIONS`.
|
|
177
|
+
// Even if `getData(...)` is `view`, multiple external calls to fetch values from storage add to the total gas used.
|
|
178
|
+
bool hasBothAddControllerAndEditPermissions = controllerPermissions.hasPermission(
|
|
179
|
+
_PERMISSION_ADDCONTROLLER | _PERMISSION_EDITPERMISSIONS
|
|
180
|
+
);
|
|
181
|
+
|
|
156
182
|
return
|
|
157
183
|
_getPermissionToSetPermissionsArray(
|
|
158
184
|
controlledContract,
|
|
159
185
|
inputDataKey,
|
|
160
|
-
inputDataValue
|
|
186
|
+
inputDataValue,
|
|
187
|
+
hasBothAddControllerAndEditPermissions
|
|
161
188
|
);
|
|
162
189
|
|
|
163
190
|
// AddressPermissions:...
|
|
164
191
|
} else if (bytes6(inputDataKey) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX) {
|
|
192
|
+
// same as above, save gas by avoiding redundants or unecessary external calls to fetch values from the `target` storage.
|
|
193
|
+
bool hasBothAddControllerAndEditPermissions = controllerPermissions.hasPermission(
|
|
194
|
+
_PERMISSION_ADDCONTROLLER | _PERMISSION_EDITPERMISSIONS
|
|
195
|
+
);
|
|
196
|
+
|
|
165
197
|
// AddressPermissions:Permissions:<address>
|
|
166
198
|
if (bytes12(inputDataKey) == _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX) {
|
|
199
|
+
// controller already has the permissions needed. Do not run internal function.
|
|
200
|
+
if (hasBothAddControllerAndEditPermissions) return (bytes32(0));
|
|
201
|
+
|
|
167
202
|
return _getPermissionToSetControllerPermissions(controlledContract, inputDataKey);
|
|
168
203
|
|
|
169
204
|
// AddressPermissions:AllowedCalls:<address>
|
|
@@ -172,7 +207,8 @@ abstract contract LSP6SetDataModule {
|
|
|
172
207
|
_getPermissionToSetAllowedCalls(
|
|
173
208
|
controlledContract,
|
|
174
209
|
inputDataKey,
|
|
175
|
-
inputDataValue
|
|
210
|
+
inputDataValue,
|
|
211
|
+
hasBothAddControllerAndEditPermissions
|
|
176
212
|
);
|
|
177
213
|
|
|
178
214
|
// AddressPermissions:AllowedERC725YKeys:<address>
|
|
@@ -183,7 +219,8 @@ abstract contract LSP6SetDataModule {
|
|
|
183
219
|
_getPermissionToSetAllowedERC725YDataKeys(
|
|
184
220
|
controlledContract,
|
|
185
221
|
inputDataKey,
|
|
186
|
-
inputDataValue
|
|
222
|
+
inputDataValue,
|
|
223
|
+
hasBothAddControllerAndEditPermissions
|
|
187
224
|
);
|
|
188
225
|
|
|
189
226
|
// if the first 6 bytes of the input data key are "AddressPermissions:..." but did not match
|
|
@@ -209,10 +246,31 @@ abstract contract LSP6SetDataModule {
|
|
|
209
246
|
inputDataKey == _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY ||
|
|
210
247
|
bytes12(inputDataKey) == _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX
|
|
211
248
|
) {
|
|
249
|
+
// same as above. If controller has both permissions, do not read the `target` storage
|
|
250
|
+
// to save gas by avoiding an extra external `view` call.
|
|
251
|
+
if (
|
|
252
|
+
controllerPermissions.hasPermission(
|
|
253
|
+
_PERMISSION_ADDUNIVERSALRECEIVERDELEGATE |
|
|
254
|
+
_PERMISSION_CHANGEUNIVERSALRECEIVERDELEGATE
|
|
255
|
+
)
|
|
256
|
+
) {
|
|
257
|
+
return bytes32(0);
|
|
258
|
+
}
|
|
259
|
+
|
|
212
260
|
return _getPermissionToSetLSP1Delegate(controlledContract, inputDataKey);
|
|
213
261
|
|
|
214
262
|
// LSP17Extension:<bytes4>
|
|
215
263
|
} else if (bytes12(inputDataKey) == _LSP17_EXTENSION_PREFIX) {
|
|
264
|
+
// same as above. If controller has both permissions, do not read the `target` storage
|
|
265
|
+
// to save gas by avoiding an extra external `view` call.
|
|
266
|
+
if (
|
|
267
|
+
controllerPermissions.hasPermission(
|
|
268
|
+
_PERMISSION_ADDEXTENSIONS | _PERMISSION_CHANGEEXTENSIONS
|
|
269
|
+
)
|
|
270
|
+
) {
|
|
271
|
+
return bytes32(0);
|
|
272
|
+
}
|
|
273
|
+
|
|
216
274
|
return _getPermissionToSetLSP17Extension(controlledContract, inputDataKey);
|
|
217
275
|
} else {
|
|
218
276
|
return _PERMISSION_SETDATA;
|
|
@@ -232,16 +290,19 @@ abstract contract LSP6SetDataModule {
|
|
|
232
290
|
function _getPermissionToSetPermissionsArray(
|
|
233
291
|
address controlledContract,
|
|
234
292
|
bytes32 inputDataKey,
|
|
235
|
-
bytes memory inputDataValue
|
|
293
|
+
bytes memory inputDataValue,
|
|
294
|
+
bool hasBothAddControllerAndEditPermissions
|
|
236
295
|
) internal view virtual returns (bytes32) {
|
|
237
|
-
bytes memory currentValue = ERC725Y(controlledContract).getData(inputDataKey);
|
|
238
|
-
|
|
239
296
|
// AddressPermissions[] -> array length
|
|
240
297
|
if (inputDataKey == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
|
|
298
|
+
// if the controller already has both permissions from one of the two required,
|
|
299
|
+
// No permission required as CHECK is already done. We don't need to read `target` storage.
|
|
300
|
+
if (hasBothAddControllerAndEditPermissions) return bytes32(0);
|
|
301
|
+
|
|
241
302
|
uint128 newLength = uint128(bytes16(inputDataValue));
|
|
242
303
|
|
|
243
304
|
return
|
|
244
|
-
newLength > uint128(bytes16(
|
|
305
|
+
newLength > uint128(bytes16(ERC725Y(controlledContract).getData(inputDataKey)))
|
|
245
306
|
? _PERMISSION_ADDCONTROLLER
|
|
246
307
|
: _PERMISSION_EDITPERMISSIONS;
|
|
247
308
|
}
|
|
@@ -253,7 +314,14 @@ abstract contract LSP6SetDataModule {
|
|
|
253
314
|
revert AddressPermissionArrayIndexValueNotAnAddress(inputDataKey, inputDataValue);
|
|
254
315
|
}
|
|
255
316
|
|
|
256
|
-
|
|
317
|
+
// if the controller already has both permissions from one of the two required below,
|
|
318
|
+
// No permission required as CHECK is already done. We don't need to read `target` storage.
|
|
319
|
+
if (hasBothAddControllerAndEditPermissions) return bytes32(0);
|
|
320
|
+
|
|
321
|
+
return
|
|
322
|
+
ERC725Y(controlledContract).getData(inputDataKey).length == 0
|
|
323
|
+
? _PERMISSION_ADDCONTROLLER
|
|
324
|
+
: _PERMISSION_EDITPERMISSIONS;
|
|
257
325
|
}
|
|
258
326
|
|
|
259
327
|
/**
|
|
@@ -284,16 +352,21 @@ abstract contract LSP6SetDataModule {
|
|
|
284
352
|
function _getPermissionToSetAllowedCalls(
|
|
285
353
|
address controlledContract,
|
|
286
354
|
bytes32 dataKey,
|
|
287
|
-
bytes memory dataValue
|
|
355
|
+
bytes memory dataValue,
|
|
356
|
+
bool hasBothAddControllerAndEditPermissions
|
|
288
357
|
) internal view virtual returns (bytes32) {
|
|
289
358
|
if (!LSP6Utils.isCompactBytesArrayOfAllowedCalls(dataValue)) {
|
|
290
359
|
revert InvalidEncodedAllowedCalls(dataValue);
|
|
291
360
|
}
|
|
292
361
|
|
|
293
|
-
// if
|
|
362
|
+
// if the controller already has both permissions from one of the two required below,
|
|
363
|
+
// No permission required as CHECK is already done. We don't need to read `target` storage.
|
|
364
|
+
if (hasBothAddControllerAndEditPermissions) return bytes32(0);
|
|
365
|
+
|
|
366
|
+
// if nothing is stored under the controller's Allowed Calls of the controller,
|
|
294
367
|
// we are trying to ADD a list of restricted calls (standards + address + function selector)
|
|
295
368
|
//
|
|
296
|
-
// if
|
|
369
|
+
// if some data is already set under the Allowed Calls of the controller,
|
|
297
370
|
// we are trying to CHANGE (= edit) these restrictions.
|
|
298
371
|
return
|
|
299
372
|
ERC725Y(controlledContract).getData(dataKey).length == 0
|
|
@@ -302,7 +375,7 @@ abstract contract LSP6SetDataModule {
|
|
|
302
375
|
}
|
|
303
376
|
|
|
304
377
|
/**
|
|
305
|
-
* @dev retrieve the permission required to set some
|
|
378
|
+
* @dev retrieve the permission required to set some Allowed ERC725Y Data Keys for a controller.
|
|
306
379
|
* @param controlledContract the address of the ERC725Y contract where the data key is verified.
|
|
307
380
|
* @param dataKey or `AddressPermissions:AllowedERC725YDataKeys:<controller-address>`.
|
|
308
381
|
* @param dataValue the updated value for the `dataKey`. MUST be a bytes[CompactBytesArray] of Allowed ERC725Y Data Keys.
|
|
@@ -311,7 +384,8 @@ abstract contract LSP6SetDataModule {
|
|
|
311
384
|
function _getPermissionToSetAllowedERC725YDataKeys(
|
|
312
385
|
address controlledContract,
|
|
313
386
|
bytes32 dataKey,
|
|
314
|
-
bytes memory dataValue
|
|
387
|
+
bytes memory dataValue,
|
|
388
|
+
bool hasBothAddControllerAndEditPermissions
|
|
315
389
|
) internal view returns (bytes32) {
|
|
316
390
|
if (!LSP6Utils.isCompactBytesArrayOfAllowedERC725YDataKeys(dataValue)) {
|
|
317
391
|
revert InvalidEncodedAllowedERC725YDataKeys(
|
|
@@ -320,6 +394,10 @@ abstract contract LSP6SetDataModule {
|
|
|
320
394
|
);
|
|
321
395
|
}
|
|
322
396
|
|
|
397
|
+
// if the controller already has both permissions from one of the two required below,
|
|
398
|
+
// CHECK is already done. We don't need to read `target` storage.
|
|
399
|
+
if (hasBothAddControllerAndEditPermissions) return bytes32(0);
|
|
400
|
+
|
|
323
401
|
// if there is nothing stored under the Allowed ERC725Y Data Keys of the controller,
|
|
324
402
|
// we are trying to ADD a list of restricted ERC725Y Data Keys.
|
|
325
403
|
//
|
|
@@ -382,13 +460,13 @@ abstract contract LSP6SetDataModule {
|
|
|
382
460
|
/**
|
|
383
461
|
* The pointer will always land on the length of each bytes value:
|
|
384
462
|
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
463
|
+
* ↓↓↓↓
|
|
464
|
+
* 0003 a00000
|
|
465
|
+
* 0005 fff83a0011
|
|
466
|
+
* 0020 aa0000000000000000000000000000000000000000000000000000000000cafe
|
|
467
|
+
* 0012 bb000000000000000000000000000000beef
|
|
468
|
+
* 0019 cc00000000000000000000000000000000000000000000deed
|
|
469
|
+
* ↑↑↑↑
|
|
392
470
|
*
|
|
393
471
|
*/
|
|
394
472
|
uint256 pointer;
|
|
@@ -401,10 +479,10 @@ abstract contract LSP6SetDataModule {
|
|
|
401
479
|
/**
|
|
402
480
|
* iterate over each data key and update the `pointer` variable with the index where to find the length of each data key.
|
|
403
481
|
*
|
|
404
|
-
* 0x
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
482
|
+
* 0x 0003 a00000 0003 fff83a 0020 aa00...00cafe
|
|
483
|
+
* ↑↑↑↑ ↑↑↑↑ ↑↑↑↑
|
|
484
|
+
* first | second | third
|
|
485
|
+
* length | length | length
|
|
408
486
|
*/
|
|
409
487
|
while (pointer < allowedERC725YDataKeysCompacted.length) {
|
|
410
488
|
// save the length of the allowed data key to calculate the `mask`.
|
|
@@ -463,7 +541,6 @@ abstract contract LSP6SetDataModule {
|
|
|
463
541
|
allowedKey := and(memoryAt, mask)
|
|
464
542
|
}
|
|
465
543
|
|
|
466
|
-
// voila you found the key ;)
|
|
467
544
|
if (allowedKey == (inputDataKey & mask)) return;
|
|
468
545
|
|
|
469
546
|
// move the pointer to the index of the next allowed data key
|
|
@@ -480,32 +557,32 @@ abstract contract LSP6SetDataModule {
|
|
|
480
557
|
* @param controllerAddress the address of the controller.
|
|
481
558
|
* @param inputDataKeys the data keys to verify against the allowed ERC725Y Data Keys of the `controllerAddress`.
|
|
482
559
|
* @param allowedERC725YDataKeysCompacted a CompactBytesArray of allowed ERC725Y Data Keys of the `controllerAddress`.
|
|
483
|
-
* @param
|
|
560
|
+
* @param validatedInputKeysList an array of booleans to store the result of the verification of each data keys checked.
|
|
561
|
+
* @param allowedDataKeysFound the number of data keys that were previously validated for other permissions like `ADDCONTROLLER`, `EDITPERMISSIONS`, etc...
|
|
484
562
|
*/
|
|
485
563
|
function _verifyAllowedERC725YDataKeys(
|
|
486
564
|
address controllerAddress,
|
|
487
565
|
bytes32[] memory inputDataKeys,
|
|
488
566
|
bytes memory allowedERC725YDataKeysCompacted,
|
|
489
|
-
bool[] memory
|
|
567
|
+
bool[] memory validatedInputKeysList,
|
|
568
|
+
uint256 allowedDataKeysFound
|
|
490
569
|
) internal pure virtual {
|
|
491
570
|
if (allowedERC725YDataKeysCompacted.length == 0)
|
|
492
571
|
revert NoERC725YDataKeysAllowed(controllerAddress);
|
|
493
572
|
|
|
494
|
-
uint256 allowedKeysFound;
|
|
495
|
-
|
|
496
573
|
// cache the input data keys from the start
|
|
497
574
|
uint256 inputKeysLength = inputDataKeys.length;
|
|
498
575
|
|
|
499
576
|
/**
|
|
500
577
|
* The pointer will always land on the length of each bytes value:
|
|
501
578
|
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
579
|
+
* ↓↓↓↓
|
|
580
|
+
* 0003 a00000
|
|
581
|
+
* 0005 fff83a0011
|
|
582
|
+
* 0020 aa0000000000000000000000000000000000000000000000000000000000cafe
|
|
583
|
+
* 0012 bb000000000000000000000000000000beef
|
|
584
|
+
* 0019 cc00000000000000000000000000000000000000000000deed
|
|
585
|
+
* ↑↑↑↑
|
|
509
586
|
*
|
|
510
587
|
*/
|
|
511
588
|
uint256 pointer;
|
|
@@ -518,10 +595,10 @@ abstract contract LSP6SetDataModule {
|
|
|
518
595
|
/**
|
|
519
596
|
* iterate over each data key and update the `pointer` variable with the index where to find the length of each data key.
|
|
520
597
|
*
|
|
521
|
-
* 0x
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
598
|
+
* 0x 0003 a00000 0003 fff83a 0020 aa00...00cafe
|
|
599
|
+
* ↑↑↑↑ ↑↑↑↑ ↑↑↑↑
|
|
600
|
+
* first | second | third
|
|
601
|
+
* length | length | length
|
|
525
602
|
*/
|
|
526
603
|
while (pointer < allowedERC725YDataKeysCompacted.length) {
|
|
527
604
|
// save the length of the allowed data key to calculate the `mask`.
|
|
@@ -583,20 +660,32 @@ abstract contract LSP6SetDataModule {
|
|
|
583
660
|
* Iterate over the `inputDataKeys` to check them against the allowed data keys.
|
|
584
661
|
* This until we have validated them all.
|
|
585
662
|
*/
|
|
586
|
-
for (uint256 ii; ii < inputKeysLength;
|
|
663
|
+
for (uint256 ii; ii < inputKeysLength; ) {
|
|
587
664
|
// if the input data key has been marked as allowed previously,
|
|
588
665
|
// SKIP it and move to the next input data key.
|
|
589
|
-
if (
|
|
666
|
+
if (validatedInputKeysList[ii]) {
|
|
667
|
+
unchecked {
|
|
668
|
+
++ii;
|
|
669
|
+
}
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
590
672
|
|
|
591
673
|
// CHECK if the input data key is allowed.
|
|
592
674
|
if ((inputDataKeys[ii] & mask) == allowedKey) {
|
|
593
675
|
// if the input data key is allowed, mark it as allowed
|
|
594
676
|
// and increment the number of allowed keys found.
|
|
595
|
-
|
|
596
|
-
|
|
677
|
+
validatedInputKeysList[ii] = true;
|
|
678
|
+
|
|
679
|
+
unchecked {
|
|
680
|
+
allowedDataKeysFound++;
|
|
681
|
+
}
|
|
597
682
|
|
|
598
683
|
// Continue checking until all the inputKeys` have been found.
|
|
599
|
-
if (
|
|
684
|
+
if (allowedDataKeysFound == inputKeysLength) return;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
unchecked {
|
|
688
|
+
++ii;
|
|
600
689
|
}
|
|
601
690
|
}
|
|
602
691
|
|
|
@@ -607,10 +696,14 @@ abstract contract LSP6SetDataModule {
|
|
|
607
696
|
}
|
|
608
697
|
|
|
609
698
|
// if we did not find all the input data keys, search for the first not allowed data key to revert.
|
|
610
|
-
for (uint256 jj; jj < inputKeysLength;
|
|
611
|
-
if (!
|
|
699
|
+
for (uint256 jj; jj < inputKeysLength; ) {
|
|
700
|
+
if (!validatedInputKeysList[jj]) {
|
|
612
701
|
revert NotAllowedERC725YDataKey(controllerAddress, inputDataKeys[jj]);
|
|
613
702
|
}
|
|
703
|
+
|
|
704
|
+
unchecked {
|
|
705
|
+
jj++;
|
|
706
|
+
}
|
|
614
707
|
}
|
|
615
708
|
}
|
|
616
709
|
|
|
@@ -9,12 +9,8 @@ import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
|
|
|
9
9
|
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
10
10
|
|
|
11
11
|
// constants
|
|
12
|
-
import {SETDATA_ARRAY_SELECTOR} from "@erc725/smart-contracts/contracts/constants.sol";
|
|
13
12
|
import "./LSP6Constants.sol";
|
|
14
13
|
|
|
15
|
-
// errors
|
|
16
|
-
import {NotAuthorised} from "./LSP6Errors.sol";
|
|
17
|
-
|
|
18
14
|
library LSP6Utils {
|
|
19
15
|
using LSP2Utils for bytes12;
|
|
20
16
|
|
|
@@ -155,7 +151,7 @@ library LSP6Utils {
|
|
|
155
151
|
bytes32[] memory keys,
|
|
156
152
|
bytes[] memory values
|
|
157
153
|
) internal returns (bytes memory result) {
|
|
158
|
-
bytes memory payload = abi.encodeWithSelector(
|
|
154
|
+
bytes memory payload = abi.encodeWithSelector(IERC725Y.setDataBatch.selector, keys, values);
|
|
159
155
|
result = ILSP6KeyManager(keyManagerAddress).execute(payload);
|
|
160
156
|
}
|
|
161
157
|
|
|
@@ -7,12 +7,6 @@ import {ILSP7DigitalAsset} from "./ILSP7DigitalAsset.sol";
|
|
|
7
7
|
|
|
8
8
|
// libraries
|
|
9
9
|
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
10
|
-
import {GasLib} from "../Utils/GasLib.sol";
|
|
11
|
-
|
|
12
|
-
// modules
|
|
13
|
-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
14
|
-
|
|
15
|
-
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
16
10
|
|
|
17
11
|
// errors
|
|
18
12
|
import "./LSP7Errors.sol";
|
|
@@ -27,19 +21,22 @@ import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "./LSP7Con
|
|
|
27
21
|
* @dev Core Implementation of a LSP7 compliant contract.
|
|
28
22
|
*
|
|
29
23
|
* This contract implement the core logic of the functions for the {ILSP7DigitalAsset} interface.
|
|
24
|
+
*
|
|
25
|
+
* Similar to ERC20, the non-standard {decreaseAllowance} and {increaseAllowance}
|
|
26
|
+
* functions have been added to mitigate the well-known issues around setting allowances.
|
|
30
27
|
*/
|
|
31
28
|
abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
32
29
|
// --- Storage
|
|
33
30
|
|
|
34
|
-
bool internal _isNonDivisible;
|
|
35
|
-
|
|
36
|
-
uint256 internal _existingTokens;
|
|
37
|
-
|
|
38
31
|
// Mapping from `tokenOwner` to an `amount` of tokens
|
|
39
|
-
mapping(address => uint256)
|
|
32
|
+
mapping(address => uint256) private _tokenOwnerBalances;
|
|
40
33
|
|
|
41
34
|
// Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
|
|
42
|
-
mapping(address => mapping(address => uint256))
|
|
35
|
+
mapping(address => mapping(address => uint256)) private _operatorAuthorizedAmount;
|
|
36
|
+
|
|
37
|
+
uint256 private _existingTokens;
|
|
38
|
+
|
|
39
|
+
bool internal _isNonDivisible;
|
|
43
40
|
|
|
44
41
|
// --- Token queries
|
|
45
42
|
|
|
@@ -155,9 +152,66 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
155
152
|
revert LSP7InvalidTransferBatch();
|
|
156
153
|
}
|
|
157
154
|
|
|
158
|
-
for (uint256 i = 0; i < fromLength;
|
|
155
|
+
for (uint256 i = 0; i < fromLength; ) {
|
|
159
156
|
// using the public transfer function to handle updates to operator authorized amounts
|
|
160
157
|
transfer(from[i], to[i], amount[i], allowNonLSP1Recipient[i], data[i]);
|
|
158
|
+
|
|
159
|
+
unchecked {
|
|
160
|
+
++i;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @notice Increase the allowance of `operator` by +`addedAmount`
|
|
167
|
+
* @dev Atomically increases the allowance granted to `operator` by the caller.
|
|
168
|
+
*
|
|
169
|
+
* This is an alternative approach to {authorizeOperator} that can be used as a mitigation
|
|
170
|
+
* for problems described in {ILSP7DigitalAsset}.
|
|
171
|
+
*
|
|
172
|
+
* Emits an {AuthorizedOperator} event indicating the updated allowance.
|
|
173
|
+
*
|
|
174
|
+
* @param operator the operator to increase the allowance for `msg.sender`
|
|
175
|
+
* @param addedAmount the additional amount to add on top of the current operator's allowance
|
|
176
|
+
*
|
|
177
|
+
* @dev Requirements:
|
|
178
|
+
* - `operator` cannot be the same address as `msg.sender`
|
|
179
|
+
* - `operator` cannot be the zero address.
|
|
180
|
+
*/
|
|
181
|
+
function increaseAllowance(address operator, uint256 addedAmount) public virtual {
|
|
182
|
+
_updateOperator(
|
|
183
|
+
msg.sender,
|
|
184
|
+
operator,
|
|
185
|
+
authorizedAmountFor(operator, msg.sender) + addedAmount
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @notice Decrease the allowance of `operator` by -`substractedAmount`
|
|
191
|
+
* @dev Atomically decreases the allowance granted to `operator` by the caller.
|
|
192
|
+
* This is an alternative approach to {authorizeOperator} that can be used as a mitigation
|
|
193
|
+
* for problems described in {ILSP7DigitalAsset}
|
|
194
|
+
*
|
|
195
|
+
* Emits:
|
|
196
|
+
* - an {AuthorizedOperator} event indicating the updated allowance after decreasing it.
|
|
197
|
+
* - a {RevokeOperator} event if `substractedAmount` is the full allowance,
|
|
198
|
+
* indicating `operator` does not have any allowance left for `msg.sender`.
|
|
199
|
+
*
|
|
200
|
+
* @param operator the operator to decrease allowance for `msg.sender`
|
|
201
|
+
* @param substractedAmount the amount to decrease by in the operator's allowance.
|
|
202
|
+
*
|
|
203
|
+
* @dev Requirements:
|
|
204
|
+
* - `operator` cannot be the zero address.
|
|
205
|
+
* - operator` must have allowance for the caller of at least `substractedAmount`.
|
|
206
|
+
*/
|
|
207
|
+
function decreaseAllowance(address operator, uint256 substractedAmount) public virtual {
|
|
208
|
+
uint256 currentAllowance = authorizedAmountFor(operator, msg.sender);
|
|
209
|
+
if (currentAllowance < substractedAmount) {
|
|
210
|
+
revert LSP7DecreasedAllowanceBelowZero();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
unchecked {
|
|
214
|
+
_updateOperator(msg.sender, operator, currentAllowance - substractedAmount);
|
|
161
215
|
}
|
|
162
216
|
}
|
|
163
217
|
|
|
@@ -55,3 +55,8 @@ error LSP7NotifyTokenReceiverIsEOA(address tokenReceiver);
|
|
|
55
55
|
* @dev reverts when trying to authorize or revoke the token's owner as an operator.
|
|
56
56
|
*/
|
|
57
57
|
error LSP7TokenOwnerCannotBeOperator();
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @dev Reverts when trying to decrease an operator's allowance to more than his current allowance
|
|
61
|
+
*/
|
|
62
|
+
error LSP7DecreasedAllowanceBelowZero();
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
|
-
import {
|
|
5
|
+
import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @dev LSP7 extension that allows token holders to destroy both
|
|
9
9
|
* their own tokens and those that they have an allowance for as an operator.
|
|
10
10
|
*/
|
|
11
|
-
abstract contract LSP7Burnable is
|
|
11
|
+
abstract contract LSP7Burnable is LSP7DigitalAsset {
|
|
12
12
|
/**
|
|
13
13
|
* @dev Destroys `amount` tokens from the `from` address.
|
|
14
14
|
*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import {LSP7DigitalAssetInitAbstract} from "../LSP7DigitalAssetInitAbstract.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 LSP7BurnableInitAbstract is LSP7DigitalAssetInitAbstract {
|
|
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
|
+
}
|
|
@@ -4,7 +4,6 @@ pragma solidity ^0.8.4;
|
|
|
4
4
|
|
|
5
5
|
// modules
|
|
6
6
|
import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol";
|
|
7
|
-
import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @dev LSP7 extension, adds token supply cap.
|
|
@@ -15,7 +14,7 @@ abstract contract LSP7CappedSupply is LSP7DigitalAsset {
|
|
|
15
14
|
error LSP7CappedSupplyCannotMintOverCap();
|
|
16
15
|
|
|
17
16
|
// --- Storage
|
|
18
|
-
uint256
|
|
17
|
+
uint256 private immutable _tokenSupplyCap;
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* @notice Sets the token max supply
|
|
@@ -4,7 +4,6 @@ pragma solidity ^0.8.4;
|
|
|
4
4
|
|
|
5
5
|
// modules
|
|
6
6
|
import {LSP7DigitalAssetInitAbstract} from "../LSP7DigitalAssetInitAbstract.sol";
|
|
7
|
-
import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @dev LSP7 extension, adds token supply cap.
|
|
@@ -15,7 +14,7 @@ abstract contract LSP7CappedSupplyInitAbstract is LSP7DigitalAssetInitAbstract {
|
|
|
15
14
|
error LSP7CappedSupplyCannotMintOverCap();
|
|
16
15
|
|
|
17
16
|
// --- Storage
|
|
18
|
-
uint256
|
|
17
|
+
uint256 private _tokenSupplyCap;
|
|
19
18
|
|
|
20
19
|
function _initialize(uint256 tokenSupplyCap_) internal virtual onlyInitializing {
|
|
21
20
|
if (tokenSupplyCap_ == 0) {
|