@lukso/lsp-smart-contracts 0.11.0-rc.0 → 0.11.1
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 +1 -0
- package/artifacts/LSP0ERC725Account.json +7 -2
- package/artifacts/LSP0ERC725AccountInit.json +7 -2
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +3 -79
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +3 -41
- package/artifacts/LSP23LinkedContractsFactory.json +544 -0
- package/artifacts/LSP6KeyManager.json +24 -19
- package/artifacts/LSP6KeyManagerInit.json +24 -19
- package/artifacts/LSP7CappedSupply.json +88 -0
- package/artifacts/LSP7CappedSupplyInitAbstract.json +88 -0
- package/artifacts/LSP7CompatibleERC20.json +88 -0
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +88 -0
- package/artifacts/LSP7CompatibleERC20Mintable.json +90 -2
- package/artifacts/LSP7CompatibleERC20MintableInit.json +90 -2
- package/artifacts/LSP7DigitalAsset.json +88 -0
- package/artifacts/LSP7DigitalAssetInitAbstract.json +88 -0
- package/artifacts/LSP7Mintable.json +90 -2
- package/artifacts/LSP7MintableInit.json +90 -2
- package/artifacts/LSP8CappedSupply.json +59 -0
- package/artifacts/LSP8CappedSupplyInitAbstract.json +59 -0
- package/artifacts/LSP8CompatibleERC721.json +60 -1
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +60 -1
- package/artifacts/LSP8CompatibleERC721Mintable.json +62 -3
- package/artifacts/LSP8CompatibleERC721MintableInit.json +62 -3
- package/artifacts/LSP8IdentifiableDigitalAsset.json +59 -0
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +59 -0
- package/artifacts/LSP8Mintable.json +61 -2
- package/artifacts/LSP8MintableInit.json +61 -2
- package/artifacts/LSP9Vault.json +7 -2
- package/artifacts/LSP9VaultInit.json +7 -2
- package/artifacts/UniversalProfile.json +7 -2
- package/artifacts/UniversalProfileInit.json +7 -2
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +8 -36
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +15 -30
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +122 -206
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +18 -36
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +8 -34
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +148 -177
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +21 -20
- package/contracts/LSP14Ownable2Step/LSP14Errors.sol +13 -2
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +50 -20
- package/contracts/LSP17ContractExtension/LSP17Errors.sol +10 -0
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +16 -34
- package/contracts/LSP17ContractExtension/LSP17Utils.sol +1 -1
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +16 -11
- package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +5 -10
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +192 -177
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +150 -88
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +66 -48
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +1 -1
- package/contracts/LSP23LinkedContractsDeployment/ILSP23LinkedContractsFactory.sol +192 -0
- package/contracts/LSP23LinkedContractsDeployment/IPostDeploymentModule.sol +18 -0
- package/contracts/LSP23LinkedContractsDeployment/LSP23Errors.sol +24 -0
- package/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol +392 -0
- package/contracts/{LSP23MultiChainDeployment → LSP23LinkedContractsDeployment}/modules/UniversalProfileInitPostDeploymentModule.sol +5 -1
- package/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfilePostDeploymentModule.sol +61 -0
- package/contracts/LSP25ExecuteRelayCall/ILSP25ExecuteRelayCall.sol +68 -0
- package/contracts/LSP25ExecuteRelayCall/LSP25Constants.sol +8 -0
- package/contracts/LSP25ExecuteRelayCall/LSP25Errors.sol +17 -0
- package/contracts/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.sol +143 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +256 -61
- package/contracts/{LSP3UniversalProfile → LSP3ProfileMetadata}/LSP3Constants.sol +3 -3
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +9 -8
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +13 -6
- package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +4 -4
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +148 -189
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +26 -54
- package/contracts/LSP6KeyManager/LSP6Constants.sol +1 -3
- package/contracts/LSP6KeyManager/LSP6Errors.sol +142 -63
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +7 -4
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +125 -80
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +8 -4
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +52 -84
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +59 -10
- package/contracts/LSP6KeyManager/LSP6Utils.sol +67 -46
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +116 -78
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +4 -1
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +128 -6
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +212 -80
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +126 -3
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +7 -5
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +27 -14
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -4
- package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +2 -4
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +29 -11
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +30 -9
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +46 -14
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +43 -12
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +14 -0
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +9 -4
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +7 -1
- package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +8 -8
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +7 -6
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +10 -2
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +120 -92
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +4 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +135 -6
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +128 -38
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +134 -5
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +83 -41
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +13 -5
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8BurnableInitAbstract.sol +24 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +30 -12
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +31 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +96 -31
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +98 -23
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +21 -4
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +12 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +21 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +9 -4
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +13 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +15 -6
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +7 -5
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +17 -2
- package/contracts/LSP9Vault/ILSP9Vault.sol +10 -5
- package/contracts/LSP9Vault/LSP9Errors.sol +3 -2
- package/contracts/LSP9Vault/LSP9Vault.sol +12 -4
- package/contracts/LSP9Vault/LSP9VaultCore.sol +245 -182
- package/contracts/LSP9Vault/LSP9VaultInit.sol +10 -3
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -6
- package/contracts/UniversalProfile.sol +8 -6
- package/contracts/UniversalProfileInit.sol +6 -6
- package/contracts/UniversalProfileInitAbstract.sol +10 -3
- package/devdocs/LSP0ERC725Account.json +54 -37
- package/devdocs/LSP0ERC725AccountInit.json +56 -38
- package/devdocs/LSP1UniversalReceiverDelegateUP.json +14 -55
- package/devdocs/LSP1UniversalReceiverDelegateVault.json +9 -33
- package/devdocs/LSP23LinkedContractsFactory.json +81 -0
- package/devdocs/LSP4DigitalAssetMetadata.json +5 -5
- package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +4 -4
- package/devdocs/LSP6KeyManager.json +109 -70
- package/devdocs/LSP6KeyManagerInit.json +109 -70
- package/devdocs/LSP7CappedSupply.json +90 -42
- package/devdocs/LSP7CappedSupplyInitAbstract.json +86 -40
- package/devdocs/LSP7CompatibleERC20.json +79 -43
- package/devdocs/LSP7CompatibleERC20InitAbstract.json +75 -39
- package/devdocs/LSP7CompatibleERC20Mintable.json +87 -40
- package/devdocs/LSP7CompatibleERC20MintableInit.json +82 -42
- package/devdocs/LSP7DigitalAsset.json +76 -40
- package/devdocs/LSP7DigitalAssetInitAbstract.json +73 -37
- package/devdocs/LSP7Mintable.json +79 -51
- package/devdocs/LSP7MintableInit.json +78 -49
- package/devdocs/LSP8CappedSupply.json +72 -43
- package/devdocs/LSP8CappedSupplyInitAbstract.json +68 -41
- package/devdocs/LSP8CompatibleERC721.json +85 -64
- package/devdocs/LSP8CompatibleERC721InitAbstract.json +81 -60
- package/devdocs/LSP8CompatibleERC721Mintable.json +98 -60
- package/devdocs/LSP8CompatibleERC721MintableInit.json +93 -62
- package/devdocs/LSP8IdentifiableDigitalAsset.json +58 -41
- package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +57 -40
- package/devdocs/LSP8Mintable.json +65 -48
- package/devdocs/LSP8MintableInit.json +64 -47
- package/devdocs/LSP9Vault.json +61 -18
- package/devdocs/LSP9VaultInit.json +59 -17
- package/devdocs/UniversalProfile.json +53 -35
- package/devdocs/UniversalProfileInit.json +53 -35
- package/dist/constants.cjs.js +6236 -2587
- package/dist/constants.d.ts +3851 -1129
- package/dist/constants.es.js +6236 -2587
- package/package.json +6 -4
- package/userdocs/LSP0ERC725Account.json +40 -8
- package/userdocs/LSP0ERC725AccountInit.json +40 -8
- package/userdocs/LSP1UniversalReceiverDelegateUP.json +18 -2
- package/userdocs/LSP1UniversalReceiverDelegateVault.json +18 -2
- package/userdocs/LSP23LinkedContractsFactory.json +29 -0
- package/userdocs/LSP4DigitalAssetMetadata.json +1 -1
- package/userdocs/LSP6KeyManager.json +144 -6
- package/userdocs/LSP6KeyManagerInit.json +147 -6
- package/userdocs/LSP7CappedSupply.json +18 -3
- package/userdocs/LSP7CappedSupplyInitAbstract.json +17 -2
- package/userdocs/LSP7CompatibleERC20.json +3 -9
- package/userdocs/LSP7CompatibleERC20InitAbstract.json +2 -8
- package/userdocs/LSP7CompatibleERC20Mintable.json +5 -8
- package/userdocs/LSP7CompatibleERC20MintableInit.json +3 -9
- package/userdocs/LSP7DigitalAsset.json +2 -2
- package/userdocs/LSP7DigitalAssetInitAbstract.json +2 -2
- package/userdocs/LSP7Mintable.json +3 -3
- package/userdocs/LSP7MintableInit.json +3 -3
- package/userdocs/LSP8CappedSupply.json +16 -1
- package/userdocs/LSP8CappedSupplyInitAbstract.json +15 -0
- package/userdocs/LSP8CompatibleERC721.json +24 -3
- package/userdocs/LSP8CompatibleERC721InitAbstract.json +23 -2
- package/userdocs/LSP8CompatibleERC721Mintable.json +29 -2
- package/userdocs/LSP8CompatibleERC721MintableInit.json +27 -3
- package/userdocs/LSP8Mintable.json +4 -1
- package/userdocs/LSP8MintableInit.json +4 -1
- package/userdocs/LSP9Vault.json +50 -4
- package/userdocs/LSP9VaultInit.json +50 -4
- package/userdocs/UniversalProfile.json +40 -8
- package/userdocs/UniversalProfileInit.json +40 -8
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -47
- package/contracts/LSP23MultiChainDeployment/IOwnerControlledContractDeployer.sol +0 -174
- package/contracts/LSP23MultiChainDeployment/IPostDeploymentModule.sol +0 -10
- package/contracts/LSP23MultiChainDeployment/LSP23Errors.sol +0 -24
- package/contracts/LSP23MultiChainDeployment/OwnerControlledContractDeployer.sol +0 -388
|
@@ -13,17 +13,39 @@ import {
|
|
|
13
13
|
LSP4DigitalAssetMetadata
|
|
14
14
|
} from "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol";
|
|
15
15
|
|
|
16
|
+
import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol";
|
|
17
|
+
|
|
18
|
+
// libraries
|
|
19
|
+
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
20
|
+
|
|
16
21
|
// constants
|
|
17
22
|
import {_INTERFACEID_LSP8} from "./LSP8Constants.sol";
|
|
18
23
|
|
|
24
|
+
import "../LSP17ContractExtension/LSP17Constants.sol";
|
|
25
|
+
|
|
26
|
+
// errors
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
NoExtensionFoundForFunctionSelector,
|
|
30
|
+
InvalidFunctionSelector,
|
|
31
|
+
InvalidExtensionAddress
|
|
32
|
+
} from "../LSP17ContractExtension/LSP17Errors.sol";
|
|
33
|
+
|
|
19
34
|
/**
|
|
20
|
-
* @title
|
|
35
|
+
* @title Implementation of a LSP8 Identifiable Digital Asset, a contract that represents a non-fungible token.
|
|
21
36
|
* @author Matthew Stevens
|
|
22
|
-
*
|
|
37
|
+
*
|
|
38
|
+
* @dev Standard implementation contract of the LSP8 standard.
|
|
39
|
+
*
|
|
40
|
+
* Minting and transferring are done by providing a unique `tokenId`.
|
|
41
|
+
* This implementation is agnostic to the way tokens are created.
|
|
42
|
+
* A supply mechanism has to be added in a derived contract using {_mint}
|
|
43
|
+
* For a generic mechanism, see {LSP7Mintable}.
|
|
23
44
|
*/
|
|
24
45
|
abstract contract LSP8IdentifiableDigitalAsset is
|
|
25
46
|
LSP4DigitalAssetMetadata,
|
|
26
|
-
LSP8IdentifiableDigitalAssetCore
|
|
47
|
+
LSP8IdentifiableDigitalAssetCore,
|
|
48
|
+
LSP17Extendable
|
|
27
49
|
{
|
|
28
50
|
/**
|
|
29
51
|
* @notice Sets the token-Metadata
|
|
@@ -37,14 +59,121 @@ abstract contract LSP8IdentifiableDigitalAsset is
|
|
|
37
59
|
address newOwner_
|
|
38
60
|
) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {}
|
|
39
61
|
|
|
62
|
+
// fallback function
|
|
63
|
+
|
|
64
|
+
// solhint-disable no-complex-fallback
|
|
65
|
+
/**
|
|
66
|
+
* @notice The `fallback` function was called with the following amount of native tokens: `msg.value`; and the following calldata: `callData`.
|
|
67
|
+
*
|
|
68
|
+
* @dev Achieves the goal of [LSP-17-ContractExtension] standard by extending the contract to handle calls of functions that do not exist natively,
|
|
69
|
+
* forwarding the function call to the extension address mapped to the function being called.
|
|
70
|
+
*
|
|
71
|
+
* This function is executed when:
|
|
72
|
+
* - Sending data of length less than 4 bytes to the contract.
|
|
73
|
+
* - The first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
|
|
74
|
+
* - Receiving native tokens
|
|
75
|
+
*
|
|
76
|
+
* 1. If the data is equal or longer than 4 bytes, the [ERC-725Y] storage is queried with the following data key: [_LSP17_EXTENSION_PREFIX] + `bytes4(msg.sig)` (Check [LSP-2-ERC725YJSONSchema] for encoding the data key)
|
|
77
|
+
*
|
|
78
|
+
* - If there is no address stored under the following data key, revert with {NoExtensionFoundForFunctionSelector(bytes4)}. The data key relative to `bytes4(0)` is an exception, where no reverts occurs if there is no extension address stored under. This exception is made to allow users to send random data (graffiti) to the account and to be able to react on it.
|
|
79
|
+
*
|
|
80
|
+
* - If there is an address, forward the `msg.data` to the extension using the CALL opcode, appending 52 bytes (20 bytes of `msg.sender` and 32 bytes of `msg.value`). Return what the calls returns, or revert if the call failed.
|
|
81
|
+
*
|
|
82
|
+
* 2. If the data sent to this function is of length less than 4 bytes (not a function selector), revert.
|
|
83
|
+
*/
|
|
84
|
+
fallback(
|
|
85
|
+
bytes calldata callData
|
|
86
|
+
) external payable virtual returns (bytes memory) {
|
|
87
|
+
if (msg.data.length < 4) {
|
|
88
|
+
revert InvalidFunctionSelector(callData);
|
|
89
|
+
}
|
|
90
|
+
return _fallbackLSP17Extendable(callData);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @dev Forwards the call with the received value to an extension mapped to a function selector.
|
|
95
|
+
*
|
|
96
|
+
* Calls {_getExtension} to get the address of the extension mapped to the function selector being
|
|
97
|
+
* called on the account. If there is no extension, the address(0) will be returned.
|
|
98
|
+
*
|
|
99
|
+
* Reverts if there is no extension for the function being called.
|
|
100
|
+
*
|
|
101
|
+
* If there is an extension for the function selector being called, it calls the extension with the
|
|
102
|
+
* CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
|
|
103
|
+
* 32 bytes of the {msg.value}
|
|
104
|
+
*
|
|
105
|
+
* Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
|
|
106
|
+
* called before other codes in fallback().
|
|
107
|
+
*
|
|
108
|
+
* Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
|
|
109
|
+
*/
|
|
110
|
+
function _fallbackLSP17Extendable(
|
|
111
|
+
bytes calldata callData
|
|
112
|
+
) internal virtual override returns (bytes memory) {
|
|
113
|
+
// If there is a function selector
|
|
114
|
+
address extension = _getExtension(msg.sig);
|
|
115
|
+
|
|
116
|
+
// if no extension was found, revert
|
|
117
|
+
if (extension == address(0))
|
|
118
|
+
revert NoExtensionFoundForFunctionSelector(msg.sig);
|
|
119
|
+
|
|
120
|
+
(bool success, bytes memory result) = extension.call{value: msg.value}(
|
|
121
|
+
abi.encodePacked(callData, msg.sender, msg.value)
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (success) {
|
|
125
|
+
return result;
|
|
126
|
+
} else {
|
|
127
|
+
// `mload(result)` -> offset in memory where `result.length` is located
|
|
128
|
+
// `add(result, 32)` -> offset in memory where `result` data starts
|
|
129
|
+
// solhint-disable no-inline-assembly
|
|
130
|
+
/// @solidity memory-safe-assembly
|
|
131
|
+
assembly {
|
|
132
|
+
let resultdata_size := mload(result)
|
|
133
|
+
revert(add(result, 32), resultdata_size)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @dev Returns the extension address stored under the following data key:
|
|
140
|
+
* - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
|
|
141
|
+
* - If no extension is stored, returns the address(0).
|
|
142
|
+
*/
|
|
143
|
+
function _getExtension(
|
|
144
|
+
bytes4 functionSelector
|
|
145
|
+
) internal view virtual override returns (address) {
|
|
146
|
+
// Generate the data key relevant for the functionSelector being called
|
|
147
|
+
bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
|
|
148
|
+
_LSP17_EXTENSION_PREFIX,
|
|
149
|
+
functionSelector
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// Check if there is an extension stored under the generated data key
|
|
153
|
+
bytes memory extensionAddress = ERC725YCore._getData(
|
|
154
|
+
mappedExtensionDataKey
|
|
155
|
+
);
|
|
156
|
+
if (extensionAddress.length != 20 && extensionAddress.length != 0)
|
|
157
|
+
revert InvalidExtensionAddress(extensionAddress);
|
|
158
|
+
|
|
159
|
+
return address(bytes20(extensionAddress));
|
|
160
|
+
}
|
|
161
|
+
|
|
40
162
|
/**
|
|
41
|
-
* @
|
|
163
|
+
* @inheritdoc IERC165
|
|
42
164
|
*/
|
|
43
165
|
function supportsInterface(
|
|
44
166
|
bytes4 interfaceId
|
|
45
|
-
)
|
|
167
|
+
)
|
|
168
|
+
public
|
|
169
|
+
view
|
|
170
|
+
virtual
|
|
171
|
+
override(IERC165, ERC725YCore, LSP17Extendable)
|
|
172
|
+
returns (bool)
|
|
173
|
+
{
|
|
46
174
|
return
|
|
47
175
|
interfaceId == _INTERFACEID_LSP8 ||
|
|
48
|
-
super.supportsInterface(interfaceId)
|
|
176
|
+
super.supportsInterface(interfaceId) ||
|
|
177
|
+
LSP17Extendable._supportsInterfaceInERC165Extension(interfaceId);
|
|
49
178
|
}
|
|
50
179
|
}
|
|
@@ -23,6 +23,7 @@ import "./LSP8Errors.sol";
|
|
|
23
23
|
// constants
|
|
24
24
|
import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
|
|
25
25
|
import {
|
|
26
|
+
_TYPEID_LSP8_TOKENOPERATOR,
|
|
26
27
|
_TYPEID_LSP8_TOKENSSENDER,
|
|
27
28
|
_TYPEID_LSP8_TOKENSRECIPIENT
|
|
28
29
|
} from "./LSP8Constants.sol";
|
|
@@ -40,18 +41,18 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
40
41
|
|
|
41
42
|
// --- Storage
|
|
42
43
|
|
|
43
|
-
uint256
|
|
44
|
+
uint256 internal _existingTokens;
|
|
44
45
|
|
|
45
46
|
// Mapping from `tokenId` to `tokenOwner`
|
|
46
|
-
mapping(bytes32 => address)
|
|
47
|
+
mapping(bytes32 => address) internal _tokenOwners;
|
|
47
48
|
|
|
48
49
|
// Mapping `tokenOwner` to owned tokenIds
|
|
49
|
-
mapping(address => EnumerableSet.Bytes32Set)
|
|
50
|
+
mapping(address => EnumerableSet.Bytes32Set) internal _ownedTokens;
|
|
50
51
|
|
|
51
52
|
// Mapping a `tokenId` to its authorized operator addresses.
|
|
52
|
-
mapping(bytes32 => EnumerableSet.AddressSet)
|
|
53
|
+
mapping(bytes32 => EnumerableSet.AddressSet) internal _operators;
|
|
53
54
|
|
|
54
|
-
mapping(address => EnumerableSet.Bytes32Set)
|
|
55
|
+
mapping(address => EnumerableSet.Bytes32Set) internal _tokenIdsForOperator;
|
|
55
56
|
|
|
56
57
|
// --- Token queries
|
|
57
58
|
|
|
@@ -104,7 +105,8 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
104
105
|
*/
|
|
105
106
|
function authorizeOperator(
|
|
106
107
|
address operator,
|
|
107
|
-
bytes32 tokenId
|
|
108
|
+
bytes32 tokenId,
|
|
109
|
+
bytes memory operatorNotificationData
|
|
108
110
|
) public virtual {
|
|
109
111
|
address tokenOwner = tokenOwnerOf(tokenId);
|
|
110
112
|
|
|
@@ -123,13 +125,29 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
123
125
|
bool isAdded = _operators[tokenId].add(operator);
|
|
124
126
|
if (!isAdded) revert LSP8OperatorAlreadyAuthorized(operator, tokenId);
|
|
125
127
|
|
|
126
|
-
emit AuthorizedOperator(
|
|
128
|
+
emit AuthorizedOperator(
|
|
129
|
+
operator,
|
|
130
|
+
tokenOwner,
|
|
131
|
+
tokenId,
|
|
132
|
+
operatorNotificationData
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
bytes memory lsp1Data = abi.encode(
|
|
136
|
+
msg.sender,
|
|
137
|
+
tokenId,
|
|
138
|
+
operatorNotificationData
|
|
139
|
+
);
|
|
140
|
+
_notifyTokenOperator(operator, lsp1Data);
|
|
127
141
|
}
|
|
128
142
|
|
|
129
143
|
/**
|
|
130
144
|
* @inheritdoc ILSP8IdentifiableDigitalAsset
|
|
131
145
|
*/
|
|
132
|
-
function revokeOperator(
|
|
146
|
+
function revokeOperator(
|
|
147
|
+
address operator,
|
|
148
|
+
bytes32 tokenId,
|
|
149
|
+
bytes memory operatorNotificationData
|
|
150
|
+
) public virtual {
|
|
133
151
|
address tokenOwner = tokenOwnerOf(tokenId);
|
|
134
152
|
|
|
135
153
|
if (tokenOwner != msg.sender) {
|
|
@@ -144,7 +162,19 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
144
162
|
revert LSP8TokenOwnerCannotBeOperator();
|
|
145
163
|
}
|
|
146
164
|
|
|
147
|
-
_revokeOperator(
|
|
165
|
+
_revokeOperator(
|
|
166
|
+
operator,
|
|
167
|
+
tokenOwner,
|
|
168
|
+
tokenId,
|
|
169
|
+
operatorNotificationData
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
bytes memory lsp1Data = abi.encode(
|
|
173
|
+
msg.sender,
|
|
174
|
+
tokenId,
|
|
175
|
+
operatorNotificationData
|
|
176
|
+
);
|
|
177
|
+
_notifyTokenOperator(operator, lsp1Data);
|
|
148
178
|
}
|
|
149
179
|
|
|
150
180
|
/**
|
|
@@ -245,15 +275,24 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
245
275
|
function _revokeOperator(
|
|
246
276
|
address operator,
|
|
247
277
|
address tokenOwner,
|
|
248
|
-
bytes32 tokenId
|
|
278
|
+
bytes32 tokenId,
|
|
279
|
+
bytes memory operatorNotificationData
|
|
249
280
|
) internal virtual {
|
|
250
281
|
bool isRemoved = _operators[tokenId].remove(operator);
|
|
251
282
|
if (!isRemoved) revert LSP8NonExistingOperator(operator, tokenId);
|
|
252
|
-
emit RevokedOperator(
|
|
283
|
+
emit RevokedOperator(
|
|
284
|
+
operator,
|
|
285
|
+
tokenOwner,
|
|
286
|
+
tokenId,
|
|
287
|
+
operatorNotificationData
|
|
288
|
+
);
|
|
253
289
|
}
|
|
254
290
|
|
|
255
291
|
/**
|
|
256
|
-
* @dev
|
|
292
|
+
* @dev revoke all the current operators for a specific `tokenId` token which belongs to `tokenOwner`.
|
|
293
|
+
*
|
|
294
|
+
* @param tokenOwner The address that is the owner of the `tokenId`.
|
|
295
|
+
* @param tokenId The token to remove the associated operators for.
|
|
257
296
|
*/
|
|
258
297
|
function _clearOperators(
|
|
259
298
|
address tokenOwner,
|
|
@@ -273,7 +312,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
273
312
|
for (uint256 i = 0; i < operatorListLength; ) {
|
|
274
313
|
// we are emptying the list, always remove from index 0
|
|
275
314
|
address operator = operatorsForTokenId.at(0);
|
|
276
|
-
_revokeOperator(operator, tokenOwner, tokenId);
|
|
315
|
+
_revokeOperator(operator, tokenOwner, tokenId, "");
|
|
277
316
|
|
|
278
317
|
unchecked {
|
|
279
318
|
++i;
|
|
@@ -284,8 +323,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
284
323
|
/**
|
|
285
324
|
* @dev Returns whether `tokenId` exists.
|
|
286
325
|
*
|
|
287
|
-
* Tokens start existing when they are minted (
|
|
288
|
-
* (`_burn`).
|
|
326
|
+
* Tokens start existing when they are minted ({_mint}), and stop existing when they are burned ({_burn}).
|
|
289
327
|
*/
|
|
290
328
|
function _exists(bytes32 tokenId) internal view virtual returns (bool) {
|
|
291
329
|
return _tokenOwners[tokenId] != address(0);
|
|
@@ -301,14 +339,18 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
301
339
|
}
|
|
302
340
|
|
|
303
341
|
/**
|
|
304
|
-
* @dev
|
|
305
|
-
*
|
|
306
|
-
* Requirements:
|
|
342
|
+
* @dev Create `tokenId` by minting it and transfers it to `to`.
|
|
307
343
|
*
|
|
308
|
-
*
|
|
344
|
+
* @custom:requirements
|
|
345
|
+
* - `tokenId` must not exist and not have been already minted.
|
|
309
346
|
* - `to` cannot be the zero address.
|
|
310
347
|
*
|
|
311
|
-
*
|
|
348
|
+
* @param to The address that will receive the minted `tokenId`.
|
|
349
|
+
* @param tokenId The token ID to create (= mint).
|
|
350
|
+
* @param allowNonLSP1Recipient When set to `true`, `to` may be any address. When set to `false`, `to` must be a contract that supports the LSP1 standard.
|
|
351
|
+
* @param data Any additional data the caller wants included in the emitted event, and sent in the hook of the `to` address.
|
|
352
|
+
*
|
|
353
|
+
* @custom:events {Transfer} event with `address(0)` as `from` address.
|
|
312
354
|
*/
|
|
313
355
|
function _mint(
|
|
314
356
|
address to,
|
|
@@ -343,18 +385,29 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
343
385
|
data
|
|
344
386
|
);
|
|
345
387
|
|
|
346
|
-
bytes memory lsp1Data = abi.
|
|
388
|
+
bytes memory lsp1Data = abi.encode(address(0), to, tokenId, data);
|
|
347
389
|
_notifyTokenReceiver(to, allowNonLSP1Recipient, lsp1Data);
|
|
348
390
|
}
|
|
349
391
|
|
|
350
392
|
/**
|
|
351
|
-
* @dev
|
|
393
|
+
* @dev Burn a specific `tokenId`, removing the `tokenId` from the {tokenIdsOf} the caller and decreasing its {balanceOf} by -1.
|
|
394
|
+
* This will also clear all the operators allowed to transfer the `tokenId`.
|
|
395
|
+
*
|
|
396
|
+
* The owner of the `tokenId` will be notified about the `tokenId` being transferred through its LSP1 {universalReceiver}
|
|
397
|
+
* function, if it is a contract that supports the LSP1 interface. Its {universalReceiver} function will receive
|
|
398
|
+
* all the parameters in the calldata packed encoded.
|
|
399
|
+
*
|
|
400
|
+
* Any logic in the {_beforeTokenTransfer} function will run before burning `tokenId` and updating the balances.
|
|
401
|
+
*
|
|
402
|
+
* @param tokenId The token to burn.
|
|
403
|
+
* @param data Any additional data the caller wants included in the emitted event, and sent in the LSP1 hook on the token owner's address.
|
|
352
404
|
*
|
|
353
|
-
*
|
|
405
|
+
* @custom:hint In dApps, you can know which addresses are burning tokens by listening for the `Transfer` event and filter with the zero address as `to`.
|
|
354
406
|
*
|
|
407
|
+
* @custom:requirements
|
|
355
408
|
* - `tokenId` must exist.
|
|
356
409
|
*
|
|
357
|
-
*
|
|
410
|
+
* @custom:events {Transfer} event with `address(0)` as the `to` address.
|
|
358
411
|
*/
|
|
359
412
|
function _burn(bytes32 tokenId, bytes memory data) internal virtual {
|
|
360
413
|
address tokenOwner = tokenOwnerOf(tokenId);
|
|
@@ -372,7 +425,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
372
425
|
|
|
373
426
|
emit Transfer(operator, tokenOwner, address(0), tokenId, false, data);
|
|
374
427
|
|
|
375
|
-
bytes memory lsp1Data = abi.
|
|
428
|
+
bytes memory lsp1Data = abi.encode(
|
|
376
429
|
tokenOwner,
|
|
377
430
|
address(0),
|
|
378
431
|
tokenId,
|
|
@@ -382,14 +435,27 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
382
435
|
}
|
|
383
436
|
|
|
384
437
|
/**
|
|
385
|
-
* @dev
|
|
438
|
+
* @dev Change the owner of the `tokenId` from `from` to `to`.
|
|
386
439
|
*
|
|
387
|
-
*
|
|
440
|
+
* Both the sender and recipient will be notified of the `tokenId` being transferred through their LSP1 {universalReceiver}
|
|
441
|
+
* function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
|
|
442
|
+
* all the parameters in the calldata packed encoded.
|
|
388
443
|
*
|
|
444
|
+
* Any logic in the {_beforeTokenTransfer} function will run before changing the owner of `tokenId`.
|
|
445
|
+
*
|
|
446
|
+
* @param from The sender address.
|
|
447
|
+
* @param to The recipient address.
|
|
448
|
+
* @param tokenId The token to transfer.
|
|
449
|
+
* @param allowNonLSP1Recipient When set to `true`, `to` may be any address. When set to `false`, `to` must be a contract that supports the LSP1 standard.
|
|
450
|
+
* @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
|
|
451
|
+
*
|
|
452
|
+
* @custom:requirements
|
|
389
453
|
* - `to` cannot be the zero address.
|
|
390
454
|
* - `tokenId` token must be owned by `from`.
|
|
391
455
|
*
|
|
392
|
-
*
|
|
456
|
+
* @custom:events {Transfer} event.
|
|
457
|
+
*
|
|
458
|
+
* @custom:danger This internal function does not check if the sender is authorized or not to operate on the `tokenId`.
|
|
393
459
|
*/
|
|
394
460
|
function _transfer(
|
|
395
461
|
address from,
|
|
@@ -423,23 +489,19 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
423
489
|
|
|
424
490
|
emit Transfer(operator, from, to, tokenId, allowNonLSP1Recipient, data);
|
|
425
491
|
|
|
426
|
-
bytes memory lsp1Data = abi.
|
|
492
|
+
bytes memory lsp1Data = abi.encode(from, to, tokenId, data);
|
|
427
493
|
|
|
428
494
|
_notifyTokenSender(from, lsp1Data);
|
|
429
495
|
_notifyTokenReceiver(to, allowNonLSP1Recipient, lsp1Data);
|
|
430
496
|
}
|
|
431
497
|
|
|
432
498
|
/**
|
|
433
|
-
* @dev Hook that is called before any token transfer
|
|
434
|
-
* and
|
|
499
|
+
* @dev Hook that is called before any token transfer, including minting and burning.
|
|
500
|
+
* * Allows to run custom logic before updating balances and notifiying sender/recipient by overriding this function.
|
|
435
501
|
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
* transferred to `to`.
|
|
440
|
-
* - When `from` is zero, `tokenId` will be minted for `to`.
|
|
441
|
-
* - When `to` is zero, ``from``'s `tokenId` will be burned.
|
|
442
|
-
* - `from` and `to` are never both zero.
|
|
502
|
+
* @param from The sender address
|
|
503
|
+
* @param to The recipient address
|
|
504
|
+
* @param tokenId The tokenId to transfer
|
|
443
505
|
*/
|
|
444
506
|
function _beforeTokenTransfer(
|
|
445
507
|
address from,
|
|
@@ -447,6 +509,34 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
|
|
|
447
509
|
bytes32 tokenId
|
|
448
510
|
) internal virtual {}
|
|
449
511
|
|
|
512
|
+
/**
|
|
513
|
+
* @dev Attempt to notify the operator `operator` about the `tokenId` tokens being authorized.
|
|
514
|
+
* This is done by calling its {universalReceiver} function with the `_TYPEID_LSP8_TOKENOPERATOR` as typeId, if `operator` is a contract that supports the LSP1 interface.
|
|
515
|
+
* If `operator` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
|
|
516
|
+
|
|
517
|
+
* @param operator The address to call the {universalReceiver} function on.
|
|
518
|
+
* @param lsp1Data the data to be sent to the `operator` address in the `universalReceiver` call.
|
|
519
|
+
*/
|
|
520
|
+
function _notifyTokenOperator(
|
|
521
|
+
address operator,
|
|
522
|
+
bytes memory lsp1Data
|
|
523
|
+
) internal virtual {
|
|
524
|
+
if (
|
|
525
|
+
ERC165Checker.supportsERC165InterfaceUnchecked(
|
|
526
|
+
operator,
|
|
527
|
+
_INTERFACEID_LSP1
|
|
528
|
+
)
|
|
529
|
+
) {
|
|
530
|
+
operator.call(
|
|
531
|
+
abi.encodeWithSelector(
|
|
532
|
+
ILSP1UniversalReceiver.universalReceiver.selector,
|
|
533
|
+
_TYPEID_LSP8_TOKENOPERATOR,
|
|
534
|
+
lsp1Data
|
|
535
|
+
)
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
450
540
|
/**
|
|
451
541
|
* @dev An attempt is made to notify the token sender about the `tokenId` changing owners using
|
|
452
542
|
* LSP1 interface.
|
|
@@ -13,17 +13,39 @@ import {
|
|
|
13
13
|
LSP4DigitalAssetMetadataInitAbstract
|
|
14
14
|
} from "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol";
|
|
15
15
|
|
|
16
|
+
import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol";
|
|
17
|
+
|
|
18
|
+
// libraries
|
|
19
|
+
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
20
|
+
|
|
16
21
|
// constants
|
|
17
22
|
import {_INTERFACEID_LSP8} from "./LSP8Constants.sol";
|
|
18
23
|
|
|
24
|
+
import "../LSP17ContractExtension/LSP17Constants.sol";
|
|
25
|
+
|
|
26
|
+
// errors
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
NoExtensionFoundForFunctionSelector,
|
|
30
|
+
InvalidFunctionSelector,
|
|
31
|
+
InvalidExtensionAddress
|
|
32
|
+
} from "../LSP17ContractExtension/LSP17Errors.sol";
|
|
33
|
+
|
|
19
34
|
/**
|
|
20
|
-
* @title
|
|
35
|
+
* @title Implementation of a LSP8 Identifiable Digital Asset, a contract that represents a non-fungible token.
|
|
21
36
|
* @author Matthew Stevens
|
|
22
|
-
*
|
|
37
|
+
*
|
|
38
|
+
* @dev Inheritable proxy implementation contract of the LSP8 standard.
|
|
39
|
+
*
|
|
40
|
+
* Minting and transferring are done using by giving a unique `tokenId`.
|
|
41
|
+
* This implementation is agnostic to the way tokens are created.
|
|
42
|
+
* A supply mechanism has to be added in a derived contract using {_mint}
|
|
43
|
+
* For a generic mechanism, see {LSP7Mintable}.
|
|
23
44
|
*/
|
|
24
45
|
abstract contract LSP8IdentifiableDigitalAssetInitAbstract is
|
|
25
46
|
LSP4DigitalAssetMetadataInitAbstract,
|
|
26
|
-
LSP8IdentifiableDigitalAssetCore
|
|
47
|
+
LSP8IdentifiableDigitalAssetCore,
|
|
48
|
+
LSP17Extendable
|
|
27
49
|
{
|
|
28
50
|
function _initialize(
|
|
29
51
|
string memory name_,
|
|
@@ -37,14 +59,121 @@ abstract contract LSP8IdentifiableDigitalAssetInitAbstract is
|
|
|
37
59
|
);
|
|
38
60
|
}
|
|
39
61
|
|
|
62
|
+
// fallback function
|
|
63
|
+
|
|
64
|
+
// solhint-disable no-complex-fallback
|
|
65
|
+
/**
|
|
66
|
+
* @notice The `fallback` function was called with the following amount of native tokens: `msg.value`; and the following calldata: `callData`.
|
|
67
|
+
*
|
|
68
|
+
* @dev Achieves the goal of [LSP-17-ContractExtension] standard by extending the contract to handle calls of functions that do not exist natively,
|
|
69
|
+
* forwarding the function call to the extension address mapped to the function being called.
|
|
70
|
+
*
|
|
71
|
+
* This function is executed when:
|
|
72
|
+
* - Sending data of length less than 4 bytes to the contract.
|
|
73
|
+
* - The first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
|
|
74
|
+
* - Receiving native tokens
|
|
75
|
+
*
|
|
76
|
+
* 1. If the data is equal or longer than 4 bytes, the [ERC-725Y] storage is queried with the following data key: [_LSP17_EXTENSION_PREFIX] + `bytes4(msg.sig)` (Check [LSP-2-ERC725YJSONSchema] for encoding the data key)
|
|
77
|
+
*
|
|
78
|
+
* - If there is no address stored under the following data key, revert with {NoExtensionFoundForFunctionSelector(bytes4)}. The data key relative to `bytes4(0)` is an exception, where no reverts occurs if there is no extension address stored under. This exception is made to allow users to send random data (graffiti) to the account and to be able to react on it.
|
|
79
|
+
*
|
|
80
|
+
* - If there is an address, forward the `msg.data` to the extension using the CALL opcode, appending 52 bytes (20 bytes of `msg.sender` and 32 bytes of `msg.value`). Return what the calls returns, or revert if the call failed.
|
|
81
|
+
*
|
|
82
|
+
* 2. If the data sent to this function is of length less than 4 bytes (not a function selector), revert.
|
|
83
|
+
*/
|
|
84
|
+
fallback(
|
|
85
|
+
bytes calldata callData
|
|
86
|
+
) external payable virtual returns (bytes memory) {
|
|
87
|
+
if (msg.data.length < 4) {
|
|
88
|
+
revert InvalidFunctionSelector(callData);
|
|
89
|
+
}
|
|
90
|
+
return _fallbackLSP17Extendable(callData);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @dev Forwards the call with the received value to an extension mapped to a function selector.
|
|
95
|
+
*
|
|
96
|
+
* Calls {_getExtension} to get the address of the extension mapped to the function selector being
|
|
97
|
+
* called on the account. If there is no extension, the address(0) will be returned.
|
|
98
|
+
*
|
|
99
|
+
* Reverts if there is no extension for the function being called.
|
|
100
|
+
*
|
|
101
|
+
* If there is an extension for the function selector being called, it calls the extension with the
|
|
102
|
+
* CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
|
|
103
|
+
* 32 bytes of the {msg.value}
|
|
104
|
+
*
|
|
105
|
+
* Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
|
|
106
|
+
* called before other codes in fallback().
|
|
107
|
+
*
|
|
108
|
+
* Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
|
|
109
|
+
*/
|
|
110
|
+
function _fallbackLSP17Extendable(
|
|
111
|
+
bytes calldata callData
|
|
112
|
+
) internal virtual override returns (bytes memory) {
|
|
113
|
+
// If there is a function selector
|
|
114
|
+
address extension = _getExtension(msg.sig);
|
|
115
|
+
|
|
116
|
+
// if no extension was found, revert
|
|
117
|
+
if (extension == address(0))
|
|
118
|
+
revert NoExtensionFoundForFunctionSelector(msg.sig);
|
|
119
|
+
|
|
120
|
+
(bool success, bytes memory result) = extension.call{value: msg.value}(
|
|
121
|
+
abi.encodePacked(callData, msg.sender, msg.value)
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (success) {
|
|
125
|
+
return result;
|
|
126
|
+
} else {
|
|
127
|
+
// `mload(result)` -> offset in memory where `result.length` is located
|
|
128
|
+
// `add(result, 32)` -> offset in memory where `result` data starts
|
|
129
|
+
// solhint-disable no-inline-assembly
|
|
130
|
+
/// @solidity memory-safe-assembly
|
|
131
|
+
assembly {
|
|
132
|
+
let resultdata_size := mload(result)
|
|
133
|
+
revert(add(result, 32), resultdata_size)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @dev Returns the extension address stored under the following data key:
|
|
140
|
+
* - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
|
|
141
|
+
* - If no extension is stored, returns the address(0).
|
|
142
|
+
*/
|
|
143
|
+
function _getExtension(
|
|
144
|
+
bytes4 functionSelector
|
|
145
|
+
) internal view virtual override returns (address) {
|
|
146
|
+
// Generate the data key relevant for the functionSelector being called
|
|
147
|
+
bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
|
|
148
|
+
_LSP17_EXTENSION_PREFIX,
|
|
149
|
+
functionSelector
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// Check if there is an extension stored under the generated data key
|
|
153
|
+
bytes memory extensionAddress = ERC725YCore._getData(
|
|
154
|
+
mappedExtensionDataKey
|
|
155
|
+
);
|
|
156
|
+
if (extensionAddress.length != 20 && extensionAddress.length != 0)
|
|
157
|
+
revert InvalidExtensionAddress(extensionAddress);
|
|
158
|
+
|
|
159
|
+
return address(bytes20(extensionAddress));
|
|
160
|
+
}
|
|
161
|
+
|
|
40
162
|
/**
|
|
41
163
|
* @dev See {IERC165-supportsInterface}.
|
|
42
164
|
*/
|
|
43
165
|
function supportsInterface(
|
|
44
166
|
bytes4 interfaceId
|
|
45
|
-
)
|
|
167
|
+
)
|
|
168
|
+
public
|
|
169
|
+
view
|
|
170
|
+
virtual
|
|
171
|
+
override(IERC165, ERC725YCore, LSP17Extendable)
|
|
172
|
+
returns (bool)
|
|
173
|
+
{
|
|
46
174
|
return
|
|
47
175
|
interfaceId == _INTERFACEID_LSP8 ||
|
|
48
|
-
super.supportsInterface(interfaceId)
|
|
176
|
+
super.supportsInterface(interfaceId) ||
|
|
177
|
+
LSP17Extendable._supportsInterfaceInERC165Extension(interfaceId);
|
|
49
178
|
}
|
|
50
179
|
}
|