Git Product home page Git Product logo

client's Introduction

@sharkyfi/client

This repo gives examples for how to use the @sharkyfi/client library to interact with the Sharky solana program. It doesn't yet contain the client's code, because we use monorepo and publish package from there. But eventually the client's code will be migrated.

The examples directory contains scripts that provide a reference for performing automated lending actions. You can copy-paste code from there into your own code, or run the scripts directly.

Keep in mind that this repo and the Sharky library are licensed under GPLv3.

How to use the package

The recommended way is to fork this repo and use examples as a starting point for your scripting.

The more custom alternative is to run:

npm install @sharkyfi/client

And write your own scripts from scratch.

Examples

To run the scripts, run yarn or npm install, then:

Get the current list of orderbooks (name and pubkey):

npx ts-node examples/get-orderbooks.ts --wallet-path ~/.config/solana/id.json

Place a loan offer on an orderbook:

npx ts-node examples/place-offer.ts --wallet-path ~/.config/solana/id.json --order-book <order-book-pubkey> --amount-sol 1

List your current offers:

npx ts-node examples/list-offers.ts --wallet-path ~/.config/solana/id.json

Revoke an offer:

npx ts-node examples/revoke-offer.ts --wallet-path ~/.config/solana/id.json --loan <loan-pubkey>

Gotchas / things to know about how our data is structured

APR and APY

We originally named a property on loans and orderbooks "APY" when actually using it mathematically as APR. We've corrected this on the frontend, but in the data structure that is returned from the chain data, orderBook.apy.fixed?.apy is actually APR, as is loan.data.loanState.taken?.taken.apy.fixed!.apy.

Additionally, those are stored as millpercents โ€” thousandths of a percent, to allow for higher precision while being stored as integers.

To get regular APR and APY as percents from the values we store on chain:

// for orderbooks:
const apr = orderBook.apy.fixed!.apy / 1000
// or for taken loans:
const apr = loan.data.loanState.taken?.taken.apy.fixed!.apy / 1000

const apy = 100 * (Math.exp(apr / 100) - 1)

client's People

Contributors

phoenixeliot avatar restuta avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.