#![allow(dead_code)]
use alloy_network::Ethereum;
use alloy_primitives::{Address, Bytes, U256};
use alloy_provider::Provider;
use alloy_rpc_types::TransactionRequest;
use alloy_sol_types::sol;
use tracing::{debug, info};
use crate::protocol::DomainId;
use crate::spans;
use TokenMessengerV2::TokenMessengerV2Instance;
#[allow(dead_code)]
pub struct TokenMessengerV2Contract<P: Provider<Ethereum>> {
instance: TokenMessengerV2Instance<P>,
}
impl<P: Provider<Ethereum>> TokenMessengerV2Contract<P> {
#[allow(dead_code)]
pub fn new(address: Address, provider: P) -> Self {
debug!(
contract_address = %address,
event = "token_messenger_v2_contract_initialized"
);
Self {
instance: TokenMessengerV2Instance::new(address, provider),
}
}
#[allow(dead_code)]
#[allow(clippy::too_many_arguments)]
fn deposit_for_burn_internal(
&self,
from_address: Address,
recipient: Address,
destination_domain: DomainId,
token_address: Address,
amount: U256,
max_fee: U256,
min_finality_threshold: u32,
destination_caller: Address,
) -> TransactionRequest {
self.instance
.depositForBurn(
amount,
destination_domain.as_u32(),
recipient.into_word(),
token_address,
destination_caller.into_word(),
max_fee,
min_finality_threshold,
)
.from(from_address)
.into_transaction_request()
}
#[allow(dead_code)]
pub fn deposit_for_burn_transaction(
&self,
from_address: Address,
recipient: Address,
destination_domain: DomainId,
token_address: Address,
amount: U256,
) -> TransactionRequest {
let span = spans::deposit_for_burn(
&from_address,
&recipient,
destination_domain.as_u32(),
&token_address,
&amount,
);
let _guard = span.enter();
info!(
from_address = %from_address,
recipient = %recipient,
destination_domain = %destination_domain,
token_address = %token_address,
amount = %amount,
contract_address = %self.instance.address(),
version = "v2",
finality_threshold = 2000,
event = "deposit_for_burn_v2_transaction_created"
);
self.deposit_for_burn_internal(
from_address,
recipient,
destination_domain,
token_address,
amount,
U256::ZERO, 2000, Address::ZERO, )
}
#[allow(dead_code)]
pub fn deposit_for_burn_fast_transaction(
&self,
from_address: Address,
recipient: Address,
destination_domain: DomainId,
token_address: Address,
amount: U256,
max_fee: U256,
) -> TransactionRequest {
info!(
from_address = %from_address,
recipient = %recipient,
destination_domain = %destination_domain,
token_address = %token_address,
amount = %amount,
max_fee = %max_fee,
contract_address = %self.instance.address(),
version = "v2",
transfer_type = "fast",
finality_threshold = 1000,
event = "deposit_for_burn_fast_transaction_created"
);
self.deposit_for_burn_internal(
from_address,
recipient,
destination_domain,
token_address,
amount,
max_fee, 1000, Address::ZERO, )
}
#[allow(dead_code)]
pub fn deposit_for_burn_with_hooks_transaction(
&self,
from_address: Address,
recipient: Address,
destination_domain: DomainId,
token_address: Address,
amount: U256,
hook_data: Bytes,
) -> TransactionRequest {
info!(
from_address = %from_address,
recipient = %recipient,
destination_domain = %destination_domain,
token_address = %token_address,
amount = %amount,
hook_data_len = hook_data.len(),
contract_address = %self.instance.address(),
version = "v2",
has_hooks = true,
finality_threshold = 2000,
event = "deposit_for_burn_hooks_transaction_created"
);
self.instance
.depositForBurnWithHook(
amount,
destination_domain.as_u32(),
recipient.into_word(),
token_address,
Address::ZERO.into_word(), U256::ZERO, 2000, hook_data,
)
.from(from_address)
.into_transaction_request()
}
pub fn address(&self) -> Address {
*self.instance.address()
}
}
sol!(
#[allow(clippy::too_many_arguments)]
#[allow(missing_docs)]
#[sol(rpc)]
TokenMessengerV2,
"abis/v2/token_messenger_v2.json"
);