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:
Serge Farny 2024-08-09 13:55:56 +02:00 committed by GitHub
parent 69d866008c
commit a7c101fe8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 14936 additions and 15547 deletions

View File

@ -725,6 +725,10 @@
{ {
"name": "collateralFeePerDay", "name": "collateralFeePerDay",
"type": "f32" "type": "f32"
},
{
"name": "tier",
"type": "string"
} }
] ]
}, },
@ -1153,6 +1157,12 @@
"type": { "type": {
"option": "bool" "option": "bool"
} }
},
{
"name": "tierOpt",
"type": {
"option": "string"
}
} }
] ]
}, },
@ -7664,7 +7674,7 @@
"type": "u8" "type": "u8"
}, },
{ {
"name": "padding", "name": "tier",
"type": { "type": {
"array": [ "array": [
"u8", "u8",
@ -10143,9 +10153,13 @@
"type": { "type": {
"array": [ "array": [
"u8", "u8",
119 111
] ]
} }
},
{
"name": "forceAlign",
"type": "u64"
} }
] ]
} }

View File

@ -56,6 +56,7 @@ pub fn token_edit(
disable_asset_liquidation_opt: Option<bool>, disable_asset_liquidation_opt: Option<bool>,
collateral_fee_per_day: Option<f32>, collateral_fee_per_day: Option<f32>,
force_withdraw_opt: Option<bool>, force_withdraw_opt: Option<bool>,
tier_opt: Option<String>,
) -> Result<()> { ) -> Result<()> {
let group = ctx.accounts.group.load()?; let group = ctx.accounts.group.load()?;
@ -323,6 +324,12 @@ pub fn token_edit(
require_group_admin = true; 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 let Some(force_close) = force_close_opt {
if force_close { if force_close {
require!(bank.reduce_only > 0, MangoError::SomeError); require!(bank.reduce_only > 0, MangoError::SomeError);

View File

@ -46,6 +46,7 @@ pub fn token_register(
platform_liquidation_fee: f32, platform_liquidation_fee: f32,
disable_asset_liquidation: bool, disable_asset_liquidation: bool,
collateral_fee_per_day: f32, collateral_fee_per_day: f32,
tier: String,
) -> Result<()> { ) -> Result<()> {
require_neq!(token_index, TokenIndex::MAX); require_neq!(token_index, TokenIndex::MAX);
@ -106,7 +107,6 @@ pub fn token_register(
force_close: 0, force_close: 0,
disable_asset_liquidation: u8::from(disable_asset_liquidation), disable_asset_liquidation: u8::from(disable_asset_liquidation),
force_withdraw: 0, force_withdraw: 0,
padding: Default::default(),
fees_withdrawn: 0, fees_withdrawn: 0,
token_conditional_swap_taker_fee_rate, token_conditional_swap_taker_fee_rate,
token_conditional_swap_maker_fee_rate, token_conditional_swap_maker_fee_rate,
@ -126,6 +126,7 @@ pub fn token_register(
collected_liquidation_fees: I80F48::ZERO, collected_liquidation_fees: I80F48::ZERO,
collected_collateral_fees: I80F48::ZERO, collected_collateral_fees: I80F48::ZERO,
collateral_fee_per_day, collateral_fee_per_day,
tier: fill_from_str(&tier)?,
reserved: [0; 1900], reserved: [0; 1900],
}; };

View File

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

View File

@ -167,6 +167,7 @@ pub mod mango_v4 {
platform_liquidation_fee: f32, platform_liquidation_fee: f32,
disable_asset_liquidation: bool, disable_asset_liquidation: bool,
collateral_fee_per_day: f32, collateral_fee_per_day: f32,
tier: String,
) -> Result<()> { ) -> Result<()> {
#[cfg(feature = "enable-gpl")] #[cfg(feature = "enable-gpl")]
instructions::token_register( instructions::token_register(
@ -202,6 +203,7 @@ pub mod mango_v4 {
platform_liquidation_fee, platform_liquidation_fee,
disable_asset_liquidation, disable_asset_liquidation,
collateral_fee_per_day, collateral_fee_per_day,
tier,
)?; )?;
Ok(()) Ok(())
} }
@ -260,6 +262,7 @@ pub mod mango_v4 {
disable_asset_liquidation_opt: Option<bool>, disable_asset_liquidation_opt: Option<bool>,
collateral_fee_per_day_opt: Option<f32>, collateral_fee_per_day_opt: Option<f32>,
force_withdraw_opt: Option<bool>, force_withdraw_opt: Option<bool>,
tier_opt: Option<String>,
) -> Result<()> { ) -> Result<()> {
#[cfg(feature = "enable-gpl")] #[cfg(feature = "enable-gpl")]
instructions::token_edit( instructions::token_edit(
@ -305,6 +308,7 @@ pub mod mango_v4 {
disable_asset_liquidation_opt, disable_asset_liquidation_opt,
collateral_fee_per_day_opt, collateral_fee_per_day_opt,
force_withdraw_opt, force_withdraw_opt,
tier_opt,
)?; )?;
Ok(()) Ok(())
} }

View File

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

View File

@ -1074,6 +1074,7 @@ impl ClientInstruction for TokenRegisterInstruction {
platform_liquidation_fee: self.platform_liquidation_fee, platform_liquidation_fee: self.platform_liquidation_fee,
disable_asset_liquidation: false, disable_asset_liquidation: false,
collateral_fee_per_day: 0.0, collateral_fee_per_day: 0.0,
tier: "A".to_string(),
}; };
let bank = Pubkey::find_program_address( 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, disable_asset_liquidation_opt: None,
collateral_fee_per_day_opt: None, collateral_fee_per_day_opt: None,
force_withdraw_opt: None, force_withdraw_opt: None,
tier_opt: None,
} }
} }

View File

@ -83,6 +83,7 @@ export class Bank implements BankForHealth {
public platformLiquidationFee: I80F48; public platformLiquidationFee: I80F48;
public collectedLiquidationFees: I80F48; public collectedLiquidationFees: I80F48;
public collectedCollateralFees: I80F48; public collectedCollateralFees: I80F48;
public tier: string;
static from( static from(
publicKey: PublicKey, publicKey: PublicKey,
@ -151,6 +152,7 @@ export class Bank implements BankForHealth {
collectedLiquidationFees: I80F48Dto; collectedLiquidationFees: I80F48Dto;
collectedCollateralFees: I80F48Dto; collectedCollateralFees: I80F48Dto;
collateralFeePerDay: number; collateralFeePerDay: number;
tier: number[];
}, },
): Bank { ): Bank {
return new Bank( return new Bank(
@ -218,6 +220,7 @@ export class Bank implements BankForHealth {
obj.disableAssetLiquidation == 0, obj.disableAssetLiquidation == 0,
obj.collectedCollateralFees, obj.collectedCollateralFees,
obj.collateralFeePerDay, obj.collateralFeePerDay,
obj.tier,
obj.forceWithdraw == 1, obj.forceWithdraw == 1,
); );
} }
@ -287,6 +290,7 @@ export class Bank implements BankForHealth {
public allowAssetLiquidation: boolean, public allowAssetLiquidation: boolean,
collectedCollateralFees: I80F48Dto, collectedCollateralFees: I80F48Dto,
public collateralFeePerDay: number, public collateralFeePerDay: number,
tier: number[],
public forceWithdraw: boolean, public forceWithdraw: boolean,
) { ) {
this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0]; this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0];
@ -325,6 +329,7 @@ export class Bank implements BankForHealth {
this._uiPrice = undefined; this._uiPrice = undefined;
this._oracleLastUpdatedSlot = undefined; this._oracleLastUpdatedSlot = undefined;
this._oracleProvider = undefined; this._oracleProvider = undefined;
this.tier = utf8.decode(new Uint8Array(tier)).split('\x00')[0];
} }
toString(): string { toString(): string {

View File

@ -359,7 +359,7 @@ export class Group {
Array.from(this.serum3MarketsMapByExternal.values()).map( Array.from(this.serum3MarketsMapByExternal.values()).map(
(serum3Market) => (serum3Market) =>
Market.load( Market.load(
client.program.provider.connection, client.program.provider.connection as any,
serum3Market.serumMarketExternal, serum3Market.serumMarketExternal,
{ commitment: client.program.provider.connection.commitment }, { commitment: client.program.provider.connection.commitment },
OPENBOOK_PROGRAM_ID[client.cluster], OPENBOOK_PROGRAM_ID[client.cluster],

View File

@ -133,7 +133,7 @@ export class Serum3Market {
this.serumMarketExternal, this.serumMarketExternal,
); );
return await serum3MarketExternal.loadBids( return await serum3MarketExternal.loadBids(
client.program.provider.connection, client.program.provider.connection as any,
); );
} }
@ -142,7 +142,7 @@ export class Serum3Market {
this.serumMarketExternal, this.serumMarketExternal,
); );
return await serum3MarketExternal.loadAsks( return await serum3MarketExternal.loadAsks(
client.program.provider.connection, client.program.provider.connection as any,
); );
} }

View File

@ -520,6 +520,7 @@ export class MangoClient {
params.platformLiquidationFee, params.platformLiquidationFee,
params.disableAssetLiquidation, params.disableAssetLiquidation,
params.collateralFeePerDay, params.collateralFeePerDay,
params.tier,
) )
.accounts({ .accounts({
group: group.publicKey, group: group.publicKey,
@ -610,6 +611,7 @@ export class MangoClient {
params.disableAssetLiquidation, params.disableAssetLiquidation,
params.collateralFeePerDay, params.collateralFeePerDay,
params.forceWithdraw, params.forceWithdraw,
params.tier,
) )
.accounts({ .accounts({
group: group.publicKey, group: group.publicKey,
@ -1447,7 +1449,6 @@ export class MangoClient {
for (const pp of clonedMangoAccount.perpActive()) { for (const pp of clonedMangoAccount.perpActive()) {
const perpMarketIndex = pp.marketIndex; const perpMarketIndex = pp.marketIndex;
const perpMarket = group.getPerpMarketByMarketIndex(perpMarketIndex);
const deactivatingPositionIx = await this.perpDeactivatePositionIx( const deactivatingPositionIx = await this.perpDeactivatePositionIx(
group, group,
clonedMangoAccount, clonedMangoAccount,

View File

@ -32,6 +32,7 @@ export interface TokenRegisterParams {
platformLiquidationFee: number; platformLiquidationFee: number;
disableAssetLiquidation: boolean; disableAssetLiquidation: boolean;
collateralFeePerDay: number; collateralFeePerDay: number;
tier: string;
} }
export const DefaultTokenRegisterParams: TokenRegisterParams = { export const DefaultTokenRegisterParams: TokenRegisterParams = {
@ -74,6 +75,7 @@ export const DefaultTokenRegisterParams: TokenRegisterParams = {
platformLiquidationFee: 0.0, platformLiquidationFee: 0.0,
disableAssetLiquidation: false, disableAssetLiquidation: false,
collateralFeePerDay: 0.0, collateralFeePerDay: 0.0,
tier: '',
}; };
export interface TokenEditParams { export interface TokenEditParams {
@ -117,6 +119,7 @@ export interface TokenEditParams {
platformLiquidationFee: number | null; platformLiquidationFee: number | null;
disableAssetLiquidation: boolean | null; disableAssetLiquidation: boolean | null;
collateralFeePerDay: number | null; collateralFeePerDay: number | null;
tier: string | null;
forceWithdraw: boolean | null; forceWithdraw: boolean | null;
} }
@ -161,6 +164,7 @@ export const NullTokenEditParams: TokenEditParams = {
platformLiquidationFee: null, platformLiquidationFee: null,
disableAssetLiquidation: null, disableAssetLiquidation: null,
collateralFeePerDay: null, collateralFeePerDay: null,
tier: null,
forceWithdraw: null, forceWithdraw: null,
}; };

File diff suppressed because it is too large Load Diff