Withdrawal

Step 1: Off-Chain Withdrawal Request Initiated by the User

The user submits a withdrawal request to the off-chain application.
Here we have a slight difference between the spot trading and perpetual flavors of StarkEx. On StarkEx for perpetual, withdrawal is a signed request (in order to ensure a malicious operator can't use this flow in order to steal the maintenance margin).
On StarkEx for spot trading this request is not signed by the user, as there is no potential for funds-stealing.

Step 2: Off-Chain Transfer Transaction (Only for spot trading)

In StarkEx for spot trading, starting v4.0, there is no on-chain registration. This means that the registration of the Ethereum address must happen off-chain. This is implemented using the transfer transaction as follows:
A transfer request, signed by the user, moves the funds from the user's Vault to another off-chain Vault, which is identified with the user's Ethereum address instead of the starkKey.

Step 3: Off-Chain Withdrawal Transaction

The off-chain app checks the validity of the withdrawal request according to its business logic and the relevant vaultId state. If it is valid, it sends the off-chain withdrawal transaction to the StarkEx service.

Step 4: Withdrawal Included in a Batch

StarkEx verifies that the withdrawal request is valid, according to the relevant business logic statement to be proved, and the relevant vaultId state. If the withdrawal is valid, it is aggregated to a batch to be submitted on-chain along with a validity proof.

Step 5: Funds Move to the Withdrawal Area

Upon performing state update , the StarkEx smart contract moves the relevant funds to the withdrawal area, under the user identity that appears in the withdrawn L2 vault.

Step 6: On-Chain Withdrawal Transaction

Once the funds are in the withdrawal area, the user the funds are belonged to under can make an on-chain call to withdraw the funds to any recipient. For more info, see withdrawals
Last modified 28d ago