Skip to content

Commit 498a781

Browse files
authored
Merge pull request #6664 from BitGo/harit/jito-withdraw-stake
feat(jito): implements staking deactivate
2 parents 7597d3f + 5cc2722 commit 498a781

16 files changed

+1015
-464
lines changed

examples/ts/sol/stake-jito.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ async function main() {
5959
.sender(account.publicKey.toBase58())
6060
.stakingAddress(JITO_STAKE_POOL_ADDRESS)
6161
.validator(JITO_STAKE_POOL_ADDRESS)
62-
.isJito(true)
62+
.stakingTypeParams({
63+
type: 'JITO',
64+
stakePoolData: {
65+
managerFeeAccount: stakePoolAccount.account.data.managerFeeAccount.toString(),
66+
poolMint: stakePoolAccount.account.data.poolMint.toString(),
67+
reserveStake: stakePoolAccount.account.data.toString(),
68+
}
69+
})
6370
.nonce(recentBlockhash.blockhash)
6471
txBuilder.sign({ key: account.secretKey })
6572
const tx = await txBuilder.build()
@@ -85,7 +92,7 @@ const getAccount = () => {
8592
const secretKey = process.env.ACCOUNT_SECRET_KEY
8693
if (publicKey === undefined || secretKey === undefined) {
8794
const { publicKey, secretKey } = Keypair.generate()
88-
console.log('Here is a new account to save into your .env file.')
95+
console.log('# Here is a new account to save into your .env file.')
8996
console.log(`ACCOUNT_PUBLIC_KEY=${publicKey.toBase58()}`)
9097
console.log(`ACCOUNT_SECRET_KEY=${bs58.encode(secretKey)}`)
9198
throw new Error("Missing account information")

modules/sdk-coin-sol/src/lib/constants.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export enum ValidInstructionTypesEnum {
3838
MintTo = 'MintTo',
3939
Burn = 'Burn',
4040
DepositSol = 'DepositSol',
41+
WithdrawStake = 'WithdrawStake',
42+
Approve = 'Approve',
4143
}
4244

4345
// Internal instructions types
@@ -58,6 +60,8 @@ export enum InstructionBuilderTypes {
5860
MintTo = 'MintTo',
5961
Burn = 'Burn',
6062
CustomInstruction = 'CustomInstruction',
63+
Approve = 'Approve',
64+
WithdrawStake = 'WithdrawStake',
6165
}
6266

6367
export const VALID_SYSTEM_INSTRUCTION_TYPES: ValidInstructionTypes[] = [
@@ -80,7 +84,9 @@ export const VALID_SYSTEM_INSTRUCTION_TYPES: ValidInstructionTypes[] = [
8084
ValidInstructionTypesEnum.SetPriorityFee,
8185
ValidInstructionTypesEnum.MintTo,
8286
ValidInstructionTypesEnum.Burn,
87+
ValidInstructionTypesEnum.Approve,
8388
ValidInstructionTypesEnum.DepositSol,
89+
ValidInstructionTypesEnum.WithdrawStake,
8490
];
8591

8692
/** Const to check the order of the Wallet Init instructions when decode */
@@ -111,6 +117,13 @@ export const jitoStakingActivateInstructionsIndexes = {
111117
DepositSol: 1,
112118
} as const;
113119

120+
/** Const to check the order of the Jito Staking Activate instructions when decode */
121+
export const jitoStakingDeactivateInstructionsIndexes = {
122+
Approve: 0,
123+
Create: 1,
124+
WithdrawStake: 2,
125+
} as const;
126+
114127
/** Const to check the order of the Staking Authorize instructions when decode */
115128
export const stakingAuthorizeInstructionsIndexes = {
116129
Authorize: 0,

modules/sdk-coin-sol/src/lib/iface.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DecodedCloseAccountInstruction } from '@solana/spl-token';
33
import { Blockhash, StakeInstructionType, SystemInstructionType, TransactionSignature } from '@solana/web3.js';
44
import { InstructionBuilderTypes } from './constants';
55
import { StakePoolInstructionType } from '@solana/spl-stake-pool';
6+
import { DepositSolStakePoolData, WithdrawStakeStakePoolData } from './jitoStakePoolOperations';
67

78
// TODO(STLX-9890): Add the interfaces for validityWindow and SequenceId
89
export interface SolanaKeys {
@@ -41,6 +42,7 @@ export type InstructionParams =
4142
| StakingDelegate
4243
| MintTo
4344
| Burn
45+
| Approve
4446
| CustomInstruction;
4547

4648
export interface Memo {
@@ -107,15 +109,38 @@ export interface Burn {
107109
};
108110
}
109111

112+
export interface Approve {
113+
type: InstructionBuilderTypes.Approve;
114+
params: {
115+
accountAddress: string;
116+
delegateAddress: string;
117+
ownerAddress: string;
118+
amount: string;
119+
programId?: string;
120+
};
121+
}
122+
123+
export enum StakingType {
124+
NATIVE = 'NATIVE',
125+
MARINADE = 'MARINADE',
126+
JITO = 'JITO',
127+
}
128+
129+
export interface JitoStakingActivateParams {
130+
stakePoolData: DepositSolStakePoolData;
131+
}
132+
133+
export type StakingActivateExtraParams = JitoStakingActivateParams;
134+
110135
export interface StakingActivate {
111136
type: InstructionBuilderTypes.StakingActivate;
112137
params: {
113138
fromAddress: string;
114139
stakingAddress: string;
115140
amount: string;
116141
validator: string;
117-
isMarinade?: boolean;
118-
isJito?: boolean;
142+
stakingType: StakingType;
143+
extraParams?: StakingActivateExtraParams;
119144
};
120145
}
121146

@@ -124,14 +149,23 @@ export interface StakingDelegate {
124149
params: { stakingAddress: string; fromAddress: string; validator: string };
125150
}
126151

152+
export interface JitoStakingDeactivateParams {
153+
stakePoolData: WithdrawStakeStakePoolData;
154+
validatorAddress: string;
155+
transferAuthorityAddress: string;
156+
}
157+
158+
export type StakingDeactivateExtraParams = JitoStakingDeactivateParams;
159+
127160
export interface StakingDeactivate {
128161
type: InstructionBuilderTypes.StakingDeactivate;
129162
params: {
130163
fromAddress: string;
131164
stakingAddress: string;
132165
amount?: string;
133166
unstakingAddress?: string;
134-
isMarinade?: boolean;
167+
stakingType: StakingType;
168+
extraParams?: StakingDeactivateExtraParams;
135169
recipients?: Recipient[];
136170
};
137171
}
@@ -187,7 +221,8 @@ export type ValidInstructionTypes =
187221
| 'TokenTransfer'
188222
| 'SetPriorityFee'
189223
| 'MintTo'
190-
| 'Burn';
224+
| 'Burn'
225+
| 'Approve';
191226

192227
export type StakingAuthorizeParams = {
193228
stakingAddress: string;

0 commit comments

Comments
 (0)