LeverageStrategiesManager
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.
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:
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
Before using the LeverageStrategiesManager, users must delegate borrowing rights to the contract:
// On the Venus Comptroller
comptroller.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
Inheritance
Ownable2StepUpgradeable- Two-step ownership transfer patternReentrancyGuardUpgradeable- Reentrancy protectionIFlashLoanReceiver- Flash loan callback interfaceILeverageStrategiesManager- Contract interface
Immutable State Variables
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
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:
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
enterSingleAssetLeverage
Enters a leveraged position using the same asset for collateral and borrowing. No swap is required.
Parameters
_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
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
SingleAssetLeverageEnteredemitted on successDustTransferredemitted if residual tokens remain
Access Requirements
User must have delegated to this contract via
Comptroller.updateDelegate
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
Enters a leveraged position by providing collateral seed and borrowing a different asset. The borrowed asset is swapped to collateral.
Parameters
_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
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
LeverageEnteredemitted on successDustTransferredemitted for residual collateral and borrowed tokens
Access Requirements
User must have delegated to this contract via
Comptroller.updateDelegate
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
Enters a leveraged position by providing the borrowed asset as seed. Both seed and flash loan are swapped to collateral.
Parameters
_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
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
LeverageEnteredFromBorrowemitted on successDustTransferredemitted for residual tokens
Access Requirements
User must have delegated to this contract
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
Closes or reduces a single-asset leveraged position. Flash loans the asset to repay debt, then redeems collateral to cover the flash loan.
Parameters
_collateralMarket
IVToken
The vToken market for both collateral and debt
_collateralAmountToFlashLoan
uint256
Amount to flash loan for debt repayment
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
SingleAssetLeverageExitedemitted on successDustTransferredemitted for residual tokens
Access Requirements
User must have delegated to this contract
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
Closes or reduces a cross-asset leveraged position. Flash loans borrowed asset to repay debt, redeems collateral, and swaps to cover the flash loan.
Parameters
_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
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
LeverageExitedemitted on successDustTransferredemitted for residual tokens
Access Requirements
User must have delegated to this contract
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
Flash loan callback invoked by the Comptroller. Routes execution to the appropriate handler based on operationType.
Parameters
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
Only callable by the Comptroller
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
Events
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
Security Considerations
Access Control
Delegate Requirement: All operations verify the user has delegated to this contract via
Comptroller.updateDelegate()Flash Loan Callback:
executeOperationvalidatesmsg.senderis the ComptrollerInitiator Validation: Callback verifies
initiator == address(this)to prevent unauthorized triggersOnBehalf Validation: Callback verifies
onBehalf == operationInitiatorfor user consistency
Reentrancy Protection
The executeOperation function is protected by OpenZeppelin's nonReentrant modifier, preventing reentrant calls during flash loan callback execution.
Slippage Protection
All swap operations accept a minAmountOutAfterSwap parameter. The transaction reverts with SlippageExceeded if the swap output falls below this threshold.
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 pre-checks since reducing debt can only improve health
Dust Handling
After every operation, any residual token balances are transferred back to the user:
Collateral dust → User
Borrowed dust (all operations) → User
Deployment
See Deployed Contracts for current addresses.
Integration
For Users
Enable Delegation: Call
Comptroller.updateDelegate(leverageStrategiesManagerAddress, true)to authorize the contractApprove Tokens: Grant token spending approval to LeverageStrategiesManager for collateral tokens
Execute Operations: Call the appropriate entry function with parameters
For Developers
LeverageStrategiesManager exposes a clear interface for integration:
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 signaturePass the signed
_swapDatato the entry function
Audits
LeverageStrategiesManager undergoes security audits before mainnet deployment. Audit reports are available in the venus-periphery repository.
Last updated

