> For the complete documentation index, see [llms.txt](https://docs.talus.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.talus.network/reference/move/nexus_policy/policy.md).

# nexus\_policy::policy

* [Struct `Policy`](#struct-policy)
* [Enum `Symbol`](#enum-symbol)
* [Constants](#constants)
* [Function `witness_symbol`](#function-witness_symbol)
* [Function `uid_symbol_from_uid`](#function-uid_symbol_from_uid)
* [Function `witness_symbol_from_name`](#function-witness_symbol_from_name)
* [Function `new`](#function-new)
* [Function `new_linear`](#function-new_linear)
* [Function `id`](#function-id)
* [Function `data`](#function-data)
* [Function `data_mut`](#function-data_mut)
* [Function `dfa`](#function-dfa)
* [Function `state`](#function-state)
* [Function `state_index`](#function-state_index)
* [Function `configured_dfa`](#function-configured_dfa)
* [Function `is_accepting`](#function-is_accepting)
* [Function `reset`](#function-reset)
* [Function `register`](#function-register)
* [Function `register_uid`](#function-register_uid)
* [Function `register_for_state`](#function-register_for_state)
* [Function `register_uid_for_state`](#function-register_uid_for_state)
* [Function `add_symbol`](#function-add_symbol)
* [Function `add_witness_symbol`](#function-add_witness_symbol)
* [Function `add_uid_symbol`](#function-add_uid_symbol)
* [Function `add_state`](#function-add_state)
* [Function `set_transition`](#function-set_transition)
* [Function `set_accepting`](#function-set_accepting)
* [Function `borrow_config`](#function-borrow_config)
* [Function `borrow_config_for_uid`](#function-borrow_config_for_uid)
* [Function `borrow_mut_config`](#function-borrow_mut_config)
* [Function `borrow_mut_config_for_uid`](#function-borrow_mut_config_for_uid)
* [Function `borrow_state_config`](#function-borrow_state_config)
* [Function `borrow_state_config_for_uid`](#function-borrow_state_config_for_uid)
* [Function `borrow_mut_state_config`](#function-borrow_mut_state_config)
* [Function `borrow_mut_state_config_for_uid`](#function-borrow_mut_state_config_for_uid)
* [Function `advance_with_witness`](#function-advance_with_witness)
* [Function `advance_with_uid`](#function-advance_with_uid)
* [Function `has_witness_symbol`](#function-has_witness_symbol)
* [Function `has_witness_config`](#function-has_witness_config)
* [Function `has_uid_config`](#function-has_uid_config)
* [Function `remove_config`](#function-remove_config)
* [Function `remove_config_for_uid`](#function-remove_config_for_uid)
* [Function `remove_state_config`](#function-remove_state_config)
* [Function `remove_state_config_for_uid`](#function-remove_state_config_for_uid)

### Struct `Policy`

Policy couples a configured DFA with caller defined payload and transition metadata.

```move
public struct Policy<T: store> has key, store
```

<details>

<summary>Fields</summary>

[`id`](#nexus_policy_policy_id)`: sui::object::UID`[`dfa`](#nexus_policy_policy_dfa)`:` [`nexus_policy::automaton::ConfiguredAutomaton`](/reference/move/nexus_policy/automaton.md#nexus_policy_automaton_ConfiguredAutomaton)`<u64,` [`nexus_policy::policy::Symbol`](#nexus_policy_policy_Symbol)`>`[`state_index`](#nexus_policy_policy_state_index)`: u64`[`data`](#nexus_policy_policy_data)`: T`

</details>

#### Enum `Symbol`

DFA alphabet symbol for policies: either a witness TypeName or a concrete sui::object::ID.

```move
public enum Symbol has copy, drop, store
```

<details>

<summary>Variants</summary>

Variant `Witness0: std::type_name::TypeName`Variant `Uid0: sui::object::ID`

</details>

#### Constants

Witness symbol not present in the DFA alphabet.

```move
#[error]
const ESymbolNotInAlphabet: vector<u8> = b"Witness not present in policy alphabet";
```

#### Function `witness_symbol`

Construct a symbol from a witness type.

```move
public fun witness_symbol<W: drop>(): nexus_policy::policy::Symbol
```

#### Function `uid_symbol_from_uid`

Construct a symbol from a specific sui::object::ID.

```move
public fun uid_symbol_from_uid(uid: &sui::object::UID): nexus_policy::policy::Symbol
```

#### Function `witness_symbol_from_name`

Helper to create a witness symbol from a precalculated type name.

```move
public fun witness_symbol_from_name(name: std::type_name::TypeName): nexus_policy::policy::Symbol
```

#### Function `new`

Instantiate a policy with the provided DFA and payload.

```move
public fun new<T: store>(dfa: nexus_policy::automaton::DeterministicAutomaton<u64, nexus_policy::policy::Symbol>, data: T, ctx: &mut sui::tx_context::TxContext): nexus_policy::policy::Policy<T>
```

#### Function `new_linear`

Build a policy that enforces a linear sequence of symbols.

```move
public fun new_linear<T: store>(sequence: &sui::table_vec::TableVec<nexus_policy::policy::Symbol>, data: T, ctx: &mut sui::tx_context::TxContext): nexus_policy::policy::Policy<T>
```

#### Function `id`

Policy object ID.

```move
public fun id<T: store>(policy: &nexus_policy::policy::Policy<T>): &sui::object::UID
```

#### Function `data`

Borrow immutable access to the policy payload.

```move
public fun data<T: store>(policy: &nexus_policy::policy::Policy<T>): &T
```

#### Function `data_mut`

Borrow mutable access to the policy payload.

```move
public fun data_mut<T: store>(policy: &mut nexus_policy::policy::Policy<T>): &mut T
```

#### Function `dfa`

Borrow the underlying DFA.

```move
public fun dfa<T: store>(policy: &nexus_policy::policy::Policy<T>): &nexus_policy::automaton::DeterministicAutomaton<u64, nexus_policy::policy::Symbol>
```

#### Function `state`

Current state as stored in the DFA basis.

```move
public fun state<T: store>(policy: &nexus_policy::policy::Policy<T>): u64
```

#### Function `state_index`

Current state index inside the DFA basis.

```move
public fun state_index<T: store>(policy: &nexus_policy::policy::Policy<T>): u64
```

#### Function `configured_dfa`

Configured DFA with transition metadata.

```move
public fun configured_dfa<T: store>(policy: &nexus_policy::policy::Policy<T>): &nexus_policy::automaton::ConfiguredAutomaton<u64, nexus_policy::policy::Symbol>
```

#### Function `is_accepting`

Check if the DFA is in an accepting state.

```move
public fun is_accepting<T: store>(policy: &nexus_policy::policy::Policy<T>): bool
```

#### Function `reset`

Reset the DFA back to its initial state.

```move
public fun reset<T: store>(policy: &mut nexus_policy::policy::Policy<T>)
```

#### Function `register`

Register a configuration payload keyed by the witness `W`.

```move
public fun register<W: drop, T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, config: Config)
```

#### Function `register_uid`

Register a configuration payload keyed by object `uid`.

```move
public fun register_uid<T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, uid: &sui::object::UID, config: Config)
```

#### Function `register_for_state`

Register a configuration scoped to `(`[`state`](#nexus_policy_policy_state)`, W)`.

```move
public fun register_for_state<W: drop, T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64, config: Config)
```

#### Function `register_uid_for_state`

Register a configuration scoped to `(`[`state`](#nexus_policy_policy_state)`, uid)`.

```move
public fun register_uid_for_state<T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64, uid: &sui::object::UID, config: Config)
```

#### Function `add_symbol`

Add a new symbol to the alphabet with transitions for every state.

```move
public fun add_symbol<T: store>(policy: &mut nexus_policy::policy::Policy<T>, symbol: nexus_policy::policy::Symbol, transitions: &sui::table_vec::TableVec<u64>): u64
```

#### Function `add_witness_symbol`

Add a new witness symbol to the alphabet.

```move
public fun add_witness_symbol<W: drop, T: store>(policy: &mut nexus_policy::policy::Policy<T>, transitions: &sui::table_vec::TableVec<u64>): u64
```

#### Function `add_uid_symbol`

Add a new `sui::object::UID` backed symbol to the alphabet.

```move
public fun add_uid_symbol<T: store>(policy: &mut nexus_policy::policy::Policy<T>, uid: &sui::object::UID, transitions: &sui::table_vec::TableVec<u64>): u64
```

#### Function `add_state`

Add a new DFA state together with its outgoing transitions.

```move
public fun add_state<T: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64, accepting: bool, transitions: &sui::table_vec::TableVec<u64>, ctx: &mut sui::tx_context::TxContext): u64
```

#### Function `set_transition`

Update a transition `(`[`state`](#nexus_policy_policy_state)`, symbol) → next`.

```move
public fun set_transition<T: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64, symbol: nexus_policy::policy::Symbol, next: u64)
```

#### Function `set_accepting`

Toggle whether a state is accepting.

```move
public fun set_accepting<T: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64, accepting: bool)
```

#### Function `borrow_config`

Borrow an immutable reference to the configuration keyed by witness `W`.

```move
public fun borrow_config<W: drop, T: store, Config: store>(policy: &nexus_policy::policy::Policy<T>): &Config
```

#### Function `borrow_config_for_uid`

Borrow an immutable reference to the configuration keyed by object `uid`.

```move
public fun borrow_config_for_uid<T: store, Config: store>(policy: &nexus_policy::policy::Policy<T>, uid: &sui::object::UID): &Config
```

#### Function `borrow_mut_config`

Borrow a mutable reference to the configuration keyed by witness `W`.

```move
public fun borrow_mut_config<W: drop, T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>): &mut Config
```

#### Function `borrow_mut_config_for_uid`

Borrow a mutable reference to the configuration keyed by object `uid`.

```move
public fun borrow_mut_config_for_uid<T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, uid: &sui::object::UID): &mut Config
```

#### Function `borrow_state_config`

Borrow an immutable reference to a configuration registered for `(`[`state`](#nexus_policy_policy_state)`, W)`.

```move
public fun borrow_state_config<W: drop, T: store, Config: store>(policy: &nexus_policy::policy::Policy<T>, state: u64): &Config
```

#### Function `borrow_state_config_for_uid`

Borrow an immutable reference to a configuration registered for `(`[`state`](#nexus_policy_policy_state)`, uid)`.

```move
public fun borrow_state_config_for_uid<T: store, Config: store>(policy: &nexus_policy::policy::Policy<T>, state: u64, uid: &sui::object::UID): &Config
```

#### Function `borrow_mut_state_config`

Borrow a mutable reference to a configuration registered for `(`[`state`](#nexus_policy_policy_state)`, W)`.

```move
public fun borrow_mut_state_config<W: drop, T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64): &mut Config
```

#### Function `borrow_mut_state_config_for_uid`

Borrow a mutable reference to a configuration registered for `(`[`state`](#nexus_policy_policy_state)`, uid)`.

```move
public fun borrow_mut_state_config_for_uid<T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64, uid: &sui::object::UID): &mut Config
```

#### Function `advance_with_witness`

Advance the DFA using witness `W` as the symbol. Witness is consumed.

```move
public fun advance_with_witness<W: drop, T: store>(policy: &mut nexus_policy::policy::Policy<T>, witness: W)
```

#### Function `advance_with_uid`

Advance the DFA using an object `uid` as the symbol.

```move
public fun advance_with_uid<T: store>(policy: &mut nexus_policy::policy::Policy<T>, uid: &sui::object::UID)
```

#### Function `has_witness_symbol`

Returns true if the witness symbol exists in the policy alphabet.

```move
public fun has_witness_symbol<W: drop, T: store>(policy: &nexus_policy::policy::Policy<T>): bool
```

#### Function `has_witness_config`

Returns true if a configuration has been registered for witness `W`.

```move
public fun has_witness_config<W: drop, T: store, Config: store>(policy: &nexus_policy::policy::Policy<T>): bool
```

#### Function `has_uid_config`

Returns true if a configuration has been registered for object `uid`.

```move
public fun has_uid_config<T: store, Config: store>(policy: &nexus_policy::policy::Policy<T>, uid: &sui::object::UID): bool
```

#### Function `remove_config`

Removes metadata keyed by witness `W`.

```move
public fun remove_config<W: drop, T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>): Config
```

#### Function `remove_config_for_uid`

Removes metadata keyed by object `uid`.

```move
public fun remove_config_for_uid<T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, uid: &sui::object::UID): Config
```

#### Function `remove_state_config`

Removes metadata for state [`state`](#nexus_policy_policy_state) and witness `W`.

```move
public fun remove_state_config<W: drop, T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64): Config
```

#### Function `remove_state_config_for_uid`

Removes metadata for state [`state`](#nexus_policy_policy_state) and object `uid`.

```move
public fun remove_state_config_for_uid<T: store, Config: store>(policy: &mut nexus_policy::policy::Policy<T>, state: u64, uid: &sui::object::UID): Config
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.talus.network/reference/move/nexus_policy/policy.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
