> ## 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        | txtx.yml을 기준으로 한 IDL `.json` 파일의 경로 |
| `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바이트 discriminator(여기서는
`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)])
}
```
