> 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/ko/rome/09-build-a-dual-lane-app.md).

# 9. 듀얼 레인 앱 구축하기

MetaMask 사용자와 Solana 지갑 사용자가 모두 입금하고 출금할 수 있는 하나의 볼트 컨트랙트를 만들고, 양쪽에서 같은 잔액을 확인해 보세요.

이것은 빌드 레슨입니다 ([2. 만들 수 있는 것](https://docs.rome.builders/ko/rome/02-what-you-can-build.md) 사용 사례를 나열합니다). USDC 볼트 하나를 만들고 한 번 배포한 뒤, MetaMask와 솔라나 지갑 두 개에서 사용합니다. 마지막에는 두 사용자 모두 같은 계약 상태에서 잔액을 갖게 됩니다.

## 배울 내용

* 듀얼 레인 계약의 형태: 일반 ERC-20 볼트.
* 각 레인이 입금과 출금을 위해 따르는 순서화된 단계.
* 왜 솔라나 레인에는 펀드 단계와 스윕 단계가 있고, EVM 레인에는 없는지.
* Solidity 코어와 솔라나 프로그램 코어 중에서 어떻게 선택할지.
* 각 단계의 비용을 어떻게 측정할지.

## 시작하기 전에

* 마치기 [8. Solana 프로그램을 EVM 사용자에게 개방하기](https://docs.rome.builders/ko/rome/08-open-your-solana-program-to-evm-users.md). 레슨 7에서는 이 빌드가 사용하는 솔라나 레인을 다루므로, [7. EVM 앱을 Solana 지갑에 개방하기](https://docs.rome.builders/ko/rome/07-open-to-solana-wallets.md) 건너뛰었다면 먼저 읽으세요.
* Hadrian에서 MetaMask와, v1 트랜잭션에 서명하는 솔라나 개발넷의 솔라나 지갑을 준비하고, 둘 다 레슨 3과 [파우셋](https://docs.rome.builders/ko/resources/faucets.md).
* TypeScript SDK가 설치되어 있어야 합니다([Rome SDK](https://docs.rome.builders/ko/products/rome-sdk.md#typescript-sdk-rome-protocol-sdk)) 그리고 Foundry 또는 Hardhat([Solidity 계약 배포](https://docs.rome.builders/ko/developer-guides/deploy-solidity.md)).

## 이 레슨

### 1단계. 코어를 선택하세요

듀얼 레인 앱은 핵심 로직을 한쪽에 둡니다. 코어가 Solidity이고 솔라나 사용자가 합성 주소를 통해 접근하거나, 코어가 네이티브 솔라나 프로그램이고 EVM 사용자가 얇은 라우터를 통해 접근합니다. 둘 중 어느 것도 규칙은 아닙니다. 이미 가지고 있는 코드, 팀, 그리고 앱이 무엇을 하는지를 기준으로 선택하세요. [핵심을 선택하세요](https://docs.rome.builders/ko/core-concepts/choose-your-core.md) 장단점을 나열합니다.

이 과정은 첫 번째 형태를 구현합니다. 더 짧은 경로이며 표준 EVM 도구를 사용합니다. 대신 솔라나 프로그램을 보유하고 있다면, 레슨 8과 [Solana 프로그램 통합](https://docs.rome.builders/ko/developer-guides/integrate-solana-program.md) 누가 서명하는지, 토큰이 어떻게 이동하는지, 그리고 단일 경로 규칙을 다룹니다. 핵심 요점은 이 레슨에도 그대로 적용됩니다: 계약은 사용자의 토큰을 스스로 이동시킬 수 없으므로, 사용자가 먼저 권한을 부여합니다.

### 2단계. 볼트를 작성하세요

볼트는 토큰을 `transferFrom` 로 가져오고 `transfer`로 돌려보냅니다. 그 안에는 로마에만 특화된 것은 없습니다.

```solidity
function deposit(uint256 amount) external {
    require(token.transferFrom(msg.sender, address(this), amount));
    balanceOf[msg.sender] += amount;
}
function withdraw(uint256 amount) external {
    balanceOf[msg.sender] -= amount;
    require(token.transfer(msg.sender, amount));
}
```

생성자는 wUSDC 래퍼 주소를 받습니다. 레슨 3에서 했던 것처럼 Hadrian에 배포한 다음, 소스를 검증하세요([계약 검증](https://docs.rome.builders/ko/developer-guides/verify-contracts.md)). 전체 계약은 [듀얼 레인 앱 빌드](https://docs.rome.builders/ko/developer-guides/dual-lane-app.md).

### 3단계. EVM 레인을 실행하세요

MetaMask 사용자는 USDC를 네이티브 가스로 보유하고 있고, 볼트는 wUSDC를 받습니다. 따라서 이 레인에는 네 단계가 있으며, 각 단계는 일반 트랜잭션입니다:

1. 일부 가스를 wUSDC로 래핑합니다 `withdraw_to_ata` Withdraw 프리컴파일에서.
2. 한 번 래퍼에 권한을 부여합니다, 만약 `isEnabled(user)` 가 false라면 래퍼를 권한 부여하세요.
3. `approve` wUSDC에 대해 볼트를.
4. `예치` 볼트로.

펀드 단계나 스윕 단계는 없습니다. 래핑된 토큰은 이미 사용자의 EVM 주소에 있습니다. 코드는 [MetaMask에서 동일한 앱](https://docs.rome.builders/ko/developer-guides/dual-lane-app.md#the-same-app-from-metamask)에 있습니다. 프리컴파일 주소는 [프리컴파일](https://docs.rome.builders/ko/reference/precompiles.md).

### 4단계. 솔라나 레인을 실행하세요

솔라나 사용자는 SOL과 SPL USDC를 보유합니다. 각 단계는 해당 지갑이 서명하는 v1 트랜잭션입니다:

1. 다음을 사용해 합성 계정을 준비합니다 `create_pda`, 한 번.
2. 펀드 단계: 지갑의 토큰 계정에서 합성 계정의 토큰 계정으로 USDC를 이동합니다.
3. 래퍼에 권한을 부여합니다, 만약 `isEnabled` 가 false라면 래퍼를 권한 부여하세요.
4. `approve` 볼트.
5. `예치`.

출금은 역순으로 진행됩니다. `withdraw` 토큰을 합성 계정으로 되돌리고, 스윕 단계가 이를 사용자의 자신의 지갑으로 옮깁니다. 전체 출금과 스윕이 끝나면 합성 계정의 입금된 토큰 잔액은 다시 0이 됩니다. 이들은 별도의 트랜잭션이므로, 입금이나 스윕이 실패하면 합성 계정의 토큰 잔액을 읽고 사용자가 다시 시도하거나 나머지를 되돌려 스윕하게 하세요. 단계별 코드는 [유입 가치](https://docs.rome.builders/ko/developer-guides/dual-lane-app.md#value-in-deposit-step-by-step) 그리고 [유출 가치](https://docs.rome.builders/ko/developer-guides/dual-lane-app.md#value-out-withdraw-step-by-step).

두 레인 모두에서 앱의 첫 입금 흐름에 권한 부여 확인을 넣어두세요. 토큰 계정에는 대리인이 하나만 있으므로, 브리지나 라우터 같은 다른 프로그램에 나중에 권한을 부여하면 래퍼의 권한 부여가 대체됩니다. 이전 권한이 아직 남아 있다고 가정하지 말고, `isEnabled` 각 입금 전에 확인하세요 ([지갑당 1회 권한 부여](https://docs.rome.builders/ko/core-concepts/token-interop.md#one-time-grant-per-wallet)).

### 5단계. 각 단계를 측정하세요

읽기 `computeUnitsConsumed` 레슨 7에서처럼 각 솔라나 레인 단계의 솔라나 영수증에서 확인하세요. 가이드에는 Hadrian에서 각 단계가 사용한 컴퓨트 유닛, 바이트, 계정 수가 나와 있습니다. 그 표의 모든 단계는 원자적 예산보다 한참 낮습니다. 그 수치를 기준선으로 삼고, 자신의 수치와 비교하세요.

단계가 약 140만 컴퓨트 유닛이나 64개 계정에 근접하면, 릴레이로 라우팅하거나 단순화하세요.  [제약 사항](https://docs.rome.builders/ko/core-concepts/constraints.md) 그리고 [컴퓨트 예산](https://docs.rome.builders/ko/core-concepts/compute-budget.md).

## 자신을 점검해 보세요

이 작업은 Hadrian에서 수행하고 링크를 보관하세요.

1. MetaMask에서 입금합니다. 솔라나 지갑에서 입금합니다.
2. 읽기 `balanceOf` 두 주소 모두에 대해 볼트에서. 각각은 자신의 입금을 보여줍니다. 솔라나 사용자의 경우, 합성 주소에서 확인하세요.
3. 각 트랜잭션을 Hadrian 탐색기에서 여세요([Hadrian](https://docs.rome.builders/ko/networks/hadrian.md) 에는 링크가 있습니다; [Via](https://docs.rome.builders/ko/rome-1/via.md) 무엇을 보여주는지 설명합니다). 솔라나 레인 입금의 경우, Via의 "Settled in" 링크를 따라 솔라나 트랜잭션으로 이동하세요. 솔라나 탐색기에서 해당 지시사항과 컴퓨트 유닛을 확인할 수 있습니다.
4. 둘 다 출금하세요. 솔라나 사용자의 USDC는 자신의 지갑으로 돌아갑니다.

솔라나 레인 입금이 SPL 오류 `0x4`로 되돌려지면, 래퍼 권한이 없습니다.

그런 다음 답하세요:

* 앱의 어느 쪽에 펀드 단계가 필요하며, 그 이유는 무엇인가요?
* 전체 왕복 후 솔라나 사용자의 합성 계정에는 무엇이 남아 있나요?

<details>

<summary>정답</summary>

* 솔라나 레인입니다. 사용자의 USDC는 지갑의 토큰 계정에서 시작합니다. 펀드 단계가 이를 합성 계정의 토큰 계정으로 옮기므로, 래퍼 잔액에 반영됩니다. MetaMask 사용자의 토큰은 이미 EVM 주소에 있습니다.
* 입금된 토큰은 없습니다. 스윕 단계가 이를 사용자의 지갑으로 되돌려보냅니다.

</details>

## 다음

[10. 다른 체인에서 사용자와 자금 가져오기](https://docs.rome.builders/ko/rome/10-from-other-chains.md)


---

# 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/ko/rome/09-build-a-dual-lane-app.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.
