Skip to content

Commit fe356a3

Browse files
authored
Migrate contracts to Diamond pattern - Part1 (#222)
2 parents 86ed12a + cd1ef4d commit fe356a3

20 files changed

+297
-261
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
## vNEXT
44

5+
- Migrate contracts to Diamond pattern - Part1 (#222)
56
- Add Github Action CI in order to publish NPM package
67

78
### Updated contracts
89

910
- [x] `IexecPoco2Delegate.sol`
1011

1112
### Features
13+
<!-- TODO update this with v5.5.1 release notes -->
1214
- Add gitub action workflow for deployment (#218)
1315
- Fix new testnets chain name (#217)
1416
- Deploy on new testnet chains using CreateX factory (#216)
1517
- Add CreateX factory for new chain deployment (#215)
1618
- Support Arbitrum & Avalanche Fuji testnets (#215)
17-
- Housekeeping (#207, )
19+
- Housekeeping (#208)
1820
- Add Halborn "Poco v5.5 & Voucher v1.0" audit report (#205)
1921
- Refactor Factory deployer (#206)
2022
- Enable native tests on CI (#204)

contracts/Store.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pragma solidity ^0.6.0;
55

66
import "@iexec/interface/contracts/IexecHub.sol";
77
import "@iexec/solidity/contracts/Libs/SafeMathExtended.sol";
8-
import "@iexec/solidity/contracts/ERC1538/ERC1538Store.sol";
98
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
109

1110
import "./libs/IexecLibCore_v5.sol";
@@ -21,10 +20,12 @@ import "./registries/IRegistry.sol";
2120
* If you want add new variables for expanded features, add them at the *
2221
* end, or (better?) create a Store_v2 that inherits from this Store. *
2322
* *
24-
* If in doubt, read about ERC1538 memory store. *
23+
* If in doubt, read about Diamond proxy storage. *
2524
****************************************************************************/
2625

27-
abstract contract Store is ERC1538Store
26+
// TODO replace with diamond AppStorage using namespaced storage.
27+
// TODO check storage padding.
28+
abstract contract Store
2829
{
2930
// Registries
3031
IRegistry internal m_appregistry;

contracts/Store.v8.sol

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,24 @@ import {IexecLibCore_v5} from "./libs/IexecLibCore_v5.sol";
1414
* If you want add new variables for expanded features, add them at the *
1515
* end, or (better?) create a Store_v2 that inherits from this Store. *
1616
* *
17-
* If in doubt, read about ERC1538 memory store. *
17+
* If in doubt, read about Diamond proxy storage. *
1818
****************************************************************************/
1919

20-
/// @dev Solstruct translation for v0.8.0
21-
library LibSet_bytes4 {
22-
struct set {
23-
bytes4[] values;
24-
mapping(bytes4 => uint256) indexes;
25-
}
26-
}
27-
28-
library LibMap2_bytes4_address_bytes {
29-
struct map {
30-
LibSet_bytes4.set keyset;
31-
mapping(bytes4 => address) values1;
32-
mapping(bytes4 => bytes) values2;
33-
}
34-
}
35-
36-
/// @dev @iexec/solidity ERC1538
37-
abstract contract ERC1538Store is Ownable {
38-
LibMap2_bytes4_address_bytes.map internal m_funcs;
39-
}
40-
4120
/// @dev registries
4221
interface IRegistry is IERC721Enumerable {
4322
function isRegistered(address _entry) external view returns (bool);
4423
}
4524

4625
/// @dev Poco store
4726
/**
48-
* @title Central storage of all modules contracts. It follows the transparent
49-
* contract standard aka ERC-1538.
27+
* @title Central storage of all modules contracts. It follows the Diamond
28+
* pattern aka ERC-2535.
5029
* @dev note the new added state variable "m_dealsBoost" that holds a new type
5130
* of deals for the PoCo Boost workflow.
5231
*/
53-
abstract contract Store is ERC1538Store {
32+
// TODO replace with diamond AppStorage using namespaced storage.
33+
// TODO check storage padding.
34+
abstract contract Store {
5435
// Registries
5536
//slither-disable-next-line constable-states
5637
IRegistry internal m_appregistry;

contracts/modules/DelegateBase.sol

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,27 @@
33

44
pragma solidity ^0.6.0;
55

6-
import "@iexec/solidity/contracts/ERC1538/ERC1538Module.sol";
76
import "../Store.sol";
7+
import "./interfaces/IOwnable.sol";
88

9-
abstract contract DelegateBase is Store, ERC1538Module {}
9+
// Functions that were declared in ERC1538Store are re-declared here.
10+
// TODO clean this (use LibDiamond)
11+
// - All calls to `owner()` should use `LibDiamond.contractOwner()`.
12+
// TODO rename this contract to `FacetBase`.
13+
14+
abstract contract DelegateBase is Store {
15+
16+
modifier onlyOwner() {
17+
require(_msgSender() == owner(), "Ownable: caller is not the owner");
18+
_;
19+
}
20+
21+
function owner() public view returns (address) {
22+
return IOwnable(address(this)).owner();
23+
}
24+
25+
function _msgSender() internal view returns (address ) {
26+
return msg.sender;
27+
}
28+
29+
}

contracts/modules/DelegateBase.v8.sol

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33

44
pragma solidity ^0.8.0;
55

6-
import {Ownable} from "@openzeppelin/contracts-v5/access/Ownable.sol";
7-
6+
import {IERC5313} from "@openzeppelin/contracts-v5/interfaces/IERC5313.sol";
87
import {Store} from "../Store.v8.sol";
98

9+
// Functions that were declared in ERC1538Store are re-declared here.
10+
// TODO clean this (use LibDiamond)
11+
// - All calls to `owner()` should use `LibDiamond.contractOwner()`.
12+
// TODO rename this contract to `FacetBase`.
13+
1014
/**
1115
* @title Base contract of all Delegate contracts.
1216
* @dev Every module must inherit from this contract.
1317
*/
1418
abstract contract DelegateBase is Store {
15-
/**
16-
* @dev Constructor used by all PoCo modules.
17-
*/
18-
constructor() Ownable(msg.sender) {
19-
renounceOwnership();
19+
modifier onlyOwner() {
20+
require(_msgSender() == owner(), "Ownable: caller is not the owner");
21+
_;
22+
}
23+
24+
function owner() public view returns (address) {
25+
// Make an external call to delegatecall the OwnershipFacet.
26+
return IERC5313(address(this)).owner();
27+
}
28+
29+
function _msgSender() internal view returns (address ) {
30+
return msg.sender;
2031
}
2132
}

contracts/modules/delegates/ENSIntegrationDelegate.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import "@iexec/solidity/contracts/ENStools/ENSReverseRegistration.sol";
2323
import "../DelegateBase.sol";
2424
import "../interfaces/ENSIntegration.sol";
2525

26-
26+
// TODO don't deploy this as ENSReverseRegistration.ADDR_REVERSE_NODE is not defined on Arbitrum.
27+
// TODO update this to use ENS on Arbitrum (update everywhere this is used).
2728
contract ENSIntegrationDelegate is ENSIntegration, ENSReverseRegistration, DelegateBase
2829
{
2930
function setName(address _ens, string calldata _name)

contracts/modules/delegates/IexecMaintenanceDelegate.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
99
import "../DelegateBase.sol";
1010
import "../interfaces/IexecMaintenance.sol";
1111

12-
1312
contract IexecMaintenanceDelegate is IexecMaintenance, DelegateBase
1413
{
1514
using SafeMathExtended for uint256;
1615
using IexecLibOrders_v5 for IexecLibOrders_v5.EIP712Domain;
1716

17+
// TODO move this to DiamondInit.init().
1818
function configure(
1919
address _token,
2020
string calldata _name,

contracts/modules/delegates/IexecPoco2Delegate.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ contract IexecPoco2Delegate is IexecPoco2, DelegateBase, IexecEscrow, SignatureV
100100
return taskid;
101101
}
102102

103-
// TODO / COMPILER ERROR: making it external causes "stack too deep" error
104103
function contribute(
105104
bytes32 _taskid,
106105
bytes32 _resultHash,
@@ -175,7 +174,6 @@ contract IexecPoco2Delegate is IexecPoco2, DelegateBase, IexecEscrow, SignatureV
175174
checkConsensus(_taskid, _resultHash);
176175
}
177176

178-
// TODO / COMPILER ERROR: making it external causes "stack too deep" error
179177
function contributeAndFinalize(
180178
bytes32 _taskid,
181179
bytes32 _resultDigest,

contracts/registries/Registry.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ abstract contract Registry is IRegistry, ERC721, ENSReverseRegistration, Ownable
7474
function setName(address _ens, string calldata _name)
7575
external onlyOwner()
7676
{
77+
// TODO update this as ENSReverseRegistration.ADDR_REVERSE_NODE is not defined on Arbitrum.
7778
_setName(IENS(_ens), _name);
7879
}
7980

contracts/registries/RegistryEntry.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ abstract contract RegistryEntry is ENSReverseRegistration
4646
function setName(address _ens, string calldata _name)
4747
external onlyOwner()
4848
{
49+
// TODO update this as ENSReverseRegistration.ADDR_REVERSE_NODE is not defined on Arbitrum.
4950
_setName(IENS(_ens), _name);
5051
}
5152
}

0 commit comments

Comments
 (0)