> For the complete documentation index, see [llms.txt](https://docs.sail.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sail.money/protocol/architecture/mandate-factory.md).

# MandateFactory

`MandateFactory` is a UX orchestrator. It bundles the two steps of attaching a configurable permission — `template.configure(...)` then `kernel.registerPermission(...)` — into a single transaction, and forwards the registration fee with an automatic refund of any excess. License: GPL-2.0-or-later.

## It holds no trust

The factory has **no privilege**. Every inner call is independently signature-authenticated:

* `configure` carries an EIP-712 signature from the account's Permission Signer (verified by the template against the kernel).
* `registerPermission` carries an EIP-712 signature from the Permission Signer (verified by the kernel).

So the factory's only value is **bundling, fee forwarding, and a canonical entry point** for tooling. Anyone can deploy a template implementing `IConfigurablePermission` and use it with the factory immediately — no allowlist, no registry. Its `receive()` accepts ETH **only from the kernel** (the fee refund), preventing balance-inflation games against the refund accounting.

## Operations

| Function                 | What it does                                                                               |
| ------------------------ | ------------------------------------------------------------------------------------------ |
| `attach`                 | `configure` one template, then `registerPermission`, one tx; refunds fee excess.           |
| `attachBatch`            | `configure` N templates, then `registerPermissions` atomically.                            |
| `reconfigure`            | re-`configure` a template's params for an account (no kernel touch).                       |
| `replace`                | `configure` a new template, then `replacePermission` (atomic kernel swap).                 |
| `deployAndAttach`        | clone a standalone template (EIP-1167), initialize it, then `registerPermission` — one tx. |
| `detach` / `detachBatch` | `revokePermission(s)` for an account.                                                      |

## Deterministic clones

`deployAndAttach` deploys an EIP-1167 minimal-proxy clone of a logic contract via `Clones.cloneDeterministic`, with the salt **namespaced by `msg.sender`** (`keccak256(abi.encode(msg.sender, salt))`) to prevent cross-caller salt squatting. Predict the address beforehand with `predictCloneAddress(impl, salt)` — **from the same EOA** that will send `deployAndAttach`, because of the namespacing. After init, a liveness check (`CloneInitializable.initialized()`) guards against a clone that failed to initialize.

## Events

`Attached`, `BatchAttached`, `Reconfigured`, `Replaced`, `Detached`, `BatchDetached`, and `CloneDeployedAndAttached(account, impl, clone, salt)`.

{% hint style="info" %}
Using the factory is optional. You can always call the kernel's `registerPermission` / `replacePermission` / `revokePermission` directly — the factory just saves a transaction when a template also needs configuring.
{% endhint %}


---

# 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 current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sail.money/protocol/architecture/mandate-factory.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
