Skip to content

Commit 8842875

Browse files
authored
Sync DVN Program: Add extend_dvn_config instruction (#136)
* feat: add extend_dvn_config instruction and update set_config logic * feat: add ExtendPriceFeed instruction for price feed management * chore: format code * chore: sync price feed logic
1 parent 48976d1 commit 8842875

File tree

10 files changed

+84
-10
lines changed

10 files changed

+84
-10
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
pub mod close_execute;
2+
pub mod extend_dvn_config;
23
pub mod invoke;
34
pub mod set_config;
45
pub mod withdraw_fee;
56

67
pub use close_execute::*;
8+
pub use extend_dvn_config::*;
79
pub use invoke::*;
810
pub use set_config::*;
911
pub use withdraw_fee::*;

packages/layerzero-v2/solana/programs/programs/dvn/src/instructions/admin/set_config.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ pub struct SetConfig<'info> {
1515

1616
impl SetConfig<'_> {
1717
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)?;
1925
emit_cpi!(AdminConfigSetEvent { config: params.config.clone() });
2026
Ok(())
2127
}
@@ -36,7 +42,7 @@ pub enum AdminConfig {
3642
}
3743

3844
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<()> {
4046
match self {
4147
AdminConfig::Admins(admins) => {
4248
config.set_admins(admins.clone())?;
@@ -45,7 +51,7 @@ impl AdminConfig {
4551
config.default_multiplier_bps = *default_multiplier_bps;
4652
},
4753
AdminConfig::DstConfigs(dst_configs) => {
48-
config.set_dst_configs(dst_configs.clone())?;
54+
config.set_dst_configs(dst_configs_max_len, dst_configs.clone())?;
4955
},
5056
AdminConfig::PriceFeed(price_feed) => {
5157
config.price_feed = *price_feed;

packages/layerzero-v2/solana/programs/programs/dvn/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ pub mod dvn {
3232
SetConfig::apply(&mut ctx, &params)
3333
}
3434

35+
pub fn extend_dvn_config(mut ctx: Context<ExtendDVNConfig>) -> Result<()> {
36+
ExtendDVNConfig::apply(&mut ctx)
37+
}
38+
3539
pub fn invoke(mut ctx: Context<Invoke>, params: InvokeParams) -> Result<()> {
3640
Invoke::apply(&mut ctx, &params)
3741
}

packages/layerzero-v2/solana/programs/programs/dvn/src/state/dvn_config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub const VERIFY_BYTES: u64 = 320;
1919
pub const ADMINS_MAX_LEN: usize = 5;
2020
pub const SIGNERS_MAX_LEN: usize = 7;
2121
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;
2324

2425
#[account]
2526
#[derive(InitSpace)]
@@ -39,7 +40,7 @@ pub struct DvnConfig {
3940
pub admins: Vec<Pubkey>,
4041
// set by admins
4142
pub price_feed: Pubkey,
42-
#[max_len(DST_CONFIG_MAX_LEN)]
43+
#[max_len(DST_CONFIG_DEFAULT_LEN)]
4344
pub dst_configs: Vec<DstConfig>,
4445
pub default_multiplier_bps: u16,
4546
}
@@ -64,12 +65,12 @@ impl DvnConfig {
6465
Ok(())
6566
}
6667

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<()> {
6869
for config in &dst_configs {
6970
sorted_list_helper::insert_or_update_sorted_list_by_eid(
7071
&mut self.dst_configs,
7172
config.clone(),
72-
DST_CONFIG_MAX_LEN,
73+
max_len,
7374
)?;
7475
}
7576
Ok(())
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
pub mod extend_price_feed;
12
pub mod init_price_feed;
23
pub mod set_price_feed;
34
pub mod transfer_admin;
45

6+
pub use extend_price_feed::*;
57
pub use init_price_feed::*;
68
pub use set_price_feed::*;
79
pub use transfer_admin::*;

packages/layerzero-v2/solana/programs/programs/pricefeed/src/instructions/updater/set_price.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ impl SetPrice<'_> {
2424
gas_per_byte: price_params.gas_per_byte,
2525
model_type: price_params.model_type,
2626
};
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+
};
2733
sorted_list_helper::insert_or_update_sorted_list_by_eid(
2834
&mut ctx.accounts.price_feed.prices,
2935
price,
30-
PRICES_MAX_LEN,
36+
max_len,
3137
)
3238
} else {
3339
sorted_list_helper::remove_from_sorted_list_by_eid(

packages/layerzero-v2/solana/programs/programs/pricefeed/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ pub mod pricefeed {
2727
) -> Result<()> {
2828
InitPriceFeed::apply(&mut ctx, &params)
2929
}
30+
31+
pub fn extend_price_feed(mut ctx: Context<ExtendPriceFeed>) -> Result<()> {
32+
ExtendPriceFeed::apply(&mut ctx)
33+
}
34+
3035
pub fn set_price_feed(
3136
mut ctx: Context<SetPriceFeed>,
3237
params: SetPriceFeedParams,
3338
) -> Result<()> {
3439
SetPriceFeed::apply(&mut ctx, &params)
3540
}
41+
3642
pub fn transfer_admin(
3743
mut ctx: Context<TransferAdmin>,
3844
params: TransferAdminParams,

packages/layerzero-v2/solana/programs/programs/pricefeed/src/state/price.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::*;
22
use utils::sorted_list_helper;
33

44
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;
67
pub const EID_MODULUS: u32 = 30000;
78

89
#[account]
@@ -14,7 +15,7 @@ pub struct PriceFeed {
1415
pub price_ratio_denominator: u128,
1516
pub arbitrum_compression_percent: u128,
1617
pub native_token_price_usd: Option<u128>,
17-
#[max_len(PRICES_MAX_LEN)]
18+
#[max_len(PRICES_DEFAULT_LEN)]
1819
pub prices: Vec<Price>,
1920
pub bump: u8,
2021
}

0 commit comments

Comments
 (0)