Withdraw Collateral
Take a whole pledged position back, with its fees. A debt-free account can always leave; an account with debt can leave while it stays healthy and the withdraw-with-debt checks pass.
Overview
A withdrawal closes one record: the proxy withdraws exactly the record's credited units from the CDP Spoke, the AaveAdapter burns them, Collateralization releases the record and its USD charge, and the LPVault returns the whole position to the depositor of record. Only the wallet whose proxy holds the record, which is always its depositor, can withdraw it. Nobody else, including governance and keepers, can move a position that has a record.
| Call | Use |
|---|---|
withdraw | Returns one whole record's position. Debt-free it is ungated; with debt it runs the withdraw-with-debt checks. |
repayAllAndWithdraw | Repays the named debt reserves in full, requires no debt left, then makes a debt-free withdrawal, in one call. |
releaseZeroCredit | Returns a position whose record has 0 credited units left, normally after a full seizure. |
removeLiquidity | Removes part of a record's units while the position stays pledged (see Manage Loans). |
Partial removal is described in Manage Loans.
The Withdraw Call
withdraw(uint256 marketId, PositionRef position, uint256 units, uint256 deadline, uint256 minHealthFactor)- The position reference names the record's position by integration ID and position key. One position per call.
- The units must equal the record's credited units after reconcile, read from Collateralization's previewRelease. The whole position is released, never part of it.
- The deadline is a timestamp: 600 seconds is 300 Base blocks or 50 Ethereum blocks.
- The minimum health factor applies only when debt remains; 0 means no extra bound.
- The market's vault token, Spoke and reserve come from the Adapter's own binding and the vault token's immutables, with no MarketRegistry read, so a faulty registry can neither block the exit nor substitute another token.
Debt-Free and With-Debt Withdrawals
The account is debt-free when Aave reports a borrow count of 0 for the proxy. Aave's count covers every reserve the account owes, so a registry that lists no debt reserves cannot make an indebted account look debt-free.
Debt-free
No pause state, circuit breaker, address freeze, sequencer gate, price, MarketRegistry view or RiskModule check is read. A debt-free withdrawal works in every Avana state and every price state. Only Aave can stop it, by pausing the vault-token reserve or halting the CDP Spoke. When the last record leaves, the reserve is disabled as collateral for the proxy.
With debt
Collateral that leaves an indebted account can no longer be seized, so a withdrawal with debt is closed whenever liquidation of the account could not run or a breaker stops new exposure. The checks are the borrow checks without the Offboarding and Aave-frozen refusals:
| Check | Rule | Error |
|---|---|---|
| Pause state | The home Hub is not Paused (either reason). A Frozen Hub allows withdraw-with-debt with every check. | ApplicationPaused |
| Address freeze | The wallet is not frozen. A frozen wallet can still leave through repayAllAndWithdraw or after repaying. | AddressIsFrozen |
| Sequencer gate (Base) | The sequencer is up and restarted more than 3,600 seconds ago. | SequencerDown / SequencerGrace |
| Prices | The market is Live with every collateral feed no older than its heartbeat plus 1,800 seconds and its second source agreeing; every debt reserve is on its recorded source and, unless GHO, priced by a Live, fresh DebtOracle. | PriceNotLive / PriceTooOld / DebtPriceTooOld / SecondSourceDisagrees |
| Aave reserves | The vault-token reserve and every owed debt reserve are not paused on Aave. | AaveReservePaused / DebtReservePaused |
| Liquidation can run | At least one active committed operator on the chain, and a usable swap route from every pool token to every owed debt asset. | LiquidationHalted / DebtLiquidationHalted |
| Configuration drift | Aave's configuration and the standard-Spoke settings match what Avana expects, and Hub shares equal assets. | ConfigDrift / HubSharesNotEqualAssets |
| Circuit breakers | Neither the market breaker nor the debt breaker of any owed reserve is tripped. | BreakerTripped / DebtBreakerTripped |
| Health after the withdrawal | Aave's own check requires HF at least 1.00. Then the rescue-excluded HF must be at least the largest of 1.00, minHealthFactor and the market's hard floor (off by default). | HealthFactorBelowThreshold / HealthFactorTooLow |
The health check runs after the record is released, with the account's remaining rescue units valued at zero. In an Offboarding market Aave applies the ramped-down liquidation threshold, so a withdrawal with debt needs more remaining collateral as the ramp advances.
Repay All and Withdraw
repayAllAndWithdraw(uint256 marketId, PositionRef position, uint256 units, uint256[] debtReserveIds, uint256[] maxRepaySpends, uint256 deadline)For each named debt reserve the call runs a repay-all with the caller as payer and borrower, under that reserve's own cap, and refunds the unused part in the same call. The app sets each cap, and its approval, to a repay-all quote sized to the deadline. If Aave still reports any debt, the call reverts with DebtRemaining for the first borrowed reserve. Otherwise it makes a debt-free withdrawal.
It reads no pause state, breaker, freeze, sequencer gate, price or MarketRegistry view and calls no RiskModule function. It therefore works under a Frozen or Paused Hub, under any breaker, for a frozen wallet and during a Base sequencer grace window. Any failure reverts all of it.
Zero-Credit Release
releaseZeroCredit(uint256 marketId, PositionRef position, uint256 deadline)When a record has no credited units left, normally after a full seizure, the depositor of record takes the position back with this call. It mints, burns and supplies nothing, makes no Spoke withdrawal and no debt check, and reads no pause state, freeze, breaker or price. It is available in every Avana and Aave state, every sequencer state and in a Closed market. The position returns with its uncollected fees and any liquidity donated to it.
Reconcile on Exit
Inside every withdrawal, zero-credit release and partial removal, Collateralization compares the account's credited units with its Aave supply. Supply can only fall below credit if a seizure was never settled. In every normal exit the two match and nothing is written.
When units are missing, Collateralization debits the account's records largest-first by the missing amount, unwinds those units into the market's pending-settlement balance and releases their charge. The seized vault tokens in circulation stay backed by the tokens in that balance. A record debited to 0 stays open, so its depositor can still collect fees and use releaseZeroCredit. Anyone can later call LPVaultSwap's settlePending, which burns the stranded vault tokens, converts the pending tokens into the market's settlement debt asset and funds that asset's Avana Umbrella (Coverage Spoke). The borrower and the caller receive nothing from it.
What You Receive
- The position itself: for Uniswap v3 and Slipstream, the NFT, transferred from the LPVault to the depositor of record without a receiver hook. A Slipstream NFT returns unstaked, as it was pledged.
- Its uncollected fees and any principal owed to it. The withdrawal neither collects nor unwinds, so these travel with the NFT and the depositor collects them directly from the AMM protocol.
- Any liquidity donated to the position and never re-credited.
- The record's USD charge is released from the market's budget (slice part first, then Regular) and from the token and depositor counters.
Availability by State
For a withdrawal with debt, the most restrictive state over the account's market and every debt reserve it owes applies. No Avana pause, breaker or freeze reaches pending settlement or liquidation in any row.
| State | Debt-free withdraw, remove or repayAllAndWithdraw | Withdraw or remove with debt | Zero-credit release |
|---|---|---|---|
| Hub None or Frozen | Allowed | Allowed | Allowed |
| Hub Paused (General or MintPathSuspect) | Allowed | Refused (ApplicationPaused) | Allowed |
| Wallet frozen | Allowed | Refused (AddressIsFrozen) | Allowed |
| Market breaker, or debt breaker of an owed reserve, tripped | Allowed | Refused | Allowed |
| Base sequencer Down | Allowed once included | Refused (SequencerDown) | Allowed once included |
| Base sequencer Grace (3,600 s after restart) | Allowed | Refused (SequencerGrace) | Allowed |
| Drifting, Cached or Expired, or stale feeds, or a disagreeing second source | Allowed | Refused | Allowed |
| Rescue units carry the health factor | Allowed | Refused (HealthFactorTooLow) | Allowed |
| Market Offboarding, or vault-token reserve frozen on Aave | Allowed | Allowed, against the ramped liquidation threshold | Allowed |
| Market Closed | Allowed forever, no price read | Not reachable: a Closed market has no debt | Allowed |
| Configuration drift, Hub shares not equal to assets | Allowed | Refused | Allowed |
| No active committed operator, or no swap route to an owed debt asset | Allowed | Refused | Allowed |
| A debt reserve of the account paused on Aave | Allowed | Refused (DebtReservePaused) | Allowed |
| Vault-token reserve paused on Aave, or the Hub halts the CDP Spoke | Refused by Aave | Refused by Aave | Allowed |
| Faulty MarketRegistry | Allowed | Still gated: the debt decision comes from Aave | Allowed |
| Unsettled earlier seizure in the market | Allowed after reconcile | Allowed after reconcile | Allowed after reconcile |
Events
- With debt: LPOracle and DebtOracle state events when a poke changes stored state.
- Hub Remove and Spoke Withdraw; the vault token's Transfer to the proxy and its burn.
- CollateralDisabled, when a debt-free account's last record leaves the reserve.
- RecordDebited and SeizureReconciled, only when reconcile on exit found missing units.
- The NFT's Transfer to the depositor, then LPVault PositionReturned and Collateralization CollateralReleased.
CollateralWithdrawn(wallet, marketId, vaultToken, positionKey, units, withDebt, healthFactorAfter)
The health factor in CollateralWithdrawn is the maximum uint256 value on the debt-free branch. repayAllAndWithdraw first emits one Repaid per reserve that moved funds.
Failures
Every failure reverts the whole transaction; the record, counters, tokens and position stay as they were.
| Error | Cause |
|---|---|
UnitsMismatch | The units argument is not the record's credited units after reconcile. Read it from previewRelease. |
ZeroAmount | Units of 0; a record with no credited units uses releaseZeroCredit. |
NoProxy / UnknownMarket / IntegrationMismatch | The wallet has no account in the market, or the position reference is not the market's. |
RecordNotFound / NotRecordProxy / InvalidVaultToken | No open record for the position in this account and market. |
ApplicationPaused | Debt remains and the home Hub is Paused. |
AddressIsFrozen | Debt remains and the wallet is frozen. |
SequencerDown / SequencerGrace | Debt remains and the Base sequencer is down or within its grace window. |
PriceNotLive / PriceTooOld / DebtPriceTooOld / SecondSourceDisagrees | Debt remains and a price is not usable. |
BreakerTripped / DebtBreakerTripped / LiquidationHalted / ConfigDrift | Debt remains and another RiskModule gate fails. |
HealthFactorBelowThreshold | Aave refuses a withdrawal that would leave its health factor below 1.00. |
HealthFactorTooLow | Debt remains and the rescue-excluded health factor is below the floor or minHealthFactor. |
DebtRemaining | repayAllAndWithdraw left debt on a reserve the call did not name. |
LengthMismatch | The reserve and cap arrays differ in length. |
NotDepositor / RecordHasCredit | A zero-credit release by someone other than the depositor, or for a record that still has credited units. |
PoolLocked | Reconcile on exit needed to unwind units while the pool was inside its own callback. |
BackingMismatch | The market's backing gap changed; the whole call reverts. |
ReservePaused / SpokeHalted / SpokeNotActive | Aave blocks the withdrawal; handled by an emergency playbook with the Aave Guardian. |
Worked Example
- The app reads getAccount and getPriceState: market Live, and removing keyB leaves CF-weighted $16,000 and HF 1.2309.
- Carol calls withdraw(3, (I, keyB), 2,500,000,000, now + 600, 1.20e18). The units come from previewRelease.
- The account has debt (borrow count 1), so the gates run: Hub not Paused, Carol not frozen, then the RiskModule pre-check finds both oracles Live and no breaker tripped.
- The proxy withdraws 2,500,000,000 units from the Spoke and the Adapter burns them.
- Collateralization closes record keyB and releases its $5,000 charge. The LPVault returns the NFT to Carol with every fee it has accrued.
- Health check: HF = 16,000 / 12,998.70 = 1.2309, above max(1.00, 1.20).
- Events PositionReturned, CollateralReleased and CollateralWithdrawn with HF 1,230,892,320,001,230,892. Carol now holds one record, collateral $20,000.
Failing case and the debt-free route
- Withdrawing key1 instead leaves CF-weighted $4,000 and HF 4,000 / 12,998.70 = 0.3077, so Aave reverts with HealthFactorBelowThreshold.
- On a Base market, 1,200 seconds after a sequencer restart, withdraw reverts with SequencerGrace. repayAllAndWithdraw(3, (I, keyB), 2,500,000,000, [r_USDC], [cap], now + 600) repays the USDC debt and returns the NFT at once, because a debt-free exit reads no gate.
- The same withdrawal while the Hub is Paused, while Carol is frozen, or while the market's pool-share breaker is tripped reverts with ApplicationPaused, AddressIsFrozen or BreakerTripped; repayAllAndWithdraw succeeds in each of these states. Under a Frozen Hub the withdrawal with debt succeeds.
How the repay-all cap is quoted is explained in Repay Loans.
