> 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/shi-yong-chang-jing/defi-protocols.md).

# DeFi 协议

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 预言机的借贷协议

```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 价格
        // 与 Ethereum 上的 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 借贷界面。
* [**cardo**](https://github.com/rome-protocol/cardo) — CPI 应用分发门户（swap / lend / perps / compose）。
* [**rome-aave-v3-demo**](https://github.com/rome-protocol/rome-aave-v3-demo) — Aave v3 借贷界面。
* [**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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
