2
2
3
3
use serde_derive:: { Deserialize , Serialize } ;
4
4
use solana_program:: {
5
+ clock:: { Epoch , UnixTimestamp } ,
5
6
instruction:: { AccountMeta , Instruction } ,
6
7
pubkey:: Pubkey ,
7
- sysvar,
8
+ system_instruction , sysvar,
8
9
} ;
9
10
10
11
solana_program:: declare_id!( "Stake11111111111111111111111111111111111111" ) ;
@@ -21,7 +22,7 @@ pub enum StakeInstruction {
21
22
/// Authorized carries pubkeys that must sign staker transactions
22
23
/// and withdrawer transactions.
23
24
/// Lockup carries information about withdrawal restrictions
24
- InitializeNOTUSED ,
25
+ Initialize ( Authorized , Lockup ) ,
25
26
26
27
/// Authorize a key to manage stake or withdrawal
27
28
///
@@ -102,6 +103,55 @@ pub enum StakeInstruction {
102
103
AuthorizeWithSeedNOTUSED ,
103
104
}
104
105
106
+ /// FIXME copied from the stake program
107
+ #[ derive( Debug , Serialize , Deserialize , PartialEq , Clone , Copy ) ]
108
+ #[ allow( clippy:: large_enum_variant) ]
109
+ pub enum StakeState {
110
+ /// FIXME copied from the stake program
111
+ Uninitialized ,
112
+ /// FIXME copied from the stake program
113
+ Initialized ( Meta ) ,
114
+ /// FIXME copied from the stake program
115
+ Stake ( Meta , Stake ) ,
116
+ /// FIXME copied from the stake program
117
+ RewardsPool ,
118
+ }
119
+
120
+ /// FIXME copied from the stake program
121
+ #[ derive( Default , Debug , Serialize , Deserialize , PartialEq , Clone , Copy ) ]
122
+ pub struct Meta {
123
+ /// FIXME copied from the stake program
124
+ pub rent_exempt_reserve : u64 ,
125
+ /// FIXME copied from the stake program
126
+ pub authorized : Authorized ,
127
+ /// FIXME copied from the stake program
128
+ pub lockup : Lockup ,
129
+ }
130
+
131
+ /// FIXME copied from the stake program
132
+ #[ derive( Debug , Default , Serialize , Deserialize , PartialEq , Clone , Copy ) ]
133
+ pub struct Stake {
134
+ /// FIXME copied from the stake program
135
+ pub delegation : Delegation ,
136
+ /// credits observed is credits from vote account state when delegated or redeemed
137
+ pub credits_observed : u64 ,
138
+ }
139
+
140
+ /// FIXME copied from the stake program
141
+ #[ derive( Debug , Default , Serialize , Deserialize , PartialEq , Clone , Copy ) ]
142
+ pub struct Delegation {
143
+ /// to whom the stake is delegated
144
+ pub voter_pubkey : Pubkey ,
145
+ /// activated stake amount, set at delegate() time
146
+ pub stake : u64 ,
147
+ /// epoch at which this stake was activated, std::Epoch::MAX if is a bootstrap stake
148
+ pub activation_epoch : Epoch ,
149
+ /// epoch the stake was deactivated, std::Epoch::MAX if not deactivated
150
+ pub deactivation_epoch : Epoch ,
151
+ /// how much stake we can activate per-epoch as a fraction of currently effective stake
152
+ pub warmup_cooldown_rate : f64 ,
153
+ }
154
+
105
155
/// FIXME copied from the stake program
106
156
#[ derive( Debug , Serialize , Deserialize , PartialEq , Clone , Copy ) ]
107
157
pub enum StakeAuthorize {
@@ -110,6 +160,28 @@ pub enum StakeAuthorize {
110
160
/// FIXME copied from the stake program
111
161
Withdrawer ,
112
162
}
163
+ /// FIXME copied from the stake program
164
+ #[ derive( Default , Debug , Serialize , Deserialize , PartialEq , Clone , Copy ) ]
165
+ pub struct Authorized {
166
+ /// FIXME copied from the stake program
167
+ pub staker : Pubkey ,
168
+ /// FIXME copied from the stake program
169
+ pub withdrawer : Pubkey ,
170
+ }
171
+
172
+ /// FIXME copied from the stake program
173
+ #[ derive( Default , Debug , Serialize , Deserialize , PartialEq , Clone , Copy ) ]
174
+ pub struct Lockup {
175
+ /// UnixTimestamp at which this stake will allow withdrawal, unless the
176
+ /// transaction is signed by the custodian
177
+ pub unix_timestamp : UnixTimestamp ,
178
+ /// epoch height at which this stake will allow withdrawal, unless the
179
+ /// transaction is signed by the custodian
180
+ pub epoch : Epoch ,
181
+ /// custodian signature on a transaction exempts the operation from
182
+ /// lockup constraints
183
+ pub custodian : Pubkey ,
184
+ }
113
185
114
186
/// FIXME copied from the stake program
115
187
pub fn split_only (
@@ -163,3 +235,35 @@ pub fn merge(
163
235
164
236
Instruction :: new ( id ( ) , & StakeInstruction :: Merge , account_metas)
165
237
}
238
+
239
+ /// FIXME copied from the stake program
240
+ pub fn create_account (
241
+ from_pubkey : & Pubkey ,
242
+ stake_pubkey : & Pubkey ,
243
+ authorized : & Authorized ,
244
+ lockup : & Lockup ,
245
+ lamports : u64 ,
246
+ ) -> Vec < Instruction > {
247
+ vec ! [
248
+ system_instruction:: create_account(
249
+ from_pubkey,
250
+ stake_pubkey,
251
+ lamports,
252
+ std:: mem:: size_of:: <StakeState >( ) as u64 ,
253
+ & id( ) ,
254
+ ) ,
255
+ initialize( stake_pubkey, authorized, lockup) ,
256
+ ]
257
+ }
258
+
259
+ /// FIXME copied from the stake program
260
+ fn initialize ( stake_pubkey : & Pubkey , authorized : & Authorized , lockup : & Lockup ) -> Instruction {
261
+ Instruction :: new (
262
+ id ( ) ,
263
+ & StakeInstruction :: Initialize ( * authorized, * lockup) ,
264
+ vec ! [
265
+ AccountMeta :: new( * stake_pubkey, false ) ,
266
+ AccountMeta :: new_readonly( sysvar:: rent:: id( ) , false ) ,
267
+ ] ,
268
+ )
269
+ }
0 commit comments