2022-07-05 10:31:47 -07:00
|
|
|
use anchor_lang::prelude::*;
|
|
|
|
|
|
|
|
use fixed::types::I80F48;
|
|
|
|
|
2022-11-24 02:55:22 -08:00
|
|
|
use crate::accounts_zerocopy::{AccountInfoRef, LoadMutZeroCopyRef};
|
2022-07-05 10:31:47 -07:00
|
|
|
|
2023-01-23 06:02:48 -08:00
|
|
|
use crate::error::MangoError;
|
2022-07-05 10:31:47 -07:00
|
|
|
use crate::state::*;
|
|
|
|
|
2023-02-14 23:42:07 -08:00
|
|
|
use crate::accounts_ix::*;
|
2023-11-17 11:08:25 -08:00
|
|
|
use crate::logs::{emit_stack, TokenMetaDataLogV2};
|
2023-03-03 01:05:12 -08:00
|
|
|
use crate::util::fill_from_str;
|
2022-10-07 12:12:55 -07:00
|
|
|
|
2022-07-05 10:31:47 -07:00
|
|
|
#[allow(unused_variables)]
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
pub fn token_edit(
|
|
|
|
ctx: Context<TokenEdit>,
|
|
|
|
oracle_opt: Option<Pubkey>,
|
2022-11-09 04:25:53 -08:00
|
|
|
oracle_config_opt: Option<OracleConfigParams>,
|
2022-08-07 05:16:23 -07:00
|
|
|
group_insurance_fund_opt: Option<bool>,
|
2022-07-05 10:31:47 -07:00
|
|
|
interest_rate_params_opt: Option<InterestRateParams>,
|
|
|
|
loan_fee_rate_opt: Option<f32>,
|
|
|
|
loan_origination_fee_rate_opt: Option<f32>,
|
|
|
|
maint_asset_weight_opt: Option<f32>,
|
|
|
|
init_asset_weight_opt: Option<f32>,
|
|
|
|
maint_liab_weight_opt: Option<f32>,
|
|
|
|
init_liab_weight_opt: Option<f32>,
|
|
|
|
liquidation_fee_opt: Option<f32>,
|
2022-11-24 02:55:22 -08:00
|
|
|
stable_price_delay_interval_seconds_opt: Option<u32>,
|
|
|
|
stable_price_delay_growth_limit_opt: Option<f32>,
|
|
|
|
stable_price_growth_limit_opt: Option<f32>,
|
2022-11-25 04:45:17 -08:00
|
|
|
min_vault_to_deposits_ratio_opt: Option<f64>,
|
2022-12-06 00:34:02 -08:00
|
|
|
net_borrow_limit_per_window_quote_opt: Option<i64>,
|
|
|
|
net_borrow_limit_window_size_ts_opt: Option<u64>,
|
|
|
|
borrow_weight_scale_start_quote_opt: Option<f64>,
|
|
|
|
deposit_weight_scale_start_quote_opt: Option<f64>,
|
2022-12-02 03:24:11 -08:00
|
|
|
reset_stable_price: bool,
|
|
|
|
reset_net_borrow_limit: bool,
|
2023-04-13 03:44:12 -07:00
|
|
|
reduce_only_opt: Option<u8>,
|
2023-03-03 01:05:12 -08:00
|
|
|
name_opt: Option<String>,
|
2023-04-13 03:44:12 -07:00
|
|
|
force_close_opt: Option<bool>,
|
2023-08-08 01:21:13 -07:00
|
|
|
token_conditional_swap_taker_fee_rate_opt: Option<f32>,
|
|
|
|
token_conditional_swap_maker_fee_rate_opt: Option<f32>,
|
2023-10-13 00:02:23 -07:00
|
|
|
flash_loan_swap_fee_rate_opt: Option<f32>,
|
2023-10-17 04:14:07 -07:00
|
|
|
interest_curve_scaling_opt: Option<f32>,
|
|
|
|
interest_target_utilization_opt: Option<f32>,
|
2023-11-14 05:52:04 -08:00
|
|
|
maint_weight_shift_start_opt: Option<u64>,
|
|
|
|
maint_weight_shift_end_opt: Option<u64>,
|
|
|
|
maint_weight_shift_asset_target_opt: Option<f32>,
|
|
|
|
maint_weight_shift_liab_target_opt: Option<f32>,
|
|
|
|
maint_weight_shift_abort: bool,
|
2023-11-21 11:40:18 -08:00
|
|
|
set_fallback_oracle: bool,
|
2022-07-05 10:31:47 -07:00
|
|
|
) -> Result<()> {
|
2023-01-23 06:02:48 -08:00
|
|
|
let group = ctx.accounts.group.load()?;
|
|
|
|
|
2022-07-14 03:06:17 -07:00
|
|
|
let mut mint_info = ctx.accounts.mint_info.load_mut()?;
|
|
|
|
mint_info.verify_banks_ais(ctx.remaining_accounts)?;
|
2022-07-05 10:31:47 -07:00
|
|
|
|
2023-01-23 06:02:48 -08:00
|
|
|
let mut require_group_admin = false;
|
2022-07-05 10:31:47 -07:00
|
|
|
for ai in ctx.remaining_accounts.iter() {
|
|
|
|
let mut bank = ai.load_mut::<Bank>()?;
|
|
|
|
|
2022-11-09 04:25:53 -08:00
|
|
|
if let Some(oracle_config) = oracle_config_opt.as_ref() {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Oracle config: old - conf_filter {:?}, max_staleness_slots {:?}, new - conf_filter {:?}, max_staleness_slots {:?}",
|
|
|
|
bank.oracle_config.conf_filter,
|
|
|
|
bank.oracle_config.max_staleness_slots,
|
|
|
|
oracle_config.conf_filter,
|
|
|
|
oracle_config.max_staleness_slots
|
|
|
|
);
|
2022-11-09 04:25:53 -08:00
|
|
|
bank.oracle_config = oracle_config.to_oracle_config();
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-07-05 10:31:47 -07:00
|
|
|
};
|
2022-11-24 02:55:22 -08:00
|
|
|
if let Some(oracle) = oracle_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!("Oracle: old - {:?}, new - {:?}", bank.oracle, oracle,);
|
2022-11-24 02:55:22 -08:00
|
|
|
bank.oracle = oracle;
|
|
|
|
mint_info.oracle = oracle;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-12-02 03:24:11 -08:00
|
|
|
}
|
2023-11-21 11:40:18 -08:00
|
|
|
if set_fallback_oracle {
|
2023-11-17 11:08:25 -08:00
|
|
|
msg!(
|
|
|
|
"Fallback oracle old {:?}, new {:?}",
|
|
|
|
bank.fallback_oracle,
|
2023-11-21 11:40:18 -08:00
|
|
|
ctx.accounts.fallback_oracle.key()
|
2023-11-17 11:08:25 -08:00
|
|
|
);
|
2023-11-21 11:40:18 -08:00
|
|
|
bank.fallback_oracle = ctx.accounts.fallback_oracle.key();
|
|
|
|
mint_info.fallback_oracle = ctx.accounts.fallback_oracle.key();
|
2023-11-17 11:08:25 -08:00
|
|
|
require_group_admin = true;
|
|
|
|
}
|
2022-12-02 03:24:11 -08:00
|
|
|
if reset_stable_price {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!("Stable price reset");
|
2022-12-02 03:24:11 -08:00
|
|
|
require_keys_eq!(bank.oracle, ctx.accounts.oracle.key());
|
2022-11-24 02:55:22 -08:00
|
|
|
let oracle_price =
|
|
|
|
bank.oracle_price(&AccountInfoRef::borrow(ctx.accounts.oracle.as_ref())?, None)?;
|
|
|
|
bank.stable_price_model.reset_to_price(
|
|
|
|
oracle_price.to_num(),
|
|
|
|
Clock::get()?.unix_timestamp.try_into().unwrap(),
|
|
|
|
);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-11-24 02:55:22 -08:00
|
|
|
}
|
2022-07-05 10:31:47 -07:00
|
|
|
|
2022-08-07 05:16:23 -07:00
|
|
|
if let Some(group_insurance_fund) = group_insurance_fund_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Group insurance fund: old - {:?}, new - {:?}",
|
|
|
|
mint_info.group_insurance_fund,
|
|
|
|
group_insurance_fund
|
|
|
|
);
|
2023-01-12 05:26:55 -08:00
|
|
|
mint_info.group_insurance_fund = u8::from(group_insurance_fund);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-08-07 05:16:23 -07:00
|
|
|
};
|
|
|
|
|
2022-07-05 10:31:47 -07:00
|
|
|
if let Some(ref interest_rate_params) = interest_rate_params_opt {
|
|
|
|
// TODO: add a require! verifying relation between the parameters
|
2023-02-14 23:42:07 -08:00
|
|
|
msg!("Interest rate params: old - adjustment_factor {:?}, util0 {:?}, rate0 {:?}, util1 {:?}, rate1 {:?}, max_rate {:?}, new - adjustment_factor {:?}, util0 {:?}, rate0 {:?}, util1 {:?}, rate1 {:?}, max_rate {:?}",
|
2023-01-25 00:02:27 -08:00
|
|
|
bank.adjustment_factor,
|
|
|
|
bank.util0,
|
|
|
|
bank.rate0,
|
|
|
|
bank.util1,
|
|
|
|
bank.rate1,
|
|
|
|
bank.max_rate,
|
|
|
|
interest_rate_params.adjustment_factor,
|
|
|
|
interest_rate_params.util0,
|
|
|
|
interest_rate_params.rate0,
|
|
|
|
interest_rate_params.util1,
|
|
|
|
interest_rate_params.rate1,
|
|
|
|
interest_rate_params.max_rate,
|
|
|
|
);
|
2022-07-11 08:08:32 -07:00
|
|
|
bank.adjustment_factor = I80F48::from_num(interest_rate_params.adjustment_factor);
|
2022-07-05 10:31:47 -07:00
|
|
|
bank.util0 = I80F48::from_num(interest_rate_params.util0);
|
|
|
|
bank.rate0 = I80F48::from_num(interest_rate_params.rate0);
|
|
|
|
bank.util1 = I80F48::from_num(interest_rate_params.util1);
|
|
|
|
bank.rate1 = I80F48::from_num(interest_rate_params.rate1);
|
|
|
|
bank.max_rate = I80F48::from_num(interest_rate_params.max_rate);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(loan_origination_fee_rate) = loan_origination_fee_rate_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Loan origination fee rate: old - {:?}, new - {:?}",
|
|
|
|
bank.loan_origination_fee_rate,
|
|
|
|
loan_origination_fee_rate
|
|
|
|
);
|
2022-07-05 10:31:47 -07:00
|
|
|
bank.loan_origination_fee_rate = I80F48::from_num(loan_origination_fee_rate);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
if let Some(loan_fee_rate) = loan_fee_rate_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Loan fee fee rate: old - {:?}, new - {:?}",
|
|
|
|
bank.loan_fee_rate,
|
|
|
|
loan_fee_rate
|
|
|
|
);
|
2022-07-05 10:31:47 -07:00
|
|
|
bank.loan_fee_rate = I80F48::from_num(loan_fee_rate);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(maint_asset_weight) = maint_asset_weight_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Maint asset weight: old - {:?}, new - {:?}",
|
|
|
|
bank.maint_asset_weight,
|
|
|
|
maint_asset_weight
|
|
|
|
);
|
2022-07-05 10:31:47 -07:00
|
|
|
bank.maint_asset_weight = I80F48::from_num(maint_asset_weight);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
if let Some(init_asset_weight) = init_asset_weight_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Init asset weight: old - {:?}, new - {:?}",
|
|
|
|
bank.init_asset_weight,
|
|
|
|
init_asset_weight
|
|
|
|
);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_gte!(
|
|
|
|
init_asset_weight,
|
|
|
|
0.0,
|
|
|
|
MangoError::InitAssetWeightCantBeNegative
|
|
|
|
);
|
|
|
|
|
2022-07-05 10:31:47 -07:00
|
|
|
bank.init_asset_weight = I80F48::from_num(init_asset_weight);
|
2023-02-28 02:49:07 -08:00
|
|
|
|
|
|
|
// The security admin is allowed to decrease the init collateral weight to zero,
|
|
|
|
// but all other changes need to go through the full group admin.
|
|
|
|
if init_asset_weight != 0.0 {
|
|
|
|
require_group_admin = true;
|
|
|
|
}
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
if let Some(maint_liab_weight) = maint_liab_weight_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Maint liab weight: old - {:?}, new - {:?}",
|
|
|
|
bank.maint_liab_weight,
|
|
|
|
maint_liab_weight
|
|
|
|
);
|
2022-07-05 10:31:47 -07:00
|
|
|
bank.maint_liab_weight = I80F48::from_num(maint_liab_weight);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
if let Some(init_liab_weight) = init_liab_weight_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Init liab weight: old - {:?}, new - {:?}",
|
|
|
|
bank.init_liab_weight,
|
|
|
|
init_liab_weight
|
|
|
|
);
|
2022-07-05 10:31:47 -07:00
|
|
|
bank.init_liab_weight = I80F48::from_num(init_liab_weight);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
if let Some(liquidation_fee) = liquidation_fee_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Liquidation fee: old - {:?}, new - {:?}",
|
|
|
|
bank.liquidation_fee,
|
|
|
|
liquidation_fee
|
|
|
|
);
|
2022-07-05 10:31:47 -07:00
|
|
|
bank.liquidation_fee = I80F48::from_num(liquidation_fee);
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
|
2022-11-24 02:55:22 -08:00
|
|
|
if let Some(stable_price_delay_interval_seconds) = stable_price_delay_interval_seconds_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Stable price delay interval seconds: old - {:?}, new - {:?}",
|
|
|
|
bank.stable_price_model.delay_interval_seconds,
|
|
|
|
stable_price_delay_interval_seconds
|
|
|
|
);
|
2022-11-24 02:55:22 -08:00
|
|
|
// Updating this makes the old delay values slightly inconsistent
|
|
|
|
bank.stable_price_model.delay_interval_seconds = stable_price_delay_interval_seconds;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-11-24 02:55:22 -08:00
|
|
|
}
|
|
|
|
if let Some(stable_price_delay_growth_limit) = stable_price_delay_growth_limit_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Stable price delay growth limit: old - {:?}, new - {:?}",
|
|
|
|
bank.stable_price_model.delay_growth_limit,
|
|
|
|
stable_price_delay_growth_limit
|
|
|
|
);
|
2022-11-24 02:55:22 -08:00
|
|
|
bank.stable_price_model.delay_growth_limit = stable_price_delay_growth_limit;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-11-24 02:55:22 -08:00
|
|
|
}
|
|
|
|
if let Some(stable_price_growth_limit) = stable_price_growth_limit_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Stable price growth limit: old - {:?}, new - {:?}",
|
|
|
|
bank.stable_price_model.stable_growth_limit,
|
|
|
|
stable_price_growth_limit
|
|
|
|
);
|
2022-11-24 02:55:22 -08:00
|
|
|
bank.stable_price_model.stable_growth_limit = stable_price_growth_limit;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-11-24 02:55:22 -08:00
|
|
|
}
|
|
|
|
|
2022-11-25 04:45:17 -08:00
|
|
|
if let Some(min_vault_to_deposits_ratio) = min_vault_to_deposits_ratio_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Min vault to deposits ratio: old - {:?}, new - {:?}",
|
|
|
|
bank.min_vault_to_deposits_ratio,
|
|
|
|
min_vault_to_deposits_ratio
|
|
|
|
);
|
2022-11-25 04:45:17 -08:00
|
|
|
bank.min_vault_to_deposits_ratio = min_vault_to_deposits_ratio;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-11-25 04:45:17 -08:00
|
|
|
}
|
2022-12-06 00:34:02 -08:00
|
|
|
if let Some(net_borrow_limit_per_window_quote) = net_borrow_limit_per_window_quote_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Net borrow limit per window quote: old - {:?}, new - {:?}",
|
|
|
|
bank.net_borrow_limit_per_window_quote,
|
|
|
|
net_borrow_limit_per_window_quote
|
|
|
|
);
|
2022-12-06 00:34:02 -08:00
|
|
|
bank.net_borrow_limit_per_window_quote = net_borrow_limit_per_window_quote;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-11-25 04:45:17 -08:00
|
|
|
}
|
2022-12-06 00:34:02 -08:00
|
|
|
if let Some(net_borrow_limit_window_size_ts) = net_borrow_limit_window_size_ts_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Net borrow limit window size ts: old - {:?}, new - {:?}",
|
|
|
|
bank.net_borrow_limit_window_size_ts,
|
|
|
|
net_borrow_limit_window_size_ts
|
|
|
|
);
|
2022-12-06 00:34:02 -08:00
|
|
|
bank.net_borrow_limit_window_size_ts = net_borrow_limit_window_size_ts;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-11-25 04:45:17 -08:00
|
|
|
}
|
2022-12-02 03:24:11 -08:00
|
|
|
if reset_net_borrow_limit {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!("Net borrow limit reset");
|
2022-12-02 03:24:11 -08:00
|
|
|
bank.net_borrows_in_window = 0;
|
|
|
|
bank.last_net_borrows_window_start_ts = 0;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-12-02 03:24:11 -08:00
|
|
|
}
|
2022-11-25 04:45:17 -08:00
|
|
|
|
2022-12-06 00:34:02 -08:00
|
|
|
if let Some(borrow_weight_scale_start_quote) = borrow_weight_scale_start_quote_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Borrow weight scale start quote: old - {:?}, new - {:?}",
|
|
|
|
bank.borrow_weight_scale_start_quote,
|
|
|
|
borrow_weight_scale_start_quote
|
|
|
|
);
|
2022-12-06 00:34:02 -08:00
|
|
|
bank.borrow_weight_scale_start_quote = borrow_weight_scale_start_quote;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-12-06 00:34:02 -08:00
|
|
|
}
|
|
|
|
if let Some(deposit_weight_scale_start_quote) = deposit_weight_scale_start_quote_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Deposit weight scale start quote: old - {:?}, new - {:?}",
|
|
|
|
bank.deposit_weight_scale_start_quote,
|
|
|
|
deposit_weight_scale_start_quote
|
|
|
|
);
|
2022-12-06 00:34:02 -08:00
|
|
|
bank.deposit_weight_scale_start_quote = deposit_weight_scale_start_quote;
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
2022-12-06 00:34:02 -08:00
|
|
|
}
|
|
|
|
|
2023-01-04 00:24:40 -08:00
|
|
|
if let Some(reduce_only) = reduce_only_opt {
|
2023-01-25 00:02:27 -08:00
|
|
|
msg!(
|
|
|
|
"Reduce only: old - {:?}, new - {:?}",
|
|
|
|
bank.reduce_only,
|
2023-04-13 03:44:12 -07:00
|
|
|
reduce_only
|
2023-01-25 00:02:27 -08:00
|
|
|
);
|
2023-01-23 06:02:48 -08:00
|
|
|
|
2023-04-13 03:44:12 -07:00
|
|
|
// security admin can only make it stricter
|
|
|
|
// anything that makes it less strict, should require admin
|
|
|
|
if reduce_only == 0 || (reduce_only == 2 && bank.reduce_only == 1) {
|
2023-01-23 06:02:48 -08:00
|
|
|
require_group_admin = true;
|
|
|
|
}
|
2023-04-13 03:44:12 -07:00
|
|
|
bank.reduce_only = reduce_only;
|
2023-01-04 00:24:40 -08:00
|
|
|
};
|
2023-03-03 01:05:12 -08:00
|
|
|
|
|
|
|
if let Some(name) = name_opt.as_ref() {
|
|
|
|
msg!("Name: old - {:?}, new - {:?}", bank.name, name);
|
|
|
|
bank.name = fill_from_str(&name)?;
|
|
|
|
require_group_admin = true;
|
|
|
|
};
|
2023-04-13 03:44:12 -07:00
|
|
|
|
|
|
|
if let Some(force_close) = force_close_opt {
|
|
|
|
if force_close {
|
|
|
|
require!(bank.reduce_only > 0, MangoError::SomeError);
|
|
|
|
}
|
|
|
|
msg!(
|
|
|
|
"Force close: old - {:?}, new - {:?}",
|
|
|
|
bank.force_close,
|
|
|
|
u8::from(force_close)
|
|
|
|
);
|
|
|
|
bank.force_close = u8::from(force_close);
|
|
|
|
require_group_admin = true;
|
|
|
|
};
|
2023-08-08 01:21:13 -07:00
|
|
|
|
2023-08-29 01:03:07 -07:00
|
|
|
if let Some(fee_rate) = token_conditional_swap_taker_fee_rate_opt {
|
2023-08-08 01:21:13 -07:00
|
|
|
msg!(
|
|
|
|
"Token conditional swap taker fee fraction old {:?}, new {:?}",
|
|
|
|
bank.token_conditional_swap_taker_fee_rate,
|
2023-08-29 01:03:07 -07:00
|
|
|
fee_rate
|
2023-08-08 01:21:13 -07:00
|
|
|
);
|
2023-08-29 01:03:07 -07:00
|
|
|
require_gte!(fee_rate, 0.0); // values <0 are not currently supported
|
|
|
|
bank.token_conditional_swap_taker_fee_rate = fee_rate;
|
2023-08-08 01:21:13 -07:00
|
|
|
require_group_admin = true;
|
|
|
|
}
|
2023-08-29 01:03:07 -07:00
|
|
|
if let Some(fee_rate) = token_conditional_swap_maker_fee_rate_opt {
|
2023-08-08 01:21:13 -07:00
|
|
|
msg!(
|
|
|
|
"Token conditional swap maker fee fraction old {:?}, new {:?}",
|
|
|
|
bank.token_conditional_swap_maker_fee_rate,
|
2023-08-29 01:03:07 -07:00
|
|
|
fee_rate
|
2023-08-08 01:21:13 -07:00
|
|
|
);
|
2023-08-29 01:03:07 -07:00
|
|
|
require_gte!(fee_rate, 0.0); // values <0 are not currently supported
|
|
|
|
bank.token_conditional_swap_maker_fee_rate = fee_rate;
|
2023-08-08 01:21:13 -07:00
|
|
|
require_group_admin = true;
|
|
|
|
}
|
2023-08-09 04:27:25 -07:00
|
|
|
|
2023-10-13 00:02:23 -07:00
|
|
|
if let Some(fee_rate) = flash_loan_swap_fee_rate_opt {
|
2023-08-09 04:27:25 -07:00
|
|
|
msg!(
|
|
|
|
"Flash loan swap fee fraction old {:?}, new {:?}",
|
2023-10-13 00:02:23 -07:00
|
|
|
bank.flash_loan_swap_fee_rate,
|
2023-08-29 01:03:07 -07:00
|
|
|
fee_rate
|
2023-08-09 04:27:25 -07:00
|
|
|
);
|
2023-08-29 01:03:07 -07:00
|
|
|
require_gte!(fee_rate, 0.0); // values <0 are not currently supported
|
2023-10-13 00:02:23 -07:00
|
|
|
bank.flash_loan_swap_fee_rate = fee_rate;
|
2023-08-09 04:27:25 -07:00
|
|
|
require_group_admin = true;
|
|
|
|
}
|
2023-10-17 04:14:07 -07:00
|
|
|
|
|
|
|
if let Some(interest_curve_scaling) = interest_curve_scaling_opt {
|
|
|
|
msg!(
|
|
|
|
"Interest curve scaling old {:?}, new {:?}",
|
|
|
|
bank.interest_curve_scaling,
|
|
|
|
interest_curve_scaling
|
|
|
|
);
|
|
|
|
require_gte!(interest_curve_scaling, 1.0);
|
|
|
|
bank.interest_curve_scaling = interest_curve_scaling.into();
|
|
|
|
require_group_admin = true;
|
|
|
|
}
|
|
|
|
if let Some(interest_target_utilization) = interest_target_utilization_opt {
|
|
|
|
msg!(
|
|
|
|
"Interest target utilization old {:?}, new {:?}",
|
|
|
|
bank.interest_target_utilization,
|
|
|
|
interest_target_utilization
|
|
|
|
);
|
|
|
|
require_gte!(interest_target_utilization, 0.0);
|
|
|
|
bank.interest_target_utilization = interest_target_utilization;
|
|
|
|
require_group_admin = true;
|
|
|
|
}
|
2023-11-14 05:52:04 -08:00
|
|
|
|
|
|
|
if maint_weight_shift_abort {
|
|
|
|
let now_ts: u64 = Clock::get()?.unix_timestamp.try_into().unwrap();
|
|
|
|
let (maint_asset_weight, maint_liab_weight) = bank.maint_weights(now_ts);
|
|
|
|
bank.maint_asset_weight = maint_asset_weight;
|
|
|
|
bank.maint_liab_weight = maint_liab_weight;
|
|
|
|
bank.maint_weight_shift_start = 0;
|
|
|
|
bank.maint_weight_shift_end = 0;
|
|
|
|
bank.maint_weight_shift_duration_inv = I80F48::ZERO;
|
|
|
|
bank.maint_weight_shift_asset_target = I80F48::ZERO;
|
|
|
|
bank.maint_weight_shift_liab_target = I80F48::ZERO;
|
|
|
|
msg!(
|
|
|
|
"Maint weight shift aborted, current maint weights asset {} liab {}",
|
|
|
|
maint_asset_weight,
|
|
|
|
maint_liab_weight,
|
|
|
|
);
|
|
|
|
// Allow execution by group admin or security admin
|
|
|
|
}
|
|
|
|
if let Some(maint_weight_shift_start) = maint_weight_shift_start_opt {
|
|
|
|
msg!(
|
|
|
|
"Maint weight shift start old {:?}, new {:?}",
|
|
|
|
bank.maint_weight_shift_start,
|
|
|
|
maint_weight_shift_start
|
|
|
|
);
|
|
|
|
bank.maint_weight_shift_start = maint_weight_shift_start;
|
|
|
|
require_group_admin = true;
|
|
|
|
}
|
|
|
|
if let Some(maint_weight_shift_end) = maint_weight_shift_end_opt {
|
|
|
|
msg!(
|
|
|
|
"Maint weight shift end old {:?}, new {:?}",
|
|
|
|
bank.maint_weight_shift_end,
|
|
|
|
maint_weight_shift_end
|
|
|
|
);
|
|
|
|
bank.maint_weight_shift_end = maint_weight_shift_end;
|
|
|
|
require_group_admin = true;
|
|
|
|
}
|
|
|
|
if let Some(maint_weight_shift_asset_target) = maint_weight_shift_asset_target_opt {
|
|
|
|
msg!(
|
|
|
|
"Maint weight shift asset target old {:?}, new {:?}",
|
|
|
|
bank.maint_weight_shift_asset_target,
|
|
|
|
maint_weight_shift_asset_target
|
|
|
|
);
|
|
|
|
bank.maint_weight_shift_asset_target =
|
|
|
|
I80F48::from_num(maint_weight_shift_asset_target);
|
|
|
|
require_group_admin = true;
|
|
|
|
}
|
|
|
|
if let Some(maint_weight_shift_liab_target) = maint_weight_shift_liab_target_opt {
|
|
|
|
msg!(
|
|
|
|
"Maint weight shift liab target old {:?}, new {:?}",
|
|
|
|
bank.maint_weight_shift_liab_target,
|
|
|
|
maint_weight_shift_liab_target
|
|
|
|
);
|
|
|
|
bank.maint_weight_shift_liab_target = I80F48::from_num(maint_weight_shift_liab_target);
|
|
|
|
require_group_admin = true;
|
|
|
|
}
|
|
|
|
if maint_weight_shift_start_opt.is_some() || maint_weight_shift_end_opt.is_some() {
|
|
|
|
let was_enabled = bank.maint_weight_shift_duration_inv.is_positive();
|
|
|
|
if bank.maint_weight_shift_end <= bank.maint_weight_shift_start {
|
|
|
|
bank.maint_weight_shift_duration_inv = I80F48::ZERO;
|
|
|
|
} else {
|
|
|
|
bank.maint_weight_shift_duration_inv = I80F48::ONE
|
|
|
|
/ I80F48::from(bank.maint_weight_shift_end - bank.maint_weight_shift_start);
|
|
|
|
}
|
|
|
|
msg!(
|
|
|
|
"Maint weight shift enabled old {}, new {}",
|
|
|
|
was_enabled,
|
|
|
|
bank.maint_weight_shift_duration_inv.is_positive(),
|
|
|
|
);
|
|
|
|
}
|
2023-01-23 06:02:48 -08:00
|
|
|
}
|
2023-01-04 00:24:40 -08:00
|
|
|
|
2023-01-23 06:02:48 -08:00
|
|
|
// account constraint #1
|
|
|
|
if require_group_admin {
|
|
|
|
require!(
|
|
|
|
group.admin == ctx.accounts.admin.key(),
|
|
|
|
MangoError::SomeError
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
require!(
|
|
|
|
group.admin == ctx.accounts.admin.key()
|
|
|
|
|| group.security_admin == ctx.accounts.admin.key(),
|
|
|
|
MangoError::SomeError
|
|
|
|
);
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
|
2022-10-07 12:12:55 -07:00
|
|
|
// Assumes that there is at least one bank
|
|
|
|
let bank = ctx.remaining_accounts.first().unwrap().load_mut::<Bank>()?;
|
2023-08-09 04:55:53 -07:00
|
|
|
bank.verify()?;
|
2022-10-07 12:12:55 -07:00
|
|
|
|
2023-11-17 11:08:25 -08:00
|
|
|
emit_stack!(TokenMetaDataLogV2 {
|
2022-10-07 12:12:55 -07:00
|
|
|
mango_group: ctx.accounts.group.key(),
|
|
|
|
mint: mint_info.mint.key(),
|
|
|
|
token_index: bank.token_index,
|
|
|
|
mint_decimals: bank.mint_decimals,
|
|
|
|
oracle: mint_info.oracle.key(),
|
2023-11-17 11:08:25 -08:00
|
|
|
fallback_oracle: ctx.accounts.fallback_oracle.key(),
|
2022-10-07 12:12:55 -07:00
|
|
|
mint_info: ctx.accounts.mint_info.key(),
|
|
|
|
});
|
|
|
|
|
2022-07-05 10:31:47 -07:00
|
|
|
Ok(())
|
|
|
|
}
|