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

Feat/zap #344

Open
wants to merge 75 commits into
base: master
Choose a base branch
from
Open

Feat/zap #344

wants to merge 75 commits into from

Conversation

0xhafa
Copy link
Contributor

@0xhafa 0xhafa commented Aug 18, 2022

PR Review:

Zapper contracts
Zapper tests

Copy link

@NouDaimon NouDaimon left a comment

Choose a reason for hiding this comment

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

I only reviewed the contracts. Upgradeability is a must.

contracts/protocol/zap/DataTypes.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/EIP712.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/IOptyFiZapper.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/OptyFiZapper.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/OptyFiZapper.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/OptyFiZapper.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/OptyFiZapper.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/OptyFiZapper.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/OptyFiZapper.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/OptyFiZapper.sol Outdated Show resolved Hide resolved
import { DataTypes as SwapTypes } from "../optyfi-swapper/contracts/swap/DataTypes.sol";
import { DataTypes } from "./DataTypes.sol";

interface IVault {

Choose a reason for hiding this comment

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

I just realized this can simply be imported from earn-protocol and should simply be imported as opposed to recreated.

contracts/protocol/zap/ZapInternal.sol Outdated Show resolved Hide resolved
contracts/utils/EIP712.sol Outdated Show resolved Hide resolved
* @param _spender address of the spender
* @param _amount transfer amount
*/
function _approveTokenIfNeeded(

Choose a reason for hiding this comment

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

I do not think it is good practice to approve for uint256.max because if a vulnerability is found which can exploit this, the approval is a big issue.

In this context it may not matter, although I would avoid doing it even here.

@dhruvinparikh @mariogutval thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is to reduce gas consumption. As the Zap contract doesn't hold tokens, I think it's not a problem to give max allowance.

contracts/protocol/zap/DataTypes.sol Outdated Show resolved Hide resolved
contracts/protocol/zap/OptyFiZapper.sol Outdated Show resolved Hide resolved
Copy link

@NouDaimon NouDaimon left a comment

Choose a reason for hiding this comment

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

Readability in test cases is paramount - this is the point where other developers can ensure code functions correctly. It will also reduce the time others spend understanding the tests.

Separate each testing point of the functions into separate tests.

Additionally, if its necessary for permit to be mixed into zapOut explain why. It should work without permit as well, so that should be tested too.

if (_token != ETH) {
_permit(_token, _permitParams);
IERC20(_token).safeTransferFrom(msg.sender, address(this), _amount);
_approveTokenIfNeeded(_token, swapper.tokenTransferProxy(), _amount);

Choose a reason for hiding this comment

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

I understand your point. I prefer to avoid doing this. Have added tags for Dhruvin + Mario to weigh in.

address(this),
_amount,
_zapParams.accountsProof,
_zapParams.codesProof

Choose a reason for hiding this comment

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

This should be set in, and read from, storage.

The codesProof is for the OptyFiZapper so this contract can hold it.

It needs a permissioned setter function, and a getter.

spec/OptyFiZapper.behaviour.ts Outdated Show resolved Hide resolved
spec/OptyFiZapper.behaviour.ts Outdated Show resolved Hide resolved
spec/OptyFiZapper.behaviour.ts Outdated Show resolved Hide resolved
expect(await vault.totalSupply()).to.eq(_previousVaultBalance.add(expectedReturns[1]));
expect(await vault.totalDeposits(maker.address)).to.eq(_previousBalance.add(expectedReturns[1]));
// the vault shares VT will be same as total supply is zero
expect(await vault.balanceOf(maker.address)).to.eq(_previousBalance.add(expectedReturns[1]));

Choose a reason for hiding this comment

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

Are you testing locally on HH or using a forked mainnet?

If the former, please change so you use the latter - this will simulate the real life situation more accurately.

spec/OptyFiZapper.behaviour.ts Outdated Show resolved Hide resolved
spec/OptyFiZapper.behaviour.ts Outdated Show resolved Hide resolved
spec/OptyFiZapper.behaviour.ts Outdated Show resolved Hide resolved
);
// await vaultToken.connect(maker).approve(instance.address, usdcZapOutAmount);
//zap UNI -> opUSDCgrow
await expect(

Choose a reason for hiding this comment

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

Are there no relevant events emitted?

@0xhafa
Copy link
Contributor Author

0xhafa commented Sep 23, 2022

@dhruvinparikh
Copy link
Collaborator

  • Zap need not be upgradeable
  • implement eip 2771 - opengsn

Base automatically changed from feat/harvest to master October 6, 2022 23:39
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