Skip to main content

IPositionRouterCallbackReceiver Interface

The IPositionRouterCallbackReceiver interface defines the function that contracts must implement to receive callbacks from the PositionRouter when positions are executed or failed to execute.

Callback Function

This function is called by the PositionRouter after a position request has been processed. The parameters provide information about the position and its execution status:
  • positionKey: The unique identifier for the position request
  • isExecuted: Whether the position was successfully executed (true) or failed (false)
  • isIncrease: Whether this was an increase position request (true) or a decrease position request (false)

Implementation Requirements

Contracts implementing this interface must:
  1. Handle both successful and failed position executions
  2. Be able to identify the original request using the positionKey
  3. Implement appropriate security measures to verify that the caller is the legitimate PositionRouter
  4. Not revert in the callback function, as this would prevent position execution

Example Implementation

Usage Notes

  • The callback mechanism allows for building more complex systems on top of the Satoshi Perps protocol, such as conditional orders, automated position management, and risk management systems.
  • When creating a position through the PositionRouter, specify your contract’s address as the _callbackTarget parameter to receive the callback.
  • The callback is called after the position execution attempt, regardless of whether it succeeded or failed.

Security Considerations

  • Always validate that the caller is the expected PositionRouter to prevent unauthorized callbacks.
  • Do not perform excessive operations in the callback function, as this could lead to high gas costs or out-of-gas errors.
  • The callback should be designed to handle both successful and failed executions gracefully.
  • No critical operations should rely solely on the callback being called, as in extreme cases, the callback might not be triggered.