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

Feat/675 on chain ouis devaddrs #431

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6060787
Move SubDao::dc_key() -> Dao::dc_key()
michaeldjeffrey Aug 1, 2024
8cae4db
Add `dc::burn_delegated` function
michaeldjeffrey Aug 1, 2024
58cf64b
add helper for going from solana keypair to wrapped helium-lib keypair
michaeldjeffrey Aug 2, 2024
d2bf60c
Add boosting module, function for starting hex boost
michaeldjeffrey Aug 2, 2024
b1734cc
merge imports
michaeldjeffrey Oct 22, 2024
c755093
add Io error to encode error when attempting to write a keypair
michaeldjeffrey Oct 22, 2024
bd87fdd
Move ReadWrite trait to helium-lib
michaeldjeffrey Oct 22, 2024
db7f998
remove after bad merge
michaeldjeffrey Oct 22, 2024
2031f39
update to use new dc_key location
michaeldjeffrey Oct 22, 2024
b2f4780
remove useless ? and Ok
michaeldjeffrey Oct 22, 2024
7a67eed
move ReadWrite back to wallet. avoid file io in helium-lib
michaeldjeffrey Oct 22, 2024
e827eeb
upgrade spl-account-compression to version compatible with anchor-lan…
michaeldjeffrey Oct 23, 2024
dc47049
move back to anchor-lang 0.29
michaeldjeffrey Oct 23, 2024
040fc93
update helium-anchor-gen with looser dep around anchor-client
michaeldjeffrey Oct 23, 2024
0e750c9
go back to master helium-anchor-gen that has updated anchor-lang >=0.28
michaeldjeffrey Oct 23, 2024
9ee2bb8
wip moving iot_routing_manager sdk here
bryzettler Oct 30, 2024
3b38d76
Pdas and instructions creators for iot_routing_manager plus a refactor
bryzettler Nov 1, 2024
74c9d34
added update org
bryzettler Nov 4, 2024
381423a
move config key to hem
bryzettler Nov 4, 2024
1e6ee06
Us as_ref for solana client
bryzettler Nov 4, 2024
3f245d4
added send instructions and restructured sol transaction utils
bryzettler Nov 5, 2024
3b7f815
structure client better
bryzettler Nov 6, 2024
1ea9ba3
add wrapper fn for getting the SolanaRpcClient
bryzettler Nov 6, 2024
02d5791
.
bryzettler Nov 6, 2024
3abf8a9
added wallet/payer logic to solana_client
bryzettler Nov 6, 2024
e14d61a
Pass tpu helium-lib
bryzettler Nov 6, 2024
174b779
add AsRef for SolanaClient
bryzettler Nov 7, 2024
3d10078
Building
bryzettler Nov 7, 2024
3b2249d
bump bubblegum
bryzettler Nov 7, 2024
0a36e98
wip
bryzettler Nov 11, 2024
b5ababb
Fix logic for existing account
bryzettler Nov 20, 2024
7d558b4
Merge branch 'master' into feat/675-on-chain-ouis-devaddrs
bryzettler Dec 5, 2024
0623a99
Fix errors after merging master
bryzettler Dec 5, 2024
c8a587f
testing
bryzettler Dec 6, 2024
d4ef2c9
remove cargo patches
bryzettler Dec 6, 2024
ca0308c
self review
bryzettler Dec 6, 2024
c9431ea
remove unused priority_fee
bryzettler Dec 10, 2024
e79b802
pr feedback
bryzettler Dec 10, 2024
7557c35
fold helium_sub_daos back into dao
bryzettler Dec 18, 2024
9c907a8
fold helium_entity_manger back into dao/asset
bryzettler Dec 18, 2024
4642b8f
Use dao/asset in iot
bryzettler Dec 18, 2024
8fde91e
update refrences of helium_entity_manger
bryzettler Dec 19, 2024
fbdf4d3
PR feedback
bryzettler Dec 19, 2024
25147f3
fix
bryzettler Dec 20, 2024
d46f7e9
Merge branch 'master' into feat/675-on-chain-ouis-devaddrs
bryzettler Dec 20, 2024
2527773
fold metaplex into asset
bryzettler Jan 14, 2025
0dd0e45
pr feedback
bryzettler Jan 14, 2025
16239b5
remove refrences to tpu
bryzettler Jan 15, 2025
fb7c2c4
pr feedback tweaks
bryzettler Jan 15, 2025
4d8ea0f
fix compute budget estimate
bryzettler Jan 17, 2025
a62acdb
unpatch crates
bryzettler Jan 17, 2025
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 Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ helium-crypto = { version = "0.8" }
helium-proto = { git = "https://github.com/helium/proto", branch = "master", features = [
"services",
] }
clap = { version = "4", features = ["derive"] }
clap = { version = "4", features = ["derive"] }
4 changes: 2 additions & 2 deletions helium-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ serde = {workspace = true}
serde_json = {workspace = true}
lazy_static = "1"
rust_decimal = {workspace = true}
helium-proto = {workspace= true}
helium-proto = {workspace = true}
angry-purple-tiger = "0"
sha2 = {workspace = true}
clap = {workspace = true, optional = true}
helium-mnemonic = { path = "../helium-mnemonic", optional = true }

[dev-dependencies]
rand = "0.8"
rand = "0.8"
9 changes: 9 additions & 0 deletions helium-lib/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, result::Result as StdResult, str::FromStr};

pub fn shared_merkle_key(proof_size: u8) -> Pubkey {
Pubkey::find_program_address(
&[b"shared_merkle", &[proof_size]],
&helium_entity_manager::ID,
)
.0
}

pub async fn for_entity_key<E, C: AsRef<DasClient>>(
client: &C,
entity_key: &E,
Expand Down Expand Up @@ -53,6 +61,7 @@ pub async fn get_with_proof<C: AsRef<DasClient>>(
let (asset, asset_proof) = futures::try_join!(get(client, pubkey), proof::get(client, pubkey))?;
Ok((asset, asset_proof))
}

pub mod canopy {
use super::*;
use spl_account_compression::state::{merkle_tree_get_size, ConcurrentMerkleTreeHeader};
Expand Down
148 changes: 104 additions & 44 deletions helium-lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ use crate::{
asset,
error::{DecodeError, Error},
is_zero,
keypair::{self, Pubkey},
keypair::{self, Keypair, Pubkey},
solana_client,
solana_sdk::{commitment_config::CommitmentConfig, signer::Signer},
};

use futures::{stream, StreamExt, TryStreamExt};
use itertools::Itertools;
use jsonrpc_client::{JsonRpcError, SendRequest};
use std::{marker::Send, sync::Arc};
use tracing::instrument;

pub use solana_client::nonblocking::rpc_client::RpcClient as SolanaRpcClient;

pub static ONBOARDING_URL_MAINNET: &str = "https://onboarding.dewi.org/api/v3";
pub static ONBOARDING_URL_DEVNET: &str = "https://onboarding.web.test-helium.com/api/v3";

Expand All @@ -23,17 +27,104 @@ pub static SOLANA_URL_DEVNET: &str = "https://solana-rpc.web.test-helium.com?ses
pub static SOLANA_URL_MAINNET_ENV: &str = "SOLANA_MAINNET_URL";
pub static SOLANA_URL_DEVNET_ENV: &str = "SOLANA_DEVNET_URL";

pub use solana_client::nonblocking::rpc_client::RpcClient as SolanaRpcClient;
static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);

#[derive(Clone)]
pub struct SolanaClient {
pub inner: Arc<SolanaRpcClient>,
pub base_url: String,
pub wallet: Option<Arc<Keypair>>,
bryzettler marked this conversation as resolved.
Show resolved Hide resolved
}

impl Default for SolanaClient {
fn default() -> Self {
// safe to unwrap
Self::new(SOLANA_URL_MAINNET, None).unwrap()
}
}

impl SolanaClient {
pub fn new(url: &str, wallet: Option<Arc<Keypair>>) -> Result<Self, Error> {
let client = Arc::new(
solana_client::nonblocking::rpc_client::RpcClient::new_with_commitment(
url.to_string(),
CommitmentConfig::finalized(),
),
);

Ok(Self {
inner: client,
base_url: url.to_string(),
wallet,
})
}

pub fn ws_url(&self) -> String {
self.base_url
.replace("https", "wss")
.replace("http", "ws")
.replace("127.0.0.1:8899", "127.0.0.1:8900")
}

pub fn pubkey(&self) -> Result<Pubkey, Error> {
self.wallet
bryzettler marked this conversation as resolved.
Show resolved Hide resolved
.as_ref()
.map(|wallet| wallet.pubkey())
.ok_or_else(|| Error::WalletUnconfigured)
}
}

#[derive(Clone)]
pub struct Client {
pub solana_client: Arc<SolanaRpcClient>,
pub solana_client: Arc<SolanaClient>,
pub das_client: Arc<DasClient>,
}

impl TryFrom<&str> for Client {
type Error = Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
fn env_or(key: &str, default: &str) -> String {
std::env::var(key).unwrap_or_else(|_| default.to_string())
}
let url = match value {
"m" | "mainnet-beta" => &env_or(SOLANA_URL_MAINNET_ENV, SOLANA_URL_MAINNET),
"d" | "devnet" => &env_or(SOLANA_URL_DEVNET_ENV, SOLANA_URL_DEVNET),
url => url,
};
let das_client = Arc::new(DasClient::with_base_url(url)?);
let solana_client = Arc::new(SolanaClient::new(url, None)?);

Ok(Self {
solana_client,
das_client,
})
}
}

impl AsRef<SolanaRpcClient> for SolanaClient {
fn as_ref(&self) -> &SolanaRpcClient {
&self.inner
}
}

impl AsRef<SolanaRpcClient> for Client {
fn as_ref(&self) -> &SolanaRpcClient {
&self.solana_client.inner
}
}

impl AsRef<DasClient> for Client {
fn as_ref(&self) -> &DasClient {
&self.das_client
}
}

#[async_trait::async_trait]
pub trait GetAnchorAccount {
async fn anchor_account<T: AccountDeserialize>(&self, pubkey: &Pubkey) -> Result<T, Error>;
async fn anchor_account<T: AccountDeserialize>(
&self,
pubkey: &Pubkey,
) -> Result<Option<T>, Error>;
async fn anchor_accounts<T: AccountDeserialize + Send>(
&self,
pubkeys: &[Pubkey],
Expand All @@ -42,18 +133,21 @@ pub trait GetAnchorAccount {

#[async_trait::async_trait]
impl GetAnchorAccount for SolanaRpcClient {
async fn anchor_account<T: AccountDeserialize>(&self, pubkey: &Pubkey) -> Result<T, Error> {
async fn anchor_account<T: AccountDeserialize>(
&self,
pubkey: &Pubkey,
) -> Result<Option<T>, Error> {
let account = self.get_account(pubkey).await?;
let decoded = T::try_deserialize(&mut account.data.as_ref())?;
Ok(decoded)
Ok(Some(decoded))
}

async fn anchor_accounts<T: AccountDeserialize + Send>(
&self,
pubkeys: &[Pubkey],
) -> Result<Vec<Option<T>>, Error> {
async fn get_accounts<A: AccountDeserialize + Send>(
client: &SolanaRpcClient,
client: &solana_client::nonblocking::rpc_client::RpcClient,
pubkeys: &[Pubkey],
) -> Result<Vec<Option<A>>, Error> {
let accounts = client.get_multiple_accounts(pubkeys).await?;
Expand Down Expand Up @@ -86,46 +180,14 @@ impl GetAnchorAccount for Client {
async fn anchor_account<T: AccountDeserialize>(
&self,
pubkey: &keypair::Pubkey,
) -> Result<T, Error> {
self.solana_client.anchor_account(pubkey).await
) -> Result<Option<T>, Error> {
self.solana_client.inner.anchor_account(pubkey).await
}
async fn anchor_accounts<T: AccountDeserialize + Send>(
&self,
pubkeys: &[Pubkey],
) -> Result<Vec<Option<T>>, Error> {
self.solana_client.anchor_accounts(pubkeys).await
}
}

impl TryFrom<&str> for Client {
type Error = Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
fn env_or(key: &str, default: &str) -> String {
std::env::var(key).unwrap_or_else(|_| default.to_string())
}
let url = match value {
"m" | "mainnet-beta" => &env_or(SOLANA_URL_MAINNET_ENV, SOLANA_URL_MAINNET),
"d" | "devnet" => &env_or(SOLANA_URL_DEVNET_ENV, SOLANA_URL_DEVNET),
url => url,
};
let das_client = Arc::new(DasClient::with_base_url(url)?);
let solana_client = Arc::new(SolanaRpcClient::new(url.to_string()));
Ok(Self {
solana_client,
das_client,
})
}
}

impl AsRef<SolanaRpcClient> for Client {
fn as_ref(&self) -> &SolanaRpcClient {
&self.solana_client
}
}

impl AsRef<DasClient> for Client {
fn as_ref(&self) -> &DasClient {
&self.das_client
self.solana_client.inner.anchor_accounts(pubkeys).await
}
}

Expand Down Expand Up @@ -199,8 +261,6 @@ impl DasClientError {
#[jsonrpc_client::api]
pub trait DAS {}

static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);

#[jsonrpc_client::implement(DAS)]
#[derive(Debug, Clone)]
pub struct DasClient {
Expand Down
Loading
Loading