> 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 một cách nguyên tử với hệ sinh thái DeFi gốc của Solana. Trang này trình bày 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](https://docs.rome.builders/vi/ung-dung-tren-rome/apps.md).

Mã bên dưới chỉ mang tính minh họa; tên giao diện cho các chương trình Solana của 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?

* **Tiếp cận 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
* **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

Phần import dưới đây đến từ [`rome-solidity`](https://github.com/rome-protocol/rome-solidity), được cài 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](https://docs.rome.builders/vi/huong-dan-cho-nha-phat-trien/deploy-solidity.md#using-the-rome-solidity-sdk)). Truyền địa chỉ feed vào từ [registry](https://docs.rome.builders/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
        // Tất cả thanh khoản DEX Solana đều có thể truy cập từ Solidity
        CpiProgram.invoke(JUPITER_PROGRAM, accounts, swapData);
    }
}
```

## Mẫu 3: Vault lợi suất

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

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

Sử dụng `RemusTx` (nhiều giao dịch EVM trên các chain Rome khác nhau, nguyên tử trong một giao dịch Solana):

1. Mua trên DEX A trên một chain Rome
2. Bán trên DEX B trên một chain Rome khác
3. Cả hai thực thi nguyên tử; nếu một bên thất bại, cả hai sẽ hoàn nguyên.

## 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ừ một trang trắng:

* [**rome-dex**](https://github.com/rome-protocol/rome-dex) — AMM hai làn; đưa ý 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 / lend / perps / 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 hoàn toàn mới: đọc các tài khoản giá Solana (Pyth, Switchboard), đăng chúng lên EVM, và cung cấp chúng cho Solidity thông qua Chainlink chuẩn `AggregatorV3Interface`.

## Liên quan

* [Cổng Oracle](https://docs.rome.builders/vi/san-pham/oracle-gateway.md) — nguồn cấp giá tương thích với Chainlink
* [Rome SDK](https://docs.rome.builders/vi/san-pham/rome-sdk.md) — các giao diện có kiểu 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.
