Skip to main content

tempo_alloy/fillers/
sponsor.rs

1use crate::rpc::TempoTransactionRequest;
2use alloy_network::Network;
3use alloy_provider::{
4    Provider, SendableTx,
5    fillers::{FillerControlFlow, TxFiller},
6};
7use alloy_transport::TransportResult;
8use tempo_primitives::transaction::FEE_PAYER_SIGNATURE_MARKER;
9
10/// A [`TxFiller`] that marks Tempo AA transactions for fee-payer sponsorship.
11///
12/// The sponsor service expects user-signed transactions to include the Tempo fee-payer signature
13/// placeholder. The sponsor replaces that placeholder with its real fee-payer signature before
14/// relaying the transaction.
15#[derive(Clone, Copy, Debug, Default)]
16pub struct SponsorFiller;
17
18impl<N: Network<TransactionRequest = TempoTransactionRequest>> TxFiller<N> for SponsorFiller {
19    type Fillable = ();
20
21    fn status(&self, tx: &N::TransactionRequest) -> FillerControlFlow {
22        // Only fill absent signatures; never overwrite an existing marker or real signature.
23        if tx.fee_payer_signature.is_none() {
24            FillerControlFlow::Ready
25        } else {
26            FillerControlFlow::Finished
27        }
28    }
29
30    fn fill_sync(&self, _tx: &mut SendableTx<N>) {}
31
32    async fn prepare<P>(&self, _provider: &P, _tx: &N::TransactionRequest) -> TransportResult<()>
33    where
34        P: Provider<N>,
35    {
36        Ok(())
37    }
38
39    async fn fill(&self, _fillable: (), mut tx: SendableTx<N>) -> TransportResult<SendableTx<N>> {
40        if let Some(builder) = tx.as_mut_builder()
41            && builder.fee_payer_signature.is_none()
42        {
43            builder.set_fee_payer_signature(FEE_PAYER_SIGNATURE_MARKER);
44        }
45        Ok(tx)
46    }
47}