💻Conditional Orders
Last updated
Last updated
Conditional Order Placement
Order Conditions: A trader must first define the conditions for the execution of a conditional order.
Verification Choice: The trader decides if these conditions should be verified on-chain or off-chain.
Setting the Verification Flag: To make this distinction, the ConditionalOrder.requireVerified
flag is set to true
for on-chain verification, or false
for off-chain.
On-Chain Verification: If requireVerified
is true
, the conditions in ConditionalOrder.conditions
need to be met on-chain.
Off-Chain Verification: If requireVerified
is false
, the specified conditions in ConditionalOrder.conditions
will not undergo on-chain verification.
Trusted Executor Assignment: For off-chain verification (requireVerified
is false
), a ConditionalOrder.trustedExecutor
address must be set, indicating the trusted party for execution.
Role of Trusted Executor: This executor is the sole entity capable of executing the order when requireVerified
is false
, acting on the presumption that off-chain conditions are met.
Note: The trader relies on the ConditionalOrder.trustedExecutor
to execute the order only when the off-chain conditions are satisfied.
Fee Specification: The trader specifies a maximum fee, ConditionalOrder.maxExecutorFee
, they are willing to pay the executor for successful execution.
Order Signing: The trader signs the ConditionalOrder
using their private key.
Order Submission: The signed ConditionalOrder
is submitted to Kwenta, or another chosen party, for storage and processing by backend infrastructure.
Account Crediting: If not done already, the trader credits their account to cover future execution fees. In Synthetix v3 Andromeda, $USDC
can be converted to $snxUSD
for credit as demonstrated here.
Condition Monitoring: Kwenta's backend infrastructure continuously monitors the conditions set in ConditionalOrder.conditions
.
Execution Initiation: Upon condition fulfillment, an executor calls Engine.execute
, submitting the ConditionalOrder
(_co
), its signature (_signature
), and a proposed execution fee (_fee
in $snxUSD
).
Execution Validity Checks: The transaction will fail if the _fee
exceeds either the ConditionalOrder.maxExecutorFee
or the account's available credit.
On-Chain Verification for Execution: If ConditionalOrder.requireVerified
is true
, on-chain verification of conditions occurs before execution. This is gas-intensive and therefore expensive.
Executor Flexibility with On-Chain Verification: Any address can execute the order if requireVerified
is true
.
Off-Chain Verification for Execution: If requireVerified
is false
, no on-chain verification occurs before execution, making it less gas-intensive and cheaper.
Executor Restriction with Off-Chain Verification: The ConditionalOrder.trustedExecutor
must be the one executing the order if requireVerified
is false
.
Execution Requirements: The ConditionalOrder
will only be executed if specific criteria are met, including fee limits, account credit, nonce uniqueness, authorized signer, and signature validity.
Order Execution: If all conditions are satisfied, the ConditionalOrder
is executed, and the ConditionalOrder.nonce
is marked as used.
Credit & Debit Management
With the integration of Conditional Orders (COs), the Engine contract now manages a credit balance for each account, utilized for executing successful conditional orders. This balance, denominated in $snxUSD
, is not factored into the account's total margin, ensuring that its debit does not affect open position liquidation risks. Unlike previous versions, the credit in the engine is never locked, as conditional order submission is entirely off-chain, preventing the establishment of a fixed credit balance for outstanding conditional orders.
refer to this test suite for programmatic examples of managing account credit