Program: add a tier string in banks (not used program side)

(cherry picked from commit bd3ab0df99)
This commit is contained in:
Serge Farny 2024-08-08 16:40:53 +02:00
parent 7a3075b6f2
commit ae5e22fb7a
8 changed files with 58 additions and 8 deletions

View File

@ -725,6 +725,10 @@
{
"name": "collateralFeePerDay",
"type": "f32"
},
{
"name": "tier",
"type": "string"
}
]
},
@ -1153,6 +1157,12 @@
"type": {
"option": "bool"
}
},
{
"name": "tierOpt",
"type": {
"option": "string"
}
}
]
},
@ -7664,7 +7674,7 @@
"type": "u8"
},
{
"name": "padding",
"name": "tier",
"type": {
"array": [
"u8",

View File

@ -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()?;
@ -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);

View File

@ -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);
@ -106,7 +107,6 @@ pub fn token_register(
force_close: 0,
disable_asset_liquidation: u8::from(disable_asset_liquidation),
force_withdraw: 0,
padding: Default::default(),
fees_withdrawn: 0,
token_conditional_swap_taker_fee_rate,
token_conditional_swap_maker_fee_rate,
@ -126,6 +126,7 @@ pub fn token_register(
collected_liquidation_fees: I80F48::ZERO,
collected_collateral_fees: I80F48::ZERO,
collateral_fee_per_day,
tier: fill_from_str(&tier)?,
reserved: [0; 1900],
};

View File

@ -92,7 +92,6 @@ pub fn token_register_trustless(
force_close: 0,
disable_asset_liquidation: 1,
force_withdraw: 0,
padding: Default::default(),
fees_withdrawn: 0,
token_conditional_swap_taker_fee_rate: 0.0,
token_conditional_swap_maker_fee_rate: 0.0,
@ -111,6 +110,7 @@ pub fn token_register_trustless(
collected_liquidation_fees: I80F48::ZERO,
collected_collateral_fees: I80F48::ZERO,
collateral_fee_per_day: 0.0, // TODO
tier: fill_from_str("C")?,
reserved: [0; 1900],
};
let oracle_ref = &AccountInfoRef::borrow(ctx.accounts.oracle.as_ref())?;

View File

@ -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(
@ -202,6 +203,7 @@ pub mod mango_v4 {
platform_liquidation_fee,
disable_asset_liquidation,
collateral_fee_per_day,
tier,
)?;
Ok(())
}
@ -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(
@ -305,6 +308,7 @@ pub mod mango_v4 {
disable_asset_liquidation_opt,
collateral_fee_per_day_opt,
force_withdraw_opt,
tier_opt,
)?;
Ok(())
}

View File

@ -164,8 +164,8 @@ pub struct Bank {
pub force_withdraw: u8,
#[derivative(Debug = "ignore")]
pub padding: [u8; 4],
#[derivative(Debug(format_with = "util::format_zero_terminated_utf8_bytes"))]
pub tier: [u8; 4],
// Do separate bookkeping for how many tokens were withdrawn
// This ensures that collected_fees_native is strictly increasing for stats gathering purposes
@ -364,7 +364,7 @@ impl Bank {
force_close: existing_bank.force_close,
disable_asset_liquidation: existing_bank.disable_asset_liquidation,
force_withdraw: existing_bank.force_withdraw,
padding: [0; 4],
tier: existing_bank.tier,
token_conditional_swap_taker_fee_rate: existing_bank
.token_conditional_swap_taker_fee_rate,
token_conditional_swap_maker_fee_rate: existing_bank
@ -440,6 +440,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
}

View File

@ -1074,6 +1074,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(
@ -1324,6 +1325,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,
}
}

View File

@ -725,6 +725,10 @@ export type MangoV4 = {
{
"name": "collateralFeePerDay",
"type": "f32"
},
{
"name": "tier",
"type": "string"
}
]
},
@ -1153,6 +1157,12 @@ export type MangoV4 = {
"type": {
"option": "bool"
}
},
{
"name": "tierOpt",
"type": {
"option": "string"
}
}
]
},
@ -7664,7 +7674,7 @@ export type MangoV4 = {
"type": "u8"
},
{
"name": "padding",
"name": "tier",
"type": {
"array": [
"u8",
@ -15301,6 +15311,10 @@ export const IDL: MangoV4 = {
{
"name": "collateralFeePerDay",
"type": "f32"
},
{
"name": "tier",
"type": "string"
}
]
},
@ -15729,6 +15743,12 @@ export const IDL: MangoV4 = {
"type": {
"option": "bool"
}
},
{
"name": "tierOpt",
"type": {
"option": "string"
}
}
]
},
@ -22240,7 +22260,7 @@ export const IDL: MangoV4 = {
"type": "u8"
},
{
"name": "padding",
"name": "tier",
"type": {
"array": [
"u8",