@neptuneprotocol/neptune-sdk v0.0.73
What's new in this SDK version?
srchas two new directories within it:token-lendingholds code to interact with the token lending program andtimelockhas code to interact with the timelock staking program.- code to interact with the timelock staking program lives in
src/timelock/actions.initializeLockwill initialize a lock action, andinitializeUnlockwill initialize an unlock action. - both
initializeLockandinitializeUnlockwill build and send the transactions needed for lock and unlock staking actions. They will both return the signatures of the transactions as a string.initializeLockmay need to send multiple transactions. - Both
initializeLockandinitializeUnlockrequire a keypair, and thesendTransactionfunction generated by the wallet provider.initializeLockalso requires theamountof tokens to lock in lamports and theyearsToLockthe tokens in the form of anumber. If a user locks tokens for 6 months, thenyearsToLockequals0.5. If a user locks tokens for 24 months, thenyearsToLockequals2.0. - there are new data points in the
reservedata structure forbaseRewardAprDepositsandbaseRewardAprBorrows. 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
obligationdata structure.obligation.obligationStatsnow has a field fornetApyto calculate a user's net APY for their deposit and borrow positions. Theobligationdata structure also has a new field forneptuneStatsthat holds a user'smultiplier, their currentvotingPower, their amount oflockedNeptuneand theirclaimableRewards.
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:
- Deposit
- Borrow
- Repay
- 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:
- Go to your root directory of your UNIX instance, run vi ~/bash.rc
- Now go to the bottom of this file using your arrow keys, then press i to insert
- Now enter: export PRIVATE_KEY=insert byte array of private key here
- Now enter: export PUBLIC_KEY=insert string of public key here
- 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();4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago