Skip to main content

Overview

Rain SDK provides set of functions helping you to interact with the program. Utility functions allow you to fetch data about pools, collections, loans and borrowers.

What's more, they also allow you to generate ready transactions instructions for lending, borrowing, managing pools, repaying loans, and much, much more!

Utility functions are simply "swiss army knife" that you can use for all kinds of activities on Rain.

Prerequisites:

To get access to utility functions, you first have to initialize new Rain class. Rain class allows you to interact with whole Rain program.

import {Rain} from '@rainfi/sdk';
import {Connection, clusterApiUrl} from "@solana/web3.js";

// We will use this wallet as a placeholder.
// Normally, you would use PublicKey of your wallet
// (or your user's wallet).
const publicKey = Keypair.generate().publicKey;

// Initialize new connection to the Solana blockchain.
const connection = new Connection( clusterApiUrl('mainnet-beta') );

// Create new Rain class.
const rain = new Rain(
connection,
publicKey
);

Now, after new Rain class is initialized, we can do the following:

// ...

// Create new Rain class.
const rain = new Rain(
connection,
publicKey
);

// Look here:
const {
computeAmount,
computeInterest,
getAvailableCollections,
getCollection,
getAllPoolAvailable,
getLoansFromPool,
// and so on....
} = rain.utils;

This way, we got access to all utility functions of the Rain program. As you can see, they will allow us to do things like:

  • Get particular collection, or get all collections that Rain.fi supports,
  • Get all loans from particular pool, or get all currently running loans,
  • Compute interest rate, loan amounts...

... and much, much more!