Skip to content

Commit

Permalink
Merge pull request #8 from Kamino-Finance/release/0.16.0
Browse files Browse the repository at this point in the history
Release 0.16.0
  • Loading branch information
mihalex98 authored Sep 10, 2024
2 parents af03a9b + da0f890 commit 23da54c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
2 changes: 2 additions & 0 deletions programs/kfarms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ static_assertions = "1.1.0"
scope = { git = "https://github.com/Kamino-Finance/scope.git", package = "scope-types", branch = "anchor_0.29_idl" }
bytemuck = { version = "1.4.0", features = ["min_const_generics", "derive"] }
uint = "0.9.5"


10 changes: 8 additions & 2 deletions programs/kfarms/src/farm_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ pub fn update_farm_config(
farm_state.scope_prices = pubkey;
}
FarmConfigOption::ScopeOraclePriceId => {
let value: u16 = BorshDeserialize::try_from_slice(&data[..2])?;
let value: u64 = BorshDeserialize::try_from_slice(&data[..8])?;
xmsg!("farm_operations::update_farm_config scope_oracle_price_id={value}",);
xmsg!("prev value {:?}", farm_state.scope_oracle_price_id);
farm_state.scope_oracle_price_id = value.into();
farm_state.scope_oracle_price_id = value;
}
FarmConfigOption::ScopeOracleMaxAge => {
let value: u64 = BorshDeserialize::try_from_slice(data)?;
Expand All @@ -281,6 +281,12 @@ pub fn update_farm_config(
xmsg!("prev value {:?}", farm_state.strategy_id);
farm_state.strategy_id = pubkey;
}
FarmConfigOption::UpdateDelegatedRpsAdmin => {
let pubkey: Pubkey = BorshDeserialize::try_from_slice(data)?;
xmsg!("farm_operations::update_farm_config delegated_rps_admin={pubkey}",);
xmsg!("prev value {}", farm_state.delegated_rps_admin);
farm_state.delegated_rps_admin = pubkey;
}
};
Ok(())
}
Expand Down
6 changes: 6 additions & 0 deletions programs/kfarms/src/handlers/handler_update_farm_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub fn process(ctx: Context<UpdateFarmAdmin>) -> Result<()> {

let farm_state = &mut ctx.accounts.farm_state.load_mut()?;

msg!(
"Update farm admin prev={:?} new={:?}",
farm_state.farm_admin,
farm_state.pending_farm_admin
);

farm_state.farm_admin = farm_state.pending_farm_admin;

Ok(())
Expand Down
22 changes: 17 additions & 5 deletions programs/kfarms/src/handlers/handler_update_farm_config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::state::FarmConfigOption;
use crate::utils::constraints::check_remaining_accounts;
use crate::utils::scope::load_scope_price;
use crate::FarmError;
use crate::{farm_operations, FarmState};
use anchor_lang::prelude::*;

Expand All @@ -11,6 +12,20 @@ pub fn process(ctx: Context<UpdateFarmConfig>, mode: u16, data: &[u8]) -> Result
let scope_price = load_scope_price(&ctx.accounts.scope_prices, farm_state).map_or(None, |v| v);

let mode: FarmConfigOption = mode.try_into().unwrap();

if matches!(
mode,
FarmConfigOption::UpdateRewardRps | FarmConfigOption::UpdateRewardScheduleCurvePoints
) {
require!(
farm_state.delegated_rps_admin == *ctx.accounts.signer.key
|| farm_state.farm_admin == *ctx.accounts.signer.key,
FarmError::InvalidFarmConfigUpdateAuthority
);
} else {
require_keys_eq!(farm_state.farm_admin, *ctx.accounts.signer.key);
}

farm_operations::update_farm_config(farm_state, scope_price, mode, data)?;

Ok(())
Expand All @@ -19,12 +34,9 @@ pub fn process(ctx: Context<UpdateFarmConfig>, mode: u16, data: &[u8]) -> Result
#[derive(Accounts)]
pub struct UpdateFarmConfig<'info> {
#[account(mut)]
pub farm_admin: Signer<'info>,
pub signer: Signer<'info>,

#[account(
mut,
has_one = farm_admin,
)]
#[account(mut)]
pub farm_state: AccountLoader<'info, FarmState>,

pub scope_prices: Option<AccountLoader<'info, scope::OraclePrices>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ pub fn process(ctx: Context<UpdateGlobalConfigAdmin>) -> Result<()> {
check_remaining_accounts(&ctx)?;
let global_config = &mut ctx.accounts.global_config.load_mut()?;

msg!(
"Update global admin prev={:?} new={:?}",
global_config.global_admin,
global_config.pending_global_admin
);

global_config.global_admin = global_config.pending_global_admin;

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions programs/kfarms/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ pub enum FarmError {
RewardScheduleCurveSet,
#[msg("Cannot initialize farm while having a mint with token22 and requested extensions")]
UnsupportedTokenExtension,
#[msg("Invalid authority for updating farm config")]
InvalidFarmConfigUpdateAuthority,
}

impl From<DecimalError> for FarmError {
Expand Down
8 changes: 6 additions & 2 deletions programs/kfarms/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ pub struct FarmState {

pub pending_farm_admin: Pubkey,
pub strategy_id: Pubkey,
pub _padding: [u64; 86],

pub delegated_rps_admin: Pubkey,
pub _padding: [u64; 82],
}

impl FarmState {
Expand Down Expand Up @@ -231,8 +233,9 @@ impl Default for FarmState {

pending_farm_admin: Pubkey::default(),
strategy_id: Pubkey::default(),
delegated_rps_admin: Pubkey::default(),

_padding: [0; 86],
_padding: [0; 82],
}
}
}
Expand Down Expand Up @@ -572,6 +575,7 @@ pub enum FarmConfigOption {
UpdateRewardScheduleCurvePoints,
UpdatePendingFarmAdmin,
UpdateStrategyId,
UpdateDelegatedRpsAdmin,
}

#[derive(
Expand Down

0 comments on commit 23da54c

Please sign in to comment.