From e4b2826c9eea78f24d4cefbbbecc38c1b895c2d4 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 14:49:32 +0200 Subject: [PATCH 01/10] Refactor Poco storage management: Introduce LibPocoStorage for improved storage handling and access patterns across facets --- contracts/Store.sol | 108 ---- contracts/Store.v8.sol | 110 ---- contracts/libs/LibPocoStorage.sol | 521 +++++++++++++++++ contracts/libs/LibPocoStorage.v8.sol | 538 ++++++++++++++++++ contracts/modules/FacetBase.sol | 25 +- contracts/modules/FacetBase.v8.sol | 23 +- .../facets/IexecAccessorsABILegacyFacet.sol | 13 +- .../modules/facets/IexecAccessorsFacet.sol | 65 +-- .../facets/IexecCategoryManagerFacet.sol | 6 +- .../facets/IexecConfigurationExtraFacet.sol | 3 +- .../facets/IexecConfigurationFacet.sol | 46 +- contracts/modules/facets/IexecERC20Core.sol | 9 +- contracts/modules/facets/IexecERC20Facet.sol | 7 +- contracts/modules/facets/IexecEscrow.v8.sol | 9 +- .../modules/facets/IexecEscrowNativeFacet.sol | 3 +- .../modules/facets/IexecEscrowTokenFacet.sol | 9 +- .../facets/IexecEscrowTokenSwapFacet.sol | 9 +- .../facets/IexecOrderManagementFacet.sol | 9 +- contracts/modules/facets/IexecPoco1Facet.sol | 5 +- contracts/modules/facets/IexecPoco2Facet.sol | 72 ++- .../facets/IexecPocoAccessorsFacet.sol | 7 +- .../facets/IexecPocoBoostAccessorsFacet.sol | 3 +- .../modules/facets/IexecPocoBoostFacet.sol | 36 +- .../modules/facets/IexecPocoCommonFacet.sol | 10 +- .../modules/facets/SignatureVerifier.sol | 3 +- .../modules/facets/SignatureVerifier.v8.sol | 9 +- .../tools/testing/IexecEscrowTestContract.sol | 7 +- 27 files changed, 1285 insertions(+), 380 deletions(-) delete mode 100644 contracts/Store.sol delete mode 100644 contracts/Store.v8.sol create mode 100644 contracts/libs/LibPocoStorage.sol create mode 100644 contracts/libs/LibPocoStorage.v8.sol diff --git a/contracts/Store.sol b/contracts/Store.sol deleted file mode 100644 index 91de34948..000000000 --- a/contracts/Store.sol +++ /dev/null @@ -1,108 +0,0 @@ -// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -pragma solidity ^0.6.0; - -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"; - -/**************************************************************************** - * WARNING: Be carefull when editing this file. * - * * - * If you want to add new variables, add them to the end of the * - * struct `PocoStorage`. * - * Read more about: * - * - Diamond proxy storage https://eips.ethereum.org/EIPS/eip-2535 * - * - Namespaced storage https://eips.ethereum.org/EIPS/eip-7201 * - * * - ****************************************************************************/ - -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; - - // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 private constant POCO_STORAGE_LOCATION = - 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; - - /// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage - struct PocoStorage { - // Registries - IRegistry m_appregistry; - IRegistry m_datasetregistry; - IRegistry m_workerpoolregistry; - // Escrow - IERC20 m_baseToken; - string m_name; - string m_symbol; - uint8 m_decimals; - uint256 m_totalSupply; - // In order to use the protocol, users have to deposit RLC - // and allow PoCo smart contracts to manage them. This state - // variable keeps track of users balances. - mapping(address => uint256) m_balances; - // When a deal is created, the protocol temporarily locks an amount - // of RLC tokens from the balances of both the requester and the workerpool owners. - // This is to guarantee the payment of different actors later. Frozen funds - // are released when the computation is completed and the result is pushed. - mapping(address => uint256) m_frozens; - mapping(address => mapping(address => uint256)) m_allowances; - // EIP-712 domain hash. - // Modified in IexecConfigurationFacet.updateDomainSeparator - bytes32 EIP712DOMAIN_SEPARATOR; // TODO rename - // Poco - Storage - - // Mapping an order hash to its owner. Since a smart contract cannot sign orders - // with a private key, it adds an entry to this mapping to provide presigned orders. - mapping(bytes32 => address) m_presigned; - // Each order has a volume (>=1). This tracks how much is consumed from - // the volume of each order. Mapping an order hash to its consumed amount. - mapping(bytes32 => uint256) m_consumed; - // a mapping to store PoCo classic deals. - mapping(bytes32 => IexecLibCore_v5.Deal) m_deals; - mapping(bytes32 => IexecLibCore_v5.Task) m_tasks; // per task - mapping(bytes32 => IexecLibCore_v5.Consensus) m_consensus; // per task - mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) m_contributions; // per task-worker - mapping(address => uint256) m_workerScores; // per worker - // Poco - Settings - // Address of a trusted TEE authority that manages enclave challenges. - // Modified in IexecConfigurationFacet.setTeeBroker - address m_teebroker; - // Max amount of gas to be used with callbacks. - // Modified in IexecConfigurationFacet.setCallbackGas - uint256 m_callbackgas; - // List of defined computation categories. - IexecLibCore_v5.Category[] m_categories; - // Backward compatibility - // Modified in IexecConfigurationFacet.configure - IexecHubInterface m_v3_iexecHub; - mapping(address => bool) m_v3_scoreImported; - } - - function getPocoStorage() internal pure returns (PocoStorage storage $) { - assembly { - $_slot := POCO_STORAGE_LOCATION - } - } -} diff --git a/contracts/Store.v8.sol b/contracts/Store.v8.sol deleted file mode 100644 index 17db6eda0..000000000 --- a/contracts/Store.v8.sol +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-FileCopyrightText: 2023-2025 IEXEC BLOCKCHAIN TECH -// SPDX-License-Identifier: Apache-2.0 - -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"; - -/**************************************************************************** - * WARNING: Be carefull when editing this file. * - * * - * If you want to add new variables, add them to the end of the * - * struct `PocoStorage`. * - * Read more about: * - * - Diamond proxy storage https://eips.ethereum.org/EIPS/eip-2535 * - * - Namespaced storage https://eips.ethereum.org/EIPS/eip-7201 * - * * - ****************************************************************************/ - -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; - - // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 private constant POCO_STORAGE_LOCATION = - 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; - - /// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage - struct PocoStorage { - // Registries - IRegistry m_appregistry; - IRegistry m_datasetregistry; - IRegistry m_workerpoolregistry; - // Escrow - IERC20 m_baseToken; - string m_name; - string m_symbol; - uint8 m_decimals; - uint256 m_totalSupply; - // In order to use the protocol, users have to deposit RLC - // and allow PoCo smart contracts to manage them. This state - // variable keeps track of users balances. - mapping(address => uint256) m_balances; - // When a deal is created, the protocol temporarily locks an amount - // of RLC tokens from the balances of both the requester and the workerpool owners. - // This is to guarantee the payment of different actors later. Frozen funds - // are released when the computation is completed and the result is pushed. - mapping(address => uint256) m_frozens; - mapping(address => mapping(address => uint256)) m_allowances; - // EIP-712 domain hash. - // Modified in IexecConfigurationFacet.updateDomainSeparator - bytes32 EIP712DOMAIN_SEPARATOR; // TODO rename - // Poco - Storage - - // Mapping an order hash to its owner. Since a smart contract cannot sign orders - // with a private key, it adds an entry to this mapping to provide presigned orders. - mapping(bytes32 => address) m_presigned; - // Each order has a volume (>=1). This tracks how much is consumed from - // the volume of each order. Mapping an order hash to its consumed amount. - mapping(bytes32 => uint256) m_consumed; - // a mapping to store PoCo classic deals. - mapping(bytes32 => IexecLibCore_v5.Deal) m_deals; - mapping(bytes32 => IexecLibCore_v5.Task) m_tasks; // per task - mapping(bytes32 => IexecLibCore_v5.Consensus) m_consensus; // per task - mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) m_contributions; // per task-worker - mapping(address => uint256) m_workerScores; // per worker - // Poco - Settings - // Address of a trusted TEE authority that manages enclave challenges. - // Modified in IexecConfigurationFacet.setTeeBroker - address m_teebroker; - // Max amount of gas to be used with callbacks. - // Modified in IexecConfigurationFacet.setCallbackGas - uint256 m_callbackgas; - // List of defined computation categories. - IexecLibCore_v5.Category[] m_categories; - // Backward compatibility - // Modified in IexecConfigurationFacet.configure - address m_v3_iexecHub; // IexecHubInterface - mapping(address => bool) m_v3_scoreImported; - // /!\ New storage variables not present in v6 store. - // A mapping to store PoCo Boost deals. - mapping(bytes32 => IexecLibCore_v5.DealBoost) m_dealsBoost; - } - - function getPocoStorage() internal pure returns (PocoStorage storage $) { - assembly ("memory-safe") { - $.slot := POCO_STORAGE_LOCATION - } - } -} - -// Use in registries. -interface IRegistry is IERC721Enumerable { - function isRegistered(address _entry) external view returns (bool); -} diff --git a/contracts/libs/LibPocoStorage.sol b/contracts/libs/LibPocoStorage.sol new file mode 100644 index 000000000..cd41c31cc --- /dev/null +++ b/contracts/libs/LibPocoStorage.sol @@ -0,0 +1,521 @@ +// SPDX-FileCopyrightText: 2020-2025 IEXEC BLOCKCHAIN TECH +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.6.0; + +import "@iexec/interface/contracts/IexecHub.sol"; +import "@iexec/solidity/contracts/Libs/SafeMathExtended.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +import "./IexecLibCore_v5.sol"; +import "../registries/IRegistry.sol"; + +/** + * @title LibPocoStorage + * @dev Library for managing PoCo diamond storage using ERC-7201 namespaced storage pattern. + * This library replaces the Store abstract contract to support ERC-2535 diamond proxy architecture. + * Solidity 0.6 version for legacy facets. + */ +library LibPocoStorage { + // Poco - Constants + uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7; + uint256 internal constant REVEAL_DEADLINE_RATIO = 2; + uint256 internal constant FINAL_DEADLINE_RATIO = 10; + uint256 internal constant WORKERPOOL_STAKE_RATIO = 30; + uint256 internal constant KITTY_RATIO = 10; + uint256 internal 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 internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; + + // Used with ERC-734 Key Manager identity contract for authorization management. + uint256 internal constant GROUPMEMBER_PURPOSE = 4; + + // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 private constant POCO_STORAGE_LOCATION = + 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; + + /// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage + struct PocoStorage { + // Registries + IRegistry m_appregistry; + IRegistry m_datasetregistry; + IRegistry m_workerpoolregistry; + // Escrow + IERC20 m_baseToken; + string m_name; + string m_symbol; + uint8 m_decimals; + uint256 m_totalSupply; + // In order to use the protocol, users have to deposit RLC + // and allow PoCo smart contracts to manage them. This state + // variable keeps track of users balances. + mapping(address => uint256) m_balances; + // When a deal is created, the protocol temporarily locks an amount + // of RLC tokens from the balances of both the requester and the workerpool owners. + // This is to guarantee the payment of different actors later. Frozen funds + // are released when the computation is completed and the result is pushed. + mapping(address => uint256) m_frozens; + mapping(address => mapping(address => uint256)) m_allowances; + // EIP-712 domain hash. + // Modified in IexecConfigurationFacet.updateDomainSeparator + bytes32 EIP712DOMAIN_SEPARATOR; // TODO rename + // Poco - Storage + + // Mapping an order hash to its owner. Since a smart contract cannot sign orders + // with a private key, it adds an entry to this mapping to provide presigned orders. + mapping(bytes32 => address) m_presigned; + // Each order has a volume (>=1). This tracks how much is consumed from + // the volume of each order. Mapping an order hash to its consumed amount. + mapping(bytes32 => uint256) m_consumed; + // a mapping to store PoCo classic deals. + mapping(bytes32 => IexecLibCore_v5.Deal) m_deals; + mapping(bytes32 => IexecLibCore_v5.Task) m_tasks; // per task + mapping(bytes32 => IexecLibCore_v5.Consensus) m_consensus; // per task + mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) m_contributions; // per task-worker + mapping(address => uint256) m_workerScores; // per worker + // Poco - Settings + // Address of a trusted TEE authority that manages enclave challenges. + // Modified in IexecConfigurationFacet.setTeeBroker + address m_teebroker; + // Max amount of gas to be used with callbacks. + // Modified in IexecConfigurationFacet.setCallbackGas + uint256 m_callbackgas; + // List of defined computation categories. + IexecLibCore_v5.Category[] m_categories; + // Backward compatibility + // Modified in IexecConfigurationFacet.configure + IexecHubInterface m_v3_iexecHub; + mapping(address => bool) m_v3_scoreImported; + } + + function getPocoStorage() internal pure returns (PocoStorage storage $) { + assembly { + $_slot := POCO_STORAGE_LOCATION + } + } + + // === Constants Getter Functions === + function getContributionDeadlineRatio() internal pure returns (uint256) { + return CONTRIBUTION_DEADLINE_RATIO; + } + + function getRevealDeadlineRatio() internal pure returns (uint256) { + return REVEAL_DEADLINE_RATIO; + } + + function getFinalDeadlineRatio() internal pure returns (uint256) { + return FINAL_DEADLINE_RATIO; + } + + function getWorkerpoolStakeRatio() internal pure returns (uint256) { + return WORKERPOOL_STAKE_RATIO; + } + + function getKittyRatio() internal pure returns (uint256) { + return KITTY_RATIO; + } + + function getKittyMin() internal pure returns (uint256) { + return KITTY_MIN; + } + + function getKittyAddress() internal pure returns (address) { + return KITTY_ADDRESS; + } + + function getGroupmemberPurpose() internal pure returns (uint256) { + return GROUPMEMBER_PURPOSE; + } + + // === Storage Getter Functions === + + /** + * @dev Get the app registry contract. + * @return The app registry contract interface. + */ + function appRegistry() internal view returns (IRegistry) { + return getPocoStorage().m_appregistry; + } + + /** + * @dev Get the dataset registry contract. + * @return The dataset registry contract interface. + */ + function datasetRegistry() internal view returns (IRegistry) { + return getPocoStorage().m_datasetregistry; + } + + /** + * @dev Get the workerpool registry contract. + * @return The workerpool registry contract interface. + */ + function workerpoolRegistry() internal view returns (IRegistry) { + return getPocoStorage().m_workerpoolregistry; + } + + /** + * @dev Get the base token contract. + * @return The base token contract interface. + */ + function baseToken() internal view returns (IERC20) { + return getPocoStorage().m_baseToken; + } + + /** + * @dev Get the token name. + * @return The token name string. + */ + function name() internal view returns (string storage) { + return getPocoStorage().m_name; + } + + /** + * @dev Get the token symbol. + * @return The token symbol string. + */ + function symbol() internal view returns (string storage) { + return getPocoStorage().m_symbol; + } + + /** + * @dev Get the token decimals. + * @return The token decimals. + */ + function decimals() internal view returns (uint8) { + return getPocoStorage().m_decimals; + } + + /** + * @dev Get the total supply. + * @return The total supply amount. + */ + function totalSupply() internal view returns (uint256) { + return getPocoStorage().m_totalSupply; + } + + /** + * @dev Get the balance of an account. + * @param account The account address. + * @return The balance amount. + */ + function balanceOf(address account) internal view returns (uint256) { + return getPocoStorage().m_balances[account]; + } + + /** + * @dev Get the frozen balance of an account. + * @param account The account address. + * @return The frozen balance amount. + */ + function frozenOf(address account) internal view returns (uint256) { + return getPocoStorage().m_frozens[account]; + } + + /** + * @dev Get the allowance amount. + * @param owner The owner address. + * @param spender The spender address. + * @return The allowance amount. + */ + function allowance(address owner, address spender) internal view returns (uint256) { + return getPocoStorage().m_allowances[owner][spender]; + } + + /** + * @dev Get the EIP712 domain separator. + * @return The domain separator hash. + */ + function domainSeparator() internal view returns (bytes32) { + return getPocoStorage().EIP712DOMAIN_SEPARATOR; + } + + /** + * @dev Get the presigned order owner. + * @param orderHash The order hash. + * @return The presigned order owner address. + */ + function presigned(bytes32 orderHash) internal view returns (address) { + return getPocoStorage().m_presigned[orderHash]; + } + + /** + * @dev Get the consumed amount of an order. + * @param orderHash The order hash. + * @return The consumed amount. + */ + function consumed(bytes32 orderHash) internal view returns (uint256) { + return getPocoStorage().m_consumed[orderHash]; + } + + /** + * @dev Get a deal by its ID. + * @param dealId The deal ID. + * @return The deal struct. + */ + function deals(bytes32 dealId) internal view returns (IexecLibCore_v5.Deal storage) { + return getPocoStorage().m_deals[dealId]; + } + + /** + * @dev Get a task by its ID. + * @param taskId The task ID. + * @return The task struct. + */ + function tasks(bytes32 taskId) internal view returns (IexecLibCore_v5.Task storage) { + return getPocoStorage().m_tasks[taskId]; + } + + /** + * @dev Get a consensus by task ID. + * @param taskId The task ID. + * @return The consensus struct. + */ + function consensus(bytes32 taskId) internal view returns (IexecLibCore_v5.Consensus storage) { + return getPocoStorage().m_consensus[taskId]; + } + + /** + * @dev Get a contribution by task ID and worker address. + * @param taskId The task ID. + * @param worker The worker address. + * @return The contribution struct. + */ + function contributions( + bytes32 taskId, + address worker + ) internal view returns (IexecLibCore_v5.Contribution storage) { + return getPocoStorage().m_contributions[taskId][worker]; + } + + /** + * @dev Get the worker score. + * @param worker The worker address. + * @return The worker score. + */ + function workerScores(address worker) internal view returns (uint256) { + return getPocoStorage().m_workerScores[worker]; + } + + /** + * @dev Get the TEE broker address. + * @return The TEE broker address. + */ + function teeBroker() internal view returns (address) { + return getPocoStorage().m_teebroker; + } + + /** + * @dev Get the callback gas limit. + * @return The callback gas limit. + */ + function callbackGas() internal view returns (uint256) { + return getPocoStorage().m_callbackgas; + } + + /** + * @dev Get all categories. + * @return The categories array. + */ + function categories() internal view returns (IexecLibCore_v5.Category[] storage) { + return getPocoStorage().m_categories; + } + + /** + * @dev Get a category by index. + * @param index The category index. + * @return The category struct. + */ + function category(uint256 index) internal view returns (IexecLibCore_v5.Category storage) { + return getPocoStorage().m_categories[index]; + } + + /** + * @dev Get the v3 iExec Hub address. + * @return The v3 iExec Hub address. + */ + function v3IexecHub() internal view returns (IexecHubInterface) { + return getPocoStorage().m_v3_iexecHub; + } + + /** + * @dev Check if v3 score is imported for an address. + * @param addr The address to check. + * @return True if v3 score is imported. + */ + function v3ScoreImported(address addr) internal view returns (bool) { + return getPocoStorage().m_v3_scoreImported[addr]; + } + + // === Storage Setter Functions === + + /** + * @dev Set the app registry contract. + * @param registry The app registry contract. + */ + function setAppRegistry(IRegistry registry) internal { + getPocoStorage().m_appregistry = registry; + } + + /** + * @dev Set the dataset registry contract. + * @param registry The dataset registry contract. + */ + function setDatasetRegistry(IRegistry registry) internal { + getPocoStorage().m_datasetregistry = registry; + } + + /** + * @dev Set the workerpool registry contract. + * @param registry The workerpool registry contract. + */ + function setWorkerpoolRegistry(IRegistry registry) internal { + getPocoStorage().m_workerpoolregistry = registry; + } + + /** + * @dev Set the base token contract. + * @param token The base token contract. + */ + function setBaseToken(IERC20 token) internal { + getPocoStorage().m_baseToken = token; + } + + /** + * @dev Set the token name. + * @param newName The new token name. + */ + function setName(string memory newName) internal { + getPocoStorage().m_name = newName; + } + + /** + * @dev Set the token symbol. + * @param newSymbol The new token symbol. + */ + function setSymbol(string memory newSymbol) internal { + getPocoStorage().m_symbol = newSymbol; + } + + /** + * @dev Set the token decimals. + * @param newDecimals The new token decimals. + */ + function setDecimals(uint8 newDecimals) internal { + getPocoStorage().m_decimals = newDecimals; + } + + /** + * @dev Set the total supply. + * @param newTotalSupply The new total supply. + */ + function setTotalSupply(uint256 newTotalSupply) internal { + getPocoStorage().m_totalSupply = newTotalSupply; + } + + /** + * @dev Set the balance of an account. + * @param account The account address. + * @param amount The balance amount. + */ + function setBalance(address account, uint256 amount) internal { + getPocoStorage().m_balances[account] = amount; + } + + /** + * @dev Set the frozen balance of an account. + * @param account The account address. + * @param amount The frozen balance amount. + */ + function setFrozen(address account, uint256 amount) internal { + getPocoStorage().m_frozens[account] = amount; + } + + /** + * @dev Set the allowance amount. + * @param owner The owner address. + * @param spender The spender address. + * @param amount The allowance amount. + */ + function setAllowance(address owner, address spender, uint256 amount) internal { + getPocoStorage().m_allowances[owner][spender] = amount; + } + + /** + * @dev Set the EIP712 domain separator. + * @param newDomainSeparator The new domain separator hash. + */ + function setDomainSeparator(bytes32 newDomainSeparator) internal { + getPocoStorage().EIP712DOMAIN_SEPARATOR = newDomainSeparator; + } + + /** + * @dev Set the presigned order owner. + * @param orderHash The order hash. + * @param owner The presigned order owner address. + */ + function setPresigned(bytes32 orderHash, address owner) internal { + getPocoStorage().m_presigned[orderHash] = owner; + } + + /** + * @dev Set the consumed amount of an order. + * @param orderHash The order hash. + * @param amount The consumed amount. + */ + function setConsumed(bytes32 orderHash, uint256 amount) internal { + getPocoStorage().m_consumed[orderHash] = amount; + } + + /** + * @dev Set the worker score. + * @param worker The worker address. + * @param score The worker score. + */ + function setWorkerScore(address worker, uint256 score) internal { + getPocoStorage().m_workerScores[worker] = score; + } + + /** + * @dev Set the TEE broker address. + * @param broker The TEE broker address. + */ + function setTeeBroker(address broker) internal { + getPocoStorage().m_teebroker = broker; + } + + /** + * @dev Set the callback gas limit. + * @param gas The callback gas limit. + */ + function setCallbackGas(uint256 gas) internal { + getPocoStorage().m_callbackgas = gas; + } + + /** + * @dev Add a new category. + * @param cat The category to add. + */ + function addCategory(IexecLibCore_v5.Category memory cat) internal { + getPocoStorage().m_categories.push(cat); + } + + /** + * @dev Set the v3 iExec Hub address. + * @param hub The v3 iExec Hub address. + */ + function setV3IexecHub(IexecHubInterface hub) internal { + getPocoStorage().m_v3_iexecHub = hub; + } + + /** + * @dev Set the v3 score imported flag for an address. + * @param addr The address. + * @param imported The imported flag. + */ + function setV3ScoreImported(address addr, bool imported) internal { + getPocoStorage().m_v3_scoreImported[addr] = imported; + } +} diff --git a/contracts/libs/LibPocoStorage.v8.sol b/contracts/libs/LibPocoStorage.v8.sol new file mode 100644 index 000000000..761f5c365 --- /dev/null +++ b/contracts/libs/LibPocoStorage.v8.sol @@ -0,0 +1,538 @@ +// SPDX-FileCopyrightText: 2023-2025 IEXEC BLOCKCHAIN TECH +// SPDX-License-Identifier: Apache-2.0 + +pragma solidity ^0.8.0; + +import {IERC20} from "@openzeppelin/contracts-v5/interfaces/IERC20.sol"; +import {IERC721Enumerable} from "@openzeppelin/contracts-v5/interfaces/IERC721Enumerable.sol"; +import {IexecLibCore_v5} from "./IexecLibCore_v5.sol"; + +/** + * @title LibPocoStorage + * @dev Library for managing PoCo diamond storage using ERC-7201 namespaced storage pattern. + * This library replaces the Store abstract contract to support ERC-2535 diamond proxy architecture. + */ +library LibPocoStorage { + // Poco - Constants + uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7; + uint256 internal constant REVEAL_DEADLINE_RATIO = 2; + uint256 internal constant FINAL_DEADLINE_RATIO = 10; + uint256 internal constant WORKERPOOL_STAKE_RATIO = 30; + uint256 internal constant KITTY_RATIO = 10; + uint256 internal 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 internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; + + // Used with ERC-734 Key Manager identity contract for authorization management. + uint256 internal constant GROUPMEMBER_PURPOSE = 4; + + // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 private constant POCO_STORAGE_LOCATION = + 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; + + /// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage + struct PocoStorage { + // Registries + IRegistry m_appregistry; + IRegistry m_datasetregistry; + IRegistry m_workerpoolregistry; + // Escrow + IERC20 m_baseToken; + string m_name; + string m_symbol; + uint8 m_decimals; + uint256 m_totalSupply; + // In order to use the protocol, users have to deposit RLC + // and allow PoCo smart contracts to manage them. This state + // variable keeps track of users balances. + mapping(address => uint256) m_balances; + // When a deal is created, the protocol temporarily locks an amount + // of RLC tokens from the balances of both the requester and the workerpool owners. + // This is to guarantee the payment of different actors later. Frozen funds + // are released when the computation is completed and the result is pushed. + mapping(address => uint256) m_frozens; + mapping(address => mapping(address => uint256)) m_allowances; + // EIP-712 domain hash. + // Modified in IexecConfigurationFacet.updateDomainSeparator + bytes32 EIP712DOMAIN_SEPARATOR; // TODO rename + // Poco - Storage + + // Mapping an order hash to its owner. Since a smart contract cannot sign orders + // with a private key, it adds an entry to this mapping to provide presigned orders. + mapping(bytes32 => address) m_presigned; + // Each order has a volume (>=1). This tracks how much is consumed from + // the volume of each order. Mapping an order hash to its consumed amount. + mapping(bytes32 => uint256) m_consumed; + // a mapping to store PoCo classic deals. + mapping(bytes32 => IexecLibCore_v5.Deal) m_deals; + mapping(bytes32 => IexecLibCore_v5.Task) m_tasks; // per task + mapping(bytes32 => IexecLibCore_v5.Consensus) m_consensus; // per task + mapping(bytes32 => mapping(address => IexecLibCore_v5.Contribution)) m_contributions; // per task-worker + mapping(address => uint256) m_workerScores; // per worker + // Poco - Settings + // Address of a trusted TEE authority that manages enclave challenges. + // Modified in IexecConfigurationFacet.setTeeBroker + address m_teebroker; + // Max amount of gas to be used with callbacks. + // Modified in IexecConfigurationFacet.setCallbackGas + uint256 m_callbackgas; + // List of defined computation categories. + IexecLibCore_v5.Category[] m_categories; + // Backward compatibility + // Modified in IexecConfigurationFacet.configure + address m_v3_iexecHub; // IexecHubInterface + mapping(address => bool) m_v3_scoreImported; + // /!\ New storage variables not present in v6 store. + // A mapping to store PoCo Boost deals. + mapping(bytes32 => IexecLibCore_v5.DealBoost) m_dealsBoost; + } + + /** + * @dev Returns the storage pointer for PocoStorage. + * @return $ The storage pointer to PocoStorage struct. + */ + function getPocoStorage() internal pure returns (PocoStorage storage $) { + assembly ("memory-safe") { + $.slot := POCO_STORAGE_LOCATION + } + } + + // === Constants Getter Functions === + function getContributionDeadlineRatio() internal pure returns (uint256) { + return CONTRIBUTION_DEADLINE_RATIO; + } + + function getRevealDeadlineRatio() internal pure returns (uint256) { + return REVEAL_DEADLINE_RATIO; + } + + function getFinalDeadlineRatio() internal pure returns (uint256) { + return FINAL_DEADLINE_RATIO; + } + + function getWorkerpoolStakeRatio() internal pure returns (uint256) { + return WORKERPOOL_STAKE_RATIO; + } + + function getKittyRatio() internal pure returns (uint256) { + return KITTY_RATIO; + } + + function getKittyMin() internal pure returns (uint256) { + return KITTY_MIN; + } + + function getKittyAddress() internal pure returns (address) { + return KITTY_ADDRESS; + } + + function getGroupmemberPurpose() internal pure returns (uint256) { + return GROUPMEMBER_PURPOSE; + } + + // === Storage Getter Functions === + + /** + * @dev Get the app registry contract. + * @return The app registry contract interface. + */ + function appRegistry() internal view returns (IRegistry) { + return getPocoStorage().m_appregistry; + } + + /** + * @dev Get the dataset registry contract. + * @return The dataset registry contract interface. + */ + function datasetRegistry() internal view returns (IRegistry) { + return getPocoStorage().m_datasetregistry; + } + + /** + * @dev Get the workerpool registry contract. + * @return The workerpool registry contract interface. + */ + function workerpoolRegistry() internal view returns (IRegistry) { + return getPocoStorage().m_workerpoolregistry; + } + + /** + * @dev Get the base token contract. + * @return The base token contract interface. + */ + function baseToken() internal view returns (IERC20) { + return getPocoStorage().m_baseToken; + } + + /** + * @dev Get the token name. + * @return The token name string. + */ + function name() internal view returns (string storage) { + return getPocoStorage().m_name; + } + + /** + * @dev Get the token symbol. + * @return The token symbol string. + */ + function symbol() internal view returns (string storage) { + return getPocoStorage().m_symbol; + } + + /** + * @dev Get the token decimals. + * @return The token decimals. + */ + function decimals() internal view returns (uint8) { + return getPocoStorage().m_decimals; + } + + /** + * @dev Get the total supply. + * @return The total supply amount. + */ + function totalSupply() internal view returns (uint256) { + return getPocoStorage().m_totalSupply; + } + + /** + * @dev Get the balance of an account. + * @param account The account address. + * @return The balance amount. + */ + function balanceOf(address account) internal view returns (uint256) { + return getPocoStorage().m_balances[account]; + } + + /** + * @dev Get the frozen balance of an account. + * @param account The account address. + * @return The frozen balance amount. + */ + function frozenOf(address account) internal view returns (uint256) { + return getPocoStorage().m_frozens[account]; + } + + /** + * @dev Get the allowance amount. + * @param owner The owner address. + * @param spender The spender address. + * @return The allowance amount. + */ + function allowance(address owner, address spender) internal view returns (uint256) { + return getPocoStorage().m_allowances[owner][spender]; + } + + /** + * @dev Get the EIP712 domain separator. + * @return The domain separator hash. + */ + function domainSeparator() internal view returns (bytes32) { + return getPocoStorage().EIP712DOMAIN_SEPARATOR; + } + + /** + * @dev Get the presigned order owner. + * @param orderHash The order hash. + * @return The presigned order owner address. + */ + function presigned(bytes32 orderHash) internal view returns (address) { + return getPocoStorage().m_presigned[orderHash]; + } + + /** + * @dev Get the consumed amount of an order. + * @param orderHash The order hash. + * @return The consumed amount. + */ + function consumed(bytes32 orderHash) internal view returns (uint256) { + return getPocoStorage().m_consumed[orderHash]; + } + + /** + * @dev Get a deal by its ID. + * @param dealId The deal ID. + * @return The deal struct. + */ + function deals(bytes32 dealId) internal view returns (IexecLibCore_v5.Deal storage) { + return getPocoStorage().m_deals[dealId]; + } + + /** + * @dev Get a boost deal by its ID. + * @param dealId The deal ID. + * @return The boost deal struct. + */ + function dealsBoost(bytes32 dealId) internal view returns (IexecLibCore_v5.DealBoost storage) { + return getPocoStorage().m_dealsBoost[dealId]; + } + + /** + * @dev Get a task by its ID. + * @param taskId The task ID. + * @return The task struct. + */ + function tasks(bytes32 taskId) internal view returns (IexecLibCore_v5.Task storage) { + return getPocoStorage().m_tasks[taskId]; + } + + /** + * @dev Get a consensus by task ID. + * @param taskId The task ID. + * @return The consensus struct. + */ + function consensus(bytes32 taskId) internal view returns (IexecLibCore_v5.Consensus storage) { + return getPocoStorage().m_consensus[taskId]; + } + + /** + * @dev Get a contribution by task ID and worker address. + * @param taskId The task ID. + * @param worker The worker address. + * @return The contribution struct. + */ + function contributions( + bytes32 taskId, + address worker + ) internal view returns (IexecLibCore_v5.Contribution storage) { + return getPocoStorage().m_contributions[taskId][worker]; + } + + /** + * @dev Get the worker score. + * @param worker The worker address. + * @return The worker score. + */ + function workerScores(address worker) internal view returns (uint256) { + return getPocoStorage().m_workerScores[worker]; + } + + /** + * @dev Get the TEE broker address. + * @return The TEE broker address. + */ + function teeBroker() internal view returns (address) { + return getPocoStorage().m_teebroker; + } + + /** + * @dev Get the callback gas limit. + * @return The callback gas limit. + */ + function callbackGas() internal view returns (uint256) { + return getPocoStorage().m_callbackgas; + } + + /** + * @dev Get all categories. + * @return The categories array. + */ + function categories() internal view returns (IexecLibCore_v5.Category[] storage) { + return getPocoStorage().m_categories; + } + + /** + * @dev Get a category by index. + * @param index The category index. + * @return The category struct. + */ + function category(uint256 index) internal view returns (IexecLibCore_v5.Category storage) { + return getPocoStorage().m_categories[index]; + } + + /** + * @dev Get the v3 iExec Hub address. + * @return The v3 iExec Hub address. + */ + function v3IexecHub() internal view returns (address) { + return getPocoStorage().m_v3_iexecHub; + } + + /** + * @dev Check if v3 score is imported for an address. + * @param addr The address to check. + * @return True if v3 score is imported. + */ + function v3ScoreImported(address addr) internal view returns (bool) { + return getPocoStorage().m_v3_scoreImported[addr]; + } + + // === Storage Setter Functions === + + /** + * @dev Set the app registry contract. + * @param registry The app registry contract. + */ + function setAppRegistry(IRegistry registry) internal { + getPocoStorage().m_appregistry = registry; + } + + /** + * @dev Set the dataset registry contract. + * @param registry The dataset registry contract. + */ + function setDatasetRegistry(IRegistry registry) internal { + getPocoStorage().m_datasetregistry = registry; + } + + /** + * @dev Set the workerpool registry contract. + * @param registry The workerpool registry contract. + */ + function setWorkerpoolRegistry(IRegistry registry) internal { + getPocoStorage().m_workerpoolregistry = registry; + } + + /** + * @dev Set the base token contract. + * @param token The base token contract. + */ + function setBaseToken(IERC20 token) internal { + getPocoStorage().m_baseToken = token; + } + + /** + * @dev Set the token name. + * @param newName The new token name. + */ + function setName(string memory newName) internal { + getPocoStorage().m_name = newName; + } + + /** + * @dev Set the token symbol. + * @param newSymbol The new token symbol. + */ + function setSymbol(string memory newSymbol) internal { + getPocoStorage().m_symbol = newSymbol; + } + + /** + * @dev Set the token decimals. + * @param newDecimals The new token decimals. + */ + function setDecimals(uint8 newDecimals) internal { + getPocoStorage().m_decimals = newDecimals; + } + + /** + * @dev Set the total supply. + * @param newTotalSupply The new total supply. + */ + function setTotalSupply(uint256 newTotalSupply) internal { + getPocoStorage().m_totalSupply = newTotalSupply; + } + + /** + * @dev Set the balance of an account. + * @param account The account address. + * @param amount The balance amount. + */ + function setBalance(address account, uint256 amount) internal { + getPocoStorage().m_balances[account] = amount; + } + + /** + * @dev Set the frozen balance of an account. + * @param account The account address. + * @param amount The frozen balance amount. + */ + function setFrozen(address account, uint256 amount) internal { + getPocoStorage().m_frozens[account] = amount; + } + + /** + * @dev Set the allowance amount. + * @param owner The owner address. + * @param spender The spender address. + * @param amount The allowance amount. + */ + function setAllowance(address owner, address spender, uint256 amount) internal { + getPocoStorage().m_allowances[owner][spender] = amount; + } + + /** + * @dev Set the EIP712 domain separator. + * @param newDomainSeparator The new domain separator hash. + */ + function setDomainSeparator(bytes32 newDomainSeparator) internal { + getPocoStorage().EIP712DOMAIN_SEPARATOR = newDomainSeparator; + } + + /** + * @dev Set the presigned order owner. + * @param orderHash The order hash. + * @param owner The presigned order owner address. + */ + function setPresigned(bytes32 orderHash, address owner) internal { + getPocoStorage().m_presigned[orderHash] = owner; + } + + /** + * @dev Set the consumed amount of an order. + * @param orderHash The order hash. + * @param amount The consumed amount. + */ + function setConsumed(bytes32 orderHash, uint256 amount) internal { + getPocoStorage().m_consumed[orderHash] = amount; + } + + /** + * @dev Set the worker score. + * @param worker The worker address. + * @param score The worker score. + */ + function setWorkerScore(address worker, uint256 score) internal { + getPocoStorage().m_workerScores[worker] = score; + } + + /** + * @dev Set the TEE broker address. + * @param broker The TEE broker address. + */ + function setTeeBroker(address broker) internal { + getPocoStorage().m_teebroker = broker; + } + + /** + * @dev Set the callback gas limit. + * @param gas The callback gas limit. + */ + function setCallbackGas(uint256 gas) internal { + getPocoStorage().m_callbackgas = gas; + } + + /** + * @dev Add a new category. + * @param cat The category to add. + */ + function addCategory(IexecLibCore_v5.Category memory cat) internal { + getPocoStorage().m_categories.push(cat); + } + + /** + * @dev Set the v3 iExec Hub address. + * @param hub The v3 iExec Hub address. + */ + function setV3IexecHub(address hub) internal { + getPocoStorage().m_v3_iexecHub = hub; + } + + /** + * @dev Set the v3 score imported flag for an address. + * @param addr The address. + * @param imported The imported flag. + */ + function setV3ScoreImported(address addr, bool imported) internal { + getPocoStorage().m_v3_scoreImported[addr] = imported; + } +} + +// Registry interface used in storage. +interface IRegistry is IERC721Enumerable { + function isRegistered(address _entry) external view returns (bool); +} diff --git a/contracts/modules/FacetBase.sol b/contracts/modules/FacetBase.sol index 826cc07d2..f0b3f31d1 100644 --- a/contracts/modules/FacetBase.sol +++ b/contracts/modules/FacetBase.sol @@ -3,24 +3,41 @@ pragma solidity ^0.6.0; -import "../Store.sol"; +import "../libs/LibPocoStorage.sol"; import "./interfaces/IOwnable.sol"; // Functions that were declared in ERC1538Store are re-declared here. // TODO clean this (use LibDiamond) // - All calls to `owner()` should use `LibDiamond.contractOwner()`. -abstract contract FacetBase is Store { +/** + * @title Base contract of all Facet contracts using diamond storage. + * @dev Every module must inherit from this contract. + * This version uses LibPocoStorage library instead of inheriting from Store abstract contract + * to support ERC-2535 diamond proxy architecture. + */ +abstract contract FacetBase { modifier onlyOwner() { require(_msgSender() == owner(), "Ownable: caller is not the owner"); _; } - function owner() public view returns (address) { + function owner() public view virtual returns (address) { return IOwnable(address(this)).owner(); } - function _msgSender() internal view returns (address) { + function _msgSender() internal view virtual returns (address) { return msg.sender; } + + // === Storage Access Helper Functions === + // These provide backward compatibility for facets that were using Store directly + + /** + * @dev Get the PocoStorage struct for direct access when needed. + * @return The storage pointer to PocoStorage struct. + */ + function getPocoStorage() internal pure returns (LibPocoStorage.PocoStorage storage) { + return LibPocoStorage.getPocoStorage(); + } } diff --git a/contracts/modules/FacetBase.v8.sol b/contracts/modules/FacetBase.v8.sol index 9e0c6065b..646c8bd4a 100644 --- a/contracts/modules/FacetBase.v8.sol +++ b/contracts/modules/FacetBase.v8.sol @@ -4,28 +4,41 @@ pragma solidity ^0.8.0; import {IERC5313} from "@openzeppelin/contracts-v5/interfaces/IERC5313.sol"; -import {Store} from "../Store.v8.sol"; +import {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; // Functions that were declared in ERC1538Store are re-declared here. // TODO clean this (use LibDiamond) // - All calls to `owner()` should use `LibDiamond.contractOwner()`. /** - * @title Base contract of all Facet contracts. + * @title Base contract of all Facet contracts using diamond storage. * @dev Every module must inherit from this contract. + * This version uses LibPocoStorage library instead of inheriting from Store abstract contract + * to support ERC-2535 diamond proxy architecture. */ -abstract contract FacetBase is Store { +abstract contract FacetBase { modifier onlyOwner() { require(_msgSender() == owner(), "Ownable: caller is not the owner"); _; } - function owner() public view returns (address) { + function owner() public view virtual returns (address) { // Make an external call to delegatecall the OwnershipFacet. return IERC5313(address(this)).owner(); } - function _msgSender() internal view returns (address) { + function _msgSender() internal view virtual returns (address) { return msg.sender; } + + // === Storage Access Helper Functions === + // These provide backward compatibility for facets that were using Store directly + + /** + * @dev Get the PocoStorage struct for direct access when needed. + * @return The storage pointer to PocoStorage struct. + */ + function _getPocoStorage() internal pure returns (LibPocoStorage.PocoStorage storage) { + return LibPocoStorage.getPocoStorage(); + } } diff --git a/contracts/modules/facets/IexecAccessorsABILegacyFacet.sol b/contracts/modules/facets/IexecAccessorsABILegacyFacet.sol index eb83136fb..347f35e9b 100644 --- a/contracts/modules/facets/IexecAccessorsABILegacyFacet.sol +++ b/contracts/modules/facets/IexecAccessorsABILegacyFacet.sol @@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2; import "../FacetBase.sol"; import "../interfaces/IexecAccessorsABILegacy.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return ($.m_balances[account], $.m_frozens[account]); } @@ -109,7 +110,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { override returns (IexecLibCore_v5.ContributionStatusEnum, bytes32, bytes32, address) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Category memory category = $.m_categories[_catid]; return (category.name, category.description, category.workClockTimeRef); } diff --git a/contracts/modules/facets/IexecAccessorsFacet.sol b/contracts/modules/facets/IexecAccessorsFacet.sol index e3e4658bc..345a4080c 100644 --- a/contracts/modules/facets/IexecAccessorsFacet.sol +++ b/contracts/modules/facets/IexecAccessorsFacet.sol @@ -6,76 +6,77 @@ pragma experimental ABIEncoderV2; import "../FacetBase.sol"; import "../interfaces/IexecAccessors.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.sol"; contract IexecAccessorsFacet is IexecAccessors, FacetBase { function name() external view override returns (string memory) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_name; } function symbol() external view override returns (string memory) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_symbol; } function decimals() external view override returns (uint8) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_decimals; } function totalSupply() external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_totalSupply; } function balanceOf(address account) external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_balances[account]; } function frozenOf(address account) external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_frozens[account]; } function allowance(address account, address spender) external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_allowances[account][spender]; } function viewAccount( address account ) external view override returns (IexecLibCore_v5.Account memory) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return IexecLibCore_v5.Account($.m_balances[account], $.m_frozens[account]); } function token() external view override returns (address) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return address($.m_baseToken); } function viewDeal( bytes32 _id ) external view override returns (IexecLibCore_v5.Deal memory deal) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_deals[_id]; } function viewConsumed(bytes32 _id) external view override returns (uint256 consumed) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_consumed[_id]; } function viewPresigned(bytes32 _id) external view override returns (address signer) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_presigned[_id]; } function viewTask( bytes32 _taskid ) external view override returns (IexecLibCore_v5.Task memory) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_contributions[_taskid][_worker]; } function viewScore(address _worker) external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_workerScores[_worker]; } function resultFor(bytes32 id) external view override returns (bytes memory) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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,74 +103,74 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { function viewCategory( uint256 _catid ) external view override returns (IexecLibCore_v5.Category memory category) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_categories[_catid]; } function countCategory() external view override returns (uint256 count) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_categories.length; } function appregistry() external view override returns (IRegistry) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_appregistry; } function datasetregistry() external view override returns (IRegistry) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_datasetregistry; } function workerpoolregistry() external view override returns (IRegistry) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_workerpoolregistry; } function teebroker() external view override returns (address) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_teebroker; } function callbackgas() external view override returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_callbackgas; } function contribution_deadline_ratio() external view override returns (uint256) { - return CONTRIBUTION_DEADLINE_RATIO; + return LibPocoStorage.getContributionDeadlineRatio(); } function reveal_deadline_ratio() external view override returns (uint256) { - return REVEAL_DEADLINE_RATIO; + return LibPocoStorage.getRevealDeadlineRatio(); } function final_deadline_ratio() external view override returns (uint256) { - return FINAL_DEADLINE_RATIO; + return LibPocoStorage.getFinalDeadlineRatio(); } function workerpool_stake_ratio() external view override returns (uint256) { - return WORKERPOOL_STAKE_RATIO; + return LibPocoStorage.getWorkerpoolStakeRatio(); } function kitty_ratio() external view override returns (uint256) { - return KITTY_RATIO; + return LibPocoStorage.getKittyRatio(); } function kitty_min() external view override returns (uint256) { - return KITTY_MIN; + return LibPocoStorage.getKittyMin(); } function kitty_address() external view override returns (address) { - return KITTY_ADDRESS; + return LibPocoStorage.getKittyAddress(); } function groupmember_purpose() external view override returns (uint256) { - return GROUPMEMBER_PURPOSE; + return LibPocoStorage.getGroupmemberPurpose(); } function eip712domain_separator() external view override returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.EIP712DOMAIN_SEPARATOR; } } diff --git a/contracts/modules/facets/IexecCategoryManagerFacet.sol b/contracts/modules/facets/IexecCategoryManagerFacet.sol index 63a155330..bebeb529f 100644 --- a/contracts/modules/facets/IexecCategoryManagerFacet.sol +++ b/contracts/modules/facets/IexecCategoryManagerFacet.sol @@ -5,6 +5,7 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; import "../FacetBase.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.sol"; import "../interfaces/IexecCategoryManager.sol"; contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase { @@ -16,10 +17,9 @@ contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase { string calldata description, uint256 workClockTimeRef ) external override onlyOwner returns (uint256) { - PocoStorage storage $ = getPocoStorage(); - $.m_categories.push(IexecLibCore_v5.Category(name, description, workClockTimeRef)); + LibPocoStorage.addCategory(IexecLibCore_v5.Category(name, description, workClockTimeRef)); - uint256 catid = $.m_categories.length - 1; + uint256 catid = LibPocoStorage.categories().length - 1; emit CreateCategory(catid, name, description, workClockTimeRef); return catid; diff --git a/contracts/modules/facets/IexecConfigurationExtraFacet.sol b/contracts/modules/facets/IexecConfigurationExtraFacet.sol index 069423401..6babb91ac 100644 --- a/contracts/modules/facets/IexecConfigurationExtraFacet.sol +++ b/contracts/modules/facets/IexecConfigurationExtraFacet.sol @@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2; import "../FacetBase.sol"; import "../interfaces/IexecConfigurationExtra.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); $.m_appregistry = IRegistry(_appregistryAddress); $.m_datasetregistry = IRegistry(_datasetregistryAddress); $.m_workerpoolregistry = IRegistry(_workerpoolregistryAddress); diff --git a/contracts/modules/facets/IexecConfigurationFacet.sol b/contracts/modules/facets/IexecConfigurationFacet.sol index a062c5157..9e0e294df 100644 --- a/contracts/modules/facets/IexecConfigurationFacet.sol +++ b/contracts/modules/facets/IexecConfigurationFacet.sol @@ -8,6 +8,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "../FacetBase.sol"; import "../interfaces/IexecConfiguration.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.sol"; contract IexecConfigurationFacet is IexecConfiguration, FacetBase { using SafeMathExtended for uint256; @@ -24,19 +25,18 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { address _workerpoolregistryAddress, address _v3_iexecHubAddress ) external override onlyOwner { - PocoStorage storage $ = getPocoStorage(); - require($.EIP712DOMAIN_SEPARATOR == bytes32(0), "already-configured"); - $.EIP712DOMAIN_SEPARATOR = _domain().hash(); + require(LibPocoStorage.domainSeparator() == bytes32(0), "already-configured"); + LibPocoStorage.setDomainSeparator(_domain().hash()); - $.m_baseToken = IERC20(_token); - $.m_name = _name; - $.m_symbol = _symbol; - $.m_decimals = _decimal; - $.m_appregistry = IRegistry(_appregistryAddress); - $.m_datasetregistry = IRegistry(_datasetregistryAddress); - $.m_workerpoolregistry = IRegistry(_workerpoolregistryAddress); - $.m_v3_iexecHub = IexecHubInterface(_v3_iexecHubAddress); - $.m_callbackgas = 100000; + LibPocoStorage.setBaseToken(IERC20(_token)); + LibPocoStorage.setName(_name); + LibPocoStorage.setSymbol(_symbol); + LibPocoStorage.setDecimals(_decimal); + LibPocoStorage.setAppRegistry(IRegistry(_appregistryAddress)); + LibPocoStorage.setDatasetRegistry(IRegistry(_datasetregistryAddress)); + LibPocoStorage.setWorkerpoolRegistry(IRegistry(_workerpoolregistryAddress)); + LibPocoStorage.setV3IexecHub(IexecHubInterface(_v3_iexecHubAddress)); + LibPocoStorage.setCallbackGas(100000); } function domain() external view override returns (IexecLibOrders_v5.EIP712Domain memory) { @@ -44,28 +44,26 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { } function updateDomainSeparator() external override { - PocoStorage storage $ = getPocoStorage(); - require($.EIP712DOMAIN_SEPARATOR != bytes32(0), "not-configured"); - $.EIP712DOMAIN_SEPARATOR = _domain().hash(); + require(LibPocoStorage.domainSeparator() != bytes32(0), "not-configured"); + LibPocoStorage.setDomainSeparator(_domain().hash()); } function importScore(address _worker) external override { - PocoStorage storage $ = getPocoStorage(); - require(!$.m_v3_scoreImported[_worker], "score-already-imported"); - $.m_workerScores[_worker] = $.m_workerScores[_worker].max( - $.m_v3_iexecHub.viewScore(_worker) + require(!LibPocoStorage.v3ScoreImported(_worker), "score-already-imported"); + uint256 currentScore = LibPocoStorage.workerScores(_worker); + uint256 newScore = currentScore.max( + IexecHubInterface(LibPocoStorage.v3IexecHub()).viewScore(_worker) ); - $.m_v3_scoreImported[_worker] = true; + LibPocoStorage.setWorkerScore(_worker, newScore); + LibPocoStorage.setV3ScoreImported(_worker, true); } function setTeeBroker(address _teebroker) external override onlyOwner { - PocoStorage storage $ = getPocoStorage(); - $.m_teebroker = _teebroker; + LibPocoStorage.setTeeBroker(_teebroker); } function setCallbackGas(uint256 _callbackgas) external override onlyOwner { - PocoStorage storage $ = getPocoStorage(); - $.m_callbackgas = _callbackgas; + LibPocoStorage.setCallbackGas(_callbackgas); } function _chainId() internal pure returns (uint256 id) { diff --git a/contracts/modules/facets/IexecERC20Core.sol b/contracts/modules/facets/IexecERC20Core.sol index d78d0f0ef..94f1bf927 100644 --- a/contracts/modules/facets/IexecERC20Core.sol +++ b/contracts/modules/facets/IexecERC20Core.sol @@ -5,6 +5,7 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; import "../FacetBase.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.sol"; contract IexecERC20Core is FacetBase { using SafeMathExtended for uint256; @@ -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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); $.m_allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } diff --git a/contracts/modules/facets/IexecERC20Facet.sol b/contracts/modules/facets/IexecERC20Facet.sol index 2069c3c0e..95091b0f5 100644 --- a/contracts/modules/facets/IexecERC20Facet.sol +++ b/contracts/modules/facets/IexecERC20Facet.sol @@ -8,6 +8,7 @@ import "./IexecERC20Core.sol"; import "../FacetBase.sol"; import "../interfaces/IexecERC20.sol"; import "../interfaces/IexecTokenSpender.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); _approve(_msgSender(), spender, $.m_allowances[_msgSender()][spender].sub(subtractedValue)); return true; } diff --git a/contracts/modules/facets/IexecEscrow.v8.sol b/contracts/modules/facets/IexecEscrow.v8.sol index 19b5c4cd9..ccf243874 100644 --- a/contracts/modules/facets/IexecEscrow.v8.sol +++ b/contracts/modules/facets/IexecEscrow.v8.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.0; import {FacetBase} from "../FacetBase.v8.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; /** * @title Manage (lock/unlock/reward/seize) user funds. @@ -21,7 +22,7 @@ contract IexecEscrow is FacetBase { * @param value The value to lock. */ function lock(address account, uint256 value) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); _transfer(account, address(this), value); $.m_frozens[account] += value; emit Lock(account, value); @@ -33,7 +34,7 @@ contract IexecEscrow is FacetBase { * @param value The value to unlock. */ function unlock(address account, uint256 value) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); _transfer(address(this), account, value); $.m_frozens[account] -= value; emit Unlock(account, value); @@ -57,7 +58,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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); $.m_frozens[account] -= value; emit Seize(account, value, ref); } @@ -78,7 +79,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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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/modules/facets/IexecEscrowNativeFacet.sol b/contracts/modules/facets/IexecEscrowNativeFacet.sol index bdb8aca91..bfc4a4c36 100644 --- a/contracts/modules/facets/IexecEscrowNativeFacet.sol +++ b/contracts/modules/facets/IexecEscrowNativeFacet.sol @@ -7,6 +7,7 @@ pragma experimental ABIEncoderV2; import "./IexecERC20Core.sol"; import "../FacetBase.sol"; import "../interfaces/IexecEscrowNative.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); uint256 delta = address(this).balance.div(nRLCtoWei).sub($.m_totalSupply); _mint(owner(), delta); return delta; diff --git a/contracts/modules/facets/IexecEscrowTokenFacet.sol b/contracts/modules/facets/IexecEscrowTokenFacet.sol index 900f9e675..25625898c 100644 --- a/contracts/modules/facets/IexecEscrowTokenFacet.sol +++ b/contracts/modules/facets/IexecEscrowTokenFacet.sol @@ -8,6 +8,7 @@ import "./IexecERC20Core.sol"; import "../FacetBase.sol"; import "../interfaces/IexecEscrowToken.sol"; import "../interfaces/IexecTokenSpender.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); require($.m_baseToken.transferFrom(from, address(this), amount), "failled-transferFrom"); } function _withdraw(address to, uint256 amount) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); $.m_baseToken.transfer(to, amount); } } diff --git a/contracts/modules/facets/IexecEscrowTokenSwapFacet.sol b/contracts/modules/facets/IexecEscrowTokenSwapFacet.sol index fbf7b3b68..db093091b 100644 --- a/contracts/modules/facets/IexecEscrowTokenSwapFacet.sol +++ b/contracts/modules/facets/IexecEscrowTokenSwapFacet.sol @@ -8,6 +8,7 @@ import "./IexecERC20Core.sol"; import "./SignatureVerifier.sol"; import "../FacetBase.sol"; import "../interfaces/IexecEscrowTokenSwap.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); uint256 volume; volume = _apporder.volume.sub( $.m_consumed[keccak256(_toEthTypedStruct(_apporder.hash(), $.EIP712DOMAIN_SEPARATOR))] diff --git a/contracts/modules/facets/IexecOrderManagementFacet.sol b/contracts/modules/facets/IexecOrderManagementFacet.sol index 8302adab9..804a7336a 100644 --- a/contracts/modules/facets/IexecOrderManagementFacet.sol +++ b/contracts/modules/facets/IexecOrderManagementFacet.sol @@ -8,6 +8,7 @@ import {SignatureVerifier} from "./SignatureVerifier.v8.sol"; import {FacetBase} from "../FacetBase.v8.sol"; import {IexecOrderManagement} from "../interfaces/IexecOrderManagement.v8.sol"; import {IexecLibOrders_v5} from "../../libs/IexecLibOrders_v5.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, SignatureVerifier { using IexecLibOrders_v5 for IexecLibOrders_v5.AppOrder; @@ -25,7 +26,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageAppOrder( IexecLibOrders_v5.AppOrderOperation calldata _apporderoperation ) external override { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); address owner = _requestorderoperation.order.requester; require( owner == _msgSender() || diff --git a/contracts/modules/facets/IexecPoco1Facet.sol b/contracts/modules/facets/IexecPoco1Facet.sol index 1932df86c..509aa5f34 100644 --- a/contracts/modules/facets/IexecPoco1Facet.sol +++ b/contracts/modules/facets/IexecPoco1Facet.sol @@ -8,6 +8,7 @@ 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 {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; import {IWorkerpool} from "../../registries/workerpools/IWorkerpool.v8.sol"; import {FacetBase} from "../FacetBase.v8.sol"; import {IexecPoco1} from "../interfaces/IexecPoco1.v8.sol"; @@ -145,7 +146,7 @@ contract IexecPoco1Facet is IexecLibOrders_v5.RequestOrder calldata _requestorder, address _sponsor ) private returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); /** * Check orders compatibility */ @@ -365,7 +366,7 @@ contract IexecPoco1Facet is //slither-disable-next-line divide-before-multiply lock( deal.workerpool.owner, - ((deal.workerpool.price * WORKERPOOL_STAKE_RATIO) / 100) * volume // ORDER IS IMPORTANT HERE! + ((deal.workerpool.price * LibPocoStorage.getWorkerpoolStakeRatio()) / 100) * volume // ORDER IS IMPORTANT HERE! ); /** diff --git a/contracts/modules/facets/IexecPoco2Facet.sol b/contracts/modules/facets/IexecPoco2Facet.sol index c7754f76c..2ec5184a3 100644 --- a/contracts/modules/facets/IexecPoco2Facet.sol +++ b/contracts/modules/facets/IexecPoco2Facet.sol @@ -8,13 +8,14 @@ import {IOracleConsumer} from "../../external/interfaces/IOracleConsumer.sol"; import {IexecLibCore_v5} from "../../libs/IexecLibCore_v5.sol"; import {IexecLibOrders_v5} from "../../libs/IexecLibOrders_v5.sol"; import {FacetBase} from "../FacetBase.v8.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; import {IexecPoco2} from "../interfaces/IexecPoco2.v8.sol"; import {IexecEscrow} from "./IexecEscrow.v8.sol"; import {SignatureVerifier} from "./SignatureVerifier.v8.sol"; contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifier { modifier onlyScheduler(bytes32 _taskId) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); require(_msgSender() == $.m_deals[$.m_tasks[_taskId].dealid].workerpool.owner); _; } @@ -23,11 +24,12 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Escrow overhead for contribution * ***************************************************************************/ function successWork(bytes32 _dealid, bytes32 _taskid) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Deal storage deal = $.m_deals[_dealid]; uint256 taskPrice = deal.app.price + deal.dataset.price + deal.workerpool.price; - uint256 poolstake = (deal.workerpool.price * WORKERPOOL_STAKE_RATIO) / 100; + uint256 poolstake = (deal.workerpool.price * LibPocoStorage.getWorkerpoolStakeRatio()) / + 100; // Seize the payer of the task seize(deal.sponsor, taskPrice, _taskid); @@ -44,21 +46,28 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie // pool reward performed by consensus manager // Retrieve part of the kitty - uint256 kitty = $.m_frozens[KITTY_ADDRESS]; + uint256 kitty = $.m_frozens[LibPocoStorage.getKittyAddress()]; if (kitty > 0) { - // Get a fraction of the kitty where KITTY_MIN <= fraction <= kitty - kitty = Math.min(Math.max((kitty * KITTY_RATIO) / 100, KITTY_MIN), kitty); - seize(KITTY_ADDRESS, kitty, _taskid); + // Get a fraction of the kitty where LibPocoStorage.getKittyMin() <= fraction <= kitty + kitty = Math.min( + Math.max( + (kitty * LibPocoStorage.getKittyRatio()) / 100, + LibPocoStorage.getKittyMin() + ), + kitty + ); + seize(LibPocoStorage.getKittyAddress(), kitty, _taskid); reward(deal.workerpool.owner, kitty, _taskid); } } function failedWork(bytes32 _dealid, bytes32 _taskid) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_dealid]; uint256 taskPrice = deal.app.price + deal.dataset.price + deal.workerpool.price; - uint256 poolstake = (deal.workerpool.price * WORKERPOOL_STAKE_RATIO) / 100; + uint256 poolstake = (deal.workerpool.price * LibPocoStorage.getWorkerpoolStakeRatio()) / + 100; unlock(deal.sponsor, taskPrice); // Refund the payer of the task seize(deal.workerpool.owner, poolstake, _taskid); @@ -68,16 +77,16 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * where functions would together uselessly transfer value from main PoCo * proxy to kitty, then would transfer value back from kitty to main PoCo proxy. */ - $.m_frozens[KITTY_ADDRESS] += poolstake; // → Kitty / Burn - emit Reward(KITTY_ADDRESS, poolstake, _taskid); - emit Lock(KITTY_ADDRESS, poolstake); + $.m_frozens[LibPocoStorage.getKittyAddress()] += poolstake; // → Kitty / Burn + emit Reward(LibPocoStorage.getKittyAddress(), poolstake, _taskid); + emit Lock(LibPocoStorage.getKittyAddress(), poolstake); } /*************************************************************************** * Consensus methods * ***************************************************************************/ function initialize(bytes32 _dealid, uint256 idx) public override returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_dealid]; require(idx >= deal.botFirst); @@ -91,8 +100,11 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie task.dealid = _dealid; task.idx = idx; task.timeref = $.m_categories[deal.category].workClockTimeRef; - task.contributionDeadline = deal.startTime + task.timeref * CONTRIBUTION_DEADLINE_RATIO; - task.finalDeadline = deal.startTime + task.timeref * FINAL_DEADLINE_RATIO; + task.contributionDeadline = + deal.startTime + + task.timeref * + LibPocoStorage.getContributionDeadlineRatio(); + task.finalDeadline = deal.startTime + task.timeref * LibPocoStorage.getFinalDeadlineRatio(); // setup denominator $.m_consensus[taskid].total = 1; @@ -110,7 +122,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _enclaveSign, bytes calldata _authorizationSign ) external override { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -188,7 +200,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _enclaveSign, bytes calldata _authorizationSign ) external override { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -239,7 +251,10 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie task.status = IexecLibCore_v5.TaskStatusEnum.COMPLETED; task.consensusValue = contribution.resultHash; - task.revealDeadline = block.timestamp + task.timeref * REVEAL_DEADLINE_RATIO; + task.revealDeadline = + block.timestamp + + task.timeref * + LibPocoStorage.getRevealDeadlineRatio(); task.revealCounter = 1; task.winnerCounter = 1; task.resultDigest = _resultDigest; @@ -259,7 +274,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function reveal(bytes32 _taskid, bytes32 _resultDigest) external override { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -282,7 +297,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function reopen(bytes32 _taskid) external override onlyScheduler(_taskid) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; require(task.status == IexecLibCore_v5.TaskStatusEnum.REVEALING); require(task.finalDeadline > block.timestamp); @@ -314,7 +329,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _results, bytes calldata _resultsCallback // Expansion - result separation ) external override onlyScheduler(_taskid) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -349,7 +364,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function claim(bytes32 _taskid) public override { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; require( task.status == IexecLibCore_v5.TaskStatusEnum.ACTIVE || @@ -379,7 +394,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Consensus detection */ function checkConsensus(bytes32 _taskid, bytes32 _consensus) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Consensus storage consensus = $.m_consensus[_taskid]; @@ -406,7 +421,10 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie // _msgSender() is a contributor: no need to check task.status = IexecLibCore_v5.TaskStatusEnum.REVEALING; task.consensusValue = _consensus; - task.revealDeadline = block.timestamp + task.timeref * REVEAL_DEADLINE_RATIO; + task.revealDeadline = + block.timestamp + + task.timeref * + LibPocoStorage.getRevealDeadlineRatio(); task.revealCounter = 0; task.winnerCounter = winnerCounter; @@ -418,7 +436,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Reward distribution */ function distributeRewards(bytes32 _taskid) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task memory task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -497,7 +515,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Reward distribution for contributeAndFinalize */ function distributeRewardsFast(bytes32 _taskid) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); IexecLibCore_v5.Task memory task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -514,7 +532,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Callback for smartcontracts using EIP1154 */ function executeCallback(bytes32 _taskid, bytes memory _resultsCallback) internal { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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/modules/facets/IexecPocoAccessorsFacet.sol b/contracts/modules/facets/IexecPocoAccessorsFacet.sol index 568364d84..56ad9f444 100644 --- a/contracts/modules/facets/IexecPocoAccessorsFacet.sol +++ b/contracts/modules/facets/IexecPocoAccessorsFacet.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.0; import {FacetBase} from "../FacetBase.v8.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; import {IexecLibCore_v5} from "../../libs/IexecLibCore_v5.sol"; import {IexecLibOrders_v5} from "../../libs/IexecLibOrders_v5.sol"; import {IexecPocoAccessors} from "../interfaces/IexecPocoAccessors.sol"; @@ -29,8 +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(); - return $.m_deals[id]; + return LibPocoStorage.deals(id); } /** @@ -38,8 +38,7 @@ contract IexecPocoAccessorsFacet is * @param id id of the task */ function viewTask(bytes32 id) external view returns (IexecLibCore_v5.Task memory) { - PocoStorage storage $ = getPocoStorage(); - return $.m_tasks[id]; + return LibPocoStorage.tasks(id); } /** diff --git a/contracts/modules/facets/IexecPocoBoostAccessorsFacet.sol b/contracts/modules/facets/IexecPocoBoostAccessorsFacet.sol index 2a4470e2f..edbc20502 100644 --- a/contracts/modules/facets/IexecPocoBoostAccessorsFacet.sol +++ b/contracts/modules/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 {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; /** * @title Getters contract for PoCo Boost module. @@ -19,7 +20,7 @@ contract IexecPocoBoostAccessorsFacet is IexecPocoBoostAccessors, FacetBase { function viewDealBoost( bytes32 id ) external view returns (IexecLibCore_v5.DealBoost memory deal) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_dealsBoost[id]; } } diff --git a/contracts/modules/facets/IexecPocoBoostFacet.sol b/contracts/modules/facets/IexecPocoBoostFacet.sol index 082a8e3cb..4e2a611cb 100644 --- a/contracts/modules/facets/IexecPocoBoostFacet.sol +++ b/contracts/modules/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 {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); // Check orders compatibility // Ensure the trust level is within the acceptable range. @@ -295,7 +296,7 @@ contract IexecPocoBoostFacet is deal.botFirst = requestOrderConsumed.toUint16(); deal.deadline = (block.timestamp + $.m_categories[category].workClockTimeRef * - CONTRIBUTION_DEADLINE_RATIO).toUint40(); + LibPocoStorage.getContributionDeadlineRatio()).toUint40(); deal.botSize = volume.toUint16(); /** * Store right part of tag for later use. @@ -335,7 +336,10 @@ contract IexecPocoBoostFacet is // Order is important here. First get percentage by task then // multiply by volume. //slither-disable-next-line divide-before-multiply - lock(workerpoolOwner, ((workerpoolPrice * WORKERPOOL_STAKE_RATIO) / 100) * volume); + lock( + workerpoolOwner, + ((workerpoolPrice * LibPocoStorage.getWorkerpoolStakeRatio()) / 100) * volume + ); // Notify workerpool. emit SchedulerNoticeBoost( workerpool, @@ -380,7 +384,7 @@ contract IexecPocoBoostFacet is address enclaveChallenge, bytes calldata enclaveSign ) external { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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)); @@ -450,16 +454,17 @@ contract IexecPocoBoostFacet is } // Unlock scheduler stake - unlock(workerpoolOwner, (workerPoolPrice * WORKERPOOL_STAKE_RATIO) / 100); + unlock(workerpoolOwner, (workerPoolPrice * LibPocoStorage.getWorkerpoolStakeRatio()) / 100); // Reward scheduler - uint256 kitty = $.m_frozens[KITTY_ADDRESS]; + uint256 kitty = $.m_frozens[LibPocoStorage.getKittyAddress()]; if (kitty > 0) { - kitty = KITTY_MIN // 1. retrieve bare minimum from kitty + kitty = LibPocoStorage + .getKittyMin() // 1. retrieve bare minimum from kitty .max( // 2. or eventually a fraction of kitty if bigger - // @dev As long as `KITTY_RATIO = 10`, we can introduce this small - kitty / KITTY_RATIO // optimization for `kitty * KITTY_RATIO / 100` + // @dev As long as `LibPocoStorage.getKittyRatio() = 10`, we can introduce this small + kitty / LibPocoStorage.getKittyRatio() // optimization for `kitty * LibPocoStorage.getKittyRatio() / 100` ).min(kitty); // 3. but no more than available - seize(KITTY_ADDRESS, kitty, taskId); + seize(LibPocoStorage.getKittyAddress(), kitty, taskId); } reward( workerpoolOwner, @@ -494,7 +499,7 @@ contract IexecPocoBoostFacet is * @param index The index of the task. */ function claimBoost(bytes32 dealId, uint256 index) external { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); // Retrieve deal and task information from storage. IexecLibCore_v5.DealBoost storage deal = $.m_dealsBoost[dealId]; bytes32 taskId = keccak256(abi.encodePacked(dealId, index)); @@ -507,16 +512,17 @@ contract IexecPocoBoostFacet is task.status = IexecLibCore_v5.TaskStatusEnum.FAILED; // Calculate workerpool price and task stake. uint96 workerPoolPrice = deal.workerpoolPrice; - uint256 workerpoolTaskStake = (workerPoolPrice * WORKERPOOL_STAKE_RATIO) / 100; + uint256 workerpoolTaskStake = (workerPoolPrice * LibPocoStorage.getWorkerpoolStakeRatio()) / + 100; // Refund the payer of the task by unlocking the locked funds. unlock(deal.sponsor, deal.appPrice + deal.datasetPrice + workerPoolPrice); // Seize task stake from workerpool. seize(deal.workerpoolOwner, workerpoolTaskStake, taskId); // Reward kitty and lock the rewarded amount. - $.m_frozens[KITTY_ADDRESS] += workerpoolTaskStake; + $.m_frozens[LibPocoStorage.getKittyAddress()] += workerpoolTaskStake; // Emit events to publish state changes. - emit Reward(KITTY_ADDRESS, workerpoolTaskStake, taskId); - emit Lock(KITTY_ADDRESS, workerpoolTaskStake); + emit Reward(LibPocoStorage.getKittyAddress(), workerpoolTaskStake, taskId); + emit Lock(LibPocoStorage.getKittyAddress(), workerpoolTaskStake); emit TaskClaimed(taskId); } diff --git a/contracts/modules/facets/IexecPocoCommonFacet.sol b/contracts/modules/facets/IexecPocoCommonFacet.sol index 9dfcee873..b2a44d19a 100644 --- a/contracts/modules/facets/IexecPocoCommonFacet.sol +++ b/contracts/modules/facets/IexecPocoCommonFacet.sol @@ -7,6 +7,7 @@ import {Math} from "@openzeppelin/contracts-v5/utils/math/Math.sol"; import {IexecLibOrders_v5} from "../../libs/IexecLibOrders_v5.sol"; import {FacetBase} from "../FacetBase.v8.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; contract IexecPocoCommonFacet is FacetBase { using Math for uint256; @@ -42,15 +43,14 @@ contract IexecPocoCommonFacet is FacetBase { uint256 requestOrderVolume, bytes32 requestOrderTypedDataHash ) internal view returns (uint256) { - PocoStorage storage $ = getPocoStorage(); return - (appOrderVolume - $.m_consumed[appOrderTypedDataHash]) + (appOrderVolume - LibPocoStorage.consumed(appOrderTypedDataHash)) .min( hasDataset - ? datasetOrderVolume - $.m_consumed[datasetOrderTypedDataHash] + ? datasetOrderVolume - LibPocoStorage.consumed(datasetOrderTypedDataHash) : type(uint256).max ) - .min(workerpoolOrderVolume - $.m_consumed[workerpoolOrderTypedDataHash]) - .min(requestOrderVolume - $.m_consumed[requestOrderTypedDataHash]); + .min(workerpoolOrderVolume - LibPocoStorage.consumed(workerpoolOrderTypedDataHash)) + .min(requestOrderVolume - LibPocoStorage.consumed(requestOrderTypedDataHash)); } } diff --git a/contracts/modules/facets/SignatureVerifier.sol b/contracts/modules/facets/SignatureVerifier.sol index fe7aaed92..33aa3a591 100644 --- a/contracts/modules/facets/SignatureVerifier.sol +++ b/contracts/modules/facets/SignatureVerifier.sol @@ -8,6 +8,7 @@ import "@iexec/solidity/contracts/ERC734/IERC734.sol"; import "@iexec/solidity/contracts/ERC1271/IERC1271.sol"; import "@iexec/solidity/contracts/ERC1654/IERC1654.sol"; import "../FacetBase.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return _identity != address(0) && _identity == $.m_presigned[_hash]; } diff --git a/contracts/modules/facets/SignatureVerifier.v8.sol b/contracts/modules/facets/SignatureVerifier.v8.sol index 067d838e2..ea88ab36a 100644 --- a/contracts/modules/facets/SignatureVerifier.v8.sol +++ b/contracts/modules/facets/SignatureVerifier.v8.sol @@ -8,6 +8,7 @@ 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 {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; contract SignatureVerifier is FacetBase { using ECDSA for bytes32; @@ -17,8 +18,7 @@ contract SignatureVerifier is FacetBase { * @param structHash The original structure hash. */ function _toTypedDataHash(bytes32 structHash) internal view returns (bytes32) { - PocoStorage storage $ = getPocoStorage(); - return MessageHashUtils.toTypedDataHash($.EIP712DOMAIN_SEPARATOR, structHash); + return MessageHashUtils.toTypedDataHash(LibPocoStorage.domainSeparator(), structHash); } /** @@ -90,8 +90,7 @@ contract SignatureVerifier is FacetBase { address account, bytes32 messageHash ) internal view returns (bool) { - PocoStorage storage $ = getPocoStorage(); - return account != address(0) && account == $.m_presigned[messageHash]; + return account != address(0) && account == LibPocoStorage.presigned(messageHash); } /** @@ -141,7 +140,7 @@ contract SignatureVerifier is FacetBase { try IERC734(restriction).keyHasPurpose( // ERC734 identity contract restriction bytes32(uint256(uint160(account))), - GROUPMEMBER_PURPOSE + LibPocoStorage.GROUPMEMBER_PURPOSE ) returns (bool success) { return success; diff --git a/contracts/tools/testing/IexecEscrowTestContract.sol b/contracts/tools/testing/IexecEscrowTestContract.sol index 44193aa72..159e4206b 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 "../../modules/facets/IexecEscrow.v8.sol"; +import {LibPocoStorage} from "../../libs/LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_balances[account]; } function frozenOf(address account) external view returns (uint256) { - PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_frozens[account]; } } From 192e8fb037311e6103d53d398191ca8e9ded974a Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 16:24:05 +0200 Subject: [PATCH 02/10] refactor: LibPocoStorage: Replace getter functions with direct access to constants --- contracts/facets/IexecAccessorsFacet.sol | 17 +- .../facets/IexecCategoryManagerFacet.sol | 5 +- contracts/facets/IexecConfigurationFacet.sol | 45 +- contracts/facets/IexecPoco1Facet.sol | 2 +- contracts/facets/IexecPoco2Facet.sol | 34 +- contracts/facets/IexecPocoAccessorsFacet.sol | 6 +- contracts/facets/IexecPocoBoostFacet.sol | 24 +- contracts/facets/IexecPocoCommonFacet.sol | 9 +- contracts/facets/SignatureVerifier.v8.sol | 6 +- contracts/libs/LibPocoStorage.sol | 422 ----------------- contracts/libs/LibPocoStorage.v8.sol | 431 ------------------ 11 files changed, 74 insertions(+), 927 deletions(-) diff --git a/contracts/facets/IexecAccessorsFacet.sol b/contracts/facets/IexecAccessorsFacet.sol index 792a43fa9..2167c3111 100644 --- a/contracts/facets/IexecAccessorsFacet.sol +++ b/contracts/facets/IexecAccessorsFacet.sol @@ -138,37 +138,36 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { } function contribution_deadline_ratio() external view override returns (uint256) { - return LibPocoStorage.getContributionDeadlineRatio(); + return LibPocoStorage.CONTRIBUTION_DEADLINE_RATIO; } function reveal_deadline_ratio() external view override returns (uint256) { - return LibPocoStorage.getRevealDeadlineRatio(); + return LibPocoStorage.REVEAL_DEADLINE_RATIO; } function final_deadline_ratio() external view override returns (uint256) { - return LibPocoStorage.getFinalDeadlineRatio(); + return LibPocoStorage.FINAL_DEADLINE_RATIO; } function workerpool_stake_ratio() external view override returns (uint256) { - return LibPocoStorage.getWorkerpoolStakeRatio(); + return LibPocoStorage.WORKERPOOL_STAKE_RATIO; } function kitty_ratio() external view override returns (uint256) { - return LibPocoStorage.getKittyRatio(); + return LibPocoStorage.KITTY_RATIO; } function kitty_min() external view override returns (uint256) { - return LibPocoStorage.getKittyMin(); + return LibPocoStorage.KITTY_MIN; } function kitty_address() external view override returns (address) { - return LibPocoStorage.getKittyAddress(); + return LibPocoStorage.KITTY_ADDRESS; } function groupmember_purpose() external view override returns (uint256) { - return LibPocoStorage.getGroupmemberPurpose(); + return LibPocoStorage.GROUPMEMBER_PURPOSE; } - function eip712domain_separator() external view override returns (bytes32) { LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_eip712DomainSeparator; diff --git a/contracts/facets/IexecCategoryManagerFacet.sol b/contracts/facets/IexecCategoryManagerFacet.sol index fcbb9f1c1..99d8148db 100644 --- a/contracts/facets/IexecCategoryManagerFacet.sol +++ b/contracts/facets/IexecCategoryManagerFacet.sol @@ -17,9 +17,10 @@ contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase { string calldata description, uint256 workClockTimeRef ) external override onlyOwner returns (uint256) { - LibPocoStorage.addCategory(IexecLibCore_v5.Category(name, description, workClockTimeRef)); + LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + $.m_categories.push(IexecLibCore_v5.Category(name, description, workClockTimeRef)); - uint256 catid = LibPocoStorage.categories().length - 1; + uint256 catid = $.m_categories.length - 1; emit CreateCategory(catid, name, description, workClockTimeRef); return catid; diff --git a/contracts/facets/IexecConfigurationFacet.sol b/contracts/facets/IexecConfigurationFacet.sol index d54c1c13a..af7929a7a 100644 --- a/contracts/facets/IexecConfigurationFacet.sol +++ b/contracts/facets/IexecConfigurationFacet.sol @@ -25,17 +25,18 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { address _workerpoolregistryAddress, address _v3_iexecHubAddress ) external override onlyOwner { - require(LibPocoStorage.domainSeparator() == bytes32(0), "already-configured"); - LibPocoStorage.setDomainSeparator(_domain().hash()); - LibPocoStorage.setBaseToken(IERC20(_token)); - LibPocoStorage.setName(_name); - LibPocoStorage.setSymbol(_symbol); - LibPocoStorage.setDecimals(_decimal); - LibPocoStorage.setAppRegistry(IRegistry(_appregistryAddress)); - LibPocoStorage.setDatasetRegistry(IRegistry(_datasetregistryAddress)); - LibPocoStorage.setWorkerpoolRegistry(IRegistry(_workerpoolregistryAddress)); - LibPocoStorage.setV3IexecHub(IexecHubInterface(_v3_iexecHubAddress)); - LibPocoStorage.setCallbackGas(100000); + LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + require($.m_eip712DomainSeparator == bytes32(0), "already-configured"); + $.m_eip712DomainSeparator = _domain().hash(); + $.m_baseToken = IERC20(_token); + $.m_name = _name; + $.m_symbol = _symbol; + $.m_decimals = _decimal; + $.m_appregistry = IRegistry(_appregistryAddress); + $.m_datasetregistry = IRegistry(_datasetregistryAddress); + $.m_workerpoolregistry = IRegistry(_workerpoolregistryAddress); + $.m_v3_iexecHub = IexecHubInterface(_v3_iexecHubAddress); + $.m_callbackgas = 100000; } function domain() external view override returns (IexecLibOrders_v5.EIP712Domain memory) { @@ -43,26 +44,28 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { } function updateDomainSeparator() external override { - require(LibPocoStorage.domainSeparator() != bytes32(0), "not-configured"); - LibPocoStorage.setDomainSeparator(_domain().hash()); + LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + require($.m_eip712DomainSeparator != bytes32(0), "not-configured"); + $.m_eip712DomainSeparator = _domain().hash(); } function importScore(address _worker) external override { - require(!LibPocoStorage.v3ScoreImported(_worker), "score-already-imported"); - uint256 currentScore = LibPocoStorage.workerScores(_worker); - uint256 newScore = currentScore.max( - IexecHubInterface(LibPocoStorage.v3IexecHub()).viewScore(_worker) + LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + require(!$.m_v3_scoreImported[_worker], "score-already-imported"); + $.m_workerScores[_worker] = $.m_workerScores[_worker].max( + $.m_v3_iexecHub.viewScore(_worker) ); - LibPocoStorage.setWorkerScore(_worker, newScore); - LibPocoStorage.setV3ScoreImported(_worker, true); + $.m_v3_scoreImported[_worker] = true; } function setTeeBroker(address _teebroker) external override onlyOwner { - LibPocoStorage.setTeeBroker(_teebroker); + LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + $.m_teebroker = _teebroker; } function setCallbackGas(uint256 _callbackgas) external override onlyOwner { - LibPocoStorage.setCallbackGas(_callbackgas); + LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + $.m_callbackgas = _callbackgas; } function _chainId() internal pure returns (uint256 id) { diff --git a/contracts/facets/IexecPoco1Facet.sol b/contracts/facets/IexecPoco1Facet.sol index d3f94884d..31fc56405 100644 --- a/contracts/facets/IexecPoco1Facet.sol +++ b/contracts/facets/IexecPoco1Facet.sol @@ -365,7 +365,7 @@ contract IexecPoco1Facet is //slither-disable-next-line divide-before-multiply lock( deal.workerpool.owner, - ((deal.workerpool.price * LibPocoStorage.getWorkerpoolStakeRatio()) / 100) * volume // ORDER IS IMPORTANT HERE! + ((deal.workerpool.price * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100) * volume // ORDER IS IMPORTANT HERE! ); /** diff --git a/contracts/facets/IexecPoco2Facet.sol b/contracts/facets/IexecPoco2Facet.sol index 04617367d..c98de2af2 100644 --- a/contracts/facets/IexecPoco2Facet.sol +++ b/contracts/facets/IexecPoco2Facet.sol @@ -28,8 +28,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie IexecLibCore_v5.Deal storage deal = $.m_deals[_dealid]; uint256 taskPrice = deal.app.price + deal.dataset.price + deal.workerpool.price; - uint256 poolstake = (deal.workerpool.price * LibPocoStorage.getWorkerpoolStakeRatio()) / - 100; + uint256 poolstake = (deal.workerpool.price * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100; // Seize the payer of the task seize(deal.sponsor, taskPrice, _taskid); @@ -46,17 +45,14 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie // pool reward performed by consensus manager // Retrieve part of the kitty - uint256 kitty = $.m_frozens[LibPocoStorage.getKittyAddress()]; + uint256 kitty = $.m_frozens[LibPocoStorage.KITTY_ADDRESS]; if (kitty > 0) { - // Get a fraction of the kitty where LibPocoStorage.getKittyMin() <= fraction <= kitty + // Get a fraction of the kitty where LibPocoStorage.KITTY_MIN <= fraction <= kitty kitty = Math.min( - Math.max( - (kitty * LibPocoStorage.getKittyRatio()) / 100, - LibPocoStorage.getKittyMin() - ), + Math.max((kitty * LibPocoStorage.KITTY_RATIO) / 100, LibPocoStorage.KITTY_MIN), kitty ); - seize(LibPocoStorage.getKittyAddress(), kitty, _taskid); + seize(LibPocoStorage.KITTY_ADDRESS, kitty, _taskid); reward(deal.workerpool.owner, kitty, _taskid); } } @@ -66,8 +62,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie IexecLibCore_v5.Deal memory deal = $.m_deals[_dealid]; uint256 taskPrice = deal.app.price + deal.dataset.price + deal.workerpool.price; - uint256 poolstake = (deal.workerpool.price * LibPocoStorage.getWorkerpoolStakeRatio()) / - 100; + uint256 poolstake = (deal.workerpool.price * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100; unlock(deal.sponsor, taskPrice); // Refund the payer of the task seize(deal.workerpool.owner, poolstake, _taskid); @@ -77,9 +72,9 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * where functions would together uselessly transfer value from main PoCo * proxy to kitty, then would transfer value back from kitty to main PoCo proxy. */ - $.m_frozens[LibPocoStorage.getKittyAddress()] += poolstake; // → Kitty / Burn - emit Reward(LibPocoStorage.getKittyAddress(), poolstake, _taskid); - emit Lock(LibPocoStorage.getKittyAddress(), poolstake); + $.m_frozens[LibPocoStorage.KITTY_ADDRESS] += poolstake; // → Kitty / Burn + emit Reward(LibPocoStorage.KITTY_ADDRESS, poolstake, _taskid); + emit Lock(LibPocoStorage.KITTY_ADDRESS, poolstake); } /*************************************************************************** @@ -103,8 +98,8 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie task.contributionDeadline = deal.startTime + task.timeref * - LibPocoStorage.getContributionDeadlineRatio(); - task.finalDeadline = deal.startTime + task.timeref * LibPocoStorage.getFinalDeadlineRatio(); + LibPocoStorage.CONTRIBUTION_DEADLINE_RATIO; + task.finalDeadline = deal.startTime + task.timeref * LibPocoStorage.FINAL_DEADLINE_RATIO; // setup denominator $.m_consensus[taskid].total = 1; @@ -251,10 +246,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie task.status = IexecLibCore_v5.TaskStatusEnum.COMPLETED; task.consensusValue = contribution.resultHash; - task.revealDeadline = - block.timestamp + - task.timeref * - LibPocoStorage.getRevealDeadlineRatio(); + task.revealDeadline = block.timestamp + task.timeref * LibPocoStorage.REVEAL_DEADLINE_RATIO; task.revealCounter = 1; task.winnerCounter = 1; task.resultDigest = _resultDigest; @@ -424,7 +416,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie task.revealDeadline = block.timestamp + task.timeref * - LibPocoStorage.getRevealDeadlineRatio(); + LibPocoStorage.REVEAL_DEADLINE_RATIO; task.revealCounter = 0; task.winnerCounter = winnerCounter; diff --git a/contracts/facets/IexecPocoAccessorsFacet.sol b/contracts/facets/IexecPocoAccessorsFacet.sol index c12ce7228..e5a41e88f 100644 --- a/contracts/facets/IexecPocoAccessorsFacet.sol +++ b/contracts/facets/IexecPocoAccessorsFacet.sol @@ -30,7 +30,8 @@ contract IexecPocoAccessorsFacet is * @param id The ID of the deal. */ function viewDeal(bytes32 id) external view returns (IexecLibCore_v5.Deal memory deal) { - return LibPocoStorage.deals(id); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + return $.m_deals[id]; } /** @@ -38,7 +39,8 @@ contract IexecPocoAccessorsFacet is * @param id id of the task */ function viewTask(bytes32 id) external view returns (IexecLibCore_v5.Task memory) { - return LibPocoStorage.tasks(id); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + return $.m_tasks[id]; } /** diff --git a/contracts/facets/IexecPocoBoostFacet.sol b/contracts/facets/IexecPocoBoostFacet.sol index 3e44e9bc3..9be2fafd6 100644 --- a/contracts/facets/IexecPocoBoostFacet.sol +++ b/contracts/facets/IexecPocoBoostFacet.sol @@ -296,7 +296,7 @@ contract IexecPocoBoostFacet is deal.botFirst = requestOrderConsumed.toUint16(); deal.deadline = (block.timestamp + $.m_categories[category].workClockTimeRef * - LibPocoStorage.getContributionDeadlineRatio()).toUint40(); + LibPocoStorage.CONTRIBUTION_DEADLINE_RATIO).toUint40(); deal.botSize = volume.toUint16(); /** * Store right part of tag for later use. @@ -338,7 +338,7 @@ contract IexecPocoBoostFacet is //slither-disable-next-line divide-before-multiply lock( workerpoolOwner, - ((workerpoolPrice * LibPocoStorage.getWorkerpoolStakeRatio()) / 100) * volume + ((workerpoolPrice * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100) * volume ); // Notify workerpool. emit SchedulerNoticeBoost( @@ -454,17 +454,17 @@ contract IexecPocoBoostFacet is } // Unlock scheduler stake - unlock(workerpoolOwner, (workerPoolPrice * LibPocoStorage.getWorkerpoolStakeRatio()) / 100); + unlock(workerpoolOwner, (workerPoolPrice * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100); // Reward scheduler - uint256 kitty = $.m_frozens[LibPocoStorage.getKittyAddress()]; + uint256 kitty = $.m_frozens[LibPocoStorage.KITTY_ADDRESS]; if (kitty > 0) { kitty = LibPocoStorage - .getKittyMin() // 1. retrieve bare minimum from kitty + .KITTY_MIN // 1. retrieve bare minimum from kitty .max( // 2. or eventually a fraction of kitty if bigger - // @dev As long as `LibPocoStorage.getKittyRatio() = 10`, we can introduce this small - kitty / LibPocoStorage.getKittyRatio() // optimization for `kitty * LibPocoStorage.getKittyRatio() / 100` + // @dev As long as `LibPocoStorage.KITTY_RATIO = 10`, we can introduce this small + kitty / LibPocoStorage.KITTY_RATIO // optimization for `kitty * LibPocoStorage.KITTY_RATIO / 100` ).min(kitty); // 3. but no more than available - seize(LibPocoStorage.getKittyAddress(), kitty, taskId); + seize(LibPocoStorage.KITTY_ADDRESS, kitty, taskId); } reward( workerpoolOwner, @@ -512,17 +512,17 @@ contract IexecPocoBoostFacet is task.status = IexecLibCore_v5.TaskStatusEnum.FAILED; // Calculate workerpool price and task stake. uint96 workerPoolPrice = deal.workerpoolPrice; - uint256 workerpoolTaskStake = (workerPoolPrice * LibPocoStorage.getWorkerpoolStakeRatio()) / + uint256 workerpoolTaskStake = (workerPoolPrice * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100; // Refund the payer of the task by unlocking the locked funds. unlock(deal.sponsor, deal.appPrice + deal.datasetPrice + workerPoolPrice); // Seize task stake from workerpool. seize(deal.workerpoolOwner, workerpoolTaskStake, taskId); // Reward kitty and lock the rewarded amount. - $.m_frozens[LibPocoStorage.getKittyAddress()] += workerpoolTaskStake; + $.m_frozens[LibPocoStorage.KITTY_ADDRESS] += workerpoolTaskStake; // Emit events to publish state changes. - emit Reward(LibPocoStorage.getKittyAddress(), workerpoolTaskStake, taskId); - emit Lock(LibPocoStorage.getKittyAddress(), workerpoolTaskStake); + emit Reward(LibPocoStorage.KITTY_ADDRESS, workerpoolTaskStake, taskId); + emit Lock(LibPocoStorage.KITTY_ADDRESS, workerpoolTaskStake); emit TaskClaimed(taskId); } diff --git a/contracts/facets/IexecPocoCommonFacet.sol b/contracts/facets/IexecPocoCommonFacet.sol index 145a4062d..c19e05aa0 100644 --- a/contracts/facets/IexecPocoCommonFacet.sol +++ b/contracts/facets/IexecPocoCommonFacet.sol @@ -42,14 +42,15 @@ contract IexecPocoCommonFacet is FacetBase { uint256 requestOrderVolume, bytes32 requestOrderTypedDataHash ) internal view returns (uint256) { + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return - (appOrderVolume - LibPocoStorage.consumed(appOrderTypedDataHash)) + (appOrderVolume - $.m_consumed[appOrderTypedDataHash]) .min( hasDataset - ? datasetOrderVolume - LibPocoStorage.consumed(datasetOrderTypedDataHash) + ? datasetOrderVolume - $.m_consumed[datasetOrderTypedDataHash] : type(uint256).max ) - .min(workerpoolOrderVolume - LibPocoStorage.consumed(workerpoolOrderTypedDataHash)) - .min(requestOrderVolume - LibPocoStorage.consumed(requestOrderTypedDataHash)); + .min(workerpoolOrderVolume - $.m_consumed[workerpoolOrderTypedDataHash]) + .min(requestOrderVolume - $.m_consumed[requestOrderTypedDataHash]); } } diff --git a/contracts/facets/SignatureVerifier.v8.sol b/contracts/facets/SignatureVerifier.v8.sol index be3b87273..2fb3bca10 100644 --- a/contracts/facets/SignatureVerifier.v8.sol +++ b/contracts/facets/SignatureVerifier.v8.sol @@ -20,7 +20,8 @@ contract SignatureVerifier is FacetBase { * @param structHash The original structure hash. */ function _toTypedDataHash(bytes32 structHash) internal view returns (bytes32) { - return MessageHashUtils.toTypedDataHash(LibPocoStorage.domainSeparator(), structHash); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + return MessageHashUtils.toTypedDataHash($.m_eip712DomainSeparator, structHash); } /** @@ -92,7 +93,8 @@ contract SignatureVerifier is FacetBase { address account, bytes32 messageHash ) internal view returns (bool) { - return account != address(0) && account == LibPocoStorage.presigned(messageHash); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + return account != address(0) && account == $.m_presigned[messageHash]; } /** diff --git a/contracts/libs/LibPocoStorage.sol b/contracts/libs/LibPocoStorage.sol index cb0197331..ce8a2d0c3 100644 --- a/contracts/libs/LibPocoStorage.sol +++ b/contracts/libs/LibPocoStorage.sol @@ -95,426 +95,4 @@ library LibPocoStorage { $_slot := POCO_STORAGE_LOCATION } } - - // === Constants Getter Functions === - function getContributionDeadlineRatio() internal pure returns (uint256) { - return CONTRIBUTION_DEADLINE_RATIO; - } - - function getRevealDeadlineRatio() internal pure returns (uint256) { - return REVEAL_DEADLINE_RATIO; - } - - function getFinalDeadlineRatio() internal pure returns (uint256) { - return FINAL_DEADLINE_RATIO; - } - - function getWorkerpoolStakeRatio() internal pure returns (uint256) { - return WORKERPOOL_STAKE_RATIO; - } - - function getKittyRatio() internal pure returns (uint256) { - return KITTY_RATIO; - } - - function getKittyMin() internal pure returns (uint256) { - return KITTY_MIN; - } - - function getKittyAddress() internal pure returns (address) { - return KITTY_ADDRESS; - } - - function getGroupmemberPurpose() internal pure returns (uint256) { - return GROUPMEMBER_PURPOSE; - } - - // === Storage Getter Functions === - - /** - * @dev Get the app registry contract. - * @return The app registry contract interface. - */ - function appRegistry() internal view returns (IRegistry) { - return getPocoStorage().m_appregistry; - } - - /** - * @dev Get the dataset registry contract. - * @return The dataset registry contract interface. - */ - function datasetRegistry() internal view returns (IRegistry) { - return getPocoStorage().m_datasetregistry; - } - - /** - * @dev Get the workerpool registry contract. - * @return The workerpool registry contract interface. - */ - function workerpoolRegistry() internal view returns (IRegistry) { - return getPocoStorage().m_workerpoolregistry; - } - - /** - * @dev Get the base token contract. - * @return The base token contract interface. - */ - function baseToken() internal view returns (IERC20) { - return getPocoStorage().m_baseToken; - } - - /** - * @dev Get the token name. - * @return The token name string. - */ - function name() internal view returns (string storage) { - return getPocoStorage().m_name; - } - - /** - * @dev Get the token symbol. - * @return The token symbol string. - */ - function symbol() internal view returns (string storage) { - return getPocoStorage().m_symbol; - } - - /** - * @dev Get the token decimals. - * @return The token decimals. - */ - function decimals() internal view returns (uint8) { - return getPocoStorage().m_decimals; - } - - /** - * @dev Get the total supply. - * @return The total supply amount. - */ - function totalSupply() internal view returns (uint256) { - return getPocoStorage().m_totalSupply; - } - - /** - * @dev Get the balance of an account. - * @param account The account address. - * @return The balance amount. - */ - function balanceOf(address account) internal view returns (uint256) { - return getPocoStorage().m_balances[account]; - } - - /** - * @dev Get the frozen balance of an account. - * @param account The account address. - * @return The frozen balance amount. - */ - function frozenOf(address account) internal view returns (uint256) { - return getPocoStorage().m_frozens[account]; - } - - /** - * @dev Get the allowance amount. - * @param owner The owner address. - * @param spender The spender address. - * @return The allowance amount. - */ - function allowance(address owner, address spender) internal view returns (uint256) { - return getPocoStorage().m_allowances[owner][spender]; - } - - /** - * @dev Get the EIP712 domain separator. - * @return The domain separator hash. - */ - function domainSeparator() internal view returns (bytes32) { - return getPocoStorage().m_eip712DomainSeparator; - } - - /** - * @dev Get the presigned order owner. - * @param orderHash The order hash. - * @return The presigned order owner address. - */ - function presigned(bytes32 orderHash) internal view returns (address) { - return getPocoStorage().m_presigned[orderHash]; - } - - /** - * @dev Get the consumed amount of an order. - * @param orderHash The order hash. - * @return The consumed amount. - */ - function consumed(bytes32 orderHash) internal view returns (uint256) { - return getPocoStorage().m_consumed[orderHash]; - } - - /** - * @dev Get a deal by its ID. - * @param dealId The deal ID. - * @return The deal struct. - */ - function deals(bytes32 dealId) internal view returns (IexecLibCore_v5.Deal storage) { - return getPocoStorage().m_deals[dealId]; - } - - /** - * @dev Get a task by its ID. - * @param taskId The task ID. - * @return The task struct. - */ - function tasks(bytes32 taskId) internal view returns (IexecLibCore_v5.Task storage) { - return getPocoStorage().m_tasks[taskId]; - } - - /** - * @dev Get a consensus by task ID. - * @param taskId The task ID. - * @return The consensus struct. - */ - function consensus(bytes32 taskId) internal view returns (IexecLibCore_v5.Consensus storage) { - return getPocoStorage().m_consensus[taskId]; - } - - /** - * @dev Get a contribution by task ID and worker address. - * @param taskId The task ID. - * @param worker The worker address. - * @return The contribution struct. - */ - function contributions( - bytes32 taskId, - address worker - ) internal view returns (IexecLibCore_v5.Contribution storage) { - return getPocoStorage().m_contributions[taskId][worker]; - } - - /** - * @dev Get the worker score. - * @param worker The worker address. - * @return The worker score. - */ - function workerScores(address worker) internal view returns (uint256) { - return getPocoStorage().m_workerScores[worker]; - } - - /** - * @dev Get the TEE broker address. - * @return The TEE broker address. - */ - function teeBroker() internal view returns (address) { - return getPocoStorage().m_teebroker; - } - - /** - * @dev Get the callback gas limit. - * @return The callback gas limit. - */ - function callbackGas() internal view returns (uint256) { - return getPocoStorage().m_callbackgas; - } - - /** - * @dev Get all categories. - * @return The categories array. - */ - function categories() internal view returns (IexecLibCore_v5.Category[] storage) { - return getPocoStorage().m_categories; - } - - /** - * @dev Get a category by index. - * @param index The category index. - * @return The category struct. - */ - function category(uint256 index) internal view returns (IexecLibCore_v5.Category storage) { - return getPocoStorage().m_categories[index]; - } - - /** - * @dev Get the v3 iExec Hub address. - * @return The v3 iExec Hub address. - */ - function v3IexecHub() internal view returns (IexecHubInterface) { - return getPocoStorage().m_v3_iexecHub; - } - - /** - * @dev Check if v3 score is imported for an address. - * @param addr The address to check. - * @return True if v3 score is imported. - */ - function v3ScoreImported(address addr) internal view returns (bool) { - return getPocoStorage().m_v3_scoreImported[addr]; - } - - // === Storage Setter Functions === - - /** - * @dev Set the app registry contract. - * @param registry The app registry contract. - */ - function setAppRegistry(IRegistry registry) internal { - getPocoStorage().m_appregistry = registry; - } - - /** - * @dev Set the dataset registry contract. - * @param registry The dataset registry contract. - */ - function setDatasetRegistry(IRegistry registry) internal { - getPocoStorage().m_datasetregistry = registry; - } - - /** - * @dev Set the workerpool registry contract. - * @param registry The workerpool registry contract. - */ - function setWorkerpoolRegistry(IRegistry registry) internal { - getPocoStorage().m_workerpoolregistry = registry; - } - - /** - * @dev Set the base token contract. - * @param token The base token contract. - */ - function setBaseToken(IERC20 token) internal { - getPocoStorage().m_baseToken = token; - } - - /** - * @dev Set the token name. - * @param newName The new token name. - */ - function setName(string memory newName) internal { - getPocoStorage().m_name = newName; - } - - /** - * @dev Set the token symbol. - * @param newSymbol The new token symbol. - */ - function setSymbol(string memory newSymbol) internal { - getPocoStorage().m_symbol = newSymbol; - } - - /** - * @dev Set the token decimals. - * @param newDecimals The new token decimals. - */ - function setDecimals(uint8 newDecimals) internal { - getPocoStorage().m_decimals = newDecimals; - } - - /** - * @dev Set the total supply. - * @param newTotalSupply The new total supply. - */ - function setTotalSupply(uint256 newTotalSupply) internal { - getPocoStorage().m_totalSupply = newTotalSupply; - } - - /** - * @dev Set the balance of an account. - * @param account The account address. - * @param amount The balance amount. - */ - function setBalance(address account, uint256 amount) internal { - getPocoStorage().m_balances[account] = amount; - } - - /** - * @dev Set the frozen balance of an account. - * @param account The account address. - * @param amount The frozen balance amount. - */ - function setFrozen(address account, uint256 amount) internal { - getPocoStorage().m_frozens[account] = amount; - } - - /** - * @dev Set the allowance amount. - * @param owner The owner address. - * @param spender The spender address. - * @param amount The allowance amount. - */ - function setAllowance(address owner, address spender, uint256 amount) internal { - getPocoStorage().m_allowances[owner][spender] = amount; - } - - /** - * @dev Set the EIP712 domain separator. - * @param newDomainSeparator The new domain separator hash. - */ - function setDomainSeparator(bytes32 newDomainSeparator) internal { - getPocoStorage().m_eip712DomainSeparator = newDomainSeparator; - } - - /** - * @dev Set the presigned order owner. - * @param orderHash The order hash. - * @param owner The presigned order owner address. - */ - function setPresigned(bytes32 orderHash, address owner) internal { - getPocoStorage().m_presigned[orderHash] = owner; - } - - /** - * @dev Set the consumed amount of an order. - * @param orderHash The order hash. - * @param amount The consumed amount. - */ - function setConsumed(bytes32 orderHash, uint256 amount) internal { - getPocoStorage().m_consumed[orderHash] = amount; - } - - /** - * @dev Set the worker score. - * @param worker The worker address. - * @param score The worker score. - */ - function setWorkerScore(address worker, uint256 score) internal { - getPocoStorage().m_workerScores[worker] = score; - } - - /** - * @dev Set the TEE broker address. - * @param broker The TEE broker address. - */ - function setTeeBroker(address broker) internal { - getPocoStorage().m_teebroker = broker; - } - - /** - * @dev Set the callback gas limit. - * @param gas The callback gas limit. - */ - function setCallbackGas(uint256 gas) internal { - getPocoStorage().m_callbackgas = gas; - } - - /** - * @dev Add a new category. - * @param cat The category to add. - */ - function addCategory(IexecLibCore_v5.Category memory cat) internal { - getPocoStorage().m_categories.push(cat); - } - - /** - * @dev Set the v3 iExec Hub address. - * @param hub The v3 iExec Hub address. - */ - function setV3IexecHub(IexecHubInterface hub) internal { - getPocoStorage().m_v3_iexecHub = hub; - } - - /** - * @dev Set the v3 score imported flag for an address. - * @param addr The address. - * @param imported The imported flag. - */ - function setV3ScoreImported(address addr, bool imported) internal { - getPocoStorage().m_v3_scoreImported[addr] = imported; - } } diff --git a/contracts/libs/LibPocoStorage.v8.sol b/contracts/libs/LibPocoStorage.v8.sol index c78391656..b2dab77e7 100644 --- a/contracts/libs/LibPocoStorage.v8.sol +++ b/contracts/libs/LibPocoStorage.v8.sol @@ -97,437 +97,6 @@ library LibPocoStorage { $.slot := POCO_STORAGE_LOCATION } } - - // === Constants Getter Functions === - function getContributionDeadlineRatio() internal pure returns (uint256) { - return CONTRIBUTION_DEADLINE_RATIO; - } - - function getRevealDeadlineRatio() internal pure returns (uint256) { - return REVEAL_DEADLINE_RATIO; - } - - function getFinalDeadlineRatio() internal pure returns (uint256) { - return FINAL_DEADLINE_RATIO; - } - - function getWorkerpoolStakeRatio() internal pure returns (uint256) { - return WORKERPOOL_STAKE_RATIO; - } - - function getKittyRatio() internal pure returns (uint256) { - return KITTY_RATIO; - } - - function getKittyMin() internal pure returns (uint256) { - return KITTY_MIN; - } - - function getKittyAddress() internal pure returns (address) { - return KITTY_ADDRESS; - } - - function getGroupmemberPurpose() internal pure returns (uint256) { - return GROUPMEMBER_PURPOSE; - } - - // === Storage Getter Functions === - - /** - * @dev Get the app registry contract. - * @return The app registry contract interface. - */ - function appRegistry() internal view returns (IRegistry) { - return getPocoStorage().m_appregistry; - } - - /** - * @dev Get the dataset registry contract. - * @return The dataset registry contract interface. - */ - function datasetRegistry() internal view returns (IRegistry) { - return getPocoStorage().m_datasetregistry; - } - - /** - * @dev Get the workerpool registry contract. - * @return The workerpool registry contract interface. - */ - function workerpoolRegistry() internal view returns (IRegistry) { - return getPocoStorage().m_workerpoolregistry; - } - - /** - * @dev Get the base token contract. - * @return The base token contract interface. - */ - function baseToken() internal view returns (IERC20) { - return getPocoStorage().m_baseToken; - } - - /** - * @dev Get the token name. - * @return The token name string. - */ - function name() internal view returns (string storage) { - return getPocoStorage().m_name; - } - - /** - * @dev Get the token symbol. - * @return The token symbol string. - */ - function symbol() internal view returns (string storage) { - return getPocoStorage().m_symbol; - } - - /** - * @dev Get the token decimals. - * @return The token decimals. - */ - function decimals() internal view returns (uint8) { - return getPocoStorage().m_decimals; - } - - /** - * @dev Get the total supply. - * @return The total supply amount. - */ - function totalSupply() internal view returns (uint256) { - return getPocoStorage().m_totalSupply; - } - - /** - * @dev Get the balance of an account. - * @param account The account address. - * @return The balance amount. - */ - function balanceOf(address account) internal view returns (uint256) { - return getPocoStorage().m_balances[account]; - } - - /** - * @dev Get the frozen balance of an account. - * @param account The account address. - * @return The frozen balance amount. - */ - function frozenOf(address account) internal view returns (uint256) { - return getPocoStorage().m_frozens[account]; - } - - /** - * @dev Get the allowance amount. - * @param owner The owner address. - * @param spender The spender address. - * @return The allowance amount. - */ - function allowance(address owner, address spender) internal view returns (uint256) { - return getPocoStorage().m_allowances[owner][spender]; - } - - /** - * @dev Get the EIP712 domain separator. - * @return The domain separator hash. - */ - function domainSeparator() internal view returns (bytes32) { - return getPocoStorage().m_eip712DomainSeparator; - } - - /** - * @dev Get the presigned order owner. - * @param orderHash The order hash. - * @return The presigned order owner address. - */ - function presigned(bytes32 orderHash) internal view returns (address) { - return getPocoStorage().m_presigned[orderHash]; - } - - /** - * @dev Get the consumed amount of an order. - * @param orderHash The order hash. - * @return The consumed amount. - */ - function consumed(bytes32 orderHash) internal view returns (uint256) { - return getPocoStorage().m_consumed[orderHash]; - } - - /** - * @dev Get a deal by its ID. - * @param dealId The deal ID. - * @return The deal struct. - */ - function deals(bytes32 dealId) internal view returns (IexecLibCore_v5.Deal storage) { - return getPocoStorage().m_deals[dealId]; - } - - /** - * @dev Get a boost deal by its ID. - * @param dealId The deal ID. - * @return The boost deal struct. - */ - function dealsBoost(bytes32 dealId) internal view returns (IexecLibCore_v5.DealBoost storage) { - return getPocoStorage().m_dealsBoost[dealId]; - } - - /** - * @dev Get a task by its ID. - * @param taskId The task ID. - * @return The task struct. - */ - function tasks(bytes32 taskId) internal view returns (IexecLibCore_v5.Task storage) { - return getPocoStorage().m_tasks[taskId]; - } - - /** - * @dev Get a consensus by task ID. - * @param taskId The task ID. - * @return The consensus struct. - */ - function consensus(bytes32 taskId) internal view returns (IexecLibCore_v5.Consensus storage) { - return getPocoStorage().m_consensus[taskId]; - } - - /** - * @dev Get a contribution by task ID and worker address. - * @param taskId The task ID. - * @param worker The worker address. - * @return The contribution struct. - */ - function contributions( - bytes32 taskId, - address worker - ) internal view returns (IexecLibCore_v5.Contribution storage) { - return getPocoStorage().m_contributions[taskId][worker]; - } - - /** - * @dev Get the worker score. - * @param worker The worker address. - * @return The worker score. - */ - function workerScores(address worker) internal view returns (uint256) { - return getPocoStorage().m_workerScores[worker]; - } - - /** - * @dev Get the TEE broker address. - * @return The TEE broker address. - */ - function teeBroker() internal view returns (address) { - return getPocoStorage().m_teebroker; - } - - /** - * @dev Get the callback gas limit. - * @return The callback gas limit. - */ - function callbackGas() internal view returns (uint256) { - return getPocoStorage().m_callbackgas; - } - - /** - * @dev Get all categories. - * @return The categories array. - */ - function categories() internal view returns (IexecLibCore_v5.Category[] storage) { - return getPocoStorage().m_categories; - } - - /** - * @dev Get a category by index. - * @param index The category index. - * @return The category struct. - */ - function category(uint256 index) internal view returns (IexecLibCore_v5.Category storage) { - return getPocoStorage().m_categories[index]; - } - - /** - * @dev Get the v3 iExec Hub address. - * @return The v3 iExec Hub address. - */ - function v3IexecHub() internal view returns (address) { - return getPocoStorage().m_v3_iexecHub; - } - - /** - * @dev Check if v3 score is imported for an address. - * @param addr The address to check. - * @return True if v3 score is imported. - */ - function v3ScoreImported(address addr) internal view returns (bool) { - return getPocoStorage().m_v3_scoreImported[addr]; - } - - // === Storage Setter Functions === - - /** - * @dev Set the app registry contract. - * @param registry The app registry contract. - */ - function setAppRegistry(IRegistry registry) internal { - getPocoStorage().m_appregistry = registry; - } - - /** - * @dev Set the dataset registry contract. - * @param registry The dataset registry contract. - */ - function setDatasetRegistry(IRegistry registry) internal { - getPocoStorage().m_datasetregistry = registry; - } - - /** - * @dev Set the workerpool registry contract. - * @param registry The workerpool registry contract. - */ - function setWorkerpoolRegistry(IRegistry registry) internal { - getPocoStorage().m_workerpoolregistry = registry; - } - - /** - * @dev Set the base token contract. - * @param token The base token contract. - */ - function setBaseToken(IERC20 token) internal { - getPocoStorage().m_baseToken = token; - } - - /** - * @dev Set the token name. - * @param newName The new token name. - */ - function setName(string memory newName) internal { - getPocoStorage().m_name = newName; - } - - /** - * @dev Set the token symbol. - * @param newSymbol The new token symbol. - */ - function setSymbol(string memory newSymbol) internal { - getPocoStorage().m_symbol = newSymbol; - } - - /** - * @dev Set the token decimals. - * @param newDecimals The new token decimals. - */ - function setDecimals(uint8 newDecimals) internal { - getPocoStorage().m_decimals = newDecimals; - } - - /** - * @dev Set the total supply. - * @param newTotalSupply The new total supply. - */ - function setTotalSupply(uint256 newTotalSupply) internal { - getPocoStorage().m_totalSupply = newTotalSupply; - } - - /** - * @dev Set the balance of an account. - * @param account The account address. - * @param amount The balance amount. - */ - function setBalance(address account, uint256 amount) internal { - getPocoStorage().m_balances[account] = amount; - } - - /** - * @dev Set the frozen balance of an account. - * @param account The account address. - * @param amount The frozen balance amount. - */ - function setFrozen(address account, uint256 amount) internal { - getPocoStorage().m_frozens[account] = amount; - } - - /** - * @dev Set the allowance amount. - * @param owner The owner address. - * @param spender The spender address. - * @param amount The allowance amount. - */ - function setAllowance(address owner, address spender, uint256 amount) internal { - getPocoStorage().m_allowances[owner][spender] = amount; - } - - /** - * @dev Set the EIP712 domain separator. - * @param newDomainSeparator The new domain separator hash. - */ - function setDomainSeparator(bytes32 newDomainSeparator) internal { - getPocoStorage().m_eip712DomainSeparator = newDomainSeparator; - } - - /** - * @dev Set the presigned order owner. - * @param orderHash The order hash. - * @param owner The presigned order owner address. - */ - function setPresigned(bytes32 orderHash, address owner) internal { - getPocoStorage().m_presigned[orderHash] = owner; - } - - /** - * @dev Set the consumed amount of an order. - * @param orderHash The order hash. - * @param amount The consumed amount. - */ - function setConsumed(bytes32 orderHash, uint256 amount) internal { - getPocoStorage().m_consumed[orderHash] = amount; - } - - /** - * @dev Set the worker score. - * @param worker The worker address. - * @param score The worker score. - */ - function setWorkerScore(address worker, uint256 score) internal { - getPocoStorage().m_workerScores[worker] = score; - } - - /** - * @dev Set the TEE broker address. - * @param broker The TEE broker address. - */ - function setTeeBroker(address broker) internal { - getPocoStorage().m_teebroker = broker; - } - - /** - * @dev Set the callback gas limit. - * @param gas The callback gas limit. - */ - function setCallbackGas(uint256 gas) internal { - getPocoStorage().m_callbackgas = gas; - } - - /** - * @dev Add a new category. - * @param cat The category to add. - */ - function addCategory(IexecLibCore_v5.Category memory cat) internal { - getPocoStorage().m_categories.push(cat); - } - - /** - * @dev Set the v3 iExec Hub address. - * @param hub The v3 iExec Hub address. - */ - function setV3IexecHub(address hub) internal { - getPocoStorage().m_v3_iexecHub = hub; - } - - /** - * @dev Set the v3 score imported flag for an address. - * @param addr The address. - * @param imported The imported flag. - */ - function setV3ScoreImported(address addr, bool imported) internal { - getPocoStorage().m_v3_scoreImported[addr] = imported; - } } // Registry interface used in storage. From 4b8ab597eade995bf0788b9400199f7daeda9289 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 16:31:05 +0200 Subject: [PATCH 03/10] refactor: Update function signatures for owner and _msgSender in FacetBase and adjust LibPocoStorage access in related facets --- contracts/facets/FacetBase.sol | 4 ++-- contracts/facets/FacetBase.v8.sol | 4 ++-- contracts/facets/IexecAccessorsABILegacyFacet.sol | 2 +- contracts/facets/IexecCategoryManagerFacet.sol | 2 +- contracts/facets/IexecConfigurationFacet.sol | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/contracts/facets/FacetBase.sol b/contracts/facets/FacetBase.sol index cb7b77567..444b5485f 100644 --- a/contracts/facets/FacetBase.sol +++ b/contracts/facets/FacetBase.sol @@ -19,11 +19,11 @@ abstract contract FacetBase { _; } - function owner() public view virtual returns (address) { + function owner() public view returns (address) { return IOwnable(address(this)).owner(); } - function _msgSender() internal view virtual returns (address) { + function _msgSender() internal view returns (address) { return msg.sender; } diff --git a/contracts/facets/FacetBase.v8.sol b/contracts/facets/FacetBase.v8.sol index 8fe6fcc2a..ecc5e41ff 100644 --- a/contracts/facets/FacetBase.v8.sol +++ b/contracts/facets/FacetBase.v8.sol @@ -19,12 +19,12 @@ abstract contract FacetBase { _; } - function owner() public view virtual returns (address) { + function owner() public view returns (address) { // Make an external call to delegatecall the OwnershipFacet. return IERC5313(address(this)).owner(); } - function _msgSender() internal view virtual returns (address) { + function _msgSender() internal view returns (address) { return msg.sender; } diff --git a/contracts/facets/IexecAccessorsABILegacyFacet.sol b/contracts/facets/IexecAccessorsABILegacyFacet.sol index bb8a24820..4b337e92f 100644 --- a/contracts/facets/IexecAccessorsABILegacyFacet.sol +++ b/contracts/facets/IexecAccessorsABILegacyFacet.sol @@ -84,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 = LibPocoStorage.getPocoStorage().m_tasks[_taskid]; return ( task.status, task.dealid, diff --git a/contracts/facets/IexecCategoryManagerFacet.sol b/contracts/facets/IexecCategoryManagerFacet.sol index 99d8148db..318247919 100644 --- a/contracts/facets/IexecCategoryManagerFacet.sol +++ b/contracts/facets/IexecCategoryManagerFacet.sol @@ -17,7 +17,7 @@ contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase { string calldata description, uint256 workClockTimeRef ) external override onlyOwner returns (uint256) { - LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); $.m_categories.push(IexecLibCore_v5.Category(name, description, workClockTimeRef)); uint256 catid = $.m_categories.length - 1; diff --git a/contracts/facets/IexecConfigurationFacet.sol b/contracts/facets/IexecConfigurationFacet.sol index af7929a7a..d25eaa515 100644 --- a/contracts/facets/IexecConfigurationFacet.sol +++ b/contracts/facets/IexecConfigurationFacet.sol @@ -25,7 +25,7 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { address _workerpoolregistryAddress, address _v3_iexecHubAddress ) external override onlyOwner { - LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); require($.m_eip712DomainSeparator == bytes32(0), "already-configured"); $.m_eip712DomainSeparator = _domain().hash(); $.m_baseToken = IERC20(_token); @@ -44,13 +44,13 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { } function updateDomainSeparator() external override { - LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); require($.m_eip712DomainSeparator != bytes32(0), "not-configured"); $.m_eip712DomainSeparator = _domain().hash(); } function importScore(address _worker) external override { - LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 { - LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); $.m_teebroker = _teebroker; } function setCallbackGas(uint256 _callbackgas) external override onlyOwner { - LibPocoStorage.PocoStorage storage $ = getPocoStorage(); + LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); $.m_callbackgas = _callbackgas; } From dd67a11bf8e003f077d9c15271154c3a8ed1e50e Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 16:53:20 +0200 Subject: [PATCH 04/10] refactor: Remove unused storage access helper functions from FacetBase --- contracts/facets/FacetBase.sol | 11 ----------- contracts/facets/FacetBase.v8.sol | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/contracts/facets/FacetBase.sol b/contracts/facets/FacetBase.sol index 444b5485f..7e04a8946 100644 --- a/contracts/facets/FacetBase.sol +++ b/contracts/facets/FacetBase.sol @@ -26,15 +26,4 @@ abstract contract FacetBase { function _msgSender() internal view returns (address) { return msg.sender; } - - // === Storage Access Helper Functions === - // These provide backward compatibility for facets that were using Store directly - - /** - * @dev Get the PocoStorage struct for direct access when needed. - * @return The storage pointer to PocoStorage struct. - */ - function getPocoStorage() internal pure returns (LibPocoStorage.PocoStorage storage) { - return LibPocoStorage.getPocoStorage(); - } } diff --git a/contracts/facets/FacetBase.v8.sol b/contracts/facets/FacetBase.v8.sol index ecc5e41ff..d842db454 100644 --- a/contracts/facets/FacetBase.v8.sol +++ b/contracts/facets/FacetBase.v8.sol @@ -27,15 +27,4 @@ abstract contract FacetBase { function _msgSender() internal view returns (address) { return msg.sender; } - - // === Storage Access Helper Functions === - // These provide backward compatibility for facets that were using Store directly - - /** - * @dev Get the PocoStorage struct for direct access when needed. - * @return The storage pointer to PocoStorage struct. - */ - function _getPocoStorage() internal pure returns (LibPocoStorage.PocoStorage storage) { - return LibPocoStorage.getPocoStorage(); - } } From e9dc1dc468b345e48ebe2dde3ee0d79b6179e904 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 17:04:16 +0200 Subject: [PATCH 05/10] refactor: reduce the diff --- contracts/facets/IexecAccessorsFacet.sol | 1 + contracts/facets/SignatureVerifier.v8.sol | 1 - contracts/libs/LibPocoStorage.sol | 33 +++++++++++++---------- contracts/libs/LibPocoStorage.v8.sol | 32 +++++++++++++--------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/contracts/facets/IexecAccessorsFacet.sol b/contracts/facets/IexecAccessorsFacet.sol index 2167c3111..7b3b62573 100644 --- a/contracts/facets/IexecAccessorsFacet.sol +++ b/contracts/facets/IexecAccessorsFacet.sol @@ -168,6 +168,7 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { function groupmember_purpose() external view override returns (uint256) { return LibPocoStorage.GROUPMEMBER_PURPOSE; } + function eip712domain_separator() external view override returns (bytes32) { LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); return $.m_eip712DomainSeparator; diff --git a/contracts/facets/SignatureVerifier.v8.sol b/contracts/facets/SignatureVerifier.v8.sol index 2fb3bca10..19b782da6 100644 --- a/contracts/facets/SignatureVerifier.v8.sol +++ b/contracts/facets/SignatureVerifier.v8.sol @@ -7,7 +7,6 @@ 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 {FacetBase} from "./FacetBase.v8.sol"; - import {IERC734} from "../external/interfaces/IERC734.sol"; import {FacetBase} from "./FacetBase.v8.sol"; import {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; diff --git a/contracts/libs/LibPocoStorage.sol b/contracts/libs/LibPocoStorage.sol index ce8a2d0c3..59b688193 100644 --- a/contracts/libs/LibPocoStorage.sol +++ b/contracts/libs/LibPocoStorage.sol @@ -10,28 +10,33 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./IexecLibCore_v5.sol"; import "../registries/IRegistry.sol"; -/** - * @title LibPocoStorage - * @dev Library for managing PoCo diamond storage using ERC-7201 namespaced storage pattern. - * This library replaces the Store abstract contract to support ERC-2535 diamond proxy architecture. - * Solidity 0.6 version for legacy facets. - */ +/**************************************************************************** + * WARNING: Be carefull when editing this file. * + * * + * If you want to add new variables, add them to the end of the * + * struct `PocoStorage`. * + * Read more about: * + * - Diamond proxy storage https://eips.ethereum.org/EIPS/eip-2535 * + * - Namespaced storage https://eips.ethereum.org/EIPS/eip-7201 * + * * + ****************************************************************************/ + library LibPocoStorage { // Poco - Constants - uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7; - uint256 internal constant REVEAL_DEADLINE_RATIO = 2; - uint256 internal constant FINAL_DEADLINE_RATIO = 10; - uint256 internal constant WORKERPOOL_STAKE_RATIO = 30; - uint256 internal constant KITTY_RATIO = 10; - uint256 internal constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE + 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 internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; + address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; // Used with ERC-734 Key Manager identity contract for authorization management. - uint256 internal constant GROUPMEMBER_PURPOSE = 4; + uint256 public constant GROUPMEMBER_PURPOSE = 4; // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); bytes32 private constant POCO_STORAGE_LOCATION = diff --git a/contracts/libs/LibPocoStorage.v8.sol b/contracts/libs/LibPocoStorage.v8.sol index b2dab77e7..00d6d2495 100644 --- a/contracts/libs/LibPocoStorage.v8.sol +++ b/contracts/libs/LibPocoStorage.v8.sol @@ -7,27 +7,33 @@ import {IERC20} from "@openzeppelin/contracts-v5/interfaces/IERC20.sol"; import {IERC721Enumerable} from "@openzeppelin/contracts-v5/interfaces/IERC721Enumerable.sol"; import {IexecLibCore_v5} from "./IexecLibCore_v5.sol"; -/** - * @title LibPocoStorage - * @dev Library for managing PoCo diamond storage using ERC-7201 namespaced storage pattern. - * This library replaces the Store abstract contract to support ERC-2535 diamond proxy architecture. - */ +/**************************************************************************** + * WARNING: Be carefull when editing this file. * + * * + * If you want to add new variables, add them to the end of the * + * struct `PocoStorage`. * + * Read more about: * + * - Diamond proxy storage https://eips.ethereum.org/EIPS/eip-2535 * + * - Namespaced storage https://eips.ethereum.org/EIPS/eip-7201 * + * * + ****************************************************************************/ + library LibPocoStorage { // Poco - Constants - uint256 internal constant CONTRIBUTION_DEADLINE_RATIO = 7; - uint256 internal constant REVEAL_DEADLINE_RATIO = 2; - uint256 internal constant FINAL_DEADLINE_RATIO = 10; - uint256 internal constant WORKERPOOL_STAKE_RATIO = 30; - uint256 internal constant KITTY_RATIO = 10; - uint256 internal constant KITTY_MIN = 1e9; // ADJUSTEMENT VARIABLE + 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 internal constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; + address public constant KITTY_ADDRESS = 0x99c2268479b93fDe36232351229815DF80837e23; // Used with ERC-734 Key Manager identity contract for authorization management. - uint256 internal constant GROUPMEMBER_PURPOSE = 4; + uint256 public constant GROUPMEMBER_PURPOSE = 4; // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); bytes32 private constant POCO_STORAGE_LOCATION = From d2666bfcc6c887bff4e238851cf56bb6ae92e3cb Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 17:10:46 +0200 Subject: [PATCH 06/10] refactor: reorganize imports and clean up comments in LibPocoStorage --- contracts/libs/LibPocoStorage.sol | 8 +++++--- contracts/libs/LibPocoStorage.v8.sol | 7 ++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/contracts/libs/LibPocoStorage.sol b/contracts/libs/LibPocoStorage.sol index 59b688193..ee16c4d31 100644 --- a/contracts/libs/LibPocoStorage.sol +++ b/contracts/libs/LibPocoStorage.sol @@ -8,8 +8,11 @@ import "@iexec/solidity/contracts/Libs/SafeMathExtended.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./IexecLibCore_v5.sol"; -import "../registries/IRegistry.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. * * * @@ -43,7 +46,6 @@ library LibPocoStorage { 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; /// @custom:storage-location erc7201:iexec.poco.storage.PocoStorage - struct PocoStorage { // Registries IRegistry m_appregistry; diff --git a/contracts/libs/LibPocoStorage.v8.sol b/contracts/libs/LibPocoStorage.v8.sol index 00d6d2495..6ce8129a2 100644 --- a/contracts/libs/LibPocoStorage.v8.sol +++ b/contracts/libs/LibPocoStorage.v8.sol @@ -5,6 +5,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 "./IexecLibCore_v5.sol"; /**************************************************************************** @@ -94,10 +95,6 @@ library LibPocoStorage { mapping(bytes32 /* dealId */ => IexecLibCore_v5.DealBoost) m_dealsBoost; } - /** - * @dev Returns the storage pointer for PocoStorage. - * @return $ The storage pointer to PocoStorage struct. - */ function getPocoStorage() internal pure returns (PocoStorage storage $) { assembly ("memory-safe") { $.slot := POCO_STORAGE_LOCATION @@ -105,7 +102,7 @@ library LibPocoStorage { } } -// Registry interface used in storage. +// Use in registries. interface IRegistry is IERC721Enumerable { function isRegistered(address _entry) external view returns (bool); } From c6813183474f75c797760df1aa681b03e2464a39 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 17:14:17 +0200 Subject: [PATCH 07/10] refactor: remove duplicate import of FacetBase in SignatureVerifier --- contracts/facets/SignatureVerifier.v8.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/facets/SignatureVerifier.v8.sol b/contracts/facets/SignatureVerifier.v8.sol index 19b782da6..965162025 100644 --- a/contracts/facets/SignatureVerifier.v8.sol +++ b/contracts/facets/SignatureVerifier.v8.sol @@ -8,7 +8,6 @@ import {ECDSA} from "@openzeppelin/contracts-v5/utils/cryptography/ECDSA.sol"; import {MessageHashUtils} from "@openzeppelin/contracts-v5/utils/cryptography/MessageHashUtils.sol"; import {FacetBase} from "./FacetBase.v8.sol"; import {IERC734} from "../external/interfaces/IERC734.sol"; -import {FacetBase} from "./FacetBase.v8.sol"; import {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; contract SignatureVerifier is FacetBase { From f821de04f38b97a97b2897cd570fbb12f504b47e Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 17:16:22 +0200 Subject: [PATCH 08/10] chore: update changelog for vNEXT with storage library usage --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b7d4776a..6bf0f7bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## vNEXT - 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) From 25fa99877ff4cde202d18030842813e54a159b29 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 17:49:05 +0200 Subject: [PATCH 09/10] refactor: migrate constants from LibPocoStorage to FacetBase and update references --- contracts/facets/FacetBase.sol | 16 +++++++++++ contracts/facets/FacetBase.v8.sol | 16 +++++++++++ contracts/facets/IexecAccessorsFacet.sol | 16 +++++------ contracts/facets/IexecPoco1Facet.sol | 2 +- contracts/facets/IexecPoco2Facet.sol | 35 +++++++++-------------- contracts/facets/IexecPocoBoostFacet.sol | 29 ++++++++----------- contracts/facets/SignatureVerifier.v8.sol | 2 +- contracts/libs/LibPocoStorage.sol | 16 ----------- contracts/libs/LibPocoStorage.v8.sol | 16 ----------- 9 files changed, 67 insertions(+), 81 deletions(-) diff --git a/contracts/facets/FacetBase.sol b/contracts/facets/FacetBase.sol index 7e04a8946..4300db1fc 100644 --- a/contracts/facets/FacetBase.sol +++ b/contracts/facets/FacetBase.sol @@ -14,6 +14,22 @@ import "../interfaces/IOwnable.sol"; * @dev Every facet must inherit from this contract. */ 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 d842db454..b63affef9 100644 --- a/contracts/facets/FacetBase.v8.sol +++ b/contracts/facets/FacetBase.v8.sol @@ -14,6 +14,22 @@ import {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; * @dev Every facet must inherit from this contract. */ 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/IexecAccessorsFacet.sol b/contracts/facets/IexecAccessorsFacet.sol index 7b3b62573..8c8311427 100644 --- a/contracts/facets/IexecAccessorsFacet.sol +++ b/contracts/facets/IexecAccessorsFacet.sol @@ -138,35 +138,35 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { } function contribution_deadline_ratio() external view override returns (uint256) { - return LibPocoStorage.CONTRIBUTION_DEADLINE_RATIO; + return CONTRIBUTION_DEADLINE_RATIO; } function reveal_deadline_ratio() external view override returns (uint256) { - return LibPocoStorage.REVEAL_DEADLINE_RATIO; + return REVEAL_DEADLINE_RATIO; } function final_deadline_ratio() external view override returns (uint256) { - return LibPocoStorage.FINAL_DEADLINE_RATIO; + return FINAL_DEADLINE_RATIO; } function workerpool_stake_ratio() external view override returns (uint256) { - return LibPocoStorage.WORKERPOOL_STAKE_RATIO; + return WORKERPOOL_STAKE_RATIO; } function kitty_ratio() external view override returns (uint256) { - return LibPocoStorage.KITTY_RATIO; + return KITTY_RATIO; } function kitty_min() external view override returns (uint256) { - return LibPocoStorage.KITTY_MIN; + return KITTY_MIN; } function kitty_address() external view override returns (address) { - return LibPocoStorage.KITTY_ADDRESS; + return KITTY_ADDRESS; } function groupmember_purpose() external view override returns (uint256) { - return LibPocoStorage.GROUPMEMBER_PURPOSE; + return GROUPMEMBER_PURPOSE; } function eip712domain_separator() external view override returns (bytes32) { diff --git a/contracts/facets/IexecPoco1Facet.sol b/contracts/facets/IexecPoco1Facet.sol index 31fc56405..147ca61b1 100644 --- a/contracts/facets/IexecPoco1Facet.sol +++ b/contracts/facets/IexecPoco1Facet.sol @@ -365,7 +365,7 @@ contract IexecPoco1Facet is //slither-disable-next-line divide-before-multiply lock( deal.workerpool.owner, - ((deal.workerpool.price * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100) * volume // ORDER IS IMPORTANT HERE! + ((deal.workerpool.price * WORKERPOOL_STAKE_RATIO) / 100) * volume // ORDER IS IMPORTANT HERE! ); /** diff --git a/contracts/facets/IexecPoco2Facet.sol b/contracts/facets/IexecPoco2Facet.sol index c98de2af2..cb702c681 100644 --- a/contracts/facets/IexecPoco2Facet.sol +++ b/contracts/facets/IexecPoco2Facet.sol @@ -28,7 +28,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie IexecLibCore_v5.Deal storage deal = $.m_deals[_dealid]; uint256 taskPrice = deal.app.price + deal.dataset.price + deal.workerpool.price; - uint256 poolstake = (deal.workerpool.price * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100; + uint256 poolstake = (deal.workerpool.price * WORKERPOOL_STAKE_RATIO) / 100; // Seize the payer of the task seize(deal.sponsor, taskPrice, _taskid); @@ -45,14 +45,11 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie // pool reward performed by consensus manager // Retrieve part of the kitty - uint256 kitty = $.m_frozens[LibPocoStorage.KITTY_ADDRESS]; + uint256 kitty = $.m_frozens[KITTY_ADDRESS]; if (kitty > 0) { - // Get a fraction of the kitty where LibPocoStorage.KITTY_MIN <= fraction <= kitty - kitty = Math.min( - Math.max((kitty * LibPocoStorage.KITTY_RATIO) / 100, LibPocoStorage.KITTY_MIN), - kitty - ); - seize(LibPocoStorage.KITTY_ADDRESS, kitty, _taskid); + // Get a fraction of the kitty where KITTY_MIN <= fraction <= kitty + kitty = Math.min(Math.max((kitty * KITTY_RATIO) / 100, KITTY_MIN), kitty); + seize(KITTY_ADDRESS, kitty, _taskid); reward(deal.workerpool.owner, kitty, _taskid); } } @@ -62,7 +59,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie IexecLibCore_v5.Deal memory deal = $.m_deals[_dealid]; uint256 taskPrice = deal.app.price + deal.dataset.price + deal.workerpool.price; - uint256 poolstake = (deal.workerpool.price * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100; + uint256 poolstake = (deal.workerpool.price * WORKERPOOL_STAKE_RATIO) / 100; unlock(deal.sponsor, taskPrice); // Refund the payer of the task seize(deal.workerpool.owner, poolstake, _taskid); @@ -72,9 +69,9 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * where functions would together uselessly transfer value from main PoCo * proxy to kitty, then would transfer value back from kitty to main PoCo proxy. */ - $.m_frozens[LibPocoStorage.KITTY_ADDRESS] += poolstake; // → Kitty / Burn - emit Reward(LibPocoStorage.KITTY_ADDRESS, poolstake, _taskid); - emit Lock(LibPocoStorage.KITTY_ADDRESS, poolstake); + $.m_frozens[KITTY_ADDRESS] += poolstake; // → Kitty / Burn + emit Reward(KITTY_ADDRESS, poolstake, _taskid); + emit Lock(KITTY_ADDRESS, poolstake); } /*************************************************************************** @@ -95,11 +92,8 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie task.dealid = _dealid; task.idx = idx; task.timeref = $.m_categories[deal.category].workClockTimeRef; - task.contributionDeadline = - deal.startTime + - task.timeref * - LibPocoStorage.CONTRIBUTION_DEADLINE_RATIO; - task.finalDeadline = deal.startTime + task.timeref * LibPocoStorage.FINAL_DEADLINE_RATIO; + task.contributionDeadline = deal.startTime + task.timeref * CONTRIBUTION_DEADLINE_RATIO; + task.finalDeadline = deal.startTime + task.timeref * FINAL_DEADLINE_RATIO; // setup denominator $.m_consensus[taskid].total = 1; @@ -246,7 +240,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie task.status = IexecLibCore_v5.TaskStatusEnum.COMPLETED; task.consensusValue = contribution.resultHash; - task.revealDeadline = block.timestamp + task.timeref * LibPocoStorage.REVEAL_DEADLINE_RATIO; + task.revealDeadline = block.timestamp + task.timeref * REVEAL_DEADLINE_RATIO; task.revealCounter = 1; task.winnerCounter = 1; task.resultDigest = _resultDigest; @@ -413,10 +407,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie // _msgSender() is a contributor: no need to check task.status = IexecLibCore_v5.TaskStatusEnum.REVEALING; task.consensusValue = _consensus; - task.revealDeadline = - block.timestamp + - task.timeref * - LibPocoStorage.REVEAL_DEADLINE_RATIO; + task.revealDeadline = block.timestamp + task.timeref * REVEAL_DEADLINE_RATIO; task.revealCounter = 0; task.winnerCounter = winnerCounter; diff --git a/contracts/facets/IexecPocoBoostFacet.sol b/contracts/facets/IexecPocoBoostFacet.sol index 9be2fafd6..8e4d105f6 100644 --- a/contracts/facets/IexecPocoBoostFacet.sol +++ b/contracts/facets/IexecPocoBoostFacet.sol @@ -296,7 +296,7 @@ contract IexecPocoBoostFacet is deal.botFirst = requestOrderConsumed.toUint16(); deal.deadline = (block.timestamp + $.m_categories[category].workClockTimeRef * - LibPocoStorage.CONTRIBUTION_DEADLINE_RATIO).toUint40(); + CONTRIBUTION_DEADLINE_RATIO).toUint40(); deal.botSize = volume.toUint16(); /** * Store right part of tag for later use. @@ -336,10 +336,7 @@ contract IexecPocoBoostFacet is // Order is important here. First get percentage by task then // multiply by volume. //slither-disable-next-line divide-before-multiply - lock( - workerpoolOwner, - ((workerpoolPrice * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100) * volume - ); + lock(workerpoolOwner, ((workerpoolPrice * WORKERPOOL_STAKE_RATIO) / 100) * volume); // Notify workerpool. emit SchedulerNoticeBoost( workerpool, @@ -454,17 +451,16 @@ contract IexecPocoBoostFacet is } // Unlock scheduler stake - unlock(workerpoolOwner, (workerPoolPrice * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / 100); + unlock(workerpoolOwner, (workerPoolPrice * WORKERPOOL_STAKE_RATIO) / 100); // Reward scheduler - uint256 kitty = $.m_frozens[LibPocoStorage.KITTY_ADDRESS]; + uint256 kitty = $.m_frozens[KITTY_ADDRESS]; if (kitty > 0) { - kitty = LibPocoStorage - .KITTY_MIN // 1. retrieve bare minimum from kitty + kitty = KITTY_MIN // 1. retrieve bare minimum from kitty .max( // 2. or eventually a fraction of kitty if bigger - // @dev As long as `LibPocoStorage.KITTY_RATIO = 10`, we can introduce this small - kitty / LibPocoStorage.KITTY_RATIO // optimization for `kitty * LibPocoStorage.KITTY_RATIO / 100` + // @dev As long as `KITTY_RATIO = 10`, we can introduce this small + kitty / KITTY_RATIO // optimization for `kitty * KITTY_RATIO / 100` ).min(kitty); // 3. but no more than available - seize(LibPocoStorage.KITTY_ADDRESS, kitty, taskId); + seize(KITTY_ADDRESS, kitty, taskId); } reward( workerpoolOwner, @@ -512,17 +508,16 @@ contract IexecPocoBoostFacet is task.status = IexecLibCore_v5.TaskStatusEnum.FAILED; // Calculate workerpool price and task stake. uint96 workerPoolPrice = deal.workerpoolPrice; - uint256 workerpoolTaskStake = (workerPoolPrice * LibPocoStorage.WORKERPOOL_STAKE_RATIO) / - 100; + uint256 workerpoolTaskStake = (workerPoolPrice * WORKERPOOL_STAKE_RATIO) / 100; // Refund the payer of the task by unlocking the locked funds. unlock(deal.sponsor, deal.appPrice + deal.datasetPrice + workerPoolPrice); // Seize task stake from workerpool. seize(deal.workerpoolOwner, workerpoolTaskStake, taskId); // Reward kitty and lock the rewarded amount. - $.m_frozens[LibPocoStorage.KITTY_ADDRESS] += workerpoolTaskStake; + $.m_frozens[KITTY_ADDRESS] += workerpoolTaskStake; // Emit events to publish state changes. - emit Reward(LibPocoStorage.KITTY_ADDRESS, workerpoolTaskStake, taskId); - emit Lock(LibPocoStorage.KITTY_ADDRESS, workerpoolTaskStake); + emit Reward(KITTY_ADDRESS, workerpoolTaskStake, taskId); + emit Lock(KITTY_ADDRESS, workerpoolTaskStake); emit TaskClaimed(taskId); } diff --git a/contracts/facets/SignatureVerifier.v8.sol b/contracts/facets/SignatureVerifier.v8.sol index 965162025..0659873a3 100644 --- a/contracts/facets/SignatureVerifier.v8.sol +++ b/contracts/facets/SignatureVerifier.v8.sol @@ -142,7 +142,7 @@ contract SignatureVerifier is FacetBase { try IERC734(restriction).keyHasPurpose( // ERC734 identity contract restriction bytes32(uint256(uint160(account))), - LibPocoStorage.GROUPMEMBER_PURPOSE + GROUPMEMBER_PURPOSE ) returns (bool success) { return success; diff --git a/contracts/libs/LibPocoStorage.sol b/contracts/libs/LibPocoStorage.sol index ee16c4d31..7e03fe173 100644 --- a/contracts/libs/LibPocoStorage.sol +++ b/contracts/libs/LibPocoStorage.sol @@ -25,22 +25,6 @@ import "./../registries/IRegistry.sol"; ****************************************************************************/ library LibPocoStorage { - // 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; - // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); bytes32 private constant POCO_STORAGE_LOCATION = 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; diff --git a/contracts/libs/LibPocoStorage.v8.sol b/contracts/libs/LibPocoStorage.v8.sol index 6ce8129a2..ec3558dda 100644 --- a/contracts/libs/LibPocoStorage.v8.sol +++ b/contracts/libs/LibPocoStorage.v8.sol @@ -20,22 +20,6 @@ import {IexecLibCore_v5} from "./IexecLibCore_v5.sol"; ****************************************************************************/ library LibPocoStorage { - // 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; - // keccak256(abi.encode(uint256(keccak256("iexec.poco.storage.PocoStorage")) - 1)) & ~bytes32(uint256(0xff)); bytes32 private constant POCO_STORAGE_LOCATION = 0x5862653c6982c162832160cf30593645e8487b257e44d77cdd6b51eee2651b00; From fefd282c67b6c4b902748e2d41a6b5e216e4fb65 Mon Sep 17 00:00:00 2001 From: gfournieriExec Date: Mon, 28 Jul 2025 17:56:36 +0200 Subject: [PATCH 10/10] refactor: change LibPocoStorage to PocoStorageLib --- contracts/facets/FacetBase.sol | 2 +- contracts/facets/FacetBase.v8.sol | 2 +- .../facets/IexecAccessorsABILegacyFacet.sol | 16 +++--- contracts/facets/IexecAccessorsFacet.sol | 50 +++++++++---------- .../facets/IexecCategoryManagerFacet.sol | 4 +- .../facets/IexecConfigurationExtraFacet.sol | 4 +- contracts/facets/IexecConfigurationFacet.sol | 12 ++--- contracts/facets/IexecERC20Core.sol | 10 ++-- contracts/facets/IexecERC20Facet.sol | 8 +-- contracts/facets/IexecEscrow.v8.sol | 10 ++-- contracts/facets/IexecEscrowNativeFacet.sol | 4 +- contracts/facets/IexecEscrowTokenFacet.sol | 10 ++-- .../facets/IexecEscrowTokenSwapFacet.sol | 10 ++-- .../facets/IexecOrderManagementFacet.sol | 10 ++-- contracts/facets/IexecPoco1Facet.sol | 4 +- contracts/facets/IexecPoco2Facet.sol | 30 +++++------ contracts/facets/IexecPocoAccessorsFacet.sol | 6 +-- .../facets/IexecPocoBoostAccessorsFacet.sol | 4 +- contracts/facets/IexecPocoBoostFacet.sol | 8 +-- contracts/facets/IexecPocoCommonFacet.sol | 4 +- contracts/facets/SignatureVerifier.sol | 4 +- contracts/facets/SignatureVerifier.v8.sol | 6 +-- ...{LibPocoStorage.sol => PocoStorageLib.sol} | 2 +- ...coStorage.v8.sol => PocoStorageLib.v8.sol} | 2 +- .../tools/testing/IexecEscrowTestContract.sol | 8 +-- 25 files changed, 115 insertions(+), 115 deletions(-) rename contracts/libs/{LibPocoStorage.sol => PocoStorageLib.sol} (99%) rename contracts/libs/{LibPocoStorage.v8.sol => PocoStorageLib.v8.sol} (99%) diff --git a/contracts/facets/FacetBase.sol b/contracts/facets/FacetBase.sol index 4300db1fc..10c164261 100644 --- a/contracts/facets/FacetBase.sol +++ b/contracts/facets/FacetBase.sol @@ -3,7 +3,7 @@ pragma solidity ^0.6.0; -import "../libs/LibPocoStorage.sol"; +import "../libs/PocoStorageLib.sol"; import "../interfaces/IOwnable.sol"; // Functions that were declared in ERC1538Store are re-declared here. diff --git a/contracts/facets/FacetBase.v8.sol b/contracts/facets/FacetBase.v8.sol index b63affef9..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 {LibPocoStorage} from "../libs/LibPocoStorage.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. diff --git a/contracts/facets/IexecAccessorsABILegacyFacet.sol b/contracts/facets/IexecAccessorsABILegacyFacet.sol index 4b337e92f..d275f9748 100644 --- a/contracts/facets/IexecAccessorsABILegacyFacet.sol +++ b/contracts/facets/IexecAccessorsABILegacyFacet.sol @@ -6,7 +6,7 @@ pragma experimental ABIEncoderV2; import "./FacetBase.sol"; import "../interfaces/IexecAccessorsABILegacy.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewDealABILegacy_pt1( @@ -17,7 +17,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { override returns (address, address, uint256, address, address, uint256, address, address, uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_id]; return ( deal.app.pointer, @@ -35,7 +35,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewDealABILegacy_pt2( bytes32 _id ) external view override returns (uint256, bytes32, address, address, address, string memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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); } @@ -43,7 +43,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewConfigABILegacy( bytes32 _id ) external view override returns (uint256, uint256, uint256, uint256, uint256, uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_id]; return ( deal.category, @@ -58,7 +58,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewAccountABILegacy( address account ) external view override returns (uint256, uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return ($.m_balances[account], $.m_frozens[account]); } @@ -84,7 +84,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { ) { /// @dev Using $.m_tasks causes "Stack too deep" error. - IexecLibCore_v5.Task memory task = LibPocoStorage.getPocoStorage().m_tasks[_taskid]; + IexecLibCore_v5.Task memory task = PocoStorageLib.getPocoStorage().m_tasks[_taskid]; return ( task.status, task.dealid, @@ -110,7 +110,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { override returns (IexecLibCore_v5.ContributionStatusEnum, bytes32, bytes32, address) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Contribution memory contribution = $.m_contributions[_taskid][_worker]; return ( contribution.status, @@ -123,7 +123,7 @@ contract IexecAccessorsABILegacyFacet is IexecAccessorsABILegacy, FacetBase { function viewCategoryABILegacy( uint256 _catid ) external view override returns (string memory, string memory, uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 8c8311427..f81003632 100644 --- a/contracts/facets/IexecAccessorsFacet.sol +++ b/contracts/facets/IexecAccessorsFacet.sol @@ -6,77 +6,77 @@ pragma experimental ABIEncoderV2; import "./FacetBase.sol"; import "../interfaces/IexecAccessors.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecAccessorsFacet is IexecAccessors, FacetBase { function name() external view override returns (string memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_name; } function symbol() external view override returns (string memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_symbol; } function decimals() external view override returns (uint8) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_decimals; } function totalSupply() external view override returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_totalSupply; } function balanceOf(address account) external view override returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_balances[account]; } function frozenOf(address account) external view override returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_frozens[account]; } function allowance(address account, address spender) external view override returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_allowances[account][spender]; } function viewAccount( address account ) external view override returns (IexecLibCore_v5.Account memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return IexecLibCore_v5.Account($.m_balances[account], $.m_frozens[account]); } function token() external view override returns (address) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return address($.m_baseToken); } function viewDeal( bytes32 _id ) external view override returns (IexecLibCore_v5.Deal memory deal) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_deals[_id]; } function viewConsumed(bytes32 _id) external view override returns (uint256 consumed) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_consumed[_id]; } function viewPresigned(bytes32 _id) external view override returns (address signer) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_presigned[_id]; } function viewTask( bytes32 _taskid ) external view override returns (IexecLibCore_v5.Task memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_tasks[_taskid]; } @@ -84,17 +84,17 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { bytes32 _taskid, address _worker ) external view override returns (IexecLibCore_v5.Contribution memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_contributions[_taskid][_worker]; } function viewScore(address _worker) external view override returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_workerScores[_worker]; } function resultFor(bytes32 id) external view override returns (bytes memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 @@ -103,37 +103,37 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { function viewCategory( uint256 _catid ) external view override returns (IexecLibCore_v5.Category memory category) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_categories[_catid]; } function countCategory() external view override returns (uint256 count) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_categories.length; } function appregistry() external view override returns (IRegistry) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_appregistry; } function datasetregistry() external view override returns (IRegistry) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_datasetregistry; } function workerpoolregistry() external view override returns (IRegistry) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_workerpoolregistry; } function teebroker() external view override returns (address) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_teebroker; } function callbackgas() external view override returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_callbackgas; } @@ -170,7 +170,7 @@ contract IexecAccessorsFacet is IexecAccessors, FacetBase { } function eip712domain_separator() external view override returns (bytes32) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_eip712DomainSeparator; } } diff --git a/contracts/facets/IexecCategoryManagerFacet.sol b/contracts/facets/IexecCategoryManagerFacet.sol index 318247919..195f3d391 100644 --- a/contracts/facets/IexecCategoryManagerFacet.sol +++ b/contracts/facets/IexecCategoryManagerFacet.sol @@ -5,7 +5,7 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; import "./FacetBase.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; import "../interfaces/IexecCategoryManager.sol"; contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase { @@ -17,7 +17,7 @@ contract IexecCategoryManagerFacet is IexecCategoryManager, FacetBase { string calldata description, uint256 workClockTimeRef ) external override onlyOwner returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 ed58ab976..aa6f1de35 100644 --- a/contracts/facets/IexecConfigurationExtraFacet.sol +++ b/contracts/facets/IexecConfigurationExtraFacet.sol @@ -6,7 +6,7 @@ pragma experimental ABIEncoderV2; import "./FacetBase.sol"; import "../interfaces/IexecConfigurationExtra.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecConfigurationExtraFacet is IexecConfigurationExtra, FacetBase { function changeRegistries( @@ -14,7 +14,7 @@ contract IexecConfigurationExtraFacet is IexecConfigurationExtra, FacetBase { address _datasetregistryAddress, address _workerpoolregistryAddress ) external override onlyOwner { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 d25eaa515..41aaac187 100644 --- a/contracts/facets/IexecConfigurationFacet.sol +++ b/contracts/facets/IexecConfigurationFacet.sol @@ -8,7 +8,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./FacetBase.sol"; import "../interfaces/IexecConfiguration.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecConfigurationFacet is IexecConfiguration, FacetBase { using SafeMathExtended for uint256; @@ -25,7 +25,7 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { address _workerpoolregistryAddress, address _v3_iexecHubAddress ) external override onlyOwner { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require($.m_eip712DomainSeparator == bytes32(0), "already-configured"); $.m_eip712DomainSeparator = _domain().hash(); $.m_baseToken = IERC20(_token); @@ -44,13 +44,13 @@ contract IexecConfigurationFacet is IexecConfiguration, FacetBase { } function updateDomainSeparator() external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require($.m_eip712DomainSeparator != bytes32(0), "not-configured"); $.m_eip712DomainSeparator = _domain().hash(); } function importScore(address _worker) external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_teebroker = _teebroker; } function setCallbackGas(uint256 _callbackgas) external override onlyOwner { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_callbackgas = _callbackgas; } diff --git a/contracts/facets/IexecERC20Core.sol b/contracts/facets/IexecERC20Core.sol index 1990b1e19..1c2adfe77 100644 --- a/contracts/facets/IexecERC20Core.sol +++ b/contracts/facets/IexecERC20Core.sol @@ -4,7 +4,7 @@ pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; import "./FacetBase.sol"; contract IexecERC20Core is FacetBase { @@ -16,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"); - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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); @@ -28,7 +28,7 @@ contract IexecERC20Core is FacetBase { function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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); @@ -36,7 +36,7 @@ contract IexecERC20Core is FacetBase { function _burn(address account, uint256 amount) internal { require(account != address(0), "ERC20: burn from the zero address"); - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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); @@ -45,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"); - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 85ef017ac..490203977 100644 --- a/contracts/facets/IexecERC20Facet.sol +++ b/contracts/facets/IexecERC20Facet.sol @@ -8,7 +8,7 @@ import "./IexecERC20Core.sol"; import "./FacetBase.sol"; import "../interfaces/IexecERC20.sol"; import "../interfaces/IexecTokenSpender.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecERC20Facet is IexecERC20, FacetBase, IexecERC20Core { function transfer(address recipient, uint256 amount) external override returns (bool) { @@ -44,7 +44,7 @@ contract IexecERC20Facet is IexecERC20, FacetBase, IexecERC20Core { address recipient, uint256 amount ) external override returns (bool) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); _transfer(sender, recipient, amount); _approve(sender, _msgSender(), $.m_allowances[sender][_msgSender()].sub(amount)); return true; @@ -54,7 +54,7 @@ contract IexecERC20Facet is IexecERC20, FacetBase, IexecERC20Core { address spender, uint256 addedValue ) external override returns (bool) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); _approve(_msgSender(), spender, $.m_allowances[_msgSender()][spender].add(addedValue)); return true; } @@ -63,7 +63,7 @@ contract IexecERC20Facet is IexecERC20, FacetBase, IexecERC20Core { address spender, uint256 subtractedValue ) external override returns (bool) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 56e5de4e3..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 {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; +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 { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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"); - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 79a9a5bdf..42a1ef056 100644 --- a/contracts/facets/IexecEscrowNativeFacet.sol +++ b/contracts/facets/IexecEscrowNativeFacet.sol @@ -7,7 +7,7 @@ pragma experimental ABIEncoderV2; import "./IexecERC20Core.sol"; import "./FacetBase.sol"; import "../interfaces/IexecEscrowNative.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecEscrowNativeFacet is IexecEscrowNative, FacetBase, IexecERC20Core { using SafeMathExtended for uint256; @@ -61,7 +61,7 @@ contract IexecEscrowNativeFacet is IexecEscrowNative, FacetBase, IexecERC20Core } function recover() external override onlyOwner returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 e41bed553..fd9e833cb 100644 --- a/contracts/facets/IexecEscrowTokenFacet.sol +++ b/contracts/facets/IexecEscrowTokenFacet.sol @@ -8,7 +8,7 @@ import "./IexecERC20Core.sol"; import "./FacetBase.sol"; import "../interfaces/IexecEscrowToken.sol"; import "../interfaces/IexecTokenSpender.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase, IexecERC20Core { using SafeMathExtended for uint256; @@ -61,7 +61,7 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase } function recover() external override onlyOwner returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); uint256 delta = $.m_baseToken.balanceOf(address(this)).sub($.m_totalSupply); _mint(owner(), delta); return delta; @@ -74,7 +74,7 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase address token, bytes calldata ) external override returns (bool) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require(token == address($.m_baseToken), "wrong-token"); _deposit(sender, amount); _mint(sender, amount); @@ -82,12 +82,12 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase } function _deposit(address from, uint256 amount) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require($.m_baseToken.transferFrom(from, address(this), amount), "failled-transferFrom"); } function _withdraw(address to, uint256 amount) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_baseToken.transfer(to, amount); } } diff --git a/contracts/facets/IexecEscrowTokenSwapFacet.sol b/contracts/facets/IexecEscrowTokenSwapFacet.sol index e6c7f2dbc..62bce85a1 100644 --- a/contracts/facets/IexecEscrowTokenSwapFacet.sol +++ b/contracts/facets/IexecEscrowTokenSwapFacet.sol @@ -8,7 +8,7 @@ import "./IexecERC20Core.sol"; import "./SignatureVerifier.sol"; import "./FacetBase.sol"; import "../interfaces/IexecEscrowTokenSwap.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; import "../interfaces/IexecPoco1.sol"; contract IexecEscrowTokenSwapFacet is @@ -37,7 +37,7 @@ contract IexecEscrowTokenSwapFacet is * Uniswap path - Internal * ***************************************************************************/ function _eth2token() internal view returns (address[] memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address[] memory path = new address[](2); path[0] = router.WETH(); path[1] = address($.m_baseToken); @@ -45,7 +45,7 @@ contract IexecEscrowTokenSwapFacet is } function _token2eth() internal view returns (address[] memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address[] memory path = new address[](2); path[0] = address($.m_baseToken); path[1] = router.WETH(); @@ -142,7 +142,7 @@ contract IexecEscrowTokenSwapFacet is } function _withdraw(address target, uint256 amount, uint256 minimum) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_baseToken.approve(address(router), amount); uint256[] memory amounts = router.swapExactTokensForETH( amount, @@ -163,7 +163,7 @@ contract IexecEscrowTokenSwapFacet is IexecLibOrders_v5.WorkerpoolOrder memory _workerpoolorder, IexecLibOrders_v5.RequestOrder memory _requestorder ) public payable override returns (bytes32) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); uint256 volume; volume = _apporder.volume.sub( $.m_consumed[keccak256(_toEthTypedStruct(_apporder.hash(), $.m_eip712DomainSeparator))] diff --git a/contracts/facets/IexecOrderManagementFacet.sol b/contracts/facets/IexecOrderManagementFacet.sol index e3115cd89..c53744549 100644 --- a/contracts/facets/IexecOrderManagementFacet.sol +++ b/contracts/facets/IexecOrderManagementFacet.sol @@ -7,7 +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 {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol"; contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, SignatureVerifier { @@ -26,7 +26,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageAppOrder( IexecLibOrders_v5.AppOrderOperation calldata _apporderoperation ) external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address owner = IERC5313(_apporderoperation.order.app).owner(); require( owner == _msgSender() || @@ -51,7 +51,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageDatasetOrder( IexecLibOrders_v5.DatasetOrderOperation calldata _datasetorderoperation ) external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address owner = IERC5313(_datasetorderoperation.order.dataset).owner(); require( owner == _msgSender() || @@ -76,7 +76,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageWorkerpoolOrder( IexecLibOrders_v5.WorkerpoolOrderOperation calldata _workerpoolorderoperation ) external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); address owner = IERC5313(_workerpoolorderoperation.order.workerpool).owner(); require( owner == _msgSender() || @@ -103,7 +103,7 @@ contract IexecOrderManagementFacet is IexecOrderManagement, FacetBase, Signature function manageRequestOrder( IexecLibOrders_v5.RequestOrderOperation calldata _requestorderoperation ) external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 147ca61b1..9475fffd4 100644 --- a/contracts/facets/IexecPoco1Facet.sol +++ b/contracts/facets/IexecPoco1Facet.sol @@ -9,7 +9,7 @@ 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 {LibPocoStorage} from "../libs/LibPocoStorage.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) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); /** * Check orders compatibility */ diff --git a/contracts/facets/IexecPoco2Facet.sol b/contracts/facets/IexecPoco2Facet.sol index cb702c681..4f5f6c9d9 100644 --- a/contracts/facets/IexecPoco2Facet.sol +++ b/contracts/facets/IexecPoco2Facet.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {Math} from "@openzeppelin/contracts-v5/utils/math/Math.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.v8.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"; @@ -15,7 +15,7 @@ import {SignatureVerifier} from "./SignatureVerifier.v8.sol"; contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifier { modifier onlyScheduler(bytes32 _taskId) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); require(_msgSender() == $.m_deals[$.m_tasks[_taskId].dealid].workerpool.owner); _; } @@ -24,7 +24,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Escrow overhead for contribution * ***************************************************************************/ function successWork(bytes32 _dealid, bytes32 _taskid) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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; @@ -55,7 +55,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function failedWork(bytes32 _dealid, bytes32 _taskid) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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; @@ -78,7 +78,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Consensus methods * ***************************************************************************/ function initialize(bytes32 _dealid, uint256 idx) public override returns (bytes32) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Deal memory deal = $.m_deals[_dealid]; require(idx >= deal.botFirst); @@ -111,7 +111,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _enclaveSign, bytes calldata _authorizationSign ) external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -189,7 +189,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _enclaveSign, bytes calldata _authorizationSign ) external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -260,7 +260,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function reveal(bytes32 _taskid, bytes32 _resultDigest) external override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Contribution storage contribution = $.m_contributions[_taskid][ _msgSender() @@ -283,7 +283,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function reopen(bytes32 _taskid) external override onlyScheduler(_taskid) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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); @@ -315,7 +315,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie bytes calldata _results, bytes calldata _resultsCallback // Expansion - result separation ) external override onlyScheduler(_taskid) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -350,7 +350,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie } function claim(bytes32 _taskid) public override { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; require( task.status == IexecLibCore_v5.TaskStatusEnum.ACTIVE || @@ -380,7 +380,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Consensus detection */ function checkConsensus(bytes32 _taskid, bytes32 _consensus) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task storage task = $.m_tasks[_taskid]; IexecLibCore_v5.Consensus storage consensus = $.m_consensus[_taskid]; @@ -419,7 +419,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Reward distribution */ function distributeRewards(bytes32 _taskid) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task memory task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -498,7 +498,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Reward distribution for contributeAndFinalize */ function distributeRewardsFast(bytes32 _taskid) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); IexecLibCore_v5.Task memory task = $.m_tasks[_taskid]; IexecLibCore_v5.Deal memory deal = $.m_deals[task.dealid]; @@ -515,7 +515,7 @@ contract IexecPoco2Facet is IexecPoco2, FacetBase, IexecEscrow, SignatureVerifie * Callback for smartcontracts using EIP1154 */ function executeCallback(bytes32 _taskid, bytes memory _resultsCallback) internal { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 e5a41e88f..9b7231a4a 100644 --- a/contracts/facets/IexecPocoAccessorsFacet.sol +++ b/contracts/facets/IexecPocoAccessorsFacet.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; -import {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; +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"; @@ -30,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) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_deals[id]; } @@ -39,7 +39,7 @@ contract IexecPocoAccessorsFacet is * @param id id of the task */ function viewTask(bytes32 id) external view returns (IexecLibCore_v5.Task memory) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_tasks[id]; } diff --git a/contracts/facets/IexecPocoBoostAccessorsFacet.sol b/contracts/facets/IexecPocoBoostAccessorsFacet.sol index 8ae101b5f..d5253803a 100644 --- a/contracts/facets/IexecPocoBoostAccessorsFacet.sol +++ b/contracts/facets/IexecPocoBoostAccessorsFacet.sol @@ -6,7 +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 {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; /** * @title Getters contract for PoCo Boost facet. @@ -20,7 +20,7 @@ contract IexecPocoBoostAccessorsFacet is IexecPocoBoostAccessors, FacetBase { function viewDealBoost( bytes32 id ) external view returns (IexecLibCore_v5.DealBoost memory deal) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_dealsBoost[id]; } } diff --git a/contracts/facets/IexecPocoBoostFacet.sol b/contracts/facets/IexecPocoBoostFacet.sol index 8e4d105f6..c5abca4e5 100644 --- a/contracts/facets/IexecPocoBoostFacet.sol +++ b/contracts/facets/IexecPocoBoostFacet.sol @@ -18,7 +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 {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; /** * @title PoCo Boost to reduce latency and increase throughput of deals. @@ -125,7 +125,7 @@ contract IexecPocoBoostFacet is IexecLibOrders_v5.RequestOrder calldata requestOrder, address sponsor ) private returns (bytes32) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); // Check orders compatibility // Ensure the trust level is within the acceptable range. @@ -381,7 +381,7 @@ contract IexecPocoBoostFacet is address enclaveChallenge, bytes calldata enclaveSign ) external { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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)); @@ -495,7 +495,7 @@ contract IexecPocoBoostFacet is * @param index The index of the task. */ function claimBoost(bytes32 dealId, uint256 index) external { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 c19e05aa0..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 {LibPocoStorage} from "../libs/LibPocoStorage.v8.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) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 74c844936..00dbd9c46 100644 --- a/contracts/facets/SignatureVerifier.sol +++ b/contracts/facets/SignatureVerifier.sol @@ -7,7 +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 {LibPocoStorage} from "../libs/LibPocoStorage.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; import "./FacetBase.sol"; contract SignatureVerifier is FacetBase { @@ -96,7 +96,7 @@ contract SignatureVerifier is FacetBase { } function _checkPresignature(address _identity, bytes32 _hash) internal view returns (bool) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.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 0659873a3..4f8a9bda1 100644 --- a/contracts/facets/SignatureVerifier.v8.sol +++ b/contracts/facets/SignatureVerifier.v8.sol @@ -8,7 +8,7 @@ import {ECDSA} from "@openzeppelin/contracts-v5/utils/cryptography/ECDSA.sol"; import {MessageHashUtils} from "@openzeppelin/contracts-v5/utils/cryptography/MessageHashUtils.sol"; import {FacetBase} from "./FacetBase.v8.sol"; import {IERC734} from "../external/interfaces/IERC734.sol"; -import {LibPocoStorage} from "../libs/LibPocoStorage.v8.sol"; +import {PocoStorageLib} from "../libs/PocoStorageLib.v8.sol"; contract SignatureVerifier is FacetBase { using ECDSA for bytes32; @@ -18,7 +18,7 @@ contract SignatureVerifier is FacetBase { * @param structHash The original structure hash. */ function _toTypedDataHash(bytes32 structHash) internal view returns (bytes32) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return MessageHashUtils.toTypedDataHash($.m_eip712DomainSeparator, structHash); } @@ -91,7 +91,7 @@ contract SignatureVerifier is FacetBase { address account, bytes32 messageHash ) internal view returns (bool) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return account != address(0) && account == $.m_presigned[messageHash]; } diff --git a/contracts/libs/LibPocoStorage.sol b/contracts/libs/PocoStorageLib.sol similarity index 99% rename from contracts/libs/LibPocoStorage.sol rename to contracts/libs/PocoStorageLib.sol index 7e03fe173..8091578dd 100644 --- a/contracts/libs/LibPocoStorage.sol +++ b/contracts/libs/PocoStorageLib.sol @@ -24,7 +24,7 @@ import "./../registries/IRegistry.sol"; * * ****************************************************************************/ -library LibPocoStorage { +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/libs/LibPocoStorage.v8.sol b/contracts/libs/PocoStorageLib.v8.sol similarity index 99% rename from contracts/libs/LibPocoStorage.v8.sol rename to contracts/libs/PocoStorageLib.v8.sol index ec3558dda..c9785ced8 100644 --- a/contracts/libs/LibPocoStorage.v8.sol +++ b/contracts/libs/PocoStorageLib.v8.sol @@ -19,7 +19,7 @@ import {IexecLibCore_v5} from "./IexecLibCore_v5.sol"; * * ****************************************************************************/ -library LibPocoStorage { +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/tools/testing/IexecEscrowTestContract.sol b/contracts/tools/testing/IexecEscrowTestContract.sol index 05e0fae9c..9fce2bf49 100644 --- a/contracts/tools/testing/IexecEscrowTestContract.sol +++ b/contracts/tools/testing/IexecEscrowTestContract.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {IexecEscrow} from "../../facets/IexecEscrow.v8.sol"; -import {LibPocoStorage} from "../../libs/LibPocoStorage.v8.sol"; +import {PocoStorageLib} from "../../libs/PocoStorageLib.v8.sol"; /** * @notice a wrapper contract to make internal functions of @@ -30,7 +30,7 @@ contract IexecEscrowTestContract is IexecEscrow { // Helper functions used in unit tests. function setBalance(address account, uint256 value) external { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); $.m_balances[account] = value; } @@ -38,12 +38,12 @@ contract IexecEscrowTestContract is IexecEscrow { // when it is migrated to solidity v8. function balanceOf(address account) external view returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_balances[account]; } function frozenOf(address account) external view returns (uint256) { - LibPocoStorage.PocoStorage storage $ = LibPocoStorage.getPocoStorage(); + PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); return $.m_frozens[account]; } }