mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Added comments
This commit is contained in:
parent
c86884ef28
commit
d8424d43a5
|
@ -6,8 +6,9 @@ import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol';
|
|||
/**
|
||||
* @title PercentageMath library
|
||||
* @author Aave
|
||||
* @notice Provides functions to calculate percentages. Percentages needs to be defined by default with 2 decimals of precision (100.00)
|
||||
* @dev Operations are rounded up
|
||||
* @notice Provides functions to calculate percentages.
|
||||
* @dev Percentages are defined by default with 2 decimals of precision (100.00). The precision is indicated by PERCENTAGE_FACTOR
|
||||
* @dev Operations are rounded half up
|
||||
**/
|
||||
|
||||
library PercentageMath {
|
||||
|
@ -16,13 +17,25 @@ library PercentageMath {
|
|||
uint256 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals
|
||||
uint256 constant HALF_PERCENT = PERCENTAGE_FACTOR / 2;
|
||||
|
||||
function percentMul(uint256 value, uint256 percentage) internal pure returns (uint256) {
|
||||
return HALF_PERCENT.add(value.mul(percentage)).div(PERCENTAGE_FACTOR);
|
||||
/**
|
||||
* @dev executes a percentage multiplication
|
||||
* @param _value the value of which the percentage needs to be calculated
|
||||
* @param _percentage the percentage of the value to be calculated
|
||||
* @return the _percentage of _value
|
||||
**/
|
||||
function percentMul(uint256 _value, uint256 _percentage) internal pure returns (uint256) {
|
||||
return HALF_PERCENT.add(_value.mul(_percentage)).div(PERCENTAGE_FACTOR);
|
||||
}
|
||||
|
||||
function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) {
|
||||
uint256 halfPercentage = percentage / 2;
|
||||
/**
|
||||
* @dev executes a percentage division
|
||||
* @param _value the value of which the percentage needs to be calculated
|
||||
* @param _percentage the percentage of the value to be calculated
|
||||
* @return the _value divided the _percentage
|
||||
**/
|
||||
function percentDiv(uint256 _value, uint256 _percentage) internal pure returns (uint256) {
|
||||
uint256 halfPercentage = _percentage / 2;
|
||||
|
||||
return halfPercentage.add(value.mul(PERCENTAGE_FACTOR)).div(percentage);
|
||||
return halfPercentage.add(_value.mul(PERCENTAGE_FACTOR)).div(_percentage);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user