Skip to content

Commit

Permalink
Expose calculateDeltaBFromReserves (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 committed Sep 18, 2024
2 parents 8cf8002 + 63024f1 commit 489ef5a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
15 changes: 15 additions & 0 deletions protocol/contracts/beanstalk/silo/ConvertGettersFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ contract ConvertGettersFacet {
return LibDeltaB.cappedReservesDeltaB(well);
}

/**
* @notice calculates the deltaB for a given well using the reserves.
* @dev reverts if the bean reserve is less than the minimum,
* or if the usd oracle fails.
* This differs from the twaDeltaB, as this function should not be used within the sunrise function.
* @return deltaB The deltaB using the reserves.
*/
function calculateDeltaBFromReserves(
address well,
uint256[] memory reserves,
uint256 lookback
) external view returns (int256) {
return LibDeltaB.calculateDeltaBFromReserves(well, reserves, lookback);
}

/**
* @notice Returns currently available convert power for this block
* @return convertCapacity The amount of convert power available for this block
Expand Down
2 changes: 1 addition & 1 deletion protocol/contracts/interfaces/IMockFBeanstalk.sol
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ interface IMockFBeanstalk {
uint256 outputTokenAmountInDirectionOfPeg
) external view returns (uint256 cumulativePenalty, PenaltyData memory pdCapacity);

function calculateDeltaBFromReservesE(
function calculateDeltaBFromReserves(
address well,
uint256[] memory reserves,
uint256 lookback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,4 @@ contract MockPipelineConvertFacet is PipelineConvertFacet {
outputTokenAmountInDirectionOfPeg
);
}

function calculateDeltaBFromReservesE(
address well,
uint256[] memory reserves,
uint256 lookback
) external view returns (int256) {
return LibDeltaB.calculateDeltaBFromReserves(well, reserves, lookback);
}
}
6 changes: 3 additions & 3 deletions protocol/test/foundry/farm/PipelineConvert.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ contract PipelineConvertTest is TestHelper {
reserves[beanIndex] = reserves[beanIndex].sub(beansOut);

// get new deltaB
deltaB = pipelineConvert.calculateDeltaBFromReservesE(well, reserves, 0);
deltaB = bs.calculateDeltaBFromReserves(well, reserves, 0);
}

function calculateDeltaBForWellAfterAddingBean(
Expand All @@ -1969,7 +1969,7 @@ contract PipelineConvertTest is TestHelper {
// add to bean index (no beans out on this one)
reserves[beanIndex] = reserves[beanIndex].add(beansIn);
// get new deltaB
deltaB = pipelineConvert.calculateDeltaBFromReservesE(well, reserves, 0);
deltaB = bs.calculateDeltaBFromReserves(well, reserves, 0);
}

function calculateDeltaBForWellAfterAddingNonBean(
Expand All @@ -1989,7 +1989,7 @@ contract PipelineConvertTest is TestHelper {
reserves[nonBeanIndex] = reserves[nonBeanIndex].add(amountIn);

// get new deltaB
deltaB = pipelineConvert.calculateDeltaBFromReservesE(well, reserves, 0);
deltaB = bs.calculateDeltaBFromReserves(well, reserves, 0);
}

// verifies there's no way to withdraw from a deposit without losing grown stalk
Expand Down

0 comments on commit 489ef5a

Please sign in to comment.