@lukso/lsp-smart-contracts 0.7.0 → 0.8.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/CONTRIBUTING.md +39 -0
- package/README.md +93 -40
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +194 -15
- package/artifacts/LSP0ERC725AccountInit.json +194 -15
- package/artifacts/LSP11BasicSocialRecovery.json +493 -0
- package/artifacts/LSP11BasicSocialRecoveryInit.json +513 -0
- package/artifacts/LSP16UniversalFactory.json +236 -0
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +134 -15
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +80 -15
- package/artifacts/LSP4Compatibility.json +16 -0
- package/artifacts/LSP4DigitalAssetMetadata.json +16 -0
- package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +16 -0
- package/artifacts/LSP6KeyManager.json +177 -33
- package/artifacts/LSP6KeyManagerInit.json +177 -33
- package/artifacts/LSP7CappedSupply.json +26 -5
- package/artifacts/LSP7CappedSupplyInitAbstract.json +26 -5
- package/artifacts/LSP7CompatibleERC20.json +26 -5
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +28 -7
- package/artifacts/LSP7CompatibleERC20Mintable.json +29 -8
- package/artifacts/LSP7CompatibleERC20MintableInit.json +29 -8
- package/artifacts/LSP7DigitalAsset.json +26 -5
- package/artifacts/LSP7DigitalAssetInitAbstract.json +26 -5
- package/artifacts/LSP7Mintable.json +29 -8
- package/artifacts/LSP7MintableInit.json +29 -8
- package/artifacts/LSP8CappedSupply.json +27 -6
- package/artifacts/LSP8CappedSupplyInitAbstract.json +27 -6
- package/artifacts/LSP8CompatibleERC721.json +28 -7
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +30 -9
- package/artifacts/LSP8CompatibleERC721Mintable.json +31 -10
- package/artifacts/LSP8CompatibleERC721MintableInit.json +31 -10
- package/artifacts/LSP8IdentifiableDigitalAsset.json +27 -6
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +27 -6
- package/artifacts/LSP8Mintable.json +30 -9
- package/artifacts/LSP8MintableInit.json +30 -9
- package/artifacts/LSP9Vault.json +202 -17
- package/artifacts/LSP9VaultInit.json +202 -17
- package/artifacts/UniversalProfile.json +194 -15
- package/artifacts/UniversalProfileInit.json +194 -15
- package/artifacts/UniversalReceiverAddressStore.json +3 -3
- package/common/constants.d.ts +738 -0
- package/common/constants.js +785 -0
- package/contracts/Custom/EIP191Signer.sol +12 -0
- package/contracts/Factories/Create2Factory.sol +1 -3
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +13 -2
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +2 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +320 -63
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +2 -2
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +2 -1
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +50 -0
- package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +212 -0
- package/contracts/LSP11BasicSocialRecovery/ILSP11BasicSocialRecovery.sol +177 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol +23 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +258 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +26 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInitAbstract.sol +19 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11Constants.sol +6 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +60 -0
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +53 -0
- package/contracts/LSP14Ownable2Step/LSP14Constants.sol +15 -0
- package/contracts/LSP14Ownable2Step/LSP14Errors.sol +12 -0
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +212 -0
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +246 -0
- package/contracts/LSP17ContractExtension/LSP17Constants.sol +17 -0
- package/contracts/LSP17ContractExtension/LSP17Errors.sol +7 -0
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +104 -0
- package/contracts/LSP17ContractExtension/LSP17Extension.sol +45 -0
- package/contracts/LSP17ContractExtension/LSP17Utils.sol +20 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +5 -5
- package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +5 -3
- package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +21 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +155 -37
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +64 -31
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +53 -40
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +45 -23
- package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +2 -2
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +2 -2
- package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +3 -3
- package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +102 -114
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +25 -7
- package/contracts/LSP6KeyManager/LSP6Constants.sol +43 -38
- package/contracts/LSP6KeyManager/LSP6Errors.sol +90 -21
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +2 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +224 -506
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +3 -2
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +229 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +25 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +606 -0
- package/contracts/LSP6KeyManager/LSP6Utils.sol +156 -35
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +8 -8
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +6 -6
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +1 -1
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +36 -36
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +1 -1
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +33 -1
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +24 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +28 -8
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +28 -11
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +87 -20
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +97 -19
- package/contracts/LSP7DigitalAsset/presets/ILSP7Mintable.sol +3 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +3 -4
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +2 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +3 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +3 -5
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +2 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +7 -7
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +7 -7
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +45 -2
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +2 -2
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +57 -60
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +5 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +20 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +27 -7
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +27 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +234 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +238 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +32 -4
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +35 -8
- package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +3 -4
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +3 -4
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +2 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +3 -3
- package/contracts/LSP9Vault/LSP9Constants.sol +10 -10
- package/contracts/LSP9Vault/LSP9Errors.sol +8 -0
- package/contracts/LSP9Vault/LSP9Vault.sol +6 -4
- package/contracts/LSP9Vault/LSP9VaultCore.sol +350 -127
- package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -2
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +4 -3
- package/contracts/Legacy/Registries/AddressRegistry.sol +1 -1
- package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +1 -1
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +4 -14
- package/contracts/UniversalProfile.sol +2 -2
- package/contracts/UniversalProfileInit.sol +2 -2
- package/contracts/UniversalProfileInitAbstract.sol +1 -1
- package/contracts/Utils/GasLib.sol +1 -1
- package/module/constants.d.ts +738 -0
- package/module/constants.js +782 -0
- package/package.json +42 -12
- package/artifacts/UniversalFactory.json +0 -127
- package/constants.js +0 -594
- package/contracts/Custom/ClaimOwnership.sol +0 -96
- package/contracts/Custom/ERC165Checker.sol +0 -130
- package/contracts/Custom/IClaimOwnership.sol +0 -12
- package/contracts/Factories/UniversalFactory.sol +0 -159
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +0 -24
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +0 -82
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +0 -73
- package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +0 -9
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +0 -17
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +0 -57
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +0 -111
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +0 -17
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +0 -17
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +0 -58
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleConstants.sol +0 -6
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +0 -211
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +0 -50
- package/contracts/Utils/UtilsLib.sol +0 -31
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
9
|
+
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
10
|
+
|
|
11
|
+
// constants
|
|
12
|
+
import "../LSP10ReceivedVaults/LSP10Constants.sol";
|
|
13
|
+
import "../LSP9Vault/LSP9Constants.sol";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @dev reverts when the value stored under the 'LSP10ReceivedVaults[]' data key is not valid.
|
|
17
|
+
* The value stored under this data key should be exactly 32 bytes long.
|
|
18
|
+
*
|
|
19
|
+
* Only possible valid values are:
|
|
20
|
+
* - any valid uint256 values
|
|
21
|
+
* i.e. 0x0000000000000000000000000000000000000000000000000000000000000000 (zero), meaning empty array, no vaults received.
|
|
22
|
+
* i.e. 0x0000000000000000000000000000000000000000000000000000000000000005 (non-zero), meaning 5 array elements, 5 vaults received.
|
|
23
|
+
*
|
|
24
|
+
* - 0x (nothing stored under this data key, equivalent to empty array)
|
|
25
|
+
*
|
|
26
|
+
* @param invalidValue the invalid value stored under the LSP10ReceivedVaults[] data key
|
|
27
|
+
* @param invalidValueLength the invalid number of bytes stored under the LSP10ReceivedVaults[] data key (MUST be 32)
|
|
28
|
+
*/
|
|
29
|
+
error InvalidLSP10ReceivedVaultsArrayLength(bytes invalidValue, uint256 invalidValueLength);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @dev reverts when the vault index is superior to uint64
|
|
33
|
+
* @param index the vault index
|
|
34
|
+
*/
|
|
35
|
+
error VaultIndexSuperiorToUint64(uint256 index);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @dev reverts when the vault index is superior to uint128
|
|
39
|
+
* @param index the vault index
|
|
40
|
+
*/
|
|
41
|
+
error VaultIndexSuperiorToUint128(uint256 index);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @title LSP10Utils
|
|
45
|
+
* @author Yamen Merhi <YamenMerhi>, Jean Cavallera <CJ42>
|
|
46
|
+
* @dev LSP5Utils is a library of functions that are used to register and manage vaults received by an ERC725Y smart contract
|
|
47
|
+
* based on the LSP10 - Received Vaults standard
|
|
48
|
+
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-10-ReceivedVaults.md
|
|
49
|
+
*/
|
|
50
|
+
library LSP10Utils {
|
|
51
|
+
/**
|
|
52
|
+
* @dev Generating the data keys/values to be set on the receiver address after receiving vaults
|
|
53
|
+
* @param receiver The address receiving the vault and where the Keys should be added
|
|
54
|
+
* @param vault The address of the vault being received
|
|
55
|
+
* @param vaultMapKey The map key of the vault being received containing the interfaceId of the
|
|
56
|
+
* vault and the index in the array
|
|
57
|
+
*/
|
|
58
|
+
function generateReceivedVaultKeys(
|
|
59
|
+
address receiver,
|
|
60
|
+
address vault,
|
|
61
|
+
bytes32 vaultMapKey
|
|
62
|
+
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
63
|
+
keys = new bytes32[](3);
|
|
64
|
+
values = new bytes[](3);
|
|
65
|
+
|
|
66
|
+
IERC725Y account = IERC725Y(receiver);
|
|
67
|
+
bytes memory encodedArrayLength = getLSP10ReceivedVaultsCount(account);
|
|
68
|
+
|
|
69
|
+
// If it's the first vault to receive
|
|
70
|
+
if (encodedArrayLength.length == 0) {
|
|
71
|
+
keys[0] = _LSP10_VAULTS_ARRAY_KEY;
|
|
72
|
+
values[0] = bytes.concat(bytes32(uint256(1)));
|
|
73
|
+
|
|
74
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(_LSP10_VAULTS_ARRAY_KEY, 0);
|
|
75
|
+
values[1] = bytes.concat(bytes20(vault));
|
|
76
|
+
|
|
77
|
+
keys[2] = vaultMapKey;
|
|
78
|
+
values[2] = bytes.concat(_INTERFACEID_LSP9, bytes8(0));
|
|
79
|
+
|
|
80
|
+
// If the storage is already initiated
|
|
81
|
+
} else if (encodedArrayLength.length == 32) {
|
|
82
|
+
uint256 oldArrayLength = uint256(bytes32(encodedArrayLength));
|
|
83
|
+
uint256 newArrayLength = oldArrayLength + 1;
|
|
84
|
+
|
|
85
|
+
if (newArrayLength > type(uint64).max) {
|
|
86
|
+
revert VaultIndexSuperiorToUint64(newArrayLength);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
keys[0] = _LSP10_VAULTS_ARRAY_KEY;
|
|
90
|
+
values[0] = bytes.concat(bytes32(newArrayLength));
|
|
91
|
+
|
|
92
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
93
|
+
_LSP10_VAULTS_ARRAY_KEY,
|
|
94
|
+
uint128(oldArrayLength)
|
|
95
|
+
);
|
|
96
|
+
values[1] = bytes.concat(bytes20(vault));
|
|
97
|
+
|
|
98
|
+
keys[2] = vaultMapKey;
|
|
99
|
+
values[2] = bytes.concat(_INTERFACEID_LSP9, bytes8(uint64(oldArrayLength)));
|
|
100
|
+
} else {
|
|
101
|
+
revert InvalidLSP10ReceivedVaultsArrayLength(
|
|
102
|
+
encodedArrayLength,
|
|
103
|
+
encodedArrayLength.length
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @dev Generating the data keys/values to be set on the sender address after sending vaults
|
|
110
|
+
* @param sender The address sending the vault and where the Keys should be updated
|
|
111
|
+
* @param vaultMapKey The map key of the vault being sent containing the interfaceId of the
|
|
112
|
+
* vault and the index in the array
|
|
113
|
+
* @param vaultInterfaceIdAndIndex The value of the map key of the vault being sent
|
|
114
|
+
*/
|
|
115
|
+
function generateSentVaultKeys(
|
|
116
|
+
address sender,
|
|
117
|
+
bytes32 vaultMapKey,
|
|
118
|
+
bytes memory vaultInterfaceIdAndIndex
|
|
119
|
+
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
120
|
+
IERC725Y account = IERC725Y(sender);
|
|
121
|
+
|
|
122
|
+
// Updating the number of the received vaults
|
|
123
|
+
uint256 oldArrayLength = uint256(bytes32(account.getData(_LSP10_VAULTS_ARRAY_KEY)));
|
|
124
|
+
|
|
125
|
+
if (oldArrayLength > type(uint128).max) {
|
|
126
|
+
revert VaultIndexSuperiorToUint128(oldArrayLength);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
uint128 newArrayLength = uint128(oldArrayLength) - 1;
|
|
130
|
+
|
|
131
|
+
uint64 index = extractIndexFromMap(vaultInterfaceIdAndIndex);
|
|
132
|
+
bytes32 vaultInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
133
|
+
_LSP10_VAULTS_ARRAY_KEY,
|
|
134
|
+
index
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
if (index == newArrayLength) {
|
|
138
|
+
/**
|
|
139
|
+
* We will be updating/removing 3 keys:
|
|
140
|
+
* - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received vaults
|
|
141
|
+
* - Keys[1]: [Remove] The element in arrayKey (Remove the address of the vault sent)
|
|
142
|
+
* - Keys[2]: [Remove] The mapKey (Remove the interfaceId and the index of the vault sent)
|
|
143
|
+
*/
|
|
144
|
+
keys = new bytes32[](3);
|
|
145
|
+
values = new bytes[](3);
|
|
146
|
+
|
|
147
|
+
keys[0] = _LSP10_VAULTS_ARRAY_KEY;
|
|
148
|
+
values[0] = bytes.concat(bytes32(oldArrayLength - 1));
|
|
149
|
+
|
|
150
|
+
keys[1] = vaultInArrayKey;
|
|
151
|
+
values[1] = "";
|
|
152
|
+
|
|
153
|
+
keys[2] = vaultMapKey;
|
|
154
|
+
values[2] = "";
|
|
155
|
+
|
|
156
|
+
// Swapping last element in ArrayKey with the element in ArrayKey to remove || {Swap and pop} method;
|
|
157
|
+
// check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
|
|
158
|
+
} else {
|
|
159
|
+
/**
|
|
160
|
+
* We will be updating/removing 5 keys:
|
|
161
|
+
* - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received vaults
|
|
162
|
+
* - Keys[1]: [Remove] The mapKey of the vault to remove (Remove the interfaceId and the index of the vault sent)
|
|
163
|
+
* - Keys[2]: [Update] The element in arrayKey to remove (Swap with the address of the last element in Array)
|
|
164
|
+
* - Keys[3]: [Remove] The last element in arrayKey (Remove (pop) the address of the last element as it's already swapped)
|
|
165
|
+
* - Keys[4]: [Update] The mapKey of the last element in array (Update the new index and the interfaceID)
|
|
166
|
+
*/
|
|
167
|
+
keys = new bytes32[](5);
|
|
168
|
+
values = new bytes[](5);
|
|
169
|
+
|
|
170
|
+
keys[0] = _LSP10_VAULTS_ARRAY_KEY;
|
|
171
|
+
values[0] = bytes.concat(bytes32(oldArrayLength - 1));
|
|
172
|
+
|
|
173
|
+
keys[1] = vaultMapKey;
|
|
174
|
+
values[1] = "";
|
|
175
|
+
|
|
176
|
+
// Generate all data Keys/values of the last element in Array to swap
|
|
177
|
+
// with data Keys/values of the vault to remove
|
|
178
|
+
bytes32 lastVaultInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
179
|
+
_LSP10_VAULTS_ARRAY_KEY,
|
|
180
|
+
newArrayLength
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
bytes20 lastVaultInArrayAddress = bytes20(account.getData(lastVaultInArrayKey));
|
|
184
|
+
|
|
185
|
+
bytes32 lastVaultInArrayMapKey = LSP2Utils.generateMappingKey(
|
|
186
|
+
_LSP10_VAULTS_MAP_KEY_PREFIX,
|
|
187
|
+
lastVaultInArrayAddress
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
keys[2] = vaultInArrayKey;
|
|
191
|
+
values[2] = bytes.concat(lastVaultInArrayAddress);
|
|
192
|
+
|
|
193
|
+
keys[3] = lastVaultInArrayKey;
|
|
194
|
+
values[3] = "";
|
|
195
|
+
|
|
196
|
+
keys[4] = lastVaultInArrayMapKey;
|
|
197
|
+
values[4] = bytes.concat(_INTERFACEID_LSP9, bytes8(index));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function getLSP10ReceivedVaultsCount(IERC725Y account) internal view returns (bytes memory) {
|
|
202
|
+
return account.getData(_LSP10_VAULTS_ARRAY_KEY);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @dev returns the index from a maping
|
|
207
|
+
*/
|
|
208
|
+
function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint64) {
|
|
209
|
+
bytes memory val = BytesLib.slice(mapValue, 4, 8);
|
|
210
|
+
return BytesLib.toUint64(val, 0);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title interface of the LSP11 - Basic Social Recovery standard
|
|
6
|
+
* @dev Sets permission for a controller address after a recovery process to interact with an ERC725
|
|
7
|
+
* contract via the LSP6KeyManager
|
|
8
|
+
*/
|
|
9
|
+
interface ILSP11BasicSocialRecovery {
|
|
10
|
+
/**
|
|
11
|
+
* @notice Emitted when setting a new guardian for the target
|
|
12
|
+
* @param newGuardian The address of the added guardian
|
|
13
|
+
*/
|
|
14
|
+
event GuardianAdded(address indexed newGuardian);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @notice Emitted when removing an existing guardian for the target
|
|
18
|
+
* @param removedGuardian The address of the guardian removed
|
|
19
|
+
*/
|
|
20
|
+
event GuardianRemoved(address indexed removedGuardian);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @notice Emitted when changing the guardian threshold
|
|
24
|
+
* @param guardianThreshold The minimum number of selection by guardians needed by a controller to start
|
|
25
|
+
* a recovery process
|
|
26
|
+
*/
|
|
27
|
+
event GuardiansThresholdChanged(uint256 indexed guardianThreshold);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @notice Emitted when changing the secret hash
|
|
31
|
+
* @param secretHash The secret hash used to finish the recovery process
|
|
32
|
+
*/
|
|
33
|
+
event SecretHashChanged(bytes32 indexed secretHash);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @notice Emitted when a guardian select a new potentiel controller address for the target
|
|
37
|
+
* @param recoveryCounter The current recovery process counter
|
|
38
|
+
* @param guardian The address of the guardian
|
|
39
|
+
* @param addressSelected The address selected by the guardian
|
|
40
|
+
*/
|
|
41
|
+
event SelectedNewController(
|
|
42
|
+
uint256 indexed recoveryCounter,
|
|
43
|
+
address indexed guardian,
|
|
44
|
+
address indexed addressSelected
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @notice Emitted when the recovery process is finished by the controller who
|
|
49
|
+
* reached the guardian threshold and submitted the string that produce the secretHash
|
|
50
|
+
* @param recoveryCounter The current recovery process
|
|
51
|
+
* @param newController The address of the new controller controlling the target by the KeyManager
|
|
52
|
+
* @param guardians The array of addresses containing the guardians of the target
|
|
53
|
+
*/
|
|
54
|
+
event RecoveryProcessSuccessful(
|
|
55
|
+
uint256 indexed recoveryCounter,
|
|
56
|
+
address indexed newController,
|
|
57
|
+
bytes32 indexed newSecretHash,
|
|
58
|
+
address[] guardians
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @dev The address of an ERC725 contract where we want to recover
|
|
63
|
+
* and set permissions for a controller address
|
|
64
|
+
*/
|
|
65
|
+
function target() external view returns (address);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @dev Returns the current recovery counter
|
|
69
|
+
* When a recovery process is successfully finished the recovery counter is incremented
|
|
70
|
+
*/
|
|
71
|
+
function getRecoveryCounter() external view returns (uint256);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @dev Returns the addresses of all guardians
|
|
75
|
+
* The guardians will select an address to be added as a controller
|
|
76
|
+
* key for the linked `target` if he reaches the guardian threshold and
|
|
77
|
+
* provide the correct string that produce the secretHash
|
|
78
|
+
*/
|
|
79
|
+
function getGuardians() external view returns (address[] memory);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @dev Returns TRUE if the address provided is a guardian, FALSE otherwise
|
|
83
|
+
* @param _address The address to query
|
|
84
|
+
*/
|
|
85
|
+
function isGuardian(address _address) external view returns (bool);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @dev Returns the recovery secret hash
|
|
89
|
+
*/
|
|
90
|
+
function getRecoverySecretHash() external view returns (bytes32);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @dev Returns the guardian threshold
|
|
94
|
+
* The guardian threshold represents the minimum number of selection by guardians required
|
|
95
|
+
* for an address to start a recovery process
|
|
96
|
+
*/
|
|
97
|
+
function getGuardiansThreshold() external view returns (uint256);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @dev Returns the address of a controller that a `guardian` selected for in order to recover the target
|
|
101
|
+
* @param guardian the address of a guardian to query his selection
|
|
102
|
+
* @return the address that `guardian` selected
|
|
103
|
+
*/
|
|
104
|
+
function getGuardianChoice(address guardian) external view returns (address);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @dev Adds a guardian of the target
|
|
108
|
+
* @dev Can be called only by the owner
|
|
109
|
+
* @param newGuardian The address to add as a guardian
|
|
110
|
+
*/
|
|
111
|
+
function addGuardian(address newGuardian) external;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @dev Removes a guardian of the target
|
|
115
|
+
* @dev Can be called only by the owner
|
|
116
|
+
* @param currentGuardian The address of the existing guardian to remove
|
|
117
|
+
*
|
|
118
|
+
* Requirements:
|
|
119
|
+
*
|
|
120
|
+
* - The guardians count should be higher or equal to the guardain threshold
|
|
121
|
+
*/
|
|
122
|
+
function removeGuardian(address currentGuardian) external;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @dev Sets the hash of the secret string to be provided in `recoverOwnership(..)` function
|
|
126
|
+
* @dev Can be called only by the owner
|
|
127
|
+
* @param newRecoverSecretHash The hash of the secret string
|
|
128
|
+
*
|
|
129
|
+
* Requirements:
|
|
130
|
+
*
|
|
131
|
+
* - `secretHash` cannot be bytes32(0)
|
|
132
|
+
*/
|
|
133
|
+
function setRecoverySecretHash(bytes32 newRecoverSecretHash) external;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @dev Sets the minimum number of selection by the guardians required so that an
|
|
137
|
+
* address can recover ownership
|
|
138
|
+
*
|
|
139
|
+
* @dev Can be called only by the owner
|
|
140
|
+
* @param guardiansThreshold The threshold to set
|
|
141
|
+
*
|
|
142
|
+
* Requirements:
|
|
143
|
+
* - `guardiansThreshold` cannot be more than the guardians count.
|
|
144
|
+
*/
|
|
145
|
+
function setGuardiansThreshold(uint256 guardiansThreshold) external;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @dev select an address to be a potentiel controller address if he reaches
|
|
149
|
+
* the guardian threshold and provide the correct secret string
|
|
150
|
+
*
|
|
151
|
+
* Requirements:
|
|
152
|
+
* - only guardians can select an address
|
|
153
|
+
*
|
|
154
|
+
* @param addressSelected The address selected by the guardian
|
|
155
|
+
*/
|
|
156
|
+
function selectNewController(address addressSelected) external;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @dev Recovers the ownership permissions of an address in the linked target
|
|
160
|
+
* and increment the recover counter
|
|
161
|
+
*
|
|
162
|
+
* Requirements
|
|
163
|
+
* - the address of the recoverer must have a selection equal or higher than the threshold
|
|
164
|
+
* defined in `getGuardiansThreshold(...)`
|
|
165
|
+
*
|
|
166
|
+
* - must have provided the right `plainSecret` that produces the secret Hash
|
|
167
|
+
*
|
|
168
|
+
* @param recoverer The address of the recoverer
|
|
169
|
+
* @param plainSecret The secret word that produce the secret Hash
|
|
170
|
+
* @param newHash The new secret Hash to be used in the next recovery process
|
|
171
|
+
*/
|
|
172
|
+
function recoverOwnership(
|
|
173
|
+
address recoverer,
|
|
174
|
+
string memory plainSecret,
|
|
175
|
+
bytes32 newHash
|
|
176
|
+
) external;
|
|
177
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
|
|
6
|
+
import {LSP11BasicSocialRecoveryCore} from "./LSP11BasicSocialRecoveryCore.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title Implementation of LSP11 - Basic Social Recovery standard
|
|
10
|
+
* @dev Sets permission for a controller address after a recovery process to interact with an ERC725
|
|
11
|
+
* contract via the LSP6KeyManager
|
|
12
|
+
*/
|
|
13
|
+
contract LSP11BasicSocialRecovery is LSP11BasicSocialRecoveryCore {
|
|
14
|
+
/**
|
|
15
|
+
* @notice Sets the target and the owner addresses
|
|
16
|
+
* @param _owner The owner of the LSP11 contract
|
|
17
|
+
* @param target_ The address of the ER725 contract to recover
|
|
18
|
+
*/
|
|
19
|
+
constructor(address _owner, address target_) {
|
|
20
|
+
OwnableUnset._setOwner(_owner);
|
|
21
|
+
_target = target_;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {ILSP11BasicSocialRecovery} from "./ILSP11BasicSocialRecovery.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {LSP6Utils} from "../LSP6KeyManager/LSP6Utils.sol";
|
|
9
|
+
|
|
10
|
+
// modules
|
|
11
|
+
import {ERC725} from "@erc725/smart-contracts/contracts/ERC725.sol";
|
|
12
|
+
import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
|
|
13
|
+
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
14
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
15
|
+
import {LSP6KeyManager} from "../LSP6KeyManager/LSP6KeyManager.sol";
|
|
16
|
+
|
|
17
|
+
// constants
|
|
18
|
+
import {ALL_REGULAR_PERMISSIONS} from "../LSP6KeyManager/LSP6Constants.sol";
|
|
19
|
+
import {_INTERFACEID_LSP11} from "./LSP11Constants.sol";
|
|
20
|
+
import "./LSP11Errors.sol";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @title Core Implementation of LSP11-BasicSocialRecovery standard
|
|
24
|
+
* @dev Sets permission for a controller address after a recovery process to interact with an ERC725
|
|
25
|
+
* contract via the LSP6KeyManager
|
|
26
|
+
*/
|
|
27
|
+
abstract contract LSP11BasicSocialRecoveryCore is OwnableUnset, ERC165, ILSP11BasicSocialRecovery {
|
|
28
|
+
using EnumerableSet for EnumerableSet.AddressSet;
|
|
29
|
+
|
|
30
|
+
address internal _target;
|
|
31
|
+
|
|
32
|
+
// The guardians threshold
|
|
33
|
+
uint256 internal _guardiansThreshold;
|
|
34
|
+
|
|
35
|
+
// The number of successfull recovery processes
|
|
36
|
+
uint256 internal _recoveryCounter;
|
|
37
|
+
|
|
38
|
+
// The secret hash to be set by the owner
|
|
39
|
+
bytes32 internal _recoverySecretHash;
|
|
40
|
+
|
|
41
|
+
// Stores the address selected by a guardian
|
|
42
|
+
// in the current `_recoveryCounter`
|
|
43
|
+
mapping(uint256 => mapping(address => address)) internal _guardiansChoice;
|
|
44
|
+
|
|
45
|
+
// List of guardians addresses
|
|
46
|
+
EnumerableSet.AddressSet internal _guardians;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @dev Throws if called by any account other than the guardians
|
|
50
|
+
*/
|
|
51
|
+
modifier onlyGuardians() virtual {
|
|
52
|
+
if (!_guardians.contains(msg.sender)) revert CallerIsNotGuardian(msg.sender);
|
|
53
|
+
_;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @inheritdoc ERC165
|
|
58
|
+
*/
|
|
59
|
+
function supportsInterface(bytes4 _interfaceId) public view virtual override returns (bool) {
|
|
60
|
+
return _interfaceId == _INTERFACEID_LSP11 || super.supportsInterface(_interfaceId);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
65
|
+
*/
|
|
66
|
+
function target() public view virtual returns (address) {
|
|
67
|
+
return _target;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
72
|
+
*/
|
|
73
|
+
function getRecoveryCounter() public view virtual returns (uint256) {
|
|
74
|
+
return _recoveryCounter;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
79
|
+
*/
|
|
80
|
+
function getGuardians() public view virtual returns (address[] memory) {
|
|
81
|
+
return _guardians.values();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
86
|
+
*/
|
|
87
|
+
function isGuardian(address _address) public view virtual returns (bool) {
|
|
88
|
+
return _guardians.contains(_address);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
93
|
+
*/
|
|
94
|
+
function getGuardiansThreshold() public view virtual returns (uint256) {
|
|
95
|
+
return _guardiansThreshold;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
100
|
+
*/
|
|
101
|
+
function getRecoverySecretHash() public view virtual returns (bytes32) {
|
|
102
|
+
return _recoverySecretHash;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
107
|
+
*/
|
|
108
|
+
function getGuardianChoice(address guardian) public view virtual returns (address) {
|
|
109
|
+
return _guardiansChoice[_recoveryCounter][guardian];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
114
|
+
*/
|
|
115
|
+
function addGuardian(address newGuardian) public virtual onlyOwner {
|
|
116
|
+
if (_guardians.contains(newGuardian)) revert GuardianAlreadyExist(newGuardian);
|
|
117
|
+
|
|
118
|
+
_guardians.add(newGuardian);
|
|
119
|
+
emit GuardianAdded(newGuardian);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
124
|
+
*/
|
|
125
|
+
function removeGuardian(address existingGuardian) public virtual onlyOwner {
|
|
126
|
+
if (!_guardians.contains(existingGuardian)) revert GuardianDoNotExist(existingGuardian);
|
|
127
|
+
if (_guardians.length() == _guardiansThreshold)
|
|
128
|
+
revert GuardiansNumberCannotGoBelowThreshold(_guardiansThreshold);
|
|
129
|
+
|
|
130
|
+
_guardians.remove(existingGuardian);
|
|
131
|
+
emit GuardianRemoved(existingGuardian);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
136
|
+
*/
|
|
137
|
+
function setGuardiansThreshold(uint256 newThreshold) public virtual onlyOwner {
|
|
138
|
+
if (newThreshold > _guardians.length())
|
|
139
|
+
revert ThresholdCannotBeHigherThanGuardiansNumber(newThreshold, _guardians.length());
|
|
140
|
+
|
|
141
|
+
_guardiansThreshold = newThreshold;
|
|
142
|
+
emit GuardiansThresholdChanged(newThreshold);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
147
|
+
* @dev Throws if hash provided is bytes32(0)
|
|
148
|
+
*/
|
|
149
|
+
function setRecoverySecretHash(bytes32 newRecoverSecretHash) public virtual onlyOwner {
|
|
150
|
+
if (newRecoverSecretHash == bytes32(0)) revert SecretHashCannotBeZero();
|
|
151
|
+
|
|
152
|
+
_recoverySecretHash = newRecoverSecretHash;
|
|
153
|
+
emit SecretHashChanged(newRecoverSecretHash);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
158
|
+
*/
|
|
159
|
+
function selectNewController(address addressSelected) public virtual onlyGuardians {
|
|
160
|
+
uint256 currentRecoveryCounter = _recoveryCounter;
|
|
161
|
+
|
|
162
|
+
_guardiansChoice[currentRecoveryCounter][msg.sender] = addressSelected;
|
|
163
|
+
emit SelectedNewController(currentRecoveryCounter, msg.sender, addressSelected);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @inheritdoc ILSP11BasicSocialRecovery
|
|
168
|
+
*/
|
|
169
|
+
function recoverOwnership(
|
|
170
|
+
address recoverer,
|
|
171
|
+
string memory plainSecret,
|
|
172
|
+
bytes32 newSecretHash
|
|
173
|
+
) public virtual {
|
|
174
|
+
// caching storage variables
|
|
175
|
+
uint256 currentRecoveryCounter = _recoveryCounter;
|
|
176
|
+
address[] memory guardians = _guardians.values();
|
|
177
|
+
address target_ = _target;
|
|
178
|
+
|
|
179
|
+
_validateRequirements(
|
|
180
|
+
recoverer,
|
|
181
|
+
currentRecoveryCounter,
|
|
182
|
+
plainSecret,
|
|
183
|
+
newSecretHash,
|
|
184
|
+
guardians
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
_recoveryCounter++;
|
|
188
|
+
_recoverySecretHash = newSecretHash;
|
|
189
|
+
emit SecretHashChanged(newSecretHash);
|
|
190
|
+
|
|
191
|
+
address keyManager = ERC725(target_).owner();
|
|
192
|
+
|
|
193
|
+
// Setting permissions for `recoverer`
|
|
194
|
+
(bytes32[] memory keys, bytes[] memory values) = LSP6Utils
|
|
195
|
+
.generatePermissionsKeysForController(
|
|
196
|
+
ERC725(target_),
|
|
197
|
+
recoverer,
|
|
198
|
+
ALL_REGULAR_PERMISSIONS
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
|
|
202
|
+
|
|
203
|
+
emit RecoveryProcessSuccessful(currentRecoveryCounter, recoverer, newSecretHash, guardians);
|
|
204
|
+
|
|
205
|
+
_cleanStorage(currentRecoveryCounter, guardians.length, guardians);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @dev The number of guardians should be reasonable, as the validation method
|
|
210
|
+
* is using a loop to check the selection of each guardian
|
|
211
|
+
*
|
|
212
|
+
* Throws if:
|
|
213
|
+
* - The address trying to recover didn't reach the guardiansThreshold
|
|
214
|
+
* - The new hash being set is bytes32(0)
|
|
215
|
+
* - The secret word provided is incorrect
|
|
216
|
+
*/
|
|
217
|
+
function _validateRequirements(
|
|
218
|
+
address recoverer,
|
|
219
|
+
uint256 currentRecoveryCounter,
|
|
220
|
+
string memory plainSecret,
|
|
221
|
+
bytes32 newHash,
|
|
222
|
+
address[] memory guardians
|
|
223
|
+
) internal view virtual {
|
|
224
|
+
if (recoverer == address(0)) revert AddressZeroNotAllowed();
|
|
225
|
+
uint256 callerSelections;
|
|
226
|
+
|
|
227
|
+
unchecked {
|
|
228
|
+
for (uint256 i; i < guardians.length; i++) {
|
|
229
|
+
if (_guardiansChoice[currentRecoveryCounter][guardians[i]] == recoverer)
|
|
230
|
+
callerSelections++;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
uint256 guardiansThreshold = _guardiansThreshold;
|
|
235
|
+
|
|
236
|
+
if (callerSelections < guardiansThreshold)
|
|
237
|
+
revert ThresholdNotReachedForRecoverer(recoverer, callerSelections, guardiansThreshold);
|
|
238
|
+
if (newHash == bytes32(0)) revert SecretHashCannotBeZero();
|
|
239
|
+
if (keccak256(abi.encodePacked(plainSecret)) != _recoverySecretHash)
|
|
240
|
+
revert WrongPlainSecret();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @dev Remove the guardians choice after a successfull recovery process
|
|
245
|
+
* To avoid keeping unnecessary state
|
|
246
|
+
*/
|
|
247
|
+
function _cleanStorage(
|
|
248
|
+
uint256 recoveryCounter,
|
|
249
|
+
uint256 guardiansLength,
|
|
250
|
+
address[] memory guardians
|
|
251
|
+
) internal virtual {
|
|
252
|
+
unchecked {
|
|
253
|
+
for (uint256 i; i < guardiansLength; i++) {
|
|
254
|
+
delete _guardiansChoice[recoveryCounter][guardians[i]];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
6
|
+
import {LSP11BasicSocialRecoveryInitAbstract} from "./LSP11BasicSocialRecoveryInitAbstract.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title Deployable Proxy Implementation of LSP11 - Basic Social Recovery standard
|
|
10
|
+
* @dev Sets permission for a controller address after a recovery process to interact with an ERC725
|
|
11
|
+
* contract via the LSP6KeyManager
|
|
12
|
+
*/
|
|
13
|
+
contract LSP11BasicSocialRecoveryInit is LSP11BasicSocialRecoveryInitAbstract {
|
|
14
|
+
constructor() {
|
|
15
|
+
_disableInitializers();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @notice Sets the target and the owner addresses
|
|
20
|
+
* @param _owner The owner of the LSP11 contract
|
|
21
|
+
* @param target_ The address of the ER725 contract to recover
|
|
22
|
+
*/
|
|
23
|
+
function initialize(address target_, address _owner) public virtual initializer {
|
|
24
|
+
LSP11BasicSocialRecoveryInitAbstract._initialize(target_, _owner);
|
|
25
|
+
}
|
|
26
|
+
}
|