RelativePositionManager
Venus Trade is a relative performance trading product built on Venus Protocol’s lending infrastructure. It allows users to express a view that one asset will outperform another, packaged into a single managed position with automated execution, proportional closing, and built-in yield generation.
For architecture details and implementation walkthrough, see the Trade Technical Article.
Version scope: This API reference follows
venus-peripheryv1.2.0. RelativePositionManager is an upgradeable proxy; PositionAccounts are deterministic EIP-1167 clones of the one-time configured implementation. Verify the current proxy implementation, locked PositionAccount implementation, ACM grants, DSA configuration, pause state, and manager dependencies before integrating.
Solidity API
Section titled “Solidity API”COMPTROLLER
Section titled “COMPTROLLER”The Venus comptroller contract
contract IComptroller COMPTROLLERLEVERAGE_MANAGER
Section titled “LEVERAGE_MANAGER”The leverage strategies manager contract
contract LeverageStrategiesManager LEVERAGE_MANAGERproportionalCloseTolerance
Section titled “proportionalCloseTolerance”Tolerance for proportional close (in basis points): 100 = 1% margin of error (governance-controlled)
uint256 proportionalCloseTolerancePOSITION_ACCOUNT_IMPLEMENTATION
Section titled “POSITION_ACCOUNT_IMPLEMENTATION”Implementation contract for PositionAccount clones (settable via governance, can only be set once)
address POSITION_ACCOUNT_IMPLEMENTATIONisPositionAccountImplementationLocked
Section titled “isPositionAccountImplementationLocked”Lock flag to prevent changing POSITION_ACCOUNT_IMPLEMENTATION after it’s set
bool isPositionAccountImplementationLockeddsaVTokenIndexCounter
Section titled “dsaVTokenIndexCounter”Counter / next index for newly added DSA vTokens (also equals current count)
uint8 dsaVTokenIndexCounterisPartiallyPaused
Section titled “isPartiallyPaused”Whether the contract is partially paused (blocks open, scale, withdraw, deactivate but allows close and supply)
bool isPartiallyPausedisCompletelyPaused
Section titled “isCompletelyPaused”Whether the contract is completely paused (blocks all state-changing user operations)
bool isCompletelyPauseddsaVTokens
Section titled “dsaVTokens”Mapping from DSA index to supported DSA (Default Settlement Asset) vToken markets
mapping(uint8 => address) dsaVTokensisDsaVTokenActive
Section titled “isDsaVTokenActive”Tracks whether a given DSA vToken is currently active for new activations
mapping(address => bool) isDsaVTokenActivepositions
Section titled “positions”Mapping from user => longAsset => shortAsset => Position data
mapping(address => mapping(address => mapping(address => struct IRelativePositionManager.Position))) positionsconstructor
Section titled “constructor”Contract constructor
constructor(address comptroller, address leverageManager) publicParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| comptroller | address | The Venus Comptroller contract address |
| leverageManager | address | The LeverageStrategiesManager contract address (provides swap helper for enter/exit leverage) |
initialize
Section titled “initialize”Initializes the upgradeable contract
function initialize(address accessControlManager_) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| accessControlManager_ | address | Address of the Access Control Manager contract |
partialPause
Section titled “partialPause”Partially pauses the manager — blocks risk-increasing operations (open, scale, withdraw, deactivate) while allowing defensive operations (close, supply principal).
function partialPause() externalAccess Requirements
Section titled “Access Requirements”- ACM permission required:
partialPause()
partialUnpause
Section titled “partialUnpause”Removes partial pause, re-enabling risk operations (unless completely paused).
function partialUnpause() externalAccess Requirements
Section titled “Access Requirements”- ACM permission required:
partialUnpause()
completePause
Section titled “completePause”Completely pauses all state-changing user operations on the manager
function completePause() externalAccess Requirements
Section titled “Access Requirements”- ACM permission required:
completePause()
completeUnpause
Section titled “completeUnpause”Removes complete pause, re-enabling all operations (unless partially paused).
function completeUnpause() externalAccess Requirements
Section titled “Access Requirements”- ACM permission required:
completeUnpause()
setPositionAccountImplementation
Section titled “setPositionAccountImplementation”Sets the implementation contract used for PositionAccount clones (can be set only once)
function setPositionAccountImplementation(address positionAccountImpl) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| positionAccountImpl | address | Implementation contract for PositionAccount EIP-1167 clones |
Access Requirements
Section titled “Access Requirements”- ACM permission required:
setPositionAccountImplementation(address) - The implementation can be set only once; existing and future clones then use that locked address
📅 Events
Section titled “📅 Events”- Emits PositionAccountImplementationSet event.
❌ Errors
Section titled “❌ Errors”- Throw ZeroAddress if positionAccountImpl is zero.
- Throw PositionAccountImplementationLocked if already set.
setProportionalCloseTolerance
Section titled “setProportionalCloseTolerance”Sets the proportional close tolerance (in basis points)
function setProportionalCloseTolerance(uint256 newTolerance) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| newTolerance | uint256 | New tolerance value in basis points |
Access Requirements
Section titled “Access Requirements”- ACM permission required:
setProportionalCloseTolerance(uint256)
📅 Events
Section titled “📅 Events”- Emits ProportionalCloseToleranceUpdated event.
❌ Errors
Section titled “❌ Errors”- Throw InvalidProportionalCloseTolerance if tolerance is outside
[1, 10000]. - Throw SameProportionalCloseTolerance if tolerance is unchanged.
addDSAVToken
Section titled “addDSAVToken”Adds a new DSA vToken to the supported list
function addDSAVToken(address dsaVToken) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| dsaVToken | address | The vToken market address to add as a supported DSA |
Access Requirements
Section titled “Access Requirements”- ACM permission required:
addDSAVToken(address)
📅 Events
Section titled “📅 Events”- Emits DSAVTokenAdded event.
❌ Errors
Section titled “❌ Errors”- Throw ZeroAddress if dsaVToken is zero.
- Throw AssetNotListed if the market is not listed in the Comptroller.
- Throw DSAVTokenAlreadyAdded if the DSA vToken is already configured.
setDSAVTokenActive
Section titled “setDSAVTokenActive”Updates the active flag for a configured DSA vToken, controlling whether it can be used for new activations
function setDSAVTokenActive(uint8 dsaIndex, bool active) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| dsaIndex | uint8 | Index of the DSA vToken in the internal mapping |
| active | bool | New active flag (true to allow new activations, false to block them) |
Access Requirements
Section titled “Access Requirements”- ACM permission required:
setDSAVTokenActive(uint8,bool)
📅 Events
Section titled “📅 Events”- Emits DSAVTokenActiveUpdated when the active flag is changed.
❌ Errors
Section titled “❌ Errors”- Throw InvalidDSA if the index or stored address is invalid.
- Throw SameDSAActiveStatus when called with the current active flag.
executePositionAccountCall
Section titled “executePositionAccountCall”Executes multiple generic calls from a position account for emergency or administrative actions.
function executePositionAccountCall(address positionAccount, address[] targets, bytes[] data) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| positionAccount | address | Address of the position account |
| targets | address[] | Array of target contract addresses |
| data | bytes[] | Array of encoded function call data |
Access Requirements
Section titled “Access Requirements”- ACM permission required:
executePositionAccountCall(address,address[],bytes[]) - The granted caller selects every target and calldata item. RelativePositionManager forwards them to the PositionAccount’s
genericCallsfunction without restricting the called contracts or selectors.
activateAndOpenPosition
Section titled “activateAndOpenPosition”Opens a leveraged position for the first time (combines activation + opening in one call)
function activateAndOpenPosition(address longVToken, address shortVToken, uint8 dsaIndex, uint256 initialPrincipal, uint256 effectiveLeverage, uint256 shortAmount, uint256 minLongAmount, bytes swapData) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | address | The vToken market address for the asset to long |
| shortVToken | address | The vToken market address for the asset to short |
| dsaIndex | uint8 | Index of the DSA vToken in the dsaVTokens array |
| initialPrincipal | uint256 | Required initial principal amount to supply during activation (must be > 0) |
| effectiveLeverage | uint256 | The target leverage ratio for this position (in mantissa, e.g., 2e18 = 2x leverage) |
| shortAmount | uint256 | Amount to borrow in shortAsset terms |
| minLongAmount | uint256 | Minimum amount of long asset expected from swap |
| swapData | bytes | Swap instructions for converting shortAsset to longAsset |
📅 Events
Section titled “📅 Events”- Emits PositionAccountDeployed (if new account), PositionActivated, PrincipalSupplied, and PositionOpened.
❌ Errors
Section titled “❌ Errors”- Throw InsufficientPrincipal if initialPrincipal is zero.
- Throw ZeroAddress if longVToken or shortVToken is zero.
- Throw SameMarketNotAllowed if long and short vTokens are identical.
- Throw AssetNotListed if a market is not listed.
- Throw InvalidDSA if dsaIndex is not Valid, or DSAInactive if the DSA is inactive.
- Throw InvalidLeverage if effectiveLeverage is out of range.
- Throw PositionAlreadyExists if the position is already active.
- Throw EnterMarketFailed if entering the DSA market on behalf fails.
- Throw MintBehalfFailed if minting initialPrincipal fails.
- Throw ZeroVTokensMinted if initialPrincipal rounds down to 0 vTokens due to exchange rate.
- Throw ZeroShortAmount if shortAmount is zero.
- Throw InvalidOraclePrice if pricing data is unavailable while computing borrow limits.
- Throw BorrowAmountExceedsMaximum if shortAmount exceeds max allowed borrow.
scalePosition
Section titled “scalePosition”Scales an existing position by adding additional leverage (borrow + swap to long)
function scalePosition(contract IVToken longVToken, contract IVToken shortVToken, uint256 additionalPrincipal, uint256 shortAmount, uint256 minLongAmount, bytes swapData) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | contract IVToken | The vToken market for the asset to long |
| shortVToken | contract IVToken | The vToken market for the asset to short |
| additionalPrincipal | uint256 | Additional principal to supply this call (0 if none) |
| shortAmount | uint256 | Amount to borrow in shortAsset terms (must not exceed max calculated borrow) |
| minLongAmount | uint256 | Minimum amount of long asset expected from swap (protects against slippage) |
| swapData | bytes | Swap instructions for converting shortAsset to longAsset |
📅 Events
Section titled “📅 Events”- Emits PositionScaled event (and PrincipalSupplied if additionalPrincipal > 0).
❌ Errors
Section titled “❌ Errors”- Throw ZeroShortAmount if shortAmount is zero.
- Throw PositionNotActive if the position is not active.
- Throw MintBehalfFailed if additionalPrincipal minting on behalf fails.
- Throw ZeroVTokensMinted if additionalPrincipal rounds down to 0 vTokens if Minted.
- Throw InvalidOraclePrice if pricing data is unavailable while computing borrow limits.
- Throw BorrowAmountExceedsMaximum if shortAmount exceeds max allowed borrow.
supplyPrincipal
Section titled “supplyPrincipal”Supplies additional principal to an active position
function supplyPrincipal(address longVToken, address shortVToken, uint256 amount) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | address | The vToken market address for the long asset |
| shortVToken | address | The vToken market address for the short asset |
| amount | uint256 | Amount of DSA underlying to supply (must be large enough to mint at least 1 vToken) |
📅 Events
Section titled “📅 Events”- Emits PrincipalSupplied event.
❌ Errors
Section titled “❌ Errors”- Throw ZeroAmount if amount is zero.
- Throw PositionNotActive if the position is not active.
- Throw MintBehalfFailed if minting supplied principal on behalf fails.
- Throw ZeroVTokensMinted if supplied amount rounds down to 0 vTokens Minted.
closeWithProfit
Section titled “closeWithProfit”Closes a position proportionally; can realize profit on the closed slice (partial or full). If treasuryPercent is enabled, the LM redeems more than the requested long amount on behalf of the position account to cover the fee; callers should reduce redeem amounts accordingly to avoid exceeding the available collateral bucket and causing a revert.
function closeWithProfit(contract IVToken longVToken, contract IVToken shortVToken, uint256 closeFractionBps, uint256 longAmountToRedeemForRepay, uint256 minAmountOutRepay, bytes swapDataRepay, uint256 longAmountToRedeemForProfit, uint256 minAmountOutProfit, bytes swapDataProfit) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
| closeFractionBps | uint256 | Proportion to close in basis points (10000 = 100%, 1 = 0.01% minimum) |
| longAmountToRedeemForRepay | uint256 | Amount of long to redeem for the repay leg (validated against BPS) |
| minAmountOutRepay | uint256 | Minimum short Amount expected from repay swap; must be >= required repay amount for the given BPS. Should Include flash-loan fees and (for 100% close) include internal tolerance buffer. |
| swapDataRepay | bytes | Swap #1: long → short for debt repayment |
| longAmountToRedeemForProfit | uint256 | Amount of long to redeem and swap long→DSA as profit (can be non-zero for partial or full close) |
| minAmountOutProfit | uint256 | Minimum DSA out from the profit swap used for slippage protection |
| swapDataProfit | bytes | Swap #2: long → DSA for profit realization |
📅 Events
Section titled “📅 Events”- Emits ProfitConverted event.
- Emits PositionClosed event. When DSA == Long, PositionClosed.longDustRedeemed is reclassified back as principal vTokens rather than transferred.
❌ Errors
Section titled “❌ Errors”- Throw PositionNotActive if the position is not active.
- Throw InvalidCloseFractionBps if closeFractionBps is not between 1 and 10000.
- Throw InvalidLongAmountToRedeem if total long to redeem is invalid for the chosen BPS.
- Throw MinAmountOutRepayBelowDebt if minAmountOutRepay is below the calculated short debt for this close.
- Throw ProportionalCloseAmountOutOfTolerance if total long amounts are not within the tolerated BPS band.
- Throw RedeemBehalfFailed if redeem on behalf (profit leg or full-close dust) fails.
- Throw TokenSwapCallFailed if the profit swap helper call fails.
- Throw SlippageExceeded if profit swap output is below minAmountOutProfit.
- Throw MintBehalfFailed if minting converted profit as principal fails.
- Throw ZeroVTokensMinted if profit swap output rounds down to 0 vTokens if Minted.
- Throw PositionNotFullyClosed if 100% close is used but short debt remains (e.g. exitLeverage did not repay fully).
closeWithLoss
Section titled “closeWithLoss”Closes a position with loss proportionally (BPS-based, same pattern as closeWithProfit). If treasuryPercent is enabled, the LM redeems more than the requested DSA amount on behalf of the position account to cover the fee.
Implementation notes:
- First exit (long → short): long/short amounts are derived from BPS; the user passes shortAmountToRepayForFirstSwap,
which is validated to be within
[0, expectedShort]and minAmountOutFirst must be >= shortAmountToRepayForFirstSwap. For 100% close with one leg, shortAmountToRepayForFirstSwap should be slightly higher to cover the internal tolerance bump. - Second exit (DSA → short): the second repay amount is calculated as expectedShort - shortAmountToRepayForFirstSwap (and bumped for 100% close when > 0). minAmountOutSecond must be >= the calculated second repay (slippage protection; and should cover the bump but exact match not required).
- Single-leg scenarios: this function also supports cases where only one leg (long or DSA) is available (e.g. after liquidation), by allowing either the first or second exit to be effectively skipped.
- Principal handling: Unused DSA principal stays on the position account. withdrawPrincipal withdraws up to the withdrawable amount; deactivatePosition redeems all remaining DSA and sends it to the user.
function closeWithLoss(contract IVToken longVToken, contract IVToken shortVToken, uint256 closeFractionBps, uint256 longAmountToRedeemForFirstSwap, uint256 shortAmountToRepayForFirstSwap, uint256 minAmountOutFirst, bytes swapDataFirst, uint256 dsaAmountToRedeemForSecondSwap, uint256 minAmountOutSecond, bytes swapDataSecond) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
| closeFractionBps | uint256 | Proportion to close in basis points (10000 = 100%, 1 = 0.01% minimum) |
| longAmountToRedeemForFirstSwap | uint256 | Long amount to redeem for the first swap (validated against BPS within 1% tolerance) |
| shortAmountToRepayForFirstSwap | uint256 | Short amount to repay in the first exit (validated: 0 <= value <= BPS-derived expected short) |
| minAmountOutFirst | uint256 | Min short Amount expected from first swap; must be >= shortAmountToRepayForFirstSwap. Should Include flash-loan fees and for 100% close with one leg, include internal tolerance buffer. |
| swapDataFirst | bytes | Swap #1 calldata: long/DSA → short for the first repay leg |
| dsaAmountToRedeemForSecondSwap | uint256 | DSA amount to redeem and use as input for the second repay swap |
| minAmountOutSecond | uint256 | Minimum short Amount expected from second swap; must be >= internally calculated second repay amount. Should Include flash-loan fees and (for 100% close) internal tolerance buffer. |
| swapDataSecond | bytes | Swap #2 calldata: DSA → short for the second repay leg |
📅 Events
Section titled “📅 Events”- Emits PositionClosed event. When DSA == Long, PositionClosed.longDustRedeemed is reclassified back as principal vTokens rather than transferred.
❌ Errors
Section titled “❌ Errors”- Throw PositionNotActive if the position is not active.
- Throw ZeroDebt if there is no short debt to close.
- Throw InvalidCloseFractionBps if closeFractionBps is not between 1 and 10000.
- Throw MinAmountOutRepayBelowDebt if minAmountOutFirst is below shortAmountToRepayForFirstSwap.
- Throw ProportionalCloseAmountOutOfTolerance if first-exit amounts are not within the tolerated BPS band.
- Throw MinAmountOutSecondBelowDebt if minAmountOutSecond is below the internally calculated second repay.
- Throw InsufficientWithdrawableAmount if either leg’s effective amount (after treasury grossup) exceeds its bucket in the shared pool (DSA==long only).
- Throw RedeemBehalfFailed if redeeming long or DSA vTokens on behalf fails.
- Throw TokenSwapCallFailed if a swap helper call fails, or SlippageExceeded if swap output is too low.
- Throw ExcessiveShortDust if short token dust after both exit legs exceeds proportional tolerance.
closeWithProfitAndDeactivate
Section titled “closeWithProfitAndDeactivate”Fully closes a profitable position and deactivates it in a single atomic transaction.
function closeWithProfitAndDeactivate(contract IVToken longVToken, contract IVToken shortVToken, struct IRelativePositionManager.CloseWithProfitParams profitSwapParams) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
| profitSwapParams | struct IRelativePositionManager.CloseWithProfitParams | CloseWithProfitParams struct containing swap parameters |
closeWithLossAndDeactivate
Section titled “closeWithLossAndDeactivate”Fully closes a position at a loss and deactivates it in a single atomic transaction.
function closeWithLossAndDeactivate(contract IVToken longVToken, contract IVToken shortVToken, struct IRelativePositionManager.CloseWithLossParams lossSwapParams) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
| lossSwapParams | struct IRelativePositionManager.CloseWithLossParams | CloseWithLossParams struct containing swap parameters |
deactivatePosition
Section titled “deactivatePosition”Deactivates a position account
function deactivatePosition(contract IVToken longVToken, contract IVToken shortVToken) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
📅 Events
Section titled “📅 Events”- Emits PositionDeactivated event.
❌ Errors
Section titled “❌ Errors”- Throw PositionNotActive if the position is not active.
- Throw PositionNotFullyClosed if short debt remains.
withdrawPrincipal
Section titled “withdrawPrincipal”Withdraws principal from an active position, subject to utilization constraints
function withdrawPrincipal(contract IVToken longVToken, contract IVToken shortVToken, uint256 amount) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
| amount | uint256 | Amount to withdraw |
📅 Events
Section titled “📅 Events”- Emits PrincipalWithdrawn event when principal is withdrawn.
❌ Errors
Section titled “❌ Errors”- Throw PositionNotActive if the position is not active.
- Throw ZeroAmount if amount is zero.
- Throw InsufficientWithdrawableAmount if amount exceeds withdrawable principal.
- Throw RedeemBehalfFailed if redeem fails.
getPositionAccountAddress
Section titled “getPositionAccountAddress”Returns the address at which the PositionAccount would be deployed for the given user and markets
function getPositionAccountAddress(address user, contract IVToken longVToken, contract IVToken shortVToken) external view returns (address predicted)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| user | address | User address |
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| predicted | address | The predicted PositionAccount address (same as deployed by activateAndOpenPosition for that user/long/short) |
❌ Errors
Section titled “❌ Errors”- Throw PositionAccountImplementationNotSet if implementation is not configured.
getDsaVTokens
Section titled “getDsaVTokens”Returns the full list of configured DSA vToken markets
function getDsaVTokens() external view returns (address[] dsaVTokensList)Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| dsaVTokensList | address[] | Array of DSA vToken addresses |
getPosition
Section titled “getPosition”Returns the position data for a user and asset pair
function getPosition(address user, contract IVToken longVToken, contract IVToken shortVToken) external view returns (struct IRelativePositionManager.Position position)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| user | address | User address |
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| position | struct IRelativePositionManager.Position | The Position struct |
getUtilizationInfo
Section titled “getUtilizationInfo”Calculates capital utilization for a position
function getUtilizationInfo(address user, contract IVToken longVToken, contract IVToken shortVToken) external returns (struct IRelativePositionManager.UtilizationInfo utilization)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| user | address | User address |
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| utilization | struct IRelativePositionManager.UtilizationInfo | Utilization information including available capital and withdrawable amount |
getAvailableShortCapacity
Section titled “getAvailableShortCapacity”Returns the remaining short borrow capacity for a position under current market conditions
function getAvailableShortCapacity(address user, contract IVToken longVToken, contract IVToken shortVToken) external returns (uint256 availableCapacity)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| user | address | User address |
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| availableCapacity | uint256 | Remaining borrow capacity in short asset terms |
getMaxLeverageAllowed
Section titled “getMaxLeverageAllowed”Returns the maximum allowed leverage for a given DSA/long market pair based on current collateral factors
function getMaxLeverageAllowed(contract IVToken dsaVToken, address longVToken) external view returns (uint256 maxLeverage)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| dsaVToken | contract IVToken | The DSA vToken market (CF_dsa used as collateral) |
| longVToken | address | The long asset vToken market (CF_long used as hedge coverage) |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| maxLeverage | uint256 | The maximum leverage ratio (1e18 mantissa) |
getLongCollateralBalance
Section titled “getLongCollateralBalance”Returns the actual long collateral balance in underlying for a given user/position, excluding DSA principal when the DSA and long assets share the same vToken market.
function getLongCollateralBalance(address user, contract IVToken longVToken, contract IVToken shortVToken) external returns (uint256 longBalance)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| user | address | The position owner |
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| longBalance | uint256 | The long collateral balance in underlying units (principal excluded when shared market) |
getSuppliedPrincipalBalance
Section titled “getSuppliedPrincipalBalance”Returns the supplied principal balance in underlying units for a given user/position
function getSuppliedPrincipalBalance(address user, contract IVToken longVToken, contract IVToken shortVToken) external returns (uint256 balance)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| user | address | The position owner |
| longVToken | contract IVToken | The vToken market for the long asset |
| shortVToken | contract IVToken | The vToken market for the short asset |
Return Values
Section titled “Return Values”| Name | Type | Description |
|---|---|---|
| balance | uint256 | The supplied principal in underlying units |
PositionAccount
Section titled “PositionAccount”Minimal proxy contract that holds user funds for isolated Relative Trading positions
Solidity API
Section titled “Solidity API”COMPTROLLER
Section titled “COMPTROLLER”Address of the Venus Comptroller (same for all clones)
contract IComptroller COMPTROLLERRELATIVE_POSITION_MANAGER
Section titled “RELATIVE_POSITION_MANAGER”Address of the authorized RelativePositionManager contract (same for all clones)
address RELATIVE_POSITION_MANAGERLEVERAGE_MANAGER
Section titled “LEVERAGE_MANAGER”Address of the LeverageStrategiesManager contract (same for all clones)
address LEVERAGE_MANAGERAddress of the position account owner (different for each clone)
address ownerlongVToken
Section titled “longVToken”Address of the long vToken for this position
address longVTokenshortVToken
Section titled “shortVToken”Address of the short vToken for this position
address shortVTokenconstructor
Section titled “constructor”Constructor for the PositionAccount implementation contract
constructor(contract IComptroller comptroller_, address relativePositionManager_, address leverageManager_) publicParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| comptroller_ | contract IComptroller | The Venus comptroller contract address |
| relativePositionManager_ | address | Address of the RelativePositionManager contract |
| leverageManager_ | address | Address of the LeverageStrategiesManager contract |
❌ Errors
Section titled “❌ Errors”- ZeroAddress if any of the addresses is zero.
initialize
Section titled “initialize”Initializes a new position account clone
function initialize(address owner_, address longVToken_, address shortVToken_) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| owner_ | address | Address of the position account owner |
| longVToken_ | address | Address of the long market vToken |
| shortVToken_ | address | Address of the short market vToken |
❌ Errors
Section titled “❌ Errors”- ZeroAddress if any of the addresses is zero.
enterLeverage
Section titled “enterLeverage”Forwards enterLeverage to the LeverageStrategiesManager on behalf of this position account
function enterLeverage(contract IVToken collateralMarket, uint256 collateralAmountSeed, contract IVToken borrowedMarket, uint256 borrowedAmountToFlashLoan, uint256 minAmountOutAfterSwap, bytes swapData) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| collateralMarket | contract IVToken | Collateral (e.g. long) vToken to supply after swap |
| collateralAmountSeed | uint256 | Optional seed amount of collateral (RPM uses 0) |
| borrowedMarket | contract IVToken | Borrowed (e.g. short) vToken to flash-borrow |
| borrowedAmountToFlashLoan | uint256 | Amount to borrow via flash loan |
| minAmountOutAfterSwap | uint256 | Minimum collateral out after swap (slippage protection) |
| swapData | bytes | Swap calldata (e.g. borrowed → collateral) |
❌ Errors
Section titled “❌ Errors”- UnauthorizedCaller if caller is not the RelativePositionManager.
exitLeverage
Section titled “exitLeverage”Forwards exitLeverage to the LeverageStrategiesManager on behalf of this position account
function exitLeverage(contract IVToken collateralMarket, uint256 collateralAmountToRedeemForSwap, contract IVToken borrowedMarket, uint256 borrowedAmountToFlashLoan, uint256 minAmountOutAfterSwap, bytes swapData) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| collateralMarket | contract IVToken | Collateral (e.g. long) vToken to redeem |
| collateralAmountToRedeemForSwap | uint256 | Amount of collateral to redeem for swap |
| borrowedMarket | contract IVToken | Borrowed (e.g. short) vToken to repay |
| borrowedAmountToFlashLoan | uint256 | Amount to repay via flash loan |
| minAmountOutAfterSwap | uint256 | Minimum amount out after swap (slippage protection) |
| swapData | bytes | Swap calldata (e.g. collateral → borrowed) |
❌ Errors
Section titled “❌ Errors”- UnauthorizedCaller if caller is not the RelativePositionManager.
exitSingleAssetLeverage
Section titled “exitSingleAssetLeverage”Forwards exitSingleAssetLeverage to the LeverageStrategiesManager on behalf of this position account
function exitSingleAssetLeverage(contract IVToken collateralMarket, uint256 collateralAmountToFlashLoan) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| collateralMarket | contract IVToken | vToken market for both collateral and debt |
| collateralAmountToFlashLoan | uint256 | Amount to borrow via flash loan for debt repayment |
❌ Errors
Section titled “❌ Errors”- UnauthorizedCaller if caller is not the RelativePositionManager.
exitMarket
Section titled “exitMarket”Exits a market by calling comptroller.exitMarket with this position account as the sender
function exitMarket(address vTokenToExit) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| vTokenToExit | address | Address of the vToken market to exit |
❌ Errors
Section titled “❌ Errors”- UnauthorizedCaller if caller is not the RelativePositionManager.
- ExitMarketFailed if the exit market operation fails.
transferDustToOwner
Section titled “transferDustToOwner”Transfers full balance of an ERC20 token from this position account to its owner (dust recovery)
function transferDustToOwner(address token) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| token | address | Address of the ERC20 token to transfer |
❌ Errors
Section titled “❌ Errors”- UnauthorizedCaller if caller is not the RelativePositionManager.
genericCalls
Section titled “genericCalls”Executes multiple generic calls to external contracts. Direct callers are restricted to RelativePositionManager, but the manager exposes the ACM-gated executePositionAccountCall administrative path described above.
function genericCalls(address[] targets, bytes[] data) externalParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| targets | address[] | Array of target contract addresses |
| data | bytes[] | Array of encoded function call data |
Trust Boundary
Section titled “Trust Boundary”Each target call executes from the PositionAccount and can therefore act on its token balances, approvals, and protocol permissions. Review the live ACM grantee for executePositionAccountCall(address,address[],bytes[]); onlyRelativePositionManager does not make this path owner-only.
❌ Errors
Section titled “❌ Errors”- UnauthorizedCaller if caller is not the RelativePositionManager.
- InvalidCallsLength if arrays are empty or lengths mismatch.