Skip to content

Curve amm adapter #155

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

Closed
wants to merge 12 commits into from
Closed

Conversation

RedVeil
Copy link

@RedVeil RedVeil commented Oct 21, 2021

Code Review Processes

New Feature Review

Before submitting a pull request for new review, make sure the following is done:

  • Design doc is created and posted here: [Insert Link]
  • Code cleanliness and completeness is addressed via guidelines

README Checks

  • README has proper context for the reviewer to understand what the code includes, any important design considerations, and areas to pay more attention to

Code Checks

  • Add explanatory comments. If there is complex code that requires specific context or understanding, note that in a comment
  • Remove unncessary comments. Any comments that do not add additional context, information, etc. should be removed
  • [] Add javadocs. -- how do i do this?
  • Scrub through the code for inconsistencies (e.g. removing extra spaces)
  • Ensure there are not any .onlys in spec files

Broader Considerations

  • Ensure variable, function and event naming is clear, consistent, and reflective for the scope of the code.
  • Consider if certain pieces of logic should be placed in a different library, module

for (uint256 i = 0; i < 2; i++) {
if (underlying[i] == _token) return i;
}
revert("token not in pool");
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think we have coverage on this revert

Copy link
Contributor

Choose a reason for hiding this comment

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

Though this revert may not be necessary because of _isValidPool we know that the passed components exist in that Meta Pool otherwise Line 160 would resolve false

Copy link
Author

Choose a reason for hiding this comment

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

you are right, i deleted the revert

@@ -0,0 +1,9 @@
## Curve FactoryMetapool Amm Adapter
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great context, lets put it in the javadocs in the adapter contract and remove this markdown file. We like to keep all the context in the contract itself.

import { IMetaPoolZap } from "../../../interfaces/external/IMetaPoolZap.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract CurveFactoryMetapoolAmmAdapter is IAmmAdapter {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can add some of the javadocs and section headers you see here for consistency.

override
returns (address, uint256, bytes memory)
{
require(_isValidPool(_pool, _components), "invalid pool");
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need this because this check comes standard on the AmmModule, see here

Copy link
Author

Choose a reason for hiding this comment

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

true, deleted it

override
returns (address, uint256, bytes memory)
{
require(_isValidPool(_pool, _components), "invalid pool");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above, this check is duplicated

Copy link
Author

Choose a reason for hiding this comment

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

true, deleted it

address[2] memory expectedTokens = metapoolFactory.get_coins(_pool);

for (uint256 i = 0; i < _components.length; i++) {
if ((_components[i] == expectedTokens[0] || _components[i] == expectedTokens[1]) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can rewrite this as !(_components[i] == expectedTokens[0] || _components[i] == expectedTokens[1]) == false

Copy link
Contributor

Choose a reason for hiding this comment

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

I think Brian means:
!(_components[i] == expectedTokens[0] || _components[i] == expectedTokens[1])

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure do

address[2] memory expectedTokens = metapoolFactory.get_coins(_pool);

for (uint256 i = 0; i < _components.length; i++) {
if ((_components[i] == expectedTokens[0] || _components[i] == expectedTokens[1]) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to check that there are no duplicates in the _components array, right now this would pass if there was a duplicate that was one of the tokens in the AMM.

But since the AmmModule is not yet deployed I say we make that check in the AmmModule itself because I can't think of a scenario where an AMM would have "duplicate" components.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would add that check here using AddressArrayUtils.hasDuplicate which can be found in contracts/lib

using SafeCast for int256;

IMetapoolFactory public metapoolFactory;
address public constant THREE_CRV = address(0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would avoid hardcoding this.You can instead pass it to the constructor. This means it will work with other metapools by just doing a new deployment (such as the btc one).

Choose a reason for hiding this comment

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

I think this can be deleted actually because it's not used

Copy link
Author

Choose a reason for hiding this comment

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

yeah its not in use anymore

address[2] memory expectedTokens = metapoolFactory.get_coins(_pool);

for (uint256 i = 0; i < _components.length; i++) {
if ((_components[i] == expectedTokens[0] || _components[i] == expectedTokens[1]) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Brian means:
!(_components[i] == expectedTokens[0] || _components[i] == expectedTokens[1])

IMetapoolFactory public metapoolFactory;
address public constant THREE_CRV = address(0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490);

string public constant ADD_LIQUIDITY = "add_liquidity(uint256[2],uint256,address)";
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want to use the ITriPoolZap functions rather than the IMetaPoolZap ones. This function requires depositing a combination of the 3Pool token and the extra token. The ITriPoolZap interface lets you deposit any of the 3Pool's pools' underlying tokens and the extra token. Makes it a lot more usable.

Copy link

@anthonymartin anthonymartin Oct 21, 2021

Choose a reason for hiding this comment

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

@ncitron it turns out that this interface & adapter is specifically for the factory metapool and not the legacy metapools. Do you know if the TriPoolZap supports the factory metapools? we had issues with the TriPoolZap reverting without any reason string response, so we ended up switching focus to the factory metapool with the intention to revisit the Zap and legacy metapool implementation afterwards.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe they do. I had checked that it works on a whole list of pools. I think one of the gotchas on some of the different pools though is that the LP token address is different than the pool address though. I believe there is a contract for converting from LP token address to pool address and vice versa somewhere in the docs. I had previously confirmed that the zap contract works with the LUSD, alUSD, and USDN pools though (and IIRC alUSD is one of the legacy ones)

@cgewecke
Copy link
Contributor

Closed in favor of #253

@cgewecke cgewecke closed this May 18, 2022
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.

5 participants