@lukso/lsp-smart-contracts 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +8 -0
- package/README.md +34 -21
- package/artifacts/LSP0ERC725Account.json +51 -5
- package/artifacts/LSP0ERC725AccountInit.json +51 -5
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP16UniversalFactory.json +31 -2
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
- package/artifacts/LSP4Compatibility.json +7 -2
- package/artifacts/LSP4DigitalAssetMetadata.json +7 -2
- package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +7 -2
- package/artifacts/LSP6KeyManager.json +91 -6
- package/artifacts/LSP6KeyManagerInit.json +103 -18
- package/artifacts/LSP7CappedSupply.json +12 -2
- package/artifacts/LSP7CappedSupplyInitAbstract.json +12 -2
- package/artifacts/LSP7CompatibleERC20.json +12 -2
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +12 -2
- package/artifacts/LSP7CompatibleERC20Mintable.json +14 -4
- package/artifacts/LSP7CompatibleERC20MintableInit.json +14 -4
- package/artifacts/LSP7DigitalAsset.json +12 -2
- package/artifacts/LSP7DigitalAssetInitAbstract.json +12 -2
- package/artifacts/LSP7Mintable.json +14 -4
- package/artifacts/LSP7MintableInit.json +14 -4
- package/artifacts/LSP8CappedSupply.json +12 -2
- package/artifacts/LSP8CappedSupplyInitAbstract.json +12 -2
- package/artifacts/LSP8CompatibleERC721.json +12 -2
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +12 -2
- package/artifacts/LSP8CompatibleERC721Mintable.json +14 -4
- package/artifacts/LSP8CompatibleERC721MintableInit.json +14 -4
- package/artifacts/LSP8IdentifiableDigitalAsset.json +12 -2
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +12 -2
- package/artifacts/LSP8Mintable.json +14 -4
- package/artifacts/LSP8MintableInit.json +14 -4
- package/artifacts/LSP9Vault.json +29 -5
- package/artifacts/LSP9VaultInit.json +29 -5
- package/artifacts/UniversalProfile.json +51 -5
- package/artifacts/UniversalProfileInit.json +51 -5
- package/common/constants.d.ts +461 -0
- package/common/constants.js +789 -0
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +27 -0
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +353 -145
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +50 -0
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +48 -54
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -6
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +36 -77
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +50 -57
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +18 -8
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
- package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +74 -0
- package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +7 -7
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +50 -56
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6Constants.sol +8 -2
- package/contracts/LSP6KeyManager/LSP6Errors.sol +18 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +126 -745
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +407 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +25 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +633 -0
- package/contracts/LSP6KeyManager/LSP6Utils.sol +60 -15
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +14 -23
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +5 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +19 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +1 -3
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +1 -3
- package/contracts/LSP9Vault/ILSP9Vault.sol +19 -0
- package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
- package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
- package/contracts/LSP9Vault/LSP9VaultCore.sol +166 -83
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
- package/module/constants.d.ts +461 -0
- package/module/constants.js +786 -0
- package/package.json +30 -6
- package/constants.js +0 -856
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
6
|
+
import {IERC725X} from "@erc725/smart-contracts/contracts/interfaces/IERC725X.sol";
|
|
7
|
+
import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
8
|
+
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
9
|
+
import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
|
|
10
|
+
import {ILSP14Ownable2Step} from "../LSP14Ownable2Step/ILSP14Ownable2Step.sol";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @title Interface of ERC725Account
|
|
14
|
+
*/
|
|
15
|
+
interface ILSP0ERC725Account is
|
|
16
|
+
IERC165,
|
|
17
|
+
IERC725X,
|
|
18
|
+
IERC725Y,
|
|
19
|
+
IERC1271,
|
|
20
|
+
ILSP1UniversalReceiver,
|
|
21
|
+
ILSP14Ownable2Step
|
|
22
|
+
{
|
|
23
|
+
/**
|
|
24
|
+
* @dev Receives and executes a batch of function calls on this contract.
|
|
25
|
+
*/
|
|
26
|
+
function batchCalls(bytes[] calldata data) external returns (bytes[] memory results);
|
|
27
|
+
}
|
|
@@ -4,6 +4,7 @@ pragma solidity ^0.8.4;
|
|
|
4
4
|
// interfaces
|
|
5
5
|
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
6
6
|
import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
|
|
7
|
+
import {ILSP20CallVerification} from "../LSP20CallVerification/ILSP20CallVerification.sol";
|
|
7
8
|
|
|
8
9
|
// libraries
|
|
9
10
|
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
@@ -12,6 +13,7 @@ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165C
|
|
|
12
13
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
13
14
|
import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
|
|
14
15
|
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
16
|
+
import {GasLib} from "../Utils/GasLib.sol";
|
|
15
17
|
|
|
16
18
|
// modules
|
|
17
19
|
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
|
|
@@ -19,10 +21,10 @@ import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
|
|
|
19
21
|
import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
|
|
20
22
|
import {LSP14Ownable2Step} from "../LSP14Ownable2Step/LSP14Ownable2Step.sol";
|
|
21
23
|
import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol";
|
|
24
|
+
import {LSP20CallVerification} from "../LSP20CallVerification/LSP20CallVerification.sol";
|
|
22
25
|
|
|
23
26
|
// constants
|
|
24
27
|
import "@erc725/smart-contracts/contracts/constants.sol";
|
|
25
|
-
import "@erc725/smart-contracts/contracts/errors.sol";
|
|
26
28
|
import {
|
|
27
29
|
_INTERFACEID_LSP0,
|
|
28
30
|
_INTERFACEID_ERC1271,
|
|
@@ -41,6 +43,10 @@ import {_INTERFACEID_LSP14} from "../LSP14Ownable2Step/LSP14Constants.sol";
|
|
|
41
43
|
|
|
42
44
|
import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.sol";
|
|
43
45
|
|
|
46
|
+
// errors
|
|
47
|
+
import "@erc725/smart-contracts/contracts/errors.sol";
|
|
48
|
+
import "../LSP17ContractExtension/LSP17Errors.sol";
|
|
49
|
+
|
|
44
50
|
/**
|
|
45
51
|
* @title Core Implementation of ERC725Account
|
|
46
52
|
* @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
|
|
@@ -49,10 +55,11 @@ import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.
|
|
|
49
55
|
abstract contract LSP0ERC725AccountCore is
|
|
50
56
|
ERC725XCore,
|
|
51
57
|
ERC725YCore,
|
|
58
|
+
IERC1271,
|
|
59
|
+
ILSP1UniversalReceiver,
|
|
52
60
|
LSP14Ownable2Step,
|
|
53
61
|
LSP17Extendable,
|
|
54
|
-
|
|
55
|
-
ILSP1UniversalReceiver
|
|
62
|
+
LSP20CallVerification
|
|
56
63
|
{
|
|
57
64
|
using ERC165Checker for address;
|
|
58
65
|
using LSP1Utils for address;
|
|
@@ -68,36 +75,14 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
68
75
|
/**
|
|
69
76
|
* @dev Emits an event when receiving native tokens
|
|
70
77
|
*
|
|
71
|
-
* Executed
|
|
78
|
+
* Executed:
|
|
79
|
+
* - when receiving some native tokens without any additional data.
|
|
80
|
+
* - on empty calls to the contract.
|
|
72
81
|
*/
|
|
73
82
|
receive() external payable virtual {
|
|
74
83
|
if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
|
|
75
84
|
}
|
|
76
85
|
|
|
77
|
-
/**
|
|
78
|
-
* @dev Returns the extension stored under the `_LSP17_EXTENSION_PREFIX` data key
|
|
79
|
-
* mapped to the functionSelector provided.
|
|
80
|
-
*
|
|
81
|
-
* If no extension is stored, returns the address(0)
|
|
82
|
-
*/
|
|
83
|
-
function _getExtension(bytes4 functionSelector)
|
|
84
|
-
internal
|
|
85
|
-
view
|
|
86
|
-
virtual
|
|
87
|
-
override
|
|
88
|
-
returns (address)
|
|
89
|
-
{
|
|
90
|
-
bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
|
|
91
|
-
_LSP17_EXTENSION_PREFIX,
|
|
92
|
-
functionSelector
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
// Check if there is an extension for the function selector provided
|
|
96
|
-
address extension = address(bytes20(_getData(mappedExtensionDataKey)));
|
|
97
|
-
|
|
98
|
-
return extension;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
86
|
// solhint-disable no-complex-fallback
|
|
102
87
|
|
|
103
88
|
/**
|
|
@@ -111,8 +96,7 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
111
96
|
* The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
|
|
112
97
|
* Returns the return value on success and revert in case of failure.
|
|
113
98
|
*
|
|
114
|
-
* If the msg.data is shorter than 4 bytes
|
|
115
|
-
* do not check for an extension and return
|
|
99
|
+
* If the msg.data is shorter than 4 bytes do not check for an extension and return
|
|
116
100
|
*
|
|
117
101
|
* Executed when:
|
|
118
102
|
* - the first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
|
|
@@ -120,68 +104,35 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
120
104
|
*/
|
|
121
105
|
fallback() external payable virtual {
|
|
122
106
|
if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
|
|
123
|
-
if (msg.data.length < 4
|
|
107
|
+
if (msg.data.length < 4) return;
|
|
124
108
|
|
|
125
109
|
_fallbackLSP17Extendable();
|
|
126
110
|
}
|
|
127
111
|
|
|
128
112
|
/**
|
|
129
|
-
* @dev
|
|
130
|
-
* `interfaceId`.
|
|
131
|
-
*
|
|
132
|
-
* If the contract doesn't support the `interfaceId`, it forwards the call to the
|
|
133
|
-
* `supportsInterface` extension according to LSP17, and checks if the extension
|
|
134
|
-
* implements the interface defined by `interfaceId`.
|
|
135
|
-
*/
|
|
136
|
-
function supportsInterface(bytes4 interfaceId)
|
|
137
|
-
public
|
|
138
|
-
view
|
|
139
|
-
virtual
|
|
140
|
-
override(ERC725XCore, ERC725YCore, LSP17Extendable)
|
|
141
|
-
returns (bool)
|
|
142
|
-
{
|
|
143
|
-
return
|
|
144
|
-
interfaceId == _INTERFACEID_ERC1271 ||
|
|
145
|
-
interfaceId == _INTERFACEID_LSP0 ||
|
|
146
|
-
interfaceId == _INTERFACEID_LSP1 ||
|
|
147
|
-
interfaceId == _INTERFACEID_LSP14 ||
|
|
148
|
-
super.supportsInterface(interfaceId) ||
|
|
149
|
-
_supportsInterfaceInERC165Extension(interfaceId);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @notice Checks if an owner signed `_data`.
|
|
154
|
-
* ERC1271 interface.
|
|
155
|
-
*
|
|
156
|
-
* @param dataHash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
|
|
157
|
-
* @param signature owner's signature(s) of the data
|
|
113
|
+
* @dev Receives and executes a batch of function calls on this contract.
|
|
158
114
|
*/
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
115
|
+
function batchCalls(bytes[] calldata data) public returns (bytes[] memory results) {
|
|
116
|
+
results = new bytes[](data.length);
|
|
117
|
+
for (uint256 i; i < data.length; i = GasLib.uncheckedIncrement(i)) {
|
|
118
|
+
(bool success, bytes memory result) = address(this).delegatecall(data[i]);
|
|
119
|
+
|
|
120
|
+
if (!success) {
|
|
121
|
+
// Look for revert reason and bubble it up if present
|
|
122
|
+
if (result.length > 0) {
|
|
123
|
+
// The easiest way to bubble the revert reason is using memory via assembly
|
|
124
|
+
// solhint-disable no-inline-assembly
|
|
125
|
+
/// @solidity memory-safe-assembly
|
|
126
|
+
assembly {
|
|
127
|
+
let returndata_size := mload(result)
|
|
128
|
+
revert(add(32, result), returndata_size)
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
revert("LSP0: batchCalls reverted");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
176
134
|
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
// If owner is an EOA
|
|
180
|
-
else {
|
|
181
|
-
return
|
|
182
|
-
_owner == ECDSA.recover(dataHash, signature)
|
|
183
|
-
? _ERC1271_MAGICVALUE
|
|
184
|
-
: _ERC1271_FAILVALUE;
|
|
135
|
+
results[i] = result;
|
|
185
136
|
}
|
|
186
137
|
}
|
|
187
138
|
|
|
@@ -190,8 +141,10 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
190
141
|
* @param target The smart contract or address to interact with, `to` will be unused if a contract is created (operation 1 and 2)
|
|
191
142
|
* @param value The amount of native tokens to transfer (in Wei).
|
|
192
143
|
* @param data The call data, or the bytecode of the contract to deploy
|
|
193
|
-
* @dev Executes any other
|
|
194
|
-
*
|
|
144
|
+
* @dev Executes any call on other addresses.
|
|
145
|
+
*
|
|
146
|
+
* MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
147
|
+
* by LSP20 - CallVerification specification
|
|
195
148
|
*
|
|
196
149
|
* Emits a {Executed} event, when a call is executed under `operationType` 0, 3 and 4
|
|
197
150
|
* Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2
|
|
@@ -202,24 +155,113 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
202
155
|
address target,
|
|
203
156
|
uint256 value,
|
|
204
157
|
bytes memory data
|
|
205
|
-
) public payable virtual override
|
|
158
|
+
) public payable virtual override returns (bytes memory) {
|
|
206
159
|
if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
|
|
207
|
-
|
|
160
|
+
|
|
161
|
+
address _owner = owner();
|
|
162
|
+
|
|
163
|
+
if (msg.sender == _owner) return _execute(operationType, target, value, data);
|
|
164
|
+
|
|
165
|
+
// perform reverse verification if the caller is not the owner
|
|
166
|
+
bool verifyAfter = _verifyCall(_owner);
|
|
167
|
+
bytes memory result = _execute(operationType, target, value, data);
|
|
168
|
+
if (verifyAfter) _verifyCallResult(_owner, result);
|
|
169
|
+
|
|
170
|
+
return result;
|
|
208
171
|
}
|
|
209
172
|
|
|
210
173
|
/**
|
|
211
174
|
* @inheritdoc ERC725XCore
|
|
212
175
|
*
|
|
213
|
-
* @dev
|
|
176
|
+
* @dev MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
177
|
+
* by LSP20 - CallVerification specification
|
|
178
|
+
*
|
|
179
|
+
* Emits a {ValueReceived} event when receiving native tokens.
|
|
214
180
|
*/
|
|
215
181
|
function execute(
|
|
216
182
|
uint256[] memory operationsType,
|
|
217
183
|
address[] memory targets,
|
|
218
184
|
uint256[] memory values,
|
|
219
185
|
bytes[] memory datas
|
|
220
|
-
) public payable virtual override
|
|
186
|
+
) public payable virtual override returns (bytes[] memory) {
|
|
187
|
+
if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
|
|
188
|
+
|
|
189
|
+
address _owner = owner();
|
|
190
|
+
|
|
191
|
+
if (msg.sender == _owner) return _execute(operationsType, targets, values, datas);
|
|
192
|
+
|
|
193
|
+
// perform reverse verification if the caller is not the owner
|
|
194
|
+
bool verifyAfter = _verifyCall(_owner);
|
|
195
|
+
bytes[] memory results = _execute(operationsType, targets, values, datas);
|
|
196
|
+
if (verifyAfter) _verifyCallResult(_owner, abi.encode(results));
|
|
197
|
+
|
|
198
|
+
return results;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @notice Sets singular data for a given `dataKey`
|
|
203
|
+
* @param dataKey The key to retrieve stored value
|
|
204
|
+
* @param dataValue The value to set
|
|
205
|
+
*
|
|
206
|
+
* MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
207
|
+
* by LSP20 - CallVerification specification
|
|
208
|
+
*
|
|
209
|
+
* Emits a {DataChanged} event.
|
|
210
|
+
*/
|
|
211
|
+
function setData(bytes32 dataKey, bytes memory dataValue) public payable virtual override {
|
|
212
|
+
if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
|
|
213
|
+
address _owner = owner();
|
|
214
|
+
|
|
215
|
+
if (msg.sender == _owner) return _setData(dataKey, dataValue);
|
|
216
|
+
|
|
217
|
+
// perform reverse verification if the caller is not the owner
|
|
218
|
+
bool verifyAfter = _verifyCall(_owner);
|
|
219
|
+
_setData(dataKey, dataValue);
|
|
220
|
+
|
|
221
|
+
// The setData function does not return, second parameter of {_verifyCallResult} will be empty
|
|
222
|
+
if (verifyAfter) _verifyCallResult(_owner, "");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @param dataKeys The array of data keys for values to set
|
|
227
|
+
* @param dataValues The array of values to set
|
|
228
|
+
* @dev Sets array of data for multiple given `dataKeys`
|
|
229
|
+
*
|
|
230
|
+
* MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
231
|
+
* by LSP20 - CallVerification specification
|
|
232
|
+
*
|
|
233
|
+
* Emits a {DataChanged} event.
|
|
234
|
+
*/
|
|
235
|
+
function setData(bytes32[] memory dataKeys, bytes[] memory dataValues)
|
|
236
|
+
public
|
|
237
|
+
payable
|
|
238
|
+
virtual
|
|
239
|
+
override
|
|
240
|
+
{
|
|
221
241
|
if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
|
|
222
|
-
|
|
242
|
+
|
|
243
|
+
if (dataKeys.length != dataValues.length) {
|
|
244
|
+
revert ERC725Y_DataKeysValuesLengthMismatch(dataKeys.length, dataValues.length);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
address _owner = owner();
|
|
248
|
+
|
|
249
|
+
if (msg.sender == _owner) {
|
|
250
|
+
for (uint256 i = 0; i < dataKeys.length; i = _uncheckedIncrementERC725Y(i)) {
|
|
251
|
+
_setData(dataKeys[i], dataValues[i]);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// perform reverse verification if the caller is not the owner
|
|
258
|
+
bool verifyAfter = _verifyCall(_owner);
|
|
259
|
+
for (uint256 i = 0; i < dataKeys.length; i = _uncheckedIncrementERC725Y(i)) {
|
|
260
|
+
_setData(dataKeys[i], dataValues[i]);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// The setData function does not return, second parameter of {_verifyCallResult} will be empty
|
|
264
|
+
if (verifyAfter) _verifyCallResult(_owner, "");
|
|
223
265
|
}
|
|
224
266
|
|
|
225
267
|
/**
|
|
@@ -283,90 +325,256 @@ abstract contract LSP0ERC725AccountCore is
|
|
|
283
325
|
}
|
|
284
326
|
|
|
285
327
|
/**
|
|
286
|
-
* @
|
|
328
|
+
* @inheritdoc LSP14Ownable2Step
|
|
329
|
+
*
|
|
330
|
+
* @dev same as ILSP14.transferOwnership with the additional requirement:
|
|
331
|
+
* Requirements:
|
|
332
|
+
*
|
|
333
|
+
* - MUST pass when called by the owner or by an authorised address that pass the verification check performed
|
|
334
|
+
* by LSP20 - CallVerification specification
|
|
287
335
|
*
|
|
288
|
-
*
|
|
336
|
+
* - When notifying the new owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferStarted')
|
|
289
337
|
*/
|
|
290
|
-
function transferOwnership(address
|
|
338
|
+
function transferOwnership(address newOwner)
|
|
291
339
|
public
|
|
292
340
|
virtual
|
|
293
341
|
override(LSP14Ownable2Step, OwnableUnset)
|
|
294
|
-
onlyOwner
|
|
295
342
|
{
|
|
296
|
-
|
|
343
|
+
address currentOwner = owner();
|
|
344
|
+
|
|
345
|
+
if (msg.sender == currentOwner) {
|
|
346
|
+
// set the pending owner
|
|
347
|
+
LSP14Ownable2Step._transferOwnership(newOwner);
|
|
348
|
+
emit OwnershipTransferStarted(currentOwner, newOwner);
|
|
349
|
+
|
|
350
|
+
// notify the pending owner through LSP1
|
|
351
|
+
newOwner.tryNotifyUniversalReceiver(_TYPEID_LSP0_OwnershipTransferStarted, "");
|
|
352
|
+
|
|
353
|
+
// Require that the owner didn't change after the LSP1 Call
|
|
354
|
+
// (Pending owner didn't automate the acceptOwnership call through LSP1)
|
|
355
|
+
require(
|
|
356
|
+
currentOwner == owner(),
|
|
357
|
+
"LSP14: newOwner MUST accept ownership in a separate transaction"
|
|
358
|
+
);
|
|
359
|
+
} else {
|
|
360
|
+
// If the caller is not the owner, do verification on the owner
|
|
361
|
+
bool verifyAfter = _verifyCall(currentOwner);
|
|
362
|
+
|
|
363
|
+
// Set the pending owner if the call is allowed
|
|
364
|
+
LSP14Ownable2Step._transferOwnership(newOwner);
|
|
365
|
+
emit OwnershipTransferStarted(currentOwner, newOwner);
|
|
366
|
+
|
|
367
|
+
// notify the pending owner through LSP1
|
|
368
|
+
newOwner.tryNotifyUniversalReceiver(_TYPEID_LSP0_OwnershipTransferStarted, "");
|
|
369
|
+
|
|
370
|
+
// Require that the owner didn't change after the LSP1 Call
|
|
371
|
+
// (Pending owner didn't automate the acceptOwnership call through LSP1)
|
|
372
|
+
require(
|
|
373
|
+
currentOwner == owner(),
|
|
374
|
+
"LSP14: newOwner MUST accept ownership in a separate transaction"
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
// The transferOwnership function does not return, second parameter of {_verifyCallResult} will be empty
|
|
378
|
+
if (verifyAfter) _verifyCallResult(currentOwner, "");
|
|
379
|
+
}
|
|
297
380
|
}
|
|
298
381
|
|
|
299
382
|
/**
|
|
300
|
-
* @
|
|
383
|
+
* @inheritdoc LSP14Ownable2Step
|
|
384
|
+
*
|
|
385
|
+
* @dev same as ILSP14.acceptOwnership with the additional requirement:
|
|
386
|
+
*
|
|
387
|
+
* Requirements:
|
|
388
|
+
* - when notifying the previous owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferred_SenderNotification')
|
|
389
|
+
* - when notifying the new owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferred_RecipientNotification')
|
|
301
390
|
*/
|
|
302
|
-
function
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
391
|
+
function acceptOwnership() public virtual override {
|
|
392
|
+
address previousOwner = owner();
|
|
393
|
+
|
|
394
|
+
_acceptOwnership();
|
|
395
|
+
|
|
396
|
+
previousOwner.tryNotifyUniversalReceiver(
|
|
397
|
+
_TYPEID_LSP0_OwnershipTransferred_SenderNotification,
|
|
398
|
+
""
|
|
399
|
+
);
|
|
400
|
+
|
|
401
|
+
msg.sender.tryNotifyUniversalReceiver(
|
|
402
|
+
_TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
|
|
403
|
+
""
|
|
404
|
+
);
|
|
309
405
|
}
|
|
310
406
|
|
|
311
407
|
/**
|
|
312
|
-
* @
|
|
408
|
+
* @inheritdoc LSP14Ownable2Step
|
|
409
|
+
*
|
|
410
|
+
* @dev MUST pass when called by the owner or by an authorised address that pass the verification
|
|
411
|
+
* check performed by LSP20 - CallVerification specification
|
|
313
412
|
*/
|
|
314
|
-
function
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
);
|
|
413
|
+
function renounceOwnership() public virtual override(LSP14Ownable2Step, OwnableUnset) {
|
|
414
|
+
address _owner = owner();
|
|
415
|
+
|
|
416
|
+
if (msg.sender == _owner) return LSP14Ownable2Step._renounceOwnership();
|
|
417
|
+
|
|
418
|
+
bool verifyAfter = _verifyCall(_owner);
|
|
419
|
+
LSP14Ownable2Step._renounceOwnership();
|
|
420
|
+
|
|
421
|
+
// The renounceOwnership function does not return, second parameter of {_verifyCallResult} will be empty
|
|
422
|
+
if (verifyAfter) _verifyCallResult(_owner, "");
|
|
320
423
|
}
|
|
321
424
|
|
|
322
|
-
|
|
425
|
+
/**
|
|
426
|
+
* @dev Returns true if this contract implements the interface defined by
|
|
427
|
+
* `interfaceId`.
|
|
428
|
+
*
|
|
429
|
+
* If the contract doesn't support the `interfaceId`, it forwards the call to the
|
|
430
|
+
* `supportsInterface` extension according to LSP17, and checks if the extension
|
|
431
|
+
* implements the interface defined by `interfaceId`.
|
|
432
|
+
*/
|
|
433
|
+
function supportsInterface(bytes4 interfaceId)
|
|
434
|
+
public
|
|
435
|
+
view
|
|
436
|
+
virtual
|
|
437
|
+
override(ERC725XCore, ERC725YCore, LSP17Extendable)
|
|
438
|
+
returns (bool)
|
|
439
|
+
{
|
|
440
|
+
return
|
|
441
|
+
interfaceId == _INTERFACEID_ERC1271 ||
|
|
442
|
+
interfaceId == _INTERFACEID_LSP0 ||
|
|
443
|
+
interfaceId == _INTERFACEID_LSP1 ||
|
|
444
|
+
interfaceId == _INTERFACEID_LSP14 ||
|
|
445
|
+
super.supportsInterface(interfaceId) ||
|
|
446
|
+
_supportsInterfaceInERC165Extension(interfaceId);
|
|
447
|
+
}
|
|
323
448
|
|
|
324
449
|
/**
|
|
325
|
-
* @
|
|
326
|
-
*
|
|
450
|
+
* @notice Checks if an owner signed `_data`.
|
|
451
|
+
* ERC1271 interface.
|
|
452
|
+
*
|
|
453
|
+
* @param dataHash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
|
|
454
|
+
* @param signature owner's signature(s) of the data
|
|
327
455
|
*/
|
|
328
|
-
function
|
|
329
|
-
|
|
456
|
+
function isValidSignature(bytes32 dataHash, bytes memory signature)
|
|
457
|
+
public
|
|
458
|
+
view
|
|
330
459
|
virtual
|
|
331
|
-
|
|
460
|
+
returns (bytes4 magicValue)
|
|
332
461
|
{
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
462
|
+
address _owner = owner();
|
|
463
|
+
|
|
464
|
+
// If owner is a contract
|
|
465
|
+
if (_owner.code.length > 0) {
|
|
466
|
+
(bool success, bytes memory result) = _owner.staticcall(
|
|
467
|
+
abi.encodeWithSelector(IERC1271.isValidSignature.selector, dataHash, signature)
|
|
337
468
|
);
|
|
469
|
+
|
|
470
|
+
bool isValid = (success &&
|
|
471
|
+
result.length == 32 &&
|
|
472
|
+
abi.decode(result, (bytes32)) == bytes32(_ERC1271_MAGICVALUE));
|
|
473
|
+
|
|
474
|
+
return isValid ? _ERC1271_MAGICVALUE : _ERC1271_FAILVALUE;
|
|
475
|
+
}
|
|
476
|
+
// If owner is an EOA
|
|
477
|
+
else {
|
|
478
|
+
return
|
|
479
|
+
_owner == ECDSA.recover(dataHash, signature)
|
|
480
|
+
? _ERC1271_MAGICVALUE
|
|
481
|
+
: _ERC1271_FAILVALUE;
|
|
338
482
|
}
|
|
339
483
|
}
|
|
340
484
|
|
|
485
|
+
// Internal functions
|
|
486
|
+
|
|
487
|
+
// Fallback
|
|
488
|
+
|
|
341
489
|
/**
|
|
342
|
-
* @dev
|
|
343
|
-
*
|
|
490
|
+
* @dev Forwards the call to an extension mapped to a function selector. If no extension address
|
|
491
|
+
* is mapped to the function selector (address(0)), then revert.
|
|
492
|
+
*
|
|
493
|
+
* The bytes4(0) msg.sig is an exception, the function won't revert if there is no extension found
|
|
494
|
+
* mapped to bytes4(0), but will execute the call to the extension in case it existed.
|
|
495
|
+
*
|
|
496
|
+
* The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
|
|
497
|
+
* Returns the return value on success and revert in case of failure.
|
|
498
|
+
*
|
|
499
|
+
* Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
|
|
500
|
+
* called before other codes in fallback().
|
|
501
|
+
*
|
|
502
|
+
* Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
|
|
344
503
|
*/
|
|
345
|
-
function
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
504
|
+
function _fallbackLSP17Extendable() internal virtual override {
|
|
505
|
+
// If there is a function selector
|
|
506
|
+
address extension = _getExtension(msg.sig);
|
|
507
|
+
|
|
508
|
+
// if no extension was found for bytes4(0) return don't revert
|
|
509
|
+
if (msg.sig == bytes4(0) && extension == address(0)) return;
|
|
510
|
+
|
|
511
|
+
// if no extension was found, revert
|
|
512
|
+
if (extension == address(0)) revert NoExtensionFoundForFunctionSelector(msg.sig);
|
|
513
|
+
|
|
514
|
+
// solhint-disable no-inline-assembly
|
|
515
|
+
// if the extension was found, call the extension with the msg.data
|
|
516
|
+
// appended with bytes20(address) and bytes32(msg.value)
|
|
517
|
+
assembly {
|
|
518
|
+
calldatacopy(0, 0, calldatasize())
|
|
519
|
+
|
|
520
|
+
// The msg.sender address is shifted to the left by 12 bytes to remove the padding
|
|
521
|
+
// Then the address without padding is stored right after the calldata
|
|
522
|
+
mstore(calldatasize(), shl(96, caller()))
|
|
523
|
+
|
|
524
|
+
// The msg.value is stored right after the calldata + msg.sender
|
|
525
|
+
mstore(add(calldatasize(), 20), callvalue())
|
|
526
|
+
|
|
527
|
+
// Add 52 bytes for the msg.sender and msg.value appended at the end of the calldata
|
|
528
|
+
let success := call(gas(), extension, 0, 0, add(calldatasize(), 52), 0, 0)
|
|
529
|
+
|
|
530
|
+
// Copy the returned data
|
|
531
|
+
returndatacopy(0, 0, returndatasize())
|
|
532
|
+
|
|
533
|
+
switch success
|
|
534
|
+
// call returns 0 on failed calls
|
|
535
|
+
case 0 {
|
|
536
|
+
revert(0, returndatasize())
|
|
537
|
+
}
|
|
538
|
+
default {
|
|
539
|
+
return(0, returndatasize())
|
|
540
|
+
}
|
|
354
541
|
}
|
|
355
542
|
}
|
|
356
543
|
|
|
357
544
|
/**
|
|
358
|
-
* @dev
|
|
359
|
-
*
|
|
545
|
+
* @dev Returns the extension stored under the `_LSP17_EXTENSION_PREFIX` data key
|
|
546
|
+
* mapped to the functionSelector provided.
|
|
547
|
+
*
|
|
548
|
+
* If no extension is stored, returns the address(0)
|
|
549
|
+
*/
|
|
550
|
+
function _getExtension(bytes4 functionSelector)
|
|
551
|
+
internal
|
|
552
|
+
view
|
|
553
|
+
virtual
|
|
554
|
+
override
|
|
555
|
+
returns (address)
|
|
556
|
+
{
|
|
557
|
+
bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
|
|
558
|
+
_LSP17_EXTENSION_PREFIX,
|
|
559
|
+
functionSelector
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
// Check if there is an extension for the function selector provided
|
|
563
|
+
address extension = address(bytes20(_getData(mappedExtensionDataKey)));
|
|
564
|
+
|
|
565
|
+
return extension;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ERC725Y
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
|
|
360
572
|
*/
|
|
361
|
-
function
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
_TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
|
|
368
|
-
data
|
|
369
|
-
);
|
|
370
|
-
}
|
|
573
|
+
function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
|
|
574
|
+
_store[dataKey] = dataValue;
|
|
575
|
+
emit DataChanged(
|
|
576
|
+
dataKey,
|
|
577
|
+
dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
|
|
578
|
+
);
|
|
371
579
|
}
|
|
372
580
|
}
|
|
@@ -11,7 +11,7 @@ import {LSP0ERC725AccountInitAbstract} from "./LSP0ERC725AccountInitAbstract.sol
|
|
|
11
11
|
*/
|
|
12
12
|
contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
|
|
13
13
|
/**
|
|
14
|
-
* @dev
|
|
14
|
+
* @dev initialize (= lock) base implementation contract on deployment
|
|
15
15
|
*/
|
|
16
16
|
constructor() {
|
|
17
17
|
_disableInitializers();
|