A Solana program for staking DEFAI tokens with tiered APY rewards and sustainable tokenomics.
The DEFAI Staking program enables users to:
- Stake DEFAI tokens in three tiers (Gold, Titanium, Infinite)
- Earn APY rewards based on stake amount
- Compound rewards to increase stake
- Time-locked withdrawals with penalty system
- Gold Tier: 10M - 99.99M DEFAI (0.5% APY)
- Titanium Tier: 100M - 999.99M DEFAI (0.75% APY)
- Infinite Tier: 1B+ DEFAI (1% APY)
- Linear reward accrual based on tier APY
- Rewards funded through separate escrow account
- Compound functionality to reinvest rewards
- 7-day initial lock period
- Early unstaking penalties:
- < 30 days: 2% penalty
- 30-90 days: 1% penalty
-
90 days: No penalty
- Penalties redistributed to reward escrow
- 48-hour timelock for admin changes
- Program pause functionality
- Separate escrow for reward distribution
# Ensure you're in the security-auditor directory
cd security-auditor
# Build the program
anchor build --skip-lint
# The built program will be at:
# target/deploy/defai_staking.so- Program ID:
DpAeweyqvHt7iuufYGoJC7oJXbpBNFgeDWCh2jKfwyWd - Localnet:
CyYfX3MjkuQBTpD8N3KLXBAr8Nik89f63FZ3jFVSMd6s
The program requires initialization in the following order:
-
Initialize Program State
await program.methods.initializeProgram( defaiMint // DEFAI token mint address )
-
Initialize Reward Escrow
await program.methods.initializeEscrow()
-
Fund Reward Escrow
await program.methods.fundEscrow( amount // Amount of DEFAI tokens to add to escrow )
// Tier Requirements (in DEFAI with 6 decimals)
pub const GOLD_MIN: u64 = 10_000_000 * 10^6; // 10M DEFAI
pub const GOLD_MAX: u64 = 99_999_999 * 10^6; // 99.99M DEFAI
pub const TITANIUM_MIN: u64 = 100_000_000 * 10^6; // 100M DEFAI
pub const TITANIUM_MAX: u64 = 999_999_999 * 10^6; // 999.99M DEFAI
pub const INFINITE_MIN: u64 = 1_000_000_000 * 10^6; // 1B DEFAI
// APY Rates (in basis points)
pub const GOLD_APY_BPS: u16 = 50; // 0.5%
pub const TITANIUM_APY_BPS: u16 = 75; // 0.75%
pub const INFINITE_APY_BPS: u16 = 100; // 1%
// Timelock
pub const ADMIN_TIMELOCK_DURATION: i64 = 48 * 60 * 60; // 48 hoursawait program.methods.stakeTokens(
new BN(50_000_000 * 10**6) // Stake 50M DEFAI
)await program.methods.claimRewards()await program.methods.compoundRewards()await program.methods.unstakeTokens(
new BN(20_000_000 * 10**6) // Unstake 20M DEFAI
)- Tracks global staking metrics
- Stores authority and mint information
- Manages pause state
- Individual staking position
- Tracks rewards earned and claimed
- Stores tier and lock information
- Holds reward tokens for distribution
- Tracks total distributed rewards
- Time-locked Admin Actions: 48-hour delay for critical changes
- Pause Mechanism: Emergency pause for protocol protection
- Escrow System: Separate reward pool prevents insolvency
- Lock Periods: Prevents gaming through quick stake/unstake
- Penalty System: Discourages short-term staking
AmountTooLow: Stake amount below minimum tier requirementInsufficientStake: Attempting to unstake more than stakedTokensLocked: Tokens still in lock periodNoRewards: No rewards available to claimInvalidAuthority: Unauthorized admin actionProgramPaused: Program is pausedInsufficientEscrowBalance: Escrow lacks funds for rewards
StakeEvent: Emitted when tokens are stakedUnstakeEvent: Emitted when tokens are unstakedRewardsClaimedEvent: Emitted when rewards are claimedRewardsCompoundedEvent: Emitted when rewards are compoundedEscrowFundedEvent: Emitted when escrow is fundedProgramPausedEvent: Emitted when program is paused/unpaused
- Update Authority: Propose and accept authority changes (48h timelock)
- Update DEFAI Mint: Change the accepted token mint
- Pause/Unpause: Emergency controls for the program
- Fund Escrow: Add rewards to the distribution pool