withdraw
---
config:
theme: dark
---
sequenceDiagram
title Withdrawal Flow
participant MySQL
participant Sequencer as Sequencer
actor A1 as User/SDK
participant P1 as Relayer (Off-chain)
participant CH as ClearingHouse
A1 ->> Sequencer: User submits withdrawal request
Sequencer ->> Sequencer: Add to Sequencer Queue
Sequencer ->> MySQL: Query position data
MySQL ->> Sequencer: Return position data
Sequencer ->> Sequencer: Risk check performed
alt Risk check fails
Sequencer ->> A1: Rejected: Withdraw violates IM
else Risk check passes
Sequencer ->> MySQL: Update user's withdraw in SQL
Sequencer ->> CH: Process User Withdraw (via Relayer)
Note over CH: Transfer amount = Withdrawal amount - Estimated gas cost
Note over CH: Estimated gas cost is transferred to exchange account
CH ->> CH: Transfer Asset, Update Ledger, emit Withdraw Event
opt Transaction Fails
P1 ->> Sequencer: Notify transaction failure
Sequencer ->> MySQL: Revert withdraw in SQL
end
end