Merge remote-tracking branch 'origin/dev' into main

This commit is contained in:
tjs 2022-05-26 15:17:06 -04:00
parent 84e9cbd030
commit c60f7b28a6
2 changed files with 19 additions and 33 deletions

View File

@ -112,26 +112,3 @@ jobs:
name: cu-per-ix-clean
path: cu-per-ix-clean.log
# Push clean logs to git if main/dev branch
push-logs:
name: Push logs
if: |
(github.actor != 'github-actions[bot]' && github.ref_name == 'main') ||
(github.actor != 'github-actions[bot]' && github.ref_name == 'dev')
runs-on: ubuntu-latest
needs: [lint, tests, process-logs]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Download clean log
uses: actions/download-artifact@v3
with:
name: cu-per-ix-clean
path: ./
- name: Push log to git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: push cu test logs"
git push

View File

@ -36,30 +36,32 @@ pub struct MarginTrade<'info> {
}
struct AllowedVault {
// index of the vault in cpi_ais
/// index of the vault in cpi_ais
vault_cpi_ai_index: usize,
// index of the bank in health_ais
/// index of the bank in health_ais
bank_health_ai_index: usize,
// raw index into account.tokens
/// raw index into account.tokens
raw_token_index: usize,
// vault amount before cpi
/// vault amount before cpi
pre_amount: u64,
// withdraw request
/// requested withdraw amount
withdraw_amount: u64,
// amount of withdraw request that is a loan
/// amount of withdraw request that is a loan
loan_amount: I80F48,
}
#[derive(AnchorDeserialize, AnchorSerialize, Clone, Copy)]
pub struct MarginTradeWithdraw {
/// Account index of the vault to withdraw from in the target_accounts section.
/// Meaning that the first account after target_program_id would have index 0.
pub index: u8,
/// Requested withdraw amount.
pub amount: u64,
}
/// - `num_health_accounts` is the number of health accounts that remaining_accounts starts with.
/// - `withdraws` is a list of tuples containing the index to a vault in target_accounts and the
/// amount that the target program shall be allowed to withdraw
/// - `cpi_data` is the bytes to call the target_program_id with
/// - `withdraws` is a list of MarginTradeWithdraw requests.
/// - `cpi_data` is the bytes to call the target_program_id with.
pub fn margin_trade<'key, 'accounts, 'remaining, 'info>(
ctx: Context<'key, 'accounts, 'remaining, 'info, MarginTrade<'info>>,
num_health_accounts: usize,
@ -124,7 +126,14 @@ pub fn margin_trade<'key, 'accounts, 'remaining, 'info>(
if ai.owner != &TokenAccount::owner() {
return None;
}
let token_account = Account::<TokenAccount>::try_from(ai).unwrap();
// Skip mints and other accounts that may be owned by the spl_token program
let maybe_token_account = Account::<TokenAccount>::try_from(ai);
if maybe_token_account.is_err() {
return None;
}
let token_account = maybe_token_account.unwrap();
if token_account.owner != ctx.accounts.group.key() {
return None;
}