# DeFi Composer

DeFi Composer 使得以 Solidity 编写、类似 Yearn 风格的多协议金库成为可能，可通过 CPI 在多个 Solana DeFi 协议之间原子化组合。

## 概览

单个 Solidity 函数即可协调 Jupiter、Kamino、Drift、Meteora 以及其他 Solana 协议上的操作——全部原子化执行。如果任一步骤失败，整个交易都会回滚。

```solidity
function executeStrategy(uint256 amount) external {
    // 1. 通过 Jupiter 将 50% 的 USDC 兑换为 SOL
    IJupiter(JUPITER).swap(USDC, SOL, amount / 2, minSolOut);

    // 2. 将 SOL 作为抵押品存入 Kamino
    IKamino(KAMINO).deposit(SOL, solAmount);

    // 3. 以 SOL 抵押借入 USDC
    IKamino(KAMINO).borrow(USDC, borrowAmount);

    // 4. 在 Drift 上开立 SOL-PERP 空头（delta 对冲）
    IDrift(DRIFT).placeOrder(SOL_PERP, SHORT, size, leverage);

    // 全部原子化。一个 Solidity 函数。四次 CPI 跳转。
}
```

## 为什么使用 Solidity 进行 DeFi 组合？

* **熟悉的工具链** — Solidity 开发者无需学习 Rust/Anchor
* **成熟的生态系统** — 可利用 OpenZeppelin、现有审计工具以及 Hardhat/Foundry 工作流
* **可组合性** — Solidity 的 `try/catch`、修饰器和继承可自然工作
* **原子执行** — Solana 的交易模型保证要么全部成功，要么全部失败

## 参考策略（计划中）

| 策略        | 协议                   | 描述                             |
| --------- | -------------------- | ------------------------------ |
| SOL 收益优化器 | Kamino、Drift         | 存入 SOL，借入稳定币，在永续合约上进行 delta 对冲 |
| 稳定币收益     | Kamino、Orca          | 在多个资金池中提供稳定币流动性，自动再平衡          |
| Delta 中性  | Jupiter、Kamino、Drift | 兑换 + 存入 + 对冲，在无敞口的情况下获取收益      |
| LST 套利    | Jupiter、Marinade     | 利用 LST 价格差异                    |

## 状态

**已设计** — 取决于 Rome SDK 第二阶段（IJupiter、IDrift、IKamino 接口）。核心 CPI 基础设施已上线；特定协议的类型化接口正在推进中。

## 下一步

* [Rome SDK](/zh/chan-pin/rome-sdk.md) — 面向 Solana 程序的类型化 Solidity 接口
* [从 EVM 调用 Solana](/zh/kai-fa-zhe-zhi-nan/call-solana-from-evm.md) — CPI 指南
* [约束条件](/zh/he-xin-gai-nian/constraints.md) — CPI 深度限制与计算预算


---

# 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/chan-pin/defi-composer.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.
