@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,8 +3,8 @@ pragma solidity ^0.8.4;
|
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
5
5
|
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
6
|
+
import {ILSP0ERC725Account} from "./ILSP0ERC725Account.sol";
|
|
6
7
|
import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
|
|
7
|
-
import {ILSP20CallVerification} from "../LSP20CallVerification/ILSP20CallVerification.sol";
|
|
8
8
|
|
|
9
9
|
// libraries
|
|
10
10
|
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
@@ -13,7 +13,6 @@ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165C
|
|
|
13
13
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
14
14
|
import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
|
|
15
15
|
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
16
|
-
import {GasLib} from "../Utils/GasLib.sol";
|
|
17
16
|
|
|
18
17
|
// modules
|
|
19
18
|
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
|
|
@@ -42,20 +41,48 @@ import {
|
|
|
42
41
|
import {_INTERFACEID_LSP14} from "../LSP14Ownable2Step/LSP14Constants.sol";
|
|
43
42
|
|
|
44
43
|
import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.sol";
|
|
44
|
+
import {_INTERFACEID_LSP20_CALL_VERIFICATION} from "../LSP20CallVerification/LSP20Constants.sol";
|
|
45
45
|
|
|
46
46
|
// errors
|
|
47
|
-
import "@erc725/smart-contracts/contracts/errors.sol";
|
|
48
|
-
import "../LSP17ContractExtension/LSP17Errors.sol";
|
|
47
|
+
import {ERC725Y_DataKeysValuesLengthMismatch} from "@erc725/smart-contracts/contracts/errors.sol";
|
|
48
|
+
import {NoExtensionFoundForFunctionSelector} from "../LSP17ContractExtension/LSP17Errors.sol";
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* @title Core Implementation of ERC725Account
|
|
52
|
-
*
|
|
53
|
-
*
|
|
51
|
+
* @title The Core Implementation of LSP0-ERC725Account Standard
|
|
52
|
+
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-0-ERC725Account.md
|
|
53
|
+
*
|
|
54
|
+
* @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42)
|
|
55
|
+
* @dev A smart contract account including basic functionalities such as:
|
|
56
|
+
*
|
|
57
|
+
* - Detecting supported standards using ERC165
|
|
58
|
+
* https://eips.ethereum.org/EIPS/eip-165
|
|
59
|
+
*
|
|
60
|
+
* - Executing several operation on other addresses including creating contracts using ERC725X
|
|
61
|
+
* https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md
|
|
62
|
+
*
|
|
63
|
+
* - Storing data in a generic way using ERC725Y
|
|
64
|
+
* https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md
|
|
65
|
+
*
|
|
66
|
+
* - Validating signatures using ERC1271
|
|
67
|
+
* https://eips.ethereum.org/EIPS/eip-1271
|
|
68
|
+
*
|
|
69
|
+
* - Receiving notification and react on them using LSP1
|
|
70
|
+
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-1-UniversalReceiver.md
|
|
71
|
+
*
|
|
72
|
+
* - Secure ownership management using LSP14
|
|
73
|
+
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-14-Ownable2Step.md
|
|
74
|
+
*
|
|
75
|
+
* - Extending the account with new functions and interfaceIds of future standards using LSP17
|
|
76
|
+
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-17-ContractExtension.md
|
|
77
|
+
*
|
|
78
|
+
* - Verifying calls on the owner to allow unified and standard interaction with the account using LSP20
|
|
79
|
+
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-20-CallVerification.md
|
|
54
80
|
*/
|
|
55
81
|
abstract contract LSP0ERC725AccountCore is
|
|
56
82
|
ERC725XCore,
|
|
57
83
|
ERC725YCore,
|
|
58
84
|
IERC1271,
|
|
85
|
+
ILSP0ERC725Account,
|
|
59
86
|
ILSP1UniversalReceiver,
|
|
60
87
|
LSP14Ownable2Step,
|
|
61
88
|
LSP17Extendable,
|
|
@@ -66,55 +93,70 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
66
93
|
using Address for address;
|
|
67
94
|
|
|
68
95
|
/**
|
|
69
|
-
* @
|
|
70
|
-
* @param sender The address of the sender
|
|
71
|
-
* @param value The amount of native tokens received
|
|
72
|
-
*/
|
|
73
|
-
event ValueReceived(address indexed sender, uint256 indexed value);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @dev Emits an event when receiving native tokens
|
|
96
|
+
* @dev Emits a `ValueReceived` event when receiving native tokens.
|
|
77
97
|
*
|
|
78
98
|
* Executed:
|
|
79
99
|
* - when receiving some native tokens without any additional data.
|
|
80
100
|
* - on empty calls to the contract.
|
|
81
101
|
*/
|
|
82
102
|
receive() external payable virtual {
|
|
83
|
-
if (msg.value != 0)
|
|
103
|
+
if (msg.value != 0) {
|
|
104
|
+
emit ValueReceived(msg.sender, msg.value);
|
|
105
|
+
}
|
|
84
106
|
}
|
|
85
107
|
|
|
86
108
|
// solhint-disable no-complex-fallback
|
|
87
109
|
|
|
88
110
|
/**
|
|
89
|
-
* @
|
|
111
|
+
* @notice Achieves the goal of {LSP17-ContractExtension} standard by extending the contract to
|
|
112
|
+
* handle calls of functions that do not exist natively, forwarding the function call to the
|
|
113
|
+
* extension address mapped to the function being called.
|
|
90
114
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*_LSP17_FALLBACK_EXTENSIONS_HANDLER_ + <function-selector>
|
|
94
|
-
* If there is no extension stored under the data key, return.
|
|
115
|
+
* @dev This function:
|
|
116
|
+
* - Emits a {ValueReceived} event when receiving native tokens
|
|
95
117
|
*
|
|
96
|
-
*
|
|
97
|
-
* Returns the return value on success and revert in case of failure.
|
|
118
|
+
* - Returns if the data sent to this function is of length less than 4 bytes (not a function selector)
|
|
98
119
|
*
|
|
99
|
-
* If the
|
|
120
|
+
* - If the data is equal or longer than 4 bytes, the ERC725Y storage is queried with the following data key:
|
|
121
|
+
* {_LSP17_EXTENSION_PREFIX + <bytes4 (msg.sig)>} (Check {LSP2-ERC725YJSONSchema} for encoding the data key)
|
|
122
|
+
*
|
|
123
|
+
* - If there is no address stored under the following data key, revert with {NoExtensionFoundForFunctionSelector(bytes4)}
|
|
124
|
+
* The data key relative to bytes4(0) is an exception, where no reverts occurs if there is no extension address stored under
|
|
125
|
+
*
|
|
126
|
+
* This exception is made to allow users to send random data (graffiti) to the account and to be able to react on it.
|
|
127
|
+
*
|
|
128
|
+
* - If there is an address, forward the {msg.data} to the extension using the CALL opcode,
|
|
129
|
+
* appending 52 bytes (20 bytes of {msg.sender} and 32 bytes of {msg.value}).
|
|
130
|
+
* Return what the calls returns, or revert if the call failed
|
|
100
131
|
*
|
|
101
132
|
* Executed when:
|
|
102
|
-
*
|
|
103
|
-
*
|
|
133
|
+
* - sending data of length less than 4 bytes to the contract.
|
|
134
|
+
* - the first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
|
|
135
|
+
* - receiving native tokens with some calldata.
|
|
104
136
|
*/
|
|
105
137
|
fallback() external payable virtual {
|
|
106
|
-
if (msg.value != 0)
|
|
107
|
-
|
|
138
|
+
if (msg.value != 0) {
|
|
139
|
+
emit ValueReceived(msg.sender, msg.value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (msg.data.length < 4) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
108
145
|
|
|
109
146
|
_fallbackLSP17Extendable();
|
|
110
147
|
}
|
|
111
148
|
|
|
112
149
|
/**
|
|
113
|
-
* @dev
|
|
150
|
+
* @dev Allows a caller to batch different function calls in one call.
|
|
151
|
+
* Perform a delegatecall on self, to call different functions with preserving the context
|
|
152
|
+
* It is not possible to send value along the functions call due to the use of delegatecall.
|
|
153
|
+
*
|
|
154
|
+
* @param data An array of ABI encoded function calls to be called on the contract.
|
|
155
|
+
* @return results An array of values returned by the executed functions.
|
|
114
156
|
*/
|
|
115
157
|
function batchCalls(bytes[] calldata data) public returns (bytes[] memory results) {
|
|
116
158
|
results = new bytes[](data.length);
|
|
117
|
-
for (uint256 i; i < data.length;
|
|
159
|
+
for (uint256 i; i < data.length; ) {
|
|
118
160
|
(bool success, bytes memory result) = address(this).delegatecall(data[i]);
|
|
119
161
|
|
|
120
162
|
if (!success) {
|
|
@@ -133,22 +175,32 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
133
175
|
}
|
|
134
176
|
|
|
135
177
|
results[i] = result;
|
|
178
|
+
|
|
179
|
+
unchecked {
|
|
180
|
+
++i;
|
|
181
|
+
}
|
|
136
182
|
}
|
|
137
183
|
}
|
|
138
184
|
|
|
139
185
|
/**
|
|
186
|
+
* @dev Executes any call on other addresses.
|
|
187
|
+
*
|
|
140
188
|
* @param operationType The operation to execute: CALL = 0 CREATE = 1 CREATE2 = 2 STATICCALL = 3 DELEGATECALL = 4
|
|
141
|
-
* @param target The smart contract
|
|
189
|
+
* @param target The address (smart contract/EOA) to interact with, `target` will be unused if a contract is created (operation 1 and 2)
|
|
142
190
|
* @param value The amount of native tokens to transfer (in Wei).
|
|
143
|
-
* @param data The call data
|
|
144
|
-
* @dev Executes any call on other addresses.
|
|
191
|
+
* @param data The call data to execute on `target`, or the bytecode of the contract to deploy
|
|
145
192
|
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
193
|
+
* Requirements:
|
|
194
|
+
*
|
|
195
|
+
* - if a `value` is provided, the contract MUST have at least this amount in its balance to execute successfully.
|
|
196
|
+
* - if the operation type is {STATICCALL} or {DELEGATECALL}, `value` SHOULD be 0.
|
|
197
|
+
* - `target` SHOULD be address(0) when deploying a contract.
|
|
198
|
+
* - MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
199
|
+
* on the owner accordinng to LSP20 - CallVerification specification
|
|
148
200
|
*
|
|
149
201
|
* Emits a {Executed} event, when a call is executed under `operationType` 0, 3 and 4
|
|
150
202
|
* Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2
|
|
151
|
-
* Emits a {ValueReceived} event
|
|
203
|
+
* Emits a {ValueReceived} event when receiving native tokens.
|
|
152
204
|
*/
|
|
153
205
|
function execute(
|
|
154
206
|
uint256 operationType,
|
|
@@ -156,121 +208,220 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
156
208
|
uint256 value,
|
|
157
209
|
bytes memory data
|
|
158
210
|
) public payable virtual override returns (bytes memory) {
|
|
159
|
-
if (msg.value != 0)
|
|
211
|
+
if (msg.value != 0) {
|
|
212
|
+
emit ValueReceived(msg.sender, msg.value);
|
|
213
|
+
}
|
|
160
214
|
|
|
161
215
|
address _owner = owner();
|
|
162
216
|
|
|
163
|
-
|
|
217
|
+
// If the caller is the owner perform execute directly
|
|
218
|
+
if (msg.sender == _owner) {
|
|
219
|
+
return ERC725XCore._execute(operationType, target, value, data);
|
|
220
|
+
}
|
|
164
221
|
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
222
|
+
// If the caller is not the owner, call {lsp20VerifyCall} on the owner
|
|
223
|
+
// Depending on the magicValue returned, a second call is done after execution
|
|
224
|
+
bool verifyAfter = LSP20CallVerification._verifyCall(_owner);
|
|
225
|
+
|
|
226
|
+
// Perform the execution
|
|
227
|
+
bytes memory result = ERC725XCore._execute(operationType, target, value, data);
|
|
228
|
+
|
|
229
|
+
// if verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
|
|
230
|
+
if (verifyAfter) {
|
|
231
|
+
LSP20CallVerification._verifyCallResult(_owner, abi.encode(result));
|
|
232
|
+
}
|
|
169
233
|
|
|
170
234
|
return result;
|
|
171
235
|
}
|
|
172
236
|
|
|
173
237
|
/**
|
|
174
|
-
* @
|
|
238
|
+
* @dev Generic batch executor function that executes any call on other addresses
|
|
175
239
|
*
|
|
176
|
-
* @
|
|
177
|
-
*
|
|
240
|
+
* @param operationsType The list of operations type used: CALL = 0; CREATE = 1; CREATE2 = 2; STATICCALL = 3; DELEGATECALL = 4
|
|
241
|
+
* @param targets The list of addresses to call. `targets` will be unused if a contract is created (operation types 1 and 2).
|
|
242
|
+
* @param values The list of native token amounts to transfer (in Wei)
|
|
243
|
+
* @param datas The list of call data to execute on `targets`, or the creation bytecode of the contracts to deploy
|
|
178
244
|
*
|
|
245
|
+
* Requirements:
|
|
246
|
+
*
|
|
247
|
+
* - The length of the parameters provided MUST be equal
|
|
248
|
+
* - if a `value` is provided, the contract MUST have at least this amount in its balance to execute successfully.
|
|
249
|
+
* - if the operation type is {STATICCALL} or {DELEGATECALL}, `value` SHOULD be 0.
|
|
250
|
+
* - `target` SHOULD be address(0) when deploying a contract.
|
|
251
|
+
* - MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
252
|
+
* on the owner accordinng to LSP20 - CallVerification specification
|
|
253
|
+
*
|
|
254
|
+
* Emits a {Executed} event, when a call is executed under `operationType` 0, 3 and 4 (each iteration)
|
|
255
|
+
* Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2 (each iteration)
|
|
179
256
|
* Emits a {ValueReceived} event when receiving native tokens.
|
|
180
257
|
*/
|
|
181
|
-
function
|
|
258
|
+
function executeBatch(
|
|
182
259
|
uint256[] memory operationsType,
|
|
183
260
|
address[] memory targets,
|
|
184
261
|
uint256[] memory values,
|
|
185
262
|
bytes[] memory datas
|
|
186
263
|
) public payable virtual override returns (bytes[] memory) {
|
|
187
|
-
if (msg.value != 0)
|
|
264
|
+
if (msg.value != 0) {
|
|
265
|
+
emit ValueReceived(msg.sender, msg.value);
|
|
266
|
+
}
|
|
188
267
|
|
|
189
268
|
address _owner = owner();
|
|
190
269
|
|
|
191
|
-
|
|
270
|
+
// If the caller is the owner perform execute directly
|
|
271
|
+
if (msg.sender == _owner) {
|
|
272
|
+
return ERC725XCore._executeBatch(operationsType, targets, values, datas);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// If the caller is not the owner, call {lsp20VerifyCall} on the owner
|
|
276
|
+
// Depending on the magicValue returned, a second call is done after execution
|
|
277
|
+
bool verifyAfter = LSP20CallVerification._verifyCall(_owner);
|
|
192
278
|
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if
|
|
279
|
+
// Perform the execution
|
|
280
|
+
bytes[] memory results = ERC725XCore._executeBatch(operationsType, targets, values, datas);
|
|
281
|
+
|
|
282
|
+
// if verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
|
|
283
|
+
if (verifyAfter) {
|
|
284
|
+
LSP20CallVerification._verifyCallResult(_owner, abi.encode(results));
|
|
285
|
+
}
|
|
197
286
|
|
|
198
287
|
return results;
|
|
199
288
|
}
|
|
200
289
|
|
|
201
290
|
/**
|
|
202
|
-
* @
|
|
291
|
+
* @dev Sets singular data for a given `dataKey`
|
|
292
|
+
*
|
|
203
293
|
* @param dataKey The key to retrieve stored value
|
|
204
294
|
* @param dataValue The value to set
|
|
205
295
|
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
296
|
+
* Requirements:
|
|
297
|
+
*
|
|
298
|
+
* - MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
299
|
+
* on the owner accordinng to LSP20 - CallVerification specification
|
|
208
300
|
*
|
|
301
|
+
* Emits a {ValueReceived} event when receiving native tokens.
|
|
209
302
|
* Emits a {DataChanged} event.
|
|
210
303
|
*/
|
|
211
304
|
function setData(bytes32 dataKey, bytes memory dataValue) public payable virtual override {
|
|
212
|
-
if (msg.value != 0)
|
|
305
|
+
if (msg.value != 0) {
|
|
306
|
+
emit ValueReceived(msg.sender, msg.value);
|
|
307
|
+
}
|
|
308
|
+
|
|
213
309
|
address _owner = owner();
|
|
214
310
|
|
|
215
|
-
|
|
311
|
+
// If the caller is the owner perform setData directly
|
|
312
|
+
if (msg.sender == _owner) {
|
|
313
|
+
return _setData(dataKey, dataValue);
|
|
314
|
+
}
|
|
216
315
|
|
|
217
|
-
//
|
|
316
|
+
// If the caller is not the owner, call {lsp20VerifyCall} on the owner
|
|
317
|
+
// Depending on the magicValue returned, a second call is done after setting data
|
|
218
318
|
bool verifyAfter = _verifyCall(_owner);
|
|
319
|
+
|
|
219
320
|
_setData(dataKey, dataValue);
|
|
220
321
|
|
|
322
|
+
// If verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
|
|
221
323
|
// The setData function does not return, second parameter of {_verifyCallResult} will be empty
|
|
222
|
-
if (verifyAfter)
|
|
324
|
+
if (verifyAfter) {
|
|
325
|
+
_verifyCallResult(_owner, "");
|
|
326
|
+
}
|
|
223
327
|
}
|
|
224
328
|
|
|
225
329
|
/**
|
|
330
|
+
* @dev Sets array of data for multiple given `dataKeys`
|
|
331
|
+
*
|
|
226
332
|
* @param dataKeys The array of data keys for values to set
|
|
227
333
|
* @param dataValues The array of values to set
|
|
228
|
-
* @dev Sets array of data for multiple given `dataKeys`
|
|
229
334
|
*
|
|
230
|
-
*
|
|
231
|
-
* by LSP20 - CallVerification specification
|
|
335
|
+
* Requirements:
|
|
232
336
|
*
|
|
233
|
-
*
|
|
337
|
+
* - MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
338
|
+
* on the owner accordinng to LSP20 - CallVerification specification
|
|
339
|
+
*
|
|
340
|
+
* Emits a {ValueReceived} event when receiving native tokens.
|
|
341
|
+
* Emits a {DataChanged} event. (on each iteration of setting data)
|
|
234
342
|
*/
|
|
235
|
-
function
|
|
343
|
+
function setDataBatch(bytes32[] memory dataKeys, bytes[] memory dataValues)
|
|
236
344
|
public
|
|
237
345
|
payable
|
|
238
346
|
virtual
|
|
239
347
|
override
|
|
240
348
|
{
|
|
241
|
-
if (msg.value != 0)
|
|
349
|
+
if (msg.value != 0) {
|
|
350
|
+
emit ValueReceived(msg.sender, msg.value);
|
|
351
|
+
}
|
|
242
352
|
|
|
243
353
|
if (dataKeys.length != dataValues.length) {
|
|
244
|
-
revert ERC725Y_DataKeysValuesLengthMismatch(
|
|
354
|
+
revert ERC725Y_DataKeysValuesLengthMismatch();
|
|
245
355
|
}
|
|
246
356
|
|
|
247
357
|
address _owner = owner();
|
|
248
358
|
|
|
359
|
+
// If the caller is the owner perform setData directly
|
|
249
360
|
if (msg.sender == _owner) {
|
|
250
|
-
for (uint256 i = 0; i < dataKeys.length;
|
|
361
|
+
for (uint256 i = 0; i < dataKeys.length; ) {
|
|
251
362
|
_setData(dataKeys[i], dataValues[i]);
|
|
363
|
+
|
|
364
|
+
unchecked {
|
|
365
|
+
++i;
|
|
366
|
+
}
|
|
252
367
|
}
|
|
253
368
|
|
|
254
369
|
return;
|
|
255
370
|
}
|
|
256
371
|
|
|
257
|
-
//
|
|
372
|
+
// If the caller is not the owner, call {lsp20VerifyCall} on the owner
|
|
373
|
+
// Depending on the magicValue returned, a second call is done after setting data
|
|
258
374
|
bool verifyAfter = _verifyCall(_owner);
|
|
259
|
-
|
|
375
|
+
|
|
376
|
+
for (uint256 i = 0; i < dataKeys.length; ) {
|
|
260
377
|
_setData(dataKeys[i], dataValues[i]);
|
|
378
|
+
|
|
379
|
+
unchecked {
|
|
380
|
+
++i;
|
|
381
|
+
}
|
|
261
382
|
}
|
|
262
383
|
|
|
384
|
+
// If verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
|
|
263
385
|
// The setData function does not return, second parameter of {_verifyCallResult} will be empty
|
|
264
|
-
if (verifyAfter)
|
|
386
|
+
if (verifyAfter) {
|
|
387
|
+
_verifyCallResult(_owner, "");
|
|
388
|
+
}
|
|
265
389
|
}
|
|
266
390
|
|
|
267
391
|
/**
|
|
268
|
-
* @notice
|
|
269
|
-
*
|
|
270
|
-
*
|
|
392
|
+
* @notice Achieves the goal of LSP1-UniversalReceiver by allowing the account to be notified about incoming/outgoing
|
|
393
|
+
* transactions and enabling reactions to these actions.
|
|
394
|
+
*
|
|
395
|
+
* The reaction is achieved by having two external contracts (UniversalReceiverDelegates) that react on the whole transaction
|
|
396
|
+
* and on the specific typeId, respectively.
|
|
397
|
+
*
|
|
398
|
+
* The notification is achieved by emitting a {UniversalReceiver} event on the call with the function parameters, call options, and the
|
|
399
|
+
* response of the UniversalReceiverDelegates (URD) contract.
|
|
400
|
+
*
|
|
401
|
+
* @dev The function performs the following steps:
|
|
402
|
+
*
|
|
403
|
+
* - Emits {ValueReceived} when receiving native tokens.
|
|
404
|
+
*
|
|
405
|
+
* - Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY}.
|
|
406
|
+
* - If there is an address stored under the data key, check if this address supports the LSP1 interfaceId.
|
|
407
|
+
*
|
|
408
|
+
* - If yes, call this address with the typeId and data (params), along with additional calldata consisting
|
|
409
|
+
* of 20 bytes of {msg.sender} and 32 bytes of {msg.value}. If not, continue the execution of the function.
|
|
410
|
+
*
|
|
411
|
+
*
|
|
412
|
+
* - Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY + <bytes32 typeId>}.
|
|
413
|
+
* (Check {LSP2-ERC725YJSONSchema} for encoding the data key)
|
|
414
|
+
*
|
|
415
|
+
* - If there is an address stored under the data key, check if this address supports the LSP1 interfaceId.
|
|
416
|
+
*
|
|
417
|
+
* - If yes, call this address with the typeId and data (params), along with additional calldata consisting
|
|
418
|
+
* of 20 bytes of {msg.sender} and 32 bytes of {msg.value}. If not, continue the execution of the function.
|
|
419
|
+
*
|
|
420
|
+
* - Emits a {UniversalReceiver} event.
|
|
271
421
|
*
|
|
272
422
|
* @param typeId The type of call received.
|
|
273
423
|
* @param receivedData The data received.
|
|
424
|
+
*
|
|
274
425
|
* @return returnedValues The ABI encoded return value of the LSP1UniversalReceiverDelegate call
|
|
275
426
|
* and the LSP1TypeIdDelegate call.
|
|
276
427
|
*/
|
|
@@ -280,14 +431,20 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
280
431
|
virtual
|
|
281
432
|
returns (bytes memory returnedValues)
|
|
282
433
|
{
|
|
283
|
-
if (msg.value != 0)
|
|
434
|
+
if (msg.value != 0) {
|
|
435
|
+
emit ValueReceived(msg.sender, msg.value);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY}
|
|
284
439
|
bytes memory lsp1DelegateValue = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
|
|
285
440
|
bytes memory resultDefaultDelegate;
|
|
286
441
|
|
|
287
442
|
if (lsp1DelegateValue.length >= 20) {
|
|
288
443
|
address universalReceiverDelegate = address(bytes20(lsp1DelegateValue));
|
|
289
444
|
|
|
445
|
+
// Checking LSP1 InterfaceId support
|
|
290
446
|
if (universalReceiverDelegate.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
|
|
447
|
+
// calling {universalReceiver} function on URD appending the caller and the value sent
|
|
291
448
|
resultDefaultDelegate = universalReceiverDelegate
|
|
292
449
|
.callUniversalReceiverWithCallerInfos(
|
|
293
450
|
typeId,
|
|
@@ -298,18 +455,22 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
298
455
|
}
|
|
299
456
|
}
|
|
300
457
|
|
|
458
|
+
// Generate the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY + <bytes32 typeId>}
|
|
301
459
|
bytes32 lsp1typeIdDelegateKey = LSP2Utils.generateMappingKey(
|
|
302
460
|
_LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
|
|
303
461
|
bytes20(typeId)
|
|
304
462
|
);
|
|
305
463
|
|
|
464
|
+
// Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY + <bytes32 typeId>}
|
|
306
465
|
bytes memory lsp1TypeIdDelegateValue = _getData(lsp1typeIdDelegateKey);
|
|
307
466
|
bytes memory resultTypeIdDelegate;
|
|
308
467
|
|
|
309
468
|
if (lsp1TypeIdDelegateValue.length >= 20) {
|
|
310
469
|
address universalReceiverDelegate = address(bytes20(lsp1TypeIdDelegateValue));
|
|
311
470
|
|
|
471
|
+
// Checking LSP1 InterfaceId support
|
|
312
472
|
if (universalReceiverDelegate.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
|
|
473
|
+
// calling {universalReceiver} function on URD appending the caller and the value sent
|
|
313
474
|
resultTypeIdDelegate = universalReceiverDelegate
|
|
314
475
|
.callUniversalReceiverWithCallerInfos(
|
|
315
476
|
typeId,
|
|
@@ -325,30 +486,40 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
325
486
|
}
|
|
326
487
|
|
|
327
488
|
/**
|
|
328
|
-
* @
|
|
489
|
+
* @notice Achieves the goal of LSP14Ownable2Step by implementing a 2-step ownership transfer process.
|
|
490
|
+
*
|
|
491
|
+
* @dev Sets the pending owner address as an address that should call {acceptOwnership} in order to complete
|
|
492
|
+
* the ownership transfer of the account.
|
|
493
|
+
*
|
|
494
|
+
* Notifies the pending owner via LSP1Standard by calling {universalReceiver} on the pending owner if it's
|
|
495
|
+
* an address that supports LSP1.
|
|
496
|
+
*
|
|
497
|
+
* @param _pendingOwner The address of the new pending owner.
|
|
329
498
|
*
|
|
330
|
-
* @dev same as ILSP14.transferOwnership with the additional requirement:
|
|
331
499
|
* Requirements:
|
|
332
500
|
*
|
|
333
|
-
* - MUST pass when called by the owner or by an
|
|
334
|
-
*
|
|
501
|
+
* - MUST pass when called by the owner or by an authorized address that passes the verification check performed
|
|
502
|
+
* on the owner according to LSP20 - CallVerification specification.
|
|
503
|
+
*
|
|
504
|
+
* - When notifying the new owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferStarted').
|
|
335
505
|
*
|
|
336
|
-
* -
|
|
506
|
+
* - pending owner cannot accept ownership in the same tx via the LSP1 hook.
|
|
337
507
|
*/
|
|
338
|
-
function transferOwnership(address
|
|
508
|
+
function transferOwnership(address _pendingOwner)
|
|
339
509
|
public
|
|
340
510
|
virtual
|
|
341
511
|
override(LSP14Ownable2Step, OwnableUnset)
|
|
342
512
|
{
|
|
343
513
|
address currentOwner = owner();
|
|
344
514
|
|
|
515
|
+
// If the caller is the owner perform transferOwnership directly
|
|
345
516
|
if (msg.sender == currentOwner) {
|
|
346
517
|
// set the pending owner
|
|
347
|
-
LSP14Ownable2Step._transferOwnership(
|
|
348
|
-
emit OwnershipTransferStarted(currentOwner,
|
|
518
|
+
LSP14Ownable2Step._transferOwnership(_pendingOwner);
|
|
519
|
+
emit OwnershipTransferStarted(currentOwner, _pendingOwner);
|
|
349
520
|
|
|
350
521
|
// notify the pending owner through LSP1
|
|
351
|
-
|
|
522
|
+
_pendingOwner.tryNotifyUniversalReceiver(_TYPEID_LSP0_OwnershipTransferStarted, "");
|
|
352
523
|
|
|
353
524
|
// Require that the owner didn't change after the LSP1 Call
|
|
354
525
|
// (Pending owner didn't automate the acceptOwnership call through LSP1)
|
|
@@ -357,15 +528,16 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
357
528
|
"LSP14: newOwner MUST accept ownership in a separate transaction"
|
|
358
529
|
);
|
|
359
530
|
} else {
|
|
360
|
-
// If the caller is not the owner,
|
|
531
|
+
// If the caller is not the owner, call {lsp20VerifyCall} on the owner
|
|
532
|
+
// Depending on the magicValue returned, a second call is done after transferring ownership
|
|
361
533
|
bool verifyAfter = _verifyCall(currentOwner);
|
|
362
534
|
|
|
363
535
|
// Set the pending owner if the call is allowed
|
|
364
|
-
LSP14Ownable2Step._transferOwnership(
|
|
365
|
-
emit OwnershipTransferStarted(currentOwner,
|
|
536
|
+
LSP14Ownable2Step._transferOwnership(_pendingOwner);
|
|
537
|
+
emit OwnershipTransferStarted(currentOwner, _pendingOwner);
|
|
366
538
|
|
|
367
539
|
// notify the pending owner through LSP1
|
|
368
|
-
|
|
540
|
+
_pendingOwner.tryNotifyUniversalReceiver(_TYPEID_LSP0_OwnershipTransferStarted, "");
|
|
369
541
|
|
|
370
542
|
// Require that the owner didn't change after the LSP1 Call
|
|
371
543
|
// (Pending owner didn't automate the acceptOwnership call through LSP1)
|
|
@@ -374,30 +546,40 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
374
546
|
"LSP14: newOwner MUST accept ownership in a separate transaction"
|
|
375
547
|
);
|
|
376
548
|
|
|
549
|
+
// If verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
|
|
377
550
|
// The transferOwnership function does not return, second parameter of {_verifyCallResult} will be empty
|
|
378
|
-
if (verifyAfter)
|
|
551
|
+
if (verifyAfter) {
|
|
552
|
+
_verifyCallResult(currentOwner, "");
|
|
553
|
+
}
|
|
379
554
|
}
|
|
380
555
|
}
|
|
381
556
|
|
|
382
557
|
/**
|
|
383
|
-
* @
|
|
558
|
+
* @notice Achieves the goal of LSP14Ownable2Step by implementing a 2-step ownership transfer process.
|
|
559
|
+
*
|
|
560
|
+
* @dev Transfer ownership of the contract from the current `owner()` to the `pendingOwner()`.
|
|
384
561
|
*
|
|
385
|
-
*
|
|
562
|
+
* Once this function is called:
|
|
563
|
+
* - the current `owner()` will loose access to the functions restricted to the `owner()` only.
|
|
564
|
+
* - the `pendingOwner()` will gain access to the functions restricted to the `owner()` only.
|
|
386
565
|
*
|
|
387
566
|
* Requirements:
|
|
388
|
-
* -
|
|
389
|
-
* -
|
|
567
|
+
* - MUST be called by the pendingOwner.
|
|
568
|
+
* - When notifying the previous owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferred_SenderNotification').
|
|
569
|
+
* - When notifying the new owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferred_RecipientNotification').
|
|
390
570
|
*/
|
|
391
571
|
function acceptOwnership() public virtual override {
|
|
392
572
|
address previousOwner = owner();
|
|
393
573
|
|
|
394
574
|
_acceptOwnership();
|
|
395
575
|
|
|
576
|
+
// notify the previous owner if supports LSP1
|
|
396
577
|
previousOwner.tryNotifyUniversalReceiver(
|
|
397
578
|
_TYPEID_LSP0_OwnershipTransferred_SenderNotification,
|
|
398
579
|
""
|
|
399
580
|
);
|
|
400
581
|
|
|
582
|
+
// notify the pending owner if supports LSP1
|
|
401
583
|
msg.sender.tryNotifyUniversalReceiver(
|
|
402
584
|
_TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
|
|
403
585
|
""
|
|
@@ -405,24 +587,46 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
405
587
|
}
|
|
406
588
|
|
|
407
589
|
/**
|
|
408
|
-
* @
|
|
590
|
+
* @notice Achieves the goal of LSP14Ownable2Step by implementing a 2-step ownership renouncing process.
|
|
591
|
+
*
|
|
592
|
+
* @dev Renounce ownership of the contract in a 2-step process.
|
|
593
|
+
*
|
|
594
|
+
* 1. the first call will initiate the process of renouncing ownership.
|
|
595
|
+
* 2. the second is used as a confirmation and will leave the contract without an owner.
|
|
596
|
+
*
|
|
597
|
+
* MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
598
|
+
* on the owner accordinng to LSP20 - CallVerification specification
|
|
409
599
|
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
600
|
+
* WARNING: once ownership of the contract has been renounced, any functions
|
|
601
|
+
* that are restricted to be called by the owner will be permanently inaccessible,
|
|
602
|
+
* making these functions not callable anymore and unusable.
|
|
412
603
|
*/
|
|
413
604
|
function renounceOwnership() public virtual override(LSP14Ownable2Step, OwnableUnset) {
|
|
414
605
|
address _owner = owner();
|
|
415
606
|
|
|
416
|
-
|
|
607
|
+
// If the caller is the owner perform renounceOwnership directly
|
|
608
|
+
if (msg.sender == _owner) {
|
|
609
|
+
return LSP14Ownable2Step._renounceOwnership();
|
|
610
|
+
}
|
|
417
611
|
|
|
612
|
+
// If the caller is not the owner, call {lsp20VerifyCall} on the owner
|
|
613
|
+
// Depending on the magicValue returned, a second call is done after transferring ownership
|
|
418
614
|
bool verifyAfter = _verifyCall(_owner);
|
|
615
|
+
|
|
616
|
+
// set the pending owner
|
|
419
617
|
LSP14Ownable2Step._renounceOwnership();
|
|
420
618
|
|
|
421
|
-
//
|
|
422
|
-
|
|
619
|
+
// If verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
|
|
620
|
+
// The transferOwnership function does not return, second parameter of {_verifyCallResult} will be empty
|
|
621
|
+
if (verifyAfter) {
|
|
622
|
+
_verifyCallResult(_owner, "");
|
|
623
|
+
}
|
|
423
624
|
}
|
|
424
625
|
|
|
425
626
|
/**
|
|
627
|
+
* @notice Achieves the goal of ERC165 to detect supported interfaces and LSP17 by
|
|
628
|
+
* checking if the interfaceId being queried is supported on another linked extension.
|
|
629
|
+
*
|
|
426
630
|
* @dev Returns true if this contract implements the interface defined by
|
|
427
631
|
* `interfaceId`.
|
|
428
632
|
*
|
|
@@ -442,16 +646,36 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
442
646
|
interfaceId == _INTERFACEID_LSP0 ||
|
|
443
647
|
interfaceId == _INTERFACEID_LSP1 ||
|
|
444
648
|
interfaceId == _INTERFACEID_LSP14 ||
|
|
649
|
+
interfaceId == _INTERFACEID_LSP20_CALL_VERIFICATION ||
|
|
445
650
|
super.supportsInterface(interfaceId) ||
|
|
446
|
-
_supportsInterfaceInERC165Extension(interfaceId);
|
|
651
|
+
LSP17Extendable._supportsInterfaceInERC165Extension(interfaceId);
|
|
447
652
|
}
|
|
448
653
|
|
|
449
654
|
/**
|
|
450
|
-
* @notice
|
|
451
|
-
*
|
|
655
|
+
* @notice Achieves the goal of EIP-1271 by validating signatures of smart contracts
|
|
656
|
+
* according to their own logic.
|
|
657
|
+
*
|
|
658
|
+
* @param dataHash The hash of the data to be validated.
|
|
659
|
+
* @param signature A signature that can validate the previous parameter (Hash).
|
|
452
660
|
*
|
|
453
|
-
* @
|
|
454
|
-
*
|
|
661
|
+
* @dev Handles two cases:
|
|
662
|
+
*
|
|
663
|
+
* - If the owner is an EOA, recovers an address from the hash and the signature provided:
|
|
664
|
+
*
|
|
665
|
+
* - Returns the magicValue if the address recovered is the same as the owner, indicating
|
|
666
|
+
* that it was a valid signature.
|
|
667
|
+
*
|
|
668
|
+
* - If the address is different, it returns the fail value indicating that the signature is not valid.
|
|
669
|
+
*
|
|
670
|
+
* - If the owner is a smart contract, it forwards the call of {isValidSignature} to the owner contract:
|
|
671
|
+
*
|
|
672
|
+
* - If the contract fails or returns the fail value, the {isValidSignature} on the account returns the
|
|
673
|
+
* fail value, indicating that the signature is not valid.
|
|
674
|
+
*
|
|
675
|
+
* - If the {isValidSignature} on the owner returned the magicValue, the {isValidSignature} on the account
|
|
676
|
+
* returns the magicValue, indicating that it's a valid signature.
|
|
677
|
+
*
|
|
678
|
+
* @return magicValue A bytes4 value that indicates if the signature is valid or not.
|
|
455
679
|
*/
|
|
456
680
|
function isValidSignature(bytes32 dataHash, bytes memory signature)
|
|
457
681
|
public
|
|
@@ -475,26 +699,36 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
475
699
|
}
|
|
476
700
|
// If owner is an EOA
|
|
477
701
|
else {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
702
|
+
// if isValidSignature fail, the error is catched in returnedError
|
|
703
|
+
(address recoveredAddress, ECDSA.RecoverError returnedError) = ECDSA.tryRecover(
|
|
704
|
+
dataHash,
|
|
705
|
+
signature
|
|
706
|
+
);
|
|
707
|
+
|
|
708
|
+
// if recovering throws an error, return the fail value
|
|
709
|
+
if (returnedError != ECDSA.RecoverError.NoError) return _ERC1271_FAILVALUE;
|
|
710
|
+
|
|
711
|
+
// if recovering is successful and the recovered address matches the owner's address,
|
|
712
|
+
// return the ERC1271 magic value. Otherwise, return the ERC1271 fail value
|
|
713
|
+
// matches the address of the owner, otherwise return fail value
|
|
714
|
+
return recoveredAddress == _owner ? _ERC1271_MAGICVALUE : _ERC1271_FAILVALUE;
|
|
482
715
|
}
|
|
483
716
|
}
|
|
484
717
|
|
|
485
718
|
// Internal functions
|
|
486
719
|
|
|
487
|
-
// Fallback
|
|
488
|
-
|
|
489
720
|
/**
|
|
490
|
-
* @dev Forwards the call to an extension mapped to a function selector.
|
|
491
|
-
* is mapped to the function selector (address(0)), then revert.
|
|
721
|
+
* @dev Forwards the call to an extension mapped to a function selector.
|
|
492
722
|
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
723
|
+
* Calls {_getExtension} to get the address of the extension mapped to the function selector being
|
|
724
|
+
* called on the account. If there is no extension, the address(0) will be returned.
|
|
495
725
|
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
726
|
+
* Reverts if there is no extension for the function being called, except for the bytes4(0) function
|
|
727
|
+
* selector, which passes even if there is no extension for it.
|
|
728
|
+
*
|
|
729
|
+
* If there is an extension for the function selector being called, it calls the extension with the
|
|
730
|
+
* CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
|
|
731
|
+
* 32 bytes of the {msg.value}
|
|
498
732
|
*
|
|
499
733
|
* Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
|
|
500
734
|
* called before other codes in fallback().
|
|
@@ -508,7 +742,7 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
508
742
|
// if no extension was found for bytes4(0) return don't revert
|
|
509
743
|
if (msg.sig == bytes4(0) && extension == address(0)) return;
|
|
510
744
|
|
|
511
|
-
// if no extension was found, revert
|
|
745
|
+
// if no extension was found for other function selectors, revert
|
|
512
746
|
if (extension == address(0)) revert NoExtensionFoundForFunctionSelector(msg.sig);
|
|
513
747
|
|
|
514
748
|
// solhint-disable no-inline-assembly
|
|
@@ -542,8 +776,8 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
542
776
|
}
|
|
543
777
|
|
|
544
778
|
/**
|
|
545
|
-
* @dev Returns the extension stored under the
|
|
546
|
-
*
|
|
779
|
+
* @dev Returns the extension address stored under the following data key:
|
|
780
|
+
* {_LSP17_EXTENSION_PREFIX + <bytes4>} (Check {LSP2-ERC725YJSONSchema} for encoding the data key)
|
|
547
781
|
*
|
|
548
782
|
* If no extension is stored, returns the address(0)
|
|
549
783
|
*/
|
|
@@ -554,24 +788,27 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
554
788
|
override
|
|
555
789
|
returns (address)
|
|
556
790
|
{
|
|
791
|
+
// Generate the data key relevant for the functionSelector being called
|
|
557
792
|
bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
|
|
558
793
|
_LSP17_EXTENSION_PREFIX,
|
|
559
794
|
functionSelector
|
|
560
795
|
);
|
|
561
796
|
|
|
562
|
-
// Check if there is an extension
|
|
563
|
-
address extension = address(bytes20(_getData(mappedExtensionDataKey)));
|
|
797
|
+
// Check if there is an extension stored under the generated data key
|
|
798
|
+
address extension = address(bytes20(ERC725YCore._getData(mappedExtensionDataKey)));
|
|
564
799
|
|
|
565
800
|
return extension;
|
|
566
801
|
}
|
|
567
802
|
|
|
568
|
-
// ERC725Y
|
|
569
|
-
|
|
570
803
|
/**
|
|
571
|
-
* @dev
|
|
804
|
+
* @dev This function overrides the {ERC725YCore} internal {_setData} function to optimize gas usage by
|
|
805
|
+
* emitting the {DataChanged} event with only the first 256 bytes of {dataValue}.
|
|
806
|
+
*
|
|
807
|
+
* @param dataKey The key to store the data value under.
|
|
808
|
+
* @param dataValue The data value to be stored.
|
|
572
809
|
*/
|
|
573
810
|
function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
|
|
574
|
-
_store[dataKey] = dataValue;
|
|
811
|
+
ERC725YCore._store[dataKey] = dataValue;
|
|
575
812
|
emit DataChanged(
|
|
576
813
|
dataKey,
|
|
577
814
|
dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
|