> ## Documentation Index
> Fetch the complete documentation index at: https://policykit.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Contracts Overview

> Overview of PolicyKit's smart contracts

# Smart Contracts Overview

PolicyKit's on-chain layer consists of Solidity contracts built with [Foundry](https://book.getfoundry.sh/). These contracts store policy configurations, evaluate on-chain rules, and verify off-chain attestations.

The contracts are published as [`@policy-kit/contracts`](https://www.npmjs.com/package/@policy-kit/contracts) on npm, so you can import them directly in your own Solidity projects:

```bash theme={null}
pnpm add @policy-kit/contracts
```

```solidity theme={null}
import { IPolicyEngine } from "@policy-kit/contracts/src/core/IPolicyEngine.sol";
import { IRuleEvaluator } from "@policy-kit/contracts/src/rules/IRuleEvaluator.sol";
```

## Contract Architecture

```mermaid theme={null}
graph TD
  subgraph SA["Smart Account"]
    PG["PolicyGuard<br/>(Guard)"]
    PM["PolicyKit7579Module<br/>(ERC-7579 Validator)"]
  end

  PG --> PE["PolicyEngine<br/>(Core)"]
  PM --> PE

  PE --> T1["Tier 1<br/>Evaluators"]
  PE --> T2["Tier 2<br/>Evaluators"]
  PE --> AV["Attestation<br/>Verifier"]
```

## Core Contracts

| Contract              | Description                                |
| --------------------- | ------------------------------------------ |
| `PolicyEngine`        | Central registry and evaluation dispatcher |
| `PolicyGuard`         | Guard hook for smart accounts              |
| `PolicyKit7579Module` | ERC-7579 validation module                 |
| `AttestationVerifier` | EIP-712 attestation verification           |

## Rule Evaluators

| Contract             | Tier | Description                             |
| -------------------- | ---- | --------------------------------------- |
| `AllowTargetsRule`   | 1    | Whitelist contract addresses            |
| `DenyTargetsRule`    | 1    | Blacklist contract addresses            |
| `AllowSelectorsRule` | 1    | Whitelist function selectors            |
| `DenySelectorsRule`  | 1    | Blacklist function selectors            |
| `MaxValueRule`       | 1    | Cap ETH value per transaction           |
| `SpendLimitRule`     | 2    | Token spending limits with time windows |
| `CooldownRule`       | 2    | Minimum time between transactions       |

## Libraries

| Library          | Description                                           |
| ---------------- | ----------------------------------------------------- |
| `PolicyCodec`    | Encode/decode policy rules for on-chain storage       |
| `CalldataParser` | Parse transaction calldata (target, selector, params) |

## Deployment

Contracts are deployed using Foundry's deployment scripts:

```bash theme={null}
cd contracts
forge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast
```

## Development

### Build

```bash theme={null}
forge build
```

### Test

```bash theme={null}
forge test
```

### Gas Report

```bash theme={null}
forge test --gas-report
```
