For the complete documentation index, see llms.txt. This page is also available as Markdown.

DeFi 协议

Rome 上 EVM DeFi 的集成模式——使用 Solana 预言机进行借贷、从 Solidity 组合 Jupiter 和 Kamino,以及共享流动性池。

Rome 使 EVM DeFi 协议能够与 Solana 的原生 DeFi 生态以原子方式组合。本页面涵盖常见的集成模式。其中已有多项已在 Rome 上线——Aave v3、Compound v3(Aerarium)、Uniswap V2/V3/V4 以及 Rome DEX——参见 Rome 上的应用.

以下代码仅作示例说明;第三方 Solana 程序的接口名称仅为示例,并非随 SDK 一并发布的接口。

为什么选择在 Rome 上开展 DeFi?

  • 访问 Solana 流动性 — Jupiter、Kamino、Drift、Meteora、Raydium、Orca

  • 原子可组合性 — 在单笔交易中执行多步骤 DeFi 操作

  • Solidity 工具链 — 熟悉的开发与审计生态

  • 共享状态 — EVM 和 Solana 用户共享同一流动性池

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

下面的导入来自 rome-solidity,它是从 GitHub 安装的,而不是从 npm 安装的: npm install github:rome-protocol/rome-solidity,或 forge install rome-protocol/rome-solidity 并使用以下重映射 @rome-protocol/rome-solidity/=lib/rome-solidity/ (详情见 部署 Solidity 合约)。将 feed 地址通过 registry 传入,而不是将其硬编码。

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 价格
        // 与以太坊上的 Chainlink 接口相同
        return (amount * uint256(price)) / 1e8;
    }
}

模式 2:通过 CPI 实现的 DEX 聚合器

模式 3:收益金库

模式 4:跨协议套利

使用 RemusTx (原子化跨 rollup 交易):

  1. 在 rollup 1 中的 DEX A 买入

  2. 在 rollup 2 中的 DEX B 卖出

  3. 两者同时原子执行——零执行风险

参考实现

请分叉一个可运行的 Rome 应用,而不是从空白页面开始:

  • rome-dex — 双通道 AMM;带来一个新想法,并通过一个流动性池同时面向 Solana 和 EVM 用户部署。

  • aerarium — 双通道 Compound v3 借贷界面。

  • cardo — CPI 应用分发门户(兑换 / 借贷 / 永续合约 / 组合)。

  • rome-aave-v3-demo — Aave v3 借贷界面。

  • compound-on-rome-comet — Comet 货币市场合约。

  • rome-oracle-gateway — 一个全新的跨 VM 应用:读取 Solana 价格账户(Pyth、Switchboard),将其发布到 EVM,并通过标准 Chainlink 向 Solidity 提供它们 AggregatorV3Interface.

相关

最后更新于

这有帮助吗?