Vault-SDK

SDK for developers who wants to integrate ratio vaults into their app.

You can find a brief tutorial example here => 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
);

Last updated