@@ -53,6 +53,7 @@ pub struct InitConfig<'info> {
53
53
}
54
54
55
55
#[ derive( Accounts ) ]
56
+ #[ instruction( delegatee: Pubkey , current_delegate_stake_account_owner: Pubkey ) ]
56
57
pub struct Delegate < ' info > {
57
58
// Native payer:
58
59
#[ account( address = stake_account_metadata. owner) ]
@@ -64,41 +65,38 @@ pub struct Delegate<'info> {
64
65
AccountLoader < ' info , checkpoints:: CheckpointData > ,
65
66
#[ account(
66
67
mut ,
67
- seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , current_delegate_stake_account_checkpoints . key ( ) . as_ref( ) ] ,
68
+ seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , current_delegate_stake_account_owner . as_ref( ) ] ,
68
69
bump = current_delegate_stake_account_metadata. metadata_bump
69
70
) ]
70
71
pub current_delegate_stake_account_metadata :
71
72
Box < Account < ' info , stake_account:: StakeAccountMetadata > > ,
72
-
73
73
// Delegatee stake accounts:
74
74
#[ account( mut ) ]
75
75
pub delegatee_stake_account_checkpoints : AccountLoader < ' info , checkpoints:: CheckpointData > ,
76
76
#[ account(
77
77
mut ,
78
- seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , delegatee_stake_account_checkpoints . key ( ) . as_ref( ) ] ,
78
+ seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , delegatee . as_ref( ) ] ,
79
79
bump = delegatee_stake_account_metadata. metadata_bump
80
80
) ]
81
81
pub delegatee_stake_account_metadata : Box < Account < ' info , stake_account:: StakeAccountMetadata > > ,
82
82
83
83
// User stake account:
84
- #[ account( mut ) ]
85
- pub stake_account_checkpoints : AccountLoader < ' info , checkpoints:: CheckpointData > ,
86
84
#[ account(
87
85
mut ,
88
- seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , stake_account_checkpoints . key( ) . as_ref( ) ] ,
86
+ seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , payer . key( ) . as_ref( ) ] ,
89
87
bump = stake_account_metadata. metadata_bump,
90
- constraint = stake_account_metadata. delegate == current_delegate_stake_account_checkpoints . key ( )
88
+ constraint = stake_account_metadata. delegate == current_delegate_stake_account_owner
91
89
@ ErrorCode :: InvalidCurrentDelegate
92
90
) ]
93
91
pub stake_account_metadata : Box < Account < ' info , stake_account:: StakeAccountMetadata > > ,
94
92
/// CHECK : This AccountInfo is safe because it's a checked PDA
95
- #[ account( seeds = [ AUTHORITY_SEED . as_bytes( ) , stake_account_checkpoints . key( ) . as_ref( ) ] , bump) ]
93
+ #[ account( seeds = [ AUTHORITY_SEED . as_bytes( ) , payer . key( ) . as_ref( ) ] , bump) ]
96
94
pub custody_authority : AccountInfo < ' info > ,
97
95
#[ account(
98
96
mut ,
99
97
seeds = [
100
98
CUSTODY_SEED . as_bytes( ) ,
101
- stake_account_checkpoints . key( ) . as_ref( )
99
+ payer . key( ) . as_ref( )
102
100
] ,
103
101
bump,
104
102
token:: mint = mint,
@@ -120,7 +118,11 @@ pub struct Delegate<'info> {
120
118
}
121
119
122
120
#[ derive( Accounts ) ]
123
- #[ instruction( proposal_id: [ u8 ; 32 ] ) ]
121
+ #[ instruction( proposal_id: [ u8 ; 32 ] ,
122
+ _against_votes: u64 ,
123
+ _for_votes: u64 ,
124
+ _abstain_votes: u64 ,
125
+ checkpoint_index: u8 ) ]
124
126
pub struct CastVote < ' info > {
125
127
#[ account( mut ) ]
126
128
pub owner : Signer < ' info > ,
@@ -132,19 +134,27 @@ pub struct CastVote<'info> {
132
134
) ]
133
135
pub proposal : Account < ' info , proposal:: ProposalData > ,
134
136
135
- #[ account( mut , has_one = owner) ]
137
+ #[ account(
138
+ mut ,
139
+ has_one = owner,
140
+ seeds = [ CHECKPOINT_DATA_SEED . as_bytes( ) , owner. key( ) . as_ref( ) , checkpoint_index. to_le_bytes( ) . as_ref( ) ] ,
141
+ bump
142
+ ) ]
136
143
pub voter_checkpoints : AccountLoader < ' info , checkpoints:: CheckpointData > ,
137
144
138
145
#[ account(
139
146
init_if_needed,
140
147
payer = owner,
141
148
space = proposal_voters_weight_cast:: ProposalVotersWeightCast :: LEN ,
142
- seeds = [ b"proposal_voters_weight_cast" , proposal. key( ) . as_ref( ) , voter_checkpoints . key( ) . as_ref( ) ] ,
149
+ seeds = [ b"proposal_voters_weight_cast" , proposal. key( ) . as_ref( ) , owner . key( ) . as_ref( ) ] ,
143
150
bump
144
151
) ]
145
152
pub proposal_voters_weight_cast :
146
153
Account < ' info , proposal_voters_weight_cast:: ProposalVotersWeightCast > ,
147
154
155
+ #[ account( seeds = [ CONFIG_SEED . as_bytes( ) ] , bump = config. bump) ]
156
+ pub config : Box < Account < ' info , global_config:: GlobalConfig > > ,
157
+
148
158
pub system_program : Program < ' info , System > ,
149
159
}
150
160
@@ -385,16 +395,22 @@ pub struct CreateStakeAccount<'info> {
385
395
// Stake program accounts:
386
396
#[ account(
387
397
init,
388
- seeds = [ CHECKPOINT_DATA_SEED . as_bytes( ) , payer. key( ) . as_ref( ) ] ,
398
+ seeds = [ CHECKPOINT_DATA_SEED . as_bytes( ) , payer. key( ) . as_ref( ) , 0u8 . to_le_bytes ( ) . as_ref ( ) ] ,
389
399
bump,
390
400
payer = payer,
391
401
space = checkpoints:: CheckpointData :: LEN ,
392
402
) ]
393
403
pub stake_account_checkpoints : AccountLoader < ' info , checkpoints:: CheckpointData > ,
394
- #[ account( init, payer = payer, space = stake_account:: StakeAccountMetadata :: LEN , seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , stake_account_checkpoints. key( ) . as_ref( ) ] , bump) ]
404
+ #[ account(
405
+ init,
406
+ payer = payer,
407
+ space = stake_account:: StakeAccountMetadata :: LEN ,
408
+ seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , payer. key( ) . as_ref( ) ] ,
409
+ bump
410
+ ) ]
395
411
pub stake_account_metadata : Box < Account < ' info , stake_account:: StakeAccountMetadata > > ,
396
412
/// CHECK : This AccountInfo is safe because it's a checked PDA
397
- #[ account( seeds = [ AUTHORITY_SEED . as_bytes( ) , stake_account_checkpoints . key( ) . as_ref( ) ] , bump) ]
413
+ #[ account( seeds = [ AUTHORITY_SEED . as_bytes( ) , payer . key( ) . as_ref( ) ] , bump) ]
398
414
pub custody_authority : AccountInfo < ' info > ,
399
415
#[ account( seeds = [ CONFIG_SEED . as_bytes( ) ] , bump = config. bump) ]
400
416
pub config : Box < Account < ' info , global_config:: GlobalConfig > > ,
@@ -405,7 +421,7 @@ pub struct CreateStakeAccount<'info> {
405
421
init,
406
422
seeds = [
407
423
CUSTODY_SEED . as_bytes( ) ,
408
- stake_account_checkpoints . key( ) . as_ref( )
424
+ payer . key( ) . as_ref( )
409
425
] ,
410
426
bump,
411
427
payer = payer,
@@ -418,11 +434,35 @@ pub struct CreateStakeAccount<'info> {
418
434
pub token_program : Program < ' info , Token > ,
419
435
pub system_program : Program < ' info , System > ,
420
436
}
437
+ #[ derive( Accounts ) ]
438
+ pub struct CreateCheckpoints < ' info > {
439
+ // Native payer:
440
+ #[ account( mut ) ]
441
+ pub payer : Signer < ' info > ,
442
+ #[ account( mut ) ]
443
+ pub stake_account_metadata : Box < Account < ' info , stake_account:: StakeAccountMetadata > > ,
444
+ // Stake program accounts:
445
+ #[ account( mut ) ]
446
+ pub stake_account_checkpoints : AccountLoader < ' info , checkpoints:: CheckpointData > ,
447
+ // Stake program accounts:
448
+ #[ account(
449
+ init,
450
+ seeds = [ CHECKPOINT_DATA_SEED . as_bytes( ) , payer. key( ) . as_ref( ) , stake_account_metadata. stake_account_checkpoints_last_index. to_le_bytes( ) . as_ref( ) ] ,
451
+ bump,
452
+ payer = payer,
453
+ space = checkpoints:: CheckpointData :: LEN ,
454
+ ) ]
455
+ pub new_stake_account_checkpoints : AccountLoader < ' info , checkpoints:: CheckpointData > ,
456
+ // Primitive accounts :
457
+ pub system_program : Program < ' info , System > ,
458
+ }
421
459
422
460
#[ derive( Accounts ) ]
461
+ #[ instruction( amount: u64 , current_delegate_stake_account_metadata_owner: Pubkey , stake_account_metadata_owner: Pubkey
462
+ ) ]
423
463
pub struct WithdrawTokens < ' info > {
424
464
// Native payer:
425
- #[ account( address = stake_account_metadata. owner) ]
465
+ #[ account( mut , address = stake_account_metadata. owner) ]
426
466
pub payer : Signer < ' info > ,
427
467
428
468
// Current delegate stake account:
@@ -431,7 +471,7 @@ pub struct WithdrawTokens<'info> {
431
471
AccountLoader < ' info , checkpoints:: CheckpointData > ,
432
472
#[ account(
433
473
mut ,
434
- seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , current_delegate_stake_account_checkpoints . key ( ) . as_ref( ) ] ,
474
+ seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , current_delegate_stake_account_metadata_owner . as_ref( ) ] ,
435
475
bump = current_delegate_stake_account_metadata. metadata_bump
436
476
) ]
437
477
pub current_delegate_stake_account_metadata :
@@ -441,23 +481,23 @@ pub struct WithdrawTokens<'info> {
441
481
#[ account( mut ) ]
442
482
pub destination : Account < ' info , TokenAccount > ,
443
483
// Stake program accounts:
444
- pub stake_account_checkpoints : AccountLoader < ' info , checkpoints:: CheckpointData > ,
445
484
#[ account(
446
485
mut ,
447
- seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , stake_account_checkpoints . key ( ) . as_ref( ) ] ,
486
+ seeds = [ STAKE_ACCOUNT_METADATA_SEED . as_bytes( ) , stake_account_metadata_owner . as_ref( ) ] ,
448
487
bump = stake_account_metadata. metadata_bump,
449
- constraint = stake_account_metadata. delegate == current_delegate_stake_account_checkpoints . key ( )
488
+ constraint = stake_account_metadata. delegate == current_delegate_stake_account_metadata_owner
450
489
@ ErrorCode :: InvalidCurrentDelegate
451
490
) ]
452
491
pub stake_account_metadata : Box < Account < ' info , stake_account:: StakeAccountMetadata > > ,
453
492
#[ account(
454
493
mut ,
455
- seeds = [ CUSTODY_SEED . as_bytes( ) , stake_account_checkpoints . key( ) . as_ref( ) ] ,
494
+ seeds = [ CUSTODY_SEED . as_bytes( ) , payer . key( ) . as_ref( ) ] ,
456
495
bump = stake_account_metadata. custody_bump,
457
496
) ]
458
497
pub stake_account_custody : Account < ' info , TokenAccount > ,
459
498
/// CHECK : This AccountInfo is safe because it's a checked PDA
460
- #[ account( seeds = [ AUTHORITY_SEED . as_bytes( ) , stake_account_checkpoints. key( ) . as_ref( ) ] , bump = stake_account_metadata. authority_bump) ]
499
+ #[ account( seeds = [ AUTHORITY_SEED . as_bytes( ) , payer. key( ) . as_ref( ) ] , bump = stake_account_metadata. authority_bump
500
+ ) ]
461
501
pub custody_authority : AccountInfo < ' info > ,
462
502
#[ account( seeds = [ CONFIG_SEED . as_bytes( ) ] , bump = config. bump) ]
463
503
pub config : Account < ' info , global_config:: GlobalConfig > ,
0 commit comments