Skip to content

Commit

Permalink
feat: auto generate open order accounts, use enums instead of static…
Browse files Browse the repository at this point in the history
… values, display wallet info along with market info in tui mode, improve docs, serialize/deserialize `MarketInfo`, graceful error handling (#10)

* feat: auto generate open order accounts, use enums instead of static values, display wallet info along with market info in tui mode, improve docs, serialize/deserialize `MarketInfo`, graceful error handling

* Bump version: 0.0.10 → 0.0.11

* feat: add circleci badge

* fix: use open order account from env var if set

* fix: update README.md
  • Loading branch information
wiseaidev authored May 3, 2024
1 parent 335ba00 commit 398cd88
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 335 deletions.
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.10
current_version = 0.0.11

[bumpversion:file:Cargo.toml]
search = 'version = "{current_version}"'
Expand Down
72 changes: 70 additions & 2 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openbook"
version = "0.0.10"
version = "0.0.11"
edition = "2021"
description = "📖 A CLI, TUI and SDK to interact with the OpenBook market on the Solana blockchain (WIP)."
license = "MIT"
Expand Down Expand Up @@ -31,7 +31,6 @@ pyth-sdk-solana = "0.10.0"
memoffset = "0.9.0"
borsh = "1.3.1"
serde_json = "1.0.114"
log = "0.4.21"
tokio = { version = "1.36.0", features = ["full"] }
spl-associated-token-account = "=2.3.0"
solana-account-decoder = "=1.18.6"
Expand All @@ -45,9 +44,11 @@ serde = { version = "1.0.200", features = ["derive"], optional = true }
crossterm = { version = "0.27.0", optional = true }
unicode-width = { version = "0.1.12", optional = true }
strum = { version = "0.26.2", optional = true }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["std"], optional = true }

[features]
cli = ["clap", "solana-cli-output", "ratatui", "tui-input", "serde", "crossterm", "unicode-width", "strum"]
cli = ["clap", "solana-cli-output", "ratatui", "tui-input", "serde", "crossterm", "unicode-width", "strum", "tracing-subscriber"]

[dev-dependencies]
bump2version = "0.1.3"
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# 📖 OpenBook

[![CircleCI](https://dl.circleci.com/status-badge/img/gh/gigadao/openbook/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/gigadao/openbook/tree/master)
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/GigaDAO/openbook/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/GigaDAO/openbook/tree/master)
[![Crates.io](https://img.shields.io/crates/v/openbook.svg)](https://crates.io/crates/openbook)
[![Crates.io Downloads](https://img.shields.io/crates/d/openbook)](https://crates.io/crates/openbook)
[![docs](https://docs.rs/openbook/badge.svg)](https://docs.rs/openbook/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

![Banner](https://github.com/GigaDAO/openbook/assets/62179149/ed83a9a8-4b8d-421d-be31-8eea73529444)

📖 A CLI, TUI and SDK to interact with the OpenBook market on the Solana blockchain.

> [!WARNING]
Expand Down Expand Up @@ -51,9 +54,6 @@ export RPC_URL=https://api.mainnet-beta.solana.com
export KEY_PATH=<path_to_your_key_file>
```

> [!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 TUI

https://github.com/GigaDAO/openbook/assets/62179149/23b411ac-243c-4f89-b8a2-fcc021eb9fdd
Expand All @@ -63,7 +63,7 @@ openbook tui
```

> [!NOTE]
> To interact with the openbook market by placing bids or asking, you'll need to set up an open order account for your wallet. In future releases, this crate will automatically fetch your associated open order account. However, for now, if you already have one, you'll need to set up this environment variable before launching the tui:
> To trade on the openbook market, you need an open order account. This current release of this crate generates one for your wallet, but it's empty. You'll have to add funds to it. In the future, you can add funds through the TUI. But, if you already have funds in your open order account, set up this variable before starting the TUI:
```sh
export OOS_KEY=<your_associated_oo_sol_account>
Expand Down Expand Up @@ -147,16 +147,17 @@ openbook consume-permissioned --limit 2

```toml
[dependencies]
openbook = "0.0.10"
openbook = "0.0.11"
```

```rust
use openbook::{pubkey::Pubkey, signature::Keypair, rpc_client::RpcClient};
use openbook::{pubkey::Pubkey, rpc_client::RpcClient};
use openbook::market::Market;
use openbook::utils::read_keypair;
use openbook::matching::Side;
use openbook::commitment_config::CommitmentConfig;
use openbook::market::OrderReturnType;
use openbook::tokens_and_markets::{Token, DexVersion};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -168,18 +169,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let keypair = read_keypair(&key_path);

let mut market = Market::new(rpc_client, 3, "jlp", "usdc", keypair, true).await;
let mut market = Market::new(rpc_client, DexVersion::default(), Token::JLP, Token::USDC, keypair, true).await?;

println!("Initialized Market: {:?}", market);

println!("[*] Place Limit Order");
if let Some(ord_ret_type) = market
.place_limit_order(
10.0,
0.1,
Side::Bid, // or Side::Ask
0.5,
0.1,
true,
15.0,
2.0,
)
.await?
{
Expand Down
2 changes: 1 addition & 1 deletion src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use solana_sdk::pubkey::Pubkey;
/// assert_eq!(is_supported, true);
/// ```
pub fn supports_srm_fee_discounts(program_id: &Pubkey) -> bool {
get_layout_version(program_id) > 1
get_layout_version(program_id) as u64 > 0
}

/// Gets the fee rates for a given fee tier.
Expand Down
39 changes: 36 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use anyhow::Result;

/// The entry point for the OpenBook CLI application.
///
/// # Returns
Expand All @@ -15,14 +17,29 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
use openbook::matching::Side;
use openbook::rpc_client::RpcClient;
use openbook::signature::Signer;
use openbook::tokens_and_markets::{DexVersion, Token};
use openbook::tui::run_tui;
use openbook::utils::read_keypair;
use solana_cli_output::display::println_transaction;
use tracing_subscriber::{filter, fmt};

// Start configuring a `fmt` subscriber
let filter = filter::LevelFilter::INFO;
let subscriber = fmt()
.compact()
.with_max_level(filter)
.with_file(false)
.with_line_number(false)
.with_thread_ids(false)
.with_target(false)
.finish();
tracing::subscriber::set_global_default(subscriber)?;

let args = Cli::parse();
let mut market;

let rpc_url = std::env::var("RPC_URL").unwrap_or("".to_string());
let rpc_url =
std::env::var("RPC_URL").unwrap_or("https://api.mainnet-beta.solana.com".to_string());
let key_path = std::env::var("KEY_PATH").unwrap_or("".to_string());

let commitment_config = CommitmentConfig::confirmed();
Expand All @@ -32,9 +49,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

assert_eq!(rpc_client.commitment(), CommitmentConfig::confirmed());
if args.command == Some(Commands::Tui) {
market = Market::new(rpc_client, 3, "jlp", "usdc", owner, false).await;
market = Market::new(
rpc_client,
DexVersion::default(),
Token::JLP,
Token::USDC,
owner,
false,
)
.await?;
} else {
market = Market::new(rpc_client, 3, "jlp", "usdc", owner, true).await;
market = Market::new(
rpc_client,
DexVersion::default(),
Token::JLP,
Token::USDC,
owner,
true,
)
.await?;
}

match args.command {
Expand Down
Loading

0 comments on commit 398cd88

Please sign in to comment.