Assessment reports>Tradoor>Threat Model>Message: CreateTpSlPerpOrder

Message: CreateTpSlPerpOrder

This operation allows to add conditional take-profit and/or stop-loss perpetual position orders. The message is rejected if the pool is in the stopped state.

The message must carry sufficient TON to cover the order executionFee and the createPerpOrderGas fees for all the conditions specified. The fees must thus be paid once if only a take-profit or stop-loss order is requested, and they must be paid twice if both conditions are specified. A condition is considered not requested if the size or trigger price is zero. Technically, it is possible to not specify either condition. This is not an issue for the pool, as it only causes the user to waste gas fees.

Next, the requested take-profit and/or stop-loss orders are inserted. Each order is assigned a unique incremental ID, used as a key to store the order details into the perpOrders map. An event is emitted for each inserted order to aid off-chain observers.

Finally, the totalExecutionFee amount of total fees collected to be paid to executors is increased, and any excess TON is returned to the message sender.

Inputs

The incoming message has the following structure:

message CreateTpSlPerpOrder { executionFee: Int as coins; tokenId: Int as uint16; isLong: Bool; tpSize: Int as coins; tpPrice: Int as uint128; slSize: Int as coins; slPrice: Int as uint128; trxId: Int as uint64; requestTime: Int as uint32; }
  • executionFee

    • Validation: Must be sufficient to cover the self.perpMinExecutionFee for however many orders will be created.

    • Impact: The fee to be paid to the executor for executing the order.

  • tokenId

    • Validation: None.

    • Impact: Identifier of the asset for which the user wants to take a position in.

  • isLong

    • Validation: None.

    • Impact: Whether the user wants to take a long or short position. If true, for take-profit orders, triggerAbove will be true, and for stop-loss orders, triggerAbove will be false. If false, the opposite will be true.

  • tpSize

    • Validation: None.

    • Impact: The size of the take-profit order. This is the amount of the asset that will be sold if the take profit is triggered.

  • tpPrice

    • Validation: None.

    • Impact: The price at which the take-profit order will be triggered.

  • slSize

    • Validation: None.

    • Impact: The size of the stop-loss order. This is the amount of the asset that will be sold if the stop loss is triggered.

  • slPrice

    • Validation: None.

    • Impact: The price at which the stop-loss order will be triggered.

  • trxId

    • Validation: None.

    • Impact: Identifier for the message — does not affect handler logic.

  • requestTime

    • Validation: None.

    • Impact: N/A.

Test coverage

Intended branches

Negative behavior

Zellic © 2025Back to top ↑