Skip to content

Commit

Permalink
increase version (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsource147 authored Sep 26, 2023
1 parent 9ea0504 commit c590d6b
Show file tree
Hide file tree
Showing 23 changed files with 1,737 additions and 2,762 deletions.
3,316 changes: 1,684 additions & 1,632 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions programs/vault/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mercurial-vault"
version = "0.4.7"
version = "0.5.0"
description = "Created with Anchor"
edition = "2018"
license = "MIT"
Expand All @@ -24,12 +24,12 @@ no-capture = []

[dependencies]
serde = { version = "1.0.136" }
anchor-lang = "0.26.0"
anchor-spl = "0.26.0"
anchor-lang = "0.28.0"
anchor-spl = "0.28.0"

[dev-dependencies]
solana-program-test = "~1.14.12"
solana-program-test = "1.14.12"
assert_matches = "1.5.0"
async-trait = "0.1.52"
solana-sdk = "~1.14.12"
solana-sdk = "1.14.12"
spl-associated-token-account = { version = "1.1.2", features = ["no-entrypoint"] }
Binary file modified programs/vault/tests/fixtures/vault.so
Binary file not shown.
45 changes: 12 additions & 33 deletions programs/vault/tests/helpers/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,41 @@ pub async fn initialize_vault(
admin: &Keypair,
banks_client: &mut BanksClient,
) -> Vault {
let base = Keypair::new();
let (vault, vault_bump) =
mercurial_vault::utils::derive_vault_address(token_mint, base.pubkey());
let base = mercurial_vault::get_base_key();
let (vault, vault_bump) = mercurial_vault::utils::derive_vault_address(token_mint, base);

let (token_vault, token_vault_bump) = mercurial_vault::utils::derive_token_vault_address(vault);

let token_mint_state = get_mint_account(&token_mint, banks_client).await;

let lp_mint = Keypair::new();

initialize_mint(
admin,
&lp_mint,
&vault,
token_mint_state.decimals,
banks_client,
)
.await;

// create fee vault as admin authority
let fee_vault = spl_associated_token_account::get_associated_token_address(
&mercurial_vault::get_treasury_address(),
&lp_mint.pubkey(),
let (lp_mint, _bump) = Pubkey::find_program_address(
&[
mercurial_vault::seed::LP_MINT_PREFIX.as_ref(),
vault.as_ref(),
],
&mercurial_vault::id(),
);
create_associated_token_account(
admin,
&lp_mint.pubkey(),
&mercurial_vault::get_treasury_address(),
banks_client,
)
.await;

let init_vault_ins = Instruction {
program_id: mercurial_vault::id(),
accounts: mercurial_vault::accounts::Initialize {
base: base.pubkey(),
vault,
admin: admin.pubkey(),
token_vault,
token_mint,
fee_vault,
lp_mint: lp_mint.pubkey(),
lp_mint,
system_program: system_program::id(),
rent: sysvar::rent::ID,
payer: admin.pubkey(),
token_program: spl_token::id(),
}
.to_account_metas(None),
data: mercurial_vault::instruction::Initialize {}.data(),
};

process_and_assert_ok(&[init_vault_ins], admin, &[admin, &base], banks_client).await;
process_and_assert_ok(&[init_vault_ins], admin, &[admin], banks_client).await;

Vault {
pubkey: vault,
token_vault: token_vault,
lp_mint: lp_mint.pubkey(),
lp_mint,
}
}

Expand Down
20 changes: 6 additions & 14 deletions rust-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
[package]
name = "rust-client"
version = "0.4.2"
version = "0.5.0"
edition = "2018"

[features]
devnet = []

[dependencies]
anchor-lang = {version = "0.26.0"}
anchor-spl = {version = "0.26.0"}
anchor-client = {version = "0.26.0"}
anchor-lang = {version = "0.28.0"}
anchor-spl = {version = "0.28.0"}
anchor-client = {version = "0.28.0"}
anyhow = "1.0"
clap = {version = "3.0.10", features=["derive"]}
mercurial-vault = { path = "../programs/vault", features = ["cpi"] }
shellexpand = "2.1.0"
spl-associated-token-account = { version = "1.0.2", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "2.1.0", features = ["no-entrypoint"] }
rust_decimal="1.20.0"
port-variable-rate-lending-instructions = "0.3.0"
apricot-client = {git="https://github.com/mercurial-finance/apricot-client", rev="af66bdcb15cdd19612ceee78f6195668a984f4b4"}
solend-program = { git="https://github.com/mercurial-finance/solana-program-library", rev="bff3df14cab2dba01dce044bb6cfc0aa86ff45c3", features = [ "no-entrypoint" ] }
bincode = "^1.3.1"
tulipv2-sdk-common = { git = "https://github.com/mercurial-finance/tulipv2-sdk", rev="ed15cea625f370828488493c13e50555d047dff3"}
tulipv2-sdk-lending = { git = "https://github.com/mercurial-finance/tulipv2-sdk", rev="ed15cea625f370828488493c13e50555d047dff3"}
drift = { git="https://github.com/mercurial-finance/protocol-v2", features = ["cpi"], rev="18423fcb249c15f8b68f4739684dddd8797d2865" }
# Need to lock this because switchboard-program have relaxed dependency version on switchboard-utils. Cargo will automatically resolved it to 0.1.37 which as_bytes_mut function was removed. Ideally, this should be fixed by switchboard
# switchboard-utils = "=0.1.32"
bincode = "^1.3.1"
6 changes: 0 additions & 6 deletions rust-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,4 @@ SUBCOMMANDS:
../target/debug/rust-client deposit 100 --provider.token_mint So11111111111111111111111111111111111111112
../target/debug/rust-client withdraw 100 --provider.token_mint So11111111111111111111111111111111111111112
../target/debug/rust-client withdraw-from-strategy 100 8xmmL78qZnAGN9qkuYTPLppqC4kySm8VxCmEJo5avPHy --provider.token_mint So11111111111111111111111111111111111111112
../target/debug/rust-client withdraw-from-strategy 100 2e5yJK9Kp47aETTg1YzigbryvWTgGtNZpPhngQZ7em7h --provider.token_mint So11111111111111111111111111111111111111112
../target/debug/rust-client withdraw-from-strategy 100 56TtMh31Fsw7btcjBhYzPxnwAdw7oCYqCCFKbsQsMKKB --provider.token_mint So11111111111111111111111111111111111111112
```
53 changes: 16 additions & 37 deletions rust-client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod strategy_handler;
mod user;
mod utils;
use anchor_client::solana_sdk::commitment_config::CommitmentConfig;
use anchor_client::solana_sdk::pubkey::Pubkey;
use anchor_client::solana_sdk::signature::Signer;
use anchor_client::solana_sdk::signature::{read_keypair_file, Keypair};
use anchor_client::Client;
use anchor_client::Cluster;
Expand All @@ -12,13 +12,11 @@ use anyhow::Result;
use bincode::deserialize;
use clap::Parser;
use mercurial_vault::get_base_key;
use strategy_handler::base::get_strategy_handler;

use user::*;

use std::convert::TryFrom;
use std::ops::Deref;
use std::rc::Rc;
use std::str::FromStr;
use user::*;

#[derive(Default, Debug, Parser)]
pub struct ConfigOverride {
Expand Down Expand Up @@ -51,16 +49,8 @@ pub enum Command {

#[derive(Debug, Parser)]
pub enum UserCommand {
Deposit {
token_amount: u64,
},
Withdraw {
unmint_amount: u64,
},
WithdrawFromStrategy {
unmint_amount: u64,
strategy: Pubkey,
},
Deposit { token_amount: u64 },
Withdraw { unmint_amount: u64 },
}

#[derive(Parser)]
Expand All @@ -79,7 +69,7 @@ fn main() -> Result<()> {
};
let url = match opts.cfg_override.cluster {
Some(cluster) => cluster,
None => Cluster::Mainnet,
None => Cluster::Devnet,
};

let client = Client::new_with_options(
Expand All @@ -93,7 +83,7 @@ fn main() -> Result<()> {
None => mercurial_vault::id(),
};

let program_client = client.program(program_id);
let program_client = client.program(program_id)?;

let token_mint = match opts.cfg_override.token_mint {
Some(token_mint) => Pubkey::from_str(&token_mint).unwrap(),
Expand Down Expand Up @@ -123,29 +113,16 @@ fn main() -> Result<()> {
UserCommand::Withdraw { unmint_amount } => {
withdraw(&program_client, token_mint, base, unmint_amount)?
}
UserCommand::WithdrawFromStrategy {
unmint_amount,
strategy,
} => {
let strategy_state: mercurial_vault::state::Strategy =
program_client.account(strategy)?;

let strategy_handler = get_strategy_handler(strategy_state.strategy_type);
strategy_handler.withdraw_directly_from_strategy(
&program_client,
strategy,
token_mint,
base,
unmint_amount,
)?
}
},
};

Ok(())
}

fn show(program_client: &anchor_client::Program, vault: Pubkey) -> Result<()> {
fn show<C: Deref<Target = impl Signer> + Clone>(
program_client: &anchor_client::Program<C>,
vault: Pubkey,
) -> Result<()> {
let vault_data: mercurial_vault::state::Vault = program_client.account(vault)?;
println!("VAULT DATA: {:#?}", vault_data);
let token_mint: anchor_spl::token::Mint = program_client.account(vault_data.lp_mint)?;
Expand Down Expand Up @@ -180,16 +157,18 @@ fn show(program_client: &anchor_client::Program, vault: Pubkey) -> Result<()> {
Ok(())
}

pub fn get_current_node_clock_time(program_client: &anchor_client::Program) -> Result<u64> {
pub fn get_current_node_clock_time<C: Deref<Target = impl Signer> + Clone>(
program_client: &anchor_client::Program<C>,
) -> Result<u64> {
let rpc = program_client.rpc();
let clock_account = rpc.get_account(&sysvar::clock::id())?;
let clock = deserialize::<Clock>(&clock_account.data)?;
let current_time = u64::try_from(clock.unix_timestamp)?;
Ok(current_time)
}

fn get_unlocked_amount(
program_client: &anchor_client::Program,
fn get_unlocked_amount<C: Deref<Target = impl Signer> + Clone>(
program_client: &anchor_client::Program<C>,
vault: Pubkey,
payer: &Keypair,
) -> Result<()> {
Expand Down
98 changes: 0 additions & 98 deletions rust-client/src/strategy_handler/apricot_without_lm.rs

This file was deleted.

Loading

0 comments on commit c590d6b

Please sign in to comment.