11mod signature;
22
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-
193use {
20- anchor_lang:: { prelude:: * , solana_program:: pubkey:: PUBKEY_BYTES } ,
4+ anchor_lang:: { prelude:: * , solana_program:: pubkey:: PUBKEY_BYTES , system_program } ,
215 std:: mem:: size_of,
226} ;
237
@@ -28,6 +12,21 @@ pub use {
2812
2913declare_id ! ( "pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt" ) ;
3014
15+ pub const STORAGE_ID : Pubkey = pubkey ! ( "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL" ) ;
16+ pub const TREASURY_ID : Pubkey = pubkey ! ( "EN4aB3soE5iuCG2fGj2r5fksh4kLRVPV8g7N86vXm8WM" ) ;
17+
18+ #[ test]
19+ fn test_ids ( ) {
20+ assert_eq ! (
21+ Pubkey :: find_program_address( & [ STORAGE_SEED ] , & ID ) . 0 ,
22+ STORAGE_ID
23+ ) ;
24+ assert_eq ! (
25+ Pubkey :: find_program_address( & [ TREASURY_SEED ] , & ID ) . 0 ,
26+ TREASURY_ID
27+ ) ;
28+ }
29+
3130pub const MAX_NUM_TRUSTED_SIGNERS : usize = 2 ;
3231
3332#[ derive( Debug , Clone , Copy , PartialEq , Eq , Default , AnchorSerialize , AnchorDeserialize ) ]
@@ -44,12 +43,14 @@ impl TrustedSignerInfo {
4443pub struct Storage {
4544 pub top_authority : Pubkey ,
4645 pub num_trusted_signers : u8 ,
46+ pub single_update_fee_in_lamports : u64 ,
4747 pub trusted_signers : [ TrustedSignerInfo ; MAX_NUM_TRUSTED_SIGNERS ] ,
4848}
4949
5050impl Storage {
5151 const SERIALIZED_LEN : usize = PUBKEY_BYTES
5252 + size_of :: < u8 > ( )
53+ + size_of :: < u64 > ( )
5354 + TrustedSignerInfo :: SERIALIZED_LEN * MAX_NUM_TRUSTED_SIGNERS ;
5455
5556 pub fn initialized_trusted_signers ( & self ) -> & [ TrustedSignerInfo ] {
@@ -58,15 +59,18 @@ impl Storage {
5859}
5960
6061pub const STORAGE_SEED : & [ u8 ] = b"storage" ;
62+ pub const TREASURY_SEED : & [ u8 ] = b"treasury" ;
6163
6264#[ program]
6365pub mod pyth_lazer_solana_contract {
66+ use anchor_lang:: system_program;
6467 use signature:: VerifiedMessage ;
6568
6669 use super :: * ;
6770
6871 pub fn initialize ( ctx : Context < Initialize > , top_authority : Pubkey ) -> Result < ( ) > {
6972 ctx. accounts . storage . top_authority = top_authority;
73+ ctx. accounts . storage . single_update_fee_in_lamports = 1 ;
7074 Ok ( ( ) )
7175 }
7276
@@ -128,6 +132,17 @@ pub mod pyth_lazer_solana_contract {
128132 signature_index : u8 ,
129133 message_offset : u16 ,
130134 ) -> Result < VerifiedMessage > {
135+ system_program:: transfer (
136+ CpiContext :: new (
137+ ctx. accounts . system_program . to_account_info ( ) ,
138+ system_program:: Transfer {
139+ from : ctx. accounts . payer . to_account_info ( ) ,
140+ to : ctx. accounts . treasury . to_account_info ( ) ,
141+ } ,
142+ ) ,
143+ ctx. accounts . storage . single_update_fee_in_lamports ,
144+ ) ?;
145+
131146 signature:: verify_message (
132147 & ctx. accounts . storage ,
133148 & ctx. accounts . sysvar ,
@@ -155,6 +170,15 @@ pub struct Initialize<'info> {
155170 bump,
156171 ) ]
157172 pub storage : Account < ' info , Storage > ,
173+ #[ account(
174+ init,
175+ payer = payer,
176+ space = 0 ,
177+ owner = system_program:: ID ,
178+ seeds = [ TREASURY_SEED ] ,
179+ bump,
180+ ) ]
181+ pub treasury : AccountInfo < ' info > ,
158182 pub system_program : Program < ' info , System > ,
159183}
160184
@@ -172,10 +196,20 @@ pub struct Update<'info> {
172196
173197#[ derive( Accounts ) ]
174198pub struct VerifyMessage < ' info > {
199+ #[ account( mut ) ]
200+ pub payer : Signer < ' info > ,
175201 #[ account(
176202 seeds = [ STORAGE_SEED ] ,
177203 bump,
178204 ) ]
179205 pub storage : Account < ' info , Storage > ,
206+ #[ account(
207+ mut ,
208+ owner = system_program:: ID ,
209+ seeds = [ TREASURY_SEED ] ,
210+ bump,
211+ ) ]
212+ pub treasury : AccountInfo < ' info > ,
213+ pub system_program : Program < ' info , System > ,
180214 pub sysvar : AccountInfo < ' info > ,
181215}
0 commit comments