Skip to content

Commit

Permalink
Merge pull request #55 from helius-labs/dev
Browse files Browse the repository at this point in the history
[Merge] Dev -> Main
  • Loading branch information
0xIchigo authored Jun 21, 2024
2 parents 8859aa0 + 3652116 commit a38611d
Show file tree
Hide file tree
Showing 10 changed files with 551 additions and 53 deletions.
63 changes: 45 additions & 18 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,28 @@ jobs:
fetch-depth: '0'

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
run: |
timeout 10m bash -c "actions/cache@v3 \
with: \
path: ~/.cargo/registry \
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} \
restore-keys: ${{ runner.os }}-cargo-registry- || echo 'Cache registry step failed or timed out.'"
- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
run: |
timeout 10m bash -c "actions/cache@v3 \
with: \
path: ~/.cargo/git \
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} \
restore-keys: ${{ runner.os }}-cargo-index- || echo 'Cache index step failed or timed out.'"
- name: Cache target directory
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-target-${{ hashFiles('**/Cargo.lock') }}
run: |
timeout 10m bash -c "actions/cache@v3 \
with: \
path: target \
key: ${{ runner.os }}-target-${{ hashFiles('**/Cargo.lock') }} \
restore-keys: ${{ runner.os }}-target- || echo 'Cache target step failed or timed out.'"
- name: Set up Rust
uses: actions-rs/toolchain@v1
Expand All @@ -48,21 +54,42 @@ jobs:
profile: minimal
override: true
components: clippy

- name: Install Protobuf Compiler
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler


- name: Clean up disk space before build
run: |
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
df -h
- name: Check formatting
run: cargo fmt --all -- --check

- name: rust-clippy-check
uses: giraffate/clippy-action@v1
with:
reporter: 'github-pr-review'
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: 'github-pr-review'
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Build
run: cargo build --verbose


- name: Save build artifacts
uses: actions/upload-artifact@v2
with:
name: build
path: target

- name: Show disk usage after build
run: df -h

- name: Run tests
run: cargo test --verbose

- name: Show disk usage after tests
run: df -h
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helius"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
description = "An asynchronous Helius Rust SDK for building the future of Solana"
keywords = ["helius", "solana", "asynchronous-sdk", "das", "cryptocurrency"]
Expand All @@ -17,6 +17,8 @@ bincode = "1.3.3"
chrono = { version = "0.4.11", features = ["serde"] }
futures = "0.3.30"
futures-util = "0.3.30"
phf = { version = "0.11.2", features = ["macros"] }
rand = "0.8.5"
reqwest = { version = "0.12.3", features = ["json"] }
semver = "1.0.23"
serde = "1.0.198"
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Remember to run `cargo update` regularly to fetch the latest version of the SDK.

## Usage
### `Helius`
The SDK provides a [`Helius`](https://github.com/helius-labs/helius-rust-sdk/blob/dev/src/client.rs) instance that can be configured with an API key and a given Solana cluster. Developers can generate a new API key on the [Helius Developer Dashboard](https://dev.helius.xyz/dashboard/app). This instance acts as the main entry point for interacting with the SDK by providing methods to access different Solana and RPC client functionalities. The following code is an example of how to use the SDK to fetch info on [Mad Lad #8420](https://xray.helius.xyz/token/F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk?network=mainnet):
The SDK provides a [`Helius`](https://github.com/helius-labs/helius-rust-sdk/blob/dev/src/client.rs) instance that can be configured with an API key and a given Solana cluster. Developers can generate a new API key on the [Helius Developer Dashboard](https://dev.helius.xyz/dashboard/app). This instance acts as the main entry point for interacting with the SDK by providing methods to access different Solana and RPC client functionalities. The following code is an example of how to use the SDK to fetch info on [Mad Lad #8420](https://explorer.solana.com/address/F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk?network=mainnet):
```rust
use helius::error::Result;
use helius::types::{Cluster, DisplayOptions, GetAssetRequest, GetAssetResponseForAsset};
Expand All @@ -32,12 +32,7 @@ async fn main() -> Result<()> {

let request: GetAssetRequest = GetAssetRequest {
id: "F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk".to_string(),
display_options: Some(DisplayOptions {
show_unverified_collections: false,
show_collection_metadata: false,
show_fungible: false,
show_inscription: false,
}),
display_options: None,
};

let response: Result<Option<GetAssetResponseForAsset>> = helius.rpc().get_asset(request).await;
Expand Down Expand Up @@ -123,9 +118,17 @@ Our SDK is designed to provide a seamless developer experience when building on
- [`remove_addresses_from_webhook`](https://github.com/helius-labs/helius-rust-sdk/blob/bf24259e3333ae93126bb65b342c2c63e80e07a6/src/webhook.rs#L75-L105) - Removes a list of addresses from an existing webhook by its ID

### Smart Transactions
- [`create_smart_transaction`](https://github.com/helius-labs/helius-rust-sdk/blob/705d66fb7d4004fc32c2a5f0d6ca4a1f2a7b175d/src/optimized_transaction.rs#L113-L312) - Creates an optimized transaction based on the provided configuration
- [`get_compute_units`](https://github.com/helius-labs/helius-rust-sdk/blob/a79a751e1a064125010bdb359068a366d635d005/src/optimized_transaction.rs#L29-L75) - Simulates a transaction to get the total compute units consumed
- [`poll_transaction_confirmation`](https://github.com/helius-labs/helius-rust-sdk/blob/a79a751e1a064125010bdb359068a366d635d005/src/optimized_transaction.rs#L77-L112) - Polls a transaction to check whether it has been confirmed in 5 second intervals with a 15 second timeout
- [`send_smart_transaction`](https://github.com/helius-labs/helius-rust-sdk/blob/a79a751e1a064125010bdb359068a366d635d005/src/optimized_transaction.rs#L114-L332) - Builds and sends an optimized transaction, and handles its confirmation status
- [`send_smart_transaction`](https://github.com/helius-labs/helius-rust-sdk/blob/705d66fb7d4004fc32c2a5f0d6ca4a1f2a7b175d/src/optimized_transaction.rs#L314-L374) - Builds and sends an optimized transaction, and handles its confirmation status

### Jito Smart Transactions and Helper Methods
- [`add_tip_instruction`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L66-L83) - Adds a tip instruction to the instructions provided
- [`create_smart_transaction_with_tip`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L85-L124) - Creates a smart transaction with a Jito tip
- [`get_bundle_statuses`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L169-L202) - Get the status of Jito bundles
- [`send_jito_bundle`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L126-L167) - Sends a bundle of transactions to the Jito Block Engine
- [`send_smart_transaction_with_tip`](https://github.com/helius-labs/helius-rust-sdk/blob/02b351a5ee3fe16a36078b40f92dc72d0ad077ed/src/jito.rs#L204-L269) - Sends a smart transaction as a Jito bundle with a tip

### Helper Methods
- [`get_priority_fee_estimate`](https://docs.helius.dev/solana-rpc-nodes/alpha-priority-fee-api) - Gets an estimate of the priority fees required for a transaction to be processed more quickly
Expand Down
70 changes: 70 additions & 0 deletions examples/send_smart_transaction_with_tip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use helius::types::*;
use helius::Helius;
use solana_client::rpc_config::RpcSendTransactionConfig;
use solana_sdk::{
instruction::Instruction, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, signature::Keypair, signer::Signer,
system_instruction::transfer,
};
use std::str::FromStr;
use std::time::Duration;
use tokio::time::sleep;

#[tokio::main]
async fn main() {
let api_key: &str = "YOUR_API_KEY";
let cluster: Cluster = Cluster::MainnetBeta;
let helius: Helius = Helius::new(api_key, cluster).unwrap();

// Replace with your actual keypair
let from_keypair: Keypair = Keypair::new();
let from_pubkey: Pubkey = from_keypair.pubkey();

// Replace with the recipient's public key
let to_pubkey: Pubkey = Pubkey::from_str("RecipientPublicKeyHere").unwrap();

// Create a simple instruction (transfer 0.01 SOL from from_pubkey to to_pubkey)
let transfer_amount: u64 = 100_000; // 0.01 SOL in lamports
let instructions: Vec<Instruction> = vec![transfer(&from_pubkey, &to_pubkey, transfer_amount)];

let create_config: CreateSmartTransactionConfig = CreateSmartTransactionConfig {
instructions,
signers: vec![&from_keypair],
lookup_tables: None,
fee_payer: None,
};

let config: SmartTransactionConfig = SmartTransactionConfig {
create_config,
send_options: RpcSendTransactionConfig {
skip_preflight: true,
preflight_commitment: None,
encoding: None,
max_retries: None,
min_context_slot: None,
},
};

// Send the optimized transaction with a 10k lamport tip using the New York region's API URL
match helius
.send_smart_transaction_with_tip(config, Some(10000), Some("NY"))
.await
{
Ok(bundle_id) => {
println!("Transaction sent successfully: {}", bundle_id);
sleep(Duration::from_secs(5)).await;

// Get final balances
let balance_from = helius.connection().get_balance(&from_pubkey).unwrap_or(0);
println!(
"From Wallet Balance: {} SOL",
balance_from as f64 / LAMPORTS_PER_SOL as f64
);

let balance_to = helius.connection().get_balance(&to_pubkey).unwrap_or(0);
println!("To Wallet Balance: {} SOL", balance_to as f64 / LAMPORTS_PER_SOL as f64);
}
Err(e) => {
eprintln!("Failed to send transaction: {:?}", e);
}
}
}
Loading

0 comments on commit a38611d

Please sign in to comment.