> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# SVM関数

> SolanaおよびSVM互換ブロックチェーン向けの関数

これらの関数は、SolanaおよびSVM互換ブロックチェーン向けのSVMアドオンを使用する際に利用できます。

## system_program_id

`svm::system_program_id` は、system program のID `11111111111111111111111111111111` を返します。

```hcl
output "system_program_id" {
    value = svm::system_program_id()
}
// > 11111111111111111111111111111111
```

---

## default_pubkey

`svm::default_pubkey` は、デフォルトの公開鍵 `11111111111111111111111111111111` を返します。

```hcl
output "default_pubkey" {
    value = svm::default_pubkey()
}
// > 11111111111111111111111111111111
```

---

## get_instruction_data_from_idl_path

`svm::get_instruction_data_from_idl_path` は、指定されたIDLファイルに基づく型チェックとシリアライズを行い、プログラム呼び出し用にエンコードされた instruction data を作成します。

### 入力

| 名前               | 必須 | 型          | 説明                                                 |
| ------------------ | -------- | ------------- | ----------------------------------------------------------- |
| `idl_path`         | 必須 | string        | IDLの `.json` ファイルへの、txtx.yml からの相対パス |
| `instruction_name` | 必須 | string        | データを生成する対象のインストラクション名            |
| `arguments`        | 任意 | array[string] | データを生成する対象のインストラクション引数              |

```hcl
output "data" {
    value = svm::get_instruction_data_from_idl_path("idl.json", "my_instruction", ["arg1", "arg2"])
}
// > data: 0xc3f1b80e7f9b443504000000617267310400000061726732
```

Anchor IDLの場合、データはインストラクションの8バイトのディスクリミネーター(ここでは `c3f1b80e7f9b4435`、つまり `sha256("global:my_instruction")` の先頭8バイト)に、Borshエンコードされた引数が続く形式になります。各文字列は、4バイトのリトルエンディアンの長さとそのUTF-8バイト列で表されます。

---

## get_instruction_data_from_idl

`svm::get_instruction_data_from_idl` は、指定されたIDLデータに基づく型チェックとシリアライズを行い、プログラム呼び出し用にエンコードされた instruction data を作成します。

### 入力

| 名前               | 必須 | 型              | 説明                                                             |
| ------------------ | -------- | ----------------- | ----------------------------------------------------------------------- |
| `idl`              | 必須 | string \| SVM_IDL | プログラムのIDL                                                         |
| `instruction_name` | 必須 | string            | データを生成する対象のインストラクション名(IDLのインデックスに基づく) |
| `arguments`        | 任意 | array[string]     | データを生成する対象のインストラクション引数                          |

```hcl
output "data" {
    value = svm::get_instruction_data_from_idl(variable.contract.idl, "my_instruction", ["arg1", "arg2"])
}
// > data: 0xc3f1b80e7f9b443504000000617267310400000061726732
```

---

## get_program_from_anchor_project

`svm::get_program_from_anchor_project` は、Anchor プロジェクト内のプログラムのデプロイ用アーティファクトを取得します。

### 入力

| 名前           | 必須 | 型   | 説明                              |
| -------------- | -------- | ------ | ---------------------------------------- |
| `program_name` | 必須 | string | デプロイするプログラムの名前   |
| `keypair_path` | 任意 | string | プログラムの keypair ファイルの場所 |
| `idl_path`     | 任意 | string | プログラムのIDLファイルの場所     |
| `bin_path`     | 任意 | string | プログラムのバイナリファイルの場所  |

```hcl
variable "contract" {
    value = svm::get_program_from_anchor_project("my_program")
}
output "idl" {
    value = variable.contract.idl
}
```

---

## get_program_from_native_project

`svm::get_program_from_native_project` は、Anchor 以外のプログラムのデプロイ用アーティファクトを取得します。

### 入力

| 名前           | 必須 | 型   | 説明                              |
| -------------- | -------- | ------ | ---------------------------------------- |
| `program_name` | 必須 | string | デプロイするプログラムの名前   |
| `keypair_path` | 任意 | string | プログラムの keypair ファイルの場所 |
| `idl_path`     | 任意 | string | プログラムのIDLファイルの場所     |
| `bin_path`     | 任意 | string | プログラムのバイナリファイルの場所  |

```hcl
variable "contract" {
    value = svm::get_program_from_native_project("my_program")
}
output "idl" {
    value = variable.contract.idl
}
```

---

## sol_to_lamports

`svm::sol_to_lamports` は、指定された SOL の量を lamports に変換します。

```hcl
output "lamports" {
    value = svm::sol_to_lamports(1.1)
}
// lamports: 1100000000
```

---

## lamports_to_sol

`svm::lamports_to_sol` は、指定された lamports の数量を SOL に変換します。

```hcl
output "sol" {
    value = svm::lamports_to_sol(1100000000)
}
// sol: 1.1
```

---

## find_pda

`svm::find_pda` は、指定されたプログラムIDと seeds を使用して有効なPDAを見つけます。

### 入力

| 名前         | 必須 | 型          | 説明                                        |
| ------------ | -------- | ------------- | -------------------------------------------------- |
| `program_id` | 必須 | string        | PDAの導出元となるプログラムのアドレス |
| `seeds`      | 任意 | array[string] | seeds の任意の配列(最大16個、各32バイト) |

```hcl
variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", ["data"])
}
output "pda" {
    value = variable.pda.pda
}
output "bump" {
    value = variable.pda.bump_seed
}
// > pda: AAU8CSawL7uBQLt4QHdTtwsNuRQthNtYzhMVNx2bwuGC
// > bump: 254
```

---

## get_associated_token_account

`svm::get_associated_token_account` は、指定されたウォレットとトークンミントのアドレスに対する associated token account のアドレスを計算します。

### 入力

| 名前                 | 必須 | 型   | 説明                   |
| -------------------- | -------- | ------ | ----------------------------- |
| `wallet_address`     | 必須 | string | ウォレットのアドレス     |
| `token_mint_address` | 任意 | string | トークンミントのアドレス |

```hcl
variable "token_account" {
    value = svm::get_associated_token_account(signer.caller.address, "So11111111111111111111111111111111111111112")
}
```

---

## create_token_account_instruction

`svm::create_token_account_instruction` は、associated token account を作成するための生のインストラクションバイトを作成します。

### 入力

| 名前                 | 必須 | 型   | 説明                        |
| -------------------- | -------- | ------ | ---------------------------------- |
| `funding_address`    | 必須 | string | 資金提供アカウントのアドレス |
| `wallet_address`     | 必須 | string | ウォレットのアドレス          |
| `token_mint_address` | 任意 | string | トークンミントのアドレス      |
| `token_program_id`   | 任意 | string | token program のアドレス   |

```hcl
action "call" "svm::process_instructions" {
    signers = [signer.caller]

    instruction {
        raw_bytes = svm::create_token_account_instruction(
            signer.caller.address, // funding address
            signer.caller.address, // wallet address
            variable.token_mint, // token mint address
            variable.token_program // token program id
        )
    }
}
```

---

## u64

`svm::u64` は、u64整数のバイト配列表現を作成します。PDA導出時の seed として使用するのに適しています。

### 入力

| 名前    | 必須 | 型    | 説明                                |
| ------- | -------- | ------- | ------------------------------------------ |
| `value` | 必須 | integer | バイト配列に変換するu64整数 |

```hcl
variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::u64(1000000000)])
}
```

---

## i64

`svm::i64` は、i64整数のバイト配列表現を作成します。PDA導出時の seed として使用するのに適しています。

### 入力

| 名前    | 必須 | 型    | 説明                                |
| ------- | -------- | ------- | ------------------------------------------ |
| `value` | 必須 | integer | バイト配列に変換するi64整数 |

```hcl
variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::i64(-1000000000)])
}
```
