Parcourir la source

feat: simple cli for setting the stake cap parameters (#1786)

* done

* cleanup

* it's working
guibescos il y a 1 an
Parent
commit
4d6991fbde

Fichier diff supprimé car celui-ci est trop grand
+ 667 - 10
pythnet/stake_caps_parameters/Cargo.lock


+ 2 - 1
pythnet/stake_caps_parameters/Cargo.toml

@@ -1,6 +1,7 @@
 [workspace]
 members = [
-    "programs/*"
+    "programs/*",
+    "cli"
 ]
 resolver = "2"
 

+ 12 - 0
pythnet/stake_caps_parameters/cli/Cargo.toml

@@ -0,0 +1,12 @@
+[package]
+name = "remote-executor-cli"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+clap = {version ="3.2.22", features = ["derive"]}
+stake_caps_parameters = { path = "../programs/stake_caps_parameters" }
+solana-sdk = "1.18.0"
+solana-client = "1.18.0"
+shellexpand = "3.1.0"
+anchor-lang = "0.30.1"

+ 39 - 0
pythnet/stake_caps_parameters/cli/src/cli.rs

@@ -0,0 +1,39 @@
+//! CLI options
+use {
+    clap::Parser,
+    solana_sdk::{
+        pubkey::Pubkey,
+        signature::{
+            read_keypair_file,
+            Keypair,
+        },
+    },
+};
+
+#[derive(Parser, Debug)]
+#[clap(
+    about = "A cli for the remote executor",
+    author = "Pyth Network Contributors"
+)]
+pub struct Cli {
+    #[clap(long, default_value = "https://pythnet.rpcpool.com/")]
+    pub rpc_url:   String,
+    #[clap(
+        long,
+        default_value = "~/.config/solana/id.json",
+        help = "Keypair file the funder of the transaction",
+        parse(try_from_str = get_keypair_from_file)
+    )]
+    pub keypair:   Keypair,
+    #[clap(long, help = "M parameter")]
+    pub m:         u64,
+    #[clap(long, help = "Z parameter")]
+    pub z:         u64,
+    #[clap(long, help = "Update authority for the parameters")]
+    pub authority: Pubkey,
+}
+
+fn get_keypair_from_file(path: &str) -> Result<Keypair, String> {
+    read_keypair_file(&*shellexpand::tilde(&path))
+        .map_err(|_| format!("Keypair not found: {}", path))
+}

+ 58 - 0
pythnet/stake_caps_parameters/cli/src/main.rs

@@ -0,0 +1,58 @@
+pub mod cli;
+use {
+    anchor_lang::{
+        InstructionData,
+        ToAccountMetas,
+    },
+    clap::Parser,
+    cli::Cli,
+    solana_client::rpc_client::RpcClient,
+    solana_sdk::{
+        commitment_config::CommitmentConfig,
+        instruction::Instruction,
+        signer::Signer,
+        transaction::Transaction,
+    },
+    stake_caps_parameters::{
+        Parameters,
+        PARAMETERS_ADDRESS,
+    },
+};
+
+
+fn main() {
+    let Cli {
+        keypair,
+        rpc_url,
+        m,
+        z,
+        authority,
+    } = Cli::parse();
+    let accs = stake_caps_parameters::accounts::SetParameters {
+        signer:         keypair.pubkey(),
+        parameters:     PARAMETERS_ADDRESS,
+        system_program: solana_sdk::system_program::id(),
+    };
+    let rpc_client = RpcClient::new_with_commitment(rpc_url, CommitmentConfig::confirmed());
+
+    let instruction = Instruction {
+        program_id: stake_caps_parameters::id(),
+        accounts:   accs.to_account_metas(None),
+        data:       stake_caps_parameters::instruction::SetParameters {
+            parameters: Parameters {
+                m,
+                z,
+                current_authority: authority,
+            },
+        }
+        .data(),
+    };
+
+
+    let mut transaction = Transaction::new_with_payer(&[instruction], Some(&keypair.pubkey()));
+    transaction.sign(&[&keypair], rpc_client.get_latest_blockhash().unwrap());
+    let transaction_signature = rpc_client
+        .send_and_confirm_transaction_with_spinner(&transaction)
+        .unwrap();
+    println!("Transaction successful : {transaction_signature:?}");
+}

+ 0 - 2
pythnet/stake_caps_parameters/programs/stake_caps_parameters/tests/test_stake_caps_parameters.rs

@@ -1,9 +1,7 @@
 use {
     anchor_lang::{
         error::Error,
-        prelude::thiserror::Error,
         solana_program::native_token::LAMPORTS_PER_SOL,
-        system_program,
         AccountDeserialize,
         InstructionData,
         ToAccountMetas,

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff