From b8dcc2252b1704fc8269156f0e00ecd0fc37f541 Mon Sep 17 00:00:00 2001 From: sirius Date: Tue, 27 Feb 2024 09:34:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20remove=20member=20finance?= =?UTF-8?q?=20statistics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #305 --- src/v0.8/core/finance/Finance.sol | 5 +- .../statistics/MemberFinanceStatistics.sol | 128 ------------------ src/v0.8/interfaces/core/IFinance.sol | 3 +- .../statistics/IMemberFinanceStatistics.sol | 50 ------- src/v0.8/types/StatisticsType.sol | 12 -- 5 files changed, 3 insertions(+), 195 deletions(-) delete mode 100644 src/v0.8/core/statistics/MemberFinanceStatistics.sol delete mode 100644 src/v0.8/interfaces/core/statistics/IMemberFinanceStatistics.sol diff --git a/src/v0.8/core/finance/Finance.sol b/src/v0.8/core/finance/Finance.sol index f6a13a1f..8ee9bf3c 100644 --- a/src/v0.8/core/finance/Finance.sol +++ b/src/v0.8/core/finance/Finance.sol @@ -39,7 +39,6 @@ import {FinanceAccountLIB} from "src/v0.8/core/finance/library/FinanceAccountLIB import {FinanceModifiers} from "src/v0.8/shared/modifiers/FinanceModifiers.sol"; import {BusinessFinanceStatistics} from "src/v0.8/core/statistics/BusinessFinanceStatistics.sol"; -import {MemberFinanceStatistics} from "src/v0.8/core/statistics/MemberFinanceStatistics.sol"; /// @title Finance /// @dev Base finance contract, holds funds designated for a payee until they withdraw them. @@ -49,20 +48,20 @@ contract Finance is RolesModifiers, FinanceModifiers, BusinessFinanceStatistics, - MemberFinanceStatistics, IFinance { using FinanceAccountLIB for FinanceType.Account; mapping(uint256 => mapping(uint256 => mapping(address => mapping(address => FinanceType.Account)))) private financeAccount; // mapping(datasetId => mapping(matchingId => mapping(sc/sp/da/dp => mapping(tokentype=>Account)))); + IRoles public roles; /// @dev This empty reserved space is put in place to allow future versions to add new uint256[32] private __gap; /// @notice Initialize function to initialize the contract and grant the default admin role to the deployer. function initialize(address _roles) public initializer { + roles = IRoles(_roles); businessFinanceStatisticsInitialize(); - memberFinanceStatisticsInitialize(_roles); __UUPSUpgradeable_init(); } diff --git a/src/v0.8/core/statistics/MemberFinanceStatistics.sol b/src/v0.8/core/statistics/MemberFinanceStatistics.sol deleted file mode 100644 index fc34e7fa..00000000 --- a/src/v0.8/core/statistics/MemberFinanceStatistics.sol +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * (c) 2024 dataswap - * - * Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0 - * (the "Apache License"). You may not use this file except in compliance with one of these - * licenses. You may obtain a copy of the MIT License at - * - * https://opensource.org/licenses/MIT - * - * Or the Apache License, Version 2.0 at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the MIT License or the Apache License for the specific language governing permissions and - * limitations under the respective licenses. - ********************************************************************************/ - -// SPDX-License-Identifier: GPL-3.0-or-later -pragma solidity ^0.8.21; -import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import {IMemberFinanceStatistics} from "src/v0.8/interfaces/core/statistics/IMemberFinanceStatistics.sol"; -import {StatisticsType} from "src/v0.8/types/StatisticsType.sol"; -import {IRoles} from "src/v0.8/interfaces/core/IRoles.sol"; -import {RolesModifiers} from "src/v0.8/shared/modifiers/RolesModifiers.sol"; - -abstract contract MemberFinanceStatistics is - Initializable, - IMemberFinanceStatistics, - RolesModifiers -{ - mapping(address => StatisticsType.FinanceStatistics) - private membersStatistics; - - address[] private members; - IRoles roles; - /// @dev This empty reserved space is put in place to allow future versions to add new - uint256[32] private __gap; - - function memberFinanceStatisticsInitialize( - address _roles - ) public virtual onlyInitializing { - roles = IRoles(_roles); - } - - /// @notice Inserts a member into the system. - /// @param _datasetId The ID of the dataset. - /// @param _matchingId The ID of the matching process. - /// @param _token The type of token for the account overview (e.g., FIL, ERC-20). - /// @param _member The address of the member to insert. - function _insertMemberAcount( - uint64 _datasetId, - uint64 _matchingId, - address _token, - address _member - ) internal { - StatisticsType.FinanceStatistics - storage memberStatistics = membersStatistics[_member]; - if (!memberStatistics.records[_datasetId][_matchingId][_token]) { - memberStatistics.records[_datasetId][_matchingId][_token] = true; - memberStatistics.statistics.push( - StatisticsType.MemberFinanceStatistics( - _datasetId, - _matchingId, - _token - ) - ); - } - } - - /// @notice Retrieves all members registered in the system. - /// @return _members An array containing the addresses of all registered members. - function getAllAccounts() - external - view - returns (address[] memory _members) - { - return members; - } - - /// @notice Retrieves the overview of an member's financial state. - /// @param _member The address of the member to retrieve the overview for. - /// @param _token The type of token used for the deposit (e.g., FIL, ERC-20). - /// @return total The total balance of the member. - /// @return available The available balance of the member. - /// @return escrow The escrow balance of the member. - /// @return locked The locked balance of the member. - function getAccountOverview( - address _member, - address _token - ) - external - view - returns ( - uint256 total, - uint256 available, - uint256 escrow, - uint256 locked - ) - { - for ( - uint64 i = 0; - i < membersStatistics[_member].statistics.length; - i++ - ) { - ( - , - , - , - uint256 _balance, - uint256 _available, - uint256 _locks, - uint256 _escrows - ) = roles.finance().getAccountOverview( - membersStatistics[_member].statistics[i].datasetId, - membersStatistics[_member].statistics[i].matchingId, - _member, - _token - ); - total += _balance; - available += _available; - escrow += _escrows; - locked += _locks; - } - } -} diff --git a/src/v0.8/interfaces/core/IFinance.sol b/src/v0.8/interfaces/core/IFinance.sol index bf850f6a..ac60f696 100644 --- a/src/v0.8/interfaces/core/IFinance.sol +++ b/src/v0.8/interfaces/core/IFinance.sol @@ -23,14 +23,13 @@ pragma solidity ^0.8.21; import {FinanceType} from "src/v0.8/types/FinanceType.sol"; import {IBusinessFinanceStatistics} from "src/v0.8/interfaces/core/statistics/IBusinessFinanceStatistics.sol"; -import {IMemberFinanceStatistics} from "src/v0.8/interfaces/core/statistics/IMemberFinanceStatistics.sol"; /// @title IPayment Interface /// @notice This interface defines the payment-related functions within the system. /// @notice instance example,type: mapping(uint256 => mapping(uint256 => mapping(address => mapping(address=>Account)))); /// explain: mapping(datasetId => mapping(matchingId => mapping(sc/sp/da/dp => mapping(tokentype=>Account)))); /// If matchingId is set to 0, it indicates the dataset phase. -interface IFinance is IBusinessFinanceStatistics, IMemberFinanceStatistics { +interface IFinance is IBusinessFinanceStatistics { /// @dev Records the deposited amount for a given dataset and matching ID. /// @param _datasetId The ID of the dataset. /// @param _matchingId The ID of the matching process. diff --git a/src/v0.8/interfaces/core/statistics/IMemberFinanceStatistics.sol b/src/v0.8/interfaces/core/statistics/IMemberFinanceStatistics.sol deleted file mode 100644 index 9b6149ca..00000000 --- a/src/v0.8/interfaces/core/statistics/IMemberFinanceStatistics.sol +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * (c) 2024 dataswap - * - * Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0 - * (the "Apache License"). You may not use this file except in compliance with one of these - * licenses. You may obtain a copy of the MIT License at - * - * https://opensource.org/licenses/MIT - * - * Or the Apache License, Version 2.0 at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the MIT License or the Apache License for the specific language governing permissions and - * limitations under the respective licenses. - ********************************************************************************/ - -// SPDX-License-Identifier: GPL-3.0-or-later -pragma solidity ^0.8.21; - -import {StatisticsType} from "src/v0.8/types/StatisticsType.sol"; - -interface IMemberFinanceStatistics { - /// @notice Retrieves all members registered in the system. - /// @return _members An array containing the addresses of all registered members. - function getAllAccounts() external view returns (address[] memory _members); - - /// @notice Retrieves the overview of an member's financial state. - /// @param _member The address of the member to retrieve the overview for. - /// @param _token The type of token used for the deposit (e.g., FIL, ERC-20). - /// @return total The total balance of the member. - /// @return available The available balance of the member. - /// @return escrow The escrow balance of the member. - /// @return locked The locked balance of the member. - function getAccountOverview( - address _member, - address _token - ) - external - view - returns ( - uint256 total, - uint256 available, - uint256 escrow, - uint256 locked - ); -} diff --git a/src/v0.8/types/StatisticsType.sol b/src/v0.8/types/StatisticsType.sol index 39490424..c66bdb37 100644 --- a/src/v0.8/types/StatisticsType.sol +++ b/src/v0.8/types/StatisticsType.sol @@ -80,16 +80,4 @@ library StatisticsType { Burn, // Burn funds Payment // payment funds } - - struct MemberFinanceStatistics { - uint64 datasetId; - uint64 matchingId; - address token; - } - - struct FinanceStatistics { - // mapping(member => mapping(datasetId => mapping(matchingId => mapping(tokentype=>exist)))); - mapping(uint64 => mapping(uint64 => mapping(address => bool))) records; - MemberFinanceStatistics[] statistics; - } }