diff --git a/src/v0.8/core/statistics/StatisticsBase.sol b/src/v0.8/core/statistics/StatisticsBase.sol index 21650f6d..312885d4 100644 --- a/src/v0.8/core/statistics/StatisticsBase.sol +++ b/src/v0.8/core/statistics/StatisticsBase.sol @@ -24,6 +24,7 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini import {IStatistics} from "src/v0.8/interfaces/core/statistics/IStatistics.sol"; import {StatisticsType} from "src/v0.8/types/StatisticsType.sol"; import {StatisticsLIB} from "src/v0.8/core/statistics/library/StatisticsLIB.sol"; +import {StatisticsEvents} from "src/v0.8/shared/events/StatisticsEvents.sol"; contract StatisticsBase is Initializable, IStatistics { using StatisticsLIB for StatisticsType.Statistics; @@ -41,36 +42,72 @@ contract StatisticsBase is Initializable, IStatistics { /// @param _size Size to be added to the total count. function _addCountTotal(uint256 _size) internal { count.addTotal(_size); + emit StatisticsEvents.CountStatistics( + uint64(block.number), + count.total, + count.success, + count.failed + ); } /// @notice Internal function to add to the total size in the statistics. /// @param _size Size to be added to the total size. function _addSizeTotal(uint256 _size) internal { size.addTotal(_size); + emit StatisticsEvents.SizeStatistics( + uint64(block.number), + count.total, + count.success, + count.failed + ); } /// @notice Internal function to add to the success count in the statistics. /// @param _size Size to be added to the success count. function _addCountSuccess(uint256 _size) internal { count.addSuccess(_size); + emit StatisticsEvents.CountStatistics( + uint64(block.number), + count.total, + count.success, + count.failed + ); } /// @notice Internal function to add to the success size in the statistics. /// @param _size Size to be added to the success size. function _addSizeSuccess(uint256 _size) internal { size.addSuccess(_size); + emit StatisticsEvents.SizeStatistics( + uint64(block.number), + count.total, + count.success, + count.failed + ); } /// @notice Internal function to add to the failed count in the statistics. /// @param _size Size to be added to the failed count. function _addCountFailed(uint256 _size) internal { count.addFailed(_size); + emit StatisticsEvents.CountStatistics( + uint64(block.number), + count.total, + count.success, + count.failed + ); } /// @notice Internal function to add to the failed size in the statistics. /// @param _size Size to be added to the failed size. function _addSizeFailed(uint256 _size) internal { size.addFailed(_size); + emit StatisticsEvents.SizeStatistics( + uint64(block.number), + count.total, + count.success, + count.failed + ); } /// @notice Internal view function to retrieve the total count. diff --git a/src/v0.8/shared/events/StatisticsEvents.sol b/src/v0.8/shared/events/StatisticsEvents.sol new file mode 100644 index 00000000..45296f3a --- /dev/null +++ b/src/v0.8/shared/events/StatisticsEvents.sol @@ -0,0 +1,50 @@ +/******************************************************************************* + * (c) 2023 Dataswap + * + * Licensed under the GNU General Public License, Version 3.0 or later (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/gpl-3.0.en.html + * + * 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 License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ + +// SPDX-License-Identifier: GPL-3.0-or-later +pragma solidity ^0.8.21; + +library StatisticsEvents { + /** + * @dev Event triggered to record count statistics. + * + * @param _height The height of the statistics. + * @param _total The total count. + * @param _success The count of successful operations. + * @param _failed The count of failed operations. + */ + event CountStatistics( + uint64 indexed _height, + uint256 _total, + uint256 _success, + uint256 _failed + ); + + /** + * @dev Event triggered to record size statistics. + * + * @param _height The height of the statistics. + * @param _total The total size. + * @param _success The size of successful operations. + * @param _failed The size of failed operations. + */ + event SizeStatistics( + uint64 indexed _height, + uint256 _total, + uint256 _success, + uint256 _failed + ); +}