# @marinade.finance/native-staking-sdk

> Marinade SDK for the Native Staking

Latest version **1.3.4** (published 2025-05-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @marinade.finance/native-staking-sdk
pnpm add @marinade.finance/native-staking-sdk
yarn add @marinade.finance/native-staking-sdk
bun add @marinade.finance/native-staking-sdk
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2025-05-21 |
| First published | 2023-07-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 73.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | lj1024-marinade, xndru, __chalda, hamster |
| Keywords | solana, marinade.finance, blockchain, staking |

## Links

- npm: https://www.npmjs.com/package/@marinade.finance/native-staking-sdk
- Repository: https://github.com/marinade-finance/native-staking
- Homepage: https://github.com/marinade-finance/native-staking#readme
- Issues: https://github.com/marinade-finance/native-staking/issues
- npm.io page: https://npm.io/package/@marinade.finance/native-staking-sdk

## Dependencies (3)

- [bn.js](https://npm.io/package/bn.js.md) ^5.2.1
- [@solana/web3.js](https://npm.io/package/@solana/web3.js.md) ^1.98.0
- [@solana/spl-memo](https://npm.io/package/@solana/spl-memo.md) ^0.2.5

## Recent versions

- 1.3.4 (latest) — 2025-05-21
- 1.3.3 — 2025-05-13
- 1.3.2 — 2025-03-07
- 1.3.1 — 2024-11-07
- 1.3.0 — 2024-10-21
- 1.2.0 — 2024-10-18
- 1.1.0 — 2024-03-14
- 1.0.0 — 2023-09-05
- 0.0.2 — 2023-08-03
- 0.0.1 — 2023-07-11

## 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 initialize the SDK](#Install-and-initialize-the-SDK)
- [Stake SOL through Marinade Native Staking](#Stake-SOL-through-Marinade-Native-Staking)
- [Migrate Stake accounts to Marinade Native Staking](#Migrate-Stake-accounts-to-Marinade-Native-Staking)
- [Prepare for unstake](#Prepare-for-unstake)
- [Fetch user's stake accounts in Marinade Native Staking](#Fetch-users-stake-accounts-in-Marinade-Native-Staking)
- [Show user's rewards](#Show-users-rewards)

## Install and initialize the SDK

### Install the package

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

### Initialize the SDK

To initialize the SDK, the type of initialized instance depends on the chosen `Configuration` class.
The Native Staking SDK provides two configuration types:

* **`NativeStakingConfig`** – used for the default native staking, as implemented in the Marinade DS SAM bidding system
* **`NativeStakingSelectConfig`** – used for native staking in the Marinade Select program

#### Initialize Default Native Staking

```ts
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)
```

#### Initialize Select Native Staking

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

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

## Stake SOL through Marinade Native Staking
```ts
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
```ts
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 { referralInstructions } = sdk.buildReferralInstructions(partnerReferralPubkey)
const { createAuthorizedStake, stakeKeypair } = sdk.buildCreateAuthorizedStakeInstructions(user.publicKey, amount)

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

tx.sign([stakeKeypair])

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

## Migrate Stake accounts to Marinade Native Staking
```ts
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
```ts
const { connection } = useConnection() // from @solana/wallet-adapter-react
const { sendTransaction, signTransaction, publicKey } = useWallet() // from @solana/wallet-adapter-react

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

const { referralInstructions } = sdk.buildReferralInstructions(partnerReferralPubkey)
const authorizeInstructions = sdk.buildAuthorizeInstructions(user.publicKey, [stakePublicKey])

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

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

## Prepare for unstake
```ts
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
```ts
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
```ts
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)
```


# Development

To test running `sdk.test.ts`.

1. Start Solana test validator
   ```sh
   solana-test-validator --reset --slots-per-epoch 32 --ticks-per-slot 5 --ledger /tmp/ledger
   ```
2. Run tests
   ```sh
   pnpm test
   ```

---
_Source: https://npm.io/package/@marinade.finance/native-staking-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
