The transfer flow

1. Alice enters a request to transfer funds in the application.
Alice enters a request to transfer collateral funds using the off-chain application.
You cannot transfer funds from synthetic assets. |
2. The application sends a Transfer
transaction to StarkEx.
The application sends a transfer request transaction to the StarkEx gateway, using the add_transaction
API with the Transfer
transaction type.
The request includes the following information:
amount
|
The quantized amount of the asset to transfer. |
sender_public_key
|
The sender’s public Stark key. |
sender_position_id
|
The sender’s position ID. |
receiver_public_key
|
The receiver’s public Stark key. |
receiver_position_id
|
The receiver’s position ID. |
asset_id
|
The unique ID of the asset to transfer, as registered on the contract. |
expiration_timestamp
|
The time after which the request is no longer valid, in hours since the Unix epoch. |
nonce
|
A nonce issued by the caller, to prevent replay attacks. |
signature
|
The sender’s signature. |
3. StarkEx checks the validity of the request.
StarkEx checks the following to validate the transfer request:
-
The balance in the sender’s position is sufficient to fulfill the transaction.
-
The maximum fee that the party is willing to pay for the transaction is not less than the actual fee.
-
The transaction request has not expired.
-
According to the orders tree, the order has not already been fulfilled.
-
All amounts in the request are ≥ 0.
-
Each asset’s ID corresponds to real assets registered in the system.
-
Every position involved is either empty or the position’s public Stark key matches the public Stark key in the request.
-
All signatures in the request are valid with respect to the corresponding public Stark key and message.
-
If a funding tick that occurs before the transaction is executed invalidates the transaction, the transaction is not completed and the funding tick is reverted.
-
Every balance that results from executing the order is within the range (-263, 263).
-
After the transaction is executed one of the following must be true:
-
The resulting position is well leveraged, that is: \(\text{total_value} \ge \text{total_risk}\)
-
Total value per risk (TV/TR) does not decrease after funding is applied, and the position’s total risk decreases or stays the same, which means that for every synthetic asset, \(|\text{new_balance}| \le |\text{old_balance}|\)
-
4. StarkEx includes the transfer in a batch.
If the transfer request is valid, the transfer is included in a batch to be submitted on-chain along with a validity proof.
Implementing a transfer in your application.
To implement transfer functionality in your application, use the add_transaction
API with the Transfer
transaction type.
The StarkEx REST API reference includes all necessary information.
Additional resources
-
StarkEx REST API reference
-
State update for information on the on-chain state update