From c60f7b28a60c7188e6607c1775d0888ec01f6e6b Mon Sep 17 00:00:00 2001 From: tjs Date: Thu, 26 May 2022 15:17:06 -0400 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into main --- .github/workflows/ci-lint-test.yml | 23 --------------- .../mango-v4/src/instructions/margin_trade.rs | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci-lint-test.yml b/.github/workflows/ci-lint-test.yml index 0c5688936..e564abdab 100644 --- a/.github/workflows/ci-lint-test.yml +++ b/.github/workflows/ci-lint-test.yml @@ -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 diff --git a/programs/mango-v4/src/instructions/margin_trade.rs b/programs/mango-v4/src/instructions/margin_trade.rs index 0992ea2dc..b1a61204e 100644 --- a/programs/mango-v4/src/instructions/margin_trade.rs +++ b/programs/mango-v4/src/instructions/margin_trade.rs @@ -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::::try_from(ai).unwrap(); + + // Skip mints and other accounts that may be owned by the spl_token program + let maybe_token_account = Account::::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; }