# Bind a policy

> How to bind, replace or remove a deposit, holder or withdrawal policy on a live vault, and what a policy must satisfy first.

Source: https://docs.trusslabs.io/vaults/guides/bind-a-policy

A policy is a separate contract the vault asks before it lets something happen, such as who may hold its shares.
Binding one to a live vault is a single call at the CRITICAL tier, so holders see it coming. The policy must be
deployed for this vault first.

> **Key points**
>
> - A policy must name this vault and answer to the vault's AccessManager, or the vault refuses it.
> - Binding, replacing and removing a policy each wait the CRITICAL tier, and are the VaultAdmin's alone.
> - Replacing the deposit policy drops the deposit cap, unless the new policy enforces one.
> - A holder or withdrawal policy can be bound at deployment instead, with no wait.

## Steps

1. Deploy the policy against this vault and its AccessManager. Its `vault()` must return this vault and its
   `authority()` the vault's AccessManager.
2. Decide who may change it. A policy's own restricted functions, such as editing a list, answer to the
   vault's AccessManager. Until they are mapped to a role, they answer to the admin role, so only the VaultAdmin
   can call them, each at the CRITICAL tier. Mapping them to another role is itself an admin change at that tier.
3. Schedule the binding on the vault with `setDepositPolicy(policy)`, `setHolderPolicy(policy)` or
   `setWithdrawalPolicy(policy)` (CRITICAL, VaultAdmin).
4. Wait the CRITICAL delay, then execute it.
5. Check that `depositPolicy()`, `holderPolicy()` or `withdrawalPolicy()` on the vault returns the policy. The
   `VaultDepositPolicySet`, `VaultHolderPolicySet` or `VaultWithdrawalPolicySet` event records the change.

## Replacing or removing a policy

The same setter replaces a policy, or removes it when given the zero address. Both wait the CRITICAL tier, like
binding. Without a deposit policy the vault checks nothing on a deposit request, so removing or replacing the
deposit-cap policy removes the cap unless the new policy keeps one.

A policy that reverts, or answers anything other than a clear yes, refuses everyone it is asked about. Test a new
policy's answers before binding it, because undoing a bad one also waits CRITICAL.

## Binding at deployment

The deployer can name a holder and a withdrawal policy when the vault is deployed, or pass the zero address for
none. A policy named there is bound before the vault goes live, through the same checks, without the CRITICAL
wait. It must be deployed first against the vault and AccessManager addresses the factory predicts. The
deposit-cap policy is always bound at deployment.

## Where to read more

| Page | What it covers |
|---|---|
| [Vault policies](https://docs.trusslabs.io/vaults/policies/vault-policies.md) | Where each policy is asked, and what it can refuse |
| [Building a policy](https://docs.trusslabs.io/vaults/policies/building-a-policy.md) | What a policy contract must provide |
| [Using policies for compliance](https://docs.trusslabs.io/vaults/compliance/using-policies.md) | Allowlists, denylists and other uses |
| [Tiers and timelocks](https://docs.trusslabs.io/vaults/roles/tiers-and-timelocks.md) | Scheduling a CRITICAL change |
