@snapshot-labs/snapshot.js 0.14.4 → 0.14.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@ export declare function getEnsTextRecord(ens: string, record: string, network?:
31
31
  export declare function getSpaceUri(id: string, network?: string, options?: any): Promise<string | null>;
32
32
  export declare function getEnsOwner(ens: string, network?: string, options?: any): Promise<string>;
33
33
  export declare function getShibariumNameOwner(id: string, network: string): Promise<string>;
34
- export declare function getSonicNameOwner(id: string, network: string): Promise<string>;
34
+ export declare function getUDNameOwner(id: string, network: string): Promise<string>;
35
35
  export declare function getSpaceController(id: string, network?: string, options?: any): Promise<string>;
36
36
  export declare function clone(item: any): any;
37
37
  export declare function sleep(time: any): Promise<unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.14.4",
3
+ "version": "0.14.5",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
package/src/utils.ts CHANGED
@@ -43,14 +43,17 @@ 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)'
46
+ const UD_MAPPING = {
47
+ '146': {
48
+ tlds: ['.sonic'],
49
+ registryContract: '0xde1dadcf11a7447c3d093e97fdbd513f488ce3b4'
50
+ }
51
+ };
52
+ const UD_REGISTRY_ABI = [
53
+ 'function ownerOf(uint256 tokenId) view returns (address owner)'
48
54
  ];
49
- const SONIC_CONTRACT_ADDRESS = '0xde1dadcf11a7447c3d093e97fdbd513f488ce3b4';
50
55
  const ENS_CHAIN_IDS = ['1', '11155111'];
51
56
  const SHIBARIUM_CHAIN_IDS = ['109', '157'];
52
- const SONIC_CHAIN_IDS = ['146'];
53
- const SONIC_TLD = '.sonic';
54
57
  const SHIBARIUM_TLD = '.shib';
55
58
  const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000';
56
59
 
@@ -701,23 +704,24 @@ export async function getShibariumNameOwner(
701
704
  return data.result;
702
705
  }
703
706
 
704
- export async function getSonicNameOwner(
707
+ export async function getUDNameOwner(
705
708
  id: string,
706
709
  network: string
707
710
  ): Promise<string> {
708
- if (!id.endsWith(SONIC_TLD)) {
711
+ const tlds = UD_MAPPING[network]?.tlds || [];
712
+ if (!tlds.some((tld: string) => id.endsWith(tld))) {
709
713
  return Promise.resolve(EMPTY_ADDRESS);
710
714
  }
711
715
 
712
716
  try {
713
717
  const hash = namehash(ensNormalize(id));
714
- const tokenId = BigInt(hash).toString();
718
+ const tokenId = BigInt(hash);
715
719
  const provider = getProvider(network);
716
720
 
717
721
  return await call(
718
722
  provider,
719
- SONIC_ABI,
720
- [SONIC_CONTRACT_ADDRESS, 'ownerOf', [tokenId]],
723
+ UD_REGISTRY_ABI,
724
+ [UD_MAPPING[network].registryContract, 'ownerOf', [tokenId]],
721
725
  {
722
726
  blockTag: 'latest'
723
727
  }
@@ -736,8 +740,8 @@ export async function getSpaceController(
736
740
  return getEnsSpaceController(id, network, options);
737
741
  } else if (SHIBARIUM_CHAIN_IDS.includes(network)) {
738
742
  return getShibariumNameOwner(id, network);
739
- } else if (SONIC_CHAIN_IDS.includes(network)) {
740
- return getSonicNameOwner(id, network);
743
+ } else if (UD_MAPPING[String(network)]) {
744
+ return getUDNameOwner(id, network);
741
745
  }
742
746
 
743
747
  throw new Error(`Network not supported: ${network}`);