1.0.80 • Published 1 year ago

@rainfi/rain v1.0.80

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago
  • 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
1.0.62

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.66

2 years ago

1.0.65

2 years ago

1.0.64

2 years ago

1.0.63

2 years ago

1.0.69

2 years ago

1.0.68

2 years ago

1.0.67

2 years ago

1.0.73

2 years ago

1.0.72

2 years ago

1.0.71

2 years ago

1.0.70

2 years ago

1.0.77

2 years ago

1.0.33

2 years ago

1.0.76

2 years ago

1.0.75

2 years ago

1.0.74

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.79

1 year ago

1.0.35

2 years ago

1.0.78

2 years ago

1.0.34

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.80

1 year ago

1.0.40

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.49

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.59

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago