Perpetual Trading
To interact with the system, users have to send messages containing orders they wish to execute. The following order types are currently supported:
    Withdrawal, requesting collateral to move from the L2 state to L1
    Limit Order with Fees, declaring intent to sell a certain amount of a certain asset in exchange for a different asset at a certain ratio. One of the assets must be the collateral
    Conditional Transfer with Fees, requesting collateral to be transferred from one vault to another if some on-chain event was recorded.
    Transfer with Fees, requesting collateral to be transferred from one vault to another.
The transaction is sent directly to the application through an interface exposed there, and the validity of the signature over all the fields is verified by the proof system.
In the case of Withdrawal, the signature is constructed as follows:
ECDSA(H(w1,w5),kprivate)ECDSA(H(w_1, w_5), k_{private})
In the case of Limit Order/Transfer/Conditional Transfer with Fees, the signature is constructed as follows:
ECDSA(H(H(H(H(w1,w2),w3),w4),w5),kprivate)ECDSA(H(H(H(H(w_1, w_2), w_3),w_4),w_5), k_{private})
Where ECDSA is the regular elliptic curve digital signature algorithm,
HH
is the Pedersen hash function,
kprivatek_{private}
is the user’s private key, and the words
w1w_1
,
w2w_2
,
w3w_3
,
w4w_4
,
w5w_5
and
w6w_6
are 252-bit words containing the data required for the signature, as described in the next section.

Withdrawal

For withdrawal, the signature is constructed as follows:
w1w_1
is the withdrawn assetId
w5w_5
is defined as follows:
1
+----+-----------------+---------+-----------+---------+------------+
2
#bits | 10 | 64 | 32 | 32 | 32 | 49 |
3
+----+-----------------+---------+-----------+---------+------------+
4
label A B C D E F
Copied!
    A: order type
      6 for a Withdrawal
    B: vaultId from which the user wants to take funds.
    C: nonce for the transaction.
    D: quantizedAmount to be withdrawn
    E: expirationTimestamp, in hours since the Unix epoch. For example, for the order to expire 24 hours from the beginning of the current hour, set the timestamp to
    𝑡𝑢𝑛𝑖𝑥3600+24⌊\frac{𝑡_{𝑢𝑛𝑖𝑥}}{3600}⌋+24
    F: padding of zeros

Limit Order with Fees

For limit order with fees, the signature is constructed as follows:
ECDSA(H(H(H(H(w1,w2),w3),w4),w5),kprivate)ECDSA(H(H(H(H(w_1, w_2), w_3),w_4),w_5), k_{private})
w1w_1
is the assetId to be sold
w2w_2
is the assetId to be bought.
w3w_3
is the assetId used to pay the fee.
w4w_4
is defined as follows:
1
+-------+--------------+--------------+--------------+--------+
2
#bits | 27 | 64 | 64 . | 64 | 32 |
3
+-------+--------------+--------------+--------------+--------+
4
label A B C D E
Copied!
    A: padding of zeros
    B: quantizedAmount to be sold.
    C: quantizedAmount to be bought
    D: quantizedAmount to pay fees
    E: nonce for the transaction.
w5w_5
is defined as follows:
1
+---+--------------+--------------+--------------+-----+-----+
2
#bits | 10| 64 | 64 . | 64 | 32 | 17 |
3
+---+--------------+--------------+--------------+-----+-----+
4
label A B C D E F
Copied!
    A: order type
      3 for a Limit Order with Fees
    B: vaultId from which the user wants to take funds.
    C: vaultId from which the user wants to take funds.
    D: vaultId from which the user wants to take funds.
    E: expirationTimestamp, in hours since the Unix epoch. For example, for the order to expire 24 hours from the beginning of the current hour, set the timestamp to
    𝑡𝑢𝑛𝑖𝑥3600+24⌊\frac{𝑡_{𝑢𝑛𝑖𝑥}}{3600}⌋+24
    F: padding of zeros

Transfer with Fees/Conditional Transfer with Fees

For transfer with fees, the signature is constructed as follows:
For Transfer with Fees, the encoding is as follows
ECDSA(H(H(H(H(w1,w2),w3),w4),w5),kprivate)ECDSA(H(H(H(H(w_1, w_2), w_3),w_4),w_5), k_{private})
For Conditional Transfer with Fees, the encoding is as follows
ECDSA(H(H(H(H(H(w1,w2),w3),w6),w4),w5),kprivate)ECDSA(H(H(H(H(H(w_1, w_2), w_3),w_6),w_4),w_5), k_{private})
w1w_1
is the assetId to be sold
w2w_2
is the assetId used to pay the fee.
w3w_3
is the receiver_starkKey used to pay the fee.
w4w_4
is defined as follows
1
+-------+--------------+--------------+--------------+--------+
2
#bits | 27 | 64 | 64 . | 64 | 32 |
3
+-------+--------------+--------------+--------------+--------+
4
label A B C D E
Copied!
    A: padding of zeros
    B: senderpositionId
    C: receiver positionId
    D: fee positionId
    E: nonce for the transaction.
w5w_5
is defined as follows:
1
+---+--------------+--------------+--------+-----------------+
2
#bits | 10| 64 | 64 | 32 | 81 |
3
+---+--------------+--------------+--------+-----------------+
4
label A B C D E
Copied!
    A: order type
      4 for Transfer with Fees
      5 for Conditional Transfer with Fees
    B: quantizedAmount to transfer
    C: quantizedAmount to limit the max fee
    D: expirationTimestamp, in hours since the Unix epoch. For example, for the order to expire 24 hours from the beginning of the current hour, set the timestamp to
    𝑡𝑢𝑛𝑖𝑥3600+24⌊\frac{𝑡_{𝑢𝑛𝑖𝑥}}{3600}⌋+24
    E: padding of zeros
w6w_6
is the condition defined as Perdersen hash of the contract address and fact.
Last modified 2mo ago