Skip to content

Commit

Permalink
Merge pull request #78 from stakedotlink/fix-vault-gas-usage
Browse files Browse the repository at this point in the history
Only read non empty community vaults
  • Loading branch information
BkChoy authored Jan 16, 2024
2 parents bd9fda7 + b4eba3d commit 2a71ca4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions contracts/linkStaking/CommunityVCS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ contract CommunityVCS is VaultControllerStrategy {
return balanceAfter - balanceBefore;
}

/**
* @notice returns the deposit change since deposits were last updated
* @dev deposit change could be positive or negative depending on reward rate and whether
* any slashing occurred
* @return deposit change
*/
function getDepositChange() public view override returns (int) {
uint256 totalBalance = token.balanceOf(address(this));
for (uint256 i = 0; i < vaults.length; ++i) {
uint256 vaultDeposits = vaults[i].getTotalDeposits();
if (vaultDeposits == 0) break;
totalBalance += vaultDeposits;
}
return int(totalBalance) - int(totalDeposits);
}

/**
* @notice returns the maximum that can be deposited into this strategy
* @return maximum deposits
Expand Down
2 changes: 1 addition & 1 deletion contracts/linkStaking/base/VaultControllerStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ abstract contract VaultControllerStrategy is Strategy {
* any slashing occurred
* @return deposit change
*/
function getDepositChange() public view returns (int) {
function getDepositChange() public view virtual returns (int) {
uint256 totalBalance = token.balanceOf(address(this));
for (uint256 i = 0; i < vaults.length; ++i) {
totalBalance += vaults[i].getTotalDeposits();
Expand Down

0 comments on commit 2a71ca4

Please sign in to comment.