Skip to content

Commit 41b15f1

Browse files
committed
add remaining accounts param to depositStake and remove spl stake pool package and replace with more handrolled stuff using coral borsh
1 parent 9c69a34 commit 41b15f1

File tree

8 files changed

+179
-51
lines changed

8 files changed

+179
-51
lines changed

.github/workflows/npm-publish.yml

-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
name: Publish Package to NPM
22

33
on:
4-
push:
5-
branches: [ master ]
6-
paths:
7-
- 'package/**'
8-
- '.github/workflows/npm-publish.yml'
94
workflow_dispatch:
105

116
jobs:

package/dist/depositStake.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Connection, PublicKey, Signer, TransactionInstruction } from "@solana/web3.js";
1+
import { Connection, PublicKey, Signer, TransactionInstruction, AccountMeta } from "@solana/web3.js";
22
/**
33
* Creates instructions required to deposit stake to stake pool via
44
* Stake Deposit Interceptor.
@@ -10,8 +10,9 @@ import { Connection, PublicKey, Signer, TransactionInstruction } from "@solana/w
1010
* @param validatorVote
1111
* @param depositStake
1212
* @param poolTokenReceiverAccount
13+
* @param remainingAccounts - optional additional accounts to append to the instruction
1314
*/
14-
export declare const depositStake: (connection: Connection, payer: PublicKey, stakePoolAddress: PublicKey, authorizedPubkey: PublicKey, validatorVote: PublicKey, depositStake: PublicKey, poolTokenReceiverAccount?: PublicKey) => Promise<{
15+
export declare const depositStake: (connection: Connection, payer: PublicKey, stakePoolAddress: PublicKey, authorizedPubkey: PublicKey, validatorVote: PublicKey, depositStake: PublicKey, poolTokenReceiverAccount?: PublicKey, remainingAccounts?: AccountMeta[]) => Promise<{
1516
instructions: TransactionInstruction[];
1617
signers: Signer[];
1718
}>;

package/dist/depositStake.js

+43-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,41 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.depositStake = void 0;
44
const web3_js_1 = require("@solana/web3.js");
5-
const spl_stake_pool_1 = require("@solana/spl-stake-pool");
65
const generated_1 = require("./generated");
76
const spl_token_1 = require("@solana/spl-token");
7+
const borsh_1 = require("@coral-xyz/borsh");
8+
/**
9+
* Copied from @solana/spl-stake-pool for compatibility reasons.
10+
* Source: https://github.com/solana-labs/solana-program-library/blob/b7dd8fee/stake-pool/js/src/index.ts
11+
*/
12+
const STAKE_POOL_PROGRAM_ID = new web3_js_1.PublicKey("SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy");
13+
const StakePoolLayout = (0, borsh_1.struct)([
14+
(0, borsh_1.u8)('accountType'),
15+
(0, borsh_1.publicKey)('manager'),
16+
(0, borsh_1.publicKey)('staker'),
17+
(0, borsh_1.publicKey)('stakeDepositAuthority'),
18+
(0, borsh_1.u8)('stakeWithdrawBumpSeed'),
19+
(0, borsh_1.publicKey)('validatorList'),
20+
(0, borsh_1.publicKey)('reserveStake'),
21+
(0, borsh_1.publicKey)('poolMint'),
22+
(0, borsh_1.publicKey)('managerFeeAccount'),
23+
(0, borsh_1.publicKey)('tokenProgramId'),
24+
(0, borsh_1.u64)('totalLamports'),
25+
(0, borsh_1.u64)('poolTokenSupply'),
26+
(0, borsh_1.u64)('lastUpdateEpoch'),
27+
]);
28+
const getStakePoolAccount = async (connection, stakePoolAddress) => {
29+
const account = await connection.getAccountInfo(stakePoolAddress);
30+
if (!account)
31+
throw new Error("Stake pool account not found");
32+
const data = StakePoolLayout.decode(account.data);
33+
return {
34+
pubkey: stakePoolAddress,
35+
account: {
36+
data
37+
}
38+
};
39+
};
840
/**
941
* Creates instructions required to deposit stake to stake pool via
1042
* Stake Deposit Interceptor.
@@ -16,12 +48,13 @@ const spl_token_1 = require("@solana/spl-token");
1648
* @param validatorVote
1749
* @param depositStake
1850
* @param poolTokenReceiverAccount
51+
* @param remainingAccounts - optional additional accounts to append to the instruction
1952
*/
20-
const depositStake = async (connection, payer, stakePoolAddress, authorizedPubkey, validatorVote, depositStake, poolTokenReceiverAccount) => {
21-
const stakePool = await (0, spl_stake_pool_1.getStakePoolAccount)(connection, stakePoolAddress);
53+
const depositStake = async (connection, payer, stakePoolAddress, authorizedPubkey, validatorVote, depositStake, poolTokenReceiverAccount, remainingAccounts) => {
54+
const stakePool = await getStakePoolAccount(connection, stakePoolAddress);
2255
const stakePoolDepositAuthority = await generated_1.StakePoolDepositStakeAuthority.fromAccountAddress(connection, stakePool.account.data.stakeDepositAuthority);
23-
const withdrawAuthority = await findWithdrawAuthorityProgramAddress(spl_stake_pool_1.STAKE_POOL_PROGRAM_ID, stakePoolAddress);
24-
const validatorStake = await findStakeProgramAddress(spl_stake_pool_1.STAKE_POOL_PROGRAM_ID, validatorVote, stakePoolAddress);
56+
const withdrawAuthority = await findWithdrawAuthorityProgramAddress(STAKE_POOL_PROGRAM_ID, stakePoolAddress);
57+
const validatorStake = await findStakeProgramAddress(STAKE_POOL_PROGRAM_ID, validatorVote, stakePoolAddress);
2558
const instructions = [];
2659
const signers = [];
2760
const base = web3_js_1.Keypair.generate();
@@ -58,7 +91,7 @@ const depositStake = async (connection, payer, stakePoolAddress, authorizedPubke
5891
};
5992
const depositStakeIxAccounts = {
6093
payer,
61-
stakePoolProgram: spl_stake_pool_1.STAKE_POOL_PROGRAM_ID,
94+
stakePoolProgram: STAKE_POOL_PROGRAM_ID,
6295
depositReceipt: depositReceiptAddress,
6396
stakePool: stakePoolAddress,
6497
validatorStakeList: stakePool.account.data.validatorList,
@@ -79,6 +112,10 @@ const depositStake = async (connection, payer, stakePoolAddress, authorizedPubke
79112
systemProgram: web3_js_1.SystemProgram.programId,
80113
};
81114
const depositStakeIx = (0, generated_1.createDepositStakeInstruction)(depositStakeIxAccounts, depositStakeIxArgs);
115+
// Add any remaining accounts to the instruction
116+
if (remainingAccounts?.length) {
117+
depositStakeIx.keys.push(...remainingAccounts);
118+
}
82119
instructions.push(depositStakeIx);
83120
return {
84121
instructions,

package/dist/generated/accounts/DepositReceipt.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ export declare class DepositReceipt implements DepositReceiptArgs {
113113
owner: string;
114114
stakePool: string;
115115
stakePoolDepositStakeAuthority: string;
116-
depositTime: any;
117-
lstAmount: any;
118-
coolDownSeconds: any;
116+
depositTime: beet.bignum;
117+
lstAmount: beet.bignum;
118+
coolDownSeconds: beet.bignum;
119119
initialFeeBps: number;
120120
bumpSeed: number;
121121
reserved: number[];

package/dist/generated/accounts/StakePoolDepositStakeAuthority.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export declare class StakePoolDepositStakeAuthority implements StakePoolDepositS
118118
authority: string;
119119
vault: string;
120120
stakePoolProgramId: string;
121-
coolDownSeconds: any;
121+
coolDownSeconds: beet.bignum;
122122
initalFeeBps: number;
123123
feeWallet: string;
124124
bumpSeed: number;

package/package.json

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jito-foundation/stake-deposit-interceptor-sdk",
3-
"version": "1.6.2",
3+
"version": "1.7.0-canary.testpool.2",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"files": [
@@ -19,19 +19,34 @@
1919
"dependencies": {
2020
"@metaplex-foundation/beet": "^0.7.1",
2121
"@metaplex-foundation/beet-solana": "^0.4.0",
22-
"@solana/spl-stake-pool": "^1.1.8",
23-
"@solana/spl-token": "^0.4.0",
22+
"@solana/buffer-layout": "^4.0.0",
23+
"@solana/buffer-layout-utils": "^0.2.0",
24+
"bs58": "^5.0.0",
25+
"buffer": "^6.0.3",
26+
"bn.js": "^5.2.0"
27+
},
28+
"peerDependencies": {
2429
"@solana/web3.js": "^1.73.5",
30+
"@solana/spl-token": "^0.4.0",
31+
"@coral-xyz/borsh": "^0.30.1",
32+
"@noble/ed25519": "^1.7.1",
2533
"@noble/curves": "^1.1.0",
2634
"@noble/hashes": "^1.3.1",
27-
"@noble/ed25519": "^1.7.1",
2835
"@noble/secp256k1": "^1.6.3",
29-
"rpc-websockets": "^7.5.1",
30-
"bs58": "^5.0.0",
31-
"buffer": "^6.0.3",
32-
"superstruct": "^1.0.3"
36+
"rpc-websockets": "^7.5.1"
3337
},
3438
"devDependencies": {
35-
"typescript": "^5.0.0"
39+
"typescript": "^5.0.0",
40+
"@solana/web3.js": "^1.73.5",
41+
"@solana/spl-token": "^0.4.0",
42+
"@coral-xyz/borsh": "^0.30.1",
43+
"@noble/ed25519": "^1.7.1",
44+
"@noble/curves": "^1.1.0",
45+
"@noble/hashes": "^1.3.1",
46+
"@noble/secp256k1": "^1.6.3",
47+
"rpc-websockets": "^7.5.1",
48+
"superstruct": "^1.0.3",
49+
"@types/node": "^20.0.0",
50+
"@types/bn.js": "^5.1.0"
3651
}
3752
}

package/src/depositStake.ts

+71-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import {
99
SYSVAR_CLOCK_PUBKEY,
1010
SYSVAR_STAKE_HISTORY_PUBKEY,
1111
TransactionInstruction,
12+
AccountMeta,
1213
} from "@solana/web3.js";
13-
import {
14-
getStakePoolAccount,
15-
STAKE_POOL_PROGRAM_ID,
16-
} from "@solana/spl-stake-pool";
1714
import {
1815
createDepositStakeInstruction,
1916
DepositStakeInstructionAccounts,
@@ -26,6 +23,67 @@ import {
2623
getAssociatedTokenAddressSync,
2724
TOKEN_PROGRAM_ID,
2825
} from "@solana/spl-token";
26+
import BN from "bn.js";
27+
import { struct, u8, publicKey, u64 } from '@coral-xyz/borsh';
28+
29+
/**
30+
* Copied from @solana/spl-stake-pool for compatibility reasons.
31+
* Source: https://github.com/solana-labs/solana-program-library/blob/b7dd8fee/stake-pool/js/src/index.ts
32+
*/
33+
const STAKE_POOL_PROGRAM_ID = new PublicKey("SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy");
34+
35+
/**
36+
* Copied from @solana/spl-stake-pool for compatibility.
37+
* We only need the account data structure, not the full package.
38+
*/
39+
type StakePoolLayout = {
40+
accountType: number;
41+
manager: PublicKey;
42+
staker: PublicKey;
43+
stakeDepositAuthority: PublicKey;
44+
stakeWithdrawBumpSeed: number;
45+
validatorList: PublicKey;
46+
reserveStake: PublicKey;
47+
poolMint: PublicKey;
48+
managerFeeAccount: PublicKey;
49+
tokenProgramId: PublicKey;
50+
totalLamports: BN;
51+
poolTokenSupply: BN;
52+
lastUpdateEpoch: BN;
53+
};
54+
55+
const StakePoolLayout = struct<StakePoolLayout>([
56+
u8('accountType'),
57+
publicKey('manager'),
58+
publicKey('staker'),
59+
publicKey('stakeDepositAuthority'),
60+
u8('stakeWithdrawBumpSeed'),
61+
publicKey('validatorList'),
62+
publicKey('reserveStake'),
63+
publicKey('poolMint'),
64+
publicKey('managerFeeAccount'),
65+
publicKey('tokenProgramId'),
66+
u64('totalLamports'),
67+
u64('poolTokenSupply'),
68+
u64('lastUpdateEpoch'),
69+
]);
70+
71+
const getStakePoolAccount = async (
72+
connection: Connection,
73+
stakePoolAddress: PublicKey
74+
) => {
75+
const account = await connection.getAccountInfo(stakePoolAddress);
76+
if (!account) throw new Error("Stake pool account not found");
77+
78+
const data = StakePoolLayout.decode(account.data) as StakePoolLayout;
79+
80+
return {
81+
pubkey: stakePoolAddress,
82+
account: {
83+
data
84+
}
85+
};
86+
};
2987

3088
/**
3189
* Creates instructions required to deposit stake to stake pool via
@@ -38,6 +96,7 @@ import {
3896
* @param validatorVote
3997
* @param depositStake
4098
* @param poolTokenReceiverAccount
99+
* @param remainingAccounts - optional additional accounts to append to the instruction
41100
*/
42101
export const depositStake = async (
43102
connection: Connection,
@@ -46,7 +105,8 @@ export const depositStake = async (
46105
authorizedPubkey: PublicKey,
47106
validatorVote: PublicKey,
48107
depositStake: PublicKey,
49-
poolTokenReceiverAccount?: PublicKey
108+
poolTokenReceiverAccount?: PublicKey,
109+
remainingAccounts?: AccountMeta[]
50110
) => {
51111
const stakePool = await getStakePoolAccount(connection, stakePoolAddress);
52112
const stakePoolDepositAuthority =
@@ -147,6 +207,12 @@ export const depositStake = async (
147207
depositStakeIxAccounts,
148208
depositStakeIxArgs
149209
);
210+
211+
// Add any remaining accounts to the instruction
212+
if (remainingAccounts?.length) {
213+
depositStakeIx.keys.push(...remainingAccounts);
214+
}
215+
150216
instructions.push(depositStakeIx);
151217

152218
return {

0 commit comments

Comments
 (0)