@rainfi/rain v1.0.80
- This code is given as is and is unaudited. Use at your own risk.
- The examples might not be always up to date since the package is in active developemnt.
Table of contents:
Installation
Yarn:
yarn add @rainfi/rain
NPM:
npm i @rainfi/rain
Usage
import { Pool, Rain } from "@rainfi/rain";
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
const publicKey = new Keypair().publicKey // Your pubkey
const poolOwner = new PublicKey("OWNER_OF_POOL_PUBKEY")
// Let you interact with a specific pool only
const pool = new Pool(connection, poolOwner, publicKey)
// Let you interact with the whole protocol
const rain = new Rain(connection, publicKey)
Examples
Pool Class
Let you interact with a specific pool only. Useful when you want to intergarte it on your website.
import { Pool } from "@rainfi/rain";
import { Connection, LAMPORTS_PER_SOL } from "@solana/web3.js";
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
const publicKey = new Keypair().publicKey // Your pubkey
const poolOwner = new PublicKey(OWNER_OF_POOL)
const pool = new Pool(connection, poolOwner, publicKey)
// To fetch/refresh data of the pool
const poolData = await pool.fetch()
// To fetch all loans from the pool, including current, liquidated and repaid ones
const allLoans = await pool.loans('all')
// To get all opens/current loans from pool
const loansOpen = await pool.loans('ongoing')
// To get all loan history from pool
const loansHistory = await pool.loans('history')
// You can also pass the borrower pubkey to get the loans related to your pool from a specific address
const allLoans = await pool.loans('all', publicKey)
// To get whitelisted collections fromm the pool
const poolCollections = await pool.collections()
// Here, we just take the first collections in the pool as example
const collection = poolCollections[0]
//Create the borrow instruction
const borrowIxs = await pool.borrow(
new PublicKey("Eb89RFb5MZh4QWaae7m3pMQf5S1eNwUvoaYcpiDGdBfE"), // NFT mint address string that you want to collateralize
3, // The duration of the loan in DAYS
20 * LAMPORTS_PER_SOL, // Amount you want to borrow, must be lower than collection.maxAmountToBorrow
collection.floorPrice // FloorPrice of the collection, used to avoid front run
)
//Create the repay instruction
const loanAddress = loansOpen[0].accountAddress // address of the account holding data for the loan
const repayIx = await rain.repay(loanAddress)
// send your instructions
Rain Class
Let you interact with the whole protocol and its features/functions with any pool.
Create a pool
import { Rain } from "@rainfi/rain";
import { Connection, LAMPORTS_PER_SOL } from "@solana/web3.js";
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
const publicKey = new Keypair().publicKey // Your pubkey
const rain = new Rain(connection, publicKey)
const instruction = await rain.createPool(
{
loanToValue: 50, // 50% of the floor price of the NFT
maxAmount: 100, // Max amount that can be used per loan in SOL, should default to size of the pool
interestType: 1, // Enable dynamic interest or not
interestRate: (!dynamicInterest && loanInterest * 100) || 0, // If dynamicInterest is used, we set the interest rate, else we set to 0 since program will overwrite
interestCurve: 25, // Interest curve depending on your parameter see docs
interestGap: 19, // Interest curve depending on your parameter see docs
maxDuration: 14, // In days
compound: true, // Compound interest or not, put the profit back in the pool or not
amount: 100, // pool size = 100 SOL
collections: [301, 793, 292] // Ids of the collections that you want to authorize loan to, can be obtained using getAvailableCollections()
}
)
// wrap and send your instructions
Borrow
import { Rain } from "@rainfi/rain";
import { Connection, LAMPORTS_PER_SOL } from "@solana/web3.js";
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
const publicKey = new Keypair().publicKey // Your pubkey
const rain = new Rain(connection, publicKey)
// Get all pools available
const poolAvailable = await rain.utils.getAllPoolAvailable(connection)
// Select the pool
const pool = poolAvailable[0]
// To get all collections and their data, use that function.
const allCollections = await rain.utils.getAvailableCollections(connection)
// Here, we just want the data of Degenerate Ape Academy collection
const collection = await rain.utils.getCollection(connection, 292) // 292 is the ID of the DAA collection on rain
const duration = 3 // The duration of the loan in DAYS
//Create a borrow instruction
const borrowIxs = await rain.borrow({
nftMint: new PublicKey("Eb89RFb5MZh4QWaae7m3pMQf5S1eNwUvoaYcpiDGdBfE"), // NFT mint address string that you want to collateralize
poolOwner: pool.owner, // The owner of the pool
duration: duration, // The duration of the loan in DAYS
amount: 20 * LAMPORTS_PER_SOL, // Amount you want to borrow, must be lower than loanToValue
floorPrice: collection.floorPrice // FloorPrice of the collection, used to avoid front run
})
// wrap and send your instructions
License
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion by you shall be licensed at the discretion of the repository maintainers without any additional terms or conditions.
TODO
- Add more examples
- actually do the TODO
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago