Skip to content

Commit 7d35ad2

Browse files
authored
stake-pool: Remove redelegate instruction from program and JS (solana-labs#7033)
* stake-pool: Remove redelegate from program * Remove redelegate from js package
1 parent 656b658 commit 7d35ad2

File tree

7 files changed

+16
-1891
lines changed

7 files changed

+16
-1891
lines changed

stake-pool/js/src/index.ts

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ export interface StakePoolAccounts {
7272
validatorList: ValidatorListAccount | undefined;
7373
}
7474

75-
interface RedelegateProps {
76-
connection: Connection;
77-
stakePoolAddress: PublicKey;
78-
sourceVoteAccount: PublicKey;
79-
destinationVoteAccount: PublicKey;
80-
sourceTransientStakeSeed: number | BN;
81-
destinationTransientStakeSeed: number | BN;
82-
ephemeralStakeSeed: number | BN;
83-
lamports: number | BN;
84-
}
85-
8675
/**
8776
* Retrieves and deserializes a StakePool account using a web3js connection and the stake pool address.
8877
* @param connection: An active web3js connection.
@@ -1160,86 +1149,6 @@ export async function stakePoolInfo(connection: Connection, stakePoolAddress: Pu
11601149
};
11611150
}
11621151

1163-
/**
1164-
* Creates instructions required to redelegate stake.
1165-
*/
1166-
export async function redelegate(props: RedelegateProps) {
1167-
const {
1168-
connection,
1169-
stakePoolAddress,
1170-
sourceVoteAccount,
1171-
sourceTransientStakeSeed,
1172-
destinationVoteAccount,
1173-
destinationTransientStakeSeed,
1174-
ephemeralStakeSeed,
1175-
lamports,
1176-
} = props;
1177-
const stakePool = await getStakePoolAccount(connection, stakePoolAddress);
1178-
1179-
const stakePoolWithdrawAuthority = await findWithdrawAuthorityProgramAddress(
1180-
STAKE_POOL_PROGRAM_ID,
1181-
stakePoolAddress,
1182-
);
1183-
1184-
const sourceValidatorStake = await findStakeProgramAddress(
1185-
STAKE_POOL_PROGRAM_ID,
1186-
sourceVoteAccount,
1187-
stakePoolAddress,
1188-
);
1189-
1190-
const sourceTransientStake = await findTransientStakeProgramAddress(
1191-
STAKE_POOL_PROGRAM_ID,
1192-
sourceVoteAccount,
1193-
stakePoolAddress,
1194-
new BN(sourceTransientStakeSeed),
1195-
);
1196-
1197-
const destinationValidatorStake = await findStakeProgramAddress(
1198-
STAKE_POOL_PROGRAM_ID,
1199-
destinationVoteAccount,
1200-
stakePoolAddress,
1201-
);
1202-
1203-
const destinationTransientStake = await findTransientStakeProgramAddress(
1204-
STAKE_POOL_PROGRAM_ID,
1205-
destinationVoteAccount,
1206-
stakePoolAddress,
1207-
new BN(destinationTransientStakeSeed),
1208-
);
1209-
1210-
const ephemeralStake = await findEphemeralStakeProgramAddress(
1211-
STAKE_POOL_PROGRAM_ID,
1212-
stakePoolAddress,
1213-
new BN(ephemeralStakeSeed),
1214-
);
1215-
1216-
const instructions: TransactionInstruction[] = [];
1217-
1218-
instructions.push(
1219-
StakePoolInstruction.redelegate({
1220-
stakePool: stakePool.pubkey,
1221-
staker: stakePool.account.data.staker,
1222-
validatorList: stakePool.account.data.validatorList,
1223-
reserveStake: stakePool.account.data.reserveStake,
1224-
stakePoolWithdrawAuthority,
1225-
ephemeralStake,
1226-
ephemeralStakeSeed,
1227-
sourceValidatorStake,
1228-
sourceTransientStake,
1229-
sourceTransientStakeSeed,
1230-
destinationValidatorStake,
1231-
destinationTransientStake,
1232-
destinationTransientStakeSeed,
1233-
validator: destinationVoteAccount,
1234-
lamports,
1235-
}),
1236-
);
1237-
1238-
return {
1239-
instructions,
1240-
};
1241-
}
1242-
12431152
/**
12441153
* Creates instructions required to create pool token metadata.
12451154
*/

stake-pool/js/src/instructions.ts

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import * as BufferLayout from '@solana/buffer-layout';
1212
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
1313
import { InstructionType, encodeData, decodeData } from './utils';
14-
import BN from 'bn.js';
1514
import {
1615
METADATA_MAX_NAME_LENGTH,
1716
METADATA_MAX_SYMBOL_LENGTH,
@@ -175,19 +174,7 @@ export const STAKE_POOL_INSTRUCTION_LAYOUTS: {
175174
},
176175
Redelegate: {
177176
index: 22,
178-
layout: BufferLayout.struct<any>([
179-
BufferLayout.u8('instruction'),
180-
/// Amount of lamports to redelegate
181-
BufferLayout.ns64('lamports'),
182-
/// Seed used to create source transient stake account
183-
BufferLayout.ns64('sourceTransientStakeSeed'),
184-
/// Seed used to create destination ephemeral account.
185-
BufferLayout.ns64('ephemeralStakeSeed'),
186-
/// Seed used to create destination transient stake account. If there is
187-
/// already transient stake, this must match the current seed, otherwise
188-
/// it can be anything
189-
BufferLayout.ns64('destinationTransientStakeSeed'),
190-
]),
177+
layout: BufferLayout.struct<any>([BufferLayout.u8('instruction')]),
191178
},
192179
});
193180

@@ -340,30 +327,6 @@ export type DepositSolParams = {
340327
lamports: number;
341328
};
342329

343-
export type RedelegateParams = {
344-
stakePool: PublicKey;
345-
staker: PublicKey;
346-
stakePoolWithdrawAuthority: PublicKey;
347-
validatorList: PublicKey;
348-
reserveStake: PublicKey;
349-
sourceValidatorStake: PublicKey;
350-
sourceTransientStake: PublicKey;
351-
ephemeralStake: PublicKey;
352-
destinationTransientStake: PublicKey;
353-
destinationValidatorStake: PublicKey;
354-
validator: PublicKey;
355-
// Amount of lamports to redelegate
356-
lamports: number | BN;
357-
// Seed used to create source transient stake account
358-
sourceTransientStakeSeed: number | BN;
359-
// Seed used to create destination ephemeral account
360-
ephemeralStakeSeed: number | BN;
361-
// Seed used to create destination transient stake account. If there is
362-
// already transient stake, this must match the current seed, otherwise
363-
// it can be anything
364-
destinationTransientStakeSeed: number | BN;
365-
};
366-
367330
export type CreateTokenMetadataParams = {
368331
stakePool: PublicKey;
369332
manager: PublicKey;
@@ -984,62 +947,6 @@ export class StakePoolInstruction {
984947
});
985948
}
986949

987-
/**
988-
* Creates `Redelegate` instruction (rebalance from one validator account to another)
989-
* @param params
990-
*/
991-
static redelegate(params: RedelegateParams): TransactionInstruction {
992-
const {
993-
stakePool,
994-
staker,
995-
stakePoolWithdrawAuthority,
996-
validatorList,
997-
reserveStake,
998-
sourceValidatorStake,
999-
sourceTransientStake,
1000-
ephemeralStake,
1001-
destinationTransientStake,
1002-
destinationValidatorStake,
1003-
validator,
1004-
lamports,
1005-
sourceTransientStakeSeed,
1006-
ephemeralStakeSeed,
1007-
destinationTransientStakeSeed,
1008-
} = params;
1009-
1010-
const keys = [
1011-
{ pubkey: stakePool, isSigner: false, isWritable: false },
1012-
{ pubkey: staker, isSigner: true, isWritable: false },
1013-
{ pubkey: stakePoolWithdrawAuthority, isSigner: false, isWritable: false },
1014-
{ pubkey: validatorList, isSigner: false, isWritable: true },
1015-
{ pubkey: reserveStake, isSigner: false, isWritable: true },
1016-
{ pubkey: sourceValidatorStake, isSigner: false, isWritable: true },
1017-
{ pubkey: sourceTransientStake, isSigner: false, isWritable: true },
1018-
{ pubkey: ephemeralStake, isSigner: false, isWritable: true },
1019-
{ pubkey: destinationTransientStake, isSigner: false, isWritable: true },
1020-
{ pubkey: destinationValidatorStake, isSigner: false, isWritable: false },
1021-
{ pubkey: validator, isSigner: false, isWritable: false },
1022-
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
1023-
{ pubkey: SYSVAR_STAKE_HISTORY_PUBKEY, isSigner: false, isWritable: false },
1024-
{ pubkey: STAKE_CONFIG_ID, isSigner: false, isWritable: false },
1025-
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
1026-
{ pubkey: StakeProgram.programId, isSigner: false, isWritable: false },
1027-
];
1028-
1029-
const data = encodeData(STAKE_POOL_INSTRUCTION_LAYOUTS.Redelegate, {
1030-
lamports,
1031-
sourceTransientStakeSeed,
1032-
ephemeralStakeSeed,
1033-
destinationTransientStakeSeed,
1034-
});
1035-
1036-
return new TransactionInstruction({
1037-
programId: STAKE_POOL_PROGRAM_ID,
1038-
keys,
1039-
data,
1040-
});
1041-
}
1042-
1043950
/**
1044951
* Creates an instruction to create metadata
1045952
* using the mpl token metadata program for the pool token

stake-pool/js/test/instructions.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
depositSol,
2828
withdrawSol,
2929
withdrawStake,
30-
redelegate,
3130
getStakeAccount,
3231
createPoolTokenMetadata,
3332
updatePoolTokenMetadata,
@@ -498,31 +497,6 @@ describe('StakePoolProgram', () => {
498497
});
499498
});
500499

501-
describe('redelegation', () => {
502-
it('should call successfully', async () => {
503-
const data = {
504-
connection,
505-
stakePoolAddress,
506-
sourceVoteAccount: PublicKey.default,
507-
sourceTransientStakeSeed: 10,
508-
destinationVoteAccount: PublicKey.default,
509-
destinationTransientStakeSeed: 20,
510-
ephemeralStakeSeed: 100,
511-
lamports: 100,
512-
};
513-
const res = await redelegate(data);
514-
515-
const decodedData = STAKE_POOL_INSTRUCTION_LAYOUTS.Redelegate.layout.decode(
516-
res.instructions[0].data,
517-
);
518-
519-
expect(decodedData.instruction).toBe(22);
520-
expect(decodedData.lamports).toBe(data.lamports);
521-
expect(decodedData.sourceTransientStakeSeed).toBe(data.sourceTransientStakeSeed);
522-
expect(decodedData.destinationTransientStakeSeed).toBe(data.destinationTransientStakeSeed);
523-
expect(decodedData.ephemeralStakeSeed).toBe(data.ephemeralStakeSeed);
524-
});
525-
});
526500
describe('createPoolTokenMetadata', () => {
527501
it('should create pool token metadata', async () => {
528502
connection.getAccountInfo = jest.fn(async (pubKey: PublicKey) => {

stake-pool/program/src/instruction.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Instruction types
22
3+
// Remove the following `allow` when `Redelegate` is removed, required to avoid
4+
// warnings from uses of deprecated types during trait derivations.
5+
#![allow(deprecated)]
36
#![allow(clippy::too_many_arguments)]
47

58
use {
@@ -599,6 +602,10 @@ pub enum StakePoolInstruction {
599602
/// 13. `[]` Stake Config sysvar
600603
/// 14. `[]` System program
601604
/// 15. `[]` Stake program
605+
#[deprecated(
606+
since = "2.0.0",
607+
note = "The stake redelegate instruction used in this will not be enabled."
608+
)]
602609
Redelegate {
603610
/// Amount of lamports to redelegate
604611
#[allow(dead_code)] // but it's not
@@ -1051,6 +1058,10 @@ pub fn increase_additional_validator_stake(
10511058

10521059
/// Creates `Redelegate` instruction (rebalance from one validator account to
10531060
/// another)
1061+
#[deprecated(
1062+
since = "2.0.0",
1063+
note = "The stake redelegate instruction used in this will not be enabled."
1064+
)]
10541065
pub fn redelegate(
10551066
program_id: &Pubkey,
10561067
stake_pool: &Pubkey,

0 commit comments

Comments
 (0)