@snapshot-labs/snapshot.js 0.14.3 → 0.14.4

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 getSonicNameOwner(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.4",
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,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}`);