# Vault-SDK

You can find a brief tutorial example here => [vault-sdk-example](https://github.com/RatioFinance/vault-sdk-example)

#### 1. Install vault-sdk

```
yarn add @ratio-finance/vault-sdk
```

**2. Get** *`RatioLendingProgram`* **instance and Initialize**

```
import { RatioLendingProgram } from "@ratio-finance/vault-sdk";
const lendingProgram = RatioLendingProgram.getInstance(conn);
await lendingProgram.init();
```

#### 3. Deposit LP

```
const raydiumUsdtUsdcKey = "As3EGgLtUVpdNpE6WCKauyNRrCCwcQ57trWQ3wyRXDa6";
const depositTx = await lendingProgram.depositLP(
  USER_KEYPAIR.publicKey,  // UserPublicKey : PublicKey
  raydiumUsdtUsdcKey,      // CollateralMint: PublicKey
  0.1                      // DepositAmount: number (must be uiAmount)
);
const depositTxHash = await sendAndConfirmTransaction(
  conn,
  depositTx,
  [USER_KEYPAIR]
);
console.log(`deposit is done successfully. txHash = ${depositTxHash}`);
```

#### 4. Other Transactions

* Withdraw (Withdraw deposited collateral)

```
let withdrawTx = await lendingProgram.withdrawLP(
  USER_KEYPAIR.publicKey,    // UserPublicKey : PublicKey
  raydiumUsdtUsdcKey,        // CollateralMint : PublicKey
  0.05                       // WithdrawAmount : Number (uiAmount)
);
```

* Harvest (Harvest Yield Farming rewards)

```
let harvestTx = await lendingProgram.harvest(
  USER_KEYPAIR.publicKey,    // UserPublicKey : PublicKey
  raydiumUsdtUsdcKey         // CollateralMint: PublicKey
);
```

* Mint (Borrow USDr against deposited collateral.)

```
let mintTx = await lendingProgram.mintUSDr(
  USER_KEYPAIR.publicKey,     // UserPublicKey : PublicKey
  raydiumUsdtUsdcKey,         // CollateralMint: PublicKey
  0.05                        // MintAmount: Number (uiAmount)
);
```

* Repay (Repay USDr)

```
let repayTx = await lendingProgram.repayUSDr(
  USER_KEYPAIR.publicKey,     // UserPublicKey : PublicKey
  raydiumUsdtUsdcKey,         // CollateralMint: PublicKey
  0.04                        // RepayAmount: Number (uiAmount)
);
```

#### 5. Get Yield Farming Reward (Get pending reward from Yield Farming)

```
const rewardAmount = await lendingProgram.getYieldFarmingReward(
  USER_KEYPAIR.publicKey,
  raydiumUsdtUsdcKey
);
```

#### 6.  Get RATIO Apr Reward (If the pool has RATIO emission, user will get RATIO reward)

```
const ratioRewardAmount = await lendingProgram.getRatioRewards(
  USER_KEYPAIR.publicKey,
  raydiumUsdtUsdcKey
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ratio.finance/for-developers/vault-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
