Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/v0.8/core/statistics/StatisticsBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
50 changes: 50 additions & 0 deletions src/v0.8/shared/events/StatisticsEvents.sol
Original file line number Diff line number Diff line change
@@ -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
);
}