Skip to content

Conversation

Exef
Copy link

@Exef Exef commented Sep 24, 2025

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

Enter Leverage Flow with ERC20 operations (2)

Exit Leveraged Position

Exit Leverage Flow with ERC20 operations (1)

Checklist

  • I have updated the documentation to account for the changes in the code.
  • If I added new functionality, I added tests covering it.
  • If I fixed a bug, I added a test preventing this bug from silently reappearing again.
  • My contribution follows Venus contribution guidelines.

@Exef Exef self-assigned this Sep 24, 2025
@Exef Exef marked this pull request as draft September 24, 2025 10:13
Comment on lines +169 to +171
function executeOperation(
IVToken[] calldata assets,
uint256[] calldata amounts,

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) {

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);

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);

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?

Comment on lines +292 to +293
function _performSwap(IERC20Upgradeable tokenIn, uint256 amountIn, bytes calldata param) internal {
tokenIn.transfer(address(swapHelper), amountIn);

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.

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.

2 participants