@lukso/lsp-smart-contracts 0.11.1 → 0.12.0-rc.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 +4 -0
- package/README.md +10 -2
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +52 -25
- package/artifacts/LSP0ERC725AccountInit.json +52 -25
- package/artifacts/LSP11BasicSocialRecovery.json +18 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +18 -2
- package/artifacts/LSP16UniversalFactory.json +3 -3
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +14 -46
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +14 -46
- package/artifacts/LSP23LinkedContractsFactory.json +3 -3
- package/artifacts/LSP4DigitalAssetMetadata.json +16 -0
- package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +16 -0
- package/artifacts/LSP6KeyManager.json +14 -9
- package/artifacts/LSP6KeyManagerInit.json +14 -9
- package/artifacts/LSP7CappedSupply.json +29 -4
- package/artifacts/LSP7CappedSupplyInitAbstract.json +29 -4
- package/artifacts/LSP7CompatibleERC20.json +48 -23
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +48 -23
- package/artifacts/LSP7CompatibleERC20Mintable.json +51 -26
- package/artifacts/LSP7CompatibleERC20MintableInit.json +51 -26
- package/artifacts/LSP7DigitalAsset.json +29 -4
- package/artifacts/LSP7DigitalAssetInitAbstract.json +29 -4
- package/artifacts/LSP7Mintable.json +32 -7
- package/artifacts/LSP7MintableInit.json +32 -7
- package/artifacts/LSP8CappedSupply.json +33 -3
- package/artifacts/LSP8CappedSupplyInitAbstract.json +33 -3
- package/artifacts/LSP8CompatibleERC721.json +55 -25
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +55 -25
- package/artifacts/LSP8CompatibleERC721Mintable.json +63 -28
- package/artifacts/LSP8CompatibleERC721MintableInit.json +63 -28
- package/artifacts/LSP8IdentifiableDigitalAsset.json +33 -3
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +33 -3
- package/artifacts/LSP8Mintable.json +41 -6
- package/artifacts/LSP8MintableInit.json +41 -6
- package/artifacts/LSP9Vault.json +38 -16
- package/artifacts/LSP9VaultInit.json +38 -16
- package/artifacts/UniversalProfile.json +52 -25
- package/artifacts/UniversalProfileInit.json +52 -25
- package/contracts/Factories/Create2Factory.sol +1 -1
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +0 -14
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +122 -94
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +5 -3
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +54 -14
- package/contracts/LSP11BasicSocialRecovery/LSP11Constants.sol +1 -1
- package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +1 -1
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +2 -2
- package/contracts/LSP14Ownable2Step/LSP14Constants.sol +1 -1
- package/contracts/LSP14Ownable2Step/LSP14Errors.sol +9 -3
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +16 -12
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +65 -96
- package/contracts/LSP17ContractExtension/LSP17Errors.sol +1 -1
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -7
- package/contracts/LSP17ContractExtension/LSP17Extension.sol +4 -4
- package/contracts/LSP17Extensions/Extension4337.sol +101 -0
- package/contracts/LSP17Extensions/OnERC721ReceivedExtension.sol +15 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +1 -2
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +24 -0
- package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +1 -0
- package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +0 -6
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +20 -27
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +18 -21
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +2 -46
- package/contracts/LSP20CallVerification/ILSP20CallVerifier.sol +13 -9
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +39 -14
- package/contracts/LSP20CallVerification/LSP20Constants.sol +6 -6
- package/contracts/LSP20CallVerification/LSP20Errors.sol +9 -3
- package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/ILSP23LinkedContractsFactory.sol +1 -1
- package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/IPostDeploymentModule.sol +1 -1
- package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/LSP23Errors.sol +1 -1
- package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/LSP23LinkedContractsFactory.sol +5 -1
- package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/modules/UniversalProfileInitPostDeploymentModule.sol +1 -1
- package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/modules/UniversalProfilePostDeploymentModule.sol +1 -1
- package/contracts/LSP25ExecuteRelayCall/LSP25Constants.sol +1 -1
- package/contracts/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.sol +8 -3
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +1 -97
- package/contracts/LSP3ProfileMetadata/LSP3Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +8 -3
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +8 -3
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +4 -3
- package/contracts/LSP6KeyManager/LSP6Constants.sol +4 -3
- package/contracts/LSP6KeyManager/LSP6Errors.sol +2 -23
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +0 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +134 -99
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +1 -2
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteRelayCallModule.sol +27 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +31 -25
- package/contracts/LSP6KeyManager/LSP6Utils.sol +29 -2
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +10 -10
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +22 -8
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +180 -118
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +21 -7
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +12 -3
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +5 -1
- package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +4 -1
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +7 -7
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +3 -3
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +120 -53
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +122 -53
- package/contracts/LSP7DigitalAsset/presets/ILSP7Mintable.sol +3 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +4 -4
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +2 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +4 -4
- package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +4 -4
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +1 -1
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +4 -4
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +11 -11
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +12 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +32 -16
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +61 -11
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +113 -74
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +63 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8BurnableInitAbstract.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +7 -7
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +162 -73
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +168 -84
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +7 -7
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +7 -7
- package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +8 -7
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +5 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +13 -7
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +9 -8
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +9 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +10 -8
- package/contracts/LSP9Vault/ILSP9Vault.sol +0 -13
- package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
- package/contracts/LSP9Vault/LSP9Errors.sol +1 -1
- package/contracts/LSP9Vault/LSP9VaultCore.sol +58 -41
- package/devdocs/LSP0ERC725Account.json +73 -45
- package/devdocs/LSP0ERC725AccountInit.json +73 -45
- package/devdocs/LSP11BasicSocialRecovery.json +13 -0
- package/devdocs/LSP11BasicSocialRecoveryInit.json +13 -0
- package/devdocs/LSP16UniversalFactory.json +9 -9
- package/devdocs/LSP1UniversalReceiverDelegateUP.json +1 -6
- package/devdocs/LSP1UniversalReceiverDelegateVault.json +1 -6
- package/devdocs/LSP4DigitalAssetMetadata.json +32 -10
- package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +32 -10
- package/devdocs/LSP6KeyManager.json +12 -14
- package/devdocs/LSP6KeyManagerInit.json +12 -14
- package/devdocs/LSP7CappedSupply.json +47 -20
- package/devdocs/LSP7CappedSupplyInitAbstract.json +47 -20
- package/devdocs/LSP7CompatibleERC20.json +88 -24
- package/devdocs/LSP7CompatibleERC20InitAbstract.json +88 -24
- package/devdocs/LSP7CompatibleERC20Mintable.json +88 -24
- package/devdocs/LSP7CompatibleERC20MintableInit.json +88 -24
- package/devdocs/LSP7DigitalAsset.json +47 -20
- package/devdocs/LSP7DigitalAssetInitAbstract.json +47 -20
- package/devdocs/LSP7Mintable.json +47 -20
- package/devdocs/LSP7MintableInit.json +47 -20
- package/devdocs/LSP8CappedSupply.json +57 -25
- package/devdocs/LSP8CappedSupplyInitAbstract.json +57 -25
- package/devdocs/LSP8CompatibleERC721.json +84 -31
- package/devdocs/LSP8CompatibleERC721InitAbstract.json +84 -31
- package/devdocs/LSP8CompatibleERC721Mintable.json +86 -33
- package/devdocs/LSP8CompatibleERC721MintableInit.json +87 -34
- package/devdocs/LSP8IdentifiableDigitalAsset.json +61 -26
- package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +57 -25
- package/devdocs/LSP8Mintable.json +59 -27
- package/devdocs/LSP8MintableInit.json +60 -28
- package/devdocs/LSP9Vault.json +57 -35
- package/devdocs/LSP9VaultInit.json +57 -35
- package/devdocs/UniversalProfile.json +73 -45
- package/devdocs/UniversalProfileInit.json +73 -45
- package/dist/constants.cjs.js +4323 -2361
- package/dist/constants.d.ts +2933 -1022
- package/dist/constants.es.js +4322 -2361
- package/package.json +8 -6
- package/userdocs/LSP0ERC725Account.json +17 -8
- package/userdocs/LSP0ERC725AccountInit.json +17 -8
- package/userdocs/LSP16UniversalFactory.json +26 -1
- package/userdocs/LSP1UniversalReceiverDelegateUP.json +1 -11
- package/userdocs/LSP1UniversalReceiverDelegateVault.json +1 -11
- package/userdocs/LSP4DigitalAssetMetadata.json +7 -4
- package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +7 -4
- package/userdocs/LSP6KeyManager.json +0 -5
- package/userdocs/LSP6KeyManagerInit.json +0 -5
- package/userdocs/LSP7CappedSupply.json +14 -6
- package/userdocs/LSP7CappedSupplyInitAbstract.json +13 -5
- package/userdocs/LSP7CompatibleERC20.json +15 -5
- package/userdocs/LSP7CompatibleERC20InitAbstract.json +15 -5
- package/userdocs/LSP7CompatibleERC20Mintable.json +15 -5
- package/userdocs/LSP7CompatibleERC20MintableInit.json +15 -5
- package/userdocs/LSP7DigitalAsset.json +15 -5
- package/userdocs/LSP7DigitalAssetInitAbstract.json +15 -5
- package/userdocs/LSP7Mintable.json +15 -5
- package/userdocs/LSP7MintableInit.json +15 -5
- package/userdocs/LSP8CappedSupply.json +13 -5
- package/userdocs/LSP8CappedSupplyInitAbstract.json +12 -4
- package/userdocs/LSP8CompatibleERC721.json +27 -17
- package/userdocs/LSP8CompatibleERC721InitAbstract.json +27 -17
- package/userdocs/LSP8CompatibleERC721Mintable.json +28 -18
- package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -19
- package/userdocs/LSP8IdentifiableDigitalAsset.json +15 -5
- package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +14 -4
- package/userdocs/LSP8Mintable.json +15 -5
- package/userdocs/LSP8MintableInit.json +16 -6
- package/userdocs/LSP9Vault.json +20 -11
- package/userdocs/LSP9VaultInit.json +20 -11
- package/userdocs/UniversalProfile.json +17 -8
- package/userdocs/UniversalProfileInit.json +17 -8
- package/artifacts/LSP4Compatibility.json +0 -216
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +0 -25
- package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +0 -38
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +0 -83
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +0 -175
- package/devdocs/LSP4Compatibility.json +0 -79
- package/userdocs/LSP4Compatibility.json +0 -20
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
@@ -17,7 +17,18 @@ import {
|
|
|
17
17
|
} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
18
18
|
|
|
19
19
|
// errors
|
|
20
|
-
import
|
|
20
|
+
import {
|
|
21
|
+
LSP7CannotSendToSelf,
|
|
22
|
+
LSP7AmountExceedsAuthorizedAmount,
|
|
23
|
+
LSP7InvalidTransferBatch,
|
|
24
|
+
LSP7AmountExceedsBalance,
|
|
25
|
+
LSP7DecreasedAllowanceBelowZero,
|
|
26
|
+
LSP7CannotUseAddressZeroAsOperator,
|
|
27
|
+
LSP7TokenOwnerCannotBeOperator,
|
|
28
|
+
LSP7CannotSendWithAddressZero,
|
|
29
|
+
LSP7NotifyTokenReceiverContractMissingLSP1Interface,
|
|
30
|
+
LSP7NotifyTokenReceiverIsEOA
|
|
31
|
+
} from "./LSP7Errors.sol";
|
|
21
32
|
|
|
22
33
|
// constants
|
|
23
34
|
import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
|
|
@@ -39,35 +50,36 @@ import {
|
|
|
39
50
|
*/
|
|
40
51
|
abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
41
52
|
using EnumerableSet for EnumerableSet.AddressSet;
|
|
53
|
+
|
|
42
54
|
// --- Storage
|
|
43
55
|
|
|
56
|
+
bool internal _isNonDivisible;
|
|
57
|
+
|
|
58
|
+
uint256 internal _existingTokens;
|
|
59
|
+
|
|
44
60
|
// Mapping from `tokenOwner` to an `amount` of tokens
|
|
45
61
|
mapping(address => uint256) internal _tokenOwnerBalances;
|
|
46
62
|
|
|
47
|
-
// Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
|
|
48
|
-
mapping(address => mapping(address => uint256))
|
|
49
|
-
internal _operatorAuthorizedAmount;
|
|
50
|
-
|
|
51
63
|
// Mapping an `address` to its authorized operator addresses.
|
|
52
64
|
mapping(address => EnumerableSet.AddressSet) internal _operators;
|
|
53
65
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
// Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
|
|
67
|
+
mapping(address => mapping(address => uint256))
|
|
68
|
+
internal _operatorAuthorizedAmount;
|
|
57
69
|
|
|
58
70
|
// --- Token queries
|
|
59
71
|
|
|
60
72
|
/**
|
|
61
73
|
* @inheritdoc ILSP7DigitalAsset
|
|
62
74
|
*/
|
|
63
|
-
function decimals() public view virtual returns (uint8) {
|
|
75
|
+
function decimals() public view virtual override returns (uint8) {
|
|
64
76
|
return _isNonDivisible ? 0 : 18;
|
|
65
77
|
}
|
|
66
78
|
|
|
67
79
|
/**
|
|
68
80
|
* @inheritdoc ILSP7DigitalAsset
|
|
69
81
|
*/
|
|
70
|
-
function totalSupply() public view virtual returns (uint256) {
|
|
82
|
+
function totalSupply() public view virtual override returns (uint256) {
|
|
71
83
|
return _existingTokens;
|
|
72
84
|
}
|
|
73
85
|
|
|
@@ -78,7 +90,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
78
90
|
*/
|
|
79
91
|
function balanceOf(
|
|
80
92
|
address tokenOwner
|
|
81
|
-
) public view virtual returns (uint256) {
|
|
93
|
+
) public view virtual override returns (uint256) {
|
|
82
94
|
return _tokenOwnerBalances[tokenOwner];
|
|
83
95
|
}
|
|
84
96
|
|
|
@@ -100,7 +112,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
100
112
|
address operator,
|
|
101
113
|
uint256 amount,
|
|
102
114
|
bytes memory operatorNotificationData
|
|
103
|
-
) public virtual {
|
|
115
|
+
) public virtual override {
|
|
104
116
|
_updateOperator(msg.sender, operator, amount, operatorNotificationData);
|
|
105
117
|
|
|
106
118
|
bytes memory lsp1Data = abi.encode(
|
|
@@ -117,7 +129,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
117
129
|
function revokeOperator(
|
|
118
130
|
address operator,
|
|
119
131
|
bytes memory operatorNotificationData
|
|
120
|
-
) public virtual {
|
|
132
|
+
) public virtual override {
|
|
121
133
|
_updateOperator(msg.sender, operator, 0, operatorNotificationData);
|
|
122
134
|
|
|
123
135
|
bytes memory lsp1Data = abi.encode(
|
|
@@ -134,7 +146,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
134
146
|
function authorizedAmountFor(
|
|
135
147
|
address operator,
|
|
136
148
|
address tokenOwner
|
|
137
|
-
) public view virtual returns (uint256) {
|
|
149
|
+
) public view virtual override returns (uint256) {
|
|
138
150
|
if (tokenOwner == operator) {
|
|
139
151
|
return _tokenOwnerBalances[tokenOwner];
|
|
140
152
|
} else {
|
|
@@ -147,7 +159,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
147
159
|
*/
|
|
148
160
|
function getOperatorsOf(
|
|
149
161
|
address tokenOwner
|
|
150
|
-
) public view virtual returns (address[] memory) {
|
|
162
|
+
) public view virtual override returns (address[] memory) {
|
|
151
163
|
return _operators[tokenOwner].values();
|
|
152
164
|
}
|
|
153
165
|
|
|
@@ -160,27 +172,20 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
160
172
|
address from,
|
|
161
173
|
address to,
|
|
162
174
|
uint256 amount,
|
|
163
|
-
bool
|
|
175
|
+
bool force,
|
|
164
176
|
bytes memory data
|
|
165
|
-
) public virtual {
|
|
177
|
+
) public virtual override {
|
|
166
178
|
if (from == to) revert LSP7CannotSendToSelf();
|
|
167
179
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
operatorAmount,
|
|
175
|
-
operator,
|
|
176
|
-
amount
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
_updateOperator(from, operator, operatorAmount - amount, "");
|
|
180
|
+
if (msg.sender != from) {
|
|
181
|
+
_spendAllowance({
|
|
182
|
+
operator: msg.sender,
|
|
183
|
+
tokenOwner: from,
|
|
184
|
+
amountToSpend: amount
|
|
185
|
+
});
|
|
181
186
|
}
|
|
182
187
|
|
|
183
|
-
_transfer(from, to, amount,
|
|
188
|
+
_transfer(from, to, amount, force, data);
|
|
184
189
|
}
|
|
185
190
|
|
|
186
191
|
/**
|
|
@@ -190,28 +195,22 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
190
195
|
address[] memory from,
|
|
191
196
|
address[] memory to,
|
|
192
197
|
uint256[] memory amount,
|
|
193
|
-
bool[] memory
|
|
198
|
+
bool[] memory force,
|
|
194
199
|
bytes[] memory data
|
|
195
|
-
) public virtual {
|
|
200
|
+
) public virtual override {
|
|
196
201
|
uint256 fromLength = from.length;
|
|
197
202
|
if (
|
|
198
203
|
fromLength != to.length ||
|
|
199
204
|
fromLength != amount.length ||
|
|
200
|
-
fromLength !=
|
|
205
|
+
fromLength != force.length ||
|
|
201
206
|
fromLength != data.length
|
|
202
207
|
) {
|
|
203
208
|
revert LSP7InvalidTransferBatch();
|
|
204
209
|
}
|
|
205
210
|
|
|
206
|
-
for (uint256 i
|
|
211
|
+
for (uint256 i; i < fromLength; ) {
|
|
207
212
|
// using the public transfer function to handle updates to operator authorized amounts
|
|
208
|
-
transfer(
|
|
209
|
-
from[i],
|
|
210
|
-
to[i],
|
|
211
|
-
amount[i],
|
|
212
|
-
allowNonLSP1Recipient[i],
|
|
213
|
-
data[i]
|
|
214
|
-
);
|
|
213
|
+
transfer(from[i], to[i], amount[i], force[i], data[i]);
|
|
215
214
|
|
|
216
215
|
unchecked {
|
|
217
216
|
++i;
|
|
@@ -230,8 +229,8 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
230
229
|
* This is an alternative approach to {authorizeOperator} that can be used as a mitigation
|
|
231
230
|
* for the double spending allowance problem.
|
|
232
231
|
*
|
|
233
|
-
* @param operator
|
|
234
|
-
* @param addedAmount
|
|
232
|
+
* @param operator The operator to increase the allowance for `msg.sender`
|
|
233
|
+
* @param addedAmount The additional amount to add on top of the current operator's allowance
|
|
235
234
|
*
|
|
236
235
|
* @custom:requirements
|
|
237
236
|
* - `operator` cannot be the same address as `msg.sender`
|
|
@@ -246,6 +245,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
246
245
|
) public virtual {
|
|
247
246
|
uint256 newAllowance = authorizedAmountFor(operator, msg.sender) +
|
|
248
247
|
addedAmount;
|
|
248
|
+
|
|
249
249
|
_updateOperator(
|
|
250
250
|
msg.sender,
|
|
251
251
|
operator,
|
|
@@ -266,7 +266,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
266
266
|
* It has been added in the LSP7 contract implementation so that it can be used as a prevention mechanism
|
|
267
267
|
* against the double spending allowance vulnerability.
|
|
268
268
|
*
|
|
269
|
-
* @notice Decrease the allowance of `operator` by -`
|
|
269
|
+
* @notice Decrease the allowance of `operator` by -`subtractedAmount`
|
|
270
270
|
*
|
|
271
271
|
* @dev Atomically decreases the allowance granted to `operator` by the caller.
|
|
272
272
|
* This is an alternative approach to {authorizeOperator} that can be used as a mitigation
|
|
@@ -274,29 +274,29 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
274
274
|
*
|
|
275
275
|
* @custom:events
|
|
276
276
|
* - {AuthorizedOperator} event indicating the updated allowance after decreasing it.
|
|
277
|
-
* - {RevokeOperator} event if `
|
|
277
|
+
* - {RevokeOperator} event if `subtractedAmount` is the full allowance,
|
|
278
278
|
* indicating `operator` does not have any alauthorizedAmountForlowance left for `msg.sender`.
|
|
279
279
|
*
|
|
280
|
-
* @param operator
|
|
281
|
-
* @param
|
|
280
|
+
* @param operator The operator to decrease allowance for `msg.sender`
|
|
281
|
+
* @param subtractedAmount The amount to decrease by in the operator's allowance.
|
|
282
282
|
*
|
|
283
283
|
* @custom:requirements
|
|
284
284
|
* - `operator` cannot be the zero address.
|
|
285
|
-
* - `operator` must have allowance for the caller of at least `
|
|
285
|
+
* - `operator` must have allowance for the caller of at least `subtractedAmount`.
|
|
286
286
|
*/
|
|
287
287
|
function decreaseAllowance(
|
|
288
288
|
address operator,
|
|
289
|
-
uint256
|
|
289
|
+
uint256 subtractedAmount,
|
|
290
290
|
bytes memory operatorNotificationData
|
|
291
291
|
) public virtual {
|
|
292
292
|
uint256 currentAllowance = authorizedAmountFor(operator, msg.sender);
|
|
293
|
-
if (currentAllowance <
|
|
293
|
+
if (currentAllowance < subtractedAmount) {
|
|
294
294
|
revert LSP7DecreasedAllowanceBelowZero();
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
uint256 newAllowance;
|
|
298
298
|
unchecked {
|
|
299
|
-
newAllowance = currentAllowance -
|
|
299
|
+
newAllowance = currentAllowance - subtractedAmount;
|
|
300
300
|
_updateOperator(
|
|
301
301
|
msg.sender,
|
|
302
302
|
operator,
|
|
@@ -318,6 +318,10 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
318
318
|
* If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators.
|
|
319
319
|
* If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified.
|
|
320
320
|
*
|
|
321
|
+
* @param tokenOwner The address that will give `operator` an allowance for on its balance.
|
|
322
|
+
* @param operator The address to grant an allowance to spend.
|
|
323
|
+
* @param allowance The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance.
|
|
324
|
+
*
|
|
321
325
|
* @custom:events
|
|
322
326
|
* - {RevokedOperator} event when operator's allowance is set to `0`.
|
|
323
327
|
* - {AuthorizedOperator} event when operator's allowance is set to any other amount.
|
|
@@ -329,7 +333,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
329
333
|
function _updateOperator(
|
|
330
334
|
address tokenOwner,
|
|
331
335
|
address operator,
|
|
332
|
-
uint256
|
|
336
|
+
uint256 allowance,
|
|
333
337
|
bytes memory operatorNotificationData
|
|
334
338
|
) internal virtual {
|
|
335
339
|
if (operator == address(0)) {
|
|
@@ -340,14 +344,14 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
340
344
|
revert LSP7TokenOwnerCannotBeOperator();
|
|
341
345
|
}
|
|
342
346
|
|
|
343
|
-
_operatorAuthorizedAmount[tokenOwner][operator] =
|
|
347
|
+
_operatorAuthorizedAmount[tokenOwner][operator] = allowance;
|
|
344
348
|
|
|
345
|
-
if (
|
|
349
|
+
if (allowance != 0) {
|
|
346
350
|
_operators[tokenOwner].add(operator);
|
|
347
351
|
emit AuthorizedOperator(
|
|
348
352
|
operator,
|
|
349
353
|
tokenOwner,
|
|
350
|
-
|
|
354
|
+
allowance,
|
|
351
355
|
operatorNotificationData
|
|
352
356
|
);
|
|
353
357
|
} else {
|
|
@@ -363,9 +367,13 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
363
367
|
/**
|
|
364
368
|
* @dev Mints `amount` of tokens and transfers it to `to`.
|
|
365
369
|
*
|
|
366
|
-
* @
|
|
367
|
-
*
|
|
368
|
-
*
|
|
370
|
+
* @custom:info Any logic in the:
|
|
371
|
+
* - {_beforeTokenTransfer} function will run before updating the balances.
|
|
372
|
+
* - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the recipient via LSP1**.
|
|
373
|
+
*
|
|
374
|
+
* @param to The address to mint tokens for.
|
|
375
|
+
* @param amount The amount of tokens to mint.
|
|
376
|
+
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
|
|
369
377
|
* @param data Additional data the caller wants included in the emitted {Transfer} event, and sent in the LSP1 hook to the `to` address.
|
|
370
378
|
*
|
|
371
379
|
* @custom:requirements
|
|
@@ -376,33 +384,26 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
376
384
|
function _mint(
|
|
377
385
|
address to,
|
|
378
386
|
uint256 amount,
|
|
379
|
-
bool
|
|
387
|
+
bool force,
|
|
380
388
|
bytes memory data
|
|
381
389
|
) internal virtual {
|
|
382
390
|
if (to == address(0)) {
|
|
383
391
|
revert LSP7CannotSendWithAddressZero();
|
|
384
392
|
}
|
|
385
393
|
|
|
386
|
-
address
|
|
387
|
-
|
|
388
|
-
_beforeTokenTransfer(address(0), to, amount);
|
|
394
|
+
_beforeTokenTransfer(address(0), to, amount, data);
|
|
389
395
|
|
|
390
396
|
// tokens being minted
|
|
391
397
|
_existingTokens += amount;
|
|
392
398
|
|
|
393
399
|
_tokenOwnerBalances[to] += amount;
|
|
394
400
|
|
|
395
|
-
emit Transfer(
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
to,
|
|
399
|
-
amount,
|
|
400
|
-
allowNonLSP1Recipient,
|
|
401
|
-
data
|
|
402
|
-
);
|
|
401
|
+
emit Transfer(msg.sender, address(0), to, amount, force, data);
|
|
402
|
+
|
|
403
|
+
_afterTokenTransfer(address(0), to, amount, data);
|
|
403
404
|
|
|
404
405
|
bytes memory lsp1Data = abi.encode(address(0), to, amount, data);
|
|
405
|
-
_notifyTokenReceiver(to,
|
|
406
|
+
_notifyTokenReceiver(to, force, lsp1Data);
|
|
406
407
|
}
|
|
407
408
|
|
|
408
409
|
/**
|
|
@@ -412,10 +413,12 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
412
413
|
* function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
|
|
413
414
|
* all the parameters in the calldata packed encoded.
|
|
414
415
|
*
|
|
415
|
-
* Any logic in the
|
|
416
|
+
* @custom:info Any logic in the:
|
|
417
|
+
* - {_beforeTokenTransfer} function will run before updating the balances.
|
|
418
|
+
* - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender via LSP1**.
|
|
416
419
|
*
|
|
417
|
-
* @param from
|
|
418
|
-
* @param amount
|
|
420
|
+
* @param from The address to burn tokens from its balance.
|
|
421
|
+
* @param amount The amount of tokens to burn.
|
|
419
422
|
* @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
|
|
420
423
|
*
|
|
421
424
|
* @custom:hint In dApps, you can know which address is burning tokens by listening for the `Transfer` event and filter with the zero address as `to`.
|
|
@@ -442,35 +445,71 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
442
445
|
revert LSP7AmountExceedsBalance(balance, from, amount);
|
|
443
446
|
}
|
|
444
447
|
|
|
445
|
-
address
|
|
446
|
-
if (operator != from) {
|
|
447
|
-
uint256 authorizedAmount = _operatorAuthorizedAmount[from][
|
|
448
|
-
operator
|
|
449
|
-
];
|
|
450
|
-
if (amount > authorizedAmount) {
|
|
451
|
-
revert LSP7AmountExceedsAuthorizedAmount(
|
|
452
|
-
from,
|
|
453
|
-
authorizedAmount,
|
|
454
|
-
operator,
|
|
455
|
-
amount
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
_operatorAuthorizedAmount[from][operator] -= amount;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
_beforeTokenTransfer(from, address(0), amount);
|
|
448
|
+
_beforeTokenTransfer(from, address(0), amount, data);
|
|
462
449
|
|
|
463
450
|
// tokens being burnt
|
|
464
451
|
_existingTokens -= amount;
|
|
465
452
|
|
|
466
453
|
_tokenOwnerBalances[from] -= amount;
|
|
467
454
|
|
|
468
|
-
emit Transfer(
|
|
455
|
+
emit Transfer(msg.sender, from, address(0), amount, false, data);
|
|
456
|
+
emit Transfer({
|
|
457
|
+
operator: msg.sender,
|
|
458
|
+
from: from,
|
|
459
|
+
to: address(0),
|
|
460
|
+
amount: amount,
|
|
461
|
+
force: false,
|
|
462
|
+
data: data
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
_afterTokenTransfer(from, address(0), amount, data);
|
|
469
466
|
|
|
470
467
|
bytes memory lsp1Data = abi.encode(from, address(0), amount, data);
|
|
471
468
|
_notifyTokenSender(from, lsp1Data);
|
|
472
469
|
}
|
|
473
470
|
|
|
471
|
+
/**
|
|
472
|
+
* @dev Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`.
|
|
473
|
+
*
|
|
474
|
+
* @param operator The address of the operator to decrease the allowance of.
|
|
475
|
+
* @param tokenOwner The address that granted an allowance on its balance to `operator`.
|
|
476
|
+
* @param amountToSpend The amount of tokens to substract in allowance of `operator`.
|
|
477
|
+
*
|
|
478
|
+
* @custom:events
|
|
479
|
+
* - {RevokedOperator} event when operator's allowance is set to `0`.
|
|
480
|
+
* - {AuthorizedOperator} event when operator's allowance is set to any other amount.
|
|
481
|
+
*
|
|
482
|
+
* @custom:requirements
|
|
483
|
+
* - The `amountToSpend` MUST be at least the allowance granted to `operator` (accessible via {`authorizedAmountFor}`)
|
|
484
|
+
* - `operator` cannot be the zero address.
|
|
485
|
+
* - `operator` cannot be the same address as `tokenOwner`.
|
|
486
|
+
*/
|
|
487
|
+
function _spendAllowance(
|
|
488
|
+
address operator,
|
|
489
|
+
address tokenOwner,
|
|
490
|
+
uint256 amountToSpend
|
|
491
|
+
) internal virtual {
|
|
492
|
+
uint256 authorizedAmount = _operatorAuthorizedAmount[tokenOwner][
|
|
493
|
+
operator
|
|
494
|
+
];
|
|
495
|
+
|
|
496
|
+
if (amountToSpend > authorizedAmount) {
|
|
497
|
+
revert LSP7AmountExceedsAuthorizedAmount(
|
|
498
|
+
tokenOwner,
|
|
499
|
+
authorizedAmount,
|
|
500
|
+
operator,
|
|
501
|
+
amountToSpend
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
_updateOperator({
|
|
506
|
+
tokenOwner: tokenOwner,
|
|
507
|
+
operator: operator,
|
|
508
|
+
allowance: authorizedAmount - amountToSpend,
|
|
509
|
+
operatorNotificationData: ""
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
474
513
|
/**
|
|
475
514
|
* @dev Transfer tokens from `from` to `to` by decreasing the balance of `from` by `-amount` and increasing the balance
|
|
476
515
|
* of `to` by `+amount`.
|
|
@@ -479,12 +518,14 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
479
518
|
* function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
|
|
480
519
|
* all the parameters in the calldata packed encoded.
|
|
481
520
|
*
|
|
482
|
-
* Any logic in the
|
|
521
|
+
* @custom:info Any logic in the:
|
|
522
|
+
* - {_beforeTokenTransfer} function will run before updating the balances.
|
|
523
|
+
* - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender/recipient via LSP1**.
|
|
483
524
|
*
|
|
484
|
-
* @param from
|
|
485
|
-
* @param to
|
|
486
|
-
* @param amount
|
|
487
|
-
* @param
|
|
525
|
+
* @param from The address to decrease the balance.
|
|
526
|
+
* @param to The address to increase the balance.
|
|
527
|
+
* @param amount The amount of tokens to transfer from `from` to `to`.
|
|
528
|
+
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
|
|
488
529
|
* @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
|
|
489
530
|
*
|
|
490
531
|
* @custom:requirements
|
|
@@ -498,7 +539,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
498
539
|
address from,
|
|
499
540
|
address to,
|
|
500
541
|
uint256 amount,
|
|
501
|
-
bool
|
|
542
|
+
bool force,
|
|
502
543
|
bytes memory data
|
|
503
544
|
) internal virtual {
|
|
504
545
|
if (from == address(0) || to == address(0)) {
|
|
@@ -510,19 +551,19 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
510
551
|
revert LSP7AmountExceedsBalance(balance, from, amount);
|
|
511
552
|
}
|
|
512
553
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
_beforeTokenTransfer(from, to, amount);
|
|
554
|
+
_beforeTokenTransfer(from, to, amount, data);
|
|
516
555
|
|
|
517
556
|
_tokenOwnerBalances[from] -= amount;
|
|
518
557
|
_tokenOwnerBalances[to] += amount;
|
|
519
558
|
|
|
520
|
-
emit Transfer(
|
|
559
|
+
emit Transfer(msg.sender, from, to, amount, force, data);
|
|
560
|
+
|
|
561
|
+
_afterTokenTransfer(from, to, amount, data);
|
|
521
562
|
|
|
522
563
|
bytes memory lsp1Data = abi.encode(from, to, amount, data);
|
|
523
564
|
|
|
524
565
|
_notifyTokenSender(from, lsp1Data);
|
|
525
|
-
_notifyTokenReceiver(to,
|
|
566
|
+
_notifyTokenReceiver(to, force, lsp1Data);
|
|
526
567
|
}
|
|
527
568
|
|
|
528
569
|
/**
|
|
@@ -532,11 +573,29 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
532
573
|
* @param from The sender address
|
|
533
574
|
* @param to The recipient address
|
|
534
575
|
* @param amount The amount of token to transfer
|
|
576
|
+
* @param data The data sent alongside the transfer
|
|
535
577
|
*/
|
|
536
578
|
function _beforeTokenTransfer(
|
|
537
579
|
address from,
|
|
538
580
|
address to,
|
|
539
|
-
uint256 amount
|
|
581
|
+
uint256 amount,
|
|
582
|
+
bytes memory data // solhint-disable-next-line no-empty-blocks
|
|
583
|
+
) internal virtual {}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* @dev Hook that is called after any token transfer, including minting and burning.
|
|
587
|
+
* Allows to run custom logic after updating balances, but **before notifiying sender/recipient** by overriding this function.
|
|
588
|
+
*
|
|
589
|
+
* @param from The sender address
|
|
590
|
+
* @param to The recipient address
|
|
591
|
+
* @param amount The amount of token to transfer
|
|
592
|
+
* @param data The data sent alongside the transfer
|
|
593
|
+
*/
|
|
594
|
+
function _afterTokenTransfer(
|
|
595
|
+
address from,
|
|
596
|
+
address to,
|
|
597
|
+
uint256 amount,
|
|
598
|
+
bytes memory data // solhint-disable-next-line no-empty-blocks
|
|
540
599
|
) internal virtual {}
|
|
541
600
|
|
|
542
601
|
/**
|
|
@@ -557,13 +616,16 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
557
616
|
_INTERFACEID_LSP1
|
|
558
617
|
)
|
|
559
618
|
) {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
ILSP1UniversalReceiver.universalReceiver.selector,
|
|
619
|
+
try
|
|
620
|
+
ILSP1UniversalReceiver(operator).universalReceiver(
|
|
563
621
|
_TYPEID_LSP7_TOKENOPERATOR,
|
|
564
622
|
lsp1Data
|
|
565
623
|
)
|
|
566
|
-
|
|
624
|
+
{
|
|
625
|
+
return;
|
|
626
|
+
} catch {
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
567
629
|
}
|
|
568
630
|
}
|
|
569
631
|
|
|
@@ -596,17 +658,17 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
596
658
|
* @dev Attempt to notify the token receiver `to` about the `amount` tokens being received.
|
|
597
659
|
* This is done by calling its {universalReceiver} function with the `_TYPEID_LSP7_TOKENSRECIPIENT` as typeId, if `to` is a contract that supports the LSP1 interface.
|
|
598
660
|
*
|
|
599
|
-
* If `to` is is an EOA or a contract that does not support the LSP1 interface, the behaviour will depend on the `
|
|
600
|
-
* - if `
|
|
601
|
-
* - if `
|
|
661
|
+
* If `to` is is an EOA or a contract that does not support the LSP1 interface, the behaviour will depend on the `force` boolean flag.
|
|
662
|
+
* - if `force` is set to `true`, nothing will happen and no notification will be sent.
|
|
663
|
+
* - if `force` is set to `false, the transaction will revert.
|
|
602
664
|
*
|
|
603
665
|
* @param to The address to call the {universalReceiver} function on.
|
|
604
|
-
* @param
|
|
605
|
-
* @param lsp1Data
|
|
666
|
+
* @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
|
|
667
|
+
* @param lsp1Data The data to be sent to the `to` address in the `universalReceiver(...)` call.
|
|
606
668
|
*/
|
|
607
669
|
function _notifyTokenReceiver(
|
|
608
670
|
address to,
|
|
609
|
-
bool
|
|
671
|
+
bool force,
|
|
610
672
|
bytes memory lsp1Data
|
|
611
673
|
) internal virtual {
|
|
612
674
|
if (
|
|
@@ -619,8 +681,8 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
|
|
|
619
681
|
_TYPEID_LSP7_TOKENSRECIPIENT,
|
|
620
682
|
lsp1Data
|
|
621
683
|
);
|
|
622
|
-
} else if (!
|
|
623
|
-
if (to.code.length
|
|
684
|
+
} else if (!force) {
|
|
685
|
+
if (to.code.length != 0) {
|
|
624
686
|
revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
|
|
625
687
|
} else {
|
|
626
688
|
revert LSP7NotifyTokenReceiverIsEOA(to);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
@@ -18,8 +18,11 @@ import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
|
18
18
|
|
|
19
19
|
// constants
|
|
20
20
|
import {_INTERFACEID_LSP7} from "./LSP7Constants.sol";
|
|
21
|
+
import {LSP7TokenContractCannotHoldValue} from "./LSP7Errors.sol";
|
|
21
22
|
|
|
22
|
-
import
|
|
23
|
+
import {
|
|
24
|
+
_LSP17_EXTENSION_PREFIX
|
|
25
|
+
} from "../LSP17ContractExtension/LSP17Constants.sol";
|
|
23
26
|
|
|
24
27
|
// errors
|
|
25
28
|
|
|
@@ -55,7 +58,6 @@ abstract contract LSP7DigitalAssetInitAbstract is
|
|
|
55
58
|
|
|
56
59
|
// fallback function
|
|
57
60
|
|
|
58
|
-
// solhint-disable no-complex-fallback
|
|
59
61
|
/**
|
|
60
62
|
* @notice The `fallback` function was called with the following amount of native tokens: `msg.value`; and the following calldata: `callData`.
|
|
61
63
|
*
|
|
@@ -75,6 +77,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
|
|
|
75
77
|
*
|
|
76
78
|
* 2. If the data sent to this function is of length less than 4 bytes (not a function selector), revert.
|
|
77
79
|
*/
|
|
80
|
+
// solhint-disable-next-line no-complex-fallback
|
|
78
81
|
fallback(
|
|
79
82
|
bytes calldata callData
|
|
80
83
|
) external payable virtual returns (bytes memory) {
|
|
@@ -84,6 +87,19 @@ abstract contract LSP7DigitalAssetInitAbstract is
|
|
|
84
87
|
return _fallbackLSP17Extendable(callData);
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
/**
|
|
91
|
+
* @dev Reverts whenever someone tries to send native tokens to a LSP7 contract.
|
|
92
|
+
* @notice LSP7 contract cannot receive native tokens.
|
|
93
|
+
*/
|
|
94
|
+
receive() external payable virtual {
|
|
95
|
+
// revert on empty calls with no value
|
|
96
|
+
if (msg.value == 0) {
|
|
97
|
+
revert InvalidFunctionSelector(hex"00000000");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
revert LSP7TokenContractCannotHoldValue();
|
|
101
|
+
}
|
|
102
|
+
|
|
87
103
|
/**
|
|
88
104
|
* @dev Forwards the call with the received value to an extension mapped to a function selector.
|
|
89
105
|
*
|
|
@@ -96,10 +112,8 @@ abstract contract LSP7DigitalAssetInitAbstract is
|
|
|
96
112
|
* CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
|
|
97
113
|
* 32 bytes of the {msg.value}
|
|
98
114
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
|
|
115
|
+
* @custom:info The LSP7 Token contract should not hold any native tokens. Any native tokens received by the contract
|
|
116
|
+
* will be forwarded to the extension address mapped to the selector from `msg.sig`.
|
|
103
117
|
*/
|
|
104
118
|
function _fallbackLSP17Extendable(
|
|
105
119
|
bytes calldata callData
|