Skip to content

Commit

Permalink
0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
googolmo committed Mar 15, 2022
1 parent 16d7eb2 commit 1a246d9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/program-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "onesol-protocol"
version = "0.4.0"
version = "0.4.1"
authors = ["croath <[email protected]>"]
edition = "2018"
exclude = ["js/**"]
Expand Down
8 changes: 5 additions & 3 deletions src/program-rust/src/parser/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
state::SwapInfo,
};
use arrayref::{array_ref, array_refs};
use solana_program::{account_info::AccountInfo, program_pack::Pack, pubkey::Pubkey, sysvar};
use solana_program::{account_info::AccountInfo, msg, program_pack::Pack, pubkey::Pubkey, sysvar};

declare_validated_account_wrapper!(SplTokenProgram, |account: &AccountInfo| {
if *account.key != spl_token::ID {
Expand Down Expand Up @@ -227,8 +227,10 @@ pub fn validate_authority_pubkey(
base_key: &[u8],
nonce: u8,
) -> Result<(), ProtocolError> {
let key = Pubkey::create_program_address(&[base_key, &[nonce]], program_id)
.map_err(|_| ProtocolError::InvalidProgramAddress)?;
let key = Pubkey::create_program_address(&[base_key, &[nonce]], program_id).map_err(|e| {
msg!("create_program_address failed: {}, nonce: {}", e, nonce);
ProtocolError::InvalidProgramAddress
})?;
if key != *authority {
return Err(ProtocolError::InvalidAuthority);
}
Expand Down
16 changes: 13 additions & 3 deletions src/program-rust/src/parser/crema.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use super::base::{validate_authority_pubkey, TokenAccount};
use super::base::TokenAccount;
use crate::{
declare_validated_account_wrapper,
error::{ProtocolError, ProtocolResult},
parser::base::validate_authority_pubkey,
};
use arrayref::array_ref;
use solana_program::{account_info::AccountInfo, pubkey::Pubkey};
use solana_program::{account_info::AccountInfo, msg, pubkey::Pubkey};

declare_validated_account_wrapper!(SwapInfoV1, |account: &AccountInfo| {
let account_data = account
Expand All @@ -20,12 +21,13 @@ declare_validated_account_wrapper!(SwapInfoV1, |account: &AccountInfo| {
});

impl<'a, 'b: 'a> SwapInfoV1<'a, 'b> {
#[allow(dead_code)]
pub fn nonce(self) -> ProtocolResult<u8> {
Ok(
self
.inner()
.try_borrow_data()
.map_err(|_| ProtocolError::BorrowAccountDataError)?[34],
.map_err(|_| ProtocolError::BorrowAccountDataError)?[35],
)
}

Expand Down Expand Up @@ -93,6 +95,13 @@ impl<'a, 'b: 'a> CremaSwapV1Args<'a, 'b> {
}
let swap_info = SwapInfoV1::new(swap_info_acc)?;
if !program_id.executable || *swap_info_acc.owner != *program_id.key {
msg!(
"program_id: {}, executable: {}, swap_info: {}, owner: {}",
program_id.key.to_string(),
program_id.executable,
swap_info_acc.key.to_string(),
swap_info_acc.owner.to_string(),
);
return Err(ProtocolError::InvalidProgramAddress);
}

Expand Down Expand Up @@ -191,5 +200,6 @@ WExa6Gae6euRW6eCcTw5Lf4F7y6PZxD3wek4uMrrHnURYHBkaumuCDiy1z3kbrv9R9RGsYT";
c.token_b_mint().unwrap().to_string(),
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".to_string()
);
assert_eq!(c.nonce().unwrap(), 254,);
}
}
1 change: 1 addition & 0 deletions src/program-rust/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ impl Processor {
accounts: &'a [AccountInfo<'b>],
) -> ProgramResult {
sol_log_compute_units();
msg!("process_step crema-finance");

let swap_args = CremaSwapV1Args::with_parsed_args(accounts)?;
let amount_in = Self::get_amount_in(amount_in, source_token_account.balance()?);
Expand Down

0 comments on commit 1a246d9

Please sign in to comment.