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:

  • Limit Order, 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, requesting collateral to be transferred from one vault to another if some on-chain event was recorded.

  • Transfer, requesting collateral to be transferred from one vault to another.

  • Withdrawal, requesting collateral to move from the L2 state to L1

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.

Withdrawal

For withdrawal, the signature is constructed as follows:

ECDSA(H(collateral_asset_id,w),kprivate)ECDSA(H(collateral\_asset\_id, w), 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, collateral_asset_id is the collateral assetId (USDC) and the world w is packed as follows:

​

+----+-----------------+---------+-----------+---------+------------+
#bits | 10 | 64 | 32 | 32 | 32 | 49 |
+----+-----------------+---------+-----------+---------+------------+
label A B C D E F

When ww is defined as follows:

A: WITHDRAWAL type (6) B: The id of the vault to withdraw the funds from C: Nonce, generated randomly for each request D: Amount: how many USDC units to withdraw (when "1" represents 10610^6USDC) E: Expiration timestamp - until which time (seconds since epoch) the request is valid F: Padding of zeroes.

Limit Order

For limit order, the signature is constructed as follows:

​ECDSA(H(H(H(H(asset_id_sell,asset_id_buy),asset_id_fee),w1),w2),kprivate)ECDSA(H(H(H(H(asset\_id\_sell, asset\_id\_buy),asset\_id\_fee), w_1), w_2), k_{private})​

When w1 w_1is defined as follows:

+-------+--------------+--------------+--------------+--------+
#bits | 27 | 64 | 64 . | 64 | 32 |
+-------+--------------+--------------+--------------+--------+
label A B C D . E

A: padding of zeroes B: amount sell C: amount buy D: amount fee E: nonce And w2 w_2is defined as follows:

+---+--------------+--------------+--------------+-----+-----+
#bits | 10| 64 | 64 . | 64 | 32 | 17 |
+---+--------------+--------------+--------------+-----+-----+
label A B C D . E F

A: LIMIT ORDER type (3) B, C and D: The vault id that initiated the limit order (written three times) E: expiration timestamp F: padding of zeroes

Transfer

For transfer, the signature is constructed as follows:

​ECDSA(H(H(H(H(asset_id,asset_id_fee),receiver_public_key),w1),w2),kprivate)ECDSA(H(H(H(H(asset\_id, asset\_id\_fee),receiver\_public\_key), w_1), w_2), k_{private})​

When w1 w_1is defined as follows:

+-------+--------------+--------------+--------------+--------+
#bits | 27 | 64 | 64 . | 64 | 32 |
+-------+--------------+--------------+--------------+--------+
label A B C D . E

A: padding of zeroes B: sender position id C: receiver position id D: fee position id E: nonce And w2 w_2is defined as follows:

+---+--------------+--------------+--------+-----------------+
#bits | 10| 64 | 64 . | 32 | 81 |
+---+--------------+--------------+--------+-----------------+
label A B C D E

A: TRANSFER type (4) B: amount to transfer C: maximal fee D: expiration timestamp E: padding of zeroes

Conditional Transfer

For conditional transfer, the signature is constructed as follows:

​ECDSA(H(H(H(H(H(asset_id,asset_id_fee),receiver_public_key),condition),w1),w2),kprivate)ECDSA(H(H(H(H(H(asset\_id, asset\_id\_fee),receiver\_public\_key), condition) , w_1), w_2), k_{private})​

When w1,w2 w_1,w_2are defined as in transfer, except for the fact that w2w_2 starts with CONDITIONAL TRANSFER type (5), and condition is the Perdersen hash of the contract address and fact

​