-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
J
committed
Nov 7, 2023
1 parent
1ace78e
commit 1529657
Showing
8 changed files
with
249 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
programs/marginfi/src/instructions/marginfi_account/close_balance.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use crate::{ | ||
check, | ||
prelude::*, | ||
state::{ | ||
marginfi_account::{BankAccountWrapper, MarginfiAccount, DISABLED_FLAG}, | ||
marginfi_group::Bank, | ||
}, | ||
}; | ||
|
||
pub fn lending_account_close_balance(ctx: Context<LendingAccountCloseBalance>) -> MarginfiResult { | ||
let LendingAccountCloseBalance { | ||
marginfi_account, | ||
bank: bank_loader, | ||
.. | ||
} = ctx.accounts; | ||
|
||
let mut marginfi_account = marginfi_account.load_mut()?; | ||
let mut bank = bank_loader.load_mut()?; | ||
|
||
check!( | ||
!marginfi_account.get_flag(DISABLED_FLAG), | ||
MarginfiError::AccountDisabled | ||
); | ||
|
||
bank.accrue_interest( | ||
Clock::get()?.unix_timestamp, | ||
#[cfg(not(feature = "client"))] | ||
bank_loader.key(), | ||
)?; | ||
|
||
let mut bank_account = BankAccountWrapper::find( | ||
&bank_loader.key(), | ||
&mut bank, | ||
&mut marginfi_account.lending_account, | ||
)?; | ||
|
||
bank_account.close_balance()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct LendingAccountCloseBalance<'info> { | ||
pub marginfi_group: AccountLoader<'info, MarginfiGroup>, | ||
|
||
#[account( | ||
mut, | ||
constraint = marginfi_account.load()?.group == marginfi_group.key(), | ||
)] | ||
pub marginfi_account: AccountLoader<'info, MarginfiAccount>, | ||
|
||
#[account( | ||
address = marginfi_account.load()?.authority, | ||
)] | ||
pub signer: Signer<'info>, | ||
|
||
#[account( | ||
mut, | ||
constraint = bank.load()?.group == marginfi_group.key(), | ||
)] | ||
pub bank: AccountLoader<'info, Bank>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env bash | ||
anchor build --program-name marginfi | ||
RUST_LOG=error cargo test-sbf --features=test -- --test-threads=1 | ||
RUST_LOG=error cargo test-sbf --features=test -- --skip marginfi_account_liquidation_success_many_balances --test-threads=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters