-
Notifications
You must be signed in to change notification settings - Fork 0
[VPD-70] Leverage Manager contract #12
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
base: feat/swapper
Are you sure you want to change the base?
Conversation
function executeOperation( | ||
IVToken[] calldata assets, | ||
uint256[] calldata amounts, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should verify that the function is called exclusively by the authorized comptroller
. While the execution would eventually revert in the current flow, failing early improves gas efficiency and provides clearer error handling.
amountsToReturn[0] = amountToRepay; | ||
|
||
return (true, amountsToReturn); | ||
} else if(operationType == OperationType.EXIT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EXIT
operation path doesn't return immediately, creating inconsistent control flow.
return (false, new uint256[](0)); | ||
} | ||
|
||
return (true, amountsToReturn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return statement is unreachable for ENTER
operations. Standardize the control flow by either returning immediately in all the statements or using a single return at the end.
*/ | ||
function _executeEnterOperation(address initiator, IVToken borrowMarket, uint256 borrowedAssetAmount, uint256 borrowedAssetFees, bytes calldata swapCallData) internal returns (uint256 borrowedAssetAmountToRepay) { | ||
IERC20Upgradeable borrowedAsset = IERC20Upgradeable(borrowMarket.underlying()); | ||
_performSwap(borrowedAsset, borrowedAssetAmount, swapCallData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aren’t checking if the swap produces the collateral tokens
that we are expecting. What if the collateral balance is 0 or insufficient?
function _performSwap(IERC20Upgradeable tokenIn, uint256 amountIn, bytes calldata param) internal { | ||
tokenIn.transfer(address(swapHelper), amountIn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should include a reentrancy flag here.
Note
To run the tests use npm pack to pack the package (VenusProtocol/venus-protocol#545) and then import it in package.json file. Ex: "@venusprotocol/venus-protocol": "file:../venus-protocol/venusprotocol-venus-protocol-9.8.0-dev.21.tgz",
Description
Implements the LeverageStrategiesManager contract to be used in the following flows:
Enter Leveraged Position
Exit Leveraged Position
Checklist