Skip to content

Commit

Permalink
Program: add a tier string in banks (not used program side)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnyser committed Aug 8, 2024
1 parent f5b4bd9 commit d4cb42e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
7 changes: 7 additions & 0 deletions programs/mango-v4/src/instructions/token_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn token_edit(
disable_asset_liquidation_opt: Option<bool>,
collateral_fee_per_day: Option<f32>,
force_withdraw_opt: Option<bool>,
tier_opt: Option<String>,
) -> Result<()> {
let group = ctx.accounts.group.load()?;

Expand Down Expand Up @@ -323,6 +324,12 @@ pub fn token_edit(
require_group_admin = true;
};

if let Some(tier) = tier_opt.as_ref() {
msg!("Tier: old - {:?}, new - {:?}", bank.tier, tier);
bank.tier = fill_from_str(&tier)?;
require_group_admin = true;
};

if let Some(force_close) = force_close_opt {
if force_close {
require!(bank.reduce_only > 0, MangoError::SomeError);
Expand Down
3 changes: 2 additions & 1 deletion programs/mango-v4/src/instructions/token_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn token_register(
platform_liquidation_fee: f32,
disable_asset_liquidation: bool,
collateral_fee_per_day: f32,
tier: String,
) -> Result<()> {
require_neq!(token_index, TokenIndex::MAX);

Expand Down Expand Up @@ -127,7 +128,7 @@ pub fn token_register(
collected_liquidation_fees: I80F48::ZERO,
collected_collateral_fees: I80F48::ZERO,
collateral_fee_per_day,
padding2: [0; 4],
tier: fill_from_str(&tier)?,
reserved: [0; 1888],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn token_register_trustless(
collected_liquidation_fees: I80F48::ZERO,
collected_collateral_fees: I80F48::ZERO,
collateral_fee_per_day: 0.0, // TODO
padding2: [0; 4],
tier: fill_from_str("C")?,
reserved: [0; 1888],
};
let oracle_ref = &AccountInfoRef::borrow(ctx.accounts.oracle.as_ref())?;
Expand Down
4 changes: 4 additions & 0 deletions programs/mango-v4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub mod mango_v4 {
platform_liquidation_fee: f32,
disable_asset_liquidation: bool,
collateral_fee_per_day: f32,
tier: String,
) -> Result<()> {
#[cfg(feature = "enable-gpl")]
instructions::token_register(
Expand Down Expand Up @@ -202,6 +203,7 @@ pub mod mango_v4 {
platform_liquidation_fee,
disable_asset_liquidation,
collateral_fee_per_day,
tier,
)?;
Ok(())
}
Expand Down Expand Up @@ -260,6 +262,7 @@ pub mod mango_v4 {
disable_asset_liquidation_opt: Option<bool>,
collateral_fee_per_day_opt: Option<f32>,
force_withdraw_opt: Option<bool>,
tier_opt: Option<String>,
) -> Result<()> {
#[cfg(feature = "enable-gpl")]
instructions::token_edit(
Expand Down Expand Up @@ -305,6 +308,7 @@ pub mod mango_v4 {
disable_asset_liquidation_opt,
collateral_fee_per_day_opt,
force_withdraw_opt,
tier_opt,
)?;
Ok(())
}
Expand Down
12 changes: 9 additions & 3 deletions programs/mango-v4/src/state/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ pub struct Bank {
/// The daily collateral fees rate for fully utilized collateral.
pub collateral_fee_per_day: f32,

#[derivative(Debug = "ignore")]
pub padding2: [u8; 4],
#[derivative(Debug(format_with = "util::format_zero_terminated_utf8_bytes"))]
pub tier: [u8; 4],

/// Largest amount of tokens that might be added the bank based on
/// oenbook open order execution.
Expand Down Expand Up @@ -391,7 +391,7 @@ impl Bank {
zero_util_rate: existing_bank.zero_util_rate,
platform_liquidation_fee: existing_bank.platform_liquidation_fee,
collateral_fee_per_day: existing_bank.collateral_fee_per_day,
padding2: [0; 4],
tier: existing_bank.tier,
reserved: [0; 1888],
}
}
Expand Down Expand Up @@ -450,6 +450,12 @@ impl Bank {
.trim_matches(char::from(0))
}

pub fn tier(&self) -> &str {
std::str::from_utf8(&self.tier)
.unwrap()
.trim_matches(char::from(0))
}

pub fn are_deposits_reduce_only(&self) -> bool {
self.reduce_only == 1
}
Expand Down
2 changes: 2 additions & 0 deletions programs/mango-v4/tests/program_test/mango_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ impl ClientInstruction for TokenRegisterInstruction {
platform_liquidation_fee: self.platform_liquidation_fee,
disable_asset_liquidation: false,
collateral_fee_per_day: 0.0,
tier: "A".to_string(),
};

let bank = Pubkey::find_program_address(
Expand Down Expand Up @@ -1327,6 +1328,7 @@ pub fn token_edit_instruction_default() -> mango_v4::instruction::TokenEdit {
disable_asset_liquidation_opt: None,
collateral_fee_per_day_opt: None,
force_withdraw_opt: None,
tier_opt: None,
}
}

Expand Down

0 comments on commit d4cb42e

Please sign in to comment.