IPositionRouterCallbackReceiver Interface
TheIPositionRouterCallbackReceiver
interface defines the function that contracts must implement to receive callbacks from the PositionRouter when positions are executed or failed to execute.
Callback Function
positionKey
: The unique identifier for the position requestisExecuted
: 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:- Handle both successful and failed position executions
- Be able to identify the original request using the positionKey
- Implement appropriate security measures to verify that the caller is the legitimate PositionRouter
- 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.