distributed (effectively cancelled). The vault must exist and must not already be distributed. This function can be called at any time before distribution, regardless of vault state.
Function signature
Parameters
This function takes no arguments. The vault owner is identified bytx-sender.
Return value
Returns
(ok true) on success. All sBTC and USDCx are returned to the owner, both balances are set to u0, and is-distributed is set to true.Returns
(err uint) on failure. See error codes below.Error codes
| Code | Constant | When returned |
|---|---|---|
| u103 | ERR-VAULT-NOT-FOUND | The calling address has no vault |
| u110 | ERR-VAULT-DISTRIBUTED | The vault has already been distributed or cancelled |
How the withdrawal works
The function reads both token balances from the vault and transfers each back to the owner usingas-contract? with with-ft. If a balance is zero, the transfer for that token is skipped:
Effect on vault lifecycle
Afteremergency-withdraw succeeds:
- The vault’s
is-distributedflag is permanently set totrue. sbtc-balanceandusdcx-balanceare both set tou0.- Heirs can no longer call
claimagainst this vault. - The owner can create a new vault from the same address using
create-vault.
| State before withdrawal | Allowed? |
|---|---|
active | Yes |
grace | Yes |
claimable | Yes |
distributed | No — returns ERR-VAULT-DISTRIBUTED |
JavaScript example
postConditionMode: 'allow' is used because the contract transfers from its own balance back to the owner using as-contract?. The actual amount transferred depends on on-chain state at execution time.