> ## 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 意图让您插入自定义验证和预言机层，使您能够为跨链用例选择最佳的信任和速度权衡。

只要支持验证来自输出链的有效负载，就可以添加任何验证层。

在最简单的实现中，验证层需要支持以下内容：

1. 求解器可以提交其填充输出的提交接口。提交接口应接受任意包进行验证，然后调用关联的输出结算合约以检查有效负载是否有效。
   ```solidity theme={"system"}
   interface IPayloadCreator {
       function arePayloadsValid(
           bytes[] calldata payloads
       ) external view returns (bool);
   }
   ```

2. 实现关联的验证接口，以便输入结算实现可以准确验证输出是否已填充。
   ```solidity theme={"system"}
    interface IOracle {
        function efficientRequireProven(
            bytes calldata proofSeries
        ) external view;
    }
   ```

重要的是，提交接口不必标准化；它只需要准确记录，以便求解器可以实现它。

## 已实现的验证接口

有三种类型的验证接口：

1. 自助服务：提交有效负载会生成必须在输入链上收集和提交的链下证明的验证接口。
2. 自动：提交有效负载会自动在输入链上交付关联证明的验证接口。

目前，所有支持的预言机系统都是自助服务。

<Note>
  **速度和价格**

  Polymer 比大多数其他预言机系统快得多。虽然速度不会影响用户的资产交付，但对求解器很重要。选择具有快速还款的预言机系统会导致更便宜的意图，因为求解器可以更快地轮换其资本。
</Note>

### Polymer

Polymer 允许验证发出的事件。验证的目标事件是 [`OutputFilled`](https://github.com/openintentsframework/oif-contracts/blob/3e4682f4366a6dd0aa46be59b5922c2231a52d41/src/output/BaseOutputSettler.sol#L95) 事件，在输出已填充时发出。

```solidity theme={"system"}
event OutputFilled(bytes32 indexed orderId, bytes32 solver, uint32 timestamp, MandateOutput output);
```

使用 Polymer [prove API](https://docs.polymerlabs.org/docs/build/get%20started/prove-api-V2/api-endpoints)，可以生成事件的证明。生成后，可以将其提交到 [`receivedMessage`](https://github.com/openintentsframework/oif-contracts/blob/222989b15241ec680d2a0503c7396e1b6c649a50/src/integrations/oracles/polymer/PolymerOracle.sol#L74-L78)。

有关此类集成的示例，请参阅 [lintent.org 实现](https://github.com/lifinance/lintent/blob/a4aa78cd058cade732b73d83aa2843dd4e9ea24d/src/lib/utils/lifiintent/tx.ts#L524-L577)。

Polymer 一次只能证明一个已填充的输出。

### Wormhole

Wormhole 实现基于 Wormhole 的广播功能。消息必须通过 [`submit`](https://github.com/openintentsframework/oif-contracts/blob/daa8913e5803d8b62b646335d4c5130cdfacfec8/src/oracles/wormhole/WormholeOracle.sol#L43) 接口提交到 Wormhole 实现。消息必须编码为 [`FillDescription`](https://github.com/openintentsframework/oif-contracts/blob/main/src/libs/MandateOutputEncodingLib.sol#L21-L36)，然后提交：

```solidity theme={"system"}
function submit(address source, bytes[] calldata payloads) public payable returns (uint256 refund);
```

然后将此消息发送到 Wormhole 守护者集。一旦关联的证明可用，求解器可以将证明提交到输入链上的 [`receiveMessage`](https://github.com/openintentsframework/oif-contracts/blob/daa8913e5803d8b62b646335d4c5130cdfacfec8/src/oracles/wormhole/WormholeOracle.sol#L78-L80) 以验证其意图。

注意：Wormhole 实现使用比 Wormhole 的 `Implementation.sol` 更高效的验证算法。

### Bitcoin

LI.FI 意图有一个比特币简化支付验证 (SPV) 客户端实现。此实现既作为输出结算实现，又作为验证层。

比特币 SPV 客户端需要持续维护——区块链必须大约每 10 分钟更新一次，或者每当需要证明交易时——才能正确验证交易。

要生成交易证明，请参考以下代码：

```typescript theme={"system"}
import mempoolJS from "@catalabs/mempool.js";
const mainnet: boolean;
const {
  bitcoin: { transactions, blocks },
} = mempoolJS({
  hostname: "mempool.space",
  network: mainnet ? undefined : "testnet4",
});

export async function generateProof(
  txid: string,
): Promise<{ blockHeader: string; proof: Proof; rawTx: string }> {
  const tx = await transactions.getTx({ txid });

  const merkleProof = await transactions.getTxMerkleProof({ txid });
  // TODO: 序列化版本 1。
  const rawTx = await transactions.getTxHex({ txid });

  const blockHash = await blocks.getBlockHeight({
    height: merkleProof.block_height,
  });

  // 大多数端点提供交易见证编码。
  // 以下函数用于剥离见证数据。
  const rawTxWitnessStripped = removeWitnesses(rawTx);

  const blockHeader = await blocks.getBlockHeader({ hash: blockHash });

  return {
    blockHeader,
    proof: {
      txId: txid,
      txIndex: merkleProof.pos,
      siblings: merkleProof.merkle.reduce(
        (accumulator, currentValue) => accumulator + currentValue,
      ),
    },
    rawTx: rawTxWitnessStripped,
  };
}
```
