Skip to content

Commit

Permalink
Merge branch 'release/program-v0.24.3' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
microwavedcola1 committed Aug 26, 2024
2 parents cced613 + af2d10f commit 549b5c6
Show file tree
Hide file tree
Showing 19 changed files with 633 additions and 1,236 deletions.
25 changes: 18 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ Update this for each program release and mainnet deployment.

## not on mainnet

### v0.24.3, 2024-8-

- Program: Remove delegate account withdrawal limit (#939)
- Program: Allow the insurance fund to be for any bank (#946)
- Program: add a tier string in banks (#988)
- Program: Allow closing open orders account for force closed spot markets (#995)

## mainnet

### v0.24.2, 2024-7-

Deployment: Jul 29, 2024 at 10:46:28 Central European Summer Time,
https://explorer.solana.com/tx/8zFSfPVSw98NL7nnJgfjNEhXcUVJtaCxLxnj9jt6kAnLwBR8LvzrS1Q5p21CuwiueJisdQFurf1ujNy38GiUEB1

- Program: charge collateral fee directly on borrowed tokens (#973)

- Program: fix TokenUpdateIndexAndRateResilient IX (#979)

- Program: add support for pyth v2 account (#980)

## mainnet

### v0.24.1, 2024-7-9

Deployment: Jul 9, 2024 at 15:46:15 Central European Summer Time,
Expand All @@ -25,18 +35,18 @@ https://explorer.solana.com/tx/5KYBSXV4uRCUK6vaQoZjipNFhTqEY1b1DHJeSh5jo87UUVGBB

### v0.24.0, 2024-4-18

Deployment: Apr 18, 2024 at 14:53:24 Central European Summer Time,
Deployment: Apr 18, 2024 at 14:53:24 Central European Summer Time,
https://explorer.solana.com/tx/2TFCGXQkUjRvkuuojxmiKefUtHPp6q6rM1frYvALByWMGfpWbiGH5hGq5suWEH7TUKoz4jb4KCGxu9DRw7YcXNdh

- Allow skipping banks and invalid oracles when computing health (#891)

This is only possible when we know for sure that the operation would not put the account into negative health zone.
This is only possible when we know for sure that the operation would not put the account into negative health zone.

- Add support for Raydium CLMM as oracle fallback (#856)

- Add a `TokenBalanceLog` when charging collateral fees (#894)

- Withdraw instruction: remove overflow error and return appropriate error message instead (#910)
- Withdraw instruction: remove overflow error and return appropriate error message instead (#910)

- Banks: add more safety checks (#895)

Expand All @@ -46,7 +56,7 @@ https://explorer.solana.com/tx/2TFCGXQkUjRvkuuojxmiKefUtHPp6q6rM1frYvALByWMGfpWb

- Add a sequence check instruction (#909)

Assert that a transaction was emitted and run with a correct view of the current mango state.
Assert that a transaction was emitted and run with a correct view of the current mango state.

### v0.23.0, 2024-3-8

Expand Down Expand Up @@ -154,6 +164,7 @@ Deployment: Dec 13, 2023 at 09:02:46 Central European Standard Time, https://exp
The DAO had previously reduced the percentage amount as a mitigation.

With this change:

- low-health settlement incentives are capped at 2x the flat fee, removing
unlimited percentual incentive fees entirely
- incentives are only paid if at least 1% of position value is settled,
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions mango_v4.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.24.2",
"version": "0.24.3",
"name": "mango_v4",
"instructions": [
{
Expand Down 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
2 changes: 1 addition & 1 deletion programs/mango-v4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mango-v4"
version = "0.24.2"
version = "0.24.3"
description = "Created with Anchor"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ use crate::error::MangoError;
use crate::state::*;

pub fn serum3_close_open_orders(ctx: Context<Serum3CloseOpenOrders>) -> Result<()> {
let serum_market = ctx.accounts.serum_market.load()?;

//
// Validation
//
let mut account = ctx.accounts.account.load_full_mut()?;
// account constraint #1
require!(
account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()),
account.fixed.is_owner_or_delegate(ctx.accounts.owner.key())
|| serum_market.is_force_close(),
MangoError::SomeError
);

let serum_market = ctx.accounts.serum_market.load()?;

// Validate open_orders #2
require!(
account
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
1 change: 1 addition & 0 deletions programs/mango-v4/src/instructions/token_liq_bankruptcy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn token_liq_bankruptcy(

// find the insurance bank token index
let insurance_mint = ctx.accounts.insurance_vault.mint;
require_keys_eq!(insurance_mint, group.insurance_mint);
let insurance_token_index = health_ais
.iter()
.find_map(|ai| {
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
5 changes: 0 additions & 5 deletions programs/mango-v4/src/state/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ pub type TokenIndex = u16;
/// incorrect assumption.
pub const QUOTE_TOKEN_INDEX: TokenIndex = 0;

/// The token index used for the insurance fund.
///
/// We should eventually generalize insurance funds.
pub const INSURANCE_TOKEN_INDEX: TokenIndex = 0;

/// The token index used for settling perp markets.
///
/// We should eventually generalize to make the whole perp quote (and settle) token
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,
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
Loading

0 comments on commit 549b5c6

Please sign in to comment.