Removed common library dependency from mango program; Added ability to deposit into other users' accounts for reimbursements; Added settle borrow at end of deposit
This commit is contained in:
parent
fcfc26dba9
commit
141b10577b
|
@ -1,7 +1,7 @@
|
|||
anchor_version = "0.13.2"
|
||||
|
||||
[workspace]
|
||||
members = ["program", "common"]
|
||||
members = ["program"]
|
||||
|
||||
[provider]
|
||||
cluster = "mainnet"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,15 +6,15 @@ edition = "2018"
|
|||
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { version = "1.5.11", features=["default"] }
|
||||
spl-token = { version = "3.0.0", features=["no-entrypoint"] }
|
||||
anyhow = "1.0.35"
|
||||
solana-client = "1.5.11"
|
||||
rand = "0.7.3"
|
||||
serde_json = "1.0.60"
|
||||
solana-sdk = "^1.7.10"
|
||||
spl-token = { version = "^3.2.0", features=["no-entrypoint"] }
|
||||
anyhow = "^1.0.43"
|
||||
solana-client = "^1.7.10"
|
||||
rand = "0.8.4"
|
||||
serde_json = "^1.0.66"
|
||||
bs58 = "0.4.0"
|
||||
bincode = "1.3.1"
|
||||
bytemuck = "1.4.1"
|
||||
tiny-bip39 = "0.7.3"
|
||||
tiny-hderive = "0.2.1"
|
||||
bincode = "^1.3.1"
|
||||
bytemuck = "^1.7.2"
|
||||
tiny-bip39 = "0.8.0"
|
||||
tiny-hderive = "0.3.0"
|
||||
ed25519-dalek = "1.0.0-pre.4"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -22,7 +22,7 @@ static_assertions = "^1.1.0"
|
|||
thiserror = "^1.0.24"
|
||||
serde = "^1.0.118"
|
||||
bincode = "^1.3.1"
|
||||
serum_dex = { version = "^0.3", git = "https://github.com/blockworks-foundation/serum-dex.git", features=["no-entrypoint", "program"] }
|
||||
serum_dex = { version = "0.4.0", git = "https://github.com/blockworks-foundation/serum-dex.git", default-features=false, features = ["no-entrypoint", "program"] }
|
||||
|
||||
num-derive = "^0.3.3"
|
||||
flux-aggregator = { version = "^0.1", git = "https://github.com/blockworks-foundation/solana-flux-aggregator.git", features=["program", "no-entrypoint"] }
|
||||
|
@ -32,7 +32,6 @@ fixed-macro = "^1.1.1"
|
|||
[dev-dependencies]
|
||||
solana-sdk = "^1.6.4"
|
||||
solana-program-test = "^1.6.4"
|
||||
common = { version = "*", path = "../common" }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
|
@ -229,7 +229,6 @@ impl Processor {
|
|||
let clock = Clock::from_account_info(clock_acc)?;
|
||||
mango_group.update_indexes(&clock)?;
|
||||
|
||||
check_eq!(&margin_account.owner, owner_acc.key, MangoErrorCode::InvalidMarginAccountOwner)?;
|
||||
|
||||
let token_index = mango_group.get_token_index_with_vault(vault_acc.key).unwrap();
|
||||
check_eq_default!(&mango_group.vaults[token_index], vault_acc.key)?;
|
||||
|
@ -252,6 +251,7 @@ impl Processor {
|
|||
|
||||
let deposit: U64F64 = U64F64::from_num(quantity) / mango_group.indexes[token_index].deposit;
|
||||
checked_add_deposit(&mut mango_group, &mut margin_account, token_index, deposit)?;
|
||||
settle_borrow_full_unchecked(&mut mango_group, &mut margin_account, token_index)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,31 +1,30 @@
|
|||
#![cfg(feature="test-bpf")]
|
||||
|
||||
use std::mem::size_of;
|
||||
use std::convert::TryInto;
|
||||
use safe_transmute::{self, to_bytes::transmute_one_to_bytes};
|
||||
use std::mem::size_of;
|
||||
|
||||
use bytemuck::{bytes_of, Contiguous};
|
||||
use fixed::types::U64F64;
|
||||
use common::create_signer_key_and_nonce;
|
||||
use flux_aggregator::borsh_utils;
|
||||
use flux_aggregator::borsh_state::BorshState;
|
||||
use flux_aggregator::borsh_utils;
|
||||
use flux_aggregator::state::{Aggregator, AggregatorConfig, Answer};
|
||||
use safe_transmute::{self, to_bytes::transmute_one_to_bytes};
|
||||
use serum_dex::state::{AccountFlag, MarketState, ToAlignedBytes};
|
||||
use solana_program::program_option::COption;
|
||||
use solana_program::program_pack::Pack;
|
||||
use solana_program::pubkey::Pubkey;
|
||||
use solana_program_test::{ProgramTest, BanksClient};
|
||||
|
||||
use solana_program::pubkey::PubkeyError;
|
||||
use solana_program_test::{BanksClient, ProgramTest};
|
||||
use solana_sdk::{
|
||||
account_info::IntoAccountInfo,
|
||||
account::Account,
|
||||
account_info::IntoAccountInfo,
|
||||
instruction::Instruction,
|
||||
signature::{Keypair, Signer}
|
||||
};
|
||||
use spl_token::state::{Account as Token, AccountState, Mint};
|
||||
|
||||
use spl_token::state::{Mint, Account as Token, AccountState};
|
||||
use serum_dex::state::{MarketState, AccountFlag, ToAlignedBytes};
|
||||
|
||||
use mango::processor::srm_token;
|
||||
use mango::instruction::init_mango_group;
|
||||
use mango::processor::srm_token;
|
||||
use mango::state::MangoGroup;
|
||||
|
||||
pub const PRICE_BTC: u64 = 50000;
|
||||
|
@ -34,6 +33,30 @@ pub const PRICE_SOL: u64 = 30;
|
|||
pub const PRICE_SRM: u64 = 5;
|
||||
pub const PRICE_RAY: u64 = 5;
|
||||
|
||||
pub fn gen_signer_seeds<'a>(nonce: &'a u64, acc_pk: &'a Pubkey) -> [&'a [u8]; 2] {
|
||||
[acc_pk.as_ref(), bytes_of(nonce)]
|
||||
}
|
||||
|
||||
fn gen_signer_key(
|
||||
nonce: u64,
|
||||
acc_pk: &Pubkey,
|
||||
program_id: &Pubkey,
|
||||
) -> Result<Pubkey, PubkeyError> {
|
||||
let seeds = gen_signer_seeds(&nonce, acc_pk);
|
||||
Pubkey::create_program_address(&seeds, program_id)
|
||||
}
|
||||
|
||||
fn create_signer_key_and_nonce(program_id: &Pubkey, acc_pk: &Pubkey) -> (Pubkey, u64) {
|
||||
|
||||
for i in 0..=u64::MAX_VALUE {
|
||||
if let Ok(pk) = gen_signer_key(i, acc_pk, program_id) {
|
||||
return (pk, i);
|
||||
}
|
||||
}
|
||||
panic!("Could not generate signer key");
|
||||
|
||||
}
|
||||
|
||||
trait AddPacked {
|
||||
fn add_packable_account<T: Pack>(
|
||||
&mut self,
|
||||
|
|
Loading…
Reference in New Issue