The withdrawal queue system is a critical component that manages and optimizes asset withdrawals across multiple chains and vaults. It maintains two fixed-size queues:
Local queue for same-chain vaults
Cross-chain queue for vaults on other networks
Queue Management
Queue Structure
// Fixed size queues for withdrawal prioritizationuint256[WITHDRAWAL_QUEUE_SIZE] public localWithdrawalQueue;uint256[WITHDRAWAL_QUEUE_SIZE] public xChainWithdrawalQueue;
Queue Registration
When a new vault is added, it's automatically registered in the appropriate queue based on its chain:
functionaddVault(uint64 chainId,uint256 superformId,address vault,// ... other params) externalonlyRoles(ADMIN_ROLE) {// Validate and store vault dataif (chainId == THIS_CHAIN_ID) {// Add to local queuefor (uint256 i =0; i != WITHDRAWAL_QUEUE_SIZE; i++) {if (localWithdrawalQueue[i] ==0) { localWithdrawalQueue[i] = superformId;break; } } } else {// Add to cross-chain queuefor (uint256 i =0; i != WITHDRAWAL_QUEUE_SIZE; i++) {if (xChainWithdrawalQueue[i] ==0) { xChainWithdrawalQueue[i] = superformId;break; } } }}
Withdrawal Processing
State Tracking
structProcessRedeemRequestCache {// Per-chain trackinguint256[WITHDRAWAL_QUEUE_SIZE][N_CHAINS] dstVaults; // Target vaultsuint256[WITHDRAWAL_QUEUE_SIZE][N_CHAINS] sharesPerVault; // Shares to withdrawuint256[WITHDRAWAL_QUEUE_SIZE][N_CHAINS] assetsPerVault; // Expected assetsuint256[N_CHAINS] lens; // Vaults per chain// Global trackinguint256 amountToWithdraw; // Remaining to withdrawuint256 sharesFulfilled; // Processed sharesuint256 totalClaimableWithdraw; // Available for immediate withdrawaluint256 totalAssets; // Total vault assetsuint256 totalIdle; // Unallocated assetsuint256 totalDebt; // Allocated assetsuint256 assets; // Requested withdrawal// Operation type flagsbool isSingleChain;bool isMultiChain;bool isMultiVault;}
Withdrawal Route Calculation
The route calculator follows a strict priority order:
Check Idle Assets
if (_totalIdle >= cache.assets) {// Fulfill directly from idle cache.totalClaimableWithdraw = cache.assets; cache.sharesFulfilled = config.shares;return;}
function_prepareWithdrawalRoute(ProcessRedeemRequestCachememory cache) privateview {// Process local queue first_exhaustWithdrawalQueue(cache, localWithdrawalQueue,false);// Process cross-chain queue if needed_exhaustWithdrawalQueue(cache, xChainWithdrawalQueue,true);}