> For the complete documentation index, see [llms.txt](https://docs.rome.builders/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rome.builders/zh/ying-yong-chang-jing/defi-protocols.md).

# DeFi 协议

Rome 上 EVM DeFi 的集成模式——使用 Solana 预言机进行借贷、从 Solidity 组合 Jupiter 和 Kamino，以及共享流动性池。

Rome 使 EVM DeFi 协议能够与 Solana 的原生 DeFi 生态进行原子级组合。本页介绍常见的集成模式。其中若干已在 Rome 上线——Aave v3、Compound v3（Aerarium）、Uniswap V2/V3/V4 以及 Rome DEX——见 [Rome 上的应用](/zh/rome-shang-de-ying-yong/apps.md).

以下代码仅用于示意；第三方 Solana 程序的接口名称为示例，并非随 SDK 一同发布的接口。

## 为什么选择在 Rome 上做 DeFi？

* **接入 Solana 流动性** — Jupiter、Kamino、Drift、Meteora、Raydium、Orca
* **原子级可组合性** — 单笔交易中完成多步骤 DeFi 操作
* **Solidity 工具链** — 熟悉的开发与审计生态
* **共享状态** — EVM 和 Solana 用户共享同一流动池

## 模式 1：带有 Solana 预言机的借贷协议

下面的导入来自 [`rome-solidity`](https://github.com/rome-protocol/rome-solidity)，它是从 GitHub 安装的，而不是来自 npm： `npm install github:rome-protocol/rome-solidity`，或 `forge install rome-protocol/rome-solidity` 使用重映射 `@rome-protocol/rome-solidity/=lib/rome-solidity/` （详情见 [部署 Solidity 合约](/zh/kai-fa-zhe-zhi-nan/deploy-solidity.md#using-the-rome-solidity-sdk)）。将喂价地址从 [registry](/zh/chan-pin/oracle-gateway.md#consume-a-feed-in-three-steps) 传入，而不是将其硬编码。

```solidity
import {IAggregatorV3Interface} from "@rome-protocol/rome-solidity/contracts/oracle/IAggregatorV3Interface.sol";

contract RomeLending {
    IAggregatorV3Interface public priceFeed;

    constructor(address _priceFeed) {
        priceFeed = IAggregatorV3Interface(_priceFeed);
    }

    function getCollateralValue(uint256 amount) public view returns (uint256) {
        (, int256 price,,,) = priceFeed.latestRoundData();
        // 通过 Oracle Gateway 获取 Pyth/Switchboard 价格
        // 与以太坊上的 Chainlink 使用相同的接口
        return (amount * uint256(price)) / 1e8;
    }
}
```

## 模式 2：通过 CPI 的 DEX 聚合器

```solidity
contract RomeSwap {
    function swap(
        bytes32 fromMint,
        bytes32 toMint,
        uint256 amount,
        uint256 minOut
    ) external {
        // 通过 CPI 调用 Jupiter/Raydium/Meteora
        // 所有 Solana DEX 流动性均可从 Solidity 访问
        CpiProgram.invoke(JUPITER_PROGRAM, accounts, swapData);
    }
}
```

## 模式 3：收益金库

```solidity
contract YieldVault {
    function deposit(uint256 amount) external {
        // 接受 USDC 存款
        // CPI → Jupiter：兑换为最优代币
        // CPI → Kamino：作为抵押品提供
        // CPI → Drift：开启 Delta 中性对冲
        // 全部原子化——一笔交易，要么全部成功，要么全部失败
    }
}
```

## 模式 4：跨协议套利

使用 `RemusTx` （原子级跨 rollup 交易）：

1. 在 rollup 1 的 DEX A 上买入
2. 在 rollup 2 的 DEX B 上卖出
3. 二者均原子执行——零执行风险

## 参考实现

从一个可运行的 Rome 应用分支，而不是从空白页开始：

* [**rome-dex**](https://github.com/rome-protocol/rome-dex) — 双通道 AMM；带来一个新创意，并通过单一流动池向 Solana 和 EVM 用户部署。
* [**aerarium**](https://github.com/rome-protocol/aerarium) — 双通道 Compound v3 借贷 UI。
* [**cardo**](https://github.com/rome-protocol/cardo) — CPI 应用分发门户（兑换 / 借贷 / 永续合约 / 组合）。
* [**rome-aave-v3-demo**](https://github.com/rome-protocol/rome-aave-v3-demo) — Aave v3 借贷 UI。
* [**compound-on-rome-comet**](https://github.com/rome-protocol/compound-on-rome-comet) — Comet 货币市场合约。
* [**rome-oracle-gateway**](https://github.com/rome-protocol/rome-oracle-gateway) — 一个全新跨 VM 应用：读取 Solana 价格账户（Pyth、Switchboard），将其发布到 EVM，并通过标准 Chainlink 向 Solidity 提供。 `AggregatorV3Interface`.

## 相关内容

* [Oracle Gateway](/zh/chan-pin/oracle-gateway.md) — 兼容 Chainlink 的价格喂价
* [Rome SDK](/zh/chan-pin/rome-sdk.md) — DeFi 协议的类型化接口


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rome.builders/zh/ying-yong-chang-jing/defi-protocols.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
