Rename bank fields, make weight scale limits editable (#319)
This commit is contained in:
parent
375b2b3fb3
commit
777c1a7804
|
@ -50,8 +50,10 @@ pub fn token_edit(
|
|||
stable_price_delay_growth_limit_opt: Option<f32>,
|
||||
stable_price_growth_limit_opt: Option<f32>,
|
||||
min_vault_to_deposits_ratio_opt: Option<f64>,
|
||||
net_borrows_limit_quote_opt: Option<i64>,
|
||||
net_borrows_window_size_ts_opt: Option<u64>,
|
||||
net_borrow_limit_per_window_quote_opt: Option<i64>,
|
||||
net_borrow_limit_window_size_ts_opt: Option<u64>,
|
||||
borrow_weight_scale_start_quote_opt: Option<f64>,
|
||||
deposit_weight_scale_start_quote_opt: Option<f64>,
|
||||
reset_stable_price: bool,
|
||||
reset_net_borrow_limit: bool,
|
||||
) -> Result<()> {
|
||||
|
@ -150,17 +152,24 @@ pub fn token_edit(
|
|||
if let Some(min_vault_to_deposits_ratio) = min_vault_to_deposits_ratio_opt {
|
||||
bank.min_vault_to_deposits_ratio = min_vault_to_deposits_ratio;
|
||||
}
|
||||
if let Some(net_borrows_limit_quote) = net_borrows_limit_quote_opt {
|
||||
bank.net_borrows_limit_quote = net_borrows_limit_quote;
|
||||
if let Some(net_borrow_limit_per_window_quote) = net_borrow_limit_per_window_quote_opt {
|
||||
bank.net_borrow_limit_per_window_quote = net_borrow_limit_per_window_quote;
|
||||
}
|
||||
if let Some(net_borrows_window_size_ts) = net_borrows_window_size_ts_opt {
|
||||
bank.net_borrows_window_size_ts = net_borrows_window_size_ts;
|
||||
if let Some(net_borrow_limit_window_size_ts) = net_borrow_limit_window_size_ts_opt {
|
||||
bank.net_borrow_limit_window_size_ts = net_borrow_limit_window_size_ts;
|
||||
}
|
||||
if reset_net_borrow_limit {
|
||||
bank.net_borrows_in_window = 0;
|
||||
bank.last_net_borrows_window_start_ts = 0;
|
||||
}
|
||||
|
||||
if let Some(borrow_weight_scale_start_quote) = borrow_weight_scale_start_quote_opt {
|
||||
bank.borrow_weight_scale_start_quote = borrow_weight_scale_start_quote;
|
||||
}
|
||||
if let Some(deposit_weight_scale_start_quote) = deposit_weight_scale_start_quote_opt {
|
||||
bank.deposit_weight_scale_start_quote = deposit_weight_scale_start_quote;
|
||||
}
|
||||
|
||||
// unchanged -
|
||||
// dust
|
||||
// flash_loan_token_account_initial
|
||||
|
|
|
@ -91,8 +91,8 @@ pub fn token_register(
|
|||
init_liab_weight: f32,
|
||||
liquidation_fee: f32,
|
||||
min_vault_to_deposits_ratio: f64,
|
||||
net_borrows_window_size_ts: u64,
|
||||
net_borrows_limit_quote: i64,
|
||||
net_borrow_limit_window_size_ts: u64,
|
||||
net_borrow_limit_per_window_quote: i64,
|
||||
) -> Result<()> {
|
||||
// Require token 0 to be in the insurance token
|
||||
if token_index == QUOTE_TOKEN_INDEX {
|
||||
|
@ -143,13 +143,13 @@ pub fn token_register(
|
|||
oracle_config: oracle_config.to_oracle_config(),
|
||||
stable_price_model: StablePriceModel::default(),
|
||||
min_vault_to_deposits_ratio,
|
||||
net_borrows_window_size_ts,
|
||||
last_net_borrows_window_start_ts: now_ts / net_borrows_window_size_ts
|
||||
* net_borrows_window_size_ts,
|
||||
net_borrows_limit_quote,
|
||||
net_borrow_limit_window_size_ts,
|
||||
last_net_borrows_window_start_ts: now_ts / net_borrow_limit_window_size_ts
|
||||
* net_borrow_limit_window_size_ts,
|
||||
net_borrow_limit_per_window_quote,
|
||||
net_borrows_in_window: 0,
|
||||
borrow_limit_quote: f64::MAX,
|
||||
collateral_limit_quote: f64::MAX,
|
||||
borrow_weight_scale_start_quote: f64::MAX,
|
||||
deposit_weight_scale_start_quote: f64::MAX,
|
||||
reserved: [0; 2120],
|
||||
};
|
||||
require_gt!(bank.max_rate, MINIMUM_MAX_RATE);
|
||||
|
|
|
@ -72,7 +72,7 @@ pub fn token_register_trustless(
|
|||
) -> Result<()> {
|
||||
require_neq!(token_index, 0);
|
||||
|
||||
let net_borrows_window_size_ts = 24 * 60 * 60 as u64;
|
||||
let net_borrow_limit_window_size_ts = 24 * 60 * 60 as u64;
|
||||
let now_ts: u64 = Clock::get()?.unix_timestamp.try_into().unwrap();
|
||||
|
||||
let mut bank = ctx.accounts.bank.load_init()?;
|
||||
|
@ -118,13 +118,13 @@ pub fn token_register_trustless(
|
|||
},
|
||||
stable_price_model: StablePriceModel::default(),
|
||||
min_vault_to_deposits_ratio: 0.2,
|
||||
net_borrows_window_size_ts,
|
||||
last_net_borrows_window_start_ts: now_ts / net_borrows_window_size_ts
|
||||
* net_borrows_window_size_ts,
|
||||
net_borrows_limit_quote: 1_000_000_000_000, // 1M USD
|
||||
net_borrow_limit_window_size_ts,
|
||||
last_net_borrows_window_start_ts: now_ts / net_borrow_limit_window_size_ts
|
||||
* net_borrow_limit_window_size_ts,
|
||||
net_borrow_limit_per_window_quote: 1_000_000_000_000, // 1M USD
|
||||
net_borrows_in_window: 0,
|
||||
borrow_limit_quote: f64::MAX,
|
||||
collateral_limit_quote: f64::MAX,
|
||||
borrow_weight_scale_start_quote: f64::MAX,
|
||||
deposit_weight_scale_start_quote: f64::MAX,
|
||||
reserved: [0; 2120],
|
||||
};
|
||||
require_gt!(bank.max_rate, MINIMUM_MAX_RATE);
|
||||
|
|
|
@ -75,8 +75,8 @@ pub mod mango_v4 {
|
|||
init_liab_weight: f32,
|
||||
liquidation_fee: f32,
|
||||
min_vault_to_deposits_ratio: f64,
|
||||
net_borrows_window_size_ts: u64,
|
||||
net_borrows_limit_quote: i64,
|
||||
net_borrow_limit_window_size_ts: u64,
|
||||
net_borrow_limit_per_window_quote: i64,
|
||||
) -> Result<()> {
|
||||
instructions::token_register(
|
||||
ctx,
|
||||
|
@ -92,8 +92,8 @@ pub mod mango_v4 {
|
|||
init_liab_weight,
|
||||
liquidation_fee,
|
||||
min_vault_to_deposits_ratio,
|
||||
net_borrows_window_size_ts,
|
||||
net_borrows_limit_quote,
|
||||
net_borrow_limit_window_size_ts,
|
||||
net_borrow_limit_per_window_quote,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -123,8 +123,10 @@ pub mod mango_v4 {
|
|||
stable_price_delay_growth_limit_opt: Option<f32>,
|
||||
stable_price_growth_limit_opt: Option<f32>,
|
||||
min_vault_to_deposits_ratio_opt: Option<f64>,
|
||||
net_borrows_limit_quote_opt: Option<i64>,
|
||||
net_borrows_window_size_ts_opt: Option<u64>,
|
||||
net_borrow_limit_per_window_quote_opt: Option<i64>,
|
||||
net_borrow_limit_window_size_ts_opt: Option<u64>,
|
||||
borrow_weight_scale_start_quote_opt: Option<f64>,
|
||||
deposit_weight_scale_start_quote_opt: Option<f64>,
|
||||
reset_stable_price: bool,
|
||||
reset_net_borrow_limit: bool,
|
||||
) -> Result<()> {
|
||||
|
@ -145,8 +147,10 @@ pub mod mango_v4 {
|
|||
stable_price_delay_growth_limit_opt,
|
||||
stable_price_growth_limit_opt,
|
||||
min_vault_to_deposits_ratio_opt,
|
||||
net_borrows_limit_quote_opt,
|
||||
net_borrows_window_size_ts_opt,
|
||||
net_borrow_limit_per_window_quote_opt,
|
||||
net_borrow_limit_window_size_ts_opt,
|
||||
borrow_weight_scale_start_quote_opt,
|
||||
deposit_weight_scale_start_quote_opt,
|
||||
reset_stable_price,
|
||||
reset_net_borrow_limit,
|
||||
)
|
||||
|
|
|
@ -101,11 +101,11 @@ pub struct Bank {
|
|||
pub min_vault_to_deposits_ratio: f64,
|
||||
|
||||
/// Size in seconds of a net borrows window
|
||||
pub net_borrows_window_size_ts: u64,
|
||||
pub net_borrow_limit_window_size_ts: u64,
|
||||
/// Timestamp at which the last net borrows window started
|
||||
pub last_net_borrows_window_start_ts: u64,
|
||||
/// Net borrow limit per window in quote native; set to -1 to disable.
|
||||
pub net_borrows_limit_quote: i64,
|
||||
pub net_borrow_limit_per_window_quote: i64,
|
||||
/// Sum of all deposits and borrows in the last window, in native units.
|
||||
pub net_borrows_in_window: i64,
|
||||
|
||||
|
@ -115,16 +115,16 @@ pub struct Bank {
|
|||
/// Set to f64::MAX to disable.
|
||||
///
|
||||
/// See scaled_init_liab_weight().
|
||||
pub borrow_limit_quote: f64,
|
||||
pub borrow_weight_scale_start_quote: f64,
|
||||
|
||||
/// Limit for collateral of deposits
|
||||
/// Limit for collateral of deposits in native quote
|
||||
///
|
||||
/// Once the deposits in the bank exceed this quote value, init_asset_weight is scaled
|
||||
/// down to keep the total collateral value constant.
|
||||
/// Set to f64::MAX to disable.
|
||||
///
|
||||
/// See scaled_init_asset_weight().
|
||||
pub collateral_limit_quote: f64,
|
||||
pub deposit_weight_scale_start_quote: f64,
|
||||
|
||||
#[derivative(Debug = "ignore")]
|
||||
pub reserved: [u8; 2120],
|
||||
|
@ -208,12 +208,12 @@ impl Bank {
|
|||
oracle_config: existing_bank.oracle_config,
|
||||
stable_price_model: StablePriceModel::default(),
|
||||
min_vault_to_deposits_ratio: existing_bank.min_vault_to_deposits_ratio,
|
||||
net_borrows_limit_quote: existing_bank.net_borrows_limit_quote,
|
||||
net_borrows_window_size_ts: existing_bank.net_borrows_window_size_ts,
|
||||
net_borrow_limit_per_window_quote: existing_bank.net_borrow_limit_per_window_quote,
|
||||
net_borrow_limit_window_size_ts: existing_bank.net_borrow_limit_window_size_ts,
|
||||
last_net_borrows_window_start_ts: existing_bank.last_net_borrows_window_start_ts,
|
||||
net_borrows_in_window: 0,
|
||||
borrow_limit_quote: f64::MAX,
|
||||
collateral_limit_quote: f64::MAX,
|
||||
borrow_weight_scale_start_quote: f64::MAX,
|
||||
deposit_weight_scale_start_quote: f64::MAX,
|
||||
reserved: [0; 2120],
|
||||
}
|
||||
}
|
||||
|
@ -553,12 +553,12 @@ impl Bank {
|
|||
/// If oracle_price is set, also do a net borrows check and error if the threshold is exceeded.
|
||||
pub fn update_net_borrows(&mut self, native_amount: I80F48, now_ts: u64) {
|
||||
let in_new_window =
|
||||
now_ts >= self.last_net_borrows_window_start_ts + self.net_borrows_window_size_ts;
|
||||
now_ts >= self.last_net_borrows_window_start_ts + self.net_borrow_limit_window_size_ts;
|
||||
|
||||
self.net_borrows_in_window = if in_new_window {
|
||||
// reset to latest window
|
||||
self.last_net_borrows_window_start_ts =
|
||||
now_ts / self.net_borrows_window_size_ts * self.net_borrows_window_size_ts;
|
||||
self.last_net_borrows_window_start_ts = now_ts / self.net_borrow_limit_window_size_ts
|
||||
* self.net_borrow_limit_window_size_ts;
|
||||
native_amount.checked_to_num::<i64>().unwrap()
|
||||
} else {
|
||||
cm!(self.net_borrows_in_window + native_amount.checked_to_num().unwrap())
|
||||
|
@ -566,7 +566,7 @@ impl Bank {
|
|||
}
|
||||
|
||||
pub fn check_net_borrows(&self, oracle_price: I80F48) -> Result<()> {
|
||||
if self.net_borrows_limit_quote < 0 {
|
||||
if self.net_borrows_in_window < 0 || self.net_borrow_limit_per_window_quote < 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -574,10 +574,10 @@ impl Bank {
|
|||
let net_borrows_quote = price
|
||||
.checked_mul_int(self.net_borrows_in_window.into())
|
||||
.unwrap();
|
||||
if net_borrows_quote > self.net_borrows_limit_quote {
|
||||
if net_borrows_quote > self.net_borrow_limit_per_window_quote {
|
||||
return Err(error_msg_typed!(BankNetBorrowsLimitReached,
|
||||
"net_borrows_in_window ({:?}) exceeds net_borrows_limit_quote ({:?}) for last_net_borrows_window_start_ts ({:?}) ",
|
||||
self.net_borrows_in_window, self.net_borrows_limit_quote, self.last_net_borrows_window_start_ts
|
||||
"net_borrows_in_window ({:?}) exceeds net_borrow_limit_per_window_quote ({:?}) for last_net_borrows_window_start_ts ({:?}) ",
|
||||
self.net_borrows_in_window, self.net_borrow_limit_per_window_quote, self.last_net_borrows_window_start_ts
|
||||
|
||||
));
|
||||
}
|
||||
|
@ -780,36 +780,36 @@ impl Bank {
|
|||
/// such that scaled_init_weight * deposits remains constant.
|
||||
#[inline(always)]
|
||||
pub fn scaled_init_asset_weight(&self, price: I80F48) -> I80F48 {
|
||||
if self.collateral_limit_quote == f64::MAX {
|
||||
if self.deposit_weight_scale_start_quote == f64::MAX {
|
||||
return self.init_asset_weight;
|
||||
}
|
||||
// The next line is around 500 CU
|
||||
let deposits_quote = self.native_deposits().to_num::<f64>() * price.to_num::<f64>();
|
||||
if deposits_quote <= self.collateral_limit_quote {
|
||||
if deposits_quote <= self.deposit_weight_scale_start_quote {
|
||||
self.init_asset_weight
|
||||
} else {
|
||||
// The next line is around 500 CU
|
||||
let scale = self.collateral_limit_quote / deposits_quote;
|
||||
let scale = self.deposit_weight_scale_start_quote / deposits_quote;
|
||||
cm!(self.init_asset_weight * I80F48::from_num(scale))
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn scaled_init_liab_weight(&self, price: I80F48) -> I80F48 {
|
||||
if self.borrow_limit_quote == f64::MAX {
|
||||
if self.borrow_weight_scale_start_quote == f64::MAX {
|
||||
return self.init_liab_weight;
|
||||
}
|
||||
// The next line is around 500 CU
|
||||
let borrows_quote = self.native_borrows().to_num::<f64>() * price.to_num::<f64>();
|
||||
if borrows_quote <= self.borrow_limit_quote {
|
||||
if borrows_quote <= self.borrow_weight_scale_start_quote {
|
||||
self.init_liab_weight
|
||||
} else if self.borrow_limit_quote == 0.0 {
|
||||
} else if self.borrow_weight_scale_start_quote == 0.0 {
|
||||
// TODO: will certainly cause overflow, so it's not exactly what is needed; health should be -MAX?
|
||||
// maybe handling this case isn't super helpful?
|
||||
I80F48::MAX
|
||||
} else {
|
||||
// The next line is around 500 CU
|
||||
let scale = borrows_quote / self.borrow_limit_quote;
|
||||
let scale = borrows_quote / self.borrow_weight_scale_start_quote;
|
||||
cm!(self.init_liab_weight * I80F48::from_num(scale))
|
||||
}
|
||||
}
|
||||
|
@ -877,8 +877,8 @@ mod tests {
|
|||
//
|
||||
|
||||
let mut bank = Bank::zeroed();
|
||||
bank.net_borrows_window_size_ts = 1; // dummy
|
||||
bank.net_borrows_limit_quote = i64::MAX; // max since we don't want this to interfere
|
||||
bank.net_borrow_limit_window_size_ts = 1; // dummy
|
||||
bank.net_borrow_limit_per_window_quote = i64::MAX; // max since we don't want this to interfere
|
||||
bank.deposit_index = I80F48::from_num(100.0);
|
||||
bank.borrow_index = I80F48::from_num(10.0);
|
||||
bank.loan_origination_fee_rate = I80F48::from_num(0.1);
|
||||
|
|
|
@ -826,8 +826,8 @@ mod tests {
|
|||
struct BankSettings {
|
||||
deposits: u64,
|
||||
borrows: u64,
|
||||
collateral_limit_quote: u64,
|
||||
borrow_limit_quote: u64,
|
||||
deposit_weight_scale_start_quote: u64,
|
||||
borrow_weight_scale_start_quote: u64,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -885,11 +885,13 @@ mod tests {
|
|||
let bank = bank.data();
|
||||
bank.indexed_deposits = I80F48::from(settings.deposits) / bank.deposit_index;
|
||||
bank.indexed_borrows = I80F48::from(settings.borrows) / bank.borrow_index;
|
||||
if settings.collateral_limit_quote > 0 {
|
||||
bank.collateral_limit_quote = settings.collateral_limit_quote as f64;
|
||||
if settings.deposit_weight_scale_start_quote > 0 {
|
||||
bank.deposit_weight_scale_start_quote =
|
||||
settings.deposit_weight_scale_start_quote as f64;
|
||||
}
|
||||
if settings.borrow_limit_quote > 0 {
|
||||
bank.borrow_limit_quote = settings.borrow_limit_quote as f64;
|
||||
if settings.borrow_weight_scale_start_quote > 0 {
|
||||
bank.borrow_weight_scale_start_quote =
|
||||
settings.borrow_weight_scale_start_quote as f64;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1064,17 +1066,17 @@ mod tests {
|
|||
bank_settings: [
|
||||
BankSettings {
|
||||
deposits: 100,
|
||||
collateral_limit_quote: 1000,
|
||||
deposit_weight_scale_start_quote: 1000,
|
||||
..BankSettings::default()
|
||||
},
|
||||
BankSettings {
|
||||
deposits: 1500,
|
||||
collateral_limit_quote: 1000 * 5,
|
||||
deposit_weight_scale_start_quote: 1000 * 5,
|
||||
..BankSettings::default()
|
||||
},
|
||||
BankSettings {
|
||||
deposits: 10000,
|
||||
collateral_limit_quote: 1000 * 10,
|
||||
deposit_weight_scale_start_quote: 1000 * 10,
|
||||
..BankSettings::default()
|
||||
},
|
||||
],
|
||||
|
@ -1094,17 +1096,17 @@ mod tests {
|
|||
bank_settings: [
|
||||
BankSettings {
|
||||
borrows: 100,
|
||||
borrow_limit_quote: 1000,
|
||||
borrow_weight_scale_start_quote: 1000,
|
||||
..BankSettings::default()
|
||||
},
|
||||
BankSettings {
|
||||
borrows: 1500,
|
||||
borrow_limit_quote: 1000 * 5,
|
||||
borrow_weight_scale_start_quote: 1000 * 5,
|
||||
..BankSettings::default()
|
||||
},
|
||||
BankSettings {
|
||||
borrows: 10000,
|
||||
borrow_limit_quote: 1000 * 10,
|
||||
borrow_weight_scale_start_quote: 1000 * 10,
|
||||
..BankSettings::default()
|
||||
},
|
||||
],
|
||||
|
|
|
@ -648,7 +648,7 @@ mod tests {
|
|||
let mut health_cache = health_cache.clone();
|
||||
adjust_by_usdc(&mut health_cache, 1, 100.0);
|
||||
let mut banks = banks.clone();
|
||||
banks[0].net_borrows_limit_quote = 50;
|
||||
banks[0].net_borrow_limit_per_window_quote = 50;
|
||||
|
||||
// The net borrow limit restricts the amount that can be swapped
|
||||
// (tracking happens without decimals)
|
||||
|
|
|
@ -96,10 +96,10 @@ pub fn mock_bank_and_oracle(
|
|||
bank.data().maint_asset_weight = I80F48::from_num(1.0 - maint_weights);
|
||||
bank.data().maint_liab_weight = I80F48::from_num(1.0 + maint_weights);
|
||||
bank.data().stable_price_model.reset_to_price(price, 0);
|
||||
bank.data().collateral_limit_quote = f64::MAX;
|
||||
bank.data().borrow_limit_quote = f64::MAX;
|
||||
bank.data().net_borrows_window_size_ts = 1; // dummy
|
||||
bank.data().net_borrows_limit_quote = i64::MAX; // max since we don't want this to interfere
|
||||
bank.data().deposit_weight_scale_start_quote = f64::MAX;
|
||||
bank.data().borrow_weight_scale_start_quote = f64::MAX;
|
||||
bank.data().net_borrow_limit_window_size_ts = 1; // dummy
|
||||
bank.data().net_borrow_limit_per_window_quote = i64::MAX; // max since we don't want this to interfere
|
||||
(bank, oracle)
|
||||
}
|
||||
|
||||
|
|
|
@ -773,8 +773,8 @@ pub struct TokenRegisterInstruction {
|
|||
pub liquidation_fee: f32,
|
||||
|
||||
pub min_vault_to_deposits_ratio: f64,
|
||||
pub net_borrows_limit_quote: i64,
|
||||
pub net_borrows_window_size_ts: u64,
|
||||
pub net_borrow_limit_per_window_quote: i64,
|
||||
pub net_borrow_limit_window_size_ts: u64,
|
||||
|
||||
pub group: Pubkey,
|
||||
pub admin: TestKeypair,
|
||||
|
@ -817,8 +817,8 @@ impl ClientInstruction for TokenRegisterInstruction {
|
|||
init_liab_weight: self.init_liab_weight,
|
||||
liquidation_fee: self.liquidation_fee,
|
||||
min_vault_to_deposits_ratio: self.min_vault_to_deposits_ratio,
|
||||
net_borrows_limit_quote: self.net_borrows_limit_quote,
|
||||
net_borrows_window_size_ts: self.net_borrows_window_size_ts,
|
||||
net_borrow_limit_per_window_quote: self.net_borrow_limit_per_window_quote,
|
||||
net_borrow_limit_window_size_ts: self.net_borrow_limit_window_size_ts,
|
||||
};
|
||||
|
||||
let bank = Pubkey::find_program_address(
|
||||
|
@ -1077,8 +1077,10 @@ impl ClientInstruction for TokenResetStablePriceModel {
|
|||
stable_price_delay_growth_limit_opt: None,
|
||||
stable_price_growth_limit_opt: None,
|
||||
min_vault_to_deposits_ratio_opt: None,
|
||||
net_borrows_limit_quote_opt: None,
|
||||
net_borrows_window_size_ts_opt: None,
|
||||
net_borrow_limit_per_window_quote_opt: None,
|
||||
net_borrow_limit_window_size_ts_opt: None,
|
||||
borrow_weight_scale_start_quote_opt: None,
|
||||
deposit_weight_scale_start_quote_opt: None,
|
||||
reset_stable_price: true,
|
||||
reset_net_borrow_limit: false,
|
||||
};
|
||||
|
@ -1111,8 +1113,8 @@ pub struct TokenResetNetBorrows {
|
|||
pub admin: TestKeypair,
|
||||
pub mint: Pubkey,
|
||||
pub min_vault_to_deposits_ratio_opt: Option<f64>,
|
||||
pub net_borrows_limit_quote_opt: Option<i64>,
|
||||
pub net_borrows_window_size_ts_opt: Option<u64>,
|
||||
pub net_borrow_limit_per_window_quote_opt: Option<i64>,
|
||||
pub net_borrow_limit_window_size_ts_opt: Option<u64>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -1152,8 +1154,10 @@ impl ClientInstruction for TokenResetNetBorrows {
|
|||
stable_price_delay_growth_limit_opt: None,
|
||||
stable_price_growth_limit_opt: None,
|
||||
min_vault_to_deposits_ratio_opt: self.min_vault_to_deposits_ratio_opt,
|
||||
net_borrows_limit_quote_opt: self.net_borrows_limit_quote_opt,
|
||||
net_borrows_window_size_ts_opt: self.net_borrows_window_size_ts_opt,
|
||||
net_borrow_limit_per_window_quote_opt: self.net_borrow_limit_per_window_quote_opt,
|
||||
net_borrow_limit_window_size_ts_opt: self.net_borrow_limit_window_size_ts_opt,
|
||||
borrow_weight_scale_start_quote_opt: None,
|
||||
deposit_weight_scale_start_quote_opt: None,
|
||||
reset_stable_price: false,
|
||||
reset_net_borrow_limit: true,
|
||||
};
|
||||
|
|
|
@ -106,8 +106,8 @@ impl<'a> GroupWithTokensConfig {
|
|||
mint: mint.pubkey,
|
||||
payer,
|
||||
min_vault_to_deposits_ratio: 0.2,
|
||||
net_borrows_limit_quote: 1_000_000_000_000,
|
||||
net_borrows_window_size_ts: 24 * 60 * 60,
|
||||
net_borrow_limit_per_window_quote: 1_000_000_000_000,
|
||||
net_borrow_limit_window_size_ts: 24 * 60 * 60,
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -151,8 +151,8 @@ async fn test_bank_net_borrows_based_borrow_limit() -> Result<(), TransportError
|
|||
mint,
|
||||
// we want to test net borrow limits in isolation
|
||||
min_vault_to_deposits_ratio_opt: Some(0.0),
|
||||
net_borrows_limit_quote_opt: Some(6000),
|
||||
net_borrows_window_size_ts_opt: Some(1000),
|
||||
net_borrow_limit_per_window_quote_opt: Some(6000),
|
||||
net_borrow_limit_window_size_ts_opt: Some(1000),
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -42,8 +42,6 @@ export class Bank implements BankForHealth {
|
|||
public borrowIndex: I80F48;
|
||||
public indexedDeposits: I80F48;
|
||||
public indexedBorrows: I80F48;
|
||||
public cachedIndexedTotalDeposits: I80F48;
|
||||
public cachedIndexedTotalBorrows: I80F48;
|
||||
public avgUtilization: I80F48;
|
||||
public adjustmentFactor: I80F48;
|
||||
public maxRate: I80F48;
|
||||
|
@ -75,8 +73,6 @@ export class Bank implements BankForHealth {
|
|||
oracleConfig: OracleConfig;
|
||||
depositIndex: I80F48Dto;
|
||||
borrowIndex: I80F48Dto;
|
||||
cachedIndexedTotalDeposits: I80F48Dto;
|
||||
cachedIndexedTotalBorrows: I80F48Dto;
|
||||
indexedDeposits: I80F48Dto;
|
||||
indexedBorrows: I80F48Dto;
|
||||
indexLastUpdated: BN;
|
||||
|
@ -104,12 +100,12 @@ export class Bank implements BankForHealth {
|
|||
bankNum: number;
|
||||
stablePriceModel: StablePriceModel;
|
||||
minVaultToDepositsRatio: number;
|
||||
netBorrowsWindowSizeTs: BN;
|
||||
netBorrowLimitWindowSizeTs: BN;
|
||||
lastNetBorrowsWindowStartTs: BN;
|
||||
netBorrowsLimitQuote: BN;
|
||||
netBorrowLimitPerWindowQuote: BN;
|
||||
netBorrowsInWindow: BN;
|
||||
borrowLimitQuote: number;
|
||||
collateralLimitQuote: number;
|
||||
borrowWeightScaleStartQuote: number;
|
||||
depositWeightScaleStartQuote: number;
|
||||
},
|
||||
): Bank {
|
||||
return new Bank(
|
||||
|
@ -122,8 +118,6 @@ export class Bank implements BankForHealth {
|
|||
obj.oracleConfig,
|
||||
obj.depositIndex,
|
||||
obj.borrowIndex,
|
||||
obj.cachedIndexedTotalDeposits,
|
||||
obj.cachedIndexedTotalBorrows,
|
||||
obj.indexedDeposits,
|
||||
obj.indexedBorrows,
|
||||
obj.indexLastUpdated,
|
||||
|
@ -151,12 +145,12 @@ export class Bank implements BankForHealth {
|
|||
obj.bankNum,
|
||||
obj.stablePriceModel,
|
||||
obj.minVaultToDepositsRatio,
|
||||
obj.netBorrowsWindowSizeTs,
|
||||
obj.netBorrowLimitWindowSizeTs,
|
||||
obj.lastNetBorrowsWindowStartTs,
|
||||
obj.netBorrowsLimitQuote,
|
||||
obj.netBorrowLimitPerWindowQuote,
|
||||
obj.netBorrowsInWindow,
|
||||
obj.borrowLimitQuote,
|
||||
obj.collateralLimitQuote,
|
||||
obj.borrowWeightScaleStartQuote,
|
||||
obj.depositWeightScaleStartQuote,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -170,8 +164,6 @@ export class Bank implements BankForHealth {
|
|||
oracleConfig: OracleConfig,
|
||||
depositIndex: I80F48Dto,
|
||||
borrowIndex: I80F48Dto,
|
||||
indexedTotalDeposits: I80F48Dto,
|
||||
indexedTotalBorrows: I80F48Dto,
|
||||
indexedDeposits: I80F48Dto,
|
||||
indexedBorrows: I80F48Dto,
|
||||
public indexLastUpdated: BN,
|
||||
|
@ -199,20 +191,18 @@ export class Bank implements BankForHealth {
|
|||
public bankNum: number,
|
||||
public stablePriceModel: StablePriceModel,
|
||||
minVaultToDepositsRatio: number,
|
||||
netBorrowsWindowSizeTs: BN,
|
||||
netBorrowLimitWindowSizeTs: BN,
|
||||
lastNetBorrowsWindowStartTs: BN,
|
||||
netBorrowsLimitQuote: BN,
|
||||
netBorrowLimitPerWindowQuote: BN,
|
||||
netBorrowsInWindow: BN,
|
||||
borrowLimitQuote: number,
|
||||
collateralLimitQuote: number,
|
||||
borrowWeightScaleStartQuote: number,
|
||||
depositWeightScaleStartQuote: number,
|
||||
) {
|
||||
this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0];
|
||||
this.depositIndex = I80F48.from(depositIndex);
|
||||
this.borrowIndex = I80F48.from(borrowIndex);
|
||||
this.indexedDeposits = I80F48.from(indexedDeposits);
|
||||
this.indexedBorrows = I80F48.from(indexedBorrows);
|
||||
this.cachedIndexedTotalDeposits = I80F48.from(indexedTotalDeposits);
|
||||
this.cachedIndexedTotalBorrows = I80F48.from(indexedTotalBorrows);
|
||||
this.avgUtilization = I80F48.from(avgUtilization);
|
||||
this.adjustmentFactor = I80F48.from(adjustmentFactor);
|
||||
this.maxRate = I80F48.from(maxRate);
|
||||
|
@ -260,10 +250,6 @@ export class Bank implements BankForHealth {
|
|||
this.indexedDeposits.toString() +
|
||||
'\n indexedBorrows - ' +
|
||||
this.indexedBorrows.toString() +
|
||||
'\n cachedIndexedTotalDeposits - ' +
|
||||
this.cachedIndexedTotalDeposits.toString() +
|
||||
'\n cachedIndexedTotalBorrows - ' +
|
||||
this.cachedIndexedTotalBorrows.toString() +
|
||||
'\n indexLastUpdated - ' +
|
||||
new Date(this.indexLastUpdated.toNumber() * 1000) +
|
||||
'\n bankRateLastUpdated - ' +
|
||||
|
|
|
@ -230,7 +230,7 @@ export class MangoClient {
|
|||
initLiabWeight: number,
|
||||
liquidationFee: number,
|
||||
minVaultToDepositsRatio: number,
|
||||
netBorrowsWindowSizeTs: number,
|
||||
netBorrowLimitWindowSizeTs: number,
|
||||
netBorrowsLimitNative: number,
|
||||
): Promise<TransactionSignature> {
|
||||
return await this.program.methods
|
||||
|
@ -247,7 +247,7 @@ export class MangoClient {
|
|||
initLiabWeight,
|
||||
liquidationFee,
|
||||
minVaultToDepositsRatio,
|
||||
new BN(netBorrowsWindowSizeTs),
|
||||
new BN(netBorrowLimitWindowSizeTs),
|
||||
new BN(netBorrowsLimitNative),
|
||||
)
|
||||
.accounts({
|
||||
|
@ -300,8 +300,10 @@ export class MangoClient {
|
|||
stablePriceDelayGrowthLimit: number | null,
|
||||
stablePriceGrowthLimit: number | null,
|
||||
minVaultToDepositsRatio: number | null,
|
||||
netBorrowsLimitQuote: number | null,
|
||||
netBorrowsWindowSizeTs: number | null,
|
||||
netBorrowLimitPerWindowQuote: number | null,
|
||||
netBorrowLimitWindowSizeTs: number | null,
|
||||
borrowWeightScaleStartQuote: number | null,
|
||||
depositWeightScaleStartQuote: number | null,
|
||||
resetStablePrice: boolean | null,
|
||||
resetNetBorrowLimit: boolean | null,
|
||||
): Promise<TransactionSignature> {
|
||||
|
@ -325,8 +327,14 @@ export class MangoClient {
|
|||
stablePriceDelayGrowthLimit,
|
||||
stablePriceGrowthLimit,
|
||||
minVaultToDepositsRatio,
|
||||
netBorrowsLimitQuote !== null ? new BN(netBorrowsLimitQuote) : null,
|
||||
netBorrowsWindowSizeTs !== null ? new BN(netBorrowsWindowSizeTs) : null,
|
||||
netBorrowLimitPerWindowQuote !== null
|
||||
? new BN(netBorrowLimitPerWindowQuote)
|
||||
: null,
|
||||
netBorrowLimitWindowSizeTs !== null
|
||||
? new BN(netBorrowLimitWindowSizeTs)
|
||||
: null,
|
||||
borrowWeightScaleStartQuote,
|
||||
depositWeightScaleStartQuote,
|
||||
resetStablePrice ?? false,
|
||||
resetNetBorrowLimit ?? false,
|
||||
)
|
||||
|
|
|
@ -113,18 +113,12 @@ async function main(): Promise<void> {
|
|||
`\n ${'deposits (sum over all mango accounts)'.padEnd(40)} ${
|
||||
(bank as any).indexedDepositsByMangoAccounts
|
||||
}` +
|
||||
`\n ${'cachedTotalDeposits'.padEnd(40)} ${(
|
||||
bank as any
|
||||
).cachedIndexedTotalDeposits.mul(bank.depositIndex)}` +
|
||||
`\n ${'borrows'.padEnd(40)} ${bank.indexedBorrows.mul(
|
||||
bank.borrowIndex,
|
||||
)}` +
|
||||
`\n ${'borrows (sum over all mango accounts)'.padEnd(40)} ${
|
||||
(bank as any).indexedBorrowsByMangoAccounts
|
||||
}` +
|
||||
`\n ${'cachedTotalBorrows'.padEnd(40)} ${(
|
||||
bank as any
|
||||
).cachedIndexedTotalBorrows.mul(bank.borrowIndex)}` +
|
||||
`\n ${'avgUtilization since last rate update'.padEnd(40)} ${(
|
||||
100 * bank.avgUtilization.toNumber()
|
||||
).toFixed(1)}%` +
|
||||
|
|
|
@ -347,11 +347,11 @@ export type MangoV4 = {
|
|||
"type": "f64"
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsWindowSizeTs",
|
||||
"name": "netBorrowLimitWindowSizeTs",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsLimitQuote",
|
||||
"name": "netBorrowLimitPerWindowQuote",
|
||||
"type": "i64"
|
||||
}
|
||||
]
|
||||
|
@ -614,17 +614,29 @@ export type MangoV4 = {
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsLimitQuoteOpt",
|
||||
"name": "netBorrowLimitPerWindowQuoteOpt",
|
||||
"type": {
|
||||
"option": "i64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsWindowSizeTsOpt",
|
||||
"name": "netBorrowLimitWindowSizeTsOpt",
|
||||
"type": {
|
||||
"option": "u64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "borrowWeightScaleStartQuoteOpt",
|
||||
"type": {
|
||||
"option": "f64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "depositWeightScaleStartQuoteOpt",
|
||||
"type": {
|
||||
"option": "f64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "resetStablePrice",
|
||||
"type": "bool"
|
||||
|
@ -3431,9 +3443,15 @@ export type MangoV4 = {
|
|||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "oracleConfFilter",
|
||||
"name": "oracleConfig",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
"defined": "OracleConfig"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "stablePriceModel",
|
||||
"type": {
|
||||
"defined": "StablePriceModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -3452,23 +3470,6 @@ export type MangoV4 = {
|
|||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "cachedIndexedTotalDeposits",
|
||||
"docs": [
|
||||
"total deposits/borrows, only updated during UpdateIndexAndRate",
|
||||
"TODO: These values could be dropped from the bank, they're written in UpdateIndexAndRate",
|
||||
"and never read."
|
||||
],
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "cachedIndexedTotalBorrows",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "indexedDeposits",
|
||||
"docs": [
|
||||
|
@ -3620,18 +3621,6 @@ export type MangoV4 = {
|
|||
"name": "bankNum",
|
||||
"type": "u32"
|
||||
},
|
||||
{
|
||||
"name": "oracleConfig",
|
||||
"type": {
|
||||
"defined": "OracleConfig"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "stablePriceModel",
|
||||
"type": {
|
||||
"defined": "StablePriceModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "minVaultToDepositsRatio",
|
||||
"docs": [
|
||||
|
@ -3640,7 +3629,7 @@ export type MangoV4 = {
|
|||
"type": "f64"
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsWindowSizeTs",
|
||||
"name": "netBorrowLimitWindowSizeTs",
|
||||
"docs": [
|
||||
"Size in seconds of a net borrows window"
|
||||
],
|
||||
|
@ -3654,7 +3643,7 @@ export type MangoV4 = {
|
|||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsLimitQuote",
|
||||
"name": "netBorrowLimitPerWindowQuote",
|
||||
"docs": [
|
||||
"Net borrow limit per window in quote native; set to -1 to disable."
|
||||
],
|
||||
|
@ -3668,7 +3657,7 @@ export type MangoV4 = {
|
|||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "borrowLimitQuote",
|
||||
"name": "borrowWeightScaleStartQuote",
|
||||
"docs": [
|
||||
"Soft borrow limit in native quote",
|
||||
"",
|
||||
|
@ -3680,9 +3669,9 @@ export type MangoV4 = {
|
|||
"type": "f64"
|
||||
},
|
||||
{
|
||||
"name": "collateralLimitQuote",
|
||||
"name": "depositWeightScaleStartQuote",
|
||||
"docs": [
|
||||
"Limit for collateral of deposits",
|
||||
"Limit for collateral of deposits in native quote",
|
||||
"",
|
||||
"Once the deposits in the bank exceed this quote value, init_asset_weight is scaled",
|
||||
"down to keep the total collateral value constant.",
|
||||
|
@ -4058,6 +4047,15 @@ export type MangoV4 = {
|
|||
"type": {
|
||||
"defined": "BookSide"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
2400
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -4083,6 +4081,15 @@ export type MangoV4 = {
|
|||
488
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
64
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -4122,13 +4129,15 @@ export type MangoV4 = {
|
|||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "padding1",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
2
|
||||
]
|
||||
}
|
||||
"name": "bump",
|
||||
"docs": [
|
||||
"PDA bump"
|
||||
],
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "baseDecimals",
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
|
@ -4139,6 +4148,14 @@ export type MangoV4 = {
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "orderbook",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "eventQueue",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "oracle",
|
||||
"type": "publicKey"
|
||||
|
@ -4150,12 +4167,10 @@ export type MangoV4 = {
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "orderbook",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "eventQueue",
|
||||
"type": "publicKey"
|
||||
"name": "stablePriceModel",
|
||||
"type": {
|
||||
"defined": "StablePriceModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "quoteLotSize",
|
||||
|
@ -4198,25 +4213,25 @@ export type MangoV4 = {
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "liquidationFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
"name": "openInterest",
|
||||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "makerFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
"name": "seqNum",
|
||||
"docs": [
|
||||
"Total number of orders seen"
|
||||
],
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "takerFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
"name": "registrationTime",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "minFunding",
|
||||
"docs": [
|
||||
"Funding"
|
||||
],
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
|
@ -4251,18 +4266,25 @@ export type MangoV4 = {
|
|||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "openInterest",
|
||||
"name": "liquidationFee",
|
||||
"docs": [
|
||||
""
|
||||
"Fees"
|
||||
],
|
||||
"type": "i64"
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "seqNum",
|
||||
"docs": [
|
||||
"Total number of orders seen"
|
||||
],
|
||||
"type": "u64"
|
||||
"name": "makerFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "takerFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "feesAccrued",
|
||||
|
@ -4273,34 +4295,6 @@ export type MangoV4 = {
|
|||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "bump",
|
||||
"docs": [
|
||||
"Liquidity mining metadata",
|
||||
"pub liquidity_mining_info: LiquidityMiningInfo,",
|
||||
"Token vault which holds mango tokens to be disbursed as liquidity incentives for this perp market",
|
||||
"pub mngo_vault: Pubkey,",
|
||||
"PDA bump"
|
||||
],
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "baseDecimals",
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "padding2",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
6
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "registrationTime",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "feesSettled",
|
||||
"docs": [
|
||||
|
@ -4336,12 +4330,6 @@ export type MangoV4 = {
|
|||
],
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "stablePriceModel",
|
||||
"type": {
|
||||
"defined": "StablePriceModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "settlePnlLimitFactor",
|
||||
"docs": [
|
||||
|
@ -4350,6 +4338,15 @@ export type MangoV4 = {
|
|||
],
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "padding3",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
4
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "settlePnlLimitWindowSizeTs",
|
||||
"docs": [
|
||||
|
@ -4854,15 +4851,6 @@ export type MangoV4 = {
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
8
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "previousIndex",
|
||||
"type": {
|
||||
|
@ -4876,6 +4864,15 @@ export type MangoV4 = {
|
|||
{
|
||||
"name": "cumulativeBorrowInterest",
|
||||
"type": "f64"
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
128
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -4963,6 +4960,10 @@ export type MangoV4 = {
|
|||
"name": "settlePnlLimitWindow",
|
||||
"type": "u32"
|
||||
},
|
||||
{
|
||||
"name": "settlePnlLimitSettledInCurrentWindowNative",
|
||||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "basePositionLots",
|
||||
"docs": [
|
||||
|
@ -4980,10 +4981,6 @@ export type MangoV4 = {
|
|||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "settlePnlLimitSettledInCurrentWindowNative",
|
||||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "quoteRunningNative",
|
||||
"docs": [
|
||||
|
@ -5023,7 +5020,6 @@ export type MangoV4 = {
|
|||
{
|
||||
"name": "takerBaseLots",
|
||||
"docs": [
|
||||
"Liquidity mining rewards",
|
||||
"Amount that's on EventQueue waiting to be processed"
|
||||
],
|
||||
"type": "i64"
|
||||
|
@ -5061,6 +5057,15 @@ export type MangoV4 = {
|
|||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
128
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -5197,7 +5202,16 @@ export type MangoV4 = {
|
|||
"fields": [
|
||||
{
|
||||
"name": "tag",
|
||||
"type": "u32"
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "padding",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
3
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "prefixLen",
|
||||
|
@ -5246,7 +5260,7 @@ export type MangoV4 = {
|
|||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
48
|
||||
72
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -5263,7 +5277,7 @@ export type MangoV4 = {
|
|||
"fields": [
|
||||
{
|
||||
"name": "tag",
|
||||
"type": "u32"
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "ownerSlot",
|
||||
|
@ -5290,7 +5304,16 @@ export type MangoV4 = {
|
|||
"Time in seconds after `timestamp` at which the order expires.",
|
||||
"A value of 0 means no expiry."
|
||||
],
|
||||
"type": "u8"
|
||||
"type": "u16"
|
||||
},
|
||||
{
|
||||
"name": "padding2",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
2
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "key",
|
||||
|
@ -5324,7 +5347,7 @@ export type MangoV4 = {
|
|||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
8
|
||||
32
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -5338,14 +5361,14 @@ export type MangoV4 = {
|
|||
"fields": [
|
||||
{
|
||||
"name": "tag",
|
||||
"type": "u32"
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
92
|
||||
119
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -7606,11 +7629,11 @@ export const IDL: MangoV4 = {
|
|||
"type": "f64"
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsWindowSizeTs",
|
||||
"name": "netBorrowLimitWindowSizeTs",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsLimitQuote",
|
||||
"name": "netBorrowLimitPerWindowQuote",
|
||||
"type": "i64"
|
||||
}
|
||||
]
|
||||
|
@ -7873,17 +7896,29 @@ export const IDL: MangoV4 = {
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsLimitQuoteOpt",
|
||||
"name": "netBorrowLimitPerWindowQuoteOpt",
|
||||
"type": {
|
||||
"option": "i64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsWindowSizeTsOpt",
|
||||
"name": "netBorrowLimitWindowSizeTsOpt",
|
||||
"type": {
|
||||
"option": "u64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "borrowWeightScaleStartQuoteOpt",
|
||||
"type": {
|
||||
"option": "f64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "depositWeightScaleStartQuoteOpt",
|
||||
"type": {
|
||||
"option": "f64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "resetStablePrice",
|
||||
"type": "bool"
|
||||
|
@ -10690,9 +10725,15 @@ export const IDL: MangoV4 = {
|
|||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "oracleConfFilter",
|
||||
"name": "oracleConfig",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
"defined": "OracleConfig"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "stablePriceModel",
|
||||
"type": {
|
||||
"defined": "StablePriceModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -10711,23 +10752,6 @@ export const IDL: MangoV4 = {
|
|||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "cachedIndexedTotalDeposits",
|
||||
"docs": [
|
||||
"total deposits/borrows, only updated during UpdateIndexAndRate",
|
||||
"TODO: These values could be dropped from the bank, they're written in UpdateIndexAndRate",
|
||||
"and never read."
|
||||
],
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "cachedIndexedTotalBorrows",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "indexedDeposits",
|
||||
"docs": [
|
||||
|
@ -10879,18 +10903,6 @@ export const IDL: MangoV4 = {
|
|||
"name": "bankNum",
|
||||
"type": "u32"
|
||||
},
|
||||
{
|
||||
"name": "oracleConfig",
|
||||
"type": {
|
||||
"defined": "OracleConfig"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "stablePriceModel",
|
||||
"type": {
|
||||
"defined": "StablePriceModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "minVaultToDepositsRatio",
|
||||
"docs": [
|
||||
|
@ -10899,7 +10911,7 @@ export const IDL: MangoV4 = {
|
|||
"type": "f64"
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsWindowSizeTs",
|
||||
"name": "netBorrowLimitWindowSizeTs",
|
||||
"docs": [
|
||||
"Size in seconds of a net borrows window"
|
||||
],
|
||||
|
@ -10913,7 +10925,7 @@ export const IDL: MangoV4 = {
|
|||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "netBorrowsLimitQuote",
|
||||
"name": "netBorrowLimitPerWindowQuote",
|
||||
"docs": [
|
||||
"Net borrow limit per window in quote native; set to -1 to disable."
|
||||
],
|
||||
|
@ -10927,7 +10939,7 @@ export const IDL: MangoV4 = {
|
|||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "borrowLimitQuote",
|
||||
"name": "borrowWeightScaleStartQuote",
|
||||
"docs": [
|
||||
"Soft borrow limit in native quote",
|
||||
"",
|
||||
|
@ -10939,9 +10951,9 @@ export const IDL: MangoV4 = {
|
|||
"type": "f64"
|
||||
},
|
||||
{
|
||||
"name": "collateralLimitQuote",
|
||||
"name": "depositWeightScaleStartQuote",
|
||||
"docs": [
|
||||
"Limit for collateral of deposits",
|
||||
"Limit for collateral of deposits in native quote",
|
||||
"",
|
||||
"Once the deposits in the bank exceed this quote value, init_asset_weight is scaled",
|
||||
"down to keep the total collateral value constant.",
|
||||
|
@ -11317,6 +11329,15 @@ export const IDL: MangoV4 = {
|
|||
"type": {
|
||||
"defined": "BookSide"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
2400
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -11342,6 +11363,15 @@ export const IDL: MangoV4 = {
|
|||
488
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
64
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -11381,13 +11411,15 @@ export const IDL: MangoV4 = {
|
|||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "padding1",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
2
|
||||
]
|
||||
}
|
||||
"name": "bump",
|
||||
"docs": [
|
||||
"PDA bump"
|
||||
],
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "baseDecimals",
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
|
@ -11398,6 +11430,14 @@ export const IDL: MangoV4 = {
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "orderbook",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "eventQueue",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "oracle",
|
||||
"type": "publicKey"
|
||||
|
@ -11409,12 +11449,10 @@ export const IDL: MangoV4 = {
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "orderbook",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "eventQueue",
|
||||
"type": "publicKey"
|
||||
"name": "stablePriceModel",
|
||||
"type": {
|
||||
"defined": "StablePriceModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "quoteLotSize",
|
||||
|
@ -11457,25 +11495,25 @@ export const IDL: MangoV4 = {
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "liquidationFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
"name": "openInterest",
|
||||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "makerFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
"name": "seqNum",
|
||||
"docs": [
|
||||
"Total number of orders seen"
|
||||
],
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "takerFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
"name": "registrationTime",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "minFunding",
|
||||
"docs": [
|
||||
"Funding"
|
||||
],
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
|
@ -11510,18 +11548,25 @@ export const IDL: MangoV4 = {
|
|||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "openInterest",
|
||||
"name": "liquidationFee",
|
||||
"docs": [
|
||||
""
|
||||
"Fees"
|
||||
],
|
||||
"type": "i64"
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "seqNum",
|
||||
"docs": [
|
||||
"Total number of orders seen"
|
||||
],
|
||||
"type": "u64"
|
||||
"name": "makerFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "takerFee",
|
||||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "feesAccrued",
|
||||
|
@ -11532,34 +11577,6 @@ export const IDL: MangoV4 = {
|
|||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "bump",
|
||||
"docs": [
|
||||
"Liquidity mining metadata",
|
||||
"pub liquidity_mining_info: LiquidityMiningInfo,",
|
||||
"Token vault which holds mango tokens to be disbursed as liquidity incentives for this perp market",
|
||||
"pub mngo_vault: Pubkey,",
|
||||
"PDA bump"
|
||||
],
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "baseDecimals",
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "padding2",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
6
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "registrationTime",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "feesSettled",
|
||||
"docs": [
|
||||
|
@ -11595,12 +11612,6 @@ export const IDL: MangoV4 = {
|
|||
],
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "stablePriceModel",
|
||||
"type": {
|
||||
"defined": "StablePriceModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "settlePnlLimitFactor",
|
||||
"docs": [
|
||||
|
@ -11609,6 +11620,15 @@ export const IDL: MangoV4 = {
|
|||
],
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "padding3",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
4
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "settlePnlLimitWindowSizeTs",
|
||||
"docs": [
|
||||
|
@ -12113,15 +12133,6 @@ export const IDL: MangoV4 = {
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
8
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "previousIndex",
|
||||
"type": {
|
||||
|
@ -12135,6 +12146,15 @@ export const IDL: MangoV4 = {
|
|||
{
|
||||
"name": "cumulativeBorrowInterest",
|
||||
"type": "f64"
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
128
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -12222,6 +12242,10 @@ export const IDL: MangoV4 = {
|
|||
"name": "settlePnlLimitWindow",
|
||||
"type": "u32"
|
||||
},
|
||||
{
|
||||
"name": "settlePnlLimitSettledInCurrentWindowNative",
|
||||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "basePositionLots",
|
||||
"docs": [
|
||||
|
@ -12239,10 +12263,6 @@ export const IDL: MangoV4 = {
|
|||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "settlePnlLimitSettledInCurrentWindowNative",
|
||||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "quoteRunningNative",
|
||||
"docs": [
|
||||
|
@ -12282,7 +12302,6 @@ export const IDL: MangoV4 = {
|
|||
{
|
||||
"name": "takerBaseLots",
|
||||
"docs": [
|
||||
"Liquidity mining rewards",
|
||||
"Amount that's on EventQueue waiting to be processed"
|
||||
],
|
||||
"type": "i64"
|
||||
|
@ -12320,6 +12339,15 @@ export const IDL: MangoV4 = {
|
|||
"type": {
|
||||
"defined": "I80F48"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "reserved",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
128
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -12456,7 +12484,16 @@ export const IDL: MangoV4 = {
|
|||
"fields": [
|
||||
{
|
||||
"name": "tag",
|
||||
"type": "u32"
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "padding",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
3
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "prefixLen",
|
||||
|
@ -12505,7 +12542,7 @@ export const IDL: MangoV4 = {
|
|||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
48
|
||||
72
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -12522,7 +12559,7 @@ export const IDL: MangoV4 = {
|
|||
"fields": [
|
||||
{
|
||||
"name": "tag",
|
||||
"type": "u32"
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "ownerSlot",
|
||||
|
@ -12549,7 +12586,16 @@ export const IDL: MangoV4 = {
|
|||
"Time in seconds after `timestamp` at which the order expires.",
|
||||
"A value of 0 means no expiry."
|
||||
],
|
||||
"type": "u8"
|
||||
"type": "u16"
|
||||
},
|
||||
{
|
||||
"name": "padding2",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
2
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "key",
|
||||
|
@ -12583,7 +12629,7 @@ export const IDL: MangoV4 = {
|
|||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
8
|
||||
32
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -12597,14 +12643,14 @@ export const IDL: MangoV4 = {
|
|||
"fields": [
|
||||
{
|
||||
"name": "tag",
|
||||
"type": "u32"
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"type": {
|
||||
"array": [
|
||||
"u8",
|
||||
92
|
||||
119
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -435,6 +435,8 @@ async function main() {
|
|||
MIN_VAULT_TO_DEPOSITS_RATIO,
|
||||
NET_BORROWS_WINDOW_SIZE_TS,
|
||||
NET_BORROWS_LIMIT_NATIVE,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
|
@ -467,6 +469,8 @@ async function main() {
|
|||
MIN_VAULT_TO_DEPOSITS_RATIO,
|
||||
NET_BORROWS_WINDOW_SIZE_TS,
|
||||
NET_BORROWS_LIMIT_NATIVE,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
|
@ -499,6 +503,8 @@ async function main() {
|
|||
MIN_VAULT_TO_DEPOSITS_RATIO,
|
||||
NET_BORROWS_WINDOW_SIZE_TS,
|
||||
NET_BORROWS_LIMIT_NATIVE,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
|
|
|
@ -175,6 +175,8 @@ async function main() {
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
try {
|
||||
// At a price of $1/ui-SOL we can buy 0.1 ui-SOL for the 100k native-USDC we have.
|
||||
|
@ -215,6 +217,8 @@ async function main() {
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue