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

@marinade.finance/native-staking-sdk

v1.3.1

Published

Marinade SDK for the Native Staking

Downloads

1,729

Readme

Marinade Native Staking SDK

This is SDK for interaction with Marinade Native Staking product.

Staking through this product is done by changing the stake authority of user's stake account(s) for example through this SDK.

Unstaking can be always done by user manually through Solana CLI - but that would be tedious as Marinade splits the user stake accounts into 100+ stake accounts. Marinade accepts requests from users to unstake part or all stake accounts and merge them into a single one, so the user flow is simplified (but Marinade charges a small fee). This is also handled by the SDK.

Overview

Install and intialize the SDK

Install the package:

pnpm i @marinade.finance/native-staking-sdk

Initialize the SDK:

import { Connection } from '@solana/web3.js'
import { NativeStakingConfig, NativeStakingSDK } from '@marinade.finance/native-staking-sdk'

const config = new NativeStakingConfig({ connection: new Connection('...') })
const sdk = new NativeStakingSDK(config)

Stake SOL through Marinade Native Staking

const { connection } = useConnection() // from @solana/wallet-adapter-react
const { sendTransaction, signTransaction, publicKey } = useWallet() // from @solana/wallet-adapter-react
const amount = new BN('1000000000') // 1 SOL

const { createAuthorizedStake, stakeKeypair } = sdk.buildCreateAuthorizedStakeInstructions(publicKey, amount)

const { blockhash } = await connection.getLatestBlockhash()
const tx = new VersionedTransaction(new TransactionMessage({
    payerKey: publicKey,
    recentBlockhash: blockhash,
    instructions: createAuthorizedStake,
}).compileToV0Message())

tx.sign([stakeKeypair]) // add signature of the stake account
await signTransaction(tx) // add signature of the user
await sendTransaction(tx, connection)

Stake Referred SOL through Marinade Native Staking

const { connection } = useConnection() // from @solana/wallet-adapter-react
const { sendTransaction, signTransaction, publicKey } = useWallet() // from @solana/wallet-adapter-react
const amount = new BN('1000000000') // 1 SOL

const partnerReferralPubkey = new PublicKey('...')

const tx = await sdk.getRefSolSignedTransaction(publicKey, amount, partnerReferralPubkey.toString())

await signTransaction(tx) // add signature of the user
await sendTransaction(tx, connection)

Migrate Stake accounts to Marinade Native Staking

const { connection } = useConnection() // from @solana/wallet-adapter-react
const { sendTransaction, signTransaction, publicKey } = useWallet() // from @solana/wallet-adapter-react
const stakeAccount = new PublicKey('...') // stake account to migrate

const authorizeInstructions = sdk.buildAuthorizeInstructions(publicKey, [stakeAccount])

const { blockhash } = await connection.getLatestBlockhash()
const tx = new VersionedTransaction(new TransactionMessage({
    payerKey: publicKey,
    recentBlockhash: blockhash,
    instructions: authorizeInstructions,
}).compileToV0Message())

await signTransaction(tx) // add signature of the user
await sendTransaction(tx, connection)

Migrate Referred Stake account to Marinade Native Staking

const { connection } = useConnection() // from @solana/wallet-adapter-react
const { sendTransaction, signTransaction, publicKey } = useWallet() // from @solana/wallet-adapter-react

const partnerReferralPubkey = new PublicKey('...')

const stakeAccount = new PublicKey('...') // stake account to migrate

const tx = await sdk.getRefStakeAccountSignedTransaction(publicKey, stakeAccount, partnerReferralPubkey.toString())

await signTransaction(tx) // add signature of the user
await sendTransaction(tx, connection)

Prepare for unstake

const { connection } = useConnection() // from @solana/wallet-adapter-react
const { sendTransaction, signTransaction, publicKey } = useWallet() // from @solana/wallet-adapter-react
const amount = new BN('1000000000') // 1 SOL

const { payFees, onPaid } = await sdk.initPrepareForRevoke(publicKey, amount) // pass `null` instead of `amount` to prepare everything for unstake

// sdk.config.prepareForRevokeCost - fee in lamports

const { blockhash } = await connection.getLatestBlockhash()
const tx = new VersionedTransaction(new TransactionMessage({
    payerKey: publicKey,
    recentBlockhash: blockhash,
    instructions: payFees,
}).compileToV0Message())

await signTransaction(tx) // add signature of the user
const signature = await sendTransaction(tx, connection)

await connection.confirmTransaction(signature, 'finalized') // wait for the payment to go through
await onPaid(signature) // notify our BE that the user has paid, so we can prepare some/all stake accounts (based on the input amount) to be merged them into a single stake account (at the beginning of the next epoch), so the SOL can be easily withdrawn (or stake account claimed if it is Locked).

Fetch user's stake accounts in Marinade Native Staking

const { publicKey } = useWallet() // from @solana/wallet-adapter-react
await sdk.getStakeAccounts(publicKey) // fetches stake accounts ready to be revoked, stake acccount that are being prepared to be revoked, stake accounts that Marinade manages

Show user's rewards

const { publicKey } = useWallet() // from @solana/wallet-adapter-react
await sdk.fetchRewards(publicKey) // fetches rewards of user's stake accounts in the Marinade Native Staking (note: apy will be `null` if there are no active stake accounts yet)