@lukso/lsp-smart-contracts 0.4.3

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.
Files changed (109) hide show
  1. package/CONTRIBUTING.md +18 -0
  2. package/LICENSE +201 -0
  3. package/README.md +75 -0
  4. package/artifacts/Create2Factory.json +107 -0
  5. package/artifacts/LSP1UniversalReceiverDelegateUP.json +64 -0
  6. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +66 -0
  7. package/artifacts/LSP1UniversalReceiverDelegateVault.json +64 -0
  8. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +66 -0
  9. package/artifacts/LSP6KeyManager.json +222 -0
  10. package/artifacts/LSP6KeyManagerInit.json +224 -0
  11. package/artifacts/LSP7CappedSupply.json +404 -0
  12. package/artifacts/LSP7CappedSupplyInit.json +481 -0
  13. package/artifacts/LSP7CompatibilityForERC20.json +495 -0
  14. package/artifacts/LSP7DigitalAsset.json +417 -0
  15. package/artifacts/LSP7DigitalAssetInit.json +455 -0
  16. package/artifacts/LSP7Mintable.json +445 -0
  17. package/artifacts/LSP7MintableInit.json +483 -0
  18. package/artifacts/LSP8CappedSupply.json +459 -0
  19. package/artifacts/LSP8CappedSupplyInit.json +508 -0
  20. package/artifacts/LSP8CompatibilityForERC721.json +711 -0
  21. package/artifacts/LSP8IdentifiableDigitalAsset.json +467 -0
  22. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +482 -0
  23. package/artifacts/LSP8Mintable.json +495 -0
  24. package/artifacts/LSP8MintableInit.json +510 -0
  25. package/artifacts/UniversalProfile.json +373 -0
  26. package/artifacts/UniversalProfileInit.json +375 -0
  27. package/constants.ts +350 -0
  28. package/contracts/Factories/Create2Factory.sol +92 -0
  29. package/contracts/LSP0ERC725Account/LSP0Constants.sol +14 -0
  30. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +23 -0
  31. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +119 -0
  32. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +20 -0
  33. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +33 -0
  34. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +37 -0
  35. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +22 -0
  36. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +17 -0
  37. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +189 -0
  38. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +26 -0
  39. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +52 -0
  40. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +26 -0
  41. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +28 -0
  42. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +114 -0
  43. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +23 -0
  44. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +41 -0
  45. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +23 -0
  46. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +25 -0
  47. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +23 -0
  48. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +47 -0
  49. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +19 -0
  50. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +36 -0
  51. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +30 -0
  52. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +41 -0
  53. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +52 -0
  54. package/contracts/LSP6KeyManager/LSP6Constants.sol +28 -0
  55. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +21 -0
  56. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +444 -0
  57. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +19 -0
  58. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +26 -0
  59. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +186 -0
  60. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +12 -0
  61. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +35 -0
  62. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +394 -0
  63. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +29 -0
  64. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +44 -0
  65. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +17 -0
  66. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +47 -0
  67. package/contracts/LSP7DigitalAsset/extensions/ILSP7Mintable.sol +32 -0
  68. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +45 -0
  69. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +55 -0
  70. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +24 -0
  71. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +50 -0
  72. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +76 -0
  73. package/contracts/LSP7DigitalAsset/extensions/LSP7Mintable.sol +41 -0
  74. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableCore.sol +26 -0
  75. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInit.sol +26 -0
  76. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +47 -0
  77. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +223 -0
  78. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +18 -0
  79. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +35 -0
  80. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +470 -0
  81. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +29 -0
  82. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +41 -0
  83. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +17 -0
  84. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +108 -0
  85. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Mintable.sol +32 -0
  86. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +53 -0
  87. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +56 -0
  88. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +24 -0
  89. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +55 -0
  90. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityConstants.sol +6 -0
  91. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +252 -0
  92. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Mintable.sol +36 -0
  93. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableCore.sol +29 -0
  94. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInit.sol +24 -0
  95. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +44 -0
  96. package/contracts/LSP9Vault/LSP9Constants.sol +12 -0
  97. package/contracts/LSP9Vault/LSP9Vault.sol +56 -0
  98. package/contracts/LSP9Vault/LSP9VaultCore.sol +174 -0
  99. package/contracts/LSP9Vault/LSP9VaultInit.sol +19 -0
  100. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +60 -0
  101. package/contracts/UniversalProfile.sol +37 -0
  102. package/contracts/UniversalProfileCore.sol +56 -0
  103. package/contracts/UniversalProfileInit.sol +19 -0
  104. package/contracts/UniversalProfileInitAbstract.sol +48 -0
  105. package/contracts/Utils/ERC725Utils.sol +169 -0
  106. package/contracts/Utils/LSP2Utils.sol +127 -0
  107. package/contracts/Utils/LSP6Utils.sol +77 -0
  108. package/contracts/Utils/UtilsLib.sol +23 -0
  109. package/package.json +84 -0
@@ -0,0 +1,174 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "@erc725/smart-contracts/contracts/ERC725X.sol";
6
+ import "@erc725/smart-contracts/contracts/ERC725Y.sol";
7
+
8
+ // interfaces
9
+ import "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
10
+ import "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
11
+
12
+ // library
13
+ import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
14
+ import "../Utils/ERC725Utils.sol";
15
+
16
+ // constants
17
+ import "../LSP1UniversalReceiver/LSP1Constants.sol";
18
+ import "./LSP9Constants.sol";
19
+
20
+ /**
21
+ * @title Core Implementation of LSP9Vault built on top of ERC725, LSP1UniversalReceiver
22
+ * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
23
+ * @dev Could be owned by a UniversalProfile and able to register received asset with UniversalReceiverDelegateVault
24
+ */
25
+ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ILSP1UniversalReceiver {
26
+ using ERC725Utils for IERC725Y;
27
+
28
+ /**
29
+ * @notice Emitted when a native token is received
30
+ * @param sender The address of the sender
31
+ * @param value The amount of value sent
32
+ */
33
+ event ValueReceived(address indexed sender, uint256 indexed value);
34
+
35
+ // modifiers
36
+
37
+ /**
38
+ * @dev Modifier restricting the call to the owner of the contract and the UniversalReceiverDelegate
39
+ */
40
+ modifier onlyAllowed() {
41
+ if (msg.sender != owner()) {
42
+ address universalReceiverAddress = address(
43
+ bytes20(
44
+ IERC725Y(this).getDataSingle(
45
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
46
+ )
47
+ )
48
+ );
49
+ require(
50
+ ERC165Checker.supportsInterface(
51
+ msg.sender,
52
+ _INTERFACEID_LSP1_DELEGATE
53
+ ) && msg.sender == universalReceiverAddress,
54
+ "Only Owner or Universal Receiver Delegate allowed"
55
+ );
56
+ }
57
+ _;
58
+ }
59
+
60
+ // public functions
61
+
62
+ /**
63
+ * @dev Emits an event when a native token is received
64
+ */
65
+ receive() external payable {
66
+ emit ValueReceived(_msgSender(), msg.value);
67
+ }
68
+
69
+ // ERC725Y
70
+
71
+ /**
72
+ * @inheritdoc IERC725Y
73
+ * @dev Sets array of data at multiple given `key`
74
+ * SHOULD only be callable by the owner of the contract set via ERC173
75
+ * and the UniversalReceiverDelegate
76
+ *
77
+ * Emits a {DataChanged} event.
78
+ */
79
+ function setData(bytes32[] memory _keys, bytes[] memory _values)
80
+ public
81
+ virtual
82
+ override
83
+ onlyAllowed
84
+ {
85
+ require(
86
+ _keys.length == _values.length,
87
+ "Keys length not equal to values length"
88
+ );
89
+ for (uint256 i = 0; i < _keys.length; i++) {
90
+ _setData(_keys[i], _values[i]);
91
+ }
92
+ }
93
+
94
+ // LSP1
95
+
96
+ function universalReceiver(bytes32 _typeId, bytes calldata _data)
97
+ external
98
+ virtual
99
+ override
100
+ returns (bytes memory returnValue)
101
+ {
102
+ bytes memory receiverData = IERC725Y(this).getDataSingle(
103
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
104
+ );
105
+ returnValue = "";
106
+
107
+ // call external contract
108
+ if (receiverData.length == 20) {
109
+ address universalReceiverAddress = BytesLib.toAddress(
110
+ receiverData,
111
+ 0
112
+ );
113
+
114
+ if (
115
+ ERC165(universalReceiverAddress).supportsInterface(
116
+ _INTERFACEID_LSP1_DELEGATE
117
+ )
118
+ ) {
119
+ returnValue = ILSP1UniversalReceiverDelegate(
120
+ universalReceiverAddress
121
+ ).universalReceiverDelegate(_msgSender(), _typeId, _data);
122
+ }
123
+ }
124
+
125
+ emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
126
+
127
+ return returnValue;
128
+ }
129
+
130
+ // ERC173
131
+
132
+ /**
133
+ * @inheritdoc OwnableUnset
134
+ * @dev Transfer the ownership and notify the vault sender and vault receiver
135
+ */
136
+ function transferOwnership(address newOwner)
137
+ public
138
+ virtual
139
+ override
140
+ onlyOwner
141
+ {
142
+ _notifyVaultSender(msg.sender);
143
+
144
+ OwnableUnset.transferOwnership(newOwner);
145
+
146
+ _notifyVaultReceiver(newOwner);
147
+ }
148
+
149
+ // internal functions
150
+
151
+ function _notifyVaultSender(address _sender) internal virtual {
152
+ if (
153
+ ERC165Checker.supportsERC165(_sender) &&
154
+ ERC165Checker.supportsInterface(_sender, _INTERFACEID_LSP1)
155
+ ) {
156
+ ILSP1UniversalReceiver(_sender).universalReceiver(
157
+ _TYPEID_LSP9_VAULTSENDER,
158
+ ""
159
+ );
160
+ }
161
+ }
162
+
163
+ function _notifyVaultReceiver(address _receiver) internal virtual {
164
+ if (
165
+ ERC165Checker.supportsERC165(_receiver) &&
166
+ ERC165Checker.supportsInterface(_receiver, _INTERFACEID_LSP1)
167
+ ) {
168
+ ILSP1UniversalReceiver(_receiver).universalReceiver(
169
+ _TYPEID_LSP9_VAULTRECIPIENT,
170
+ ""
171
+ );
172
+ }
173
+ }
174
+ }
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "./LSP9VaultInitAbstract.sol";
6
+
7
+ /**
8
+ * @title Deployable Proxy Implementation of LSP9Vault built on top of ERC725, LSP1UniversalReceiver
9
+ * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
10
+ * @dev Could be owned by a UniversalProfile and able to register received asset with UniversalReceiverDelegateVault
11
+ */
12
+ contract LSP9VaultInit is LSP9VaultInitAbstract {
13
+ /**
14
+ * @inheritdoc LSP9VaultInitAbstract
15
+ */
16
+ function initialize(address _newOwner) public override initializer {
17
+ LSP9VaultInitAbstract.initialize(_newOwner);
18
+ }
19
+ }
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "@erc725/smart-contracts/contracts/ERC725InitAbstract.sol";
6
+ import "./LSP9VaultCore.sol";
7
+
8
+ /**
9
+ * @title Inheritable Proxy Implementation of LSP9Vault built on top of ERC725, LSP1UniversalReceiver
10
+ * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
11
+ * @dev Could be owned by a UniversalProfile and able to register received asset with UniversalReceiverDelegateVault
12
+ */
13
+ abstract contract LSP9VaultInitAbstract is LSP9VaultCore, ERC725InitAbstract {
14
+ /**
15
+ * @notice Sets the owner of the contract and sets the SupportedStandards:LSP9Vault key and register
16
+ * LSP1UniversalReceiver and LSP9Vault InterfaceId
17
+ * @param _newOwner the owner of the contract
18
+ */
19
+ function initialize(address _newOwner)
20
+ public
21
+ virtual
22
+ override
23
+ onlyInitializing
24
+ {
25
+ ERC725InitAbstract.initialize(_newOwner);
26
+
27
+ // set SupportedStandards:LSP9Vault
28
+ bytes32 key = 0xeafec4d89fa9619884b6b891356264550000000000000000000000007c0334a1;
29
+ bytes memory value = hex"7c0334a1";
30
+ _setData(key, value);
31
+
32
+ _notifyVaultReceiver(_newOwner);
33
+
34
+ _registerInterface(_INTERFACEID_LSP1);
35
+ _registerInterface(_INTERFACEID_LSP9);
36
+ }
37
+
38
+ /**
39
+ * @inheritdoc OwnableUnset
40
+ */
41
+ function transferOwnership(address newOwner)
42
+ public
43
+ override(OwnableUnset, LSP9VaultCore)
44
+ onlyOwner
45
+ {
46
+ LSP9VaultCore.transferOwnership(newOwner);
47
+ }
48
+
49
+ /**
50
+ * @inheritdoc LSP9VaultCore
51
+ */
52
+ function setData(bytes32[] memory _keys, bytes[] memory _values)
53
+ public
54
+ virtual
55
+ override(ERC725YCore, LSP9VaultCore)
56
+ onlyAllowed
57
+ {
58
+ LSP9VaultCore.setData(_keys, _values);
59
+ }
60
+ }
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "./UniversalProfileCore.sol";
6
+ import "./LSP0ERC725Account/LSP0ERC725Account.sol";
7
+
8
+ /**
9
+ * @title implementation of a LUKSO's Universal Profile based on LSP3
10
+ * @author Fabian Vogelsteller <fabian@lukso.network>
11
+ * @dev Implementation of the ERC725Account + LSP1 universalReceiver
12
+ */
13
+ contract UniversalProfile is LSP0ERC725Account, UniversalProfileCore {
14
+ /**
15
+ * @notice Sets the owner of the contract and sets the SupportedStandards:LSP3UniversalProfile key
16
+ * @param _newOwner the owner of the contract
17
+ */
18
+ constructor(address _newOwner) LSP0ERC725Account(_newOwner) {
19
+ // set SupportedStandards:LSP3UniversalProfile
20
+ bytes32 key = 0xeafec4d89fa9619884b6b89135626455000000000000000000000000abe425d6;
21
+ bytes memory value = hex"abe425d6";
22
+ _setData(key, value);
23
+
24
+ dataKeys.push(key);
25
+ }
26
+
27
+ /**
28
+ * @inheritdoc UniversalProfileCore
29
+ */
30
+ function setData(bytes32[] memory _keys, bytes[] memory _values)
31
+ public
32
+ override(UniversalProfileCore, ERC725YCore)
33
+ onlyOwner
34
+ {
35
+ UniversalProfileCore.setData(_keys, _values);
36
+ }
37
+ }
@@ -0,0 +1,56 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "./LSP0ERC725Account/LSP0ERC725AccountCore.sol";
6
+ import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
7
+
8
+ // libraries
9
+ import "./Utils/ERC725Utils.sol";
10
+
11
+ /**
12
+ * @title Core implementation of a LUKSO's Universal Profile based on LSP3
13
+ * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera, Yamen Merhi
14
+ * @dev Implementation of the ERC725Account + LSP1 universalReceiver
15
+ */
16
+ abstract contract UniversalProfileCore is ERC165Storage, LSP0ERC725AccountCore {
17
+ bytes32[] public dataKeys;
18
+
19
+ /* non-standard public functions */
20
+
21
+ /**
22
+ * @dev Returns all the keys set on the account
23
+ * @return The array of keys set on the account
24
+ */
25
+ function allDataKeys() public view returns (bytes32[] memory) {
26
+ return dataKeys;
27
+ }
28
+
29
+ /* Standard public functions */
30
+
31
+ /**
32
+ * @inheritdoc IERC725Y
33
+ * @dev Sets array of data at multiple given `key`
34
+ * Push all the keys to the `dataKeys` array
35
+ * SHOULD only be callable by the owner of the contract set via ERC173
36
+ *
37
+ * Emits a {DataChanged} event.
38
+ */
39
+ function setData(bytes32[] memory _keys, bytes[] memory _values)
40
+ public
41
+ virtual
42
+ override
43
+ onlyOwner
44
+ {
45
+ require(
46
+ _keys.length == _values.length,
47
+ "Keys length not equal to values length"
48
+ );
49
+ for (uint256 ii = 0; ii < _keys.length; ii++) {
50
+ if (store[_keys[ii]].length == 0) {
51
+ dataKeys.push(_keys[ii]);
52
+ }
53
+ _setData(_keys[ii], _values[ii]);
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "./UniversalProfileInitAbstract.sol";
6
+
7
+ /**
8
+ * @title Deployable Proxy implementation of a LUKSO's Universal Profile based on LSP3
9
+ * @author Fabian Vogelsteller <fabian@lukso.network>
10
+ * @dev Implementation of the ERC725Account + LSP1 universalReceiver
11
+ */
12
+ contract UniversalProfileInit is UniversalProfileInitAbstract {
13
+ /**
14
+ * @inheritdoc UniversalProfileInitAbstract
15
+ */
16
+ function initialize(address _newOwner) public virtual override initializer {
17
+ UniversalProfileInitAbstract.initialize(_newOwner);
18
+ }
19
+ }
@@ -0,0 +1,48 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "./UniversalProfileCore.sol";
6
+ import "./LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol";
7
+
8
+ /**
9
+ * @title Inheritable Proxy implementation of a LUKSO's Universal Profile based on LSP3
10
+ * @author Fabian Vogelsteller <fabian@lukso.network>
11
+ * @dev Implementation of the ERC725Account + LSP1 universalReceiver
12
+ */
13
+ abstract contract UniversalProfileInitAbstract is
14
+ Initializable,
15
+ LSP0ERC725AccountInitAbstract,
16
+ UniversalProfileCore
17
+ {
18
+ /**
19
+ * @notice Sets the owner of the contract and sets the SupportedStandards:LSP3UniversalProfile key
20
+ * @param _newOwner the owner of the contract
21
+ */
22
+ function initialize(address _newOwner)
23
+ public
24
+ virtual
25
+ override
26
+ onlyInitializing
27
+ {
28
+ LSP0ERC725AccountInitAbstract.initialize(_newOwner);
29
+
30
+ // set SupportedStandards:LSP3UniversalProfile
31
+ bytes32 key = 0xeafec4d89fa9619884b6b89135626455000000000000000000000000abe425d6;
32
+ bytes memory value = hex"abe425d6";
33
+ _setData(key, value);
34
+
35
+ dataKeys.push(key);
36
+ }
37
+
38
+ /**
39
+ * @inheritdoc UniversalProfileCore
40
+ */
41
+ function setData(bytes32[] memory _keys, bytes[] memory _values)
42
+ public
43
+ override(UniversalProfileCore, ERC725YCore)
44
+ onlyOwner
45
+ {
46
+ UniversalProfileCore.setData(_keys, _values);
47
+ }
48
+ }
@@ -0,0 +1,169 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
5
+ import "solidity-bytes-utils/contracts/BytesLib.sol";
6
+
7
+ library ERC725Utils {
8
+ // internal functions
9
+
10
+ /**
11
+ * @dev Gets one value from account storage
12
+ */
13
+ function getDataSingle(IERC725Y _account, bytes32 _key)
14
+ internal
15
+ view
16
+ returns (bytes memory)
17
+ {
18
+ bytes32[] memory keys = new bytes32[](1);
19
+ keys[0] = _key;
20
+ bytes memory fetchResult = _account.getData(keys)[0];
21
+ return fetchResult;
22
+ }
23
+
24
+ /**
25
+ * @dev Initiates Map and ArrayKey and sets the length of the Array to `1` if it's not set before,
26
+ * If it's already set, it decodes the arrayLength, increment it and adds Map and ArrayKey
27
+ */
28
+ function addMapAndArrayKey(
29
+ IERC725Y _account,
30
+ bytes32 _arrayKey,
31
+ bytes32 _mapKey,
32
+ address _sender,
33
+ bytes4 _appendix
34
+ ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
35
+ keys = new bytes32[](3);
36
+ values = new bytes[](3);
37
+
38
+ bytes memory rawArrayLength = getDataSingle(_account, _arrayKey);
39
+
40
+ keys[0] = _arrayKey;
41
+ keys[2] = _mapKey;
42
+
43
+ values[1] = abi.encodePacked(_sender);
44
+
45
+ if (rawArrayLength.length != 32) {
46
+ keys[1] = _generateArrayKeyAtIndex(_arrayKey, 0);
47
+
48
+ values[0] = abi.encodePacked(uint256(1));
49
+ values[2] = abi.encodePacked(bytes8(0), _appendix);
50
+ } else if (rawArrayLength.length == 32) {
51
+ uint256 arrayLength = abi.decode(rawArrayLength, (uint256));
52
+ uint256 newArrayLength = arrayLength + 1;
53
+
54
+ keys[1] = _generateArrayKeyAtIndex(_arrayKey, newArrayLength - 1);
55
+
56
+ values[0] = abi.encodePacked(newArrayLength);
57
+ values[2] = abi.encodePacked(
58
+ bytes8(uint64(arrayLength)),
59
+ _appendix
60
+ );
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @dev Decrements the arrayLength, removes the Map, swaps the arrayKey that need to be removed with
66
+ * the last `arrayKey` in the array and removes the last arrayKey with updating all modified entries
67
+ */
68
+ function removeMapAndArrayKey(
69
+ IERC725Y _account,
70
+ bytes32 _arrayKey,
71
+ bytes32 mapHash,
72
+ bytes32 _mapKeyToRemove
73
+ ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
74
+ keys = new bytes32[](5);
75
+ values = new bytes[](5);
76
+
77
+ uint64 index = _extractIndexFromMap(_account, _mapKeyToRemove);
78
+ bytes32 arrayKeyToRemove = _generateArrayKeyAtIndex(_arrayKey, index);
79
+
80
+ bytes memory rawArrayLength = getDataSingle(_account, _arrayKey);
81
+ uint256 arrayLength = abi.decode(rawArrayLength, (uint256));
82
+ uint256 newLength = arrayLength - 1;
83
+
84
+ keys[0] = _arrayKey;
85
+ values[0] = abi.encodePacked(newLength);
86
+
87
+ keys[1] = _mapKeyToRemove;
88
+ values[1] = "";
89
+
90
+ if (index == (arrayLength - 1)) {
91
+ keys[2] = arrayKeyToRemove;
92
+ values[2] = "";
93
+ } else {
94
+ bytes32 lastKey = _generateArrayKeyAtIndex(_arrayKey, newLength);
95
+ bytes memory lastKeyValue = getDataSingle(_account, lastKey);
96
+
97
+ bytes32 mapOfLastkey = generateMapKey(mapHash, lastKeyValue);
98
+ bytes memory mapValueOfLastkey = getDataSingle(
99
+ _account,
100
+ mapOfLastkey
101
+ );
102
+
103
+ bytes memory appendix = BytesLib.slice(mapValueOfLastkey, 8, 4);
104
+
105
+ keys[2] = arrayKeyToRemove;
106
+ values[2] = lastKeyValue;
107
+
108
+ keys[3] = lastKey;
109
+ values[3] = "";
110
+
111
+ keys[4] = mapOfLastkey;
112
+ values[4] = abi.encodePacked(bytes8(index), appendix);
113
+ }
114
+ }
115
+
116
+ function generateMapKey(bytes32 _mapHash, bytes memory _sender)
117
+ internal
118
+ pure
119
+ returns (bytes32)
120
+ {
121
+ bytes memory mapKey = abi.encodePacked(
122
+ bytes8(_mapHash),
123
+ bytes4(0),
124
+ _sender
125
+ );
126
+ return _generateBytes32Key(mapKey);
127
+ }
128
+
129
+ // private functions
130
+
131
+ function _generateBytes32Key(bytes memory _rawKey)
132
+ private
133
+ pure
134
+ returns (bytes32 key)
135
+ {
136
+ /* solhint-disable */
137
+ assembly {
138
+ key := mload(add(_rawKey, 32))
139
+ }
140
+ /* solhint-enable */
141
+ }
142
+
143
+ function _generateArrayKeyAtIndex(bytes32 _arrayKey, uint256 _index)
144
+ private
145
+ pure
146
+ returns (bytes32)
147
+ {
148
+ bytes memory elementInArray = abi.encodePacked(
149
+ bytes16(_arrayKey),
150
+ bytes16(uint128(_index))
151
+ );
152
+ return _generateBytes32Key(elementInArray);
153
+ }
154
+
155
+ function _extractIndexFromMap(IERC725Y _account, bytes32 _mapKey)
156
+ private
157
+ view
158
+ returns (uint64)
159
+ {
160
+ bytes memory indexInBytes = getDataSingle(_account, _mapKey);
161
+ bytes8 indexKey;
162
+ /* solhint-disable */
163
+ assembly {
164
+ indexKey := mload(add(indexInBytes, 32))
165
+ }
166
+ /* solhint-enable */
167
+ return uint64(indexKey);
168
+ }
169
+ }