Self-Custodial Withdrawals (Escape Hatch)
Derive is a self-custodial exchange, meaning you always have custody of your assets. In the case of exchange failure (including failure or downtime of the trading interface, or off-chain matching engine), there is still a permissionless way to withdraw funds from Derive.
This guide is written assuming you onboarded via the trading interface (app.derive.xyz), and have deposited funds into a trading account (subaccount), which in turn is owned by your Smart Contract Wallet (SCW) deployed when your account was created on Derive’s rollup.
This guide is broken up into several steps.
1. Fund owner wallet with native ETH
Bridge a minimal amount (0.0005) of ETH from mainnet to Derive using the superbridge app. This is used for gas to execute transactions on Derive’s layer-2 rollup: https://superbridge.app/?fromChainId=1&toChainId=957
2. Withdraw SubAccounts from Derive Matching system
2.1 Get your SCW (Derive Wallet) address
Call: getAddress(<Owner address>, 0)
This will return your SCW (Derive wallet) address. Save this.
2.2 Get a list of your owned subaccounts
Easier Option:
Find the list of your owned subaccounts from the interface.
Harder Option:
Add your SCW to the following query and post it in your browser URL. This will return a list of subaccounts that your SCW has ever historically deposited to the matching contract.
Example response, you may see more than one row:
Under “topics” you will see your subaccountId in hexadecimal as the 2nd “topic”. E.g.
2.3 Start your subaccount withdrawal
2.3.1 Get the calldata for the withdrawal
2.3.2 Execute initiate withdrawal
Navigate to your SCW page on the explorer. Then go to Contract → Read/Write proxy → Write → execute
Connect your owner wallet
Call execute with:
Repeat for every subaccount
This removes your subaccount from the exchange and starts a 30min cooldown before the next step can proceed
2.3.3 Complete the subaccount withdrawal
After waiting 30min, follow the same steps as 2.3.2, but use the completeWithdrawAccount calldata. This will move your subaccounts from the matching system to be held by your SCW.
3. Withdraw collaterals from subaccount
This step will be tricky if you hold multiple different collateral assets but still have perp or short option positions. If you have open positions, it may be easiest to just borrow the max amount of USDC to withdraw, and then return later when you get liquidated to withdraw the remainder.
After this you should have one or more assets held by the SCW, withdrawn from the protocol, that can now be bridged
3.1a Get Available collaterals
3.1b Withdraw maximum possible USDC
4. Bridge from derive
Withdrawing from derive can be done via a “wrapper” that converts some of the tokens to ETH to pay the bridging fee.
You will have to execute 2 functions for each token. Firstly approve and then the bridge.
For each token in step 3 (Find these on your SCW page under the “Tokens” drop down):
Updated about 1 month ago
