@snapshot-labs/snapshot.js 0.14.3 → 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,6 +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 getUDNameOwner(id: string, network: string): Promise<string>;
34
35
  export declare function getSpaceController(id: string, network?: string, options?: any): Promise<string>;
35
36
  export declare function clone(item: any): any;
36
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.3",
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/networks.json CHANGED
@@ -518,6 +518,20 @@
518
518
  "start": 13960096,
519
519
  "logo": "ipfs://QmU7f1MyRz8rLELFfypnWZQjGbDGYgZtC9rjw47jYMYrnu"
520
520
  },
521
+ "291": {
522
+ "key": "291",
523
+ "name": "Orderly",
524
+ "shortName": "mainnet",
525
+ "chainId": 291,
526
+ "network": "mainnet",
527
+ "multicall": "0x73e524d811263a145026113219F13f9133966b6b",
528
+ "rpc": [],
529
+ "explorer": {
530
+ "url": "https://explorer.orderly.network"
531
+ },
532
+ "start": 22457562,
533
+ "logo": "ipfs://bafkreibo62xtgkpam6nm34mau26gn65jlw6npb5odw4ylcd6dkwocea5ni"
534
+ },
521
535
  "296": {
522
536
  "key": "296",
523
537
  "name": "Hedera Testnet",
@@ -1983,7 +1997,9 @@
1983
1997
  "explorer": {
1984
1998
  "url": "https://starkscan.co"
1985
1999
  },
1986
- "rpc": ["https://starknet-mainnet.public.blastapi.io"],
2000
+ "rpc": [
2001
+ "https://starknet-mainnet.public.blastapi.io"
2002
+ ],
1987
2003
  "start": 8446,
1988
2004
  "logo": "ipfs://bafkreihbjafyh7eud7r6e5743esaamifcttsvbspfwcrfoc5ykodjdi67m"
1989
2005
  },
@@ -2000,8 +2016,10 @@
2000
2016
  "explorer": {
2001
2017
  "url": "https://sepolia.starkscan.co"
2002
2018
  },
2003
- "rpc": ["https://starknet-sepolia.public.blastapi.io"],
2019
+ "rpc": [
2020
+ "https://starknet-sepolia.public.blastapi.io"
2021
+ ],
2004
2022
  "start": 7,
2005
2023
  "logo": "ipfs://bafkreihbjafyh7eud7r6e5743esaamifcttsvbspfwcrfoc5ykodjdi67m"
2006
2024
  }
2007
- }
2025
+ }
package/src/utils.ts CHANGED
@@ -43,6 +43,18 @@ 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 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)'
54
+ ];
55
+ const ENS_CHAIN_IDS = ['1', '11155111'];
56
+ const SHIBARIUM_CHAIN_IDS = ['109', '157'];
57
+ const SHIBARIUM_TLD = '.shib';
46
58
  const EMPTY_ADDRESS = '0x0000000000000000000000000000000000000000';
47
59
 
48
60
  const scoreApiHeaders = {
@@ -672,7 +684,7 @@ export async function getShibariumNameOwner(
672
684
  id: string,
673
685
  network: string
674
686
  ): Promise<string> {
675
- if (!id.endsWith('.shib')) {
687
+ if (!id.endsWith(SHIBARIUM_TLD)) {
676
688
  return EMPTY_ADDRESS;
677
689
  }
678
690
 
@@ -692,15 +704,44 @@ export async function getShibariumNameOwner(
692
704
  return data.result;
693
705
  }
694
706
 
707
+ export async function getUDNameOwner(
708
+ id: string,
709
+ network: string
710
+ ): Promise<string> {
711
+ const tlds = UD_MAPPING[network]?.tlds || [];
712
+ if (!tlds.some((tld: string) => id.endsWith(tld))) {
713
+ return Promise.resolve(EMPTY_ADDRESS);
714
+ }
715
+
716
+ try {
717
+ const hash = namehash(ensNormalize(id));
718
+ const tokenId = BigInt(hash);
719
+ const provider = getProvider(network);
720
+
721
+ return await call(
722
+ provider,
723
+ UD_REGISTRY_ABI,
724
+ [UD_MAPPING[network].registryContract, 'ownerOf', [tokenId]],
725
+ {
726
+ blockTag: 'latest'
727
+ }
728
+ );
729
+ } catch (e: any) {
730
+ return EMPTY_ADDRESS;
731
+ }
732
+ }
733
+
695
734
  export async function getSpaceController(
696
735
  id: string,
697
736
  network = '1',
698
737
  options: any = {}
699
738
  ): Promise<string> {
700
- if (['1', '11155111'].includes(network)) {
739
+ if (ENS_CHAIN_IDS.includes(network)) {
701
740
  return getEnsSpaceController(id, network, options);
702
- } else if (['109', '157'].includes(network)) {
741
+ } else if (SHIBARIUM_CHAIN_IDS.includes(network)) {
703
742
  return getShibariumNameOwner(id, network);
743
+ } else if (UD_MAPPING[String(network)]) {
744
+ return getUDNameOwner(id, network);
704
745
  }
705
746
 
706
747
  throw new Error(`Network not supported: ${network}`);