Skip to main content
PositionRouter bundles common position flows into one transaction: open (permit, supply, borrow), close (repay, withdraw), and deleverage (sell collateral, repay). Positions always stay on the user’s account in Stockline; the router holds nothing between calls and sweeps leftovers back to the caller. It also implements the deleverage callback that sells collateral for USDG along the registry’s zap route. PositionRouter lets you:
  • Supply collateral and borrow USDG in one transaction, with an optional permit
  • Repay and withdraw in one transaction, using max sentinels for full close
  • Sell collateral and repay debt atomically
Addresses per network. Every address is also on Addresses. The source code is src/periphery/PositionRouter.sol on GitHub. The ABI is /abis/PositionRouter.json.

Write methods

openPosition

Optionally applies an ERC-2612 permit, pulls supplyAmount collateral from the caller, supplies it to the caller’s account, and borrows borrowAmount USDG to the caller if non-zero. Reverts with ZeroAmount for a zero supply. Borrow reverts follow Stockline rules (LIVE, unpaused, caps, LTV).
The caller must approve the router for the collateral, either through the permit or a prior approval. If borrowAmount is non-zero the caller must first set the router as operator with Stockline.setOperator.
Input parameters

closePosition

Pulls repayAmount USDG from the caller and repays their book, then withdraws withdrawAmount collateral to them. Passing the maximum uint256 for either value uses the full debt or full collateral. Reverts with ZeroAmount when both are 0.
The caller must approve the router for USDG and, if withdrawing, set the router as operator. Withdraw needs LIVE regime and unpaused state; repay always works.
Input parameters

deleverage

Calls Stockline.deleverage with this router as callee. The router sells amount of fromBook collateral for USDG along the token’s zap route and the proceeds repay repayBook. Leftover collateral and USDG return to the caller. Works in every regime and while paused because it only reduces risk.
The caller must first set the router as operator. The swap uses the registry’s slippage cap against the router’s TWAP quote; a thin market can revert.
Input parameters

onDeleverage

Callback invoked by Stockline during deleverage. Sells the received collateral for USDG along its zap route, sends the USDG back to Stockline, and returns any collateral dust to the account. Reverts with NotCore for any other caller and InvalidRoute if the token has no allowed route ending in USDG.
Core only. Do not call directly.
Input parameters

Events

Opened

Fires after openPosition, with the supplied and borrowed amounts.

Closed

Fires after closePosition, with the resolved repay and withdraw amounts.

Errors

ZeroAddress

The core was zero at deployment.

ZeroAmount

The supply, deleverage amount, or both close amounts were zero.

InvalidRoute

The collateral token has no allowed zap route to USDG.

NotCore

Only Stockline can call onDeleverage.