# DeFi 协议

Rome 使 EVM DeFi 协议能够与 Solana 原生 DeFi 生态系统以原子方式进行组合。本页涵盖常见的集成模式。

## 为什么选择在 Rome 上进行 DeFi？

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

## 模式 1：使用 Solana 预言机的借贷协议

```solidity
import {IAggregatorV3Interface} from "@rome-protocol/solidity-sdk/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
        // Solidity 可访问所有 Solana DEX 流动性
        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. 二者均以原子方式执行——零执行风险

## 相关内容

* [DeFi Composer](/zh/chan-pin/defi-composer.md) — 多协议金库基础设施
* [预言机网关](/zh/chan-pin/oracle-gateway.md) — 兼容 Chainlink 的价格馈送
* [Rome SDK](/zh/chan-pin/rome-sdk.md) — DeFi 协议的类型化接口


---

# Agent Instructions: 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:

```
GET https://docs.rome.builders/zh/yong-li/defi-protocols.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
