Skip to content

Commit

Permalink
patch: fix capital efficiency test and increase EPSILON to 1000
Browse files Browse the repository at this point in the history
  • Loading branch information
kinrezC committed Apr 11, 2024
1 parent 5b1b5df commit 3582603
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/CoveredCall/CoveredCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ contract CoveredCall is PairStrategy {
int256 computedInvariant =
tradingFunction(pool.reserves, computedL, params);

if (computedInvariant <= 0 && computedInvariant <= EPSILON) {
console2.log("Computed Invariant: {}", computedInvariant);

if (computedInvariant < 0 || computedInvariant > EPSILON) {
revert InvalidComputedLiquidity(computedInvariant);
}

Expand Down
10 changes: 5 additions & 5 deletions src/CoveredCall/CoveredCallMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using FixedPointMathLib for uint256;
using FixedPointMathLib for int256;
using SignedWadMathLib for int256;

uint256 constant MAX_ITER = 128;
uint256 constant MAX_ITER = 256;
uint256 constant YEAR = 31_536_000;

function computeTradingFunction(
Expand Down Expand Up @@ -393,7 +393,7 @@ function computeNextRx(
int256 computedInvariant = invariant;
if (computedInvariant < 0) {
while (computedInvariant < 0) {
upper = upper.mulDivUp(101, 100);
upper = upper.mulDivUp(1001, 1000);
upper = upper > L ? L : upper;
computedInvariant = computeTradingFunction({
rX: upper,
Expand All @@ -404,7 +404,7 @@ function computeNextRx(
}
} else {
while (computedInvariant > 0) {
lower = lower.mulDivDown(99, 100);
lower = lower.mulDivDown(999, 1000);
lower = lower > L ? L : lower;
computedInvariant = computeTradingFunction({
rX: lower,
Expand Down Expand Up @@ -440,7 +440,7 @@ function computeNextRy(
int256 computedInvariant = invariant;
if (computedInvariant < 0) {
while (computedInvariant < 0) {
upper = upper.mulDivUp(101, 100);
upper = upper.mulDivUp(1001, 1000);
computedInvariant = computeTradingFunction({
rX: rX,
rY: upper,
Expand All @@ -450,7 +450,7 @@ function computeNextRy(
}
} else {
while (computedInvariant > 0) {
lower = lower.mulDivDown(99, 100);
lower = lower.mulDivDown(999, 1000);
computedInvariant = computeTradingFunction({
rX: rX,
rY: lower,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/StrategyLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.13;

import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol";

int256 constant EPSILON = 30;
int256 constant EPSILON = 1000;
uint256 constant HALF = 0.5e18;
uint256 constant ONE = 1e18;
uint256 constant TWO = 2e18;
Expand Down

0 comments on commit 3582603

Please sign in to comment.