Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding back concentration ratio #12

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
* @param repoToken The address of the repoToken to be simulated
* @param amount The amount of the repoToken to be simulated
* @return simulatedWeightedMaturity The simulated weighted time to maturity for the entire strategy
* @return simulatedRepoTokenConcentrationRatio The concentration ratio of the repoToken in the strategy (in 1e18 precision)
* @return simulatedLiquidityRatio The simulated liquidity ratio after the transaction
*
* @dev This function simulates the effects of a potential transaction on the strategy's key metrics.
Expand All @@ -348,6 +349,7 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
uint256 amount
) external view returns (
uint256 simulatedWeightedMaturity,
uint256 simulatedRepoTokenConcentrationRatio,
uint256 simulatedLiquidityRatio
) {
// do not validate if we are simulating with existing repoTokens
Expand Down Expand Up @@ -383,6 +385,15 @@ contract Strategy is BaseStrategy, Pausable, ReentrancyGuard {
simulatedWeightedMaturity = _calculateWeightedMaturity(
repoToken, amount, liquidBalance - proceeds);

if (repoToken != address(0)) {
simulatedRepoTokenConcentrationRatio = _getRepoTokenConcentrationRatio(
repoToken,
repoTokenAmountInBaseAssetPrecision,
_totalAssetValue(liquidBalance),
proceeds
);
}

simulatedLiquidityRatio = _liquidReserveRatio(liquidBalance - proceeds);
}

Expand Down
18 changes: 9 additions & 9 deletions src/test/TestUSDCSellRepoToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract TestUSDCSellRepoToken is Setup {
assertEq(termStrategy.totalLiquidBalance(), initialState.totalLiquidBalance - expectedProceeds);
assertEq(termStrategy.totalAssetValue(), initialState.totalAssetValue);

(uint256 weightedTimeToMaturity, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 weightedTimeToMaturity, ,) = termStrategy.simulateTransaction(address(0), 0);

(uint256 redemptionTimestamp, , ,) = ITermRepoToken(repoToken1Week).config();

Expand Down Expand Up @@ -253,47 +253,47 @@ contract TestUSDCSellRepoToken is Setup {
function testSellMultipleRepoTokens_7_14_28_3_9_3() public {
_sell3RepoTokens(repoToken1Week, 3e18, repoToken2Week, 9e18, repoToken4Week, 3e18);
_sell3RepoTokensCheckHoldings();
(uint256 weightedTimeToMaturity, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 weightedTimeToMaturity, ,) = termStrategy.simulateTransaction(address(0), 0);
assertEq(weightedTimeToMaturity, 1330560);
}

// 14 days (9), 7 days (3), 28 days (3)
function testSellMultipleRepoTokens_14_7_28_9_3_3() public {
_sell3RepoTokens(repoToken2Week, 9e18, repoToken1Week, 3e18, repoToken4Week, 3e18);
_sell3RepoTokensCheckHoldings();
(uint256 weightedTimeToMaturity, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 weightedTimeToMaturity, ,) = termStrategy.simulateTransaction(address(0), 0);
assertEq(weightedTimeToMaturity, 1330560);
}

// 28 days (3), 14 days (9), 7 days (3)
function testSellMultipleRepoTokens_28_14_7_3_9_3() public {
_sell3RepoTokens(repoToken4Week, 3e18, repoToken2Week, 9e18, repoToken1Week, 3e18);
_sell3RepoTokensCheckHoldings();
(uint256 weightedTimeToMaturity, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 weightedTimeToMaturity, ,) = termStrategy.simulateTransaction(address(0), 0);
assertEq(weightedTimeToMaturity, 1330560);
}

// 28 days (3), 7 days (3), 14 days (9)
function testSellMultipleRepoTokens_28_7_14_3_3_9() public {
_sell3RepoTokens(repoToken4Week, 3e18, repoToken1Week, 3e18, repoToken2Week, 9e18);
_sell3RepoTokensCheckHoldings();
(uint256 weightedTimeToMaturity, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 weightedTimeToMaturity, ,) = termStrategy.simulateTransaction(address(0), 0);
assertEq(weightedTimeToMaturity, 1330560);
}

// 7 days (6), 14 days (2), 28 days (8)
function testSellMultipleRepoTokens_7_14_28_6_2_8() public {
_sell3RepoTokens(repoToken1Week, 6e18, repoToken2Week, 2e18, repoToken4Week, 8e18);
_sell3RepoTokensCheckHoldings();
(uint256 weightedTimeToMaturity, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 weightedTimeToMaturity, ,) = termStrategy.simulateTransaction(address(0), 0);
assertEq(weightedTimeToMaturity, 1587600);
}

// 7 days (8), 14 days (1), 28 days (3)
function testSellMultipleRepoTokens_7_14_28_8_1_3() public {
_sell3RepoTokens(repoToken1Week, 8e18, repoToken2Week, 1e18, repoToken4Week, 3e18);
_sell3RepoTokensCheckHoldings();
(uint256 weightedTimeToMaturity, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 weightedTimeToMaturity, ,) = termStrategy.simulateTransaction(address(0), 0);
assertEq(weightedTimeToMaturity, 1108800);
}

Expand All @@ -312,7 +312,7 @@ contract TestUSDCSellRepoToken is Setup {
repoToken4WeekAuction, address(repoToken4Week), idHash, bytes32("test price"), 3e6
);

(uint256 weightedTimeToMaturity, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 weightedTimeToMaturity, ,) = termStrategy.simulateTransaction(address(0), 0);

assertEq(weightedTimeToMaturity, 1108800);
}
Expand Down Expand Up @@ -402,7 +402,7 @@ contract TestUSDCSellRepoToken is Setup {
function testAboveMaturityThresholdFailure() public {
_sell1RepoToken(repoToken2Week, 2e18);

(uint256 timeToMat, ) = termStrategy.simulateTransaction(address(0), 0);
(uint256 timeToMat, ,) = termStrategy.simulateTransaction(address(0), 0);

vm.prank(management);
termStrategy.setTimeToMaturityThreshold(timeToMat);
Expand Down
Loading