Skip to content

Commit

Permalink
change dependencies, update readme to explain migration better (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggnine-jito authored Jan 9, 2025
1 parent 2739863 commit af5f76a
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 119 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
**/node_modules/
**/.crates/
cranker/.env
.DS_Store
**/.DS_Store
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"dependencies": {
"@metaplex-foundation/beet": "^0.7.2",
"@metaplex-foundation/beet-solana": "^0.4.1",
"@solana/spl-stake-pool": "^1.1.8",
"@solana/spl-token": "^0.4.9",
"@solana/web3.js": "^1.98.0"
"@solana/spl-stake-pool": "1.1.8",
"@solana/spl-token": "0.4.0",
"@solana/web3.js": "1.73.5"
},
"devDependencies": {
"@metaplex-foundation/solita": "^0.20.1",
Expand Down
81 changes: 72 additions & 9 deletions package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ More information available in the [Jito governance forum](https://forum.jito.net
npm install @jito-foundation/stake-deposit-interceptor-sdk
```

## Core Functionality
## Migration from @solana/spl-stake-pool

The SDK provides functionality to interact with the stake deposit interceptor program:
This SDK extends the standard SPL stake pool functionality by adding a cool-down period and fee mechanism for stake deposits.

### Depositing Stake
When depositing stake, instead of receiving LST tokens immediately, they are held by the interceptor program until claimed. All you need to do is swap out the spl stake pool program depositStake method for the jito interceptor version:

### Deposit Stake
```typescript
import { depositStake } from '@jito-foundation/stake-deposit-interceptor-sdk';

// Returns instructions to deposit stake and create a deposit receipt
const { instructions, signers } = await depositStake(
connection,
payer,
stakePoolAddress,
authorizedPubkey,
validatorVote,
depositStake,
poolTokenReceiverAccount // optional
wallet.publicKey, // payer for deposit receipt rent
stakePoolAddress, // stake pool to deposit into
wallet.publicKey, // authorized withdrawer/staker
validatorVote, // validator vote account
stakeAccount, // stake account to deposit
poolTokenReceiverAccount // optional, will create ATA if not provided
);
```

Expand All @@ -41,6 +44,64 @@ The SDK also includes generated instruction builders for:
- `createDepositStakeWithSlippageInstruction`: Deposit with minimum LST output protection
- `createClaimPoolTokensInstruction`: Claim LST tokens (with fees during cooldown)

### Claiming Deposited Stake
After the deposit, you can claim the LST tokens. A fee may apply if claiming before the cool-down period ends:

```typescript
import {
createClaimPoolTokensInstruction,
StakePoolDepositStakeAuthority,
PROGRAM_ID
} from '@jito-foundation/stake-deposit-interceptor-sdk';

// Get the deposit authority account which contains fee/vault info
const depositAuthority = await StakePoolDepositStakeAuthority.fromAccountAddress(
connection,
receipt.stakePoolDepositStakeAuthority
);

// Create claim instruction
const claimIx = createClaimPoolTokensInstruction({
depositReceipt: receiptAddress, // address of the deposit receipt
owner: wallet.publicKey, // receipt owner
vault: depositAuthority.vault, // vault holding LST tokens
destination: destinationTokenAccount, // where to send claimed tokens
feeWallet: feeWalletAta, // where fees are sent if applicable
depositAuthority: receipt.stakePoolDepositStakeAuthority,
poolMint, // LST mint
tokenProgram: TOKEN_PROGRAM_ID,
systemProgram: SystemProgram.programId,
});
```

### Finding Deposit Receipts
To fetch all unclaimed deposits for a wallet:

```typescript
import { DepositReceipt, PROGRAM_ID } from '@jito-foundation/stake-deposit-interceptor-sdk';

// Fetch all receipts for a wallet
const accounts = await connection.getProgramAccounts(PROGRAM_ID, {
filters: [
// Filter by owner (40 bytes offset: 8 bytes discriminator + 32 bytes base)
{ memcmp: { offset: 40, bytes: walletPublicKey.toBase58() } },
],
});

// Parse the receipt accounts
const receipts = accounts.map(({ pubkey, account }) => {
const [receipt] = DepositReceipt.fromAccountInfo(account);
return {
address: pubkey, // deposit receipt address
receipt, // parsed receipt data including:
// - lstAmount: amount of LST to claim
// - depositTime: when stake was deposited
// - coolDownSeconds: required wait for fee-free claim
// - initialFeeBps: starting fee rate
};
});
```

## Program Accounts

### StakePoolDepositStakeAuthority
Expand All @@ -57,6 +118,7 @@ interface StakePoolDepositStakeAuthority {
initialFeeBps: number;
feeWallet: PublicKey;
bumpSeed: number;
reserved: number[]; // 256 bytes of reserved space
}
```

Expand All @@ -73,6 +135,7 @@ interface DepositReceipt {
coolDownSeconds: BN;
initialFeeBps: number;
bumpSeed: number;
reserved: number[]; // 256 bytes of reserved space
}
```

Expand Down
13 changes: 9 additions & 4 deletions package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jito-foundation/stake-deposit-interceptor-sdk",
"version": "1.3.0",
"version": "1.4.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand All @@ -19,9 +19,14 @@
"dependencies": {
"@metaplex-foundation/beet": "^0.7.2",
"@metaplex-foundation/beet-solana": "^0.4.1",
"@solana/spl-stake-pool": "^1.1.8",
"@solana/spl-token": "^0.4.9",
"@solana/web3.js": "^1.98.0"
"@solana/spl-stake-pool": "1.1.8",
"@solana/spl-token": "0.4.0",
"@solana/web3.js": "1.73.5"
},
"resolutions": {
"@solana/web3.js": "1.73.5",
"@solana/spl-token": "0.4.0",
"buffer": "6.0.3"
},
"devDependencies": {
"typescript": "^5.0.0"
Expand Down
Loading

0 comments on commit af5f76a

Please sign in to comment.