|
| 1 | +use crate::contract::sEOA::SubmitNewBlobInput; |
| 2 | +use alloy::{ |
| 3 | + consensus::BlobTransactionSidecar, |
| 4 | + network::EthereumWallet, |
| 5 | + primitives::{Address, Bytes, FixedBytes}, |
| 6 | + providers::{ |
| 7 | + Identity, ProviderBuilder, |
| 8 | + fillers::{ |
| 9 | + BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, |
| 10 | + WalletFiller, |
| 11 | + }, |
| 12 | + }, |
| 13 | + sol, |
| 14 | +}; |
| 15 | +use blobs_batch_sender::BlobsBatchSenderConfig; |
| 16 | +use lambda_runtime::Error; |
| 17 | +use owen::blobs_queue::BlobsQueueS3JsonFile; |
| 18 | + |
| 19 | +sol!( |
| 20 | + #[allow(missing_docs)] |
| 21 | + #[sol(rpc)] |
| 22 | + sEOA, |
| 23 | + "../../submodules/account-abstraction/artifacts/contracts/sEOA.sol/sEOA.json" |
| 24 | +); |
| 25 | + |
| 26 | +type HardlyTypedProvider = FillProvider< |
| 27 | + JoinFill< |
| 28 | + JoinFill< |
| 29 | + Identity, |
| 30 | + JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>, |
| 31 | + >, |
| 32 | + WalletFiller<EthereumWallet>, |
| 33 | + >, |
| 34 | + alloy::providers::RootProvider, |
| 35 | +>; |
| 36 | + |
| 37 | +struct SendBatchTxInput { |
| 38 | + tx_params: Vec<SubmitNewBlobInput>, |
| 39 | + sidecar: BlobTransactionSidecar, |
| 40 | +} |
| 41 | + |
| 42 | +pub struct SmartEoaManager { |
| 43 | + ddex_sequencer_address: Address, |
| 44 | + s_eoa: sEOA::sEOAInstance<HardlyTypedProvider>, |
| 45 | +} |
| 46 | + |
| 47 | +impl SmartEoaManager { |
| 48 | + pub fn build(config: &BlobsBatchSenderConfig, wallet: EthereumWallet) -> Result<Self, Error> { |
| 49 | + let provider = ProviderBuilder::new() |
| 50 | + .wallet(wallet) |
| 51 | + .connect_http(config.rpc_url.parse()?); |
| 52 | + |
| 53 | + let s_eoa = sEOA::new(config.s_eoa_address, provider); |
| 54 | + |
| 55 | + Ok(Self { |
| 56 | + ddex_sequencer_address: config.ddex_sequencer_address, |
| 57 | + s_eoa, |
| 58 | + }) |
| 59 | + } |
| 60 | + |
| 61 | + fn parse_batch_input( |
| 62 | + blob_tx_data_vec: Vec<BlobsQueueS3JsonFile>, |
| 63 | + ) -> Result<SendBatchTxInput, Error> { |
| 64 | + let tx_params: Vec<SubmitNewBlobInput> = blob_tx_data_vec |
| 65 | + .iter() |
| 66 | + .map(|blob_json_file| SubmitNewBlobInput { |
| 67 | + imageId: blob_json_file.image_id, |
| 68 | + commitment: Bytes::from(blob_json_file.tx_data.kzg_commitment.to_vec()), |
| 69 | + blobSha2: FixedBytes::<32>::from(blob_json_file.tx_data.blob_sha2), |
| 70 | + }) |
| 71 | + .collect(); |
| 72 | + |
| 73 | + let mut sidecar = BlobTransactionSidecar { |
| 74 | + blobs: Vec::new(), |
| 75 | + commitments: Vec::new(), |
| 76 | + proofs: Vec::new(), |
| 77 | + }; |
| 78 | + |
| 79 | + for blob_json_file in blob_tx_data_vec { |
| 80 | + sidecar.blobs.push( |
| 81 | + blob_json_file |
| 82 | + .tx_data |
| 83 | + .blob_sidecar |
| 84 | + .blobs |
| 85 | + .first() |
| 86 | + .expect("Blob missing in input") |
| 87 | + .clone(), |
| 88 | + ); |
| 89 | + sidecar.commitments.push( |
| 90 | + blob_json_file |
| 91 | + .tx_data |
| 92 | + .blob_sidecar |
| 93 | + .commitments |
| 94 | + .first() |
| 95 | + .expect("commitment missing in input") |
| 96 | + .clone(), |
| 97 | + ); |
| 98 | + sidecar.proofs.push( |
| 99 | + blob_json_file |
| 100 | + .tx_data |
| 101 | + .blob_sidecar |
| 102 | + .proofs |
| 103 | + .first() |
| 104 | + .expect("proof missing in input") |
| 105 | + .clone(), |
| 106 | + ); |
| 107 | + } |
| 108 | + Ok(SendBatchTxInput { tx_params, sidecar }) |
| 109 | + } |
| 110 | + |
| 111 | + pub async fn send_batch( |
| 112 | + &self, |
| 113 | + blob_tx_data_vec: Vec<BlobsQueueS3JsonFile>, |
| 114 | + ) -> Result<(), Error> { |
| 115 | + let batch_input = Self::parse_batch_input(blob_tx_data_vec)?; |
| 116 | + let mut _tx_builder = self |
| 117 | + .s_eoa |
| 118 | + .submitNewBlobBatch(batch_input.tx_params, self.ddex_sequencer_address) |
| 119 | + .sidecar(batch_input.sidecar) |
| 120 | + .max_fee_per_blob_gas(1000000001); |
| 121 | + Ok(()) |
| 122 | + } |
| 123 | +} |
0 commit comments