LeverageStrategiesManager
LeverageStrategiesManager
Section titled “LeverageStrategiesManager”The LeverageStrategiesManager is a Venus periphery contract that enables users to enter and exit leveraged positions atomically using flash loans. It integrates with the Venus Comptroller’s flash loan functionality and the SwapHelper contract to execute complex leverage operations in a single transaction.
Version scope: This API reference follows
venus-peripheryv1.2.0. The deployed manager is an upgradeable proxy whose implementation fixes the Comptroller, SwapHelper, and unsupported vBNB address. Verify the current proxy implementation and dependencies before approving tokens or delegation.
Overview
Section titled “Overview”Leverage operations in DeFi typically require multiple transactions: borrowing, swapping, and supplying assets. The LeverageStrategiesManager consolidates these into atomic operations using flash loans, eliminating intermediate exposure and reducing gas costs.
The contract supports five distinct leverage strategies:
| Strategy | Description | Swap Required |
|---|---|---|
enterSingleAssetLeverage | Amplify exposure to a single asset | No |
enterLeverage | Enter leverage with collateral seed, borrow different asset | Yes |
enterLeverageFromBorrow | Enter leverage using borrowed asset as seed | Yes |
exitSingleAssetLeverage | Close single-asset leveraged position | No |
exitLeverage | Close cross-asset leveraged position | Yes |
Prerequisites
Section titled “Prerequisites”Before using the LeverageStrategiesManager, users must delegate account actions to the exact manager proxy for their network:
// On the Venus Comptrollercomptroller.updateDelegate(leverageStrategiesManagerAddress, true);This delegation allows the contract to:
- Borrow on behalf of the user
- Mint vTokens on behalf of the user
- Redeem vTokens on behalf of the user
- Repay borrows on behalf of the user
Obtain leverageStrategiesManagerAddress from Deployed Contracts, not from an implementation address or the SwapHelper address. The delegation remains enabled until the user revokes it with updateDelegate(leverageStrategiesManagerAddress, false).
Inheritance
Section titled “Inheritance”Ownable2StepUpgradeable- Two-step ownership transfer patternReentrancyGuardUpgradeable- Reentrancy protectionIFlashLoanReceiver- Flash loan callback interfaceILeverageStrategiesManager- Contract interface
Immutable State Variables
Section titled “Immutable State Variables”| Variable | Type | Description |
|---|---|---|
COMPTROLLER | IComptroller | Venus Comptroller for market interactions and flash loan execution |
swapHelper | SwapHelper | Token swap executor for cross-asset operations |
vBNB | IVToken | vBNB market address (not supported for leverage operations) |
Architecture
Section titled “Architecture”
Transient Storage (EIP-1153)
Section titled “Transient Storage (EIP-1153)”The contract uses EIP-1153 transient storage to pass state between entry functions and flash loan callbacks. These values are automatically cleared at transaction end:
| Variable | Type | Description |
|---|---|---|
operationType | OperationType | Current operation being executed |
operationInitiator | address | Original msg.sender of the entry function |
collateralMarket | IVToken | Target collateral market |
collateralAmount | uint256 | Collateral seed or redeem amount |
borrowedAmountSeed | uint256 | User-provided borrowed asset seed |
minAmountOutAfterSwap | uint256 | Slippage protection threshold |
Solidity API
Section titled “Solidity API”initialize
Section titled “initialize”Initializes two-step ownership and reentrancy protection on the manager proxy.
function initialize() external initializerThe implementation constructor fixes the Comptroller, SwapHelper, and vBNB addresses and disables initialization on the implementation. Verify that the deployed proxy has already been initialized.
enterSingleAssetLeverage
Section titled “enterSingleAssetLeverage”Enters a leveraged position using the same asset for collateral and borrowing. No swap is required.
function enterSingleAssetLeverage( IVToken _collateralMarket, uint256 _collateralAmountSeed, uint256 _collateralAmountToFlashLoan) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| _collateralMarket | IVToken | The vToken market to use for both collateral and borrowing |
| _collateralAmountSeed | uint256 | Amount of underlying tokens the user provides as initial capital |
| _collateralAmountToFlashLoan | uint256 | Amount to flash loan for leverage amplification |
Example
Section titled “Example”User has 10 ETH and wants 2x exposure:
- Provide 10 ETH as seed
- Flash loan 10 ETH
- Supply 20 ETH as collateral
- Final: 20 ETH collateral, 10 ETH debt (plus fees)
Events
Section titled “Events”SingleAssetLeverageEnteredemitted on successDustTransferredemitted if residual tokens remain
Access Requirements
Section titled “Access Requirements”- User must have delegated to this contract via
Comptroller.updateDelegate
Errors
Section titled “Errors”ZeroFlashLoanAmountif_collateralAmountToFlashLoanis zeroMarketNotListedif market is not listed in ComptrollerVBNBNotSupportedif the market is vBNBNotAnApprovedDelegateif user has not delegated to this contractAccrueInterestFailedif interest accrual fails on the marketEnterMarketFailedif entering the market failsOperationCausesLiquidationif pre/post position is unsafe
enterLeverage
Section titled “enterLeverage”Enters a leveraged position by providing collateral seed and borrowing a different asset. The borrowed asset is swapped to collateral.
function enterLeverage( IVToken _collateralMarket, uint256 _collateralAmountSeed, IVToken _borrowedMarket, uint256 _borrowedAmountToFlashLoan, uint256 _minAmountOutAfterSwap, bytes calldata _swapData) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| _collateralMarket | IVToken | The vToken market to supply collateral to |
| _collateralAmountSeed | uint256 | Amount of collateral underlying the user provides |
| _borrowedMarket | IVToken | The vToken market to borrow from |
| _borrowedAmountToFlashLoan | uint256 | Amount of borrowed asset to flash loan |
| _minAmountOutAfterSwap | uint256 | Minimum collateral tokens expected from swap (slippage protection) |
| _swapData | bytes | Encoded swap data from Venus Swap API |
Example
Section titled “Example”User has 1,000 USDC and wants 3x USDC exposure:
- Provide 1,000 USDC as collateral seed
- Flash loan 2,000 USDT
- Swap 2,000 USDT → ~2,000 USDC
- Supply 3,000 USDC as collateral
- Final: 3,000 USDC collateral, 2,000 USDT debt (plus fees)
Events
Section titled “Events”LeverageEnteredemitted on successDustTransferredemitted for residual collateral and borrowed tokens
Access Requirements
Section titled “Access Requirements”- User must have delegated to this contract via
Comptroller.updateDelegate
Errors
Section titled “Errors”ZeroFlashLoanAmountif_borrowedAmountToFlashLoanis zeroIdenticalMarketsif collateral and borrowed markets are the sameMarketNotListedif either market is not listed in ComptrollerVBNBNotSupportedif either market is vBNBNotAnApprovedDelegateif user has not delegated to this contractAccrueInterestFailedif interest accrual fails on either marketEnterMarketFailedif entering either market failsSlippageExceededif swap output is below_minAmountOutAfterSwapTokenSwapCallFailedif swap execution revertsOperationCausesLiquidationif position becomes unsafe
enterLeverageFromBorrow
Section titled “enterLeverageFromBorrow”Enters a leveraged position by providing the borrowed asset as seed. Both seed and flash loan are swapped to collateral.
function enterLeverageFromBorrow( IVToken _collateralMarket, IVToken _borrowedMarket, uint256 _borrowedAmountSeed, uint256 _borrowedAmountToFlashLoan, uint256 _minAmountOutAfterSwap, bytes calldata _swapData) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| _collateralMarket | IVToken | The vToken market to supply collateral to |
| _borrowedMarket | IVToken | The vToken market providing the seed and flash loan |
| _borrowedAmountSeed | uint256 | Amount of borrowed asset the user provides as seed |
| _borrowedAmountToFlashLoan | uint256 | Amount of borrowed asset to flash loan |
| _minAmountOutAfterSwap | uint256 | Minimum collateral tokens expected from swap |
| _swapData | bytes | Encoded swap data (must account for seed + flash loan amount) |
Example
Section titled “Example”User has 1 ETH and wants leveraged USDC exposure:
- Provide 1 ETH as seed
- Flash loan 2 ETH
- Swap 3 ETH → ~6,000 USDC
- Supply 6,000 USDC as collateral
- Final: 6,000 USDC collateral, 2 ETH debt (plus fees)
Events
Section titled “Events”LeverageEnteredFromBorrowemitted on successDustTransferredemitted for residual tokens
Access Requirements
Section titled “Access Requirements”- User must have delegated to this contract
Errors
Section titled “Errors”ZeroFlashLoanAmountif_borrowedAmountToFlashLoanis zeroMarketNotListedif either market is not listed in ComptrollerVBNBNotSupportedif either market is vBNBNotAnApprovedDelegateif user has not delegated to this contractAccrueInterestFailedif interest accrual fails on either marketEnterMarketFailedif entering either market failsSlippageExceededif swap output is below_minAmountOutAfterSwapTokenSwapCallFailedif swap execution revertsOperationCausesLiquidationif position becomes unsafe
exitSingleAssetLeverage
Section titled “exitSingleAssetLeverage”Closes or reduces a single-asset leveraged position. Flash loans the asset to repay debt, then redeems collateral to cover the flash loan.
function exitSingleAssetLeverage( IVToken _collateralMarket, uint256 _collateralAmountToFlashLoan) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| _collateralMarket | IVToken | The vToken market for both collateral and debt |
| _collateralAmountToFlashLoan | uint256 | Amount to flash loan for debt repayment |
Example
Section titled “Example”User has 20 ETH collateral and 10 ETH debt:
- Flash loan 10 ETH
- Repay 10 ETH debt
- Redeem ~10 ETH (plus fees) from collateral
- Final: ~10 ETH collateral, 0 debt
Events
Section titled “Events”SingleAssetLeverageExitedemitted on successDustTransferredemitted for residual tokens
Access Requirements
Section titled “Access Requirements”- User must have delegated to this contract
Errors
Section titled “Errors”ZeroFlashLoanAmountif flash loan amount is zeroMarketNotListedif market is not listed in ComptrollerVBNBNotSupportedif the market is vBNBNotAnApprovedDelegateif user has not delegated to this contractAccrueInterestFailedif interest accrual fails on the marketInsufficientFundsToRepayFlashloanif redemption insufficient for repaymentOperationCausesLiquidationif final position is unsafe
exitLeverage
Section titled “exitLeverage”Closes or reduces a cross-asset leveraged position. Flash loans borrowed asset to repay debt, redeems collateral, and swaps to cover the flash loan.
function exitLeverage( IVToken _collateralMarket, uint256 _collateralAmountToRedeemForSwap, IVToken _borrowedMarket, uint256 _borrowedAmountToFlashLoan, uint256 _minAmountOutAfterSwap, bytes calldata _swapData) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| _collateralMarket | IVToken | The vToken market holding user’s collateral |
| _collateralAmountToRedeemForSwap | uint256 | Amount of collateral to redeem and swap |
| _borrowedMarket | IVToken | The vToken market where user has debt |
| _borrowedAmountToFlashLoan | uint256 | Amount to flash loan for debt repayment |
| _minAmountOutAfterSwap | uint256 | Minimum borrowed tokens expected from swap |
| _swapData | bytes | Encoded swap data |
Example
Section titled “Example”User has 3,000 USDC collateral and 1 ETH debt:
- Flash loan 1 ETH
- Repay 1 ETH debt
- Redeem 2,000 USDC from collateral
- Swap 2,000 USDC → ~1 ETH (plus fees)
- Final: ~1,000 USDC collateral, 0 ETH debt
Events
Section titled “Events”LeverageExitedemitted on successDustTransferredemitted for residual tokens
Access Requirements
Section titled “Access Requirements”- User must have delegated to this contract
Errors
Section titled “Errors”ZeroFlashLoanAmountif flash loan amount is zeroIdenticalMarketsif collateral and borrowed markets are the sameMarketNotListedif either market is not listed in ComptrollerVBNBNotSupportedif either market is vBNBNotAnApprovedDelegateif user has not delegated to this contractAccrueInterestFailedif interest accrual fails on either marketSlippageExceededif swap output is below minimumInsufficientFundsToRepayFlashloanif swap output insufficient for repaymentOperationCausesLiquidationif final position is unsafe
executeOperation
Section titled “executeOperation”Flash loan callback invoked by the Comptroller. Routes execution to the appropriate handler based on operationType.
function executeOperation( IVToken[] calldata vTokens, uint256[] calldata amounts, uint256[] calldata premiums, address initiator, address onBehalf, bytes calldata param) external override nonReentrant returns (bool success, uint256[] memory repayAmounts)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| vTokens | IVToken[] | Array with the borrowed vToken market (single element) |
| amounts | uint256[] | Array with the borrowed underlying amount (single element) |
| premiums | uint256[] | Array with the flash loan fee amount (single element) |
| initiator | address | Address that initiated the flash loan (must be this contract) |
| onBehalf | address | User for whom debt will be opened |
| param | bytes | Encoded auxiliary data for the operation |
Access Requirements
Section titled “Access Requirements”- Only callable by the Comptroller
Errors
Section titled “Errors”UnauthorizedExecutorif caller is not ComptrollerInitiatorMismatchif initiator is not this contractOnBehalfMismatchif onBehalf does not match operationInitiatorFlashLoanAssetOrAmountMismatchif arrays length is not 1InvalidExecuteOperationif operation type is unknown
sweepToken
Section titled “sweepToken”Transfers the manager’s full balance of an ERC-20 token to its current owner. This is a recovery function, not a user refund path.
function sweepToken(address token) external onlyOwner nonReentrantAccess Requirements
Section titled “Access Requirements”- Current contract owner only
Security Considerations
Section titled “Security Considerations”- The call transfers the entire token balance and has no protected-token list or lifecycle condition. Integrations should avoid leaving balances on the manager and should verify the live proxy owner before relying on recovery.
Events
Section titled “Events”| Event | Parameters | Description |
|---|---|---|
SingleAssetLeverageEntered | user, collateralMarket, collateralAmountSeed, collateralAmountToFlashLoan | Single-asset leverage position opened |
LeverageEntered | user, collateralMarket, collateralAmountSeed, borrowedMarket, borrowedAmountToFlashLoan | Cross-asset leverage position opened with collateral seed |
LeverageEnteredFromBorrow | user, collateralMarket, borrowedMarket, borrowedAmountSeed, borrowedAmountToFlashLoan | Cross-asset leverage position opened with borrowed seed |
LeverageExited | user, collateralMarket, collateralAmountToRedeemForSwap, borrowedMarket, borrowedAmountToFlashLoan | Cross-asset leverage position closed |
SingleAssetLeverageExited | user, collateralMarket, collateralAmountToFlashLoan | Single-asset leverage position closed |
DustTransferred | recipient, token, amount | Residual tokens transferred after operation |
TokensSwept | token, recipient, amount | Owner recovered the manager’s full token balance |
Security Considerations
Section titled “Security Considerations”Access Control
Section titled “Access Control”- Delegate Requirement: All operations verify the user has delegated to this contract via
Comptroller.updateDelegate() - Flash Loan Callback:
executeOperationvalidatesmsg.senderis the Comptroller - Initiator Validation: Callback verifies
initiator == address(this)to prevent unauthorized triggers - OnBehalf Validation: Callback verifies
onBehalf == operationInitiatorfor user consistency
Reentrancy Protection
Section titled “Reentrancy Protection”The executeOperation function is protected by OpenZeppelin’s nonReentrant modifier, preventing reentrant calls during flash loan callback execution.
Slippage Protection
Section titled “Slippage Protection”All swap operations accept a minAmountOutAfterSwap parameter. The transaction reverts with SlippageExceeded if the swap output falls below this threshold.
Account Safety
Section titled “Account Safety”- Enter operations perform pre-checks to ensure the user is not already at liquidation risk
- All operations perform post-checks to verify the final position is healthy
- Exit operations skip the initial liquidity pre-check because they begin by reducing debt, but they also redeem collateral to settle the flash loan. The contract therefore still performs a final account-liquidity check; an exit is not assumed safe solely because debt decreased.
Dust Handling
Section titled “Dust Handling”After every operation, any residual token balances are transferred back to the user:
- Collateral dust → User
- Borrowed dust (all operations) → User
Deployment
Section titled “Deployment”See Deployed Contracts for current addresses.
Integration
Section titled “Integration”For Users
Section titled “For Users”- Enable Delegation: Resolve the network’s manager proxy from Deployed Contracts, then call
Comptroller.updateDelegate(leverageStrategiesManagerAddress, true) - Approve Tokens: Grant token spending approval to LeverageStrategiesManager for collateral tokens
- Execute Operations: Call the appropriate entry function with parameters
- Revoke When Finished: Call
Comptroller.updateDelegate(leverageStrategiesManagerAddress, false)when the manager no longer needs to act for the account
For Developers
Section titled “For Developers”LeverageStrategiesManager exposes a clear interface for integration:
interface ILeverageStrategiesManager { function enterSingleAssetLeverage( IVToken _collateralMarket, uint256 _collateralAmountSeed, uint256 _collateralAmountToFlashLoan ) external;
function enterLeverage( IVToken _collateralMarket, uint256 _collateralAmountSeed, IVToken _borrowedMarket, uint256 _borrowedAmountToFlashLoan, uint256 _minAmountOutAfterSwap, bytes calldata _swapData ) external;
function exitSingleAssetLeverage( IVToken _collateralMarket, uint256 _collateralAmountToFlashLoan ) external;
function exitLeverage( IVToken _collateralMarket, uint256 _collateralAmountToRedeemForSwap, IVToken _borrowedMarket, uint256 _borrowedAmountToFlashLoan, uint256 _minAmountOutAfterSwap, bytes calldata _swapData ) external;}Swap API Integration
Section titled “Swap API Integration”Cross-asset operations (enterLeverage, enterLeverageFromBorrow, exitLeverage) require signed swap data from the Venus Swap API:
- Request a swap quote from the API with source and destination tokens
- Receive encoded
multicallparameters with backend signature - Pass the signed
_swapDatato the entry function
Audits
Section titled “Audits”Published LeverageStrategiesManager audit reports are indexed in the venus-periphery v1.2.0 release. Check each report’s scope and reviewed commit against the current proxy implementation.