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 hotspots transfer <hotspot_key> <recipient> command #372

Merged
merged 3 commits into from
Jun 10, 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
56 changes: 40 additions & 16 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions helium-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ reqwest = { version = "0", default-features = false, features = [
] }
helium-anchor-gen = {git = "https://github.com/helium/helium-anchor-gen.git"}
spl-associated-token-account = { version = "*", features = ["no-entrypoint"] }
mpl-bubblegum = "1"
solana-program = "*"
solana-transaction-status = "*"
serde = {workspace = true}
Expand Down
42 changes: 40 additions & 2 deletions helium-lib/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use crate::{
settings::{DasClient, DasSearchAssetsParams, Settings},
};
use helium_anchor_gen::helium_entity_manager;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use solana_sdk::{bs58, signer::Signer};
use std::{ops::Deref, result::Result as StdResult, str::FromStr};
use std::{collections::HashMap, ops::Deref, result::Result as StdResult, str::FromStr};

pub async fn account_for_entity_key<C: Clone + Deref<Target = impl Signer>, E>(
client: &anchor_client::Client<C>,
Expand Down Expand Up @@ -54,6 +55,26 @@ pub async fn get_with_proof(
Ok((asset, asset_proof))
}

pub async fn get_canopy_heights() -> Result<HashMap<Pubkey, usize>> {
const KNOWN_CANOPY_HEIGHT_URL: &str = "https://shdw-drive.genesysgo.net/6tcnBSybPG7piEDShBcrVtYJDPSvGrDbVvXmXKpzBvWP/merkles.json";
let client = reqwest::Client::new();
let map: HashMap<String, usize> = client
.get(KNOWN_CANOPY_HEIGHT_URL)
.send()
.await?
.error_for_status()?
.json()
.await?;

map.into_iter()
.map(|(str, value)| {
Pubkey::from_str(str.as_str())
.map_err(|err| DecodeError::from(err).into())
.map(|key| (key, value))
})
.try_collect()
}

pub mod proof {
use super::*;

Expand Down Expand Up @@ -151,12 +172,18 @@ pub struct AssetProof {
pub proof: Vec<String>,
#[serde(with = "serde_pubkey")]
pub root: Pubkey,
#[serde(with = "serde_pubkey")]
pub tree_id: Pubkey,
}

impl AssetProof {
pub fn proof(&self) -> Result<Vec<solana_program::instruction::AccountMeta>> {
pub fn proof(
&self,
len: Option<usize>,
) -> Result<Vec<solana_program::instruction::AccountMeta>> {
self.proof
.iter()
.take(len.unwrap_or(self.proof.len()))
.map(|s| {
Pubkey::from_str(s)
.map_err(DecodeError::from)
Expand All @@ -169,6 +196,17 @@ impl AssetProof {
})
.collect()
}

pub async fn proof_for_tree(
&self,
tree: &Pubkey,
) -> Result<Vec<solana_program::instruction::AccountMeta>> {
let canopy_heights = get_canopy_heights().await?;
let height = canopy_heights
.get(tree)
.ok_or_else(|| anchor_client::ClientError::AccountNotFound)?;
self.proof(Some(*height))
}
}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down
18 changes: 9 additions & 9 deletions helium-lib/src/dc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
dao::{Dao, SubDao},
keypair::{Pubkey, PublicKey},
keypair::{GetPubkey, Pubkey},
result::{DecodeError, Result},
settings::Settings,
token::{Token, TokenAmount},
Expand All @@ -9,7 +9,7 @@ use anchor_client::solana_sdk::signature::Signer;
use helium_anchor_gen::{circuit_breaker, data_credits};
use std::{ops::Deref, result::Result as StdResult};

pub async fn mint<C: Clone + Deref<Target = impl Signer> + PublicKey>(
pub async fn mint<C: Clone + Deref<Target = impl Signer> + GetPubkey>(
settings: &Settings,
amount: TokenAmount,
payee: &Pubkey,
Expand Down Expand Up @@ -45,7 +45,7 @@ pub async fn mint<C: Clone + Deref<Target = impl Signer> + PublicKey>(
let recipient_token_account = Token::Dc.associated_token_adress(payee);
let accounts = data_credits::accounts::MintDataCreditsV0 {
data_credits,
owner: keypair.public_key(),
owner: keypair.pubkey(),
hnt_mint: *Token::Hnt.mint(),
dc_mint: *Token::Dc.mint(),
recipient: *payee,
Expand All @@ -71,7 +71,7 @@ pub async fn mint<C: Clone + Deref<Target = impl Signer> + PublicKey>(
Ok(tx)
}

pub async fn delegate<C: Clone + Deref<Target = impl Signer> + PublicKey>(
pub async fn delegate<C: Clone + Deref<Target = impl Signer> + GetPubkey>(
settings: &Settings,
subdao: SubDao,
payer_key: &str,
Expand All @@ -89,10 +89,10 @@ pub async fn delegate<C: Clone + Deref<Target = impl Signer> + PublicKey>(
dc_mint: *Token::Dc.mint(),
dao: Dao::Hnt.key(),
sub_dao: subdao.key(),
owner: keypair.public_key(),
from_account: Token::Dc.associated_token_adress(&keypair.public_key()),
owner: keypair.pubkey(),
from_account: Token::Dc.associated_token_adress(&keypair.pubkey()),
escrow_account: subdao.escrow_account_key(&delegated_data_credits),
payer: keypair.public_key(),
payer: keypair.pubkey(),
associated_token_program: anchor_spl::associated_token::ID,
token_program: anchor_spl::token::ID,
system_program: solana_sdk::system_program::ID,
Expand All @@ -113,7 +113,7 @@ pub async fn delegate<C: Clone + Deref<Target = impl Signer> + PublicKey>(
Ok(tx)
}

pub async fn burn<C: Clone + Deref<Target = impl Signer> + PublicKey>(
pub async fn burn<C: Clone + Deref<Target = impl Signer> + GetPubkey>(
settings: &Settings,
amount: u64,
keypair: C,
Expand All @@ -130,7 +130,7 @@ pub async fn burn<C: Clone + Deref<Target = impl Signer> + PublicKey>(
token_program: anchor_spl::token::ID,
system_program: solana_sdk::system_program::ID,
associated_token_program: anchor_spl::associated_token::ID,
owner: keypair.public_key(),
owner: keypair.pubkey(),
},
};

Expand Down
Loading