Skip to main content

IOrderBook Interface

The IOrderBook interface defines the functions available in the OrderBook contract, which manages limit orders for the Satoshi Perps protocol.

Order Creation

Increase Position Orders

function createIncreaseOrder(
    address[] memory _path,
    uint256 _amountIn,
    address _indexToken,
    uint256 _minOut,
    uint256 _sizeDelta,
    address _collateralToken,
    bool _isLong,
    uint256 _triggerPrice,
    bool _triggerAboveThreshold,
    uint256 _executionFee,
    bool _shouldWrap
) external payable;
Creates a limit order to increase a position when the price reaches the trigger price.

Decrease Position Orders

function createDecreaseOrder(
    address _indexToken,
    uint256 _sizeDelta,
    address _collateralToken,
    uint256 _collateralDelta,
    bool _isLong,
    uint256 _triggerPrice,
    bool _triggerAboveThreshold,
    uint256 _executionFee
) external payable;
Creates a limit order to decrease a position when the price reaches the trigger price.

Swap Orders

function createSwapOrder(
    address[] memory _path,
    uint256 _amountIn,
    uint256 _minOut,
    uint256 _triggerRatio,
    bool _triggerAboveThreshold,
    uint256 _executionFee,
    bool _shouldWrap
) external payable;
Creates a limit order to swap tokens when the exchange rate reaches the trigger ratio.

Order Cancellation

function cancelIncreaseOrder(uint256 _orderIndex) external;
Cancels a pending increase position order.
function cancelDecreaseOrder(uint256 _orderIndex) external;
Cancels a pending decrease position order.
function cancelSwapOrder(uint256 _orderIndex) external;
Cancels a pending swap order.

Order Execution

function executeIncreaseOrder(
    address _account,
    uint256 _orderIndex,
    address payable _executionFeeReceiver
) external;
Executes an increase position order when the trigger condition is met.
function executeDecreaseOrder(
    address _account,
    uint256 _orderIndex,
    address payable _executionFeeReceiver
) external;
Executes a decrease position order when the trigger condition is met.
function executeSwapOrder(
    address _account,
    uint256 _orderIndex,
    address payable _executionFeeReceiver
) external;
Executes a swap order when the trigger condition is met.

Order Access

function getIncreaseOrder(
    address _account,
    uint256 _orderIndex
) external view returns (
    address[] memory path,
    uint256 amountIn,
    address indexToken,
    uint256 minOut,
    uint256 sizeDelta,
    address collateralToken,
    bool isLong,
    uint256 triggerPrice,
    bool triggerAboveThreshold,
    uint256 executionFee
);
Returns the details of an increase position order.
function getDecreaseOrder(
    address _account,
    uint256 _orderIndex
) external view returns (
    address indexToken,
    uint256 sizeDelta,
    address collateralToken,
    uint256 collateralDelta,
    bool isLong,
    uint256 triggerPrice,
    bool triggerAboveThreshold,
    uint256 executionFee
);
Returns the details of a decrease position order.
function getSwapOrder(
    address _account,
    uint256 _orderIndex
) external view returns (
    address[] memory path,
    uint256 amountIn,
    uint256 minOut,
    uint256 triggerRatio,
    bool triggerAboveThreshold,
    uint256 executionFee,
    bool shouldUnwrap
);
Returns the details of a swap order.

Configuration

function setMinExecutionFee(uint256 _minExecutionFee) external;
Sets the minimum execution fee required for orders.
function setMinPurchaseTokenAmountUsd(uint256 _minPurchaseTokenAmountUsd) external;
Sets the minimum purchase token amount in USD.
function setPositionManager(address _positionManager) external;
Sets the address of the PositionManager contract.

State Access

function increaseOrdersIndex(address _account) external view returns (uint256);
Returns the number of increase orders for an account.
function decreaseOrdersIndex(address _account) external view returns (uint256);
Returns the number of decrease orders for an account.
function swapOrdersIndex(address _account) external view returns (uint256);
Returns the number of swap orders for an account.
function minExecutionFee() external view returns (uint256);
Returns the minimum execution fee required for orders.

Usage Notes

  • Orders are triggered when the price or ratio conditions are met.
  • Each order requires an execution fee to incentivize keepers to execute it.
  • For increase orders with token swaps, the path should include the tokens to swap through.
  • The triggerAboveThreshold parameter determines if the order should execute when the price goes above or below the trigger price.

Security Considerations

  • Ensure trigger prices are set appropriately to avoid unexpected execution
  • The execution fee should be sufficient to cover gas costs, otherwise orders may not be executed
  • For increase orders, ensure sufficient tokens are approved or sent with the transaction
I