Skip to content

Commit

Permalink
Add back getLockedBeansfromTwaReserves
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkatsios committed Aug 15, 2024
1 parent b1c3d01 commit a77e024
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions protocol/contracts/beanstalk/barn/UnripeFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,21 @@ contract UnripeFacet is Invariable, ReentrancyGuard {
return LibUnripe.getLockedBeansFromLP(twaReserves);
}

/**
* @notice Returns the locked beans given the cumulative reserves and timestamp.
*/
function getLockedBeansFromTwaReserves(
bytes memory cumulativeReserves,
uint40 timestamp
) external view returns (uint256) {
uint256[] memory twaReserves = LibWell.getTwaReservesFromPump(
LibBarnRaise.getBarnRaiseWell(),
cumulativeReserves,
timestamp
);
return LibUnripe.getLockedBeans(twaReserves);
}

/**
* @notice returns the amount of dollars recapitalized in the barn raise.
*/
Expand Down
23 changes: 23 additions & 0 deletions protocol/contracts/libraries/Well/LibWell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,29 @@ library LibWell {
}
}

/**
* @notice returns the twa reserves for well,
* given the cumulative reserves and timestamp.
* @dev wrapped in a try/catch to return gracefully.
*/
function getTwaReservesFromPump(
address well,
bytes memory cumulativeReserves,
uint40 timestamp
) internal view returns (uint256[] memory) {
Call[] memory pump = IWell(well).pumps();
try ICumulativePump(pump[0].target).readTwaReserves(
well,
cumulativeReserves,
timestamp,
pump[0].data
) returns (uint[] memory twaReserves, bytes memory) {
return twaReserves;
} catch {
return (new uint256[](2));
}
}

/**
* @notice gets the TwaLiquidity of a given well.
* @dev only supports wells that are whitelisted in beanstalk.
Expand Down

0 comments on commit a77e024

Please sign in to comment.