Skip to content

Commit

Permalink
remove unoptimized functions from the model
Browse files Browse the repository at this point in the history
  • Loading branch information
pysel committed Nov 28, 2024
1 parent 204134d commit 7b2f366
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions src/ClvrModel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ contract ClvrModel {
o[i2] = temp;
}

// CONTRACT: note in TradeMinimal implemented!
function P(ClvrHook.SwapParamsExtended[] memory o, uint256 i) public view returns (uint256) {
uint256 base = 1e18;
return Y(o, i) * base / X(o, i);
}

function set_reserve_x(uint256 reserve_x) internal {
reserveX = reserve_x;
}
Expand All @@ -135,44 +129,6 @@ contract ClvrModel {

// INTERNAL FUNCTIONS

function y_out(ClvrHook.SwapParamsExtended[] memory o, uint256 i) private view returns (uint256) {
if (direction(o[i]) == Direction.Sell) {
uint256 fraction = Y(o, i - 1) / (X(o, i - 1) + amountIn(o[i]));
return fraction * amountIn(o[i]);
}
return 0;
}

function x_out(ClvrHook.SwapParamsExtended[] memory o, uint256 i) private view returns (uint256) {
if (direction(o[i]) == Direction.Buy) {
uint256 fraction = X(o, i - 1) / (Y(o, i - 1) + amountIn(o[i]));
return fraction * amountIn(o[i]);
}
return 0;
}

function Y(ClvrHook.SwapParamsExtended[] memory o, uint256 i) private view returns (uint256) {
if (i == 0) {
return reserveY;
} else if (i > 0 && direction(o[i]) == Direction.Buy) {
return Y(o, i - 1) + amountIn(o[i]);
} else if (i > 0 && direction(o[i]) == Direction.Sell) {
return Y(o, i - 1) - y_out(o, i);
}
revert("Invalid call to Y");
}

function X(ClvrHook.SwapParamsExtended[] memory o, uint256 i) private view returns (uint256) {
if (i == 0) {
return reserveX;
} else if (i > 0 && direction(o[i]) == Direction.Sell) {
return X(o, i - 1) + amountIn(o[i]);
} else if (i > 0 && direction(o[i]) == Direction.Buy) {
return X(o, i - 1) - x_out(o, i);
}
revert("Invalid call to X");
}

function y_out_cached(ClvrHook.SwapParamsExtended[] memory o, uint256 i, uint256 cachedY, uint256 cachedX) private pure returns (uint256) {
if (direction(o[i]) == Direction.Sell) {
uint256 fraction = cachedY / (cachedX + amountIn(o[i]));
Expand Down

0 comments on commit 7b2f366

Please sign in to comment.