Conditional Orders
Conditional Orders Life Cycle
Structure
Off-Chain Submission Process in Smart Margin v3
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 totrue
for on-chain verification, orfalse
for off-chain.On-Chain Verification: If
requireVerified
istrue
, the conditions inConditionalOrder.conditions
need to be met on-chain.Off-Chain Verification: If
requireVerified
isfalse
, the specified conditions inConditionalOrder.conditions
will not undergo on-chain verification.Trusted Executor Assignment: For off-chain verification (
requireVerified
isfalse
), aConditionalOrder.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
isfalse
, 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.
On-Chain Execution Procedure
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.
Execution (Off- and On-Chain)
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 theConditionalOrder
(_co
), its signature (_signature
), and a proposed execution fee (_fee
in$snxUSD
).Execution Validity Checks: The transaction will fail if the
_fee
exceeds either theConditionalOrder.maxExecutorFee
or the account's available credit.On-Chain Verification for Execution: If
ConditionalOrder.requireVerified
istrue
, 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
istrue
.Off-Chain Verification for Execution: If
requireVerified
isfalse
, 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 ifrequireVerified
isfalse
.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 theConditionalOrder.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
Last updated