Withdrawing Funds
Introduction
Withdrawals are the counterpart of deposits: they are transactions that move tokens from Cloak (L3) back to the host chain (Scroll).
Cloak offers two ways to withdraw funds:
-
Slow withdrawals: Same mechanism as Scroll: The user submits a withdraw transaction on L3, waits for it to be finalized (validity proof submitted on the host chain), then claims on L2 using a Merkle proof. This withdraw path has guaranteed liquidity from the L2 bridge (since assets are locked 1:1), but having to wait for finalization makes it slow.
-
Fast withdrawals: Alternatively, we offer a sequencer-maintained liquidity bridge. The user submits a withdraw transaction to the host
FastWithdrawVault
contract. The Cloak sequencer checks that the transaction is valid. If the checks are passed, the sequencer immediately releases funds to the user on L2. This withdraw path is very fast, but requires liquidity management from the sequencer, and as such it might fail if the vault is depleted.
We recommend using fast withdrawals for frequent, low-value withdrawals, and slow withdrawals for large-value transactions.
Slow Withdrawals: Withdrawing via the Canonical Bridge
See the full example at withdraw.ts example in the @scroll-tech/cloak-js
package.
In all cases, withdrawals are initiated via the ValidiumERC20Gateway.withdrawERC20AndCall
method.
This will create a withdraw request on L3, enqueuing it on the ValidiumMessageQueue
contract.
Once the transaction has been proven and finalized, the withdraw proof can be queried using a special RPC endpoint:
Finally, the user can claim on L2 using this withdraw proof:
Fast Withdrawals: Withdrawing via the Fast Withdraw Vault
Fast withdrawals are still experimental.
To use the fast withdraw vault, simply send a withdrawal with these parameters:
l2Address
should be theHostFastWithdrawVault
contract.payload
should be the target address on L2.
- Withdraw target address is
HostFastWithdrawVault
, which checks the sequencer permit and releases the funds. - The actual target address should be specified as the withdraw message payload.
- Withdraw target address is
HostFastWithdrawVault
, which checks the sequencer permit and releases the funds. - The actual target address should be specified as the withdraw message payload.
Next, the sequencer will index this withdraw transaction and run some checks.
If all checks pass, the sequencer will sign a permit authorizing the withdrawal, and it submits it on L2, releasing the tokens to the specified l2Address
.