diff --git a/apps/fortuna/Cargo.lock b/apps/fortuna/Cargo.lock index f2163868..f2b5be54 100644 --- a/apps/fortuna/Cargo.lock +++ b/apps/fortuna/Cargo.lock @@ -1488,7 +1488,7 @@ dependencies = [ [[package]] name = "fortuna" -version = "5.2.1" +version = "6.0.0" dependencies = [ "anyhow", "axum", diff --git a/apps/fortuna/Cargo.toml b/apps/fortuna/Cargo.toml index b6595753..71070ecb 100644 --- a/apps/fortuna/Cargo.toml +++ b/apps/fortuna/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fortuna" -version = "5.2.1" +version = "6.0.0" edition = "2021" [dependencies] diff --git a/apps/fortuna/src/command/run.rs b/apps/fortuna/src/command/run.rs index d3eaea96..1c8a81cc 100644 --- a/apps/fortuna/src/command/run.rs +++ b/apps/fortuna/src/command/run.rs @@ -122,25 +122,15 @@ pub async fn run_keeper( pub async fn run(opts: &RunOptions) -> Result<()> { let config = Config::load(&opts.config.config)?; - let provider_config = opts - .provider_config - .provider_config - .as_ref() - .map(|path| ProviderConfig::load(&path).expect("Failed to load provider config")); + let provider_config = ProviderConfig::load(&opts.provider_config.provider_config)?; let secret = opts.randomness.load_secret()?; let (tx_exit, rx_exit) = watch::channel(false); let mut chains: HashMap = HashMap::new(); for (chain_id, chain_config) in &config.chains { let contract = Arc::new(PythContract::from_config(&chain_config)?); - let provider_chain_config = provider_config - .as_ref() - .and_then(|c| c.get_chain_config(chain_id)); - let mut provider_commitments = provider_chain_config - .as_ref() - .map(|c| c.get_sorted_commitments()) - .unwrap_or_else(|| Vec::new()); - + let provider_chain_config = provider_config.get_chain_config(chain_id)?; + let mut provider_commitments = provider_chain_config.get_sorted_commitments(); let provider_info = contract.get_provider_info(opts.provider).call().await?; let latest_metadata = bincode::deserialize::(&provider_info.commitment_metadata) diff --git a/apps/fortuna/src/command/setup_provider.rs b/apps/fortuna/src/command/setup_provider.rs index 71d0a35f..d19404f5 100644 --- a/apps/fortuna/src/command/setup_provider.rs +++ b/apps/fortuna/src/command/setup_provider.rs @@ -8,6 +8,7 @@ use { }, config::{ Config, + ProviderConfig, RegisterProviderOptions, SetupProviderOptions, }, @@ -39,11 +40,13 @@ use { /// 5. Update provider uri if there is a mismatch with the uri set on contract. pub async fn setup_provider(opts: &SetupProviderOptions) -> Result<()> { let config = Config::load(&opts.config.config)?; + let provider_config = ProviderConfig::load(&opts.provider_config.provider_config)?; let private_key = opts.load_private_key()?; let secret = opts.randomness.load_secret()?; let provider_address = private_key.clone().parse::()?.address(); for (chain_id, chain_config) in &config.chains { + let provider_fee = provider_config.get_chain_config(chain_id)?.fee; // Initialize a Provider to interface with the EVM contract. let contract = Arc::new(SignablePythContract::from_config(&chain_config, &private_key).await?); @@ -112,16 +115,21 @@ pub async fn setup_provider(opts: &SetupProviderOptions) -> Result<()> { chain_id: chain_id.clone(), private_key: private_key.clone(), randomness: opts.randomness.clone(), - fee: opts.fee, + fee: provider_fee, uri, }) .await .map_err(|e| anyhow!("Chain: {} - Failed to register provider: {}", &chain_id, e))?; tracing::info!("{}: registered", &chain_id); } else { - if provider_info.fee_in_wei != opts.fee { + if provider_info.fee_in_wei != provider_fee { tracing::info!("{}: updating provider fee", chain_id); - if let Some(r) = contract.set_provider_fee(opts.fee).send().await?.await? { + if let Some(r) = contract + .set_provider_fee(provider_fee) + .send() + .await? + .await? + { tracing::info!("{0}: updated provider fee: {1:?}", chain_id, r); } } diff --git a/apps/fortuna/src/config.rs b/apps/fortuna/src/config.rs index ead14c72..8bde4864 100644 --- a/apps/fortuna/src/config.rs +++ b/apps/fortuna/src/config.rs @@ -165,7 +165,7 @@ pub struct EthereumConfig { pub struct ProviderConfigOptions { #[arg(long = "provider-config")] #[arg(env = "FORTUNA_PROVIDER_CONFIG")] - pub provider_config: Option, + pub provider_config: String, } #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] @@ -183,14 +183,21 @@ impl ProviderConfig { /// Get the provider chain config. The method returns an Option for ProviderChainConfig. /// We may not have past any commitments for a chain. For example, for a new chain - pub fn get_chain_config(&self, chain_id: &ChainId) -> Option { - self.chains.get(chain_id).map(|x| x.clone()) + pub fn get_chain_config(&self, chain_id: &ChainId) -> Result { + self.chains.get(chain_id).map(|x| x.clone()).ok_or( + anyhow!( + "Could not find chain id {} in provider configuration", + &chain_id + ) + .into(), + ) } } #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct ProviderChainConfig { commitments: Vec, + pub fee: u128, } impl ProviderChainConfig { diff --git a/apps/fortuna/src/config/setup_provider.rs b/apps/fortuna/src/config/setup_provider.rs index 1bee7fb9..e7f8750f 100644 --- a/apps/fortuna/src/config/setup_provider.rs +++ b/apps/fortuna/src/config/setup_provider.rs @@ -7,6 +7,7 @@ use { clap::Args, std::fs, }; +use crate::config::ProviderConfigOptions; #[derive(Args, Clone, Debug)] #[command(next_help_heading = "Setup Provider Options")] @@ -15,6 +16,9 @@ pub struct SetupProviderOptions { #[command(flatten)] pub config: ConfigOptions, + #[command(flatten)] + pub provider_config: ProviderConfigOptions, + /// Path to a file containing a 20-byte (40 char) hex encoded Ethereum private key. /// This key is required to submit transactions (such as registering with the contract). #[arg(long = "private-key")] @@ -24,11 +28,6 @@ pub struct SetupProviderOptions { #[command(flatten)] pub randomness: RandomnessOptions, - /// The fee to charge (in wei) for each requested random number - #[arg(long = "pyth-contract-fee")] - #[arg(default_value = "100")] - pub fee: u128, - /// The base URI for fortuna. /// e.g., https://fortuna-staging.dourolabs.app #[arg(long = "uri")]