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

# GeodeTypes.sol

> Geode 协议中使用的所有共享结构体、常量和 EIP-712 typehash。

## 概述

`GeodeTypes.sol` 定义所有共享数据结构、协议常量和 EIP-712 typehash。所有结构体在文件级别声明，方便跨代码库导入。

## EIP-712 常量

```solidity theme={null}
// 意图 typehash — 包含 poolId 用于跨池重放保护
bytes32 constant INTENT_TYPEHASH = keccak256(
    "GeodeIntent(bytes32 poolId,address owner,address tokenIn,address tokenOut,"
    "uint256 amountIn,uint256 minAmountOut,uint256 deadline,uint256 nonce)"
);

// Permit2 witness — 不在 PermitTransferFrom 中的字段
bytes32 constant GEODE_WITNESS_TYPEHASH = keccak256(
    "GeodeWitness(bytes32 poolId,address tokenOut,uint256 minAmountOut)"
);
```

## 协议常量

| 常量                              | 值          | 描述               |
| ------------------------------- | ---------- | ---------------- |
| `Q128`                          | `1 << 128` | 价格表示的定点乘数        |
| `ABSOLUTE_MAX_BATCH_SIZE`       | 256        | 每侧意图的硬上限         |
| `DEFAULT_BATCH_INTERVAL`        | 1 个区块      | 结算间最小区块数         |
| `DEFAULT_DIRECT_SWAP_FEE_BPS`   | 30（0.3%）   | 直接交换费用（曲线池；三方分配） |
| `DEFAULT_SETTLEMENT_FEE_BPS`    | 10（0.1%）   | 每个已成交意图输入的费用     |
| `DEFAULT_MAX_GAS_REIMBURSEMENT` | 0.01 ETH   | 每批次上限            |
| `BPS_DENOMINATOR`               | 10,000     | 基点除数             |

## 结构体

### GeodeIntent

用户的签名交易意图：

```solidity theme={null}
struct GeodeIntent {
    PoolId poolId;        // 跨池重放保护
    address owner;        // 意图签名者
    address tokenIn;      // 卖出的代币
    address tokenOut;     // 接收的代币
    uint256 amountIn;     // 卖出数量
    uint256 minAmountOut; // 最低可接受输出（滑点保护）
    uint256 deadline;     // 过期时间戳
    uint256 nonce;        // Permit2 重放保护
}
```

### SettlementResult

出清价格计算的输出：

```solidity theme={null}
struct SettlementResult {
    uint256 clearingPrice;          // Q128 统一价格
    uint256 internalMatch0;         // 内部交叉的 currency0 → 卖家
    uint256 internalMatch1;         // 内部交叉的 currency1 → 买家
    uint256 residualSwapAmount;     // 路由到 AMM/曲线的数量
    bool residualZeroForOne;        // 交换方向
    uint256 buyFees;                // 来自买入输入的结算费用
    uint256 sellFees;               // 来自卖出输入的结算费用
    // 曲线模式字段（标准模式下为零）：
    uint256 curveDispensed;         // 从 Hook 储备分发的代币
    uint256 curveAbsorbed;          // 吸收回 Hook 的代币
    uint256 deployerRoyalty;        // 部署者盈余份额
}
```

### PoolConfig

每池配置——通过 `geodeInitializePool` 设置一次：

```solidity theme={null}
struct PoolConfig {
    uint256 batchInterval;
    uint24 directSwapFeeBps;          // 曲线池 0.3%（三方分配）
    uint256 settlementFeeBps;
    uint256 maxBatchSize;
    uint256 maxGasReimbursement;
    uint256 gasReimbursementMultiplier;
    // 曲线池字段（标准池为零）：
    address deployer;
    uint24 deployerRoyaltyBps;
    uint256 virtualTokenReserve;
    uint256 virtualEthReserve;
}
```

### LaunchPhase

```solidity theme={null}
enum LaunchPhase {
    None,   // 标准 Geode 池（非曲线）
    Active  // 永久联合曲线——双路径交易（直接 + 意图）
}
```

<Note>
  `LaunchPhase` 枚举只有两个值。曲线是永久的——没有 `PendingGraduation` 或 `Graduated` 阶段。一旦 `Active`，曲线永远运行。
</Note>

## 源代码

<Card title="GeodeTypes.sol" icon="github" href="https://github.com/Geode-vAMM/geodex/blob/main/contracts/src/libraries/GeodeTypes.sol">
  在 GitHub 上查看完整源代码（约 157 行）。
</Card>
