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

# 结算

> 介绍 LI.FI Intents 中的输入结算与输出结算如何运作，涵盖托管、Compact 和输出结算器合约。

结算是指托管用户资金（输入结算）并记录求解器交付（输出结算）的过程。本页涵盖这两个方面。

***

## 输入结算

支持两种单链输入结算器：

* [**InputSettlerEscrow**](https://github.com/openintentsframework/oif-contracts/blob/main/src/input/escrow/InputSettlerEscrow.sol)。标准托管，将代币与其意图关联起来。
* [**InputSettlerCompact**](https://github.com/openintentsframework/oif-contracts/blob/main/src/input/compact/InputSettlerCompact.sol)。通过 The Compact 资源锁实现的长期存款。

[多链输入结算器](https://github.com/openintentsframework/oif-contracts/pull/49)正在开发中。

The Compact 通过资源锁支持先填充流程。Escrow 结算器使用传统流程，即必须在填充之前开启托管。

### StandardOrder

单链输入结算器使用以下订单结构：

```solidity theme={"system"}
struct StandardOrder {
    address user;
    uint256 nonce;
    uint256 originChainId;
    uint32 expires;
    uint32 fillDeadline;
    address inputOracle;
    uint256[2][] inputs;
    MandateOutput[] outputs;
}
```

### MandateOutput

```solidity theme={"system"}
struct MandateOutput {
    bytes32 oracle;
    bytes32 settler;
    uint256 chainId;
    bytes32 token;
    uint256 amount;
    bytes32 recipient;
    bytes call;
    bytes context;
}
```

### 完结（Finalization）

要在填充订单后领取输入资金，请调用以下之一：

1. **`finalise`** 由求解器调用。调用者指定将资产发送到何处以及是否进行外部调用。
2. **`finaliseWithSignature`** 由任何持有求解器签发的、包含目标地址和调用细节的 `AllowOpen` 签名的人调用。

### Compact 注册

Compact 意图使用 The Compact 的 EIP-712 域分隔符签名为 `BatchClaim`：

```solidity theme={"system"}
struct BatchCompact {
    address arbiter;
    address sponsor;
    uint256 nonce;
    uint256 expires;
    uint256[2][] idsAndAmounts;
    Mandate mandate;
}

struct Mandate {
    uint32 fillDeadline;
    address inputOracle;
    MandateOutput[] outputs;
}
```

或者，意图也可以由发起人在链上注册，或由某人代其支付索赔并注册。

### Escrow 注册

Escrow 意图可以通过多种方式注册：

1. **直接开启（Direct open）**，由所有者通过 ERC-7683 `function open(bytes)` 完成。发出 `event Open(bytes32 indexed orderId, bytes order)`。
2. **ERC-3009**，以 orderId 作为 nonce。每个输入都需要一个签名。
3. **Permit2**，使用 EIP-712 签名的 `PermitBatchWitnessTransferFrom`。

### 集成示例

* 智能合约注册：[`RegisterIntentLib.sol`](https://github.com/catalystsystem/catalyst-intent/blob/27ce0972c150ed113f66ae91069eb953f23d920b/src/libs/RegisterIntentLib.sol#L100-L131)
* UI 签名（Batch Compact）：[lintent.org 演示](https://github.com/lifinance/lintent/blob/a4aa78cd058cade732b73d83aa2843dd4e9ea24d/src/lib/utils/lifiintent/tx.ts#L144)
* UI 存款与注册：[lintent.org 演示](https://github.com/lifinance/lintent/blob/a4aa78cd058cade732b73d83aa2843dd4e9ea24d/src/lib/utils/lifiintent/tx.ts#L199)

***

## 输出结算

目前存在一种输出结算器：[`OutputSettlerSimple.sol`](https://github.com/openintentsframework/oif-contracts/blob/main/src/output/simple/OutputSettlerSimple.sol)。它支持四种订单类型：简单限价订单、荷兰式拍卖、独占限价订单和独占荷兰式拍卖。

### 配置拍卖类型

拍卖类型由 `MandateOutput` 中的 `context` 字段决定：

```solidity theme={"system"}
// Simple limit order (no auction)
context = "0x" or "0x00";

// Dutch auction
context = abi.encodePacked(0x01, slope, stopTime);
```

对于包含多个输出的荷兰式拍卖，只有第一个输出会作为拍卖发挥作用。其余输出解析为其最差价格，因为求解器只在第一个输出上竞争（赢得它即赢得整个订单）。

有关拍卖机制的更多详情，请参阅[拍卖](/lifi-intents/for-solvers/auctions)。

***

## 后续步骤

<CardGroup cols={2}>
  <Card title="系统概述" icon="diagram-project" href="/lifi-intents/architecture/overview">
    完整架构与合约地址
  </Card>

  <Card title="预言机系统" icon="satellite-dish" href="/lifi-intents/architecture/oracle-systems">
    验证与证明系统
  </Card>

  <Card title="创建并提交订单" icon="paper-plane" href="/lifi-intents/intents-api/create-and-submit">
    面向集成商的订单构造
  </Card>

  <Card title="填充订单" icon="bolt" href="/lifi-intents/for-solvers/filling-orders">
    求解器如何交付输出
  </Card>
</CardGroup>
