0.0.73 • Published 2 years ago

@neptuneprotocol/neptune-sdk v0.0.73

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

What's new in this SDK version?

  • src has two new directories within it: token-lending holds code to interact with the token lending program and timelock has code to interact with the timelock staking program.
  • code to interact with the timelock staking program lives in src/timelock/actions. initializeLock will initialize a lock action, and initializeUnlock will initialize an unlock action.
  • both initializeLock and initializeUnlock will build and send the transactions needed for lock and unlock staking actions. They will both return the signatures of the transactions as a string. initializeLock may need to send multiple transactions.
  • Both initializeLock and initializeUnlock require a keypair, and the sendTransaction function generated by the wallet provider. initializeLock also requires the amount of tokens to lock in lamports and the yearsToLock the tokens in the form of a number. If a user locks tokens for 6 months, then yearsToLock equals 0.5. If a user locks tokens for 24 months, then yearsToLock equals 2.0.
  • there are new data points in the reserve data structure for baseRewardAprDeposits and baseRewardAprBorrows. This is the base APR a user receives for depositing or borrowing tokens with zero voting power expressed as a percentage. To calculate the APR a user receives with a full multiplier, multiply this value by 3.
  • there are new data points in the obligation data structure. obligation.obligationStats now has a field for netApy to calculate a user's net APY for their deposit and borrow positions. The obligation data structure also has a new field for neptuneStats that holds a user's multiplier, their current votingPower, their amount of lockedNeptune and their claimableRewards.

Got a basic webserver working with the Neptune SDK

New code is within the src/classes directory. The new files are server.ts, utils.ts, constant.ts and the routes directory.

First install dependancies with yarn and set solana config to devnet

Next, fill in the USER_PK and USER_SK values in the constant.ts file to your public key string and the uint8 array of your devnet wallet.

Run the script to generate a deposit transaction with ts-node scripts/testDeposit.ts.

The script is dependant on the API_ENDPOINT constant defined in src/classes/action.ts. It is currently set to the Neptune Devnet endpoint. We can change it to the API that we've created (http://neptune-finance-api.herokuapp.com/info) but this one currently returns Neptune account info from PRD, and will cause transactions to fail on devnet if used.


Quickstart examples

See the examples in the scripts folder for examples of how to configure the following types of transactions:

  1. Deposit
  2. Borrow
  3. Repay
  4. Withdraw

The following example illustrates how to set up a transaction that will deposit 2 SOL into our lending protocol, and then borrows 1 SOL from that deposited collateral

Private Key Storage (UNIX):

  • You can store your wallets private key as an environment variable in your .bashrc file (this keeps it as permanent storage every time you boot up your UNIX instance)
  • Do this:
    1. Go to your root directory of your UNIX instance, run vi ~/bash.rc
    2. Now go to the bottom of this file using your arrow keys, then press i to insert
    3. Now enter: export PRIVATE_KEY=insert byte array of private key here
    4. Now enter: export PUBLIC_KEY=insert string of public key here
    5. Press ESC then :wq
import {NeptuneAction} from '../src/classes/action'
import {
  Connection,
  clusterApiUrl, 
} from "@solana/web3.js";
import {sendTransaction} from './utils'

const dotenv = require('dotenv');
dotenv.config();
const USER_SK = process.env.PRIVATE_KEY
const USER_PK = process.env.PUBLIC_KEY

const tryDeposit = async () => {
  const conn = new Connection(clusterApiUrl('devnet'), 'confirmed');
  try {
    //build instructions for a deposit transaction
    const depositAction = await NeptuneAction.buildDepositTxns(
      conn,
      "2000000000", //note, amount is in lamports for transactions in SOL
      "SOL",
      USER_PK,
      "devnet"
    )

    //send the transaction to the blockchain. 
    const sig = await depositAction.sendTransactions(sendTransaction)
    console.log("Deposit signature", sig)
  } catch(err: any) {
    console.log(err.message)
  }
}

const tryBorrow = async () => {
  const conn = new Connection(clusterApiUrl('devnet'), 'confirmed');
  try {
    //build instructions for a deposit transaction
    const borrowAction = await NeptuneAction.buildBorrowTxns(
      conn,
      "1000000000", //note, amount is in lamports for transactions in SOL
      "SOL",
      USER_PK,
      "devnet"
    )

    //send the transaction to the blockchain. 
    const sig = await borrowAction.sendTransactions(sendTransaction)
    console.log("Borrow signature", sig)
  } catch(err: any) {
    console.log(err.message)
  }
}

tryDeposit();
tryBorrow();
0.0.62

2 years ago

0.0.63

2 years ago

0.0.64

2 years ago

0.0.65

2 years ago

0.0.67

2 years ago

0.0.68

2 years ago

0.0.69

2 years ago

0.0.61

2 years ago

0.0.73

2 years ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.71

2 years ago

0.0.72

2 years ago

0.0.6

2 years ago

0.0.50

2 years ago

0.0.49

2 years ago

0.0.48

2 years ago

0.0.47

2 years ago

0.0.46

2 years ago

0.0.45

2 years ago

0.0.44

2 years ago

0.0.43

2 years ago

0.0.42

2 years ago

0.0.41

2 years ago

0.0.40

2 years ago

0.0.39

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.36

2 years ago

0.0.35

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.32

2 years ago

0.0.31

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago