# MetaVaultsRegistryV2



The registry stores configuration for each MetaVault Safe on its chain. A reader looks up a known key with the getter for its value type. For example, the `core.wrapper` address identifies the share token and the contract that handles deposit and redemption requests. [Registry addresses](/docs/metavaults/deployed-contracts)

<Mermaid
  chart="flowchart TB
    reader[&#x22;Integration&#x22;] -->|&#x22;Vault Safe + hash of core.wrapper&#x22;| registry[&#x22;Registry getAddress&#x22;]
    registry -->|&#x22;Returns&#x22;| wrapper[&#x22;Wrapper address&#x22;]"
/>

## Read a value [#read-a-value]

Every getter below takes the same two arguments. `vault` is the address of the vault Safe on this chain. `key` is a `bytes32` hash of the exact UTF-8 key name, including punctuation and case.

```solidity
bytes32 key = keccak256(bytes("core.wrapper"));
bool configured = registry.isKeySet(vaultSafe, key);
address wrapper = registry.getAddress(vaultSafe, key);
```

| Function                                  | Return type | Meaning                                                                                                                                        |
| ----------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `getAddress(address vault, bytes32 key)`  | `address`   | Account or contract named by the key. For example, `core.vault` identifies the infrastructure vault and `core.wrapper` identifies its wrapper. |
| `getString(address vault, bytes32 key)`   | `string`    | Text such as the display name under `metadata.name`.                                                                                           |
| `getUint256(address vault, bytes32 key)`  | `uint256`   | Unsigned quantity in the unit defined for the key. For example, `settlement.minInterval` is in seconds.                                        |
| `getBytes(address vault, bytes32 key)`    | `bytes`     | Stored bytes. Interpret the payload according to the key's schema.                                                                             |
| `getBool(address vault, bytes32 key)`     | `bool`      | Boolean flag.                                                                                                                                  |
| `isKeySet(address vault, bytes32 key)`    | `bool`      | Whether the stored bytes have nonzero length. A stored numeric zero or `false` counts as set. An empty raw bytes value counts as unset.        |
| `isKeyLocked(address vault, bytes32 key)` | `bool`      | Whether the vault itself is prevented from writing the key.                                                                                    |
| `authority()`                             | `address`   | The access manager that authorizes administrative calls to this registry.                                                                      |

An unset key returns the getter's zero value. Use the getter matching the stored type. A getter for a different type may return a misleading value or revert during decoding. To discover keys for a Safe, index the registry's typed write events for that Safe.

## Write configuration [#write-configuration]

The vault Safe can set an unlocked key in its own namespace. A caller authorized by the registry's access manager can also write, including to a locked key. Each scalar setter takes `vault`, `key` and the new typed `value`, returns no value, and emits the event corresponding to the overload.

| Setter signature               | Event                         |
| ------------------------------ | ----------------------------- |
| `set(address,bytes32,string)`  | `StringSet(vault,key,value)`  |
| `set(address,bytes32,address)` | `AddressSet(vault,key,value)` |
| `set(address,bytes32,uint256)` | `Uint256Set(vault,key,value)` |
| `set(address,bytes32,bytes)`   | `BytesSet(vault,key,value)`   |
| `set(address,bytes32,bool)`    | `BoolSet(vault,key,value)`    |

For several keys in one transaction, call `set(address vault, RegistryEntry[] entries)`. Entries are applied in order. A failure reverts the entire batch.

```solidity
struct RegistryEntry {
    bytes32 key;
    bytes value;
    uint8 valueType;
    bool lock;
}
```

| Field       | Type      | Meaning                                                                                                                 |
| ----------- | --------- | ----------------------------------------------------------------------------------------------------------------------- |
| `key`       | `bytes32` | Hash of the key name in this vault's namespace.                                                                         |
| `value`     | `bytes`   | Raw payload for a bytes entry. For the other four types, supply `abi.encode(typedValue)`.                               |
| `valueType` | `uint8`   | `0` string, `1` address, `2` uint256, `3` bytes, `4` bool. Selects the typed event.                                     |
| `lock`      | `bool`    | If true, lock this key after setting it and emit `KeyLocked` when newly locked. False preserves its current lock state. |

A self-write to a locked key reverts with `KeyIsLocked(key)`. An unauthorized write to another vault’s namespace reverts. An authorized administrative write to a locked key also emits `ForceSetEntry(vault,key,valueType)`.

## Manage a lock [#manage-a-lock]

The access manager controls `lockKey(address vault, bytes32 key)` and `unlockKey(address vault, bytes32 key)`. They take the same vault and key as the getters, return no value and emit `KeyLocked(vault,key)` or `KeyUnlocked(vault,key)`. Unauthorized calls revert.
