File tree 10 files changed +84
-10
lines changed
packages/layerzero-v2/solana/programs/programs 10 files changed +84
-10
lines changed Original file line number Diff line number Diff line change
1
+ use crate :: * ;
2
+
3
+ #[ derive( Accounts ) ]
4
+ pub struct ExtendDVNConfig < ' info > {
5
+ #[ account( mut ) ]
6
+ pub admin : Signer < ' info > ,
7
+ #[ account(
8
+ mut ,
9
+ seeds = [ DVN_CONFIG_SEED ] ,
10
+ bump = config. bump,
11
+ realloc = 8 + DvnConfig :: INIT_SPACE + DstConfig :: INIT_SPACE * ( DST_CONFIG_MAX_LEN - DST_CONFIG_DEFAULT_LEN ) ,
12
+ realloc:: payer = admin,
13
+ realloc:: zero = false ,
14
+ constraint = config. admins. contains( admin. key) @DvnError :: NotAdmin
15
+ ) ]
16
+ pub config : Account < ' info , DvnConfig > ,
17
+ pub system_program : Program < ' info , System > ,
18
+ }
19
+
20
+ impl ExtendDVNConfig < ' _ > {
21
+ pub fn apply ( _ctx : & mut Context < ExtendDVNConfig > ) -> Result < ( ) > {
22
+ Ok ( ( ) )
23
+ }
24
+ }
Original file line number Diff line number Diff line change 1
1
pub mod close_execute;
2
+ pub mod extend_dvn_config;
2
3
pub mod invoke;
3
4
pub mod set_config;
4
5
pub mod withdraw_fee;
5
6
6
7
pub use close_execute:: * ;
8
+ pub use extend_dvn_config:: * ;
7
9
pub use invoke:: * ;
8
10
pub use set_config:: * ;
9
11
pub use withdraw_fee:: * ;
Original file line number Diff line number Diff line change @@ -15,7 +15,13 @@ pub struct SetConfig<'info> {
15
15
16
16
impl SetConfig < ' _ > {
17
17
pub fn apply ( ctx : & mut Context < SetConfig > , params : & SetConfigParams ) -> Result < ( ) > {
18
- params. config . apply ( & mut ctx. accounts . config ) ?;
18
+ let account_size = ctx. accounts . config . to_account_info ( ) . data_len ( ) ;
19
+ let dst_configs_max_len = if account_size > ( DvnConfig :: INIT_SPACE + 8 ) {
20
+ DST_CONFIG_MAX_LEN
21
+ } else {
22
+ DST_CONFIG_DEFAULT_LEN
23
+ } ;
24
+ params. config . apply ( dst_configs_max_len, & mut ctx. accounts . config ) ?;
19
25
emit_cpi ! ( AdminConfigSetEvent { config: params. config. clone( ) } ) ;
20
26
Ok ( ( ) )
21
27
}
@@ -36,7 +42,7 @@ pub enum AdminConfig {
36
42
}
37
43
38
44
impl AdminConfig {
39
- pub fn apply ( & self , config : & mut DvnConfig ) -> Result < ( ) > {
45
+ pub fn apply ( & self , dst_configs_max_len : usize , config : & mut DvnConfig ) -> Result < ( ) > {
40
46
match self {
41
47
AdminConfig :: Admins ( admins) => {
42
48
config. set_admins ( admins. clone ( ) ) ?;
@@ -45,7 +51,7 @@ impl AdminConfig {
45
51
config. default_multiplier_bps = * default_multiplier_bps;
46
52
} ,
47
53
AdminConfig :: DstConfigs ( dst_configs) => {
48
- config. set_dst_configs ( dst_configs. clone ( ) ) ?;
54
+ config. set_dst_configs ( dst_configs_max_len , dst_configs. clone ( ) ) ?;
49
55
} ,
50
56
AdminConfig :: PriceFeed ( price_feed) => {
51
57
config. price_feed = * price_feed;
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ pub mod dvn {
32
32
SetConfig :: apply ( & mut ctx, & params)
33
33
}
34
34
35
+ pub fn extend_dvn_config ( mut ctx : Context < ExtendDVNConfig > ) -> Result < ( ) > {
36
+ ExtendDVNConfig :: apply ( & mut ctx)
37
+ }
38
+
35
39
pub fn invoke ( mut ctx : Context < Invoke > , params : InvokeParams ) -> Result < ( ) > {
36
40
Invoke :: apply ( & mut ctx, & params)
37
41
}
Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ pub const VERIFY_BYTES: u64 = 320;
19
19
pub const ADMINS_MAX_LEN : usize = 5 ;
20
20
pub const SIGNERS_MAX_LEN : usize = 7 ;
21
21
pub const MSGLIBS_MAX_LEN : usize = 10 ;
22
- pub const DST_CONFIG_MAX_LEN : usize = 140 ;
22
+ pub const DST_CONFIG_DEFAULT_LEN : usize = 140 ;
23
+ pub const DST_CONFIG_MAX_LEN : usize = 200 ;
23
24
24
25
#[ account]
25
26
#[ derive( InitSpace ) ]
@@ -39,7 +40,7 @@ pub struct DvnConfig {
39
40
pub admins : Vec < Pubkey > ,
40
41
// set by admins
41
42
pub price_feed : Pubkey ,
42
- #[ max_len( DST_CONFIG_MAX_LEN ) ]
43
+ #[ max_len( DST_CONFIG_DEFAULT_LEN ) ]
43
44
pub dst_configs : Vec < DstConfig > ,
44
45
pub default_multiplier_bps : u16 ,
45
46
}
@@ -64,12 +65,12 @@ impl DvnConfig {
64
65
Ok ( ( ) )
65
66
}
66
67
67
- pub fn set_dst_configs ( & mut self , dst_configs : Vec < DstConfig > ) -> Result < ( ) > {
68
+ pub fn set_dst_configs ( & mut self , max_len : usize , dst_configs : Vec < DstConfig > ) -> Result < ( ) > {
68
69
for config in & dst_configs {
69
70
sorted_list_helper:: insert_or_update_sorted_list_by_eid (
70
71
& mut self . dst_configs ,
71
72
config. clone ( ) ,
72
- DST_CONFIG_MAX_LEN ,
73
+ max_len ,
73
74
) ?;
74
75
}
75
76
Ok ( ( ) )
Original file line number Diff line number Diff line change
1
+ use crate :: * ;
2
+
3
+ #[ derive( Accounts ) ]
4
+ pub struct ExtendPriceFeed < ' info > {
5
+ #[ account( mut ) ]
6
+ pub admin : Signer < ' info > ,
7
+ #[ account(
8
+ mut ,
9
+ realloc = 8 + PriceFeed :: INIT_SPACE + Price :: INIT_SPACE * ( PRICES_MAX_LEN - PRICES_DEFAULT_LEN ) ,
10
+ realloc:: payer = admin,
11
+ realloc:: zero = false ,
12
+ has_one = admin,
13
+ ) ]
14
+ pub price_feed : Account < ' info , PriceFeed > ,
15
+ pub system_program : Program < ' info , System > ,
16
+ }
17
+
18
+ impl ExtendPriceFeed < ' _ > {
19
+ pub fn apply ( _ctx : & mut Context < ExtendPriceFeed > ) -> Result < ( ) > {
20
+ Ok ( ( ) )
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ pub mod extend_price_feed;
1
2
pub mod init_price_feed;
2
3
pub mod set_price_feed;
3
4
pub mod transfer_admin;
4
5
6
+ pub use extend_price_feed:: * ;
5
7
pub use init_price_feed:: * ;
6
8
pub use set_price_feed:: * ;
7
9
pub use transfer_admin:: * ;
Original file line number Diff line number Diff line change @@ -24,10 +24,16 @@ impl SetPrice<'_> {
24
24
gas_per_byte : price_params. gas_per_byte ,
25
25
model_type : price_params. model_type ,
26
26
} ;
27
+ let account_size = ctx. accounts . price_feed . to_account_info ( ) . data_len ( ) ;
28
+ let max_len = if account_size > ( PriceFeed :: INIT_SPACE + 8 ) {
29
+ PRICES_MAX_LEN
30
+ } else {
31
+ PRICES_DEFAULT_LEN
32
+ } ;
27
33
sorted_list_helper:: insert_or_update_sorted_list_by_eid (
28
34
& mut ctx. accounts . price_feed . prices ,
29
35
price,
30
- PRICES_MAX_LEN ,
36
+ max_len ,
31
37
)
32
38
} else {
33
39
sorted_list_helper:: remove_from_sorted_list_by_eid (
Original file line number Diff line number Diff line change @@ -27,12 +27,18 @@ pub mod pricefeed {
27
27
) -> Result < ( ) > {
28
28
InitPriceFeed :: apply ( & mut ctx, & params)
29
29
}
30
+
31
+ pub fn extend_price_feed ( mut ctx : Context < ExtendPriceFeed > ) -> Result < ( ) > {
32
+ ExtendPriceFeed :: apply ( & mut ctx)
33
+ }
34
+
30
35
pub fn set_price_feed (
31
36
mut ctx : Context < SetPriceFeed > ,
32
37
params : SetPriceFeedParams ,
33
38
) -> Result < ( ) > {
34
39
SetPriceFeed :: apply ( & mut ctx, & params)
35
40
}
41
+
36
42
pub fn transfer_admin (
37
43
mut ctx : Context < TransferAdmin > ,
38
44
params : TransferAdminParams ,
Original file line number Diff line number Diff line change @@ -2,7 +2,8 @@ use crate::*;
2
2
use utils:: sorted_list_helper;
3
3
4
4
pub const UPDATERS_MAX_LEN : usize = 8 ;
5
- pub const PRICES_MAX_LEN : usize = 140 ;
5
+ pub const PRICES_DEFAULT_LEN : usize = 140 ;
6
+ pub const PRICES_MAX_LEN : usize = 340 ;
6
7
pub const EID_MODULUS : u32 = 30000 ;
7
8
8
9
#[ account]
@@ -14,7 +15,7 @@ pub struct PriceFeed {
14
15
pub price_ratio_denominator : u128 ,
15
16
pub arbitrum_compression_percent : u128 ,
16
17
pub native_token_price_usd : Option < u128 > ,
17
- #[ max_len( PRICES_MAX_LEN ) ]
18
+ #[ max_len( PRICES_DEFAULT_LEN ) ]
18
19
pub prices : Vec < Price > ,
19
20
pub bump : u8 ,
20
21
}
You can’t perform that action at this time.
0 commit comments