Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Commit 1862e8a

Browse files
authored
implement full solana chain signer in rust (transfer and stake) (#1135)
1 parent 50c6176 commit 1862e8a

28 files changed

Lines changed: 1185 additions & 429 deletions

Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/gem_solana/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ chain_integration_tests = [
2323
integration = []
2424

2525
[dependencies]
26-
curve25519-dalek = { workspace = true }
2726
sha2 = { workspace = true }
2827
bs58 = { workspace = true }
2928
borsh = { workspace = true }
@@ -40,7 +39,7 @@ gem_client = { path = "../gem_client", optional = true }
4039
chain_traits = { path = "../chain_traits", optional = true }
4140
futures = { workspace = true, optional = true }
4241
settings = { path = "../settings", features = ["testkit"], optional = true }
43-
solana-primitives = "0.2.3"
42+
solana-primitives = "0.2.5"
4443
num-traits = { workspace = true, optional = true }
4544

4645
[dev-dependencies]

crates/gem_solana/src/address.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use primitives::Address as AddressTrait;
2-
3-
use crate::pubkey::Pubkey;
1+
use solana_primitives::Pubkey;
42

53
pub fn validate_address(address: &str) -> bool {
6-
Pubkey::is_valid(address)
4+
Pubkey::from_base58(address).is_ok()
75
}
86

97
#[cfg(test)]
@@ -13,11 +11,11 @@ mod tests {
1311
#[test]
1412
fn test_solana_address() {
1513
let address = "GvhwZwtV32kYUXUw965CUM3KGPdtBsDwPVpi92brY5R2";
16-
let parsed = Pubkey::try_parse(address).unwrap();
14+
let parsed = Pubkey::from_base58(address).unwrap();
1715

1816
assert!(validate_address(address));
1917
assert_eq!(parsed.as_bytes().len(), 32);
20-
assert_eq!(parsed.encode(), address);
18+
assert_eq!(parsed.to_base58(), address);
2119
assert!(!validate_address("invalid"));
2220
}
2321
}

crates/gem_solana/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub mod constants;
33
pub mod hash;
44
pub mod jsonrpc;
55
pub mod metaplex;
6-
pub mod pubkey;
76
pub mod token_account;
87

98
#[cfg(any(feature = "rpc", feature = "reqwest"))]
@@ -20,6 +19,7 @@ pub mod signer;
2019

2120
pub use address::validate_address;
2221
pub use jsonrpc::SolanaRpc;
22+
pub use solana_primitives::{Pubkey, find_program_address};
2323
pub use transaction::{decode_transaction, try_decode_transaction};
2424

2525
#[cfg(all(feature = "reqwest", not(feature = "rpc")))]
@@ -58,9 +58,6 @@ pub const SYSTEM_PROGRAMS: &[&str] = &[
5858
pub const COMMITMENT_CONFIRMED: &str = "confirmed";
5959

6060
use primitives::{AssetId, SolanaTokenProgramId};
61-
use pubkey::Pubkey;
62-
use std::str::FromStr;
63-
6461
pub fn get_token_program_by_id(id: SolanaTokenProgramId) -> &'static str {
6562
match id {
6663
SolanaTokenProgramId::Token => TOKEN_PROGRAM,
@@ -80,8 +77,8 @@ pub fn get_token_program_id_by_address(address: &str) -> Result<SolanaTokenProgr
8077

8178
pub fn get_pubkey_by_asset(asset_id: &AssetId) -> Option<Pubkey> {
8279
match &asset_id.token_id {
83-
Some(token_id) => <Pubkey as FromStr>::from_str(token_id).ok(),
84-
None => <Pubkey as FromStr>::from_str(WSOL_TOKEN_ADDRESS).ok(),
80+
Some(token_id) => Pubkey::from_base58(token_id).ok(),
81+
None => Pubkey::from_base58(WSOL_TOKEN_ADDRESS).ok(),
8582
}
8683
}
8784

crates/gem_solana/src/metaplex/collection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::pubkey::Pubkey;
21
use borsh::{BorshDeserialize, BorshSerialize};
2+
use solana_primitives::Pubkey;
33

44
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
55
pub struct Collection {

crates/gem_solana/src/metaplex/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::pubkey::Pubkey;
21
use borsh::{BorshDeserialize, BorshSerialize};
2+
use solana_primitives::Pubkey;
33

44
#[derive(BorshSerialize, BorshDeserialize, Default, PartialEq, Eq, Debug, Clone)]
55
pub struct Data {

crates/gem_solana/src/metaplex/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::metaplex::{
66
data::Data,
77
uses::Uses,
88
};
9-
use crate::{METAPLEX_PROGRAM, pubkey::Pubkey};
9+
use crate::{METAPLEX_PROGRAM, Pubkey, find_program_address};
1010
use borsh::{BorshDeserialize, BorshSerialize};
1111

1212
#[derive(Clone, BorshDeserialize, BorshSerialize, Debug, PartialEq, Eq)]
@@ -45,7 +45,7 @@ pub enum ProgrammableConfig {
4545
impl Metadata {
4646
pub fn find_pda(mint: Pubkey) -> Option<(Pubkey, u8)> {
4747
let mpl_id = Pubkey::from_str(METAPLEX_PROGRAM).unwrap();
48-
let seeds = &["metadata".as_bytes(), mpl_id.as_ref(), mint.as_ref()];
49-
Pubkey::try_find_program_address(seeds, &mpl_id)
48+
let seeds = &["metadata".as_bytes(), mpl_id.as_bytes().as_ref(), mint.as_bytes().as_ref()];
49+
find_program_address(&mpl_id, seeds).ok()
5050
}
5151
}

crates/gem_solana/src/metaplex/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ pub fn decode_metadata(base64_str: &str) -> Result<Metadata, Box<dyn std::error:
4646
#[cfg(test)]
4747
mod tests {
4848
use crate::{
49-
USDC_TOKEN_MINT,
49+
Pubkey, USDC_TOKEN_MINT,
5050
metaplex::{Key, decode_metadata, metadata::Metadata},
51-
pubkey::Pubkey,
5251
};
5352
use std::str::FromStr;
5453

0 commit comments

Comments
 (0)