# TokenF Modules

## Modules Architecture

Modules are the backbone of the TokenF framework regulatory mechanics. All rules, requirements, and compliance for KYC and various token transfers can be customized via modular plugin-based architecture.

In the vanilla TokenF version there are two main types of modules:

1. KYC modules
2. Regulatory modules

The KYC modules are responsible for any KYC-related compliance checks while Regulatory modules are used to perform conditional transfer limits / token balance obligations / operational limits / etc.

Modules represent quite a complex set of smart contracts that are related through inheritance and plugged in through composition to the aforementioned `RegulatoryCompliance` and `KYCCompliance` facets.

<figure><img src="/files/7JREvbKwqNL5cEDPbngR" alt=""><figcaption><p>Pic. 2 TokenF modules architecture</p></figcaption></figure>

The diagram depicts the relationships between contracts within the TokenF modules architecture. The bulk of the logic is implemented in the `AbstractModule` that `AbstractKYCModule` and `AbstractRegulatoryModule` extend. Certain modules will then inherit from `AbstractKYCModule` and `AbstractRegulatoryModule` contracts to define handlers, their relation to handler topics, context keys construction, and perform the required checks.

## AbstractModule Contract

The `AbstractModule` contract is the basis for writing new modules for the TokenF framework. The contract implements the logic of handler topics management, the definition of handlers, and stores the “weak reference” to the AssetF token contract itself (for certain operations that should only be called by the token).\
\
Moreover, the `AbstractModule` contract defines an interface through which the TokenF managers will “speak” with the module.

## AbstractKYCModule Contract

The `AbstractKYCModule` contract implements the `AbstractModule` interface and extends it by introducing the `isKYCed` function. This function is used by the `KYCCompliance` AssetF facet to authorize the user of the token. By default, the context key is `keccak256(function selector)`.

## AbstractRegulatoryModule Contract

The `AbstractRegulatoryModule` contract is very similar to the `AbstractKYCModule` in terms that it also implements the `AbstractModule` interface. However, two new functions are introduced: `canTransfer` and `transferred`. `RegulatoryCompliance` AssetF facet will call them to perform regulatory compliance checks. Similar to `AbstractKYCModule`, the default context key is `keccak256(function selector)`.


---

# Agent Instructions: 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 current page URL with the `ask` query parameter:

```
GET https://tokenf.gitbook.io/tokenf/deep-dive/tokenf-modules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
