Withdrawal

1. The user submits an off-chain withdrawal request
Alice sends a withdrawal request using the off-chain application.
The request is signed in order to prevent a malicious operator from issuing withdrawals at their own discretion, which might put Alice’s position below the maintenance margin, enabling the operator to liquidate the position.
The request includes Alice’s signature and Ethereum address.
2. The application sends a withdrawal transaction to StarkEx
The off-chain application checks the validity of the withdrawal request according to its business logic and the relevant positionId
state. If it is valid, it sends the off-chain withdrawal transaction to the StarkEx service using the add_transaction
API method with the appropriate transaction type:
-
StarkEx Perpetual Trading v1.0:
Withdrawal
-
StarkEx Perpetual Trading v2.0:
WithdrawalToAddress
3. StarkEx includes the withdrawal in a batch
StarkEx verifies that the withdrawal request is valid, according to the relevant business logic statement to be proved, and the relevant positionId
state, ensuring the following:
-
The position has enough funds to withdraw.
-
The withdrawal execution does not put the position below the maintenance margin
-
The position is properly signed by the Stark key that owns the position.
If the withdrawal is valid, it is aggregated to a batch to be submitted on-chain along with a validity proof.
4. StarkEx moves the funds to the withdrawal area
Upon performing a state update, the StarkEx smart contract moves the relevant funds to the withdrawal area, under the Stark key that owns the L2 position from which the funds were withdrawn.
Upon performing a state update, the StarkEx smart contract moves the relevant funds to the withdrawal area, under Alice’s Ethereum address.
5. On-chain withdrawal transaction
Once the funds are in the withdrawal area, Alice can make an on-chain call to register her Ethereum address, using her Stark key, which enables her to reclaim her funds from the withdrawal area to her Ethereum address.
Once the funds are in the withdrawal area, every user can make an on-chain call to withdraw the funds to the Ethereum address the funds are belonged to. The ownerKey
parameter should be the Ethereum address, and not the Stark key.
Additional resources
-
StarkEx REST API reference
-
Structure of a
WithdrawalToAddress
transaction (StarkEx Perpetual Trading 2.0) -
Structure of a
Withdrawal
transaction (StarkEx Perpetual Trading 1.0)