Skip to content

Commit 4376b26

Browse files
authored
feat: use storage lib (#243)
* Refactor Poco storage management: Introduce LibPocoStorage for improved storage handling and access patterns across facets * refactor: LibPocoStorage: Replace getter functions with direct access to constants * refactor: Update function signatures for owner and _msgSender in FacetBase and adjust LibPocoStorage access in related facets * refactor: Remove unused storage access helper functions from FacetBase * refactor: reduce the diff * refactor: reorganize imports and clean up comments in LibPocoStorage * refactor: remove duplicate import of FacetBase in SignatureVerifier * chore: update changelog for vNEXT with storage library usage * refactor: migrate constants from LibPocoStorage to FacetBase and update references * refactor: change LibPocoStorage to PocoStorageLib
1 parent 11b00d0 commit 4376b26

30 files changed

+164
-146
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Save IexecLibOrders_v5 in config file (#242)
66
- Migrate proxy to Diamond pattern (ERC-2535):
7+
- Use lib as storage. (#243)
78
- Restore compatibility with iExec SDK. (#240)
89
- Target latest EVM version (#239)
910
- Adapt contracts file tree (#238)

contracts/facets/FacetBase.sol

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

44
pragma solidity ^0.6.0;
55

6-
import "../Store.sol";
6+
import "../libs/PocoStorageLib.sol";
77
import "../interfaces/IOwnable.sol";
88

99
// Functions that were declared in ERC1538Store are re-declared here.
@@ -13,7 +13,23 @@ import "../interfaces/IOwnable.sol";
1313
* @title Base contract of all Facet contracts.
1414
* @dev Every facet must inherit from this contract.
1515
*/
16-
abstract contract FacetBase is Store {
16+
abstract contract FacetBase {
17+
// Poco - Constants
18+
uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7;
19+
uint256 public constant REVEAL_DEADLINE_RATIO = 2;
20+
uint256 public constant FINAL_DEADLINE_RATIO = 10;
21+
uint256 public constant WORKERPOOL_STAKE_RATIO = 30;
22+
uint256 public constant KITTY_RATIO = 10;
23+
uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE
24+
25+
// Seized funds of workerpools that do not honor their deals are sent
26+
// out to this kitty address.
27+
// It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1).
28+
address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;
29+
30+
// Used with ERC-734 Key Manager identity contract for authorization management.
31+
uint256 public constant GROUPMEMBER_PURPOSE = 4;
32+
1733
modifier onlyOwner() {
1834
require(_msgSender() == owner(), "Ownable: caller is not the owner");
1935
_;

contracts/facets/FacetBase.v8.sol

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pragma solidity ^0.8.0;
55

66
import {IERC5313} from "@openzeppelin/contracts-v5/interfaces/IERC5313.sol";
7-
import {Store} from "../Store.v8.sol";
7+
import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol";
88

99
// Functions that were declared in ERC1538Store are re-declared here.
1010
// TODO use LibDiamond.contractOwner() when migrating all contracts to v8.
@@ -13,7 +13,23 @@ import {Store} from "../Store.v8.sol";
1313
* @title Base contract of all Facet contracts.
1414
* @dev Every facet must inherit from this contract.
1515
*/
16-
abstract contract FacetBase is Store {
16+
abstract contract FacetBase {
17+
// Poco - Constants
18+
uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7;
19+
uint256 public constant REVEAL_DEADLINE_RATIO = 2;
20+
uint256 public constant FINAL_DEADLINE_RATIO = 10;
21+
uint256 public constant WORKERPOOL_STAKE_RATIO = 30;
22+
uint256 public constant KITTY_RATIO = 10;
23+
uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE
24+
25+
// Seized funds of workerpools that do not honor their deals are sent
26+
// out to this kitty address.
27+
// It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1).
28+
address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23;
29+
30+
// Used with ERC-734 Key Manager identity contract for authorization management.
31+
uint256 public constant GROUPMEMBER_PURPOSE = 4;
32+
1733
modifier onlyOwner() {
1834
require(_msgSender() == owner(), "Ownable: caller is not the owner");
1935
_;

contracts/facets/IexecAccessorsABILegacyFacet.sol

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2;
66

77
import "./FacetBase.sol";
88
import "../interfaces/IexecAccessorsABILegacy.sol";
9+
import {PocoStorageLib} from "../libs/PocoStorageLib.sol";
910

1011
contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
1112
function viewDealABILegacy_pt1(
@@ -16,7 +17,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
1617
override
1718
returns (address, address, uint256, address, address, uint256, address, address, uint256)
1819
{
19-
PocoStorage storage $ = getPocoStorage();
20+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
2021
IexecLibCore_v5.Deal memory deal = $.m_deals[_id];
2122
return (
2223
deal.app.pointer,
@@ -34,15 +35,15 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
3435
function viewDealABILegacy_pt2(
3536
bytes32 _id
3637
) external view override returns (uint256, bytes32, address, address, address, string memory) {
37-
PocoStorage storage $ = getPocoStorage();
38+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
3839
IexecLibCore_v5.Deal memory deal = $.m_deals[_id];
3940
return (deal.trust, deal.tag, deal.requester, deal.beneficiary, deal.callback, deal.params);
4041
}
4142

4243
function viewConfigABILegacy(
4344
bytes32 _id
4445
) external view override returns (uint256, uint256, uint256, uint256, uint256, uint256) {
45-
PocoStorage storage $ = getPocoStorage();
46+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
4647
IexecLibCore_v5.Deal memory deal = $.m_deals[_id];
4748
return (
4849
deal.category,
@@ -57,7 +58,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
5758
function viewAccountABILegacy(
5859
address account
5960
) external view override returns (uint256, uint256) {
60-
PocoStorage storage $ = getPocoStorage();
61+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
6162
return ($.m_balances[account], $.m_frozens[account]);
6263
}
6364

@@ -83,7 +84,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
8384
)
8485
{
8586
/// @dev Using $.m_tasks causes "Stack too deep" error.
86-
IexecLibCore_v5.Task memory task = getPocoStorage().m_tasks[_taskid];
87+
IexecLibCore_v5.Task memory task = PocoStorageLib.getPocoStorage().m_tasks[_taskid];
8788
return (
8889
task.status,
8990
task.dealid,
@@ -109,7 +110,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
109110
override
110111
returns (IexecLibCore_v5.ContributionStatusEnum, bytes32, bytes32, address)
111112
{
112-
PocoStorage storage $ = getPocoStorage();
113+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
113114
IexecLibCore_v5.Contribution memory contribution = $.m_contributions[_taskid][_worker];
114115
return (
115116
contribution.status,
@@ -122,7 +123,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase {
122123
function viewCategoryABILegacy(
123124
uint256 _catid
124125
) external view override returns (string memory, string memory, uint256) {
125-
PocoStorage storage $ = getPocoStorage();
126+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
126127
IexecLibCore_v5.Category memory category = $.m_categories[_catid];
127128
return (category.name, category.description, category.workClockTimeRef);
128129
}

contracts/facets/IexecAccessorsFacet.sol

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,94 +6,95 @@ pragma experimental ABIEncoderV2;
66

77
import "./FacetBase.sol";
88
import "../interfaces/IexecAccessors.sol";
9+
import {PocoStorageLib} from "../libs/PocoStorageLib.sol";
910

1011
contract IexecAccessorsFacet is IexecAccessors, FacetBase {
1112
function name() external view override returns (string memory) {
12-
PocoStorage storage $ = getPocoStorage();
13+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
1314
return $.m_name;
1415
}
1516

1617
function symbol() external view override returns (string memory) {
17-
PocoStorage storage $ = getPocoStorage();
18+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
1819
return $.m_symbol;
1920
}
2021

2122
function decimals() external view override returns (uint8) {
22-
PocoStorage storage $ = getPocoStorage();
23+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
2324
return $.m_decimals;
2425
}
2526

2627
function totalSupply() external view override returns (uint256) {
27-
PocoStorage storage $ = getPocoStorage();
28+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
2829
return $.m_totalSupply;
2930
}
3031

3132
function balanceOf(address account) external view override returns (uint256) {
32-
PocoStorage storage $ = getPocoStorage();
33+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
3334
return $.m_balances[account];
3435
}
3536

3637
function frozenOf(address account) external view override returns (uint256) {
37-
PocoStorage storage $ = getPocoStorage();
38+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
3839
return $.m_frozens[account];
3940
}
4041

4142
function allowance(address account, address spender) external view override returns (uint256) {
42-
PocoStorage storage $ = getPocoStorage();
43+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
4344
return $.m_allowances[account][spender];
4445
}
4546

4647
function viewAccount(
4748
address account
4849
) external view override returns (IexecLibCore_v5.Account memory) {
49-
PocoStorage storage $ = getPocoStorage();
50+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
5051
return IexecLibCore_v5.Account($.m_balances[account], $.m_frozens[account]);
5152
}
5253

5354
function token() external view override returns (address) {
54-
PocoStorage storage $ = getPocoStorage();
55+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
5556
return address($.m_baseToken);
5657
}
5758

5859
function viewDeal(
5960
bytes32 _id
6061
) external view override returns (IexecLibCore_v5.Deal memory deal) {
61-
PocoStorage storage $ = getPocoStorage();
62+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
6263
return $.m_deals[_id];
6364
}
6465

6566
function viewConsumed(bytes32 _id) external view override returns (uint256 consumed) {
66-
PocoStorage storage $ = getPocoStorage();
67+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
6768
return $.m_consumed[_id];
6869
}
6970

7071
function viewPresigned(bytes32 _id) external view override returns (address signer) {
71-
PocoStorage storage $ = getPocoStorage();
72+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
7273
return $.m_presigned[_id];
7374
}
7475

7576
function viewTask(
7677
bytes32 _taskid
7778
) external view override returns (IexecLibCore_v5.Task memory) {
78-
PocoStorage storage $ = getPocoStorage();
79+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
7980
return $.m_tasks[_taskid];
8081
}
8182

8283
function viewContribution(
8384
bytes32 _taskid,
8485
address _worker
8586
) external view override returns (IexecLibCore_v5.Contribution memory) {
86-
PocoStorage storage $ = getPocoStorage();
87+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
8788
return $.m_contributions[_taskid][_worker];
8889
}
8990

9091
function viewScore(address _worker) external view override returns (uint256) {
91-
PocoStorage storage $ = getPocoStorage();
92+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
9293
return $.m_workerScores[_worker];
9394
}
9495

9596
function resultFor(bytes32 id) external view override returns (bytes memory) {
96-
PocoStorage storage $ = getPocoStorage();
97+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
9798
IexecLibCore_v5.Task storage task = $.m_tasks[id];
9899
require(task.status == IexecLibCore_v5.TaskStatusEnum.COMPLETED, "task-pending");
99100
return task.resultsCallback; // Expansion - result separation
@@ -102,37 +103,37 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase {
102103
function viewCategory(
103104
uint256 _catid
104105
) external view override returns (IexecLibCore_v5.Category memory category) {
105-
PocoStorage storage $ = getPocoStorage();
106+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
106107
return $.m_categories[_catid];
107108
}
108109

109110
function countCategory() external view override returns (uint256 count) {
110-
PocoStorage storage $ = getPocoStorage();
111+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
111112
return $.m_categories.length;
112113
}
113114

114115
function appregistry() external view override returns (IRegistry) {
115-
PocoStorage storage $ = getPocoStorage();
116+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
116117
return $.m_appregistry;
117118
}
118119

119120
function datasetregistry() external view override returns (IRegistry) {
120-
PocoStorage storage $ = getPocoStorage();
121+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
121122
return $.m_datasetregistry;
122123
}
123124

124125
function workerpoolregistry() external view override returns (IRegistry) {
125-
PocoStorage storage $ = getPocoStorage();
126+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
126127
return $.m_workerpoolregistry;
127128
}
128129

129130
function teebroker() external view override returns (address) {
130-
PocoStorage storage $ = getPocoStorage();
131+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
131132
return $.m_teebroker;
132133
}
133134

134135
function callbackgas() external view override returns (uint256) {
135-
PocoStorage storage $ = getPocoStorage();
136+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
136137
return $.m_callbackgas;
137138
}
138139

@@ -169,7 +170,7 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase {
169170
}
170171

171172
function eip712domain_separator() external view override returns (bytes32) {
172-
PocoStorage storage $ = getPocoStorage();
173+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
173174
return $.m_eip712DomainSeparator;
174175
}
175176
}

contracts/facets/IexecCategoryManagerFacet.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.6.0;
55
pragma experimental ABIEncoderV2;
66

77
import "./FacetBase.sol";
8+
import {PocoStorageLib} from "../libs/PocoStorageLib.sol";
89
import "../interfaces/IexecCategoryManager.sol";
910

1011
contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase {
@@ -16,7 +17,7 @@ contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase {
1617
string calldata description,
1718
uint256 workClockTimeRef
1819
) external override onlyOwner returns (uint256) {
19-
PocoStorage storage $ = getPocoStorage();
20+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
2021
$.m_categories.push(IexecLibCore_v5.Category(name, description, workClockTimeRef));
2122

2223
uint256 catid = $.m_categories.length - 1;

contracts/facets/IexecConfigurationExtraFacet.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ pragma experimental ABIEncoderV2;
66

77
import "./FacetBase.sol";
88
import "../interfaces/IexecConfigurationExtra.sol";
9+
import {PocoStorageLib} from "../libs/PocoStorageLib.sol";
910

1011
contract IexecConfigurationExtraFacet is IexecConfigurationExtra, FacetBase {
1112
function changeRegistries(
1213
address _appregistryAddress,
1314
address _datasetregistryAddress,
1415
address _workerpoolregistryAddress
1516
) external override onlyOwner {
16-
PocoStorage storage $ = getPocoStorage();
17+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
1718
$.m_appregistry = IRegistry(_appregistryAddress);
1819
$.m_datasetregistry = IRegistry(_datasetregistryAddress);
1920
$.m_workerpoolregistry = IRegistry(_workerpoolregistryAddress);

contracts/facets/IexecConfigurationFacet.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
88

99
import "./FacetBase.sol";
1010
import "../interfaces/IexecConfiguration.sol";
11+
import {PocoStorageLib} from "../libs/PocoStorageLib.sol";
1112

1213
contract IexecConfigurationFacet is IexecConfiguration, FacetBase {
1314
using SafeMathExtended for uint256;
@@ -24,10 +25,9 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase {
2425
address _workerpoolregistryAddress,
2526
address _v3_iexecHubAddress
2627
) external override onlyOwner {
27-
PocoStorage storage $ = getPocoStorage();
28+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
2829
require($.m_eip712DomainSeparator == bytes32(0), "already-configured");
2930
$.m_eip712DomainSeparator = _domain().hash();
30-
3131
$.m_baseToken = IERC20(_token);
3232
$.m_name = _name;
3333
$.m_symbol = _symbol;
@@ -44,13 +44,13 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase {
4444
}
4545

4646
function updateDomainSeparator() external override {
47-
PocoStorage storage $ = getPocoStorage();
47+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
4848
require($.m_eip712DomainSeparator != bytes32(0), "not-configured");
4949
$.m_eip712DomainSeparator = _domain().hash();
5050
}
5151

5252
function importScore(address _worker) external override {
53-
PocoStorage storage $ = getPocoStorage();
53+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
5454
require(!$.m_v3_scoreImported[_worker], "score-already-imported");
5555
$.m_workerScores[_worker] = $.m_workerScores[_worker].max(
5656
$.m_v3_iexecHub.viewScore(_worker)
@@ -59,12 +59,12 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase {
5959
}
6060

6161
function setTeeBroker(address _teebroker) external override onlyOwner {
62-
PocoStorage storage $ = getPocoStorage();
62+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
6363
$.m_teebroker = _teebroker;
6464
}
6565

6666
function setCallbackGas(uint256 _callbackgas) external override onlyOwner {
67-
PocoStorage storage $ = getPocoStorage();
67+
PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage();
6868
$.m_callbackgas = _callbackgas;
6969
}
7070

0 commit comments

Comments
 (0)