Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fortuna] Withdraw fees #1610

Merged
merged 14 commits into from
Jun 5, 2024
Merged

[fortuna] Withdraw fees #1610

merged 14 commits into from
Jun 5, 2024

Conversation

jayantk
Copy link
Contributor

@jayantk jayantk commented May 24, 2024

Add logic to withdraw fees. Couple related features here:

  1. The provider configuration now includes the fee manager and the provider config job sets it on-chain
  2. CLI command for withdrawing fees as either the provider or keeper
  3. Background task for the keeper to withdraw fees when its wallet gets low

Copy link

vercel bot commented May 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) Visit Preview Jun 5, 2024 6:42pm
xc-admin-frontend ⬜️ Ignored (Inspect) Visit Preview Jun 5, 2024 6:42pm

&provider_info,
provider_config
.fee_manager
.unwrap_or(Address::from([0u8; 20])),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address::zero()

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. "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space at the end of string

contract.wallet().address()
);

if is_fee_manager {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part has a bit of repeated logic. Can refactor into something like this:

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?;
log_tx_hash(&tx_result);


let fees = provider_info.accrued_fees_in_wei;

let min_balance = U256::from(12345);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably read this from some config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops

.await
.map_err(|e| anyhow!("Error while getting provider info. error: {:?}", e))?;

let fees = provider_info.accrued_fees_in_wei;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add some check that the fee_manager is actually the keeper. Otherwise, we may get confusing revert errors

@@ -837,3 +846,68 @@ pub async fn track_provider(
})
.set(end_sequence_number as i64);
}

// TODO: fields
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no fields necessary here. We only want the chain_id and if you add in_current_span when you are spawning this, it should be enough.

@jayantk jayantk merged commit 98a02e3 into main Jun 5, 2024
4 checks passed
@jayantk jayantk deleted the fortuna_withdraw branch June 5, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants