@@ -43,6 +43,15 @@ const ENS_ABI = [
43
43
'function text(bytes32 node, string calldata key) external view returns (string memory)' ,
44
44
'function resolver(bytes32 node) view returns (address)' // ENS registry ABI
45
45
] ;
46
+ const SONIC_ABI = [
47
+ 'function ownerOf(uint256 tokenId) external view returns (address address)'
48
+ ] ;
49
+ const SONIC_CONTRACT_ADDRESS = '0xde1dadcf11a7447c3d093e97fdbd513f488ce3b4' ;
50
+ const ENS_CHAIN_IDS = [ '1' , '11155111' ] ;
51
+ const SHIBARIUM_CHAIN_IDS = [ '109' , '157' ] ;
52
+ const SONIC_CHAIN_IDS = [ '146' ] ;
53
+ const SONIC_TLD = '.sonic' ;
54
+ const SHIBARIUM_TLD = '.shib' ;
46
55
const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000' ;
47
56
48
57
const scoreApiHeaders = {
@@ -672,7 +681,7 @@ export async function getShibariumNameOwner(
672
681
id : string ,
673
682
network : string
674
683
) : Promise < string > {
675
- if ( ! id . endsWith ( '.shib' ) ) {
684
+ if ( ! id . endsWith ( SHIBARIUM_TLD ) ) {
676
685
return EMPTY_ADDRESS ;
677
686
}
678
687
@@ -692,15 +701,43 @@ export async function getShibariumNameOwner(
692
701
return data . result ;
693
702
}
694
703
704
+ export async function getSonicNameOwner (
705
+ id : string ,
706
+ network : string
707
+ ) : Promise < string > {
708
+ if ( ! id . endsWith ( SONIC_TLD ) ) {
709
+ return Promise . resolve ( EMPTY_ADDRESS ) ;
710
+ }
711
+
712
+ try {
713
+ const hash = namehash ( ensNormalize ( id ) ) ;
714
+ const tokenId = BigInt ( hash ) . toString ( ) ;
715
+ const provider = getProvider ( network ) ;
716
+
717
+ return await call (
718
+ provider ,
719
+ SONIC_ABI ,
720
+ [ SONIC_CONTRACT_ADDRESS , 'ownerOf' , [ tokenId ] ] ,
721
+ {
722
+ blockTag : 'latest'
723
+ }
724
+ ) ;
725
+ } catch ( e : any ) {
726
+ return EMPTY_ADDRESS ;
727
+ }
728
+ }
729
+
695
730
export async function getSpaceController (
696
731
id : string ,
697
732
network = '1' ,
698
733
options : any = { }
699
734
) : Promise < string > {
700
- if ( [ '1' , '11155111' ] . includes ( network ) ) {
735
+ if ( ENS_CHAIN_IDS . includes ( network ) ) {
701
736
return getEnsSpaceController ( id , network , options ) ;
702
- } else if ( [ '109' , '157' ] . includes ( network ) ) {
737
+ } else if ( SHIBARIUM_CHAIN_IDS . includes ( network ) ) {
703
738
return getShibariumNameOwner ( id , network ) ;
739
+ } else if ( SONIC_CHAIN_IDS . includes ( network ) ) {
740
+ return getSonicNameOwner ( id , network ) ;
704
741
}
705
742
706
743
throw new Error ( `Network not supported: ${ network } ` ) ;
0 commit comments