diff --git a/CHANGELOG.md b/CHANGELOG.md index 7115e1c55..099312ab7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Save IexecLibOrders_v5 in config file (#242) - Migrate proxy to Diamond pattern (ERC-2535): + - Use lib as storage. (#243) - Restore compatibility with iExec SDK. (#240) - Target latest EVM version (#239) - Adapt contracts file tree (#238) diff --git a/contracts/facets/FacetBase.sol b/contracts/facets/FacetBase.sol index bc73b9436..10c164261 100644 --- a/contracts/facets/FacetBase.sol +++ b/contracts/facets/FacetBase.sol @@ -3,7 +3,7 @@ pragma solidity ^0.6.0; -import "../Store.sol"; +import "../libs/PocoStorageLib.sol"; import "../interfaces/IOwnable.sol"; // Functions that were declared in ERC1538Store are re-declared here. @@ -13,7 +13,23 @@ import "../interfaces/IOwnable.sol"; * @title Base contract of all Facet contracts. * @dev Every facet must inherit from this contract. */ -abstract contract FacetBase is Store { +abstract contract FacetBase { + // Poco - Constants + uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7; + uint256 public constant REVEAL_DEADLINE_RATIO = 2; + uint256 public constant FINAL_DEADLINE_RATIO = 10; + uint256 public constant WORKERPOOL_STAKE_RATIO = 30; + uint256 public constant KITTY_RATIO = 10; + uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE + + // Seized funds of workerpools that do not honor their deals are sent + // out to this kitty address. + // It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1). + address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; + + // Used with ERC-734 Key Manager identity contract for authorization management. + uint256 public constant GROUPMEMBER_PURPOSE = 4; + modifier onlyOwner() { require(_msgSender() == owner(), "Ownable: caller is not the owner"); _; diff --git a/contracts/facets/FacetBase.v8.sol b/contracts/facets/FacetBase.v8.sol index 327f0527f..13d38a96f 100644 --- a/contracts/facets/FacetBase.v8.sol +++ b/contracts/facets/FacetBase.v8.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {IERC5313} from "@openzeppelin/contracts-v5/interfaces/IERC5313.sol"; -import {Store} from "../Store.v8.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; // Functions that were declared in ERC1538Store are re-declared here. // TODO use LibDiamond.contractOwner() when migrating all contracts to v8. @@ -13,7 +13,23 @@ import {Store} from "../Store.v8.sol"; * @title Base contract of all Facet contracts. * @dev Every facet must inherit from this contract. */ -abstract contract FacetBase is Store { +abstract contract FacetBase { + // Poco - Constants + uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7; + uint256 public constant REVEAL_DEADLINE_RATIO = 2; + uint256 public constant FINAL_DEADLINE_RATIO = 10; + uint256 public constant WORKERPOOL_STAKE_RATIO = 30; + uint256 public constant KITTY_RATIO = 10; + uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE + + // Seized funds of workerpools that do not honor their deals are sent + // out to this kitty address. + // It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1). + address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; + + // Used with ERC-734 Key Manager identity contract for authorization management. + uint256 public constant GROUPMEMBER_PURPOSE = 4; + modifier onlyOwner() { require(_msgSender() == owner(), "Ownable: caller is not the owner"); _; diff --git a/contracts/facets/IexecAccessorsABILegacyFacet.sol b/contracts/facets/IexecAccessorsABILegacyFacet.sol index 05fb18fcc..d275f9748 100644 --- a/contracts/facets/IexecAccessorsABILegacyFacet.sol +++ b/contracts/facets/IexecAccessorsABILegacyFacet.sol @@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2; import "./FacetBase.sol"; import "../interfaces/IexecAccessorsABILegacy.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewDealABILegacy_pt1( @@ -16,7 +17,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { override returns (address, address, uint256, address, address, uint256, address, address, uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_id]; return ( deal.app.pointer, @@ -34,7 +35,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewDealABILegacy_pt2( bytes32 _id ) external view override returns (uint256, bytes32, address, address, address, string memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_id]; return (deal.trust, deal.tag, deal.requester, deal.beneficiary, deal.callback, deal.params); } @@ -42,7 +43,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewConfigABILegacy( bytes32 _id ) external view override returns (uint256, uint256, uint256, uint256, uint256, uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_id]; return ( deal.category, @@ -57,7 +58,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewAccountABILegacy( address account ) external view override returns (uint256, uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return ($.m_balances[account], $.m_frozens[account]); } @@ -83,7 +84,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { ) { /// @dev Using $.m_tasks causes "Stack too deep" error. - IexecLibCore_v5.Task memory task = getPocoStorage().m_tasks[_taskid]; + IexecLibCore_v5.Task memory task = PocoStorageLib.getPocoStorage().m_tasks[_taskid]; return ( task.status, task.dealid, @@ -109,7 +110,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { override returns (IexecLibCore_v5.ContributionStatusEnum, bytes32, bytes32, address) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Contribution memory contribution = $.m_contributions[_taskid][_worker]; return ( contribution.status, @@ -122,7 +123,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewCategoryABILegacy( uint256 _catid ) external view override returns (string memory, string memory, uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Category memory category = $.m_categories[_catid]; return (category.name, category.description, category.workClockTimeRef); } diff --git a/contracts/facets/IexecAccessorsFacet.sol b/contracts/facets/IexecAccessorsFacet.sol index 1d7c73b59..f81003632 100644 --- a/contracts/facets/IexecAccessorsFacet.sol +++ b/contracts/facets/IexecAccessorsFacet.sol @@ -6,76 +6,77 @@ pragma experimental ABIEncoderV2; import "./FacetBase.sol"; import "../interfaces/IexecAccessors.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecAccessorsFacet is IexecAccessors, FacetBase { function name() external view override returns (string memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_name; } function symbol() external view override returns (string memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_symbol; } function decimals() external view override returns (uint8) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_decimals; } function totalSupply() external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_totalSupply; } function balanceOf(address account) external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_balances[account]; } function frozenOf(address account) external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_frozens[account]; } function allowance(address account, address spender) external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_allowances[account][spender]; } function viewAccount( address account ) external view override returns (IexecLibCore_v5.Account memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return IexecLibCore_v5.Account($.m_balances[account], $.m_frozens[account]); } function token() external view override returns (address) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return address($.m_baseToken); } function viewDeal( bytes32 _id ) external view override returns (IexecLibCore_v5.Deal memory deal) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_deals[_id]; } function viewConsumed(bytes32 _id) external view override returns (uint256 consumed) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_consumed[_id]; } function viewPresigned(bytes32 _id) external view override returns (address signer) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_presigned[_id]; } function viewTask( bytes32 _taskid ) external view override returns (IexecLibCore_v5.Task memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_tasks[_taskid]; } @@ -83,17 +84,17 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { bytes32 _taskid, address _worker ) external view override returns (IexecLibCore_v5.Contribution memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_contributions[_taskid][_worker]; } function viewScore(address _worker) external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_workerScores[_worker]; } function resultFor(bytes32 id) external view override returns (bytes memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[id]; require(task.status == IexecLibCore_v5.TaskStatusEnum.COMPLETED, "task-pending"); return task.resultsCallback; // Expansion - result separation @@ -102,37 +103,37 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { function viewCategory( uint256 _catid ) external view override returns (IexecLibCore_v5.Category memory category) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_categories[_catid]; } function countCategory() external view override returns (uint256 count) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_categories.length; } function appregistry() external view override returns (IRegistry) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_appregistry; } function datasetregistry() external view override returns (IRegistry) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_datasetregistry; } function workerpoolregistry() external view override returns (IRegistry) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_workerpoolregistry; } function teebroker() external view override returns (address) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_teebroker; } function callbackgas() external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_callbackgas; } @@ -169,7 +170,7 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { } function eip712domain_separator() external view override returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_eip712DomainSeparator; } } diff --git a/contracts/facets/IexecCategoryManagerFacet.sol b/contracts/facets/IexecCategoryManagerFacet.sol index f4203786b..195f3d391 100644 --- a/contracts/facets/IexecCategoryManagerFacet.sol +++ b/contracts/facets/IexecCategoryManagerFacet.sol @@ -5,6 +5,7 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; import "./FacetBase.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; import "../interfaces/IexecCategoryManager.sol"; contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase { @@ -16,7 +17,7 @@ contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase { string calldata description, uint256 workClockTimeRef ) external override onlyOwner returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_categories.push(IexecLibCore_v5.Category(name, description, workClockTimeRef)); uint256 catid = $.m_categories.length - 1; diff --git a/contracts/facets/IexecConfigurationExtraFacet.sol b/contracts/facets/IexecConfigurationExtraFacet.sol index eaf3e20d2..aa6f1de35 100644 --- a/contracts/facets/IexecConfigurationExtraFacet.sol +++ b/contracts/facets/IexecConfigurationExtraFacet.sol @@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2; import "./FacetBase.sol"; import "../interfaces/IexecConfigurationExtra.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecConfigurationExtraFacet is IexecConfigurationExtra, FacetBase { function changeRegistries( @@ -13,7 +14,7 @@ contract IexecConfigurationExtraFacet is IexecConfigurationExtra, FacetBase { address _datasetregistryAddress, address _workerpoolregistryAddress ) external override onlyOwner { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_appregistry = IRegistry(_appregistryAddress); $.m_datasetregistry = IRegistry(_datasetregistryAddress); $.m_workerpoolregistry = IRegistry(_workerpoolregistryAddress); diff --git a/contracts/facets/IexecConfigurationFacet.sol b/contracts/facets/IexecConfigurationFacet.sol index fe2f859f5..41aaac187 100644 --- a/contracts/facets/IexecConfigurationFacet.sol +++ b/contracts/facets/IexecConfigurationFacet.sol @@ -8,6 +8,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./FacetBase.sol"; import "../interfaces/IexecConfiguration.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecConfigurationFacet is IexecConfiguration, FacetBase { using SafeMathExtended for uint256; @@ -24,10 +25,9 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { address _workerpoolregistryAddress, address _v3_iexecHubAddress ) external override onlyOwner { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require($.m_eip712DomainSeparator == bytes32(0), "already-configured"); $.m_eip712DomainSeparator = _domain().hash(); - $.m_baseToken = IERC20(_token); $.m_name = _name; $.m_symbol = _symbol; @@ -44,13 +44,13 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { } function updateDomainSeparator() external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require($.m_eip712DomainSeparator != bytes32(0), "not-configured"); $.m_eip712DomainSeparator = _domain().hash(); } function importScore(address _worker) external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require(!$.m_v3_scoreImported[_worker], "score-already-imported"); $.m_workerScores[_worker] = $.m_workerScores[_worker].max( $.m_v3_iexecHub.viewScore(_worker) @@ -59,12 +59,12 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { } function setTeeBroker(address _teebroker) external override onlyOwner { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_teebroker = _teebroker; } function setCallbackGas(uint256 _callbackgas) external override onlyOwner { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_callbackgas = _callbackgas; } diff --git a/contracts/facets/IexecERC20Core.sol b/contracts/facets/IexecERC20Core.sol index 2e115b4e2..1c2adfe77 100644 --- a/contracts/facets/IexecERC20Core.sol +++ b/contracts/facets/IexecERC20Core.sol @@ -4,6 +4,7 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; import "./FacetBase.sol"; contract IexecERC20Core is FacetBase { @@ -15,7 +16,7 @@ contract IexecERC20Core is FacetBase { function _transferUnchecked(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_balances[sender] = $.m_balances[sender].sub(amount); $.m_balances[recipient] = $.m_balances[recipient].add(amount); emit Transfer(sender, recipient, amount); @@ -27,7 +28,7 @@ contract IexecERC20Core is FacetBase { function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_totalSupply = $.m_totalSupply.add(amount); $.m_balances[account] = $.m_balances[account].add(amount); emit Transfer(address(0), account, amount); @@ -35,7 +36,7 @@ contract IexecERC20Core is FacetBase { function _burn(address account, uint256 amount) internal { require(account != address(0), "ERC20: burn from the zero address"); - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_totalSupply = $.m_totalSupply.sub(amount); $.m_balances[account] = $.m_balances[account].sub(amount); emit Transfer(account, address(0), amount); @@ -44,7 +45,7 @@ contract IexecERC20Core is FacetBase { function _approve(address owner, address spender, uint256 amount) internal { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } diff --git a/contracts/facets/IexecERC20Facet.sol b/contracts/facets/IexecERC20Facet.sol index de92cdea3..490203977 100644 --- a/contracts/facets/IexecERC20Facet.sol +++ b/contracts/facets/IexecERC20Facet.sol @@ -8,6 +8,7 @@ import "./IexecERC20Core.sol"; import "./FacetBase.sol"; import "../interfaces/IexecERC20.sol"; import "../interfaces/IexecTokenSpender.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecERC20Facet is IexecERC20, FacetBase, IexecERC20Core { function transfer(address recipient, uint256 amount) external override returns (bool) { @@ -43,7 +44,7 @@ contract IexecERC20Facet is IexecERC20, FacetBase, IexecERC20Core { address recipient, uint256 amount ) external override returns (bool) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); _transfer(sender, recipient, amount); _approve(sender, _msgSender(), $.m_allowances[sender][_msgSender()].sub(amount)); return true; @@ -53,7 +54,7 @@ contract IexecERC20Facet is IexecERC20, FacetBase, IexecERC20Core { address spender, uint256 addedValue ) external override returns (bool) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); _approve(_msgSender(), spender, $.m_allowances[_msgSender()][spender].add(addedValue)); return true; } @@ -62,7 +63,7 @@ contract IexecERC20Facet is IexecERC20, FacetBase, IexecERC20Core { address spender, uint256 subtractedValue ) external override returns (bool) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); _approve(_msgSender(), spender, $.m_allowances[_msgSender()][spender].sub(subtractedValue)); return true; } diff --git a/contracts/facets/IexecEscrow.v8.sol b/contracts/facets/IexecEscrow.v8.sol index 661d38ac5..bfbb5daa7 100644 --- a/contracts/facets/IexecEscrow.v8.sol +++ b/contracts/facets/IexecEscrow.v8.sol @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; - +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; import {FacetBase} from "./FacetBase.v8.sol"; /** @@ -21,7 +21,7 @@ contract IexecEscrow is FacetBase { * @param value The value to lock. */ function lock(address account, uint256 value) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); _transfer(account, address(this), value); $.m_frozens[account] += value; emit Lock(account, value); @@ -33,7 +33,7 @@ contract IexecEscrow is FacetBase { * @param value The value to unlock. */ function unlock(address account, uint256 value) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); _transfer(address(this), account, value); $.m_frozens[account] -= value; emit Unlock(account, value); @@ -57,7 +57,7 @@ contract IexecEscrow is FacetBase { * @param ref A reference of the seize context. */ function seize(address account, uint256 value, bytes32 ref) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_frozens[account] -= value; emit Seize(account, value, ref); } @@ -78,7 +78,7 @@ contract IexecEscrow is FacetBase { function _transfer(address from, address to, uint256 value) private { require(from != address(0), "IexecEscrow: Transfer from empty address"); require(to != address(0), "IexecEscrow: Transfer to empty address"); - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); uint256 fromBalance = $.m_balances[from]; require(value <= fromBalance, "IexecEscrow: Transfer amount exceeds balance"); // This block is guaranteed to not underflow because we check the from balance diff --git a/contracts/facets/IexecEscrowNativeFacet.sol b/contracts/facets/IexecEscrowNativeFacet.sol index c4686b4b1..42a1ef056 100644 --- a/contracts/facets/IexecEscrowNativeFacet.sol +++ b/contracts/facets/IexecEscrowNativeFacet.sol @@ -7,6 +7,7 @@ pragma experimental ABIEncoderV2; import "./IexecERC20Core.sol"; import "./FacetBase.sol"; import "../interfaces/IexecEscrowNative.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecEscrowNativeFacet is IexecEscrowNative, FacetBase, IexecERC20Core { using SafeMathExtended for uint256; @@ -60,7 +61,7 @@ contract IexecEscrowNativeFacet is IexecEscrowNative, FacetBase, IexecERC20Core } function recover() external override onlyOwner returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); uint256 delta = address(this).balance.div(nRLCtoWei).sub($.m_totalSupply); _mint(owner(), delta); return delta; diff --git a/contracts/facets/IexecEscrowTokenFacet.sol b/contracts/facets/IexecEscrowTokenFacet.sol index 2e1a997f6..fd9e833cb 100644 --- a/contracts/facets/IexecEscrowTokenFacet.sol +++ b/contracts/facets/IexecEscrowTokenFacet.sol @@ -8,6 +8,7 @@ import "./IexecERC20Core.sol"; import "./FacetBase.sol"; import "../interfaces/IexecEscrowToken.sol"; import "../interfaces/IexecTokenSpender.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase, IexecERC20Core { using SafeMathExtended for uint256; @@ -60,7 +61,7 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase } function recover() external override onlyOwner returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); uint256 delta = $.m_baseToken.balanceOf(address(this)).sub($.m_totalSupply); _mint(owner(), delta); return delta; @@ -73,7 +74,7 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase address token, bytes calldata ) external override returns (bool) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require(token == address($.m_baseToken), "wrong-token"); _deposit(sender, amount); _mint(sender, amount); @@ -81,12 +82,12 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase } function _deposit(address from, uint256 amount) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require($.m_baseToken.transferFrom(from, address(this), amount), "failled-transferFrom"); } function _withdraw(address to, uint256 amount) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_baseToken.transfer(to, amount); } } diff --git a/contracts/facets/IexecEscrowTokenSwapFacet.sol b/contracts/facets/IexecEscrowTokenSwapFacet.sol index f2347d48f..62bce85a1 100644 --- a/contracts/facets/IexecEscrowTokenSwapFacet.sol +++ b/contracts/facets/IexecEscrowTokenSwapFacet.sol @@ -8,6 +8,7 @@ import "./IexecERC20Core.sol"; import "./SignatureVerifier.sol"; import "./FacetBase.sol"; import "../interfaces/IexecEscrowTokenSwap.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; import "../interfaces/IexecPoco1.sol"; contract IexecEscrowTokenSwapFacet is @@ -36,7 +37,7 @@ contract IexecEscrowTokenSwapFacet is * Uniswap path - Internal * ***************************************************************************/ function _eth2token() internal view returns (address[] memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address[] memory path = new address[](2); path[0] = router.WETH(); path[1] = address($.m_baseToken); @@ -44,7 +45,7 @@ contract IexecEscrowTokenSwapFacet is } function _token2eth() internal view returns (address[] memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address[] memory path = new address[](2); path[0] = address($.m_baseToken); path[1] = router.WETH(); @@ -141,7 +142,7 @@ contract IexecEscrowTokenSwapFacet is } function _withdraw(address target, uint256 amount, uint256 minimum) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_baseToken.approve(address(router), amount); uint256[] memory amounts = router.swapExactTokensForETH( amount, @@ -162,7 +163,7 @@ contract IexecEscrowTokenSwapFacet is IexecLibOrders_v5.WorkerpoolOrder memory _workerpoolorder, IexecLibOrders_v5.RequestOrder memory _requestorder ) public payable override returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); uint256 volume; volume = _apporder.volume.sub( $.m_consumed[keccak256(_toEthTypedStruct(_apporder.hash(), $.m_eip712DomainSeparator))] @@ -171,7 +172,9 @@ contract IexecEscrowTokenSwapFacet is volume = volume.min( _datasetorder.volume.sub( $.m_consumed[ - keccak256(_toEthTypedStruct(_datasetorder.hash(), $.m_eip712DomainSeparator)) + keccak256( + _toEthTypedStruct(_datasetorder.hash(), $.m_eip712DomainSeparator) + ) ] ) ); diff --git a/contracts/facets/IexecOrderManagementFacet.sol b/contracts/facets/IexecOrderManagementFacet.sol index cfcba0949..c53744549 100644 --- a/contracts/facets/IexecOrderManagementFacet.sol +++ b/contracts/facets/IexecOrderManagementFacet.sol @@ -7,6 +7,7 @@ import {IERC5313} from "@openzeppelin/contracts-v5/interfaces/IERC5313.sol"; import {SignatureVerifier} from "./SignatureVerifier.v8.sol"; import {FacetBase} from "./FacetBase.v8.sol"; import {IexecOrderManagement} from "../interfaces/IexecOrderManagement.v8.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol"; contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, SignatureVerifier { @@ -25,7 +26,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageAppOrder( IexecLibOrders_v5.AppOrderOperation calldata _apporderoperation ) external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address owner = IERC5313(_apporderoperation.order.app).owner(); require( owner == _msgSender() || @@ -50,7 +51,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageDatasetOrder( IexecLibOrders_v5.DatasetOrderOperation calldata _datasetorderoperation ) external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address owner = IERC5313(_datasetorderoperation.order.dataset).owner(); require( owner == _msgSender() || @@ -75,7 +76,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageWorkerpoolOrder( IexecLibOrders_v5.WorkerpoolOrderOperation calldata _workerpoolorderoperation ) external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address owner = IERC5313(_workerpoolorderoperation.order.workerpool).owner(); require( owner == _msgSender() || @@ -102,7 +103,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageRequestOrder( IexecLibOrders_v5.RequestOrderOperation calldata _requestorderoperation ) external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address owner = _requestorderoperation.order.requester; require( owner == _msgSender() || diff --git a/contracts/facets/IexecPoco1Facet.sol b/contracts/facets/IexecPoco1Facet.sol index 646514afe..9475fffd4 100644 --- a/contracts/facets/IexecPoco1Facet.sol +++ b/contracts/facets/IexecPoco1Facet.sol @@ -5,11 +5,11 @@ pragma solidity ^0.8.0; import {IERC5313} from "@openzeppelin/contracts-v5/interfaces/IERC5313.sol"; import {Math} from "@openzeppelin/contracts-v5/utils/math/Math.sol"; - import {IexecLibCore_v5} from "../libs/IexecLibCore_v5.sol"; import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol"; import {IWorkerpool} from "../registries/workerpools/IWorkerpool.v8.sol"; import {FacetBase} from "./FacetBase.v8.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; import {IexecPoco1} from "../interfaces/IexecPoco1.v8.sol"; import {IexecEscrow} from "./IexecEscrow.v8.sol"; import {IexecPocoCommonFacet} from "./IexecPocoCommonFacet.sol"; @@ -145,7 +145,7 @@ contract IexecPoco1Facet is IexecLibOrders_v5.RequestOrder calldata _requestorder, address _sponsor ) private returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); /** * Check orders compatibility */ diff --git a/contracts/facets/IexecPoco2Facet.sol b/contracts/facets/IexecPoco2Facet.sol index b366c2bc7..4f5f6c9d9 100644 --- a/contracts/facets/IexecPoco2Facet.sol +++ b/contracts/facets/IexecPoco2Facet.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.0; import {Math} from "@openzeppelin/contracts-v5/utils/math/Math.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; import {IOracleConsumer} from "../external/interfaces/IOracleConsumer.sol"; import {IexecLibCore_v5} from "../libs/IexecLibCore_v5.sol"; import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol"; @@ -14,7 +15,7 @@ import {SignatureVerifier} from "./SignatureVerifier.v8.sol"; contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifier { modifier onlyScheduler(bytes32 _taskId) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require(_msgSender() == $.m_deals[$.m_tasks[_taskId].dealid].workerpool.owner); _; } @@ -23,7 +24,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Escrow overhead for contribution * ***************************************************************************/ function successWork(bytes32 _dealid, bytes32 _taskid) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal storage deal = $.m_deals[_dealid]; uint256 taskPrice = deal.app.price + deal.dataset.price + deal.workerpool.price; @@ -54,7 +55,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function failedWork(bytes32 _dealid, bytes32 _taskid) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_dealid]; uint256 taskPrice = deal.app.price + deal.dataset.price + deal.workerpool.price; @@ -77,7 +78,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Consensus methods * ***************************************************************************/ function initialize(bytes32 _dealid, uint256 idx) public override returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_dealid]; require(idx >= deal.botFirst); @@ -110,7 +111,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _enclaveSign, bytes calldata _authorizationSign ) external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -188,7 +189,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _enclaveSign, bytes calldata _authorizationSign ) external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -259,7 +260,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function reveal(bytes32 _taskid, bytes32 _resultDigest) external override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -282,7 +283,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function reopen(bytes32 _taskid) external override onlyScheduler(_taskid) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; require(task.status == IexecLibCore_v5.TaskStatusEnum.REVEALING); require(task.finalDeadline > block.timestamp); @@ -314,7 +315,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _results, bytes calldata _resultsCallback // Expansion - result separation ) external override onlyScheduler(_taskid) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -349,7 +350,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function claim(bytes32 _taskid) public override { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; require( task.status == IexecLibCore_v5.TaskStatusEnum.ACTIVE || @@ -379,7 +380,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Consensus detection */ function checkConsensus(bytes32 _taskid, bytes32 _consensus) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Consensus storage consensus = $.m_consensus[_taskid]; @@ -418,7 +419,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Reward distribution */ function distributeRewards(bytes32 _taskid) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task memory task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -497,7 +498,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Reward distribution for contributeAndFinalize */ function distributeRewardsFast(bytes32 _taskid) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task memory task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -514,7 +515,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Callback for smartcontracts using EIP1154 */ function executeCallback(bytes32 _taskid, bytes memory _resultsCallback) internal { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address target = $.m_deals[$.m_tasks[_taskid].dealid].callback; if (target != address(0)) { // Solidity 0.6.0 reverts if target is not a smartcontracts diff --git a/contracts/facets/IexecPocoAccessorsFacet.sol b/contracts/facets/IexecPocoAccessorsFacet.sol index bd1f9d28e..9b7231a4a 100644 --- a/contracts/facets/IexecPocoAccessorsFacet.sol +++ b/contracts/facets/IexecPocoAccessorsFacet.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.0; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; import {FacetBase} from "./FacetBase.v8.sol"; import {IexecLibCore_v5} from "../libs/IexecLibCore_v5.sol"; import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol"; @@ -29,7 +30,7 @@ contract IexecPocoAccessorsFacet is * @param id The ID of the deal. */ function viewDeal(bytes32 id) external view returns (IexecLibCore_v5.Deal memory deal) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_deals[id]; } @@ -38,7 +39,7 @@ contract IexecPocoAccessorsFacet is * @param id id of the task */ function viewTask(bytes32 id) external view returns (IexecLibCore_v5.Task memory) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_tasks[id]; } diff --git a/contracts/facets/IexecPocoBoostAccessorsFacet.sol b/contracts/facets/IexecPocoBoostAccessorsFacet.sol index 747b0a5a2..d5253803a 100644 --- a/contracts/facets/IexecPocoBoostAccessorsFacet.sol +++ b/contracts/facets/IexecPocoBoostAccessorsFacet.sol @@ -6,6 +6,7 @@ pragma solidity ^0.8.0; import {IexecLibCore_v5} from "../libs/IexecLibCore_v5.sol"; import {FacetBase} from "./FacetBase.v8.sol"; import {IexecPocoBoostAccessors} from "../interfaces/IexecPocoBoostAccessors.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; /** * @title Getters contract for PoCo Boost facet. @@ -19,7 +20,7 @@ contract IexecPocoBoostAccessorsFacet is IexecPocoBoostAccessors, FacetBase { function viewDealBoost( bytes32 id ) external view returns (IexecLibCore_v5.DealBoost memory deal) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_dealsBoost[id]; } } diff --git a/contracts/facets/IexecPocoBoostFacet.sol b/contracts/facets/IexecPocoBoostFacet.sol index 6e3f174b1..c5abca4e5 100644 --- a/contracts/facets/IexecPocoBoostFacet.sol +++ b/contracts/facets/IexecPocoBoostFacet.sol @@ -18,6 +18,7 @@ import {IexecPocoBoost} from "../interfaces/IexecPocoBoost.sol"; import {IexecEscrow} from "./IexecEscrow.v8.sol"; import {IexecPocoCommonFacet} from "./IexecPocoCommonFacet.sol"; import {SignatureVerifier} from "./SignatureVerifier.v8.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; /** * @title PoCo Boost to reduce latency and increase throughput of deals. @@ -124,7 +125,7 @@ contract IexecPocoBoostFacet is IexecLibOrders_v5.RequestOrder calldata requestOrder, address sponsor ) private returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); // Check orders compatibility // Ensure the trust level is within the acceptable range. @@ -380,7 +381,7 @@ contract IexecPocoBoostFacet is address enclaveChallenge, bytes calldata enclaveSign ) external { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.DealBoost storage deal = $.m_dealsBoost[dealId]; // Compute the unique task identifier based on deal id and task index. bytes32 taskId = keccak256(abi.encodePacked(dealId, index)); @@ -494,7 +495,7 @@ contract IexecPocoBoostFacet is * @param index The index of the task. */ function claimBoost(bytes32 dealId, uint256 index) external { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); // Retrieve deal and task information from storage. IexecLibCore_v5.DealBoost storage deal = $.m_dealsBoost[dealId]; bytes32 taskId = keccak256(abi.encodePacked(dealId, index)); diff --git a/contracts/facets/IexecPocoCommonFacet.sol b/contracts/facets/IexecPocoCommonFacet.sol index 7a617aca9..ebea3d6f4 100644 --- a/contracts/facets/IexecPocoCommonFacet.sol +++ b/contracts/facets/IexecPocoCommonFacet.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {Math} from "@openzeppelin/contracts-v5/utils/math/Math.sol"; - +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol"; import {FacetBase} from "./FacetBase.v8.sol"; @@ -42,7 +42,7 @@ contract IexecPocoCommonFacet is FacetBase { uint256 requestOrderVolume, bytes32 requestOrderTypedDataHash ) internal view returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return (appOrderVolume - $.m_consumed[appOrderTypedDataHash]) .min( diff --git a/contracts/facets/SignatureVerifier.sol b/contracts/facets/SignatureVerifier.sol index a9877dbb2..00dbd9c46 100644 --- a/contracts/facets/SignatureVerifier.sol +++ b/contracts/facets/SignatureVerifier.sol @@ -7,6 +7,7 @@ pragma experimental ABIEncoderV2; import "@iexec/solidity/contracts/ERC734/IERC734.sol"; import "@iexec/solidity/contracts/ERC1271/IERC1271.sol"; import "@iexec/solidity/contracts/ERC1654/IERC1654.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; import "./FacetBase.sol"; contract SignatureVerifier is FacetBase { @@ -95,7 +96,7 @@ contract SignatureVerifier is FacetBase { } function _checkPresignature(address _identity, bytes32 _hash) internal view returns (bool) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return _identity != address(0) && _identity == $.m_presigned[_hash]; } diff --git a/contracts/facets/SignatureVerifier.v8.sol b/contracts/facets/SignatureVerifier.v8.sol index 8bece6eed..4f8a9bda1 100644 --- a/contracts/facets/SignatureVerifier.v8.sol +++ b/contracts/facets/SignatureVerifier.v8.sol @@ -6,8 +6,9 @@ pragma solidity ^0.8.0; import {IERC1271} from "@openzeppelin/contracts-v5/interfaces/IERC1271.sol"; import {ECDSA} from "@openzeppelin/contracts-v5/utils/cryptography/ECDSA.sol"; import {MessageHashUtils} from "@openzeppelin/contracts-v5/utils/cryptography/MessageHashUtils.sol"; -import {IERC734} from "../external/interfaces/IERC734.sol"; import {FacetBase} from "./FacetBase.v8.sol"; +import {IERC734} from "../external/interfaces/IERC734.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; contract SignatureVerifier is FacetBase { using ECDSA for bytes32; @@ -17,7 +18,7 @@ contract SignatureVerifier is FacetBase { * @param structHash The original structure hash. */ function _toTypedDataHash(bytes32 structHash) internal view returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return MessageHashUtils.toTypedDataHash($.m_eip712DomainSeparator, structHash); } @@ -90,7 +91,7 @@ contract SignatureVerifier is FacetBase { address account, bytes32 messageHash ) internal view returns (bool) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return account != address(0) && account == $.m_presigned[messageHash]; } diff --git a/contracts/Store.sol b/contracts/libs/PocoStorageLib.sol similarity index 80% rename from contracts/Store.sol rename to contracts/libs/PocoStorageLib.sol index c04f383e3..8091578dd 100644 --- a/contracts/Store.sol +++ b/contracts/libs/PocoStorageLib.sol @@ -7,13 +7,12 @@ import "@iexec/interface/contracts/IexecHub.sol"; import "@iexec/solidity/contracts/Libs/SafeMathExtended.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "./libs/IexecLibCore_v5.sol"; -import "./libs/IexecLibOrders_v5.sol"; -import "./registries/apps/App.sol"; -import "./registries/datasets/Dataset.sol"; -import "./registries/workerpools/Workerpool.sol"; -import "./registries/IRegistry.sol"; - +import "./IexecLibCore_v5.sol"; +import "./IexecLibOrders_v5.sol"; +import "./../registries/apps/App.sol"; +import "./../registries/datasets/Dataset.sol"; +import "./../registries/workerpools/Workerpool.sol"; +import "./../registries/IRegistry.sol"; /**************************************************************************** * WARNING: Be carefull when editing this file. * * * @@ -25,23 +24,7 @@ import "./registries/IRegistry.sol"; * * ****************************************************************************/ -abstract contract Store { - // Poco - Constants - uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7; - uint256 public constant REVEAL_DEADLINE_RATIO = 2; - uint256 public constant FINAL_DEADLINE_RATIO = 10; - uint256 public constant WORKERPOOL_STAKE_RATIO = 30; - uint256 public constant KITTY_RATIO = 10; - uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE - - // Seized funds of workerpools that do not honor their deals are sent - // out to this kitty address. - // It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1). - address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; - - // Used with ERC-734 Key Manager identity contract for authorization management. - uint256 public constant GROUPMEMBER_PURPOSE = 4; - +library PocoStorageLib { // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); bytes32 private constant POCO_STORAGE_LOCATION = 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; diff --git a/contracts/Store.v8.sol b/contracts/libs/PocoStorageLib.v8.sol similarity index 84% rename from contracts/Store.v8.sol rename to contracts/libs/PocoStorageLib.v8.sol index cb5c0f948..c9785ced8 100644 --- a/contracts/Store.v8.sol +++ b/contracts/libs/PocoStorageLib.v8.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.0; import {IERC20} from "@openzeppelin/contracts-v5/interfaces/IERC20.sol"; import {IERC721Enumerable} from "@openzeppelin/contracts-v5/interfaces/IERC721Enumerable.sol"; import {Ownable} from "@openzeppelin/contracts-v5/access/Ownable.sol"; -import {IexecLibCore_v5} from "./libs/IexecLibCore_v5.sol"; +import {IexecLibCore_v5} from "./IexecLibCore_v5.sol"; /**************************************************************************** * WARNING: Be carefull when editing this file. * @@ -19,23 +19,7 @@ import {IexecLibCore_v5} from "./libs/IexecLibCore_v5.sol"; * * ****************************************************************************/ -abstract contract Store { - // Poco - Constants - uint256 public constant CONTRIBUTION_DEADLINE_RATIO = 7; - uint256 public constant REVEAL_DEADLINE_RATIO = 2; - uint256 public constant FINAL_DEADLINE_RATIO = 10; - uint256 public constant WORKERPOOL_STAKE_RATIO = 30; - uint256 public constant KITTY_RATIO = 10; - uint256 public constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE - - // Seized funds of workerpools that do not honor their deals are sent - // out to this kitty address. - // It is determined with address(uint256(keccak256(bytes('iExecKitty'))) - 1). - address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; - - // Used with ERC-734 Key Manager identity contract for authorization management. - uint256 public constant GROUPMEMBER_PURPOSE = 4; - +library PocoStorageLib { // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); bytes32 private constant POCO_STORAGE_LOCATION = 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; diff --git a/contracts/registries/Registry.sol b/contracts/registries/Registry.sol index 66c0ade93..901d4ae47 100644 --- a/contracts/registries/Registry.sol +++ b/contracts/registries/Registry.sol @@ -50,7 +50,7 @@ abstract contract Registry is IRegistry, ERC721, Ownable { * in the SDK. */ // TODO remove this function when Bellecour is deprecated. - function setName(address /* _ens */, string calldata /* _name */) external view onlyOwner() { + function setName(address /* _ens */, string calldata /* _name */) external view onlyOwner { revert("Operation not supported on this chain"); } diff --git a/contracts/registries/RegistryEntry.sol b/contracts/registries/RegistryEntry.sol index c8efded62..8c3874a2b 100644 --- a/contracts/registries/RegistryEntry.sol +++ b/contracts/registries/RegistryEntry.sol @@ -28,7 +28,7 @@ abstract contract RegistryEntry { * in the SDK. */ // TODO remove this function when Bellecour is deprecated. - function setName(address /* _ens */, string calldata /* _name */) external view onlyOwner() { + function setName(address /* _ens */, string calldata /* _name */) external view onlyOwner { revert("Operation not supported on this chain"); } diff --git a/contracts/tools/testing/IexecEscrowTestContract.sol b/contracts/tools/testing/IexecEscrowTestContract.sol index 70e3d1bd2..9fce2bf49 100644 --- a/contracts/tools/testing/IexecEscrowTestContract.sol +++ b/contracts/tools/testing/IexecEscrowTestContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.0; import {IexecEscrow} from "../../facets/IexecEscrow.v8.sol"; +import {PocoStorageLib} from "../../libs/PocoStorageLib.v8.sol"; /** * @notice a wrapper contract to make internal functions of @@ -29,7 +30,7 @@ contract IexecEscrowTestContract is IexecEscrow { // Helper functions used in unit tests. function setBalance(address account, uint256 value) external { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_balances[account] = value; } @@ -37,12 +38,12 @@ contract IexecEscrowTestContract is IexecEscrow { // when it is migrated to solidity v8. function balanceOf(address account) external view returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_balances[account]; } function frozenOf(address account) external view returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_frozens[account]; } } diff --git a/test/000_fullchain-boost.test.ts b/test/000_fullchain-boost.test.ts index 6a2cdcf39..3e006017e 100644 --- a/test/000_fullchain-boost.test.ts +++ b/test/000_fullchain-boost.test.ts @@ -5,7 +5,7 @@ import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import { loadFixture, time } from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; import { TypedDataDomain } from 'ethers'; -import hre, { ethers } from 'hardhat'; +import hre from 'hardhat'; import { IexecAccessors, IexecAccessors__factory, diff --git a/test/000_fullchain.test.ts b/test/000_fullchain.test.ts index 2a94c7592..c8b8a2609 100644 --- a/test/000_fullchain.test.ts +++ b/test/000_fullchain.test.ts @@ -4,7 +4,6 @@ import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; -import { ethers } from 'hardhat'; import { IexecInterfaceNative, IexecInterfaceNative__factory } from '../typechain'; import { OrdersActors, OrdersAssets, OrdersPrices, buildOrders } from '../utils/createOrders'; import {