Skip to content

Commit

Permalink
fix saber error
Browse files Browse the repository at this point in the history
  • Loading branch information
googolmo committed Mar 15, 2022
1 parent 8bea011 commit 16d7eb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
26 changes: 17 additions & 9 deletions src/program-rust/src/parser/stable_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::{
declare_validated_account_wrapper,
error::{ProtocolError, ProtocolResult},
};
use arrayref::array_ref;
use arrayref::{array_ref, array_refs};
use solana_program::{account_info::AccountInfo, pubkey::Pubkey};

use super::base::{SysClockAccount, TokenAccount};
use super::base::TokenAccount;

declare_validated_account_wrapper!(StableSwapInfo, |account: &AccountInfo| {
let data = account
Expand Down Expand Up @@ -90,25 +90,34 @@ pub struct StableSwapArgs<'a, 'b: 'a> {
pub token_a: TokenAccount<'a, 'b>,
pub token_b: TokenAccount<'a, 'b>,
pub admin_fee_acc: &'a AccountInfo<'b>,
pub clock_sysvar_acc: SysClockAccount<'a, 'b>,
pub program_acc: &'a AccountInfo<'b>,
}

impl<'a, 'b: 'a> StableSwapArgs<'a, 'b> {
const MIN_ACCOUNTS: usize = 6;

pub fn with_parsed_args(accounts: &'a [AccountInfo<'b>]) -> ProtocolResult<Self> {
const MIN_ACCOUNTS: usize = 7;
if accounts.len() != MIN_ACCOUNTS {
if accounts.len() < Self::MIN_ACCOUNTS {
return Err(ProtocolError::InvalidAccountsLength);
}
#[allow(clippy::ptr_offset_with_cast)]
let (fixed_accounts, other_accounts) = array_refs![accounts, 5; ..;];

let &[
ref swap_info_acc,
ref authority_acc,
ref token_a_acc,
ref token_b_acc,
ref admin_fee_acc,
ref clock_sysvar_acc,
ref program_acc,
]: &'a[AccountInfo<'b>; MIN_ACCOUNTS] = array_ref![accounts, 0, MIN_ACCOUNTS];
//ref clock_sysvar_acc,
//ref program_acc,
]: &'a[AccountInfo<'b>; 5] = array_ref![fixed_accounts, 0, 5];

let program_acc = if other_accounts.len() == 1 {
other_accounts.get(0).unwrap()
} else {
other_accounts.get(1).unwrap()
};

let swap_info = StableSwapInfo::new(swap_info_acc)?;

Expand Down Expand Up @@ -137,7 +146,6 @@ impl<'a, 'b: 'a> StableSwapArgs<'a, 'b> {
token_a: TokenAccount::new(token_a_acc)?,
token_b: TokenAccount::new(token_b_acc)?,
admin_fee_acc,
clock_sysvar_acc: SysClockAccount::new(clock_sysvar_acc)?,
program_acc,
})
}
Expand Down
11 changes: 5 additions & 6 deletions src/program-rust/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl Processor {
&user_args.token_destination_account,
user_args.source_account_owner,
&spl_token_program,
accounts,
other_accounts,
),
ExchangerType::AldrinExchange => Self::process_step_aldrin_exchange(
program_id,
Expand All @@ -377,7 +377,7 @@ impl Processor {
&user_args.token_destination_account,
user_args.source_account_owner,
&spl_token_program,
accounts,
other_accounts,
),
ExchangerType::CropperFinance => Self::process_step_cropper_finance(
program_id,
Expand All @@ -387,7 +387,7 @@ impl Processor {
&user_args.token_destination_account,
user_args.source_account_owner,
&spl_token_program,
accounts,
other_accounts,
),
}?;
let from_amount_after = user_args.token_source_account.balance()?;
Expand Down Expand Up @@ -1144,7 +1144,7 @@ impl Processor {
/// Step swap in spl-token-swap
#[allow(clippy::too_many_arguments)]
fn process_step_stableswap<'a, 'b: 'a>(
program_id: &Pubkey,
_program_id: &Pubkey,
amount_in: u64,
minimum_amount_out: u64,
source_token_account: &TokenAccount<'a, 'b>,
Expand Down Expand Up @@ -1187,12 +1187,11 @@ impl Processor {
destination_token_account.inner().clone(),
swap_args.admin_fee_acc.clone(),
spl_token_program.inner().clone(),
swap_args.clock_sysvar_acc.inner().clone(),
swap_args.program_acc.clone(),
];

let instruction = stable_swap::instruction::swap(
program_id,
swap_args.program_acc.key,
spl_token_program.inner().key,
swap_args.swap_info.inner().key,
swap_args.authority_acc.key,
Expand Down

0 comments on commit 16d7eb2

Please sign in to comment.