@lukso/lsp-smart-contracts 0.6.0 → 0.7.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.
Files changed (140) hide show
  1. package/README.md +13 -12
  2. package/artifacts/Create2Factory.json +2 -2
  3. package/artifacts/LSP0ERC725Account.json +66 -27
  4. package/artifacts/LSP0ERC725AccountInit.json +71 -53
  5. package/artifacts/LSP1UniversalReceiverDelegateUP.json +23 -2
  6. package/artifacts/LSP1UniversalReceiverDelegateVault.json +23 -2
  7. package/artifacts/LSP4Compatibility.json +15 -9
  8. package/artifacts/LSP4DigitalAssetMetadata.json +25 -9
  9. package/artifacts/{LSP4DigitalAssetMetadataInit.json → LSP4DigitalAssetMetadataInitAbstract.json} +27 -60
  10. package/artifacts/LSP6KeyManager.json +93 -13
  11. package/artifacts/LSP6KeyManagerInit.json +98 -13
  12. package/artifacts/LSP7CappedSupply.json +56 -35
  13. package/artifacts/{LSP7CappedSupplyInit.json → LSP7CappedSupplyInitAbstract.json} +58 -104
  14. package/artifacts/LSP7CompatibleERC20.json +704 -0
  15. package/artifacts/LSP7CompatibleERC20InitAbstract.json +717 -0
  16. package/artifacts/LSP7CompatibleERC20Mintable.json +753 -0
  17. package/artifacts/LSP7CompatibleERC20MintableInit.json +773 -0
  18. package/artifacts/LSP7DigitalAsset.json +56 -61
  19. package/artifacts/LSP7DigitalAssetInitAbstract.json +540 -0
  20. package/artifacts/LSP7Mintable.json +59 -38
  21. package/artifacts/LSP7MintableInit.json +64 -64
  22. package/artifacts/LSP8CappedSupply.json +62 -9
  23. package/artifacts/{LSP8CappedSupplyInit.json → LSP8CappedSupplyInitAbstract.json} +64 -73
  24. package/artifacts/LSP8CompatibleERC721.json +907 -0
  25. package/artifacts/LSP8CompatibleERC721InitAbstract.json +920 -0
  26. package/artifacts/LSP8CompatibleERC721Mintable.json +967 -0
  27. package/artifacts/LSP8CompatibleERC721MintableInit.json +987 -0
  28. package/artifacts/LSP8IdentifiableDigitalAsset.json +62 -30
  29. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +628 -0
  30. package/artifacts/LSP8Mintable.json +64 -11
  31. package/artifacts/LSP8MintableInit.json +69 -37
  32. package/artifacts/LSP9Vault.json +63 -24
  33. package/artifacts/LSP9VaultInit.json +68 -50
  34. package/artifacts/UniversalFactory.json +2 -2
  35. package/artifacts/UniversalProfile.json +66 -27
  36. package/artifacts/UniversalProfileInit.json +71 -53
  37. package/artifacts/UniversalReceiverAddressStore.json +7 -2
  38. package/constants.js +273 -31
  39. package/contracts/Custom/ClaimOwnership.sol +74 -9
  40. package/contracts/Custom/ERC165Checker.sol +1 -1
  41. package/contracts/Custom/IClaimOwnership.sol +3 -1
  42. package/contracts/Factories/Create2Factory.sol +3 -13
  43. package/contracts/Factories/UniversalFactory.sol +20 -16
  44. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  45. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +3 -3
  46. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +49 -37
  47. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +10 -3
  48. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +3 -3
  49. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
  50. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +3 -0
  51. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
  52. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +1 -1
  53. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +22 -16
  54. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +14 -10
  55. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +35 -29
  56. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +10 -3
  57. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +24 -9
  58. package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +9 -0
  59. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +157 -75
  60. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
  61. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
  62. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +24 -4
  63. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +26 -5
  64. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +16 -0
  65. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
  66. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +151 -77
  67. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +16 -16
  68. package/contracts/LSP6KeyManager/LSP6Constants.sol +16 -21
  69. package/contracts/LSP6KeyManager/LSP6Errors.sol +42 -5
  70. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +6 -4
  71. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +293 -284
  72. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +11 -4
  73. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +5 -3
  74. package/contracts/LSP6KeyManager/LSP6Utils.sol +24 -27
  75. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +18 -5
  76. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
  77. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +8 -4
  78. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +35 -24
  79. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +5 -3
  80. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +2 -0
  81. package/contracts/LSP7DigitalAsset/extensions/{ILSP7CompatibilityForERC20.sol → ILSP7CompatibleERC20.sol} +6 -6
  82. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +1 -1
  83. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +5 -2
  84. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20.sol → LSP7CompatibleERC20.sol} +6 -7
  85. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20Core.sol → LSP7CompatibleERC20Core.sol} +23 -19
  86. package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20InitAbstract.sol → LSP7CompatibleERC20InitAbstract.sol} +11 -10
  87. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +22 -0
  88. package/contracts/{LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol → LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol} +12 -7
  89. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +27 -0
  90. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +9 -7
  91. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +11 -4
  92. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +8 -7
  93. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +3 -1
  94. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +4 -4
  95. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +6 -0
  96. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +1 -1
  97. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +31 -30
  98. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +3 -1
  99. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{ILSP8CompatibilityForERC721.sol → ILSP8CompatibleERC721.sol} +16 -2
  100. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +17 -0
  101. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +1 -1
  102. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +4 -2
  103. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityConstants.sol → LSP8CompatibleConstants.sol} +0 -0
  104. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721.sol → LSP8CompatibleERC721.sol} +12 -11
  105. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Core.sol → LSP8CompatibleERC721Core.sol} +61 -37
  106. package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721InitAbstract.sol → LSP8CompatibleERC721InitAbstract.sol} +13 -9
  107. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +21 -0
  108. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +50 -0
  109. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +24 -0
  110. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +22 -0
  111. package/contracts/{LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol → LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol} +12 -4
  112. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +27 -0
  113. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +6 -4
  114. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +7 -0
  115. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +8 -5
  116. package/contracts/LSP9Vault/LSP9Constants.sol +6 -3
  117. package/contracts/LSP9Vault/LSP9Vault.sol +9 -5
  118. package/contracts/LSP9Vault/LSP9VaultCore.sol +152 -69
  119. package/contracts/LSP9Vault/LSP9VaultInit.sol +10 -3
  120. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +9 -5
  121. package/contracts/Legacy/UniversalReceiverAddressStore.sol +6 -2
  122. package/contracts/UniversalProfile.sol +3 -4
  123. package/contracts/UniversalProfileInit.sol +10 -3
  124. package/contracts/UniversalProfileInitAbstract.sol +3 -5
  125. package/contracts/Utils/GasLib.sol +17 -0
  126. package/contracts/Utils/UtilsLib.sol +6 -34
  127. package/package.json +27 -30
  128. package/artifacts/LSP7CompatibilityForERC20.json +0 -686
  129. package/artifacts/LSP7CompatibilityForERC20Init.json +0 -727
  130. package/artifacts/LSP7DigitalAssetInit.json +0 -573
  131. package/artifacts/LSP8CompatibilityForERC721.json +0 -832
  132. package/artifacts/LSP8CompatibilityForERC721Init.json +0 -873
  133. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +0 -624
  134. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +0 -26
  135. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +0 -28
  136. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +0 -19
  137. package/contracts/LSP7DigitalAsset/presets/LSP7MintableCore.sol +0 -26
  138. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +0 -26
  139. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +0 -19
  140. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableCore.sol +0 -26
@@ -13,9 +13,9 @@ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnse
13
13
  contract LSP0ERC725Account is LSP0ERC725AccountCore {
14
14
  /**
15
15
  * @notice Sets the owner of the contract
16
- * @param _newOwner the owner of the contract
16
+ * @param newOwner the owner of the contract
17
17
  */
18
- constructor(address _newOwner) {
19
- OwnableUnset._setOwner(_newOwner);
18
+ constructor(address newOwner) payable {
19
+ OwnableUnset._setOwner(newOwner);
20
20
  }
21
21
  }
@@ -4,9 +4,12 @@ pragma solidity ^0.8.0;
4
4
  // interfaces
5
5
  import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
6
  import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
- import {ILSP1UniversalReceiverDelegate} from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
7
+ import {
8
+ ILSP1UniversalReceiverDelegate
9
+ } from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
8
10
 
9
11
  // libraries
12
+ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
10
13
  import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
11
14
  import {ERC165Checker} from "../Custom/ERC165Checker.sol";
12
15
 
@@ -17,8 +20,16 @@ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnse
17
20
  import {ClaimOwnership} from "../Custom/ClaimOwnership.sol";
18
21
 
19
22
  // constants
20
- import {_INTERFACEID_LSP0, _INTERFACEID_ERC1271, _ERC1271_FAILVALUE} from "../LSP0ERC725Account/LSP0Constants.sol";
21
- import {_INTERFACEID_LSP1, _INTERFACEID_LSP1_DELEGATE, _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY} from "../LSP1UniversalReceiver/LSP1Constants.sol";
23
+ import {
24
+ _INTERFACEID_LSP0,
25
+ _INTERFACEID_ERC1271,
26
+ _ERC1271_FAILVALUE
27
+ } from "../LSP0ERC725Account/LSP0Constants.sol";
28
+ import {
29
+ _INTERFACEID_LSP1,
30
+ _INTERFACEID_LSP1_DELEGATE,
31
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
32
+ } from "../LSP1UniversalReceiver/LSP1Constants.sol";
22
33
  import {_INTERFACEID_CLAIM_OWNERSHIP} from "../Custom/IClaimOwnership.sol";
23
34
 
24
35
  /**
@@ -43,25 +54,10 @@ abstract contract LSP0ERC725AccountCore is
43
54
  /**
44
55
  * @dev Emits an event when receiving native tokens
45
56
  */
46
- receive() external payable {
47
- emit ValueReceived(_msgSender(), msg.value);
57
+ fallback() external payable virtual {
58
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
48
59
  }
49
60
 
50
- // TODO to be discussed
51
- // function fallback()
52
- // public
53
- // {
54
- // address to = owner();
55
- // assembly {
56
- // calldatacopy(0, 0, calldatasize())
57
- // let result := staticcall(gas(), to, 0, calldatasize(), 0, 0)
58
- // returndatacopy(0, 0, returndatasize())
59
- // switch result
60
- // case 0 { revert (0, returndatasize()) }
61
- // default { return (0, returndatasize()) }
62
- // }
63
- // }
64
-
65
61
  // ERC165
66
62
 
67
63
  /**
@@ -96,33 +92,38 @@ abstract contract LSP0ERC725AccountCore is
96
92
  ClaimOwnership._transferOwnership(_newOwner);
97
93
  }
98
94
 
95
+ /**
96
+ * @dev Renounce ownership of the contract in a 2-step process
97
+ */
98
+ function renounceOwnership() public virtual override(ClaimOwnership, OwnableUnset) onlyOwner {
99
+ ClaimOwnership._renounceOwnership();
100
+ }
101
+
99
102
  // ERC1271
100
103
 
101
104
  /**
102
105
  * @notice Checks if an owner signed `_data`.
103
106
  * ERC1271 interface.
104
107
  *
105
- * @param _hash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
106
- * @param _signature owner's signature(s) of the data
108
+ * @param dataHash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
109
+ * @param signature owner's signature(s) of the data
107
110
  */
108
- function isValidSignature(bytes32 _hash, bytes memory _signature)
111
+ function isValidSignature(bytes32 dataHash, bytes memory signature)
109
112
  public
110
113
  view
111
- override
112
114
  returns (bytes4 magicValue)
113
115
  {
114
- // prettier-ignore
115
116
  address _owner = owner();
116
117
  // if OWNER is a contract
117
118
  if (_owner.code.length != 0) {
118
119
  return
119
120
  ERC165Checker.supportsERC165Interface(_owner, _INTERFACEID_ERC1271)
120
- ? IERC1271(_owner).isValidSignature(_hash, _signature)
121
+ ? IERC1271(_owner).isValidSignature(dataHash, signature)
121
122
  : _ERC1271_FAILVALUE;
122
123
  // if OWNER is a key
123
124
  } else {
124
125
  return
125
- _owner == ECDSA.recover(_hash, _signature)
126
+ _owner == ECDSA.recover(dataHash, signature)
126
127
  ? _INTERFACEID_ERC1271
127
128
  : _ERC1271_FAILVALUE;
128
129
  }
@@ -133,19 +134,19 @@ abstract contract LSP0ERC725AccountCore is
133
134
  /**
134
135
  * @notice Triggers the UniversalReceiver event when this function gets executed successfully.
135
136
  * @dev Forwards the call to the UniversalReceiverDelegate if set.
136
- * @param _typeId The type of call received.
137
- * @param _data The data received.
137
+ * @param typeId The type of call received.
138
+ * @param data The data received.
138
139
  */
139
- function universalReceiver(bytes32 _typeId, bytes calldata _data)
140
- external
140
+ function universalReceiver(bytes32 typeId, bytes calldata data)
141
+ public
142
+ payable
141
143
  virtual
142
- override
143
144
  returns (bytes memory returnValue)
144
145
  {
145
- bytes memory data = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
146
+ bytes memory lsp1DelegateValue = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
146
147
 
147
- if (data.length >= 20) {
148
- address universalReceiverDelegate = address(bytes20(data));
148
+ if (lsp1DelegateValue.length >= 20) {
149
+ address universalReceiverDelegate = address(bytes20(lsp1DelegateValue));
149
150
 
150
151
  if (
151
152
  ERC165Checker.supportsERC165Interface(
@@ -154,9 +155,20 @@ abstract contract LSP0ERC725AccountCore is
154
155
  )
155
156
  ) {
156
157
  returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
157
- .universalReceiverDelegate(_msgSender(), _typeId, _data);
158
+ .universalReceiverDelegate(msg.sender, msg.value, typeId, data);
158
159
  }
159
160
  }
160
- emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
161
+ emit UniversalReceiver(msg.sender, msg.value, typeId, returnValue, data);
162
+ }
163
+
164
+ /**
165
+ * @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
166
+ */
167
+ function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
168
+ store[dataKey] = dataValue;
169
+ emit DataChanged(
170
+ dataKey,
171
+ dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
172
+ );
161
173
  }
162
174
  }
@@ -10,11 +10,18 @@ import {LSP0ERC725AccountInitAbstract} from "./LSP0ERC725AccountInitAbstract.sol
10
10
  * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
11
11
  */
12
12
  contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
13
+ /**
14
+ * @dev @dev initialize (= lock) base implementation contract on deployment
15
+ */
16
+ constructor() {
17
+ _disableInitializers();
18
+ }
19
+
13
20
  /**
14
21
  * @notice Sets the owner of the contract
15
- * @param _newOwner the owner of the contract
22
+ * @param newOwner the owner of the contract
16
23
  */
17
- function initialize(address _newOwner) public virtual initializer {
18
- LSP0ERC725AccountInitAbstract._initialize(_newOwner);
24
+ function initialize(address newOwner) public payable virtual initializer {
25
+ LSP0ERC725AccountInitAbstract._initialize(newOwner);
19
26
  }
20
27
  }
@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
5
  import {LSP0ERC725AccountCore} from "./LSP0ERC725AccountCore.sol";
6
- import {Initializable} from "@erc725/smart-contracts/contracts/custom/Initializable.sol";
6
+ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
7
7
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
8
8
 
9
9
  /**
@@ -12,7 +12,7 @@ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnse
12
12
  * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
13
13
  */
14
14
  abstract contract LSP0ERC725AccountInitAbstract is Initializable, LSP0ERC725AccountCore {
15
- function _initialize(address _newOwner) internal virtual onlyInitializing {
16
- OwnableUnset._setOwner(_newOwner);
15
+ function _initialize(address newOwner) internal virtual onlyInitializing {
16
+ OwnableUnset._setOwner(newOwner);
17
17
  }
18
18
  }
@@ -6,5 +6,5 @@ pragma solidity ^0.8.0;
6
6
  // keccak256('LSP10Vaults[]')
7
7
  bytes32 constant _LSP10_VAULTS_ARRAY_KEY = 0x55482936e01da86729a45d2b87a6b1d3bc582bea0ec00e38bdb340e3af6f9f06;
8
8
 
9
- // bytes10(keccak256('LSP10VaultsMap')) + bytes2(0)
10
- bytes12 constant _LSP10_VAULTS_MAP_KEY_PREFIX = 0x192448c3c0f88c7f238c0000;
9
+ // bytes10(keccak256('LSP10VaultsMap'))
10
+ bytes10 constant _LSP10_VAULTS_MAP_KEY_PREFIX = 0x192448c3c0f88c7f238c;
@@ -9,12 +9,14 @@ interface ILSP1UniversalReceiver {
9
9
  /**
10
10
  * @notice Emitted when the universalReceiver function is succesfully executed
11
11
  * @param from The address calling the universalReceiver function
12
+ * @param value The amount sent to the universalReceiver function
12
13
  * @param typeId The hash of a specific standard or a hook
13
14
  * @param returnedValue The return value of universalReceiver function
14
15
  * @param receivedData The arbitrary data passed to universalReceiver function
15
16
  */
16
17
  event UniversalReceiver(
17
18
  address indexed from,
19
+ uint256 value,
18
20
  bytes32 indexed typeId,
19
21
  bytes indexed returnedValue,
20
22
  bytes receivedData
@@ -33,5 +35,6 @@ interface ILSP1UniversalReceiver {
33
35
  */
34
36
  function universalReceiver(bytes32 typeId, bytes calldata data)
35
37
  external
38
+ payable
36
39
  returns (bytes memory);
37
40
  }
@@ -9,13 +9,15 @@ pragma solidity ^0.8.0;
9
9
  interface ILSP1UniversalReceiverDelegate {
10
10
  /**
11
11
  * @dev Get called by the universalReceiver function, can be customized to have a specific logic
12
- * @param sender The address calling the universalReceiver function
12
+ * @param caller The address calling the universalReceiver function
13
+ * @param value The amount sent to the universalReceiver function
13
14
  * @param typeId The hash of a specific standard or a hook
14
15
  * @param data The arbitrary data received with the call
15
16
  * @return result Any useful data could be returned
16
17
  */
17
18
  function universalReceiverDelegate(
18
- address sender,
19
+ address caller,
20
+ uint256 value,
19
21
  bytes32 typeId,
20
22
  bytes memory data
21
23
  ) external returns (bytes memory result);
@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  // --- ERC165 interface ids
5
5
  bytes4 constant _INTERFACEID_LSP1 = 0x6bb56a14;
6
- bytes4 constant _INTERFACEID_LSP1_DELEGATE = 0xc2d7bcc1;
6
+ bytes4 constant _INTERFACEID_LSP1_DELEGATE = 0xa245bbda;
7
7
 
8
8
  // --- ERC725Y Keys
9
9
 
@@ -24,13 +24,10 @@ import {_TYPEID_LSP9_VAULTSENDER} from "../../../LSP9Vault/LSP9Constants.sol";
24
24
  * @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
25
25
  */
26
26
  abstract contract TokenAndVaultHandling {
27
- // internal functions
28
- function _tokenAndVaultHandling(address sender, bytes32 typeId)
27
+ function _tokenAndVaultHandling(address caller, bytes32 typeId)
29
28
  internal
30
29
  returns (bytes memory result)
31
30
  {
32
- if (sender.code.length == 0) return "";
33
-
34
31
  address keyManager = ERC725Y(msg.sender).owner();
35
32
  if (!ERC165Checker.supportsERC165Interface(keyManager, _INTERFACEID_LSP6)) return "";
36
33
 
@@ -38,34 +35,43 @@ abstract contract TokenAndVaultHandling {
38
35
 
39
36
  // check if the caller is the same account controlled by the keyManager
40
37
  if (msg.sender != target) return "";
41
- (bool senderHook, bytes32 arrayKey, bytes12 mapPrefix, bytes4 interfaceID) = LSP1Utils
42
- .getTransferDetails(typeId);
43
38
 
44
- bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(sender));
39
+ (
40
+ bool isReceiving,
41
+ bytes32 arrayLengthKey,
42
+ bytes10 mapPrefix,
43
+ bytes4 interfaceID
44
+ ) = LSP1Utils.getTransferDetails(typeId);
45
+
46
+ bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
45
47
  bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
46
48
 
47
- if (!senderHook) {
48
- // if the map is already set, then do nothing
49
+ if (isReceiving) {
50
+ // if the map value is already set, then do nothing
49
51
  if (bytes12(mapValue) != bytes12(0)) return "";
52
+
50
53
  result = LSP5Utils.addMapAndArrayKeyViaKeyManager(
51
54
  IERC725Y(msg.sender),
52
- arrayKey,
55
+ arrayLengthKey,
53
56
  mapKey,
54
- sender,
57
+ caller,
55
58
  interfaceID,
56
59
  keyManager
57
60
  );
58
- } else if (senderHook) {
59
- // if there is no map for the asset to remove, then do nothing
61
+ } else {
62
+ // if there is no map value for the asset to remove, then do nothing
60
63
  if (bytes12(mapValue) == bytes12(0)) return "";
64
+
65
+ // if it's a token transfer (LSP7/LSP8)
61
66
  if (typeId != _TYPEID_LSP9_VAULTSENDER) {
62
- uint256 balance = ILSP7DigitalAsset(sender).balanceOf(msg.sender);
63
- // if the amount sent is not the full balance, then do nothing
67
+ // if the amount sent is not the full balance, then do not remove the keys
68
+ uint256 balance = ILSP7DigitalAsset(caller).balanceOf(msg.sender);
64
69
  if (balance != 0) return "";
65
70
  }
71
+
66
72
  result = LSP5Utils.removeMapAndArrayKeyViaKeyManager(
67
73
  IERC725Y(msg.sender),
68
- arrayKey,
74
+ arrayLengthKey,
69
75
  mapPrefix,
70
76
  mapKey,
71
77
  mapValue,
@@ -10,9 +10,18 @@ import {TokenAndVaultHandling} from "./Handling/TokenAndVaultHandling.sol";
10
10
 
11
11
  // constants
12
12
  import {_INTERFACEID_LSP1_DELEGATE} from "../LSP1Constants.sol";
13
- import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "../../LSP7DigitalAsset/LSP7Constants.sol";
14
- import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
15
- import {_TYPEID_LSP9_VAULTSENDER, _TYPEID_LSP9_VAULTRECIPIENT} from "../../LSP9Vault/LSP9Constants.sol";
13
+ import {
14
+ _TYPEID_LSP7_TOKENSSENDER,
15
+ _TYPEID_LSP7_TOKENSRECIPIENT
16
+ } from "../../LSP7DigitalAsset/LSP7Constants.sol";
17
+ import {
18
+ _TYPEID_LSP8_TOKENSSENDER,
19
+ _TYPEID_LSP8_TOKENSRECIPIENT
20
+ } from "../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
21
+ import {
22
+ _TYPEID_LSP9_VAULTSENDER,
23
+ _TYPEID_LSP9_VAULTRECIPIENT
24
+ } from "../../LSP9Vault/LSP9Constants.sol";
16
25
 
17
26
  /**
18
27
  * @title Core Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
@@ -36,9 +45,10 @@ contract LSP1UniversalReceiverDelegateUP is
36
45
  */
37
46
  function universalReceiverDelegate(
38
47
  address sender,
48
+ uint256 value, // solhint-disable no-unused-vars
39
49
  bytes32 typeId,
40
50
  bytes memory data // solhint-disable no-unused-vars
41
- ) public virtual override returns (bytes memory result) {
51
+ ) public virtual returns (bytes memory result) {
42
52
  if (
43
53
  typeId == _TYPEID_LSP7_TOKENSSENDER ||
44
54
  typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
@@ -49,12 +59,6 @@ contract LSP1UniversalReceiverDelegateUP is
49
59
  ) {
50
60
  result = _tokenAndVaultHandling(sender, typeId);
51
61
  }
52
-
53
- /* @TODO
54
- else if() {
55
- result = FollowerHandling(sender, typeId, data);
56
- }
57
- */
58
62
  }
59
63
 
60
64
  // --- Overrides
@@ -23,45 +23,51 @@ import "../../../LSP9Vault/LSP9Constants.sol";
23
23
  * @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
24
24
  */
25
25
  abstract contract TokenHandling {
26
- // internal functions
27
- function _tokenHandling(address sender, bytes32 typeId) internal returns (bytes memory result) {
28
- if (sender.code.length == 0) return "";
29
-
26
+ function _tokenHandling(address caller, bytes32 typeId) internal returns (bytes memory result) {
30
27
  if (!ERC165Checker.supportsERC165Interface(msg.sender, _INTERFACEID_LSP9)) return "";
31
28
 
32
- (bool senderHook, bytes32 arrayKey, bytes12 mapPrefix, bytes4 interfaceID) = LSP1Utils
33
- .getTransferDetails(typeId);
29
+ (
30
+ bool isReceiving,
31
+ bytes32 arrayLengthKey,
32
+ bytes10 mapPrefix,
33
+ bytes4 interfaceID
34
+ ) = LSP1Utils.getTransferDetails(typeId);
34
35
 
35
- bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(sender));
36
+ bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
36
37
  bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
37
38
 
38
- if (!senderHook) {
39
- // if the map is already set, then do nothing
39
+ if (isReceiving) {
40
+ // if the map value is already set, then do nothing
40
41
  if (bytes12(mapValue) != bytes12(0)) return "";
41
42
 
42
- (bytes32[] memory keys, bytes[] memory values) = LSP5Utils.addMapAndArrayKey(
43
- IERC725Y(msg.sender),
44
- arrayKey,
45
- mapKey,
46
- sender,
47
- interfaceID
48
- );
49
- IERC725Y(msg.sender).setData(keys, values);
50
- } else if (senderHook) {
51
- // if there is no map for the asset to remove, then do nothing
43
+ (bytes32[] memory receiverDataKeys, bytes[] memory receiverDataValues) = LSP5Utils
44
+ .addMapAndArrayKey(
45
+ IERC725Y(msg.sender),
46
+ arrayLengthKey,
47
+ mapKey,
48
+ caller,
49
+ interfaceID
50
+ );
51
+
52
+ IERC725Y(msg.sender).setData(receiverDataKeys, receiverDataValues);
53
+ } else {
54
+ // if there is no map value for the asset to remove, then do nothing
52
55
  if (bytes12(mapValue) == bytes12(0)) return "";
53
- uint256 balance = ILSP7DigitalAsset(sender).balanceOf(msg.sender);
54
- // if the amount sent is not the full balance, then do nothing
56
+
57
+ // if the amount sent is not the full balance, then do not remove the keys
58
+ uint256 balance = ILSP7DigitalAsset(caller).balanceOf(msg.sender);
55
59
  if (balance != 0) return "";
56
60
 
57
- (bytes32[] memory keys, bytes[] memory values) = LSP5Utils.removeMapAndArrayKey(
58
- IERC725Y(msg.sender),
59
- arrayKey,
60
- mapPrefix,
61
- mapKey,
62
- mapValue
63
- );
64
- IERC725Y(msg.sender).setData(keys, values);
61
+ (bytes32[] memory senderDataKeys, bytes[] memory senderDataValues) = LSP5Utils
62
+ .removeMapAndArrayKey(
63
+ IERC725Y(msg.sender),
64
+ arrayLengthKey,
65
+ mapPrefix,
66
+ mapKey,
67
+ mapValue
68
+ );
69
+
70
+ IERC725Y(msg.sender).setData(senderDataKeys, senderDataValues);
65
71
  }
66
72
  }
67
73
  }
@@ -10,8 +10,14 @@ import {TokenHandling} from "./Handling/TokenHandling.sol";
10
10
 
11
11
  // constants
12
12
  import {_INTERFACEID_LSP1_DELEGATE} from "../LSP1Constants.sol";
13
- import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "../../LSP7DigitalAsset/LSP7Constants.sol";
14
- import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
13
+ import {
14
+ _TYPEID_LSP7_TOKENSSENDER,
15
+ _TYPEID_LSP7_TOKENSRECIPIENT
16
+ } from "../../LSP7DigitalAsset/LSP7Constants.sol";
17
+ import {
18
+ _TYPEID_LSP8_TOKENSSENDER,
19
+ _TYPEID_LSP8_TOKENSRECIPIENT
20
+ } from "../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
15
21
 
16
22
  /**
17
23
  * @title Core Implementation of contract writing the received LSP7 and LSP8 assets into your Vault using
@@ -32,9 +38,10 @@ contract LSP1UniversalReceiverDelegateVault is
32
38
  */
33
39
  function universalReceiverDelegate(
34
40
  address sender,
41
+ uint256 value, // solhint-disable no-unused-vars
35
42
  bytes32 typeId,
36
43
  bytes memory data // solhint-disable no-unused-vars
37
- ) public virtual override returns (bytes memory result) {
44
+ ) public virtual returns (bytes memory result) {
38
45
  if (
39
46
  typeId == _TYPEID_LSP7_TOKENSSENDER ||
40
47
  typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
@@ -2,11 +2,25 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // constants
5
- import {_LSP5_RECEIVED_ASSETS_ARRAY_KEY, _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX} from "../LSP5ReceivedAssets/LSP5Constants.sol";
6
- import {_INTERFACEID_LSP7, _TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "../LSP7DigitalAsset/LSP7Constants.sol";
7
- import {_INTERFACEID_LSP8, _TYPEID_LSP8_TOKENSRECIPIENT, _TYPEID_LSP8_TOKENSSENDER} from "../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
8
- import {_INTERFACEID_LSP9, _TYPEID_LSP9_VAULTSENDER} from "../LSP9Vault/LSP9Constants.sol";
9
- import {_LSP10_VAULTS_ARRAY_KEY, _LSP10_VAULTS_MAP_KEY_PREFIX} from "../LSP10ReceivedVaults/LSP10Constants.sol";
5
+ import {
6
+ _LSP5_RECEIVED_ASSETS_ARRAY_KEY,
7
+ _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX
8
+ } from "../LSP5ReceivedAssets/LSP5Constants.sol";
9
+ import {
10
+ _INTERFACEID_LSP7,
11
+ _TYPEID_LSP7_TOKENSSENDER,
12
+ _TYPEID_LSP7_TOKENSRECIPIENT
13
+ } from "../LSP7DigitalAsset/LSP7Constants.sol";
14
+ import {
15
+ _INTERFACEID_LSP8,
16
+ _TYPEID_LSP8_TOKENSRECIPIENT,
17
+ _TYPEID_LSP8_TOKENSSENDER
18
+ } from "../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
19
+ import {_INTERFACEID_LSP9, _TYPEID_LSP9_VAULTRECIPIENT} from "../LSP9Vault/LSP9Constants.sol";
20
+ import {
21
+ _LSP10_VAULTS_ARRAY_KEY,
22
+ _LSP10_VAULTS_MAP_KEY_PREFIX
23
+ } from "../LSP10ReceivedVaults/LSP10Constants.sol";
10
24
 
11
25
  library LSP1Utils {
12
26
  /**
@@ -16,9 +30,9 @@ library LSP1Utils {
16
30
  internal
17
31
  pure
18
32
  returns (
19
- bool senderHook,
33
+ bool isReceiving,
20
34
  bytes32 arrayKey,
21
- bytes12 mapPrefix,
35
+ bytes10 mapPrefix,
22
36
  bytes4 interfaceId
23
37
  )
24
38
  {
@@ -34,14 +48,15 @@ library LSP1Utils {
34
48
  typeId == _TYPEID_LSP7_TOKENSRECIPIENT
35
49
  ? _INTERFACEID_LSP7
36
50
  : _INTERFACEID_LSP8;
37
- senderHook = typeId == _TYPEID_LSP7_TOKENSSENDER || typeId == _TYPEID_LSP8_TOKENSSENDER
51
+ isReceiving = typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
52
+ typeId == _TYPEID_LSP8_TOKENSRECIPIENT
38
53
  ? true
39
54
  : false;
40
55
  } else {
41
56
  arrayKey = _LSP10_VAULTS_ARRAY_KEY;
42
57
  mapPrefix = _LSP10_VAULTS_MAP_KEY_PREFIX;
43
58
  interfaceId = _INTERFACEID_LSP9;
44
- senderHook = typeId == _TYPEID_LSP9_VAULTSENDER ? true : false;
59
+ isReceiving = typeId == _TYPEID_LSP9_VAULTRECIPIENT ? true : false;
45
60
  }
46
61
  }
47
62
  }
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ /**
5
+ * @dev reverts when `value` is not a properly ABI encoded array
6
+ * @param value the value to check for an abi-encoded array
7
+ * @param valueType the type of the value to check for an abi-encoded array
8
+ */
9
+ error InvalidABIEncodedArray(bytes value, string valueType);