LeverageRouterBase
Inherits: FlashLoanBase, Ownable2Step, Pausable, ReentrancyGuard
Title: LeverageRouterBase
Abstract base for leverage routers with shared validation and admin logic.
Common infrastructure for LeverageRouter (plDXY-BEAR) and BullLeverageRouter (plDXY-BULL).
Note: security-contact: contact@plether.com
Constants
MAX_SLIPPAGE_BPS
Maximum slippage in basis points (1% = 100 bps).
uint256 public constant MAX_SLIPPAGE_BPS = 100
EXCHANGE_RATE_BUFFER_BPS
Buffer for exchange rate drift protection (1% = 100 bps).
uint256 public constant EXCHANGE_RATE_BUFFER_BPS = 100
USDC_INDEX
USDC index in Curve USDC/plDXY-BEAR pool.
uint256 public constant USDC_INDEX = 0
PLDXY_BEAR_INDEX
plDXY-BEAR index in Curve USDC/plDXY-BEAR pool.
uint256 public constant PLDXY_BEAR_INDEX = 1
OP_OPEN
Operation type: open leverage position.
uint8 internal constant OP_OPEN = 1
OP_CLOSE
Operation type: close leverage position.
uint8 internal constant OP_CLOSE = 2
MORPHO
Morpho Blue lending protocol.
IMorpho public immutable MORPHO
CURVE_POOL
Curve pool for USDC/plDXY-BEAR swaps.
ICurvePool public immutable CURVE_POOL
USDC
USDC stablecoin.
IERC20 public immutable USDC
PLDXY_BEAR
plDXY-BEAR token.
IERC20 public immutable PLDXY_BEAR
State Variables
marketParams
Morpho market configuration.
MarketParams public marketParams
Functions
constructor
Initializes base router with core dependencies.
constructor(
address _morpho,
address _curvePool,
address _usdc,
address _plDxyBear
) Ownable(msg.sender);
Parameters
| Name | Type | Description |
|---|---|---|
_morpho | address | Morpho Blue protocol address. |
_curvePool | address | Curve USDC/plDXY-BEAR pool address. |
_usdc | address | USDC token address. |
_plDxyBear | address | plDXY-BEAR token address. |
pause
Pause the router. Blocks openLeverage and closeLeverage.
function pause() external onlyOwner;
unpause
Unpause the router.
function unpause() external onlyOwner;
getActualDebt
Returns the user’s current debt in this market (includes accrued interest).
function getActualDebt(
address user
) external view returns (uint256 debt);
Parameters
| Name | Type | Description |
|---|---|---|
user | address | The address to query debt for. |
Returns
| Name | Type | Description |
|---|---|---|
debt | uint256 | The actual debt amount in USDC (rounded up). |
getCollateral
Returns the user’s collateral in this market.
function getCollateral(
address user
) external view returns (uint256 collateral);
Parameters
| Name | Type | Description |
|---|---|---|
user | address | The address to query collateral for. |
Returns
| Name | Type | Description |
|---|---|---|
collateral | uint256 | The collateral amount in staked token shares. |
_marketId
Computes market ID from marketParams.
function _marketId() internal view returns (bytes32);
_getActualDebt
Computes actual debt from Morpho position, rounded up to ensure full repayment.
function _getActualDebt(
address user
) internal view returns (uint256);
_getBorrowShares
Returns user’s borrow shares from Morpho position.
function _getBorrowShares(
address user
) internal view returns (uint256);
_getCollateral
Returns user’s collateral from Morpho position.
function _getCollateral(
address user
) internal view returns (uint256);
Errors
LeverageRouterBase__ZeroAddress
Thrown when zero address provided.
error LeverageRouterBase__ZeroAddress();
LeverageRouterBase__ZeroPrincipal
Thrown when principal is zero.
error LeverageRouterBase__ZeroPrincipal();
LeverageRouterBase__ZeroCollateral
Thrown when collateral is zero.
error LeverageRouterBase__ZeroCollateral();
LeverageRouterBase__Expired
Thrown when deadline has passed.
error LeverageRouterBase__Expired();
LeverageRouterBase__LeverageTooLow
Thrown when leverage multiplier <= 1x.
error LeverageRouterBase__LeverageTooLow();
LeverageRouterBase__SlippageExceedsMax
Thrown when slippage exceeds MAX_SLIPPAGE_BPS.
error LeverageRouterBase__SlippageExceedsMax();
LeverageRouterBase__NotAuthorized
Thrown when user hasn’t authorized router in Morpho.
error LeverageRouterBase__NotAuthorized();
LeverageRouterBase__InsufficientOutput
Thrown when swap output is insufficient.
error LeverageRouterBase__InsufficientOutput();
LeverageRouterBase__InvalidCurvePrice
Thrown when Curve price query returns zero.
error LeverageRouterBase__InvalidCurvePrice();
LeverageRouterBase__SplitterNotActive
Thrown when Splitter is not active.
error LeverageRouterBase__SplitterNotActive();
LeverageRouterBase__ZeroAmount
Thrown when amount is zero.
error LeverageRouterBase__ZeroAmount();
LeverageRouterBase__NoPosition
Thrown when user has no position in Morpho.
error LeverageRouterBase__NoPosition();
LeverageRouterBase__Unhealthy
Thrown when withdrawal would make position unhealthy.
error LeverageRouterBase__Unhealthy();
LeverageRouterBase__AmountTooSmall
Thrown when amount is too small after conversion.
error LeverageRouterBase__AmountTooSmall();
LeverageRouterBase__PermitFailed
error LeverageRouterBase__PermitFailed();
LeverageRouterBase__BelowMinAmountOut
Thrown when output is below user-specified minimum (MEV protection).
error LeverageRouterBase__BelowMinAmountOut();