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

Marinade common CLI artifacts #1

Merged
merged 11 commits into from
Jul 4, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
/.idea
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[package]
name = "marinade-common-rs-cli"
version = "0.1.0"
edition = "2021"
[workspace]
members = [
"libs/*"
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[profile.release]
lto = true
7 changes: 7 additions & 0 deletions libs/dynsigner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "dynsigner"
version = "0.1.0"
edition = "2021"

[dependencies]
solana-sdk = "1.14.18"
22 changes: 22 additions & 0 deletions libs/dynsigner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# DynSigner

When using Solana labs CLI utilities
(`solana-clap-utils`, https://github.com/solana-labs/solana/tree/master/clap-utils
-> https://github.com/solana-labs/solana/blob/6b013f46ebd30c82f7fa9c50c5a0e9ae32df3c44/clap-utils/src/keypair.rs#L357)
the loaded signer of type `Box<dyn Signer>` is not aligned to the expected `Client<C>` type of `<C: Clone + Deref<Target = impl Signer>>`.
Using the dyn Signer fails with error:

```
the size for values of type `dyn solana_sdk::signature::Signer` cannot be known at compilation time [E0277] doesn't have a size known at compile-time Help: the trait `Sized` is not implemented for `dyn solana_sdk::signature::Signer` Note: required by a bound in `anchor_client::Client::<C>::new_with_options`
```

Adding the helper DynSigner makes possible to match those types and use the Signer loded from the Solana utils with the Anchor client.

```
let fee_payer: Arc<dyn Signer> = ...
let anchor_client: Client<Arc<DynSigner>> = Client::new_with_options(
anchor_cluster,
Arc::new(DynSigner(fee_payer.clone())),
CommitmentConfig::confirmed(),
);
```
31 changes: 31 additions & 0 deletions libs/dynsigner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signer::Signer;
use std::sync::Arc;

/// Auxiliary data structure to align the types of the solana-clap-utils with anchor-client.
pub struct DynSigner(pub Arc<dyn Signer>);

impl Signer for DynSigner {
fn pubkey(&self) -> Pubkey {
self.0.pubkey()
}

fn try_pubkey(&self) -> Result<Pubkey, solana_sdk::signer::SignerError> {
self.0.try_pubkey()
}

fn sign_message(&self, message: &[u8]) -> solana_sdk::signature::Signature {
self.0.sign_message(message)
}

fn try_sign_message(
&self,
message: &[u8],
) -> Result<solana_sdk::signature::Signature, solana_sdk::signer::SignerError> {
self.0.try_sign_message(message)
}

fn is_interactive(&self) -> bool {
self.0.is_interactive()
}
}
20 changes: 20 additions & 0 deletions libs/marinade-client-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "marinade-client-rs"
version = "0.1.0"
edition = "2021"

[dependencies]
solana-sdk = "1.14.18"
once_cell = "1.8.0"
thiserror = "1.0.30"
anyhow = "1.0.71"
bincode = "1.3.3"
spl-token = { version = "3.5.0", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "1.1.3", features = ["no-entrypoint"] }
log = "0.4.18"
solana-client = "1.14.18"
marinade-finance = { git = "https://github.com/marinade-finance/liquid-staking-program.git", branch = "anchor-0.27" }
dynsigner = { path = "../dynsigner" }
anchor-lang = "0.27.0"
anchor-client = "0.27.0"
borsh = "0.9.3"
Loading