Bank: rename indexed total deposits and schedule for removal
This commit is contained in:
parent
e8cb27610e
commit
30a221047c
|
@ -116,8 +116,8 @@ pub fn token_register(
|
|||
oracle_config,
|
||||
deposit_index: INDEX_START,
|
||||
borrow_index: INDEX_START,
|
||||
indexed_total_deposits: I80F48::ZERO,
|
||||
indexed_total_borrows: I80F48::ZERO,
|
||||
cached_indexed_total_deposits: I80F48::ZERO,
|
||||
cached_indexed_total_borrows: I80F48::ZERO,
|
||||
indexed_deposits: I80F48::ZERO,
|
||||
indexed_borrows: I80F48::ZERO,
|
||||
last_updated: Clock::get()?.unix_timestamp,
|
||||
|
|
|
@ -56,8 +56,8 @@ pub fn update_index(ctx: Context<UpdateIndex>) -> Result<()> {
|
|||
for ai in all_banks.iter() {
|
||||
let mut bank = ai.load_mut::<Bank>()?;
|
||||
|
||||
bank.indexed_total_deposits = indexed_total_deposits;
|
||||
bank.indexed_total_borrows = indexed_total_borrows;
|
||||
bank.cached_indexed_total_deposits = indexed_total_deposits;
|
||||
bank.cached_indexed_total_borrows = indexed_total_borrows;
|
||||
|
||||
bank.last_updated = now_ts;
|
||||
bank.charge_loan_fee(diff_ts);
|
||||
|
|
|
@ -27,9 +27,11 @@ pub struct Bank {
|
|||
pub deposit_index: I80F48,
|
||||
pub borrow_index: I80F48,
|
||||
|
||||
/// total deposits/borrows, for utilization
|
||||
pub indexed_total_deposits: I80F48,
|
||||
pub indexed_total_borrows: I80F48,
|
||||
/// total deposits/borrows, only updated during UpdateIndex
|
||||
/// TODO: These values could be dropped from the bank, they're written in UpdateIndex
|
||||
/// and never read.
|
||||
pub cached_indexed_total_deposits: I80F48,
|
||||
pub cached_indexed_total_borrows: I80F48,
|
||||
|
||||
/// deposits/borrows for this bank
|
||||
pub indexed_deposits: I80F48,
|
||||
|
@ -96,8 +98,14 @@ impl std::fmt::Debug for Bank {
|
|||
.field("oracle_config", &self.oracle_config)
|
||||
.field("deposit_index", &self.deposit_index)
|
||||
.field("borrow_index", &self.borrow_index)
|
||||
.field("indexed_total_deposits", &self.indexed_total_deposits)
|
||||
.field("indexed_total_borrows", &self.indexed_total_borrows)
|
||||
.field(
|
||||
"cached_indexed_total_deposits",
|
||||
&self.cached_indexed_total_deposits,
|
||||
)
|
||||
.field(
|
||||
"cached_indexed_total_borrows",
|
||||
&self.cached_indexed_total_borrows,
|
||||
)
|
||||
.field("indexed_deposits", &self.indexed_deposits)
|
||||
.field("indexed_borrows", &self.indexed_borrows)
|
||||
.field("last_updated", &self.last_updated)
|
||||
|
@ -137,8 +145,8 @@ impl Bank {
|
|||
oracle_config: existing_bank.oracle_config,
|
||||
deposit_index: existing_bank.deposit_index,
|
||||
borrow_index: existing_bank.borrow_index,
|
||||
indexed_total_deposits: existing_bank.indexed_total_deposits,
|
||||
indexed_total_borrows: existing_bank.indexed_total_borrows,
|
||||
cached_indexed_total_deposits: existing_bank.cached_indexed_total_deposits,
|
||||
cached_indexed_total_borrows: existing_bank.cached_indexed_total_borrows,
|
||||
indexed_deposits: I80F48::ZERO,
|
||||
indexed_borrows: I80F48::ZERO,
|
||||
last_updated: existing_bank.last_updated,
|
||||
|
@ -172,14 +180,6 @@ impl Bank {
|
|||
.trim_matches(char::from(0))
|
||||
}
|
||||
|
||||
pub fn native_total_borrows(&self) -> I80F48 {
|
||||
self.borrow_index * self.indexed_total_borrows
|
||||
}
|
||||
|
||||
pub fn native_total_deposits(&self) -> I80F48 {
|
||||
self.deposit_index * self.indexed_total_deposits
|
||||
}
|
||||
|
||||
pub fn native_borrows(&self) -> I80F48 {
|
||||
self.borrow_index * self.indexed_borrows
|
||||
}
|
||||
|
|
|
@ -79,9 +79,7 @@ async fn test_basic() -> Result<(), TransportError> {
|
|||
deposit_amount as i64
|
||||
);
|
||||
let bank_data: Bank = solana.get_account(bank).await;
|
||||
assert!(
|
||||
bank_data.native_total_deposits() - I80F48::from_num(deposit_amount) < dust_threshold
|
||||
);
|
||||
assert!(bank_data.native_deposits() - I80F48::from_num(deposit_amount) < dust_threshold);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -129,7 +127,7 @@ async fn test_basic() -> Result<(), TransportError> {
|
|||
);
|
||||
let bank_data: Bank = solana.get_account(bank).await;
|
||||
assert!(
|
||||
bank_data.native_total_deposits() - I80F48::from_num(start_amount - withdraw_amount)
|
||||
bank_data.native_deposits() - I80F48::from_num(start_amount - withdraw_amount)
|
||||
< dust_threshold
|
||||
);
|
||||
}
|
||||
|
@ -155,7 +153,7 @@ async fn test_basic() -> Result<(), TransportError> {
|
|||
send_tx(
|
||||
solana,
|
||||
TokenWithdrawInstruction {
|
||||
amount: bank_data.native_total_deposits().to_num(),
|
||||
amount: bank_data.native_deposits().to_num(),
|
||||
allow_borrow: false,
|
||||
account,
|
||||
owner,
|
||||
|
|
Loading…
Reference in New Issue