Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serge/bank token tier #992

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions mango_v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,10 @@
{
"name": "collateralFeePerDay",
"type": "f32"
},
{
"name": "tier",
"type": "string"
}
]
},
Expand Down Expand Up @@ -1153,6 +1157,12 @@
"type": {
"option": "bool"
}
},
{
"name": "tierOpt",
"type": {
"option": "string"
}
}
]
},
Expand Down Expand Up @@ -7664,7 +7674,7 @@
"type": "u8"
},
{
"name": "padding",
"name": "tier",
"type": {
"array": [
"u8",
Expand Down Expand Up @@ -10143,9 +10153,13 @@
"type": {
"array": [
"u8",
119
111
]
}
},
{
"name": "forceAlign",
"type": "u64"
}
]
}
Expand Down
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 @@ -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,
Expand All @@ -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],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())?;
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 @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
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 @@ -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(
Expand Down Expand Up @@ -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,
}
}

Expand Down
5 changes: 5 additions & 0 deletions ts/client/src/accounts/bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -151,6 +152,7 @@ export class Bank implements BankForHealth {
collectedLiquidationFees: I80F48Dto;
collectedCollateralFees: I80F48Dto;
collateralFeePerDay: number;
tier: number[];
},
): Bank {
return new Bank(
Expand Down Expand Up @@ -218,6 +220,7 @@ export class Bank implements BankForHealth {
obj.disableAssetLiquidation == 0,
obj.collectedCollateralFees,
obj.collateralFeePerDay,
obj.tier,
obj.forceWithdraw == 1,
);
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ts/client/src/accounts/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably masking an underlying version incompatibility issue, would it be possible to just update or override the dependency?

serum3Market.serumMarketExternal,
{ commitment: client.program.provider.connection.commitment },
OPENBOOK_PROGRAM_ID[client.cluster],
Expand Down
4 changes: 2 additions & 2 deletions ts/client/src/accounts/serum3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class Serum3Market {
this.serumMarketExternal,
);
return await serum3MarketExternal.loadBids(
client.program.provider.connection,
client.program.provider.connection as any,
);
}

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

Expand Down
3 changes: 2 additions & 1 deletion ts/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ export class MangoClient {
params.platformLiquidationFee,
params.disableAssetLiquidation,
params.collateralFeePerDay,
params.tier,
)
.accounts({
group: group.publicKey,
Expand Down Expand Up @@ -610,6 +611,7 @@ export class MangoClient {
params.disableAssetLiquidation,
params.collateralFeePerDay,
params.forceWithdraw,
params.tier,
)
.accounts({
group: group.publicKey,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions ts/client/src/clientIxParamBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface TokenRegisterParams {
platformLiquidationFee: number;
disableAssetLiquidation: boolean;
collateralFeePerDay: number;
tier: string;
}

export const DefaultTokenRegisterParams: TokenRegisterParams = {
Expand Down Expand Up @@ -74,6 +75,7 @@ export const DefaultTokenRegisterParams: TokenRegisterParams = {
platformLiquidationFee: 0.0,
disableAssetLiquidation: false,
collateralFeePerDay: 0.0,
tier: '',
};

export interface TokenEditParams {
Expand Down Expand Up @@ -117,6 +119,7 @@ export interface TokenEditParams {
platformLiquidationFee: number | null;
disableAssetLiquidation: boolean | null;
collateralFeePerDay: number | null;
tier: string | null;
forceWithdraw: boolean | null;
}

Expand Down Expand Up @@ -161,6 +164,7 @@ export const NullTokenEditParams: TokenEditParams = {
platformLiquidationFee: null,
disableAssetLiquidation: null,
collateralFeePerDay: null,
tier: null,
forceWithdraw: null,
};

Expand Down
Loading
Loading