-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* withdraw fees command * hmmmm * rg * withdraw fees * it builds * add fee manager to config * withdrawal cli fixes * cleanup * pr comments * cargo bump * log
- Loading branch information
Showing
11 changed files
with
290 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "fortuna" | ||
version = "6.2.3" | ||
version = "6.3.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use { | ||
crate::{ | ||
chain::ethereum::SignablePythContract, | ||
config::{ | ||
Config, | ||
WithdrawFeesOptions, | ||
}, | ||
}, | ||
anyhow::{ | ||
anyhow, | ||
Result, | ||
}, | ||
ethers::{ | ||
signers::Signer, | ||
types::Address, | ||
}, | ||
}; | ||
|
||
|
||
pub async fn withdraw_fees(opts: &WithdrawFeesOptions) -> Result<()> { | ||
let config = Config::load(&opts.config.config)?; | ||
|
||
let private_key_string = if opts.keeper { | ||
config.keeper.private_key.load()?.ok_or(anyhow!("Please specify a keeper private key in the config or omit the --keeper option to use the provider private key"))? | ||
} else { | ||
config.provider.private_key.load()?.ok_or(anyhow!( | ||
"Please specify a provider private key in the config or provide the --keeper option to use the keeper private key instead." | ||
))? | ||
}; | ||
|
||
match opts.chain_id.clone() { | ||
Some(chain_id) => { | ||
let chain_config = &config.get_chain_config(&chain_id)?; | ||
let contract = | ||
SignablePythContract::from_config(&chain_config, &private_key_string).await?; | ||
|
||
withdraw_fees_for_chain( | ||
contract, | ||
config.provider.address.clone(), | ||
opts.keeper, | ||
opts.retain_balance_wei, | ||
) | ||
.await?; | ||
} | ||
None => { | ||
for (chain_id, chain_config) in config.chains.iter() { | ||
tracing::info!("Withdrawing fees for chain: {}", chain_id); | ||
let contract = | ||
SignablePythContract::from_config(&chain_config, &private_key_string).await?; | ||
|
||
withdraw_fees_for_chain( | ||
contract, | ||
config.provider.address.clone(), | ||
opts.keeper, | ||
opts.retain_balance_wei, | ||
) | ||
.await?; | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub async fn withdraw_fees_for_chain( | ||
contract: SignablePythContract, | ||
provider_address: Address, | ||
is_fee_manager: bool, | ||
retained_balance: u128, | ||
) -> Result<()> { | ||
tracing::info!("Fetching fees for provider: {:?}", provider_address); | ||
let provider_info = contract.get_provider_info(provider_address).call().await?; | ||
let fees = provider_info.accrued_fees_in_wei; | ||
tracing::info!("Accrued fees: {} wei", fees); | ||
|
||
let withdrawal_amount_wei = fees.saturating_sub(retained_balance); | ||
if withdrawal_amount_wei > 0 { | ||
tracing::info!( | ||
"Withdrawing {} wei to {}...", | ||
withdrawal_amount_wei, | ||
contract.wallet().address() | ||
); | ||
|
||
let call = match is_fee_manager { | ||
true => contract.withdraw_as_fee_manager(provider_address, withdrawal_amount_wei), | ||
false => contract.withdraw(withdrawal_amount_wei), | ||
}; | ||
let tx_result = call.send().await?.await?; | ||
|
||
match &tx_result { | ||
Some(receipt) => { | ||
tracing::info!("Withdrawal transaction hash {:?}", receipt.transaction_hash); | ||
} | ||
None => { | ||
tracing::warn!("No transaction receipt. Unclear what happened to the transaction"); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use { | ||
crate::{ | ||
api::ChainId, | ||
config::ConfigOptions, | ||
}, | ||
clap::Args, | ||
}; | ||
|
||
#[derive(Args, Clone, Debug)] | ||
#[command(next_help_heading = "Withdraw Fees Options")] | ||
#[group(id = "Withdraw Fees")] | ||
pub struct WithdrawFeesOptions { | ||
#[command(flatten)] | ||
pub config: ConfigOptions, | ||
|
||
/// Withdraw the fees on this chain, or all chains if not specified. | ||
#[arg(long = "chain-id")] | ||
pub chain_id: Option<ChainId>, | ||
|
||
/// If provided, run the command using the keeper wallet. By default, the command uses the provider wallet. | ||
/// If this option is provided, the keeper wallet must be configured and set as the fee manager for the provider. | ||
#[arg(long = "keeper")] | ||
#[arg(default_value = "false")] | ||
pub keeper: bool, | ||
|
||
/// If specified, only withdraw fees over the given balance from the contract. | ||
/// If omitted, all accrued fees are withdrawn. | ||
#[arg(long = "retain-balance")] | ||
#[arg(default_value = "0")] | ||
pub retain_balance_wei: u128, | ||
} |
Oops, something went wrong.