> 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/ja/zhi-pin/rome-sdk.md).

# Rome SDK

EVMコントラクトからSolanaプログラムを呼び出すための型付きSolidityインターフェースと、Romeのオフチェーンサービスの基盤となるRust SDK。

Rome SDK は、EVMスマートコントラクトからSolanaプログラムとやり取りするための型付きSolidityインターフェースを提供します。Rome上でクロスランタイムアプリケーションを構築するための開発者向けツールキットです。

## SDK

Rome には3つの対象向けに SDK があります — アプリ開発者（TypeScript）、コントラクト開発者（Solidity）、そして Rome 上で自前のサービスを運用するチーム（Rust）です。

### TypeScript SDK (`@rome-protocol/sdk`)

**dapp およびフロントエンド開発者向け** — 多くのアプリ開発者が最初に使う SDK です。 [`@rome-protocol/sdk`](https://github.com/rome-protocol/rome-sdk-ts) Rome の書き込みパスをラップし、Webアプリが Rome トランザクションを正しく送信できるようにします: `submitRomeTx` （正しい書き込みパスに加え、ガス/手数料の処理）、PDA / ATA の導出、CPI `invoke` / `invoke_signed` エンコーダー、プリコンパイルバインディング、そして `/bridge` サブパス。リポジトリ先行インストール（npm公開は未定）:

```bash
npm install github:rome-protocol/rome-sdk-ts#v0.4.0
```

```typescript
import { submitRomeTx } from '@rome-protocol/sdk';
// すべての Rome EVM の書き込みを、正しい書き込みパスで送信します（ガス/手数料のエンコードを処理します）。
```

公開 [rome-dex](https://github.com/rome-protocol/rome-dex) app は SDK のヘルパーのうちごく一部（PDA とトークンアカウントの導出、CPI `invoke` エンコーダーと 1.3x のガスパッド）しか使っておらず、 [cardo](https://github.com/rome-protocol/cardo) それに依存していません。どちらも呼び出し `submitRomeTx` または `submitRomeTxV1`ません。そのため、SDK の書き込みパスではなく、アプリが CPI プリコンパイルをどう呼び出すかを読むためのものです。

**両方のレーンを、1つの SDK で。** `submitRomeTx` は EVM レーン（MetaMask）です。 **Solana レーン** — Solana ウォレットがあなたの EVM アプリを駆動する — `submitRomeTxV1` では、それを再現します: プロキシが呼び出し用に1つの Solana v1 トランザクションを組み立て、ウォレットは同じ鍵で2回署名し（読み取り可能な認可メッセージ、その後トランザクション）、Rome はその呼び出しをユーザーの派生IDからの EVM トランザクションとして実行します。EVM鍵は不要です。1つのトランザクションに収まらない呼び出しは、同じ認可署名を使ってプロキシにより中継され、 `fundSyntheticGas` 中継された呼び出しが消費するネイティブガスを補充します。中継された呼び出しが revert した場合は、 `receipt.status === "0x0"` を投げる代わりに解決されるので、それを確認してください； [中継された呼び出しと長い呼び出し](https://docs.rome.builders/ja/gaido/call-evm-from-solana.md#relayed-calls-and-long-calls) のセクションにガスのルールと制限があります。値の出し入れは `buildFundLeg` / `buildSweepLeg` ERC-20 ラッパーとして（例: `wUSDC`）、ネイティブではありません `msg.value` — 合成送信者は静止状態では何も保持しません — また、初回の合成送信者は、明示的に一度だけ `buildCreatePdaCall`. 以前の `submitRomeTxSolanaLane`は、クライアント側でレガシー Solana トランザクションを構築するもので、今も SDK にあります。 [デュアルレーンアプリを作る](https://docs.rome.builders/ja/gaido/dual-lane-app.md) および [Solana から EVM を呼び出す](https://docs.rome.builders/ja/gaido/call-evm-from-solana.md).

### Solidity SDK (`@rome-protocol/rome-solidity`)

**Solidity 開発者向け。** プリコンパイルインターフェース、ERC-20/SPL ラッパー、PDA 導出、CPI ユーティリティを提供します。npm 公開は未定です；現時点では公開 [`rome-solidity`](https://github.com/rome-protocol/rome-solidity) リポジトリ（git依存関係またはコピー済みファイル）から利用します。

```solidity
import {ISystemProgram, ICrossProgramInvocation, IHelperProgram, IWithdraw}
    from "@rome-protocol/rome-solidity/contracts/interface.sol";
import {SPL_ERC20} from "@rome-protocol/rome-solidity/contracts/erc20spl/erc20spl.sol";
import {RomeEVMAccount} from "@rome-protocol/rome-solidity/contracts/rome_evm_account.sol";
```

### Rust SDK (`rome-sdk`)

**Rome 上で自前のサービスを運用するチーム向け。** トランザクションの組み立て、Solana とのやり取り、ガス価格設定、ブロック索引を扱う Rust ワークスペースです。Proxy と Hercules はこれの上に構築されています。ソースは [`rome-protocol/rome-sdk`](https://github.com/rome-protocol/rome-sdk)にあります。Solana v1 トランザクション（4 KB、最大64アカウント）を送信します。

**構築について。** このワークスペースはリポジトリ [`rome-sdk`](https://github.com/rome-protocol/rome-sdk), [`rome-evm`](https://github.com/rome-protocol/rome-evm) および [`mollusk`](https://github.com/rome-protocol/mollusk) が並んでクローンされていることを前提にしています。というのも、相対パスで他の2つに依存しているためです。そのため、別プロジェクトから使う推奨方法は plain な git 依存ではなく、path 依存です。Rust 1.85 以降と、初回ビルド時のネットワークアクセスが必要です。 `rome-evm` にはデフォルトのネットワーク機能がないため、それをコンパイルするビルドでは、次のうちちょうど1つが必要です `ci`, `テストネット` または `メインネット`； `ci` はローカル作業用に使います。たとえば `cargo test -p rome-sdk --features ci`. リポジトリの README に手順の全体と feature 表があります。

**ライセンス。** Rust SDK はソース公開であり、オープンソースではありません。無断転載禁止で、個人利用・非商用目的に限り使用できます。商用利用には Rome Protocol の書面による許可が必要です。リポジトリの `LICENSE` に、申請方法が記載されています。

## Solidity SDK: 含まれるもの

### プリコンパイルインターフェース

インターフェースをそのプリコンパイルアドレスにバインドします:

```solidity
ISystemProgram          constant System   = ISystemProgram(0xFF00000000000000000000000000000000000007);
ICrossProgramInvocation constant Cpi      = ICrossProgramInvocation(0xFF00000000000000000000000000000000000008);
IHelperProgram          constant Helper   = IHelperProgram(0xFF00000000000000000000000000000000000009);
IWithdraw               constant Withdraw = IWithdraw(0x4200000000000000000000000000000000000016);
// キャッシュ済みトラック: ISplCached 0xff…05, IAssociatedSplCached 0xff…06, ISystemCached 0xff…04, IWithdrawCached 0xff…0b
```

### SPL トークン操作

使用 `IHelperProgram` (`0xff…09`) は、ユーザーPDA署名付きの SPL プリミティブ用です:

```solidity
// ミント用に呼び出し元の ATA を作成する
Helper.create_ata(user, mint);

// 呼び出し元の PDA から SPL を送信する
Helper.transfer_spl(to, tokens, mint);
```

キャッシュ済みトラックでは、同等の操作は `ISplCached` (`0xff…05`と `IAssociatedSplCached` (`0xff…06`にあります。すべてのオーバーロードについては `interface.sol` を参照してください。コントラクトは一貫して1つのトラックを使います。

### PDA の導出

```solidity
// ユーザーの Solana PDA を導出する
bytes32 userPda = RomeEVMAccount.pda(msg.sender);

// salt を使って PDA を導出する（ユーザーごとに複数の PDA を作成する場合）
bytes32 pda = RomeEVMAccount.pda_with_salt(msg.sender, salt);

// 任意の PDA を見つける
(bytes32 pda, uint8 bump) = SystemProgram.find_program_address(programId, seeds);
```

### クロスプログラム呼び出し

```solidity
// 任意の Solana プログラムを呼び出す
ICrossProgramInvocation.AccountMeta[] memory accounts = new ICrossProgramInvocation.AccountMeta[](2);
accounts[0] = ICrossProgramInvocation.AccountMeta(signerPda, true, true);
accounts[1] = ICrossProgramInvocation.AccountMeta(targetAccount, false, true);

CpiProgram.invoke(programId, accounts, instructionData);

// PDA 署名で呼び出す
CpiProgram.invoke_signed(programId, accounts, data, seeds);

// アカウントデータを読み取る
(uint64 lamports, bytes32 owner, bool isSigner, bool isWritable, bool executable, bytes memory data)
    = CpiProgram.account_info(pubkey);
```

### SPL トークン上の ERC-20

```solidity
// 任意の SPL ミント用のラッパーをデプロイする
ERC20SPLFactory factory = ERC20SPLFactory(FACTORY_ADDRESS);
address wrapper = factory.add_spl_token_with_metadata(splMint);

// ラッパーを標準 ERC-20 として使う
SPL_ERC20 token = SPL_ERC20(wrapper);
token.transfer(recipient, amount);
uint256 balance = token.balanceOf(user);
```

### Borsh のデシリアライズ

```solidity
import {Convert} from "@rome-protocol/rome-solidity/contracts/convert.sol";

// Solana のアカウントデータを解析する（リトルエンディアンの Borsh 形式）
(uint64 value, uint256 newOffset) = Convert.read_u64le(data, offset);
(bytes32 pubkey, uint256 newOffset2) = Convert.read_bytes32(data, offset);
```

### Metaplex メタデータ

```solidity
import {MplTokenMetadataLib} from "@rome-protocol/rome-solidity/contracts/mpl_token_metadata/lib.sol";

// Metaplex からトークンメタデータを読み込む
MplTokenMetadataLib.Metadata memory meta = MplTokenMetadataLib.load_metadata(
    mintPubkey, mplProgramId, cpiAddress
);
string memory name = meta.name;
string memory symbol = meta.symbol;
```

## Rust SDK: アーキテクチャ

Rust SDK は Cargo ワークスペースです。主要なクレートは次のとおりです:

| クレート                | 目的                                                                                     |
| ------------------- | -------------------------------------------------------------------------------------- |
| `rome-sdk`          | コアAPI: `Rome` struct、config、3つのトランザクション型（`RheaTx`, `RemusTx`, `RomulusTx`)             |
| `rome-evm-client`   | Rome チェーン用 EVM クライアント、TxBuilder、ResourceFactory、エミュレータ統合                               |
| `rome-solana`       | Solana tower、RPC クライアント、トランザクションのバッチ処理と追跡                                              |
| `rome-utils`        | RLP、hex、JSON-RPC、認証ユーティリティ                                                             |
| `rome-obs`          | OpenTelemetry によるオブザーバビリティ（トレース、メトリクス、ログ）                                              |
| `rome-meteora`      | ガス価格設定用の Meteora DAMM v1/v2 プールリーダー                                                    |
| `rome-meta-hook`    | Meta-Hook Router プログラム向けクライアント：Token-2022 の transfer-hook 設定、追加アカウントの解決、計算量予算見積もり付きの転送 |
| `rome-jito-bundler` | 原子的な複数トランザクション送信のための Jito バンドルビルダー                                                     |

### トランザクション種別

```rust
// 1つの Rome チェーン上での1つの EVM トランザクション
let rhea = RheaTx::new(signed_eth_tx);
let mut tx = rome.compose_rollup_tx(rhea).await?;
let sig = rome.send_and_confirm(&mut *tx).await?;

// 複数の Rome チェーン上の複数 EVM トランザクションを、1つの Solana トランザクションで原子的に実行
let remus = RemusTx::new(vec![tx1, tx2]);
let mut tx = rome.compose_cross_rollup_tx(remus).await?;

// EVM トランザクションに加え、ネイティブ Solana 命令を、1つの Solana トランザクションで原子的に実行
let romulus = RomulusTx::new(eth_txs, sol_ixs);
let mut tx = rome.compose_cross_chain_tx(romulus, signers).await?;
```

### リソースプーリング

SDK は、並列トランザクション送信のために Solana の keypair（payer）と holder アカウントのインデックスをプールします:

```rust
let resource = resource_factory.get().await?;
let payer = resource.payer();       // Solana keypair
let holder = resource.holder();     // Holder アカウントのインデックス
// Resource は Drop 時に自動的にプールへ戻される
```

## SDK ロードマップ

### 実装済み・動作中

* SPL トークンラッパーとプリコンパイルインターフェース
* CPI 経由の Meteora DAMM v1 スワップ
* Oracle Gateway V1 + V2（Pyth Pull、Switchboard V3）
* System Program ヘルパー、Borsh デシリアライズ
* ERC20SPL Factory + ブリッジコントラクト

## 次は何か

* [Solidityをデプロイ](https://docs.rome.builders/ja/gaido/deploy-solidity.md) — SDK を使って最初のコントラクトをデプロイ
* [EVM から Solana を呼び出す](https://docs.rome.builders/ja/gaido/call-solana-from-evm.md) — CPI を使って Solana プログラムとやり取り
* [Contract Addresses](https://docs.rome.builders/ja/rifarensu/contract-addresses.md) — デプロイ済み SDK コントラクトアドレス


---

# 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/ja/zhi-pin/rome-sdk.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.
