@@ -5,6 +5,7 @@ use alloy::rpc::types::request::{TransactionInput, TransactionRequest};
55use alloy:: { hex, primitives:: keccak256} ;
66use alloy_primitives:: { Address , Bytes , FixedBytes , B256 } ;
77use alloy_sol_types:: { SolCall , SolEvent , SolValue } ;
8+ use contract:: tokenCall;
89use serde:: { Deserialize , Serialize } ;
910use std:: error:: Error ;
1011use std:: fmt;
@@ -212,12 +213,19 @@ pub mod contract {
212213
213214 function supportsInterface( bytes4 interfaceId) external view returns ( bool ) ;
214215
215- /// Retrieves the address of the ERC-6551 implementation of the
216- /// zeroth entry. This is set once at initialization.
216+ /// Gets the token identifier that owns this token-bound account (TBA).
217+ /// This is a core function of the ERC-6551 standard that returns the
218+ /// identifying information about the NFT that owns this account.
219+ /// The return values are constant and cannot change over time.
217220 ///
218221 /// Returns:
219- /// - implementation: The address of the ERC-6551 implementation.
220- function get6551Implementation( ) external view returns ( address) ;
222+ /// - chainId: The EIP-155 chain ID where the owning NFT exists
223+ /// - tokenContract: The contract address of the owning NFT
224+ /// - tokenId: The token ID of the owning NFT
225+ function token( )
226+ external
227+ view
228+ returns ( uint256 chainId, address tokenContract, uint256 tokenId) ;
221229 }
222230}
223231
@@ -267,7 +275,9 @@ impl fmt::Display for DecodeLogError {
267275 DecodeLogError :: UnexpectedTopic ( topic) => write ! ( f, "Unexpected topic: {:?}" , topic) ,
268276 DecodeLogError :: InvalidName ( name) => write ! ( f, "Invalid name: {}" , name) ,
269277 DecodeLogError :: DecodeError ( err) => write ! ( f, "Decode error: {}" , err) ,
270- DecodeLogError :: UnresolvedParent ( parent) => write ! ( f, "Could not resolve parent: {}" , parent) ,
278+ DecodeLogError :: UnresolvedParent ( parent) => {
279+ write ! ( f, "Could not resolve parent: {}" , parent)
280+ }
271281 }
272282 }
273283}
@@ -529,6 +539,28 @@ impl Kimap {
529539 Ok ( ( res. tba , res. owner , note_data) )
530540 }
531541
542+ /// Gets a namehash from an existing TBA address.
543+ ///
544+ /// # Parameters
545+ /// - `tba`: The TBA to get the namehash of.
546+ /// # Returns
547+ /// A `Result<String, EthError>` representing the namehash of the TBA.
548+ pub fn get_namehash_from_tba ( & self , tba : Address ) -> Result < String , EthError > {
549+ let token_call = tokenCall { } . abi_encode ( ) ;
550+
551+ let tx_req = TransactionRequest :: default ( )
552+ . input ( TransactionInput :: new ( token_call. into ( ) ) )
553+ . to ( tba) ;
554+
555+ let res_bytes = self . provider . call ( tx_req, None ) ?;
556+
557+ let res = tokenCall:: abi_decode_returns ( & res_bytes, false )
558+ . map_err ( |_| EthError :: RpcMalformedResponse ) ?;
559+
560+ let bytes = res. tokenId . to_be_bytes :: < 32 > ( ) ;
561+ Ok ( format ! ( "0x{}" , hex:: encode( bytes) ) )
562+ }
563+
532564 /// Create a filter for all mint events.
533565 pub fn mint_filter ( & self ) -> crate :: eth:: Filter {
534566 crate :: eth:: Filter :: new ( )
0 commit comments