npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@famousfoxfederation/citrus-sdk

v0.3.3

Published

SDK to interact with the Citrus P2P lending platform

Downloads

12

Readme

Citrus SDK

Citrus is a P2P lending platform on Solana by Famous Fox Federation. This package can be used to interact with the program directly.

Installation

npm i @famousfoxfederation/citrus-sdk

Update

Starting, 27/04/2023 you can make offers directly using LTV. Offers with LTV set have principal set to 0, you can fill this in using the floor prices from the fetchCollections call.

Usage

Create a CitrusSDK object with a wallet and connection. You can use Wallet from @coral-xyz/anchor or AnchorWallet from @solana/wallet-adapter.

import { Wallet, web3 } from "@coral-xyz/anchor";
import { CitrusSdk } from "@famousfoxfederation/citrus-sdk";

const keypair = web3.Keypair.fromSecretKey(process.env.SECRETKEY);
const wallet = new Wallet(keypair);
const conn = new web3.Connection(process.env.RPC_NODE, { commitment: 'confirmed' });
const sdk = new CitrusSdk(wallet, conn);
const collections = await sdk.fetchCollections();

Methods

The SDK provides the following methods to fetch data:

  • fetchCollections : Get list of collections available for lending on Citrus.
  • fetchLoan : Get loan information from a loan account.
  • fetchLoans : Get loan information for multiple loan accounts.
  • fetchUserLoans : Get loans lent or borrowed by a user.
  • fetchCollectionLoans : Get loans available or active for a collection.
  • calculateInterest : Calculate interest for given terms

Note: These methods use getProgramAccounts under the hood and are subject to performance issues. You can also use the Hellomoon Citrus API for faster and efficient data fetching.

And the following methods to make transactions:

  • offerLoan : Offer a loan with given terms for a collection.
  • cancelLoanOffer : Cancel an offer created with the method above.
  • borrowLoan : Borrow an open loan offer with an NFT.
  • borrowTxn : Transaction object to borrow a loan.
  • repayLoan: Repay an active loan.
  • claimLoan: Claim a defaulted loan.
  • requestLoan: List an NFT for loan.
  • cancelLoanRequest: Cancel the listing made above.
  • lend: Fulfil a loan request.
  • reborrow: Borrow a loan by repaying the active one.

Additionally, the SDK also provides a couple onchain listeners to get loans created, updated or cancelled in real time.

  • loanUpdateListener : Stream loans created or updated.
  • loanCancelListener: Stream loans cancelled.

Example

const collections = await sdk.fetchCollections();
const fff = collections.find((c) => c.name === 'Famous Fox Federation');
const terms: OfferTerms = {
    principal: 40,
    apy: 140,
    duration: 7,
};
const { loanAccount } = await sdk.offerLoan(terms, new web3.PublicKey(fff!.id));
console.log(`Created new loan offer ${loanAccount} with interest ${sdk.calculateInterest(terms) / web3.LAMPORTS_PER_SOL} SOL`);
await sdk.cancelLoanOffer(new web3.PublicKey(loanAccount));
console.log(`Cancelled loan offer ${loanAccount}`);