Skip to content

Commit

Permalink
remove OZ dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdomrom committed May 28, 2024
1 parent c687464 commit d43ec45
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/openzeppelin/openzeppelin-contracts-upgradeable
branch = v5.0.2
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts-upgradeable
Submodule openzeppelin-contracts-upgradeable deleted from dd8ca8
1 change: 0 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
forge-std/=lib/forge-std/src/
openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
16 changes: 11 additions & 5 deletions src/math/SVI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import "src/decimals/SignedDecimalMath.sol";
import "src/decimals/DecimalMath.sol";
import "./FixedPointMathLib.sol";

import "openzeppelin-upgradeable/utils/math/SafeCastUpgradeable.sol";

/**
* @title SVI
* @author Lyra
Expand All @@ -18,8 +16,6 @@ library SVI {
using SignedDecimalMath for int;
using FixedPointMathLib for uint;
using FixedPointMathLib for int;
using SafeCastUpgradeable for int;
using SafeCastUpgradeable for uint;

error SVI_InvalidParameters();
error SVI_NoForwardPrice();
Expand Down Expand Up @@ -81,7 +77,7 @@ library SVI {
*/
function getK(uint strike, int a, uint b, uint sigma, uint forwardPrice) internal pure returns (int k) {
// calculate the bounds
int volFactor = int(FixedPointMathLib.sqrt((a + b.multiplyDecimal(sigma).toInt256()).toUint256()));
int volFactor = int(FixedPointMathLib.sqrt(toUintSafe(a + toIntSafe(b.multiplyDecimal(sigma)))));
int k_bound = volFactor.multiplyDecimal(TOTAL_VOL_SCALAR);
int sk = int(strike.divideDecimal(forwardPrice));

Expand All @@ -94,4 +90,14 @@ library SVI {
if (k > k_bound) return k_bound;
if (k < -k_bound) return -k_bound;
}

function toIntSafe(uint value) internal pure returns (int) {
if (int(value) < 0) revert("SVI: invalid uint cast");
return int(value);
}

function toUintSafe(int value) internal pure returns (uint) {
if (value < 0) revert("SVI: value must be positive");
return uint(value);
}
}
2 changes: 1 addition & 1 deletion test/math/SVI.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ contract SVITest is Test {
sigma: 0.000410958904109589e18,
forwardPrice: 1800e18
});
vm.expectRevert(bytes("SafeCast: value must be positive"));
vm.expectRevert(bytes("SVI: value must be positive"));
tester.getVol(1800e18, params);
}

Expand Down

0 comments on commit d43ec45

Please sign in to comment.