Skip to content

Commit 6945b58

Browse files
authored
Fix/ts stuff (#4)
* update typescript is happening, make sure build happens correctly * increase package version
1 parent e32719d commit 6945b58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2569
-1847
lines changed

.github/workflows/npm-publish.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ jobs:
2323
registry-url: 'https://registry.npmjs.org'
2424
cache: 'yarn'
2525

26-
- name: Install and Prepare
26+
- name: Install and Build
2727
working-directory: ./package
2828
run: |
2929
yarn install --frozen-lockfile
30-
yarn clean
31-
yarn prepare
30+
yarn build
3231
3332
- name: Publish to NPM
3433
working-directory: ./package

package.json

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
{
2+
"name": "@jito-foundation/stake-deposit-interceptor-sdk",
3+
"version": "1.1.1",
4+
"main": "dist/index.js",
5+
"types": "dist/index.d.ts",
6+
"files": [
7+
"dist",
8+
"src"
9+
],
10+
"license": "MIT",
211
"scripts": {
3-
"generate": "solita"
12+
"clean": "rm -rf dist",
13+
"build": "tsc",
14+
"prepare": "yarn clean && yarn build"
15+
},
16+
"publishConfig": {
17+
"access": "public"
18+
},
19+
"dependencies": {
20+
"@metaplex-foundation/beet": "^0.7.2",
21+
"@metaplex-foundation/beet-solana": "^0.4.1",
22+
"@solana/spl-stake-pool": "^1.1.8",
23+
"@solana/spl-token": "^0.4.9",
24+
"@solana/web3.js": "^1.98.0"
425
},
5-
"name": "stake-deposit-interceptor",
6-
"version": "1.0.0",
7-
"description": "A Solana program intended to become the `stake_deposit_authority` of a StakePool deployed via the SPL stake-pool program. This program allows an admin to set a fee (in basis points) on the LST received from DepositStake that linearly decays to zero over a set number of seconds. This mechanism disincentivizes the immediate transfer of the LST after deposit.",
8-
"main": "index.js",
9-
"keywords": [],
10-
"author": "",
11-
"license": "ISC",
1226
"devDependencies": {
13-
"@metaplex-foundation/shank-js": "^0.1.7",
14-
"@metaplex-foundation/solita": "metaplex-foundation/solita"
27+
"typescript": "^5.0.0",
28+
"@types/node": "^20.0.0"
1529
}
16-
}
30+
}

package/dist/depositStake.d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Connection, PublicKey, Signer, TransactionInstruction } from "@solana/web3.js";
2+
/**
3+
* Creates instructions required to deposit stake to stake pool via
4+
* Stake Deposit Interceptor.
5+
*
6+
* @param connection
7+
* @param payer - [NEW] pays rent for DepositReceipt
8+
* @param stakePoolAddress
9+
* @param authorizedPubkey
10+
* @param validatorVote
11+
* @param depositStake
12+
* @param poolTokenReceiverAccount
13+
*/
14+
export declare const depositStake: (connection: Connection, payer: PublicKey, stakePoolAddress: PublicKey, authorizedPubkey: PublicKey, validatorVote: PublicKey, depositStake: PublicKey, poolTokenReceiverAccount?: PublicKey) => Promise<{
15+
instructions: TransactionInstruction[];
16+
signers: Signer[];
17+
}>;

package/dist/depositStake.js

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.depositStake = void 0;
4+
const web3_js_1 = require("@solana/web3.js");
5+
const spl_stake_pool_1 = require("@solana/spl-stake-pool");
6+
const generated_1 = require("./generated");
7+
const spl_token_1 = require("@solana/spl-token");
8+
/**
9+
* Creates instructions required to deposit stake to stake pool via
10+
* Stake Deposit Interceptor.
11+
*
12+
* @param connection
13+
* @param payer - [NEW] pays rent for DepositReceipt
14+
* @param stakePoolAddress
15+
* @param authorizedPubkey
16+
* @param validatorVote
17+
* @param depositStake
18+
* @param poolTokenReceiverAccount
19+
*/
20+
const depositStake = async (connection, payer, stakePoolAddress, authorizedPubkey, validatorVote, depositStake, poolTokenReceiverAccount) => {
21+
const stakePool = await (0, spl_stake_pool_1.getStakePoolAccount)(connection, stakePoolAddress);
22+
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);
25+
const instructions = [];
26+
const signers = [];
27+
const base = web3_js_1.Keypair.generate();
28+
const poolMint = stakePool.account.data.poolMint;
29+
signers.push(base);
30+
// Create token account if not specified
31+
if (!poolTokenReceiverAccount) {
32+
const associatedAddress = (0, spl_token_1.getAssociatedTokenAddressSync)(poolMint, authorizedPubkey);
33+
instructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(authorizedPubkey, associatedAddress, authorizedPubkey, poolMint));
34+
poolTokenReceiverAccount = associatedAddress;
35+
}
36+
instructions.push(...web3_js_1.StakeProgram.authorize({
37+
stakePubkey: depositStake,
38+
authorizedPubkey,
39+
newAuthorizedPubkey: stakePool.account.data.stakeDepositAuthority,
40+
stakeAuthorizationType: web3_js_1.StakeAuthorizationLayout.Staker,
41+
}).instructions);
42+
instructions.push(...web3_js_1.StakeProgram.authorize({
43+
stakePubkey: depositStake,
44+
authorizedPubkey,
45+
newAuthorizedPubkey: stakePool.account.data.stakeDepositAuthority,
46+
stakeAuthorizationType: web3_js_1.StakeAuthorizationLayout.Withdrawer,
47+
}).instructions);
48+
// Derive DepositReceipt Address
49+
const [depositReceiptAddress] = web3_js_1.PublicKey.findProgramAddressSync([
50+
Buffer.from("deposit_receipt"),
51+
stakePoolAddress.toBuffer(),
52+
base.publicKey.toBuffer(),
53+
], generated_1.PROGRAM_ID);
54+
const depositStakeIxArgs = {
55+
depositStakeArgs: {
56+
owner: authorizedPubkey,
57+
},
58+
};
59+
const depositStakeIxAccounts = {
60+
payer,
61+
stakePoolProgram: spl_stake_pool_1.STAKE_POOL_PROGRAM_ID,
62+
depositReceipt: depositReceiptAddress,
63+
stakePool: stakePoolAddress,
64+
validatorStakeList: stakePool.account.data.validatorList,
65+
depositStakeAuthority: stakePool.account.data.stakeDepositAuthority,
66+
base: base.publicKey,
67+
stakePoolWithdrawAuthority: withdrawAuthority,
68+
stake: depositStake,
69+
validatorStakeAccount: validatorStake,
70+
reserveStakeAccount: stakePool.account.data.reserveStake,
71+
vault: stakePoolDepositAuthority.vault,
72+
managerFeeAccount: stakePool.account.data.managerFeeAccount,
73+
referrerPoolTokensAccount: poolTokenReceiverAccount,
74+
poolMint,
75+
clock: web3_js_1.SYSVAR_CLOCK_PUBKEY,
76+
stakeHistory: web3_js_1.SYSVAR_STAKE_HISTORY_PUBKEY,
77+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
78+
stakeProgram: web3_js_1.StakeProgram.programId,
79+
systemProgram: web3_js_1.SystemProgram.programId,
80+
};
81+
const depositStakeIx = (0, generated_1.createDepositStakeInstruction)(depositStakeIxAccounts, depositStakeIxArgs);
82+
instructions.push(depositStakeIx);
83+
return {
84+
instructions,
85+
signers,
86+
};
87+
};
88+
exports.depositStake = depositStake;
89+
/**
90+
* Generates the withdraw authority program address for the stake pool
91+
*/
92+
const findWithdrawAuthorityProgramAddress = (programId, stakePoolAddress) => {
93+
const [publicKey] = web3_js_1.PublicKey.findProgramAddressSync([stakePoolAddress.toBuffer(), Buffer.from("withdraw")], programId);
94+
return publicKey;
95+
};
96+
/**
97+
* Generates the stake program address for a validator's vote account
98+
*/
99+
const findStakeProgramAddress = (programId, voteAccountAddress, stakePoolAddress) => {
100+
const [publicKey] = web3_js_1.PublicKey.findProgramAddressSync([
101+
voteAccountAddress.toBuffer(),
102+
stakePoolAddress.toBuffer(),
103+
Buffer.alloc(0),
104+
], programId);
105+
return publicKey;
106+
};

package/dist/depositStake.ts

-189
This file was deleted.

0 commit comments

Comments
 (0)