Skip to content

Commit

Permalink
expand list of invariable monitor tokens. incl sop token
Browse files Browse the repository at this point in the history
  • Loading branch information
funderbrker committed Apr 22, 2024
1 parent 993bcdd commit b31768c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions protocol/contracts/beanstalk/Invariable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract contract Invariable {
*/
modifier fundsSafu() {
_;
address[] memory tokens = LibWhitelistedTokens.getSiloTokens();
address[] memory tokens = getTokensOfInterest();
(
uint256[] memory entitlements,
uint256[] memory balances
Expand All @@ -51,12 +51,11 @@ abstract contract Invariable {
/// @dev Attempt to minimize effect on stack depth.
modifier noNetFlow() {
uint256 initialStalk = LibAppStorage.diamondStorage().s.stalk;
address[] memory tokens = LibWhitelistedTokens.getSiloTokens();
address[] memory tokens = getTokensOfInterest();
uint256[] memory initialProtocolTokenBalances = getTokenBalances(tokens);

_;

uint256[] memory finalProtocolTokenBalances = getTokenBalances(tokens);

require(LibAppStorage.diamondStorage().s.stalk >= initialStalk, "INV: Stalk decreased");
for (uint256 i; i < tokens.length; i++) {
require(
Expand All @@ -76,6 +75,21 @@ abstract contract Invariable {
require(C.bean().totalSupply() == initialSupply, "INV: Supply changed");
}


function getTokensOfInterest() internal view returns (address[] memory tokens) {
address[] memory whitelistedTokens = LibWhitelistedTokens.getWhitelistedTokens();
address sopToken = address(LibSilo.getSopToken());
if (sopToken == address(0)) {
tokens = new address[](whitelistedTokens.length);
} else {
tokens = new address[](whitelistedTokens.length + 1);
tokens[tokens.length - 1] = sopToken;
}
for (uint256 i; i < whitelistedTokens.length; i++) {
tokens[i] = whitelistedTokens[i];
}
}

function getTokenBalances(
address[] memory tokens
) internal view returns (uint256[] memory balances) {
Expand Down Expand Up @@ -108,6 +122,9 @@ abstract contract Invariable {
s.fertilizedIndex.sub(s.fertilizedPaidIndex) + // unrinsed rinsable beans
s.u[C.UNRIPE_BEAN].balanceOfUnderlying; // unchopped underlying beans
}
if (s.sopWell != address(0) && tokens[i] == address(LibSilo.getSopToken())) {
entitlements[i] += s.plenty;

This comment has been minimized.

Copy link
@Brean0

Brean0 Apr 27, 2024

Contributor

@pizzaman1337 will need to update this to support general flood.

}
// NOTE: Asset entitlements too low due to a lack of accounting for internal balances. Balances need init.
balances[i] = IERC20(tokens[i]).balanceOf(address(this));
}
Expand Down

0 comments on commit b31768c

Please sign in to comment.