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

reduce SLOAD calls in _depositInVault #5

Merged
merged 1 commit into from
Jul 13, 2021
Merged

Conversation

kamescg
Copy link

@kamescg kamescg commented Jun 30, 2021

Comment on lines 171 to 172
IERC20Upgradeable _token = token;
if(_token.allowance(address(this), address(v)) < _token.balanceOf(address(this))) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some space

Suggested change
IERC20Upgradeable _token = token;
if(_token.allowance(address(this), address(v)) < _token.balanceOf(address(this))) {
IERC20Upgradeable _token = token;
if (_token.allowance(address(this), address(v)) < _token.balanceOf(address(this))) {

token.safeApprove(address(v), type(uint256).max);
IERC20Upgradeable _token = token;
if(_token.allowance(address(this), address(v)) < _token.balanceOf(address(this))) {
_token.safeApprove(address(v), type(uint256).max);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this in initialize, this way we wouldn't have to write all this if.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(maxLosses != 0) {
vault.withdraw(yShares, address(this), maxLosses);
uint256 _maxLosses = maxLosses;
if(_maxLosses != 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space

Suggested change
if(_maxLosses != 0) {
if (_maxLosses != 0) {

@PierrickGT
Copy link

PierrickGT commented Jun 30, 2021

As a side note that should be addressed in another PR, we don't need to initialize with token since we can retrieve the underlying token address with _vault.token().

Which would avoid us doing this check:

require(_vault.token() == address(_token), "YearnV2YieldSource:: incorrect vault");

Fixed in this PR: #8

@PierrickGT
Copy link

Not sure if it will lower gas consumption since token is an internal variable anyway?

token.safeApprove(address(v), type(uint256).max);
IERC20Upgradeable _token = token;
if(_token.allowance(address(this), address(v)) < _token.balanceOf(address(this))) {
_token.safeApprove(address(v), type(uint256).max);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PierrickGT PierrickGT merged commit a88e669 into fixes/c4-audit Jul 13, 2021
@PierrickGT PierrickGT deleted the fix/44 branch July 13, 2021 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants