Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

stake-pool: Remove redelegate instruction from program and JS #7033

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions stake-pool/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ export interface StakePoolAccounts {
validatorList: ValidatorListAccount | undefined;
}

interface RedelegateProps {
connection: Connection;
stakePoolAddress: PublicKey;
sourceVoteAccount: PublicKey;
destinationVoteAccount: PublicKey;
sourceTransientStakeSeed: number | BN;
destinationTransientStakeSeed: number | BN;
ephemeralStakeSeed: number | BN;
lamports: number | BN;
}

/**
* Retrieves and deserializes a StakePool account using a web3js connection and the stake pool address.
* @param connection: An active web3js connection.
Expand Down Expand Up @@ -1160,86 +1149,6 @@ export async function stakePoolInfo(connection: Connection, stakePoolAddress: Pu
};
}

/**
* Creates instructions required to redelegate stake.
*/
export async function redelegate(props: RedelegateProps) {
const {
connection,
stakePoolAddress,
sourceVoteAccount,
sourceTransientStakeSeed,
destinationVoteAccount,
destinationTransientStakeSeed,
ephemeralStakeSeed,
lamports,
} = props;
const stakePool = await getStakePoolAccount(connection, stakePoolAddress);

const stakePoolWithdrawAuthority = await findWithdrawAuthorityProgramAddress(
STAKE_POOL_PROGRAM_ID,
stakePoolAddress,
);

const sourceValidatorStake = await findStakeProgramAddress(
STAKE_POOL_PROGRAM_ID,
sourceVoteAccount,
stakePoolAddress,
);

const sourceTransientStake = await findTransientStakeProgramAddress(
STAKE_POOL_PROGRAM_ID,
sourceVoteAccount,
stakePoolAddress,
new BN(sourceTransientStakeSeed),
);

const destinationValidatorStake = await findStakeProgramAddress(
STAKE_POOL_PROGRAM_ID,
destinationVoteAccount,
stakePoolAddress,
);

const destinationTransientStake = await findTransientStakeProgramAddress(
STAKE_POOL_PROGRAM_ID,
destinationVoteAccount,
stakePoolAddress,
new BN(destinationTransientStakeSeed),
);

const ephemeralStake = await findEphemeralStakeProgramAddress(
STAKE_POOL_PROGRAM_ID,
stakePoolAddress,
new BN(ephemeralStakeSeed),
);

const instructions: TransactionInstruction[] = [];

instructions.push(
StakePoolInstruction.redelegate({
stakePool: stakePool.pubkey,
staker: stakePool.account.data.staker,
validatorList: stakePool.account.data.validatorList,
reserveStake: stakePool.account.data.reserveStake,
stakePoolWithdrawAuthority,
ephemeralStake,
ephemeralStakeSeed,
sourceValidatorStake,
sourceTransientStake,
sourceTransientStakeSeed,
destinationValidatorStake,
destinationTransientStake,
destinationTransientStakeSeed,
validator: destinationVoteAccount,
lamports,
}),
);

return {
instructions,
};
}

/**
* Creates instructions required to create pool token metadata.
*/
Expand Down
95 changes: 1 addition & 94 deletions stake-pool/js/src/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import * as BufferLayout from '@solana/buffer-layout';
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
import { InstructionType, encodeData, decodeData } from './utils';
import BN from 'bn.js';
import {
METADATA_MAX_NAME_LENGTH,
METADATA_MAX_SYMBOL_LENGTH,
Expand Down Expand Up @@ -175,19 +174,7 @@ export const STAKE_POOL_INSTRUCTION_LAYOUTS: {
},
Redelegate: {
index: 22,
layout: BufferLayout.struct<any>([
BufferLayout.u8('instruction'),
/// Amount of lamports to redelegate
BufferLayout.ns64('lamports'),
/// Seed used to create source transient stake account
BufferLayout.ns64('sourceTransientStakeSeed'),
/// Seed used to create destination ephemeral account.
BufferLayout.ns64('ephemeralStakeSeed'),
/// Seed used to create destination transient stake account. If there is
/// already transient stake, this must match the current seed, otherwise
/// it can be anything
BufferLayout.ns64('destinationTransientStakeSeed'),
]),
layout: BufferLayout.struct<any>([BufferLayout.u8('instruction')]),
},
});

Expand Down Expand Up @@ -340,30 +327,6 @@ export type DepositSolParams = {
lamports: number;
};

export type RedelegateParams = {
stakePool: PublicKey;
staker: PublicKey;
stakePoolWithdrawAuthority: PublicKey;
validatorList: PublicKey;
reserveStake: PublicKey;
sourceValidatorStake: PublicKey;
sourceTransientStake: PublicKey;
ephemeralStake: PublicKey;
destinationTransientStake: PublicKey;
destinationValidatorStake: PublicKey;
validator: PublicKey;
// Amount of lamports to redelegate
lamports: number | BN;
// Seed used to create source transient stake account
sourceTransientStakeSeed: number | BN;
// Seed used to create destination ephemeral account
ephemeralStakeSeed: number | BN;
// Seed used to create destination transient stake account. If there is
// already transient stake, this must match the current seed, otherwise
// it can be anything
destinationTransientStakeSeed: number | BN;
};

export type CreateTokenMetadataParams = {
stakePool: PublicKey;
manager: PublicKey;
Expand Down Expand Up @@ -984,62 +947,6 @@ export class StakePoolInstruction {
});
}

/**
* Creates `Redelegate` instruction (rebalance from one validator account to another)
* @param params
*/
static redelegate(params: RedelegateParams): TransactionInstruction {
const {
stakePool,
staker,
stakePoolWithdrawAuthority,
validatorList,
reserveStake,
sourceValidatorStake,
sourceTransientStake,
ephemeralStake,
destinationTransientStake,
destinationValidatorStake,
validator,
lamports,
sourceTransientStakeSeed,
ephemeralStakeSeed,
destinationTransientStakeSeed,
} = params;

const keys = [
{ pubkey: stakePool, isSigner: false, isWritable: false },
{ pubkey: staker, isSigner: true, isWritable: false },
{ pubkey: stakePoolWithdrawAuthority, isSigner: false, isWritable: false },
{ pubkey: validatorList, isSigner: false, isWritable: true },
{ pubkey: reserveStake, isSigner: false, isWritable: true },
{ pubkey: sourceValidatorStake, isSigner: false, isWritable: true },
{ pubkey: sourceTransientStake, isSigner: false, isWritable: true },
{ pubkey: ephemeralStake, isSigner: false, isWritable: true },
{ pubkey: destinationTransientStake, isSigner: false, isWritable: true },
{ pubkey: destinationValidatorStake, isSigner: false, isWritable: false },
{ pubkey: validator, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_STAKE_HISTORY_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: STAKE_CONFIG_ID, isSigner: false, isWritable: false },
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
{ pubkey: StakeProgram.programId, isSigner: false, isWritable: false },
];

const data = encodeData(STAKE_POOL_INSTRUCTION_LAYOUTS.Redelegate, {
lamports,
sourceTransientStakeSeed,
ephemeralStakeSeed,
destinationTransientStakeSeed,
});

return new TransactionInstruction({
programId: STAKE_POOL_PROGRAM_ID,
keys,
data,
});
}

/**
* Creates an instruction to create metadata
* using the mpl token metadata program for the pool token
Expand Down
26 changes: 0 additions & 26 deletions stake-pool/js/test/instructions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
depositSol,
withdrawSol,
withdrawStake,
redelegate,
getStakeAccount,
createPoolTokenMetadata,
updatePoolTokenMetadata,
Expand Down Expand Up @@ -498,31 +497,6 @@ describe('StakePoolProgram', () => {
});
});

describe('redelegation', () => {
it('should call successfully', async () => {
const data = {
connection,
stakePoolAddress,
sourceVoteAccount: PublicKey.default,
sourceTransientStakeSeed: 10,
destinationVoteAccount: PublicKey.default,
destinationTransientStakeSeed: 20,
ephemeralStakeSeed: 100,
lamports: 100,
};
const res = await redelegate(data);

const decodedData = STAKE_POOL_INSTRUCTION_LAYOUTS.Redelegate.layout.decode(
res.instructions[0].data,
);

expect(decodedData.instruction).toBe(22);
expect(decodedData.lamports).toBe(data.lamports);
expect(decodedData.sourceTransientStakeSeed).toBe(data.sourceTransientStakeSeed);
expect(decodedData.destinationTransientStakeSeed).toBe(data.destinationTransientStakeSeed);
expect(decodedData.ephemeralStakeSeed).toBe(data.ephemeralStakeSeed);
});
});
describe('createPoolTokenMetadata', () => {
it('should create pool token metadata', async () => {
connection.getAccountInfo = jest.fn(async (pubKey: PublicKey) => {
Expand Down
11 changes: 11 additions & 0 deletions stake-pool/program/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Instruction types

// Remove the following `allow` when `Redelegate` is removed, required to avoid
// warnings from uses of deprecated types during trait derivations.
#![allow(deprecated)]
#![allow(clippy::too_many_arguments)]

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

/// Creates `Redelegate` instruction (rebalance from one validator account to
/// another)
#[deprecated(
since = "2.0.0",
note = "The stake redelegate instruction used in this will not be enabled."
)]
pub fn redelegate(
program_id: &Pubkey,
stake_pool: &Pubkey,
Expand Down
Loading
Loading