> ## 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 意图支持各种输入结算方案。Compact 和 Rhinestone 都允许先填充流程和赞助交易，假设用户有现有存款。

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

* [**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)

[正在进行的工作](https://github.com/openintentsframework/oif-contracts/pull/49)以支持多链输入结算器。

Compact 使用资源锁并支持先填充流程。对于没有资源锁的传统流程，可以使用托管结算器。托管流程在先填充流程中不安全，必须在填充之前打开。

#### 默认输出

结算方案的默认输出是 [`MandateOutput`](https://github.com/openintentsframework/oif-contracts/blob/main/src/input/types/MandateOutputType.sol#L4-L18)：

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

要验证编码的输出描述是否已验证，请将哈希编码的有效负载发送到适当的本地预言机以及相关的解析详细信息，例如求解器的身份。

## 单链输入

单链输入结算器使用 [`StandardOrder`](https://github.com/openintentsframework/oif-contracts/blob/main/src/input/types/StandardOrderType.sol#L6-L15)：

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

要完成订单以获得其输入的报酬，必须调用相关的完成函数。有 2 个端点可用：

1. `finalise`：由求解器调用，调用者可以指定将资产发送到何处以及是否进行外部调用。请注意，托管和 Compact 接口不同以优化 gas。
2. `finaliseWithSignature`：任何人都可以使用来自求解器的 [`AllowOpen`](https://github.com/openintentsframework/oif-contracts/blob/main/src/input/types/AllowOpenType.sol#L5-L9) 签名调用，其中包含目标和调用详细信息。

### Compact 意图注册

意图作为 `StandardOrder` 传输，在 Compact 中它们被签名为具有以下结构的 `BatchClaim`：

```solidity theme={"system"}
struct BatchCompact {
    address arbiter;
    address sponsor;
    uint256 nonce;
    uint256 expires;
    uint256[2][] idsAndAmounts;
    Mandate mandate;
}
// Mandate 定义为：
struct Mandate {
    uint32 fillDeadline;
    address inputOracle;
    MandateOutput[] outputs;
}
```

意图是使用 The Compact 的域分隔符进行 EIP712 签名的 `BatchClaim`。

或者，可以在链上注册意图。有两种方法可以做到这一点：赞助商（用户）注册它，或者有人为整个索赔付费并代表他们注册。

### 托管 Compact 注册

意图作为 `StandardOrder` 传输，但可以通过几种方式注册：

1. 通过 ERC-7683 `function open(bytes)` 由其所有者注册。这会发出 ERC-7683 `event Open(bytes32 indexed orderId, bytes order)` 并将其 `function orderStatus(bytes)` 设置为 1。
2. 通过 ERC-3009 注册，orderId 作为 nonce。对于每个输入，必须提供签名，然后是 `0x01, abi.encode(bytes[])`。
3. 通过 Permit2 注册，签名作为 `0x00, bytes` 从 EIP-712 签名对象 `PermitBatchWitnessTransferFrom` 提供：

   ```solidity theme={"system"}
   struct PermitBatchWitnessTransferFrom {
       TokenPermissions[] permitted;
       address spender;
       uint256 nonce;
       uint256 deadline;
       Permit2Witness witness;
   }
   // TokenPermissions 为
   TokenPermissions(
       address token;
       uint256 amount;
   )
   // Permit2Witness 为
   Permit2Witness(
       uint32 expires;
       address inputOracle;
       MandateOutput[] outputs;
   )
   ```

#### 集成示例

* 有关代表他人注册意图的智能合约示例，请参阅 [`RegisterIntentLib.sol`](https://github.com/catalystsystem/catalyst-intent/blob/27ce0972c150ed113f66ae91069eb953f23d920b/src/libs/RegisterIntentLib.sol#L100-L131)。
* 有关签署 Batch Compact 的 UI 示例，请参阅 [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)。
