Skip to content

Commit

Permalink
Delete DSMath lib
Browse files Browse the repository at this point in the history
Added private function _rpow to AbstractCompoundRateKeeper
  • Loading branch information
aritkulova committed Oct 23, 2023
1 parent dc6dff0 commit 68a882d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 115 deletions.
30 changes: 26 additions & 4 deletions contracts/compound-rate-keeper/AbstractCompoundRateKeeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

import {ICompoundRateKeeper} from "../interfaces/compound-rate-keeper/ICompoundRateKeeper.sol";

import {DSMath} from "../libs/math/DSMath.sol";

import {PRECISION} from "../utils/Globals.sol";

/**
Expand All @@ -24,7 +22,6 @@ import {PRECISION} from "../utils/Globals.sol";
*/
abstract contract AbstractCompoundRateKeeper is ICompoundRateKeeper, Initializable {
using Math for uint256;
using DSMath for uint256;

uint256 private _capitalizationRate;
uint64 private _capitalizationPeriod;
Expand Down Expand Up @@ -96,7 +93,8 @@ abstract contract AbstractCompoundRateKeeper is ICompoundRateKeeper, Initializab
uint256 rate_ = _currentRate;

if (capitalizationPeriodsNum_ != 0) {
uint256 capitalizationPeriodRate_ = capitalizationRate_.rpow(
uint256 capitalizationPeriodRate_ = _rpow(
capitalizationRate_,
capitalizationPeriodsNum_,
PRECISION
);
Expand Down Expand Up @@ -209,4 +207,28 @@ abstract contract AbstractCompoundRateKeeper is ICompoundRateKeeper, Initializab
function _getMaxRate() private pure returns (uint256) {
return type(uint128).max * PRECISION;
}

function _rpow(uint256 x_, uint256 n_, uint256 b_) private pure returns (uint256 z_) {
if (x_ == 0) {
if (n_ == 0) {
z_ = b_;
} else {
z_ = 0;
}
} else {
if (n_ % 2 == 0) {
z_ = b_;
} else {
z_ = x_;
}
uint256 half = b_ / 2; // for rounding

for (uint256 i = n_ / 2; i >= 1; i = i / 2) {
x_ = (x_ * x_ + half) / b_;
if (i % 2 == 1) {
z_ = (z_ * x_ + half) / b_;
}
}
}
}
}
60 changes: 0 additions & 60 deletions contracts/libs/math/DSMath.sol

This file was deleted.

10 changes: 0 additions & 10 deletions contracts/mock/libs/math/DSMathMock.sol

This file was deleted.

41 changes: 0 additions & 41 deletions test/libs/math/DSMath.test.ts

This file was deleted.

0 comments on commit 68a882d

Please sign in to comment.