OffchainPositionManager

Inherits: Initializable, OwnableUpgradeable, IHedgeManager

Author: Logarithm Labs

OffChainPositionManager is a smart contract component designed to interact with off-chain perpetual protocols to manage hedge positions. By coordinating with off-chain systems, such as through an oracle or relayer network, the contract adjusts perpetual positions to maintain a target exposure aligned with the strategy’s requirements. This component is ideal for delta-neutral strategies seeking yield from funding payments on off-chain perpetual markets.

OffChainPositionManager is an upgradeable smart contract, deployed through the beacon proxy pattern.

State Variables

OffChainPositionManagerStorageLocation

bytes32 private constant OffChainPositionManagerStorageLocation =
    0xc79dcf1ab1ed210e1b815a3e944622845af0e197fa2b370829d3b756c740ef00;

Functions

_getOffChainPositionManagerStorage

function _getOffChainPositionManagerStorage() private pure returns (OffChainPositionManagerStorage storage $);

onlyAgent

Authorize caller if it is a configured agent.

modifier onlyAgent();

initialize

_setAgent

setAgent

adjustPosition

Called to adjust the hedge position based on specified parameters.

Parameters

Name
Type
Description

params

AdjustPositionPayload

reportState

Reports the state of the hedge position.

reportStateAndExecuteRequest

Reports the state of the hedge position while calling the strategy’s callback functions if there is a position adjustment request from the strategy.

getLastRequest

Returns the last request that was requested from strategy.

clearIdleCollateral

Transfers idle assets to the vault to process withdraw requests.

forcedTransferToAgent

_transferToAgent

forcedTransferFromAgent

_transferFromAgent

positionNetBalance

Gets the net collateral balance of the position, including pending adjustments.

Returns

Name
Type
Description

<none>

uint256

The total collateral asset amount in the position.

currentPositionState

Returns the current state of position.

currentLeverage

Retrieves the current leverage of the position.

Returns

Name
Type
Description

leverage

uint256

The leverage ratio as a uint256.

config

The address of OffChainConfig smart contract.

agent

The address of agent.

oracle

The address of oracle smart contract.

lastRequestRound

The last request round.

currentRound

The current round which is increased by reporting state.

positionState

The position state at a specific round.

pendingCollateralIncrease

The pending collateral amount that is transferred to agent to increase collateral, but not reported by agent.

requests

The request info at a specific round.

positionSizeInTokens

Returns the current size of the position in terms of index tokens.

Returns

Name
Type
Description

<none>

uint256

The size of the position in index tokens.

needKeep

Checks whether the keep function needs to be called to maintain the position.

Returns

Name
Type
Description

<none>

bool

A boolean indicating if keep should be executed.

keep

Called to maintain or adjust the hedge position as required by strategy logic.

Executes actions needed to align the position with target hedge requirements.

increaseCollateralMinMax

Returns the minimum and maximum collateral limits for increasing the position.

Returns

Name
Type
Description

min

uint256

The minimum allowable collateral increase amount.

max

uint256

The maximum allowable collateral increase amount.

increaseSizeMinMax

Returns the minimum and maximum limits for increasing the position size.

Returns

Name
Type
Description

min

uint256

The minimum allowable increase in position size.

max

uint256

The maximum allowable increase in position size.

decreaseCollateralMinMax

Returns the minimum and maximum collateral limits for decreasing the position.

Returns

Name
Type
Description

min

uint256

The minimum allowable collateral decrease amount.

max

uint256

The maximum allowable collateral decrease amount.

decreaseSizeMinMax

Returns the minimum and maximum limits for decreasing the position size.

Returns

Name
Type
Description

min

uint256

The minimum allowable decrease in position size.

max

uint256

The maximum allowable decrease in position size.

limitDecreaseCollateral

Retrieves the minimum decrease in collateral required for cost-efficient execution.

Helps in optimizing gas usage and cost efficiency.

Returns

Name
Type
Description

<none>

uint256

The minimum decrease collateral amount that qualifies for cost-effective execution.

collateralToken

Returns the address of the collateral token used in the position.

Returns

Name
Type
Description

<none>

address

The address of the collateral token.

indexToken

Returns the address of the index token used in the position.

Returns

Name
Type
Description

<none>

address

The address of the index token.

idleCollateralAmount

The balance of collateral asset of this position manager.

Events

AgentUpdated

Emitted when agent gets updated.

CreateRequest

Emitted when a new request from strategy is created.

ReportRequest

Emitted when a report is executed after requesting.

RequestIncreasePosition

Emitted when a increase request is created.

RequestDecreasePosition

Emitted when a decrease request is created.

AgentTransfer

Emitted when asset is transferred to agent to increase collateral.

ReportState

Emitted when position’s state is reported.

Structs

PositionState

Used to store the state of offchain position.

RequestInfo

Used for the request and response infos.

OffChainPositionManagerStorage

Last updated