This repository has been archived by the owner on Oct 5, 2022. It is now read-only.
/
LSP3Account.sol
114 lines (90 loc) · 3.21 KB
/
LSP3Account.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-License-Identifier: Apache-2.0
/*
* @title ERC725Account implementation for LUKSO
* @author Fabian Vogelsteller <fabian@lukso.network>
*
* @dev Implementation of the ERC725Account + LSP1 universalReceiver
*/
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
// interfaces
import "../_LSPs/ILSP1_UniversalReceiver.sol";
import "../_LSPs/ILSP1_UniversalReceiverDelegate.sol";
// modules
import "erc725/contracts/ERC725/ERC725Account.sol";
import "@openzeppelin/contracts/introspection/ERC165.sol";
contract LSP3Account is ERC165, ERC725Account, ILSP1 {
bytes4 _INTERFACE_ID_LSP1 = 0x6bb56a14;
bytes4 _INTERFACE_ID_LSP1DELEGATE = 0xc2d7bcc1;
bytes32 constant private _UNIVERSAL_RECEIVER_DELEGATE_KEY =
0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47; // keccak256("LSP1UniversalReceiverDelegate")
bytes32[] public dataKeys;
constructor(address _newOwner) ERC725Account(_newOwner) public {
// Add the key of the SupportedStandards:ERC725Account set in the constructor of ERC725Account.sol
dataKeys.push(0xeafec4d89fa9619884b6b89135626455000000000000000000000000afdeb5d6);
_registerInterface(_INTERFACE_ID_LSP1);
}
/* non-standard public functions */
function dataCount() public view returns (uint256) {
return dataKeys.length;
}
function allDataKeys() public view returns (bytes32[] memory) {
return dataKeys;
}
function setDataMultiple(bytes32[] calldata _keys, bytes[] calldata _values)
public
onlyOwner
{
for (uint256 i = 0; i < _keys.length; i++) {
setData(_keys[i], _values[i]);
}
}
function getDataMultiple(bytes32[] calldata _keys)
public
view
returns(bytes[] memory)
{
uint256 length = _keys.length;
bytes[] memory values = new bytes[](length);
for (uint256 i=0; i < length; i++) {
values[i] = getData(_keys[i]);
}
return values;
}
/* Public functions */
function setData(bytes32 _key, bytes calldata _value)
public
override
onlyOwner
{
if(store[_key].length == 0) {
dataKeys.push(_key); // 30k more gas on initial set
}
store[_key] = _value;
emit DataChanged(_key, _value);
}
/**
* @notice Notify the smart contract about any received asset
* LSP1 interface
* @param _typeId The type of transfer received
* @param _data The data received
*/
function universalReceiver(bytes32 _typeId, bytes calldata _data)
external
override
virtual
returns (bytes32 returnValue)
{
bytes memory receiverData = getData(_UNIVERSAL_RECEIVER_DELEGATE_KEY);
returnValue = "";
// call external contract
if (receiverData.length == 20) {
address universalReceiverAddress = BytesLib.toAddress(receiverData, 0);
if(ERC165(universalReceiverAddress).supportsInterface(_INTERFACE_ID_LSP1DELEGATE)) {
returnValue = ILSP1Delegate(universalReceiverAddress).universalReceiverDelegate(_msgSender(), _typeId, _data);
}
}
emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
return returnValue;
}
}