Program: add a tier string in banks (not used program side) (#988)
* Program: add a tier string in banks (not used program side) * ts part Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> --------- Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
69d866008c
commit
a7c101fe8f
|
@ -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",
|
||||
|
@ -10143,9 +10153,13 @@
|
|||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
119
|
||||
111
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "forceAlign",
|
||||
"type": "u64"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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],
|
||||
};
|
||||
|
||||
|
|
|
@ -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())?;
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ export class Bank implements BankForHealth {
|
|||
public platformLiquidationFee: I80F48;
|
||||
public collectedLiquidationFees: I80F48;
|
||||
public collectedCollateralFees: I80F48;
|
||||
public tier: string;
|
||||
|
||||
static from(
|
||||
publicKey: PublicKey,
|
||||
|
@ -151,6 +152,7 @@ export class Bank implements BankForHealth {
|
|||
collectedLiquidationFees: I80F48Dto;
|
||||
collectedCollateralFees: I80F48Dto;
|
||||
collateralFeePerDay: number;
|
||||
tier: number[];
|
||||
},
|
||||
): Bank {
|
||||
return new Bank(
|
||||
|
@ -218,6 +220,7 @@ export class Bank implements BankForHealth {
|
|||
obj.disableAssetLiquidation == 0,
|
||||
obj.collectedCollateralFees,
|
||||
obj.collateralFeePerDay,
|
||||
obj.tier,
|
||||
obj.forceWithdraw == 1,
|
||||
);
|
||||
}
|
||||
|
@ -287,6 +290,7 @@ export class Bank implements BankForHealth {
|
|||
public allowAssetLiquidation: boolean,
|
||||
collectedCollateralFees: I80F48Dto,
|
||||
public collateralFeePerDay: number,
|
||||
tier: number[],
|
||||
public forceWithdraw: boolean,
|
||||
) {
|
||||
this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0];
|
||||
|
@ -325,6 +329,7 @@ export class Bank implements BankForHealth {
|
|||
this._uiPrice = undefined;
|
||||
this._oracleLastUpdatedSlot = undefined;
|
||||
this._oracleProvider = undefined;
|
||||
this.tier = utf8.decode(new Uint8Array(tier)).split('\x00')[0];
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
|
|
|
@ -359,7 +359,7 @@ export class Group {
|
|||
Array.from(this.serum3MarketsMapByExternal.values()).map(
|
||||
(serum3Market) =>
|
||||
Market.load(
|
||||
client.program.provider.connection,
|
||||
client.program.provider.connection as any,
|
||||
serum3Market.serumMarketExternal,
|
||||
{ commitment: client.program.provider.connection.commitment },
|
||||
OPENBOOK_PROGRAM_ID[client.cluster],
|
||||
|
|
|
@ -133,7 +133,7 @@ export class Serum3Market {
|
|||
this.serumMarketExternal,
|
||||
);
|
||||
return await serum3MarketExternal.loadBids(
|
||||
client.program.provider.connection,
|
||||
client.program.provider.connection as any,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ export class Serum3Market {
|
|||
this.serumMarketExternal,
|
||||
);
|
||||
return await serum3MarketExternal.loadAsks(
|
||||
client.program.provider.connection,
|
||||
client.program.provider.connection as any,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -520,6 +520,7 @@ export class MangoClient {
|
|||
params.platformLiquidationFee,
|
||||
params.disableAssetLiquidation,
|
||||
params.collateralFeePerDay,
|
||||
params.tier,
|
||||
)
|
||||
.accounts({
|
||||
group: group.publicKey,
|
||||
|
@ -610,6 +611,7 @@ export class MangoClient {
|
|||
params.disableAssetLiquidation,
|
||||
params.collateralFeePerDay,
|
||||
params.forceWithdraw,
|
||||
params.tier,
|
||||
)
|
||||
.accounts({
|
||||
group: group.publicKey,
|
||||
|
@ -1447,7 +1449,6 @@ export class MangoClient {
|
|||
|
||||
for (const pp of clonedMangoAccount.perpActive()) {
|
||||
const perpMarketIndex = pp.marketIndex;
|
||||
const perpMarket = group.getPerpMarketByMarketIndex(perpMarketIndex);
|
||||
const deactivatingPositionIx = await this.perpDeactivatePositionIx(
|
||||
group,
|
||||
clonedMangoAccount,
|
||||
|
|
|
@ -32,6 +32,7 @@ export interface TokenRegisterParams {
|
|||
platformLiquidationFee: number;
|
||||
disableAssetLiquidation: boolean;
|
||||
collateralFeePerDay: number;
|
||||
tier: string;
|
||||
}
|
||||
|
||||
export const DefaultTokenRegisterParams: TokenRegisterParams = {
|
||||
|
@ -74,6 +75,7 @@ export const DefaultTokenRegisterParams: TokenRegisterParams = {
|
|||
platformLiquidationFee: 0.0,
|
||||
disableAssetLiquidation: false,
|
||||
collateralFeePerDay: 0.0,
|
||||
tier: '',
|
||||
};
|
||||
|
||||
export interface TokenEditParams {
|
||||
|
@ -117,6 +119,7 @@ export interface TokenEditParams {
|
|||
platformLiquidationFee: number | null;
|
||||
disableAssetLiquidation: boolean | null;
|
||||
collateralFeePerDay: number | null;
|
||||
tier: string | null;
|
||||
forceWithdraw: boolean | null;
|
||||
}
|
||||
|
||||
|
@ -161,6 +164,7 @@ export const NullTokenEditParams: TokenEditParams = {
|
|||
platformLiquidationFee: null,
|
||||
disableAssetLiquidation: null,
|
||||
collateralFeePerDay: null,
|
||||
tier: null,
|
||||
forceWithdraw: null,
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue