-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: upgrade OZ and erc725-sc packages * feat: add LSP0ERC725Account contracts * feat: add ERC725Utils and Utils lib * fix: remove unused parameter in ERC725Utils * fix: fix import path in LSP6Utils * feat: add InitAbstract contracts After OZ breaking change concerning how to initialize proxies, InitAbstract contracts are for inheritance and normal Init contracts are for deploying * test: fix events name failing tests name of the args of the events changed, so we changed them in the tests * test: rename to LSP0ERC725Account test * fix: fix OZ initialize breaking change * fix: fix path importing conflicts * docs: add generated docs * build: upgrade package-lock.json * refactor: use IERC1271 from OZ-contracts * docs: add generated docs
- Loading branch information
1 parent
9d46299
commit 6c11e54
Showing
141 changed files
with
7,219 additions
and
937 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
// >> INTERFACES | ||
|
||
bytes4 constant _INTERFACE_ID_ERC725ACCOUNT = 0x63cb749b; | ||
|
||
bytes4 constant _INTERFACE_ID_ERC1271 = 0x1626ba7e; | ||
|
||
// >> OTHER | ||
|
||
// ERC1271 - Standard Signature Validation | ||
bytes4 constant _ERC1271MAGICVALUE = 0x1626ba7e; | ||
bytes4 constant _ERC1271FAILVALUE = 0xffffffff; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
// modules | ||
import "./LSP0ERC725AccountCore.sol"; | ||
import "@erc725/smart-contracts/contracts/ERC725.sol"; | ||
|
||
/** | ||
* @title Implementation of ERC725Account | ||
* @author Fabian Vogelsteller <[email protected]>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi) | ||
* @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens | ||
*/ | ||
contract LSP0ERC725Account is ERC725, LSP0ERC725AccountCore { | ||
/** | ||
* @notice Sets the owner of the contract and register ERC725Account, ERC1271 and LSP1UniversalReceiver interfacesId | ||
* @param _newOwner the owner of the contract | ||
*/ | ||
constructor(address _newOwner) ERC725(_newOwner) { | ||
_registerInterface(_INTERFACE_ID_ERC725ACCOUNT); | ||
_registerInterface(_INTERFACE_ID_ERC1271); | ||
_registerInterface(_INTERFACEID_LSP1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
// interfaces | ||
import "@openzeppelin/contracts/interfaces/IERC1271.sol"; | ||
import "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol"; | ||
import "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol"; | ||
|
||
// modules | ||
|
||
import "@erc725/smart-contracts/contracts/ERC725YCore.sol"; | ||
import "@erc725/smart-contracts/contracts/ERC725XCore.sol"; | ||
|
||
// libraries | ||
import "../Utils/UtilsLib.sol"; | ||
import "../Utils/ERC725Utils.sol"; | ||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
|
||
// constants | ||
import "../LSP1UniversalReceiver/LSP1Constants.sol"; | ||
import "../LSP0ERC725Account/LSP0Constants.sol"; | ||
|
||
/** | ||
* @title Core Implementation of ERC725Account | ||
* @author Fabian Vogelsteller <[email protected]>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi) | ||
* @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens | ||
*/ | ||
abstract contract LSP0ERC725AccountCore is | ||
ERC725XCore, | ||
ERC725YCore, | ||
ILSP1UniversalReceiver, | ||
IERC1271 | ||
{ | ||
using ERC725Utils for IERC725Y; | ||
|
||
event ValueReceived(address indexed sender, uint256 indexed value); | ||
|
||
receive() external payable { | ||
emit ValueReceived(_msgSender(), msg.value); | ||
} | ||
|
||
// TODO to be discussed | ||
// function fallback() | ||
// public | ||
// { | ||
// address to = owner(); | ||
// assembly { | ||
// calldatacopy(0, 0, calldatasize()) | ||
// let result := staticcall(gas(), to, 0, calldatasize(), 0, 0) | ||
// returndatacopy(0, 0, returndatasize()) | ||
// switch result | ||
// case 0 { revert (0, returndatasize()) } | ||
// default { return (0, returndatasize()) } | ||
// } | ||
// } | ||
|
||
/** | ||
* @notice Checks if an owner signed `_data`. | ||
* ERC1271 interface. | ||
* | ||
* @param _hash hash of the data signed//Arbitrary length data signed on the behalf of address(this) | ||
* @param _signature owner's signature(s) of the data | ||
*/ | ||
function isValidSignature(bytes32 _hash, bytes memory _signature) | ||
public | ||
view | ||
override | ||
returns (bytes4 magicValue) | ||
{ | ||
// prettier-ignore | ||
// if OWNER is a contract | ||
if (UtilsLib.isContract(owner())) { | ||
return | ||
supportsInterface(_INTERFACE_ID_ERC1271) | ||
? IERC1271(owner()).isValidSignature(_hash, _signature) | ||
: _ERC1271FAILVALUE; | ||
// if OWNER is a key | ||
} else { | ||
return | ||
owner() == ECDSA.recover(_hash, _signature) | ||
? _INTERFACE_ID_ERC1271 | ||
: _ERC1271FAILVALUE; | ||
} | ||
} | ||
|
||
function universalReceiver(bytes32 _typeId, bytes calldata _data) | ||
external | ||
virtual | ||
override | ||
returns (bytes memory returnValue) | ||
{ | ||
bytes memory receiverData = IERC725Y(this).getDataSingle( | ||
_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY | ||
); | ||
returnValue = ""; | ||
|
||
// call external contract | ||
if (receiverData.length == 20) { | ||
address universalReceiverAddress = BytesLib.toAddress( | ||
receiverData, | ||
0 | ||
); | ||
|
||
if ( | ||
ERC165(universalReceiverAddress).supportsInterface( | ||
_INTERFACEID_LSP1_DELEGATE | ||
) | ||
) { | ||
returnValue = ILSP1UniversalReceiverDelegate( | ||
universalReceiverAddress | ||
).universalReceiverDelegate(_msgSender(), _typeId, _data); | ||
} | ||
} | ||
|
||
emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data); | ||
|
||
return returnValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
// modules | ||
import "./LSP0ERC725AccountInitAbstract.sol"; | ||
|
||
/** | ||
* @title Deployable Proxy Implementation of ERC725Account | ||
* @author Fabian Vogelsteller <[email protected]>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi) | ||
* @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens | ||
*/ | ||
contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract { | ||
/** | ||
* @inheritdoc LSP0ERC725AccountInitAbstract | ||
*/ | ||
|
||
function initialize(address _newOwner) public virtual override initializer { | ||
LSP0ERC725AccountInitAbstract.initialize(_newOwner); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
// modules | ||
import "@erc725/smart-contracts/contracts/ERC725InitAbstract.sol"; | ||
import "./LSP0ERC725AccountCore.sol"; | ||
|
||
/** | ||
* @title Inheritable Proxy Implementation of ERC725Account | ||
* @author Fabian Vogelsteller <[email protected]>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi) | ||
* @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens | ||
*/ | ||
abstract contract LSP0ERC725AccountInitAbstract is | ||
ERC725InitAbstract, | ||
LSP0ERC725AccountCore | ||
{ | ||
/** | ||
* @notice Sets the owner of the contract and register ERC725Account, ERC1271 and LSP1UniversalReceiver interfacesId | ||
* @param _newOwner the owner of the contract | ||
*/ | ||
function initialize(address _newOwner) | ||
public | ||
virtual | ||
override | ||
onlyInitializing | ||
{ | ||
ERC725InitAbstract.initialize(_newOwner); | ||
|
||
_registerInterface(_INTERFACE_ID_ERC725ACCOUNT); | ||
_registerInterface(_INTERFACE_ID_ERC1271); | ||
_registerInterface(_INTERFACEID_LSP1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.