1
1
mod signature;
2
2
3
- pub mod storage {
4
- use anchor_lang:: prelude:: { pubkey, Pubkey } ;
5
-
6
- pub const ID : Pubkey = pubkey ! ( "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL" ) ;
7
-
8
- #[ test]
9
- fn test_storage_id ( ) {
10
- use { crate :: STORAGE_SEED , anchor_lang:: prelude:: Pubkey } ;
11
-
12
- assert_eq ! (
13
- Pubkey :: find_program_address( & [ STORAGE_SEED ] , & super :: ID ) . 0 ,
14
- ID
15
- ) ;
16
- }
17
- }
18
-
19
3
use {
20
- anchor_lang:: { prelude:: * , solana_program:: pubkey:: PUBKEY_BYTES } ,
4
+ crate :: signature:: VerifiedMessage ,
5
+ anchor_lang:: { prelude:: * , solana_program:: pubkey:: PUBKEY_BYTES , system_program} ,
21
6
std:: mem:: size_of,
22
7
} ;
23
8
@@ -28,6 +13,21 @@ pub use {
28
13
29
14
declare_id ! ( "pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt" ) ;
30
15
16
+ pub const STORAGE_ID : Pubkey = pubkey ! ( "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL" ) ;
17
+ pub const TREASURY_ID : Pubkey = pubkey ! ( "EN4aB3soE5iuCG2fGj2r5fksh4kLRVPV8g7N86vXm8WM" ) ;
18
+
19
+ #[ test]
20
+ fn test_ids ( ) {
21
+ assert_eq ! (
22
+ Pubkey :: find_program_address( & [ STORAGE_SEED ] , & ID ) . 0 ,
23
+ STORAGE_ID
24
+ ) ;
25
+ assert_eq ! (
26
+ Pubkey :: find_program_address( & [ TREASURY_SEED ] , & ID ) . 0 ,
27
+ TREASURY_ID
28
+ ) ;
29
+ }
30
+
31
31
pub const MAX_NUM_TRUSTED_SIGNERS : usize = 2 ;
32
32
33
33
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Default , AnchorSerialize , AnchorDeserialize ) ]
@@ -44,12 +44,14 @@ impl TrustedSignerInfo {
44
44
pub struct Storage {
45
45
pub top_authority : Pubkey ,
46
46
pub num_trusted_signers : u8 ,
47
+ pub single_update_fee_in_lamports : u64 ,
47
48
pub trusted_signers : [ TrustedSignerInfo ; MAX_NUM_TRUSTED_SIGNERS ] ,
48
49
}
49
50
50
51
impl Storage {
51
52
const SERIALIZED_LEN : usize = PUBKEY_BYTES
52
53
+ size_of :: < u8 > ( )
54
+ + size_of :: < u64 > ( )
53
55
+ TrustedSignerInfo :: SERIALIZED_LEN * MAX_NUM_TRUSTED_SIGNERS ;
54
56
55
57
pub fn initialized_trusted_signers ( & self ) -> & [ TrustedSignerInfo ] {
@@ -58,15 +60,15 @@ impl Storage {
58
60
}
59
61
60
62
pub const STORAGE_SEED : & [ u8 ] = b"storage" ;
63
+ pub const TREASURY_SEED : & [ u8 ] = b"treasury" ;
61
64
62
65
#[ program]
63
66
pub mod pyth_lazer_solana_contract {
64
- use signature:: VerifiedMessage ;
65
-
66
67
use super :: * ;
67
68
68
69
pub fn initialize ( ctx : Context < Initialize > , top_authority : Pubkey ) -> Result < ( ) > {
69
70
ctx. accounts . storage . top_authority = top_authority;
71
+ ctx. accounts . storage . single_update_fee_in_lamports = 1 ;
70
72
Ok ( ( ) )
71
73
}
72
74
@@ -128,9 +130,20 @@ pub mod pyth_lazer_solana_contract {
128
130
signature_index : u8 ,
129
131
message_offset : u16 ,
130
132
) -> Result < VerifiedMessage > {
133
+ system_program:: transfer (
134
+ CpiContext :: new (
135
+ ctx. accounts . system_program . to_account_info ( ) ,
136
+ system_program:: Transfer {
137
+ from : ctx. accounts . payer . to_account_info ( ) ,
138
+ to : ctx. accounts . treasury . to_account_info ( ) ,
139
+ } ,
140
+ ) ,
141
+ ctx. accounts . storage . single_update_fee_in_lamports ,
142
+ ) ?;
143
+
131
144
signature:: verify_message (
132
145
& ctx. accounts . storage ,
133
- & ctx. accounts . sysvar ,
146
+ & ctx. accounts . instructions_sysvar ,
134
147
& message_data,
135
148
ed25519_instruction_index,
136
149
signature_index,
@@ -155,6 +168,18 @@ pub struct Initialize<'info> {
155
168
bump,
156
169
) ]
157
170
pub storage : Account < ' info , Storage > ,
171
+ #[ account(
172
+ init,
173
+ payer = payer,
174
+ space = 0 ,
175
+ owner = system_program:: ID ,
176
+ seeds = [ TREASURY_SEED ] ,
177
+ bump,
178
+ ) ]
179
+ /// CHECK: this is a system program account but using anchor's `SystemAccount`
180
+ /// results in invalid output from the Accounts proc macro. No extra checks
181
+ /// are necessary because all necessary constraints are specified in the attribute.
182
+ pub treasury : AccountInfo < ' info > ,
158
183
pub system_program : Program < ' info , System > ,
159
184
}
160
185
@@ -172,10 +197,26 @@ pub struct Update<'info> {
172
197
173
198
#[ derive( Accounts ) ]
174
199
pub struct VerifyMessage < ' info > {
200
+ #[ account( mut ) ]
201
+ pub payer : Signer < ' info > ,
175
202
#[ account(
176
203
seeds = [ STORAGE_SEED ] ,
177
204
bump,
178
205
) ]
179
206
pub storage : Account < ' info , Storage > ,
180
- pub sysvar : AccountInfo < ' info > ,
207
+ #[ account(
208
+ mut ,
209
+ owner = system_program:: ID ,
210
+ seeds = [ TREASURY_SEED ] ,
211
+ bump,
212
+ ) ]
213
+ /// CHECK: this is a system program account but using anchor's `SystemAccount`
214
+ /// results in invalid output from the Accounts proc macro. No extra checks
215
+ /// are necessary because all necessary constraints are specified in the attribute.
216
+ pub treasury : AccountInfo < ' info > ,
217
+ pub system_program : Program < ' info , System > ,
218
+ /// CHECK: account ID is checked in Solana SDK during calls
219
+ /// (e.g. in `sysvar::instructions::load_instruction_at_checked`).
220
+ /// This account is not usable with anchor's `Program` account type because it's not executable.
221
+ pub instructions_sysvar : AccountInfo < ' info > ,
181
222
}
0 commit comments