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

Expose calculateDeltaBFromReserves #1097

Merged
merged 1 commit into from
Sep 18, 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
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
Loading