1use crate::{
2 tempo::tempo_provider,
3 tx::{SendTxOpts, TxParams},
4};
5use alloy_ens::NameOrAddress;
6use alloy_sol_types::SolCall;
7use eyre::Result;
8use foundry_common::tempo::{Tip20LogoUriValidationError, validate_tip20_logo_uri};
9use tempo_contracts::precompiles::ITIP20;
10
11pub(super) fn check(logo_uri: &str) -> Result<()> {
12 validate_logo_uri(logo_uri)?;
13 sh_println!("Valid TIP-20 logo URI")
14}
15
16pub(super) async fn set(
17 token: NameOrAddress,
18 logo_uri: String,
19 send_tx: SendTxOpts,
20 tx_opts: TxParams,
21) -> Result<()> {
22 validate_logo_uri(&logo_uri)?;
23 let (_, provider) = tempo_provider(&send_tx.eth.rpc)?;
24 let token = token.resolve(&provider).await?;
25 let data = ITIP20::setLogoURICall { newLogoURI: logo_uri }.abi_encode();
26 super::send_tip20_transaction(token, data, send_tx, tx_opts).await
27}
28
29pub(super) fn validate_logo_uri(logo_uri: &str) -> Result<()> {
30 validate_tip20_logo_uri(logo_uri).map_err(|err| match err {
31 Tip20LogoUriValidationError::LogoURITooLong => {
32 eyre::eyre!("client-side validation failed: LogoURITooLong: logo URI exceeds 256 bytes")
33 }
34 Tip20LogoUriValidationError::InvalidLogoURI => {
35 eyre::eyre!(
36 "client-side validation failed: InvalidLogoURI: logo URI must use one of: https, http, ipfs, data"
37 )
38 }
39 })
40}