From 02e3333f5b23e0e190c4278178f5ad1cc830d94e Mon Sep 17 00:00:00 2001 From: Nick Garfield Date: Tue, 2 May 2023 10:16:37 -0500 Subject: [PATCH] Nuke the client module (#246) * Remove the client module * Remove all uses of clockwork_client in cli * Readd localnet startup script * Migrate to ToAccountMetas --- Cargo.lock | 25 +- Cargo.toml | 1 - cli/Cargo.toml | 4 +- cli/src/cli.rs | 26 +- cli/src/client.rs | 158 +++++++ cli/src/main.rs | 1 + cli/src/parser.rs | 44 +- cli/src/processor/config.rs | 22 +- cli/src/processor/crontab.rs | 12 +- cli/src/processor/delegation.rs | 70 ++- cli/src/processor/explorer.rs | 4 +- cli/src/processor/initialize.rs | 40 +- cli/src/processor/localnet.rs | 193 ++++++--- cli/src/processor/mod.rs | 10 +- cli/src/processor/pool.rs | 32 +- cli/src/processor/registry.rs | 24 +- cli/src/processor/secret.rs | 3 +- cli/src/processor/snapshot.rs | 4 +- cli/src/processor/thread.rs | 104 +++-- cli/src/processor/webhook.rs | 8 +- cli/src/processor/worker.rs | 55 ++- client/.gitignore | 2 - client/Cargo.toml | 29 -- client/README.md | 1 - client/src/client.rs | 404 ------------------ client/src/lib.rs | 6 - .../src/network/instruction/config_update.rs | 21 - .../network/instruction/delegation_create.rs | 36 -- .../network/instruction/delegation_deposit.rs | 31 -- .../instruction/delegation_withdraw.rs | 31 -- client/src/network/instruction/initialize.rs | 26 -- client/src/network/instruction/mod.rs | 25 -- client/src/network/instruction/pool_create.rs | 26 -- client/src/network/instruction/pool_rotate.rs | 32 -- client/src/network/instruction/pool_update.rs | 30 -- .../instruction/registry_nonce_hash.rs | 22 - .../network/instruction/registry_unlock.rs | 22 - .../src/network/instruction/worker_create.rs | 39 -- .../src/network/instruction/worker_update.rs | 21 - client/src/network/job/delete_snapshot.rs | 22 - client/src/network/job/distribute_fees.rs | 22 - client/src/network/job/increment_epoch.rs | 22 - client/src/network/job/mod.rs | 13 - client/src/network/job/process_unstakes.rs | 22 - client/src/network/job/stake_delegations.rs | 22 - client/src/network/job/take_snapshot.rs | 22 - client/src/network/mod.rs | 5 - .../src/thread/instruction/get_crate_info.rs | 15 - client/src/thread/instruction/mod.rs | 19 - .../src/thread/instruction/thread_create.rs | 36 -- .../src/thread/instruction/thread_delete.rs | 19 - client/src/thread/instruction/thread_exec.rs | 22 - .../src/thread/instruction/thread_kickoff.rs | 19 - client/src/thread/instruction/thread_pause.rs | 18 - client/src/thread/instruction/thread_reset.rs | 18 - .../src/thread/instruction/thread_resume.rs | 18 - .../src/thread/instruction/thread_update.rs | 22 - client/src/thread/mod.rs | 5 - client/src/webhook/instruction/api_new.rs | 28 -- client/src/webhook/instruction/initialize.rs | 21 - client/src/webhook/instruction/mod.rs | 9 - client/src/webhook/instruction/request_ack.rs | 32 -- client/src/webhook/instruction/request_new.rs | 37 -- client/src/webhook/mod.rs | 4 - plugin/Cargo.toml | 3 +- plugin/src/builders/pool_rotation.rs | 26 +- plugin/src/builders/thread_exec.rs | 14 +- plugin/src/events.rs | 4 +- plugin/src/executors/tx.rs | 2 +- plugin/src/executors/webhook.rs | 2 +- plugin/src/observers/thread.rs | 3 +- plugin/src/observers/webhook.rs | 2 +- 72 files changed, 607 insertions(+), 1585 deletions(-) create mode 100644 cli/src/client.rs delete mode 100644 client/.gitignore delete mode 100644 client/Cargo.toml delete mode 100644 client/README.md delete mode 100644 client/src/client.rs delete mode 100644 client/src/lib.rs delete mode 100644 client/src/network/instruction/config_update.rs delete mode 100644 client/src/network/instruction/delegation_create.rs delete mode 100644 client/src/network/instruction/delegation_deposit.rs delete mode 100644 client/src/network/instruction/delegation_withdraw.rs delete mode 100644 client/src/network/instruction/initialize.rs delete mode 100644 client/src/network/instruction/mod.rs delete mode 100644 client/src/network/instruction/pool_create.rs delete mode 100644 client/src/network/instruction/pool_rotate.rs delete mode 100644 client/src/network/instruction/pool_update.rs delete mode 100644 client/src/network/instruction/registry_nonce_hash.rs delete mode 100644 client/src/network/instruction/registry_unlock.rs delete mode 100644 client/src/network/instruction/worker_create.rs delete mode 100644 client/src/network/instruction/worker_update.rs delete mode 100644 client/src/network/job/delete_snapshot.rs delete mode 100644 client/src/network/job/distribute_fees.rs delete mode 100644 client/src/network/job/increment_epoch.rs delete mode 100644 client/src/network/job/mod.rs delete mode 100644 client/src/network/job/process_unstakes.rs delete mode 100644 client/src/network/job/stake_delegations.rs delete mode 100644 client/src/network/job/take_snapshot.rs delete mode 100644 client/src/network/mod.rs delete mode 100644 client/src/thread/instruction/get_crate_info.rs delete mode 100644 client/src/thread/instruction/mod.rs delete mode 100644 client/src/thread/instruction/thread_create.rs delete mode 100644 client/src/thread/instruction/thread_delete.rs delete mode 100644 client/src/thread/instruction/thread_exec.rs delete mode 100644 client/src/thread/instruction/thread_kickoff.rs delete mode 100644 client/src/thread/instruction/thread_pause.rs delete mode 100644 client/src/thread/instruction/thread_reset.rs delete mode 100644 client/src/thread/instruction/thread_resume.rs delete mode 100644 client/src/thread/instruction/thread_update.rs delete mode 100644 client/src/thread/mod.rs delete mode 100644 client/src/webhook/instruction/api_new.rs delete mode 100644 client/src/webhook/instruction/initialize.rs delete mode 100644 client/src/webhook/instruction/mod.rs delete mode 100644 client/src/webhook/instruction/request_ack.rs delete mode 100644 client/src/webhook/instruction/request_new.rs delete mode 100644 client/src/webhook/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 55c526180..c43f90a25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1095,16 +1095,18 @@ name = "clockwork-cli" version = "2.0.15" dependencies = [ "anchor-lang", + "anchor-spl", "anyhow", "bincode", "bzip2", "cargo_metadata", "chrono", "clap 3.2.23", - "clockwork-client", "clockwork-cron", + "clockwork-network-program", "clockwork-plugin-utils", "clockwork-relayer-api", + "clockwork-thread-program", "clockwork-utils", "clockwork-webhook-program", "dirs-next", @@ -1126,24 +1128,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "clockwork-client" -version = "2.0.15" -dependencies = [ - "anchor-lang", - "anchor-spl", - "bincode", - "borsh", - "clockwork-network-program", - "clockwork-thread-program", - "clockwork-utils", - "clockwork-webhook-program", - "solana-client", - "solana-sdk", - "spl-associated-token-account", - "thiserror", -] - [[package]] name = "clockwork-cron" version = "2.0.15" @@ -1272,13 +1256,14 @@ dependencies = [ "bugsnag", "cargo_metadata", "chrono", - "clockwork-client", "clockwork-cron", + "clockwork-network-program", "clockwork-plugin-utils", "clockwork-relayer-api", "clockwork-thread-program", "clockwork-thread-program-v1", "clockwork-utils", + "clockwork-webhook-program", "futures", "lazy_static", "log 0.4.17", diff --git a/Cargo.toml b/Cargo.toml index ab2da889a..41de481ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [workspace] members = [ "cli", - "client", "cron", "plugin", "programs/*", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8d65973bb..978525a66 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -13,14 +13,16 @@ build = "build.rs" [dependencies] anchor-lang = "0.27.0" +anchor-spl = { features = ["mint", "token"], version = "0.27.0" } anyhow = "1.0.61" bincode = "1.3.3" bzip2 = "0.4" clap = { version = "3.1.2", features = ["derive"] } -clockwork-client = { path = "../client", version = "=2.0.15" } clockwork-cron = { path = "../cron", version = "=2.0.15" } +clockwork-network-program = { path = "../programs/network", version = "=2.0.15" } clockwork-relayer-api = { path = "../relayer/api", version = "=2.0.15" } clockwork-plugin-utils= { path = "../plugin/utils", version = "=2.0.15" } +clockwork-thread-program = { path = "../programs/thread", version = "=2.0.15" } clockwork-utils = { path = "../utils", version = "=2.0.15" } clockwork-webhook-program = { path = "../programs/webhook", version = "=2.0.15" } chrono = { version = "0.4.19", default-features = false, features = ["alloc"] } diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 5aeb4b2d4..59db072af 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -1,23 +1,9 @@ -use { - crate::parser::ProgramInfo, - clap::{ - crate_version, - Arg, - ArgGroup, - Command, - }, - clockwork_client::{ - thread::state::{ - SerializableInstruction, - Trigger, - }, - webhook::state::HttpMethod, - }, - solana_sdk::{ - pubkey::Pubkey, - signature::Keypair, - }, -}; +use clap::{crate_version, Arg, ArgGroup, Command}; +use clockwork_thread_program::state::{SerializableInstruction, Trigger}; +use clockwork_webhook_program::state::HttpMethod; +use solana_sdk::{pubkey::Pubkey, signature::Keypair}; + +use crate::parser::ProgramInfo; #[derive(Debug, PartialEq)] pub enum CliCommand { diff --git a/cli/src/client.rs b/cli/src/client.rs new file mode 100644 index 000000000..6075781a8 --- /dev/null +++ b/cli/src/client.rs @@ -0,0 +1,158 @@ +use anchor_lang::{prelude::Clock, AccountDeserialize}; +use clockwork_utils::ProgramLogsDeserializable; +use solana_client::{ + client_error, rpc_client::RpcClient, + rpc_response::RpcSimulateTransactionResult, +}; +use solana_sdk::{ + commitment_config::CommitmentConfig, + hash::Hash, + instruction::Instruction, + program_error::ProgramError, + pubkey::Pubkey, + signature::{Keypair, Signature, Signer}, + signers::Signers, + transaction::Transaction, +}; +use std::{ + fmt::Debug, + ops::{Deref, DerefMut}, + str::FromStr, +}; +use thiserror::Error; + + +#[derive(Debug, Error)] +pub enum ClientError { + #[error(transparent)] + Client(#[from] client_error::ClientError), + + #[error(transparent)] + Program(#[from] ProgramError), + + #[error("Failed to deserialize account data")] + DeserializationError, +} + +pub type ClientResult = Result; + +pub struct Client { + pub client: RpcClient, + pub payer: Keypair, +} + +impl Client { + pub fn new(payer: Keypair, url: String) -> Self { + let client = RpcClient::new_with_commitment::(url, CommitmentConfig::processed()); + Self { client, payer } + } + + pub fn get(&self, pubkey: &Pubkey) -> ClientResult { + let data = self.client.get_account_data(pubkey)?; + T::try_deserialize(&mut data.as_slice()).map_err(|_| ClientError::DeserializationError) + } + + pub fn get_clock(&self) -> ClientResult { + let clock_pubkey = Pubkey::from_str("SysvarC1ock11111111111111111111111111111111").unwrap(); + let clock_data = self.client.get_account_data(&clock_pubkey)?; + bincode::deserialize::(&clock_data).map_err(|_| ClientError::DeserializationError) + } + + pub fn get_return_data( + &self, + ix: Instruction, + ) -> ClientResult { + // let result = self.simulate_transaction(&[ix.clone()], &[self.payer()])?; + + // After we can upgrade our Solana SDK version to 1.14.0 we can just use the below code: + // let data = result.logs; + // Ok(T::try_from_slice(logs, &data) + // .map_err(|_| ClientError::DeserializationError)?) + // + // But for the time being since RpcSimulateTransactionResult.data does not exist yet, + // We can only parse the logs ourselves to find the return_data + let logs = self.get_instruction_logs(ix.clone())?; + T::try_from_program_logs(logs, &ix.program_id) + .map_err(|_| ClientError::DeserializationError) + } + + pub fn get_instruction_logs(&self, ix: Instruction) -> ClientResult> { + let result = self.simulate_transaction(&[ix], &[self.payer()])?; + let logs = result.logs.ok_or(ClientError::DeserializationError)?; + Ok(logs) + } + + pub fn payer(&self) -> &Keypair { + &self.payer + } + + pub fn payer_pubkey(&self) -> Pubkey { + self.payer.pubkey() + } + + pub fn latest_blockhash(&self) -> ClientResult { + Ok(self.client.get_latest_blockhash()?) + } + + pub fn airdrop(&self, to_pubkey: &Pubkey, lamports: u64) -> ClientResult { + let blockhash = self.client.get_latest_blockhash()?; + let signature = self.request_airdrop_with_blockhash(to_pubkey, lamports, &blockhash)?; + self.confirm_transaction_with_spinner(&signature, &blockhash, self.commitment())?; + Ok(signature) + } + + pub fn send_and_confirm( + &self, + ixs: &[Instruction], + signers: &T, + ) -> ClientResult { + let tx = self.transaction(ixs, signers)?; + Ok(self.send_and_confirm_transaction(&tx)?) + } + + pub fn simulate_transaction( + &self, + ixs: &[Instruction], + signers: &T, + ) -> ClientResult { + let tx = self.transaction(ixs, signers)?; + let result = self.client.simulate_transaction(&tx)?; + if result.value.err.is_some() { + Err(ClientError::DeserializationError) + } else { + Ok(result.value) + } + } + + fn transaction( + &self, + ixs: &[Instruction], + signers: &T, + ) -> ClientResult { + let mut tx = Transaction::new_with_payer(ixs, Some(&self.payer_pubkey())); + tx.sign(signers, self.latest_blockhash()?); + Ok(tx) + } +} + + +impl Debug for Client { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "RPC client payer {}", self.payer_pubkey()) + } +} + +impl Deref for Client { + type Target = RpcClient; + + fn deref(&self) -> &Self::Target { + &self.client + } +} + +impl DerefMut for Client { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.client + } +} + diff --git a/cli/src/main.rs b/cli/src/main.rs index 3a9f94e3d..6b109c7e9 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,4 +1,5 @@ mod cli; +mod client; mod config; mod deps; mod errors; diff --git a/cli/src/parser.rs b/cli/src/parser.rs index b1a2cdfde..cc11b46e7 100644 --- a/cli/src/parser.rs +++ b/cli/src/parser.rs @@ -1,37 +1,17 @@ -use { - crate::{ - cli::CliCommand, - errors::CliError, - }, - clap::ArgMatches, - clockwork_client::{ - thread::state::{ - SerializableAccount, - SerializableInstruction, - Trigger, - }, - webhook::state::HttpMethod, - }, - serde::{ - Deserialize as JsonDeserialize, - Serialize as JsonSerialize, - }, - solana_sdk::{ - pubkey::Pubkey, - signature::{ - read_keypair_file, - Keypair, - }, - signer::Signer, - }, - std::{ - convert::TryFrom, - fs, - path::PathBuf, - str::FromStr, - }, +use std::{convert::TryFrom, fs, path::PathBuf, str::FromStr}; + +use clap::ArgMatches; +use clockwork_thread_program::state::{SerializableAccount, SerializableInstruction, Trigger}; +use clockwork_webhook_program::state::HttpMethod; +use serde::{Deserialize as JsonDeserialize, Serialize as JsonSerialize}; +use solana_sdk::{ + pubkey::Pubkey, + signature::{read_keypair_file, Keypair}, + signer::Signer, }; +use crate::{cli::CliCommand, errors::CliError}; + impl TryFrom<&ArgMatches> for CliCommand { type Error = CliError; diff --git a/cli/src/processor/config.rs b/cli/src/processor/config.rs index d9a7c71b9..6e983ef75 100644 --- a/cli/src/processor/config.rs +++ b/cli/src/processor/config.rs @@ -1,11 +1,12 @@ -use { - crate::errors::CliError, - clockwork_client::{ - network::state::{Config, ConfigSettings}, - Client, +use anchor_lang::{ + solana_program::{ + instruction::Instruction, pubkey::Pubkey, }, - solana_sdk::pubkey::Pubkey, + InstructionData, ToAccountMetas }; +use clockwork_network_program::state::{Config, ConfigSettings}; + +use crate::{client::Client, errors::CliError}; pub fn get(client: &Client) -> Result<(), CliError> { let config = client @@ -35,7 +36,14 @@ pub fn set( }; // Submit tx - let ix = clockwork_client::network::instruction::config_update(client.payer_pubkey(), settings); + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::ConfigUpdate { + admin: client.payer_pubkey(), + config: Config::pubkey(), + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::ConfigUpdate { settings }.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client)?; Ok(()) diff --git a/cli/src/processor/crontab.rs b/cli/src/processor/crontab.rs index 508607623..c9e2888be 100644 --- a/cli/src/processor/crontab.rs +++ b/cli/src/processor/crontab.rs @@ -1,10 +1,8 @@ -use { - crate::errors::CliError, - chrono::{DateTime, NaiveDateTime, Utc}, - clockwork_client::Client, - clockwork_cron::Schedule, - std::str::FromStr, -}; +use chrono::{DateTime, NaiveDateTime, Utc}; +use clockwork_cron::Schedule; +use std::str::FromStr; + +use crate::{client::Client, errors::CliError}; pub fn get(client: &Client, schedule: String) -> Result<(), CliError> { let clock = client.get_clock().unwrap(); diff --git a/cli/src/processor/delegation.rs b/cli/src/processor/delegation.rs index 6c7f637fa..a2c80359c 100644 --- a/cli/src/processor/delegation.rs +++ b/cli/src/processor/delegation.rs @@ -1,11 +1,13 @@ -use anchor_lang::AccountDeserialize; -use clockwork_client::{ - network::state::{Config, Delegation, Worker}, - Client, +use anchor_lang::{ + solana_program::{ + instruction::Instruction, system_program, sysvar + }, + InstructionData, AccountDeserialize, ToAccountMetas }; +use clockwork_network_program::state::{Config, Delegation, Worker}; use spl_associated_token_account::get_associated_token_address; -use crate::errors::CliError; +use crate::{client::Client, errors::CliError}; pub fn create(client: &Client, worker_id: u64) -> Result<(), CliError> { // Get config data @@ -26,12 +28,22 @@ pub fn create(client: &Client, worker_id: u64) -> Result<(), CliError> { // Build ix let delegation_pubkey = Delegation::pubkey(worker_pubkey, worker.total_delegations); - let ix = clockwork_client::network::instruction::delegation_create( - client.payer_pubkey(), - delegation_pubkey, - config.mint, - worker_pubkey, - ); + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::DelegationCreate { + associated_token_program: anchor_spl::associated_token::ID, + authority: client.payer_pubkey(), + config: Config::pubkey(), + delegation: delegation_pubkey, + delegation_tokens: get_associated_token_address(&delegation_pubkey, &config.mint), + mint: config.mint, + rent: sysvar::rent::ID, + system_program: system_program::ID, + token_program: anchor_spl::token::ID, + worker: worker_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::DelegationCreate {}.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); Ok(()) @@ -56,12 +68,18 @@ pub fn deposit( // Build ix let worker_pubkey = Worker::pubkey(worker_id); let delegation_pubkey = Delegation::pubkey(worker_pubkey, delegation_id); - let ix = clockwork_client::network::instruction::delegation_deposit( - amount, - client.payer_pubkey(), - delegation_pubkey, - config.mint, - ); + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::DelegationDeposit { + authority: client.payer_pubkey(), + authority_tokens: get_associated_token_address(&client.payer_pubkey(), &config.mint), + config: Config::pubkey(), + delegation: delegation_pubkey, + delegation_tokens: get_associated_token_address(&delegation_pubkey, &config.mint), + token_program: anchor_spl::token::ID, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::DelegationDeposit { amount }.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); Ok(()) @@ -86,12 +104,18 @@ pub fn withdraw( // Build ix let worker_pubkey = Worker::pubkey(worker_id); let delegation_pubkey = Delegation::pubkey(worker_pubkey, delegation_id); - let ix = clockwork_client::network::instruction::delegation_withdraw( - amount, - client.payer_pubkey(), - delegation_pubkey, - config.mint, - ); + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::DelegationWithdraw { + authority: client.payer_pubkey(), + authority_tokens: get_associated_token_address(&client.payer_pubkey(), &config.mint), + config: Config::pubkey(), + delegation: delegation_pubkey, + delegation_tokens: get_associated_token_address(&delegation_pubkey, &config.mint), + token_program: anchor_spl::token::ID, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::DelegationWithdraw { amount }.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); Ok(()) diff --git a/cli/src/processor/explorer.rs b/cli/src/processor/explorer.rs index e1994f70a..213320c90 100644 --- a/cli/src/processor/explorer.rs +++ b/cli/src/processor/explorer.rs @@ -2,13 +2,11 @@ use { crate::errors::CliError, crate::config::CliConfig, clockwork_utils::explorer::Explorer, - }; pub fn thread_url(thread: T, config: CliConfig) -> Result<(), CliError> { - println!("thread: {}", explorer(config).thread_url(thread, - clockwork_client::thread::ID)); + println!("thread: {}", explorer(config).thread_url(thread, clockwork_thread_program::ID)); Ok(()) } diff --git a/cli/src/processor/initialize.rs b/cli/src/processor/initialize.rs index 91007f09e..db30c0ec1 100644 --- a/cli/src/processor/initialize.rs +++ b/cli/src/processor/initialize.rs @@ -1,14 +1,42 @@ -use { - crate::errors::CliError, - clockwork_client::{network::state::Pool, Client}, - solana_sdk::pubkey::Pubkey, +use anchor_lang::{ + solana_program::{ + instruction::Instruction, + pubkey::Pubkey, + system_program, + }, + InstructionData, ToAccountMetas, }; +use clockwork_network_program::state::{Config, Pool, Registry, Snapshot}; + +use crate::{client::Client, errors::CliError}; pub fn initialize(client: &Client, mint: Pubkey) -> Result<(), CliError> { // Initialize the programs let admin = client.payer_pubkey(); - let ix_a = clockwork_client::network::instruction::initialize(admin, mint); - let ix_b = clockwork_client::network::instruction::pool_create(admin, admin, Pool::pubkey(0)); + let ix_a = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::Initialize { + admin, + config: Config::pubkey(), + mint, + registry: Registry::pubkey(), + snapshot: Snapshot::pubkey(0), + system_program: system_program::ID, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::Initialize {}.data(), + }; + let ix_b = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::PoolCreate { + admin, + config: Config::pubkey(), + payer: admin, + pool: Pool::pubkey(0), + registry: Registry::pubkey(), + system_program: system_program::ID, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::PoolCreate {}.data(), + }; // Submit tx client diff --git a/cli/src/processor/localnet.rs b/cli/src/processor/localnet.rs index 2733b24c3..7f00ca94e 100644 --- a/cli/src/processor/localnet.rs +++ b/cli/src/processor/localnet.rs @@ -1,28 +1,25 @@ -use { - crate::print_status, - clap::crate_version, -}; #[allow(deprecated)] use { crate::{ + client::Client, config::CliConfig, deps, errors::CliError, parser::ProgramInfo, print::print_style, + print_status }, anyhow::{ Context, Result, }, - clockwork_client::{ - network::state::ConfigSettings, - thread::state::{ - Thread, - Trigger, - }, - Client, + anchor_lang::{ + solana_program::{instruction::Instruction, system_program}, + InstructionData, ToAccountMetas }, + clap::crate_version, + clockwork_network_program::state::{Config, ConfigSettings, Registry}, + clockwork_thread_program::state::{Thread, Trigger}, solana_sdk::{ native_token::LAMPORTS_PER_SOL, program_pack::Pack, @@ -172,55 +169,136 @@ fn create_threads(client: &Client, mint_pubkey: Pubkey) -> Result<()> { // Create epoch thread. let epoch_thread_id = "clockwork.network.epoch"; let epoch_thread_pubkey = Thread::pubkey(client.payer_pubkey(), epoch_thread_id.into()); - let ix_a = clockwork_client::thread::instruction::thread_create( - LAMPORTS_PER_SOL, - client.payer_pubkey(), - epoch_thread_id.into(), - vec![ - clockwork_client::network::job::distribute_fees(epoch_thread_pubkey).into(), - clockwork_client::network::job::process_unstakes(epoch_thread_pubkey).into(), - clockwork_client::network::job::stake_delegations(epoch_thread_pubkey).into(), - clockwork_client::network::job::take_snapshot(epoch_thread_pubkey).into(), - clockwork_client::network::job::increment_epoch(epoch_thread_pubkey).into(), - clockwork_client::network::job::delete_snapshot(epoch_thread_pubkey).into(), - ], - client.payer_pubkey(), - epoch_thread_pubkey, - Trigger::Cron { - schedule: "0 * * * * * *".into(), - skippable: true, - }, - ); + let ix_a1 = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::DistributeFeesJob { + config: Config::pubkey(), + registry: Registry::pubkey(), + thread: epoch_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::DistributeFeesJob {}.data(), + }; + let ix_a2 = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::ProcessUnstakesJob { + config: Config::pubkey(), + registry: Registry::pubkey(), + thread: epoch_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::ProcessUnstakesJob {}.data(), + }; + let ix_a3 = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::StakeDelegationsJob { + config: Config::pubkey(), + registry: Registry::pubkey(), + thread: epoch_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::StakeDelegationsJob {}.data(), + }; + let ix_a4 = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::TakeSnapshotJob { + config: Config::pubkey(), + registry: Registry::pubkey(), + thread: epoch_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::TakeSnapshotJob {}.data(), + }; + let ix_a5 = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::EpochCutover { + config: Config::pubkey(), + registry: Registry::pubkey(), + thread: epoch_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::IncrementEpoch {}.data(), + }; + let ix_a6 = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::DeleteSnapshotJob { + config: Config::pubkey(), + registry: Registry::pubkey(), + thread: epoch_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::DeleteSnapshotJob {}.data(), + }; + let ix_a = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::ThreadCreate { + authority: client.payer_pubkey(), + payer: client.payer_pubkey(), + system_program: system_program::ID, + thread: epoch_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::ThreadCreate { + amount: LAMPORTS_PER_SOL, + id: epoch_thread_id.into(), + instructions: vec![ + ix_a1.into(), + ix_a2.into(), + ix_a3.into(), + ix_a4.into(), + ix_a5.into(), + ix_a6.into(), + ], + trigger: Trigger::Cron { + schedule: "0 * * * * * *".into(), + skippable: true, + }, + } + .data(), + }; // Create hasher thread. let hasher_thread_id = "clockwork.network.hasher"; let hasher_thread_pubkey = Thread::pubkey(client.payer_pubkey(), hasher_thread_id.into()); - let ix_b = clockwork_client::thread::instruction::thread_create( - LAMPORTS_PER_SOL, - client.payer_pubkey(), - hasher_thread_id.into(), - vec![ - clockwork_client::network::instruction::registry_nonce_hash(hasher_thread_pubkey) - .into(), - ], - client.payer_pubkey(), - hasher_thread_pubkey, - Trigger::Cron { - schedule: "*/15 * * * * * *".into(), - skippable: true, - }, - ); + let registry_hash_ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::RegistryNonceHash { + config: Config::pubkey(), + registry: Registry::pubkey(), + thread: hasher_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::RegistryNonceHash {}.data(), + }; + let ix_b = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::ThreadCreate { + authority: client.payer_pubkey(), + payer: client.payer_pubkey(), + system_program: system_program::ID, + thread: hasher_thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::ThreadCreate { + amount: LAMPORTS_PER_SOL, + id: hasher_thread_id.into(), + instructions: vec![ + registry_hash_ix.into(), + ], + trigger: Trigger::Cron { + schedule: "*/15 * * * * * *".into(), + skippable: true, + }, + } + .data(), + }; // Update config with thread pubkeys - let ix_c = clockwork_client::network::instruction::config_update( - client.payer_pubkey(), - ConfigSettings { + let settings = ConfigSettings { + admin: client.payer_pubkey(), + epoch_thread: epoch_thread_pubkey, + hasher_thread: hasher_thread_pubkey, + mint: mint_pubkey, + }; + let ix_c = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::ConfigUpdate { admin: client.payer_pubkey(), - epoch_thread: epoch_thread_pubkey, - hasher_thread: hasher_thread_pubkey, - mint: mint_pubkey, - }, - ); + config: Config::pubkey() + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::ConfigUpdate { settings }.data(), + }; client .send_and_confirm(&vec![ix_a], &[client.payer()]) @@ -256,14 +334,12 @@ fn start_test_validator( network_url: Option, clone_addresses: Vec, ) -> Result { - print_status!("Running", "Clockwork Validator {}\n", crate_version!()); - let path = config.active_runtime("solana-test-validator").to_owned(); let cmd = &mut Command::new(path); cmd.arg("-r") - .bpf_program(config, clockwork_client::network::ID, "network") - .bpf_program(config, clockwork_client::thread::ID, "thread") - .bpf_program(config, clockwork_client::webhook::ID, "webhook") + .bpf_program(config, clockwork_network_program::ID, "network") + .bpf_program(config, clockwork_thread_program::ID, "thread") + .bpf_program(config, clockwork_webhook_program::ID, "webhook") .network_url(network_url) .clone_addresses(clone_addresses) .add_programs_with_path(program_infos) @@ -272,6 +348,7 @@ fn start_test_validator( let mut process = cmd .spawn() .context(format!("solana-test-validator command: {:#?}", cmd))?; +print_status!("Running", "Clockwork Validator {}\n", crate_version!()); // Wait for the validator to become healthy let ms_wait = 10_000; diff --git a/cli/src/processor/mod.rs b/cli/src/processor/mod.rs index 6509f0588..97f3e0788 100644 --- a/cli/src/processor/mod.rs +++ b/cli/src/processor/mod.rs @@ -11,14 +11,12 @@ mod thread; mod webhook; mod worker; -use { - anyhow::Result, - clap::ArgMatches, - clockwork_client::Client, - solana_sdk::signature::read_keypair_file, -}; +use anyhow::Result; +use clap::ArgMatches; +use solana_sdk::signature::read_keypair_file; use crate::{ + client::Client, cli::CliCommand, config::CliConfig, errors::CliError, diff --git a/cli/src/processor/pool.rs b/cli/src/processor/pool.rs index 87fc6e9a1..8da7c4a0b 100644 --- a/cli/src/processor/pool.rs +++ b/cli/src/processor/pool.rs @@ -1,12 +1,12 @@ -use clockwork_client::network::state::PoolSettings; - -use { - crate::errors::CliError, - clockwork_client::{ - network::state::{Pool, Registry}, - Client, +use anchor_lang::{ + solana_program::{ + instruction::Instruction, system_program, }, + InstructionData, ToAccountMetas }; +use clockwork_network_program::state::{Config, Pool, Registry, PoolSettings}; + +use crate::{client::Client, errors::CliError}; pub fn get(client: &Client, id: u64) -> Result<(), CliError> { let pool_pubkey = Pool::pubkey(id); @@ -36,12 +36,18 @@ pub fn list(client: &Client) -> Result<(), CliError> { pub fn update(client: &Client, id: u64, size: usize) -> Result<(), CliError> { let pool_pubkey = Pool::pubkey(id); - let ix = clockwork_client::network::instruction::pool_update( - client.payer_pubkey(), - client.payer_pubkey(), - pool_pubkey, - PoolSettings { size }, - ); + let settings = PoolSettings { size }; + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::PoolUpdate { + admin: client.payer_pubkey(), + config: Config::pubkey(), + payer: client.payer_pubkey(), + pool: pool_pubkey, + system_program: system_program::ID, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::PoolUpdate { settings }.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client, id)?; Ok(()) diff --git a/cli/src/processor/registry.rs b/cli/src/processor/registry.rs index 174c7bd8f..bf6a99e42 100644 --- a/cli/src/processor/registry.rs +++ b/cli/src/processor/registry.rs @@ -1,13 +1,13 @@ -use { - crate::errors::CliError, - clockwork_client::{ - network::state::{Registry, Snapshot}, - Client, - }, +use anchor_lang::{ + solana_program::instruction::Instruction, + InstructionData, ToAccountMetas }; +use clockwork_network_program::state::{Config, Registry, Snapshot}; + +use crate::{client::Client, errors::CliError}; pub fn get(client: &Client) -> Result<(), CliError> { - let registry_pubkey = clockwork_client::network::state::Registry::pubkey(); + let registry_pubkey = clockwork_network_program::state::Registry::pubkey(); let registry = client .get::(®istry_pubkey) .map_err(|_err| CliError::AccountDataNotParsable(registry_pubkey.to_string()))?; @@ -23,7 +23,15 @@ pub fn get(client: &Client) -> Result<(), CliError> { } pub fn unlock(client: &Client) -> Result<(), CliError> { - let ix = clockwork_client::network::instruction::registry_unlock(client.payer_pubkey()); + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::RegistryUnlock { + admin: client.payer_pubkey(), + config: Config::pubkey(), + registry: Registry::pubkey() + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::RegistryUnlock {}.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client)?; Ok(()) diff --git a/cli/src/processor/secret.rs b/cli/src/processor/secret.rs index d465da9bd..d2343579c 100644 --- a/cli/src/processor/secret.rs +++ b/cli/src/processor/secret.rs @@ -1,12 +1,11 @@ use anchor_lang::prelude::Pubkey; -use clockwork_client::Client; use clockwork_relayer_api::{ SecretApprove, SecretCreate, SecretGet, SecretList, SecretRevoke, SignedRequest, }; use reqwest::header::CONTENT_TYPE; use solana_sdk::signer::Signer; -use crate::errors::CliError; +use crate::{client::Client, errors::CliError}; pub fn get(client: &Client, name: String) -> Result<(), CliError> { let keypair = &client.payer; diff --git a/cli/src/processor/snapshot.rs b/cli/src/processor/snapshot.rs index 7e3ceb89a..1c7a502f2 100644 --- a/cli/src/processor/snapshot.rs +++ b/cli/src/processor/snapshot.rs @@ -1,7 +1,7 @@ -use clockwork_client::network::objects::{Registry, Snapshot, SnapshotEntry}; +use clockwork_network_program::state::{Registry, Snapshot, SnapshotEntry}; use solana_sdk::pubkey::Pubkey; -use {crate::errors::CliError, clockwork_client::Client}; +use crate::{client::Client, errors::CliError}; pub fn get(client: &Client, entry_id: Option) -> Result<(), CliError> { let registry_pubkey = clockwork_client::network::objects::Registry::pubkey(); diff --git a/cli/src/processor/thread.rs b/cli/src/processor/thread.rs index 75980c53f..d7aca69e2 100644 --- a/cli/src/processor/thread.rs +++ b/cli/src/processor/thread.rs @@ -1,15 +1,21 @@ -use anchor_lang::AccountDeserialize; -use clockwork_client::{ - thread::state::{SerializableInstruction, Thread, ThreadSettings, Trigger, VersionedThread}, - Client, +use anchor_lang::{ + solana_program::{instruction::Instruction, system_program}, + InstructionData, AccountDeserialize, ToAccountMetas }; +use clockwork_thread_program::state::{SerializableInstruction, Thread, ThreadSettings, Trigger, VersionedThread}; use clockwork_utils::CrateInfo; use solana_sdk::pubkey::Pubkey; -use crate::errors::CliError; +use crate::{client::Client, errors::CliError}; pub fn crate_info(client: &Client) -> Result<(), CliError> { - let ix = clockwork_client::thread::instruction::get_crate_info(); + let ix = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::GetCrateInfo { + system_program: system_program::ID, + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::GetCrateInfo {}.data(), + }; let crate_info: CrateInfo = client.get_return_data(ix).unwrap(); println!("{:#?}", crate_info); Ok(()) @@ -22,15 +28,22 @@ pub fn create( trigger: Trigger, ) -> Result<(), CliError> { let thread_pubkey = Thread::pubkey(client.payer_pubkey(), id.clone().into_bytes()); - let ix = clockwork_client::thread::instruction::thread_create( - 0, - client.payer_pubkey(), - id.into_bytes(), - instructions, - client.payer_pubkey(), - thread_pubkey, - trigger, - ); + let ix = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::ThreadCreate { + authority: client.payer_pubkey(), + payer: client.payer_pubkey(), + system_program: system_program::ID, + thread: thread_pubkey + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::ThreadCreate { + amount: 0, + id: id.into_bytes(), + instructions, + trigger, + } + .data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client, thread_pubkey)?; Ok(()) @@ -38,11 +51,15 @@ pub fn create( pub fn delete(client: &Client, id: String) -> Result<(), CliError> { let thread_pubkey = Thread::pubkey(client.payer_pubkey(), id.into_bytes()); - let ix = clockwork_client::thread::instruction::thread_delete( - client.payer_pubkey(), - client.payer_pubkey(), - thread_pubkey, - ); + let ix = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::ThreadDelete { + authority: client.payer_pubkey(), + close_to: client.payer_pubkey(), + thread: thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::ThreadDelete {}.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); Ok(()) } @@ -50,17 +67,20 @@ pub fn delete(client: &Client, id: String) -> Result<(), CliError> { pub fn get(client: &Client, address: Pubkey) -> Result<(), CliError> { let data = client.get_account_data(&address).unwrap(); let thread = VersionedThread::try_deserialize(&mut data.as_slice()).unwrap(); - // let thread = client - // .get::(&address) - // .map_err(|_err| CliError::AccountDataNotParsable(address.to_string()))?; println!("Address: {}\n{:#?}", address, thread); Ok(()) } pub fn pause(client: &Client, id: String) -> Result<(), CliError> { let thread_pubkey = Thread::pubkey(client.payer_pubkey(), id.into_bytes()); - let ix = - clockwork_client::thread::instruction::thread_pause(client.payer_pubkey(), thread_pubkey); + let ix = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::ThreadPause { + authority: client.payer_pubkey(), + thread: thread_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::ThreadPause {}.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client, thread_pubkey)?; Ok(()) @@ -68,8 +88,14 @@ pub fn pause(client: &Client, id: String) -> Result<(), CliError> { pub fn resume(client: &Client, id: String) -> Result<(), CliError> { let thread_pubkey = Thread::pubkey(client.payer_pubkey(), id.into_bytes()); - let ix = - clockwork_client::thread::instruction::thread_resume(client.payer_pubkey(), thread_pubkey); + let ix = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::ThreadResume { + authority: client.payer_pubkey(), + thread: thread_pubkey + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::ThreadResume {}.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client, thread_pubkey)?; Ok(()) @@ -77,8 +103,14 @@ pub fn resume(client: &Client, id: String) -> Result<(), CliError> { pub fn reset(client: &Client, id: String) -> Result<(), CliError> { let thread_pubkey = Thread::pubkey(client.payer_pubkey(), id.into_bytes()); - let ix = - clockwork_client::thread::instruction::thread_reset(client.payer_pubkey(), thread_pubkey); + let ix = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::ThreadReset { + authority: client.payer_pubkey(), + thread: thread_pubkey + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::ThreadReset {}.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client, thread_pubkey)?; Ok(()) @@ -106,11 +138,15 @@ pub fn update( rate_limit, trigger, }; - let ix = clockwork_client::thread::instruction::thread_update( - client.payer_pubkey(), - thread_pubkey, - settings, - ); + let ix = Instruction { + program_id: clockwork_thread_program::ID, + accounts: clockwork_thread_program::accounts::ThreadUpdate { + authority: client.payer_pubkey(), + system_program: system_program::ID, + thread: thread_pubkey + }.to_account_metas(Some(false)), + data: clockwork_thread_program::instruction::ThreadUpdate { settings }.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client, thread_pubkey)?; Ok(()) diff --git a/cli/src/processor/webhook.rs b/cli/src/processor/webhook.rs index 5975467e5..9af3748e3 100644 --- a/cli/src/processor/webhook.rs +++ b/cli/src/processor/webhook.rs @@ -1,14 +1,10 @@ use std::collections::HashMap; -// use anchor_lang::prelude::*; use anchor_lang::{InstructionData, ToAccountMetas}; -use clockwork_client::{ - webhook::state::{HttpMethod, Webhook}, - Client, -}; +use clockwork_webhook_program::state::{HttpMethod, Webhook}; use solana_sdk::{instruction::Instruction, system_program}; -use crate::errors::CliError; +use crate::{client::Client, errors::CliError}; pub fn create( client: &Client, diff --git a/cli/src/processor/worker.rs b/cli/src/processor/worker.rs index 604a5a36f..3b2db1e91 100644 --- a/cli/src/processor/worker.rs +++ b/cli/src/processor/worker.rs @@ -1,13 +1,17 @@ -use anchor_lang::AccountDeserialize; -use clockwork_client::{ - network::state::{ - Config, Fee, Penalty, Registry, Snapshot, SnapshotFrame, Worker, WorkerSettings, +use anchor_lang::{ + solana_program::{ + instruction::Instruction, + system_program, sysvar, }, - Client, + AccountDeserialize, InstructionData, ToAccountMetas +}; +use anchor_spl::{associated_token, associated_token::get_associated_token_address, token}; +use clockwork_network_program::state::{ + Config, Fee, Penalty, Registry, Snapshot, SnapshotFrame, Worker, WorkerSettings, }; use solana_sdk::signature::{Keypair, Signer}; -use crate::errors::CliError; +use crate::{client::Client, errors::CliError}; pub fn get(client: &Client, id: u64) -> Result<(), CliError> { let worker_pubkey = Worker::pubkey(id); @@ -87,12 +91,25 @@ pub fn create(client: &Client, signatory: Keypair, silent: bool) -> Result<(), C // Build ix let worker_id = registry.total_workers; let worker_pubkey = Worker::pubkey(worker_id); - let ix = clockwork_client::network::instruction::worker_create( - client.payer_pubkey(), - config.mint, - signatory.pubkey(), - worker_pubkey, - ); + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::WorkerCreate { + associated_token_program: associated_token::ID, + authority: client.payer_pubkey(), + config: Config::pubkey(), + fee: Fee::pubkey(worker_pubkey), + penalty: Penalty::pubkey(worker_pubkey), + mint: config.mint, + registry: Registry::pubkey(), + rent: sysvar::rent::ID, + signatory: signatory.pubkey(), + system_program: system_program::ID, + token_program: token::ID, + worker: worker_pubkey, + worker_tokens: get_associated_token_address(&worker_pubkey, &config.mint), + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::WorkerCreate {}.data(), + }; client .send_and_confirm(&[ix], &[client.payer(), &signatory]) .unwrap(); @@ -114,11 +131,15 @@ pub fn update(client: &Client, id: u64, signatory: Option) -> Result<() commission_rate: 0, signatory: signatory.map_or(worker.signatory, |v| v.pubkey()), }; - let ix = clockwork_client::network::instruction::worker_update( - client.payer_pubkey(), - settings, - worker_pubkey, - ); + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::WorkerUpdate { + authority: client.payer_pubkey(), + system_program: system_program::ID, + worker: worker_pubkey, + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::WorkerUpdate { settings }.data(), + }; client.send_and_confirm(&[ix], &[client.payer()]).unwrap(); get(client, worker.id)?; Ok(()) diff --git a/client/.gitignore b/client/.gitignore deleted file mode 100644 index 89b165399..000000000 --- a/client/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -keypair.json \ No newline at end of file diff --git a/client/Cargo.toml b/client/Cargo.toml deleted file mode 100644 index db29bfcc9..000000000 --- a/client/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "clockwork-client" -version = "2.0.15" -edition = "2021" -description = "Clockwork client" -license = "AGPL-3.0-or-later" -homepage = "https://clockwork.xyz" -repository = "https://github.com/clockwork-xyz/client" -documentation = "https://docs.rs/clockwork-client" -readme = "./README.md" -keywords = ["solana"] - -[lib] -crate-type = ["cdylib", "lib"] -name = "clockwork_client" - -[dependencies] -anchor-lang = "0.27.0" -anchor-spl = { features = ["mint", "token"], version = "0.27.0" } -bincode = "1.3.3" -borsh = "0.9.3" -clockwork-network-program = { path = "../programs/network", features = ["no-entrypoint"], version = "=2.0.15" } -clockwork-thread-program = { path = "../programs/thread", features = ["no-entrypoint"], version = "=2.0.15" } -clockwork-utils = { path = "../utils", version = "=2.0.15" } -clockwork-webhook-program = { path = "../programs/webhook", features = ["no-entrypoint"], version = "=2.0.15" } -solana-client = "=1.14.16" -solana-sdk = "=1.14.16" -spl-associated-token-account = { version = "1.1.1", features = ["no-entrypoint"] } -thiserror = "1.0.31" diff --git a/client/README.md b/client/README.md deleted file mode 100644 index 3ec4ba41e..000000000 --- a/client/README.md +++ /dev/null @@ -1 +0,0 @@ -# Clockwork SDK diff --git a/client/src/client.rs b/client/src/client.rs deleted file mode 100644 index b123e020b..000000000 --- a/client/src/client.rs +++ /dev/null @@ -1,404 +0,0 @@ -use anchor_lang::{prelude::Clock, AccountDeserialize}; -use anchor_spl::token::{ - spl_token::{self, state::Account as TokenAccount}, - Mint, -}; -use clockwork_utils::ProgramLogsDeserializable; -use solana_client::{ - client_error, rpc_client::RpcClient, rpc_config::RpcSendTransactionConfig, - rpc_response::RpcSimulateTransactionResult, -}; -use solana_sdk::{ - commitment_config::CommitmentConfig, - hash::Hash, - instruction::Instruction, - program_error::ProgramError, - program_pack::Pack, - pubkey::Pubkey, - signature::{Keypair, Signature, Signer}, - signers::Signers, - system_instruction, - transaction::Transaction, -}; -use std::{ - fmt::Debug, - ops::{Deref, DerefMut}, - str::FromStr, -}; -use thiserror::Error; - -#[derive(Debug, Error)] -pub enum ClientError { - #[error(transparent)] - Client(#[from] client_error::ClientError), - - #[error(transparent)] - Program(#[from] ProgramError), - - #[error("Failed to deserialize account data")] - DeserializationError, -} - -pub type ClientResult = Result; - -pub struct Client { - pub client: RpcClient, - pub payer: Keypair, -} - -impl Client { - pub fn new(payer: Keypair, url: String) -> Self { - let client = RpcClient::new_with_commitment::(url, CommitmentConfig::processed()); - Self { client, payer } - } - - pub fn get(&self, pubkey: &Pubkey) -> ClientResult { - let data = self.client.get_account_data(pubkey)?; - T::try_deserialize(&mut data.as_slice()).map_err(|_| ClientError::DeserializationError) - } - - pub fn get_clock(&self) -> ClientResult { - let clock_pubkey = Pubkey::from_str("SysvarC1ock11111111111111111111111111111111").unwrap(); - let clock_data = self.client.get_account_data(&clock_pubkey)?; - bincode::deserialize::(&clock_data).map_err(|_| ClientError::DeserializationError) - } - - pub fn get_return_data( - &self, - ix: Instruction, - ) -> ClientResult { - // let result = self.simulate_transaction(&[ix.clone()], &[self.payer()])?; - - // After we can upgrade our Solana SDK version to 1.14.0 we can just use the below code: - // let data = result.logs; - // Ok(T::try_from_slice(logs, &data) - // .map_err(|_| ClientError::DeserializationError)?) - // - // But for the time being since RpcSimulateTransactionResult.data does not exist yet, - // We can only parse the logs ourselves to find the return_data - let logs = self.get_instruction_logs(ix.clone())?; - T::try_from_program_logs(logs, &ix.program_id) - .map_err(|_| ClientError::DeserializationError) - } - - pub fn get_instruction_logs(&self, ix: Instruction) -> ClientResult> { - let result = self.simulate_transaction(&[ix], &[self.payer()])?; - let logs = result.logs.ok_or(ClientError::DeserializationError)?; - Ok(logs) - } - - pub fn payer(&self) -> &Keypair { - &self.payer - } - - pub fn payer_pubkey(&self) -> Pubkey { - self.payer.pubkey() - } - - pub fn latest_blockhash(&self) -> ClientResult { - Ok(self.client.get_latest_blockhash()?) - } - - pub fn airdrop(&self, to_pubkey: &Pubkey, lamports: u64) -> ClientResult { - let blockhash = self.client.get_latest_blockhash()?; - let signature = self.request_airdrop_with_blockhash(to_pubkey, lamports, &blockhash)?; - self.confirm_transaction_with_spinner(&signature, &blockhash, self.commitment())?; - Ok(signature) - } - - pub fn send(&self, ixs: &[Instruction], signers: &T) -> ClientResult { - let mut tx = Transaction::new_with_payer(ixs, Some(&self.payer_pubkey())); - tx.sign(signers, self.latest_blockhash()?); - Ok(self.send_transaction(&tx)?) - } - - pub fn send_with_config( - &self, - ixs: &[Instruction], - signers: &T, - config: RpcSendTransactionConfig, - ) -> ClientResult { - let tx = self.transaction(ixs, signers)?; - Ok(self.client.send_transaction_with_config(&tx, config)?) - } - - pub fn send_and_confirm( - &self, - ixs: &[Instruction], - signers: &T, - ) -> ClientResult { - let tx = self.transaction(ixs, signers)?; - Ok(self.send_and_confirm_transaction(&tx)?) - } - - pub fn simulate_transaction( - &self, - ixs: &[Instruction], - signers: &T, - ) -> ClientResult { - let tx = self.transaction(ixs, signers)?; - let result = self.client.simulate_transaction(&tx)?; - if result.value.err.is_some() { - Err(ClientError::DeserializationError) - } else { - Ok(result.value) - } - } - - fn transaction( - &self, - ixs: &[Instruction], - signers: &T, - ) -> ClientResult { - let mut tx = Transaction::new_with_payer(ixs, Some(&self.payer_pubkey())); - tx.sign(signers, self.latest_blockhash()?); - Ok(tx) - } -} - -impl Debug for Client { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "RPC client payer {}", self.payer_pubkey()) - } -} - -impl Deref for Client { - type Target = RpcClient; - - fn deref(&self) -> &Self::Target { - &self.client - } -} - -impl DerefMut for Client { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.client - } -} - -pub trait SplToken { - fn create_token_mint(&self, owner: &Pubkey, decimals: u8) -> ClientResult; - fn create_token_account(&self, owner: &Pubkey, token_mint: &Pubkey) -> ClientResult; - fn create_token_account_with_lamports( - &self, - owner: &Pubkey, - token_mint: &Pubkey, - lamports: u64, - ) -> ClientResult; - fn mint_to( - &self, - owner: &Keypair, - token_mint: &Pubkey, - account: &Pubkey, - amount: u64, - decimals: u8, - ) -> ClientResult<()>; - fn transfer_to( - &self, - owner: &Keypair, - token_mint: &Pubkey, - source: &Pubkey, - destination: &Pubkey, - amount: u64, - decimals: u8, - ) -> ClientResult<()>; - fn get_associated_token_address(wallet_address: &Pubkey, token_mint: &Pubkey) -> Pubkey; - fn create_associated_token_account( - &self, - funder: &Keypair, - recipient: &Pubkey, - token_mint: &Pubkey, - ) -> ClientResult; - fn create_associated_token_account_by_payer( - &self, - recipient: &Pubkey, - token_mint: &Pubkey, - ) -> ClientResult; - fn close_token_account( - &self, - owner: &Keypair, - account: &Pubkey, - destination: &Pubkey, - ) -> ClientResult<()>; -} - -impl SplToken for Client { - fn create_token_mint(&self, owner: &Pubkey, decimals: u8) -> ClientResult { - let token_mint = Keypair::new(); - - let mut transaction = Transaction::new_with_payer( - &[ - system_instruction::create_account( - &self.payer_pubkey(), - &token_mint.pubkey(), - self.get_minimum_balance_for_rent_exemption(Mint::LEN)?, - Mint::LEN as u64, - &spl_token::id(), - ), - spl_token::instruction::initialize_mint( - &spl_token::id(), - &token_mint.pubkey(), - owner, - None, - decimals, - )?, - ], - Some(&self.payer_pubkey()), - ); - transaction.sign(&[self.payer(), &token_mint], self.latest_blockhash()?); - self.send_and_confirm_transaction(&transaction)?; - - Ok(token_mint) - } - fn create_token_account(&self, owner: &Pubkey, token_mint: &Pubkey) -> ClientResult { - self.create_token_account_with_lamports( - owner, - token_mint, - self.get_minimum_balance_for_rent_exemption(TokenAccount::LEN)?, - ) - } - fn create_token_account_with_lamports( - &self, - owner: &Pubkey, - token_mint: &Pubkey, - lamports: u64, - ) -> ClientResult { - let token_account = Keypair::new(); - - let mut transaction = Transaction::new_with_payer( - &[ - system_instruction::create_account( - &self.payer_pubkey(), - &token_account.pubkey(), - lamports, - TokenAccount::LEN as u64, - &spl_token::id(), - ), - spl_token::instruction::initialize_account( - &spl_token::id(), - &token_account.pubkey(), - token_mint, - owner, - )?, - ], - Some(&self.payer_pubkey()), - ); - transaction.sign(&[self.payer(), &token_account], self.latest_blockhash()?); - self.send_and_confirm_transaction(&transaction)?; - - Ok(token_account) - } - fn mint_to( - &self, - owner: &Keypair, - token_mint: &Pubkey, - account: &Pubkey, - amount: u64, - decimals: u8, - ) -> ClientResult<()> { - let mut transaction = Transaction::new_with_payer( - &[spl_token::instruction::mint_to_checked( - &spl_token::id(), - token_mint, - account, - &owner.pubkey(), - &[], - amount, - decimals, - )?], - Some(&self.payer_pubkey()), - ); - transaction.sign(&[self.payer(), owner], self.latest_blockhash()?); - self.send_and_confirm_transaction(&transaction)?; - - Ok(()) - } - - fn transfer_to( - &self, - authority: &Keypair, - token_mint: &Pubkey, - source: &Pubkey, - destination: &Pubkey, - amount: u64, - decimals: u8, - ) -> ClientResult<()> { - let mut transaction = Transaction::new_with_payer( - &[spl_token::instruction::transfer_checked( - &spl_token::id(), - source, - token_mint, - destination, - &authority.pubkey(), - &[], - amount, - decimals, - )?], - Some(&self.payer_pubkey()), - ); - transaction.sign(&[self.payer(), authority], self.latest_blockhash()?); - self.send_and_confirm_transaction(&transaction)?; - - Ok(()) - } - fn get_associated_token_address(wallet_address: &Pubkey, token_mint: &Pubkey) -> Pubkey { - spl_associated_token_account::get_associated_token_address(wallet_address, token_mint) - } - - fn create_associated_token_account( - &self, - funder: &Keypair, - recipient: &Pubkey, - token_mint: &Pubkey, - ) -> ClientResult { - let mut transaction = Transaction::new_with_payer( - &[ - spl_associated_token_account::instruction::create_associated_token_account( - &funder.pubkey(), - recipient, - token_mint, - &anchor_spl::token::ID, - ), - ], - Some(&self.payer_pubkey()), - ); - if funder.pubkey() == self.payer_pubkey() { - transaction.sign(&[self.payer()], self.latest_blockhash()?); - } else { - transaction.sign(&[self.payer(), funder], self.latest_blockhash()?); - }; - self.send_and_confirm_transaction(&transaction)?; - - Ok(Self::get_associated_token_address(recipient, token_mint)) - } - - fn create_associated_token_account_by_payer( - &self, - recipient: &Pubkey, - token_mint: &Pubkey, - ) -> ClientResult { - self.create_associated_token_account(self.payer(), recipient, token_mint) - } - - fn close_token_account( - &self, - owner: &Keypair, - account: &Pubkey, - destination: &Pubkey, - ) -> ClientResult<()> { - let mut transaction = Transaction::new_with_payer( - &[spl_token::instruction::close_account( - &spl_token::id(), - account, - destination, - &owner.pubkey(), - &[], - )?], - Some(&self.payer_pubkey()), - ); - transaction.sign(&[self.payer(), owner], self.latest_blockhash()?); - self.send_and_confirm_transaction(&transaction)?; - - Ok(()) - } -} diff --git a/client/src/lib.rs b/client/src/lib.rs deleted file mode 100644 index 8032bbad4..000000000 --- a/client/src/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod network; -pub mod thread; -pub mod webhook; - -mod client; -pub use client::{Client, ClientError, ClientResult, SplToken}; diff --git a/client/src/network/instruction/config_update.rs b/client/src/network/instruction/config_update.rs deleted file mode 100644 index 5564859d9..000000000 --- a/client/src/network/instruction/config_update.rs +++ /dev/null @@ -1,21 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn config_update(admin: Pubkey, settings: ConfigSettings) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new(admin, true), - AccountMeta::new(Config::pubkey(), false), - ], - data: clockwork_network_program::instruction::ConfigUpdate { settings }.data(), - } -} diff --git a/client/src/network/instruction/delegation_create.rs b/client/src/network/instruction/delegation_create.rs deleted file mode 100644 index bf6bd08f7..000000000 --- a/client/src/network/instruction/delegation_create.rs +++ /dev/null @@ -1,36 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, sysvar, - }, - InstructionData, - }, - clockwork_network_program::state::*, - spl_associated_token_account::get_associated_token_address, -}; - -pub fn delegation_create( - authority: Pubkey, - delegation: Pubkey, - mint: Pubkey, - worker: Pubkey, -) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(anchor_spl::associated_token::ID, false), - AccountMeta::new(authority, true), - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(delegation, false), - AccountMeta::new(get_associated_token_address(&delegation, &mint), false), - AccountMeta::new_readonly(mint, false), - AccountMeta::new_readonly(sysvar::rent::ID, false), - AccountMeta::new_readonly(system_program::ID, false), - AccountMeta::new_readonly(anchor_spl::token::ID, false), - AccountMeta::new(worker, false), - ], - data: clockwork_network_program::instruction::DelegationCreate {}.data(), - } -} diff --git a/client/src/network/instruction/delegation_deposit.rs b/client/src/network/instruction/delegation_deposit.rs deleted file mode 100644 index 6ed3f15b3..000000000 --- a/client/src/network/instruction/delegation_deposit.rs +++ /dev/null @@ -1,31 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, - spl_associated_token_account::get_associated_token_address, -}; - -pub fn delegation_deposit( - amount: u64, - authority: Pubkey, - delegation: Pubkey, - mint: Pubkey, -) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new(authority, true), - AccountMeta::new(get_associated_token_address(&authority, &mint), false), - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(delegation, false), - AccountMeta::new(get_associated_token_address(&delegation, &mint), false), - AccountMeta::new_readonly(anchor_spl::token::ID, false), - ], - data: clockwork_network_program::instruction::DelegationDeposit { amount }.data(), - } -} diff --git a/client/src/network/instruction/delegation_withdraw.rs b/client/src/network/instruction/delegation_withdraw.rs deleted file mode 100644 index d3dcf5a77..000000000 --- a/client/src/network/instruction/delegation_withdraw.rs +++ /dev/null @@ -1,31 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, - spl_associated_token_account::get_associated_token_address, -}; - -pub fn delegation_withdraw( - amount: u64, - authority: Pubkey, - delegation: Pubkey, - mint: Pubkey, -) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new(authority, true), - AccountMeta::new(get_associated_token_address(&authority, &mint), false), - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(delegation, false), - AccountMeta::new(get_associated_token_address(&delegation, &mint), false), - AccountMeta::new_readonly(anchor_spl::token::ID, false), - ], - data: clockwork_network_program::instruction::DelegationWithdraw { amount }.data(), - } -} diff --git a/client/src/network/instruction/initialize.rs b/client/src/network/instruction/initialize.rs deleted file mode 100644 index 77129257b..000000000 --- a/client/src/network/instruction/initialize.rs +++ /dev/null @@ -1,26 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn initialize(admin: Pubkey, mint: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new(admin, true), - AccountMeta::new(Config::pubkey(), false), - AccountMeta::new_readonly(mint, false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new(Snapshot::pubkey(0), false), - AccountMeta::new_readonly(system_program::ID, false), - ], - data: clockwork_network_program::instruction::Initialize {}.data(), - } -} diff --git a/client/src/network/instruction/mod.rs b/client/src/network/instruction/mod.rs deleted file mode 100644 index dedc4f0b3..000000000 --- a/client/src/network/instruction/mod.rs +++ /dev/null @@ -1,25 +0,0 @@ -mod config_update; -mod delegation_create; -mod delegation_deposit; -mod delegation_withdraw; -mod initialize; -mod pool_create; -mod pool_rotate; -mod pool_update; -mod registry_nonce_hash; -mod registry_unlock; -mod worker_create; -mod worker_update; - -pub use config_update::*; -pub use delegation_create::*; -pub use delegation_deposit::*; -pub use delegation_withdraw::*; -pub use initialize::*; -pub use pool_create::*; -pub use pool_rotate::*; -pub use pool_update::*; -pub use registry_nonce_hash::*; -pub use registry_unlock::*; -pub use worker_create::*; -pub use worker_update::*; diff --git a/client/src/network/instruction/pool_create.rs b/client/src/network/instruction/pool_create.rs deleted file mode 100644 index 284ae7266..000000000 --- a/client/src/network/instruction/pool_create.rs +++ /dev/null @@ -1,26 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn pool_create(admin: Pubkey, payer: Pubkey, pool: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(admin, true), - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(payer, true), - AccountMeta::new(pool, false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new_readonly(system_program::ID, false), - ], - data: clockwork_network_program::instruction::PoolCreate {}.data(), - } -} diff --git a/client/src/network/instruction/pool_rotate.rs b/client/src/network/instruction/pool_rotate.rs deleted file mode 100644 index e6c0c8123..000000000 --- a/client/src/network/instruction/pool_rotate.rs +++ /dev/null @@ -1,32 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn pool_rotate( - pool: Pubkey, - signatory: Pubkey, - snapshot: Pubkey, - snapshot_frame: Pubkey, - worker: Pubkey, -) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(pool, false), - AccountMeta::new_readonly(Registry::pubkey(), false), - AccountMeta::new(signatory, true), - AccountMeta::new_readonly(snapshot, false), - AccountMeta::new_readonly(snapshot_frame, false), - AccountMeta::new_readonly(worker, false), - ], - data: clockwork_network_program::instruction::PoolRotate {}.data(), - } -} diff --git a/client/src/network/instruction/pool_update.rs b/client/src/network/instruction/pool_update.rs deleted file mode 100644 index 8c095d263..000000000 --- a/client/src/network/instruction/pool_update.rs +++ /dev/null @@ -1,30 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn pool_update( - admin: Pubkey, - payer: Pubkey, - pool: Pubkey, - settings: PoolSettings, -) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(admin, true), - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(payer, true), - AccountMeta::new(pool, false), - AccountMeta::new_readonly(system_program::ID, false), - ], - data: clockwork_network_program::instruction::PoolUpdate { settings }.data(), - } -} diff --git a/client/src/network/instruction/registry_nonce_hash.rs b/client/src/network/instruction/registry_nonce_hash.rs deleted file mode 100644 index 006a332c6..000000000 --- a/client/src/network/instruction/registry_nonce_hash.rs +++ /dev/null @@ -1,22 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn registry_nonce_hash(thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new_readonly(thread, true), - ], - data: clockwork_network_program::instruction::RegistryNonceHash {}.data(), - } -} diff --git a/client/src/network/instruction/registry_unlock.rs b/client/src/network/instruction/registry_unlock.rs deleted file mode 100644 index 53889e6d8..000000000 --- a/client/src/network/instruction/registry_unlock.rs +++ /dev/null @@ -1,22 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn registry_unlock(admin: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new(admin, true), - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(Registry::pubkey(), false), - ], - data: clockwork_network_program::instruction::RegistryUnlock {}.data(), - } -} diff --git a/client/src/network/instruction/worker_create.rs b/client/src/network/instruction/worker_create.rs deleted file mode 100644 index f6aa78f48..000000000 --- a/client/src/network/instruction/worker_create.rs +++ /dev/null @@ -1,39 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, sysvar, - }, - InstructionData, - }, - anchor_spl::{associated_token, associated_token::get_associated_token_address, token}, - clockwork_network_program::state::*, -}; - -pub fn worker_create( - authority: Pubkey, - mint: Pubkey, - signatory: Pubkey, - worker: Pubkey, -) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(associated_token::ID, false), - AccountMeta::new(authority, true), - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(Fee::pubkey(worker), false), - AccountMeta::new(Penalty::pubkey(worker), false), - AccountMeta::new_readonly(mint, false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new_readonly(sysvar::rent::ID, false), - AccountMeta::new_readonly(signatory, true), - AccountMeta::new_readonly(system_program::ID, false), - AccountMeta::new_readonly(token::ID, false), - AccountMeta::new(worker, false), - AccountMeta::new(get_associated_token_address(&worker, &mint), false), - ], - data: clockwork_network_program::instruction::WorkerCreate {}.data(), - } -} diff --git a/client/src/network/instruction/worker_update.rs b/client/src/network/instruction/worker_update.rs deleted file mode 100644 index 1e55d5920..000000000 --- a/client/src/network/instruction/worker_update.rs +++ /dev/null @@ -1,21 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, - }, - InstructionData, -}; -use clockwork_network_program::state::*; - -pub fn worker_update(authority: Pubkey, settings: WorkerSettings, worker: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new(authority, true), - AccountMeta::new_readonly(system_program::ID, false), - AccountMeta::new(worker, false), - ], - data: clockwork_network_program::instruction::WorkerUpdate { settings }.data(), - } -} diff --git a/client/src/network/job/delete_snapshot.rs b/client/src/network/job/delete_snapshot.rs deleted file mode 100644 index 0cf08d858..000000000 --- a/client/src/network/job/delete_snapshot.rs +++ /dev/null @@ -1,22 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn delete_snapshot(thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new_readonly(thread, true), - ], - data: clockwork_network_program::instruction::DeleteSnapshotJob {}.data(), - } -} diff --git a/client/src/network/job/distribute_fees.rs b/client/src/network/job/distribute_fees.rs deleted file mode 100644 index 43061cceb..000000000 --- a/client/src/network/job/distribute_fees.rs +++ /dev/null @@ -1,22 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn distribute_fees(thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new_readonly(thread, true), - ], - data: clockwork_network_program::instruction::DistributeFeesJob {}.data(), - } -} diff --git a/client/src/network/job/increment_epoch.rs b/client/src/network/job/increment_epoch.rs deleted file mode 100644 index 9e44fce20..000000000 --- a/client/src/network/job/increment_epoch.rs +++ /dev/null @@ -1,22 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn increment_epoch(thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new_readonly(thread, true), - ], - data: clockwork_network_program::instruction::IncrementEpoch {}.data(), - } -} diff --git a/client/src/network/job/mod.rs b/client/src/network/job/mod.rs deleted file mode 100644 index 53bf44788..000000000 --- a/client/src/network/job/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -mod delete_snapshot; -mod distribute_fees; -mod increment_epoch; -mod process_unstakes; -mod stake_delegations; -mod take_snapshot; - -pub use delete_snapshot::*; -pub use distribute_fees::*; -pub use increment_epoch::*; -pub use process_unstakes::*; -pub use stake_delegations::*; -pub use take_snapshot::*; diff --git a/client/src/network/job/process_unstakes.rs b/client/src/network/job/process_unstakes.rs deleted file mode 100644 index 5bb315ba2..000000000 --- a/client/src/network/job/process_unstakes.rs +++ /dev/null @@ -1,22 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn process_unstakes(thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new_readonly(Registry::pubkey(), false), - AccountMeta::new_readonly(thread, true), - ], - data: clockwork_network_program::instruction::ProcessUnstakesJob {}.data(), - } -} diff --git a/client/src/network/job/stake_delegations.rs b/client/src/network/job/stake_delegations.rs deleted file mode 100644 index 6ba9a6185..000000000 --- a/client/src/network/job/stake_delegations.rs +++ /dev/null @@ -1,22 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn stake_delegations(thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new_readonly(thread, true), - ], - data: clockwork_network_program::instruction::StakeDelegationsJob {}.data(), - } -} diff --git a/client/src/network/job/take_snapshot.rs b/client/src/network/job/take_snapshot.rs deleted file mode 100644 index f33cebdf8..000000000 --- a/client/src/network/job/take_snapshot.rs +++ /dev/null @@ -1,22 +0,0 @@ -use { - anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, - }, - clockwork_network_program::state::*, -}; - -pub fn take_snapshot(thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_network_program::ID, - accounts: vec![ - AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new(Registry::pubkey(), false), - AccountMeta::new_readonly(thread, true), - ], - data: clockwork_network_program::instruction::TakeSnapshotJob {}.data(), - } -} diff --git a/client/src/network/mod.rs b/client/src/network/mod.rs deleted file mode 100644 index 5fe9cf305..000000000 --- a/client/src/network/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod instruction; -pub mod job; - -pub use clockwork_network_program::state; -pub use clockwork_network_program::ID; diff --git a/client/src/thread/instruction/get_crate_info.rs b/client/src/thread/instruction/get_crate_info.rs deleted file mode 100644 index 2d4e0faa2..000000000 --- a/client/src/thread/instruction/get_crate_info.rs +++ /dev/null @@ -1,15 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - system_program, - }, - InstructionData, -}; - -pub fn get_crate_info() -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![AccountMeta::new_readonly(system_program::ID, false)], - data: clockwork_thread_program::instruction::GetCrateInfo {}.data(), - } -} diff --git a/client/src/thread/instruction/mod.rs b/client/src/thread/instruction/mod.rs deleted file mode 100644 index b61974ec9..000000000 --- a/client/src/thread/instruction/mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -mod thread_create; -mod thread_delete; -mod thread_exec; -mod thread_kickoff; -mod thread_pause; -mod thread_reset; -mod thread_resume; -mod thread_update; -mod get_crate_info; - -pub use thread_create::*; -pub use thread_delete::*; -pub use thread_exec::*; -pub use thread_kickoff::*; -pub use thread_pause::*; -pub use thread_reset::*; -pub use thread_resume::*; -pub use thread_update::*; -pub use get_crate_info::*; diff --git a/client/src/thread/instruction/thread_create.rs b/client/src/thread/instruction/thread_create.rs deleted file mode 100644 index 0f0c14d52..000000000 --- a/client/src/thread/instruction/thread_create.rs +++ /dev/null @@ -1,36 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, - }, - InstructionData, -}; -use clockwork_thread_program::state::{SerializableInstruction, Trigger}; - -pub fn thread_create( - amount: u64, - authority: Pubkey, - id: Vec, - instructions: Vec, - payer: Pubkey, - thread: Pubkey, - trigger: Trigger, -) -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![ - AccountMeta::new_readonly(authority, true), - AccountMeta::new(payer, true), - AccountMeta::new_readonly(system_program::ID, false), - AccountMeta::new(thread, false), - ], - data: clockwork_thread_program::instruction::ThreadCreate { - amount, - id, - instructions, - trigger, - } - .data(), - } -} diff --git a/client/src/thread/instruction/thread_delete.rs b/client/src/thread/instruction/thread_delete.rs deleted file mode 100644 index 294465ae1..000000000 --- a/client/src/thread/instruction/thread_delete.rs +++ /dev/null @@ -1,19 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, -}; - -pub fn thread_delete(authority: Pubkey, close_to: Pubkey, thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![ - AccountMeta::new_readonly(authority, true), - AccountMeta::new(close_to, true), - AccountMeta::new(thread, false), - ], - data: clockwork_thread_program::instruction::ThreadDelete {}.data(), - } -} diff --git a/client/src/thread/instruction/thread_exec.rs b/client/src/thread/instruction/thread_exec.rs deleted file mode 100644 index 45dc4d51b..000000000 --- a/client/src/thread/instruction/thread_exec.rs +++ /dev/null @@ -1,22 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, -}; -use clockwork_network_program::state::{Fee, Pool}; - -pub fn thread_exec(signatory: Pubkey, thread: Pubkey, worker: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![ - AccountMeta::new(Fee::pubkey(worker), false), - AccountMeta::new_readonly(Pool::pubkey(0), false), - AccountMeta::new(signatory, true), - AccountMeta::new(thread, false), - AccountMeta::new_readonly(worker, false), - ], - data: clockwork_thread_program::instruction::ThreadExec {}.data(), - } -} diff --git a/client/src/thread/instruction/thread_kickoff.rs b/client/src/thread/instruction/thread_kickoff.rs deleted file mode 100644 index cd0ffdce0..000000000 --- a/client/src/thread/instruction/thread_kickoff.rs +++ /dev/null @@ -1,19 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, -}; - -pub fn thread_kickoff(signatory: Pubkey, thread: Pubkey, worker: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![ - AccountMeta::new(signatory, true), - AccountMeta::new(thread, false), - AccountMeta::new_readonly(worker, false), - ], - data: clockwork_thread_program::instruction::ThreadKickoff {}.data(), - } -} diff --git a/client/src/thread/instruction/thread_pause.rs b/client/src/thread/instruction/thread_pause.rs deleted file mode 100644 index 48a4248ca..000000000 --- a/client/src/thread/instruction/thread_pause.rs +++ /dev/null @@ -1,18 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, -}; - -pub fn thread_pause(authority: Pubkey, thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![ - AccountMeta::new_readonly(authority, true), - AccountMeta::new(thread, false), - ], - data: clockwork_thread_program::instruction::ThreadPause {}.data(), - } -} diff --git a/client/src/thread/instruction/thread_reset.rs b/client/src/thread/instruction/thread_reset.rs deleted file mode 100644 index f605f01f4..000000000 --- a/client/src/thread/instruction/thread_reset.rs +++ /dev/null @@ -1,18 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, -}; - -pub fn thread_reset(authority: Pubkey, thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![ - AccountMeta::new_readonly(authority, true), - AccountMeta::new(thread, false), - ], - data: clockwork_thread_program::instruction::ThreadReset {}.data(), - } -} diff --git a/client/src/thread/instruction/thread_resume.rs b/client/src/thread/instruction/thread_resume.rs deleted file mode 100644 index 41cb026a7..000000000 --- a/client/src/thread/instruction/thread_resume.rs +++ /dev/null @@ -1,18 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - }, - InstructionData, -}; - -pub fn thread_resume(authority: Pubkey, thread: Pubkey) -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![ - AccountMeta::new_readonly(authority, true), - AccountMeta::new(thread, false), - ], - data: clockwork_thread_program::instruction::ThreadResume {}.data(), - } -} diff --git a/client/src/thread/instruction/thread_update.rs b/client/src/thread/instruction/thread_update.rs deleted file mode 100644 index 95cbd2076..000000000 --- a/client/src/thread/instruction/thread_update.rs +++ /dev/null @@ -1,22 +0,0 @@ -use clockwork_thread_program::state::ThreadSettings; - -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, - }, - InstructionData, -}; - -pub fn thread_update(authority: Pubkey, thread: Pubkey, settings: ThreadSettings) -> Instruction { - Instruction { - program_id: clockwork_thread_program::ID, - accounts: vec![ - AccountMeta::new_readonly(authority, true), - AccountMeta::new_readonly(system_program::ID, false), - AccountMeta::new(thread, false), - ], - data: clockwork_thread_program::instruction::ThreadUpdate { settings }.data(), - } -} diff --git a/client/src/thread/mod.rs b/client/src/thread/mod.rs deleted file mode 100644 index ca960d339..000000000 --- a/client/src/thread/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod instruction; - -pub use clockwork_thread_program::errors; -pub use clockwork_thread_program::state; -pub use clockwork_thread_program::ID; diff --git a/client/src/webhook/instruction/api_new.rs b/client/src/webhook/instruction/api_new.rs deleted file mode 100644 index 3cfd61c33..000000000 --- a/client/src/webhook/instruction/api_new.rs +++ /dev/null @@ -1,28 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, - }, - InstructionData, -}; - -pub fn api_new( - ack_authority: Pubkey, - authority: Pubkey, - base_url: String, - payer: Pubkey, -) -> Instruction { - let api_pubkey = clockwork_webhook_program::objects::Api::pubkey(authority, base_url.clone()); - Instruction { - program_id: clockwork_webhook_program::ID, - accounts: vec![ - AccountMeta::new_readonly(ack_authority, false), - AccountMeta::new(api_pubkey, false), - AccountMeta::new_readonly(authority, true), - AccountMeta::new(payer, true), - AccountMeta::new_readonly(system_program::ID, false), - ], - data: clockwork_webhook_program::instruction::ApiNew { base_url }.data(), - } -} diff --git a/client/src/webhook/instruction/initialize.rs b/client/src/webhook/instruction/initialize.rs deleted file mode 100644 index ee1607e69..000000000 --- a/client/src/webhook/instruction/initialize.rs +++ /dev/null @@ -1,21 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, - }, - InstructionData, -}; - -pub fn initialize(admin: Pubkey) -> Instruction { - let config_pubkey = clockwork_webhook_program::objects::Config::pubkey(); - Instruction { - program_id: clockwork_webhook_program::ID, - accounts: vec![ - AccountMeta::new(admin, true), - AccountMeta::new(config_pubkey, false), - AccountMeta::new_readonly(system_program::ID, false), - ], - data: clockwork_webhook_program::instruction::Initialize {}.data(), - } -} diff --git a/client/src/webhook/instruction/mod.rs b/client/src/webhook/instruction/mod.rs deleted file mode 100644 index e5c579485..000000000 --- a/client/src/webhook/instruction/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod api_new; -mod initialize; -mod request_ack; -mod request_new; - -pub use api_new::*; -pub use initialize::*; -pub use request_ack::*; -pub use request_new::*; diff --git a/client/src/webhook/instruction/request_ack.rs b/client/src/webhook/instruction/request_ack.rs deleted file mode 100644 index a014ce7fb..000000000 --- a/client/src/webhook/instruction/request_ack.rs +++ /dev/null @@ -1,32 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, sysvar, - }, - InstructionData, -}; - -pub fn request_ack( - ack_authority: Pubkey, - caller: Pubkey, - request: Pubkey, - worker: Pubkey, -) -> Instruction { - let config_pubkey = clockwork_webhook_program::objects::Config::pubkey(); - let fee_pubkey = clockwork_webhook_program::objects::Fee::pubkey(worker); - Instruction { - program_id: clockwork_webhook_program::ID, - accounts: vec![ - AccountMeta::new(ack_authority, true), - AccountMeta::new(caller, false), - AccountMeta::new_readonly(sysvar::clock::ID, false), - AccountMeta::new_readonly(config_pubkey, false), - AccountMeta::new(fee_pubkey, false), - AccountMeta::new(request, false), - AccountMeta::new_readonly(system_program::ID, false), - AccountMeta::new_readonly(worker, false), - ], - data: clockwork_webhook_program::instruction::RequestAck {}.data(), - } -} diff --git a/client/src/webhook/instruction/request_new.rs b/client/src/webhook/instruction/request_new.rs deleted file mode 100644 index 317ddee6b..000000000 --- a/client/src/webhook/instruction/request_new.rs +++ /dev/null @@ -1,37 +0,0 @@ -use anchor_lang::{ - solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, sysvar, - }, - InstructionData, -}; -use clockwork_webhook_program::objects::HttpMethod; - -pub fn request_new( - api: Pubkey, - caller: Pubkey, - id: String, - method: HttpMethod, - payer: Pubkey, - route: String, -) -> Instruction { - let config_pubkey = clockwork_webhook_program::objects::Config::pubkey(); - let pool_pubkey = clockwork_pool_program::objects::Pool::pubkey("http_workers".into()); - let request_pubkey = - clockwork_webhook_program::objects::Request::pubkey(api, caller, id.clone()); - Instruction { - program_id: clockwork_webhook_program::ID, - accounts: vec![ - AccountMeta::new_readonly(api, false), - AccountMeta::new_readonly(caller, true), - AccountMeta::new_readonly(sysvar::clock::ID, false), - AccountMeta::new_readonly(config_pubkey, false), - AccountMeta::new(payer, true), - AccountMeta::new(pool_pubkey, false), - AccountMeta::new(request_pubkey, false), - AccountMeta::new_readonly(system_program::ID, false), - ], - data: clockwork_webhook_program::instruction::RequestNew { id, method, route }.data(), - } -} diff --git a/client/src/webhook/mod.rs b/client/src/webhook/mod.rs deleted file mode 100644 index 68ad4740e..000000000 --- a/client/src/webhook/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -// pub mod instruction; - -pub use clockwork_webhook_program::state; -pub use clockwork_webhook_program::ID; diff --git a/plugin/Cargo.toml b/plugin/Cargo.toml index a6dd0dac8..8e955eba0 100644 --- a/plugin/Cargo.toml +++ b/plugin/Cargo.toml @@ -26,12 +26,13 @@ bincode = "1.3.3" bs58 = "0.4.0" bugsnag = "0.2.1" chrono = { version = "0.4.19", default-features = false, features = ["alloc"] } -clockwork-client = { path = "../client", version = "=2.0.15" } clockwork-cron = { path = "../cron", version = "=2.0.15" } +clockwork-network-program = { path = "../programs/network", version = "=2.0.15" } clockwork-plugin-utils = { path = "utils", version = "=2.0.15" } clockwork-relayer-api = { path = "../relayer/api", version = "=2.0.15" } clockwork-thread-program = { package = "clockwork-thread-program", path = "../programs/thread", version = "=2.0.15" } clockwork-thread-program-v1 = { package = "clockwork-thread-program-v1", path = "../programs/thread/v1", version = "=1.4.4" } +clockwork-webhook-program = { path = "../programs/webhook", version = "=2.0.15" } clockwork-utils = { path = "../utils", version = "=2.0.15" } lazy_static = "1.4.0" log = "0.4" diff --git a/plugin/src/builders/pool_rotation.rs b/plugin/src/builders/pool_rotation.rs index 712eb9499..85c2f504b 100644 --- a/plugin/src/builders/pool_rotation.rs +++ b/plugin/src/builders/pool_rotation.rs @@ -1,6 +1,10 @@ use std::sync::Arc; -use clockwork_client::network::state::{Pool, Registry, Snapshot, SnapshotFrame, Worker}; +use anchor_lang::{ + solana_program::instruction::Instruction, + InstructionData, ToAccountMetas +}; +use clockwork_network_program::state::{Config, Pool, Registry, Snapshot, SnapshotFrame, Worker}; use log::info; use solana_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction}; @@ -62,13 +66,19 @@ pub async fn build_pool_rotation_tx<'a>( // Build rotation instruction to rotate the worker into pool 0. let snapshot_pubkey = Snapshot::pubkey(snapshot.id); - let ix = clockwork_client::network::instruction::pool_rotate( - Pool::pubkey(0), - keypair.pubkey(), - snapshot_pubkey, - SnapshotFrame::pubkey(snapshot_pubkey, worker_id), - Worker::pubkey(worker_id), - ); + let ix = Instruction { + program_id: clockwork_network_program::ID, + accounts: clockwork_network_program::accounts::PoolRotate { + config: Config::pubkey(), + pool: Pool::pubkey(0), + registry: Registry::pubkey(), + signatory: keypair.pubkey(), + snapshot: snapshot_pubkey, + snapshot_frame: SnapshotFrame::pubkey(snapshot_pubkey, worker_id), + worker: Worker::pubkey(worker_id), + }.to_account_metas(Some(false)), + data: clockwork_network_program::instruction::PoolRotate {}.data(), + }; // Build and sign tx. let mut tx = Transaction::new_with_payer(&[ix.clone()], Some(&keypair.pubkey())); diff --git a/plugin/src/builders/thread_exec.rs b/plugin/src/builders/thread_exec.rs index aac777d15..e0ac02df7 100644 --- a/plugin/src/builders/thread_exec.rs +++ b/plugin/src/builders/thread_exec.rs @@ -1,8 +1,8 @@ use std::sync::Arc; use anchor_lang::{InstructionData, ToAccountMetas}; -use clockwork_client::{network::state::Worker, thread::state::Trigger}; -use clockwork_thread_program::state::VersionedThread; +use clockwork_thread_program::state::{VersionedThread, Trigger}; +use clockwork_network_program::state::Worker; use clockwork_utils::thread::PAYER_PUBKEY; use log::info; use solana_account_decoder::UiAccountEncoding; @@ -280,9 +280,9 @@ fn build_exec_ix( VersionedThread::V1(_) => Instruction { program_id: clockwork_thread_program_v1::ID, accounts: clockwork_thread_program_v1::accounts::ThreadExec { - fee: clockwork_client::network::state::Fee::pubkey(worker_pubkey), - penalty: clockwork_client::network::state::Penalty::pubkey(worker_pubkey), - pool: clockwork_client::network::state::Pool::pubkey(0), + fee: clockwork_network_program::state::Fee::pubkey(worker_pubkey), + penalty: clockwork_network_program::state::Penalty::pubkey(worker_pubkey), + pool: clockwork_network_program::state::Pool::pubkey(0), signatory: signatory_pubkey, thread: thread_pubkey, worker: worker_pubkey, @@ -293,8 +293,8 @@ fn build_exec_ix( VersionedThread::V2(_) => Instruction { program_id: clockwork_thread_program::ID, accounts: clockwork_thread_program::accounts::ThreadExec { - fee: clockwork_client::network::state::Fee::pubkey(worker_pubkey), - pool: clockwork_client::network::state::Pool::pubkey(0), + fee: clockwork_network_program::state::Fee::pubkey(worker_pubkey), + pool: clockwork_network_program::state::Pool::pubkey(0), signatory: signatory_pubkey, thread: thread_pubkey, worker: worker_pubkey, diff --git a/plugin/src/events.rs b/plugin/src/events.rs index 19c8e0cdd..0582279ae 100644 --- a/plugin/src/events.rs +++ b/plugin/src/events.rs @@ -1,8 +1,8 @@ use anchor_lang::{prelude::AccountInfo, AccountDeserialize, Discriminator}; use bincode::deserialize; -use clockwork_client::webhook::state::Webhook; use clockwork_thread_program::state::{Thread as ThreadV2, VersionedThread}; use clockwork_thread_program_v1::state::Thread as ThreadV1; +use clockwork_webhook_program::state::Webhook; use pyth_sdk_solana::{load_price_feed_from_account_info, PriceFeed}; use solana_geyser_plugin_interface::geyser_plugin_interface::{ GeyserPluginError, ReplicaAccountInfo, @@ -97,7 +97,7 @@ impl TryFrom<&mut ReplicaAccountInfo<'_>> for AccountUpdateEvent { } // If the account belongs to the webhook program, parse in - if owner_pubkey.eq(&clockwork_client::webhook::ID) && account_info.data.len() > 8 { + if owner_pubkey.eq(&clockwork_webhook_program::ID) && account_info.data.len() > 8 { return Ok(AccountUpdateEvent::Webhook { webhook: Webhook::try_deserialize(&mut account_info.data).map_err(|_| { GeyserPluginError::AccountsUpdateError { diff --git a/plugin/src/executors/tx.rs b/plugin/src/executors/tx.rs index a29cdbfc6..5898989ad 100644 --- a/plugin/src/executors/tx.rs +++ b/plugin/src/executors/tx.rs @@ -9,7 +9,7 @@ use std::{ use async_once::AsyncOnce; use bincode::serialize; -use clockwork_client::network::state::{Pool, Registry, Snapshot, SnapshotFrame, Worker}; +use clockwork_network_program::state::{Pool, Registry, Snapshot, SnapshotFrame, Worker}; use clockwork_thread_program::state::VersionedThread; use lazy_static::lazy_static; use log::info; diff --git a/plugin/src/executors/webhook.rs b/plugin/src/executors/webhook.rs index 07cf8d444..ea459487f 100644 --- a/plugin/src/executors/webhook.rs +++ b/plugin/src/executors/webhook.rs @@ -1,7 +1,7 @@ use std::{fmt::Debug, sync::Arc}; use anchor_lang::prelude::Pubkey; -use clockwork_client::webhook::state::Webhook; +use clockwork_webhook_program::state::Webhook; use clockwork_relayer_api::Relay; use log::info; use reqwest::header::CONTENT_TYPE; diff --git a/plugin/src/observers/thread.rs b/plugin/src/observers/thread.rs index 8f84a5c9c..9ac1457a9 100644 --- a/plugin/src/observers/thread.rs +++ b/plugin/src/observers/thread.rs @@ -6,9 +6,8 @@ use std::{ }; use chrono::{DateTime, NaiveDateTime, Utc}; -use clockwork_client::thread::state::{Trigger, TriggerContext}; use clockwork_cron::Schedule; -use clockwork_thread_program::state::{Equality, VersionedThread}; +use clockwork_thread_program::state::{Trigger, TriggerContext, Equality, VersionedThread}; use log::info; use pyth_sdk_solana::PriceFeed; use solana_geyser_plugin_interface::geyser_plugin_interface::{ diff --git a/plugin/src/observers/webhook.rs b/plugin/src/observers/webhook.rs index 4628d835b..e9a5bb045 100644 --- a/plugin/src/observers/webhook.rs +++ b/plugin/src/observers/webhook.rs @@ -1,6 +1,6 @@ use std::{collections::HashSet, fmt::Debug, sync::Arc}; -use clockwork_client::webhook::state::Webhook; +use clockwork_webhook_program::state::Webhook; use solana_geyser_plugin_interface::geyser_plugin_interface::Result as PluginResult; use solana_program::pubkey::Pubkey; use tokio::sync::RwLock;