Skip to content
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
171 changes: 102 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ borsh = "1.5.3"
async-std = "1.13.0"
jsonrpsee-core = { version = "0.16.2", features = ["server"] }
env_logger = "0.11.5"
async-trait = "0.1.83"
async-trait = "0.1.89"
base64 = "0.22.1"
log = "0.4.22"
bytes = "1.9.0"
Expand Down
3 changes: 3 additions & 0 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jup-ag = { workspace = true }
spl-token = { workspace = true }
spl-token-2022 = { workspace = true }
spl-associated-token-account = { workspace = true }
solana-signers = { git = "https://github.com/solana-foundation/solana-signers", features = [
"all",
] }
vaultrs = { workspace = true }
deadpool-redis = { workspace = true }
jsonrpsee = { workspace = true }
Expand Down
31 changes: 13 additions & 18 deletions crates/lib/src/admin/token_util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
error::KoraError,
signer::{KoraSigner, Signer},
state::{get_all_signers, get_request_signer_with_signer_key},
token::token::TokenType,
transaction::TransactionUtil,
Expand All @@ -9,8 +8,8 @@ use solana_client::nonblocking::rpc_client::RpcClient;
use solana_message::{Message, VersionedMessage};
use solana_sdk::{
compute_budget::ComputeBudgetInstruction, instruction::Instruction, pubkey::Pubkey,
signature::Signature,
};
use solana_signers::SolanaSigner;

use spl_associated_token_account::{
get_associated_token_address, instruction::create_associated_token_account,
Expand Down Expand Up @@ -65,10 +64,7 @@ pub async fn initialize_atas(
vec![Pubkey::from_str(payment_address)
.map_err(|e| KoraError::InternalServerError(format!("Invalid payment address: {e}")))?]
} else {
get_all_signers()?
.iter()
.map(|signer| signer.signer.solana_pubkey())
.collect::<Vec<Pubkey>>()
get_all_signers()?.iter().map(|signer| signer.signer.pubkey()).collect::<Vec<Pubkey>>()
};

initialize_atas_with_chunk_size(
Expand All @@ -86,7 +82,7 @@ pub async fn initialize_atas(
/// This function does not use cache and directly checks on-chain
pub async fn initialize_atas_with_chunk_size(
rpc_client: &RpcClient,
fee_payer: &Arc<KoraSigner>,
fee_payer: &Arc<solana_signers::Signer>,
addresses_to_initialize_atas: &Vec<Pubkey>,
compute_unit_price: Option<u64>,
compute_unit_limit: Option<u32>,
Expand Down Expand Up @@ -122,7 +118,7 @@ pub async fn initialize_atas_with_chunk_size(
/// Helper function to create ATAs for a single signer
async fn create_atas_for_signer(
rpc_client: &RpcClient,
fee_payer: &Arc<KoraSigner>,
fee_payer: &Arc<solana_signers::Signer>,
address: &Pubkey,
atas_to_create: &[ATAToCreate],
compute_unit_price: Option<u64>,
Expand All @@ -133,7 +129,7 @@ async fn create_atas_for_signer(
.iter()
.map(|ata| {
create_associated_token_account(
&fee_payer.solana_pubkey(),
&fee_payer.pubkey(),
address,
&ata.mint,
&ata.token_program,
Expand Down Expand Up @@ -177,22 +173,21 @@ async fn create_atas_for_signer(
.await
.map_err(|e| KoraError::RpcError(format!("Failed to get blockhash: {e}")))?;

let fee_payer_pubkey = fee_payer.pubkey();
let message = VersionedMessage::Legacy(Message::new_with_blockhash(
&chunk_instructions,
Some(&fee_payer.solana_pubkey()),
Some(&fee_payer_pubkey),
&blockhash,
));

let mut tx = TransactionUtil::new_unsigned_versioned_transaction(message);
let signature = fee_payer.sign(&tx).await?;

let sig_bytes: [u8; 64] = signature
.bytes
.try_into()
.map_err(|_| KoraError::SigningError("Invalid signature length".to_string()))?;
let message_bytes = tx.message.serialize();
let signature = fee_payer
.sign_message(&message_bytes)
.await
.map_err(|e| KoraError::SigningError(e.to_string()))?;

let sig = Signature::from(sig_bytes);
tx.signatures = vec![sig];
tx.signatures = vec![signature];

match rpc_client.send_and_confirm_transaction_with_spinner(&tx).await {
Ok(signature) => {
Expand Down
10 changes: 2 additions & 8 deletions crates/lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,8 @@ impl From<anyhow::Error> for KoraError {
}
}

impl From<crate::signer::privy::types::PrivyError> for KoraError {
fn from(err: crate::signer::privy::types::PrivyError) -> Self {
KoraError::SigningError(err.to_string())
}
}

impl From<crate::signer::turnkey::types::TurnkeyError> for KoraError {
fn from(err: crate::signer::turnkey::types::TurnkeyError) -> Self {
impl From<solana_signers::SignerError> for KoraError {
fn from(err: solana_signers::SignerError) -> Self {
KoraError::SigningError(err.to_string())
}
}
Expand Down
17 changes: 9 additions & 8 deletions crates/lib/src/metrics/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ mod tests {
use super::*;
use crate::{
config::FeePayerBalanceMetricsConfig,
signer::{
memory_signer::solana_signer::SolanaMemorySigner, KoraSigner, SignerPool,
SignerWithMetadata,
},
signer::{SignerPool, SignerWithMetadata},
state::update_signer_pool,
tests::{
account_mock::create_mock_account_with_balance,
Expand All @@ -162,14 +159,18 @@ mod tests {
},
};
use solana_sdk::signature::Keypair;
use solana_signers::Signer;

fn setup_test_signer_pool() {
let signer1 = SolanaMemorySigner::new(Keypair::new());
let signer2 = SolanaMemorySigner::new(Keypair::new());
let keypair1 = Keypair::new();
let keypair2 = Keypair::new();

let external_signer1 = Signer::from_memory(&keypair1.to_base58_string()).unwrap();
let external_signer2 = Signer::from_memory(&keypair2.to_base58_string()).unwrap();

let pool = SignerPool::new(vec![
SignerWithMetadata::new("test_signer_1".to_string(), KoraSigner::Memory(signer1), 1),
SignerWithMetadata::new("test_signer_2".to_string(), KoraSigner::Memory(signer2), 1),
SignerWithMetadata::new("signer_1".to_string(), Arc::new(external_signer1), 1),
SignerWithMetadata::new("signer_2".to_string(), Arc::new(external_signer2), 2),
]);

let _ = update_signer_pool(pool);
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod validator;
pub use cache::CacheUtil;
pub use config::Config;
pub use error::KoraError;
pub use signer::{Signature, Signer};
pub use signer::SolanaSigner;
pub use state::{get_all_signers, get_request_signer_with_signer_key};

#[cfg(test)]
Expand Down
5 changes: 3 additions & 2 deletions crates/lib/src/rpc_server/method/estimate_transaction_fee.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use solana_signers::SolanaSigner;
use std::sync::Arc;
use utoipa::ToSchema;

Expand Down Expand Up @@ -49,10 +50,10 @@ pub async fn estimate_transaction_fee(

let signer = get_request_signer_with_signer_key(request.signer_key.as_deref())?;
let config = get_config()?;
let payment_destination = config.kora.get_payment_address(&signer.solana_pubkey())?;
let payment_destination = config.kora.get_payment_address(&signer.pubkey())?;

let validation_config = &config.validation;
let fee_payer = signer.solana_pubkey();
let fee_payer = signer.pubkey();

let mut resolved_transaction = VersionedTransactionResolved::from_transaction(
&transaction,
Expand Down
3 changes: 2 additions & 1 deletion crates/lib/src/rpc_server/method/get_payer_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
state::{get_config, get_signer_pool},
};
use serde::{Deserialize, Serialize};
use solana_signers::SolanaSigner;
use utoipa::ToSchema;

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
Expand All @@ -19,7 +20,7 @@ pub async fn get_payer_signer() -> Result<GetPayerSignerResponse, KoraError> {

// Get the next signer according to the configured strategy
let signer_meta = pool.get_next_signer()?;
let signer_pubkey = signer_meta.signer.solana_pubkey();
let signer_pubkey = signer_meta.signer.pubkey();
// Get the payment destination address (falls back to signer if no payment address is configured)
let payment_destination = config.kora.get_payment_address(&signer_pubkey)?;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{rpc_server::middleware_utils::default_sig_verify, usage_limit::UsageTracker};
use serde::{Deserialize, Serialize};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_signers::SolanaSigner;
use std::sync::Arc;
use utoipa::ToSchema;

Expand Down Expand Up @@ -51,7 +52,7 @@ pub async fn sign_and_send_transaction(

Ok(SignAndSendTransactionResponse {
signed_transaction,
signer_pubkey: signer.solana_pubkey().to_string(),
signer_pubkey: signer.pubkey().to_string(),
})
}

Expand Down
3 changes: 2 additions & 1 deletion crates/lib/src/rpc_server/method/sign_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
};
use serde::{Deserialize, Serialize};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_signers::SolanaSigner;
use std::sync::Arc;
use utoipa::ToSchema;

Expand Down Expand Up @@ -53,7 +54,7 @@ pub async fn sign_transaction(

Ok(SignTransactionResponse {
signed_transaction: encoded,
signer_pubkey: signer.solana_pubkey().to_string(),
signer_pubkey: signer.pubkey().to_string(),
})
}

Expand Down
3 changes: 2 additions & 1 deletion crates/lib/src/rpc_server/method/sign_transaction_if_paid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
};
use serde::{Deserialize, Serialize};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_signers::SolanaSigner;
use std::sync::Arc;
use utoipa::ToSchema;

Expand Down Expand Up @@ -55,7 +56,7 @@ pub async fn sign_transaction_if_paid(
Ok(SignTransactionIfPaidResponse {
transaction: TransactionUtil::encode_versioned_transaction(&transaction),
signed_transaction,
signer_pubkey: signer.solana_pubkey().to_string(),
signer_pubkey: signer.pubkey().to_string(),
})
}

Expand Down
11 changes: 8 additions & 3 deletions crates/lib/src/rpc_server/method/transfer_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use solana_client::nonblocking::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;
use solana_message::Message;
use solana_sdk::{message::VersionedMessage, pubkey::Pubkey};
use solana_signers::SolanaSigner;
use solana_system_interface::instruction::transfer;
use std::{str::FromStr, sync::Arc};
use utoipa::ToSchema;
Expand All @@ -14,7 +15,7 @@ use crate::{
TransactionUtil, VersionedMessageExt, VersionedTransactionOps, VersionedTransactionResolved,
},
validator::transaction_validator::TransactionValidator,
CacheUtil, KoraError, Signer as _,
CacheUtil, KoraError,
};

#[derive(Debug, Deserialize, ToSchema)]
Expand Down Expand Up @@ -42,7 +43,7 @@ pub async fn transfer_transaction(
request: TransferTransactionRequest,
) -> Result<TransferTransactionResponse, KoraError> {
let signer = get_request_signer_with_signer_key(request.signer_key.as_deref())?;
let fee_payer = signer.solana_pubkey();
let fee_payer = signer.pubkey();

let validator = TransactionValidator::new(fee_payer)?;

Expand Down Expand Up @@ -130,7 +131,11 @@ pub async fn transfer_transaction(
// Find the fee payer position in the account keys
let fee_payer_position = resolved_transaction.find_signer_position(&fee_payer)?;

let signature = signer.sign_solana(&resolved_transaction).await?;
let message_bytes = resolved_transaction.transaction.message.serialize();
let signature = signer
.sign_message(&message_bytes)
.await
.map_err(|e| KoraError::SigningError(e.to_string()))?;

resolved_transaction.transaction.signatures[fee_payer_position] = signature;

Expand Down
Loading
Loading