Skip to content

Commit

Permalink
fix: calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Oct 2, 2024
1 parent 3f512e4 commit 3656207
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions flow/FlowUtilities.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity >=0.8.22;
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { ud21x18, UD21x18 } from "@prb/math/src/UD21x18.sol";

/// @dev A utility library to calculate the rate per second for a given amount of tokens for a specific duration, and
/// the amounts streamed over a various periods of time.
/// @dev A utility library to calculate the rate per second for a given amount of tokens over a specific duration, and
/// the amounts streamed over various periods of time.
library FlowUtilities {
/// @notice This function calculates the rate per second for a given amount of tokens for a specific duration.
/// @dev The rate per second is a 18 decimal fixed-point number and it is calculated as `amount / duration`.
Expand Down Expand Up @@ -76,22 +76,22 @@ library FlowUtilities {
/// @param ratePerSecond The rate per second as a fixed-point number.
/// @return amountPerWeek The amount streamed over a week.
function calculateAmountStreamedPerWeek(UD21x18 ratePerSecond) internal pure returns (uint128 amountPerWeek) {
amountPerWeek = uint128(ratePerSecond.unwrap() / 1 weeks);
amountPerWeek = ratePerSecond.unwrap() * 1 weeks;
}

/// @notice This function calculates the amount streamed over a month for a given rate per second.
/// @dev We use 30 days as the number of days in a month.
/// @param ratePerSecond The rate per second as a fixed-point number.
/// @return amountPerMonth The amount streamed over a month.
function calculateAmountStreamedPerMonth(UD21x18 ratePerSecond) internal pure returns (uint128 amountPerMonth) {
amountPerMonth = uint128(ratePerSecond.unwrap() / 30 days);
amountPerMonth = ratePerSecond.unwrap() * 30 days;
}

/// @notice This function calculates the amount streamed over a year for a given rate per second.
/// @dev We use 365 days as the number of days in a year.
/// @param ratePerSecond The rate per second as a fixed-point number.
/// @return amountPerYear The amount streamed over a year.
function calculateAmountStreamedPerYear(UD21x18 ratePerSecond) internal pure returns (uint128 amountPerYear) {
amountPerYear = uint128(ratePerSecond.unwrap() / 365 days);
amountPerYear = ratePerSecond.unwrap() * 365 days;
}
}

0 comments on commit 3656207

Please sign in to comment.