본문으로 바로가기
Time to read: 1 min

Deploying Your First Organic Yield Vault

Yield vaults turn rBTC into a productive asset by automating interest-bearing strategies. The Rootstock Vaults SDK provides a standardized way to interact with ERC-4626 vaults. This tutorial explains how to initialize the SDK and deposit rBTC into a vault.

Vaults SDK Architecture

The Vaults SDK sits on top of the Web3 Core Layer to manage financial logic. It uses a modular pattern to separate chain communication from vault-specific functions.

  1. Web3 Core Layer: It provides the connection to the Rootstock network.
  2. Vaults Module: It contains functions to read vault data and execute deposits.
  3. Contract Registry: It stores the addresses and ABIs for the vault ecosystem.

Prerequisites

You must prepare your environment before you interact with a vault.

  • Install the @rskSmart/vaults and @rskSmart/w3layer packages.
  • Acquire a small amount of rBTC for transaction fees.
  • Configure a provider for the Rootstock Testnet or Mainnet.

Initializing the Vaults SDK

You must establish a connection to the Rootstock network through the Web3 Core Layer. This layer is agnostic to the specific module you use.

// Define your network configuration
const config = { rpcUrl: "https://public-node.testnet.rsk.co" };

// Initialize the core interaction layer
const core = new Web3CoreLayer(config);

// Load the vaults module using the core layer
const vaults = new VaultsSDK(core);

Interacting with a Yield Vault

The SDK uses the "Read" sequence to fetch vault metadata from the Contract Registry. This metadata includes the vault address and the current Annual Percentage Yield (APY).

Reading Vault State

You check the status of a vault before you commit funds.

// Fetch the vault instance by its identifier
const vaultInstance = await vaults.getVault("rBTC-Primary-Vault");

// Retrieve the current total assets managed by the vault
const totalAssets = await vaultInstance.readBalance();

Executing a Deposit

Depositing assets follows the SDK "Write" sequence. The process includes a mandatory simulation step to verify the transaction success[cite: 908].

Depositing rBTC

The SDK handles the complexity of the ERC-4626 deposit function.

// Set the amount of rBTC to deposit
const depositAmount = parseEther("0.05");

// The SDK simulates the transaction to prevent gas loss
// It then requests a signature from your wallet client
const txHash = await vaults.writeContract("deposit", { amount: depositAmount }, signer);

// Wait for the network to confirm the transaction
const confirmation = await core.checkConfirmations(txHash);

Functional Flow in the Stack

Yield generation is the primary outcome of the BTCFi ecosystem. The following diagram shows how the Vaults SDK connects your application to Bitcoin security.

OUTCOME
ORGANIC YIELD
YIELD AGGREGATION
DEVELOP

ROOTSTOCK VAULTS SDK • FOUNDRY

UTILITY
CONTRACT REGISTRY
WEB3 CORE LAYER
LOGIC
ROOTSTOCK VIRTUAL MACHINE (RVM)
SETTLE
BITCOIN: PROOF-OF-WORK SECURITY

Next Steps

After you deploy your first vault interaction, you should improve your application:

최종 수정: 작성일: 작성자: Owanate Amachree