# MIMOProxyGuard

As previously mentioned, the management of MIMOProxy's permissions has been delegated to the `MIMOProxyGuard`, which is deployed through the Openzeppelin Clones library in the `MIMOProxyFactory` for each `MIMOProxy`.

Having the permission management outside the `MIMOProxy` reduces the risk of storage collision, and having a separate contract for it enables easy permission clearing. In the event of an ownership transfer of the `MIMOProxy`, a new owner will likely want to clear existing permissions for security reasons (e.g., malicious action contracts may have been granted permissions before the transfer). However, due to the granularity of permissions, it would be difficult and expensive to remove them one by one. With the `MIMOProxyGuard`, a user can simply clone a new `MIMOProxyGuard`, which will not have any permissions set.

### Write Methods

#### `initialize(address proxyFactory, address proxy)`

Initializer function to set state variables upon cloning.

| Param Name     | Type    | Description                                       |
| -------------- | ------- | ------------------------------------------------- |
| `proxyFactory` | address | `MIMOProxyFactory` address                        |
| `proxy`        | address | Address of the `MIMOProxy` linked to the contract |

#### `setPermission(address envoy, address target, bytes4 selector, bool permission)`

Gives or takes a permission from an envoy to call the given target contract and function selector on behalf of the owner.

Requirements :&#x20;

* Caller must the owner of the set `MIMOProxy` or the `MIMOProxy`

| Param Name   | Type    | Description                                          |
| ------------ | ------- | ---------------------------------------------------- |
| `envoy`      | address | The address of the envoy account                     |
| `target`     | address | The address of the target contract                   |
| `selector`   | bytes4  | The 4 bytes function selector on the target contract |
| `permission` | bool    | The boolean permission to set                        |

### View Methods

#### `getPermission(address envoy, address target, bytes4 selector)`

Returns the permission for specific `envoy`, `target` and `selector`.

**Call Params**

| Name       | Type     | Description                                          |
| ---------- | -------- | ---------------------------------------------------- |
| `envoy`    | address  | The address of the envoy account                     |
| `target`   | target   | The address of the target contract                   |
| `selector` | selector | The 4 bytes function selector on the target contract |

**Return Values**

| Name         | Type | Description                                                        |
| ------------ | ---- | ------------------------------------------------------------------ |
| `permission` | bool | `true` if envoys is allowed to perform the call and `false` if not |

#### `getProxy()`

Returns the address of the MIMOProxy associated with the `MIMOProxyGuard` contract.
