Module: Solana::Ruby::Kit::Programs::StakeProgram
- Extended by:
- T::Sig
- Defined in:
- lib/solana/ruby/kit/programs/stake_program.rb
Overview
Ruby interface for the Solana Stake Program.
The Stake Program manages stake accounts used for delegating SOL to validators and earning staking rewards. Instruction data uses little-endian encoding: a u32 discriminator followed by any instruction-specific fields.
Reference: github.com/solana-labs/solana-web3.js/blob/master/packages/library-legacy/src/programs/stake.ts
Constant Summary collapse
- PROGRAM_ID =
The Stake Program address.
T.let( Addresses::Address.new('Stake11111111111111111111111111111111111111'), Addresses::Address )
- STAKE_CONFIG_ID =
The Stake Config sysvar / config account.
T.let( Addresses::Address.new('StakeConfig11111111111111111111111111111111'), Addresses::Address )
- STAKE_ACCOUNT_SPACE =
Number of bytes required to store a stake account on-chain.
T.let(200, Integer)
- DISCRIMINATOR_INITIALIZE =
Instruction discriminators (u32 little-endian).
T.let(0, Integer)
- DISCRIMINATOR_DELEGATE =
T.let(2, Integer)
Class Method Summary collapse
- .create_account_instructions(from:, stake_account:, authorized:, lamports:) ⇒ Object
- .delegate_instruction(stake_account:, vote_account:, authorized:) ⇒ Object
Class Method Details
.create_account_instructions(from:, stake_account:, authorized:, lamports:) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/solana/ruby/kit/programs/stake_program.rb', line 79 def create_account_instructions(from:, stake_account:, authorized:, lamports:) stake_program_bytes = Encoding::Base58.decode(PROGRAM_ID.value) = Encoding::Base58.decode(.value) zero_pubkey = ("\x00" * 32).b # Instruction 0: System Program createAccount (discriminant = 0) create_data = [0, lamports, STAKE_ACCOUNT_SPACE, stake_program_bytes].pack('VQ<Q<a32').b create_account_ix = Instructions::Instruction.new( program_address: SystemProgram::PROGRAM_ID, accounts: [ Instructions.writable_signer_account(from), # 0 from Instructions.writable_signer_account(stake_account), # 1 stake_account ], data: create_data ) # Instruction 1: Stake Program Initialize initialize_data = [ DISCRIMINATOR_INITIALIZE, , # staker , # withdrawer 0, # lockup.unix_timestamp (i64) 0, # lockup.epoch (u64) zero_pubkey # lockup.custodian ].pack('Va32a32q<Q<a32').b initialize_ix = Instructions::Instruction.new( program_address: PROGRAM_ID, accounts: [ Instructions.writable_account(stake_account), # 0 stake_account Instructions.readonly_account(Addresses::Address.new(Sysvars::SYSVAR_RENT_ADDRESS)), # 1 sysvar rent ], data: initialize_data ) [create_account_ix, initialize_ix] end |
.delegate_instruction(stake_account:, vote_account:, authorized:) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/solana/ruby/kit/programs/stake_program.rb', line 144 def delegate_instruction(stake_account:, vote_account:, authorized:) data = [DISCRIMINATOR_DELEGATE].pack('V').b Instructions::Instruction.new( program_address: PROGRAM_ID, accounts: [ Instructions.writable_account(stake_account), # 0 stake_account Instructions.readonly_account(vote_account), # 1 vote_account Instructions.readonly_account(Addresses::Address.new(Sysvars::SYSVAR_CLOCK_ADDRESS)), # 2 clock Instructions.readonly_account(Addresses::Address.new(Sysvars::SYSVAR_STAKE_HISTORY_ADDRESS)), # 3 stake history Instructions.readonly_account(STAKE_CONFIG_ID), # 4 stake config Instructions.readonly_signer_account(), # 5 authorized staker ], data: data ) end |