> 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/vi/cac-truong-hop-su-dung/defi-protocols.md).

# Các giao thức DeFi

Các mẫu tích hợp cho DeFi EVM trên Rome — lending với oracle Solana, kết hợp Jupiter và Kamino từ Solidity, và các pool thanh khoản dùng chung.

Rome cho phép các giao thức DeFi EVM kết hợp nguyên tử với hệ sinh thái DeFi gốc của Solana. Trang này bao gồm các mẫu tích hợp phổ biến. Một số đã hoạt động trên Rome — Aave v3, Compound v3 (Aerarium), Uniswap V2/V3/V4, và Rome DEX — xem [Ứng dụng trên Rome](/vi/ung-dung-tren-rome/apps.md).

Đoạn mã dưới đây chỉ mang tính minh họa; tên giao diện cho các chương trình Solana bên thứ ba là ví dụ, không phải các giao diện SDK được phát hành.

## Tại sao DeFi trên Rome?

* **Truy cập thanh khoản Solana** — Jupiter, Kamino, Drift, Meteora, Raydium, Orca
* **Khả năng kết hợp nguyên tử** — các thao tác DeFi nhiều bước trong một giao dịch duy nhất
* **Công cụ Solidity** — hệ sinh thái phát triển và kiểm toán quen thuộc
* **Trạng thái dùng chung** — người dùng EVM và Solana dùng chung cùng các pool

## Mẫu 1: Giao thức cho vay với Oracle Solana

Lệnh import bên dưới đến từ [`rome-solidity`](https://github.com/rome-protocol/rome-solidity), được cài đặt từ GitHub, không phải từ npm: `npm install github:rome-protocol/rome-solidity`, hoặc `forge install rome-protocol/rome-solidity` với remapping `@rome-protocol/rome-solidity/=lib/rome-solidity/` (chi tiết trong [Triển khai Hợp đồng Solidity](/vi/huong-dan-cho-nha-phat-trien/deploy-solidity.md#using-the-rome-solidity-sdk)). Truyền địa chỉ feed vào từ [registry](/vi/san-pham/oracle-gateway.md#consume-a-feed-in-three-steps) thay vì mã hóa cứng nó.

```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();
        // Giá Pyth/Switchboard qua Oracle Gateway
        // Cùng giao diện như Chainlink trên Ethereum
        return (amount * uint256(price)) / 1e8;
    }
}
```

## Mẫu 2: Bộ tổng hợp DEX qua CPI

```solidity
contract RomeSwap {
    function swap(
        bytes32 fromMint,
        bytes32 toMint,
        uint256 amount,
        uint256 minOut
    ) external {
        // CPI tới Jupiter/Raydium/Meteora
        // Có thể truy cập toàn bộ thanh khoản DEX Solana từ Solidity
        CpiProgram.invoke(JUPITER_PROGRAM, accounts, swapData);
    }
}
```

## Mẫu 3: Kho lưu trữ lợi suất

```solidity
contract YieldVault {
    function deposit(uint256 amount) external {
        // Chấp nhận tiền gửi USDC
        // CPI → Jupiter: hoán đổi sang token tối ưu
        // CPI → Kamino: cung cấp làm tài sản thế chấp
        // CPI → Drift: mở vị thế phòng hộ delta-neutral
        // Hoàn toàn nguyên tử — một giao dịch, hoặc tất cả hoặc không gì cả
    }
}
```

## Mẫu 4: Chênh lệch giá xuyên giao thức

Sử dụng `RemusTx` (giao dịch nguyên tử xuyên rollup):

1. Mua trên DEX A trong rollup 1
2. Bán trên DEX B trong rollup 2
3. Cả hai đều nguyên tử — không có rủi ro thực thi

## Các triển khai tham chiếu

Fork một ứng dụng Rome đang hoạt động thay vì bắt đầu từ trang trắng:

* [**rome-dex**](https://github.com/rome-protocol/rome-dex) — AMM hai làn; đưa một ý tưởng mới và triển khai nó cho cả người dùng Solana và EVM trên một pool.
* [**aerarium**](https://github.com/rome-protocol/aerarium) — giao diện cho vay Compound v3 hai làn.
* [**cardo**](https://github.com/rome-protocol/cardo) — cổng phân phối ứng dụng CPI (swap / cho vay / phái sinh vĩnh viễn / compose).
* [**rome-aave-v3-demo**](https://github.com/rome-protocol/rome-aave-v3-demo) — giao diện cho vay Aave v3.
* [**compound-on-rome-comet**](https://github.com/rome-protocol/compound-on-rome-comet) — các hợp đồng thị trường tiền tệ Comet.
* [**rome-oracle-gateway**](https://github.com/rome-protocol/rome-oracle-gateway) — một ứng dụng cross-VM từ đầu: đọc các tài khoản giá Solana (Pyth, Switchboard), đăng chúng lên EVM, và cung cấp cho Solidity thông qua Chainlink tiêu chuẩn `AggregatorV3Interface`.

## Liên quan

* [Oracle Gateway](/vi/san-pham/oracle-gateway.md) — nguồn cấp giá tương thích với Chainlink
* [Rome SDK](/vi/san-pham/rome-sdk.md) — giao diện được kiểu hóa cho các giao thức 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/vi/cac-truong-hop-su-dung/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.
