Skip to content

feat: Eip155OrSolanaAddressKind #164

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

Merged
merged 2 commits into from
May 1, 2025
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
21 changes: 21 additions & 0 deletions crates/yttrium/src/chain_abstraction/api/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ pub enum Eip155OrSolanaAddress {
Solana(crate::chain_abstraction::solana::SolanaPubkey),
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Eip155OrSolanaAddressKind {
#[cfg(feature = "eip155")]
Eip155,
#[cfg(feature = "solana")]
Solana,
}

impl fmt::Display for Eip155OrSolanaAddress {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -107,6 +115,19 @@ impl Eip155OrSolanaAddress {
Self::Solana(_) => None,
}
}

pub fn kind(&self) -> Eip155OrSolanaAddressKind {
match self {
#[cfg(feature = "eip155")]
Self::Eip155(_) => Eip155OrSolanaAddressKind::Eip155,
#[cfg(feature = "solana")]
Self::Solana(_) => Eip155OrSolanaAddressKind::Solana,
}
}

pub fn same_kind_as(&self, other: &Self) -> bool {
self.kind() == other.kind()
}
}

#[derive(Debug, Clone, thiserror::Error)]
Expand Down
2 changes: 2 additions & 0 deletions crates/yttrium/src/chain_abstraction/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ impl Client {
}
#[cfg(feature = "solana")]
(Route::Solana(txn), RouteSig::Solana(sig)) => {
// TODO use Blockchain API
let sol_rpc = "https://api.mainnet-beta.solana.com";
let solana_rpc_client =
solana::SolanaRpcClient::new_with_commitment(
Expand Down Expand Up @@ -702,6 +703,7 @@ impl Client {
signature
),
Err(e) => {
// TODO handle error without panic
panic!("Error sending transaction: {}", e)
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/yttrium/src/chain_abstraction/solana/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ async fn solana_happy_path() {
"minimum_balance_for_rent_exemption: {}",
minimum_balance_for_rent_exemption
);
let next_txn_fee = 100_000;
let next_txn_fee = 200_000; // TODO use actual estimated gas fee
let min_balance = minimum_balance_for_rent_exemption + next_txn_fee;

if account_sol_sol_balance < min_balance {
Expand All @@ -344,6 +344,7 @@ async fn solana_happy_path() {
println!("funding from faucet: {}", faucet_solana.pubkey());

let faucet_amount = (min_balance - account_sol_sol_balance) * 2;
// TODO use actual estimated gas fee + minimum balance for rent instead of arbitrary 0.001 SOL
#[allow(clippy::zero_prefixed_literal)]
if faucet_sol_sol_balance - faucet_amount < 0_001_000_000 {
// 0.001 SOL = ~$0.15
Expand Down
Loading