Skip to content
Closed
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
6,517 changes: 881 additions & 5,636 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
[workspace]
resolver = "2"
members = ["clients/rust", "program"]
members = ["interface"]

[workspace.metadata.cli]
solana = "edge"

# Specify Rust toolchains for rustfmt, clippy, and build.
# Any unprovided toolchains default to stable.
[workspace.metadata.toolchains]
format = "nightly-2023-10-05"
lint = "nightly-2023-10-05"

[workspace.lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(target_os, values("solana"))',
'cfg(feature, values("frozen-abi"))',
]
7 changes: 0 additions & 7 deletions clients/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ readme = "README.md"
license-file = "../../LICENSE"

[features]
anchor = ["dep:anchor-lang"]
test-sbf = []
serde = ["dep:serde", "dep:serde_with"]

[dependencies]
anchor-lang = { version = "0.30.0", optional = true }
borsh = "^0.10"
num-derive = "^0.3"
num-traits = "^0.2"
serde = { version = "^1.0", features = ["derive"], optional = true }
serde_with = { version = "^3.0", optional = true }
solana-program = { git = "https://github.com/2501babe/solana", branch = "hana-neostake-checkpoint" }
thiserror = "^1.0"

[dev-dependencies]
assert_matches = "1.5.0"
solana-program-test = { git = "https://github.com/2501babe/solana", branch = "hana-neostake-checkpoint" }
solana-sdk = { git = "https://github.com/2501babe/solana", branch = "hana-neostake-checkpoint" }
52 changes: 52 additions & 0 deletions interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "solana-stake-interface"
version = "0.1.0"
description = "Instructions and constructors for the Stake program"
repository = "https://github.com/solana-program/stake"
edition = "2021"
readme = "README.md"
license-file = "../LICENSE"

[dependencies]
borsh = { version = "1.5.1", features = ["derive", "unstable__schema"], optional=true }
borsh0-10 = { package = "borsh", version = "0.10.3", optional=true }
num-derive = "0.4"
num-traits = "0.2"
serde = { version="1.0.210" }
solana-decode-error = { version="2.1.0", git="https://github.com/anza-xyz/agave.git" }
serde_derive = { version="1.0.210" }
solana-clock = { version="2.1.0", features=["serde"], git="https://github.com/anza-xyz/agave.git" }
solana-frozen-abi = { version="=2.1.0", features=["frozen-abi"], optional=true, git="https://github.com/anza-xyz/agave.git" }
solana-frozen-abi-macro = { version="=2.1.0", features=["frozen-abi"], optional=true, git="https://github.com/anza-xyz/agave.git" }
solana-instruction = { version="2.1.0", features=["bincode", "std"], git="https://github.com/anza-xyz/agave.git" }
solana-program = { version="2.1.0", git="https://github.com/anza-xyz/agave.git" }
solana-program-error = { version="2.1.0", features=["serde"], git="https://github.com/anza-xyz/agave.git" }
solana-pubkey = { version="2.1.0", features=["serde"], git="https://github.com/anza-xyz/agave.git" }
solana-system-interface = { version="0.0.1", git="https://github.com/solana-program/system.git", branch="febo/system-instruction" }

[dev-dependencies]
assert_matches = "1.5.0"
bincode = "1.3.3"
static_assertions = "1.1.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[features]
default = ["borsh"]
borsh = [
"dep:borsh",
"dep:borsh0-10",
"solana-instruction/borsh",
"solana-program-error/borsh",
"solana-pubkey/borsh"
]
frozen-abi = [
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"solana-instruction/frozen-abi",
"solana-pubkey/frozen-abi"
]

[lints]
workspace = true
35 changes: 35 additions & 0 deletions interface/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! config for staking
//! carries variables that the stake program cares about

#[deprecated(
since = "1.16.7",
note = "Please use `solana_sdk::stake::state::{DEFAULT_SLASH_PENALTY, \
DEFAULT_WARMUP_COOLDOWN_RATE}` instead"
)]
pub use super::state::{DEFAULT_SLASH_PENALTY, DEFAULT_WARMUP_COOLDOWN_RATE};
use solana_pubkey::declare_deprecated_id;

// stake config ID
declare_deprecated_id!("StakeConfig11111111111111111111111111111111");

#[deprecated(
since = "1.16.7",
note = "Please use `solana_sdk::stake::state::warmup_cooldown_rate()` instead"
)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)]
pub struct Config {
/// how much stake we can activate/deactivate per-epoch as a fraction of
/// currently effective stake
pub warmup_cooldown_rate: f64,
/// percentage of stake lost when slash, expressed as a portion of u8::MAX
pub slash_penalty: u8,
}

impl Default for Config {
fn default() -> Self {
Self {
warmup_cooldown_rate: DEFAULT_WARMUP_COOLDOWN_RATE,
slash_penalty: DEFAULT_SLASH_PENALTY,
}
}
}
162 changes: 162 additions & 0 deletions interface/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
use {
num_derive::{FromPrimitive, ToPrimitive},
solana_decode_error::DecodeError,
solana_program_error::ProgramError,
};

/// Reasons the stake might have had an error
#[derive(Debug, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum StakeError {
// 0
/// Not enough credits to redeem.
NoCreditsToRedeem,

/// Lockup has not yet expired.
LockupInForce,

/// Stake already deactivated.
AlreadyDeactivated,

/// One re-delegation permitted per epoch.
TooSoonToRedelegate,

/// Split amount is more than is staked.
InsufficientStake,

// 5
/// Stake account with transient stake cannot be merged.
MergeTransientStake,

/// Stake account merge failed due to different authority, lockups or state.
MergeMismatch,

/// Custodian address not present.
CustodianMissing,

/// Custodian signature not present.
CustodianSignatureMissing,

/// Insufficient voting activity in the reference vote account.
InsufficientReferenceVotes,

// 10
/// Stake account is not delegated to the provided vote account.
VoteAddressMismatch,

/// Stake account has not been delinquent for the minimum epochs required
/// for deactivation.
MinimumDelinquentEpochsForDeactivationNotMet,

/// Delegation amount is less than the minimum.
InsufficientDelegation,

/// Stake account with transient or inactive stake cannot be redelegated.
RedelegateTransientOrInactiveStake,

/// Stake redelegation to the same vote account is not permitted.
RedelegateToSameVoteAccount,

// 15
/// Redelegated stake must be fully activated before deactivation.
RedelegatedStakeMustFullyActivateBeforeDeactivationIsPermitted,

/// Stake action is not permitted while the epoch rewards period is active.
EpochRewardsActive,
}

impl std::error::Error for StakeError {}

impl core::fmt::Display for StakeError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
StakeError::NoCreditsToRedeem => {
write!(f, "not enough credits to redeem")
}
StakeError::LockupInForce => {
write!(f, "lockup has not yet expired")
}
StakeError::AlreadyDeactivated => {
write!(f, "stake already deactivated")
}
StakeError::TooSoonToRedelegate => {
write!(f, "one re-delegation permitted per epoch")
}
StakeError::InsufficientStake => {
write!(f, "split amount is more than is staked")
}
StakeError::MergeTransientStake => {
write!(f, "stake account with transient stake cannot be merged")
}
StakeError::MergeMismatch => {
write!(
f,
"stake account merge failed due to different authority, lockups or state"
)
}
StakeError::CustodianMissing => {
write!(f, "custodian address not present")
}
StakeError::CustodianSignatureMissing => {
write!(f, "custodian signature not present")
}
StakeError::InsufficientReferenceVotes => {
write!(
f,
"insufficient voting activity in the reference vote account"
)
}
StakeError::VoteAddressMismatch => {
write!(
f,
"stake account is not delegated to the provided vote account"
)
}
StakeError::MinimumDelinquentEpochsForDeactivationNotMet => {
write!(
f,
"stake account has not been delinquent for the minimum epochs required for \
deactivation"
)
}
StakeError::InsufficientDelegation => {
write!(f, "delegation amount is less than the minimum")
}
StakeError::RedelegateTransientOrInactiveStake => {
write!(
f,
"stake account with transient or inactive stake cannot be redelegated"
)
}
StakeError::RedelegateToSameVoteAccount => {
write!(
f,
"stake redelegation to the same vote account is not permitted"
)
}
StakeError::RedelegatedStakeMustFullyActivateBeforeDeactivationIsPermitted => {
write!(
f,
"redelegated stake must be fully activated before deactivation"
)
}
StakeError::EpochRewardsActive => {
write!(
f,
"stake action is not permitted while the epoch rewards period is active"
)
}
}
}
}

impl From<StakeError> for ProgramError {
fn from(e: StakeError) -> Self {
ProgramError::Custom(e as u32)
}
}

impl<E> DecodeError<E> for StakeError {
fn type_of() -> &'static str {
"StakeError"
}
}
Loading