import { ethers } from 'ethers'; import { CollectionsRegistry as BaseContract } from '../config/abi/CollectionsRegistry'; import { CollectionsRegistry__factory } from '../config/abi/factories/CollectionsRegistry__factory'; import { ContractInitializer } from './ContractInitializer'; const iface = CollectionsRegistry__factory.createInterface(); export class CollectionsRegistry extends ContractInitializer { className = CollectionsRegistry.name; static create( signer: ethers.providers.JsonRpcSigner, address: string, chainId: string ) { const instance = new CollectionsRegistry(chainId, iface, signer); instance.address = address; instance.initialize(); return instance; } static _newInstance = (chainId: string) => { const selfInstance = new CollectionsRegistry(chainId, iface); selfInstance.address = selfInstance.contractAddress.collectionRegistry; selfInstance.initialize(); return selfInstance; }; static externalToCollection = async ( chainId: string, tokenAddress: string ): Promise => { const selfInstance = CollectionsRegistry._newInstance(chainId); return selfInstance.contractInstance.externalToCollection(tokenAddress); }; static addressOf = async (chainId: string, collectionId: string) => { const selfInstance = CollectionsRegistry._newInstance(chainId); return selfInstance.contractInstance.addressOf(collectionId); }; static getCollectionIds = async ( chainId: string, collectionAddresses: Array ) => { const selfInstance = CollectionsRegistry._newInstance(chainId); return selfInstance.contractInstance.getCollectionIds( collectionAddresses ); }; /** * Return all owner collections on given chain * * @param {string} chainId - Chain ID * @param {string} ownerAddress - Address of the owner */ static listCollectionsPerOwner = async ( chainId: string, ownerAddress: string ) => { const selfInstance = CollectionsRegistry._newInstance(chainId); selfInstance.logCall('listCollectionsPerOwner', { chainId, ownerAddress, address: selfInstance.contractAddress, }); return selfInstance.contractInstance.listCollectionsPerOwner( ownerAddress ); }; /** * Return collection id of the given collection address * * @param {string} chainId * @param {string} tokenAddress */ static collections = async (chainId: string, tokenAddress: string) => { const selfInstance = CollectionsRegistry._newInstance(chainId); return selfInstance.contractInstance.collections(tokenAddress); }; static getRecord = async (chainId: string, collectionId: string) => { const selfInstance = CollectionsRegistry._newInstance(chainId); return selfInstance.contractInstance.getRecord(collectionId); }; }