Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit tests in tests directory, improve market new params #4

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.2
current_version = 0.0.3

[bumpversion:file:Cargo.toml]
search = 'version = "{current_version}"'
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openbook"
version = "0.0.2"
version = "0.0.3"
edition = "2021"
description = "📖 A CLI and library for interacting with the OpenBook market on the Solana blockchain."
license = "MIT"
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ Before using the `openbook` crate or CLI, make sure to set the following environ
```bash
export RPC_URL=https://api.mainnet-beta.solana.com
export KEY_PATH=<path_to_your_key_file>
export MARKET_ID=8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6
export OPENBOOK_V1_PROGRAM_ID=srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX
```

> [!NOTE]
> Certain RPC methods, like `getProgramAccounts`, are no longer available on `api.mainnet-beta.solana.com`. We recommend utilizing [helius.dev](https://www.helius.dev) as an alternative.

## ⌨ Usage as CLI

### Get Market Info:

```sh
openbook info
```

### Place a limit bid:

```sh
Expand Down
32 changes: 1 addition & 31 deletions src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use solana_sdk::pubkey::Pubkey;
/// # Examples
///
/// ```rust
/// use solana_sdk::pubkey::Pubkey;
/// use openbook::pubkey::Pubkey;
/// use openbook::fees::supports_srm_fee_discounts;
///
/// let program_id = Pubkey::new_unique();
Expand Down Expand Up @@ -99,33 +99,3 @@ pub fn get_fee_tier(msrm_balance: f64, srm_balance: f64) -> u32 {
0
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_supports_srm_fee_discounts() {
let program_id = Pubkey::new_unique();
assert!(supports_srm_fee_discounts(&program_id));
}

#[test]
fn test_get_fee_rates() {
assert_eq!(get_fee_rates(1), (0.002, -0.0003));
assert_eq!(get_fee_rates(3), (0.0016, -0.0003));
assert_eq!(get_fee_rates(6), (0.001, -0.0005));
assert_eq!(get_fee_rates(7), (0.0022, -0.0003));
}

#[test]
fn test_get_fee_tier() {
assert_eq!(get_fee_tier(1.5, 0.0), 6);
assert_eq!(get_fee_tier(0.0, 1_000_001.0), 5);
assert_eq!(get_fee_tier(0.0, 100_001.0), 4);
assert_eq!(get_fee_tier(0.0, 10_001.0), 3);
assert_eq!(get_fee_tier(0.0, 1_001.0), 2);
assert_eq!(get_fee_tier(0.0, 101.0), 1);
assert_eq!(get_fee_tier(0.0, 0.0), 0);
}
}
12 changes: 1 addition & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
//! ```bash
//! export RPC_URL=https://api.mainnet-beta.solana.com
//! export KEY_PATH=<path_to_your_key_file>
//! export MARKET_ID=8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6
//! export OPENBOOK_V1_PROGRAM_ID=srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX
//! ```
//!
//! Get started with the `openbook` crate by following these simple steps:
Expand All @@ -33,20 +31,12 @@
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let rpc_url = std::env::var("RPC_URL").expect("RPC_URL is not set in .env file");
//! let key_path = std::env::var("KEY_PATH").expect("KEY_PATH is not set in .env file");
//! let market_address = std::env::var("MARKET_ID")
//! .expect("MARKET_ID is not set in .env file")
//! .parse()
//! .unwrap();
//! let program_id = std::env::var("OPENBOOK_V1_PROGRAM_ID")
//! .expect("OPENBOOK_V1_PROGRAM_ID is not set in .env file")
//! .parse()
//! .unwrap();
//!
//! let rpc_client = RpcClient::new(rpc_url);
//!
//! let keypair = read_keypair(&key_path);
//!
//! let mut market = Market::new(rpc_client, program_id, market_address, keypair).await;
//! let mut market = Market::new(rpc_client, 3, "openbook", keypair).await;
//!
//! println!("Initialized Market: {:?}", market);
//!
Expand Down
10 changes: 1 addition & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let rpc_url = std::env::var("RPC_URL").expect("RPC_URL is not set");
let key_path = std::env::var("KEY_PATH").expect("KEY_PATH is not set");
let market_address = std::env::var("MARKET_ID")
.expect("MARKET_ID is not set")
.parse()
.unwrap();
let program_id = std::env::var("OPENBOOK_V1_PROGRAM_ID")
.unwrap_or("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX".to_string())
.parse()
.unwrap();

let args = Cli::parse();

Expand All @@ -32,7 +24,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let keypair = read_keypair(&key_path);

let mut market = Market::new(rpc_client, program_id, market_address, keypair).await;
let mut market = Market::new(rpc_client, 3, "openbook", keypair).await;

match args.command {
Some(Commands::Info(_)) => {
Expand Down
Loading